Skip to content

Commit b380beb

Browse files
authored
Add GREY pixelformat (#171)
Fixes #170 Monochrome cameras send only Y component of YUV image
1 parent 3a06a48 commit b380beb

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

src/libs/capture.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ static const struct {
6969
{"UYVY", V4L2_PIX_FMT_UYVY},
7070
{"YUV420", V4L2_PIX_FMT_YUV420},
7171
{"YVU420", V4L2_PIX_FMT_YVU420},
72+
{"GREY", V4L2_PIX_FMT_GREY},
7273
{"RGB565", V4L2_PIX_FMT_RGB565},
7374
{"RGB24", V4L2_PIX_FMT_RGB24},
7475
{"BGR24", V4L2_PIX_FMT_BGR24},

src/libs/frame.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ uint us_frame_get_padding(const us_frame_s *frame) {
8484
switch (frame->format) {
8585
case V4L2_PIX_FMT_YUV420:
8686
case V4L2_PIX_FMT_YVU420:
87+
case V4L2_PIX_FMT_GREY:
8788
bytes_per_pixel = 1;
8889
break;
8990

src/ustreamer/encoders/cpu/encoder.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ static void _jpeg_set_dest_frame(j_compress_ptr jpeg, us_frame_s *frame);
3939

4040
static void _jpeg_write_scanlines_yuv(struct jpeg_compress_struct *jpeg, const us_frame_s *frame);
4141
static void _jpeg_write_scanlines_yuv_planar(struct jpeg_compress_struct *jpeg, const us_frame_s *frame);
42+
static void _jpeg_write_scanlines_grey(struct jpeg_compress_struct *jpeg, const us_frame_s *frame);
4243
static void _jpeg_write_scanlines_rgb565(struct jpeg_compress_struct *jpeg, const us_frame_s *frame);
4344
static void _jpeg_write_scanlines_rgb24(struct jpeg_compress_struct *jpeg, const us_frame_s *frame);
4445
#ifndef JCS_EXTENSIONS
@@ -75,6 +76,10 @@ void us_cpu_encoder_compress(const us_frame_s *src, us_frame_s *dest, uint quali
7576
case V4L2_PIX_FMT_YVU420:
7677
jpeg.in_color_space = JCS_YCbCr;
7778
break;
79+
case V4L2_PIX_FMT_GREY:
80+
jpeg.input_components = 1;
81+
jpeg.in_color_space = JCS_GRAYSCALE;
82+
break;
7883
# ifdef JCS_EXTENSIONS
7984
case V4L2_PIX_FMT_BGR24:
8085
jpeg.in_color_space = JCS_EXT_BGR;
@@ -102,6 +107,10 @@ void us_cpu_encoder_compress(const us_frame_s *src, us_frame_s *dest, uint quali
102107
case V4L2_PIX_FMT_YVU420:
103108
_jpeg_write_scanlines_yuv_planar(&jpeg, src);
104109
break;
110+
111+
case V4L2_PIX_FMT_GREY:
112+
_jpeg_write_scanlines_grey(&jpeg, src);
113+
break;
105114

106115
case V4L2_PIX_FMT_RGB565:
107116
_jpeg_write_scanlines_rgb565(&jpeg, src);
@@ -249,6 +258,30 @@ static void _jpeg_write_scanlines_yuv_planar(struct jpeg_compress_struct *jpeg,
249258
free(line_buf);
250259
}
251260

261+
static void _jpeg_write_scanlines_grey(struct jpeg_compress_struct *jpeg, const us_frame_s *frame) {
262+
u8 *line_buf;
263+
US_CALLOC(line_buf, frame->width);
264+
265+
const uint padding = us_frame_get_padding(frame);
266+
const u8 *data = frame->data;
267+
268+
while (jpeg->next_scanline < frame->height) {
269+
u8 *ptr = line_buf;
270+
271+
for (uint x = 0; x < frame->width; ++x) {
272+
ptr[0] = data[x];
273+
ptr += 1;
274+
}
275+
276+
data += frame->width + padding;
277+
278+
JSAMPROW scanlines[1] = {line_buf};
279+
jpeg_write_scanlines(jpeg, scanlines, 1);
280+
}
281+
282+
free(line_buf);
283+
}
284+
252285
static void _jpeg_write_scanlines_rgb565(struct jpeg_compress_struct *jpeg, const us_frame_s *frame) {
253286
u8 *line_buf;
254287
US_CALLOC(line_buf, frame->width * 3);

0 commit comments

Comments
 (0)