@@ -155,10 +155,8 @@ static avifBool avifPrepareReformatState(const avifImage * image, const avifRGBI
155155 state->rgbMaxChannelF = (float )state->rgbMaxChannel ;
156156 state->biasY = (state->yuvRange == AVIF_RANGE_LIMITED) ? (float )(16 << (state->yuvDepth - 8 )) : 0 .0f ;
157157 state->biasUV = (float )(1 << (state->yuvDepth - 1 ));
158- state->biasA = (image->alphaRange == AVIF_RANGE_LIMITED) ? (float )(16 << (state->yuvDepth - 8 )) : 0 .0f ;
159158 state->rangeY = (float )((state->yuvRange == AVIF_RANGE_LIMITED) ? (219 << (state->yuvDepth - 8 )) : state->yuvMaxChannel );
160159 state->rangeUV = (float )((state->yuvRange == AVIF_RANGE_LIMITED) ? (224 << (state->yuvDepth - 8 )) : state->yuvMaxChannel );
161- state->rangeA = (float )((image->alphaRange == AVIF_RANGE_LIMITED) ? (219 << (state->yuvDepth - 8 )) : state->yuvMaxChannel );
162160
163161 uint32_t cpCount = 1 << image->depth ;
164162 if (state->mode == AVIF_REFORMAT_MODE_IDENTITY) {
@@ -386,6 +384,7 @@ static CGImageRef CreateCGImage8(avifImage * avif) {
386384 uint8_t const permuteMap[4 ] = {0 , 1 , 2 , 3 };
387385 switch (avif->yuvFormat ) {
388386 case AVIF_PIXEL_FORMAT_NONE:
387+ case AVIF_PIXEL_FORMAT_COUNT:
389388 NSLog (@" Invalid pixel format." );
390389 goto end_all;
391390 case AVIF_PIXEL_FORMAT_YUV420:
@@ -567,51 +566,11 @@ static CGImageRef CreateCGImage8(avifImage * avif) {
567566
568567 if (hasAlpha) { // alpha
569568 vImage_Buffer alphaBuffer = {0 };
570- if (avif->alphaRange == AVIF_RANGE_LIMITED) {
571- float * floatAlphaBufferData = NULL ;
572- floatAlphaBufferData = calloc (avif->width * avif->height , sizeof (float ));
573- scaledAlphaBufferData = calloc (avif->width * avif->height , sizeof (uint8_t ));
574- if (floatAlphaBufferData == NULL || scaledAlphaBufferData == NULL ) {
575- err = kvImageMemoryAllocationError;
576- goto end_prepare_alpha;
577- }
578- vImage_Buffer origAlphaBuffer = {
579- .data = avif->alphaPlane ,
580- .width = avif->width ,
581- .height = avif->height ,
582- .rowBytes = avif->alphaRowBytes ,
583- };
584- vImage_Buffer floatAlphaBuffer = {
585- .data = floatAlphaBufferData,
586- .width = avif->width ,
587- .height = avif->height ,
588- .rowBytes = avif->width * sizeof (float ),
589- };
590- alphaBuffer.width = avif->width ;
591- alphaBuffer.height = avif->height ;
592- alphaBuffer.data = scaledAlphaBufferData;
593- alphaBuffer.rowBytes = avif->width * sizeof (uint8_t );
594- err = vImageConvert_Planar8toPlanarF (&origAlphaBuffer, &floatAlphaBuffer, 255 .0f , 0 .0f , kvImageNoFlags);
595- if (err != kvImageNoError) {
596- NSLog (@" Failed to convert alpha planes from uint8 to float: %ld " , err);
597- goto end_prepare_alpha;
598- }
599- err = vImageConvert_PlanarFtoPlanar8 (&floatAlphaBuffer, &alphaBuffer, 235 .0f , 16 .0f , kvImageNoFlags);
600- if (err != kvImageNoError) {
601- NSLog (@" Failed to convert alpha planes from float to uint8: %ld " , err);
602- goto end_prepare_alpha;
603- }
604- end_prepare_alpha:
605- free (floatAlphaBufferData);
606- if (err != kvImageNoError) {
607- goto end_alpha;
608- }
609- } else {
610- alphaBuffer.width = avif->width ;
611- alphaBuffer.height = avif->height ;
612- alphaBuffer.data = avif->alphaPlane ;
613- alphaBuffer.rowBytes = avif->alphaRowBytes ;
614- }
569+ // libavif 0.11.0: alphaRange field was removed from the avifImage struct. It it presumed that alpha plane is always full range.
570+ alphaBuffer.width = avif->width ;
571+ alphaBuffer.height = avif->height ;
572+ alphaBuffer.data = avif->alphaPlane ;
573+ alphaBuffer.rowBytes = avif->alphaRowBytes ;
615574 if (monochrome) { // alpha_mono
616575 uint8_t * tmpBufferData = NULL ;
617576 uint8_t * monoBufferData = NULL ;
@@ -861,22 +820,13 @@ static CGImageRef CreateCGImage16U(avifImage * avif) {
861820 };
862821 float offset = 0 .0f ;
863822 float rangeMax = 0 .0f ;
823+ // libavif 0.11.0: alphaRange field was removed from the avifImage struct. It it presumed that alpha plane is always full range.
864824 if (avif->depth == 10 ) {
865- if (avif->alphaRange == AVIF_RANGE_LIMITED) {
866- offset = 64 .0f ;
867- rangeMax = 940 .0f ;
868- } else {
869- offset = 0 .0f ;
870- rangeMax = 1023 .0f ;
871- }
825+ offset = 0 .0f ;
826+ rangeMax = 1023 .0f ;
872827 } else if (avif->depth == 12 ) {
873- if (avif->alphaRange == AVIF_RANGE_LIMITED) {
874- offset = 256 .0f ;
875- rangeMax = 3760 .0f ;
876- } else {
877- offset = 0 .0f ;
878- rangeMax = 4095 .0f ;
879- }
828+ offset = 0 .0f ;
829+ rangeMax = 4095 .0f ;
880830 }
881831 float const scale = (float )(rangeMax - offset) / 65535 .0f ;
882832 err = vImageConvert_16UToF (&origAlpha, &floatAlphaBuffer, 0 .0f , 1 .0f , kvImageNoFlags);
@@ -919,6 +869,7 @@ static CGImageRef CreateCGImage16U(avifImage * avif) {
919869 uint8_t const permuteMap[4 ] = {0 , 1 , 2 , 3 };
920870 switch (avif->yuvFormat ) {
921871 case AVIF_PIXEL_FORMAT_NONE:
872+ case AVIF_PIXEL_FORMAT_COUNT:
922873 NSLog (@" Invalid pixel format." );
923874 goto end_all;
924875 case AVIF_PIXEL_FORMAT_YUV420:
0 commit comments