28#ifndef KIMG_AVIF_DEFAULT_QUALITY
29#define KIMG_AVIF_DEFAULT_QUALITY 68
32#ifndef KIMG_AVIF_QUALITY_BEST
33#define KIMG_AVIF_QUALITY_BEST 90
36#ifndef KIMG_AVIF_QUALITY_HIGH
37#define KIMG_AVIF_QUALITY_HIGH 80
40#ifndef KIMG_AVIF_QUALITY_LOW
41#define KIMG_AVIF_QUALITY_LOW 51
44QAVIFHandler::QAVIFHandler()
45 : m_parseState(ParseAvifNotParsed)
46 , m_quality(KIMG_AVIF_DEFAULT_QUALITY)
47 , m_container_width(0)
48 , m_container_height(0)
49 , m_rawAvifData(AVIF_DATA_EMPTY)
51 , m_must_jump_to_next_image(false)
55QAVIFHandler::~QAVIFHandler()
58 avifDecoderDestroy(m_decoder);
62bool QAVIFHandler::canRead()
const
64 if (m_parseState == ParseAvifNotParsed && !canRead(device())) {
68 if (m_parseState != ParseAvifError) {
71 if (m_parseState == ParseAvifFinished) {
80bool QAVIFHandler::canRead(
QIODevice *device)
86 if (header.
size() < 12) {
91 input.
data =
reinterpret_cast<const uint8_t *
>(header.
constData());
92 input.size = header.
size();
94 if (avifPeekCompatibleFileType(&input)) {
100bool QAVIFHandler::ensureParsed()
const
102 if (m_parseState == ParseAvifSuccess || m_parseState == ParseAvifMetadata || m_parseState == ParseAvifFinished) {
105 if (m_parseState == ParseAvifError) {
109 QAVIFHandler *that =
const_cast<QAVIFHandler *
>(
this);
111 return that->ensureDecoder();
114bool QAVIFHandler::ensureOpened()
const
116 if (m_parseState == ParseAvifSuccess || m_parseState == ParseAvifFinished) {
119 if (m_parseState == ParseAvifError) {
123 QAVIFHandler *that =
const_cast<QAVIFHandler *
>(
this);
124 if (ensureParsed()) {
125 if (m_parseState == ParseAvifMetadata) {
126 bool success = that->jumpToNextImage();
127 that->m_parseState = success ? ParseAvifSuccess : ParseAvifError;
132 that->m_parseState = ParseAvifError;
136bool QAVIFHandler::ensureDecoder()
142 m_rawData = device()->
readAll();
144 m_rawAvifData.
data =
reinterpret_cast<const uint8_t *
>(m_rawData.constData());
145 m_rawAvifData.size = m_rawData.size();
147 if (avifPeekCompatibleFileType(&m_rawAvifData) == AVIF_FALSE) {
148 m_parseState = ParseAvifError;
152 m_decoder = avifDecoderCreate();
154 m_decoder->ignoreExif = AVIF_TRUE;
155 m_decoder->ignoreXMP = AVIF_TRUE;
157#if AVIF_VERSION >= 80400
161#if AVIF_VERSION >= 90100
162 m_decoder->strictFlags = AVIF_STRICT_DISABLED;
165#if AVIF_VERSION >= 110000
166 m_decoder->imageDimensionLimit = 65535;
169 avifResult decodeResult;
171 decodeResult = avifDecoderSetIOMemory(m_decoder, m_rawAvifData.data, m_rawAvifData.size);
172 if (decodeResult != AVIF_RESULT_OK) {
173 qWarning(
"ERROR: avifDecoderSetIOMemory failed: %s", avifResultToString(decodeResult));
175 avifDecoderDestroy(m_decoder);
177 m_parseState = ParseAvifError;
181 decodeResult = avifDecoderParse(m_decoder);
182 if (decodeResult != AVIF_RESULT_OK) {
183 qWarning(
"ERROR: Failed to parse input: %s", avifResultToString(decodeResult));
185 avifDecoderDestroy(m_decoder);
187 m_parseState = ParseAvifError;
191 m_container_width = m_decoder->image->width;
192 m_container_height = m_decoder->image->height;
194 if ((m_container_width > 65535) || (m_container_height > 65535)) {
195 qWarning(
"AVIF image (%dx%d) is too large!", m_container_width, m_container_height);
196 m_parseState = ParseAvifError;
200 if ((m_container_width == 0) || (m_container_height == 0)) {
201 qWarning(
"Empty image, nothing to decode");
202 m_parseState = ParseAvifError;
206 if (m_container_width > ((16384 * 16384) / m_container_height)) {
207 qWarning(
"AVIF image (%dx%d) has more than 256 megapixels!", m_container_width, m_container_height);
208 m_parseState = ParseAvifError;
213 int new_width = m_container_width;
214 int new_height = m_container_height;
216 if (m_decoder->image->transformFlags & AVIF_TRANSFORM_CLAP) {
217 if ((m_decoder->image->clap.widthD > 0) && (m_decoder->image->clap.heightD > 0) && (m_decoder->image->clap.horizOffD > 0)
218 && (m_decoder->image->clap.vertOffD > 0)) {
219 int crop_width = (int)((
double)(m_decoder->image->clap.widthN) / (m_decoder->image->clap.widthD) + 0.5);
220 if (crop_width < new_width && crop_width > 0) {
221 new_width = crop_width;
223 int crop_height = (int)((
double)(m_decoder->image->clap.heightN) / (m_decoder->image->clap.heightD) + 0.5);
224 if (crop_height < new_height && crop_height > 0) {
225 new_height = crop_height;
230 if (m_decoder->image->transformFlags & AVIF_TRANSFORM_IROT) {
231 if (m_decoder->image->irot.angle == 1 || m_decoder->image->irot.angle == 3) {
233 new_width = new_height;
238 m_estimated_dimensions.setWidth(new_width);
239 m_estimated_dimensions.setHeight(new_height);
241 m_parseState = ParseAvifMetadata;
245bool QAVIFHandler::decode_one_frame()
247 if (!ensureParsed()) {
253 if (m_decoder->image->alphaPlane) {
261 if (m_decoder->image->depth > 8) {
275 QImage result = imageAlloc(m_decoder->image->width, m_decoder->image->height, resultformat);
277 qWarning(
"Memory cannot be allocated");
282 if (m_decoder->image->icc.data && (m_decoder->image->icc.size > 0)) {
283 const QByteArray icc_data(
reinterpret_cast<const char *
>(m_decoder->image->icc.data), m_decoder->image->icc.size);
286 qWarning(
"AVIF image has Qt-unsupported or invalid ICC profile!");
289 float prim[8] = {0.64f, 0.33f, 0.3f, 0.6f, 0.15f, 0.06f, 0.3127f, 0.329f};
291 avifColorPrimariesGetValues(m_decoder->image->colorPrimaries, prim);
293 const QPointF redPoint(QAVIFHandler::CompatibleChromacity(prim[0], prim[1]));
294 const QPointF greenPoint(QAVIFHandler::CompatibleChromacity(prim[2], prim[3]));
295 const QPointF bluePoint(QAVIFHandler::CompatibleChromacity(prim[4], prim[5]));
296 const QPointF whitePoint(QAVIFHandler::CompatibleChromacity(prim[6], prim[7]));
299 float q_trc_gamma = 0.0f;
301 switch (m_decoder->image->transferCharacteristics) {
304 q_trc = QColorSpace::TransferFunction::Gamma;
309 q_trc = QColorSpace::TransferFunction::Gamma;
314 q_trc = QColorSpace::TransferFunction::Linear;
320 q_trc = QColorSpace::TransferFunction::SRgb;
323 qWarning(
"CICP colorPrimaries: %d, transferCharacteristics: %d\nThe colorspace is unsupported by this plug-in yet.",
324 m_decoder->image->colorPrimaries,
325 m_decoder->image->transferCharacteristics);
326 q_trc = QColorSpace::TransferFunction::SRgb;
330 if (q_trc != QColorSpace::TransferFunction::Custom) {
331 switch (m_decoder->image->colorPrimaries) {
336 colorspace =
QColorSpace(QColorSpace::Primaries::SRgb, q_trc, q_trc_gamma);
340 colorspace =
QColorSpace(QColorSpace::Primaries::DciP3D65, q_trc, q_trc_gamma);
343 colorspace =
QColorSpace(whitePoint, redPoint, greenPoint, bluePoint, q_trc, q_trc_gamma);
349 qWarning(
"AVIF plugin created invalid QColorSpace from NCLX/CICP!");
356 avifRGBImageSetDefaults(&rgb, m_decoder->image);
358#if AVIF_VERSION >= 1000000
359 rgb.maxThreads = m_decoder->maxThreads;
362 if (m_decoder->image->depth > 8) {
364 rgb.format = AVIF_RGB_FORMAT_RGBA;
366 if (!loadalpha && (m_decoder->image->yuvFormat == AVIF_PIXEL_FORMAT_YUV400)) {
371#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
372 rgb.format = AVIF_RGB_FORMAT_BGRA;
374 rgb.format = AVIF_RGB_FORMAT_ARGB;
377#if AVIF_VERSION >= 80400
378 if (m_decoder->imageCount > 1) {
380 rgb.chromaUpsampling = AVIF_CHROMA_UPSAMPLING_FASTEST;
384 if (!loadalpha && (m_decoder->image->yuvFormat == AVIF_PIXEL_FORMAT_YUV400)) {
390 rgb.pixels = result.
bits();
392 avifResult res = avifImageYUVToRGB(m_decoder->image, &rgb);
393 if (res != AVIF_RESULT_OK) {
394 qWarning(
"ERROR in avifImageYUVToRGB: %s", avifResultToString(res));
398 if (m_decoder->image->transformFlags & AVIF_TRANSFORM_CLAP) {
399 if ((m_decoder->image->clap.widthD > 0) && (m_decoder->image->clap.heightD > 0) && (m_decoder->image->clap.horizOffD > 0)
400 && (m_decoder->image->clap.vertOffD > 0)) {
401 int new_width = (int)((
double)(m_decoder->image->clap.widthN) / (m_decoder->image->clap.widthD) + 0.5);
402 if (new_width > result.
width()) {
403 new_width = result.
width();
406 int new_height = (int)((
double)(m_decoder->image->clap.heightN) / (m_decoder->image->clap.heightD) + 0.5);
407 if (new_height > result.
height()) {
408 new_height = result.
height();
411 if (new_width > 0 && new_height > 0) {
413 ((double)((int32_t)m_decoder->image->clap.horizOffN)) / (m_decoder->image->clap.horizOffD) + (result.
width() - new_width) / 2.0 + 0.5;
416 }
else if (offx > (result.
width() - new_width)) {
417 offx = result.
width() - new_width;
421 ((double)((int32_t)m_decoder->image->clap.vertOffN)) / (m_decoder->image->clap.vertOffD) + (result.
height() - new_height) / 2.0 + 0.5;
424 }
else if (offy > (result.
height() - new_height)) {
425 offy = result.
height() - new_height;
428 result = result.
copy(offx, offy, new_width, new_height);
433 qWarning(
"ERROR: Wrong values in avifCleanApertureBox");
437 if (m_decoder->image->transformFlags & AVIF_TRANSFORM_IROT) {
439 switch (m_decoder->image->irot.angle) {
455 if (m_decoder->image->transformFlags & AVIF_TRANSFORM_IMIR) {
456#if AVIF_VERSION > 90100 && AVIF_VERSION < 1000000
457 switch (m_decoder->image->imir.mode) {
459 switch (m_decoder->image->imir.axis) {
462 result = result.
mirrored(
false,
true);
465 result = result.
mirrored(
true,
false);
470 if (resultformat == result.
format()) {
471 m_current_image = result;
476 m_estimated_dimensions = m_current_image.size();
478 m_must_jump_to_next_image =
false;
482bool QAVIFHandler::read(
QImage *image)
484 if (!ensureOpened()) {
488 if (m_must_jump_to_next_image) {
492 *image = m_current_image;
493 if (imageCount() >= 2) {
494 m_must_jump_to_next_image =
true;
495 if (m_decoder->imageIndex >= m_decoder->imageCount - 1) {
497 m_parseState = ParseAvifFinished;
501 m_parseState = ParseAvifFinished;
506bool QAVIFHandler::write(
const QImage &image)
509 qWarning(
"No image data to save!");
514 if ((image.
width() > 65535) || (image.
height() > 65535)) {
515 qWarning(
"Image (%dx%d) is too large to save!", image.
width(), image.
height());
519 if (image.
width() > ((16384 * 16384) / image.
height())) {
520 qWarning(
"Image (%dx%d) will not be saved because it has more than 256 megapixels!", image.
width(), image.
height());
524 if ((image.
width() > 32768) || (image.
height() > 32768)) {
525 qWarning(
"Image (%dx%d) has a dimension above 32768 pixels, saved AVIF may not work in other software!", image.
width(), image.
height());
528 qWarning(
"Image has zero dimension!");
532 const char *encoder_name = avifCodecName(AVIF_CODEC_CHOICE_AUTO, AVIF_CODEC_FLAG_CAN_ENCODE);
534 qWarning(
"Cannot save AVIF images because libavif was built without AV1 encoders!");
538 bool lossless =
false;
539 if (m_quality >= 100) {
540 if (avifCodecName(AVIF_CODEC_CHOICE_AOM, AVIF_CODEC_FLAG_CAN_ENCODE)) {
543 qWarning(
"You are using %s encoder. It is recommended to enable libAOM encoder in libavif to use lossless compression.", encoder_name);
547 if (m_quality > 100) {
549 }
else if (m_quality < 0) {
550 m_quality = KIMG_AVIF_DEFAULT_QUALITY;
553#if AVIF_VERSION < 1000000
554 int maxQuantizer = AVIF_QUANTIZER_WORST_QUALITY * (100 - qBound(0, m_quality, 100)) / 100;
555 int minQuantizer = 0;
556 int maxQuantizerAlpha = 0;
564 avifImage *avif =
nullptr;
572 save_grayscale =
true;
578 save_grayscale =
false;
595 if (image.
depth() > 32) {
603#if AVIF_VERSION < 1000000
605 if (maxQuantizer > 20) {
606 minQuantizer = maxQuantizer - 20;
607 if (maxQuantizer > 40) {
608 maxQuantizerAlpha = maxQuantizer - 40;
614 if (save_depth > 8) {
621 avif = avifImageCreate(tmpgrayimage.
width(), tmpgrayimage.
height(), save_depth, AVIF_PIXEL_FORMAT_YUV400);
622#if AVIF_VERSION >= 110000
623 res = avifImageAllocatePlanes(avif, AVIF_PLANES_YUV);
624 if (res != AVIF_RESULT_OK) {
625 qWarning(
"ERROR in avifImageAllocatePlanes: %s", avifResultToString(res));
629 avifImageAllocatePlanes(avif, AVIF_PLANES_YUV);
633 avif->colorPrimaries = (avifColorPrimaries)1;
634 avif->matrixCoefficients = (avifMatrixCoefficients)1;
637 case QColorSpace::TransferFunction::Linear:
639 avif->transferCharacteristics = (avifTransferCharacteristics)8;
641 case QColorSpace::TransferFunction::SRgb:
643 avif->transferCharacteristics = (avifTransferCharacteristics)13;
651 if (save_depth > 8) {
652 for (
int y = 0; y < tmpgrayimage.
height(); y++) {
653 const uint16_t *src16bit =
reinterpret_cast<const uint16_t *
>(tmpgrayimage.
constScanLine(y));
654 uint16_t *dest16bit =
reinterpret_cast<uint16_t *
>(avif->yuvPlanes[0] + y * avif->yuvRowBytes[0]);
655 for (
int x = 0; x < tmpgrayimage.
width(); x++) {
656 int tmp_pixelval = (int)(((
float)(*src16bit) / 65535.0f) * 1023.0f + 0.5f);
657 *dest16bit = qBound(0, tmp_pixelval, 1023);
663 for (
int y = 0; y < tmpgrayimage.
height(); y++) {
665 uint8_t *dest8bit = avif->yuvPlanes[0] + y * avif->yuvRowBytes[0];
666 for (
int x = 0; x < tmpgrayimage.
width(); x++) {
667 *dest8bit = *src8bit;
675 if (save_depth > 8) {
691 avifPixelFormat pixel_format = AVIF_PIXEL_FORMAT_YUV420;
692 if (m_quality >= KIMG_AVIF_QUALITY_HIGH) {
693 if (m_quality >= KIMG_AVIF_QUALITY_BEST) {
694 pixel_format = AVIF_PIXEL_FORMAT_YUV444;
696 pixel_format = AVIF_PIXEL_FORMAT_YUV422;
700 avifMatrixCoefficients matrix_to_save = (avifMatrixCoefficients)1;
702 avifColorPrimaries primaries_to_save = (avifColorPrimaries)2;
703 avifTransferCharacteristics transfer_to_save = (avifTransferCharacteristics)2;
708 case QColorSpace::Primaries::SRgb:
710 primaries_to_save = (avifColorPrimaries)1;
712 matrix_to_save = (avifMatrixCoefficients)1;
714 case QColorSpace::Primaries::DciP3D65:
716 primaries_to_save = (avifColorPrimaries)12;
718 matrix_to_save = (avifMatrixCoefficients)12;
722 primaries_to_save = (avifColorPrimaries)2;
724 matrix_to_save = (avifMatrixCoefficients)2;
729 case QColorSpace::TransferFunction::Linear:
731 transfer_to_save = (avifTransferCharacteristics)8;
733 case QColorSpace::TransferFunction::Gamma:
736 transfer_to_save = (avifTransferCharacteristics)4;
739 transfer_to_save = (avifTransferCharacteristics)5;
742 transfer_to_save = (avifTransferCharacteristics)2;
745 case QColorSpace::TransferFunction::SRgb:
747 transfer_to_save = (avifTransferCharacteristics)13;
751 transfer_to_save = (avifTransferCharacteristics)2;
756 if ((primaries_to_save == 2) || (transfer_to_save == 2)) {
761 if (save_depth == 8) {
770 if ((primaries_to_save == 2) && (transfer_to_save != 2)) {
771 primaries_to_save = (avifColorPrimaries)1;
772 matrix_to_save = (avifMatrixCoefficients)1;
774 switch (transfer_to_save) {
786 transfer_to_save = (avifTransferCharacteristics)13;
789 }
else if ((primaries_to_save != 2) && (transfer_to_save == 2)) {
790 transfer_to_save = (avifTransferCharacteristics)13;
793 primaries_to_save = (avifColorPrimaries)1;
794 transfer_to_save = (avifTransferCharacteristics)13;
795 matrix_to_save = (avifMatrixCoefficients)1;
802 if (iccprofile.
size() > 0) {
803 matrix_to_save = (avifMatrixCoefficients)6;
807 if (lossless && pixel_format == AVIF_PIXEL_FORMAT_YUV444) {
808 matrix_to_save = (avifMatrixCoefficients)0;
810 avif = avifImageCreate(tmpcolorimage.
width(), tmpcolorimage.
height(), save_depth, pixel_format);
811 avif->matrixCoefficients = matrix_to_save;
813 avif->colorPrimaries = primaries_to_save;
814 avif->transferCharacteristics = transfer_to_save;
816 if (iccprofile.
size() > 0) {
817#if AVIF_VERSION >= 1000000
818 res = avifImageSetProfileICC(avif,
reinterpret_cast<const uint8_t *
>(iccprofile.
constData()), iccprofile.
size());
819 if (res != AVIF_RESULT_OK) {
820 qWarning(
"ERROR in avifImageSetProfileICC: %s", avifResultToString(res));
824 avifImageSetProfileICC(avif,
reinterpret_cast<const uint8_t *
>(iccprofile.
constData()), iccprofile.
size());
829 avifRGBImageSetDefaults(&rgb, avif);
831 rgb.pixels =
const_cast<uint8_t *
>(tmpcolorimage.
constBits());
833 if (save_depth > 8) {
837 rgb.ignoreAlpha = AVIF_TRUE;
840 rgb.format = AVIF_RGB_FORMAT_RGBA;
845 rgb.format = AVIF_RGB_FORMAT_RGBA;
847 rgb.format = AVIF_RGB_FORMAT_RGB;
851 res = avifImageRGBToYUV(avif, &rgb);
852 if (res != AVIF_RESULT_OK) {
853 qWarning(
"ERROR in avifImageRGBToYUV: %s", avifResultToString(res));
858 avifRWData raw = AVIF_DATA_EMPTY;
859 avifEncoder *encoder = avifEncoderCreate();
862#if AVIF_VERSION < 1000000
863 encoder->minQuantizer = minQuantizer;
864 encoder->maxQuantizer = maxQuantizer;
867 encoder->minQuantizerAlpha = AVIF_QUANTIZER_LOSSLESS;
868 encoder->maxQuantizerAlpha = maxQuantizerAlpha;
871 encoder->quality = m_quality;
874 if (m_quality >= KIMG_AVIF_QUALITY_LOW) {
875 encoder->qualityAlpha = 100;
877 encoder->qualityAlpha = 100 - (KIMG_AVIF_QUALITY_LOW - m_quality) / 2;
884 res = avifEncoderWrite(encoder, avif, &raw);
885 avifEncoderDestroy(encoder);
886 avifImageDestroy(avif);
888 if (res == AVIF_RESULT_OK) {
889 qint64
status = device()->
write(
reinterpret_cast<const char *
>(raw.data), raw.size);
890 avifRWDataFree(&raw);
894 }
else if (
status == -1) {
895 qWarning(
"Write error: %s", qUtf8Printable(device()->errorString()));
899 qWarning(
"ERROR: Failed to encode: %s", avifResultToString(res));
905QVariant QAVIFHandler::option(ImageOption option)
const
907 if (option == Quality) {
911 if (!supportsOption(option) || !ensureParsed()) {
917 return m_estimated_dimensions;
919 if (imageCount() >= 2) {
929void QAVIFHandler::setOption(ImageOption option,
const QVariant &value)
933 m_quality = value.
toInt();
934 if (m_quality > 100) {
936 }
else if (m_quality < 0) {
937 m_quality = KIMG_AVIF_DEFAULT_QUALITY;
946bool QAVIFHandler::supportsOption(ImageOption option)
const
948 return option == Quality || option == Size || option ==
Animation;
951int QAVIFHandler::imageCount()
const
953 if (!ensureParsed()) {
957 if (m_decoder->imageCount >= 1) {
958 return m_decoder->imageCount;
963int QAVIFHandler::currentImageNumber()
const
965 if (m_parseState == ParseAvifNotParsed) {
969 if (m_parseState == ParseAvifError || !m_decoder) {
973 if (m_parseState == ParseAvifMetadata) {
974 if (m_decoder->imageCount >= 2) {
981 return m_decoder->imageIndex;
984bool QAVIFHandler::jumpToNextImage()
986 if (!ensureParsed()) {
990 avifResult decodeResult;
992 if (m_decoder->imageIndex >= 0) {
993 if (m_decoder->imageCount < 2) {
994 m_parseState = ParseAvifSuccess;
998 if (m_decoder->imageIndex >= m_decoder->imageCount - 1) {
999 decodeResult = avifDecoderReset(m_decoder);
1000 if (decodeResult != AVIF_RESULT_OK) {
1001 qWarning(
"ERROR in avifDecoderReset: %s", avifResultToString(decodeResult));
1002 m_parseState = ParseAvifError;
1008 decodeResult = avifDecoderNextImage(m_decoder);
1010 if (decodeResult != AVIF_RESULT_OK) {
1011 qWarning(
"ERROR: Failed to decode Next image in sequence: %s", avifResultToString(decodeResult));
1012 m_parseState = ParseAvifError;
1016 if ((m_container_width != m_decoder->image->width) || (m_container_height != m_decoder->image->height)) {
1017 qWarning(
"Decoded image sequence size (%dx%d) do not match first image size (%dx%d)!",
1018 m_decoder->image->width,
1019 m_decoder->image->height,
1021 m_container_height);
1023 m_parseState = ParseAvifError;
1027 if (decode_one_frame()) {
1028 m_parseState = ParseAvifSuccess;
1031 m_parseState = ParseAvifError;
1036bool QAVIFHandler::jumpToImage(
int imageNumber)
1038 if (!ensureParsed()) {
1042 if (m_decoder->imageCount < 2) {
1043 if (imageNumber == 0) {
1044 if (ensureOpened()) {
1045 m_parseState = ParseAvifSuccess;
1052 if (imageNumber < 0 || imageNumber >= m_decoder->imageCount) {
1056 if (imageNumber == m_decoder->imageIndex) {
1057 m_must_jump_to_next_image =
false;
1058 m_parseState = ParseAvifSuccess;
1062 avifResult decodeResult = avifDecoderNthImage(m_decoder, imageNumber);
1064 if (decodeResult != AVIF_RESULT_OK) {
1065 qWarning(
"ERROR: Failed to decode %d th Image in sequence: %s", imageNumber, avifResultToString(decodeResult));
1066 m_parseState = ParseAvifError;
1070 if ((m_container_width != m_decoder->image->width) || (m_container_height != m_decoder->image->height)) {
1071 qWarning(
"Decoded image sequence size (%dx%d) do not match declared container size (%dx%d)!",
1072 m_decoder->image->width,
1073 m_decoder->image->height,
1075 m_container_height);
1077 m_parseState = ParseAvifError;
1081 if (decode_one_frame()) {
1082 m_parseState = ParseAvifSuccess;
1085 m_parseState = ParseAvifError;
1090int QAVIFHandler::nextImageDelay()
const
1092 if (!ensureOpened()) {
1096 if (m_decoder->imageCount < 2) {
1100 int delay_ms = 1000.0 * m_decoder->imageTiming.duration;
1107int QAVIFHandler::loopCount()
const
1109 if (!ensureParsed()) {
1113 if (m_decoder->imageCount < 2) {
1117#if AVIF_VERSION >= 1000000
1118 if (m_decoder->repetitionCount >= 0) {
1119 return m_decoder->repetitionCount;
1126QPointF QAVIFHandler::CompatibleChromacity(qreal chrX, qreal chrY)
1128 chrX = qBound(qreal(0.0), chrX, qreal(1.0));
1129 chrY = qBound(qreal(DBL_MIN), chrY, qreal(1.0));
1131 if ((chrX + chrY) > qreal(1.0)) {
1132 chrX = qreal(1.0) - chrY;
1140 static const bool isAvifDecoderAvailable(avifCodecName(AVIF_CODEC_CHOICE_AUTO, AVIF_CODEC_FLAG_CAN_DECODE) !=
nullptr);
1141 static const bool isAvifEncoderAvailable(avifCodecName(AVIF_CODEC_CHOICE_AUTO, AVIF_CODEC_FLAG_CAN_ENCODE) !=
nullptr);
1143 if (format ==
"avif") {
1145 if (isAvifDecoderAvailable) {
1146 format_cap |= CanRead;
1148 if (isAvifEncoderAvailable) {
1149 format_cap |= CanWrite;
1154 if (format ==
"avifs") {
1156 if (isAvifDecoderAvailable) {
1157 format_cap |= CanRead;
1170 if (device->
isReadable() && QAVIFHandler::canRead(device) && isAvifDecoderAvailable) {
1173 if (device->
isWritable() && isAvifEncoderAvailable) {
1187#include "moc_avif_p.cpp"
Q_SCRIPTABLE CaptureState status()
QFlags< Capability > Capabilities
const char * constData() const const
bool isEmpty() const const
qsizetype size() const const
QColorSpace fromIccProfile(const QByteArray &iccProfile)
float gamma() const const
QByteArray iccProfile() const const
bool isValid() const const
Primaries primaries() const const
TransferFunction transferFunction() const const
QColorSpace withTransferFunction(TransferFunction transferFunction, float gamma) const const
qsizetype bytesPerLine() const const
QColorSpace colorSpace() const const
const uchar * constBits() const const
const uchar * constScanLine(int i) const const
void convertTo(Format format, Qt::ImageConversionFlags flags)
void convertToColorSpace(const QColorSpace &colorSpace)
QImage copy(const QRect &rectangle) const const
bool hasAlphaChannel() const const
bool isGrayscale() const const
bool isNull() const const
QImage mirrored(bool horizontal, bool vertical) &&
void setColorSpace(const QColorSpace &colorSpace)
void setDevice(QIODevice *device)
virtual void setOption(ImageOption option, const QVariant &value)
bool isOpen() const const
bool isReadable() const const
bool isWritable() const const
QByteArray peek(qint64 maxSize)
qint64 write(const QByteArray &data)
int toInt(bool *ok) const const