gen-image: Subsample YUV chroma on input
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Mon, 12 Sep 2016 21:36:59 +0000 (00:36 +0300)
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Mon, 12 Sep 2016 21:39:16 +0000 (00:39 +0300)
When the input format is YUV, subsample the chroma during RGB to YUV
conversion based on the YUV format parameters. This matches the RGB to
YUV conversion performed to generate the test input frame fed to the
RPF.

A better fix would be to add support for unpacking all RGB and YUV
formats instead of converting the .pnm reference frames.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
src/gen-image.c

index a389f77..15107d1 100644 (file)
@@ -715,6 +715,7 @@ static void colorspace_rgb2ycbcr(int m[3][3],
 
 static void image_colorspace_rgb_to_yuv(const struct image *input,
                                        struct image *output,
+                                       const struct format_info *format,
                                        const struct params *params)
 {
        int matrix[3][3];
@@ -727,10 +728,17 @@ static void image_colorspace_rgb_to_yuv(const struct image *input,
 
        for (y = 0; y < output->height; ++y) {
                for (x = 0; x < output->width; ++x) {
-                       colorspace_rgb2ycbcr(matrix, params->quantization, idata, odata);
-                       idata += 3;
-                       odata += 3;
+                       colorspace_rgb2ycbcr(matrix, params->quantization,
+                                            &idata[3*x], &odata[3*x]);
+               }
+               if (format->yuv.xsub == 2) {
+                       for (x = 1; x < output->width - 1; x += 2) {
+                               odata[3*x + 1] = (odata[3*(x-1) + 1] + odata[3*(x+1) + 1]) / 2;
+                               odata[3*x + 2] = (odata[3*(x-1) + 2] + odata[3*(x+1) + 2]) / 2;
+                       }
                }
+               idata += 3 * output->width;
+               odata += 3 * output->width;
        }
 }
 
@@ -1158,7 +1166,8 @@ static int process(const struct options *options)
                        goto done;
                }
 
-               image_colorspace_rgb_to_yuv(input, yuv, &options->params);
+               image_colorspace_rgb_to_yuv(input, yuv, options->input_format,
+                                           &options->params);
                image_delete(input);
                input = yuv;
        } else if (options->input_format->rgb.bpp < 24) {
@@ -1300,7 +1309,8 @@ static int process(const struct options *options)
                        goto done;
                }
 
-               image_colorspace_rgb_to_yuv(input, converted, &options->params);
+               image_colorspace_rgb_to_yuv(input, converted, format,
+                                           &options->params);
                image_delete(input);
                input = converted;
        }