Move checks to avifAreGridDimensionsValid() (#834)
It was possible to encode a 65x65 4:2:0 image with avifenc that could
not be decoded with avifdec. Calling avifAreGridDimensionsValid() from
both encoding and decoding pipelines removes this asymmetric behavior.
Add tests/avifgridapitest.c.
diff --git a/src/write.c b/src/write.c
index 657bfaa..cd0a274 100644
--- a/src/write.c
+++ b/src/write.c
@@ -567,15 +567,28 @@
return AVIF_RESULT_NO_CONTENT;
}
- if ((cellCount > 1) && ((firstCell->width < 64) || (firstCell->height < 64))) {
+ if ((cellCount > 1) && !avifAreGridDimensionsValid(firstCell->yuvFormat,
+ gridCols * firstCell->width,
+ gridRows * firstCell->height,
+ firstCell->width,
+ firstCell->height,
+ &encoder->diag)) {
return AVIF_RESULT_INVALID_IMAGE_GRID;
}
for (uint32_t cellIndex = 0; cellIndex < cellCount; ++cellIndex) {
const avifImage * cellImage = cellImages[cellIndex];
- if ((cellImage->depth != firstCell->depth) || (cellImage->width != firstCell->width) ||
- (cellImage->height != firstCell->height) || (!!cellImage->alphaPlane != !!firstCell->alphaPlane) ||
- (cellImage->alphaPremultiplied != firstCell->alphaPremultiplied)) {
+ // HEIF (ISO 23008-12:2017), Section 6.6.2.3.1:
+ // All input images shall have exactly the same width and height; call those tile_width and tile_height.
+ // MIAF (ISO 23000-22:2019), Section 7.3.11.4.1:
+ // All input images of a grid image item shall use the same coding format, chroma sampling format, and the
+ // same decoder configuration (see 7.3.6.2).
+ if ((cellImage->width != firstCell->width) || (cellImage->height != firstCell->height) ||
+ (cellImage->depth != firstCell->depth) || (cellImage->yuvFormat != firstCell->yuvFormat) ||
+ (cellImage->yuvRange != firstCell->yuvRange) || (cellImage->colorPrimaries != firstCell->colorPrimaries) ||
+ (cellImage->transferCharacteristics != firstCell->transferCharacteristics) ||
+ (cellImage->matrixCoefficients != firstCell->matrixCoefficients) || (cellImage->alphaRange != firstCell->alphaRange) ||
+ (!!cellImage->alphaPlane != !!firstCell->alphaPlane) || (cellImage->alphaPremultiplied != firstCell->alphaPremultiplied)) {
return AVIF_RESULT_INVALID_IMAGE_GRID;
}