diff --git a/doc/changelog.md b/doc/changelog.md index 2a4b4f8d..d6999045 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -24,6 +24,7 @@ The LICENSE has changed from a single license (Apache 2) to a dual license - Added `std/xxhash32`. - Added `std/xxhash64`. - Added `std/xz`. +- Added `WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST`. - Added `wuffs_base__status__is_truncated_input_error`. - Changed `lzw.set_literal_width` to `lzw.set_quirk`. - Changed `set_quirk_enabled!(quirk: u32, enabled: bool)` to `set_quirk!(key: diff --git a/example/convert-to-nia/convert-to-nia.c b/example/convert-to-nia/convert-to-nia.c index ed1bd945..d439eddf 100644 --- a/example/convert-to-nia/convert-to-nia.c +++ b/example/convert-to-nia/convert-to-nia.c @@ -70,6 +70,21 @@ https://skia-review.googlesource.com/c/skia/+/290618 #define WUFFS_CONFIG__MODULE__WBMP #define WUFFS_CONFIG__MODULE__ZLIB +// Defining the WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST (and the +// associated ETC__ALLOW_FOO) macros are optional, but can lead to smaller +// programs (in terms of binary size). By default (without these macros), +// Wuffs' standard library can decode images to a variety of pixel formats, +// such as BGR_565, BGRA_PREMUL or RGBA_NONPREMUL. The destination pixel format +// is selectable at runtime. Using these macros essentially makes the selection +// at compile time, by narrowing the list of supported destination pixel +// formats. The FOO in ETC__ALLOW_FOO should match the pixel format passed (as +// part of the wuffs_base__image_config argument) to the decode_frame method. +// +// If using the wuffs_aux C++ API, without overriding the SelectPixfmt method, +// the implicit destination pixel format is BGRA_PREMUL. +#define WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST +#define WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_NONPREMUL + // If building this program in an environment that doesn't easily accommodate // relative includes, you can use the script/inline-c-relative-includes.go // program to generate a stand-alone C file. diff --git a/example/gifplayer/gifplayer.c b/example/gifplayer/gifplayer.c index 5f1538df..40643c13 100644 --- a/example/gifplayer/gifplayer.c +++ b/example/gifplayer/gifplayer.c @@ -88,6 +88,21 @@ micros_since_start(struct timespec* now) { #define WUFFS_CONFIG__MODULE__BASE #define WUFFS_CONFIG__MODULE__GIF +// Defining the WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST (and the +// associated ETC__ALLOW_FOO) macros are optional, but can lead to smaller +// programs (in terms of binary size). By default (without these macros), +// Wuffs' standard library can decode images to a variety of pixel formats, +// such as BGR_565, BGRA_PREMUL or RGBA_NONPREMUL. The destination pixel format +// is selectable at runtime. Using these macros essentially makes the selection +// at compile time, by narrowing the list of supported destination pixel +// formats. The FOO in ETC__ALLOW_FOO should match the pixel format passed (as +// part of the wuffs_base__image_config argument) to the decode_frame method. +// +// If using the wuffs_aux C++ API, without overriding the SelectPixfmt method, +// the implicit destination pixel format is BGRA_PREMUL. +#define WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST +#define WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_PREMUL + // If building this program in an environment that doesn't easily accommodate // relative includes, you can use the script/inline-c-relative-includes.go // program to generate a stand-alone C file. diff --git a/example/imageviewer/imageviewer.cc b/example/imageviewer/imageviewer.cc index e89bd7d3..b2d37635 100644 --- a/example/imageviewer/imageviewer.cc +++ b/example/imageviewer/imageviewer.cc @@ -83,6 +83,21 @@ The Escape key quits. #define WUFFS_CONFIG__MODULE__WBMP #define WUFFS_CONFIG__MODULE__ZLIB +// Defining the WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST (and the +// associated ETC__ALLOW_FOO) macros are optional, but can lead to smaller +// programs (in terms of binary size). By default (without these macros), +// Wuffs' standard library can decode images to a variety of pixel formats, +// such as BGR_565, BGRA_PREMUL or RGBA_NONPREMUL. The destination pixel format +// is selectable at runtime. Using these macros essentially makes the selection +// at compile time, by narrowing the list of supported destination pixel +// formats. The FOO in ETC__ALLOW_FOO should match the pixel format passed (as +// part of the wuffs_base__image_config argument) to the decode_frame method. +// +// If using the wuffs_aux C++ API, without overriding the SelectPixfmt method, +// the implicit destination pixel format is BGRA_PREMUL. +#define WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST +#define WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_PREMUL + // If building this program in an environment that doesn't easily accommodate // relative includes, you can use the script/inline-c-relative-includes.go // program to generate a stand-alone C file. diff --git a/example/sdl-imageviewer/sdl-imageviewer.cc b/example/sdl-imageviewer/sdl-imageviewer.cc index 95669317..ebbe81d5 100644 --- a/example/sdl-imageviewer/sdl-imageviewer.cc +++ b/example/sdl-imageviewer/sdl-imageviewer.cc @@ -81,6 +81,21 @@ isn't otherwise doing anything. #define WUFFS_CONFIG__MODULE__WBMP #define WUFFS_CONFIG__MODULE__ZLIB +// Defining the WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST (and the +// associated ETC__ALLOW_FOO) macros are optional, but can lead to smaller +// programs (in terms of binary size). By default (without these macros), +// Wuffs' standard library can decode images to a variety of pixel formats, +// such as BGR_565, BGRA_PREMUL or RGBA_NONPREMUL. The destination pixel format +// is selectable at runtime. Using these macros essentially makes the selection +// at compile time, by narrowing the list of supported destination pixel +// formats. The FOO in ETC__ALLOW_FOO should match the pixel format passed (as +// part of the wuffs_base__image_config argument) to the decode_frame method. +// +// If using the wuffs_aux C++ API, without overriding the SelectPixfmt method, +// the implicit destination pixel format is BGRA_PREMUL. +#define WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST +#define WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_NONPREMUL + // If building this program in an environment that doesn't easily accommodate // relative includes, you can use the script/inline-c-relative-includes.go // program to generate a stand-alone C file. diff --git a/example/toy-aux-image/toy-aux-image.cc b/example/toy-aux-image/toy-aux-image.cc index 2873d112..352ba17c 100644 --- a/example/toy-aux-image/toy-aux-image.cc +++ b/example/toy-aux-image/toy-aux-image.cc @@ -77,6 +77,21 @@ OOOOXXXXXXXXXXOXXXXXXXXXXXXOOO #define WUFFS_CONFIG__MODULE__BASE #define WUFFS_CONFIG__MODULE__JPEG +// Defining the WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST (and the +// associated ETC__ALLOW_FOO) macros are optional, but can lead to smaller +// programs (in terms of binary size). By default (without these macros), +// Wuffs' standard library can decode images to a variety of pixel formats, +// such as BGR_565, BGRA_PREMUL or RGBA_NONPREMUL. The destination pixel format +// is selectable at runtime. Using these macros essentially makes the selection +// at compile time, by narrowing the list of supported destination pixel +// formats. The FOO in ETC__ALLOW_FOO should match the pixel format passed (as +// part of the wuffs_base__image_config argument) to the decode_frame method. +// +// If using the wuffs_aux C++ API, without overriding the SelectPixfmt method, +// the implicit destination pixel format is BGRA_PREMUL. +#define WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST +#define WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_PREMUL + // If building this program in an environment that doesn't easily accommodate // relative includes, you can use the script/inline-c-relative-includes.go // program to generate a stand-alone C file. diff --git a/internal/cgen/base/pixconv-submodule-regular.c b/internal/cgen/base/pixconv-submodule-regular.c index a4d83f5b..28447959 100644 --- a/internal/cgen/base/pixconv-submodule-regular.c +++ b/internal/cgen/base/pixconv-submodule-regular.c @@ -5888,6 +5888,50 @@ wuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swizzler* p, p->private_impl.dst_pixfmt_bytes_per_pixel = 0; p->private_impl.src_pixfmt_bytes_per_pixel = 0; + // ---- + +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST) + switch (dst_pixfmt.repr) { +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGR_565) + case WUFFS_BASE__PIXEL_FORMAT__BGR_565: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGR) + case WUFFS_BASE__PIXEL_FORMAT__BGR: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_NONPREMUL) + case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_NONPREMUL_4X16LE) + case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_PREMUL) + case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_RGB) + case WUFFS_BASE__PIXEL_FORMAT__RGB: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_RGBA_NONPREMUL) + case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_RGBA_PREMUL) + case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL: + break; +#endif + default: + return wuffs_base__make_status( + wuffs_base__error__disabled_by_wuffs_config_dst_pixel_format_enable_allowlist); + } +#endif // defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST) + + // ---- + wuffs_base__pixel_swizzler__func func = NULL; wuffs_base__pixel_swizzler__transparent_black_func transparent_black_func = NULL; diff --git a/internal/cgen/base/pixconv-submodule-ycck.c b/internal/cgen/base/pixconv-submodule-ycck.c index 1ac5e088..0e0c4e9d 100644 --- a/internal/cgen/base/pixconv-submodule-ycck.c +++ b/internal/cgen/base/pixconv-submodule-ycck.c @@ -1194,6 +1194,47 @@ wuffs_base__pixel_swizzler__swizzle_ycck( wuffs_base__error__unsupported_pixel_swizzler_option); } + // ---- + +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST) + switch (dst->pixcfg.private_impl.pixfmt.repr) { +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGR_565) + case WUFFS_BASE__PIXEL_FORMAT__BGR_565: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGR) + case WUFFS_BASE__PIXEL_FORMAT__BGR: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_NONPREMUL) + case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_NONPREMUL_4X16LE) + case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_PREMUL) + case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_RGB) + case WUFFS_BASE__PIXEL_FORMAT__RGB: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_RGBA_NONPREMUL) + case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_RGBA_PREMUL) + case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL: + break; +#endif + default: + return wuffs_base__make_status( + wuffs_base__error__disabled_by_wuffs_config_dst_pixel_format_enable_allowlist); + } +#else // defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST) switch (dst->pixcfg.private_impl.pixfmt.repr) { case WUFFS_BASE__PIXEL_FORMAT__Y: case WUFFS_BASE__PIXEL_FORMAT__Y_16LE: @@ -1219,6 +1260,9 @@ wuffs_base__pixel_swizzler__swizzle_ycck( return wuffs_base__make_status( wuffs_base__error__unsupported_pixel_swizzler_option); } +#endif // defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST) + + // ---- if ((width <= 0u) || (height <= 0u)) { return wuffs_base__make_status(NULL); diff --git a/lang/builtin/builtin.go b/lang/builtin/builtin.go index 43fa9d9e..8e113c67 100644 --- a/lang/builtin/builtin.go +++ b/lang/builtin/builtin.go @@ -262,6 +262,7 @@ var Statuses = [...]string{ `"#bad workbuf length"`, `"#bad wuffs version"`, `"#cannot return a suspension"`, + `"#disabled by WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST"`, `"#disabled by previous error"`, `"#initialize falsely claimed already zeroed"`, `"#initialize not called"`, diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index 36537c7e..ce15746b 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -555,6 +555,7 @@ extern const char wuffs_base__error__bad_vtable[]; extern const char wuffs_base__error__bad_workbuf_length[]; extern const char wuffs_base__error__bad_wuffs_version[]; extern const char wuffs_base__error__cannot_return_a_suspension[]; +extern const char wuffs_base__error__disabled_by_wuffs_config_dst_pixel_format_enable_allowlist[]; extern const char wuffs_base__error__disabled_by_previous_error[]; extern const char wuffs_base__error__initialize_falsely_claimed_already_zeroed[]; extern const char wuffs_base__error__initialize_not_called[]; @@ -15979,6 +15980,7 @@ const char wuffs_base__error__bad_vtable[] = "#base: bad vtable"; const char wuffs_base__error__bad_workbuf_length[] = "#base: bad workbuf length"; const char wuffs_base__error__bad_wuffs_version[] = "#base: bad wuffs version"; const char wuffs_base__error__cannot_return_a_suspension[] = "#base: cannot return a suspension"; +const char wuffs_base__error__disabled_by_wuffs_config_dst_pixel_format_enable_allowlist[] = "#base: disabled by WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST"; const char wuffs_base__error__disabled_by_previous_error[] = "#base: disabled by previous error"; const char wuffs_base__error__initialize_falsely_claimed_already_zeroed[] = "#base: initialize falsely claimed already zeroed"; const char wuffs_base__error__initialize_not_called[] = "#base: initialize not called"; @@ -26864,6 +26866,50 @@ wuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swizzler* p, p->private_impl.dst_pixfmt_bytes_per_pixel = 0; p->private_impl.src_pixfmt_bytes_per_pixel = 0; + // ---- + +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST) + switch (dst_pixfmt.repr) { +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGR_565) + case WUFFS_BASE__PIXEL_FORMAT__BGR_565: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGR) + case WUFFS_BASE__PIXEL_FORMAT__BGR: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_NONPREMUL) + case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_NONPREMUL_4X16LE) + case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_PREMUL) + case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_RGB) + case WUFFS_BASE__PIXEL_FORMAT__RGB: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_RGBA_NONPREMUL) + case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_RGBA_PREMUL) + case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL: + break; +#endif + default: + return wuffs_base__make_status( + wuffs_base__error__disabled_by_wuffs_config_dst_pixel_format_enable_allowlist); + } +#endif // defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST) + + // ---- + wuffs_base__pixel_swizzler__func func = NULL; wuffs_base__pixel_swizzler__transparent_black_func transparent_black_func = NULL; @@ -28234,6 +28280,47 @@ wuffs_base__pixel_swizzler__swizzle_ycck( wuffs_base__error__unsupported_pixel_swizzler_option); } + // ---- + +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST) + switch (dst->pixcfg.private_impl.pixfmt.repr) { +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGR_565) + case WUFFS_BASE__PIXEL_FORMAT__BGR_565: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGR) + case WUFFS_BASE__PIXEL_FORMAT__BGR: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_NONPREMUL) + case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_NONPREMUL_4X16LE) + case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_PREMUL) + case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_RGB) + case WUFFS_BASE__PIXEL_FORMAT__RGB: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_RGBA_NONPREMUL) + case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL: + break; +#endif +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_RGBA_PREMUL) + case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL: + break; +#endif + default: + return wuffs_base__make_status( + wuffs_base__error__disabled_by_wuffs_config_dst_pixel_format_enable_allowlist); + } +#else // defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST) switch (dst->pixcfg.private_impl.pixfmt.repr) { case WUFFS_BASE__PIXEL_FORMAT__Y: case WUFFS_BASE__PIXEL_FORMAT__Y_16LE: @@ -28259,6 +28346,9 @@ wuffs_base__pixel_swizzler__swizzle_ycck( return wuffs_base__make_status( wuffs_base__error__unsupported_pixel_swizzler_option); } +#endif // defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST) + + // ---- if ((width <= 0u) || (height <= 0u)) { return wuffs_base__make_status(NULL);