49 avifImage avif_image = {0};
50 avifImage *avif = NULL;
52 .format = AVIF_RGB_FORMAT_RGB,
54 avifDecoder *decoder = NULL;
57 decoder = avifDecoderCreate();
65 result = avifDecoderReadFile(decoder, &avif_image, filename);
66 if(result != AVIF_RESULT_OK)
75 avifRGBImageSetDefaults(&
rgb, avif);
77 rgb.format = AVIF_RGB_FORMAT_RGB;
79 (
void)avifRGBImageAllocatePixels(&
rgb);
81 result = avifImageYUVToRGB(avif, &
rgb);
82 if(result != AVIF_RESULT_OK)
85 avifResultToString(result));
101 img->
dsc.
bpp = 4 *
sizeof(float);
104 img->
flags &= ~DT_IMAGE_RAW;
105 img->
flags &= ~DT_IMAGE_S_RAW;
111 img->
flags &= ~DT_IMAGE_LDR;
115 img->
flags &= ~DT_IMAGE_HDR;
139 const float max_channel_f = (float)((1 <<
bit_depth) - 1);
141 const size_t rowbytes =
rgb.rowBytes;
143 const uint8_t *
const restrict in = (
const uint8_t *)
rgb.pixels;
149 for (
size_t y = 0; y <
height; y++)
153 uint16_t *in_pixel = (uint16_t *)&in[(y * rowbytes) + (3 *
sizeof(uint16_t) *
x)];
154 float *out_pixel = &mipbuf[(size_t)4 * ((y *
width) +
x)];
157 out_pixel[0] = ((float)in_pixel[0]) * (1.0f / max_channel_f);
158 out_pixel[1] = ((float)in_pixel[1]) * (1.0f / max_channel_f);
159 out_pixel[2] = ((float)in_pixel[2]) * (1.0f / max_channel_f);
167 for (
size_t y = 0; y <
height; y++)
171 uint8_t *in_pixel = (uint8_t *)&in[(y * rowbytes) + (3 *
sizeof(uint8_t) *
x)];
172 float *out_pixel = &mipbuf[(size_t)4 * ((y *
width) +
x)];
175 out_pixel[0] = (float)(in_pixel[0]) * (1.0f / max_channel_f);
176 out_pixel[1] = (float)(in_pixel[1]) * (1.0f / max_channel_f);
177 out_pixel[2] = (float)(in_pixel[2]) * (1.0f / max_channel_f);
190 avifRWData *icc = &(avif->icc);
191 if(icc->size && icc->data)
193 img->
profile = (uint8_t *)g_malloc0(icc->size);
194 memcpy(img->
profile, icc->data, icc->size);
199 avifRGBImageFreePixels(&
rgb);
200 avifDecoderDestroy(decoder);
214 avifDecoder *decoder = NULL;
215 avifImage avif_image = {0};
218 decoder = avifDecoderCreate();
225 result = avifDecoderReadFile(decoder, &avif_image, filename);
226 if(result != AVIF_RESULT_OK)
232 if(avif_image.icc.size > 0)
234 avifRWData *icc = &avif_image.icc;
238 *
out = (uint8_t *)g_malloc0(icc->size);
239 memcpy(*
out, icc->data, icc->size);
249 if(avif_image.colorPrimaries == AVIF_COLOR_PRIMARIES_BT709)
251 gboolean over =
FALSE;
254 if(avif_image.transferCharacteristics == AVIF_TRANSFER_CHARACTERISTICS_BT470M
255 && avif_image.matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_BT709)
265 filename, avif_image.transferCharacteristics, avif_image.matrixCoefficients,
272 avifDecoderDestroy(decoder);
void dt_print(dt_debug_thread_t thread, const char *msg,...) __attribute__((format(printf
Print to stdout when thread is enabled, prefixed with seconds since startup.