@@ -393,7 +393,13 @@ gdImagePtr gdImageCreateFromAvifCtx (gdIOCtx *ctx)
393393 // (While AVIF image pixel depth can be 8, 10, or 12 bits, GD truecolor images are 8-bit.)
394394 avifRGBImageSetDefaults (& rgb , decoder -> image );
395395 rgb .depth = 8 ;
396+ #if AVIF_VERSION >= 1000000
397+ result = avifRGBImageAllocatePixels (& rgb );
398+ if (isAvifError (result , "Allocating RGB pixels failed" ))
399+ goto cleanup ;
400+ #else
396401 avifRGBImageAllocatePixels (& rgb );
402+ #endif
397403
398404 result = avifImageYUVToRGB (decoder -> image , & rgb );
399405 if (isAvifError (result , "Conversion from YUV to RGB failed" ))
@@ -522,14 +528,25 @@ void gdImageAvifCtx(gdImagePtr im, gdIOCtx *outfile, int quality, int speed)
522528 // Note that MATRIX_COEFFICIENTS_IDENTITY enables lossless conversion from RGB to YUV.
523529
524530 avifImage * avifIm = avifImageCreate (gdImageSX (im ), gdImageSY (im ), 8 , subsampling );
525-
531+ #if AVIF_VERSION >= 1000000
532+ if (avifIm == NULL ) {
533+ gd_error ("avif error - Creating image failed\n" );
534+ goto cleanup ;
535+ }
536+ #endif
526537 avifIm -> colorPrimaries = AVIF_COLOR_PRIMARIES_BT709 ;
527538 avifIm -> transferCharacteristics = AVIF_TRANSFER_CHARACTERISTICS_SRGB ;
528539 avifIm -> matrixCoefficients = lossless ? AVIF_MATRIX_COEFFICIENTS_IDENTITY : AVIF_MATRIX_COEFFICIENTS_BT709 ;
529540
530541 avifRGBImageSetDefaults (& rgb , avifIm );
531542 // this allocates memory, and sets rgb.rowBytes and rgb.pixels.
543+ #if AVIF_VERSION >= 1000000
544+ result = avifRGBImageAllocatePixels (& rgb );
545+ if (isAvifError (result , "Allocating RGB pixels failed" ))
546+ goto cleanup ;
547+ #else
532548 avifRGBImageAllocatePixels (& rgb );
549+ #endif
533550
534551 // Parse RGB data from the GD image, and copy it into the AVIF RGB image.
535552 // Convert 7-bit GD alpha channel values to 8-bit AVIF values.
@@ -555,6 +572,12 @@ void gdImageAvifCtx(gdImagePtr im, gdIOCtx *outfile, int quality, int speed)
555572 // Encode the image in AVIF format.
556573
557574 encoder = avifEncoderCreate ();
575+ #if AVIF_VERSION >= 1000000
576+ if (encoder == NULL ) {
577+ gd_error ("avif error - Creating encoder failed\n" );
578+ goto cleanup ;
579+ }
580+ #endif
558581 int quantizerQuality = quality == QUALITY_DEFAULT ?
559582 QUANTIZER_DEFAULT : quality2Quantizer (quality );
560583
0 commit comments