Skip to content

Commit ab0af73

Browse files
committed
Op_RRGGBBxx_HDR_to_YCbCr420: move chroma 4:2:0 sampling position to center (#521)
1 parent 2c8d963 commit ab0af73

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

libheif/heif_colorconversion.cc

+19
Original file line numberDiff line numberDiff line change
@@ -2786,6 +2786,25 @@ Op_RRGGBBxx_HDR_to_YCbCr420::convert_colorspace(const std::shared_ptr<const Heif
27862786
float g = static_cast<float>((in[2 + le] << 8) | in[3 - le]);
27872787
float b = static_cast<float>((in[4 + le] << 8) | in[5 - le]);
27882788

2789+
int dx = (x + 1 < width) ? bytesPerPixel : 0;
2790+
int dy = (y + 1 < height) ? in_p_stride : 0;
2791+
2792+
r += static_cast<float>((in[0 + le + dx] << 8) | in[1 - le + dx]);
2793+
g += static_cast<float>((in[2 + le + dx] << 8) | in[3 - le + dx]);
2794+
b += static_cast<float>((in[4 + le + dx] << 8) | in[5 - le + dx]);
2795+
2796+
r += static_cast<float>((in[0 + le + dy] << 8) | in[1 - le + dy]);
2797+
g += static_cast<float>((in[2 + le + dy] << 8) | in[3 - le + dy]);
2798+
b += static_cast<float>((in[4 + le + dy] << 8) | in[5 - le + dy]);
2799+
2800+
r += static_cast<float>((in[0 + le + dx + dy] << 8) | in[1 - le + dx + dy]);
2801+
g += static_cast<float>((in[2 + le + dx + dy] << 8) | in[3 - le + dx + dy]);
2802+
b += static_cast<float>((in[4 + le + dx + dy] << 8) | in[5 - le + dx + dy]);
2803+
2804+
r *= 0.25f;
2805+
g *= 0.25f;
2806+
b *= 0.25f;
2807+
27892808
float cb = r * coeffs.c[1][0] + g * coeffs.c[1][1] + b * coeffs.c[1][2];
27902809
float cr = r * coeffs.c[2][0] + g * coeffs.c[2][1] + b * coeffs.c[2][2];
27912810

0 commit comments

Comments
 (0)