feat: add test_image module, xorg viewer sink, and feature flag build system
Feature flags (FEATURES= make variable):
glfw — GLFW + OpenGL viewer (libglfw3, libglew)
vulkan — future Vulkan renderer
turbojpeg — MJPEG decode/encode (libturbojpeg)
xorg — XRandR geometry + screen grab (libx11, libxrandr)
vaapi — VA-API hardware codec (libva)
Each flag injects -DHAVE_<FEATURE> and the relevant pkg-config flags.
Headless build: make (no FEATURES set).
test_image module (src/modules/test_image/):
Generates test frames in YUV420, YUV422, and BGRA.
Patterns: SMPTE 75% colour bars, greyscale ramp, white/black grid.
BT.601 limited-range RGB→YCbCr in write_pixel().
test_image_cli (dev/cli/):
Generates a frame and writes it as a PPM file for visual verification.
Usage: test_image_cli [--pattern bars|ramp|grid]
[--width N] [--height N]
[--format yuv420|yuv422|bgra]
--out FILE.ppm
xorg module (src/modules/xorg/):
xorg.c — full GLFW+OpenGL implementation (compiled with FEATURES=glfw)
xorg_stub.c — no-op stub (compiled otherwise; xorg_available() returns false)
Renderer: full-screen quad via gl_VertexID, three GL_R8 textures for YUV,
BT.601 matrix in fragment shader, GL_BGRA texture for packed frames.
MJPEG path: tjDecompressToYUVPlanes → planar YUV → upload (requires turbojpeg).
push_yuv420/push_bgra/push_mjpeg all usable independently.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
ROOT := $(abspath ../..)
|
||||
include $(ROOT)/common.mk
|
||||
|
||||
CLI_BUILD = $(BUILD)/cli
|
||||
COMMON_OBJ = $(BUILD)/common/error.o
|
||||
MEDIA_CTRL_OBJ = $(BUILD)/media_ctrl/media_ctrl.o
|
||||
V4L2_CTRL_OBJ = $(BUILD)/v4l2_ctrl/v4l2_ctrl.o
|
||||
SERIAL_OBJ = $(BUILD)/serial/serial.o
|
||||
TRANSPORT_OBJ = $(BUILD)/transport/transport.o
|
||||
DISCOVERY_OBJ = $(BUILD)/discovery/discovery.o
|
||||
CONFIG_OBJ = $(BUILD)/config/config.o
|
||||
PROTOCOL_OBJ = $(BUILD)/protocol/protocol.o
|
||||
CLI_BUILD = $(BUILD)/cli
|
||||
COMMON_OBJ = $(BUILD)/common/error.o
|
||||
MEDIA_CTRL_OBJ = $(BUILD)/media_ctrl/media_ctrl.o
|
||||
V4L2_CTRL_OBJ = $(BUILD)/v4l2_ctrl/v4l2_ctrl.o
|
||||
SERIAL_OBJ = $(BUILD)/serial/serial.o
|
||||
TRANSPORT_OBJ = $(BUILD)/transport/transport.o
|
||||
DISCOVERY_OBJ = $(BUILD)/discovery/discovery.o
|
||||
CONFIG_OBJ = $(BUILD)/config/config.o
|
||||
PROTOCOL_OBJ = $(BUILD)/protocol/protocol.o
|
||||
TEST_IMAGE_OBJ = $(BUILD)/test_image/test_image.o
|
||||
|
||||
CLI_SRCS = \
|
||||
media_ctrl_cli.c \
|
||||
@@ -18,7 +19,8 @@ CLI_SRCS = \
|
||||
discovery_cli.c \
|
||||
config_cli.c \
|
||||
protocol_cli.c \
|
||||
query_cli.c
|
||||
query_cli.c \
|
||||
test_image_cli.c
|
||||
|
||||
CLI_OBJS = $(CLI_SRCS:%.c=$(CLI_BUILD)/%.o)
|
||||
|
||||
@@ -31,17 +33,19 @@ all: \
|
||||
$(CLI_BUILD)/discovery_cli \
|
||||
$(CLI_BUILD)/config_cli \
|
||||
$(CLI_BUILD)/protocol_cli \
|
||||
$(CLI_BUILD)/query_cli
|
||||
$(CLI_BUILD)/query_cli \
|
||||
$(CLI_BUILD)/test_image_cli
|
||||
|
||||
# Module objects delegate to their sub-makes.
|
||||
$(COMMON_OBJ): ; $(MAKE) -C $(ROOT)/src/modules/common
|
||||
$(MEDIA_CTRL_OBJ):; $(MAKE) -C $(ROOT)/src/modules/media_ctrl
|
||||
$(V4L2_CTRL_OBJ): ; $(MAKE) -C $(ROOT)/src/modules/v4l2_ctrl
|
||||
$(SERIAL_OBJ): ; $(MAKE) -C $(ROOT)/src/modules/serial
|
||||
$(TRANSPORT_OBJ): ; $(MAKE) -C $(ROOT)/src/modules/transport
|
||||
$(DISCOVERY_OBJ): ; $(MAKE) -C $(ROOT)/src/modules/discovery
|
||||
$(CONFIG_OBJ): ; $(MAKE) -C $(ROOT)/src/modules/config
|
||||
$(PROTOCOL_OBJ): ; $(MAKE) -C $(ROOT)/src/modules/protocol
|
||||
$(COMMON_OBJ): ; $(MAKE) -C $(ROOT)/src/modules/common
|
||||
$(MEDIA_CTRL_OBJ): ; $(MAKE) -C $(ROOT)/src/modules/media_ctrl
|
||||
$(V4L2_CTRL_OBJ): ; $(MAKE) -C $(ROOT)/src/modules/v4l2_ctrl
|
||||
$(SERIAL_OBJ): ; $(MAKE) -C $(ROOT)/src/modules/serial
|
||||
$(TRANSPORT_OBJ): ; $(MAKE) -C $(ROOT)/src/modules/transport
|
||||
$(DISCOVERY_OBJ): ; $(MAKE) -C $(ROOT)/src/modules/discovery
|
||||
$(CONFIG_OBJ): ; $(MAKE) -C $(ROOT)/src/modules/config
|
||||
$(PROTOCOL_OBJ): ; $(MAKE) -C $(ROOT)/src/modules/protocol
|
||||
$(TEST_IMAGE_OBJ): ; $(MAKE) -C $(ROOT)/src/modules/test_image
|
||||
|
||||
# Compile each CLI source to its own .o (generates .d alongside).
|
||||
$(CLI_BUILD)/%.o: %.c | $(CLI_BUILD)
|
||||
@@ -69,6 +73,9 @@ $(CLI_BUILD)/protocol_cli: $(CLI_BUILD)/protocol_cli.o $(COMMON_OBJ) $(SERIAL_OB
|
||||
$(CLI_BUILD)/query_cli: $(CLI_BUILD)/query_cli.o $(COMMON_OBJ) $(SERIAL_OBJ) $(TRANSPORT_OBJ) $(DISCOVERY_OBJ) $(PROTOCOL_OBJ)
|
||||
$(CC) $(CFLAGS) -o $@ $^ -lpthread
|
||||
|
||||
$(CLI_BUILD)/test_image_cli: $(CLI_BUILD)/test_image_cli.o $(TEST_IMAGE_OBJ)
|
||||
$(CC) $(CFLAGS) -o $@ $^
|
||||
|
||||
$(CLI_BUILD):
|
||||
mkdir -p $@
|
||||
|
||||
@@ -82,6 +89,7 @@ clean:
|
||||
$(CLI_BUILD)/discovery_cli \
|
||||
$(CLI_BUILD)/config_cli \
|
||||
$(CLI_BUILD)/protocol_cli \
|
||||
$(CLI_BUILD)/query_cli
|
||||
$(CLI_BUILD)/query_cli \
|
||||
$(CLI_BUILD)/test_image_cli
|
||||
|
||||
-include $(CLI_OBJS:%.o=%.d)
|
||||
|
||||
147
dev/cli/test_image_cli.c
Normal file
147
dev/cli/test_image_cli.c
Normal file
@@ -0,0 +1,147 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "test_image.h"
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* BT.601 limited-range YCbCr → RGB (for PPM output only) */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
static void ycbcr_to_rgb(uint8_t y, uint8_t cb, uint8_t cr,
|
||||
uint8_t *r, uint8_t *g, uint8_t *b)
|
||||
{
|
||||
int yy = (int)y - 16;
|
||||
int cb_ = (int)cb - 128;
|
||||
int cr_ = (int)cr - 128;
|
||||
int rv = (298 * yy + 409 * cr_ + 128) >> 8;
|
||||
int gv = (298 * yy - 100 * cb_ - 208 * cr_ + 128) >> 8;
|
||||
int bv = (298 * yy + 516 * cb_ + 128) >> 8;
|
||||
*r = (uint8_t)(rv < 0 ? 0 : rv > 255 ? 255 : rv);
|
||||
*g = (uint8_t)(gv < 0 ? 0 : gv > 255 ? 255 : gv);
|
||||
*b = (uint8_t)(bv < 0 ? 0 : bv > 255 ? 255 : bv);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* PPM output */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
static int write_ppm(const char *path, Test_Frame *f)
|
||||
{
|
||||
FILE *fp = fopen(path, "wb");
|
||||
if (!fp) { perror(path); return -1; }
|
||||
|
||||
fprintf(fp, "P6\n%d %d\n255\n", f->width, f->height);
|
||||
|
||||
for (int row = 0; row < f->height; row++) {
|
||||
for (int col = 0; col < f->width; col++) {
|
||||
uint8_t r, g, b;
|
||||
|
||||
if (f->fmt == TEST_FMT_BGRA) {
|
||||
const uint8_t *p = f->plane[0] + row * f->stride[0] + col * 4;
|
||||
b = p[0]; g = p[1]; r = p[2];
|
||||
} else {
|
||||
uint8_t luma = f->plane[0][row * f->stride[0] + col];
|
||||
uint8_t cb, cr;
|
||||
if (f->fmt == TEST_FMT_YUV420) {
|
||||
cb = f->plane[1][(row / 2) * f->stride[1] + col / 2];
|
||||
cr = f->plane[2][(row / 2) * f->stride[2] + col / 2];
|
||||
} else { /* YUV422 */
|
||||
cb = f->plane[1][row * f->stride[1] + col / 2];
|
||||
cr = f->plane[2][row * f->stride[2] + col / 2];
|
||||
}
|
||||
ycbcr_to_rgb(luma, cb, cr, &r, &g, &b);
|
||||
}
|
||||
|
||||
uint8_t pix[3] = {r, g, b};
|
||||
fwrite(pix, 1, 3, fp);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Main */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"usage: test_image_cli [--pattern bars|ramp|grid]\n"
|
||||
" [--width N] [--height N]\n"
|
||||
" [--format yuv420|yuv422|bgra]\n"
|
||||
" --out FILE.ppm\n"
|
||||
"\n"
|
||||
"defaults: bars 1280x720 yuv420\n");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
Test_Pattern pattern = TEST_PATTERN_BARS;
|
||||
Test_Fmt fmt = TEST_FMT_YUV420;
|
||||
int width = 1280;
|
||||
int height = 720;
|
||||
const char *out = NULL;
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (strcmp(argv[i], "--pattern") == 0 && i + 1 < argc) {
|
||||
i++;
|
||||
if (strcmp(argv[i], "bars") == 0) { pattern = TEST_PATTERN_BARS; }
|
||||
else if (strcmp(argv[i], "ramp") == 0) { pattern = TEST_PATTERN_RAMP; }
|
||||
else if (strcmp(argv[i], "grid") == 0) { pattern = TEST_PATTERN_GRID; }
|
||||
else {
|
||||
fprintf(stderr, "unknown pattern: %s\n", argv[i]);
|
||||
usage(); return 1;
|
||||
}
|
||||
} else if (strcmp(argv[i], "--width") == 0 && i + 1 < argc) {
|
||||
width = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "--height") == 0 && i + 1 < argc) {
|
||||
height = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "--format") == 0 && i + 1 < argc) {
|
||||
i++;
|
||||
if (strcmp(argv[i], "yuv420") == 0) { fmt = TEST_FMT_YUV420; }
|
||||
else if (strcmp(argv[i], "yuv422") == 0) { fmt = TEST_FMT_YUV422; }
|
||||
else if (strcmp(argv[i], "bgra") == 0) { fmt = TEST_FMT_BGRA; }
|
||||
else {
|
||||
fprintf(stderr, "unknown format: %s\n", argv[i]);
|
||||
usage(); return 1;
|
||||
}
|
||||
} else if (strcmp(argv[i], "--out") == 0 && i + 1 < argc) {
|
||||
out = argv[++i];
|
||||
} else {
|
||||
usage(); return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!out) {
|
||||
fprintf(stderr, "test_image_cli: --out FILE required\n");
|
||||
usage(); return 1;
|
||||
}
|
||||
if (width < 2 || height < 2) {
|
||||
fprintf(stderr, "test_image_cli: width and height must be >= 2\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
Test_Frame *f = test_image_alloc(width, height, fmt);
|
||||
if (!f) {
|
||||
fprintf(stderr, "test_image_cli: allocation failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
test_image_generate(f, pattern);
|
||||
|
||||
int rc = write_ppm(out, f);
|
||||
test_image_free(f);
|
||||
if (rc != 0) { return 1; }
|
||||
|
||||
const char *fmt_name = fmt == TEST_FMT_YUV420 ? "yuv420"
|
||||
: fmt == TEST_FMT_YUV422 ? "yuv422"
|
||||
: "bgra";
|
||||
const char *pat_name = pattern == TEST_PATTERN_BARS ? "bars"
|
||||
: pattern == TEST_PATTERN_RAMP ? "ramp"
|
||||
: "grid";
|
||||
|
||||
printf("%s: %dx%d format=%s pattern=%s\n", out, width, height, fmt_name, pat_name);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user