Skip to content

Commit 539aeb7

Browse files
ensure subsequent avifEncoderAddImage call passes compatible image
1 parent 0ebc70f commit 539aeb7

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

include/avif/avif.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ typedef enum avifResult
147147
AVIF_RESULT_INVALID_ARGUMENT, // an argument passed into this function is invalid
148148
AVIF_RESULT_NOT_IMPLEMENTED, // a requested code path is not (yet) implemented
149149
AVIF_RESULT_OUT_OF_MEMORY,
150-
AVIF_RESULT_CANNOT_CHANGE_SETTING // a setting that can't change is changed during encoding
150+
AVIF_RESULT_CANNOT_CHANGE_SETTING, // a setting that can't change is changed during encoding
151+
AVIF_RESULT_INCOMPATIBLE_IMAGE // given image is not compatible with already encoded image
151152
} avifResult;
152153

153154
AVIF_API const char * avifResultToString(avifResult result);

src/avif.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ const char * avifResultToString(avifResult result)
9797
case AVIF_RESULT_NOT_IMPLEMENTED: return "Not implemented";
9898
case AVIF_RESULT_OUT_OF_MEMORY: return "Out of memory";
9999
case AVIF_RESULT_CANNOT_CHANGE_SETTING: return "Can not change some settings during encoding";
100+
case AVIF_RESULT_INCOMPATIBLE_IMAGE: return "This image is incompatible with already encoded image";
100101
case AVIF_RESULT_UNKNOWN_ERROR:
101102
default:
102103
break;

src/write.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -863,10 +863,23 @@ static avifResult avifEncoderAddImageInternal(avifEncoder * encoder,
863863
} else {
864864
// Another frame in an image sequence
865865

866-
if (encoder->data->alphaPresent && !firstCell->alphaPlane) {
867-
// If the first image in the sequence had an alpha plane (even if fully opaque), all
868-
// subsequence images must have alpha as well.
869-
return AVIF_RESULT_ENCODE_ALPHA_FAILED;
866+
const avifImage * imageMetadata = encoder->data->imageMetadata;
867+
// HEIF (ISO 23008-12:2017), Section 6.6.2.3.1:
868+
// All input images shall have exactly the same width and height; call those tile_width and tile_height.
869+
// MIAF (ISO 23000-22:2019), Section 7.3.11.4.1:
870+
// All input images of a grid image item shall use the same coding format, chroma sampling format, and the
871+
// same decoder configuration (see 7.3.6.2).
872+
// If the first image in the sequence had an alpha plane (even if fully opaque), all
873+
// subsequence images must have alpha as well.
874+
if ((imageMetadata->width != firstCell->width) || (imageMetadata->height != firstCell->height) ||
875+
(imageMetadata->depth != firstCell->depth) || (imageMetadata->yuvFormat != firstCell->yuvFormat) ||
876+
(imageMetadata->yuvRange != firstCell->yuvRange) || (imageMetadata->colorPrimaries != firstCell->colorPrimaries) ||
877+
(imageMetadata->transferCharacteristics != firstCell->transferCharacteristics) ||
878+
(imageMetadata->matrixCoefficients != firstCell->matrixCoefficients) ||
879+
(!!imageMetadata->alphaPlane != !!firstCell->alphaPlane) ||
880+
(imageMetadata->alphaPremultiplied != firstCell->alphaPremultiplied) ||
881+
(encoder->data->alphaPresent && !firstCell->alphaPlane)) {
882+
return AVIF_RESULT_INCOMPATIBLE_IMAGE;
870883
}
871884
}
872885

0 commit comments

Comments
 (0)