Fix signed/unsigned mismatch and loss-of-data conversion warnings for CL in new avif tests
This also switches all plane looping and formatInfo querying blocks in y4m code/tests to use
consistent types and variable naming for intermediate variables (plane, planeCount, formatInfo).
diff --git a/apps/shared/y4m.c b/apps/shared/y4m.c
index 4557bae..018f0e6 100644
--- a/apps/shared/y4m.c
+++ b/apps/shared/y4m.c
@@ -360,12 +360,13 @@
avifImageAllocatePlanes(avif, AVIF_PLANES_A);
}
- avifPixelFormatInfo info;
- avifGetPixelFormatInfo(avif->yuvFormat, &info);
+ avifPixelFormatInfo formatInfo;
+ avifGetPixelFormatInfo(avif->yuvFormat, &formatInfo);
- for (int plane = 0; plane < (info.monochrome ? 1 : AVIF_PLANE_COUNT_YUV); ++plane) {
- uint32_t planeWidth = (plane > 0) ? ((avif->width + info.chromaShiftX) >> info.chromaShiftX) : avif->width;
- uint32_t planeHeight = (plane > 0) ? ((avif->height + info.chromaShiftY) >> info.chromaShiftY) : avif->height;
+ const int planeCount = formatInfo.monochrome ? 1 : AVIF_PLANE_COUNT_YUV;
+ for (int plane = 0; plane < planeCount; ++plane) {
+ uint32_t planeWidth = (plane > 0) ? ((avif->width + formatInfo.chromaShiftX) >> formatInfo.chromaShiftX) : avif->width;
+ uint32_t planeHeight = (plane > 0) ? ((avif->height + formatInfo.chromaShiftY) >> formatInfo.chromaShiftY) : avif->height;
uint32_t rowBytes = planeWidth << (avif->depth > 8);
uint8_t * row = avif->yuvPlanes[plane];
for (uint32_t y = 0; y < planeHeight; ++y) {
@@ -512,8 +513,8 @@
rangeString = "XCOLORRANGE=LIMITED";
}
- avifPixelFormatInfo info;
- avifGetPixelFormatInfo(avif->yuvFormat, &info);
+ avifPixelFormatInfo formatInfo;
+ avifGetPixelFormatInfo(avif->yuvFormat, &formatInfo);
FILE * f = fopen(outputFilename, "wb");
if (!f) {
@@ -528,9 +529,10 @@
goto cleanup;
}
- for (int plane = 0; plane < (info.monochrome ? 1 : AVIF_PLANE_COUNT_YUV); ++plane) {
- uint32_t planeWidth = (plane > 0) ? ((avif->width + info.chromaShiftX) >> info.chromaShiftX) : avif->width;
- uint32_t planeHeight = (plane > 0) ? ((avif->height + info.chromaShiftY) >> info.chromaShiftY) : avif->height;
+ const int planeCount = formatInfo.monochrome ? 1 : AVIF_PLANE_COUNT_YUV;
+ for (int plane = 0; plane < planeCount; ++plane) {
+ uint32_t planeWidth = (plane > 0) ? ((avif->width + formatInfo.chromaShiftX) >> formatInfo.chromaShiftX) : avif->width;
+ uint32_t planeHeight = (plane > 0) ? ((avif->height + formatInfo.chromaShiftY) >> formatInfo.chromaShiftY) : avif->height;
uint32_t rowBytes = planeWidth << (avif->depth > 8);
const uint8_t * row = avif->yuvPlanes[plane];
for (uint32_t y = 0; y < planeHeight; ++y) {
diff --git a/tests/avifgridapitest.c b/tests/avifgridapitest.c
index 410c933..231f4a1 100644
--- a/tests/avifgridapitest.c
+++ b/tests/avifgridapitest.c
@@ -29,7 +29,8 @@
uint32_t uvWidth = ((*image)->width + formatInfo.chromaShiftX) >> formatInfo.chromaShiftX;
uint32_t uvHeight = ((*image)->height + formatInfo.chromaShiftY) >> formatInfo.chromaShiftY;
- for (uint32_t plane = 0; plane < (formatInfo.monochrome ? 1 : AVIF_PLANE_COUNT_YUV); ++plane) {
+ const int planeCount = formatInfo.monochrome ? 1 : AVIF_PLANE_COUNT_YUV;
+ for (int plane = 0; plane < planeCount; ++plane) {
const uint32_t widthByteCount = ((plane == AVIF_CHAN_Y) ? (*image)->width : uvWidth) * (((*image)->depth > 8) ? 2 : 1);
const uint32_t planeHeight = (plane == AVIF_CHAN_Y) ? (*image)->height : uvHeight;
uint8_t * row = (*image)->yuvPlanes[plane];
@@ -147,10 +148,11 @@
for (int i = 0; i < horizontalCombinationCount; ++i) {
for (int j = 0; j < verticalCombinationCount; ++j) {
if (!encodeDecode(/*columns=*/columnsCellWidths[i][0],
- /*rows=*/rowsCellHeights[j][0],
- /*cellWidth=*/columnsCellWidths[i][1],
- /*cellHeight=*/rowsCellHeights[j][1],
- yuvFormat, expected_success)) {
+ /*rows=*/rowsCellHeights[j][0],
+ /*cellWidth=*/columnsCellWidths[i][1],
+ /*cellHeight=*/rowsCellHeights[j][1],
+ yuvFormat,
+ expected_success)) {
return AVIF_FALSE;
}
}
diff --git a/tests/avify4mtest.c b/tests/avify4mtest.c
index 4211f14..d7af314 100644
--- a/tests/avify4mtest.c
+++ b/tests/avify4mtest.c
@@ -28,7 +28,8 @@
const uint32_t uvWidth = (image1->width + formatInfo.chromaShiftX) >> formatInfo.chromaShiftX;
const uint32_t uvHeight = (image1->height + formatInfo.chromaShiftY) >> formatInfo.chromaShiftY;
- for (uint32_t plane = 0; plane < (formatInfo.monochrome ? 1 : AVIF_PLANE_COUNT_YUV); ++plane) {
+ const int planeCount = formatInfo.monochrome ? 1 : AVIF_PLANE_COUNT_YUV;
+ for (int plane = 0; plane < planeCount; ++plane) {
const uint32_t widthByteCount =
((plane == AVIF_CHAN_Y) ? image1->width : uvWidth) * ((image1->depth > 8) ? sizeof(uint16_t) : sizeof(uint8_t));
const uint32_t height = (plane == AVIF_CHAN_Y) ? image1->height : uvHeight;
@@ -70,15 +71,16 @@
// Fills each plane of the image with the maximum allowed value.
static void fillPlanes(avifImage * image)
{
- const uint32_t yuvValue = (image->yuvRange == AVIF_RANGE_LIMITED) ? (235 << (image->depth - 8)) : ((1 << image->depth) - 1);
- avifPixelFormatInfo info;
- avifGetPixelFormatInfo(image->yuvFormat, &info);
- for (int plane = 0; plane < (info.monochrome ? 1 : AVIF_PLANE_COUNT_YUV); ++plane) {
+ const uint16_t yuvValue = (image->yuvRange == AVIF_RANGE_LIMITED) ? (235 << (image->depth - 8)) : ((1 << image->depth) - 1);
+ avifPixelFormatInfo formatInfo;
+ avifGetPixelFormatInfo(image->yuvFormat, &formatInfo);
+ const int planeCount = formatInfo.monochrome ? 1 : AVIF_PLANE_COUNT_YUV;
+ for (int plane = 0; plane < planeCount; ++plane) {
if (image->yuvPlanes[plane] != NULL) {
- const uint32_t planeWidth = (plane == AVIF_CHAN_Y) ? image->width
- : ((image->width + info.chromaShiftX) >> info.chromaShiftX);
- const uint32_t planeHeight = (plane == AVIF_CHAN_Y) ? image->height
- : ((image->height + info.chromaShiftY) >> info.chromaShiftY);
+ const uint32_t planeWidth =
+ (plane == AVIF_CHAN_Y) ? image->width : ((image->width + formatInfo.chromaShiftX) >> formatInfo.chromaShiftX);
+ const uint32_t planeHeight =
+ (plane == AVIF_CHAN_Y) ? image->height : ((image->height + formatInfo.chromaShiftY) >> formatInfo.chromaShiftY);
for (uint32_t y = 0; y < planeHeight; ++y) {
uint8_t * const row = image->yuvPlanes[plane] + y * image->yuvRowBytes[plane];
if (image->depth == 8) {
@@ -93,7 +95,7 @@
}
if (image->alphaPlane != NULL) {
assert(image->alphaRange == AVIF_RANGE_FULL);
- const uint32_t alphaValue = (1 << image->depth) - 1;
+ const uint16_t alphaValue = (1 << image->depth) - 1;
for (uint32_t y = 0; y < image->height; ++y) {
uint8_t * const row = image->alphaPlane + y * image->alphaRowBytes;
if (image->depth == 8) {