@@ -618,8 +618,15 @@ static void image_format_yuv_packed(const struct image *input, struct image *out
o_c[2*x + u_offset] = idata[3*x + 1];
o_c[2*x + v_offset] = idata[3*x + 2];
} else {
- o_c[2*x + u_offset] = (idata[3*x + 1] + idata[3*x + 4]) / 2;
- o_c[2*x + v_offset] = (idata[3*x + 2] + idata[3*x + 5]) / 2;
+ unsigned int u = idata[3*x + 1] + idata[3*x + 4];
+ unsigned int v = idata[3*x + 2] + idata[3*x + 5];
+
+ /* Round towards the middle value. */
+ u += u < 0x100 ? 1 : 0;
+ v += v < 0x100 ? 1 : 0;
+
+ o_c[2*x + u_offset] = u / 2;
+ o_c[2*x + v_offset] = v / 2;
}
}
@@ -674,8 +681,15 @@ static void image_format_yuv_planar(const struct image *input, struct image *out
}
} else {
for (x = 0; x < output->width; x += xsub) {
- o_u[x*c_stride/xsub] = (idata[3*x + 1] + idata[3*x + 4]) / 2;
- o_v[x*c_stride/xsub] = (idata[3*x + 2] + idata[3*x + 5]) / 2;
+ unsigned int u = idata[3*x + 1] + idata[3*x + 4];
+ unsigned int v = idata[3*x + 2] + idata[3*x + 5];
+
+ /* Round towards the middle value. */
+ u += u < 0x100 ? 1 : 0;
+ v += v < 0x100 ? 1 : 0;
+
+ o_u[x*c_stride/xsub] = u / 2;
+ o_v[x*c_stride/xsub] = v / 2;
}
}
Based on tests, the VSP1 hardware seems to round averaged chroma values towards 0 when subsampling YUV formats. Replicate the same calculation in gen-image. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- src/gen-image.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-)