@@ -393,7 +393,13 @@ gdImagePtr gdImageCreateFromAvifCtx (gdIOCtx *ctx)
393
393
// (While AVIF image pixel depth can be 8, 10, or 12 bits, GD truecolor images are 8-bit.)
394
394
avifRGBImageSetDefaults (& rgb , decoder -> image );
395
395
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
396
401
avifRGBImageAllocatePixels (& rgb );
402
+ #endif
397
403
398
404
result = avifImageYUVToRGB (decoder -> image , & rgb );
399
405
if (isAvifError (result , "Conversion from YUV to RGB failed" ))
@@ -522,14 +528,25 @@ void gdImageAvifCtx(gdImagePtr im, gdIOCtx *outfile, int quality, int speed)
522
528
// Note that MATRIX_COEFFICIENTS_IDENTITY enables lossless conversion from RGB to YUV.
523
529
524
530
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
526
537
avifIm -> colorPrimaries = AVIF_COLOR_PRIMARIES_BT709 ;
527
538
avifIm -> transferCharacteristics = AVIF_TRANSFER_CHARACTERISTICS_SRGB ;
528
539
avifIm -> matrixCoefficients = lossless ? AVIF_MATRIX_COEFFICIENTS_IDENTITY : AVIF_MATRIX_COEFFICIENTS_BT709 ;
529
540
530
541
avifRGBImageSetDefaults (& rgb , avifIm );
531
542
// 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
532
548
avifRGBImageAllocatePixels (& rgb );
549
+ #endif
533
550
534
551
// Parse RGB data from the GD image, and copy it into the AVIF RGB image.
535
552
// 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)
555
572
// Encode the image in AVIF format.
556
573
557
574
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
558
581
int quantizerQuality = quality == QUALITY_DEFAULT ?
559
582
QUANTIZER_DEFAULT : quality2Quantizer (quality );
560
583
0 commit comments