Skip to content

Commit 390d5af

Browse files
committed
wip: qoi image video
1 parent f30191d commit 390d5af

File tree

10 files changed

+104
-42
lines changed

10 files changed

+104
-42
lines changed

common/contrib/qoi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../contrib/qoi

common/generate_links.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ link ../../contrib/imgui_knobs contrib/imgui_knobs
1414
link ../../contrib/imgui_toggle contrib/imgui_toggle
1515
link ../../contrib/tracy contrib/tracy
1616
link ../../contrib/sdl contrib/sdl3
17+
link ../../contrib/qoi contrib/qoi
1718
link ./contrib/imgui_toggle/imgui_toggle.cpp ./src/widgets/imgui_toggle/imgui_toggle.cpp
1819
link ./contrib/imgui_toggle/imgui_toggle_palette.cpp ./src/widgets/imgui_toggle/imgui_toggle_palette.cpp
1920
link ./contrib/imgui_toggle/imgui_toggle_presets.cpp ./src/widgets/imgui_toggle/imgui_toggle_presets.cpp

dhall/sourceTreeParts.dhall

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ let skiaVideo = \(asan : Bool) ->
578578
, imgui.dir
579579
, imguiImplot.dir
580580
, render.dir
581+
, "./contrib/qoi"
581582
]
582583
, global = [
583584
, "${contribDir}"

scripts/install_3rd_party_git_repos.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,5 @@ getContribRepo "https://github.com/google/flatbuffers.git" "flatbuffers" "master
5252
getContribRepo "https://github.com/google/skia" "skia" "chrome/m124" ""
5353
getContribRepo "https://github.com/wolfpld/tracy" "tracy" "master" "0d5bd53be393b590da9c7b29079d919d488412c1"
5454
getContribRepo "https://github.com/libsdl-org/SDL.git" "sdl" "main" "e049098733739664ffbeac6967568b2421a0cb2e"
55+
getContribRepo "https://github.com/phoboslab/qoi.git" "qoi" "master" "bf7b41c2ff3f24a2031193b62aa76d35e8842b5a"
5556
getMyRepo "https://github.com/stergiotis/boxer.git" "boxer" "main" ""

skia/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ SK_BUILD_FOR_UNIX)
134134
target_include_directories(skiaVideo PUBLIC "${CMAKE_CURRENT_LIST_DIR}/./skia"
135135
"${CMAKE_CURRENT_LIST_DIR}/./imgui"
136136
"${CMAKE_CURRENT_LIST_DIR}/./src/widgets/imgui_implot"
137-
"${CMAKE_CURRENT_LIST_DIR}/./src")
137+
"${CMAKE_CURRENT_LIST_DIR}/./src"
138+
"${CMAKE_CURRENT_LIST_DIR}/./contrib/qoi")
138139
add_library(skiaVideo_imported OBJECT IMPORTED)
139140
set_property(TARGET skiaVideo_imported PROPERTY IMPORTED_OBJECTS "${CMAKE_CURRENT_LIST_DIR}/./contrib/skia/out/Static/obj/../libskparagraph.a"
140141
"${CMAKE_CURRENT_LIST_DIR}/./contrib/skia/out/Static/obj/../libsvg.a"

skia/contrib/qoi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../common/contrib/qoi

skia/generate_links.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ link ../common/contrib/imgui_implot/implot_demo.cpp ./implot/implot_demo.cpp
2020
link ../common/contrib/imgui_ImGuiColorTextEdit/TextEditor.cpp ./imcolortextedit/TextEditor.cpp
2121
link ../common/contrib/imgui_ImGuiColorTextEdit/TextEditor.h ./imcolortextedit/TextEditor.h
2222
link ../common/contrib/sdl3 contrib/sdl3
23+
link ../common/contrib/qoi contrib/qoi

skia/skia/video/app.cpp

Lines changed: 75 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,7 @@
1414
#include "include/encode/SkWebpEncoder.h"
1515
#include "include/gpu/GrDirectContext.h"
1616
#include "include/gpu/gl/GrGLInterface.h"
17-
#if defined(__linux__)
18-
#include "include/gpu/gl/glx/GrGLMakeGLXInterface.h"
19-
#include <X11/Xlib.h>
20-
#include <GL/glx.h>
21-
#include <GL/gl.h>
22-
#endif
23-
24-
#include "gpu/ganesh/gl/GrGLDirectContext.h"
25-
#include "gpu/ganesh/SkSurfaceGanesh.h"
26-
#include "gpu/ganesh/gl/GrGLBackendSurface.h"
27-
#include "src/gpu/ganesh/gl/GrGLDefines.h"
28-
#include "src/gpu/ganesh/gl/GrGLUtil.h"
29-
//#include "SkBitmap.h"
17+
3018

3119
#include "tracy/Tracy.hpp"
3220

@@ -36,6 +24,22 @@
3624
#include "marshalling/receive.h"
3725
#include "marshalling/send.h"
3826

27+
#define QOI_IMPLEMENTATION
28+
#define QOI_NO_STDIO
29+
#define QOI_FREE static_assert(false && "free should never be called")
30+
#define QOI_MALLOC(sz) qoi_malloc(sz)
31+
static void *qoi_malloc(size_t sz) {
32+
static void *qoiBuffer = nullptr;
33+
static size_t lastSz = 0;
34+
if(qoiBuffer == nullptr) {
35+
lastSz = sz;
36+
qoiBuffer = malloc(sz);
37+
}
38+
assert(lastSz == sz && "assuming constant width, height and depth of qoi images");
39+
return qoiBuffer;
40+
}
41+
#include "qoi.h"
42+
3943
template <typename T>
4044
static inline void applyFlag(int &flag,T val,bool v) {
4145
if(v) {
@@ -342,41 +346,72 @@ int App::Run(CliOptions &opts) {
342346
options.fQuality = 70.0f;
343347
}
344348
auto stream = SkFILEWStream(opts.videoRawFramesFile);
349+
qoi_desc qd{
350+
static_cast<unsigned int>(w),
351+
static_cast<unsigned int>(h),
352+
4,
353+
QOI_SRGB
354+
};
355+
char pamHeader[4096];
356+
snprintf(pamHeader, sizeof(pamHeader), "P7\nWIDTH %d\nHEIGHT %d\nDEPTH 4\nMAXVAL 255\nTUPLTYPE RGB_ALPHA\nENDHDR\n", w, h);
357+
auto pamHeaderLen = strlen(pamHeader);
345358
while(!done) {
346359
ImGui::NewFrame();
347360

348361
ImGui::ShowMetricsWindow();
349362

350363
sk_sp<SkImage> img(rasterSurface->makeImageSnapshot(SkIRect::MakeWH(w,h)));
351-
if(true) {
352-
{ ZoneScoped;
353-
auto canvas = rasterSurface->getCanvas();
354-
canvas->clear(clearColor);
355-
Paint(rasterSurface.get(),w,h); // will call ImGui::Render();
356-
}
357-
{ ZoneScoped;
358-
SkPixmap pixmap;
359-
if(img->peekPixels(&pixmap)) {
360-
if (!SkWebpEncoder::Encode(static_cast<SkWStream *>(&stream), pixmap, options)) {
361-
fprintf(stderr,"unable to encode frame as image. Skipping.\n");
364+
{ ZoneScoped;
365+
auto canvas = rasterSurface->getCanvas();
366+
canvas->clear(clearColor);
367+
Paint(rasterSurface.get(),w,h); // will call ImGui::Render();
368+
}
369+
switch(1) {
370+
case 0:
371+
{ ZoneScoped;
372+
SkPixmap pixmap;
373+
if(img->peekPixels(&pixmap)) {
374+
if (!SkWebpEncoder::Encode(static_cast<SkWStream *>(&stream), pixmap, options)) {
375+
fprintf(stderr,"unable to encode frame as image. Skipping.\n");
376+
}
362377
}
363378
}
364-
}
365-
} else {
366-
Paint(nullptr,w,h); // will call ImGui::Render();
367-
368-
snprintf(pathBuffer,sizeof(pathBuffer),"/tmp/video/out_%09u.flatbuffers",frame);
369-
SkFILEWStream stream(pathBuffer);
370-
371-
const ImDrawData* drawData = ImGui::GetDrawData();
372-
fTotalVectorCmdSerializedSize = 0;
373-
for (int i = 0; i < drawData->CmdListsCount; ++i) {
374-
ImDrawList* drawList = drawData->CmdLists[i];
375-
const uint8_t *buf;
376-
size_t sz;
377-
drawList->serializeFB(buf,sz);
378-
stream.write(buf,sz);
379-
}
379+
break;
380+
case 1:
381+
{ ZoneScoped;
382+
SkPixmap pixmap;
383+
if (img->peekPixels(&pixmap)) {
384+
int imgLen;
385+
auto const imgMem = qoi_encode(pixmap.addr(), &qd, &imgLen);
386+
stream.write(imgMem, static_cast<size_t>(imgLen));
387+
stream.flush();
388+
}
389+
}
390+
break;
391+
case 2:
392+
{ ZoneScoped;
393+
SkPixmap pixmap;
394+
if (img->peekPixels(&pixmap)) {
395+
stream.write(pamHeader, pamHeaderLen);
396+
stream.write(pixmap.addr(),pixmap.computeByteSize());
397+
stream.flush();
398+
}
399+
}
400+
break;
401+
case 3:
402+
{ ZoneScoped;
403+
const ImDrawData* drawData = ImGui::GetDrawData();
404+
fTotalVectorCmdSerializedSize = 0;
405+
for (int i = 0; i < drawData->CmdListsCount; ++i) {
406+
ImDrawList* drawList = drawData->CmdLists[i];
407+
const uint8_t *buf;
408+
size_t sz;
409+
drawList->serializeFB(buf,sz);
410+
stream.write(buf,sz);
411+
}
412+
stream.flush();
413+
}
414+
break;
380415
}
381416

382417
{

skia/video.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pid=$!
6565
#-loglevel debug \
6666
ffmpeg -hide_banner \
6767
-re -fflags +genpts \
68-
-f image2pipe -i transferRawFrames \
68+
-f image2pipe -vcodec qoi -i transferRawFrames \
6969
-flags +global_header -r 30000/1001 \
7070
-an \
7171
-vaapi_device /dev/dri/renderD128 \

skia/video_null.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
rm -f transferRawFrames
3+
mkfifo transferRawFrames
4+
5+
resW=1920
6+
resH=1080
7+
8+
./imgui_skia_exe -fffiInterpreter off -ttfFilePath ./SauceCodeProNerdFontPropo-Regular.ttf -backdropFilter off -videoRawFramesFile transferRawFrames -videoResolutionWidth $resW -videoResolutionHeight $resH &
9+
pid=$!
10+
cat transferRawFrames | tee out.raw | \
11+
mpv --no-cache --untimed --no-demuxer-thread -
12+
#ffplay -hide_banner \
13+
# -threads 1 -filter_threads 1 \
14+
# -probesize 32 -sync ext \
15+
# -fpsprobesize 0 -framedrop -fast -infbuf \
16+
# -f nut -fflags '+nobuffer' -flags2 '+fast' -i "pipe:0" \
17+
# -vf "drawtext=text='%{localtime\:%S-%6N}':fontsize=144:box=1:boxcolor=black:fontcolor=red:y=(main_h/2)+text_h"
18+
19+
#mpv --no-cache --untimed --no-demuxer-thread --video-sync=audio \
20+
kill $pid

0 commit comments

Comments
 (0)