diff --git a/extras/scripts/build-libheif_libavif.bat b/extras/scripts/build-libheif_libavif.bat index 7f55dba6..cdde862d 100644 --- a/extras/scripts/build-libheif_libavif.bat +++ b/extras/scripts/build-libheif_libavif.bat @@ -153,7 +153,7 @@ msbuild.exe /p:Platform=%2 /p:configuration="Release" libde265.sln /t:de265 IF ERRORLEVEL 1 exit /b 1 -copy /y "%XBUILD_DIR%\libde265\Release\de265.dll" "%XSRC_DIR%\bin%~3\" +copy /y "%XBUILD_DIR%\libde265\Release\libde265.dll" "%XSRC_DIR%\bin%~3\" IF ERRORLEVEL 1 exit /b 1 diff --git a/extras/third_party/libavif b/extras/third_party/libavif index ab98eb17..d1c26fac 160000 --- a/extras/third_party/libavif +++ b/extras/third_party/libavif @@ -1 +1 @@ -Subproject commit ab98eb17f12ba1c207f6fd6db7d85bad18939353 +Subproject commit d1c26facaf5a8a97919ceee06814d05d10e25622 diff --git a/extras/third_party/libheif/libde265 b/extras/third_party/libheif/libde265 index e255f057..a267c847 160000 --- a/extras/third_party/libheif/libde265 +++ b/extras/third_party/libheif/libde265 @@ -1 +1 @@ -Subproject commit e255f0571a46935955deef15808e52b18043788c +Subproject commit a267c84707ab264928fa9b86de2ee749c48c318c diff --git a/extras/third_party/libjxl b/extras/third_party/libjxl index c27d4992..5d20fbe1 160000 --- a/extras/third_party/libjxl +++ b/extras/third_party/libjxl @@ -1 +1 @@ -Subproject commit c27d499263435ac77007174e0f1cf54557cff23a +Subproject commit 5d20fbe1cfcdb54bcc7880fc8a59bb9047d8c60f diff --git a/extras/third_party/libpng-apng.src-patch/libpng b/extras/third_party/libpng-apng.src-patch/libpng index 07b88031..f135775a 160000 --- a/extras/third_party/libpng-apng.src-patch/libpng +++ b/extras/third_party/libpng-apng.src-patch/libpng @@ -1 +1 @@ -Subproject commit 07b8803110da160b158ebfef872627da6c85cbdf +Subproject commit f135775ad4e5d4408d2e12ffcc71bb36e6b48551 diff --git a/extras/third_party/libpng-apng.src-patch/libpng-apng/README.txt b/extras/third_party/libpng-apng.src-patch/libpng-apng/README.txt index 77cba2f7..46c46aa2 100644 --- a/extras/third_party/libpng-apng.src-patch/libpng-apng/README.txt +++ b/extras/third_party/libpng-apng.src-patch/libpng-apng/README.txt @@ -1,11 +1,11 @@ This modified version of libpng code adds animated PNG support and is released under the same license as the upstream library. The modifications -are Copyright (c) 2006-2007 Andrew Smith, Copyright (c) 2008-2017 Max Stepin, +are Copyright (c) 2006-2007 Andrew Smith, Copyright (c) 2008-2023 Max Stepin, and are delimited by "#ifdef PNG_APNG_SUPPORTED / #endif" directives surrounding them in the modified libpng source files. You can get it from: -https://sourceforge.net/projects/libpng-apng/files/libpng16/ https://sourceforge.net/projects/apng/files/libpng/libpng16/ +https://sourceforge.net/projects/libpng-apng/files/libpng16/ https://hg.mozilla.org/mozilla-central/file/tip/media/libpng/apng.patch diff --git a/extras/third_party/libpng-apng.src-patch/libpng-apng/libpng-1.6.39-apng.patch b/extras/third_party/libpng-apng.src-patch/libpng-apng/libpng-1.6.40-apng.patch similarity index 72% rename from extras/third_party/libpng-apng.src-patch/libpng-apng/libpng-1.6.39-apng.patch rename to extras/third_party/libpng-apng.src-patch/libpng-apng/libpng-1.6.40-apng.patch index 0b9c56d0..52e36ac7 100644 --- a/extras/third_party/libpng-apng.src-patch/libpng-apng/libpng-1.6.39-apng.patch +++ b/extras/third_party/libpng-apng.src-patch/libpng-apng/libpng-1.6.40-apng.patch @@ -1,148 +1,130 @@ -diff -Naru libpng-1.6.39.org/png.h libpng-1.6.39/png.h ---- libpng-1.6.39.org/png.h 2022-11-24 08:37:51.507052183 +0900 -+++ libpng-1.6.39/png.h 2022-11-24 08:41:17.785489740 +0900 -@@ -330,6 +330,10 @@ - # include "pnglibconf.h" - #endif +Index: LICENSE +=================================================================== +--- LICENSE ++++ LICENSE +@@ -1,6 +1,12 @@ + COPYRIGHT NOTICE, DISCLAIMER, and LICENSE + ========================================= -+#define PNG_APNG_SUPPORTED -+#define PNG_READ_APNG_SUPPORTED -+#define PNG_WRITE_APNG_SUPPORTED -+ - #ifndef PNG_VERSION_INFO_ONLY - /* Machine specific configuration. */ - # include "pngconf.h" -@@ -425,6 +429,17 @@ - * See pngconf.h for base types that vary by machine/system - */ ++This modified version of libpng code adds animated PNG support and is ++released under the libpng license described below. The modifications are ++Copyright (c) 2006-2007 Andrew Smith, Copyright (c) 2008-2023 Max Stepin, ++and are delimited by "#ifdef PNG_APNG_SUPPORTED / #endif" directives ++surrounding them in the modified libpng source files. ++ + PNG Reference Library License version 2 + --------------------------------------- -+#ifdef PNG_APNG_SUPPORTED -+/* dispose_op flags from inside fcTL */ -+#define PNG_DISPOSE_OP_NONE 0x00U -+#define PNG_DISPOSE_OP_BACKGROUND 0x01U -+#define PNG_DISPOSE_OP_PREVIOUS 0x02U -+ -+/* blend_op flags from inside fcTL */ -+#define PNG_BLEND_OP_SOURCE 0x00U -+#define PNG_BLEND_OP_OVER 0x01U -+#endif /* PNG_APNG_SUPPORTED */ -+ - /* This triggers a compiler error in png.c, if png.c and png.h - * do not agree upon the version number. - */ -@@ -746,6 +761,10 @@ - #define PNG_INFO_sCAL 0x4000U /* ESR, 1.0.6 */ - #define PNG_INFO_IDAT 0x8000U /* ESR, 1.0.6 */ - #define PNG_INFO_eXIf 0x10000U /* GR-P, 1.6.31 */ -+#ifdef PNG_APNG_SUPPORTED -+#define PNG_INFO_acTL 0x20000U -+#define PNG_INFO_fcTL 0x40000U +Index: pngread.c +=================================================================== +--- pngread.c ++++ pngread.c +@@ -161,6 +161,9 @@ + + else if (chunk_name == png_IDAT) + { ++#ifdef PNG_READ_APNG_SUPPORTED ++ png_have_info(png_ptr, info_ptr); +#endif + png_ptr->idat_size = length; + break; + } +@@ -255,6 +258,17 @@ + png_handle_iTXt(png_ptr, info_ptr, length); + #endif - /* This is used for the transformation routines, as some of them - * change these values for the row. It also should enable using -@@ -783,6 +802,10 @@ - #ifdef PNG_PROGRESSIVE_READ_SUPPORTED - typedef PNG_CALLBACK(void, *png_progressive_info_ptr, (png_structp, png_infop)); - typedef PNG_CALLBACK(void, *png_progressive_end_ptr, (png_structp, png_infop)); -+#ifdef PNG_APNG_SUPPORTED -+typedef PNG_CALLBACK(void, *png_progressive_frame_ptr, (png_structp, -+ png_uint_32)); ++#ifdef PNG_READ_APNG_SUPPORTED ++ else if (chunk_name == png_acTL) ++ png_handle_acTL(png_ptr, info_ptr, length); ++ ++ else if (chunk_name == png_fcTL) ++ png_handle_fcTL(png_ptr, info_ptr, length); ++ ++ else if (chunk_name == png_fdAT) ++ png_handle_fdAT(png_ptr, info_ptr, length); +#endif ++ + else + png_handle_unknown(png_ptr, info_ptr, length, + PNG_HANDLE_CHUNK_AS_DEFAULT); +@@ -262,6 +276,72 @@ + } + #endif /* SEQUENTIAL_READ */ - /* The following callback receives png_uint_32 row_number, int pass for the - * png_bytep data of the row. When transforming an interlaced image the -@@ -3226,6 +3249,74 @@ - /******************************************************************************* - * END OF HARDWARE AND SOFTWARE OPTIONS - ******************************************************************************/ -+#ifdef PNG_APNG_SUPPORTED -+PNG_EXPORT(250, png_uint_32, png_get_acTL, (png_structp png_ptr, -+ png_infop info_ptr, png_uint_32 *num_frames, png_uint_32 *num_plays)); ++#ifdef PNG_READ_APNG_SUPPORTED ++void PNGAPI ++png_read_frame_head(png_structp png_ptr, png_infop info_ptr) ++{ ++ png_byte have_chunk_after_DAT; /* after IDAT or after fdAT */ + -+PNG_EXPORT(251, png_uint_32, png_set_acTL, (png_structp png_ptr, -+ png_infop info_ptr, png_uint_32 num_frames, png_uint_32 num_plays)); ++ png_debug(0, "Reading frame head"); + -+PNG_EXPORT(252, png_uint_32, png_get_num_frames, (png_structp png_ptr, -+ png_infop info_ptr)); ++ if ((png_ptr->mode & PNG_HAVE_acTL) == 0) ++ png_error(png_ptr, "attempt to png_read_frame_head() but " ++ "no acTL present"); + -+PNG_EXPORT(253, png_uint_32, png_get_num_plays, (png_structp png_ptr, -+ png_infop info_ptr)); ++ /* do nothing for the main IDAT */ ++ if (png_ptr->num_frames_read == 0) ++ return; + -+PNG_EXPORT(254, png_uint_32, png_get_next_frame_fcTL, -+ (png_structp png_ptr, png_infop info_ptr, png_uint_32 *width, -+ png_uint_32 *height, png_uint_32 *x_offset, png_uint_32 *y_offset, -+ png_uint_16 *delay_num, png_uint_16 *delay_den, png_byte *dispose_op, -+ png_byte *blend_op)); ++ png_read_reset(png_ptr); ++ png_ptr->flags &= ~PNG_FLAG_ROW_INIT; ++ png_ptr->mode &= ~PNG_HAVE_fcTL; + -+PNG_EXPORT(255, png_uint_32, png_set_next_frame_fcTL, -+ (png_structp png_ptr, png_infop info_ptr, png_uint_32 width, -+ png_uint_32 height, png_uint_32 x_offset, png_uint_32 y_offset, -+ png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op, -+ png_byte blend_op)); ++ have_chunk_after_DAT = 0; ++ for (;;) ++ { ++ png_uint_32 length = png_read_chunk_header(png_ptr); + -+PNG_EXPORT(256, png_uint_32, png_get_next_frame_width, -+ (png_structp png_ptr, png_infop info_ptr)); -+PNG_EXPORT(257, png_uint_32, png_get_next_frame_height, -+ (png_structp png_ptr, png_infop info_ptr)); -+PNG_EXPORT(258, png_uint_32, png_get_next_frame_x_offset, -+ (png_structp png_ptr, png_infop info_ptr)); -+PNG_EXPORT(259, png_uint_32, png_get_next_frame_y_offset, -+ (png_structp png_ptr, png_infop info_ptr)); -+PNG_EXPORT(260, png_uint_16, png_get_next_frame_delay_num, -+ (png_structp png_ptr, png_infop info_ptr)); -+PNG_EXPORT(261, png_uint_16, png_get_next_frame_delay_den, -+ (png_structp png_ptr, png_infop info_ptr)); -+PNG_EXPORT(262, png_byte, png_get_next_frame_dispose_op, -+ (png_structp png_ptr, png_infop info_ptr)); -+PNG_EXPORT(263, png_byte, png_get_next_frame_blend_op, -+ (png_structp png_ptr, png_infop info_ptr)); -+PNG_EXPORT(264, png_byte, png_get_first_frame_is_hidden, -+ (png_structp png_ptr, png_infop info_ptr)); -+PNG_EXPORT(265, png_uint_32, png_set_first_frame_is_hidden, -+ (png_structp png_ptr, png_infop info_ptr, png_byte is_hidden)); ++ if (png_ptr->chunk_name == png_IDAT) ++ { ++ /* discard trailing IDATs for the first frame */ ++ if (have_chunk_after_DAT != 0 || png_ptr->num_frames_read > 1) ++ png_error(png_ptr, "png_read_frame_head(): out of place IDAT"); ++ png_crc_finish(png_ptr, length); ++ } + -+#ifdef PNG_READ_APNG_SUPPORTED -+PNG_EXPORT(266, void, png_read_frame_head, (png_structp png_ptr, -+ png_infop info_ptr)); -+#ifdef PNG_PROGRESSIVE_READ_SUPPORTED -+PNG_EXPORT(267, void, png_set_progressive_frame_fn, (png_structp png_ptr, -+ png_progressive_frame_ptr frame_info_fn, -+ png_progressive_frame_ptr frame_end_fn)); -+#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ -+#endif /* PNG_READ_APNG_SUPPORTED */ ++ else if (png_ptr->chunk_name == png_fcTL) ++ { ++ png_handle_fcTL(png_ptr, info_ptr, length); ++ have_chunk_after_DAT = 1; ++ } + -+#ifdef PNG_WRITE_APNG_SUPPORTED -+PNG_EXPORT(268, void, png_write_frame_head, (png_structp png_ptr, -+ png_infop info_ptr, png_bytepp row_pointers, -+ png_uint_32 width, png_uint_32 height, -+ png_uint_32 x_offset, png_uint_32 y_offset, -+ png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op, -+ png_byte blend_op)); ++ else if (png_ptr->chunk_name == png_fdAT) ++ { ++ png_ensure_sequence_number(png_ptr, length); + -+PNG_EXPORT(269, void, png_write_frame_tail, (png_structp png_ptr, -+ png_infop info_ptr)); -+#endif /* PNG_WRITE_APNG_SUPPORTED */ -+#endif /* PNG_APNG_SUPPORTED */ - - /* Maintainer: Put new public prototypes here ^, in libpng.3, in project - * defs, and in scripts/symbols.def. -@@ -3235,7 +3326,11 @@ - * one to use is one more than this.) - */ - #ifdef PNG_EXPORT_LAST_ORDINAL -+#ifdef PNG_APNG_SUPPORTED -+ PNG_EXPORT_LAST_ORDINAL(269); -+#else - PNG_EXPORT_LAST_ORDINAL(249); -+#endif /* PNG_APNG_SUPPORTED */ - #endif - - #ifdef __cplusplus -diff -Naru libpng-1.6.39.org/pngget.c libpng-1.6.39/pngget.c ---- libpng-1.6.39.org/pngget.c 2022-11-24 08:37:51.507052183 +0900 -+++ libpng-1.6.39/pngget.c 2022-11-24 08:41:17.785489740 +0900 -@@ -1246,4 +1246,166 @@ ++ /* discard trailing fdATs for frames other than the first */ ++ if (have_chunk_after_DAT == 0 && png_ptr->num_frames_read > 1) ++ png_crc_finish(png_ptr, length - 4); ++ else if (png_ptr->mode & PNG_HAVE_fcTL) ++ { ++ png_ptr->idat_size = length - 4; ++ png_ptr->mode |= PNG_HAVE_IDAT; ++ ++ break; ++ } ++ else ++ png_error(png_ptr, "png_read_frame_head(): out of place fdAT"); ++ } ++ else ++ { ++ png_warning(png_ptr, "Skipped (ignored) a chunk " ++ "between APNG chunks"); ++ png_crc_finish(png_ptr, length); ++ } ++ } ++} ++#endif /* READ_APNG */ ++ + /* Optional call to update the users info_ptr structure */ + void PNGAPI + png_read_update_info(png_structrp png_ptr, png_inforp info_ptr) +Index: pngget.c +=================================================================== +--- pngget.c ++++ pngget.c +@@ -1257,4 +1257,166 @@ # endif #endif @@ -154,7 +136,7 @@ diff -Naru libpng-1.6.39.org/pngget.c libpng-1.6.39/pngget.c + png_debug1(1, "in %s retrieval function", "acTL"); + + if (png_ptr != NULL && info_ptr != NULL && -+ (info_ptr->valid & PNG_INFO_acTL) && ++ (info_ptr->valid & PNG_INFO_acTL) != 0 && + num_frames != NULL && num_plays != NULL) + { + *num_frames = info_ptr->num_frames; @@ -195,7 +177,7 @@ diff -Naru libpng-1.6.39.org/pngget.c libpng-1.6.39/pngget.c + png_debug1(1, "in %s retrieval function", "fcTL"); + + if (png_ptr != NULL && info_ptr != NULL && -+ (info_ptr->valid & PNG_INFO_fcTL) && ++ (info_ptr->valid & PNG_INFO_fcTL) != 0 && + width != NULL && height != NULL && + x_offset != NULL && y_offset != NULL && + delay_num != NULL && delay_den != NULL && @@ -307,80 +289,443 @@ diff -Naru libpng-1.6.39.org/pngget.c libpng-1.6.39/pngget.c + + return 0; +} -+#endif /* PNG_APNG_SUPPORTED */ ++#endif /* APNG */ #endif /* READ || WRITE */ -diff -Naru libpng-1.6.39.org/pnginfo.h libpng-1.6.39/pnginfo.h ---- libpng-1.6.39.org/pnginfo.h 2022-11-24 08:37:51.507052183 +0900 -+++ libpng-1.6.39/pnginfo.h 2022-11-24 08:41:17.785489740 +0900 -@@ -263,5 +263,18 @@ - png_bytepp row_pointers; /* the image bits */ +Index: png.c +=================================================================== +--- png.c ++++ png.c +@@ -815,13 +815,15 @@ + return PNG_STRING_COPYRIGHT + #else + return PNG_STRING_NEWLINE \ +- "libpng version 1.6.40" PNG_STRING_NEWLINE \ ++ "libpng version 1.6.40+apng" PNG_STRING_NEWLINE \ + "Copyright (c) 2018-2023 Cosmin Truta" PNG_STRING_NEWLINE \ + "Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson" \ + PNG_STRING_NEWLINE \ + "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \ + "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \ +- PNG_STRING_NEWLINE; ++ PNG_STRING_NEWLINE \ ++ "Portions Copyright (c) 2006-2007 Andrew Smith" PNG_STRING_NEWLINE \ ++ "Portions Copyright (c) 2008-2023 Max Stepin" PNG_STRING_NEWLINE ; + #endif + } + +Index: png.h +=================================================================== +--- png.h ++++ png.h +@@ -24,6 +24,12 @@ + * COPYRIGHT NOTICE, DISCLAIMER, and LICENSE + * ========================================= + * ++ * This modified version of libpng code adds animated PNG support and is ++ * released under the libpng license described below. The modifications are ++ * Copyright (c) 2006-2007 Andrew Smith, Copyright (c) 2008-2023 Max Stepin, ++ * and are delimited by "#ifdef PNG_APNG_SUPPORTED / #endif" directives ++ * surrounding them in the modified libpng source files. ++ * + * PNG Reference Library License version 2 + * --------------------------------------- + * +@@ -278,8 +284,9 @@ + */ + + /* Version information for png.h - this should match the version in png.c */ +-#define PNG_LIBPNG_VER_STRING "1.6.40" +-#define PNG_HEADER_VERSION_STRING " libpng version 1.6.40 - June 21, 2023\n" ++#define PNG_LIBPNG_VER_STRING "1.6.40+apng" ++#define PNG_HEADER_VERSION_STRING \ ++ " libpng version 1.6.40+apng - June 21, 2023\n" + + #define PNG_LIBPNG_VER_SONUM 16 + #define PNG_LIBPNG_VER_DLLNUM 16 +@@ -330,6 +337,10 @@ + # include "pnglibconf.h" #endif ++#define PNG_APNG_SUPPORTED ++#define PNG_READ_APNG_SUPPORTED ++#define PNG_WRITE_APNG_SUPPORTED ++ + #ifndef PNG_VERSION_INFO_ONLY + /* Machine specific configuration. */ + # include "pngconf.h" +@@ -425,6 +436,17 @@ + * See pngconf.h for base types that vary by machine/system + */ + +#ifdef PNG_APNG_SUPPORTED -+ png_uint_32 num_frames; /* including default image */ -+ png_uint_32 num_plays; -+ png_uint_32 next_frame_width; -+ png_uint_32 next_frame_height; -+ png_uint_32 next_frame_x_offset; -+ png_uint_32 next_frame_y_offset; -+ png_uint_16 next_frame_delay_num; -+ png_uint_16 next_frame_delay_den; -+ png_byte next_frame_dispose_op; -+ png_byte next_frame_blend_op; -+#endif ++/* dispose_op flags from inside fcTL */ ++#define PNG_DISPOSE_OP_NONE 0x00 ++#define PNG_DISPOSE_OP_BACKGROUND 0x01 ++#define PNG_DISPOSE_OP_PREVIOUS 0x02 + - }; - #endif /* PNGINFO_H */ -diff -Naru libpng-1.6.39.org/pngpread.c libpng-1.6.39/pngpread.c ---- libpng-1.6.39.org/pngpread.c 2022-11-24 08:37:51.507052183 +0900 -+++ libpng-1.6.39/pngpread.c 2022-11-24 08:41:17.785489740 +0900 -@@ -195,6 +195,106 @@ ++/* blend_op flags from inside fcTL */ ++#define PNG_BLEND_OP_SOURCE 0x00 ++#define PNG_BLEND_OP_OVER 0x01 ++#endif /* APNG */ ++ + /* This triggers a compiler error in png.c, if png.c and png.h + * do not agree upon the version number. + */ +@@ -746,6 +768,10 @@ + #define PNG_INFO_sCAL 0x4000U /* ESR, 1.0.6 */ + #define PNG_INFO_IDAT 0x8000U /* ESR, 1.0.6 */ + #define PNG_INFO_eXIf 0x10000U /* GR-P, 1.6.31 */ ++#ifdef PNG_APNG_SUPPORTED ++#define PNG_INFO_acTL 0x20000U ++#define PNG_INFO_fcTL 0x40000U ++#endif - chunk_name = png_ptr->chunk_name; + /* This is used for the transformation routines, as some of them + * change these values for the row. It also should enable using +@@ -783,6 +809,10 @@ + #ifdef PNG_PROGRESSIVE_READ_SUPPORTED + typedef PNG_CALLBACK(void, *png_progressive_info_ptr, (png_structp, png_infop)); + typedef PNG_CALLBACK(void, *png_progressive_end_ptr, (png_structp, png_infop)); ++#ifdef PNG_APNG_SUPPORTED ++typedef PNG_CALLBACK(void, *png_progressive_frame_ptr, (png_structp, ++ png_uint_32)); ++#endif -+#ifdef PNG_READ_APNG_SUPPORTED -+ if (png_ptr->num_frames_read > 0 && -+ png_ptr->num_frames_read < info_ptr->num_frames) -+ { -+ if (chunk_name == png_IDAT) -+ { -+ /* Discard trailing IDATs for the first frame */ -+ if (png_ptr->mode & PNG_HAVE_fcTL || png_ptr->num_frames_read > 1) -+ png_error(png_ptr, "out of place IDAT"); + /* The following callback receives png_uint_32 row_number, int pass for the + * png_bytep data of the row. When transforming an interlaced image the +@@ -3227,6 +3257,75 @@ + * END OF HARDWARE AND SOFTWARE OPTIONS + ******************************************************************************/ + ++#ifdef PNG_APNG_SUPPORTED ++PNG_EXPORT(248, png_uint_32, png_get_acTL, (png_structp png_ptr, ++ png_infop info_ptr, png_uint_32 *num_frames, png_uint_32 *num_plays)); + -+ if (png_ptr->push_length + 4 > png_ptr->buffer_size) -+ { -+ png_push_save_buffer(png_ptr); -+ return; -+ } ++PNG_EXPORT(249, png_uint_32, png_set_acTL, (png_structp png_ptr, ++ png_infop info_ptr, png_uint_32 num_frames, png_uint_32 num_plays)); + -+ png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; -+ return; -+ } -+ else if (chunk_name == png_fdAT) -+ { -+ if (png_ptr->buffer_size < 4) -+ { -+ png_push_save_buffer(png_ptr); -+ return; -+ } ++PNG_EXPORT(250, png_uint_32, png_get_num_frames, (png_structp png_ptr, ++ png_infop info_ptr)); + -+ png_ensure_sequence_number(png_ptr, 4); ++PNG_EXPORT(251, png_uint_32, png_get_num_plays, (png_structp png_ptr, ++ png_infop info_ptr)); + -+ if (!(png_ptr->mode & PNG_HAVE_fcTL)) -+ { -+ /* Discard trailing fdATs for frames other than the first */ -+ if (png_ptr->num_frames_read < 2) -+ png_error(png_ptr, "out of place fdAT"); ++PNG_EXPORT(252, png_uint_32, png_get_next_frame_fcTL, ++ (png_structp png_ptr, png_infop info_ptr, png_uint_32 *width, ++ png_uint_32 *height, png_uint_32 *x_offset, png_uint_32 *y_offset, ++ png_uint_16 *delay_num, png_uint_16 *delay_den, png_byte *dispose_op, ++ png_byte *blend_op)); + -+ if (png_ptr->push_length + 4 > png_ptr->buffer_size) -+ { -+ png_push_save_buffer(png_ptr); -+ return; -+ } ++PNG_EXPORT(253, png_uint_32, png_set_next_frame_fcTL, ++ (png_structp png_ptr, png_infop info_ptr, png_uint_32 width, ++ png_uint_32 height, png_uint_32 x_offset, png_uint_32 y_offset, ++ png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op, ++ png_byte blend_op)); ++ ++PNG_EXPORT(254, png_uint_32, png_get_next_frame_width, ++ (png_structp png_ptr, png_infop info_ptr)); ++PNG_EXPORT(255, png_uint_32, png_get_next_frame_height, ++ (png_structp png_ptr, png_infop info_ptr)); ++PNG_EXPORT(256, png_uint_32, png_get_next_frame_x_offset, ++ (png_structp png_ptr, png_infop info_ptr)); ++PNG_EXPORT(257, png_uint_32, png_get_next_frame_y_offset, ++ (png_structp png_ptr, png_infop info_ptr)); ++PNG_EXPORT(258, png_uint_16, png_get_next_frame_delay_num, ++ (png_structp png_ptr, png_infop info_ptr)); ++PNG_EXPORT(259, png_uint_16, png_get_next_frame_delay_den, ++ (png_structp png_ptr, png_infop info_ptr)); ++PNG_EXPORT(260, png_byte, png_get_next_frame_dispose_op, ++ (png_structp png_ptr, png_infop info_ptr)); ++PNG_EXPORT(261, png_byte, png_get_next_frame_blend_op, ++ (png_structp png_ptr, png_infop info_ptr)); ++PNG_EXPORT(262, png_byte, png_get_first_frame_is_hidden, ++ (png_structp png_ptr, png_infop info_ptr)); ++PNG_EXPORT(263, png_uint_32, png_set_first_frame_is_hidden, ++ (png_structp png_ptr, png_infop info_ptr, png_byte is_hidden)); ++ ++#ifdef PNG_READ_APNG_SUPPORTED ++PNG_EXPORT(264, void, png_read_frame_head, (png_structp png_ptr, ++ png_infop info_ptr)); ++#ifdef PNG_PROGRESSIVE_READ_SUPPORTED ++PNG_EXPORT(265, void, png_set_progressive_frame_fn, (png_structp png_ptr, ++ png_progressive_frame_ptr frame_info_fn, ++ png_progressive_frame_ptr frame_end_fn)); ++#endif /* PROGRESSIVE_READ */ ++#endif /* READ_APNG */ ++ ++#ifdef PNG_WRITE_APNG_SUPPORTED ++PNG_EXPORT(266, void, png_write_frame_head, (png_structp png_ptr, ++ png_infop info_ptr, png_bytepp row_pointers, ++ png_uint_32 width, png_uint_32 height, ++ png_uint_32 x_offset, png_uint_32 y_offset, ++ png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op, ++ png_byte blend_op)); ++ ++PNG_EXPORT(267, void, png_write_frame_tail, (png_structp png_ptr, ++ png_infop info_ptr)); ++#endif /* WRITE_APNG */ ++#endif /* APNG */ ++ + /* Maintainer: Put new public prototypes here ^, in libpng.3, in project + * defs, and in scripts/symbols.def. + */ +@@ -3235,7 +3334,11 @@ + * one to use is one more than this.) + */ + #ifdef PNG_EXPORT_LAST_ORDINAL ++#ifdef PNG_APNG_SUPPORTED ++ PNG_EXPORT_LAST_ORDINAL(269); ++#else + PNG_EXPORT_LAST_ORDINAL(249); ++#endif /* APNG */ + #endif + + #ifdef __cplusplus +Index: pngpriv.h +=================================================================== +--- pngpriv.h ++++ pngpriv.h +@@ -628,6 +628,10 @@ + #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000U /* Have another chunk after IDAT */ + #define PNG_WROTE_eXIf 0x4000U + #define PNG_IS_READ_STRUCT 0x8000U /* Else is a write struct */ ++#ifdef PNG_APNG_SUPPORTED ++#define PNG_HAVE_acTL 0x10000U ++#define PNG_HAVE_fcTL 0x20000U ++#endif + + /* Flags for the transformations the PNG library does on the image data */ + #define PNG_BGR 0x0001U +@@ -864,6 +868,16 @@ + #define png_tRNS PNG_U32(116, 82, 78, 83) + #define png_zTXt PNG_U32(122, 84, 88, 116) + ++#ifdef PNG_APNG_SUPPORTED ++#define png_acTL PNG_U32( 97, 99, 84, 76) ++#define png_fcTL PNG_U32(102, 99, 84, 76) ++#define png_fdAT PNG_U32(102, 100, 65, 84) ++ ++/* For png_struct.apng_flags: */ ++#define PNG_FIRST_FRAME_HIDDEN 0x0001U ++#define PNG_APNG_APP 0x0002U ++#endif ++ + /* The following will work on (signed char*) strings, whereas the get_uint_32 + * macro will fail on top-bit-set values because of the sign extension. + */ +@@ -1615,6 +1629,49 @@ + + #endif /* PROGRESSIVE_READ */ + ++#ifdef PNG_APNG_SUPPORTED ++PNG_INTERNAL_FUNCTION(void,png_ensure_fcTL_is_valid,(png_structp png_ptr, ++ png_uint_32 width, png_uint_32 height, ++ png_uint_32 x_offset, png_uint_32 y_offset, ++ png_uint_16 delay_num, png_uint_16 delay_den, ++ png_byte dispose_op, png_byte blend_op),PNG_EMPTY); ++ ++#ifdef PNG_READ_APNG_SUPPORTED ++PNG_INTERNAL_FUNCTION(void,png_handle_acTL,(png_structp png_ptr, ++ png_infop info_ptr, png_uint_32 length),PNG_EMPTY); ++PNG_INTERNAL_FUNCTION(void,png_handle_fcTL,(png_structp png_ptr, ++ png_infop info_ptr, png_uint_32 length),PNG_EMPTY); ++PNG_INTERNAL_FUNCTION(void,png_handle_fdAT,(png_structp png_ptr, ++ png_infop info_ptr, png_uint_32 length),PNG_EMPTY); ++PNG_INTERNAL_FUNCTION(void,png_have_info,(png_structp png_ptr, ++ png_infop info_ptr),PNG_EMPTY); ++PNG_INTERNAL_FUNCTION(void,png_ensure_sequence_number,(png_structp png_ptr, ++ png_uint_32 length),PNG_EMPTY); ++PNG_INTERNAL_FUNCTION(void,png_read_reset,(png_structp png_ptr),PNG_EMPTY); ++PNG_INTERNAL_FUNCTION(void,png_read_reinit,(png_structp png_ptr, ++ png_infop info_ptr),PNG_EMPTY); ++#ifdef PNG_PROGRESSIVE_READ_SUPPORTED ++PNG_INTERNAL_FUNCTION(void,png_progressive_read_reset,(png_structp png_ptr), ++ PNG_EMPTY); ++#endif /* PROGRESSIVE_READ */ ++#endif /* READ_APNG */ ++ ++#ifdef PNG_WRITE_APNG_SUPPORTED ++PNG_INTERNAL_FUNCTION(void,png_write_acTL,(png_structp png_ptr, ++ png_uint_32 num_frames, png_uint_32 num_plays),PNG_EMPTY); ++PNG_INTERNAL_FUNCTION(void,png_write_fcTL,(png_structp png_ptr, ++ png_uint_32 width, png_uint_32 height, ++ png_uint_32 x_offset, png_uint_32 y_offset, ++ png_uint_16 delay_num, png_uint_16 delay_den, ++ png_byte dispose_op, png_byte blend_op),PNG_EMPTY); ++PNG_INTERNAL_FUNCTION(void,png_write_fdAT,(png_structp png_ptr, ++ png_const_bytep data, size_t length),PNG_EMPTY); ++PNG_INTERNAL_FUNCTION(void,png_write_reset,(png_structp png_ptr),PNG_EMPTY); ++PNG_INTERNAL_FUNCTION(void,png_write_reinit,(png_structp png_ptr, ++ png_infop info_ptr, png_uint_32 width, png_uint_32 height),PNG_EMPTY); ++#endif /* WRITE_APNG */ ++#endif /* APNG */ ++ + /* Added at libpng version 1.6.0 */ + #ifdef PNG_GAMMA_SUPPORTED + PNG_INTERNAL_FUNCTION(void,png_colorspace_set_gamma,(png_const_structrp png_ptr, +Index: pnginfo.h +=================================================================== +--- pnginfo.h ++++ pnginfo.h +@@ -263,5 +263,18 @@ + png_bytepp row_pointers; /* the image bits */ + #endif + ++#ifdef PNG_APNG_SUPPORTED ++ png_uint_32 num_frames; /* including default image */ ++ png_uint_32 num_plays; ++ png_uint_32 next_frame_width; ++ png_uint_32 next_frame_height; ++ png_uint_32 next_frame_x_offset; ++ png_uint_32 next_frame_y_offset; ++ png_uint_16 next_frame_delay_num; ++ png_uint_16 next_frame_delay_den; ++ png_byte next_frame_dispose_op; ++ png_byte next_frame_blend_op; ++#endif ++ + }; + #endif /* PNGINFO_H */ +Index: pngstruct.h +=================================================================== +--- pngstruct.h ++++ pngstruct.h +@@ -399,6 +399,27 @@ + png_byte filter_type; + #endif + ++#ifdef PNG_APNG_SUPPORTED ++ png_uint_32 apng_flags; ++ png_uint_32 next_seq_num; /* next fcTL/fdAT chunk sequence number */ ++ png_uint_32 first_frame_width; ++ png_uint_32 first_frame_height; ++ ++#ifdef PNG_READ_APNG_SUPPORTED ++ png_uint_32 num_frames_read; /* incremented after all image data of */ ++ /* a frame is read */ ++#ifdef PNG_PROGRESSIVE_READ_SUPPORTED ++ png_progressive_frame_ptr frame_info_fn; /* frame info read callback */ ++ png_progressive_frame_ptr frame_end_fn; /* frame data read callback */ ++#endif ++#endif ++ ++#ifdef PNG_WRITE_APNG_SUPPORTED ++ png_uint_32 num_frames_to_write; ++ png_uint_32 num_frames_written; ++#endif ++#endif /* APNG */ ++ + /* New members added in libpng-1.2.0 */ + + /* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */ +Index: pngwrite.c +=================================================================== +--- pngwrite.c ++++ pngwrite.c +@@ -128,6 +128,10 @@ + * the application continues writing the PNG. So check the 'invalid' + * flag here too. + */ ++#ifdef PNG_WRITE_APNG_SUPPORTED ++ if ((info_ptr->valid & PNG_INFO_acTL) != 0) ++ png_write_acTL(png_ptr, info_ptr->num_frames, info_ptr->num_plays); ++#endif + #ifdef PNG_GAMMA_SUPPORTED + # ifdef PNG_WRITE_gAMA_SUPPORTED + if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 && +@@ -368,6 +372,11 @@ + if ((png_ptr->mode & PNG_HAVE_IDAT) == 0) + png_error(png_ptr, "No IDATs written into file"); + ++#ifdef PNG_WRITE_APNG_SUPPORTED ++ if (png_ptr->num_frames_written != png_ptr->num_frames_to_write) ++ png_error(png_ptr, "Not enough frames written"); ++#endif ++ + #ifdef PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED + if (png_ptr->num_palette_max > png_ptr->num_palette) + png_benign_error(png_ptr, "Wrote palette index exceeding num_palette"); +@@ -2406,4 +2415,42 @@ + } + #endif /* SIMPLIFIED_WRITE_STDIO */ + #endif /* SIMPLIFIED_WRITE */ ++ ++#ifdef PNG_WRITE_APNG_SUPPORTED ++void PNGAPI ++png_write_frame_head(png_structp png_ptr, png_infop info_ptr, ++ png_bytepp row_pointers, png_uint_32 width, png_uint_32 height, ++ png_uint_32 x_offset, png_uint_32 y_offset, ++ png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op, ++ png_byte blend_op) ++{ ++ png_debug(1, "in png_write_frame_head"); ++ ++ /* there is a chance this has been set after png_write_info was called, ++ * so it would be set but not written. is there a way to be sure? */ ++ if ((info_ptr->valid & PNG_INFO_acTL) == 0) ++ png_error(png_ptr, "png_write_frame_head(): acTL not set"); ++ ++ png_write_reset(png_ptr); ++ ++ png_write_reinit(png_ptr, info_ptr, width, height); ++ ++ if ((png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN) == 0 || ++ png_ptr->num_frames_written != 0) ++ png_write_fcTL(png_ptr, width, height, x_offset, y_offset, ++ delay_num, delay_den, dispose_op, blend_op); ++ ++ PNG_UNUSED(row_pointers) ++} ++ ++void PNGAPI ++png_write_frame_tail(png_structp png_ptr, png_infop info_ptr) ++{ ++ png_debug(1, "in png_write_frame_tail"); ++ ++ png_ptr->num_frames_written++; ++ ++ PNG_UNUSED(info_ptr) ++} ++#endif /* WRITE_APNG */ + #endif /* WRITE */ +Index: pngpread.c +=================================================================== +--- pngpread.c ++++ pngpread.c +@@ -195,6 +195,89 @@ + + chunk_name = png_ptr->chunk_name; + ++#ifdef PNG_READ_APNG_SUPPORTED ++ if (png_ptr->num_frames_read > 0 && ++ png_ptr->num_frames_read < info_ptr->num_frames) ++ { ++ if (chunk_name == png_IDAT) ++ { ++ /* Discard trailing IDATs for the first frame */ ++ if ((png_ptr->mode & PNG_HAVE_fcTL) != 0 || ++ png_ptr->num_frames_read > 1) ++ png_error(png_ptr, "out of place IDAT"); ++ ++ PNG_PUSH_SAVE_BUFFER_IF_FULL ++ png_crc_finish(png_ptr, png_ptr->push_length); ++ png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; ++ } ++ ++ else if (chunk_name == png_fdAT) ++ { ++ PNG_PUSH_SAVE_BUFFER_IF_LT(4) ++ png_ensure_sequence_number(png_ptr, 4); ++ ++ if ((png_ptr->mode & PNG_HAVE_fcTL) == 0) ++ { ++ /* Discard trailing fdATs for frames other than the first */ ++ if (png_ptr->num_frames_read < 2) ++ png_error(png_ptr, "out of place fdAT"); + ++ PNG_PUSH_SAVE_BUFFER_IF_FULL ++ png_crc_finish(png_ptr, png_ptr->push_length); + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; -+ return; + } + + else @@ -389,25 +734,18 @@ diff -Naru libpng-1.6.39.org/pngpread.c libpng-1.6.39/pngpread.c + png_ptr->idat_size = png_ptr->push_length - 4; + png_ptr->mode |= PNG_HAVE_IDAT; + png_ptr->process_mode = PNG_READ_IDAT_MODE; -+ -+ return; + } + } + + else if (chunk_name == png_fcTL) + { -+ if (png_ptr->push_length + 4 > png_ptr->buffer_size) -+ { -+ png_push_save_buffer(png_ptr); -+ return; -+ } -+ ++ PNG_PUSH_SAVE_BUFFER_IF_FULL + png_read_reset(png_ptr); + png_ptr->mode &= ~PNG_HAVE_fcTL; + + png_handle_fcTL(png_ptr, info_ptr, png_ptr->push_length); + -+ if (!(png_ptr->mode & PNG_HAVE_fcTL)) ++ if ((png_ptr->mode & PNG_HAVE_fcTL) == 0) + png_error(png_ptr, "missing required fcTL chunk"); + + png_read_reinit(png_ptr, info_ptr); @@ -417,31 +755,34 @@ diff -Naru libpng-1.6.39.org/pngpread.c libpng-1.6.39/pngpread.c + (*(png_ptr->frame_info_fn))(png_ptr, png_ptr->num_frames_read); + + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; ++ } + -+ return; ++ else if (chunk_name == png_IEND) ++ { ++ PNG_PUSH_SAVE_BUFFER_IF_FULL ++ png_warning(png_ptr, "Number of actual frames fewer than expected"); ++ png_crc_finish(png_ptr, png_ptr->push_length); ++ png_ptr->process_mode = PNG_READ_DONE_MODE; ++ png_push_have_end(png_ptr, info_ptr); + } + + else + { -+ if (png_ptr->push_length + 4 > png_ptr->buffer_size) -+ { -+ png_push_save_buffer(png_ptr); -+ return; -+ } ++ PNG_PUSH_SAVE_BUFFER_IF_FULL + png_warning(png_ptr, "Skipped (ignored) a chunk " + "between APNG chunks"); ++ png_crc_finish(png_ptr, png_ptr->push_length); + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; -+ return; + } + + return; + } -+#endif /* PNG_READ_APNG_SUPPORTED */ ++#endif /* READ_APNG */ + if (chunk_name == png_IDAT) { if ((png_ptr->mode & PNG_AFTER_IDAT) != 0) -@@ -261,6 +361,9 @@ +@@ -261,6 +344,9 @@ else if (chunk_name == png_IDAT) { @@ -451,38 +792,28 @@ diff -Naru libpng-1.6.39.org/pngpread.c libpng-1.6.39/pngpread.c png_ptr->idat_size = png_ptr->push_length; png_ptr->process_mode = PNG_READ_IDAT_MODE; png_push_have_info(png_ptr, info_ptr); -@@ -406,6 +509,30 @@ - png_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length); +@@ -407,6 +493,20 @@ } #endif + +#ifdef PNG_READ_APNG_SUPPORTED + else if (chunk_name == png_acTL) + { -+ if (png_ptr->push_length + 4 > png_ptr->buffer_size) -+ { -+ png_push_save_buffer(png_ptr); -+ return; -+ } -+ ++ PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_acTL(png_ptr, info_ptr, png_ptr->push_length); + } + + else if (chunk_name == png_fcTL) + { -+ if (png_ptr->push_length + 4 > png_ptr->buffer_size) -+ { -+ png_push_save_buffer(png_ptr); -+ return; -+ } -+ ++ PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_fcTL(png_ptr, info_ptr, png_ptr->push_length); + } + -+#endif /* PNG_READ_APNG_SUPPORTED */ - ++#endif /* READ_APNG */ else { -@@ -539,7 +666,11 @@ + PNG_PUSH_SAVE_BUFFER_IF_FULL +@@ -539,7 +639,11 @@ png_byte chunk_tag[4]; /* TODO: this code can be commoned up with the same code in push_read */ @@ -494,14 +825,14 @@ diff -Naru libpng-1.6.39.org/pngpread.c libpng-1.6.39/pngpread.c png_push_fill_buffer(png_ptr, chunk_length, 4); png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length); png_reset_crc(png_ptr); -@@ -547,17 +678,64 @@ +@@ -547,17 +651,60 @@ png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag); png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; +#ifdef PNG_READ_APNG_SUPPORTED + if (png_ptr->chunk_name != png_fdAT && png_ptr->num_frames_read > 0) + { -+ if (png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) ++ if ((png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) != 0) + { + png_ptr->process_mode = PNG_READ_CHUNK_MODE; + if (png_ptr->frame_end_fn != NULL) @@ -513,11 +844,7 @@ diff -Naru libpng-1.6.39.org/pngpread.c libpng-1.6.39/pngpread.c + { + if (png_ptr->chunk_name == png_IEND) + png_error(png_ptr, "Not enough image data"); -+ if (png_ptr->push_length + 4 > png_ptr->buffer_size) -+ { -+ png_push_save_buffer(png_ptr); -+ return; -+ } ++ PNG_PUSH_SAVE_BUFFER_IF_FULL + png_warning(png_ptr, "Skipping (ignoring) a chunk between " + "APNG chunks"); + png_crc_finish(png_ptr, png_ptr->push_length); @@ -559,23 +886,24 @@ diff -Naru libpng-1.6.39.org/pngpread.c libpng-1.6.39/pngpread.c } if (png_ptr->idat_size != 0 && png_ptr->save_buffer_size != 0) -@@ -631,6 +809,15 @@ +@@ -631,6 +778,16 @@ if (!(buffer_length > 0) || buffer == NULL) png_error(png_ptr, "No IDAT data (internal error)"); +#ifdef PNG_READ_APNG_SUPPORTED + /* If the app is not APNG-aware, decode only the first frame */ -+ if (!(png_ptr->apng_flags & PNG_APNG_APP) && png_ptr->num_frames_read > 0) ++ if ((png_ptr->apng_flags & PNG_APNG_APP) == 0 && ++ png_ptr->num_frames_read > 0) + { -+ png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED; -+ return; ++ png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED; ++ return; + } +#endif + /* This routine must process all the data it has been given * before returning, calling the row callback as required to * handle the uncompressed results. -@@ -1085,6 +1272,18 @@ +@@ -1085,6 +1242,18 @@ png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer); } @@ -594,192 +922,173 @@ diff -Naru libpng-1.6.39.org/pngpread.c libpng-1.6.39/pngpread.c png_voidp PNGAPI png_get_progressive_ptr(png_const_structrp png_ptr) { -diff -Naru libpng-1.6.39.org/pngpriv.h libpng-1.6.39/pngpriv.h ---- libpng-1.6.39.org/pngpriv.h 2022-11-24 08:37:51.508052181 +0900 -+++ libpng-1.6.39/pngpriv.h 2022-11-24 08:41:17.785489740 +0900 -@@ -628,6 +628,10 @@ - #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000U /* Have another chunk after IDAT */ - /* 0x4000U (unused) */ - #define PNG_IS_READ_STRUCT 0x8000U /* Else is a write struct */ -+#ifdef PNG_APNG_SUPPORTED -+#define PNG_HAVE_acTL 0x10000U -+#define PNG_HAVE_fcTL 0x20000U -+#endif - - /* Flags for the transformations the PNG library does on the image data */ - #define PNG_BGR 0x0001U -@@ -864,6 +868,16 @@ - #define png_tRNS PNG_U32(116, 82, 78, 83) - #define png_zTXt PNG_U32(122, 84, 88, 116) +Index: pngset.c +=================================================================== +--- pngset.c ++++ pngset.c +@@ -280,6 +280,11 @@ + info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth); -+#ifdef PNG_APNG_SUPPORTED -+#define png_acTL PNG_U32( 97, 99, 84, 76) -+#define png_fcTL PNG_U32(102, 99, 84, 76) -+#define png_fdAT PNG_U32(102, 100, 65, 84) -+ -+/* For png_struct.apng_flags: */ -+#define PNG_FIRST_FRAME_HIDDEN 0x0001U -+#define PNG_APNG_APP 0x0002U -+#endif + info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width); + - /* The following will work on (signed char*) strings, whereas the get_uint_32 - * macro will fail on top-bit-set values because of the sign extension. - */ -@@ -1635,6 +1649,47 @@ - */ - #endif - +#ifdef PNG_APNG_SUPPORTED -+PNG_INTERNAL_FUNCTION(void,png_ensure_fcTL_is_valid,(png_structp png_ptr, -+ png_uint_32 width, png_uint_32 height, -+ png_uint_32 x_offset, png_uint_32 y_offset, -+ png_uint_16 delay_num, png_uint_16 delay_den, -+ png_byte dispose_op, png_byte blend_op), PNG_EMPTY); -+ -+#ifdef PNG_READ_APNG_SUPPORTED -+PNG_INTERNAL_FUNCTION(void,png_handle_acTL,(png_structp png_ptr, png_infop info_ptr, -+ png_uint_32 length),PNG_EMPTY); -+PNG_INTERNAL_FUNCTION(void,png_handle_fcTL,(png_structp png_ptr, png_infop info_ptr, -+ png_uint_32 length),PNG_EMPTY); -+PNG_INTERNAL_FUNCTION(void,png_handle_fdAT,(png_structp png_ptr, png_infop info_ptr, -+ png_uint_32 length),PNG_EMPTY); -+PNG_INTERNAL_FUNCTION(void,png_have_info,(png_structp png_ptr, png_infop info_ptr),PNG_EMPTY); -+PNG_INTERNAL_FUNCTION(void,png_ensure_sequence_number,(png_structp png_ptr, -+ png_uint_32 length),PNG_EMPTY); -+PNG_INTERNAL_FUNCTION(void,png_read_reset,(png_structp png_ptr),PNG_EMPTY); -+PNG_INTERNAL_FUNCTION(void,png_read_reinit,(png_structp png_ptr, -+ png_infop info_ptr),PNG_EMPTY); -+#ifdef PNG_PROGRESSIVE_READ_SUPPORTED -+PNG_INTERNAL_FUNCTION(void,png_progressive_read_reset,(png_structp png_ptr),PNG_EMPTY); -+#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ -+#endif /* PNG_READ_APNG_SUPPORTED */ -+ -+#ifdef PNG_WRITE_APNG_SUPPORTED -+PNG_INTERNAL_FUNCTION(void,png_write_acTL,(png_structp png_ptr, -+ png_uint_32 num_frames, png_uint_32 num_plays),PNG_EMPTY); -+PNG_INTERNAL_FUNCTION(void,png_write_fcTL,(png_structp png_ptr, -+ png_uint_32 width, png_uint_32 height, -+ png_uint_32 x_offset, png_uint_32 y_offset, -+ png_uint_16 delay_num, png_uint_16 delay_den, -+ png_byte dispose_op, png_byte blend_op),PNG_EMPTY); -+PNG_INTERNAL_FUNCTION(void,png_write_fdAT,(png_structp png_ptr, -+ png_const_bytep data, png_size_t length),PNG_EMPTY); -+PNG_INTERNAL_FUNCTION(void,png_write_reset,(png_structp png_ptr),PNG_EMPTY); -+PNG_INTERNAL_FUNCTION(void,png_write_reinit,(png_structp png_ptr, -+ png_infop info_ptr, png_uint_32 width, png_uint_32 height),PNG_EMPTY); -+#endif /* PNG_WRITE_APNG_SUPPORTED */ -+#endif /* PNG_APNG_SUPPORTED */ -+ - /* Added at libpng version 1.4.0 */ - #ifdef PNG_COLORSPACE_SUPPORTED - /* These internal functions are for maintaining the colorspace structure within -diff -Naru libpng-1.6.39.org/pngread.c libpng-1.6.39/pngread.c ---- libpng-1.6.39.org/pngread.c 2022-11-24 08:37:51.508052181 +0900 -+++ libpng-1.6.39/pngread.c 2022-11-24 08:41:17.786489737 +0900 -@@ -161,6 +161,9 @@ - - else if (chunk_name == png_IDAT) - { -+#ifdef PNG_READ_APNG_SUPPORTED -+ png_have_info(png_ptr, info_ptr); ++ /* for non-animated png. this may be overwritten from an acTL chunk later */ ++ info_ptr->num_frames = 1; +#endif - png_ptr->idat_size = length; - break; - } -@@ -255,6 +258,17 @@ - png_handle_iTXt(png_ptr, info_ptr, length); - #endif + } -+#ifdef PNG_READ_APNG_SUPPORTED -+ else if (chunk_name == png_acTL) -+ png_handle_acTL(png_ptr, info_ptr, length); -+ -+ else if (chunk_name == png_fcTL) -+ png_handle_fcTL(png_ptr, info_ptr, length); -+ -+ else if (chunk_name == png_fdAT) -+ png_handle_fdAT(png_ptr, info_ptr, length); -+#endif -+ - else - png_handle_unknown(png_ptr, info_ptr, length, - PNG_HANDLE_CHUNK_AS_DEFAULT); -@@ -262,6 +276,72 @@ + #ifdef PNG_oFFs_SUPPORTED +@@ -1149,6 +1154,146 @@ } - #endif /* SEQUENTIAL_READ */ + #endif /* sPLT */ -+#ifdef PNG_READ_APNG_SUPPORTED -+void PNGAPI -+png_read_frame_head(png_structp png_ptr, png_infop info_ptr) ++#ifdef PNG_APNG_SUPPORTED ++png_uint_32 PNGAPI ++png_set_acTL(png_structp png_ptr, png_infop info_ptr, ++ png_uint_32 num_frames, png_uint_32 num_plays) +{ -+ png_byte have_chunk_after_DAT; /* after IDAT or after fdAT */ ++ png_debug1(1, "in %s storage function", "acTL"); + -+ png_debug(0, "Reading frame head"); ++ if (png_ptr == NULL || info_ptr == NULL) ++ { ++ png_warning(png_ptr, ++ "Call to png_set_acTL() with NULL png_ptr " ++ "or info_ptr ignored"); ++ return (0); ++ } ++ if (num_frames == 0) ++ { ++ png_warning(png_ptr, ++ "Ignoring attempt to set acTL with num_frames zero"); ++ return (0); ++ } ++ if (num_frames > PNG_UINT_31_MAX) ++ { ++ png_warning(png_ptr, ++ "Ignoring attempt to set acTL with num_frames > 2^31-1"); ++ return (0); ++ } ++ if (num_plays > PNG_UINT_31_MAX) ++ { ++ png_warning(png_ptr, ++ "Ignoring attempt to set acTL with num_plays > 2^31-1"); ++ return (0); ++ } + -+ if (!(png_ptr->mode & PNG_HAVE_acTL)) -+ png_error(png_ptr, "attempt to png_read_frame_head() but " -+ "no acTL present"); ++ info_ptr->num_frames = num_frames; ++ info_ptr->num_plays = num_plays; + -+ /* do nothing for the main IDAT */ -+ if (png_ptr->num_frames_read == 0) -+ return; ++ info_ptr->valid |= PNG_INFO_acTL; + -+ png_read_reset(png_ptr); -+ png_ptr->flags &= ~PNG_FLAG_ROW_INIT; -+ png_ptr->mode &= ~PNG_HAVE_fcTL; ++ return (1); ++} + -+ have_chunk_after_DAT = 0; -+ for (;;) ++/* delay_num and delay_den can hold any 16-bit values including zero */ ++png_uint_32 PNGAPI ++png_set_next_frame_fcTL(png_structp png_ptr, png_infop info_ptr, ++ png_uint_32 width, png_uint_32 height, ++ png_uint_32 x_offset, png_uint_32 y_offset, ++ png_uint_16 delay_num, png_uint_16 delay_den, ++ png_byte dispose_op, png_byte blend_op) ++{ ++ png_debug1(1, "in %s storage function", "fcTL"); ++ ++ if (png_ptr == NULL || info_ptr == NULL) + { -+ png_uint_32 length = png_read_chunk_header(png_ptr); ++ png_warning(png_ptr, ++ "Call to png_set_fcTL() with NULL png_ptr or info_ptr " ++ "ignored"); ++ return (0); ++ } + -+ if (png_ptr->chunk_name == png_IDAT) -+ { -+ /* discard trailing IDATs for the first frame */ -+ if (have_chunk_after_DAT || png_ptr->num_frames_read > 1) -+ png_error(png_ptr, "png_read_frame_head(): out of place IDAT"); -+ png_crc_finish(png_ptr, length); -+ } ++ png_ensure_fcTL_is_valid(png_ptr, width, height, x_offset, y_offset, ++ delay_num, delay_den, dispose_op, blend_op); + -+ else if (png_ptr->chunk_name == png_fcTL) ++ if (blend_op == PNG_BLEND_OP_OVER) ++ { ++ if ((png_ptr->color_type & PNG_COLOR_MASK_ALPHA) == 0 && ++ png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) == 0) + { -+ png_handle_fcTL(png_ptr, info_ptr, length); -+ have_chunk_after_DAT = 1; ++ png_warning(png_ptr, "PNG_BLEND_OP_OVER is meaningless " ++ "and wasteful for opaque images, ignored"); ++ blend_op = PNG_BLEND_OP_SOURCE; + } ++ } + -+ else if (png_ptr->chunk_name == png_fdAT) -+ { -+ png_ensure_sequence_number(png_ptr, length); ++ info_ptr->next_frame_width = width; ++ info_ptr->next_frame_height = height; ++ info_ptr->next_frame_x_offset = x_offset; ++ info_ptr->next_frame_y_offset = y_offset; ++ info_ptr->next_frame_delay_num = delay_num; ++ info_ptr->next_frame_delay_den = delay_den; ++ info_ptr->next_frame_dispose_op = dispose_op; ++ info_ptr->next_frame_blend_op = blend_op; + -+ /* discard trailing fdATs for frames other than the first */ -+ if (!have_chunk_after_DAT && png_ptr->num_frames_read > 1) -+ png_crc_finish(png_ptr, length - 4); -+ else if(png_ptr->mode & PNG_HAVE_fcTL) -+ { -+ png_ptr->idat_size = length - 4; -+ png_ptr->mode |= PNG_HAVE_IDAT; ++ info_ptr->valid |= PNG_INFO_fcTL; + -+ break; -+ } -+ else -+ png_error(png_ptr, "png_read_frame_head(): out of place fdAT"); -+ } -+ else -+ { -+ png_warning(png_ptr, "Skipped (ignored) a chunk " -+ "between APNG chunks"); -+ png_crc_finish(png_ptr, length); -+ } -+ } ++ return (1); +} -+#endif /* PNG_READ_APNG_SUPPORTED */ + - /* Optional call to update the users info_ptr structure */ - void PNGAPI - png_read_update_info(png_structrp png_ptr, png_inforp info_ptr) -diff -Naru libpng-1.6.39.org/pngrutil.c libpng-1.6.39/pngrutil.c ---- libpng-1.6.39.org/pngrutil.c 2022-11-24 08:37:51.510052177 +0900 -+++ libpng-1.6.39/pngrutil.c 2022-11-24 08:41:17.787489734 +0900 ++void /* PRIVATE */ ++png_ensure_fcTL_is_valid(png_structp png_ptr, ++ png_uint_32 width, png_uint_32 height, ++ png_uint_32 x_offset, png_uint_32 y_offset, ++ png_uint_16 delay_num, png_uint_16 delay_den, ++ png_byte dispose_op, png_byte blend_op) ++{ ++ if (width == 0 || width > PNG_UINT_31_MAX) ++ png_error(png_ptr, "invalid width in fcTL (0 or > 2^31-1)"); ++ if (height == 0 || height > PNG_UINT_31_MAX) ++ png_error(png_ptr, "invalid height in fcTL (0 or > 2^31-1)"); ++ if (x_offset > PNG_UINT_31_MAX) ++ png_error(png_ptr, "invalid x_offset in fcTL (> 2^31-1)"); ++ if (y_offset > PNG_UINT_31_MAX) ++ png_error(png_ptr, "invalid y_offset in fcTL (> 2^31-1)"); ++ if (width + x_offset > png_ptr->first_frame_width || ++ height + y_offset > png_ptr->first_frame_height) ++ png_error(png_ptr, "dimensions of a frame are greater than " ++ "the ones in IHDR"); ++ ++ if (dispose_op != PNG_DISPOSE_OP_NONE && ++ dispose_op != PNG_DISPOSE_OP_BACKGROUND && ++ dispose_op != PNG_DISPOSE_OP_PREVIOUS) ++ png_error(png_ptr, "invalid dispose_op in fcTL"); ++ ++ if (blend_op != PNG_BLEND_OP_SOURCE && ++ blend_op != PNG_BLEND_OP_OVER) ++ png_error(png_ptr, "invalid blend_op in fcTL"); ++ ++ PNG_UNUSED(delay_num) ++ PNG_UNUSED(delay_den) ++} ++ ++png_uint_32 PNGAPI ++png_set_first_frame_is_hidden(png_structp png_ptr, png_infop info_ptr, ++ png_byte is_hidden) ++{ ++ png_debug(1, "in png_first_frame_is_hidden()"); ++ ++ if (png_ptr == NULL) ++ return 0; ++ ++ if (is_hidden != 0) ++ png_ptr->apng_flags |= PNG_FIRST_FRAME_HIDDEN; ++ else ++ png_ptr->apng_flags &= ~PNG_FIRST_FRAME_HIDDEN; ++ ++ PNG_UNUSED(info_ptr) ++ ++ return 1; ++} ++#endif /* APNG */ ++ + #ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED + static png_byte + check_location(png_const_structrp png_ptr, int location) +Index: pngrutil.c +=================================================================== +--- pngrutil.c ++++ pngrutil.c @@ -864,6 +864,11 @@ filter_type = buf[11]; interlace_type = buf[12]; @@ -792,7 +1101,7 @@ diff -Naru libpng-1.6.39.org/pngrutil.c libpng-1.6.39/pngrutil.c /* Set internal variables */ png_ptr->width = width; png_ptr->height = height; -@@ -2858,6 +2863,179 @@ +@@ -2858,6 +2863,180 @@ } #endif @@ -807,17 +1116,17 @@ diff -Naru libpng-1.6.39.org/pngrutil.c libpng-1.6.39/pngrutil.c + + png_debug(1, "in png_handle_acTL"); + -+ if (!(png_ptr->mode & PNG_HAVE_IHDR)) ++ if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + { + png_error(png_ptr, "Missing IHDR before acTL"); + } -+ else if (png_ptr->mode & PNG_HAVE_IDAT) ++ else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) + { + png_warning(png_ptr, "Invalid acTL after IDAT skipped"); + png_crc_finish(png_ptr, length); + return; + } -+ else if (png_ptr->mode & PNG_HAVE_acTL) ++ else if ((png_ptr->mode & PNG_HAVE_acTL) != 0) + { + png_warning(png_ptr, "Duplicate acTL skipped"); + png_crc_finish(png_ptr, length); @@ -838,7 +1147,7 @@ diff -Naru libpng-1.6.39.org/pngrutil.c libpng-1.6.39/pngrutil.c + + /* the set function will do error checking on num_frames */ + didSet = png_set_acTL(png_ptr, info_ptr, num_frames, num_plays); -+ if(didSet) ++ if (didSet != 0) + png_ptr->mode |= PNG_HAVE_acTL; +} + @@ -859,11 +1168,11 @@ diff -Naru libpng-1.6.39.org/pngrutil.c libpng-1.6.39/pngrutil.c + + png_ensure_sequence_number(png_ptr, length); + -+ if (!(png_ptr->mode & PNG_HAVE_IHDR)) ++ if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + { + png_error(png_ptr, "Missing IHDR before fcTL"); + } -+ else if (png_ptr->mode & PNG_HAVE_IDAT) ++ else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) + { + /* for any frames other then the first this message may be misleading, + * but correct. PNG_HAVE_IDAT is unset before the frame head is read @@ -872,7 +1181,7 @@ diff -Naru libpng-1.6.39.org/pngrutil.c libpng-1.6.39/pngrutil.c + png_crc_finish(png_ptr, length-4); + return; + } -+ else if (png_ptr->mode & PNG_HAVE_fcTL) ++ else if ((png_ptr->mode & PNG_HAVE_fcTL) != 0) + { + png_warning(png_ptr, "Duplicate fcTL within one frame skipped"); + png_crc_finish(png_ptr, length-4); @@ -927,7 +1236,8 @@ diff -Naru libpng-1.6.39.org/pngrutil.c libpng-1.6.39/pngrutil.c +void /* PRIVATE */ +png_have_info(png_structp png_ptr, png_infop info_ptr) +{ -+ if((info_ptr->valid & PNG_INFO_acTL) && !(info_ptr->valid & PNG_INFO_fcTL)) ++ if ((info_ptr->valid & PNG_INFO_acTL) != 0 && ++ (info_ptr->valid & PNG_INFO_fcTL) == 0) + { + png_ptr->apng_flags |= PNG_FIRST_FRAME_HIDDEN; + info_ptr->num_frames++; @@ -967,23 +1277,35 @@ diff -Naru libpng-1.6.39.org/pngrutil.c libpng-1.6.39/pngrutil.c + + png_ptr->next_seq_num++; +} -+#endif /* PNG_READ_APNG_SUPPORTED */ ++#endif /* READ_APNG */ + #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED /* Utility function for png_handle_unknown; set up png_ptr::unknown_chunk */ static int -@@ -4166,7 +4344,38 @@ - { - uInt avail_in; - png_bytep buffer; +@@ -3163,7 +3342,11 @@ + if (PNG_USER_CHUNK_MALLOC_MAX < limit) + limit = PNG_USER_CHUNK_MALLOC_MAX; + # endif +#ifdef PNG_READ_APNG_SUPPORTED -+ png_uint_32 bytes_to_skip = 0; ++ if (png_ptr->chunk_name == png_IDAT || png_ptr->chunk_name == png_fdAT) ++#else + if (png_ptr->chunk_name == png_IDAT) ++#endif + { + png_alloc_size_t idat_limit = PNG_UINT_31_MAX; + size_t row_factor = +@@ -4167,6 +4350,38 @@ + uInt avail_in; + png_bytep buffer; + ++#ifdef PNG_READ_APNG_SUPPORTED ++ png_uint_32 bytes_to_skip = 0; + + while (png_ptr->idat_size == 0 || bytes_to_skip != 0) + { + png_crc_finish(png_ptr, bytes_to_skip); + bytes_to_skip = 0; - ++ + png_ptr->idat_size = png_read_chunk_header(png_ptr); + if (png_ptr->num_frames_read == 0) + { @@ -1011,16 +1333,15 @@ diff -Naru libpng-1.6.39.org/pngrutil.c libpng-1.6.39/pngrutil.c while (png_ptr->idat_size == 0) { png_crc_finish(png_ptr, 0); -@@ -4178,7 +4387,7 @@ +@@ -4178,6 +4393,7 @@ if (png_ptr->chunk_name != png_IDAT) png_error(png_ptr, "Not enough image data"); } -- -+#endif /* PNG_READ_APNG_SUPPORTED */ ++#endif /* READ_APNG */ + avail_in = png_ptr->IDAT_read_size; - if (avail_in > png_ptr->idat_size) -@@ -4241,6 +4450,9 @@ +@@ -4241,6 +4457,9 @@ png_ptr->mode |= PNG_AFTER_IDAT; png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED; @@ -1030,7 +1351,7 @@ diff -Naru libpng-1.6.39.org/pngrutil.c libpng-1.6.39/pngrutil.c if (png_ptr->zstream.avail_in > 0 || png_ptr->idat_size > 0) png_chunk_benign_error(png_ptr, "Extra compressed data"); -@@ -4678,4 +4890,80 @@ +@@ -4678,4 +4897,80 @@ png_ptr->flags |= PNG_FLAG_ROW_INIT; } @@ -1056,7 +1377,7 @@ diff -Naru libpng-1.6.39.org/pngrutil.c libpng-1.6.39/pngrutil.c + png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width); + png_ptr->info_rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, + png_ptr->width); -+ if (png_ptr->prev_row) ++ if (png_ptr->prev_row != NULL) + memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1); +} + @@ -1066,23 +1387,23 @@ diff -Naru libpng-1.6.39.org/pngrutil.c libpng-1.6.39/pngrutil.c +png_progressive_read_reset(png_structp png_ptr) +{ +#ifdef PNG_READ_INTERLACING_SUPPORTED -+ /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ ++ /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + -+ /* Start of interlace block */ -+ const int png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; ++ /* Start of interlace block */ ++ static const png_byte png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; + + /* Offset to next interlace block */ -+ const int png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; ++ static const png_byte png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; + + /* Start of interlace block in the y direction */ -+ const int png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1}; ++ static const png_byte png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1}; + + /* Offset to next interlace block in the y direction */ -+ const int png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; ++ static const png_byte png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; + -+ if (png_ptr->interlaced) ++ if (png_ptr->interlaced != 0) + { -+ if (!(png_ptr->transformations & PNG_INTERLACE)) ++ if ((png_ptr->transformations & PNG_INTERLACE) == 0) + png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 - + png_pass_ystart[0]) / png_pass_yinc[0]; + else @@ -1094,7 +1415,7 @@ diff -Naru libpng-1.6.39.org/pngrutil.c libpng-1.6.39/pngrutil.c + png_pass_inc[png_ptr->pass]; + } + else -+#endif /* PNG_READ_INTERLACING_SUPPORTED */ ++#endif /* READ_INTERLACING */ + { + png_ptr->num_rows = png_ptr->height; + png_ptr->iwidth = png_ptr->width; @@ -1108,424 +1429,13 @@ diff -Naru libpng-1.6.39.org/pngrutil.c libpng-1.6.39/pngrutil.c + png_ptr->zstream.avail_out = (uInt)PNG_ROWBYTES(png_ptr->pixel_depth, + png_ptr->iwidth) + 1; +} -+#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ -+#endif /* PNG_READ_APNG_SUPPORTED */ ++#endif /* PROGRESSIVE_READ */ ++#endif /* READ_APNG */ #endif /* READ */ -diff -Naru libpng-1.6.39.org/pngset.c libpng-1.6.39/pngset.c ---- libpng-1.6.39.org/pngset.c 2022-11-24 08:37:51.510052177 +0900 -+++ libpng-1.6.39/pngset.c 2022-11-24 08:41:17.787489734 +0900 -@@ -288,6 +288,11 @@ - info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth); - - info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width); -+ -+#ifdef PNG_APNG_SUPPORTED -+ /* for non-animated png. this may be overwritten from an acTL chunk later */ -+ info_ptr->num_frames = 1; -+#endif - } - - #ifdef PNG_oFFs_SUPPORTED -@@ -1161,6 +1166,147 @@ - } - #endif /* sPLT */ - -+#ifdef PNG_APNG_SUPPORTED -+png_uint_32 PNGAPI -+png_set_acTL(png_structp png_ptr, png_infop info_ptr, -+ png_uint_32 num_frames, png_uint_32 num_plays) -+{ -+ png_debug1(1, "in %s storage function", "acTL"); -+ -+ if (png_ptr == NULL || info_ptr == NULL) -+ { -+ png_warning(png_ptr, -+ "Call to png_set_acTL() with NULL png_ptr " -+ "or info_ptr ignored"); -+ return (0); -+ } -+ if (num_frames == 0) -+ { -+ png_warning(png_ptr, -+ "Ignoring attempt to set acTL with num_frames zero"); -+ return (0); -+ } -+ if (num_frames > PNG_UINT_31_MAX) -+ { -+ png_warning(png_ptr, -+ "Ignoring attempt to set acTL with num_frames > 2^31-1"); -+ return (0); -+ } -+ if (num_plays > PNG_UINT_31_MAX) -+ { -+ png_warning(png_ptr, -+ "Ignoring attempt to set acTL with num_plays " -+ "> 2^31-1"); -+ return (0); -+ } -+ -+ info_ptr->num_frames = num_frames; -+ info_ptr->num_plays = num_plays; -+ -+ info_ptr->valid |= PNG_INFO_acTL; -+ -+ return (1); -+} -+ -+/* delay_num and delay_den can hold any 16-bit values including zero */ -+png_uint_32 PNGAPI -+png_set_next_frame_fcTL(png_structp png_ptr, png_infop info_ptr, -+ png_uint_32 width, png_uint_32 height, -+ png_uint_32 x_offset, png_uint_32 y_offset, -+ png_uint_16 delay_num, png_uint_16 delay_den, -+ png_byte dispose_op, png_byte blend_op) -+{ -+ png_debug1(1, "in %s storage function", "fcTL"); -+ -+ if (png_ptr == NULL || info_ptr == NULL) -+ { -+ png_warning(png_ptr, -+ "Call to png_set_fcTL() with NULL png_ptr or info_ptr " -+ "ignored"); -+ return (0); -+ } -+ -+ png_ensure_fcTL_is_valid(png_ptr, width, height, x_offset, y_offset, -+ delay_num, delay_den, dispose_op, blend_op); -+ -+ if (blend_op == PNG_BLEND_OP_OVER) -+ { -+ if (!(png_ptr->color_type & PNG_COLOR_MASK_ALPHA) && -+ !(png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))) -+ { -+ png_warning(png_ptr, "PNG_BLEND_OP_OVER is meaningless " -+ "and wasteful for opaque images, ignored"); -+ blend_op = PNG_BLEND_OP_SOURCE; -+ } -+ } -+ -+ info_ptr->next_frame_width = width; -+ info_ptr->next_frame_height = height; -+ info_ptr->next_frame_x_offset = x_offset; -+ info_ptr->next_frame_y_offset = y_offset; -+ info_ptr->next_frame_delay_num = delay_num; -+ info_ptr->next_frame_delay_den = delay_den; -+ info_ptr->next_frame_dispose_op = dispose_op; -+ info_ptr->next_frame_blend_op = blend_op; -+ -+ info_ptr->valid |= PNG_INFO_fcTL; -+ -+ return (1); -+} -+ -+void /* PRIVATE */ -+png_ensure_fcTL_is_valid(png_structp png_ptr, -+ png_uint_32 width, png_uint_32 height, -+ png_uint_32 x_offset, png_uint_32 y_offset, -+ png_uint_16 delay_num, png_uint_16 delay_den, -+ png_byte dispose_op, png_byte blend_op) -+{ -+ if (width == 0 || width > PNG_UINT_31_MAX) -+ png_error(png_ptr, "invalid width in fcTL (> 2^31-1)"); -+ if (height == 0 || height > PNG_UINT_31_MAX) -+ png_error(png_ptr, "invalid height in fcTL (> 2^31-1)"); -+ if (x_offset > PNG_UINT_31_MAX) -+ png_error(png_ptr, "invalid x_offset in fcTL (> 2^31-1)"); -+ if (y_offset > PNG_UINT_31_MAX) -+ png_error(png_ptr, "invalid y_offset in fcTL (> 2^31-1)"); -+ if (width + x_offset > png_ptr->first_frame_width || -+ height + y_offset > png_ptr->first_frame_height) -+ png_error(png_ptr, "dimensions of a frame are greater than" -+ "the ones in IHDR"); -+ -+ if (dispose_op != PNG_DISPOSE_OP_NONE && -+ dispose_op != PNG_DISPOSE_OP_BACKGROUND && -+ dispose_op != PNG_DISPOSE_OP_PREVIOUS) -+ png_error(png_ptr, "invalid dispose_op in fcTL"); -+ -+ if (blend_op != PNG_BLEND_OP_SOURCE && -+ blend_op != PNG_BLEND_OP_OVER) -+ png_error(png_ptr, "invalid blend_op in fcTL"); -+ -+ PNG_UNUSED(delay_num) -+ PNG_UNUSED(delay_den) -+} -+ -+png_uint_32 PNGAPI -+png_set_first_frame_is_hidden(png_structp png_ptr, png_infop info_ptr, -+ png_byte is_hidden) -+{ -+ png_debug(1, "in png_first_frame_is_hidden()"); -+ -+ if (png_ptr == NULL) -+ return 0; -+ -+ if (is_hidden) -+ png_ptr->apng_flags |= PNG_FIRST_FRAME_HIDDEN; -+ else -+ png_ptr->apng_flags &= ~PNG_FIRST_FRAME_HIDDEN; -+ -+ PNG_UNUSED(info_ptr) -+ -+ return 1; -+} -+#endif /* PNG_APNG_SUPPORTED */ -+ - #ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED - static png_byte - check_location(png_const_structrp png_ptr, int location) -diff -Naru libpng-1.6.39.org/pngstruct.h libpng-1.6.39/pngstruct.h ---- libpng-1.6.39.org/pngstruct.h 2022-11-24 08:37:51.510052177 +0900 -+++ libpng-1.6.39/pngstruct.h 2022-11-24 08:41:17.787489734 +0900 -@@ -399,6 +399,27 @@ - png_byte filter_type; - #endif - -+#ifdef PNG_APNG_SUPPORTED -+ png_uint_32 apng_flags; -+ png_uint_32 next_seq_num; /* next fcTL/fdAT chunk sequence number */ -+ png_uint_32 first_frame_width; -+ png_uint_32 first_frame_height; -+ -+#ifdef PNG_READ_APNG_SUPPORTED -+ png_uint_32 num_frames_read; /* incremented after all image data of */ -+ /* a frame is read */ -+#ifdef PNG_PROGRESSIVE_READ_SUPPORTED -+ png_progressive_frame_ptr frame_info_fn; /* frame info read callback */ -+ png_progressive_frame_ptr frame_end_fn; /* frame data read callback */ -+#endif -+#endif -+ -+#ifdef PNG_WRITE_APNG_SUPPORTED -+ png_uint_32 num_frames_to_write; -+ png_uint_32 num_frames_written; -+#endif -+#endif /* PNG_APNG_SUPPORTED */ -+ - /* New members added in libpng-1.2.0 */ - - /* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */ -diff -Naru libpng-1.6.39.org/pngtest.c libpng-1.6.39/pngtest.c ---- libpng-1.6.39.org/pngtest.c 2022-11-24 08:37:51.510052177 +0900 -+++ libpng-1.6.39/pngtest.c 2022-11-24 08:41:17.787489734 +0900 -@@ -875,6 +875,10 @@ - volatile int num_passes; - int pass; - int bit_depth, color_type; -+#ifdef PNG_APNG_SUPPORTED -+ png_uint_32 num_frames; -+ png_uint_32 num_plays; -+#endif - - row_buf = NULL; - error_parameters.file_name = inname; -@@ -1383,6 +1387,22 @@ - } - } - #endif -+ -+#ifdef PNG_APNG_SUPPORTED -+ if (png_get_valid(read_ptr, read_info_ptr, PNG_INFO_acTL)) -+ { -+ if (png_get_acTL(read_ptr, read_info_ptr, &num_frames, &num_plays)) -+ { -+ png_byte is_hidden; -+ pngtest_debug2("Handling acTL chunks (frames %ld, plays %ld)", -+ num_frames, num_plays); -+ png_set_acTL(write_ptr, write_info_ptr, num_frames, num_plays); -+ is_hidden = png_get_first_frame_is_hidden(read_ptr, read_info_ptr); -+ png_set_first_frame_is_hidden(write_ptr, write_info_ptr, is_hidden); -+ } -+ } -+#endif -+ - #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED - { - png_unknown_chunkp unknowns; -@@ -1463,6 +1483,110 @@ - t_misc += (t_stop - t_start); - t_start = t_stop; - #endif -+#ifdef PNG_APNG_SUPPORTED -+ if (png_get_valid(read_ptr, read_info_ptr, PNG_INFO_acTL)) -+ { -+ png_uint_32 frame; -+ for (frame = 0; frame < num_frames; frame++) -+ { -+ png_uint_32 frame_width; -+ png_uint_32 frame_height; -+ png_uint_32 x_offset; -+ png_uint_32 y_offset; -+ png_uint_16 delay_num; -+ png_uint_16 delay_den; -+ png_byte dispose_op; -+ png_byte blend_op; -+ png_read_frame_head(read_ptr, read_info_ptr); -+ if (png_get_valid(read_ptr, read_info_ptr, PNG_INFO_fcTL)) -+ { -+ png_get_next_frame_fcTL(read_ptr, read_info_ptr, -+ &frame_width, &frame_height, -+ &x_offset, &y_offset, -+ &delay_num, &delay_den, -+ &dispose_op, &blend_op); -+ } -+ else -+ { -+ frame_width = width; -+ frame_height = height; -+ x_offset = 0; -+ y_offset = 0; -+ delay_num = 1; -+ delay_den = 1; -+ dispose_op = PNG_DISPOSE_OP_NONE; -+ blend_op = PNG_BLEND_OP_SOURCE; -+ } -+#ifdef PNG_WRITE_APNG_SUPPORTED -+ png_write_frame_head(write_ptr, write_info_ptr, (png_bytepp)&row_buf, -+ frame_width, frame_height, -+ x_offset, y_offset, -+ delay_num, delay_den, -+ dispose_op, blend_op); -+#endif -+ for (pass = 0; pass < num_passes; pass++) -+ { -+# ifdef calc_pass_height -+ png_uint_32 pass_height; -+ -+ if (num_passes == 7) /* interlaced */ -+ { -+ if (PNG_PASS_COLS(frame_width, pass) > 0) -+ pass_height = PNG_PASS_ROWS(frame_height, pass); -+ -+ else -+ pass_height = 0; -+ } -+ -+ else /* not interlaced */ -+ pass_height = frame_height; -+# else -+# define pass_height frame_height -+# endif -+ -+ pngtest_debug1("Writing row data for pass %d", pass); -+ for (y = 0; y < pass_height; y++) -+ { -+#ifndef SINGLE_ROWBUF_ALLOC -+ pngtest_debug2("Allocating row buffer (pass %d, y = %u)...", pass, y); -+ -+ row_buf = (png_bytep)png_malloc(read_ptr, -+ png_get_rowbytes(read_ptr, read_info_ptr)); -+ -+ pngtest_debug2("\t0x%08lx (%lu bytes)", (unsigned long)row_buf, -+ (unsigned long)png_get_rowbytes(read_ptr, read_info_ptr)); -+ -+#endif /* !SINGLE_ROWBUF_ALLOC */ -+ png_read_rows(read_ptr, (png_bytepp)&row_buf, NULL, 1); -+ -+#ifdef PNG_WRITE_SUPPORTED -+#ifdef PNGTEST_TIMING -+ t_stop = (float)clock(); -+ t_decode += (t_stop - t_start); -+ t_start = t_stop; -+#endif -+ png_write_rows(write_ptr, (png_bytepp)&row_buf, 1); -+#ifdef PNGTEST_TIMING -+ t_stop = (float)clock(); -+ t_encode += (t_stop - t_start); -+ t_start = t_stop; -+#endif -+#endif /* PNG_WRITE_SUPPORTED */ -+ -+#ifndef SINGLE_ROWBUF_ALLOC -+ pngtest_debug2("Freeing row buffer (pass %d, y = %u)", pass, y); -+ png_free(read_ptr, row_buf); -+ row_buf = NULL; -+#endif /* !SINGLE_ROWBUF_ALLOC */ -+ } -+ } -+#ifdef PNG_WRITE_APNG_SUPPORTED -+ png_write_frame_tail(write_ptr, write_info_ptr); -+#endif -+ } -+ } -+ else -+#endif - for (pass = 0; pass < num_passes; pass++) - { - # ifdef calc_pass_height -diff -Naru libpng-1.6.39.org/pngwrite.c libpng-1.6.39/pngwrite.c ---- libpng-1.6.39.org/pngwrite.c 2022-11-24 08:37:51.511052176 +0900 -+++ libpng-1.6.39/pngwrite.c 2022-11-24 08:41:17.787489734 +0900 -@@ -128,6 +128,10 @@ - * the application continues writing the PNG. So check the 'invalid' - * flag here too. - */ -+#ifdef PNG_WRITE_APNG_SUPPORTED -+ if (info_ptr->valid & PNG_INFO_acTL) -+ png_write_acTL(png_ptr, info_ptr->num_frames, info_ptr->num_plays); -+#endif - #ifdef PNG_GAMMA_SUPPORTED - # ifdef PNG_WRITE_gAMA_SUPPORTED - if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 && -@@ -370,6 +374,11 @@ - png_benign_error(png_ptr, "Wrote palette index exceeding num_palette"); - #endif - -+#ifdef PNG_WRITE_APNG_SUPPORTED -+ if (png_ptr->num_frames_written != png_ptr->num_frames_to_write) -+ png_error(png_ptr, "Not enough frames written"); -+#endif -+ - /* See if user wants us to write information chunks */ - if (info_ptr != NULL) - { -@@ -1471,6 +1480,43 @@ - } - #endif - -+#ifdef PNG_WRITE_APNG_SUPPORTED -+void PNGAPI -+png_write_frame_head(png_structp png_ptr, png_infop info_ptr, -+ png_bytepp row_pointers, png_uint_32 width, png_uint_32 height, -+ png_uint_32 x_offset, png_uint_32 y_offset, -+ png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op, -+ png_byte blend_op) -+{ -+ png_debug(1, "in png_write_frame_head"); -+ -+ /* there is a chance this has been set after png_write_info was called, -+ * so it would be set but not written. is there a way to be sure? */ -+ if (!(info_ptr->valid & PNG_INFO_acTL)) -+ png_error(png_ptr, "png_write_frame_head(): acTL not set"); -+ -+ png_write_reset(png_ptr); -+ -+ png_write_reinit(png_ptr, info_ptr, width, height); -+ -+ if ( !(png_ptr->num_frames_written == 0 && -+ (png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN) ) ) -+ png_write_fcTL(png_ptr, width, height, x_offset, y_offset, -+ delay_num, delay_den, dispose_op, blend_op); -+ -+ PNG_UNUSED(row_pointers) -+} -+ -+void PNGAPI -+png_write_frame_tail(png_structp png_ptr, png_infop info_ptr) -+{ -+ png_debug(1, "in png_write_frame_tail"); -+ -+ png_ptr->num_frames_written++; -+ -+ PNG_UNUSED(info_ptr) -+} -+#endif /* PNG_WRITE_APNG_SUPPORTED */ - - #ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED - /* Initialize the write structure - general purpose utility. */ -diff -Naru libpng-1.6.39.org/pngwutil.c libpng-1.6.39/pngwutil.c ---- libpng-1.6.39.org/pngwutil.c 2022-11-24 08:37:51.511052176 +0900 -+++ libpng-1.6.39/pngwutil.c 2022-11-24 08:41:17.788489731 +0900 +Index: pngwutil.c +=================================================================== +--- pngwutil.c ++++ pngwutil.c @@ -821,6 +821,11 @@ /* Write the chunk */ png_write_complete_chunk(png_ptr, png_IHDR, buf, 13); @@ -1538,27 +1448,25 @@ diff -Naru libpng-1.6.39.org/pngwutil.c libpng-1.6.39/pngwutil.c if ((png_ptr->do_filter) == PNG_NO_FILTERS) { if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE || -@@ -1002,8 +1007,17 @@ - optimize_cmf(data, png_image_size(png_ptr)); +@@ -1003,7 +1008,17 @@ #endif -- if (size > 0) -- png_write_complete_chunk(png_ptr, png_IDAT, data, size); -+ if (size > 0) + if (size > 0) +#ifdef PNG_WRITE_APNG_SUPPORTED -+ { -+ if (png_ptr->num_frames_written == 0) ++ { ++ if (png_ptr->num_frames_written == 0) +#endif -+ png_write_complete_chunk(png_ptr, png_IDAT, data, size); + png_write_complete_chunk(png_ptr, png_IDAT, data, size); +#ifdef PNG_WRITE_APNG_SUPPORTED -+ else -+ png_write_fdAT(png_ptr, data, size); -+ } -+#endif /* PNG_WRITE_APNG_SUPPORTED */ ++ else ++ png_write_fdAT(png_ptr, data, size); ++ } ++#endif /* WRITE_APNG */ ++ png_ptr->mode |= PNG_HAVE_IDAT; png_ptr->zstream.next_out = data; -@@ -1050,7 +1064,17 @@ +@@ -1050,7 +1065,17 @@ #endif if (size > 0) @@ -1571,12 +1479,12 @@ diff -Naru libpng-1.6.39.org/pngwutil.c libpng-1.6.39/pngwutil.c + else + png_write_fdAT(png_ptr, data, size); + } -+#endif /* PNG_WRITE_APNG_SUPPORTED */ ++#endif /* WRITE_APNG */ + png_ptr->zstream.avail_out = 0; png_ptr->zstream.next_out = NULL; png_ptr->mode |= PNG_HAVE_IDAT | PNG_AFTER_IDAT; -@@ -1885,6 +1909,82 @@ +@@ -1885,6 +1910,82 @@ } #endif @@ -1591,13 +1499,13 @@ diff -Naru libpng-1.6.39.org/pngwutil.c libpng-1.6.39/pngwutil.c + + png_ptr->num_frames_to_write = num_frames; + -+ if (png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN) ++ if ((png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN) != 0) + num_frames--; + + png_save_uint_32(buf, num_frames); + png_save_uint_32(buf + 4, num_plays); + -+ png_write_complete_chunk(png_ptr, png_acTL, buf, (png_size_t)8); ++ png_write_complete_chunk(png_ptr, png_acTL, buf, 8); +} + +void /* PRIVATE */ @@ -1632,14 +1540,14 @@ diff -Naru libpng-1.6.39.org/pngwutil.c libpng-1.6.39/pngwutil.c + buf[24] = dispose_op; + buf[25] = blend_op; + -+ png_write_complete_chunk(png_ptr, png_fcTL, buf, (png_size_t)26); ++ png_write_complete_chunk(png_ptr, png_fcTL, buf, 26); + + png_ptr->next_seq_num++; +} + +void /* PRIVATE */ +png_write_fdAT(png_structp png_ptr, -+ png_const_bytep data, png_size_t length) ++ png_const_bytep data, size_t length) +{ + png_byte buf[4]; + @@ -1654,12 +1562,12 @@ diff -Naru libpng-1.6.39.org/pngwutil.c libpng-1.6.39/pngwutil.c + + png_ptr->next_seq_num++; +} -+#endif /* PNG_WRITE_APNG_SUPPORTED */ ++#endif /* WRITE_APNG */ + /* Initializes the row writing capability of libpng */ void /* PRIVATE */ png_write_start_row(png_structrp png_ptr) -@@ -2778,4 +2878,39 @@ +@@ -2778,4 +2879,39 @@ } #endif /* WRITE_FLUSH */ } @@ -1684,7 +1592,7 @@ diff -Naru libpng-1.6.39.org/pngwutil.c libpng-1.6.39/pngwutil.c + "don't match the ones in IHDR"); + if (width > png_ptr->first_frame_width || + height > png_ptr->first_frame_height) -+ png_error(png_ptr, "width and/or height for a frame greater than" ++ png_error(png_ptr, "width and/or height for a frame greater than " + "the ones in IHDR"); + + png_set_IHDR(png_ptr, info_ptr, width, height, @@ -1697,11 +1605,12 @@ diff -Naru libpng-1.6.39.org/pngwutil.c libpng-1.6.39/pngwutil.c + png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width); + png_ptr->usr_width = png_ptr->width; +} -+#endif /* PNG_WRITE_APNG_SUPPORTED */ ++#endif /* WRITE_APNG */ #endif /* WRITE */ -diff -Naru libpng-1.6.39.org/scripts/symbols.def libpng-1.6.39/scripts/symbols.def ---- libpng-1.6.39.org/scripts/symbols.def 2022-11-24 08:37:51.515052168 +0900 -+++ libpng-1.6.39/scripts/symbols.def 2022-11-24 08:41:17.788489731 +0900 +Index: scripts/symbols.def +=================================================================== +--- scripts/symbols.def ++++ scripts/symbols.def @@ -253,3 +253,23 @@ png_set_eXIf @247 png_get_eXIf_1 @248 diff --git a/extras/third_party/libpng-apng.src-patch/patch-libpng.sh b/extras/third_party/libpng-apng.src-patch/patch-libpng.sh index 68f3b878..aad41a19 100644 --- a/extras/third_party/libpng-apng.src-patch/patch-libpng.sh +++ b/extras/third_party/libpng-apng.src-patch/patch-libpng.sh @@ -4,7 +4,7 @@ # apng support echo "--- Patching libpng with apng support ---" -patch -d libpng -p1 --forward < libpng-apng/libpng-1.6.39-apng.patch +patch -d libpng -p0 --forward < libpng-apng/libpng-1.6.40-apng.patch # error check, fail and return error if failed if [ $? -ne 0 ]; then echo apng patch failed diff --git a/extras/third_party/libpng-apng.src-patch/zlib b/extras/third_party/libpng-apng.src-patch/zlib index 04f42cec..09155eaa 160000 --- a/extras/third_party/libpng-apng.src-patch/zlib +++ b/extras/third_party/libpng-apng.src-patch/zlib @@ -1 +1 @@ -Subproject commit 04f42ceca40f73e2978b50e93806c2a18c1281fc +Subproject commit 09155eaa2f9270dc4ed1fa13e2b4b2613e6e4851 diff --git a/extras/third_party/libwebp b/extras/third_party/libwebp index b5577769..ca332209 160000 --- a/extras/third_party/libwebp +++ b/extras/third_party/libwebp @@ -1 +1 @@ -Subproject commit b557776962a3dcc985d83bd4ed94e1e2e50d0fa2 +Subproject commit ca332209cb5567c9b249c86788cb2dbf8847e760 diff --git a/src/JPEGView.Setup/Product.wxs b/src/JPEGView.Setup/Product.wxs index cbfdf37e..d7dd698f 100644 --- a/src/JPEGView.Setup/Product.wxs +++ b/src/JPEGView.Setup/Product.wxs @@ -209,7 +209,7 @@ - + @@ -487,8 +487,8 @@ - - + + diff --git a/src/JPEGView/JXLWrapper.cpp b/src/JPEGView/JXLWrapper.cpp index b48c00dc..c43f49c7 100644 --- a/src/JPEGView/JXLWrapper.cpp +++ b/src/JPEGView/JXLWrapper.cpp @@ -89,12 +89,12 @@ bool JxlReader::DecodeJpegXlOneShot(const uint8_t* jxl, size_t size, std::vector size_t icc_size; if (JXL_DEC_SUCCESS != JxlDecoderGetICCProfileSize( - cache.decoder.get(), &format, JXL_COLOR_PROFILE_TARGET_DATA, &icc_size)) { + cache.decoder.get(), JXL_COLOR_PROFILE_TARGET_DATA, &icc_size)) { return false; } icc_profile->resize(icc_size); if (JXL_DEC_SUCCESS != JxlDecoderGetColorAsICCProfile( - cache.decoder.get(), &format, + cache.decoder.get(), JXL_COLOR_PROFILE_TARGET_DATA, icc_profile->data(), icc_profile->size())) { return false; diff --git a/src/JPEGView/libavif/bin/avif.dll b/src/JPEGView/libavif/bin/avif.dll index 79db40de..ba80c1f7 100644 Binary files a/src/JPEGView/libavif/bin/avif.dll and b/src/JPEGView/libavif/bin/avif.dll differ diff --git a/src/JPEGView/libavif/bin64/avif.dll b/src/JPEGView/libavif/bin64/avif.dll index 9da66746..dd401170 100644 Binary files a/src/JPEGView/libavif/bin64/avif.dll and b/src/JPEGView/libavif/bin64/avif.dll differ diff --git a/src/JPEGView/libavif/include/avif/avif.h b/src/JPEGView/libavif/include/avif/avif.h index 282d5076..04a7bdbf 100644 --- a/src/JPEGView/libavif/include/avif/avif.h +++ b/src/JPEGView/libavif/include/avif/avif.h @@ -55,10 +55,10 @@ 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 1 +#define AVIF_VERSION_DEVEL 0 #define AVIF_VERSION \ ((AVIF_VERSION_MAJOR * 1000000) + (AVIF_VERSION_MINOR * 10000) + (AVIF_VERSION_PATCH * 100) + AVIF_VERSION_DEVEL) @@ -132,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); @@ -199,8 +202,9 @@ 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); // --------------------------------------------------------------------------- @@ -267,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 { @@ -322,6 +326,7 @@ 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 { @@ -428,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; // --------------------------------------------------------------------------- @@ -500,6 +500,8 @@ typedef struct 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 @@ -555,6 +557,8 @@ 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. @@ -564,14 +568,14 @@ AVIF_API avifResult avifImageCopy(avifImage * dstImage, const avifImage * srcIma 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 @@ -667,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 @@ -714,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 @@ -897,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 { // -------------------------------------------------------------------------------------------- @@ -1006,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); @@ -1111,6 +1121,8 @@ typedef struct avifScalingMode } 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 @@ -1172,6 +1184,8 @@ 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. @@ -1213,6 +1227,8 @@ typedef uint32_t avifAddImageFlags; // * avifEncoderFinish() // * avifEncoderDestroy() // +// The image passed to avifEncoderAddImage() or avifEncoderAddImageGrid() is encoded during the +// call (which may be slow) and can be freed after the function returns. // durationInTimescales is ignored if AVIF_ADD_IMAGE_FLAG_SINGLE is set in addImageFlags, // or if we are encoding a layered image. diff --git a/src/JPEGView/libavif/include/avif/internal.h b/src/JPEGView/libavif/include/avif/internal.h index 92229489..74eb7d54 100644 --- a/src/JPEGView/libavif/include/avif/internal.h +++ b/src/JPEGView/libavif/include/avif/internal.h @@ -224,6 +224,15 @@ avifBool avifImageScale(avifImage * image, uint32_t imageDimensionLimit, avifDiagnostics * diag); +// --------------------------------------------------------------------------- +// AVIF item type + +typedef enum avifItemCategory +{ + AVIF_ITEM_COLOR = 0, + AVIF_ITEM_ALPHA = 1 +} avifItemCategory; + // --------------------------------------------------------------------------- // Grid AVIF images @@ -262,8 +271,8 @@ AVIF_ARRAY_DECLARE(avifDecodeSampleArray, avifDecodeSample, sample); typedef struct avifCodecDecodeInput { avifDecodeSampleArray samples; - avifBool allLayers; // if true, the underlying codec must decode all layers, not just the best layer - avifBool alpha; // if true, this is decoding an alpha plane + avifBool allLayers; // if true, the underlying codec must decode all layers, not just the best layer + avifItemCategory itemCategory; // category of item being decoded } avifCodecDecodeInput; avifCodecDecodeInput * avifCodecDecodeInputCreate(void); @@ -285,7 +294,7 @@ typedef struct avifCodecEncodeOutput } avifCodecEncodeOutput; avifCodecEncodeOutput * avifCodecEncodeOutputCreate(void); -void avifCodecEncodeOutputAddSample(avifCodecEncodeOutput * encodeOutput, const uint8_t * data, size_t len, avifBool sync); +avifResult avifCodecEncodeOutputAddSample(avifCodecEncodeOutput * encodeOutput, const uint8_t * data, size_t len, avifBool sync); void avifCodecEncodeOutputDestroy(avifCodecEncodeOutput * encodeOutput); // --------------------------------------------------------------------------- @@ -431,14 +440,25 @@ typedef size_t avifBoxMarker; typedef struct avifBoxHeader { + // Size of the box in bytes, excluding the box header. size_t size; + uint8_t type[4]; } avifBoxHeader; typedef struct avifROStream { avifROData * raw; + + // Index of the next byte in the raw stream. size_t offset; + + // If 0, byte-aligned functions can be used (avifROStreamRead() etc.). + // Otherwise, it represents the number of bits already used in the last byte + // (located at offset-1). + size_t numUsedBitsInPartialByte; + + // Error information, if any. avifDiagnostics * diag; const char * diagContext; } avifROStream; @@ -450,6 +470,7 @@ void avifROStreamSetOffset(avifROStream * stream, size_t offset); avifBool avifROStreamHasBytesLeft(const avifROStream * stream, size_t byteCount); size_t avifROStreamRemainingBytes(const avifROStream * stream); +// The following functions require byte alignment. avifBool avifROStreamSkip(avifROStream * stream, size_t byteCount); avifBool avifROStreamRead(avifROStream * stream, uint8_t * data, size_t size); avifBool avifROStreamReadU16(avifROStream * stream, uint16_t * v); @@ -463,29 +484,43 @@ avifBool avifROStreamReadBoxHeader(avifROStream * stream, avifBoxHeader * header avifBool avifROStreamReadBoxHeaderPartial(avifROStream * stream, avifBoxHeader * header); // This doesn't require that the full box can fit in the stream avifBool avifROStreamReadVersionAndFlags(avifROStream * stream, uint8_t * version, uint32_t * flags); // version and flags ptrs are both optional avifBool avifROStreamReadAndEnforceVersion(avifROStream * stream, uint8_t enforcedVersion); // currently discards flags +// The following functions can write non-aligned bits. +avifBool avifROStreamReadBits8(avifROStream * stream, uint8_t * v, size_t bitCount); +avifBool avifROStreamReadBits(avifROStream * stream, uint32_t * v, size_t bitCount); +avifBool avifROStreamReadVarInt(avifROStream * stream, uint32_t * v); typedef struct avifRWStream { avifRWData * raw; + + // Index of the next byte in the raw stream. size_t offset; + + // If 0, byte-aligned functions can be used (avifRWStreamWrite() etc.). + // Otherwise, it represents the number of bits already used in the last byte + // (located at offset-1). + size_t numUsedBitsInPartialByte; } avifRWStream; -uint8_t * avifRWStreamCurrent(avifRWStream * stream); void avifRWStreamStart(avifRWStream * stream, avifRWData * raw); size_t avifRWStreamOffset(const avifRWStream * stream); void avifRWStreamSetOffset(avifRWStream * stream, size_t offset); void avifRWStreamFinishWrite(avifRWStream * stream); -void avifRWStreamWrite(avifRWStream * stream, const void * data, size_t size); -void avifRWStreamWriteChars(avifRWStream * stream, const char * chars, size_t size); -avifBoxMarker avifRWStreamWriteBox(avifRWStream * stream, const char * type, size_t contentSize); -avifBoxMarker avifRWStreamWriteFullBox(avifRWStream * stream, const char * type, size_t contentSize, int version, uint32_t flags); +// The following functions require byte alignment. +avifResult avifRWStreamWrite(avifRWStream * stream, const void * data, size_t size); +avifResult avifRWStreamWriteChars(avifRWStream * stream, const char * chars, size_t size); +avifResult avifRWStreamWriteBox(avifRWStream * stream, const char * type, size_t contentSize, avifBoxMarker * marker); +avifResult avifRWStreamWriteFullBox(avifRWStream * stream, const char * type, size_t contentSize, int version, uint32_t flags, avifBoxMarker * marker); void avifRWStreamFinishBox(avifRWStream * stream, avifBoxMarker marker); -void avifRWStreamWriteU8(avifRWStream * stream, uint8_t v); -void avifRWStreamWriteU16(avifRWStream * stream, uint16_t v); -void avifRWStreamWriteU32(avifRWStream * stream, uint32_t v); -void avifRWStreamWriteU64(avifRWStream * stream, uint64_t v); -void avifRWStreamWriteZeros(avifRWStream * stream, size_t byteCount); +avifResult avifRWStreamWriteU8(avifRWStream * stream, uint8_t v); +avifResult avifRWStreamWriteU16(avifRWStream * stream, uint16_t v); +avifResult avifRWStreamWriteU32(avifRWStream * stream, uint32_t v); +avifResult avifRWStreamWriteU64(avifRWStream * stream, uint64_t v); +avifResult avifRWStreamWriteZeros(avifRWStream * stream, size_t byteCount); +// The following functions can write non-aligned bits. +avifResult avifRWStreamWriteBits(avifRWStream * stream, uint32_t v, size_t bitCount); +avifResult avifRWStreamWriteVarInt(avifRWStream * stream, uint32_t v); // This is to make it clear that the box size is currently unknown, and will be determined later (with a call to avifRWStreamFinishBox) #define AVIF_BOX_SIZE_TBD 0 diff --git a/src/JPEGView/libavif/lib/avif.lib b/src/JPEGView/libavif/lib/avif.lib index 9c8bf0c6..718353e7 100644 Binary files a/src/JPEGView/libavif/lib/avif.lib and b/src/JPEGView/libavif/lib/avif.lib differ diff --git a/src/JPEGView/libavif/lib64/avif.lib b/src/JPEGView/libavif/lib64/avif.lib index 87746eb8..63be1dd0 100644 Binary files a/src/JPEGView/libavif/lib64/avif.lib and b/src/JPEGView/libavif/lib64/avif.lib differ diff --git a/src/JPEGView/libheif/bin/de265.dll b/src/JPEGView/libheif/bin/libde265.dll similarity index 54% rename from src/JPEGView/libheif/bin/de265.dll rename to src/JPEGView/libheif/bin/libde265.dll index a2aa1f0b..7cf64e24 100644 Binary files a/src/JPEGView/libheif/bin/de265.dll and b/src/JPEGView/libheif/bin/libde265.dll differ diff --git a/src/JPEGView/libheif/bin64/de265.dll b/src/JPEGView/libheif/bin64/libde265.dll similarity index 62% rename from src/JPEGView/libheif/bin64/de265.dll rename to src/JPEGView/libheif/bin64/libde265.dll index 50f0c55a..5a38f5b4 100644 Binary files a/src/JPEGView/libheif/bin64/de265.dll and b/src/JPEGView/libheif/bin64/libde265.dll differ diff --git a/src/JPEGView/libjxl/bin/brotlicommon.dll b/src/JPEGView/libjxl/bin/brotlicommon.dll index c6d8ff6b..528db7c2 100644 Binary files a/src/JPEGView/libjxl/bin/brotlicommon.dll and b/src/JPEGView/libjxl/bin/brotlicommon.dll differ diff --git a/src/JPEGView/libjxl/bin/brotlidec.dll b/src/JPEGView/libjxl/bin/brotlidec.dll index 907420a1..cc19c143 100644 Binary files a/src/JPEGView/libjxl/bin/brotlidec.dll and b/src/JPEGView/libjxl/bin/brotlidec.dll differ diff --git a/src/JPEGView/libjxl/bin/jxl_dec.dll b/src/JPEGView/libjxl/bin/jxl_dec.dll index d6245b45..9144ba82 100644 Binary files a/src/JPEGView/libjxl/bin/jxl_dec.dll and b/src/JPEGView/libjxl/bin/jxl_dec.dll differ diff --git a/src/JPEGView/libjxl/bin/jxl_threads.dll b/src/JPEGView/libjxl/bin/jxl_threads.dll index fe278fb0..9a72bac1 100644 Binary files a/src/JPEGView/libjxl/bin/jxl_threads.dll and b/src/JPEGView/libjxl/bin/jxl_threads.dll differ diff --git a/src/JPEGView/libjxl/bin64/brotlicommon.dll b/src/JPEGView/libjxl/bin64/brotlicommon.dll index 55b06257..4964b87a 100644 Binary files a/src/JPEGView/libjxl/bin64/brotlicommon.dll and b/src/JPEGView/libjxl/bin64/brotlicommon.dll differ diff --git a/src/JPEGView/libjxl/bin64/brotlidec.dll b/src/JPEGView/libjxl/bin64/brotlidec.dll index 1fd8a289..3eb73991 100644 Binary files a/src/JPEGView/libjxl/bin64/brotlidec.dll and b/src/JPEGView/libjxl/bin64/brotlidec.dll differ diff --git a/src/JPEGView/libjxl/bin64/jxl_dec.dll b/src/JPEGView/libjxl/bin64/jxl_dec.dll index 8097afc2..79870bbd 100644 Binary files a/src/JPEGView/libjxl/bin64/jxl_dec.dll and b/src/JPEGView/libjxl/bin64/jxl_dec.dll differ diff --git a/src/JPEGView/libjxl/bin64/jxl_threads.dll b/src/JPEGView/libjxl/bin64/jxl_threads.dll index 85a60065..9de09d94 100644 Binary files a/src/JPEGView/libjxl/bin64/jxl_threads.dll and b/src/JPEGView/libjxl/bin64/jxl_threads.dll differ diff --git a/src/JPEGView/libjxl/include/jxl/butteraugli.h b/src/JPEGView/libjxl/include/jxl/butteraugli.h deleted file mode 100644 index ba69a296..00000000 --- a/src/JPEGView/libjxl/include/jxl/butteraugli.h +++ /dev/null @@ -1,160 +0,0 @@ -/* Copyright (c) the JPEG XL Project Authors. All rights reserved. - * - * Use of this source code is governed by a BSD-style - * license that can be found in the LICENSE file. - */ - -/** @addtogroup libjxl_butteraugli - * @{ - * @file butteraugli.h - * @brief Butteraugli API for JPEG XL. - */ - -#ifndef JXL_BUTTERAUGLI_H_ -#define JXL_BUTTERAUGLI_H_ - -#if defined(__cplusplus) || defined(c_plusplus) -extern "C" { -#endif - -#include "jxl/jxl_export.h" -#include "jxl/memory_manager.h" -#include "jxl/parallel_runner.h" -#include "jxl/types.h" - -/** - * Opaque structure that holds a butteraugli API. - * - * Allocated and initialized with JxlButteraugliApiCreate(). - * Cleaned up and deallocated with JxlButteraugliApiDestroy(). - */ -typedef struct JxlButteraugliApiStruct JxlButteraugliApi; - -/** - * Opaque structure that holds intermediary butteraugli results. - * - * Allocated and initialized with JxlButteraugliCompute(). - * Cleaned up and deallocated with JxlButteraugliResultDestroy(). - */ -typedef struct JxlButteraugliResultStruct JxlButteraugliResult; - -/** - * Deinitializes and frees JxlButteraugliResult instance. - * - * @param result instance to be cleaned up and deallocated. - */ -JXL_EXPORT void JxlButteraugliResultDestroy(JxlButteraugliResult* result); - -/** - * Creates an instance of JxlButteraugliApi and initializes it. - * - * @p memory_manager will be used for all the library dynamic allocations made - * from this instance. The parameter may be NULL, in which case the default - * allocator will be used. See jxl/memory_manager.h for details. - * - * @param memory_manager custom allocator function. It may be NULL. The memory - * manager will be copied internally. - * @return @c NULL if the instance can not be allocated or initialized - * @return pointer to initialized JxlEncoder otherwise - */ -JXL_EXPORT JxlButteraugliApi* JxlButteraugliApiCreate( - const JxlMemoryManager* memory_manager); - -/** - * Set the parallel runner for multithreading. - * - * @param api api instance. - * @param parallel_runner function pointer to runner for multithreading. A - * multithreaded runner should be set to reach fast performance. - * @param parallel_runner_opaque opaque pointer for parallel_runner. - */ -JXL_EXPORT void JxlButteraugliApiSetParallelRunner( - JxlButteraugliApi* api, JxlParallelRunner parallel_runner, - void* parallel_runner_opaque); - -/** - * Set the hf_asymmetry option for butteraugli. - * - * @param api api instance. - * @param v new hf_asymmetry value. - */ -JXL_EXPORT void JxlButteraugliApiSetHFAsymmetry(JxlButteraugliApi* api, - float v); - -/** - * Set the intensity_target option for butteraugli. - * - * @param api api instance. - * @param v new intensity_target value. - */ -JXL_EXPORT void JxlButteraugliApiSetIntensityTarget(JxlButteraugliApi* api, - float v); - -/** - * Deinitializes and frees JxlButteraugliApi instance. - * - * @param api instance to be cleaned up and deallocated. - */ -JXL_EXPORT void JxlButteraugliApiDestroy(JxlButteraugliApi* api); - -/** - * Computes intermediary butteraugli result between an original image and a - * distortion. - * - * @param api api instance for this computation. - * @param xsize width of the compared images. - * @param ysize height of the compared images. - * @param pixel_format_orig pixel format for original image. - * @param buffer_orig pixel data for original image. - * @param size_orig size of buffer_orig in bytes. - * @param pixel_format_dist pixel format for distortion. - * @param buffer_dist pixel data for distortion. - * @param size_dist size of buffer_dist in bytes. - * @return @c NULL if the results can not be computed or initialized. - * @return pointer to initialized and computed intermediary result. - */ -JXL_EXPORT JxlButteraugliResult* JxlButteraugliCompute( - const JxlButteraugliApi* api, uint32_t xsize, uint32_t ysize, - const JxlPixelFormat* pixel_format_orig, const void* buffer_orig, - size_t size_orig, const JxlPixelFormat* pixel_format_dist, - const void* buffer_dist, size_t size_dist); - -/** - * Computes butteraugli max distance based on an intermediary butteraugli - * result. - * - * @param result intermediary result instance. - * @return max distance. - */ -JXL_EXPORT float JxlButteraugliResultGetMaxDistance( - const JxlButteraugliResult* result); - -/** - * Computes a butteraugli distance based on an intermediary butteraugli result. - * - * @param result intermediary result instance. - * @param pnorm pnorm to calculate. - * @return distance using the given pnorm. - */ -JXL_EXPORT float JxlButteraugliResultGetDistance( - const JxlButteraugliResult* result, float pnorm); - -/** - * Get a pointer to the distmap in the result. - * - * @param result intermediary result instance. - * @param buffer will be set to the distmap. The distance value for (x,y) will - * be available at buffer + y * row_stride + x. - * @param row_stride will be set to the row stride of the distmap. - */ -JXL_EXPORT void JxlButteraugliResultGetDistmap( - const JxlButteraugliResult* result, const float** buffer, - uint32_t* row_stride); - -#if defined(__cplusplus) || defined(c_plusplus) -} -#endif - -#endif /* JXL_BUTTERAUGLI_H_ */ - -/** @}*/ diff --git a/src/JPEGView/libjxl/include/jxl/butteraugli_cxx.h b/src/JPEGView/libjxl/include/jxl/butteraugli_cxx.h deleted file mode 100644 index 55efd74d..00000000 --- a/src/JPEGView/libjxl/include/jxl/butteraugli_cxx.h +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) the JPEG XL Project Authors. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -/// @addtogroup libjxl_butteraugli -/// @{ -/// -/// @file butteraugli_cxx.h -/// @brief C++ header-only helper for @ref butteraugli.h. -/// -/// There's no binary library associated with the header since this is a header -/// only library. - -#ifndef JXL_BUTTERAUGLI_CXX_H_ -#define JXL_BUTTERAUGLI_CXX_H_ - -#include - -#include "jxl/butteraugli.h" - -#if !(defined(__cplusplus) || defined(c_plusplus)) -#error "This a C++ only header. Use jxl/butteraugli.h from C sources." -#endif - -/// Struct to call JxlButteraugliApiDestroy from the JxlButteraugliApiPtr -/// unique_ptr. -struct JxlButteraugliApiDestroyStruct { - /// Calls @ref JxlButteraugliApiDestroy() on the passed api. - void operator()(JxlButteraugliApi* api) { JxlButteraugliApiDestroy(api); } -}; - -/// std::unique_ptr<> type that calls JxlButteraugliApiDestroy() when releasing -/// the pointer. -/// -/// Use this helper type from C++ sources to ensure the api is destroyed and -/// their internal resources released. -typedef std::unique_ptr - JxlButteraugliApiPtr; - -/// Struct to call JxlButteraugliResultDestroy from the JxlButteraugliResultPtr -/// unique_ptr. -struct JxlButteraugliResultDestroyStruct { - /// Calls @ref JxlButteraugliResultDestroy() on the passed result object. - void operator()(JxlButteraugliResult* result) { - JxlButteraugliResultDestroy(result); - } -}; - -/// std::unique_ptr<> type that calls JxlButteraugliResultDestroy() when -/// releasing the pointer. -/// -/// Use this helper type from C++ sources to ensure the result object is -/// destroyed and their internal resources released. -typedef std::unique_ptr - JxlButteraugliResultPtr; - -#endif // JXL_BUTTERAUGLI_CXX_H_ - -/// @} diff --git a/src/JPEGView/libjxl/include/jxl/cms_interface.h b/src/JPEGView/libjxl/include/jxl/cms_interface.h index fb852eeb..56da9fe9 100644 --- a/src/JPEGView/libjxl/include/jxl/cms_interface.h +++ b/src/JPEGView/libjxl/include/jxl/cms_interface.h @@ -4,7 +4,7 @@ * license that can be found in the LICENSE file. */ -/** @addtogroup libjxl_common +/** @addtogroup libjxl_color * @{ * @file cms_interface.h * @brief Interface to allow the injection of different color management systems @@ -18,13 +18,28 @@ #ifndef JXL_CMS_INTERFACE_H_ #define JXL_CMS_INTERFACE_H_ -#include "jxl/color_encoding.h" -#include "jxl/types.h" +#include +#include #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif +/** Parses an ICC profile and populates @p c and @p cmyk with the data. + * + * @param user_data JxlCmsInterface::set_fields_data passed as-is. + * @param icc_data the ICC data to parse. + * @param icc_size how many bytes of icc_data are valid. + * @param c a JxlColorEncoding to populate if applicable. + * @param cmyk a boolean to set to whether the colorspace is a CMYK colorspace. + * @return Whether the relevant fields in @p c were successfully populated. + */ +typedef JXL_BOOL (*jpegxl_cms_set_fields_from_icc_func)(void* user_data, + const uint8_t* icc_data, + size_t icc_size, + JxlColorEncoding* c, + JXL_BOOL* cmyk); + /** Represents an input or output colorspace to a color transform, as a * serialized ICC profile. */ typedef struct { @@ -207,6 +222,11 @@ typedef void (*jpegxl_cms_destroy_func)(void*); * @enddot */ typedef struct { + /** CMS-specific data that will be passed to @ref set_fields_from_icc. */ + void* set_fields_data; + /** Populates a JxlColorEncoding from an ICC profile. */ + jpegxl_cms_set_fields_from_icc_func set_fields_from_icc; + /** CMS-specific data that will be passed to @ref init. */ void* init_data; /** Prepares a colorspace transform as described in the documentation of @ref diff --git a/src/JPEGView/libjxl/include/jxl/codestream_header.h b/src/JPEGView/libjxl/include/jxl/codestream_header.h index cf807bce..fb714842 100644 --- a/src/JPEGView/libjxl/include/jxl/codestream_header.h +++ b/src/JPEGView/libjxl/include/jxl/codestream_header.h @@ -4,7 +4,7 @@ * license that can be found in the LICENSE file. */ -/** @addtogroup libjxl_common +/** @addtogroup libjxl_metadata * @{ * @file codestream_header.h * @brief Definitions of structs and enums for the metadata from the JPEG XL @@ -15,11 +15,10 @@ #ifndef JXL_CODESTREAM_HEADER_H_ #define JXL_CODESTREAM_HEADER_H_ +#include #include #include -#include "jxl/types.h" - #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif @@ -245,7 +244,7 @@ typedef struct { */ uint32_t intrinsic_xsize; - /** Intrinsic heigth of the image. + /** Intrinsic height of the image. * The intrinsic size can be different from the actual size in pixels * (as given by xsize and ysize) and it denotes the recommended dimensions * for displaying the image, i.e. applications are advised to resample the @@ -380,6 +379,8 @@ typedef struct { /** After blending, save the frame as reference frame with this ID (0-3). * Special case: if the frame duration is nonzero, ID 0 means "will not be * referenced in the future". This value is not used for the last frame. + * When encoding, ID 3 is reserved to frames that are generated internally by + * the encoder, and should not be used by applications. */ uint32_t save_as_reference; } JxlLayerInfo; diff --git a/src/JPEGView/libjxl/include/jxl/color_encoding.h b/src/JPEGView/libjxl/include/jxl/color_encoding.h index b16f6a01..928117e8 100644 --- a/src/JPEGView/libjxl/include/jxl/color_encoding.h +++ b/src/JPEGView/libjxl/include/jxl/color_encoding.h @@ -4,7 +4,7 @@ * license that can be found in the LICENSE file. */ -/** @addtogroup libjxl_common +/** @addtogroup libjxl_color * @{ * @file color_encoding.h * @brief Color Encoding definitions used by JPEG XL. diff --git a/src/JPEGView/libjxl/include/jxl/decode.h b/src/JPEGView/libjxl/include/jxl/decode.h index 7c0e5555..f0804875 100644 --- a/src/JPEGView/libjxl/include/jxl/decode.h +++ b/src/JPEGView/libjxl/include/jxl/decode.h @@ -13,18 +13,17 @@ #ifndef JXL_DECODE_H_ #define JXL_DECODE_H_ +#include +#include +#include +#include +#include +#include +#include +#include #include #include -#include "jxl/cms_interface.h" -#include "jxl/codestream_header.h" -#include "jxl/color_encoding.h" -#include "jxl/jxl_export.h" -#include "jxl/memory_manager.h" -#include "jxl/parallel_runner.h" -#include "jxl/types.h" -#include "jxl/version.h" - #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif @@ -199,16 +198,6 @@ typedef enum { */ JXL_DEC_BASIC_INFO = 0x40, - /** Informative event by @ref JxlDecoderProcessInput - * "JxlDecoderProcessInput": User extensions of the codestream header. This - * event occurs max once per image and always later than @ref - * JXL_DEC_BASIC_INFO and earlier than any pixel data. - * - * @deprecated The decoder no longer returns this, the header extensions, - * if any, are available at the JXL_DEC_BASIC_INFO event. - */ - JXL_DEC_EXTENSIONS = 0x80, - /** Informative event by @ref JxlDecoderProcessInput * "JxlDecoderProcessInput": Color encoding or ICC profile from the * codestream header. This event occurs max once per image and always later @@ -331,6 +320,33 @@ typedef enum { JXL_DEC_FRAME_PROGRESSION = 0x8000, } JxlDecoderStatus; +/** Types of progressive detail. + * Setting a progressive detail with value N implies all progressive details + * with smaller or equal value. Currently only the following level of + * progressive detail is implemented: + * - kDC (which implies kFrames) + * - kLastPasses (which implies kDC and kFrames) + * - kPasses (which implies kLastPasses, kDC and kFrames) + */ +typedef enum { + // after completed kRegularFrames + kFrames = 0, + // after completed DC (1:8) + kDC = 1, + // after completed AC passes that are the last pass for their resolution + // target. + kLastPasses = 2, + // after completed AC passes that are not the last pass for their resolution + // target. + kPasses = 3, + // during DC frame when lower resolution are completed (1:32, 1:16) + kDCProgressive = 4, + // after completed groups + kDCGroups = 5, + // after completed groups + kGroups = 6, +} JxlProgressiveDetail; + /** Rewinds decoder to the beginning. The same input must be given again from * the beginning of the file and the decoder will emit events from the beginning * again. When rewinding (as opposed to @ref JxlDecoderReset), the decoder can @@ -379,7 +395,7 @@ JXL_EXPORT void JxlDecoderSkipFrames(JxlDecoder* dec, size_t amount); /** * Skips processing the current frame. Can be called after frame processing * already started, signaled by a @ref JXL_DEC_NEED_IMAGE_OUT_BUFFER event, - * but before the corrsponding @ref JXL_DEC_FULL_IMAGE event. The next signaled + * but before the corresponding @ref JXL_DEC_FULL_IMAGE event. The next signaled * event will be another @ref JXL_DEC_FRAME, or @ref JXL_DEC_SUCCESS if there * are no more frames. If pixel data is required from the already processed part * of the frame, @ref JxlDecoderFlushImage must be called before this. @@ -390,23 +406,6 @@ JXL_EXPORT void JxlDecoderSkipFrames(JxlDecoder* dec, size_t amount); */ JXL_EXPORT JxlDecoderStatus JxlDecoderSkipCurrentFrame(JxlDecoder* dec); -/** - * Get the default pixel format for this decoder. - * - * Requires that the decoder can produce JxlBasicInfo. - * - * @param dec @ref JxlDecoder to query when creating the recommended pixel - * format. - * @param format JxlPixelFormat to populate with the recommended settings for - * the data loaded into this decoder. - * @return @ref JXL_DEC_SUCCESS if no error, @ref JXL_DEC_NEED_MORE_INPUT if the - * basic info isn't yet available, and @ref JXL_DEC_ERROR otherwise. - * - * DEPRECATED: this function will be removed in the future. - */ -JXL_DEPRECATED JXL_EXPORT JxlDecoderStatus -JxlDecoderDefaultPixelFormat(const JxlDecoder* dec, JxlPixelFormat* format); - /** * Set the parallel runner for multithreading. May only be set before starting * decoding. @@ -738,7 +737,6 @@ typedef enum { * JxlDecoderGetColorAsEncodedProfile should be used first. * * @param dec decoder object - * @param unused_format deprecated, can be NULL * @param target whether to get the original color profile from the metadata * or the color profile of the decoded pixels. * @param color_encoding struct to copy the information into, or NULL to only @@ -749,8 +747,8 @@ typedef enum { * codestream. */ JXL_EXPORT JxlDecoderStatus JxlDecoderGetColorAsEncodedProfile( - const JxlDecoder* dec, const JxlPixelFormat* unused_format, - JxlColorProfileTarget target, JxlColorEncoding* color_encoding); + const JxlDecoder* dec, JxlColorProfileTarget target, + JxlColorEncoding* color_encoding); /** * Outputs the size in bytes of the ICC profile returned by @ref @@ -764,7 +762,6 @@ JXL_EXPORT JxlDecoderStatus JxlDecoderGetColorAsEncodedProfile( * depending of what is encoded in the codestream. * * @param dec decoder object - * @param unused_format deprecated, can be NULL * @param target whether to get the original color profile from the metadata * or the color profile of the decoded pixels. * @param size variable to output the size into, or NULL to only check the @@ -776,8 +773,7 @@ JXL_EXPORT JxlDecoderStatus JxlDecoderGetColorAsEncodedProfile( * cannot be generated. */ JXL_EXPORT JxlDecoderStatus JxlDecoderGetICCProfileSize( - const JxlDecoder* dec, const JxlPixelFormat* unused_format, - JxlColorProfileTarget target, size_t* size); + const JxlDecoder* dec, JxlColorProfileTarget target, size_t* size); /** * Outputs ICC profile if available. The profile is only available if @ref @@ -785,7 +781,6 @@ JXL_EXPORT JxlDecoderStatus JxlDecoderGetICCProfileSize( * at least as many bytes as given by @ref JxlDecoderGetICCProfileSize. * * @param dec decoder object - * @param unused_format deprecated, can be NULL * @param target whether to get the original color profile from the metadata * or the color profile of the decoded pixels. * @param icc_profile buffer to copy the ICC profile into @@ -796,8 +791,8 @@ JXL_EXPORT JxlDecoderStatus JxlDecoderGetICCProfileSize( * large enough. */ JXL_EXPORT JxlDecoderStatus JxlDecoderGetColorAsICCProfile( - const JxlDecoder* dec, const JxlPixelFormat* unused_format, - JxlColorProfileTarget target, uint8_t* icc_profile, size_t size); + const JxlDecoder* dec, JxlColorProfileTarget target, uint8_t* icc_profile, + size_t size); /** Sets the desired output color profile of the decoded image by calling * @ref JxlDecoderSetOutputColorProfile, passing on @c color_encoding and @@ -835,7 +830,7 @@ JXL_EXPORT JxlDecoderStatus JxlDecoderSetDesiredIntensityTarget( * behavior is as follows: * * If a color management system (CMS) has been set with @ref JxlDecoderSetCms, - * and the CMS suppports output to the desired color encoding or ICC profile, + * and the CMS supports output to the desired color encoding or ICC profile, * then it will provide the output in that color encoding or ICC profile. If the * desired color encoding or the ICC is not supported, then an error will be * returned. @@ -884,7 +879,7 @@ JXL_EXPORT JxlDecoderStatus JxlDecoderSetOutputColorProfile( */ JXL_EXPORT void JxlDecoderSetCms(JxlDecoder* dec, JxlCmsInterface cms); // TODO(firsching): add a function JxlDecoderSetDefaultCms() for setting a -// default in case libjxl is build with an CMS. +// default in case libjxl is build with a CMS. /** * Returns the minimum size in bytes of the preview image output pixel buffer @@ -1293,7 +1288,7 @@ JXL_EXPORT JxlDecoderStatus JxlDecoderSetDecompressBoxes(JxlDecoder* dec, JXL_BOOL decompress); /** - * Outputs the type of the current box, after a @ref JXL_DEC_BOX event occured, + * Outputs the type of the current box, after a @ref JXL_DEC_BOX event occurred, * as 4 characters without null termination character. In case of a compressed * "brob" box, this will return "brob" if the decompressed argument is * JXL_FALSE, or the underlying box type if the decompressed argument is diff --git a/src/JPEGView/libjxl/include/jxl/decode_cxx.h b/src/JPEGView/libjxl/include/jxl/decode_cxx.h index ed5c3934..3dd0d2a5 100644 --- a/src/JPEGView/libjxl/include/jxl/decode_cxx.h +++ b/src/JPEGView/libjxl/include/jxl/decode_cxx.h @@ -3,7 +3,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -/// @addtogroup libjxl_decoder +/// @addtogroup libjxl_cpp /// @{ /// /// @file decode_cxx.h @@ -15,9 +15,9 @@ #ifndef JXL_DECODE_CXX_H_ #define JXL_DECODE_CXX_H_ -#include +#include -#include "jxl/decode.h" +#include #if !(defined(__cplusplus) || defined(c_plusplus)) #error "This a C++ only header. Use jxl/decode.h from C sources." diff --git a/src/JPEGView/libjxl/include/jxl/encode.h b/src/JPEGView/libjxl/include/jxl/encode.h index f5087c78..fa400d5b 100644 --- a/src/JPEGView/libjxl/include/jxl/encode.h +++ b/src/JPEGView/libjxl/include/jxl/encode.h @@ -13,12 +13,13 @@ #ifndef JXL_ENCODE_H_ #define JXL_ENCODE_H_ -#include "jxl/cms_interface.h" -#include "jxl/codestream_header.h" -#include "jxl/jxl_export.h" -#include "jxl/memory_manager.h" -#include "jxl/parallel_runner.h" -#include "jxl/version.h" +#include +#include +#include +#include +#include +#include +#include #if defined(__cplusplus) || defined(c_plusplus) extern "C" { @@ -51,10 +52,6 @@ typedef struct JxlEncoderStruct JxlEncoder; */ typedef struct JxlEncoderFrameSettingsStruct JxlEncoderFrameSettings; -/** DEPRECATED: Use JxlEncoderFrameSettings instead. - */ -typedef JxlEncoderFrameSettings JxlEncoderOptions; - /** * Return value for multiple encoder functions. */ @@ -72,13 +69,6 @@ typedef enum { */ JXL_ENC_NEED_MORE_OUTPUT = 2, - /** DEPRECATED: the encoder does not return this status and there is no need - * to handle or expect it. - * Instead, JXL_ENC_ERROR is returned with error condition - * JXL_ENC_ERR_NOT_SUPPORTED. - */ - JXL_ENC_NOT_SUPPORTED = 3, - } JxlEncoderStatus; /** @@ -346,6 +336,43 @@ typedef enum { */ JXL_ENC_FRAME_SETTING_JPEG_COMPRESS_BOXES = 33, + /** Control what kind of buffering is used, when using chunked image frames. + * 0 = buffers everything, basically the same as non-streamed code path + (mainly for testing) + * 1 = can buffer internal data (the tokens) + * 2 = can buffer the output + * 3 = minimize buffer usage: streamed input and chunked output, writing TOC + last (will not work with progressive) + + When the image dimensions is smaller than 2048 x 2048 all the options are the + same. Using 1, 2 or 3 can result increasingly in less compression density. + */ + JXL_ENC_FRAME_SETTING_BUFFERING = 34, + + /** Keep or discard Exif metadata boxes derived from a JPEG frame when using + * JxlEncoderAddJPEGFrame. This has no effect on boxes added using + * JxlEncoderAddBox. When JxlEncoderStoreJPEGMetadata is set to 1, this option + * cannot be set to 0. Even when Exif metadata is discarded, the orientation + * will still be applied. 0 = discard Exif metadata, 1 = keep Exif metadata + * (default). + */ + JXL_ENC_FRAME_SETTING_JPEG_KEEP_EXIF = 35, + + /** Keep or discard XMP metadata boxes derived from a JPEG frame when using + * JxlEncoderAddJPEGFrame. This has no effect on boxes added using + * JxlEncoderAddBox. When JxlEncoderStoreJPEGMetadata is set to 1, this option + * cannot be set to 0. 0 = discard XMP metadata, 1 = keep XMP metadata + * (default). + */ + JXL_ENC_FRAME_SETTING_JPEG_KEEP_XMP = 36, + + /** Keep or discard JUMBF metadata boxes derived from a JPEG frame when using + * JxlEncoderAddJPEGFrame. This has no effect on boxes added using + * JxlEncoderAddBox. 0 = discard JUMBF metadata, 1 = keep JUMBF metadata + * (default). + */ + JXL_ENC_FRAME_SETTING_JPEG_KEEP_JUMBF = 37, + /** Enum value not to be used as an option. This value is added to force the * C compiler to have the enum to take a known size. */ @@ -641,6 +668,129 @@ JXL_EXPORT JxlEncoderStatus JxlEncoderAddImageFrame( const JxlEncoderFrameSettings* frame_settings, const JxlPixelFormat* pixel_format, const void* buffer, size_t size); +/** + * The JxlEncoderOutputProcessor structure provides an interface for the + * encoder's output processing. Users of the library, who want to do streaming + * encoding, should implement the required callbacks for buffering, writing, + * seeking (if supported), and setting a finalized position during the encoding + * process. + * + * At a high level, the processor can be in one of two states: + * - With an active buffer: This indicates that a buffer has been acquired using + * `get_buffer` and encoded data can be written to it. + * - Without an active buffer: In this state, no data can be written. A new + * buffer must be acquired after releasing any previously active buffer. + * + * The library will not acquire more than one buffer at a given time. + * + * The state of the processor includes `position` and `finalized position`, + * which have the following meaning. + * + * - position: Represents the current position, in bytes, within the output + * stream where the encoded data will be written next. This position moves + * forward with each `release_buffer` call as data is written, and can also be + * adjusted through the optional seek callback, if provided. At this position + * the next write will occur. + * + * - finalized position: A position in the output stream that ensures all bytes + * before this point are finalized and won't be changed by later writes. + * + * All fields but `seek` are required, `seek` is optional and can be NULL. + */ +struct JxlEncoderOutputProcessor { + /** + * Required. + * An opaque pointer that the client can use to store custom data. + * This data will be passed to the associated callback functions. + */ + void* opaque; + + /** + * Required. + * Acquires a buffer at the current position into which the library will write + * the output data. + * + * If the `size` argument points to 0 and the returned value is NULL, this + * will be interpreted as asking the output writing to stop. In such a case, + * the library will return an error. The client is expected to set the size of + * the returned buffer based on the suggested `size` when this function is + * called. + * + * @param opaque user supplied parameters to the callback + * @param size points to a suggested buffer size when called; must be set to + * the size of the returned buffer once the function returns. + * @return a pointer to the acquired buffer or NULL to indicate a stop + * condition. + */ + void* (*get_buffer)(void* opaque, size_t* size); + + /** + * Required. + * Notifies the user of library that the current buffer's data has been + * written and can be released. This function should advance the current + * position of the buffer by `written_bytes` number of bytes. + * + * @param opaque user supplied parameters to the callback + * @param written_bytes the number of bytes written to the buffer. + */ + void (*release_buffer)(void* opaque, size_t written_bytes); + + /** + * Optional, can be NULL + * Seeks to a specific position in the output. This function is optional and + * can be set to NULL if the output doesn't support seeking. Can only be done + * when there is no buffer. Cannot be used to seek before the finalized + * position. + * + * @param opaque user supplied parameters to the callback + * @param position the position to seek to, in bytes. + */ + void (*seek)(void* opaque, uint64_t position); + + /** + * Required. + * Sets a finalized position on the output data, at a specific position. + * Seeking will never request a position before the finalized position. + * + * Will only be called if there is no active buffer. + * + * @param opaque user supplied parameters to the callback + * @param finalized_position the position, in bytes, where the finalized + * position should be set. + */ + void (*set_finalized_position)(void* opaque, uint64_t finalized_position); +}; + +/** + * Sets the output processor for the encoder. This processor determines how the + * encoder will handle buffering, writing, seeking (if supported), and + * setting a finalized position during the encoding process. + * + * This should not be used when using @ref JxlEncoderProcessOutput. + * + * @param enc encoder object. + * @param output_processor the struct containing the callbacks for managing + * output. + * @return JXL_ENC_SUCCESS on success, JXL_ENC_ERROR on error. + */ +JXL_EXPORT JxlEncoderStatus JxlEncoderSetOutputProcessor( + JxlEncoder* enc, struct JxlEncoderOutputProcessor output_processor); + +/** + * Flushes any buffered input in the encoder, ensuring that all available input + * data has been processed and written to the output. + * + * This function can only be used after @ref JxlEncoderSetOutputProcessor. + * Before making the last call to @ref JxlEncoderFlushInput, users should call + * @ref JxlEncoderCloseInput to signal the end of input data. + * + * This should not be used when using @ref JxlEncoderProcessOutput. + * + * @param enc encoder object. + * @return JXL_ENC_SUCCESS on success, JXL_ENC_ERROR on error. + */ +JXL_EXPORT JxlEncoderStatus JxlEncoderFlushInput(JxlEncoder* enc); + /** * Sets the buffer to read pixels from for an extra channel at a given index. * The index must be smaller than the num_extra_channels in the associated @@ -886,6 +1036,26 @@ JXL_EXPORT void JxlEncoderInitBlendInfo(JxlBlendInfo* blend_info); JXL_EXPORT JxlEncoderStatus JxlEncoderSetBasicInfo(JxlEncoder* enc, const JxlBasicInfo* info); +/** + * Sets the upsampling method the decoder will use in case there are frames + * with JXL_ENC_FRAME_SETTING_RESAMPLING set. This is useful in combination + * with the JXL_ENC_FRAME_SETTING_ALREADY_DOWNSAMPLED option, to control the + * type of upsampling that will be used. + * + * @param enc encoder object. + * @param factor upsampling factor to configure (1, 2, 4 or 8; for 1 this + * function has no effect at all) + * @param mode upsampling mode to use for this upsampling: + * -1: default (good for photographic images, no signaling overhead) + * 0: nearest neighbor (good for pixel art) + * 1: 'pixel dots' (same as NN for 2x, diamond-shaped 'pixel dots' for 4x/8x) + * @return JXL_ENC_SUCCESS if the operation was successful, + * JXL_ENC_ERROR or JXL_ENC_NOT_SUPPORTED otherwise + */ +JXL_EXPORT JxlEncoderStatus JxlEncoderSetUpsamplingMode(JxlEncoder* enc, + const int64_t factor, + const int64_t mode); + /** * Initializes a JxlExtraChannelInfo struct to default values. * For forwards-compatibility, this function has to be called before values @@ -1084,37 +1254,6 @@ JXL_EXPORT int JxlEncoderGetRequiredCodestreamLevel(const JxlEncoder* enc); JXL_EXPORT JxlEncoderStatus JxlEncoderSetFrameLossless( JxlEncoderFrameSettings* frame_settings, JXL_BOOL lossless); -/** DEPRECATED: use JxlEncoderSetFrameLossless instead. - */ -JXL_EXPORT JxlEncoderStatus -JxlEncoderOptionsSetLossless(JxlEncoderFrameSettings*, JXL_BOOL); - -/** - * @param frame_settings set of options and metadata for this frame. Also - * includes reference to the encoder object. - * @param effort the effort value to set. - * @return JXL_ENC_SUCCESS if the operation was successful, JXL_ENC_ERROR - * otherwise. - * - * DEPRECATED: use JxlEncoderFrameSettingsSetOption(frame_settings, - * JXL_ENC_FRAME_SETTING_EFFORT, effort) instead. - */ -JXL_DEPRECATED JXL_EXPORT JxlEncoderStatus -JxlEncoderOptionsSetEffort(JxlEncoderFrameSettings* frame_settings, int effort); - -/** - * @param frame_settings set of options and metadata for this frame. Also - * includes reference to the encoder object. - * @param tier the decoding speed tier to set. - * @return JXL_ENC_SUCCESS if the operation was successful, JXL_ENC_ERROR - * otherwise. - * - * DEPRECATED: use JxlEncoderFrameSettingsSetOption(frame_settings, - * JXL_ENC_FRAME_SETTING_DECODING_SPEED, tier) instead. - */ -JXL_DEPRECATED JXL_EXPORT JxlEncoderStatus JxlEncoderOptionsSetDecodingSpeed( - JxlEncoderFrameSettings* frame_settings, int tier); - /** * Sets the distance level for lossy compression: target max butteraugli * distance, lower = higher quality. Range: 0 .. 15. @@ -1132,10 +1271,21 @@ JXL_DEPRECATED JXL_EXPORT JxlEncoderStatus JxlEncoderOptionsSetDecodingSpeed( JXL_EXPORT JxlEncoderStatus JxlEncoderSetFrameDistance( JxlEncoderFrameSettings* frame_settings, float distance); -/** DEPRECATED: use JxlEncoderSetFrameDistance instead. +/** + * Sets the distance level for lossy compression of extra channels. + * The distance is as in JxlEncoderSetFrameDistance (lower = higher quality). + * If not set, or if set to the special value -1, the distance that was set with + * JxlEncoderSetFrameDistance will be used. + * + * @param frame_settings set of options and metadata for this frame. Also + * includes reference to the encoder object. + * @param index index of the extra channel to set a distance value for. + * @param distance the distance value to set. + * @return JXL_ENC_SUCCESS if the operation was successful, JXL_ENC_ERROR + * otherwise. */ -JXL_DEPRECATED JXL_EXPORT JxlEncoderStatus -JxlEncoderOptionsSetDistance(JxlEncoderFrameSettings*, float); +JXL_EXPORT JxlEncoderStatus JxlEncoderSetExtraChannelDistance( + JxlEncoderFrameSettings* frame_settings, size_t index, float distance); /** * Create a new set of encoder options, with all values initially copied from @@ -1155,11 +1305,6 @@ JxlEncoderOptionsSetDistance(JxlEncoderFrameSettings*, float); JXL_EXPORT JxlEncoderFrameSettings* JxlEncoderFrameSettingsCreate( JxlEncoder* enc, const JxlEncoderFrameSettings* source); -/** DEPRECATED: use JxlEncoderFrameSettingsCreate instead. - */ -JXL_DEPRECATED JXL_EXPORT JxlEncoderFrameSettings* JxlEncoderOptionsCreate( - JxlEncoder*, const JxlEncoderFrameSettings*); - /** * Sets a color encoding to be sRGB. * @@ -1188,6 +1333,57 @@ JXL_EXPORT void JxlColorEncodingSetToLinearSRGB( */ JXL_EXPORT void JxlEncoderAllowExpertOptions(JxlEncoder* enc); +/** + * Function type for @ref JxlEncoderSetDebugImageCallback. + * + * The callback may be called simultaneously by different threads when using a + * threaded parallel runner, on different debug images. + * + * @param opaque optional user data, as given to @ref + * JxlEncoderSetDebugImageCallback. + * @param label label of debug image, can be used in filenames + * @param xsize width of debug image + * @param ysize height of debug image + * @param color color encoding of debug image + * @param pixels pixel data of debug image as big-endian 16-bit unsigned + * samples. The memory is not owned by the user, and is only valid during the + * time the callback is running. + */ +typedef void (*JxlDebugImageCallback)(void* opaque, const char* label, + size_t xsize, size_t ysize, + const JxlColorEncoding* color, + const uint16_t* pixels); + +/** + * Sets the given debug image callback that will be used by the encoder to + * output various debug images during encoding. + * + * This only has any effect if the encoder was compiled with the appropriate + * debug build flags. + * + * @param frame_settings set of options and metadata for this frame. Also + * includes reference to the encoder object. + * @param callback used to return the debug image + * @param opaque user supplied parameter to the image callback + */ +JXL_EXPORT void JxlEncoderSetDebugImageCallback( + JxlEncoderFrameSettings* frame_settings, JxlDebugImageCallback callback, + void* opaque); + +/** + * Sets the given stats object for gathering various statistics during encoding. + * + * This only has any effect if the encoder was compiled with the appropriate + * debug build flags. + * + * @param frame_settings set of options and metadata for this frame. Also + * includes reference to the encoder object. + * @param stats object that can be used to query the gathered stats (created + * by @ref JxlEncoderStatsCreate) + */ +JXL_EXPORT void JxlEncoderCollectStats(JxlEncoderFrameSettings* frame_settings, + JxlEncoderStats* stats); + #if defined(__cplusplus) || defined(c_plusplus) } #endif diff --git a/src/JPEGView/libjxl/include/jxl/encode_cxx.h b/src/JPEGView/libjxl/include/jxl/encode_cxx.h index 494c03c7..1f695755 100644 --- a/src/JPEGView/libjxl/include/jxl/encode_cxx.h +++ b/src/JPEGView/libjxl/include/jxl/encode_cxx.h @@ -3,7 +3,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -/// @addtogroup libjxl_encoder +/// @addtogroup libjxl_cpp ///@{ /// /// @file encode_cxx.h @@ -15,9 +15,9 @@ #ifndef JXL_ENCODE_CXX_H_ #define JXL_ENCODE_CXX_H_ -#include +#include -#include "jxl/encode.h" +#include #if !(defined(__cplusplus) || defined(c_plusplus)) #error "This a C++ only header. Use jxl/encode.h from C sources." diff --git a/src/JPEGView/libjxl/include/jxl/parallel_runner.h b/src/JPEGView/libjxl/include/jxl/parallel_runner.h index 45394e97..e71e0aa9 100644 --- a/src/JPEGView/libjxl/include/jxl/parallel_runner.h +++ b/src/JPEGView/libjxl/include/jxl/parallel_runner.h @@ -4,7 +4,7 @@ * license that can be found in the LICENSE file. */ -/** @addtogroup libjxl_common +/** @addtogroup libjxl_threads * @{ */ /** diff --git a/src/JPEGView/libjxl/include/jxl/resizable_parallel_runner.h b/src/JPEGView/libjxl/include/jxl/resizable_parallel_runner.h index f6344bdf..a65015d8 100644 --- a/src/JPEGView/libjxl/include/jxl/resizable_parallel_runner.h +++ b/src/JPEGView/libjxl/include/jxl/resizable_parallel_runner.h @@ -30,15 +30,13 @@ #ifndef JXL_RESIZABLE_PARALLEL_RUNNER_H_ #define JXL_RESIZABLE_PARALLEL_RUNNER_H_ +#include +#include +#include #include #include -#include #include -#include "jxl/jxl_threads_export.h" -#include "jxl/memory_manager.h" -#include "jxl/parallel_runner.h" - #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif diff --git a/src/JPEGView/libjxl/include/jxl/resizable_parallel_runner_cxx.h b/src/JPEGView/libjxl/include/jxl/resizable_parallel_runner_cxx.h index 9a310c81..8c617aee 100644 --- a/src/JPEGView/libjxl/include/jxl/resizable_parallel_runner_cxx.h +++ b/src/JPEGView/libjxl/include/jxl/resizable_parallel_runner_cxx.h @@ -3,7 +3,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -/// @addtogroup libjxl_threads +/// @addtogroup libjxl_cpp /// @{ /// /// @file resizable_parallel_runner_cxx.h @@ -16,9 +16,9 @@ #ifndef JXL_RESIZABLE_PARALLEL_RUNNER_CXX_H_ #define JXL_RESIZABLE_PARALLEL_RUNNER_CXX_H_ -#include +#include -#include "jxl/resizable_parallel_runner.h" +#include #if !(defined(__cplusplus) || defined(c_plusplus)) #error \ diff --git a/src/JPEGView/libjxl/include/jxl/stats.h b/src/JPEGView/libjxl/include/jxl/stats.h new file mode 100644 index 00000000..7aeca263 --- /dev/null +++ b/src/JPEGView/libjxl/include/jxl/stats.h @@ -0,0 +1,103 @@ +/* Copyright (c) the JPEG XL Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style + * license that can be found in the LICENSE file. + */ + +/** @addtogroup libjxl_encoder + * @{ + * @file stats.h + * @brief API to collect various statistics from JXL encoder. + */ + +#ifndef JXL_STATS_H_ +#define JXL_STATS_H_ + +#include +#include + +#if defined(__cplusplus) || defined(c_plusplus) +extern "C" { +#endif + +/** + * Opaque structure that holds the encoder statistics. + * + * Allocated and initialized with JxlEncoderStatsCreate(). + * Cleaned up and deallocated with JxlEncoderStatsDestroy(). + */ +typedef struct JxlEncoderStatsStruct JxlEncoderStats; + +/** + * Creates an instance of JxlEncoderStats and initializes it. + * + * @return pointer to initialized JxlEncoderStats instance + */ +JXL_EXPORT JxlEncoderStats* JxlEncoderStatsCreate(); + +/** + * Deinitializes and frees JxlEncoderStats instance. + * + * @param stats instance to be cleaned up and deallocated. No-op if stats is + * null pointer. + */ +JXL_EXPORT void JxlEncoderStatsDestroy(JxlEncoderStats* stats); + +/** Data type for querying JxlEncoderStats object + */ +typedef enum { + JXL_ENC_STAT_HEADER_BITS, + JXL_ENC_STAT_TOC_BITS, + JXL_ENC_STAT_DICTIONARY_BITS, + JXL_ENC_STAT_SPLINES_BITS, + JXL_ENC_STAT_NOISE_BITS, + JXL_ENC_STAT_QUANT_BITS, + JXL_ENC_STAT_MODULAR_TREE_BITS, + JXL_ENC_STAT_MODULAR_GLOBAL_BITS, + JXL_ENC_STAT_DC_BITS, + JXL_ENC_STAT_MODULAR_DC_GROUP_BITS, + JXL_ENC_STAT_CONTROL_FIELDS_BITS, + JXL_ENC_STAT_COEF_ORDER_BITS, + JXL_ENC_STAT_AC_HISTOGRAM_BITS, + JXL_ENC_STAT_AC_BITS, + JXL_ENC_STAT_MODULAR_AC_GROUP_BITS, + JXL_ENC_STAT_NUM_SMALL_BLOCKS, + JXL_ENC_STAT_NUM_DCT4X8_BLOCKS, + JXL_ENC_STAT_NUM_AFV_BLOCKS, + JXL_ENC_STAT_NUM_DCT8_BLOCKS, + JXL_ENC_STAT_NUM_DCT8X32_BLOCKS, + JXL_ENC_STAT_NUM_DCT16_BLOCKS, + JXL_ENC_STAT_NUM_DCT16X32_BLOCKS, + JXL_ENC_STAT_NUM_DCT32_BLOCKS, + JXL_ENC_STAT_NUM_DCT32X64_BLOCKS, + JXL_ENC_STAT_NUM_DCT64_BLOCKS, + JXL_ENC_STAT_NUM_BUTTERAUGLI_ITERS, + JXL_ENC_NUM_STATS, +} JxlEncoderStatsKey; + +/** Returns the value of the statistics corresponding the given key. + * + * @param stats object that was passed to the encoder with a + * @ref JxlEncoderCollectStats function + * @param key the particular statistics to query + * + * @return the value of the statistics + */ +JXL_EXPORT size_t JxlEncoderStatsGet(const JxlEncoderStats* stats, + JxlEncoderStatsKey key); + +/** Updates the values of the given stats object with that of an other. + * + * @param stats object whose values will be updated (usually added together) + * @param other stats object whose values will be merged with stats + */ +JXL_EXPORT void JxlEncoderStatsMerge(JxlEncoderStats* stats, + const JxlEncoderStats* other); + +#if defined(__cplusplus) || defined(c_plusplus) +} +#endif + +#endif /* JXL_STATS_H_ */ + +/** @}*/ diff --git a/src/JPEGView/libjxl/include/jxl/thread_parallel_runner.h b/src/JPEGView/libjxl/include/jxl/thread_parallel_runner.h index 581ff732..0017ced8 100644 --- a/src/JPEGView/libjxl/include/jxl/thread_parallel_runner.h +++ b/src/JPEGView/libjxl/include/jxl/thread_parallel_runner.h @@ -30,15 +30,13 @@ #ifndef JXL_THREAD_PARALLEL_RUNNER_H_ #define JXL_THREAD_PARALLEL_RUNNER_H_ +#include +#include +#include #include #include -#include #include -#include "jxl/jxl_threads_export.h" -#include "jxl/memory_manager.h" -#include "jxl/parallel_runner.h" - #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif diff --git a/src/JPEGView/libjxl/include/jxl/thread_parallel_runner_cxx.h b/src/JPEGView/libjxl/include/jxl/thread_parallel_runner_cxx.h index a71d18c2..ba7e2856 100644 --- a/src/JPEGView/libjxl/include/jxl/thread_parallel_runner_cxx.h +++ b/src/JPEGView/libjxl/include/jxl/thread_parallel_runner_cxx.h @@ -3,7 +3,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -/// @addtogroup libjxl_threads +/// @addtogroup libjxl_cpp /// @{ /// /// @file thread_parallel_runner_cxx.h @@ -15,9 +15,9 @@ #ifndef JXL_THREAD_PARALLEL_RUNNER_CXX_H_ #define JXL_THREAD_PARALLEL_RUNNER_CXX_H_ -#include +#include -#include "jxl/thread_parallel_runner.h" +#include #if !(defined(__cplusplus) || defined(c_plusplus)) #error \ diff --git a/src/JPEGView/libjxl/include/jxl/types.h b/src/JPEGView/libjxl/include/jxl/types.h index 9b5908ef..626f197b 100644 --- a/src/JPEGView/libjxl/include/jxl/types.h +++ b/src/JPEGView/libjxl/include/jxl/types.h @@ -13,11 +13,10 @@ #ifndef JXL_TYPES_H_ #define JXL_TYPES_H_ +#include #include #include -#include "jxl/jxl_export.h" - #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif @@ -55,14 +54,6 @@ typedef enum { JXL_TYPE_FLOAT16 = 5, } JxlDataType; -/* DEPRECATED: bit-packed 1-bit data type. Use JXL_TYPE_UINT8 instead. - */ -JXL_DEPRECATED static const int JXL_TYPE_BOOLEAN = 1; - -/* DEPRECATED: uint32_t data type. Use JXL_TYPE_FLOAT instead. - */ -JXL_DEPRECATED static const int JXL_TYPE_UINT32 = 4; - /** Ordering of multi-byte data. */ typedef enum { @@ -110,7 +101,8 @@ typedef struct { size_t align; } JxlPixelFormat; -/** Settings for the interpretation of the input and output buffers. +/** Settings for the interpretation of UINT input and output buffers. + * (buffers using a FLOAT data type are not affected by this) */ typedef enum { /** This is the default setting, where the encoder expects the input pixels @@ -118,7 +110,7 @@ typedef enum { * input range is 0 .. 65535 and the value 65535 is mapped to 1.0 when * converting to float), and the decoder uses the full range to output * pixels. If the bit depth in the basic info is different from this, the - * encoder expects the values to be rescaled accordingly (e.g multiplied by + * encoder expects the values to be rescaled accordingly (e.g. multiplied by * 65535/4095 for a 12-bit image using UINT16 input data type). */ JXL_BIT_DEPTH_FROM_PIXEL_FORMAT = 0, @@ -151,33 +143,6 @@ typedef struct { */ typedef char JxlBoxType[4]; -/** Types of progressive detail. - * Setting a progressive detail with value N implies all progressive details - * with smaller or equal value. Currently only the following level of - * progressive detail is implemented: - * - kDC (which implies kFrames) - * - kLastPasses (which implies kDC and kFrames) - * - kPasses (which implies kLastPasses, kDC and kFrames) - */ -typedef enum { - // after completed kRegularFrames - kFrames = 0, - // after completed DC (1:8) - kDC = 1, - // after completed AC passes that are the last pass for their resolution - // target. - kLastPasses = 2, - // after completed AC passes that are not the last pass for their resolution - // target. - kPasses = 3, - // during DC frame when lower resolution are completed (1:32, 1:16) - kDCProgressive = 4, - // after completed groups - kDCGroups = 5, - // after completed groups - kGroups = 6, -} JxlProgressiveDetail; - #if defined(__cplusplus) || defined(c_plusplus) } #endif diff --git a/src/JPEGView/libjxl/include/jxl/version.h b/src/JPEGView/libjxl/include/jxl/version.h index bb1d24ad..80035c93 100644 --- a/src/JPEGView/libjxl/include/jxl/version.h +++ b/src/JPEGView/libjxl/include/jxl/version.h @@ -14,8 +14,8 @@ #define JXL_VERSION_H_ #define JPEGXL_MAJOR_VERSION 0 ///< JPEG XL Major version -#define JPEGXL_MINOR_VERSION 8 ///< JPEG XL Minor version -#define JPEGXL_PATCH_VERSION 1 ///< JPEG XL Patch version +#define JPEGXL_MINOR_VERSION 9 ///< JPEG XL Minor version +#define JPEGXL_PATCH_VERSION 0 ///< JPEG XL Patch version /** Can be used to conditionally compile code for a specific JXL version * @param[maj] major version diff --git a/src/JPEGView/libjxl/lib/jxl_dec.lib b/src/JPEGView/libjxl/lib/jxl_dec.lib index eb2c5c05..4396280b 100644 Binary files a/src/JPEGView/libjxl/lib/jxl_dec.lib and b/src/JPEGView/libjxl/lib/jxl_dec.lib differ diff --git a/src/JPEGView/libjxl/lib/jxl_threads.lib b/src/JPEGView/libjxl/lib/jxl_threads.lib index d0689a0c..a60132d4 100644 Binary files a/src/JPEGView/libjxl/lib/jxl_threads.lib and b/src/JPEGView/libjxl/lib/jxl_threads.lib differ diff --git a/src/JPEGView/libjxl/lib64/jxl_dec.lib b/src/JPEGView/libjxl/lib64/jxl_dec.lib index 585fb2ff..f991cfd5 100644 Binary files a/src/JPEGView/libjxl/lib64/jxl_dec.lib and b/src/JPEGView/libjxl/lib64/jxl_dec.lib differ diff --git a/src/JPEGView/libjxl/lib64/jxl_threads.lib b/src/JPEGView/libjxl/lib64/jxl_threads.lib index bb439e3a..dacd29ae 100644 Binary files a/src/JPEGView/libjxl/lib64/jxl_threads.lib and b/src/JPEGView/libjxl/lib64/jxl_threads.lib differ diff --git a/src/JPEGView/libpng-apng/include/png.h b/src/JPEGView/libpng-apng/include/png.h index 9b36ea4b..0b26e307 100644 --- a/src/JPEGView/libpng-apng/include/png.h +++ b/src/JPEGView/libpng-apng/include/png.h @@ -1,9 +1,9 @@ /* png.h - header file for PNG reference library * - * libpng version 1.6.39 - November 20, 2022 + * libpng version 1.6.40 * - * Copyright (c) 2018-2022 Cosmin Truta + * Copyright (c) 2018-2023 Cosmin Truta * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson * Copyright (c) 1996-1997 Andreas Dilger * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. @@ -15,7 +15,7 @@ * libpng versions 0.89, June 1996, through 0.96, May 1997: Andreas Dilger * libpng versions 0.97, January 1998, through 1.6.35, July 2018: * Glenn Randers-Pehrson - * libpng versions 1.6.36, December 2018, through 1.6.39, November 2022: + * libpng versions 1.6.36, December 2018, through 1.6.40, June 2023: * Cosmin Truta * See also "Contributing Authors", below. */ @@ -24,11 +24,17 @@ * COPYRIGHT NOTICE, DISCLAIMER, and LICENSE * ========================================= * + * This modified version of libpng code adds animated PNG support and is + * released under the libpng license described below. The modifications are + * Copyright (c) 2006-2007 Andrew Smith, Copyright (c) 2008-2023 Max Stepin, + * and are delimited by "#ifdef PNG_APNG_SUPPORTED / #endif" directives + * surrounding them in the modified libpng source files. + * * PNG Reference Library License version 2 * --------------------------------------- * - * * Copyright (c) 1995-2022 The PNG Reference Library Authors. - * * Copyright (c) 2018-2022 Cosmin Truta. + * * Copyright (c) 1995-2023 The PNG Reference Library Authors. + * * Copyright (c) 2018-2023 Cosmin Truta. * * Copyright (c) 2000-2002, 2004, 2006-2018 Glenn Randers-Pehrson. * * Copyright (c) 1996-1997 Andreas Dilger. * * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. @@ -239,7 +245,7 @@ * ... * 1.5.30 15 10530 15.so.15.30[.0] * ... - * 1.6.39 16 10639 16.so.16.39[.0] + * 1.6.40 16 10640 16.so.16.40[.0] * * Henceforth the source version will match the shared-library major and * minor numbers; the shared-library major version number will be used for @@ -278,8 +284,9 @@ */ /* Version information for png.h - this should match the version in png.c */ -#define PNG_LIBPNG_VER_STRING "1.6.39" -#define PNG_HEADER_VERSION_STRING " libpng version 1.6.39 - November 20, 2022\n" +#define PNG_LIBPNG_VER_STRING "1.6.40+apng" +#define PNG_HEADER_VERSION_STRING \ + " libpng version 1.6.40+apng - June 21, 2023\n" #define PNG_LIBPNG_VER_SONUM 16 #define PNG_LIBPNG_VER_DLLNUM 16 @@ -287,7 +294,7 @@ /* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */ #define PNG_LIBPNG_VER_MAJOR 1 #define PNG_LIBPNG_VER_MINOR 6 -#define PNG_LIBPNG_VER_RELEASE 39 +#define PNG_LIBPNG_VER_RELEASE 40 /* This should be zero for a public release, or non-zero for a * development version. [Deprecated] @@ -318,7 +325,7 @@ * From version 1.0.1 it is: * XXYYZZ, where XX=major, YY=minor, ZZ=release */ -#define PNG_LIBPNG_VER 10639 /* 1.6.39 */ +#define PNG_LIBPNG_VER 10640 /* 1.6.40 */ /* Library configuration: these options cannot be changed after * the library has been built. @@ -431,19 +438,19 @@ extern "C" { #ifdef PNG_APNG_SUPPORTED /* dispose_op flags from inside fcTL */ -#define PNG_DISPOSE_OP_NONE 0x00U -#define PNG_DISPOSE_OP_BACKGROUND 0x01U -#define PNG_DISPOSE_OP_PREVIOUS 0x02U +#define PNG_DISPOSE_OP_NONE 0x00 +#define PNG_DISPOSE_OP_BACKGROUND 0x01 +#define PNG_DISPOSE_OP_PREVIOUS 0x02 /* blend_op flags from inside fcTL */ -#define PNG_BLEND_OP_SOURCE 0x00U -#define PNG_BLEND_OP_OVER 0x01U -#endif /* PNG_APNG_SUPPORTED */ +#define PNG_BLEND_OP_SOURCE 0x00 +#define PNG_BLEND_OP_OVER 0x01 +#endif /* APNG */ /* This triggers a compiler error in png.c, if png.c and png.h * do not agree upon the version number. */ -typedef char* png_libpng_version_1_6_39; +typedef char* png_libpng_version_1_6_40; /* Basic control structions. Read libpng-manual.txt or libpng.3 for more info. * @@ -3249,74 +3256,75 @@ PNG_EXPORT(244, int, png_set_option, (png_structrp png_ptr, int option, /******************************************************************************* * END OF HARDWARE AND SOFTWARE OPTIONS ******************************************************************************/ + #ifdef PNG_APNG_SUPPORTED -PNG_EXPORT(250, png_uint_32, png_get_acTL, (png_structp png_ptr, +PNG_EXPORT(248, png_uint_32, png_get_acTL, (png_structp png_ptr, png_infop info_ptr, png_uint_32 *num_frames, png_uint_32 *num_plays)); -PNG_EXPORT(251, png_uint_32, png_set_acTL, (png_structp png_ptr, +PNG_EXPORT(249, png_uint_32, png_set_acTL, (png_structp png_ptr, png_infop info_ptr, png_uint_32 num_frames, png_uint_32 num_plays)); -PNG_EXPORT(252, png_uint_32, png_get_num_frames, (png_structp png_ptr, +PNG_EXPORT(250, png_uint_32, png_get_num_frames, (png_structp png_ptr, png_infop info_ptr)); -PNG_EXPORT(253, png_uint_32, png_get_num_plays, (png_structp png_ptr, +PNG_EXPORT(251, png_uint_32, png_get_num_plays, (png_structp png_ptr, png_infop info_ptr)); -PNG_EXPORT(254, png_uint_32, png_get_next_frame_fcTL, +PNG_EXPORT(252, png_uint_32, png_get_next_frame_fcTL, (png_structp png_ptr, png_infop info_ptr, png_uint_32 *width, png_uint_32 *height, png_uint_32 *x_offset, png_uint_32 *y_offset, png_uint_16 *delay_num, png_uint_16 *delay_den, png_byte *dispose_op, png_byte *blend_op)); -PNG_EXPORT(255, png_uint_32, png_set_next_frame_fcTL, +PNG_EXPORT(253, png_uint_32, png_set_next_frame_fcTL, (png_structp png_ptr, png_infop info_ptr, png_uint_32 width, png_uint_32 height, png_uint_32 x_offset, png_uint_32 y_offset, png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op, png_byte blend_op)); -PNG_EXPORT(256, png_uint_32, png_get_next_frame_width, +PNG_EXPORT(254, png_uint_32, png_get_next_frame_width, (png_structp png_ptr, png_infop info_ptr)); -PNG_EXPORT(257, png_uint_32, png_get_next_frame_height, +PNG_EXPORT(255, png_uint_32, png_get_next_frame_height, (png_structp png_ptr, png_infop info_ptr)); -PNG_EXPORT(258, png_uint_32, png_get_next_frame_x_offset, +PNG_EXPORT(256, png_uint_32, png_get_next_frame_x_offset, (png_structp png_ptr, png_infop info_ptr)); -PNG_EXPORT(259, png_uint_32, png_get_next_frame_y_offset, +PNG_EXPORT(257, png_uint_32, png_get_next_frame_y_offset, (png_structp png_ptr, png_infop info_ptr)); -PNG_EXPORT(260, png_uint_16, png_get_next_frame_delay_num, +PNG_EXPORT(258, png_uint_16, png_get_next_frame_delay_num, (png_structp png_ptr, png_infop info_ptr)); -PNG_EXPORT(261, png_uint_16, png_get_next_frame_delay_den, +PNG_EXPORT(259, png_uint_16, png_get_next_frame_delay_den, (png_structp png_ptr, png_infop info_ptr)); -PNG_EXPORT(262, png_byte, png_get_next_frame_dispose_op, +PNG_EXPORT(260, png_byte, png_get_next_frame_dispose_op, (png_structp png_ptr, png_infop info_ptr)); -PNG_EXPORT(263, png_byte, png_get_next_frame_blend_op, +PNG_EXPORT(261, png_byte, png_get_next_frame_blend_op, (png_structp png_ptr, png_infop info_ptr)); -PNG_EXPORT(264, png_byte, png_get_first_frame_is_hidden, +PNG_EXPORT(262, png_byte, png_get_first_frame_is_hidden, (png_structp png_ptr, png_infop info_ptr)); -PNG_EXPORT(265, png_uint_32, png_set_first_frame_is_hidden, +PNG_EXPORT(263, png_uint_32, png_set_first_frame_is_hidden, (png_structp png_ptr, png_infop info_ptr, png_byte is_hidden)); #ifdef PNG_READ_APNG_SUPPORTED -PNG_EXPORT(266, void, png_read_frame_head, (png_structp png_ptr, +PNG_EXPORT(264, void, png_read_frame_head, (png_structp png_ptr, png_infop info_ptr)); #ifdef PNG_PROGRESSIVE_READ_SUPPORTED -PNG_EXPORT(267, void, png_set_progressive_frame_fn, (png_structp png_ptr, +PNG_EXPORT(265, void, png_set_progressive_frame_fn, (png_structp png_ptr, png_progressive_frame_ptr frame_info_fn, png_progressive_frame_ptr frame_end_fn)); -#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ -#endif /* PNG_READ_APNG_SUPPORTED */ +#endif /* PROGRESSIVE_READ */ +#endif /* READ_APNG */ #ifdef PNG_WRITE_APNG_SUPPORTED -PNG_EXPORT(268, void, png_write_frame_head, (png_structp png_ptr, +PNG_EXPORT(266, void, png_write_frame_head, (png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers, png_uint_32 width, png_uint_32 height, png_uint_32 x_offset, png_uint_32 y_offset, png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op, png_byte blend_op)); -PNG_EXPORT(269, void, png_write_frame_tail, (png_structp png_ptr, +PNG_EXPORT(267, void, png_write_frame_tail, (png_structp png_ptr, png_infop info_ptr)); -#endif /* PNG_WRITE_APNG_SUPPORTED */ -#endif /* PNG_APNG_SUPPORTED */ +#endif /* WRITE_APNG */ +#endif /* APNG */ /* Maintainer: Put new public prototypes here ^, in libpng.3, in project * defs, and in scripts/symbols.def. @@ -3330,7 +3338,7 @@ PNG_EXPORT(269, void, png_write_frame_tail, (png_structp png_ptr, PNG_EXPORT_LAST_ORDINAL(269); #else PNG_EXPORT_LAST_ORDINAL(249); -#endif /* PNG_APNG_SUPPORTED */ +#endif /* APNG */ #endif #ifdef __cplusplus diff --git a/src/JPEGView/libpng-apng/include/pngconf.h b/src/JPEGView/libpng-apng/include/pngconf.h index fcb4b430..6671e3c3 100644 --- a/src/JPEGView/libpng-apng/include/pngconf.h +++ b/src/JPEGView/libpng-apng/include/pngconf.h @@ -1,7 +1,7 @@ /* pngconf.h - machine-configurable file for libpng * - * libpng version 1.6.39 + * libpng version 1.6.40 * * Copyright (c) 2018-2022 Cosmin Truta * Copyright (c) 1998-2002,2004,2006-2016,2018 Glenn Randers-Pehrson diff --git a/src/JPEGView/libpng-apng/include/pnglibconf.h b/src/JPEGView/libpng-apng/include/pnglibconf.h index e5948c8c..c7033ae1 100644 --- a/src/JPEGView/libpng-apng/include/pnglibconf.h +++ b/src/JPEGView/libpng-apng/include/pnglibconf.h @@ -1,8 +1,8 @@ /* pnglibconf.h - library build configuration */ -/* libpng version 1.6.39 */ +/* libpng version 1.6.40 */ -/* Copyright (c) 2018-2022 Cosmin Truta */ +/* Copyright (c) 2018-2023 Cosmin Truta */ /* Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson */ /* This code is released under the libpng license. */ diff --git a/src/JPEGView/libpng-apng/lib/libpng16.lib b/src/JPEGView/libpng-apng/lib/libpng16.lib index 6b3a6754..3008a168 100644 Binary files a/src/JPEGView/libpng-apng/lib/libpng16.lib and b/src/JPEGView/libpng-apng/lib/libpng16.lib differ diff --git a/src/JPEGView/libpng-apng/lib/zlib.lib b/src/JPEGView/libpng-apng/lib/zlib.lib index d27390bd..1906b6d4 100644 Binary files a/src/JPEGView/libpng-apng/lib/zlib.lib and b/src/JPEGView/libpng-apng/lib/zlib.lib differ diff --git a/src/JPEGView/libpng-apng/lib64/libpng16.lib b/src/JPEGView/libpng-apng/lib64/libpng16.lib index 745e1ec6..d6b194aa 100644 Binary files a/src/JPEGView/libpng-apng/lib64/libpng16.lib and b/src/JPEGView/libpng-apng/lib64/libpng16.lib differ diff --git a/src/JPEGView/libpng-apng/lib64/zlib.lib b/src/JPEGView/libpng-apng/lib64/zlib.lib index d0ef5b23..4e20d6f2 100644 Binary files a/src/JPEGView/libpng-apng/lib64/zlib.lib and b/src/JPEGView/libpng-apng/lib64/zlib.lib differ diff --git a/src/JPEGView/libwebp/include/webp/decode.h b/src/JPEGView/libwebp/include/webp/decode.h index 0386bb99..0177b120 100644 --- a/src/JPEGView/libwebp/include/webp/decode.h +++ b/src/JPEGView/libwebp/include/webp/decode.h @@ -1,503 +1,504 @@ -// Copyright 2010 Google Inc. All Rights Reserved. -// -// Use of this source code is governed by a BSD-style license -// that can be found in the COPYING file in the root of the source -// tree. An additional intellectual property rights grant can be found -// in the file PATENTS. All contributing project authors may -// be found in the AUTHORS file in the root of the source tree. -// ----------------------------------------------------------------------------- -// -// Main decoding functions for WebP images. -// -// Author: Skal (pascal.massimino@gmail.com) - -#ifndef WEBP_WEBP_DECODE_H_ -#define WEBP_WEBP_DECODE_H_ - -#include "./types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define WEBP_DECODER_ABI_VERSION 0x0209 // MAJOR(8b) + MINOR(8b) - -// Note: forward declaring enumerations is not allowed in (strict) C and C++, -// the types are left here for reference. -// typedef enum VP8StatusCode VP8StatusCode; -// typedef enum WEBP_CSP_MODE WEBP_CSP_MODE; -typedef struct WebPRGBABuffer WebPRGBABuffer; -typedef struct WebPYUVABuffer WebPYUVABuffer; -typedef struct WebPDecBuffer WebPDecBuffer; -typedef struct WebPIDecoder WebPIDecoder; -typedef struct WebPBitstreamFeatures WebPBitstreamFeatures; -typedef struct WebPDecoderOptions WebPDecoderOptions; -typedef struct WebPDecoderConfig WebPDecoderConfig; - -// Return the decoder's version number, packed in hexadecimal using 8bits for -// each of major/minor/revision. E.g: v2.5.7 is 0x020507. -WEBP_EXTERN int WebPGetDecoderVersion(void); - -// Retrieve basic header information: width, height. -// This function will also validate the header, returning true on success, -// false otherwise. '*width' and '*height' are only valid on successful return. -// Pointers 'width' and 'height' can be passed NULL if deemed irrelevant. -// Note: The following chunk sequences (before the raw VP8/VP8L data) are -// considered valid by this function: -// RIFF + VP8(L) -// RIFF + VP8X + (optional chunks) + VP8(L) -// ALPH + VP8 <-- Not a valid WebP format: only allowed for internal purpose. -// VP8(L) <-- Not a valid WebP format: only allowed for internal purpose. -WEBP_EXTERN int WebPGetInfo(const uint8_t* data, size_t data_size, - int* width, int* height); - -// Decodes WebP images pointed to by 'data' and returns RGBA samples, along -// with the dimensions in *width and *height. The ordering of samples in -// memory is R, G, B, A, R, G, B, A... in scan order (endian-independent). -// The returned pointer should be deleted calling WebPFree(). -// Returns NULL in case of error. -WEBP_EXTERN uint8_t* WebPDecodeRGBA(const uint8_t* data, size_t data_size, - int* width, int* height); - -// Same as WebPDecodeRGBA, but returning A, R, G, B, A, R, G, B... ordered data. -WEBP_EXTERN uint8_t* WebPDecodeARGB(const uint8_t* data, size_t data_size, - int* width, int* height); - -// Same as WebPDecodeRGBA, but returning B, G, R, A, B, G, R, A... ordered data. -WEBP_EXTERN uint8_t* WebPDecodeBGRA(const uint8_t* data, size_t data_size, - int* width, int* height); - -// Same as WebPDecodeRGBA, but returning R, G, B, R, G, B... ordered data. -// If the bitstream contains transparency, it is ignored. -WEBP_EXTERN uint8_t* WebPDecodeRGB(const uint8_t* data, size_t data_size, - int* width, int* height); - -// Same as WebPDecodeRGB, but returning B, G, R, B, G, R... ordered data. -WEBP_EXTERN uint8_t* WebPDecodeBGR(const uint8_t* data, size_t data_size, - int* width, int* height); - - -// Decode WebP images pointed to by 'data' to Y'UV format(*). The pointer -// returned is the Y samples buffer. Upon return, *u and *v will point to -// the U and V chroma data. These U and V buffers need NOT be passed to -// WebPFree(), unlike the returned Y luma one. The dimension of the U and V -// planes are both (*width + 1) / 2 and (*height + 1)/ 2. -// Upon return, the Y buffer has a stride returned as '*stride', while U and V -// have a common stride returned as '*uv_stride'. -// Return NULL in case of error. -// (*) Also named Y'CbCr. See: https://en.wikipedia.org/wiki/YCbCr -WEBP_EXTERN uint8_t* WebPDecodeYUV(const uint8_t* data, size_t data_size, - int* width, int* height, - uint8_t** u, uint8_t** v, - int* stride, int* uv_stride); - -// These five functions are variants of the above ones, that decode the image -// directly into a pre-allocated buffer 'output_buffer'. The maximum storage -// available in this buffer is indicated by 'output_buffer_size'. If this -// storage is not sufficient (or an error occurred), NULL is returned. -// Otherwise, output_buffer is returned, for convenience. -// The parameter 'output_stride' specifies the distance (in bytes) -// between scanlines. Hence, output_buffer_size is expected to be at least -// output_stride x picture-height. -WEBP_EXTERN uint8_t* WebPDecodeRGBAInto( - const uint8_t* data, size_t data_size, - uint8_t* output_buffer, size_t output_buffer_size, int output_stride); -WEBP_EXTERN uint8_t* WebPDecodeARGBInto( - const uint8_t* data, size_t data_size, - uint8_t* output_buffer, size_t output_buffer_size, int output_stride); -WEBP_EXTERN uint8_t* WebPDecodeBGRAInto( - const uint8_t* data, size_t data_size, - uint8_t* output_buffer, size_t output_buffer_size, int output_stride); - -// RGB and BGR variants. Here too the transparency information, if present, -// will be dropped and ignored. -WEBP_EXTERN uint8_t* WebPDecodeRGBInto( - const uint8_t* data, size_t data_size, - uint8_t* output_buffer, size_t output_buffer_size, int output_stride); -WEBP_EXTERN uint8_t* WebPDecodeBGRInto( - const uint8_t* data, size_t data_size, - uint8_t* output_buffer, size_t output_buffer_size, int output_stride); - -// WebPDecodeYUVInto() is a variant of WebPDecodeYUV() that operates directly -// into pre-allocated luma/chroma plane buffers. This function requires the -// strides to be passed: one for the luma plane and one for each of the -// chroma ones. The size of each plane buffer is passed as 'luma_size', -// 'u_size' and 'v_size' respectively. -// Pointer to the luma plane ('*luma') is returned or NULL if an error occurred -// during decoding (or because some buffers were found to be too small). -WEBP_EXTERN uint8_t* WebPDecodeYUVInto( - const uint8_t* data, size_t data_size, - uint8_t* luma, size_t luma_size, int luma_stride, - uint8_t* u, size_t u_size, int u_stride, - uint8_t* v, size_t v_size, int v_stride); - -//------------------------------------------------------------------------------ -// Output colorspaces and buffer - -// Colorspaces -// Note: the naming describes the byte-ordering of packed samples in memory. -// For instance, MODE_BGRA relates to samples ordered as B,G,R,A,B,G,R,A,... -// Non-capital names (e.g.:MODE_Argb) relates to pre-multiplied RGB channels. -// RGBA-4444 and RGB-565 colorspaces are represented by following byte-order: -// RGBA-4444: [r3 r2 r1 r0 g3 g2 g1 g0], [b3 b2 b1 b0 a3 a2 a1 a0], ... -// RGB-565: [r4 r3 r2 r1 r0 g5 g4 g3], [g2 g1 g0 b4 b3 b2 b1 b0], ... -// In the case WEBP_SWAP_16BITS_CSP is defined, the bytes are swapped for -// these two modes: -// RGBA-4444: [b3 b2 b1 b0 a3 a2 a1 a0], [r3 r2 r1 r0 g3 g2 g1 g0], ... -// RGB-565: [g2 g1 g0 b4 b3 b2 b1 b0], [r4 r3 r2 r1 r0 g5 g4 g3], ... - -typedef enum WEBP_CSP_MODE { - MODE_RGB = 0, MODE_RGBA = 1, - MODE_BGR = 2, MODE_BGRA = 3, - MODE_ARGB = 4, MODE_RGBA_4444 = 5, - MODE_RGB_565 = 6, - // RGB-premultiplied transparent modes (alpha value is preserved) - MODE_rgbA = 7, - MODE_bgrA = 8, - MODE_Argb = 9, - MODE_rgbA_4444 = 10, - // YUV modes must come after RGB ones. - MODE_YUV = 11, MODE_YUVA = 12, // yuv 4:2:0 - MODE_LAST = 13 -} WEBP_CSP_MODE; - -// Some useful macros: -static WEBP_INLINE int WebPIsPremultipliedMode(WEBP_CSP_MODE mode) { - return (mode == MODE_rgbA || mode == MODE_bgrA || mode == MODE_Argb || - mode == MODE_rgbA_4444); -} - -static WEBP_INLINE int WebPIsAlphaMode(WEBP_CSP_MODE mode) { - return (mode == MODE_RGBA || mode == MODE_BGRA || mode == MODE_ARGB || - mode == MODE_RGBA_4444 || mode == MODE_YUVA || - WebPIsPremultipliedMode(mode)); -} - -static WEBP_INLINE int WebPIsRGBMode(WEBP_CSP_MODE mode) { - return (mode < MODE_YUV); -} - -//------------------------------------------------------------------------------ -// WebPDecBuffer: Generic structure for describing the output sample buffer. - -struct WebPRGBABuffer { // view as RGBA - uint8_t* rgba; // pointer to RGBA samples - int stride; // stride in bytes from one scanline to the next. - size_t size; // total size of the *rgba buffer. -}; - -struct WebPYUVABuffer { // view as YUVA - uint8_t* y, *u, *v, *a; // pointer to luma, chroma U/V, alpha samples - int y_stride; // luma stride - int u_stride, v_stride; // chroma strides - int a_stride; // alpha stride - size_t y_size; // luma plane size - size_t u_size, v_size; // chroma planes size - size_t a_size; // alpha-plane size -}; - -// Output buffer -struct WebPDecBuffer { - WEBP_CSP_MODE colorspace; // Colorspace. - int width, height; // Dimensions. - int is_external_memory; // If non-zero, 'internal_memory' pointer is not - // used. If value is '2' or more, the external - // memory is considered 'slow' and multiple - // read/write will be avoided. - union { - WebPRGBABuffer RGBA; - WebPYUVABuffer YUVA; - } u; // Nameless union of buffer parameters. - uint32_t pad[4]; // padding for later use - - uint8_t* private_memory; // Internally allocated memory (only when - // is_external_memory is 0). Should not be used - // externally, but accessed via the buffer union. -}; - -// Internal, version-checked, entry point -WEBP_EXTERN int WebPInitDecBufferInternal(WebPDecBuffer*, int); - -// Initialize the structure as empty. Must be called before any other use. -// Returns false in case of version mismatch -static WEBP_INLINE int WebPInitDecBuffer(WebPDecBuffer* buffer) { - return WebPInitDecBufferInternal(buffer, WEBP_DECODER_ABI_VERSION); -} - -// Free any memory associated with the buffer. Must always be called last. -// Note: doesn't free the 'buffer' structure itself. -WEBP_EXTERN void WebPFreeDecBuffer(WebPDecBuffer* buffer); - -//------------------------------------------------------------------------------ -// Enumeration of the status codes - -typedef enum VP8StatusCode { - VP8_STATUS_OK = 0, - VP8_STATUS_OUT_OF_MEMORY, - VP8_STATUS_INVALID_PARAM, - VP8_STATUS_BITSTREAM_ERROR, - VP8_STATUS_UNSUPPORTED_FEATURE, - VP8_STATUS_SUSPENDED, - VP8_STATUS_USER_ABORT, - VP8_STATUS_NOT_ENOUGH_DATA -} VP8StatusCode; - -//------------------------------------------------------------------------------ -// Incremental decoding -// -// This API allows streamlined decoding of partial data. -// Picture can be incrementally decoded as data become available thanks to the -// WebPIDecoder object. This object can be left in a SUSPENDED state if the -// picture is only partially decoded, pending additional input. -// Code example: -// -// WebPInitDecBuffer(&output_buffer); -// output_buffer.colorspace = mode; -// ... -// WebPIDecoder* idec = WebPINewDecoder(&output_buffer); -// while (additional_data_is_available) { -// // ... (get additional data in some new_data[] buffer) -// status = WebPIAppend(idec, new_data, new_data_size); -// if (status != VP8_STATUS_OK && status != VP8_STATUS_SUSPENDED) { -// break; // an error occurred. -// } -// -// // The above call decodes the current available buffer. -// // Part of the image can now be refreshed by calling -// // WebPIDecGetRGB()/WebPIDecGetYUVA() etc. -// } -// WebPIDelete(idec); - -// Creates a new incremental decoder with the supplied buffer parameter. -// This output_buffer can be passed NULL, in which case a default output buffer -// is used (with MODE_RGB). Otherwise, an internal reference to 'output_buffer' -// is kept, which means that the lifespan of 'output_buffer' must be larger than -// that of the returned WebPIDecoder object. -// The supplied 'output_buffer' content MUST NOT be changed between calls to -// WebPIAppend() or WebPIUpdate() unless 'output_buffer.is_external_memory' is -// not set to 0. In such a case, it is allowed to modify the pointers, size and -// stride of output_buffer.u.RGBA or output_buffer.u.YUVA, provided they remain -// within valid bounds. -// All other fields of WebPDecBuffer MUST remain constant between calls. -// Returns NULL if the allocation failed. -WEBP_EXTERN WebPIDecoder* WebPINewDecoder(WebPDecBuffer* output_buffer); - -// This function allocates and initializes an incremental-decoder object, which -// will output the RGB/A samples specified by 'csp' into a preallocated -// buffer 'output_buffer'. The size of this buffer is at least -// 'output_buffer_size' and the stride (distance in bytes between two scanlines) -// is specified by 'output_stride'. -// Additionally, output_buffer can be passed NULL in which case the output -// buffer will be allocated automatically when the decoding starts. The -// colorspace 'csp' is taken into account for allocating this buffer. All other -// parameters are ignored. -// Returns NULL if the allocation failed, or if some parameters are invalid. -WEBP_EXTERN WebPIDecoder* WebPINewRGB( - WEBP_CSP_MODE csp, - uint8_t* output_buffer, size_t output_buffer_size, int output_stride); - -// This function allocates and initializes an incremental-decoder object, which -// will output the raw luma/chroma samples into a preallocated planes if -// supplied. The luma plane is specified by its pointer 'luma', its size -// 'luma_size' and its stride 'luma_stride'. Similarly, the chroma-u plane -// is specified by the 'u', 'u_size' and 'u_stride' parameters, and the chroma-v -// plane by 'v' and 'v_size'. And same for the alpha-plane. The 'a' pointer -// can be pass NULL in case one is not interested in the transparency plane. -// Conversely, 'luma' can be passed NULL if no preallocated planes are supplied. -// In this case, the output buffer will be automatically allocated (using -// MODE_YUVA) when decoding starts. All parameters are then ignored. -// Returns NULL if the allocation failed or if a parameter is invalid. -WEBP_EXTERN WebPIDecoder* WebPINewYUVA( - uint8_t* luma, size_t luma_size, int luma_stride, - uint8_t* u, size_t u_size, int u_stride, - uint8_t* v, size_t v_size, int v_stride, - uint8_t* a, size_t a_size, int a_stride); - -// Deprecated version of the above, without the alpha plane. -// Kept for backward compatibility. -WEBP_EXTERN WebPIDecoder* WebPINewYUV( - uint8_t* luma, size_t luma_size, int luma_stride, - uint8_t* u, size_t u_size, int u_stride, - uint8_t* v, size_t v_size, int v_stride); - -// Deletes the WebPIDecoder object and associated memory. Must always be called -// if WebPINewDecoder, WebPINewRGB or WebPINewYUV succeeded. -WEBP_EXTERN void WebPIDelete(WebPIDecoder* idec); - -// Copies and decodes the next available data. Returns VP8_STATUS_OK when -// the image is successfully decoded. Returns VP8_STATUS_SUSPENDED when more -// data is expected. Returns error in other cases. -WEBP_EXTERN VP8StatusCode WebPIAppend( - WebPIDecoder* idec, const uint8_t* data, size_t data_size); - -// A variant of the above function to be used when data buffer contains -// partial data from the beginning. In this case data buffer is not copied -// to the internal memory. -// Note that the value of the 'data' pointer can change between calls to -// WebPIUpdate, for instance when the data buffer is resized to fit larger data. -WEBP_EXTERN VP8StatusCode WebPIUpdate( - WebPIDecoder* idec, const uint8_t* data, size_t data_size); - -// Returns the RGB/A image decoded so far. Returns NULL if output params -// are not initialized yet. The RGB/A output type corresponds to the colorspace -// specified during call to WebPINewDecoder() or WebPINewRGB(). -// *last_y is the index of last decoded row in raster scan order. Some pointers -// (*last_y, *width etc.) can be NULL if corresponding information is not -// needed. The values in these pointers are only valid on successful (non-NULL) -// return. -WEBP_EXTERN uint8_t* WebPIDecGetRGB( - const WebPIDecoder* idec, int* last_y, - int* width, int* height, int* stride); - -// Same as above function to get a YUVA image. Returns pointer to the luma -// plane or NULL in case of error. If there is no alpha information -// the alpha pointer '*a' will be returned NULL. -WEBP_EXTERN uint8_t* WebPIDecGetYUVA( - const WebPIDecoder* idec, int* last_y, - uint8_t** u, uint8_t** v, uint8_t** a, - int* width, int* height, int* stride, int* uv_stride, int* a_stride); - -// Deprecated alpha-less version of WebPIDecGetYUVA(): it will ignore the -// alpha information (if present). Kept for backward compatibility. -static WEBP_INLINE uint8_t* WebPIDecGetYUV( - const WebPIDecoder* idec, int* last_y, uint8_t** u, uint8_t** v, - int* width, int* height, int* stride, int* uv_stride) { - return WebPIDecGetYUVA(idec, last_y, u, v, NULL, width, height, - stride, uv_stride, NULL); -} - -// Generic call to retrieve information about the displayable area. -// If non NULL, the left/right/width/height pointers are filled with the visible -// rectangular area so far. -// Returns NULL in case the incremental decoder object is in an invalid state. -// Otherwise returns the pointer to the internal representation. This structure -// is read-only, tied to WebPIDecoder's lifespan and should not be modified. -WEBP_EXTERN const WebPDecBuffer* WebPIDecodedArea( - const WebPIDecoder* idec, int* left, int* top, int* width, int* height); - -//------------------------------------------------------------------------------ -// Advanced decoding parametrization -// -// Code sample for using the advanced decoding API -/* - // A) Init a configuration object - WebPDecoderConfig config; - CHECK(WebPInitDecoderConfig(&config)); - - // B) optional: retrieve the bitstream's features. - CHECK(WebPGetFeatures(data, data_size, &config.input) == VP8_STATUS_OK); - - // C) Adjust 'config', if needed - config.no_fancy_upsampling = 1; - config.output.colorspace = MODE_BGRA; - // etc. - - // Note that you can also make config.output point to an externally - // supplied memory buffer, provided it's big enough to store the decoded - // picture. Otherwise, config.output will just be used to allocate memory - // and store the decoded picture. - - // D) Decode! - CHECK(WebPDecode(data, data_size, &config) == VP8_STATUS_OK); - - // E) Decoded image is now in config.output (and config.output.u.RGBA) - - // F) Reclaim memory allocated in config's object. It's safe to call - // this function even if the memory is external and wasn't allocated - // by WebPDecode(). - WebPFreeDecBuffer(&config.output); -*/ - -// Features gathered from the bitstream -struct WebPBitstreamFeatures { - int width; // Width in pixels, as read from the bitstream. - int height; // Height in pixels, as read from the bitstream. - int has_alpha; // True if the bitstream contains an alpha channel. - int has_animation; // True if the bitstream is an animation. - int format; // 0 = undefined (/mixed), 1 = lossy, 2 = lossless - - uint32_t pad[5]; // padding for later use -}; - -// Internal, version-checked, entry point -WEBP_EXTERN VP8StatusCode WebPGetFeaturesInternal( - const uint8_t*, size_t, WebPBitstreamFeatures*, int); - -// Retrieve features from the bitstream. The *features structure is filled -// with information gathered from the bitstream. -// Returns VP8_STATUS_OK when the features are successfully retrieved. Returns -// VP8_STATUS_NOT_ENOUGH_DATA when more data is needed to retrieve the -// features from headers. Returns error in other cases. -// Note: The following chunk sequences (before the raw VP8/VP8L data) are -// considered valid by this function: -// RIFF + VP8(L) -// RIFF + VP8X + (optional chunks) + VP8(L) -// ALPH + VP8 <-- Not a valid WebP format: only allowed for internal purpose. -// VP8(L) <-- Not a valid WebP format: only allowed for internal purpose. -static WEBP_INLINE VP8StatusCode WebPGetFeatures( - const uint8_t* data, size_t data_size, - WebPBitstreamFeatures* features) { - return WebPGetFeaturesInternal(data, data_size, features, - WEBP_DECODER_ABI_VERSION); -} - -// Decoding options -struct WebPDecoderOptions { - int bypass_filtering; // if true, skip the in-loop filtering - int no_fancy_upsampling; // if true, use faster pointwise upsampler - int use_cropping; // if true, cropping is applied _first_ - int crop_left, crop_top; // top-left position for cropping. - // Will be snapped to even values. - int crop_width, crop_height; // dimension of the cropping area - int use_scaling; // if true, scaling is applied _afterward_ - int scaled_width, scaled_height; // final resolution - int use_threads; // if true, use multi-threaded decoding - int dithering_strength; // dithering strength (0=Off, 100=full) - int flip; // if true, flip output vertically - int alpha_dithering_strength; // alpha dithering strength in [0..100] - - uint32_t pad[5]; // padding for later use -}; - -// Main object storing the configuration for advanced decoding. -struct WebPDecoderConfig { - WebPBitstreamFeatures input; // Immutable bitstream features (optional) - WebPDecBuffer output; // Output buffer (can point to external mem) - WebPDecoderOptions options; // Decoding options -}; - -// Internal, version-checked, entry point -WEBP_EXTERN int WebPInitDecoderConfigInternal(WebPDecoderConfig*, int); - -// Initialize the configuration as empty. This function must always be -// called first, unless WebPGetFeatures() is to be called. -// Returns false in case of mismatched version. -static WEBP_INLINE int WebPInitDecoderConfig(WebPDecoderConfig* config) { - return WebPInitDecoderConfigInternal(config, WEBP_DECODER_ABI_VERSION); -} - -// Instantiate a new incremental decoder object with the requested -// configuration. The bitstream can be passed using 'data' and 'data_size' -// parameter, in which case the features will be parsed and stored into -// config->input. Otherwise, 'data' can be NULL and no parsing will occur. -// Note that 'config' can be NULL too, in which case a default configuration -// is used. If 'config' is not NULL, it must outlive the WebPIDecoder object -// as some references to its fields will be used. No internal copy of 'config' -// is made. -// The return WebPIDecoder object must always be deleted calling WebPIDelete(). -// Returns NULL in case of error (and config->status will then reflect -// the error condition, if available). -WEBP_EXTERN WebPIDecoder* WebPIDecode(const uint8_t* data, size_t data_size, - WebPDecoderConfig* config); - -// Non-incremental version. This version decodes the full data at once, taking -// 'config' into account. Returns decoding status (which should be VP8_STATUS_OK -// if the decoding was successful). Note that 'config' cannot be NULL. -WEBP_EXTERN VP8StatusCode WebPDecode(const uint8_t* data, size_t data_size, - WebPDecoderConfig* config); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // WEBP_WEBP_DECODE_H_ +// Copyright 2010 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Main decoding functions for WebP images. +// +// Author: Skal (pascal.massimino@gmail.com) + +#ifndef WEBP_WEBP_DECODE_H_ +#define WEBP_WEBP_DECODE_H_ + +#include "./types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define WEBP_DECODER_ABI_VERSION 0x0209 // MAJOR(8b) + MINOR(8b) + +// Note: forward declaring enumerations is not allowed in (strict) C and C++, +// the types are left here for reference. +// typedef enum VP8StatusCode VP8StatusCode; +// typedef enum WEBP_CSP_MODE WEBP_CSP_MODE; +typedef struct WebPRGBABuffer WebPRGBABuffer; +typedef struct WebPYUVABuffer WebPYUVABuffer; +typedef struct WebPDecBuffer WebPDecBuffer; +typedef struct WebPIDecoder WebPIDecoder; +typedef struct WebPBitstreamFeatures WebPBitstreamFeatures; +typedef struct WebPDecoderOptions WebPDecoderOptions; +typedef struct WebPDecoderConfig WebPDecoderConfig; + +// Return the decoder's version number, packed in hexadecimal using 8bits for +// each of major/minor/revision. E.g: v2.5.7 is 0x020507. +WEBP_EXTERN int WebPGetDecoderVersion(void); + +// Retrieve basic header information: width, height. +// This function will also validate the header, returning true on success, +// false otherwise. '*width' and '*height' are only valid on successful return. +// Pointers 'width' and 'height' can be passed NULL if deemed irrelevant. +// Note: The following chunk sequences (before the raw VP8/VP8L data) are +// considered valid by this function: +// RIFF + VP8(L) +// RIFF + VP8X + (optional chunks) + VP8(L) +// ALPH + VP8 <-- Not a valid WebP format: only allowed for internal purpose. +// VP8(L) <-- Not a valid WebP format: only allowed for internal purpose. +WEBP_EXTERN int WebPGetInfo(const uint8_t* data, size_t data_size, + int* width, int* height); + +// Decodes WebP images pointed to by 'data' and returns RGBA samples, along +// with the dimensions in *width and *height. The ordering of samples in +// memory is R, G, B, A, R, G, B, A... in scan order (endian-independent). +// The returned pointer should be deleted calling WebPFree(). +// Returns NULL in case of error. +WEBP_EXTERN uint8_t* WebPDecodeRGBA(const uint8_t* data, size_t data_size, + int* width, int* height); + +// Same as WebPDecodeRGBA, but returning A, R, G, B, A, R, G, B... ordered data. +WEBP_EXTERN uint8_t* WebPDecodeARGB(const uint8_t* data, size_t data_size, + int* width, int* height); + +// Same as WebPDecodeRGBA, but returning B, G, R, A, B, G, R, A... ordered data. +WEBP_EXTERN uint8_t* WebPDecodeBGRA(const uint8_t* data, size_t data_size, + int* width, int* height); + +// Same as WebPDecodeRGBA, but returning R, G, B, R, G, B... ordered data. +// If the bitstream contains transparency, it is ignored. +WEBP_EXTERN uint8_t* WebPDecodeRGB(const uint8_t* data, size_t data_size, + int* width, int* height); + +// Same as WebPDecodeRGB, but returning B, G, R, B, G, R... ordered data. +WEBP_EXTERN uint8_t* WebPDecodeBGR(const uint8_t* data, size_t data_size, + int* width, int* height); + + +// Decode WebP images pointed to by 'data' to Y'UV format(*). The pointer +// returned is the Y samples buffer. Upon return, *u and *v will point to +// the U and V chroma data. These U and V buffers need NOT be passed to +// WebPFree(), unlike the returned Y luma one. The dimension of the U and V +// planes are both (*width + 1) / 2 and (*height + 1) / 2. +// Upon return, the Y buffer has a stride returned as '*stride', while U and V +// have a common stride returned as '*uv_stride'. +// 'width' and 'height' may be NULL, the other pointers must not be. +// Returns NULL in case of error. +// (*) Also named Y'CbCr. See: https://en.wikipedia.org/wiki/YCbCr +WEBP_EXTERN uint8_t* WebPDecodeYUV(const uint8_t* data, size_t data_size, + int* width, int* height, + uint8_t** u, uint8_t** v, + int* stride, int* uv_stride); + +// These five functions are variants of the above ones, that decode the image +// directly into a pre-allocated buffer 'output_buffer'. The maximum storage +// available in this buffer is indicated by 'output_buffer_size'. If this +// storage is not sufficient (or an error occurred), NULL is returned. +// Otherwise, output_buffer is returned, for convenience. +// The parameter 'output_stride' specifies the distance (in bytes) +// between scanlines. Hence, output_buffer_size is expected to be at least +// output_stride x picture-height. +WEBP_EXTERN uint8_t* WebPDecodeRGBAInto( + const uint8_t* data, size_t data_size, + uint8_t* output_buffer, size_t output_buffer_size, int output_stride); +WEBP_EXTERN uint8_t* WebPDecodeARGBInto( + const uint8_t* data, size_t data_size, + uint8_t* output_buffer, size_t output_buffer_size, int output_stride); +WEBP_EXTERN uint8_t* WebPDecodeBGRAInto( + const uint8_t* data, size_t data_size, + uint8_t* output_buffer, size_t output_buffer_size, int output_stride); + +// RGB and BGR variants. Here too the transparency information, if present, +// will be dropped and ignored. +WEBP_EXTERN uint8_t* WebPDecodeRGBInto( + const uint8_t* data, size_t data_size, + uint8_t* output_buffer, size_t output_buffer_size, int output_stride); +WEBP_EXTERN uint8_t* WebPDecodeBGRInto( + const uint8_t* data, size_t data_size, + uint8_t* output_buffer, size_t output_buffer_size, int output_stride); + +// WebPDecodeYUVInto() is a variant of WebPDecodeYUV() that operates directly +// into pre-allocated luma/chroma plane buffers. This function requires the +// strides to be passed: one for the luma plane and one for each of the +// chroma ones. The size of each plane buffer is passed as 'luma_size', +// 'u_size' and 'v_size' respectively. +// Pointer to the luma plane ('*luma') is returned or NULL if an error occurred +// during decoding (or because some buffers were found to be too small). +WEBP_EXTERN uint8_t* WebPDecodeYUVInto( + const uint8_t* data, size_t data_size, + uint8_t* luma, size_t luma_size, int luma_stride, + uint8_t* u, size_t u_size, int u_stride, + uint8_t* v, size_t v_size, int v_stride); + +//------------------------------------------------------------------------------ +// Output colorspaces and buffer + +// Colorspaces +// Note: the naming describes the byte-ordering of packed samples in memory. +// For instance, MODE_BGRA relates to samples ordered as B,G,R,A,B,G,R,A,... +// Non-capital names (e.g.:MODE_Argb) relates to pre-multiplied RGB channels. +// RGBA-4444 and RGB-565 colorspaces are represented by following byte-order: +// RGBA-4444: [r3 r2 r1 r0 g3 g2 g1 g0], [b3 b2 b1 b0 a3 a2 a1 a0], ... +// RGB-565: [r4 r3 r2 r1 r0 g5 g4 g3], [g2 g1 g0 b4 b3 b2 b1 b0], ... +// In the case WEBP_SWAP_16BITS_CSP is defined, the bytes are swapped for +// these two modes: +// RGBA-4444: [b3 b2 b1 b0 a3 a2 a1 a0], [r3 r2 r1 r0 g3 g2 g1 g0], ... +// RGB-565: [g2 g1 g0 b4 b3 b2 b1 b0], [r4 r3 r2 r1 r0 g5 g4 g3], ... + +typedef enum WEBP_CSP_MODE { + MODE_RGB = 0, MODE_RGBA = 1, + MODE_BGR = 2, MODE_BGRA = 3, + MODE_ARGB = 4, MODE_RGBA_4444 = 5, + MODE_RGB_565 = 6, + // RGB-premultiplied transparent modes (alpha value is preserved) + MODE_rgbA = 7, + MODE_bgrA = 8, + MODE_Argb = 9, + MODE_rgbA_4444 = 10, + // YUV modes must come after RGB ones. + MODE_YUV = 11, MODE_YUVA = 12, // yuv 4:2:0 + MODE_LAST = 13 +} WEBP_CSP_MODE; + +// Some useful macros: +static WEBP_INLINE int WebPIsPremultipliedMode(WEBP_CSP_MODE mode) { + return (mode == MODE_rgbA || mode == MODE_bgrA || mode == MODE_Argb || + mode == MODE_rgbA_4444); +} + +static WEBP_INLINE int WebPIsAlphaMode(WEBP_CSP_MODE mode) { + return (mode == MODE_RGBA || mode == MODE_BGRA || mode == MODE_ARGB || + mode == MODE_RGBA_4444 || mode == MODE_YUVA || + WebPIsPremultipliedMode(mode)); +} + +static WEBP_INLINE int WebPIsRGBMode(WEBP_CSP_MODE mode) { + return (mode < MODE_YUV); +} + +//------------------------------------------------------------------------------ +// WebPDecBuffer: Generic structure for describing the output sample buffer. + +struct WebPRGBABuffer { // view as RGBA + uint8_t* rgba; // pointer to RGBA samples + int stride; // stride in bytes from one scanline to the next. + size_t size; // total size of the *rgba buffer. +}; + +struct WebPYUVABuffer { // view as YUVA + uint8_t* y, *u, *v, *a; // pointer to luma, chroma U/V, alpha samples + int y_stride; // luma stride + int u_stride, v_stride; // chroma strides + int a_stride; // alpha stride + size_t y_size; // luma plane size + size_t u_size, v_size; // chroma planes size + size_t a_size; // alpha-plane size +}; + +// Output buffer +struct WebPDecBuffer { + WEBP_CSP_MODE colorspace; // Colorspace. + int width, height; // Dimensions. + int is_external_memory; // If non-zero, 'internal_memory' pointer is not + // used. If value is '2' or more, the external + // memory is considered 'slow' and multiple + // read/write will be avoided. + union { + WebPRGBABuffer RGBA; + WebPYUVABuffer YUVA; + } u; // Nameless union of buffer parameters. + uint32_t pad[4]; // padding for later use + + uint8_t* private_memory; // Internally allocated memory (only when + // is_external_memory is 0). Should not be used + // externally, but accessed via the buffer union. +}; + +// Internal, version-checked, entry point +WEBP_EXTERN int WebPInitDecBufferInternal(WebPDecBuffer*, int); + +// Initialize the structure as empty. Must be called before any other use. +// Returns false in case of version mismatch +static WEBP_INLINE int WebPInitDecBuffer(WebPDecBuffer* buffer) { + return WebPInitDecBufferInternal(buffer, WEBP_DECODER_ABI_VERSION); +} + +// Free any memory associated with the buffer. Must always be called last. +// Note: doesn't free the 'buffer' structure itself. +WEBP_EXTERN void WebPFreeDecBuffer(WebPDecBuffer* buffer); + +//------------------------------------------------------------------------------ +// Enumeration of the status codes + +typedef enum VP8StatusCode { + VP8_STATUS_OK = 0, + VP8_STATUS_OUT_OF_MEMORY, + VP8_STATUS_INVALID_PARAM, + VP8_STATUS_BITSTREAM_ERROR, + VP8_STATUS_UNSUPPORTED_FEATURE, + VP8_STATUS_SUSPENDED, + VP8_STATUS_USER_ABORT, + VP8_STATUS_NOT_ENOUGH_DATA +} VP8StatusCode; + +//------------------------------------------------------------------------------ +// Incremental decoding +// +// This API allows streamlined decoding of partial data. +// Picture can be incrementally decoded as data become available thanks to the +// WebPIDecoder object. This object can be left in a SUSPENDED state if the +// picture is only partially decoded, pending additional input. +// Code example: +// +// WebPInitDecBuffer(&output_buffer); +// output_buffer.colorspace = mode; +// ... +// WebPIDecoder* idec = WebPINewDecoder(&output_buffer); +// while (additional_data_is_available) { +// // ... (get additional data in some new_data[] buffer) +// status = WebPIAppend(idec, new_data, new_data_size); +// if (status != VP8_STATUS_OK && status != VP8_STATUS_SUSPENDED) { +// break; // an error occurred. +// } +// +// // The above call decodes the current available buffer. +// // Part of the image can now be refreshed by calling +// // WebPIDecGetRGB()/WebPIDecGetYUVA() etc. +// } +// WebPIDelete(idec); + +// Creates a new incremental decoder with the supplied buffer parameter. +// This output_buffer can be passed NULL, in which case a default output buffer +// is used (with MODE_RGB). Otherwise, an internal reference to 'output_buffer' +// is kept, which means that the lifespan of 'output_buffer' must be larger than +// that of the returned WebPIDecoder object. +// The supplied 'output_buffer' content MUST NOT be changed between calls to +// WebPIAppend() or WebPIUpdate() unless 'output_buffer.is_external_memory' is +// not set to 0. In such a case, it is allowed to modify the pointers, size and +// stride of output_buffer.u.RGBA or output_buffer.u.YUVA, provided they remain +// within valid bounds. +// All other fields of WebPDecBuffer MUST remain constant between calls. +// Returns NULL if the allocation failed. +WEBP_EXTERN WebPIDecoder* WebPINewDecoder(WebPDecBuffer* output_buffer); + +// This function allocates and initializes an incremental-decoder object, which +// will output the RGB/A samples specified by 'csp' into a preallocated +// buffer 'output_buffer'. The size of this buffer is at least +// 'output_buffer_size' and the stride (distance in bytes between two scanlines) +// is specified by 'output_stride'. +// Additionally, output_buffer can be passed NULL in which case the output +// buffer will be allocated automatically when the decoding starts. The +// colorspace 'csp' is taken into account for allocating this buffer. All other +// parameters are ignored. +// Returns NULL if the allocation failed, or if some parameters are invalid. +WEBP_EXTERN WebPIDecoder* WebPINewRGB( + WEBP_CSP_MODE csp, + uint8_t* output_buffer, size_t output_buffer_size, int output_stride); + +// This function allocates and initializes an incremental-decoder object, which +// will output the raw luma/chroma samples into a preallocated planes if +// supplied. The luma plane is specified by its pointer 'luma', its size +// 'luma_size' and its stride 'luma_stride'. Similarly, the chroma-u plane +// is specified by the 'u', 'u_size' and 'u_stride' parameters, and the chroma-v +// plane by 'v' and 'v_size'. And same for the alpha-plane. The 'a' pointer +// can be pass NULL in case one is not interested in the transparency plane. +// Conversely, 'luma' can be passed NULL if no preallocated planes are supplied. +// In this case, the output buffer will be automatically allocated (using +// MODE_YUVA) when decoding starts. All parameters are then ignored. +// Returns NULL if the allocation failed or if a parameter is invalid. +WEBP_EXTERN WebPIDecoder* WebPINewYUVA( + uint8_t* luma, size_t luma_size, int luma_stride, + uint8_t* u, size_t u_size, int u_stride, + uint8_t* v, size_t v_size, int v_stride, + uint8_t* a, size_t a_size, int a_stride); + +// Deprecated version of the above, without the alpha plane. +// Kept for backward compatibility. +WEBP_EXTERN WebPIDecoder* WebPINewYUV( + uint8_t* luma, size_t luma_size, int luma_stride, + uint8_t* u, size_t u_size, int u_stride, + uint8_t* v, size_t v_size, int v_stride); + +// Deletes the WebPIDecoder object and associated memory. Must always be called +// if WebPINewDecoder, WebPINewRGB or WebPINewYUV succeeded. +WEBP_EXTERN void WebPIDelete(WebPIDecoder* idec); + +// Copies and decodes the next available data. Returns VP8_STATUS_OK when +// the image is successfully decoded. Returns VP8_STATUS_SUSPENDED when more +// data is expected. Returns error in other cases. +WEBP_EXTERN VP8StatusCode WebPIAppend( + WebPIDecoder* idec, const uint8_t* data, size_t data_size); + +// A variant of the above function to be used when data buffer contains +// partial data from the beginning. In this case data buffer is not copied +// to the internal memory. +// Note that the value of the 'data' pointer can change between calls to +// WebPIUpdate, for instance when the data buffer is resized to fit larger data. +WEBP_EXTERN VP8StatusCode WebPIUpdate( + WebPIDecoder* idec, const uint8_t* data, size_t data_size); + +// Returns the RGB/A image decoded so far. Returns NULL if output params +// are not initialized yet. The RGB/A output type corresponds to the colorspace +// specified during call to WebPINewDecoder() or WebPINewRGB(). +// *last_y is the index of last decoded row in raster scan order. Some pointers +// (*last_y, *width etc.) can be NULL if corresponding information is not +// needed. The values in these pointers are only valid on successful (non-NULL) +// return. +WEBP_EXTERN uint8_t* WebPIDecGetRGB( + const WebPIDecoder* idec, int* last_y, + int* width, int* height, int* stride); + +// Same as above function to get a YUVA image. Returns pointer to the luma +// plane or NULL in case of error. If there is no alpha information +// the alpha pointer '*a' will be returned NULL. +WEBP_EXTERN uint8_t* WebPIDecGetYUVA( + const WebPIDecoder* idec, int* last_y, + uint8_t** u, uint8_t** v, uint8_t** a, + int* width, int* height, int* stride, int* uv_stride, int* a_stride); + +// Deprecated alpha-less version of WebPIDecGetYUVA(): it will ignore the +// alpha information (if present). Kept for backward compatibility. +static WEBP_INLINE uint8_t* WebPIDecGetYUV( + const WebPIDecoder* idec, int* last_y, uint8_t** u, uint8_t** v, + int* width, int* height, int* stride, int* uv_stride) { + return WebPIDecGetYUVA(idec, last_y, u, v, NULL, width, height, + stride, uv_stride, NULL); +} + +// Generic call to retrieve information about the displayable area. +// If non NULL, the left/right/width/height pointers are filled with the visible +// rectangular area so far. +// Returns NULL in case the incremental decoder object is in an invalid state. +// Otherwise returns the pointer to the internal representation. This structure +// is read-only, tied to WebPIDecoder's lifespan and should not be modified. +WEBP_EXTERN const WebPDecBuffer* WebPIDecodedArea( + const WebPIDecoder* idec, int* left, int* top, int* width, int* height); + +//------------------------------------------------------------------------------ +// Advanced decoding parametrization +// +// Code sample for using the advanced decoding API +/* + // A) Init a configuration object + WebPDecoderConfig config; + CHECK(WebPInitDecoderConfig(&config)); + + // B) optional: retrieve the bitstream's features. + CHECK(WebPGetFeatures(data, data_size, &config.input) == VP8_STATUS_OK); + + // C) Adjust 'config', if needed + config.no_fancy_upsampling = 1; + config.output.colorspace = MODE_BGRA; + // etc. + + // Note that you can also make config.output point to an externally + // supplied memory buffer, provided it's big enough to store the decoded + // picture. Otherwise, config.output will just be used to allocate memory + // and store the decoded picture. + + // D) Decode! + CHECK(WebPDecode(data, data_size, &config) == VP8_STATUS_OK); + + // E) Decoded image is now in config.output (and config.output.u.RGBA) + + // F) Reclaim memory allocated in config's object. It's safe to call + // this function even if the memory is external and wasn't allocated + // by WebPDecode(). + WebPFreeDecBuffer(&config.output); +*/ + +// Features gathered from the bitstream +struct WebPBitstreamFeatures { + int width; // Width in pixels, as read from the bitstream. + int height; // Height in pixels, as read from the bitstream. + int has_alpha; // True if the bitstream contains an alpha channel. + int has_animation; // True if the bitstream is an animation. + int format; // 0 = undefined (/mixed), 1 = lossy, 2 = lossless + + uint32_t pad[5]; // padding for later use +}; + +// Internal, version-checked, entry point +WEBP_EXTERN VP8StatusCode WebPGetFeaturesInternal( + const uint8_t*, size_t, WebPBitstreamFeatures*, int); + +// Retrieve features from the bitstream. The *features structure is filled +// with information gathered from the bitstream. +// Returns VP8_STATUS_OK when the features are successfully retrieved. Returns +// VP8_STATUS_NOT_ENOUGH_DATA when more data is needed to retrieve the +// features from headers. Returns error in other cases. +// Note: The following chunk sequences (before the raw VP8/VP8L data) are +// considered valid by this function: +// RIFF + VP8(L) +// RIFF + VP8X + (optional chunks) + VP8(L) +// ALPH + VP8 <-- Not a valid WebP format: only allowed for internal purpose. +// VP8(L) <-- Not a valid WebP format: only allowed for internal purpose. +static WEBP_INLINE VP8StatusCode WebPGetFeatures( + const uint8_t* data, size_t data_size, + WebPBitstreamFeatures* features) { + return WebPGetFeaturesInternal(data, data_size, features, + WEBP_DECODER_ABI_VERSION); +} + +// Decoding options +struct WebPDecoderOptions { + int bypass_filtering; // if true, skip the in-loop filtering + int no_fancy_upsampling; // if true, use faster pointwise upsampler + int use_cropping; // if true, cropping is applied _first_ + int crop_left, crop_top; // top-left position for cropping. + // Will be snapped to even values. + int crop_width, crop_height; // dimension of the cropping area + int use_scaling; // if true, scaling is applied _afterward_ + int scaled_width, scaled_height; // final resolution + int use_threads; // if true, use multi-threaded decoding + int dithering_strength; // dithering strength (0=Off, 100=full) + int flip; // if true, flip output vertically + int alpha_dithering_strength; // alpha dithering strength in [0..100] + + uint32_t pad[5]; // padding for later use +}; + +// Main object storing the configuration for advanced decoding. +struct WebPDecoderConfig { + WebPBitstreamFeatures input; // Immutable bitstream features (optional) + WebPDecBuffer output; // Output buffer (can point to external mem) + WebPDecoderOptions options; // Decoding options +}; + +// Internal, version-checked, entry point +WEBP_EXTERN int WebPInitDecoderConfigInternal(WebPDecoderConfig*, int); + +// Initialize the configuration as empty. This function must always be +// called first, unless WebPGetFeatures() is to be called. +// Returns false in case of mismatched version. +static WEBP_INLINE int WebPInitDecoderConfig(WebPDecoderConfig* config) { + return WebPInitDecoderConfigInternal(config, WEBP_DECODER_ABI_VERSION); +} + +// Instantiate a new incremental decoder object with the requested +// configuration. The bitstream can be passed using 'data' and 'data_size' +// parameter, in which case the features will be parsed and stored into +// config->input. Otherwise, 'data' can be NULL and no parsing will occur. +// Note that 'config' can be NULL too, in which case a default configuration +// is used. If 'config' is not NULL, it must outlive the WebPIDecoder object +// as some references to its fields will be used. No internal copy of 'config' +// is made. +// The return WebPIDecoder object must always be deleted calling WebPIDelete(). +// Returns NULL in case of error (and config->status will then reflect +// the error condition, if available). +WEBP_EXTERN WebPIDecoder* WebPIDecode(const uint8_t* data, size_t data_size, + WebPDecoderConfig* config); + +// Non-incremental version. This version decodes the full data at once, taking +// 'config' into account. Returns decoding status (which should be VP8_STATUS_OK +// if the decoding was successful). Note that 'config' cannot be NULL. +WEBP_EXTERN VP8StatusCode WebPDecode(const uint8_t* data, size_t data_size, + WebPDecoderConfig* config); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // WEBP_WEBP_DECODE_H_ diff --git a/src/JPEGView/libwebp/include/webp/demux.h b/src/JPEGView/libwebp/include/webp/demux.h index 4567e693..846eeb15 100644 --- a/src/JPEGView/libwebp/include/webp/demux.h +++ b/src/JPEGView/libwebp/include/webp/demux.h @@ -1,363 +1,363 @@ -// Copyright 2012 Google Inc. All Rights Reserved. -// -// Use of this source code is governed by a BSD-style license -// that can be found in the COPYING file in the root of the source -// tree. An additional intellectual property rights grant can be found -// in the file PATENTS. All contributing project authors may -// be found in the AUTHORS file in the root of the source tree. -// ----------------------------------------------------------------------------- -// -// Demux API. -// Enables extraction of image and extended format data from WebP files. - -// Code Example: Demuxing WebP data to extract all the frames, ICC profile -// and EXIF/XMP metadata. -/* - WebPDemuxer* demux = WebPDemux(&webp_data); - - uint32_t width = WebPDemuxGetI(demux, WEBP_FF_CANVAS_WIDTH); - uint32_t height = WebPDemuxGetI(demux, WEBP_FF_CANVAS_HEIGHT); - // ... (Get information about the features present in the WebP file). - uint32_t flags = WebPDemuxGetI(demux, WEBP_FF_FORMAT_FLAGS); - - // ... (Iterate over all frames). - WebPIterator iter; - if (WebPDemuxGetFrame(demux, 1, &iter)) { - do { - // ... (Consume 'iter'; e.g. Decode 'iter.fragment' with WebPDecode(), - // ... and get other frame properties like width, height, offsets etc. - // ... see 'struct WebPIterator' below for more info). - } while (WebPDemuxNextFrame(&iter)); - WebPDemuxReleaseIterator(&iter); - } - - // ... (Extract metadata). - WebPChunkIterator chunk_iter; - if (flags & ICCP_FLAG) WebPDemuxGetChunk(demux, "ICCP", 1, &chunk_iter); - // ... (Consume the ICC profile in 'chunk_iter.chunk'). - WebPDemuxReleaseChunkIterator(&chunk_iter); - if (flags & EXIF_FLAG) WebPDemuxGetChunk(demux, "EXIF", 1, &chunk_iter); - // ... (Consume the EXIF metadata in 'chunk_iter.chunk'). - WebPDemuxReleaseChunkIterator(&chunk_iter); - if (flags & XMP_FLAG) WebPDemuxGetChunk(demux, "XMP ", 1, &chunk_iter); - // ... (Consume the XMP metadata in 'chunk_iter.chunk'). - WebPDemuxReleaseChunkIterator(&chunk_iter); - WebPDemuxDelete(demux); -*/ - -#ifndef WEBP_WEBP_DEMUX_H_ -#define WEBP_WEBP_DEMUX_H_ - -#include "./decode.h" // for WEBP_CSP_MODE -#include "./mux_types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define WEBP_DEMUX_ABI_VERSION 0x0107 // MAJOR(8b) + MINOR(8b) - -// Note: forward declaring enumerations is not allowed in (strict) C and C++, -// the types are left here for reference. -// typedef enum WebPDemuxState WebPDemuxState; -// typedef enum WebPFormatFeature WebPFormatFeature; -typedef struct WebPDemuxer WebPDemuxer; -typedef struct WebPIterator WebPIterator; -typedef struct WebPChunkIterator WebPChunkIterator; -typedef struct WebPAnimInfo WebPAnimInfo; -typedef struct WebPAnimDecoderOptions WebPAnimDecoderOptions; - -//------------------------------------------------------------------------------ - -// Returns the version number of the demux library, packed in hexadecimal using -// 8bits for each of major/minor/revision. E.g: v2.5.7 is 0x020507. -WEBP_EXTERN int WebPGetDemuxVersion(void); - -//------------------------------------------------------------------------------ -// Life of a Demux object - -typedef enum WebPDemuxState { - WEBP_DEMUX_PARSE_ERROR = -1, // An error occurred while parsing. - WEBP_DEMUX_PARSING_HEADER = 0, // Not enough data to parse full header. - WEBP_DEMUX_PARSED_HEADER = 1, // Header parsing complete, - // data may be available. - WEBP_DEMUX_DONE = 2 // Entire file has been parsed. -} WebPDemuxState; - -// Internal, version-checked, entry point -WEBP_EXTERN WebPDemuxer* WebPDemuxInternal( - const WebPData*, int, WebPDemuxState*, int); - -// Parses the full WebP file given by 'data'. For single images the WebP file -// header alone or the file header and the chunk header may be absent. -// Returns a WebPDemuxer object on successful parse, NULL otherwise. -static WEBP_INLINE WebPDemuxer* WebPDemux(const WebPData* data) { - return WebPDemuxInternal(data, 0, NULL, WEBP_DEMUX_ABI_VERSION); -} - -// Parses the possibly incomplete WebP file given by 'data'. -// If 'state' is non-NULL it will be set to indicate the status of the demuxer. -// Returns NULL in case of error or if there isn't enough data to start parsing; -// and a WebPDemuxer object on successful parse. -// Note that WebPDemuxer keeps internal pointers to 'data' memory segment. -// If this data is volatile, the demuxer object should be deleted (by calling -// WebPDemuxDelete()) and WebPDemuxPartial() called again on the new data. -// This is usually an inexpensive operation. -static WEBP_INLINE WebPDemuxer* WebPDemuxPartial( - const WebPData* data, WebPDemuxState* state) { - return WebPDemuxInternal(data, 1, state, WEBP_DEMUX_ABI_VERSION); -} - -// Frees memory associated with 'dmux'. -WEBP_EXTERN void WebPDemuxDelete(WebPDemuxer* dmux); - -//------------------------------------------------------------------------------ -// Data/information extraction. - -typedef enum WebPFormatFeature { - WEBP_FF_FORMAT_FLAGS, // bit-wise combination of WebPFeatureFlags - // corresponding to the 'VP8X' chunk (if present). - WEBP_FF_CANVAS_WIDTH, - WEBP_FF_CANVAS_HEIGHT, - WEBP_FF_LOOP_COUNT, // only relevant for animated file - WEBP_FF_BACKGROUND_COLOR, // idem. - WEBP_FF_FRAME_COUNT // Number of frames present in the demux object. - // In case of a partial demux, this is the number - // of frames seen so far, with the last frame - // possibly being partial. -} WebPFormatFeature; - -// Get the 'feature' value from the 'dmux'. -// NOTE: values are only valid if WebPDemux() was used or WebPDemuxPartial() -// returned a state > WEBP_DEMUX_PARSING_HEADER. -// If 'feature' is WEBP_FF_FORMAT_FLAGS, the returned value is a bit-wise -// combination of WebPFeatureFlags values. -// If 'feature' is WEBP_FF_LOOP_COUNT, WEBP_FF_BACKGROUND_COLOR, the returned -// value is only meaningful if the bitstream is animated. -WEBP_EXTERN uint32_t WebPDemuxGetI( - const WebPDemuxer* dmux, WebPFormatFeature feature); - -//------------------------------------------------------------------------------ -// Frame iteration. - -struct WebPIterator { - int frame_num; - int num_frames; // equivalent to WEBP_FF_FRAME_COUNT. - int x_offset, y_offset; // offset relative to the canvas. - int width, height; // dimensions of this frame. - int duration; // display duration in milliseconds. - WebPMuxAnimDispose dispose_method; // dispose method for the frame. - int complete; // true if 'fragment' contains a full frame. partial images - // may still be decoded with the WebP incremental decoder. - WebPData fragment; // The frame given by 'frame_num'. Note for historical - // reasons this is called a fragment. - int has_alpha; // True if the frame contains transparency. - WebPMuxAnimBlend blend_method; // Blend operation for the frame. - - uint32_t pad[2]; // padding for later use. - void* private_; // for internal use only. -}; - -// Retrieves frame 'frame_number' from 'dmux'. -// 'iter->fragment' points to the frame on return from this function. -// Setting 'frame_number' equal to 0 will return the last frame of the image. -// Returns false if 'dmux' is NULL or frame 'frame_number' is not present. -// Call WebPDemuxReleaseIterator() when use of the iterator is complete. -// NOTE: 'dmux' must persist for the lifetime of 'iter'. -WEBP_EXTERN int WebPDemuxGetFrame( - const WebPDemuxer* dmux, int frame_number, WebPIterator* iter); - -// Sets 'iter->fragment' to point to the next ('iter->frame_num' + 1) or -// previous ('iter->frame_num' - 1) frame. These functions do not loop. -// Returns true on success, false otherwise. -WEBP_EXTERN int WebPDemuxNextFrame(WebPIterator* iter); -WEBP_EXTERN int WebPDemuxPrevFrame(WebPIterator* iter); - -// Releases any memory associated with 'iter'. -// Must be called before any subsequent calls to WebPDemuxGetChunk() on the same -// iter. Also, must be called before destroying the associated WebPDemuxer with -// WebPDemuxDelete(). -WEBP_EXTERN void WebPDemuxReleaseIterator(WebPIterator* iter); - -//------------------------------------------------------------------------------ -// Chunk iteration. - -struct WebPChunkIterator { - // The current and total number of chunks with the fourcc given to - // WebPDemuxGetChunk(). - int chunk_num; - int num_chunks; - WebPData chunk; // The payload of the chunk. - - uint32_t pad[6]; // padding for later use - void* private_; -}; - -// Retrieves the 'chunk_number' instance of the chunk with id 'fourcc' from -// 'dmux'. -// 'fourcc' is a character array containing the fourcc of the chunk to return, -// e.g., "ICCP", "XMP ", "EXIF", etc. -// Setting 'chunk_number' equal to 0 will return the last chunk in a set. -// Returns true if the chunk is found, false otherwise. Image related chunk -// payloads are accessed through WebPDemuxGetFrame() and related functions. -// Call WebPDemuxReleaseChunkIterator() when use of the iterator is complete. -// NOTE: 'dmux' must persist for the lifetime of the iterator. -WEBP_EXTERN int WebPDemuxGetChunk(const WebPDemuxer* dmux, - const char fourcc[4], int chunk_number, - WebPChunkIterator* iter); - -// Sets 'iter->chunk' to point to the next ('iter->chunk_num' + 1) or previous -// ('iter->chunk_num' - 1) chunk. These functions do not loop. -// Returns true on success, false otherwise. -WEBP_EXTERN int WebPDemuxNextChunk(WebPChunkIterator* iter); -WEBP_EXTERN int WebPDemuxPrevChunk(WebPChunkIterator* iter); - -// Releases any memory associated with 'iter'. -// Must be called before destroying the associated WebPDemuxer with -// WebPDemuxDelete(). -WEBP_EXTERN void WebPDemuxReleaseChunkIterator(WebPChunkIterator* iter); - -//------------------------------------------------------------------------------ -// WebPAnimDecoder API -// -// This API allows decoding (possibly) animated WebP images. -// -// Code Example: -/* - WebPAnimDecoderOptions dec_options; - WebPAnimDecoderOptionsInit(&dec_options); - // Tune 'dec_options' as needed. - WebPAnimDecoder* dec = WebPAnimDecoderNew(webp_data, &dec_options); - WebPAnimInfo anim_info; - WebPAnimDecoderGetInfo(dec, &anim_info); - for (uint32_t i = 0; i < anim_info.loop_count; ++i) { - while (WebPAnimDecoderHasMoreFrames(dec)) { - uint8_t* buf; - int timestamp; - WebPAnimDecoderGetNext(dec, &buf, ×tamp); - // ... (Render 'buf' based on 'timestamp'). - // ... (Do NOT free 'buf', as it is owned by 'dec'). - } - WebPAnimDecoderReset(dec); - } - const WebPDemuxer* demuxer = WebPAnimDecoderGetDemuxer(dec); - // ... (Do something using 'demuxer'; e.g. get EXIF/XMP/ICC data). - WebPAnimDecoderDelete(dec); -*/ - -typedef struct WebPAnimDecoder WebPAnimDecoder; // Main opaque object. - -// Global options. -struct WebPAnimDecoderOptions { - // Output colorspace. Only the following modes are supported: - // MODE_RGBA, MODE_BGRA, MODE_rgbA and MODE_bgrA. - WEBP_CSP_MODE color_mode; - int use_threads; // If true, use multi-threaded decoding. - uint32_t padding[7]; // Padding for later use. -}; - -// Internal, version-checked, entry point. -WEBP_EXTERN int WebPAnimDecoderOptionsInitInternal( - WebPAnimDecoderOptions*, int); - -// Should always be called, to initialize a fresh WebPAnimDecoderOptions -// structure before modification. Returns false in case of version mismatch. -// WebPAnimDecoderOptionsInit() must have succeeded before using the -// 'dec_options' object. -static WEBP_INLINE int WebPAnimDecoderOptionsInit( - WebPAnimDecoderOptions* dec_options) { - return WebPAnimDecoderOptionsInitInternal(dec_options, - WEBP_DEMUX_ABI_VERSION); -} - -// Internal, version-checked, entry point. -WEBP_EXTERN WebPAnimDecoder* WebPAnimDecoderNewInternal( - const WebPData*, const WebPAnimDecoderOptions*, int); - -// Creates and initializes a WebPAnimDecoder object. -// Parameters: -// webp_data - (in) WebP bitstream. This should remain unchanged during the -// lifetime of the output WebPAnimDecoder object. -// dec_options - (in) decoding options. Can be passed NULL to choose -// reasonable defaults (in particular, color mode MODE_RGBA -// will be picked). -// Returns: -// A pointer to the newly created WebPAnimDecoder object, or NULL in case of -// parsing error, invalid option or memory error. -static WEBP_INLINE WebPAnimDecoder* WebPAnimDecoderNew( - const WebPData* webp_data, const WebPAnimDecoderOptions* dec_options) { - return WebPAnimDecoderNewInternal(webp_data, dec_options, - WEBP_DEMUX_ABI_VERSION); -} - -// Global information about the animation.. -struct WebPAnimInfo { - uint32_t canvas_width; - uint32_t canvas_height; - uint32_t loop_count; - uint32_t bgcolor; - uint32_t frame_count; - uint32_t pad[4]; // padding for later use -}; - -// Get global information about the animation. -// Parameters: -// dec - (in) decoder instance to get information from. -// info - (out) global information fetched from the animation. -// Returns: -// True on success. -WEBP_EXTERN int WebPAnimDecoderGetInfo(const WebPAnimDecoder* dec, - WebPAnimInfo* info); - -// Fetch the next frame from 'dec' based on options supplied to -// WebPAnimDecoderNew(). This will be a fully reconstructed canvas of size -// 'canvas_width * 4 * canvas_height', and not just the frame sub-rectangle. The -// returned buffer 'buf' is valid only until the next call to -// WebPAnimDecoderGetNext(), WebPAnimDecoderReset() or WebPAnimDecoderDelete(). -// Parameters: -// dec - (in/out) decoder instance from which the next frame is to be fetched. -// buf - (out) decoded frame. -// timestamp - (out) timestamp of the frame in milliseconds. -// Returns: -// False if any of the arguments are NULL, or if there is a parsing or -// decoding error, or if there are no more frames. Otherwise, returns true. -WEBP_EXTERN int WebPAnimDecoderGetNext(WebPAnimDecoder* dec, - uint8_t** buf, int* timestamp); - -// Check if there are more frames left to decode. -// Parameters: -// dec - (in) decoder instance to be checked. -// Returns: -// True if 'dec' is not NULL and some frames are yet to be decoded. -// Otherwise, returns false. -WEBP_EXTERN int WebPAnimDecoderHasMoreFrames(const WebPAnimDecoder* dec); - -// Resets the WebPAnimDecoder object, so that next call to -// WebPAnimDecoderGetNext() will restart decoding from 1st frame. This would be -// helpful when all frames need to be decoded multiple times (e.g. -// info.loop_count times) without destroying and recreating the 'dec' object. -// Parameters: -// dec - (in/out) decoder instance to be reset -WEBP_EXTERN void WebPAnimDecoderReset(WebPAnimDecoder* dec); - -// Grab the internal demuxer object. -// Getting the demuxer object can be useful if one wants to use operations only -// available through demuxer; e.g. to get XMP/EXIF/ICC metadata. The returned -// demuxer object is owned by 'dec' and is valid only until the next call to -// WebPAnimDecoderDelete(). -// -// Parameters: -// dec - (in) decoder instance from which the demuxer object is to be fetched. -WEBP_EXTERN const WebPDemuxer* WebPAnimDecoderGetDemuxer( - const WebPAnimDecoder* dec); - -// Deletes the WebPAnimDecoder object. -// Parameters: -// dec - (in/out) decoder instance to be deleted -WEBP_EXTERN void WebPAnimDecoderDelete(WebPAnimDecoder* dec); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // WEBP_WEBP_DEMUX_H_ +// Copyright 2012 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Demux API. +// Enables extraction of image and extended format data from WebP files. + +// Code Example: Demuxing WebP data to extract all the frames, ICC profile +// and EXIF/XMP metadata. +/* + WebPDemuxer* demux = WebPDemux(&webp_data); + + uint32_t width = WebPDemuxGetI(demux, WEBP_FF_CANVAS_WIDTH); + uint32_t height = WebPDemuxGetI(demux, WEBP_FF_CANVAS_HEIGHT); + // ... (Get information about the features present in the WebP file). + uint32_t flags = WebPDemuxGetI(demux, WEBP_FF_FORMAT_FLAGS); + + // ... (Iterate over all frames). + WebPIterator iter; + if (WebPDemuxGetFrame(demux, 1, &iter)) { + do { + // ... (Consume 'iter'; e.g. Decode 'iter.fragment' with WebPDecode(), + // ... and get other frame properties like width, height, offsets etc. + // ... see 'struct WebPIterator' below for more info). + } while (WebPDemuxNextFrame(&iter)); + WebPDemuxReleaseIterator(&iter); + } + + // ... (Extract metadata). + WebPChunkIterator chunk_iter; + if (flags & ICCP_FLAG) WebPDemuxGetChunk(demux, "ICCP", 1, &chunk_iter); + // ... (Consume the ICC profile in 'chunk_iter.chunk'). + WebPDemuxReleaseChunkIterator(&chunk_iter); + if (flags & EXIF_FLAG) WebPDemuxGetChunk(demux, "EXIF", 1, &chunk_iter); + // ... (Consume the EXIF metadata in 'chunk_iter.chunk'). + WebPDemuxReleaseChunkIterator(&chunk_iter); + if (flags & XMP_FLAG) WebPDemuxGetChunk(demux, "XMP ", 1, &chunk_iter); + // ... (Consume the XMP metadata in 'chunk_iter.chunk'). + WebPDemuxReleaseChunkIterator(&chunk_iter); + WebPDemuxDelete(demux); +*/ + +#ifndef WEBP_WEBP_DEMUX_H_ +#define WEBP_WEBP_DEMUX_H_ + +#include "./decode.h" // for WEBP_CSP_MODE +#include "./mux_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define WEBP_DEMUX_ABI_VERSION 0x0107 // MAJOR(8b) + MINOR(8b) + +// Note: forward declaring enumerations is not allowed in (strict) C and C++, +// the types are left here for reference. +// typedef enum WebPDemuxState WebPDemuxState; +// typedef enum WebPFormatFeature WebPFormatFeature; +typedef struct WebPDemuxer WebPDemuxer; +typedef struct WebPIterator WebPIterator; +typedef struct WebPChunkIterator WebPChunkIterator; +typedef struct WebPAnimInfo WebPAnimInfo; +typedef struct WebPAnimDecoderOptions WebPAnimDecoderOptions; + +//------------------------------------------------------------------------------ + +// Returns the version number of the demux library, packed in hexadecimal using +// 8bits for each of major/minor/revision. E.g: v2.5.7 is 0x020507. +WEBP_EXTERN int WebPGetDemuxVersion(void); + +//------------------------------------------------------------------------------ +// Life of a Demux object + +typedef enum WebPDemuxState { + WEBP_DEMUX_PARSE_ERROR = -1, // An error occurred while parsing. + WEBP_DEMUX_PARSING_HEADER = 0, // Not enough data to parse full header. + WEBP_DEMUX_PARSED_HEADER = 1, // Header parsing complete, + // data may be available. + WEBP_DEMUX_DONE = 2 // Entire file has been parsed. +} WebPDemuxState; + +// Internal, version-checked, entry point +WEBP_EXTERN WebPDemuxer* WebPDemuxInternal( + const WebPData*, int, WebPDemuxState*, int); + +// Parses the full WebP file given by 'data'. For single images the WebP file +// header alone or the file header and the chunk header may be absent. +// Returns a WebPDemuxer object on successful parse, NULL otherwise. +static WEBP_INLINE WebPDemuxer* WebPDemux(const WebPData* data) { + return WebPDemuxInternal(data, 0, NULL, WEBP_DEMUX_ABI_VERSION); +} + +// Parses the possibly incomplete WebP file given by 'data'. +// If 'state' is non-NULL it will be set to indicate the status of the demuxer. +// Returns NULL in case of error or if there isn't enough data to start parsing; +// and a WebPDemuxer object on successful parse. +// Note that WebPDemuxer keeps internal pointers to 'data' memory segment. +// If this data is volatile, the demuxer object should be deleted (by calling +// WebPDemuxDelete()) and WebPDemuxPartial() called again on the new data. +// This is usually an inexpensive operation. +static WEBP_INLINE WebPDemuxer* WebPDemuxPartial( + const WebPData* data, WebPDemuxState* state) { + return WebPDemuxInternal(data, 1, state, WEBP_DEMUX_ABI_VERSION); +} + +// Frees memory associated with 'dmux'. +WEBP_EXTERN void WebPDemuxDelete(WebPDemuxer* dmux); + +//------------------------------------------------------------------------------ +// Data/information extraction. + +typedef enum WebPFormatFeature { + WEBP_FF_FORMAT_FLAGS, // bit-wise combination of WebPFeatureFlags + // corresponding to the 'VP8X' chunk (if present). + WEBP_FF_CANVAS_WIDTH, + WEBP_FF_CANVAS_HEIGHT, + WEBP_FF_LOOP_COUNT, // only relevant for animated file + WEBP_FF_BACKGROUND_COLOR, // idem. + WEBP_FF_FRAME_COUNT // Number of frames present in the demux object. + // In case of a partial demux, this is the number + // of frames seen so far, with the last frame + // possibly being partial. +} WebPFormatFeature; + +// Get the 'feature' value from the 'dmux'. +// NOTE: values are only valid if WebPDemux() was used or WebPDemuxPartial() +// returned a state > WEBP_DEMUX_PARSING_HEADER. +// If 'feature' is WEBP_FF_FORMAT_FLAGS, the returned value is a bit-wise +// combination of WebPFeatureFlags values. +// If 'feature' is WEBP_FF_LOOP_COUNT, WEBP_FF_BACKGROUND_COLOR, the returned +// value is only meaningful if the bitstream is animated. +WEBP_EXTERN uint32_t WebPDemuxGetI( + const WebPDemuxer* dmux, WebPFormatFeature feature); + +//------------------------------------------------------------------------------ +// Frame iteration. + +struct WebPIterator { + int frame_num; + int num_frames; // equivalent to WEBP_FF_FRAME_COUNT. + int x_offset, y_offset; // offset relative to the canvas. + int width, height; // dimensions of this frame. + int duration; // display duration in milliseconds. + WebPMuxAnimDispose dispose_method; // dispose method for the frame. + int complete; // true if 'fragment' contains a full frame. partial images + // may still be decoded with the WebP incremental decoder. + WebPData fragment; // The frame given by 'frame_num'. Note for historical + // reasons this is called a fragment. + int has_alpha; // True if the frame contains transparency. + WebPMuxAnimBlend blend_method; // Blend operation for the frame. + + uint32_t pad[2]; // padding for later use. + void* private_; // for internal use only. +}; + +// Retrieves frame 'frame_number' from 'dmux'. +// 'iter->fragment' points to the frame on return from this function. +// Setting 'frame_number' equal to 0 will return the last frame of the image. +// Returns false if 'dmux' is NULL or frame 'frame_number' is not present. +// Call WebPDemuxReleaseIterator() when use of the iterator is complete. +// NOTE: 'dmux' must persist for the lifetime of 'iter'. +WEBP_EXTERN int WebPDemuxGetFrame( + const WebPDemuxer* dmux, int frame_number, WebPIterator* iter); + +// Sets 'iter->fragment' to point to the next ('iter->frame_num' + 1) or +// previous ('iter->frame_num' - 1) frame. These functions do not loop. +// Returns true on success, false otherwise. +WEBP_EXTERN int WebPDemuxNextFrame(WebPIterator* iter); +WEBP_EXTERN int WebPDemuxPrevFrame(WebPIterator* iter); + +// Releases any memory associated with 'iter'. +// Must be called before any subsequent calls to WebPDemuxGetChunk() on the same +// iter. Also, must be called before destroying the associated WebPDemuxer with +// WebPDemuxDelete(). +WEBP_EXTERN void WebPDemuxReleaseIterator(WebPIterator* iter); + +//------------------------------------------------------------------------------ +// Chunk iteration. + +struct WebPChunkIterator { + // The current and total number of chunks with the fourcc given to + // WebPDemuxGetChunk(). + int chunk_num; + int num_chunks; + WebPData chunk; // The payload of the chunk. + + uint32_t pad[6]; // padding for later use + void* private_; +}; + +// Retrieves the 'chunk_number' instance of the chunk with id 'fourcc' from +// 'dmux'. +// 'fourcc' is a character array containing the fourcc of the chunk to return, +// e.g., "ICCP", "XMP ", "EXIF", etc. +// Setting 'chunk_number' equal to 0 will return the last chunk in a set. +// Returns true if the chunk is found, false otherwise. Image related chunk +// payloads are accessed through WebPDemuxGetFrame() and related functions. +// Call WebPDemuxReleaseChunkIterator() when use of the iterator is complete. +// NOTE: 'dmux' must persist for the lifetime of the iterator. +WEBP_EXTERN int WebPDemuxGetChunk(const WebPDemuxer* dmux, + const char fourcc[4], int chunk_number, + WebPChunkIterator* iter); + +// Sets 'iter->chunk' to point to the next ('iter->chunk_num' + 1) or previous +// ('iter->chunk_num' - 1) chunk. These functions do not loop. +// Returns true on success, false otherwise. +WEBP_EXTERN int WebPDemuxNextChunk(WebPChunkIterator* iter); +WEBP_EXTERN int WebPDemuxPrevChunk(WebPChunkIterator* iter); + +// Releases any memory associated with 'iter'. +// Must be called before destroying the associated WebPDemuxer with +// WebPDemuxDelete(). +WEBP_EXTERN void WebPDemuxReleaseChunkIterator(WebPChunkIterator* iter); + +//------------------------------------------------------------------------------ +// WebPAnimDecoder API +// +// This API allows decoding (possibly) animated WebP images. +// +// Code Example: +/* + WebPAnimDecoderOptions dec_options; + WebPAnimDecoderOptionsInit(&dec_options); + // Tune 'dec_options' as needed. + WebPAnimDecoder* dec = WebPAnimDecoderNew(webp_data, &dec_options); + WebPAnimInfo anim_info; + WebPAnimDecoderGetInfo(dec, &anim_info); + for (uint32_t i = 0; i < anim_info.loop_count; ++i) { + while (WebPAnimDecoderHasMoreFrames(dec)) { + uint8_t* buf; + int timestamp; + WebPAnimDecoderGetNext(dec, &buf, ×tamp); + // ... (Render 'buf' based on 'timestamp'). + // ... (Do NOT free 'buf', as it is owned by 'dec'). + } + WebPAnimDecoderReset(dec); + } + const WebPDemuxer* demuxer = WebPAnimDecoderGetDemuxer(dec); + // ... (Do something using 'demuxer'; e.g. get EXIF/XMP/ICC data). + WebPAnimDecoderDelete(dec); +*/ + +typedef struct WebPAnimDecoder WebPAnimDecoder; // Main opaque object. + +// Global options. +struct WebPAnimDecoderOptions { + // Output colorspace. Only the following modes are supported: + // MODE_RGBA, MODE_BGRA, MODE_rgbA and MODE_bgrA. + WEBP_CSP_MODE color_mode; + int use_threads; // If true, use multi-threaded decoding. + uint32_t padding[7]; // Padding for later use. +}; + +// Internal, version-checked, entry point. +WEBP_EXTERN int WebPAnimDecoderOptionsInitInternal( + WebPAnimDecoderOptions*, int); + +// Should always be called, to initialize a fresh WebPAnimDecoderOptions +// structure before modification. Returns false in case of version mismatch. +// WebPAnimDecoderOptionsInit() must have succeeded before using the +// 'dec_options' object. +static WEBP_INLINE int WebPAnimDecoderOptionsInit( + WebPAnimDecoderOptions* dec_options) { + return WebPAnimDecoderOptionsInitInternal(dec_options, + WEBP_DEMUX_ABI_VERSION); +} + +// Internal, version-checked, entry point. +WEBP_EXTERN WebPAnimDecoder* WebPAnimDecoderNewInternal( + const WebPData*, const WebPAnimDecoderOptions*, int); + +// Creates and initializes a WebPAnimDecoder object. +// Parameters: +// webp_data - (in) WebP bitstream. This should remain unchanged during the +// lifetime of the output WebPAnimDecoder object. +// dec_options - (in) decoding options. Can be passed NULL to choose +// reasonable defaults (in particular, color mode MODE_RGBA +// will be picked). +// Returns: +// A pointer to the newly created WebPAnimDecoder object, or NULL in case of +// parsing error, invalid option or memory error. +static WEBP_INLINE WebPAnimDecoder* WebPAnimDecoderNew( + const WebPData* webp_data, const WebPAnimDecoderOptions* dec_options) { + return WebPAnimDecoderNewInternal(webp_data, dec_options, + WEBP_DEMUX_ABI_VERSION); +} + +// Global information about the animation.. +struct WebPAnimInfo { + uint32_t canvas_width; + uint32_t canvas_height; + uint32_t loop_count; + uint32_t bgcolor; + uint32_t frame_count; + uint32_t pad[4]; // padding for later use +}; + +// Get global information about the animation. +// Parameters: +// dec - (in) decoder instance to get information from. +// info - (out) global information fetched from the animation. +// Returns: +// True on success. +WEBP_EXTERN int WebPAnimDecoderGetInfo(const WebPAnimDecoder* dec, + WebPAnimInfo* info); + +// Fetch the next frame from 'dec' based on options supplied to +// WebPAnimDecoderNew(). This will be a fully reconstructed canvas of size +// 'canvas_width * 4 * canvas_height', and not just the frame sub-rectangle. The +// returned buffer 'buf' is valid only until the next call to +// WebPAnimDecoderGetNext(), WebPAnimDecoderReset() or WebPAnimDecoderDelete(). +// Parameters: +// dec - (in/out) decoder instance from which the next frame is to be fetched. +// buf - (out) decoded frame. +// timestamp - (out) timestamp of the frame in milliseconds. +// Returns: +// False if any of the arguments are NULL, or if there is a parsing or +// decoding error, or if there are no more frames. Otherwise, returns true. +WEBP_EXTERN int WebPAnimDecoderGetNext(WebPAnimDecoder* dec, + uint8_t** buf, int* timestamp); + +// Check if there are more frames left to decode. +// Parameters: +// dec - (in) decoder instance to be checked. +// Returns: +// True if 'dec' is not NULL and some frames are yet to be decoded. +// Otherwise, returns false. +WEBP_EXTERN int WebPAnimDecoderHasMoreFrames(const WebPAnimDecoder* dec); + +// Resets the WebPAnimDecoder object, so that next call to +// WebPAnimDecoderGetNext() will restart decoding from 1st frame. This would be +// helpful when all frames need to be decoded multiple times (e.g. +// info.loop_count times) without destroying and recreating the 'dec' object. +// Parameters: +// dec - (in/out) decoder instance to be reset +WEBP_EXTERN void WebPAnimDecoderReset(WebPAnimDecoder* dec); + +// Grab the internal demuxer object. +// Getting the demuxer object can be useful if one wants to use operations only +// available through demuxer; e.g. to get XMP/EXIF/ICC metadata. The returned +// demuxer object is owned by 'dec' and is valid only until the next call to +// WebPAnimDecoderDelete(). +// +// Parameters: +// dec - (in) decoder instance from which the demuxer object is to be fetched. +WEBP_EXTERN const WebPDemuxer* WebPAnimDecoderGetDemuxer( + const WebPAnimDecoder* dec); + +// Deletes the WebPAnimDecoder object. +// Parameters: +// dec - (in/out) decoder instance to be deleted +WEBP_EXTERN void WebPAnimDecoderDelete(WebPAnimDecoder* dec); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // WEBP_WEBP_DEMUX_H_ diff --git a/src/JPEGView/libwebp/include/webp/encode.h b/src/JPEGView/libwebp/include/webp/encode.h index 10729eb6..56b68e2f 100644 --- a/src/JPEGView/libwebp/include/webp/encode.h +++ b/src/JPEGView/libwebp/include/webp/encode.h @@ -1,552 +1,552 @@ -// Copyright 2011 Google Inc. All Rights Reserved. -// -// Use of this source code is governed by a BSD-style license -// that can be found in the COPYING file in the root of the source -// tree. An additional intellectual property rights grant can be found -// in the file PATENTS. All contributing project authors may -// be found in the AUTHORS file in the root of the source tree. -// ----------------------------------------------------------------------------- -// -// WebP encoder: main interface -// -// Author: Skal (pascal.massimino@gmail.com) - -#ifndef WEBP_WEBP_ENCODE_H_ -#define WEBP_WEBP_ENCODE_H_ - -#include "./types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define WEBP_ENCODER_ABI_VERSION 0x020f // MAJOR(8b) + MINOR(8b) - -// Note: forward declaring enumerations is not allowed in (strict) C and C++, -// the types are left here for reference. -// typedef enum WebPImageHint WebPImageHint; -// typedef enum WebPEncCSP WebPEncCSP; -// typedef enum WebPPreset WebPPreset; -// typedef enum WebPEncodingError WebPEncodingError; -typedef struct WebPConfig WebPConfig; -typedef struct WebPPicture WebPPicture; // main structure for I/O -typedef struct WebPAuxStats WebPAuxStats; -typedef struct WebPMemoryWriter WebPMemoryWriter; - -// Return the encoder's version number, packed in hexadecimal using 8bits for -// each of major/minor/revision. E.g: v2.5.7 is 0x020507. -WEBP_EXTERN int WebPGetEncoderVersion(void); - -//------------------------------------------------------------------------------ -// One-stop-shop call! No questions asked: - -// Returns the size of the compressed data (pointed to by *output), or 0 if -// an error occurred. The compressed data must be released by the caller -// using the call 'WebPFree(*output)'. -// These functions compress using the lossy format, and the quality_factor -// can go from 0 (smaller output, lower quality) to 100 (best quality, -// larger output). -WEBP_EXTERN size_t WebPEncodeRGB(const uint8_t* rgb, - int width, int height, int stride, - float quality_factor, uint8_t** output); -WEBP_EXTERN size_t WebPEncodeBGR(const uint8_t* bgr, - int width, int height, int stride, - float quality_factor, uint8_t** output); -WEBP_EXTERN size_t WebPEncodeRGBA(const uint8_t* rgba, - int width, int height, int stride, - float quality_factor, uint8_t** output); -WEBP_EXTERN size_t WebPEncodeBGRA(const uint8_t* bgra, - int width, int height, int stride, - float quality_factor, uint8_t** output); - -// These functions are the equivalent of the above, but compressing in a -// lossless manner. Files are usually larger than lossy format, but will -// not suffer any compression loss. -// Note these functions, like the lossy versions, use the library's default -// settings. For lossless this means 'exact' is disabled. RGB values in -// transparent areas will be modified to improve compression. To avoid this, -// use WebPEncode() and set WebPConfig::exact to 1. -WEBP_EXTERN size_t WebPEncodeLosslessRGB(const uint8_t* rgb, - int width, int height, int stride, - uint8_t** output); -WEBP_EXTERN size_t WebPEncodeLosslessBGR(const uint8_t* bgr, - int width, int height, int stride, - uint8_t** output); -WEBP_EXTERN size_t WebPEncodeLosslessRGBA(const uint8_t* rgba, - int width, int height, int stride, - uint8_t** output); -WEBP_EXTERN size_t WebPEncodeLosslessBGRA(const uint8_t* bgra, - int width, int height, int stride, - uint8_t** output); - -//------------------------------------------------------------------------------ -// Coding parameters - -// Image characteristics hint for the underlying encoder. -typedef enum WebPImageHint { - WEBP_HINT_DEFAULT = 0, // default preset. - WEBP_HINT_PICTURE, // digital picture, like portrait, inner shot - WEBP_HINT_PHOTO, // outdoor photograph, with natural lighting - WEBP_HINT_GRAPH, // Discrete tone image (graph, map-tile etc). - WEBP_HINT_LAST -} WebPImageHint; - -// Compression parameters. -struct WebPConfig { - int lossless; // Lossless encoding (0=lossy(default), 1=lossless). - float quality; // between 0 and 100. For lossy, 0 gives the smallest - // size and 100 the largest. For lossless, this - // parameter is the amount of effort put into the - // compression: 0 is the fastest but gives larger - // files compared to the slowest, but best, 100. - int method; // quality/speed trade-off (0=fast, 6=slower-better) - - WebPImageHint image_hint; // Hint for image type (lossless only for now). - - int target_size; // if non-zero, set the desired target size in bytes. - // Takes precedence over the 'compression' parameter. - float target_PSNR; // if non-zero, specifies the minimal distortion to - // try to achieve. Takes precedence over target_size. - int segments; // maximum number of segments to use, in [1..4] - int sns_strength; // Spatial Noise Shaping. 0=off, 100=maximum. - int filter_strength; // range: [0 = off .. 100 = strongest] - int filter_sharpness; // range: [0 = off .. 7 = least sharp] - int filter_type; // filtering type: 0 = simple, 1 = strong (only used - // if filter_strength > 0 or autofilter > 0) - int autofilter; // Auto adjust filter's strength [0 = off, 1 = on] - int alpha_compression; // Algorithm for encoding the alpha plane (0 = none, - // 1 = compressed with WebP lossless). Default is 1. - int alpha_filtering; // Predictive filtering method for alpha plane. - // 0: none, 1: fast, 2: best. Default if 1. - int alpha_quality; // Between 0 (smallest size) and 100 (lossless). - // Default is 100. - int pass; // number of entropy-analysis passes (in [1..10]). - - int show_compressed; // if true, export the compressed picture back. - // In-loop filtering is not applied. - int preprocessing; // preprocessing filter: - // 0=none, 1=segment-smooth, 2=pseudo-random dithering - int partitions; // log2(number of token partitions) in [0..3]. Default - // is set to 0 for easier progressive decoding. - int partition_limit; // quality degradation allowed to fit the 512k limit - // on prediction modes coding (0: no degradation, - // 100: maximum possible degradation). - int emulate_jpeg_size; // If true, compression parameters will be remapped - // to better match the expected output size from - // JPEG compression. Generally, the output size will - // be similar but the degradation will be lower. - int thread_level; // If non-zero, try and use multi-threaded encoding. - int low_memory; // If set, reduce memory usage (but increase CPU use). - - int near_lossless; // Near lossless encoding [0 = max loss .. 100 = off - // (default)]. - int exact; // if non-zero, preserve the exact RGB values under - // transparent area. Otherwise, discard this invisible - // RGB information for better compression. The default - // value is 0. - - int use_delta_palette; // reserved for future lossless feature - int use_sharp_yuv; // if needed, use sharp (and slow) RGB->YUV conversion - - int qmin; // minimum permissible quality factor - int qmax; // maximum permissible quality factor -}; - -// Enumerate some predefined settings for WebPConfig, depending on the type -// of source picture. These presets are used when calling WebPConfigPreset(). -typedef enum WebPPreset { - WEBP_PRESET_DEFAULT = 0, // default preset. - WEBP_PRESET_PICTURE, // digital picture, like portrait, inner shot - WEBP_PRESET_PHOTO, // outdoor photograph, with natural lighting - WEBP_PRESET_DRAWING, // hand or line drawing, with high-contrast details - WEBP_PRESET_ICON, // small-sized colorful images - WEBP_PRESET_TEXT // text-like -} WebPPreset; - -// Internal, version-checked, entry point -WEBP_EXTERN int WebPConfigInitInternal(WebPConfig*, WebPPreset, float, int); - -// Should always be called, to initialize a fresh WebPConfig structure before -// modification. Returns false in case of version mismatch. WebPConfigInit() -// must have succeeded before using the 'config' object. -// Note that the default values are lossless=0 and quality=75. -static WEBP_INLINE int WebPConfigInit(WebPConfig* config) { - return WebPConfigInitInternal(config, WEBP_PRESET_DEFAULT, 75.f, - WEBP_ENCODER_ABI_VERSION); -} - -// This function will initialize the configuration according to a predefined -// set of parameters (referred to by 'preset') and a given quality factor. -// This function can be called as a replacement to WebPConfigInit(). Will -// return false in case of error. -static WEBP_INLINE int WebPConfigPreset(WebPConfig* config, - WebPPreset preset, float quality) { - return WebPConfigInitInternal(config, preset, quality, - WEBP_ENCODER_ABI_VERSION); -} - -// Activate the lossless compression mode with the desired efficiency level -// between 0 (fastest, lowest compression) and 9 (slower, best compression). -// A good default level is '6', providing a fair tradeoff between compression -// speed and final compressed size. -// This function will overwrite several fields from config: 'method', 'quality' -// and 'lossless'. Returns false in case of parameter error. -WEBP_EXTERN int WebPConfigLosslessPreset(WebPConfig* config, int level); - -// Returns true if 'config' is non-NULL and all configuration parameters are -// within their valid ranges. -WEBP_EXTERN int WebPValidateConfig(const WebPConfig* config); - -//------------------------------------------------------------------------------ -// Input / Output -// Structure for storing auxiliary statistics. - -struct WebPAuxStats { - int coded_size; // final size - - float PSNR[5]; // peak-signal-to-noise ratio for Y/U/V/All/Alpha - int block_count[3]; // number of intra4/intra16/skipped macroblocks - int header_bytes[2]; // approximate number of bytes spent for header - // and mode-partition #0 - int residual_bytes[3][4]; // approximate number of bytes spent for - // DC/AC/uv coefficients for each (0..3) segments. - int segment_size[4]; // number of macroblocks in each segments - int segment_quant[4]; // quantizer values for each segments - int segment_level[4]; // filtering strength for each segments [0..63] - - int alpha_data_size; // size of the transparency data - int layer_data_size; // size of the enhancement layer data - - // lossless encoder statistics - uint32_t lossless_features; // bit0:predictor bit1:cross-color transform - // bit2:subtract-green bit3:color indexing - int histogram_bits; // number of precision bits of histogram - int transform_bits; // precision bits for transform - int cache_bits; // number of bits for color cache lookup - int palette_size; // number of color in palette, if used - int lossless_size; // final lossless size - int lossless_hdr_size; // lossless header (transform, huffman etc) size - int lossless_data_size; // lossless image data size - - uint32_t pad[2]; // padding for later use -}; - -// Signature for output function. Should return true if writing was successful. -// data/data_size is the segment of data to write, and 'picture' is for -// reference (and so one can make use of picture->custom_ptr). -typedef int (*WebPWriterFunction)(const uint8_t* data, size_t data_size, - const WebPPicture* picture); - -// WebPMemoryWrite: a special WebPWriterFunction that writes to memory using -// the following WebPMemoryWriter object (to be set as a custom_ptr). -struct WebPMemoryWriter { - uint8_t* mem; // final buffer (of size 'max_size', larger than 'size'). - size_t size; // final size - size_t max_size; // total capacity - uint32_t pad[1]; // padding for later use -}; - -// The following must be called first before any use. -WEBP_EXTERN void WebPMemoryWriterInit(WebPMemoryWriter* writer); - -// The following must be called to deallocate writer->mem memory. The 'writer' -// object itself is not deallocated. -WEBP_EXTERN void WebPMemoryWriterClear(WebPMemoryWriter* writer); -// The custom writer to be used with WebPMemoryWriter as custom_ptr. Upon -// completion, writer.mem and writer.size will hold the coded data. -// writer.mem must be freed by calling WebPMemoryWriterClear. -WEBP_EXTERN int WebPMemoryWrite(const uint8_t* data, size_t data_size, - const WebPPicture* picture); - -// Progress hook, called from time to time to report progress. It can return -// false to request an abort of the encoding process, or true otherwise if -// everything is OK. -typedef int (*WebPProgressHook)(int percent, const WebPPicture* picture); - -// Color spaces. -typedef enum WebPEncCSP { - // chroma sampling - WEBP_YUV420 = 0, // 4:2:0 - WEBP_YUV420A = 4, // alpha channel variant - WEBP_CSP_UV_MASK = 3, // bit-mask to get the UV sampling factors - WEBP_CSP_ALPHA_BIT = 4 // bit that is set if alpha is present -} WebPEncCSP; - -// Encoding error conditions. -typedef enum WebPEncodingError { - VP8_ENC_OK = 0, - VP8_ENC_ERROR_OUT_OF_MEMORY, // memory error allocating objects - VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY, // memory error while flushing bits - VP8_ENC_ERROR_NULL_PARAMETER, // a pointer parameter is NULL - VP8_ENC_ERROR_INVALID_CONFIGURATION, // configuration is invalid - VP8_ENC_ERROR_BAD_DIMENSION, // picture has invalid width/height - VP8_ENC_ERROR_PARTITION0_OVERFLOW, // partition is bigger than 512k - VP8_ENC_ERROR_PARTITION_OVERFLOW, // partition is bigger than 16M - VP8_ENC_ERROR_BAD_WRITE, // error while flushing bytes - VP8_ENC_ERROR_FILE_TOO_BIG, // file is bigger than 4G - VP8_ENC_ERROR_USER_ABORT, // abort request by user - VP8_ENC_ERROR_LAST // list terminator. always last. -} WebPEncodingError; - -// maximum width/height allowed (inclusive), in pixels -#define WEBP_MAX_DIMENSION 16383 - -// Main exchange structure (input samples, output bytes, statistics) -// -// Once WebPPictureInit() has been called, it's ok to make all the INPUT fields -// (use_argb, y/u/v, argb, ...) point to user-owned data, even if -// WebPPictureAlloc() has been called. Depending on the value use_argb, -// it's guaranteed that either *argb or *y/*u/*v content will be kept untouched. -struct WebPPicture { - // INPUT - ////////////// - // Main flag for encoder selecting between ARGB or YUV input. - // It is recommended to use ARGB input (*argb, argb_stride) for lossless - // compression, and YUV input (*y, *u, *v, etc.) for lossy compression - // since these are the respective native colorspace for these formats. - int use_argb; - - // YUV input (mostly used for input to lossy compression) - WebPEncCSP colorspace; // colorspace: should be YUV420 for now (=Y'CbCr). - int width, height; // dimensions (less or equal to WEBP_MAX_DIMENSION) - uint8_t* y, *u, *v; // pointers to luma/chroma planes. - int y_stride, uv_stride; // luma/chroma strides. - uint8_t* a; // pointer to the alpha plane - int a_stride; // stride of the alpha plane - uint32_t pad1[2]; // padding for later use - - // ARGB input (mostly used for input to lossless compression) - uint32_t* argb; // Pointer to argb (32 bit) plane. - int argb_stride; // This is stride in pixels units, not bytes. - uint32_t pad2[3]; // padding for later use - - // OUTPUT - /////////////// - // Byte-emission hook, to store compressed bytes as they are ready. - WebPWriterFunction writer; // can be NULL - void* custom_ptr; // can be used by the writer. - - // map for extra information (only for lossy compression mode) - int extra_info_type; // 1: intra type, 2: segment, 3: quant - // 4: intra-16 prediction mode, - // 5: chroma prediction mode, - // 6: bit cost, 7: distortion - uint8_t* extra_info; // if not NULL, points to an array of size - // ((width + 15) / 16) * ((height + 15) / 16) that - // will be filled with a macroblock map, depending - // on extra_info_type. - - // STATS AND REPORTS - /////////////////////////// - // Pointer to side statistics (updated only if not NULL) - WebPAuxStats* stats; - - // Error code for the latest error encountered during encoding - WebPEncodingError error_code; - - // If not NULL, report progress during encoding. - WebPProgressHook progress_hook; - - void* user_data; // this field is free to be set to any value and - // used during callbacks (like progress-report e.g.). - - uint32_t pad3[3]; // padding for later use - - // Unused for now - uint8_t* pad4, *pad5; - uint32_t pad6[8]; // padding for later use - - // PRIVATE FIELDS - //////////////////// - void* memory_; // row chunk of memory for yuva planes - void* memory_argb_; // and for argb too. - void* pad7[2]; // padding for later use -}; - -// Internal, version-checked, entry point -WEBP_EXTERN int WebPPictureInitInternal(WebPPicture*, int); - -// Should always be called, to initialize the structure. Returns false in case -// of version mismatch. WebPPictureInit() must have succeeded before using the -// 'picture' object. -// Note that, by default, use_argb is false and colorspace is WEBP_YUV420. -static WEBP_INLINE int WebPPictureInit(WebPPicture* picture) { - return WebPPictureInitInternal(picture, WEBP_ENCODER_ABI_VERSION); -} - -//------------------------------------------------------------------------------ -// WebPPicture utils - -// Convenience allocation / deallocation based on picture->width/height: -// Allocate y/u/v buffers as per colorspace/width/height specification. -// Note! This function will free the previous buffer if needed. -// Returns false in case of memory error. -WEBP_EXTERN int WebPPictureAlloc(WebPPicture* picture); - -// Release the memory allocated by WebPPictureAlloc() or WebPPictureImport*(). -// Note that this function does _not_ free the memory used by the 'picture' -// object itself. -// Besides memory (which is reclaimed) all other fields of 'picture' are -// preserved. -WEBP_EXTERN void WebPPictureFree(WebPPicture* picture); - -// Copy the pixels of *src into *dst, using WebPPictureAlloc. Upon return, *dst -// will fully own the copied pixels (this is not a view). The 'dst' picture need -// not be initialized as its content is overwritten. -// Returns false in case of memory allocation error. -WEBP_EXTERN int WebPPictureCopy(const WebPPicture* src, WebPPicture* dst); - -// Compute the single distortion for packed planes of samples. -// 'src' will be compared to 'ref', and the raw distortion stored into -// '*distortion'. The refined metric (log(MSE), log(1 - ssim),...' will be -// stored in '*result'. -// 'x_step' is the horizontal stride (in bytes) between samples. -// 'src/ref_stride' is the byte distance between rows. -// Returns false in case of error (bad parameter, memory allocation error, ...). -WEBP_EXTERN int WebPPlaneDistortion(const uint8_t* src, size_t src_stride, - const uint8_t* ref, size_t ref_stride, - int width, int height, - size_t x_step, - int type, // 0 = PSNR, 1 = SSIM, 2 = LSIM - float* distortion, float* result); - -// Compute PSNR, SSIM or LSIM distortion metric between two pictures. Results -// are in dB, stored in result[] in the B/G/R/A/All order. The distortion is -// always performed using ARGB samples. Hence if the input is YUV(A), the -// picture will be internally converted to ARGB (just for the measurement). -// Warning: this function is rather CPU-intensive. -WEBP_EXTERN int WebPPictureDistortion( - const WebPPicture* src, const WebPPicture* ref, - int metric_type, // 0 = PSNR, 1 = SSIM, 2 = LSIM - float result[5]); - -// self-crops a picture to the rectangle defined by top/left/width/height. -// Returns false in case of memory allocation error, or if the rectangle is -// outside of the source picture. -// The rectangle for the view is defined by the top-left corner pixel -// coordinates (left, top) as well as its width and height. This rectangle -// must be fully be comprised inside the 'src' source picture. If the source -// picture uses the YUV420 colorspace, the top and left coordinates will be -// snapped to even values. -WEBP_EXTERN int WebPPictureCrop(WebPPicture* picture, - int left, int top, int width, int height); - -// Extracts a view from 'src' picture into 'dst'. The rectangle for the view -// is defined by the top-left corner pixel coordinates (left, top) as well -// as its width and height. This rectangle must be fully be comprised inside -// the 'src' source picture. If the source picture uses the YUV420 colorspace, -// the top and left coordinates will be snapped to even values. -// Picture 'src' must out-live 'dst' picture. Self-extraction of view is allowed -// ('src' equal to 'dst') as a mean of fast-cropping (but note that doing so, -// the original dimension will be lost). Picture 'dst' need not be initialized -// with WebPPictureInit() if it is different from 'src', since its content will -// be overwritten. -// Returns false in case of invalid parameters. -WEBP_EXTERN int WebPPictureView(const WebPPicture* src, - int left, int top, int width, int height, - WebPPicture* dst); - -// Returns true if the 'picture' is actually a view and therefore does -// not own the memory for pixels. -WEBP_EXTERN int WebPPictureIsView(const WebPPicture* picture); - -// Rescale a picture to new dimension width x height. -// If either 'width' or 'height' (but not both) is 0 the corresponding -// dimension will be calculated preserving the aspect ratio. -// No gamma correction is applied. -// Returns false in case of error (invalid parameter or insufficient memory). -WEBP_EXTERN int WebPPictureRescale(WebPPicture* picture, int width, int height); - -// Colorspace conversion function to import RGB samples. -// Previous buffer will be free'd, if any. -// *rgb buffer should have a size of at least height * rgb_stride. -// Returns false in case of memory error. -WEBP_EXTERN int WebPPictureImportRGB( - WebPPicture* picture, const uint8_t* rgb, int rgb_stride); -// Same, but for RGBA buffer. -WEBP_EXTERN int WebPPictureImportRGBA( - WebPPicture* picture, const uint8_t* rgba, int rgba_stride); -// Same, but for RGBA buffer. Imports the RGB direct from the 32-bit format -// input buffer ignoring the alpha channel. Avoids needing to copy the data -// to a temporary 24-bit RGB buffer to import the RGB only. -WEBP_EXTERN int WebPPictureImportRGBX( - WebPPicture* picture, const uint8_t* rgbx, int rgbx_stride); - -// Variants of the above, but taking BGR(A|X) input. -WEBP_EXTERN int WebPPictureImportBGR( - WebPPicture* picture, const uint8_t* bgr, int bgr_stride); -WEBP_EXTERN int WebPPictureImportBGRA( - WebPPicture* picture, const uint8_t* bgra, int bgra_stride); -WEBP_EXTERN int WebPPictureImportBGRX( - WebPPicture* picture, const uint8_t* bgrx, int bgrx_stride); - -// Converts picture->argb data to the YUV420A format. The 'colorspace' -// parameter is deprecated and should be equal to WEBP_YUV420. -// Upon return, picture->use_argb is set to false. The presence of real -// non-opaque transparent values is detected, and 'colorspace' will be -// adjusted accordingly. Note that this method is lossy. -// Returns false in case of error. -WEBP_EXTERN int WebPPictureARGBToYUVA(WebPPicture* picture, - WebPEncCSP /*colorspace = WEBP_YUV420*/); - -// Same as WebPPictureARGBToYUVA(), but the conversion is done using -// pseudo-random dithering with a strength 'dithering' between -// 0.0 (no dithering) and 1.0 (maximum dithering). This is useful -// for photographic picture. -WEBP_EXTERN int WebPPictureARGBToYUVADithered( - WebPPicture* picture, WebPEncCSP colorspace, float dithering); - -// Performs 'sharp' RGBA->YUVA420 downsampling and colorspace conversion. -// Downsampling is handled with extra care in case of color clipping. This -// method is roughly 2x slower than WebPPictureARGBToYUVA() but produces better -// and sharper YUV representation. -// Returns false in case of error. -WEBP_EXTERN int WebPPictureSharpARGBToYUVA(WebPPicture* picture); -// kept for backward compatibility: -WEBP_EXTERN int WebPPictureSmartARGBToYUVA(WebPPicture* picture); - -// Converts picture->yuv to picture->argb and sets picture->use_argb to true. -// The input format must be YUV_420 or YUV_420A. The conversion from YUV420 to -// ARGB incurs a small loss too. -// Note that the use of this colorspace is discouraged if one has access to the -// raw ARGB samples, since using YUV420 is comparatively lossy. -// Returns false in case of error. -WEBP_EXTERN int WebPPictureYUVAToARGB(WebPPicture* picture); - -// Helper function: given a width x height plane of RGBA or YUV(A) samples -// clean-up or smoothen the YUV or RGB samples under fully transparent area, -// to help compressibility (no guarantee, though). -WEBP_EXTERN void WebPCleanupTransparentArea(WebPPicture* picture); - -// Scan the picture 'picture' for the presence of non fully opaque alpha values. -// Returns true in such case. Otherwise returns false (indicating that the -// alpha plane can be ignored altogether e.g.). -WEBP_EXTERN int WebPPictureHasTransparency(const WebPPicture* picture); - -// Remove the transparency information (if present) by blending the color with -// the background color 'background_rgb' (specified as 24bit RGB triplet). -// After this call, all alpha values are reset to 0xff. -WEBP_EXTERN void WebPBlendAlpha(WebPPicture* picture, uint32_t background_rgb); - -//------------------------------------------------------------------------------ -// Main call - -// Main encoding call, after config and picture have been initialized. -// 'picture' must be less than 16384x16384 in dimension (cf WEBP_MAX_DIMENSION), -// and the 'config' object must be a valid one. -// Returns false in case of error, true otherwise. -// In case of error, picture->error_code is updated accordingly. -// 'picture' can hold the source samples in both YUV(A) or ARGB input, depending -// on the value of 'picture->use_argb'. It is highly recommended to use -// the former for lossy encoding, and the latter for lossless encoding -// (when config.lossless is true). Automatic conversion from one format to -// another is provided but they both incur some loss. -WEBP_EXTERN int WebPEncode(const WebPConfig* config, WebPPicture* picture); - -//------------------------------------------------------------------------------ - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // WEBP_WEBP_ENCODE_H_ +// Copyright 2011 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// WebP encoder: main interface +// +// Author: Skal (pascal.massimino@gmail.com) + +#ifndef WEBP_WEBP_ENCODE_H_ +#define WEBP_WEBP_ENCODE_H_ + +#include "./types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define WEBP_ENCODER_ABI_VERSION 0x020f // MAJOR(8b) + MINOR(8b) + +// Note: forward declaring enumerations is not allowed in (strict) C and C++, +// the types are left here for reference. +// typedef enum WebPImageHint WebPImageHint; +// typedef enum WebPEncCSP WebPEncCSP; +// typedef enum WebPPreset WebPPreset; +// typedef enum WebPEncodingError WebPEncodingError; +typedef struct WebPConfig WebPConfig; +typedef struct WebPPicture WebPPicture; // main structure for I/O +typedef struct WebPAuxStats WebPAuxStats; +typedef struct WebPMemoryWriter WebPMemoryWriter; + +// Return the encoder's version number, packed in hexadecimal using 8bits for +// each of major/minor/revision. E.g: v2.5.7 is 0x020507. +WEBP_EXTERN int WebPGetEncoderVersion(void); + +//------------------------------------------------------------------------------ +// One-stop-shop call! No questions asked: + +// Returns the size of the compressed data (pointed to by *output), or 0 if +// an error occurred. The compressed data must be released by the caller +// using the call 'WebPFree(*output)'. +// These functions compress using the lossy format, and the quality_factor +// can go from 0 (smaller output, lower quality) to 100 (best quality, +// larger output). +WEBP_EXTERN size_t WebPEncodeRGB(const uint8_t* rgb, + int width, int height, int stride, + float quality_factor, uint8_t** output); +WEBP_EXTERN size_t WebPEncodeBGR(const uint8_t* bgr, + int width, int height, int stride, + float quality_factor, uint8_t** output); +WEBP_EXTERN size_t WebPEncodeRGBA(const uint8_t* rgba, + int width, int height, int stride, + float quality_factor, uint8_t** output); +WEBP_EXTERN size_t WebPEncodeBGRA(const uint8_t* bgra, + int width, int height, int stride, + float quality_factor, uint8_t** output); + +// These functions are the equivalent of the above, but compressing in a +// lossless manner. Files are usually larger than lossy format, but will +// not suffer any compression loss. +// Note these functions, like the lossy versions, use the library's default +// settings. For lossless this means 'exact' is disabled. RGB values in +// transparent areas will be modified to improve compression. To avoid this, +// use WebPEncode() and set WebPConfig::exact to 1. +WEBP_EXTERN size_t WebPEncodeLosslessRGB(const uint8_t* rgb, + int width, int height, int stride, + uint8_t** output); +WEBP_EXTERN size_t WebPEncodeLosslessBGR(const uint8_t* bgr, + int width, int height, int stride, + uint8_t** output); +WEBP_EXTERN size_t WebPEncodeLosslessRGBA(const uint8_t* rgba, + int width, int height, int stride, + uint8_t** output); +WEBP_EXTERN size_t WebPEncodeLosslessBGRA(const uint8_t* bgra, + int width, int height, int stride, + uint8_t** output); + +//------------------------------------------------------------------------------ +// Coding parameters + +// Image characteristics hint for the underlying encoder. +typedef enum WebPImageHint { + WEBP_HINT_DEFAULT = 0, // default preset. + WEBP_HINT_PICTURE, // digital picture, like portrait, inner shot + WEBP_HINT_PHOTO, // outdoor photograph, with natural lighting + WEBP_HINT_GRAPH, // Discrete tone image (graph, map-tile etc). + WEBP_HINT_LAST +} WebPImageHint; + +// Compression parameters. +struct WebPConfig { + int lossless; // Lossless encoding (0=lossy(default), 1=lossless). + float quality; // between 0 and 100. For lossy, 0 gives the smallest + // size and 100 the largest. For lossless, this + // parameter is the amount of effort put into the + // compression: 0 is the fastest but gives larger + // files compared to the slowest, but best, 100. + int method; // quality/speed trade-off (0=fast, 6=slower-better) + + WebPImageHint image_hint; // Hint for image type (lossless only for now). + + int target_size; // if non-zero, set the desired target size in bytes. + // Takes precedence over the 'compression' parameter. + float target_PSNR; // if non-zero, specifies the minimal distortion to + // try to achieve. Takes precedence over target_size. + int segments; // maximum number of segments to use, in [1..4] + int sns_strength; // Spatial Noise Shaping. 0=off, 100=maximum. + int filter_strength; // range: [0 = off .. 100 = strongest] + int filter_sharpness; // range: [0 = off .. 7 = least sharp] + int filter_type; // filtering type: 0 = simple, 1 = strong (only used + // if filter_strength > 0 or autofilter > 0) + int autofilter; // Auto adjust filter's strength [0 = off, 1 = on] + int alpha_compression; // Algorithm for encoding the alpha plane (0 = none, + // 1 = compressed with WebP lossless). Default is 1. + int alpha_filtering; // Predictive filtering method for alpha plane. + // 0: none, 1: fast, 2: best. Default if 1. + int alpha_quality; // Between 0 (smallest size) and 100 (lossless). + // Default is 100. + int pass; // number of entropy-analysis passes (in [1..10]). + + int show_compressed; // if true, export the compressed picture back. + // In-loop filtering is not applied. + int preprocessing; // preprocessing filter: + // 0=none, 1=segment-smooth, 2=pseudo-random dithering + int partitions; // log2(number of token partitions) in [0..3]. Default + // is set to 0 for easier progressive decoding. + int partition_limit; // quality degradation allowed to fit the 512k limit + // on prediction modes coding (0: no degradation, + // 100: maximum possible degradation). + int emulate_jpeg_size; // If true, compression parameters will be remapped + // to better match the expected output size from + // JPEG compression. Generally, the output size will + // be similar but the degradation will be lower. + int thread_level; // If non-zero, try and use multi-threaded encoding. + int low_memory; // If set, reduce memory usage (but increase CPU use). + + int near_lossless; // Near lossless encoding [0 = max loss .. 100 = off + // (default)]. + int exact; // if non-zero, preserve the exact RGB values under + // transparent area. Otherwise, discard this invisible + // RGB information for better compression. The default + // value is 0. + + int use_delta_palette; // reserved for future lossless feature + int use_sharp_yuv; // if needed, use sharp (and slow) RGB->YUV conversion + + int qmin; // minimum permissible quality factor + int qmax; // maximum permissible quality factor +}; + +// Enumerate some predefined settings for WebPConfig, depending on the type +// of source picture. These presets are used when calling WebPConfigPreset(). +typedef enum WebPPreset { + WEBP_PRESET_DEFAULT = 0, // default preset. + WEBP_PRESET_PICTURE, // digital picture, like portrait, inner shot + WEBP_PRESET_PHOTO, // outdoor photograph, with natural lighting + WEBP_PRESET_DRAWING, // hand or line drawing, with high-contrast details + WEBP_PRESET_ICON, // small-sized colorful images + WEBP_PRESET_TEXT // text-like +} WebPPreset; + +// Internal, version-checked, entry point +WEBP_EXTERN int WebPConfigInitInternal(WebPConfig*, WebPPreset, float, int); + +// Should always be called, to initialize a fresh WebPConfig structure before +// modification. Returns false in case of version mismatch. WebPConfigInit() +// must have succeeded before using the 'config' object. +// Note that the default values are lossless=0 and quality=75. +static WEBP_INLINE int WebPConfigInit(WebPConfig* config) { + return WebPConfigInitInternal(config, WEBP_PRESET_DEFAULT, 75.f, + WEBP_ENCODER_ABI_VERSION); +} + +// This function will initialize the configuration according to a predefined +// set of parameters (referred to by 'preset') and a given quality factor. +// This function can be called as a replacement to WebPConfigInit(). Will +// return false in case of error. +static WEBP_INLINE int WebPConfigPreset(WebPConfig* config, + WebPPreset preset, float quality) { + return WebPConfigInitInternal(config, preset, quality, + WEBP_ENCODER_ABI_VERSION); +} + +// Activate the lossless compression mode with the desired efficiency level +// between 0 (fastest, lowest compression) and 9 (slower, best compression). +// A good default level is '6', providing a fair tradeoff between compression +// speed and final compressed size. +// This function will overwrite several fields from config: 'method', 'quality' +// and 'lossless'. Returns false in case of parameter error. +WEBP_EXTERN int WebPConfigLosslessPreset(WebPConfig* config, int level); + +// Returns true if 'config' is non-NULL and all configuration parameters are +// within their valid ranges. +WEBP_EXTERN int WebPValidateConfig(const WebPConfig* config); + +//------------------------------------------------------------------------------ +// Input / Output +// Structure for storing auxiliary statistics. + +struct WebPAuxStats { + int coded_size; // final size + + float PSNR[5]; // peak-signal-to-noise ratio for Y/U/V/All/Alpha + int block_count[3]; // number of intra4/intra16/skipped macroblocks + int header_bytes[2]; // approximate number of bytes spent for header + // and mode-partition #0 + int residual_bytes[3][4]; // approximate number of bytes spent for + // DC/AC/uv coefficients for each (0..3) segments. + int segment_size[4]; // number of macroblocks in each segments + int segment_quant[4]; // quantizer values for each segments + int segment_level[4]; // filtering strength for each segments [0..63] + + int alpha_data_size; // size of the transparency data + int layer_data_size; // size of the enhancement layer data + + // lossless encoder statistics + uint32_t lossless_features; // bit0:predictor bit1:cross-color transform + // bit2:subtract-green bit3:color indexing + int histogram_bits; // number of precision bits of histogram + int transform_bits; // precision bits for transform + int cache_bits; // number of bits for color cache lookup + int palette_size; // number of color in palette, if used + int lossless_size; // final lossless size + int lossless_hdr_size; // lossless header (transform, huffman etc) size + int lossless_data_size; // lossless image data size + + uint32_t pad[2]; // padding for later use +}; + +// Signature for output function. Should return true if writing was successful. +// data/data_size is the segment of data to write, and 'picture' is for +// reference (and so one can make use of picture->custom_ptr). +typedef int (*WebPWriterFunction)(const uint8_t* data, size_t data_size, + const WebPPicture* picture); + +// WebPMemoryWrite: a special WebPWriterFunction that writes to memory using +// the following WebPMemoryWriter object (to be set as a custom_ptr). +struct WebPMemoryWriter { + uint8_t* mem; // final buffer (of size 'max_size', larger than 'size'). + size_t size; // final size + size_t max_size; // total capacity + uint32_t pad[1]; // padding for later use +}; + +// The following must be called first before any use. +WEBP_EXTERN void WebPMemoryWriterInit(WebPMemoryWriter* writer); + +// The following must be called to deallocate writer->mem memory. The 'writer' +// object itself is not deallocated. +WEBP_EXTERN void WebPMemoryWriterClear(WebPMemoryWriter* writer); +// The custom writer to be used with WebPMemoryWriter as custom_ptr. Upon +// completion, writer.mem and writer.size will hold the coded data. +// writer.mem must be freed by calling WebPMemoryWriterClear. +WEBP_EXTERN int WebPMemoryWrite(const uint8_t* data, size_t data_size, + const WebPPicture* picture); + +// Progress hook, called from time to time to report progress. It can return +// false to request an abort of the encoding process, or true otherwise if +// everything is OK. +typedef int (*WebPProgressHook)(int percent, const WebPPicture* picture); + +// Color spaces. +typedef enum WebPEncCSP { + // chroma sampling + WEBP_YUV420 = 0, // 4:2:0 + WEBP_YUV420A = 4, // alpha channel variant + WEBP_CSP_UV_MASK = 3, // bit-mask to get the UV sampling factors + WEBP_CSP_ALPHA_BIT = 4 // bit that is set if alpha is present +} WebPEncCSP; + +// Encoding error conditions. +typedef enum WebPEncodingError { + VP8_ENC_OK = 0, + VP8_ENC_ERROR_OUT_OF_MEMORY, // memory error allocating objects + VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY, // memory error while flushing bits + VP8_ENC_ERROR_NULL_PARAMETER, // a pointer parameter is NULL + VP8_ENC_ERROR_INVALID_CONFIGURATION, // configuration is invalid + VP8_ENC_ERROR_BAD_DIMENSION, // picture has invalid width/height + VP8_ENC_ERROR_PARTITION0_OVERFLOW, // partition is bigger than 512k + VP8_ENC_ERROR_PARTITION_OVERFLOW, // partition is bigger than 16M + VP8_ENC_ERROR_BAD_WRITE, // error while flushing bytes + VP8_ENC_ERROR_FILE_TOO_BIG, // file is bigger than 4G + VP8_ENC_ERROR_USER_ABORT, // abort request by user + VP8_ENC_ERROR_LAST // list terminator. always last. +} WebPEncodingError; + +// maximum width/height allowed (inclusive), in pixels +#define WEBP_MAX_DIMENSION 16383 + +// Main exchange structure (input samples, output bytes, statistics) +// +// Once WebPPictureInit() has been called, it's ok to make all the INPUT fields +// (use_argb, y/u/v, argb, ...) point to user-owned data, even if +// WebPPictureAlloc() has been called. Depending on the value use_argb, +// it's guaranteed that either *argb or *y/*u/*v content will be kept untouched. +struct WebPPicture { + // INPUT + ////////////// + // Main flag for encoder selecting between ARGB or YUV input. + // It is recommended to use ARGB input (*argb, argb_stride) for lossless + // compression, and YUV input (*y, *u, *v, etc.) for lossy compression + // since these are the respective native colorspace for these formats. + int use_argb; + + // YUV input (mostly used for input to lossy compression) + WebPEncCSP colorspace; // colorspace: should be YUV420 for now (=Y'CbCr). + int width, height; // dimensions (less or equal to WEBP_MAX_DIMENSION) + uint8_t* y, *u, *v; // pointers to luma/chroma planes. + int y_stride, uv_stride; // luma/chroma strides. + uint8_t* a; // pointer to the alpha plane + int a_stride; // stride of the alpha plane + uint32_t pad1[2]; // padding for later use + + // ARGB input (mostly used for input to lossless compression) + uint32_t* argb; // Pointer to argb (32 bit) plane. + int argb_stride; // This is stride in pixels units, not bytes. + uint32_t pad2[3]; // padding for later use + + // OUTPUT + /////////////// + // Byte-emission hook, to store compressed bytes as they are ready. + WebPWriterFunction writer; // can be NULL + void* custom_ptr; // can be used by the writer. + + // map for extra information (only for lossy compression mode) + int extra_info_type; // 1: intra type, 2: segment, 3: quant + // 4: intra-16 prediction mode, + // 5: chroma prediction mode, + // 6: bit cost, 7: distortion + uint8_t* extra_info; // if not NULL, points to an array of size + // ((width + 15) / 16) * ((height + 15) / 16) that + // will be filled with a macroblock map, depending + // on extra_info_type. + + // STATS AND REPORTS + /////////////////////////// + // Pointer to side statistics (updated only if not NULL) + WebPAuxStats* stats; + + // Error code for the latest error encountered during encoding + WebPEncodingError error_code; + + // If not NULL, report progress during encoding. + WebPProgressHook progress_hook; + + void* user_data; // this field is free to be set to any value and + // used during callbacks (like progress-report e.g.). + + uint32_t pad3[3]; // padding for later use + + // Unused for now + uint8_t* pad4, *pad5; + uint32_t pad6[8]; // padding for later use + + // PRIVATE FIELDS + //////////////////// + void* memory_; // row chunk of memory for yuva planes + void* memory_argb_; // and for argb too. + void* pad7[2]; // padding for later use +}; + +// Internal, version-checked, entry point +WEBP_EXTERN int WebPPictureInitInternal(WebPPicture*, int); + +// Should always be called, to initialize the structure. Returns false in case +// of version mismatch. WebPPictureInit() must have succeeded before using the +// 'picture' object. +// Note that, by default, use_argb is false and colorspace is WEBP_YUV420. +static WEBP_INLINE int WebPPictureInit(WebPPicture* picture) { + return WebPPictureInitInternal(picture, WEBP_ENCODER_ABI_VERSION); +} + +//------------------------------------------------------------------------------ +// WebPPicture utils + +// Convenience allocation / deallocation based on picture->width/height: +// Allocate y/u/v buffers as per colorspace/width/height specification. +// Note! This function will free the previous buffer if needed. +// Returns false in case of memory error. +WEBP_EXTERN int WebPPictureAlloc(WebPPicture* picture); + +// Release the memory allocated by WebPPictureAlloc() or WebPPictureImport*(). +// Note that this function does _not_ free the memory used by the 'picture' +// object itself. +// Besides memory (which is reclaimed) all other fields of 'picture' are +// preserved. +WEBP_EXTERN void WebPPictureFree(WebPPicture* picture); + +// Copy the pixels of *src into *dst, using WebPPictureAlloc. Upon return, *dst +// will fully own the copied pixels (this is not a view). The 'dst' picture need +// not be initialized as its content is overwritten. +// Returns false in case of memory allocation error. +WEBP_EXTERN int WebPPictureCopy(const WebPPicture* src, WebPPicture* dst); + +// Compute the single distortion for packed planes of samples. +// 'src' will be compared to 'ref', and the raw distortion stored into +// '*distortion'. The refined metric (log(MSE), log(1 - ssim),...' will be +// stored in '*result'. +// 'x_step' is the horizontal stride (in bytes) between samples. +// 'src/ref_stride' is the byte distance between rows. +// Returns false in case of error (bad parameter, memory allocation error, ...). +WEBP_EXTERN int WebPPlaneDistortion(const uint8_t* src, size_t src_stride, + const uint8_t* ref, size_t ref_stride, + int width, int height, + size_t x_step, + int type, // 0 = PSNR, 1 = SSIM, 2 = LSIM + float* distortion, float* result); + +// Compute PSNR, SSIM or LSIM distortion metric between two pictures. Results +// are in dB, stored in result[] in the B/G/R/A/All order. The distortion is +// always performed using ARGB samples. Hence if the input is YUV(A), the +// picture will be internally converted to ARGB (just for the measurement). +// Warning: this function is rather CPU-intensive. +WEBP_EXTERN int WebPPictureDistortion( + const WebPPicture* src, const WebPPicture* ref, + int metric_type, // 0 = PSNR, 1 = SSIM, 2 = LSIM + float result[5]); + +// self-crops a picture to the rectangle defined by top/left/width/height. +// Returns false in case of memory allocation error, or if the rectangle is +// outside of the source picture. +// The rectangle for the view is defined by the top-left corner pixel +// coordinates (left, top) as well as its width and height. This rectangle +// must be fully be comprised inside the 'src' source picture. If the source +// picture uses the YUV420 colorspace, the top and left coordinates will be +// snapped to even values. +WEBP_EXTERN int WebPPictureCrop(WebPPicture* picture, + int left, int top, int width, int height); + +// Extracts a view from 'src' picture into 'dst'. The rectangle for the view +// is defined by the top-left corner pixel coordinates (left, top) as well +// as its width and height. This rectangle must be fully be comprised inside +// the 'src' source picture. If the source picture uses the YUV420 colorspace, +// the top and left coordinates will be snapped to even values. +// Picture 'src' must out-live 'dst' picture. Self-extraction of view is allowed +// ('src' equal to 'dst') as a mean of fast-cropping (but note that doing so, +// the original dimension will be lost). Picture 'dst' need not be initialized +// with WebPPictureInit() if it is different from 'src', since its content will +// be overwritten. +// Returns false in case of invalid parameters. +WEBP_EXTERN int WebPPictureView(const WebPPicture* src, + int left, int top, int width, int height, + WebPPicture* dst); + +// Returns true if the 'picture' is actually a view and therefore does +// not own the memory for pixels. +WEBP_EXTERN int WebPPictureIsView(const WebPPicture* picture); + +// Rescale a picture to new dimension width x height. +// If either 'width' or 'height' (but not both) is 0 the corresponding +// dimension will be calculated preserving the aspect ratio. +// No gamma correction is applied. +// Returns false in case of error (invalid parameter or insufficient memory). +WEBP_EXTERN int WebPPictureRescale(WebPPicture* picture, int width, int height); + +// Colorspace conversion function to import RGB samples. +// Previous buffer will be free'd, if any. +// *rgb buffer should have a size of at least height * rgb_stride. +// Returns false in case of memory error. +WEBP_EXTERN int WebPPictureImportRGB( + WebPPicture* picture, const uint8_t* rgb, int rgb_stride); +// Same, but for RGBA buffer. +WEBP_EXTERN int WebPPictureImportRGBA( + WebPPicture* picture, const uint8_t* rgba, int rgba_stride); +// Same, but for RGBA buffer. Imports the RGB direct from the 32-bit format +// input buffer ignoring the alpha channel. Avoids needing to copy the data +// to a temporary 24-bit RGB buffer to import the RGB only. +WEBP_EXTERN int WebPPictureImportRGBX( + WebPPicture* picture, const uint8_t* rgbx, int rgbx_stride); + +// Variants of the above, but taking BGR(A|X) input. +WEBP_EXTERN int WebPPictureImportBGR( + WebPPicture* picture, const uint8_t* bgr, int bgr_stride); +WEBP_EXTERN int WebPPictureImportBGRA( + WebPPicture* picture, const uint8_t* bgra, int bgra_stride); +WEBP_EXTERN int WebPPictureImportBGRX( + WebPPicture* picture, const uint8_t* bgrx, int bgrx_stride); + +// Converts picture->argb data to the YUV420A format. The 'colorspace' +// parameter is deprecated and should be equal to WEBP_YUV420. +// Upon return, picture->use_argb is set to false. The presence of real +// non-opaque transparent values is detected, and 'colorspace' will be +// adjusted accordingly. Note that this method is lossy. +// Returns false in case of error. +WEBP_EXTERN int WebPPictureARGBToYUVA(WebPPicture* picture, + WebPEncCSP /*colorspace = WEBP_YUV420*/); + +// Same as WebPPictureARGBToYUVA(), but the conversion is done using +// pseudo-random dithering with a strength 'dithering' between +// 0.0 (no dithering) and 1.0 (maximum dithering). This is useful +// for photographic picture. +WEBP_EXTERN int WebPPictureARGBToYUVADithered( + WebPPicture* picture, WebPEncCSP colorspace, float dithering); + +// Performs 'sharp' RGBA->YUVA420 downsampling and colorspace conversion. +// Downsampling is handled with extra care in case of color clipping. This +// method is roughly 2x slower than WebPPictureARGBToYUVA() but produces better +// and sharper YUV representation. +// Returns false in case of error. +WEBP_EXTERN int WebPPictureSharpARGBToYUVA(WebPPicture* picture); +// kept for backward compatibility: +WEBP_EXTERN int WebPPictureSmartARGBToYUVA(WebPPicture* picture); + +// Converts picture->yuv to picture->argb and sets picture->use_argb to true. +// The input format must be YUV_420 or YUV_420A. The conversion from YUV420 to +// ARGB incurs a small loss too. +// Note that the use of this colorspace is discouraged if one has access to the +// raw ARGB samples, since using YUV420 is comparatively lossy. +// Returns false in case of error. +WEBP_EXTERN int WebPPictureYUVAToARGB(WebPPicture* picture); + +// Helper function: given a width x height plane of RGBA or YUV(A) samples +// clean-up or smoothen the YUV or RGB samples under fully transparent area, +// to help compressibility (no guarantee, though). +WEBP_EXTERN void WebPCleanupTransparentArea(WebPPicture* picture); + +// Scan the picture 'picture' for the presence of non fully opaque alpha values. +// Returns true in such case. Otherwise returns false (indicating that the +// alpha plane can be ignored altogether e.g.). +WEBP_EXTERN int WebPPictureHasTransparency(const WebPPicture* picture); + +// Remove the transparency information (if present) by blending the color with +// the background color 'background_rgb' (specified as 24bit RGB triplet). +// After this call, all alpha values are reset to 0xff. +WEBP_EXTERN void WebPBlendAlpha(WebPPicture* picture, uint32_t background_rgb); + +//------------------------------------------------------------------------------ +// Main call + +// Main encoding call, after config and picture have been initialized. +// 'picture' must be less than 16384x16384 in dimension (cf WEBP_MAX_DIMENSION), +// and the 'config' object must be a valid one. +// Returns false in case of error, true otherwise. +// In case of error, picture->error_code is updated accordingly. +// 'picture' can hold the source samples in both YUV(A) or ARGB input, depending +// on the value of 'picture->use_argb'. It is highly recommended to use +// the former for lossy encoding, and the latter for lossless encoding +// (when config.lossless is true). Automatic conversion from one format to +// another is provided but they both incur some loss. +WEBP_EXTERN int WebPEncode(const WebPConfig* config, WebPPicture* picture); + +//------------------------------------------------------------------------------ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // WEBP_WEBP_ENCODE_H_ diff --git a/src/JPEGView/libwebp/include/webp/mux.h b/src/JPEGView/libwebp/include/webp/mux.h index 6cc0fce2..7d27489a 100644 --- a/src/JPEGView/libwebp/include/webp/mux.h +++ b/src/JPEGView/libwebp/include/webp/mux.h @@ -1,530 +1,530 @@ -// Copyright 2011 Google Inc. All Rights Reserved. -// -// Use of this source code is governed by a BSD-style license -// that can be found in the COPYING file in the root of the source -// tree. An additional intellectual property rights grant can be found -// in the file PATENTS. All contributing project authors may -// be found in the AUTHORS file in the root of the source tree. -// ----------------------------------------------------------------------------- -// -// RIFF container manipulation and encoding for WebP images. -// -// Authors: Urvang (urvang@google.com) -// Vikas (vikasa@google.com) - -#ifndef WEBP_WEBP_MUX_H_ -#define WEBP_WEBP_MUX_H_ - -#include "./mux_types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define WEBP_MUX_ABI_VERSION 0x0108 // MAJOR(8b) + MINOR(8b) - -//------------------------------------------------------------------------------ -// Mux API -// -// This API allows manipulation of WebP container images containing features -// like color profile, metadata, animation. -// -// Code Example#1: Create a WebPMux object with image data, color profile and -// XMP metadata. -/* - int copy_data = 0; - WebPMux* mux = WebPMuxNew(); - // ... (Prepare image data). - WebPMuxSetImage(mux, &image, copy_data); - // ... (Prepare ICCP color profile data). - WebPMuxSetChunk(mux, "ICCP", &icc_profile, copy_data); - // ... (Prepare XMP metadata). - WebPMuxSetChunk(mux, "XMP ", &xmp, copy_data); - // Get data from mux in WebP RIFF format. - WebPMuxAssemble(mux, &output_data); - WebPMuxDelete(mux); - // ... (Consume output_data; e.g. write output_data.bytes to file). - WebPDataClear(&output_data); -*/ - -// Code Example#2: Get image and color profile data from a WebP file. -/* - int copy_data = 0; - // ... (Read data from file). - WebPMux* mux = WebPMuxCreate(&data, copy_data); - WebPMuxGetFrame(mux, 1, &image); - // ... (Consume image; e.g. call WebPDecode() to decode the data). - WebPMuxGetChunk(mux, "ICCP", &icc_profile); - // ... (Consume icc_data). - WebPMuxDelete(mux); - WebPFree(data); -*/ - -// Note: forward declaring enumerations is not allowed in (strict) C and C++, -// the types are left here for reference. -// typedef enum WebPMuxError WebPMuxError; -// typedef enum WebPChunkId WebPChunkId; -typedef struct WebPMux WebPMux; // main opaque object. -typedef struct WebPMuxFrameInfo WebPMuxFrameInfo; -typedef struct WebPMuxAnimParams WebPMuxAnimParams; -typedef struct WebPAnimEncoderOptions WebPAnimEncoderOptions; - -// Error codes -typedef enum WebPMuxError { - WEBP_MUX_OK = 1, - WEBP_MUX_NOT_FOUND = 0, - WEBP_MUX_INVALID_ARGUMENT = -1, - WEBP_MUX_BAD_DATA = -2, - WEBP_MUX_MEMORY_ERROR = -3, - WEBP_MUX_NOT_ENOUGH_DATA = -4 -} WebPMuxError; - -// IDs for different types of chunks. -typedef enum WebPChunkId { - WEBP_CHUNK_VP8X, // VP8X - WEBP_CHUNK_ICCP, // ICCP - WEBP_CHUNK_ANIM, // ANIM - WEBP_CHUNK_ANMF, // ANMF - WEBP_CHUNK_DEPRECATED, // (deprecated from FRGM) - WEBP_CHUNK_ALPHA, // ALPH - WEBP_CHUNK_IMAGE, // VP8/VP8L - WEBP_CHUNK_EXIF, // EXIF - WEBP_CHUNK_XMP, // XMP - WEBP_CHUNK_UNKNOWN, // Other chunks. - WEBP_CHUNK_NIL -} WebPChunkId; - -//------------------------------------------------------------------------------ - -// Returns the version number of the mux library, packed in hexadecimal using -// 8bits for each of major/minor/revision. E.g: v2.5.7 is 0x020507. -WEBP_EXTERN int WebPGetMuxVersion(void); - -//------------------------------------------------------------------------------ -// Life of a Mux object - -// Internal, version-checked, entry point -WEBP_EXTERN WebPMux* WebPNewInternal(int); - -// Creates an empty mux object. -// Returns: -// A pointer to the newly created empty mux object. -// Or NULL in case of memory error. -static WEBP_INLINE WebPMux* WebPMuxNew(void) { - return WebPNewInternal(WEBP_MUX_ABI_VERSION); -} - -// Deletes the mux object. -// Parameters: -// mux - (in/out) object to be deleted -WEBP_EXTERN void WebPMuxDelete(WebPMux* mux); - -//------------------------------------------------------------------------------ -// Mux creation. - -// Internal, version-checked, entry point -WEBP_EXTERN WebPMux* WebPMuxCreateInternal(const WebPData*, int, int); - -// Creates a mux object from raw data given in WebP RIFF format. -// Parameters: -// bitstream - (in) the bitstream data in WebP RIFF format -// copy_data - (in) value 1 indicates given data WILL be copied to the mux -// object and value 0 indicates data will NOT be copied. -// Returns: -// A pointer to the mux object created from given data - on success. -// NULL - In case of invalid data or memory error. -static WEBP_INLINE WebPMux* WebPMuxCreate(const WebPData* bitstream, - int copy_data) { - return WebPMuxCreateInternal(bitstream, copy_data, WEBP_MUX_ABI_VERSION); -} - -//------------------------------------------------------------------------------ -// Non-image chunks. - -// Note: Only non-image related chunks should be managed through chunk APIs. -// (Image related chunks are: "ANMF", "VP8 ", "VP8L" and "ALPH"). -// To add, get and delete images, use WebPMuxSetImage(), WebPMuxPushFrame(), -// WebPMuxGetFrame() and WebPMuxDeleteFrame(). - -// Adds a chunk with id 'fourcc' and data 'chunk_data' in the mux object. -// Any existing chunk(s) with the same id will be removed. -// Parameters: -// mux - (in/out) object to which the chunk is to be added -// fourcc - (in) a character array containing the fourcc of the given chunk; -// e.g., "ICCP", "XMP ", "EXIF" etc. -// chunk_data - (in) the chunk data to be added -// copy_data - (in) value 1 indicates given data WILL be copied to the mux -// object and value 0 indicates data will NOT be copied. -// Returns: -// WEBP_MUX_INVALID_ARGUMENT - if mux, fourcc or chunk_data is NULL -// or if fourcc corresponds to an image chunk. -// WEBP_MUX_MEMORY_ERROR - on memory allocation error. -// WEBP_MUX_OK - on success. -WEBP_EXTERN WebPMuxError WebPMuxSetChunk( - WebPMux* mux, const char fourcc[4], const WebPData* chunk_data, - int copy_data); - -// Gets a reference to the data of the chunk with id 'fourcc' in the mux object. -// The caller should NOT free the returned data. -// Parameters: -// mux - (in) object from which the chunk data is to be fetched -// fourcc - (in) a character array containing the fourcc of the chunk; -// e.g., "ICCP", "XMP ", "EXIF" etc. -// chunk_data - (out) returned chunk data -// Returns: -// WEBP_MUX_INVALID_ARGUMENT - if mux, fourcc or chunk_data is NULL -// or if fourcc corresponds to an image chunk. -// WEBP_MUX_NOT_FOUND - If mux does not contain a chunk with the given id. -// WEBP_MUX_OK - on success. -WEBP_EXTERN WebPMuxError WebPMuxGetChunk( - const WebPMux* mux, const char fourcc[4], WebPData* chunk_data); - -// Deletes the chunk with the given 'fourcc' from the mux object. -// Parameters: -// mux - (in/out) object from which the chunk is to be deleted -// fourcc - (in) a character array containing the fourcc of the chunk; -// e.g., "ICCP", "XMP ", "EXIF" etc. -// Returns: -// WEBP_MUX_INVALID_ARGUMENT - if mux or fourcc is NULL -// or if fourcc corresponds to an image chunk. -// WEBP_MUX_NOT_FOUND - If mux does not contain a chunk with the given fourcc. -// WEBP_MUX_OK - on success. -WEBP_EXTERN WebPMuxError WebPMuxDeleteChunk( - WebPMux* mux, const char fourcc[4]); - -//------------------------------------------------------------------------------ -// Images. - -// Encapsulates data about a single frame. -struct WebPMuxFrameInfo { - WebPData bitstream; // image data: can be a raw VP8/VP8L bitstream - // or a single-image WebP file. - int x_offset; // x-offset of the frame. - int y_offset; // y-offset of the frame. - int duration; // duration of the frame (in milliseconds). - - WebPChunkId id; // frame type: should be one of WEBP_CHUNK_ANMF - // or WEBP_CHUNK_IMAGE - WebPMuxAnimDispose dispose_method; // Disposal method for the frame. - WebPMuxAnimBlend blend_method; // Blend operation for the frame. - uint32_t pad[1]; // padding for later use -}; - -// Sets the (non-animated) image in the mux object. -// Note: Any existing images (including frames) will be removed. -// Parameters: -// mux - (in/out) object in which the image is to be set -// bitstream - (in) can be a raw VP8/VP8L bitstream or a single-image -// WebP file (non-animated) -// copy_data - (in) value 1 indicates given data WILL be copied to the mux -// object and value 0 indicates data will NOT be copied. -// Returns: -// WEBP_MUX_INVALID_ARGUMENT - if mux is NULL or bitstream is NULL. -// WEBP_MUX_MEMORY_ERROR - on memory allocation error. -// WEBP_MUX_OK - on success. -WEBP_EXTERN WebPMuxError WebPMuxSetImage( - WebPMux* mux, const WebPData* bitstream, int copy_data); - -// Adds a frame at the end of the mux object. -// Notes: (1) frame.id should be WEBP_CHUNK_ANMF -// (2) For setting a non-animated image, use WebPMuxSetImage() instead. -// (3) Type of frame being pushed must be same as the frames in mux. -// (4) As WebP only supports even offsets, any odd offset will be snapped -// to an even location using: offset &= ~1 -// Parameters: -// mux - (in/out) object to which the frame is to be added -// frame - (in) frame data. -// copy_data - (in) value 1 indicates given data WILL be copied to the mux -// object and value 0 indicates data will NOT be copied. -// Returns: -// WEBP_MUX_INVALID_ARGUMENT - if mux or frame is NULL -// or if content of 'frame' is invalid. -// WEBP_MUX_MEMORY_ERROR - on memory allocation error. -// WEBP_MUX_OK - on success. -WEBP_EXTERN WebPMuxError WebPMuxPushFrame( - WebPMux* mux, const WebPMuxFrameInfo* frame, int copy_data); - -// Gets the nth frame from the mux object. -// The content of 'frame->bitstream' is allocated using WebPMalloc(), and NOT -// owned by the 'mux' object. It MUST be deallocated by the caller by calling -// WebPDataClear(). -// nth=0 has a special meaning - last position. -// Parameters: -// mux - (in) object from which the info is to be fetched -// nth - (in) index of the frame in the mux object -// frame - (out) data of the returned frame -// Returns: -// WEBP_MUX_INVALID_ARGUMENT - if mux or frame is NULL. -// WEBP_MUX_NOT_FOUND - if there are less than nth frames in the mux object. -// WEBP_MUX_BAD_DATA - if nth frame chunk in mux is invalid. -// WEBP_MUX_MEMORY_ERROR - on memory allocation error. -// WEBP_MUX_OK - on success. -WEBP_EXTERN WebPMuxError WebPMuxGetFrame( - const WebPMux* mux, uint32_t nth, WebPMuxFrameInfo* frame); - -// Deletes a frame from the mux object. -// nth=0 has a special meaning - last position. -// Parameters: -// mux - (in/out) object from which a frame is to be deleted -// nth - (in) The position from which the frame is to be deleted -// Returns: -// WEBP_MUX_INVALID_ARGUMENT - if mux is NULL. -// WEBP_MUX_NOT_FOUND - If there are less than nth frames in the mux object -// before deletion. -// WEBP_MUX_OK - on success. -WEBP_EXTERN WebPMuxError WebPMuxDeleteFrame(WebPMux* mux, uint32_t nth); - -//------------------------------------------------------------------------------ -// Animation. - -// Animation parameters. -struct WebPMuxAnimParams { - uint32_t bgcolor; // Background color of the canvas stored (in MSB order) as: - // Bits 00 to 07: Alpha. - // Bits 08 to 15: Red. - // Bits 16 to 23: Green. - // Bits 24 to 31: Blue. - int loop_count; // Number of times to repeat the animation [0 = infinite]. -}; - -// Sets the animation parameters in the mux object. Any existing ANIM chunks -// will be removed. -// Parameters: -// mux - (in/out) object in which ANIM chunk is to be set/added -// params - (in) animation parameters. -// Returns: -// WEBP_MUX_INVALID_ARGUMENT - if mux or params is NULL. -// WEBP_MUX_MEMORY_ERROR - on memory allocation error. -// WEBP_MUX_OK - on success. -WEBP_EXTERN WebPMuxError WebPMuxSetAnimationParams( - WebPMux* mux, const WebPMuxAnimParams* params); - -// Gets the animation parameters from the mux object. -// Parameters: -// mux - (in) object from which the animation parameters to be fetched -// params - (out) animation parameters extracted from the ANIM chunk -// Returns: -// WEBP_MUX_INVALID_ARGUMENT - if mux or params is NULL. -// WEBP_MUX_NOT_FOUND - if ANIM chunk is not present in mux object. -// WEBP_MUX_OK - on success. -WEBP_EXTERN WebPMuxError WebPMuxGetAnimationParams( - const WebPMux* mux, WebPMuxAnimParams* params); - -//------------------------------------------------------------------------------ -// Misc Utilities. - -// Sets the canvas size for the mux object. The width and height can be -// specified explicitly or left as zero (0, 0). -// * When width and height are specified explicitly, then this frame bound is -// enforced during subsequent calls to WebPMuxAssemble() and an error is -// reported if any animated frame does not completely fit within the canvas. -// * When unspecified (0, 0), the constructed canvas will get the frame bounds -// from the bounding-box over all frames after calling WebPMuxAssemble(). -// Parameters: -// mux - (in) object to which the canvas size is to be set -// width - (in) canvas width -// height - (in) canvas height -// Returns: -// WEBP_MUX_INVALID_ARGUMENT - if mux is NULL; or -// width or height are invalid or out of bounds -// WEBP_MUX_OK - on success. -WEBP_EXTERN WebPMuxError WebPMuxSetCanvasSize(WebPMux* mux, - int width, int height); - -// Gets the canvas size from the mux object. -// Note: This method assumes that the VP8X chunk, if present, is up-to-date. -// That is, the mux object hasn't been modified since the last call to -// WebPMuxAssemble() or WebPMuxCreate(). -// Parameters: -// mux - (in) object from which the canvas size is to be fetched -// width - (out) canvas width -// height - (out) canvas height -// Returns: -// WEBP_MUX_INVALID_ARGUMENT - if mux, width or height is NULL. -// WEBP_MUX_BAD_DATA - if VP8X/VP8/VP8L chunk or canvas size is invalid. -// WEBP_MUX_OK - on success. -WEBP_EXTERN WebPMuxError WebPMuxGetCanvasSize(const WebPMux* mux, - int* width, int* height); - -// Gets the feature flags from the mux object. -// Note: This method assumes that the VP8X chunk, if present, is up-to-date. -// That is, the mux object hasn't been modified since the last call to -// WebPMuxAssemble() or WebPMuxCreate(). -// Parameters: -// mux - (in) object from which the features are to be fetched -// flags - (out) the flags specifying which features are present in the -// mux object. This will be an OR of various flag values. -// Enum 'WebPFeatureFlags' can be used to test individual flag values. -// Returns: -// WEBP_MUX_INVALID_ARGUMENT - if mux or flags is NULL. -// WEBP_MUX_BAD_DATA - if VP8X/VP8/VP8L chunk or canvas size is invalid. -// WEBP_MUX_OK - on success. -WEBP_EXTERN WebPMuxError WebPMuxGetFeatures(const WebPMux* mux, - uint32_t* flags); - -// Gets number of chunks with the given 'id' in the mux object. -// Parameters: -// mux - (in) object from which the info is to be fetched -// id - (in) chunk id specifying the type of chunk -// num_elements - (out) number of chunks with the given chunk id -// Returns: -// WEBP_MUX_INVALID_ARGUMENT - if mux, or num_elements is NULL. -// WEBP_MUX_OK - on success. -WEBP_EXTERN WebPMuxError WebPMuxNumChunks(const WebPMux* mux, - WebPChunkId id, int* num_elements); - -// Assembles all chunks in WebP RIFF format and returns in 'assembled_data'. -// This function also validates the mux object. -// Note: The content of 'assembled_data' will be ignored and overwritten. -// Also, the content of 'assembled_data' is allocated using WebPMalloc(), and -// NOT owned by the 'mux' object. It MUST be deallocated by the caller by -// calling WebPDataClear(). It's always safe to call WebPDataClear() upon -// return, even in case of error. -// Parameters: -// mux - (in/out) object whose chunks are to be assembled -// assembled_data - (out) assembled WebP data -// Returns: -// WEBP_MUX_BAD_DATA - if mux object is invalid. -// WEBP_MUX_INVALID_ARGUMENT - if mux or assembled_data is NULL. -// WEBP_MUX_MEMORY_ERROR - on memory allocation error. -// WEBP_MUX_OK - on success. -WEBP_EXTERN WebPMuxError WebPMuxAssemble(WebPMux* mux, - WebPData* assembled_data); - -//------------------------------------------------------------------------------ -// WebPAnimEncoder API -// -// This API allows encoding (possibly) animated WebP images. -// -// Code Example: -/* - WebPAnimEncoderOptions enc_options; - WebPAnimEncoderOptionsInit(&enc_options); - // Tune 'enc_options' as needed. - WebPAnimEncoder* enc = WebPAnimEncoderNew(width, height, &enc_options); - while() { - WebPConfig config; - WebPConfigInit(&config); - // Tune 'config' as needed. - WebPAnimEncoderAdd(enc, frame, timestamp_ms, &config); - } - WebPAnimEncoderAdd(enc, NULL, timestamp_ms, NULL); - WebPAnimEncoderAssemble(enc, webp_data); - WebPAnimEncoderDelete(enc); - // Write the 'webp_data' to a file, or re-mux it further. -*/ - -typedef struct WebPAnimEncoder WebPAnimEncoder; // Main opaque object. - -// Forward declarations. Defined in encode.h. -struct WebPPicture; -struct WebPConfig; - -// Global options. -struct WebPAnimEncoderOptions { - WebPMuxAnimParams anim_params; // Animation parameters. - int minimize_size; // If true, minimize the output size (slow). Implicitly - // disables key-frame insertion. - int kmin; - int kmax; // Minimum and maximum distance between consecutive key - // frames in the output. The library may insert some key - // frames as needed to satisfy this criteria. - // Note that these conditions should hold: kmax > kmin - // and kmin >= kmax / 2 + 1. Also, if kmax <= 0, then - // key-frame insertion is disabled; and if kmax == 1, - // then all frames will be key-frames (kmin value does - // not matter for these special cases). - int allow_mixed; // If true, use mixed compression mode; may choose - // either lossy and lossless for each frame. - int verbose; // If true, print info and warning messages to stderr. - - uint32_t padding[4]; // Padding for later use. -}; - -// Internal, version-checked, entry point. -WEBP_EXTERN int WebPAnimEncoderOptionsInitInternal( - WebPAnimEncoderOptions*, int); - -// Should always be called, to initialize a fresh WebPAnimEncoderOptions -// structure before modification. Returns false in case of version mismatch. -// WebPAnimEncoderOptionsInit() must have succeeded before using the -// 'enc_options' object. -static WEBP_INLINE int WebPAnimEncoderOptionsInit( - WebPAnimEncoderOptions* enc_options) { - return WebPAnimEncoderOptionsInitInternal(enc_options, WEBP_MUX_ABI_VERSION); -} - -// Internal, version-checked, entry point. -WEBP_EXTERN WebPAnimEncoder* WebPAnimEncoderNewInternal( - int, int, const WebPAnimEncoderOptions*, int); - -// Creates and initializes a WebPAnimEncoder object. -// Parameters: -// width/height - (in) canvas width and height of the animation. -// enc_options - (in) encoding options; can be passed NULL to pick -// reasonable defaults. -// Returns: -// A pointer to the newly created WebPAnimEncoder object. -// Or NULL in case of memory error. -static WEBP_INLINE WebPAnimEncoder* WebPAnimEncoderNew( - int width, int height, const WebPAnimEncoderOptions* enc_options) { - return WebPAnimEncoderNewInternal(width, height, enc_options, - WEBP_MUX_ABI_VERSION); -} - -// Optimize the given frame for WebP, encode it and add it to the -// WebPAnimEncoder object. -// The last call to 'WebPAnimEncoderAdd' should be with frame = NULL, which -// indicates that no more frames are to be added. This call is also used to -// determine the duration of the last frame. -// Parameters: -// enc - (in/out) object to which the frame is to be added. -// frame - (in/out) frame data in ARGB or YUV(A) format. If it is in YUV(A) -// format, it will be converted to ARGB, which incurs a small loss. -// timestamp_ms - (in) timestamp of this frame in milliseconds. -// Duration of a frame would be calculated as -// "timestamp of next frame - timestamp of this frame". -// Hence, timestamps should be in non-decreasing order. -// config - (in) encoding options; can be passed NULL to pick -// reasonable defaults. -// Returns: -// On error, returns false and frame->error_code is set appropriately. -// Otherwise, returns true. -WEBP_EXTERN int WebPAnimEncoderAdd( - WebPAnimEncoder* enc, struct WebPPicture* frame, int timestamp_ms, - const struct WebPConfig* config); - -// Assemble all frames added so far into a WebP bitstream. -// This call should be preceded by a call to 'WebPAnimEncoderAdd' with -// frame = NULL; if not, the duration of the last frame will be internally -// estimated. -// Parameters: -// enc - (in/out) object from which the frames are to be assembled. -// webp_data - (out) generated WebP bitstream. -// Returns: -// True on success. -WEBP_EXTERN int WebPAnimEncoderAssemble(WebPAnimEncoder* enc, - WebPData* webp_data); - -// Get error string corresponding to the most recent call using 'enc'. The -// returned string is owned by 'enc' and is valid only until the next call to -// WebPAnimEncoderAdd() or WebPAnimEncoderAssemble() or WebPAnimEncoderDelete(). -// Parameters: -// enc - (in/out) object from which the error string is to be fetched. -// Returns: -// NULL if 'enc' is NULL. Otherwise, returns the error string if the last call -// to 'enc' had an error, or an empty string if the last call was a success. -WEBP_EXTERN const char* WebPAnimEncoderGetError(WebPAnimEncoder* enc); - -// Deletes the WebPAnimEncoder object. -// Parameters: -// enc - (in/out) object to be deleted -WEBP_EXTERN void WebPAnimEncoderDelete(WebPAnimEncoder* enc); - -//------------------------------------------------------------------------------ - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // WEBP_WEBP_MUX_H_ +// Copyright 2011 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// RIFF container manipulation and encoding for WebP images. +// +// Authors: Urvang (urvang@google.com) +// Vikas (vikasa@google.com) + +#ifndef WEBP_WEBP_MUX_H_ +#define WEBP_WEBP_MUX_H_ + +#include "./mux_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define WEBP_MUX_ABI_VERSION 0x0108 // MAJOR(8b) + MINOR(8b) + +//------------------------------------------------------------------------------ +// Mux API +// +// This API allows manipulation of WebP container images containing features +// like color profile, metadata, animation. +// +// Code Example#1: Create a WebPMux object with image data, color profile and +// XMP metadata. +/* + int copy_data = 0; + WebPMux* mux = WebPMuxNew(); + // ... (Prepare image data). + WebPMuxSetImage(mux, &image, copy_data); + // ... (Prepare ICCP color profile data). + WebPMuxSetChunk(mux, "ICCP", &icc_profile, copy_data); + // ... (Prepare XMP metadata). + WebPMuxSetChunk(mux, "XMP ", &xmp, copy_data); + // Get data from mux in WebP RIFF format. + WebPMuxAssemble(mux, &output_data); + WebPMuxDelete(mux); + // ... (Consume output_data; e.g. write output_data.bytes to file). + WebPDataClear(&output_data); +*/ + +// Code Example#2: Get image and color profile data from a WebP file. +/* + int copy_data = 0; + // ... (Read data from file). + WebPMux* mux = WebPMuxCreate(&data, copy_data); + WebPMuxGetFrame(mux, 1, &image); + // ... (Consume image; e.g. call WebPDecode() to decode the data). + WebPMuxGetChunk(mux, "ICCP", &icc_profile); + // ... (Consume icc_data). + WebPMuxDelete(mux); + WebPFree(data); +*/ + +// Note: forward declaring enumerations is not allowed in (strict) C and C++, +// the types are left here for reference. +// typedef enum WebPMuxError WebPMuxError; +// typedef enum WebPChunkId WebPChunkId; +typedef struct WebPMux WebPMux; // main opaque object. +typedef struct WebPMuxFrameInfo WebPMuxFrameInfo; +typedef struct WebPMuxAnimParams WebPMuxAnimParams; +typedef struct WebPAnimEncoderOptions WebPAnimEncoderOptions; + +// Error codes +typedef enum WebPMuxError { + WEBP_MUX_OK = 1, + WEBP_MUX_NOT_FOUND = 0, + WEBP_MUX_INVALID_ARGUMENT = -1, + WEBP_MUX_BAD_DATA = -2, + WEBP_MUX_MEMORY_ERROR = -3, + WEBP_MUX_NOT_ENOUGH_DATA = -4 +} WebPMuxError; + +// IDs for different types of chunks. +typedef enum WebPChunkId { + WEBP_CHUNK_VP8X, // VP8X + WEBP_CHUNK_ICCP, // ICCP + WEBP_CHUNK_ANIM, // ANIM + WEBP_CHUNK_ANMF, // ANMF + WEBP_CHUNK_DEPRECATED, // (deprecated from FRGM) + WEBP_CHUNK_ALPHA, // ALPH + WEBP_CHUNK_IMAGE, // VP8/VP8L + WEBP_CHUNK_EXIF, // EXIF + WEBP_CHUNK_XMP, // XMP + WEBP_CHUNK_UNKNOWN, // Other chunks. + WEBP_CHUNK_NIL +} WebPChunkId; + +//------------------------------------------------------------------------------ + +// Returns the version number of the mux library, packed in hexadecimal using +// 8bits for each of major/minor/revision. E.g: v2.5.7 is 0x020507. +WEBP_EXTERN int WebPGetMuxVersion(void); + +//------------------------------------------------------------------------------ +// Life of a Mux object + +// Internal, version-checked, entry point +WEBP_EXTERN WebPMux* WebPNewInternal(int); + +// Creates an empty mux object. +// Returns: +// A pointer to the newly created empty mux object. +// Or NULL in case of memory error. +static WEBP_INLINE WebPMux* WebPMuxNew(void) { + return WebPNewInternal(WEBP_MUX_ABI_VERSION); +} + +// Deletes the mux object. +// Parameters: +// mux - (in/out) object to be deleted +WEBP_EXTERN void WebPMuxDelete(WebPMux* mux); + +//------------------------------------------------------------------------------ +// Mux creation. + +// Internal, version-checked, entry point +WEBP_EXTERN WebPMux* WebPMuxCreateInternal(const WebPData*, int, int); + +// Creates a mux object from raw data given in WebP RIFF format. +// Parameters: +// bitstream - (in) the bitstream data in WebP RIFF format +// copy_data - (in) value 1 indicates given data WILL be copied to the mux +// object and value 0 indicates data will NOT be copied. +// Returns: +// A pointer to the mux object created from given data - on success. +// NULL - In case of invalid data or memory error. +static WEBP_INLINE WebPMux* WebPMuxCreate(const WebPData* bitstream, + int copy_data) { + return WebPMuxCreateInternal(bitstream, copy_data, WEBP_MUX_ABI_VERSION); +} + +//------------------------------------------------------------------------------ +// Non-image chunks. + +// Note: Only non-image related chunks should be managed through chunk APIs. +// (Image related chunks are: "ANMF", "VP8 ", "VP8L" and "ALPH"). +// To add, get and delete images, use WebPMuxSetImage(), WebPMuxPushFrame(), +// WebPMuxGetFrame() and WebPMuxDeleteFrame(). + +// Adds a chunk with id 'fourcc' and data 'chunk_data' in the mux object. +// Any existing chunk(s) with the same id will be removed. +// Parameters: +// mux - (in/out) object to which the chunk is to be added +// fourcc - (in) a character array containing the fourcc of the given chunk; +// e.g., "ICCP", "XMP ", "EXIF" etc. +// chunk_data - (in) the chunk data to be added +// copy_data - (in) value 1 indicates given data WILL be copied to the mux +// object and value 0 indicates data will NOT be copied. +// Returns: +// WEBP_MUX_INVALID_ARGUMENT - if mux, fourcc or chunk_data is NULL +// or if fourcc corresponds to an image chunk. +// WEBP_MUX_MEMORY_ERROR - on memory allocation error. +// WEBP_MUX_OK - on success. +WEBP_EXTERN WebPMuxError WebPMuxSetChunk( + WebPMux* mux, const char fourcc[4], const WebPData* chunk_data, + int copy_data); + +// Gets a reference to the data of the chunk with id 'fourcc' in the mux object. +// The caller should NOT free the returned data. +// Parameters: +// mux - (in) object from which the chunk data is to be fetched +// fourcc - (in) a character array containing the fourcc of the chunk; +// e.g., "ICCP", "XMP ", "EXIF" etc. +// chunk_data - (out) returned chunk data +// Returns: +// WEBP_MUX_INVALID_ARGUMENT - if mux, fourcc or chunk_data is NULL +// or if fourcc corresponds to an image chunk. +// WEBP_MUX_NOT_FOUND - If mux does not contain a chunk with the given id. +// WEBP_MUX_OK - on success. +WEBP_EXTERN WebPMuxError WebPMuxGetChunk( + const WebPMux* mux, const char fourcc[4], WebPData* chunk_data); + +// Deletes the chunk with the given 'fourcc' from the mux object. +// Parameters: +// mux - (in/out) object from which the chunk is to be deleted +// fourcc - (in) a character array containing the fourcc of the chunk; +// e.g., "ICCP", "XMP ", "EXIF" etc. +// Returns: +// WEBP_MUX_INVALID_ARGUMENT - if mux or fourcc is NULL +// or if fourcc corresponds to an image chunk. +// WEBP_MUX_NOT_FOUND - If mux does not contain a chunk with the given fourcc. +// WEBP_MUX_OK - on success. +WEBP_EXTERN WebPMuxError WebPMuxDeleteChunk( + WebPMux* mux, const char fourcc[4]); + +//------------------------------------------------------------------------------ +// Images. + +// Encapsulates data about a single frame. +struct WebPMuxFrameInfo { + WebPData bitstream; // image data: can be a raw VP8/VP8L bitstream + // or a single-image WebP file. + int x_offset; // x-offset of the frame. + int y_offset; // y-offset of the frame. + int duration; // duration of the frame (in milliseconds). + + WebPChunkId id; // frame type: should be one of WEBP_CHUNK_ANMF + // or WEBP_CHUNK_IMAGE + WebPMuxAnimDispose dispose_method; // Disposal method for the frame. + WebPMuxAnimBlend blend_method; // Blend operation for the frame. + uint32_t pad[1]; // padding for later use +}; + +// Sets the (non-animated) image in the mux object. +// Note: Any existing images (including frames) will be removed. +// Parameters: +// mux - (in/out) object in which the image is to be set +// bitstream - (in) can be a raw VP8/VP8L bitstream or a single-image +// WebP file (non-animated) +// copy_data - (in) value 1 indicates given data WILL be copied to the mux +// object and value 0 indicates data will NOT be copied. +// Returns: +// WEBP_MUX_INVALID_ARGUMENT - if mux is NULL or bitstream is NULL. +// WEBP_MUX_MEMORY_ERROR - on memory allocation error. +// WEBP_MUX_OK - on success. +WEBP_EXTERN WebPMuxError WebPMuxSetImage( + WebPMux* mux, const WebPData* bitstream, int copy_data); + +// Adds a frame at the end of the mux object. +// Notes: (1) frame.id should be WEBP_CHUNK_ANMF +// (2) For setting a non-animated image, use WebPMuxSetImage() instead. +// (3) Type of frame being pushed must be same as the frames in mux. +// (4) As WebP only supports even offsets, any odd offset will be snapped +// to an even location using: offset &= ~1 +// Parameters: +// mux - (in/out) object to which the frame is to be added +// frame - (in) frame data. +// copy_data - (in) value 1 indicates given data WILL be copied to the mux +// object and value 0 indicates data will NOT be copied. +// Returns: +// WEBP_MUX_INVALID_ARGUMENT - if mux or frame is NULL +// or if content of 'frame' is invalid. +// WEBP_MUX_MEMORY_ERROR - on memory allocation error. +// WEBP_MUX_OK - on success. +WEBP_EXTERN WebPMuxError WebPMuxPushFrame( + WebPMux* mux, const WebPMuxFrameInfo* frame, int copy_data); + +// Gets the nth frame from the mux object. +// The content of 'frame->bitstream' is allocated using WebPMalloc(), and NOT +// owned by the 'mux' object. It MUST be deallocated by the caller by calling +// WebPDataClear(). +// nth=0 has a special meaning - last position. +// Parameters: +// mux - (in) object from which the info is to be fetched +// nth - (in) index of the frame in the mux object +// frame - (out) data of the returned frame +// Returns: +// WEBP_MUX_INVALID_ARGUMENT - if mux or frame is NULL. +// WEBP_MUX_NOT_FOUND - if there are less than nth frames in the mux object. +// WEBP_MUX_BAD_DATA - if nth frame chunk in mux is invalid. +// WEBP_MUX_MEMORY_ERROR - on memory allocation error. +// WEBP_MUX_OK - on success. +WEBP_EXTERN WebPMuxError WebPMuxGetFrame( + const WebPMux* mux, uint32_t nth, WebPMuxFrameInfo* frame); + +// Deletes a frame from the mux object. +// nth=0 has a special meaning - last position. +// Parameters: +// mux - (in/out) object from which a frame is to be deleted +// nth - (in) The position from which the frame is to be deleted +// Returns: +// WEBP_MUX_INVALID_ARGUMENT - if mux is NULL. +// WEBP_MUX_NOT_FOUND - If there are less than nth frames in the mux object +// before deletion. +// WEBP_MUX_OK - on success. +WEBP_EXTERN WebPMuxError WebPMuxDeleteFrame(WebPMux* mux, uint32_t nth); + +//------------------------------------------------------------------------------ +// Animation. + +// Animation parameters. +struct WebPMuxAnimParams { + uint32_t bgcolor; // Background color of the canvas stored (in MSB order) as: + // Bits 00 to 07: Alpha. + // Bits 08 to 15: Red. + // Bits 16 to 23: Green. + // Bits 24 to 31: Blue. + int loop_count; // Number of times to repeat the animation [0 = infinite]. +}; + +// Sets the animation parameters in the mux object. Any existing ANIM chunks +// will be removed. +// Parameters: +// mux - (in/out) object in which ANIM chunk is to be set/added +// params - (in) animation parameters. +// Returns: +// WEBP_MUX_INVALID_ARGUMENT - if mux or params is NULL. +// WEBP_MUX_MEMORY_ERROR - on memory allocation error. +// WEBP_MUX_OK - on success. +WEBP_EXTERN WebPMuxError WebPMuxSetAnimationParams( + WebPMux* mux, const WebPMuxAnimParams* params); + +// Gets the animation parameters from the mux object. +// Parameters: +// mux - (in) object from which the animation parameters to be fetched +// params - (out) animation parameters extracted from the ANIM chunk +// Returns: +// WEBP_MUX_INVALID_ARGUMENT - if mux or params is NULL. +// WEBP_MUX_NOT_FOUND - if ANIM chunk is not present in mux object. +// WEBP_MUX_OK - on success. +WEBP_EXTERN WebPMuxError WebPMuxGetAnimationParams( + const WebPMux* mux, WebPMuxAnimParams* params); + +//------------------------------------------------------------------------------ +// Misc Utilities. + +// Sets the canvas size for the mux object. The width and height can be +// specified explicitly or left as zero (0, 0). +// * When width and height are specified explicitly, then this frame bound is +// enforced during subsequent calls to WebPMuxAssemble() and an error is +// reported if any animated frame does not completely fit within the canvas. +// * When unspecified (0, 0), the constructed canvas will get the frame bounds +// from the bounding-box over all frames after calling WebPMuxAssemble(). +// Parameters: +// mux - (in) object to which the canvas size is to be set +// width - (in) canvas width +// height - (in) canvas height +// Returns: +// WEBP_MUX_INVALID_ARGUMENT - if mux is NULL; or +// width or height are invalid or out of bounds +// WEBP_MUX_OK - on success. +WEBP_EXTERN WebPMuxError WebPMuxSetCanvasSize(WebPMux* mux, + int width, int height); + +// Gets the canvas size from the mux object. +// Note: This method assumes that the VP8X chunk, if present, is up-to-date. +// That is, the mux object hasn't been modified since the last call to +// WebPMuxAssemble() or WebPMuxCreate(). +// Parameters: +// mux - (in) object from which the canvas size is to be fetched +// width - (out) canvas width +// height - (out) canvas height +// Returns: +// WEBP_MUX_INVALID_ARGUMENT - if mux, width or height is NULL. +// WEBP_MUX_BAD_DATA - if VP8X/VP8/VP8L chunk or canvas size is invalid. +// WEBP_MUX_OK - on success. +WEBP_EXTERN WebPMuxError WebPMuxGetCanvasSize(const WebPMux* mux, + int* width, int* height); + +// Gets the feature flags from the mux object. +// Note: This method assumes that the VP8X chunk, if present, is up-to-date. +// That is, the mux object hasn't been modified since the last call to +// WebPMuxAssemble() or WebPMuxCreate(). +// Parameters: +// mux - (in) object from which the features are to be fetched +// flags - (out) the flags specifying which features are present in the +// mux object. This will be an OR of various flag values. +// Enum 'WebPFeatureFlags' can be used to test individual flag values. +// Returns: +// WEBP_MUX_INVALID_ARGUMENT - if mux or flags is NULL. +// WEBP_MUX_BAD_DATA - if VP8X/VP8/VP8L chunk or canvas size is invalid. +// WEBP_MUX_OK - on success. +WEBP_EXTERN WebPMuxError WebPMuxGetFeatures(const WebPMux* mux, + uint32_t* flags); + +// Gets number of chunks with the given 'id' in the mux object. +// Parameters: +// mux - (in) object from which the info is to be fetched +// id - (in) chunk id specifying the type of chunk +// num_elements - (out) number of chunks with the given chunk id +// Returns: +// WEBP_MUX_INVALID_ARGUMENT - if mux, or num_elements is NULL. +// WEBP_MUX_OK - on success. +WEBP_EXTERN WebPMuxError WebPMuxNumChunks(const WebPMux* mux, + WebPChunkId id, int* num_elements); + +// Assembles all chunks in WebP RIFF format and returns in 'assembled_data'. +// This function also validates the mux object. +// Note: The content of 'assembled_data' will be ignored and overwritten. +// Also, the content of 'assembled_data' is allocated using WebPMalloc(), and +// NOT owned by the 'mux' object. It MUST be deallocated by the caller by +// calling WebPDataClear(). It's always safe to call WebPDataClear() upon +// return, even in case of error. +// Parameters: +// mux - (in/out) object whose chunks are to be assembled +// assembled_data - (out) assembled WebP data +// Returns: +// WEBP_MUX_BAD_DATA - if mux object is invalid. +// WEBP_MUX_INVALID_ARGUMENT - if mux or assembled_data is NULL. +// WEBP_MUX_MEMORY_ERROR - on memory allocation error. +// WEBP_MUX_OK - on success. +WEBP_EXTERN WebPMuxError WebPMuxAssemble(WebPMux* mux, + WebPData* assembled_data); + +//------------------------------------------------------------------------------ +// WebPAnimEncoder API +// +// This API allows encoding (possibly) animated WebP images. +// +// Code Example: +/* + WebPAnimEncoderOptions enc_options; + WebPAnimEncoderOptionsInit(&enc_options); + // Tune 'enc_options' as needed. + WebPAnimEncoder* enc = WebPAnimEncoderNew(width, height, &enc_options); + while() { + WebPConfig config; + WebPConfigInit(&config); + // Tune 'config' as needed. + WebPAnimEncoderAdd(enc, frame, timestamp_ms, &config); + } + WebPAnimEncoderAdd(enc, NULL, timestamp_ms, NULL); + WebPAnimEncoderAssemble(enc, webp_data); + WebPAnimEncoderDelete(enc); + // Write the 'webp_data' to a file, or re-mux it further. +*/ + +typedef struct WebPAnimEncoder WebPAnimEncoder; // Main opaque object. + +// Forward declarations. Defined in encode.h. +struct WebPPicture; +struct WebPConfig; + +// Global options. +struct WebPAnimEncoderOptions { + WebPMuxAnimParams anim_params; // Animation parameters. + int minimize_size; // If true, minimize the output size (slow). Implicitly + // disables key-frame insertion. + int kmin; + int kmax; // Minimum and maximum distance between consecutive key + // frames in the output. The library may insert some key + // frames as needed to satisfy this criteria. + // Note that these conditions should hold: kmax > kmin + // and kmin >= kmax / 2 + 1. Also, if kmax <= 0, then + // key-frame insertion is disabled; and if kmax == 1, + // then all frames will be key-frames (kmin value does + // not matter for these special cases). + int allow_mixed; // If true, use mixed compression mode; may choose + // either lossy and lossless for each frame. + int verbose; // If true, print info and warning messages to stderr. + + uint32_t padding[4]; // Padding for later use. +}; + +// Internal, version-checked, entry point. +WEBP_EXTERN int WebPAnimEncoderOptionsInitInternal( + WebPAnimEncoderOptions*, int); + +// Should always be called, to initialize a fresh WebPAnimEncoderOptions +// structure before modification. Returns false in case of version mismatch. +// WebPAnimEncoderOptionsInit() must have succeeded before using the +// 'enc_options' object. +static WEBP_INLINE int WebPAnimEncoderOptionsInit( + WebPAnimEncoderOptions* enc_options) { + return WebPAnimEncoderOptionsInitInternal(enc_options, WEBP_MUX_ABI_VERSION); +} + +// Internal, version-checked, entry point. +WEBP_EXTERN WebPAnimEncoder* WebPAnimEncoderNewInternal( + int, int, const WebPAnimEncoderOptions*, int); + +// Creates and initializes a WebPAnimEncoder object. +// Parameters: +// width/height - (in) canvas width and height of the animation. +// enc_options - (in) encoding options; can be passed NULL to pick +// reasonable defaults. +// Returns: +// A pointer to the newly created WebPAnimEncoder object. +// Or NULL in case of memory error. +static WEBP_INLINE WebPAnimEncoder* WebPAnimEncoderNew( + int width, int height, const WebPAnimEncoderOptions* enc_options) { + return WebPAnimEncoderNewInternal(width, height, enc_options, + WEBP_MUX_ABI_VERSION); +} + +// Optimize the given frame for WebP, encode it and add it to the +// WebPAnimEncoder object. +// The last call to 'WebPAnimEncoderAdd' should be with frame = NULL, which +// indicates that no more frames are to be added. This call is also used to +// determine the duration of the last frame. +// Parameters: +// enc - (in/out) object to which the frame is to be added. +// frame - (in/out) frame data in ARGB or YUV(A) format. If it is in YUV(A) +// format, it will be converted to ARGB, which incurs a small loss. +// timestamp_ms - (in) timestamp of this frame in milliseconds. +// Duration of a frame would be calculated as +// "timestamp of next frame - timestamp of this frame". +// Hence, timestamps should be in non-decreasing order. +// config - (in) encoding options; can be passed NULL to pick +// reasonable defaults. +// Returns: +// On error, returns false and frame->error_code is set appropriately. +// Otherwise, returns true. +WEBP_EXTERN int WebPAnimEncoderAdd( + WebPAnimEncoder* enc, struct WebPPicture* frame, int timestamp_ms, + const struct WebPConfig* config); + +// Assemble all frames added so far into a WebP bitstream. +// This call should be preceded by a call to 'WebPAnimEncoderAdd' with +// frame = NULL; if not, the duration of the last frame will be internally +// estimated. +// Parameters: +// enc - (in/out) object from which the frames are to be assembled. +// webp_data - (out) generated WebP bitstream. +// Returns: +// True on success. +WEBP_EXTERN int WebPAnimEncoderAssemble(WebPAnimEncoder* enc, + WebPData* webp_data); + +// Get error string corresponding to the most recent call using 'enc'. The +// returned string is owned by 'enc' and is valid only until the next call to +// WebPAnimEncoderAdd() or WebPAnimEncoderAssemble() or WebPAnimEncoderDelete(). +// Parameters: +// enc - (in/out) object from which the error string is to be fetched. +// Returns: +// NULL if 'enc' is NULL. Otherwise, returns the error string if the last call +// to 'enc' had an error, or an empty string if the last call was a success. +WEBP_EXTERN const char* WebPAnimEncoderGetError(WebPAnimEncoder* enc); + +// Deletes the WebPAnimEncoder object. +// Parameters: +// enc - (in/out) object to be deleted +WEBP_EXTERN void WebPAnimEncoderDelete(WebPAnimEncoder* enc); + +//------------------------------------------------------------------------------ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // WEBP_WEBP_MUX_H_ diff --git a/src/JPEGView/libwebp/include/webp/mux_types.h b/src/JPEGView/libwebp/include/webp/mux_types.h index 242ee6f5..2fe81958 100644 --- a/src/JPEGView/libwebp/include/webp/mux_types.h +++ b/src/JPEGView/libwebp/include/webp/mux_types.h @@ -1,98 +1,98 @@ -// Copyright 2012 Google Inc. All Rights Reserved. -// -// Use of this source code is governed by a BSD-style license -// that can be found in the COPYING file in the root of the source -// tree. An additional intellectual property rights grant can be found -// in the file PATENTS. All contributing project authors may -// be found in the AUTHORS file in the root of the source tree. -// ----------------------------------------------------------------------------- -// -// Data-types common to the mux and demux libraries. -// -// Author: Urvang (urvang@google.com) - -#ifndef WEBP_WEBP_MUX_TYPES_H_ -#define WEBP_WEBP_MUX_TYPES_H_ - -#include // memset() -#include "./types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// Note: forward declaring enumerations is not allowed in (strict) C and C++, -// the types are left here for reference. -// typedef enum WebPFeatureFlags WebPFeatureFlags; -// typedef enum WebPMuxAnimDispose WebPMuxAnimDispose; -// typedef enum WebPMuxAnimBlend WebPMuxAnimBlend; -typedef struct WebPData WebPData; - -// VP8X Feature Flags. -typedef enum WebPFeatureFlags { - ANIMATION_FLAG = 0x00000002, - XMP_FLAG = 0x00000004, - EXIF_FLAG = 0x00000008, - ALPHA_FLAG = 0x00000010, - ICCP_FLAG = 0x00000020, - - ALL_VALID_FLAGS = 0x0000003e -} WebPFeatureFlags; - -// Dispose method (animation only). Indicates how the area used by the current -// frame is to be treated before rendering the next frame on the canvas. -typedef enum WebPMuxAnimDispose { - WEBP_MUX_DISPOSE_NONE, // Do not dispose. - WEBP_MUX_DISPOSE_BACKGROUND // Dispose to background color. -} WebPMuxAnimDispose; - -// Blend operation (animation only). Indicates how transparent pixels of the -// current frame are blended with those of the previous canvas. -typedef enum WebPMuxAnimBlend { - WEBP_MUX_BLEND, // Blend. - WEBP_MUX_NO_BLEND // Do not blend. -} WebPMuxAnimBlend; - -// Data type used to describe 'raw' data, e.g., chunk data -// (ICC profile, metadata) and WebP compressed image data. -// 'bytes' memory must be allocated using WebPMalloc() and such. -struct WebPData { - const uint8_t* bytes; - size_t size; -}; - -// Initializes the contents of the 'webp_data' object with default values. -static WEBP_INLINE void WebPDataInit(WebPData* webp_data) { - if (webp_data != NULL) { - memset(webp_data, 0, sizeof(*webp_data)); - } -} - -// Clears the contents of the 'webp_data' object by calling WebPFree(). -// Does not deallocate the object itself. -static WEBP_INLINE void WebPDataClear(WebPData* webp_data) { - if (webp_data != NULL) { - WebPFree((void*)webp_data->bytes); - WebPDataInit(webp_data); - } -} - -// Allocates necessary storage for 'dst' and copies the contents of 'src'. -// Returns true on success. -static WEBP_INLINE int WebPDataCopy(const WebPData* src, WebPData* dst) { - if (src == NULL || dst == NULL) return 0; - WebPDataInit(dst); - if (src->bytes != NULL && src->size != 0) { - dst->bytes = (uint8_t*)WebPMalloc(src->size); - if (dst->bytes == NULL) return 0; - memcpy((void*)dst->bytes, src->bytes, src->size); - dst->size = src->size; - } - return 1; -} - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // WEBP_WEBP_MUX_TYPES_H_ +// Copyright 2012 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Data-types common to the mux and demux libraries. +// +// Author: Urvang (urvang@google.com) + +#ifndef WEBP_WEBP_MUX_TYPES_H_ +#define WEBP_WEBP_MUX_TYPES_H_ + +#include // memset() +#include "./types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// Note: forward declaring enumerations is not allowed in (strict) C and C++, +// the types are left here for reference. +// typedef enum WebPFeatureFlags WebPFeatureFlags; +// typedef enum WebPMuxAnimDispose WebPMuxAnimDispose; +// typedef enum WebPMuxAnimBlend WebPMuxAnimBlend; +typedef struct WebPData WebPData; + +// VP8X Feature Flags. +typedef enum WebPFeatureFlags { + ANIMATION_FLAG = 0x00000002, + XMP_FLAG = 0x00000004, + EXIF_FLAG = 0x00000008, + ALPHA_FLAG = 0x00000010, + ICCP_FLAG = 0x00000020, + + ALL_VALID_FLAGS = 0x0000003e +} WebPFeatureFlags; + +// Dispose method (animation only). Indicates how the area used by the current +// frame is to be treated before rendering the next frame on the canvas. +typedef enum WebPMuxAnimDispose { + WEBP_MUX_DISPOSE_NONE, // Do not dispose. + WEBP_MUX_DISPOSE_BACKGROUND // Dispose to background color. +} WebPMuxAnimDispose; + +// Blend operation (animation only). Indicates how transparent pixels of the +// current frame are blended with those of the previous canvas. +typedef enum WebPMuxAnimBlend { + WEBP_MUX_BLEND, // Blend. + WEBP_MUX_NO_BLEND // Do not blend. +} WebPMuxAnimBlend; + +// Data type used to describe 'raw' data, e.g., chunk data +// (ICC profile, metadata) and WebP compressed image data. +// 'bytes' memory must be allocated using WebPMalloc() and such. +struct WebPData { + const uint8_t* bytes; + size_t size; +}; + +// Initializes the contents of the 'webp_data' object with default values. +static WEBP_INLINE void WebPDataInit(WebPData* webp_data) { + if (webp_data != NULL) { + memset(webp_data, 0, sizeof(*webp_data)); + } +} + +// Clears the contents of the 'webp_data' object by calling WebPFree(). +// Does not deallocate the object itself. +static WEBP_INLINE void WebPDataClear(WebPData* webp_data) { + if (webp_data != NULL) { + WebPFree((void*)webp_data->bytes); + WebPDataInit(webp_data); + } +} + +// Allocates necessary storage for 'dst' and copies the contents of 'src'. +// Returns true on success. +static WEBP_INLINE int WebPDataCopy(const WebPData* src, WebPData* dst) { + if (src == NULL || dst == NULL) return 0; + WebPDataInit(dst); + if (src->bytes != NULL && src->size != 0) { + dst->bytes = (uint8_t*)WebPMalloc(src->size); + if (dst->bytes == NULL) return 0; + memcpy((void*)dst->bytes, src->bytes, src->size); + dst->size = src->size; + } + return 1; +} + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // WEBP_WEBP_MUX_TYPES_H_ diff --git a/src/JPEGView/libwebp/include/webp/types.h b/src/JPEGView/libwebp/include/webp/types.h index e1dc422b..f255432e 100644 --- a/src/JPEGView/libwebp/include/webp/types.h +++ b/src/JPEGView/libwebp/include/webp/types.h @@ -1,72 +1,72 @@ -// Copyright 2010 Google Inc. All Rights Reserved. -// -// Use of this source code is governed by a BSD-style license -// that can be found in the COPYING file in the root of the source -// tree. An additional intellectual property rights grant can be found -// in the file PATENTS. All contributing project authors may -// be found in the AUTHORS file in the root of the source tree. -// ----------------------------------------------------------------------------- -// -// Common types + memory wrappers -// -// Author: Skal (pascal.massimino@gmail.com) - -#ifndef WEBP_WEBP_TYPES_H_ -#define WEBP_WEBP_TYPES_H_ - -#include // for size_t - -#ifndef _MSC_VER -#include -#if defined(__cplusplus) || !defined(__STRICT_ANSI__) || \ - (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) -#define WEBP_INLINE inline -#else -#define WEBP_INLINE -#endif -#else -typedef signed char int8_t; -typedef unsigned char uint8_t; -typedef signed short int16_t; -typedef unsigned short uint16_t; -typedef signed int int32_t; -typedef unsigned int uint32_t; -typedef unsigned long long int uint64_t; -typedef long long int int64_t; -#define WEBP_INLINE __forceinline -#endif /* _MSC_VER */ - -#ifndef WEBP_EXTERN -// This explicitly marks library functions and allows for changing the -// signature for e.g., Windows DLL builds. -# if defined(__GNUC__) && __GNUC__ >= 4 -# define WEBP_EXTERN extern __attribute__ ((visibility ("default"))) -# else -# if defined(_MSC_VER) && defined(WEBP_DLL) -# define WEBP_EXTERN __declspec(dllexport) -# else -# define WEBP_EXTERN extern -# endif -# endif /* __GNUC__ >= 4 */ -#endif /* WEBP_EXTERN */ - -// Macro to check ABI compatibility (same major revision number) -#define WEBP_ABI_IS_INCOMPATIBLE(a, b) (((a) >> 8) != ((b) >> 8)) - -#ifdef __cplusplus -extern "C" { -#endif - -// Allocates 'size' bytes of memory. Returns NULL upon error. Memory -// must be deallocated by calling WebPFree(). This function is made available -// by the core 'libwebp' library. -WEBP_EXTERN void* WebPMalloc(size_t size); - -// Releases memory returned by the WebPDecode*() functions (from decode.h). -WEBP_EXTERN void WebPFree(void* ptr); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // WEBP_WEBP_TYPES_H_ +// Copyright 2010 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Common types + memory wrappers +// +// Author: Skal (pascal.massimino@gmail.com) + +#ifndef WEBP_WEBP_TYPES_H_ +#define WEBP_WEBP_TYPES_H_ + +#include // for size_t + +#ifndef _MSC_VER +#include +#if defined(__cplusplus) || !defined(__STRICT_ANSI__) || \ + (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) +#define WEBP_INLINE inline +#else +#define WEBP_INLINE +#endif +#else +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef signed short int16_t; +typedef unsigned short uint16_t; +typedef signed int int32_t; +typedef unsigned int uint32_t; +typedef unsigned long long int uint64_t; +typedef long long int int64_t; +#define WEBP_INLINE __forceinline +#endif /* _MSC_VER */ + +#ifndef WEBP_EXTERN +// This explicitly marks library functions and allows for changing the +// signature for e.g., Windows DLL builds. +# if defined(__GNUC__) && __GNUC__ >= 4 +# define WEBP_EXTERN extern __attribute__ ((visibility ("default"))) +# else +# if defined(_MSC_VER) && defined(WEBP_DLL) +# define WEBP_EXTERN __declspec(dllexport) +# else +# define WEBP_EXTERN extern +# endif +# endif /* __GNUC__ >= 4 */ +#endif /* WEBP_EXTERN */ + +// Macro to check ABI compatibility (same major revision number) +#define WEBP_ABI_IS_INCOMPATIBLE(a, b) (((a) >> 8) != ((b) >> 8)) + +#ifdef __cplusplus +extern "C" { +#endif + +// Allocates 'size' bytes of memory. Returns NULL upon error. Memory +// must be deallocated by calling WebPFree(). This function is made available +// by the core 'libwebp' library. +WEBP_EXTERN void* WebPMalloc(size_t size); + +// Releases memory returned by the WebPDecode*() functions (from decode.h). +WEBP_EXTERN void WebPFree(void* ptr); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // WEBP_WEBP_TYPES_H_ diff --git a/src/JPEGView/libwebp/lib/libwebp.lib b/src/JPEGView/libwebp/lib/libwebp.lib index 97db2af1..7729a388 100644 Binary files a/src/JPEGView/libwebp/lib/libwebp.lib and b/src/JPEGView/libwebp/lib/libwebp.lib differ diff --git a/src/JPEGView/libwebp/lib/libwebpdemux.lib b/src/JPEGView/libwebp/lib/libwebpdemux.lib index dfe83e48..12388eb3 100644 Binary files a/src/JPEGView/libwebp/lib/libwebpdemux.lib and b/src/JPEGView/libwebp/lib/libwebpdemux.lib differ diff --git a/src/JPEGView/libwebp/lib64/libwebp.lib b/src/JPEGView/libwebp/lib64/libwebp.lib index cf49ac13..29020392 100644 Binary files a/src/JPEGView/libwebp/lib64/libwebp.lib and b/src/JPEGView/libwebp/lib64/libwebp.lib differ diff --git a/src/JPEGView/libwebp/lib64/libwebpdemux.lib b/src/JPEGView/libwebp/lib64/libwebpdemux.lib index c2428ef2..9e075710 100644 Binary files a/src/JPEGView/libwebp/lib64/libwebpdemux.lib and b/src/JPEGView/libwebp/lib64/libwebpdemux.lib differ