From f1da63ad838b0dc7aa2af2b802b597c25eef6079 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Sat, 23 Sep 2023 21:55:10 +0300
Subject: [PATCH] MSVC project: rebuilt libavif.dll from latest 1.0.1 release.
---
VisualC/SDL_image.vcxproj | 8 +-
VisualC/external/include/avif/avif.h | 291 +++++++++++++-----
.../x64/{libavif.dll => libavif-16.dll} | Bin 2232320 -> 2254336 bytes
.../x86/{libavif.dll => libavif-16.dll} | Bin 1515520 -> 1537024 bytes
4 files changed, 226 insertions(+), 73 deletions(-)
rename VisualC/external/optional/x64/{libavif.dll => libavif-16.dll} (73%)
rename VisualC/external/optional/x86/{libavif.dll => libavif-16.dll} (71%)
diff --git a/VisualC/SDL_image.vcxproj b/VisualC/SDL_image.vcxproj
index f12066bd..5ed188bf 100644
--- a/VisualC/SDL_image.vcxproj
+++ b/VisualC/SDL_image.vcxproj
@@ -108,7 +108,7 @@
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>$(ProjectDir)\..\include;external\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>DLL_EXPORT;_DEBUG;WIN32;_WINDOWS;USE_STBIMAGE;LOAD_AVIF;LOAD_AVIF_DYNAMIC="libavif.dll";LOAD_BMP;LOAD_GIF;LOAD_JPG;LOAD_LBM;LOAD_PCX;LOAD_PNG;LOAD_PNM;LOAD_QOI;LOAD_SVG;LOAD_TGA;LOAD_TIF;LOAD_TIF_DYNAMIC="libtiff-5.dll";LOAD_WEBP;LOAD_WEBP_DYNAMIC="libwebp-7.dll";LOAD_WEBPDEMUX_DYNAMIC="libwebpdemux-2.dll";LOAD_XCF;LOAD_XPM;LOAD_XV;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>DLL_EXPORT;_DEBUG;WIN32;_WINDOWS;USE_STBIMAGE;LOAD_AVIF;LOAD_AVIF_DYNAMIC="libavif-16.dll";LOAD_BMP;LOAD_GIF;LOAD_JPG;LOAD_LBM;LOAD_PCX;LOAD_PNG;LOAD_PNM;LOAD_QOI;LOAD_SVG;LOAD_TGA;LOAD_TIF;LOAD_TIF_DYNAMIC="libtiff-5.dll";LOAD_WEBP;LOAD_WEBP_DYNAMIC="libwebp-7.dll";LOAD_WEBPDEMUX_DYNAMIC="libwebpdemux-2.dll";LOAD_XCF;LOAD_XPM;LOAD_XV;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>OldStyle</DebugInformationFormat>
@@ -136,7 +136,7 @@
</Midl>
<ClCompile>
<AdditionalIncludeDirectories>$(ProjectDir)\..\include;external\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>DLL_EXPORT;_DEBUG;WIN32;_WINDOWS;USE_STBIMAGE;LOAD_AVIF;LOAD_AVIF_DYNAMIC="libavif.dll";LOAD_BMP;LOAD_GIF;LOAD_JPG;LOAD_LBM;LOAD_PCX;LOAD_PNG;LOAD_PNM;LOAD_QOI;LOAD_SVG;LOAD_TGA;LOAD_TIF;LOAD_TIF_DYNAMIC="libtiff-5.dll";LOAD_WEBP;LOAD_WEBP_DYNAMIC="libwebp-7.dll";LOAD_WEBPDEMUX_DYNAMIC="libwebpdemux-2.dll";LOAD_XCF;LOAD_XPM;LOAD_XV;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>DLL_EXPORT;_DEBUG;WIN32;_WINDOWS;USE_STBIMAGE;LOAD_AVIF;LOAD_AVIF_DYNAMIC="libavif-16.dll";LOAD_BMP;LOAD_GIF;LOAD_JPG;LOAD_LBM;LOAD_PCX;LOAD_PNG;LOAD_PNM;LOAD_QOI;LOAD_SVG;LOAD_TGA;LOAD_TIF;LOAD_TIF_DYNAMIC="libtiff-5.dll";LOAD_WEBP;LOAD_WEBP_DYNAMIC="libwebp-7.dll";LOAD_WEBPDEMUX_DYNAMIC="libwebpdemux-2.dll";LOAD_XCF;LOAD_XPM;LOAD_XV;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
@@ -165,7 +165,7 @@
</Midl>
<ClCompile>
<AdditionalIncludeDirectories>$(ProjectDir)\..\include;external\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>DLL_EXPORT;NDEBUG;WIN32;_WINDOWS;USE_STBIMAGE;LOAD_AVIF;LOAD_AVIF_DYNAMIC="libavif.dll";LOAD_BMP;LOAD_GIF;LOAD_JPG;LOAD_LBM;LOAD_PCX;LOAD_PNG;LOAD_PNM;LOAD_QOI;LOAD_SVG;LOAD_TGA;LOAD_TIF;LOAD_TIF_DYNAMIC="libtiff-5.dll";LOAD_WEBP;LOAD_WEBP_DYNAMIC="libwebp-7.dll";LOAD_WEBPDEMUX_DYNAMIC="libwebpdemux-2.dll";LOAD_XCF;LOAD_XPM;LOAD_XV;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>DLL_EXPORT;NDEBUG;WIN32;_WINDOWS;USE_STBIMAGE;LOAD_AVIF;LOAD_AVIF_DYNAMIC="libavif-16.dll";LOAD_BMP;LOAD_GIF;LOAD_JPG;LOAD_LBM;LOAD_PCX;LOAD_PNG;LOAD_PNM;LOAD_QOI;LOAD_SVG;LOAD_TGA;LOAD_TIF;LOAD_TIF_DYNAMIC="libtiff-5.dll";LOAD_WEBP;LOAD_WEBP_DYNAMIC="libwebp-7.dll";LOAD_WEBPDEMUX_DYNAMIC="libwebpdemux-2.dll";LOAD_XCF;LOAD_XPM;LOAD_XV;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions</EnableEnhancedInstructionSet>
@@ -191,7 +191,7 @@
</Midl>
<ClCompile>
<AdditionalIncludeDirectories>$(ProjectDir)\..\include;external\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>DLL_EXPORT;NDEBUG;WIN32;_WINDOWS;USE_STBIMAGE;LOAD_AVIF;LOAD_AVIF_DYNAMIC="libavif.dll";LOAD_BMP;LOAD_GIF;LOAD_JPG;LOAD_LBM;LOAD_PCX;LOAD_PNG;LOAD_PNM;LOAD_QOI;LOAD_SVG;LOAD_TGA;LOAD_TIF;LOAD_TIF_DYNAMIC="libtiff-5.dll";LOAD_WEBP;LOAD_WEBP_DYNAMIC="libwebp-7.dll";LOAD_WEBPDEMUX_DYNAMIC="libwebpdemux-2.dll";LOAD_XCF;LOAD_XPM;LOAD_XV;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>DLL_EXPORT;NDEBUG;WIN32;_WINDOWS;USE_STBIMAGE;LOAD_AVIF;LOAD_AVIF_DYNAMIC="libavif-16.dll";LOAD_BMP;LOAD_GIF;LOAD_JPG;LOAD_LBM;LOAD_PCX;LOAD_PNG;LOAD_PNM;LOAD_QOI;LOAD_SVG;LOAD_TGA;LOAD_TIF;LOAD_TIF_DYNAMIC="libtiff-5.dll";LOAD_WEBP;LOAD_WEBP_DYNAMIC="libwebp-7.dll";LOAD_WEBPDEMUX_DYNAMIC="libwebpdemux-2.dll";LOAD_XCF;LOAD_XPM;LOAD_XV;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions</EnableEnhancedInstructionSet>
diff --git a/VisualC/external/include/avif/avif.h b/VisualC/external/include/avif/avif.h
index 60641bcb..04a7bdbf 100644
--- a/VisualC/external/include/avif/avif.h
+++ b/VisualC/external/include/avif/avif.h
@@ -55,8 +55,8 @@ extern "C" {
// and non-zero during development of the next release. This should allow for
// downstream projects to do greater-than preprocessor checks on AVIF_VERSION
// to leverage in-development code without breaking their stable builds.
-#define AVIF_VERSION_MAJOR 0
-#define AVIF_VERSION_MINOR 11
+#define AVIF_VERSION_MAJOR 1
+#define AVIF_VERSION_MINOR 0
#define AVIF_VERSION_PATCH 1
#define AVIF_VERSION_DEVEL 0
#define AVIF_VERSION \
@@ -78,6 +78,11 @@ typedef int avifBool;
// a 12 hour AVIF image sequence, running at 60 fps (a basic sanity check as this is quite ridiculous)
#define AVIF_DEFAULT_IMAGE_COUNT_LIMIT (12 * 3600 * 60)
+#define AVIF_QUALITY_DEFAULT -1
+#define AVIF_QUALITY_LOSSLESS 100
+#define AVIF_QUALITY_WORST 0
+#define AVIF_QUALITY_BEST 100
+
#define AVIF_QUANTIZER_LOSSLESS 0
#define AVIF_QUANTIZER_BEST_QUALITY 0
#define AVIF_QUANTIZER_WORST_QUALITY 63
@@ -88,6 +93,15 @@ typedef int avifBool;
#define AVIF_SPEED_SLOWEST 0
#define AVIF_SPEED_FASTEST 10
+// This value is used to indicate that an animated AVIF file has to be repeated infinitely.
+#define AVIF_REPETITION_COUNT_INFINITE -1
+// This value is used if an animated AVIF file does not have repetitions specified using an EditList box. Applications can choose
+// to handle this case however they want.
+#define AVIF_REPETITION_COUNT_UNKNOWN -2
+
+// The number of spatial layers in AV1, with spatial_id = 0..3.
+#define AVIF_MAX_AV1_LAYER_COUNT 4
+
typedef enum avifPlanesFlag
{
AVIF_PLANES_YUV = (1 << 0),
@@ -102,7 +116,10 @@ typedef enum avifChannelIndex
// These can be used as the index for the yuvPlanes and yuvRowBytes arrays in avifImage.
AVIF_CHAN_Y = 0,
AVIF_CHAN_U = 1,
- AVIF_CHAN_V = 2
+ AVIF_CHAN_V = 2,
+
+ // This may not be used in yuvPlanes and yuvRowBytes, but is available for use with avifImagePlane().
+ AVIF_CHAN_A = 3
} avifChannelIndex;
// ---------------------------------------------------------------------------
@@ -115,6 +132,9 @@ AVIF_API unsigned int avifLibYUVVersion(void); // returns 0 if libavif wasn't co
// ---------------------------------------------------------------------------
// Memory management
+// NOTE: On memory allocation failure, the current implementation of avifAlloc() calls abort(),
+// but in a future release it may return NULL. To be future-proof, callers should check for a NULL
+// return value.
AVIF_API void * avifAlloc(size_t size);
AVIF_API void avifFree(void * p);
@@ -124,34 +144,37 @@ AVIF_API void avifFree(void * p);
typedef enum avifResult
{
AVIF_RESULT_OK = 0,
- AVIF_RESULT_UNKNOWN_ERROR,
- AVIF_RESULT_INVALID_FTYP,
- AVIF_RESULT_NO_CONTENT,
- AVIF_RESULT_NO_YUV_FORMAT_SELECTED,
- AVIF_RESULT_REFORMAT_FAILED,
- AVIF_RESULT_UNSUPPORTED_DEPTH,
- AVIF_RESULT_ENCODE_COLOR_FAILED,
- AVIF_RESULT_ENCODE_ALPHA_FAILED,
- AVIF_RESULT_BMFF_PARSE_FAILED,
- AVIF_RESULT_NO_AV1_ITEMS_FOUND,
- AVIF_RESULT_DECODE_COLOR_FAILED,
- AVIF_RESULT_DECODE_ALPHA_FAILED,
- AVIF_RESULT_COLOR_ALPHA_SIZE_MISMATCH,
- AVIF_RESULT_ISPE_SIZE_MISMATCH,
- AVIF_RESULT_NO_CODEC_AVAILABLE,
- AVIF_RESULT_NO_IMAGES_REMAINING,
- AVIF_RESULT_INVALID_EXIF_PAYLOAD,
- AVIF_RESULT_INVALID_IMAGE_GRID,
- AVIF_RESULT_INVALID_CODEC_SPECIFIC_OPTION,
- AVIF_RESULT_TRUNCATED_DATA,
- AVIF_RESULT_IO_NOT_SET, // the avifIO field of avifDecoder is not set
- AVIF_RESULT_IO_ERROR,
- AVIF_RESULT_WAITING_ON_IO, // similar to EAGAIN/EWOULDBLOCK, this means the avifIO doesn't have necessary data available yet
- AVIF_RESULT_INVALID_ARGUMENT, // an argument passed into this function is invalid
- AVIF_RESULT_NOT_IMPLEMENTED, // a requested code path is not (yet) implemented
- AVIF_RESULT_OUT_OF_MEMORY,
- AVIF_RESULT_CANNOT_CHANGE_SETTING, // a setting that can't change is changed during encoding
- AVIF_RESULT_INCOMPATIBLE_IMAGE // the image is incompatible with already encoded images
+ AVIF_RESULT_UNKNOWN_ERROR = 1,
+ AVIF_RESULT_INVALID_FTYP = 2,
+ AVIF_RESULT_NO_CONTENT = 3,
+ AVIF_RESULT_NO_YUV_FORMAT_SELECTED = 4,
+ AVIF_RESULT_REFORMAT_FAILED = 5,
+ AVIF_RESULT_UNSUPPORTED_DEPTH = 6,
+ AVIF_RESULT_ENCODE_COLOR_FAILED = 7,
+ AVIF_RESULT_ENCODE_ALPHA_FAILED = 8,
+ AVIF_RESULT_BMFF_PARSE_FAILED = 9,
+ AVIF_RESULT_MISSING_IMAGE_ITEM = 10,
+ AVIF_RESULT_DECODE_COLOR_FAILED = 11,
+ AVIF_RESULT_DECODE_ALPHA_FAILED = 12,
+ AVIF_RESULT_COLOR_ALPHA_SIZE_MISMATCH = 13,
+ AVIF_RESULT_ISPE_SIZE_MISMATCH = 14,
+ AVIF_RESULT_NO_CODEC_AVAILABLE = 15,
+ AVIF_RESULT_NO_IMAGES_REMAINING = 16,
+ AVIF_RESULT_INVALID_EXIF_PAYLOAD = 17,
+ AVIF_RESULT_INVALID_IMAGE_GRID = 18,
+ AVIF_RESULT_INVALID_CODEC_SPECIFIC_OPTION = 19,
+ AVIF_RESULT_TRUNCATED_DATA = 20,
+ AVIF_RESULT_IO_NOT_SET = 21, // the avifIO field of avifDecoder is not set
+ AVIF_RESULT_IO_ERROR = 22,
+ AVIF_RESULT_WAITING_ON_IO = 23, // similar to EAGAIN/EWOULDBLOCK, this means the avifIO doesn't have necessary data available yet
+ AVIF_RESULT_INVALID_ARGUMENT = 24, // an argument passed into this function is invalid
+ AVIF_RESULT_NOT_IMPLEMENTED = 25, // a requested code path is not (yet) implemented
+ AVIF_RESULT_OUT_OF_MEMORY = 26,
+ AVIF_RESULT_CANNOT_CHANGE_SETTING = 27, // a setting that can't change is changed during encoding
+ AVIF_RESULT_INCOMPATIBLE_IMAGE = 28, // the image is incompatible with already encoded images
+
+ // Kept for backward compatibility; please use the symbols above instead.
+ AVIF_RESULT_NO_AV1_ITEMS_FOUND = AVIF_RESULT_MISSING_IMAGE_ITEM
} avifResult;
AVIF_API const char * avifResultToString(avifResult result);
@@ -179,10 +202,20 @@ typedef struct avifRWData
// clang-format on
// The avifRWData input must be zero-initialized before being manipulated with these functions.
-AVIF_API void avifRWDataRealloc(avifRWData * raw, size_t newSize);
-AVIF_API void avifRWDataSet(avifRWData * raw, const uint8_t * data, size_t len);
+// If AVIF_RESULT_OUT_OF_MEMORY is returned, raw is left unchanged.
+AVIF_API avifResult avifRWDataRealloc(avifRWData * raw, size_t newSize);
+AVIF_API avifResult avifRWDataSet(avifRWData * raw, const uint8_t * data, size_t len);
AVIF_API void avifRWDataFree(avifRWData * raw);
+// ---------------------------------------------------------------------------
+// Metadata
+
+// Validates the first bytes of the Exif payload and finds the TIFF header offset (up to UINT32_MAX).
+AVIF_API avifResult avifGetExifTiffHeaderOffset(const uint8_t * exif, size_t exifSize, size_t * offset);
+// Returns the offset to the Exif 8-bit orientation value and AVIF_RESULT_OK, or an error.
+// If the offset is set to exifSize, there was no parsing error but no orientation tag was found.
+AVIF_API avifResult avifGetExifOrientationOffset(const uint8_t * exif, size_t exifSize, size_t * offset);
+
// ---------------------------------------------------------------------------
// avifPixelFormat
//
@@ -210,6 +243,12 @@ typedef struct avifPixelFormatInfo
int chromaShiftY;
} avifPixelFormatInfo;
+// Returns the avifPixelFormatInfo depending on the avifPixelFormat.
+// When monochrome is AVIF_TRUE, chromaShiftX and chromaShiftY are set to 1 according to the AV1 specification but they should be ignored.
+//
+// Note: This function implements the second table on page 119 of the AV1 specification version 1.0.0 with Errata 1.
+// For monochrome 4:0:0, subsampling_x and subsampling are specified as 1 to allow
+// an AV1 implementation that only supports profile 0 to hardcode subsampling_x and subsampling_y to 1.
AVIF_API void avifGetPixelFormatInfo(avifPixelFormat format, avifPixelFormatInfo * info);
// ---------------------------------------------------------------------------
@@ -232,7 +271,7 @@ typedef enum avifRange
} avifRange;
// ---------------------------------------------------------------------------
-// CICP enums - https://www.itu.int/rec/T-REC-H.273-201612-I/en
+// CICP enums - https://www.itu.int/rec/T-REC-H.273-201612-S/en
enum
{
@@ -284,6 +323,11 @@ enum
};
typedef uint16_t avifTransferCharacteristics; // AVIF_TRANSFER_CHARACTERISTICS_*
+// If the given transfer characteristics can be expressed with a simple gamma value, sets 'gamma'
+// to that value and returns AVIF_RESULT_OK. Returns an error otherwise.
+AVIF_API avifResult avifTransferCharacteristicsGetGamma(avifTransferCharacteristics atc, float * gamma);
+AVIF_API avifTransferCharacteristics avifTransferCharacteristicsFindByGamma(float gamma);
+
enum
{
AVIF_MATRIX_COEFFICIENTS_IDENTITY = 0,
@@ -299,7 +343,12 @@ enum
AVIF_MATRIX_COEFFICIENTS_SMPTE2085 = 11,
AVIF_MATRIX_COEFFICIENTS_CHROMA_DERIVED_NCL = 12,
AVIF_MATRIX_COEFFICIENTS_CHROMA_DERIVED_CL = 13,
- AVIF_MATRIX_COEFFICIENTS_ICTCP = 14
+ AVIF_MATRIX_COEFFICIENTS_ICTCP = 14,
+#if defined(AVIF_ENABLE_EXPERIMENTAL_YCGCO_R)
+ AVIF_MATRIX_COEFFICIENTS_YCGCO_RE = 15,
+ AVIF_MATRIX_COEFFICIENTS_YCGCO_RO = 16,
+#endif
+ AVIF_MATRIX_COEFFICIENTS_LAST
};
typedef uint16_t avifMatrixCoefficients; // AVIF_MATRIX_COEFFICIENTS_*
@@ -321,6 +370,15 @@ typedef struct avifDiagnostics
AVIF_API void avifDiagnosticsClearError(avifDiagnostics * diag);
+// ---------------------------------------------------------------------------
+// Fraction utility
+
+typedef struct avifFraction
+{
+ int32_t n;
+ int32_t d;
+} avifFraction;
+
// ---------------------------------------------------------------------------
// Optional transformation structs
@@ -375,24 +433,19 @@ typedef struct avifImageRotation
typedef struct avifImageMirror
{
- // 'imir' from ISO/IEC 23008-12:2017 6.5.12 (Draft Amendment 2):
+ // 'imir' from ISO/IEC 23008-12:2022 6.5.12:
//
- // 'mode' specifies how the mirroring is performed:
+ // 'axis' specifies how the mirroring is performed:
//
// 0 indicates that the top and bottom parts of the image are exchanged;
// 1 specifies that the left and right parts are exchanged.
//
// NOTE In Exif, orientation tag can be used to signal mirroring operations. Exif
- // orientation tag 4 corresponds to mode = 0 of ImageMirror, and Exif orientation tag 2
- // corresponds to mode = 1 accordingly.
+ // orientation tag 4 corresponds to axis = 0 of ImageMirror, and Exif orientation tag 2
+ // corresponds to axis = 1 accordingly.
//
// Legal values: [0, 1]
- //
- // NOTE: As of HEIF Draft Amendment 2, the name of this variable has changed from 'axis' to 'mode' as
- // the logic behind it has been *inverted*. Please use the wording above describing the legal
- // values for 'mode' and update any code that previously may have used `axis` to use
- // the *opposite* value (0 now means top-to-bottom, where it used to mean left-to-right).
- uint8_t mode;
+ uint8_t axis;
} avifImageMirror;
// ---------------------------------------------------------------------------
@@ -421,9 +474,34 @@ AVIF_API avifBool avifCleanApertureBoxConvertCropRect(avifCleanApertureBox * cla
avifPixelFormat yuvFormat,
avifDiagnostics * diag);
+// ---------------------------------------------------------------------------
+// avifContentLightLevelInformationBox
+
+typedef struct avifContentLightLevelInformationBox
+{
+ // 'clli' from ISO/IEC 23000-22:2019 (MIAF) 7.4.4.2.2. The SEI message semantics written above
+ // each entry were originally described in ISO/IEC 23008-2.
+
+ // max_content_light_level, when not equal to 0, indicates an upper bound on the maximum light
+ // level among all individual samples in a 4:4:4 representation of red, green, and blue colour
+ // primary intensities (in the linear light domain) for the pictures of the CLVS, in units of
+ // candelas per square metre. When equal to 0, no such upper bound is indicated by
+ // max_content_light_level.
+ uint16_t maxCLL;
+
+ // max_pic_average_light_level, when not equal to 0, indicates an upper bound on the maximum
+ // average light level among the samples in a 4:4:4 representation of red, green, and blue
+ // colour primary intensities (in the linear light domain) for any individual picture of the
+ // CLVS, in units of candelas per square metre. When equal to 0, no such upper bound is
+ // indicated by max_pic_average_light_level.
+ uint16_t maxPALL;
+} avifContentLightLevelInformationBox;
+
// ---------------------------------------------------------------------------
// avifImage
+// NOTE: The avifImage struct may be extended in a future release. Code outside the libavif library
+// must allocate avifImage by calling the avifImageCreate() or avifImageCreateEmpty() function.
typedef struct avifImage
{
// Image information
@@ -455,6 +533,13 @@ typedef struct avifImage
avifTransferCharacteristics transferCharacteristics;
avifMatrixCoefficients matrixCoefficients;
+ // CLLI information:
+ // Content Light Level Information. Used to represent maximum and average light level of an
+ // image. Useful for tone mapping HDR images, especially when using transfer characteristics
+ // SMPTE2084 (PQ). The default value of (0, 0) means the content light level information is
+ // unknown or unavailable, and will cause libavif to avoid writing a clli box for it.
+ avifContentLightLevelInformationBox clli;
+
// Transformations - These metadata values are encoded/decoded when transformFlags are set
// appropriately, but do not impact/adjust the actual pixel buffers used (images won't be
// pre-cropped or mirrored upon decode). Basic explanations from the standards are offered in
@@ -472,22 +557,25 @@ typedef struct avifImage
// Metadata - set with avifImageSetMetadata*() before write, check .size>0 for existence after read
avifRWData exif;
avifRWData xmp;
+
+ // Version 1.0.0 ends here. Add any new members after this line.
} avifImage;
+// avifImageCreate() and avifImageCreateEmpty() return NULL if arguments are invalid or if a memory allocation failed.
AVIF_API avifImage * avifImageCreate(uint32_t width, uint32_t height, uint32_t depth, avifPixelFormat yuvFormat);
AVIF_API avifImage * avifImageCreateEmpty(void); // helper for making an image to decode into
AVIF_API avifResult avifImageCopy(avifImage * dstImage, const avifImage * srcImage, avifPlanesFlags planes); // deep copy
AVIF_API avifResult avifImageSetViewRect(avifImage * dstImage, const avifImage * srcImage, const avifCropRect * rect); // shallow copy, no metadata
AVIF_API void avifImageDestroy(avifImage * image);
-AVIF_API void avifImageSetProfileICC(avifImage * image, const uint8_t * icc, size_t iccSize);
+AVIF_API avifResult avifImageSetProfileICC(avifImage * image, const uint8_t * icc, size_t iccSize);
// Sets Exif metadata. Attempts to parse the Exif metadata for Exif orientation. Sets
// image->transformFlags, image->irot and image->imir if the Exif metadata is parsed successfully,
// otherwise leaves image->transformFlags, image->irot and image->imir unchanged.
// Warning: If the Exif payload is set and invalid, avifEncoderWrite() may return AVIF_RESULT_INVALID_EXIF_PAYLOAD.
-AVIF_API void avifImageSetMetadataExif(avifImage * image, const uint8_t * exif, size_t exifSize);
+AVIF_API avifResult avifImageSetMetadataExif(avifImage * image, const uint8_t * exif, size_t exifSize);
// Sets XMP metadata.
-AVIF_API void avifImageSetMetadataXMP(avifImage * image, const uint8_t * xmp, size_t xmpSize);
+AVIF_API avifResult avifImageSetMetadataXMP(avifImage * image, const uint8_t * xmp, size_t xmpSize);
AVIF_API avifResult avifImageAllocatePlanes(avifImage * image, avifPlanesFlags planes); // Ignores any pre-existing planes
AVIF_API void avifImageFreePlanes(avifImage * image, avifPlanesFlags planes); // Ignores already-freed planes
@@ -583,6 +671,8 @@ typedef enum avifChromaDownsampling
AVIF_CHROMA_DOWNSAMPLING_SHARP_YUV = 4 // Uses sharp yuv filter (libsharpyuv), available for 4:2:0 only, ignored for 4:2:2
} avifChromaDownsampling;
+// NOTE: avifRGBImage must be initialized with avifRGBImageSetDefaults() (preferred) or memset()
+// before use.
typedef struct avifRGBImage
{
uint32_t width; // must match associated avifImage
@@ -599,6 +689,9 @@ typedef struct avifRGBImage
// the alpha bits as if they were all 1.
avifBool alphaPremultiplied; // indicates if RGB value is pre-multiplied by alpha. Default: false
avifBool isFloat; // indicates if RGBA values are in half float (f16) format. Valid only when depth == 16. Default: false
+ int maxThreads; // Number of threads to be used for the YUV to RGB conversion. Note that this value is ignored for RGB to YUV
+ // conversion. Setting this to zero has the same effect as setting it to one. Negative values are invalid.
+ // Default: 1.
uint8_t * pixels;
uint32_t rowBytes;
@@ -611,7 +704,7 @@ AVIF_API void avifRGBImageSetDefaults(avifRGBImage * rgb, const avifImage * imag
AVIF_API uint32_t avifRGBImagePixelSize(const avifRGBImage * rgb);
// Convenience functions. If you supply your own pixels/rowBytes, you do not need to use these.
-AVIF_API void avifRGBImageAllocatePixels(avifRGBImage * rgb);
+AVIF_API avifResult avifRGBImageAllocatePixels(avifRGBImage * rgb);
AVIF_API void avifRGBImageFreePixels(avifRGBImage * rgb);
// The main conversion functions
@@ -627,10 +720,10 @@ AVIF_API avifResult avifRGBImageUnpremultiplyAlpha(avifRGBImage * rgb);
// ---------------------------------------------------------------------------
// YUV Utils
-AVIF_API int avifFullToLimitedY(int depth, int v);
-AVIF_API int avifFullToLimitedUV(int depth, int v);
-AVIF_API int avifLimitedToFullY(int depth, int v);
-AVIF_API int avifLimitedToFullUV(int depth, int v);
+AVIF_API int avifFullToLimitedY(uint32_t depth, int v);
+AVIF_API int avifFullToLimitedUV(uint32_t depth, int v);
+AVIF_API int avifLimitedToFullY(uint32_t depth, int v);
+AVIF_API int avifLimitedToFullUV(uint32_t depth, int v);
// ---------------------------------------------------------------------------
// Codec selection
@@ -642,7 +735,8 @@ typedef enum avifCodecChoice
AVIF_CODEC_CHOICE_DAV1D, // Decode only
AVIF_CODEC_CHOICE_LIBGAV1, // Decode only
AVIF_CODEC_CHOICE_RAV1E, // Encode only
- AVIF_CODEC_CHOICE_SVT // Encode only
+ AVIF_CODEC_CHOICE_SVT, // Encode only
+ AVIF_CODEC_CHOICE_AVM // Experimental (AV2)
} avifCodecChoice;
typedef enum avifCodecFlag
@@ -752,7 +846,9 @@ typedef uint32_t avifStrictFlags;
// Useful stats related to a read/write
typedef struct avifIOStats
{
+ // Size in bytes of the AV1 image item or track data containing color samples.
size_t colorOBUSize;
+ // Size in bytes of the AV1 image item or track data containing alpha samples.
size_t alphaOBUSize;
} avifIOStats;
@@ -807,6 +903,8 @@ typedef enum avifProgressiveState
} avifProgressiveState;
AVIF_API const char * avifProgressiveStateToString(avifProgressiveState progressiveState);
+// NOTE: The avifDecoder struct may be extended in a future release. Code outside the libavif
+// library must allocate avifDecoder by calling the avifDecoderCreate() function.
typedef struct avifDecoder
{
// --------------------------------------------------------------------------------------------
@@ -889,8 +987,13 @@ typedef struct avifDecoder
avifProgressiveState progressiveState; // See avifProgressiveState declaration
avifImageTiming imageTiming; //
uint64_t timescale; // timescale of the media (Hz)
- double duration; // in seconds (durationInTimescales / timescale)
- uint64_t durationInTimescales; // duration in "timescales"
+ double duration; // duration of a single playback of the image sequence in seconds
+ // (durationInTimescales / timescale)
+ uint64_t durationInTimescales; // duration of a single playback of the image sequence in "timescales"
+ int repetitionCount; // number of times the sequence has to be repeated. This can also be one of
+ // AVIF_REPETITION_COUNT_INFINITE or AVIF_REPETITION_COUNT_UNKNOWN. Essentially, if
+ // repetitionCount is a non-negative integer `n`, then the image sequence should be
+ // played back `n + 1` times.
// This is true when avifDecoderParse() detects an alpha plane. Use this to find out if alpha is
// present after a successful call to avifDecoderParse(), but prior to any call to
@@ -911,6 +1014,8 @@ typedef struct avifDecoder
// Internals used by the decoder
struct avifDecoderData * data;
+
+ // Version 1.0.0 ends here. Add any new members after this line.
} avifDecoder;
AVIF_API avifDecoder * avifDecoderCreate(void);
@@ -1009,11 +1114,26 @@ AVIF_API avifResult avifDecoderNthImageMaxExtent(const avifDecoder * decoder, ui
struct avifEncoderData;
struct avifCodecSpecificOptions;
+typedef struct avifScalingMode
+{
+ avifFraction horizontal;
+ avifFraction vertical;
+} avifScalingMode;
+
// Notes:
+// * The avifEncoder struct may be extended in a future release. Code outside the libavif library
+// must allocate avifEncoder by calling the avifEncoderCreate() function.
// * If avifEncoderWrite() returns AVIF_RESULT_OK, output must be freed with avifRWDataFree()
// * If (maxThreads < 2), multithreading is disabled
// * NOTE: Please see the "Understanding maxThreads" comment block above
-// * Quality range: [AVIF_QUANTIZER_BEST_QUALITY - AVIF_QUANTIZER_WORST_QUALITY]
+// * Quality range: [AVIF_QUALITY_WORST - AVIF_QUALITY_BEST]
+// * Quantizer range: [AVIF_QUANTIZER_BEST_QUALITY - AVIF_QUANTIZER_WORST_QUALITY]
+// * In older versions of libavif, the avifEncoder struct doesn't have the quality and qualityAlpha
+// fields. For backward compatibility, if the quality field is not set, the default value of
+// quality is based on the average of minQuantizer and maxQuantizer. Similarly the default value
+// of qualityAlpha is based on the average of minQuantizerAlpha and maxQuantizerAlpha. New code
+// should set quality and qualityAlpha and leave minQuantizer, maxQuantizer, minQuantizerAlpha,
+// and maxQuantizerAlpha initialized to their default values.
// * To enable tiling, set tileRowsLog2 > 0 and/or tileColsLog2 > 0.
// Tiling values range [0-6], where the value indicates a request for 2^n tiles in that dimension.
// If autoTiling is set to AVIF_TRUE, libavif ignores tileRowsLog2 and tileColsLog2 and
@@ -1022,6 +1142,8 @@ struct avifCodecSpecificOptions;
// image in less bytes. AVIF_SPEED_DEFAULT means "Leave the AV1 codec to its default speed settings"./
// If avifEncoder uses rav1e, the speed value is directly passed through (0-10). If libaom is used,
// a combination of settings are tweaked to simulate this speed range.
+// * Extra layer count: [0 - (AVIF_MAX_AV1_LAYER_COUNT-1)]. Non-zero value indicates a layered
+// (progressive) image.
// * Some encoder settings can be changed after encoding starts. Changes will take effect in the next
// call to avifEncoderAddImage().
typedef struct avifEncoder
@@ -1032,9 +1154,18 @@ typedef struct avifEncoder
// settings (see Notes above)
int maxThreads;
int speed;
- int keyframeInterval; // How many frames between automatic forced keyframes; 0 to disable (default).
- uint64_t timescale; // timescale of the media (Hz)
+ int keyframeInterval; // Any set of |keyframeInterval| consecutive frames will have at least one keyframe. When it is 0,
+ // there is no such restriction.
+ uint64_t timescale; // timescale of the media (Hz)
+ int repetitionCount; // Number of times the image sequence should be repeated. This can also be set to
+ // AVIF_REPETITION_COUNT_INFINITE for infinite repetitions. Only applicable for image sequences.
+ // Essentially, if repetitionCount is a non-negative integer `n`, then the image sequence should be
+ // played back `n + 1` times. Defaults to AVIF_REPETITION_COUNT_INFINITE.
+ uint32_t extraLayerCount; // EXPERIMENTAL: Non-zero value encodes layered image.
+
// changeable encoder settings
+ int quality;
+ int qualityAlpha;
int minQuantizer;
int maxQuantizer;
int minQuantizerAlpha;
@@ -1042,6 +1173,7 @@ typedef struct avifEncoder
int tileRowsLog2;
int tileColsLog2;
avifBool autoTiling;
+ avifScalingMode scalingMode;
// stats from the most recent write
avifIOStats ioStats;
@@ -1052,8 +1184,11 @@ typedef struct avifEncoder
// Internals used by the encoder
struct avifEncoderData * data;
struct avifCodecSpecificOptions * csOptions;
+
+ // Version 1.0.0 ends here. Add any new members after this line.
} avifEncoder;
+// avifEncoderCreate() returns NULL if a memory allocation failed.
AVIF_API avifEncoder * avifEncoderCreate(void);
AVIF_API avifResult avifEncoderWrite(avifEncoder * encoder, const avifImage * image, avifRWData * output);
AVIF_API void avifEncoderDestroy(avifEncoder * encoder);
@@ -1065,26 +1200,38 @@ typedef enum avifAddImageFlag
// Force this frame to be a ke
(Patch may be truncated, please check the link at the top of this post.)