52 avifImage avif_image = {0};
53 avifImage *avif = NULL;
55 .format = AVIF_RGB_FORMAT_RGB,
57 avifDecoder *decoder = NULL;
60 decoder = avifDecoderCreate();
68 result = avifDecoderReadFile(decoder, &avif_image, filename);
69 if(result != AVIF_RESULT_OK)
78 avifRGBImageSetDefaults(&
rgb, avif);
80 rgb.format = AVIF_RGB_FORMAT_RGB;
82 (
void)avifRGBImageAllocatePixels(&
rgb);
84 result = avifImageYUVToRGB(avif, &
rgb);
85 if(result != AVIF_RESULT_OK)
88 avifResultToString(result));
104 img->
dsc.
bpp = 4 *
sizeof(float);
107 img->
flags &= ~DT_IMAGE_RAW;
108 img->
flags &= ~DT_IMAGE_S_RAW;
114 img->
flags &= ~DT_IMAGE_LDR;
118 img->
flags &= ~DT_IMAGE_HDR;
142 const float max_channel_f = (float)((1 <<
bit_depth) - 1);
144 const size_t rowbytes =
rgb.rowBytes;
146 const uint8_t *
const restrict in = (
const uint8_t *)
rgb.pixels;
152 for (
size_t y = 0; y <
height; y++)
156 uint16_t *in_pixel = (uint16_t *)&in[(y * rowbytes) + (3 *
sizeof(uint16_t) *
x)];
157 float *out_pixel = &mipbuf[(size_t)4 * ((y *
width) +
x)];
160 out_pixel[0] = ((float)in_pixel[0]) * (1.0f / max_channel_f);
161 out_pixel[1] = ((float)in_pixel[1]) * (1.0f / max_channel_f);
162 out_pixel[2] = ((float)in_pixel[2]) * (1.0f / max_channel_f);
170 for (
size_t y = 0; y <
height; y++)
174 uint8_t *in_pixel = (uint8_t *)&in[(y * rowbytes) + (3 *
sizeof(uint8_t) *
x)];
175 float *out_pixel = &mipbuf[(size_t)4 * ((y *
width) +
x)];
178 out_pixel[0] = (float)(in_pixel[0]) * (1.0f / max_channel_f);
179 out_pixel[1] = (float)(in_pixel[1]) * (1.0f / max_channel_f);
180 out_pixel[2] = (float)(in_pixel[2]) * (1.0f / max_channel_f);
193 avifRWData *icc = &(avif->icc);
194 if(icc->size && icc->data)
196 img->
profile = (uint8_t *)g_malloc0(icc->size);
197 memcpy(img->
profile, icc->data, icc->size);
202 avifRGBImageFreePixels(&
rgb);
203 avifDecoderDestroy(decoder);
217 avifDecoder *decoder = NULL;
218 avifImage avif_image = {0};
221 decoder = avifDecoderCreate();
228 result = avifDecoderReadFile(decoder, &avif_image, filename);
229 if(result != AVIF_RESULT_OK)
235 if(avif_image.icc.size > 0)
237 avifRWData *icc = &avif_image.icc;
241 *
out = (uint8_t *)g_malloc0(icc->size);
242 memcpy(*
out, icc->data, icc->size);
252 if(avif_image.colorPrimaries == AVIF_COLOR_PRIMARIES_BT709)
254 gboolean over =
FALSE;
257 if(avif_image.transferCharacteristics == AVIF_TRANSFER_CHARACTERISTICS_BT470M
258 && avif_image.matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_BT709)
268 filename, avif_image.transferCharacteristics, avif_image.matrixCoefficients,
275 avifDecoderDestroy(decoder);