@@ -39,6 +39,7 @@ static void _jpeg_set_dest_frame(j_compress_ptr jpeg, us_frame_s *frame);
39
39
40
40
static void _jpeg_write_scanlines_yuv (struct jpeg_compress_struct * jpeg , const us_frame_s * frame );
41
41
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 );
42
43
static void _jpeg_write_scanlines_rgb565 (struct jpeg_compress_struct * jpeg , const us_frame_s * frame );
43
44
static void _jpeg_write_scanlines_rgb24 (struct jpeg_compress_struct * jpeg , const us_frame_s * frame );
44
45
#ifndef JCS_EXTENSIONS
@@ -75,6 +76,10 @@ void us_cpu_encoder_compress(const us_frame_s *src, us_frame_s *dest, uint quali
75
76
case V4L2_PIX_FMT_YVU420 :
76
77
jpeg .in_color_space = JCS_YCbCr ;
77
78
break ;
79
+ case V4L2_PIX_FMT_GREY :
80
+ jpeg .input_components = 1 ;
81
+ jpeg .in_color_space = JCS_GRAYSCALE ;
82
+ break ;
78
83
# ifdef JCS_EXTENSIONS
79
84
case V4L2_PIX_FMT_BGR24 :
80
85
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
102
107
case V4L2_PIX_FMT_YVU420 :
103
108
_jpeg_write_scanlines_yuv_planar (& jpeg , src );
104
109
break ;
110
+
111
+ case V4L2_PIX_FMT_GREY :
112
+ _jpeg_write_scanlines_grey (& jpeg , src );
113
+ break ;
105
114
106
115
case V4L2_PIX_FMT_RGB565 :
107
116
_jpeg_write_scanlines_rgb565 (& jpeg , src );
@@ -249,6 +258,30 @@ static void _jpeg_write_scanlines_yuv_planar(struct jpeg_compress_struct *jpeg,
249
258
free (line_buf );
250
259
}
251
260
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
+
252
285
static void _jpeg_write_scanlines_rgb565 (struct jpeg_compress_struct * jpeg , const us_frame_s * frame ) {
253
286
u8 * line_buf ;
254
287
US_CALLOC (line_buf , frame -> width * 3 );
0 commit comments