Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/reformat.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ avifResult avifImageRGBToYUV(avifImage * image, const avifRGBImage * rgb)

struct YUVBlock yuvBlock[2][2];
float rgbPixel[3];
const uint32_t rgbPixelBytes = state.rgb.pixelBytes;
const size_t rgbPixelBytes = state.rgb.pixelBytes;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vincent: This PR is no longer necessary now that pull request #3072 has been updated to declare the index variables i, j, uvI, uvJ as size_t. But I think it is still good to declare rgbPixelBytes and grayPixelBytes as size_t because the related *RowBytes variables are declared as size_t.

const uint32_t offsetBytesR = state.rgb.offsetBytesR;
const uint32_t offsetBytesG = state.rgb.offsetBytesG;
const uint32_t offsetBytesB = state.rgb.offsetBytesB;
Expand Down Expand Up @@ -387,13 +387,13 @@ avifResult avifImageRGBToYUV(avifImage * image, const avifRGBImage * rgb)
}

if (state.yuv.channelBytes > 1) {
uint16_t * pY = (uint16_t *)&yPlane[(i * 2) + (j * yRowBytes)];
uint16_t * pY = (uint16_t *)&yPlane[(i * sizeof(uint16_t)) + (j * yRowBytes)];
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, if you think changing 2 to sizeof(uint16_t) is too verbose, I can revert these changes.

*pY = (uint16_t)avifYUVColorSpaceInfoYToUNorm(&state.yuv, yuvBlock[bI][bJ].y);
if (image->yuvFormat == AVIF_PIXEL_FORMAT_YUV444) {
// YUV444, full chroma
uint16_t * pU = (uint16_t *)&uPlane[(i * 2) + (j * uRowBytes)];
uint16_t * pU = (uint16_t *)&uPlane[(i * sizeof(uint16_t)) + (j * uRowBytes)];
*pU = (uint16_t)avifYUVColorSpaceInfoUVToUNorm(&state.yuv, yuvBlock[bI][bJ].u);
uint16_t * pV = (uint16_t *)&vPlane[(i * 2) + (j * vRowBytes)];
uint16_t * pV = (uint16_t *)&vPlane[(i * sizeof(uint16_t)) + (j * vRowBytes)];
*pV = (uint16_t)avifYUVColorSpaceInfoUVToUNorm(&state.yuv, yuvBlock[bI][bJ].v);
}
} else {
Expand Down Expand Up @@ -430,9 +430,9 @@ avifResult avifImageRGBToYUV(avifImage * image, const avifRGBImage * rgb)
size_t uvI = outerI >> chromaShiftX;
size_t uvJ = outerJ >> chromaShiftY;
if (state.yuv.channelBytes > 1) {
uint16_t * pU = (uint16_t *)&uPlane[(uvI * 2) + (uvJ * uRowBytes)];
uint16_t * pU = (uint16_t *)&uPlane[(uvI * sizeof(uint16_t)) + (uvJ * uRowBytes)];
*pU = (uint16_t)avifYUVColorSpaceInfoUVToUNorm(&state.yuv, avgU);
uint16_t * pV = (uint16_t *)&vPlane[(uvI * 2) + (uvJ * vRowBytes)];
uint16_t * pV = (uint16_t *)&vPlane[(uvI * sizeof(uint16_t)) + (uvJ * vRowBytes)];
*pV = (uint16_t)avifYUVColorSpaceInfoUVToUNorm(&state.yuv, avgV);
} else {
uPlane[uvI + (uvJ * uRowBytes)] = (uint8_t)avifYUVColorSpaceInfoUVToUNorm(&state.yuv, avgU);
Expand All @@ -456,9 +456,9 @@ avifResult avifImageRGBToYUV(avifImage * image, const avifRGBImage * rgb)
size_t uvI = outerI >> chromaShiftX;
size_t uvJ = outerJ + bJ;
if (state.yuv.channelBytes > 1) {
uint16_t * pU = (uint16_t *)&uPlane[(uvI * 2) + (uvJ * uRowBytes)];
uint16_t * pU = (uint16_t *)&uPlane[(uvI * sizeof(uint16_t)) + (uvJ * uRowBytes)];
*pU = (uint16_t)avifYUVColorSpaceInfoUVToUNorm(&state.yuv, avgU);
uint16_t * pV = (uint16_t *)&vPlane[(uvI * 2) + (uvJ * vRowBytes)];
uint16_t * pV = (uint16_t *)&vPlane[(uvI * sizeof(uint16_t)) + (uvJ * vRowBytes)];
*pV = (uint16_t)avifYUVColorSpaceInfoUVToUNorm(&state.yuv, avgV);
} else {
uPlane[uvI + (uvJ * uRowBytes)] = (uint8_t)avifYUVColorSpaceInfoUVToUNorm(&state.yuv, avgU);
Expand All @@ -469,7 +469,7 @@ avifResult avifImageRGBToYUV(avifImage * image, const avifRGBImage * rgb)
}
}
} else if (!converted && isGray) {
const uint32_t grayPixelBytes = state.rgb.pixelBytes;
const size_t grayPixelBytes = state.rgb.pixelBytes;
const uint32_t offsetBytesGray = state.rgb.offsetBytesGray;
const uint32_t offsetBytesA = state.rgb.offsetBytesA;
const size_t grayRowBytes = rgb->rowBytes;
Expand Down Expand Up @@ -510,7 +510,7 @@ avifResult avifImageRGBToYUV(avifImage * image, const avifRGBImage * rgb)
}
int gInt = avifYUVColorSpaceInfoYToUNorm(&state.yuv, g);
if (state.yuv.channelBytes > 1) {
uint16_t * pY = (uint16_t *)&yPlane[(i * 2) + j * yRowBytes];
uint16_t * pY = (uint16_t *)&yPlane[(i * sizeof(uint16_t)) + j * yRowBytes];
*pY = (uint16_t)gInt;
} else {
yPlane[i + (j * yRowBytes)] = (uint8_t)gInt;
Expand Down
Loading