std/thumbhash: add new package

This commit is contained in:
Nigel Tao committed 2024-09-03 20:07:37 +10:00
1 parent aa28bb076c
commit b8740d8881
15 files changed
+1812 -2

No files matched your search

+1
View File
@@ -23,6 +23,7 @@ The LICENSE has changed from a single license (Apache 2) to a dual license
- Added `std/netpbm`.
- Added `std/qoi`.
- Added `std/sha256`.
- Added `std/thumbhash`.
- Added `std/vp8`.
- Added `std/webp`.
- Added `std/xxhash32`.
+1
View File
@@ -66,6 +66,7 @@ to enable.
- `QOI: BASE`
- `SHA256: BASE`
- `TGA: BASE`
- `THUMBHASH: BASE`
- `VP8: BASE`
- `WBMP: BASE`
- `WEBP: BASE, VP8`
+1
View File
@@ -132,6 +132,7 @@ In Wuffs syntax, the `base.image_decoder` methods are:
- [std/png](/std/png)
- [std/qoi](/std/qoi)
- [std/tga](/std/tga)
- [std/thumbhash](/std/thumbhash)
- [std/wbmp](/std/wbmp)
- [std/webp](/std/webp)
+13
View File
@@ -69,6 +69,7 @@ https://skia-review.googlesource.com/c/skia/+/290618
#define WUFFS_CONFIG__MODULE__PNG
#define WUFFS_CONFIG__MODULE__QOI
#define WUFFS_CONFIG__MODULE__TGA
#define WUFFS_CONFIG__MODULE__THUMBHASH
#define WUFFS_CONFIG__MODULE__VP8
#define WUFFS_CONFIG__MODULE__WBMP
#define WUFFS_CONFIG__MODULE__WEBP
@@ -169,6 +170,7 @@ union {
wuffs_png__decoder png;
wuffs_qoi__decoder qoi;
wuffs_tga__decoder tga;
wuffs_thumbhash__decoder thumbhash;
wuffs_wbmp__decoder wbmp;
wuffs_webp__decoder webp;
} g_potential_decoders;
@@ -431,6 +433,17 @@ initialize_image_decoder() {
&g_potential_decoders.tga);
return NULL;
case WUFFS_BASE__FOURCC__TH:
status = wuffs_thumbhash__decoder__initialize(
&g_potential_decoders.thumbhash,
sizeof g_potential_decoders.thumbhash, WUFFS_VERSION,
WUFFS_INITIALIZE__DEFAULT_OPTIONS);
TRY(wuffs_base__status__message(&status));
g_image_decoder =
wuffs_thumbhash__decoder__upcast_as__wuffs_base__image_decoder(
&g_potential_decoders.thumbhash);
return NULL;
case WUFFS_BASE__FOURCC__WBMP:
status = wuffs_wbmp__decoder__initialize(
&g_potential_decoders.wbmp, sizeof g_potential_decoders.wbmp,
+1
View File
@@ -82,6 +82,7 @@ The Escape key quits.
#define WUFFS_CONFIG__MODULE__PNG
#define WUFFS_CONFIG__MODULE__QOI
#define WUFFS_CONFIG__MODULE__TGA
#define WUFFS_CONFIG__MODULE__THUMBHASH
#define WUFFS_CONFIG__MODULE__VP8
#define WUFFS_CONFIG__MODULE__WBMP
#define WUFFS_CONFIG__MODULE__WEBP
@@ -80,6 +80,7 @@ isn't otherwise doing anything.
#define WUFFS_CONFIG__MODULE__PNG
#define WUFFS_CONFIG__MODULE__QOI
#define WUFFS_CONFIG__MODULE__TGA
#define WUFFS_CONFIG__MODULE__THUMBHASH
#define WUFFS_CONFIG__MODULE__VP8
#define WUFFS_CONFIG__MODULE__WBMP
#define WUFFS_CONFIG__MODULE__WEBP
+5
View File
@@ -106,6 +106,11 @@ DecodeImageCallbacks::SelectDecoder(uint32_t fourcc,
return wuffs_tga__decoder::alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__THUMBHASH)
case WUFFS_BASE__FOURCC__TH:
return wuffs_thumbhash__decoder::alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WBMP)
case WUFFS_BASE__FOURCC__WBMP:
return wuffs_wbmp__decoder::alloc_as__wuffs_base__image_decoder();
+7 -1
View File
@@ -83,8 +83,9 @@ class DecodeImageCallbacks {
// of the FOO file format is optional (for each value of FOO) and depends on
// the corresponding module to be enabled at compile time (i.e. #define'ing
// WUFFS_CONFIG__MODULE__FOO).
//
// - WUFFS_BASE__FOURCC__BMP
// - WUFFS_BASE__FOURCC__ETC
// - WUFFS_BASE__FOURCC__ETC2
// - WUFFS_BASE__FOURCC__GIF
// - WUFFS_BASE__FOURCC__JPEG
// - WUFFS_BASE__FOURCC__NIE
@@ -92,8 +93,13 @@ class DecodeImageCallbacks {
// - WUFFS_BASE__FOURCC__PNG
// - WUFFS_BASE__FOURCC__QOI
// - WUFFS_BASE__FOURCC__TGA
// - WUFFS_BASE__FOURCC__TH
// - WUFFS_BASE__FOURCC__WBMP
// - WUFFS_BASE__FOURCC__WEBP
//
// The FOOBAR in WUFFS_BASE__FOURCC__FOBA is limited to four characters, but
// the FOOBAR in the corresponding WUFFS_CONFIG__MODULE__FOOBAR macro might
// be fuller and longer. For example, NPBM / NETPBM or TH / THUMBHASH.
virtual wuffs_base__image_decoder::unique_ptr //
SelectDecoder(uint32_t fourcc,
wuffs_base__slice_u8 prefix_data,
+1274 -1
View File
@@ -14098,6 +14098,355 @@ struct wuffs_tga__decoder__struct {
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__THUMBHASH) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_thumbhash__error__bad_header[];
extern const char wuffs_thumbhash__error__truncated_input[];
// ---------------- Public Consts
#define WUFFS_THUMBHASH__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0u
// ---------------- Struct Declarations
typedef struct wuffs_thumbhash__decoder__struct wuffs_thumbhash__decoder;
#ifdef __cplusplus
extern "C" {
#endif
// ---------------- Public Initializer Prototypes
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for options.
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
wuffs_thumbhash__decoder__initialize(
wuffs_thumbhash__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options);
size_t
sizeof__wuffs_thumbhash__decoder(void);
// ---------------- Allocs
// These functions allocate and initialize Wuffs structs. They return NULL if
// memory allocation fails. If they return non-NULL, there is no need to call
// wuffs_foo__bar__initialize, but the caller is responsible for eventually
// calling free on the returned pointer. That pointer is effectively a C++
// std::unique_ptr<T, wuffs_unique_ptr_deleter>.
wuffs_thumbhash__decoder*
wuffs_thumbhash__decoder__alloc(void);
static inline wuffs_base__image_decoder*
wuffs_thumbhash__decoder__alloc_as__wuffs_base__image_decoder(void) {
return (wuffs_base__image_decoder*)(wuffs_thumbhash__decoder__alloc());
}
// ---------------- Upcasts
static inline wuffs_base__image_decoder*
wuffs_thumbhash__decoder__upcast_as__wuffs_base__image_decoder(
wuffs_thumbhash__decoder* p) {
return (wuffs_base__image_decoder*)p;
}
// ---------------- Public Function Prototypes
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_thumbhash__decoder__get_quirk(
const wuffs_thumbhash__decoder* self,
uint32_t a_key);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__set_quirk(
wuffs_thumbhash__decoder* self,
uint32_t a_key,
uint64_t a_value);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__decode_image_config(
wuffs_thumbhash__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__decode_frame_config(
wuffs_thumbhash__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__decode_frame(
wuffs_thumbhash__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32
wuffs_thumbhash__decoder__frame_dirty_rect(
const wuffs_thumbhash__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint32_t
wuffs_thumbhash__decoder__num_animation_loops(
const wuffs_thumbhash__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_thumbhash__decoder__num_decoded_frame_configs(
const wuffs_thumbhash__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_thumbhash__decoder__num_decoded_frames(
const wuffs_thumbhash__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__restart_frame(
wuffs_thumbhash__decoder* self,
uint64_t a_index,
uint64_t a_io_position);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
wuffs_thumbhash__decoder__set_report_metadata(
wuffs_thumbhash__decoder* self,
uint32_t a_fourcc,
bool a_report);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__tell_me_more(
wuffs_thumbhash__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
wuffs_thumbhash__decoder__workbuf_len(
const wuffs_thumbhash__decoder* self);
#ifdef __cplusplus
} // extern "C"
#endif
// ---------------- Struct Definitions
// These structs' fields, and the sizeof them, are private implementation
// details that aren't guaranteed to be stable across Wuffs versions.
//
// See https://en.wikipedia.org/wiki/Opaque_pointer#C
#if defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
struct wuffs_thumbhash__decoder__struct {
// Do not access the private_impl's or private_data's fields directly. There
// is no API/ABI compatibility or safety guarantee if you do so. Instead, use
// the wuffs_foo__bar__baz functions.
//
// It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
// can be stack allocated when WUFFS_IMPLEMENTATION is defined.
struct {
uint32_t magic;
uint32_t active_coroutine;
wuffs_base__vtable vtable_for__wuffs_base__image_decoder;
wuffs_base__vtable null_vtable;
uint32_t f_pixfmt;
uint32_t f_width;
uint32_t f_height;
uint8_t f_call_sequence;
wuffs_base__pixel_swizzler f_swizzler;
uint32_t p_decode_image_config;
uint32_t p_do_decode_image_config;
uint32_t p_decode_frame_config;
uint32_t p_do_decode_frame_config;
uint32_t p_decode_frame;
uint32_t p_do_decode_frame;
} private_impl;
struct {
uint8_t f_pixels[32][128];
struct {
uint64_t scratch;
} s_do_decode_image_config;
} private_data;
#ifdef __cplusplus
#if defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
using unique_ptr = std::unique_ptr<wuffs_thumbhash__decoder, wuffs_unique_ptr_deleter>;
// On failure, the alloc_etc functions return nullptr. They don't throw.
static inline unique_ptr
alloc() {
return unique_ptr(wuffs_thumbhash__decoder__alloc());
}
static inline wuffs_base__image_decoder::unique_ptr
alloc_as__wuffs_base__image_decoder() {
return wuffs_base__image_decoder::unique_ptr(
wuffs_thumbhash__decoder__alloc_as__wuffs_base__image_decoder());
}
#endif // defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
#if defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
// Disallow constructing or copying an object via standard C++ mechanisms,
// e.g. the "new" operator, as this struct is intentionally opaque. Its total
// size and field layout is not part of the public, stable, memory-safe API.
// Use malloc or memcpy and the sizeof__wuffs_foo__bar function instead, and
// call wuffs_foo__bar__baz methods (which all take a "this"-like pointer as
// their first argument) rather than tweaking bar.private_impl.qux fields.
//
// In C, we can just leave wuffs_foo__bar as an incomplete type (unless
// WUFFS_IMPLEMENTATION is #define'd). In C++, we define a complete type in
// order to provide convenience methods. These forward on "this", so that you
// can write "bar->baz(etc)" instead of "wuffs_foo__bar__baz(bar, etc)".
wuffs_thumbhash__decoder__struct() = delete;
wuffs_thumbhash__decoder__struct(const wuffs_thumbhash__decoder__struct&) = delete;
wuffs_thumbhash__decoder__struct& operator=(
const wuffs_thumbhash__decoder__struct&) = delete;
#endif // defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
#if !defined(WUFFS_IMPLEMENTATION)
// As above, the size of the struct is not part of the public API, and unless
// WUFFS_IMPLEMENTATION is #define'd, this struct type T should be heap
// allocated, not stack allocated. Its size is not intended to be known at
// compile time, but it is unfortunately divulged as a side effect of
// defining C++ convenience methods. Use "sizeof__T()", calling the function,
// instead of "sizeof T", invoking the operator. To make the two values
// different, so that passing the latter will be rejected by the initialize
// function, we add an arbitrary amount of dead weight.
uint8_t dead_weight[123000000]; // 123 MB.
#endif // !defined(WUFFS_IMPLEMENTATION)
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
initialize(
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options) {
return wuffs_thumbhash__decoder__initialize(
this, sizeof_star_self, wuffs_version, options);
}
inline wuffs_base__image_decoder*
upcast_as__wuffs_base__image_decoder() {
return (wuffs_base__image_decoder*)this;
}
inline uint64_t
get_quirk(
uint32_t a_key) const {
return wuffs_thumbhash__decoder__get_quirk(this, a_key);
}
inline wuffs_base__status
set_quirk(
uint32_t a_key,
uint64_t a_value) {
return wuffs_thumbhash__decoder__set_quirk(this, a_key, a_value);
}
inline wuffs_base__status
decode_image_config(
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
return wuffs_thumbhash__decoder__decode_image_config(this, a_dst, a_src);
}
inline wuffs_base__status
decode_frame_config(
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
return wuffs_thumbhash__decoder__decode_frame_config(this, a_dst, a_src);
}
inline wuffs_base__status
decode_frame(
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
return wuffs_thumbhash__decoder__decode_frame(this, a_dst, a_src, a_blend, a_workbuf, a_opts);
}
inline wuffs_base__rect_ie_u32
frame_dirty_rect() const {
return wuffs_thumbhash__decoder__frame_dirty_rect(this);
}
inline uint32_t
num_animation_loops() const {
return wuffs_thumbhash__decoder__num_animation_loops(this);
}
inline uint64_t
num_decoded_frame_configs() const {
return wuffs_thumbhash__decoder__num_decoded_frame_configs(this);
}
inline uint64_t
num_decoded_frames() const {
return wuffs_thumbhash__decoder__num_decoded_frames(this);
}
inline wuffs_base__status
restart_frame(
uint64_t a_index,
uint64_t a_io_position) {
return wuffs_thumbhash__decoder__restart_frame(this, a_index, a_io_position);
}
inline wuffs_base__empty_struct
set_report_metadata(
uint32_t a_fourcc,
bool a_report) {
return wuffs_thumbhash__decoder__set_report_metadata(this, a_fourcc, a_report);
}
inline wuffs_base__status
tell_me_more(
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src) {
return wuffs_thumbhash__decoder__tell_me_more(this, a_dst, a_minfo, a_src);
}
inline wuffs_base__range_ii_u64
workbuf_len() const {
return wuffs_thumbhash__decoder__workbuf_len(this);
}
#endif // __cplusplus
}; // struct wuffs_thumbhash__decoder__struct
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__THUMBHASH) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__VP8) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
@@ -16104,8 +16453,9 @@ class DecodeImageCallbacks {
// of the FOO file format is optional (for each value of FOO) and depends on
// the corresponding module to be enabled at compile time (i.e. #define'ing
// WUFFS_CONFIG__MODULE__FOO).
//
// - WUFFS_BASE__FOURCC__BMP
// - WUFFS_BASE__FOURCC__ETC
// - WUFFS_BASE__FOURCC__ETC2
// - WUFFS_BASE__FOURCC__GIF
// - WUFFS_BASE__FOURCC__JPEG
// - WUFFS_BASE__FOURCC__NIE
@@ -16113,8 +16463,13 @@ class DecodeImageCallbacks {
// - WUFFS_BASE__FOURCC__PNG
// - WUFFS_BASE__FOURCC__QOI
// - WUFFS_BASE__FOURCC__TGA
// - WUFFS_BASE__FOURCC__TH
// - WUFFS_BASE__FOURCC__WBMP
// - WUFFS_BASE__FOURCC__WEBP
//
// The FOOBAR in WUFFS_BASE__FOURCC__FOBA is limited to four characters, but
// the FOOBAR in the corresponding WUFFS_CONFIG__MODULE__FOOBAR macro might
// be fuller and longer. For example, NPBM / NETPBM or TH / THUMBHASH.
virtual wuffs_base__image_decoder::unique_ptr //
SelectDecoder(uint32_t fourcc,
wuffs_base__slice_u8 prefix_data,
@@ -72912,6 +73267,919 @@ wuffs_tga__decoder__workbuf_len(
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__THUMBHASH)
// ---------------- Status Codes Implementations
const char wuffs_thumbhash__error__bad_header[] = "#thumbhash: bad header";
const char wuffs_thumbhash__error__truncated_input[] = "#thumbhash: truncated input";
// ---------------- Private Consts
// ---------------- Private Initializer Prototypes
// ---------------- Private Function Prototypes
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__do_decode_image_config(
wuffs_thumbhash__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__do_decode_frame_config(
wuffs_thumbhash__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__do_decode_frame(
wuffs_thumbhash__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__from_src_to_pixels(
wuffs_thumbhash__decoder* self,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__from_pixels_to_dst(
wuffs_thumbhash__decoder* self,
wuffs_base__pixel_buffer* a_dst);
// ---------------- VTables
const wuffs_base__image_decoder__func_ptrs
wuffs_thumbhash__decoder__func_ptrs_for__wuffs_base__image_decoder = {
(wuffs_base__status(*)(void*,
wuffs_base__pixel_buffer*,
wuffs_base__io_buffer*,
wuffs_base__pixel_blend,
wuffs_base__slice_u8,
wuffs_base__decode_frame_options*))(&wuffs_thumbhash__decoder__decode_frame),
(wuffs_base__status(*)(void*,
wuffs_base__frame_config*,
wuffs_base__io_buffer*))(&wuffs_thumbhash__decoder__decode_frame_config),
(wuffs_base__status(*)(void*,
wuffs_base__image_config*,
wuffs_base__io_buffer*))(&wuffs_thumbhash__decoder__decode_image_config),
(wuffs_base__rect_ie_u32(*)(const void*))(&wuffs_thumbhash__decoder__frame_dirty_rect),
(uint64_t(*)(const void*,
uint32_t))(&wuffs_thumbhash__decoder__get_quirk),
(uint32_t(*)(const void*))(&wuffs_thumbhash__decoder__num_animation_loops),
(uint64_t(*)(const void*))(&wuffs_thumbhash__decoder__num_decoded_frame_configs),
(uint64_t(*)(const void*))(&wuffs_thumbhash__decoder__num_decoded_frames),
(wuffs_base__status(*)(void*,
uint64_t,
uint64_t))(&wuffs_thumbhash__decoder__restart_frame),
(wuffs_base__status(*)(void*,
uint32_t,
uint64_t))(&wuffs_thumbhash__decoder__set_quirk),
(wuffs_base__empty_struct(*)(void*,
uint32_t,
bool))(&wuffs_thumbhash__decoder__set_report_metadata),
(wuffs_base__status(*)(void*,
wuffs_base__io_buffer*,
wuffs_base__more_information*,
wuffs_base__io_buffer*))(&wuffs_thumbhash__decoder__tell_me_more),
(wuffs_base__range_ii_u64(*)(const void*))(&wuffs_thumbhash__decoder__workbuf_len),
};
// ---------------- Initializer Implementations
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
wuffs_thumbhash__decoder__initialize(
wuffs_thumbhash__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options){
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (sizeof(*self) != sizeof_star_self) {
return wuffs_base__make_status(wuffs_base__error__bad_sizeof_receiver);
}
if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) ||
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__make_status(wuffs_base__error__bad_wuffs_version);
}
if ((options & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
// The whole point of this if-check is to detect an uninitialized *self.
// We disable the warning on GCC. Clang-5.0 does not have this warning.
#if !defined(__clang__) && defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
if (self->private_impl.magic != 0) {
return wuffs_base__make_status(wuffs_base__error__initialize_falsely_claimed_already_zeroed);
}
#if !defined(__clang__) && defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
} else {
if ((options & WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
memset(self, 0, sizeof(*self));
options |= WUFFS_INITIALIZE__ALREADY_ZEROED;
} else {
memset(&(self->private_impl), 0, sizeof(self->private_impl));
}
}
self->private_impl.magic = WUFFS_BASE__MAGIC;
self->private_impl.vtable_for__wuffs_base__image_decoder.vtable_name =
wuffs_base__image_decoder__vtable_name;
self->private_impl.vtable_for__wuffs_base__image_decoder.function_pointers =
(const void*)(&wuffs_thumbhash__decoder__func_ptrs_for__wuffs_base__image_decoder);
return wuffs_base__make_status(NULL);
}
wuffs_thumbhash__decoder*
wuffs_thumbhash__decoder__alloc(void) {
wuffs_thumbhash__decoder* x =
(wuffs_thumbhash__decoder*)(calloc(1, sizeof(wuffs_thumbhash__decoder)));
if (!x) {
return NULL;
}
if (wuffs_thumbhash__decoder__initialize(
x, sizeof(wuffs_thumbhash__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) {
free(x);
return NULL;
}
return x;
}
size_t
sizeof__wuffs_thumbhash__decoder(void) {
return sizeof(wuffs_thumbhash__decoder);
}
// ---------------- Function Implementations
// -------- func thumbhash.decoder.get_quirk
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_thumbhash__decoder__get_quirk(
const wuffs_thumbhash__decoder* self,
uint32_t a_key) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
return 0u;
}
// -------- func thumbhash.decoder.set_quirk
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__set_quirk(
wuffs_thumbhash__decoder* self,
uint32_t a_key,
uint64_t a_value) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
}
// -------- func thumbhash.decoder.decode_image_config
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__decode_image_config(
wuffs_thumbhash__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 1)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_image_config;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_thumbhash__decoder__do_decode_image_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_thumbhash__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_image_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func thumbhash.decoder.do_decode_image_config
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__do_decode_image_config(
wuffs_thumbhash__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_c32 = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_do_decode_image_config;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence != 0u) {
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
goto exit;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
uint32_t t_0;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 3)) {
t_0 = ((uint32_t)(wuffs_base__peek_u24le__no_bounds_check(iop_a_src)));
iop_a_src += 3;
} else {
self->private_data.s_do_decode_image_config.scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_do_decode_image_config.scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_0;
if (num_bits_0 == 16) {
t_0 = ((uint32_t)(*scratch));
break;
}
num_bits_0 += 8u;
*scratch |= ((uint64_t)(num_bits_0)) << 56;
}
}
v_c32 = t_0;
}
if (v_c32 != 16694979u) {
status = wuffs_base__make_status(wuffs_thumbhash__error__bad_header);
goto exit;
}
self->private_impl.f_pixfmt = 2415954056u;
self->private_impl.f_width = 32u;
self->private_impl.f_height = 32u;
if (a_dst != NULL) {
wuffs_base__image_config__set(
a_dst,
self->private_impl.f_pixfmt,
0u,
self->private_impl.f_width,
self->private_impl.f_height,
3u,
(self->private_impl.f_pixfmt == 2415954056u));
}
self->private_impl.f_call_sequence = 32u;
goto ok;
ok:
self->private_impl.p_do_decode_image_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_do_decode_image_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func thumbhash.decoder.decode_frame_config
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__decode_frame_config(
wuffs_thumbhash__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 2)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_thumbhash__decoder__do_decode_frame_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_thumbhash__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func thumbhash.decoder.do_decode_frame_config
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__do_decode_frame_config(
wuffs_thumbhash__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame_config;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence == 32u) {
} else if (self->private_impl.f_call_sequence < 32u) {
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_thumbhash__decoder__do_decode_image_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
} else if (self->private_impl.f_call_sequence == 40u) {
if (3u != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
goto exit;
}
} else if (self->private_impl.f_call_sequence == 64u) {
self->private_impl.f_call_sequence = 96u;
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
} else {
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
}
if (a_dst != NULL) {
wuffs_base__frame_config__set(
a_dst,
wuffs_base__utility__make_rect_ie_u32(
0u,
0u,
self->private_impl.f_width,
self->private_impl.f_height),
((wuffs_base__flicks)(0u)),
0u,
3u,
0u,
(self->private_impl.f_pixfmt == 2415954056u),
false,
0u);
}
self->private_impl.f_call_sequence = 64u;
ok:
self->private_impl.p_do_decode_frame_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_do_decode_frame_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func thumbhash.decoder.decode_frame
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__decode_frame(
wuffs_thumbhash__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_dst || !a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 3)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_thumbhash__decoder__do_decode_frame(self,
a_dst,
a_src,
a_blend,
a_workbuf,
a_opts);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_thumbhash__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func thumbhash.decoder.do_decode_frame
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__do_decode_frame(
wuffs_thumbhash__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence == 64u) {
} else if (self->private_impl.f_call_sequence < 64u) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_thumbhash__decoder__do_decode_frame_config(self, NULL, a_src);
if (status.repr) {
goto suspend;
}
} else {
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
}
v_status = wuffs_base__pixel_swizzler__prepare(&self->private_impl.f_swizzler,
wuffs_base__pixel_buffer__pixel_format(a_dst),
wuffs_base__pixel_buffer__palette(a_dst),
wuffs_base__utility__make_pixel_format(self->private_impl.f_pixfmt),
wuffs_base__utility__empty_slice_u8(),
a_blend);
if ( ! wuffs_base__status__is_ok(&v_status)) {
status = v_status;
if (wuffs_base__status__is_error(&status)) {
goto exit;
} else if (wuffs_base__status__is_suspension(&status)) {
status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);
goto exit;
}
goto ok;
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
status = wuffs_thumbhash__decoder__from_src_to_pixels(self, a_src);
if (status.repr) {
goto suspend;
}
v_status = wuffs_thumbhash__decoder__from_pixels_to_dst(self, a_dst);
if ( ! wuffs_base__status__is_ok(&v_status)) {
status = v_status;
if (wuffs_base__status__is_error(&status)) {
goto exit;
} else if (wuffs_base__status__is_suspension(&status)) {
status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);
goto exit;
}
goto ok;
}
self->private_impl.f_call_sequence = 96u;
ok:
self->private_impl.p_do_decode_frame = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_do_decode_frame = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
return status;
}
// -------- func thumbhash.decoder.from_src_to_pixels
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__from_src_to_pixels(
wuffs_thumbhash__decoder* self,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_y = 0;
uint32_t v_x = 0;
v_y = 0u;
while (v_y < 32u) {
v_x = 0u;
while (v_x < 32u) {
self->private_data.f_pixels[v_y][((4u * v_x) + 0u)] = ((uint8_t)((v_x * 8u)));
self->private_data.f_pixels[v_y][((4u * v_x) + 1u)] = ((uint8_t)((v_y * 8u)));
self->private_data.f_pixels[v_y][((4u * v_x) + 2u)] = 0u;
self->private_data.f_pixels[v_y][((4u * v_x) + 3u)] = 255u;
v_x += 1u;
}
v_y += 1u;
}
goto ok;
ok:
goto exit;
exit:
return status;
}
// -------- func thumbhash.decoder.from_pixels_to_dst
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__from_pixels_to_dst(
wuffs_thumbhash__decoder* self,
wuffs_base__pixel_buffer* a_dst) {
wuffs_base__pixel_format v_dst_pixfmt = {0};
uint32_t v_dst_bits_per_pixel = 0;
uint32_t v_dst_bytes_per_pixel = 0;
uint64_t v_dst_bytes_per_row = 0;
wuffs_base__table_u8 v_tab = {0};
uint32_t v_y = 0;
wuffs_base__slice_u8 v_dst = {0};
wuffs_base__slice_u8 v_src = {0};
v_dst_pixfmt = wuffs_base__pixel_buffer__pixel_format(a_dst);
v_dst_bits_per_pixel = wuffs_base__pixel_format__bits_per_pixel(&v_dst_pixfmt);
if ((v_dst_bits_per_pixel & 7u) != 0u) {
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
}
v_dst_bytes_per_pixel = (v_dst_bits_per_pixel / 8u);
v_dst_bytes_per_row = ((uint64_t)((self->private_impl.f_width * v_dst_bytes_per_pixel)));
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0u);
while (v_y < self->private_impl.f_height) {
v_src = wuffs_base__make_slice_u8(self->private_data.f_pixels[v_y], (self->private_impl.f_width * 4u));
v_dst = wuffs_private_impl__table_u8__row_u32(v_tab, v_y);
if (v_dst_bytes_per_row < ((uint64_t)(v_dst.len))) {
v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_dst_bytes_per_row);
}
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, wuffs_base__pixel_buffer__palette(a_dst), v_src);
v_y += 1u;
}
return wuffs_base__make_status(NULL);
}
// -------- func thumbhash.decoder.frame_dirty_rect
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32
wuffs_thumbhash__decoder__frame_dirty_rect(
const wuffs_thumbhash__decoder* self) {
if (!self) {
return wuffs_base__utility__empty_rect_ie_u32();
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return wuffs_base__utility__empty_rect_ie_u32();
}
return wuffs_base__utility__make_rect_ie_u32(
0u,
0u,
self->private_impl.f_width,
self->private_impl.f_height);
}
// -------- func thumbhash.decoder.num_animation_loops
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint32_t
wuffs_thumbhash__decoder__num_animation_loops(
const wuffs_thumbhash__decoder* self) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
return 0u;
}
// -------- func thumbhash.decoder.num_decoded_frame_configs
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_thumbhash__decoder__num_decoded_frame_configs(
const wuffs_thumbhash__decoder* self) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
if (self->private_impl.f_call_sequence > 32u) {
return 1u;
}
return 0u;
}
// -------- func thumbhash.decoder.num_decoded_frames
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_thumbhash__decoder__num_decoded_frames(
const wuffs_thumbhash__decoder* self) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
if (self->private_impl.f_call_sequence > 64u) {
return 1u;
}
return 0u;
}
// -------- func thumbhash.decoder.restart_frame
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__restart_frame(
wuffs_thumbhash__decoder* self,
uint64_t a_index,
uint64_t a_io_position) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (self->private_impl.f_call_sequence < 32u) {
return wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
}
if ((a_index != 0u) || (a_io_position != 3u)) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
self->private_impl.f_call_sequence = 40u;
return wuffs_base__make_status(NULL);
}
// -------- func thumbhash.decoder.set_report_metadata
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
wuffs_thumbhash__decoder__set_report_metadata(
wuffs_thumbhash__decoder* self,
uint32_t a_fourcc,
bool a_report) {
return wuffs_base__make_empty_struct();
}
// -------- func thumbhash.decoder.tell_me_more
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__tell_me_more(
wuffs_thumbhash__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_dst || !a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 4)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
status = wuffs_base__make_status(wuffs_base__error__no_more_information);
goto exit;
goto ok;
ok:
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func thumbhash.decoder.workbuf_len
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
wuffs_thumbhash__decoder__workbuf_len(
const wuffs_thumbhash__decoder* self) {
if (!self) {
return wuffs_base__utility__empty_range_ii_u64();
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return wuffs_base__utility__empty_range_ii_u64();
}
return wuffs_base__utility__make_range_ii_u64(0u, 0u);
}
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__THUMBHASH)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__VP8)
// ---------------- Status Codes Implementations
@@ -82037,6 +83305,11 @@ DecodeImageCallbacks::SelectDecoder(uint32_t fourcc,
return wuffs_tga__decoder::alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__THUMBHASH)
case WUFFS_BASE__FOURCC__TH:
return wuffs_thumbhash__decoder::alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WBMP)
case WUFFS_BASE__FOURCC__WBMP:
return wuffs_wbmp__decoder::alloc_as__wuffs_base__image_decoder();
+4
View File
@@ -68,6 +68,7 @@
#define WUFFS_CONFIG__MODULE__PNG
#define WUFFS_CONFIG__MODULE__QOI
#define WUFFS_CONFIG__MODULE__TGA
#define WUFFS_CONFIG__MODULE__THUMBHASH
#define WUFFS_CONFIG__MODULE__VP8
#define WUFFS_CONFIG__MODULE__WBMP
#define WUFFS_CONFIG__MODULE__WEBP
@@ -136,6 +137,9 @@ handle_image_decoder(wuffs_base__io_buffer src,
case WUFFS_BASE__FOURCC__TGA:
dec = wuffs_tga__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__TH:
dec = wuffs_thumbhash__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__WBMP:
dec = wuffs_wbmp__decoder::alloc_as__wuffs_base__image_decoder();
break;
+1
View File
@@ -60,6 +60,7 @@ to use the wuffs_aux C++ API to decode an image and iterate over its pixels.
#define WUFFS_CONFIG__MODULE__PNG
#define WUFFS_CONFIG__MODULE__QOI
#define WUFFS_CONFIG__MODULE__TGA
#define WUFFS_CONFIG__MODULE__THUMBHASH
#define WUFFS_CONFIG__MODULE__WBMP
#define WUFFS_CONFIG__MODULE__ZLIB
+4
View File
@@ -56,6 +56,7 @@ print-image-metadata prints images' metadata.
#define WUFFS_CONFIG__MODULE__PNG
#define WUFFS_CONFIG__MODULE__QOI
#define WUFFS_CONFIG__MODULE__TGA
#define WUFFS_CONFIG__MODULE__THUMBHASH
#define WUFFS_CONFIG__MODULE__VP8
#define WUFFS_CONFIG__MODULE__WBMP
#define WUFFS_CONFIG__MODULE__WEBP
@@ -398,6 +399,9 @@ redirect:
case WUFFS_BASE__FOURCC__TGA:
dec = wuffs_tga__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__TH:
dec = wuffs_thumbhash__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__WBMP:
dec = wuffs_wbmp__decoder::alloc_as__wuffs_base__image_decoder();
break;
+299
View File
@@ -0,0 +1,299 @@
// Copyright 2024 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
// --------
// Thumbhash is a tiny image format (maximum image dimensions are 32×32 pixels;
// maximum image file size is 29 bytes or 32 bytes with a 3-byte header), based
// on the Discrete Cosine Transform.
//
// https://evanw.github.io/thumbhash/ has the original description and
// implementation. This implementation assumes a 3-byte magic identifier is
// prepended, unless QUIRK_JUST_RAW_THUMBHASH is enabled, so that /usr/bin/file
// or similar programs can identify the data as thumbhash-formatted data.
//
// That 3-byte magic string is "\xC3\xBE\xFE", which is arbitrary and not part
// of the original thumbhash description or implementation. But "\xC3\xBE" is
// the UTF-8 encoding of 'þ' (U+00FE LATIN SMALL LETTER THORN) and "\xFE" is
// invalid UTF-8 but is the ISO-8859-1 encoding of 'þ'. The Old English letter
// 'þ' is pronounced like the "th" that starts "thumbhash".
//
// This implementation also uses fixed point math instead of floating point.
pub status "#bad header"
pub status "#truncated input"
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
pub struct decoder? implements base.image_decoder(
pixfmt : base.u32,
width : base.u32[..= 32],
height : base.u32[..= 32],
// The call sequence state machine is discussed in
// (/doc/std/image-decoders-call-sequence.md).
call_sequence : base.u8,
swizzler : base.pixel_swizzler,
util : base.utility,
) + (
pixels : array[32] array[128] base.u8,
)
pub func decoder.get_quirk(key: base.u32) base.u64 {
return 0
}
pub func decoder.set_quirk!(key: base.u32, value: base.u64) base.status {
return base."#unsupported option"
}
pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
var status : base.status
while true {
status =? this.do_decode_image_config?(dst: args.dst, src: args.src)
if (status == base."$short read") and args.src.is_closed() {
return "#truncated input"
}
yield? status
}
}
pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
var c32 : base.u32
if this.call_sequence <> 0x00 {
return base."#bad call sequence"
}
// TODO: implement QUIRK_JUST_RAW_THUMBHASH.
c32 = args.src.read_u24le_as_u32?()
if c32 <> '\xC3\xBE\xFE'le {
return "#bad header"
}
this.pixfmt = base.PIXEL_FORMAT__BGRX
this.width = 32
this.height = 32
if args.dst <> nullptr {
args.dst.set!(
pixfmt: this.pixfmt,
pixsub: 0,
width: this.width,
height: this.height,
first_frame_io_position: 3,
first_frame_is_opaque: this.pixfmt == base.PIXEL_FORMAT__BGRX)
}
this.call_sequence = 0x20
}
pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
var status : base.status
while true {
status =? this.do_decode_frame_config?(dst: args.dst, src: args.src)
if (status == base."$short read") and args.src.is_closed() {
return "#truncated input"
}
yield? status
}
}
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
if this.call_sequence == 0x20 {
// No-op.
} else if this.call_sequence < 0x20 {
this.do_decode_image_config?(dst: nullptr, src: args.src)
} else if this.call_sequence == 0x28 {
if 3 <> args.src.position() {
return base."#bad restart"
}
} else if this.call_sequence == 0x40 {
this.call_sequence = 0x60
return base."@end of data"
} else {
return base."@end of data"
}
if args.dst <> nullptr {
args.dst.set!(bounds: this.util.make_rect_ie_u32(
min_incl_x: 0,
min_incl_y: 0,
max_excl_x: this.width,
max_excl_y: this.height),
duration: 0,
index: 0,
io_position: 3,
disposal: 0,
opaque_within_bounds: this.pixfmt == base.PIXEL_FORMAT__BGRX,
overwrite_instead_of_blend: false,
background_color: 0x0000_0000)
}
this.call_sequence = 0x40
}
pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
var status : base.status
while true {
status =? this.do_decode_frame?(dst: args.dst, src: args.src, blend: args.blend, workbuf: args.workbuf, opts: args.opts)
if (status == base."$short read") and args.src.is_closed() {
return "#truncated input"
}
yield? status
}
}
pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
var status : base.status
if this.call_sequence == 0x40 {
// No-op.
} else if this.call_sequence < 0x40 {
this.do_decode_frame_config?(dst: nullptr, src: args.src)
} else {
return base."@end of data"
}
status = this.swizzler.prepare!(
dst_pixfmt: args.dst.pixel_format(),
dst_palette: args.dst.palette(),
src_pixfmt: this.util.make_pixel_format(repr: this.pixfmt),
src_palette: this.util.empty_slice_u8(),
blend: args.blend)
if not status.is_ok() {
return status
}
this.from_src_to_pixels?(src: args.src)
status = this.from_pixels_to_dst!(dst: args.dst)
if not status.is_ok() {
return status
}
this.call_sequence = 0x60
}
pri func decoder.from_src_to_pixels?(src: base.io_reader) {
var y : base.u32
var x : base.u32
// TODO: actually implement the format. For now, fill in a placeholder
// blue-green gradient.
y = 0
while y < 32 {
x = 0
while x < 32,
inv y < 32,
{
this.pixels[y][(4 * x) + 0] = (x * 8) as base.u8
this.pixels[y][(4 * x) + 1] = (y * 8) as base.u8
this.pixels[y][(4 * x) + 2] = 0x00
this.pixels[y][(4 * x) + 3] = 0xFF
x += 1
}
y += 1
}
}
pri func decoder.from_pixels_to_dst!(dst: ptr base.pixel_buffer) base.status {
var dst_pixfmt : base.pixel_format
var dst_bits_per_pixel : base.u32[..= 256]
var dst_bytes_per_pixel : base.u32[..= 32]
var dst_bytes_per_row : base.u64
var tab : table base.u8
var y : base.u32
var dst : slice base.u8
var src : slice base.u8
// TODO: the dst_pixfmt variable shouldn't be necessary. We should be able
// to chain the two calls: "args.dst.pixel_format().bits_per_pixel()".
dst_pixfmt = args.dst.pixel_format()
dst_bits_per_pixel = dst_pixfmt.bits_per_pixel()
if (dst_bits_per_pixel & 7) <> 0 {
return base."#unsupported option"
}
dst_bytes_per_pixel = dst_bits_per_pixel / 8
dst_bytes_per_row = (this.width * dst_bytes_per_pixel) as base.u64
tab = args.dst.plane(p: 0)
while y < this.height {
assert y < 32 via "a < b: a < c; c <= b"(c: this.height)
src = this.pixels[y][.. this.width * 4]
dst = tab.row_u32(y: y)
if dst_bytes_per_row < dst.length() {
dst = dst[.. dst_bytes_per_row]
}
this.swizzler.swizzle_interleaved_from_slice!(
dst: dst,
dst_palette: args.dst.palette(),
src: src)
y += 1
}
return ok
}
pub func decoder.frame_dirty_rect() base.rect_ie_u32 {
return this.util.make_rect_ie_u32(
min_incl_x: 0,
min_incl_y: 0,
max_excl_x: this.width,
max_excl_y: this.height)
}
pub func decoder.num_animation_loops() base.u32 {
return 0
}
pub func decoder.num_decoded_frame_configs() base.u64 {
if this.call_sequence > 0x20 {
return 1
}
return 0
}
pub func decoder.num_decoded_frames() base.u64 {
if this.call_sequence > 0x40 {
return 1
}
return 0
}
pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.status {
if this.call_sequence < 0x20 {
return base."#bad call sequence"
}
if (args.index <> 0) or (args.io_position <> 3) {
return base."#bad argument"
}
this.call_sequence = 0x28
return ok
}
pub func decoder.set_report_metadata!(fourcc: base.u32, report: base.bool) {
// No-op. Thumbhash doesn't support metadata.
}
pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
return base."#no more information"
}
pub func decoder.workbuf_len() base.range_ii_u64 {
return this.util.make_range_ii_u64(min_incl: 0, max_incl: 0)
}
+191
View File
@@ -0,0 +1,191 @@
// Copyright 2024 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
// ----------------
/*
This test program is typically run indirectly, by the "wuffs test" or "wuffs
bench" commands. These commands take an optional "-mimic" flag to check that
Wuffs' output mimics (i.e. exactly matches) other libraries' output, such as
giflib for GIF, libpng for PNG, etc.
To manually run this test:
for CC in clang gcc; do
$CC -std=c99 -Wall -Werror thumbhash.c && ./a.out
rm -f a.out
done
Each edition should print "PASS", amongst other information, and exit(0).
Add the "wuffs mimic cflags" (everything after the colon below) to the C
compiler flags (after the .c file) to run the mimic tests.
To manually run the benchmarks, replace "-Wall -Werror" with "-O3" and replace
the first "./a.out" with "./a.out -bench". Combine these changes with the
"wuffs mimic cflags" to run the mimic benchmarks.
*/
// ¿ wuffs mimic cflags: -DWUFFS_MIMIC
// Wuffs ships as a "single file C library" or "header file library" as per
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
//
// To use that single file as a "foo.c"-like implementation, instead of a
// "foo.h"-like header, #define WUFFS_IMPLEMENTATION before #include'ing or
// compiling it.
#define WUFFS_IMPLEMENTATION
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
// entire Wuffs standard library, implementing a variety of codecs and file
// formats. Without this macro definition, an optimizing compiler or linker may
// very well discard Wuffs code for unused codecs, but listing the Wuffs
// modules we use makes that process explicit. Preprocessing means that such
// code simply isn't compiled.
#define WUFFS_CONFIG__MODULES
#define WUFFS_CONFIG__MODULE__BASE
#define WUFFS_CONFIG__MODULE__THUMBHASH
// 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.
#include "../../../release/c/wuffs-unsupported-snapshot.c"
#include "../testlib/testlib.c"
#ifdef WUFFS_MIMIC
// No mimic library.
#endif
// ---------------- Thumbhash Tests
const char* //
test_wuffs_thumbhash_decode_interface() {
CHECK_FOCUS(__func__);
wuffs_thumbhash__decoder dec;
CHECK_STATUS("initialize",
wuffs_thumbhash__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
return do_test__wuffs_base__image_decoder(
wuffs_thumbhash__decoder__upcast_as__wuffs_base__image_decoder(&dec),
"test/data/artificial-thumbhash/3OcRJYB4d3h_iIeHeEh3eIhw-j3A.th", 0,
SIZE_MAX, 32, 32, 0xFF00F8F8);
}
const char* //
test_wuffs_thumbhash_decode_truncated_input() {
CHECK_FOCUS(__func__);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader(g_src_array_u8, 0, false);
wuffs_thumbhash__decoder dec;
CHECK_STATUS("initialize",
wuffs_thumbhash__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_base__status status =
wuffs_thumbhash__decoder__decode_image_config(&dec, NULL, &src);
if (status.repr != wuffs_base__suspension__short_read) {
RETURN_FAIL("closed=false: have \"%s\", want \"%s\"", status.repr,
wuffs_base__suspension__short_read);
}
src.meta.closed = true;
status = wuffs_thumbhash__decoder__decode_image_config(&dec, NULL, &src);
if (status.repr != wuffs_thumbhash__error__truncated_input) {
RETURN_FAIL("closed=true: have \"%s\", want \"%s\"", status.repr,
wuffs_thumbhash__error__truncated_input);
}
return NULL;
}
const char* //
test_wuffs_thumbhash_decode_frame_config() {
CHECK_FOCUS(__func__);
wuffs_thumbhash__decoder dec;
CHECK_STATUS("initialize",
wuffs_thumbhash__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_base__frame_config fc = ((wuffs_base__frame_config){});
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
.data = g_src_slice_u8,
});
CHECK_STRING(read_file(
&src, "test/data/artificial-thumbhash/3OcRJYB4d3h_iIeHeEh3eIhw-j3A.th"));
CHECK_STATUS("decode_frame_config #0",
wuffs_thumbhash__decoder__decode_frame_config(&dec, &fc, &src));
wuffs_base__status status =
wuffs_thumbhash__decoder__decode_frame_config(&dec, &fc, &src);
if (status.repr != wuffs_base__note__end_of_data) {
RETURN_FAIL("decode_frame_config #1: have \"%s\", want \"%s\"", status.repr,
wuffs_base__note__end_of_data);
}
return NULL;
}
// ---------------- Mimic Tests
#ifdef WUFFS_MIMIC
// No mimic tests.
#endif // WUFFS_MIMIC
// ---------------- Thumbhash Benches
// No Thumbhash benches.
// ---------------- Mimic Benches
#ifdef WUFFS_MIMIC
// No mimic benches.
#endif // WUFFS_MIMIC
// ---------------- Manifest
proc g_tests[] = {
test_wuffs_thumbhash_decode_frame_config,
test_wuffs_thumbhash_decode_interface,
test_wuffs_thumbhash_decode_truncated_input,
#ifdef WUFFS_MIMIC
// No mimic tests.
#endif // WUFFS_MIMIC
NULL,
};
proc g_benches[] = {
// No Thumbhash benches.
#ifdef WUFFS_MIMIC
// No mimic benches.
#endif // WUFFS_MIMIC
NULL,
};
int //
main(int argc, char** argv) {
g_proc_package_name = "std/thumbhash";
return test_main(argc, argv, g_tests, g_benches);
}
+9
View File
@@ -26,6 +26,15 @@ OK. 96bdbbb3 test/data/artificial-jpeg/hippopotamus-sof-dht-swap.jpeg
OK. 0564b364 test/data/artificial-png/apng-skip-idat.png
OK. e08a7cc8 test/data/artificial-png/exif.png
OK. e08a7cc8 test/data/artificial-png/key-value-pairs.png
OK. 0508510a test/data/artificial-thumbhash/1QcSHQRnh493V4dIh4eXh1h4kJUI.th
OK. 0508510a test/data/artificial-thumbhash/2IqDBQQnxnj0JoLYdM3f8ahpuDeHiHdwZw.th
OK. 0508510a test/data/artificial-thumbhash/2fcZFIB3iId_h3iJh4aIYJ2V8g.th
OK. 0508510a test/data/artificial-thumbhash/3OcRJYB4d3h_iIeHeEh3eIhw-j3A.th
OK. 0508510a test/data/artificial-thumbhash/3PcNNYSFeXh_d3eld0iHZoZgVwh2.th
OK. 0508510a test/data/artificial-thumbhash/HBkSHYSIeHiPiHh8eJd4eTN0EEQG.th
OK. 0508510a test/data/artificial-thumbhash/IQgSLYZ6iHePh4h1eFeHh4dwgwg3.th
OK. 0508510a test/data/artificial-thumbhash/VggKDYAW6lZvdYd6d2iZh_p4GE_k.th
OK. 0508510a test/data/artificial-thumbhash/YJqGPQw7sFlslqhFafSE-Q6oJ1h2iHB2Rw.th
OK. 076cb375 test/data/bricks-color.bmp
OK. bdbbfadb test/data/bricks-color.etc1.pkm
OK. 41e6110e test/data/bricks-color.etc1s.pkm