base: add ETC__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST

Binary size, before:
412128 gen/bin/example-convert-to-nia
 50680 gen/bin/example-gifplayer
449680 gen/bin/example-imageviewer
439000 gen/bin/example-sdl-imageviewer
151848 gen/bin/example-toy-aux-image

After:
302232 gen/bin/example-convert-to-nia
 46144 gen/bin/example-gifplayer
352112 gen/bin/example-imageviewer
329168 gen/bin/example-sdl-imageviewer
138656 gen/bin/example-toy-aux-image

For further data points, if you hard-code define'ing
WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST and
WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_PREMUL:

Binary size, before:
121368 gen/lib/c/clang-dynamic/wuffs-base-pixconv.lo
121368 gen/lib/c/clang-static/wuffs-base-pixconv.o
181088 gen/lib/c/gcc-dynamic/wuffs-base-pixconv.lo
181136 gen/lib/c/gcc-static/wuffs-base-pixconv.o

After:
 54784 gen/lib/c/clang-dynamic/wuffs-base-pixconv.lo
 54784 gen/lib/c/clang-static/wuffs-base-pixconv.o
 72144 gen/lib/c/gcc-dynamic/wuffs-base-pixconv.lo
 72272 gen/lib/c/gcc-static/wuffs-base-pixconv.o
This commit is contained in:
Nigel Tao committed 2024-03-29 22:19:47 +11:00
1 parent b2c7c69227
commit f5bb519320
10 files changed
+255

No files matched your search

+1
View File
@@ -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:
+15
View File
@@ -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.
+15
View File
@@ -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.
+15
View File
@@ -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.
@@ -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.
+15
View File
@@ -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.
@@ -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;
@@ -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);
+1
View File
@@ -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"`,
+90
View File
@@ -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);