diff --git a/release/c/wuffs-v0.4.c b/release/c/wuffs-v0.4.c index 0c6616a6..014b1293 100644 --- a/release/c/wuffs-v0.4.c +++ b/release/c/wuffs-v0.4.c @@ -81,15 +81,15 @@ extern "C" { // each major.minor branch, the commit count should increase monotonically. // // WUFFS_VERSION was overridden by "wuffs gen -version" based on revision -// 5d69840f8e7ca481551b02c7e8d4c5fb69521bb9 committed on 2024-08-12. +// a14745aa458fd2b2785034efa04eab3c7b5b91e0 committed on 2024-09-14. #define WUFFS_VERSION 0x000040000 #define WUFFS_VERSION_MAJOR 0 #define WUFFS_VERSION_MINOR 4 #define WUFFS_VERSION_PATCH 0 -#define WUFFS_VERSION_PRE_RELEASE_LABEL "alpha.8" -#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3796 -#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20240812 -#define WUFFS_VERSION_STRING "0.4.0-alpha.8+3796.20240812" +#define WUFFS_VERSION_PRE_RELEASE_LABEL "alpha.9" +#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3837 +#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20240914 +#define WUFFS_VERSION_STRING "0.4.0-alpha.9+3837.20240914" // ---------------- Private Implementation Macros Re-definition Check @@ -119,6 +119,20 @@ extern "C" { #endif +// ---------------- Obsolete Macros Check + +// std/tga was renamed to std/targa in September 2024 (Wuffs v0.4 alpha). +#if defined(WUFFS_CONFIG__MODULE__TGA) + +#if defined(__GNUC__) || defined(__clang__) +#warning "WUFFS_CONFIG__MODULE__TGA was renamed to WUFFS_CONFIG__MODULE__TARGA" +#elif defined(_MSC_VER) +#pragma message( \ + "WUFFS_CONFIG__MODULE__TGA was renamed to WUFFS_CONFIG__MODULE__TARGA") +#endif + +#endif + // ---------------- Configuration // Define WUFFS_CONFIG__AVOID_CPU_ARCH to avoid any code tied to a specific CPU @@ -755,6 +769,12 @@ typedef struct wuffs_base__transform__output__struct { // Wuffs' u32 values are big-endian ("JPEG" is 0x4A504547 not 0x4745504A) to // preserve ordering: "JPEG" < "MP3 " and 0x4A504547 < 0x4D503320. +// Android Binary XML (for resources; see AndroidBinXmlParser.java). +#define WUFFS_BASE__FOURCC__ABXR 0x41425852 + +// Android Binary XML (for system_server; see BinaryXmlSerializer.java). +#define WUFFS_BASE__FOURCC__ABXS 0x41425853 + // Background Color. #define WUFFS_BASE__FOURCC__BGCL 0x4247434C @@ -779,6 +799,9 @@ typedef struct wuffs_base__transform__output__struct { // Encapsulated PostScript. #define WUFFS_BASE__FOURCC__EPS 0x45505320 +// Ericsson Texture Compression 2 (iPACKMAN). +#define WUFFS_BASE__FOURCC__ETC2 0x45544332 + // Exchangeable Image File Format. #define WUFFS_BASE__FOURCC__EXIF 0x45584946 @@ -908,6 +931,9 @@ typedef struct wuffs_base__transform__output__struct { // Truevision Advanced Raster Graphics Adapter. #define WUFFS_BASE__FOURCC__TGA 0x54474120 +// Thumbhash. +#define WUFFS_BASE__FOURCC__TH 0x54482020 + // Tagged Image File Format. #define WUFFS_BASE__FOURCC__TIFF 0x54494646 @@ -4213,6 +4239,46 @@ wuffs_base__color_u32_argb_premul__as__color_u64_argb_nonpremul( return (a16 << 48) | (r16 << 32) | (g16 << 16) | (b16 << 0); } +static inline uint8_t // +wuffs_base__color_u64_argb_premul__as__color_u8_gray(uint64_t argb_premul) { + uint32_t r16 = ((uint32_t)(0xFFFF & (argb_premul >> 32))); + uint32_t g16 = ((uint32_t)(0xFFFF & (argb_premul >> 16))); + uint32_t b16 = ((uint32_t)(0xFFFF & (argb_premul >> 0))); + + // These coefficients (the fractions 0.299, 0.587 and 0.114) are the same + // as those given by the JFIF specification. + // + // Note that 19595 + 38470 + 7471 equals 65536, also known as (1 << 16). We + // shift by 24, not just by 16, because the return value is 8-bit color, not + // 16-bit color. + uint32_t weighted_average = + (19595 * r16) + (38470 * g16) + (7471 * b16) + 32768; + return (uint8_t)(weighted_average >> 24); +} + +static inline uint8_t // +wuffs_base__color_u64_argb_nonpremul__as__color_u8_gray( + uint64_t argb_nonpremul) { + uint32_t a16 = ((uint32_t)(0xFFFF & (argb_nonpremul >> 48))); + + uint32_t r16 = ((uint32_t)(0xFFFF & (argb_nonpremul >> 32))); + r16 = (r16 * a16) / 0xFFFF; + uint32_t g16 = ((uint32_t)(0xFFFF & (argb_nonpremul >> 16))); + g16 = (g16 * a16) / 0xFFFF; + uint32_t b16 = ((uint32_t)(0xFFFF & (argb_nonpremul >> 0))); + b16 = (b16 * a16) / 0xFFFF; + + // These coefficients (the fractions 0.299, 0.587 and 0.114) are the same + // as those given by the JFIF specification. + // + // Note that 19595 + 38470 + 7471 equals 65536, also known as (1 << 16). We + // shift by 24, not just by 16, because the return value is 8-bit color, not + // 16-bit color. + uint32_t weighted_average = + (19595 * r16) + (38470 * g16) + (7471 * b16) + 32768; + return (uint8_t)(weighted_average >> 24); +} + static inline uint64_t // wuffs_base__color_u32__as__color_u64(uint32_t c) { uint64_t a16 = 0x101 * (0xFF & (c >> 24)); @@ -4335,6 +4401,20 @@ typedef uint32_t wuffs_base__pixel_alpha_transparency; // -------- +// wuffs_base__pixel_coloration is whether a pixel format's color model has no +// color (alpha only), gray color or rich (non-gray) color. Rich color includes +// RGB, BGR, YCC, YCCK, CMY and CMYK. +// +// Coloration does not capture the alpha aspect of the color model. It does not +// distinguish RGB from RGBA. +typedef uint32_t wuffs_base__pixel_coloration; + +#define WUFFS_BASE__PIXEL_COLORATION__NONE 0 +#define WUFFS_BASE__PIXEL_COLORATION__GRAY 1 +#define WUFFS_BASE__PIXEL_COLORATION__RICH 3 + +// -------- + // Deprecated: use WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX_INCL. #define WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX 4 @@ -4363,6 +4443,7 @@ typedef struct wuffs_base__pixel_format__struct { inline bool is_indexed() const; inline bool is_interleaved() const; inline bool is_planar() const; + inline uint32_t coloration() const; inline uint32_t num_planes() const; inline wuffs_base__pixel_alpha_transparency transparency() const; #endif // __cplusplus @@ -4469,6 +4550,12 @@ wuffs_base__pixel_format__is_planar(const wuffs_base__pixel_format* f) { return ((f->repr >> 16) & 0x03) != 0; } +static inline uint32_t // +wuffs_base__pixel_format__coloration(const wuffs_base__pixel_format* f) { + uint32_t n = (f->repr) >> 29; + return (n <= 1) ? n : 3; +} + static inline uint32_t // wuffs_base__pixel_format__num_planes(const wuffs_base__pixel_format* f) { return ((f->repr >> 16) & 0x03) + 1; @@ -4511,6 +4598,11 @@ wuffs_base__pixel_format::is_planar() const { return wuffs_base__pixel_format__is_planar(this); } +inline uint32_t // +wuffs_base__pixel_format::coloration() const { + return wuffs_base__pixel_format__coloration(this); +} + inline uint32_t // wuffs_base__pixel_format::num_planes() const { return wuffs_base__pixel_format__num_planes(this); @@ -7963,7 +8055,7 @@ extern const char wuffs_cbor__error__unsupported_recursion_depth[]; #define WUFFS_CBOR__DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL 9u -#define WUFFS_CBOR__TOKEN_VALUE_MAJOR 787997u +#define WUFFS_CBOR__TOKEN_VALUE_MAJOR 731642u #define WUFFS_CBOR__TOKEN_VALUE_MINOR__DETAIL_MASK 262143u @@ -8936,6 +9028,372 @@ struct wuffs_deflate__decoder__struct { #endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__DEFLATE) || defined(WUFFS_NONMONOLITHIC) +#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ETC2) || defined(WUFFS_NONMONOLITHIC) + +// ---------------- Status Codes + +extern const char wuffs_etc2__error__bad_header[]; +extern const char wuffs_etc2__error__truncated_input[]; +extern const char wuffs_etc2__error__unsupported_etc2_file[]; + +// ---------------- Public Consts + +#define WUFFS_ETC2__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0u + +// ---------------- Struct Declarations + +typedef struct wuffs_etc2__decoder__struct wuffs_etc2__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_etc2__decoder__initialize( + wuffs_etc2__decoder* self, + size_t sizeof_star_self, + uint64_t wuffs_version, + uint32_t options); + +size_t +sizeof__wuffs_etc2__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. + +wuffs_etc2__decoder* +wuffs_etc2__decoder__alloc(void); + +static inline wuffs_base__image_decoder* +wuffs_etc2__decoder__alloc_as__wuffs_base__image_decoder(void) { + return (wuffs_base__image_decoder*)(wuffs_etc2__decoder__alloc()); +} + +// ---------------- Upcasts + +static inline wuffs_base__image_decoder* +wuffs_etc2__decoder__upcast_as__wuffs_base__image_decoder( + wuffs_etc2__decoder* p) { + return (wuffs_base__image_decoder*)p; +} + +// ---------------- Public Function Prototypes + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC uint64_t +wuffs_etc2__decoder__get_quirk( + const wuffs_etc2__decoder* self, + uint32_t a_key); + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_etc2__decoder__set_quirk( + wuffs_etc2__decoder* self, + uint32_t a_key, + uint64_t a_value); + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_etc2__decoder__decode_image_config( + wuffs_etc2__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_etc2__decoder__decode_frame_config( + wuffs_etc2__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_etc2__decoder__decode_frame( + wuffs_etc2__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_etc2__decoder__frame_dirty_rect( + const wuffs_etc2__decoder* self); + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC uint32_t +wuffs_etc2__decoder__num_animation_loops( + const wuffs_etc2__decoder* self); + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC uint64_t +wuffs_etc2__decoder__num_decoded_frame_configs( + const wuffs_etc2__decoder* self); + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC uint64_t +wuffs_etc2__decoder__num_decoded_frames( + const wuffs_etc2__decoder* self); + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_etc2__decoder__restart_frame( + wuffs_etc2__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_etc2__decoder__set_report_metadata( + wuffs_etc2__decoder* self, + uint32_t a_fourcc, + bool a_report); + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_etc2__decoder__tell_me_more( + wuffs_etc2__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_etc2__decoder__workbuf_len( + const wuffs_etc2__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_etc2__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; + bool f_srgb; + uint32_t f_num_buffered_blocks; + uint32_t f_dst_x; + uint32_t f_dst_y; + 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; + uint32_t p_from_src_to_colors; + } private_impl; + + struct { + uint64_t f_alphas[64]; + uint64_t f_colors[64]; + uint8_t f_buffer[4096]; + + struct { + uint16_t v_rounded_up_width; + uint16_t v_rounded_up_height; + uint64_t scratch; + } s_do_decode_image_config; + struct { + uint32_t v_remaining; + } s_do_decode_frame; + struct { + uint32_t v_bi; + uint64_t scratch; + } s_from_src_to_colors; + } private_data; + +#ifdef __cplusplus +#if defined(WUFFS_BASE__HAVE_UNIQUE_PTR) + using unique_ptr = std::unique_ptr; + + // On failure, the alloc_etc functions return nullptr. They don't throw. + + static inline unique_ptr + alloc() { + return unique_ptr(wuffs_etc2__decoder__alloc()); + } + + static inline wuffs_base__image_decoder::unique_ptr + alloc_as__wuffs_base__image_decoder() { + return wuffs_base__image_decoder::unique_ptr( + wuffs_etc2__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_etc2__decoder__struct() = delete; + wuffs_etc2__decoder__struct(const wuffs_etc2__decoder__struct&) = delete; + wuffs_etc2__decoder__struct& operator=( + const wuffs_etc2__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_etc2__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_etc2__decoder__get_quirk(this, a_key); + } + + inline wuffs_base__status + set_quirk( + uint32_t a_key, + uint64_t a_value) { + return wuffs_etc2__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_etc2__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_etc2__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_etc2__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_etc2__decoder__frame_dirty_rect(this); + } + + inline uint32_t + num_animation_loops() const { + return wuffs_etc2__decoder__num_animation_loops(this); + } + + inline uint64_t + num_decoded_frame_configs() const { + return wuffs_etc2__decoder__num_decoded_frame_configs(this); + } + + inline uint64_t + num_decoded_frames() const { + return wuffs_etc2__decoder__num_decoded_frames(this); + } + + inline wuffs_base__status + restart_frame( + uint64_t a_index, + uint64_t a_io_position) { + return wuffs_etc2__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_etc2__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_etc2__decoder__tell_me_more(this, a_dst, a_minfo, a_src); + } + + inline wuffs_base__range_ii_u64 + workbuf_len() const { + return wuffs_etc2__decoder__workbuf_len(this); + } + +#endif // __cplusplus +}; // struct wuffs_etc2__decoder__struct + +#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION) + +#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ETC2) || defined(WUFFS_NONMONOLITHIC) + #if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GIF) || defined(WUFFS_NONMONOLITHIC) // ---------------- Status Codes @@ -8953,19 +9411,19 @@ extern const char wuffs_gif__error__truncated_input[]; #define WUFFS_GIF__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0u -#define WUFFS_GIF__QUIRK_DELAY_NUM_DECODED_FRAMES 1041635328u +#define WUFFS_GIF__QUIRK_DELAY_NUM_DECODED_FRAMES 983928832u -#define WUFFS_GIF__QUIRK_FIRST_FRAME_LOCAL_PALETTE_MEANS_BLACK_BACKGROUND 1041635329u +#define WUFFS_GIF__QUIRK_FIRST_FRAME_LOCAL_PALETTE_MEANS_BLACK_BACKGROUND 983928833u -#define WUFFS_GIF__QUIRK_HONOR_BACKGROUND_COLOR 1041635330u +#define WUFFS_GIF__QUIRK_HONOR_BACKGROUND_COLOR 983928834u -#define WUFFS_GIF__QUIRK_IGNORE_TOO_MUCH_PIXEL_DATA 1041635331u +#define WUFFS_GIF__QUIRK_IGNORE_TOO_MUCH_PIXEL_DATA 983928835u -#define WUFFS_GIF__QUIRK_IMAGE_BOUNDS_ARE_STRICT 1041635332u +#define WUFFS_GIF__QUIRK_IMAGE_BOUNDS_ARE_STRICT 983928836u -#define WUFFS_GIF__QUIRK_REJECT_EMPTY_FRAME 1041635333u +#define WUFFS_GIF__QUIRK_REJECT_EMPTY_FRAME 983928837u -#define WUFFS_GIF__QUIRK_REJECT_EMPTY_PALETTE 1041635334u +#define WUFFS_GIF__QUIRK_REJECT_EMPTY_PALETTE 983928838u // ---------------- Struct Declarations @@ -9666,6 +10124,7 @@ extern const char wuffs_jpeg__error__bad_scan_count[]; extern const char wuffs_jpeg__error__missing_huffman_table[]; extern const char wuffs_jpeg__error__missing_quantization_table[]; extern const char wuffs_jpeg__error__rejected_progressive_jpeg[]; +extern const char wuffs_jpeg__error__short_sos_bitstream[]; extern const char wuffs_jpeg__error__truncated_input[]; extern const char wuffs_jpeg__error__unsupported_arithmetic_coding[]; extern const char wuffs_jpeg__error__unsupported_color_model[]; @@ -9683,7 +10142,7 @@ extern const char wuffs_jpeg__error__unsupported_scan_count[]; #define WUFFS_JPEG__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 51552191232u -#define WUFFS_JPEG__QUIRK_REJECT_PROGRESSIVE_JPEGS 1220532224u +#define WUFFS_JPEG__QUIRK_REJECT_PROGRESSIVE_JPEGS 1162824704u // ---------------- Struct Declarations @@ -10181,45 +10640,45 @@ extern const char wuffs_json__error__unsupported_recursion_depth[]; #define WUFFS_JSON__DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL 100u -#define WUFFS_JSON__QUIRK_ALLOW_ASCII_CONTROL_CODES 1225364480u +#define WUFFS_JSON__QUIRK_ALLOW_ASCII_CONTROL_CODES 1167656960u -#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_A 1225364481u +#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_A 1167656961u -#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_CAPITAL_U 1225364482u +#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_CAPITAL_U 1167656962u -#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_E 1225364483u +#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_E 1167656963u -#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_NEW_LINE 1225364484u +#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_NEW_LINE 1167656964u -#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_QUESTION_MARK 1225364485u +#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_QUESTION_MARK 1167656965u -#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_SINGLE_QUOTE 1225364486u +#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_SINGLE_QUOTE 1167656966u -#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_V 1225364487u +#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_V 1167656967u -#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_X_AS_CODE_POINTS 1225364489u +#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_X_AS_CODE_POINTS 1167656969u -#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_ZERO 1225364490u +#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_ZERO 1167656970u -#define WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK 1225364491u +#define WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK 1167656971u -#define WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE 1225364492u +#define WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE 1167656972u -#define WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA 1225364493u +#define WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA 1167656973u -#define WUFFS_JSON__QUIRK_ALLOW_INF_NAN_NUMBERS 1225364494u +#define WUFFS_JSON__QUIRK_ALLOW_INF_NAN_NUMBERS 1167656974u -#define WUFFS_JSON__QUIRK_ALLOW_LEADING_ASCII_RECORD_SEPARATOR 1225364495u +#define WUFFS_JSON__QUIRK_ALLOW_LEADING_ASCII_RECORD_SEPARATOR 1167656975u -#define WUFFS_JSON__QUIRK_ALLOW_LEADING_UNICODE_BYTE_ORDER_MARK 1225364496u +#define WUFFS_JSON__QUIRK_ALLOW_LEADING_UNICODE_BYTE_ORDER_MARK 1167656976u -#define WUFFS_JSON__QUIRK_ALLOW_TRAILING_FILLER 1225364497u +#define WUFFS_JSON__QUIRK_ALLOW_TRAILING_FILLER 1167656977u -#define WUFFS_JSON__QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF 1225364498u +#define WUFFS_JSON__QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF 1167656978u -#define WUFFS_JSON__QUIRK_JSON_POINTER_ALLOW_TILDE_N_TILDE_R_TILDE_T 1225364499u +#define WUFFS_JSON__QUIRK_JSON_POINTER_ALLOW_TILDE_N_TILDE_R_TILDE_T 1167656979u -#define WUFFS_JSON__QUIRK_REPLACE_INVALID_UNICODE 1225364500u +#define WUFFS_JSON__QUIRK_REPLACE_INVALID_UNICODE 1167656980u // ---------------- Struct Declarations @@ -10465,9 +10924,9 @@ extern const char wuffs_lzma__error__unsupported_properties[]; #define WUFFS_LZMA__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 4294967568u -#define WUFFS_LZMA__QUIRK_ALLOW_NON_ZERO_INITIAL_BYTE 1348001792u +#define WUFFS_LZMA__QUIRK_ALLOW_NON_ZERO_INITIAL_BYTE 1290294272u -#define WUFFS_LZMA__QUIRK_FORMAT_EXTENSION 1348001793u +#define WUFFS_LZMA__QUIRK_FORMAT_EXTENSION 1290294273u // ---------------- Struct Declarations @@ -11026,7 +11485,7 @@ extern const char wuffs_lzw__error__truncated_input[]; #define WUFFS_LZW__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0u -#define WUFFS_LZW__QUIRK_LITERAL_WIDTH_PLUS_ONE 1348378624u +#define WUFFS_LZW__QUIRK_LITERAL_WIDTH_PLUS_ONE 1290672128u // ---------------- Struct Declarations @@ -11982,7 +12441,7 @@ extern const char wuffs_zlib__error__truncated_input[]; // ---------------- Public Consts -#define WUFFS_ZLIB__QUIRK_JUST_RAW_DEFLATE 2113790976u +#define WUFFS_ZLIB__QUIRK_JUST_RAW_DEFLATE 2056083456u #define WUFFS_ZLIB__DECODER_DST_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE 0u @@ -13343,22 +13802,22 @@ struct wuffs_sha256__hasher__struct { #endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__SHA256) || defined(WUFFS_NONMONOLITHIC) -#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA) || defined(WUFFS_NONMONOLITHIC) +#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TARGA) || defined(WUFFS_NONMONOLITHIC) // ---------------- Status Codes -extern const char wuffs_tga__error__bad_header[]; -extern const char wuffs_tga__error__bad_run_length_encoding[]; -extern const char wuffs_tga__error__truncated_input[]; -extern const char wuffs_tga__error__unsupported_tga_file[]; +extern const char wuffs_targa__error__bad_header[]; +extern const char wuffs_targa__error__bad_run_length_encoding[]; +extern const char wuffs_targa__error__truncated_input[]; +extern const char wuffs_targa__error__unsupported_targa_file[]; // ---------------- Public Consts -#define WUFFS_TGA__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0u +#define WUFFS_TARGA__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0u // ---------------- Struct Declarations -typedef struct wuffs_tga__decoder__struct wuffs_tga__decoder; +typedef struct wuffs_targa__decoder__struct wuffs_targa__decoder; #ifdef __cplusplus extern "C" { @@ -13373,14 +13832,14 @@ extern "C" { // Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for options. wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT -wuffs_tga__decoder__initialize( - wuffs_tga__decoder* self, +wuffs_targa__decoder__initialize( + wuffs_targa__decoder* self, size_t sizeof_star_self, uint64_t wuffs_version, uint32_t options); size_t -sizeof__wuffs_tga__decoder(void); +sizeof__wuffs_targa__decoder(void); // ---------------- Allocs @@ -13390,19 +13849,19 @@ sizeof__wuffs_tga__decoder(void); // calling free on the returned pointer. That pointer is effectively a C++ // std::unique_ptr. -wuffs_tga__decoder* -wuffs_tga__decoder__alloc(void); +wuffs_targa__decoder* +wuffs_targa__decoder__alloc(void); static inline wuffs_base__image_decoder* -wuffs_tga__decoder__alloc_as__wuffs_base__image_decoder(void) { - return (wuffs_base__image_decoder*)(wuffs_tga__decoder__alloc()); +wuffs_targa__decoder__alloc_as__wuffs_base__image_decoder(void) { + return (wuffs_base__image_decoder*)(wuffs_targa__decoder__alloc()); } // ---------------- Upcasts static inline wuffs_base__image_decoder* -wuffs_tga__decoder__upcast_as__wuffs_base__image_decoder( - wuffs_tga__decoder* p) { +wuffs_targa__decoder__upcast_as__wuffs_base__image_decoder( + wuffs_targa__decoder* p) { return (wuffs_base__image_decoder*)p; } @@ -13410,35 +13869,35 @@ wuffs_tga__decoder__upcast_as__wuffs_base__image_decoder( WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC uint64_t -wuffs_tga__decoder__get_quirk( - const wuffs_tga__decoder* self, +wuffs_targa__decoder__get_quirk( + const wuffs_targa__decoder* self, uint32_t a_key); WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_tga__decoder__set_quirk( - wuffs_tga__decoder* self, +wuffs_targa__decoder__set_quirk( + wuffs_targa__decoder* self, uint32_t a_key, uint64_t a_value); WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_tga__decoder__decode_image_config( - wuffs_tga__decoder* self, +wuffs_targa__decoder__decode_image_config( + wuffs_targa__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_tga__decoder__decode_frame_config( - wuffs_tga__decoder* self, +wuffs_targa__decoder__decode_frame_config( + wuffs_targa__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_tga__decoder__decode_frame( - wuffs_tga__decoder* self, +wuffs_targa__decoder__decode_frame( + wuffs_targa__decoder* self, wuffs_base__pixel_buffer* a_dst, wuffs_base__io_buffer* a_src, wuffs_base__pixel_blend a_blend, @@ -13447,50 +13906,50 @@ wuffs_tga__decoder__decode_frame( WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32 -wuffs_tga__decoder__frame_dirty_rect( - const wuffs_tga__decoder* self); +wuffs_targa__decoder__frame_dirty_rect( + const wuffs_targa__decoder* self); WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC uint32_t -wuffs_tga__decoder__num_animation_loops( - const wuffs_tga__decoder* self); +wuffs_targa__decoder__num_animation_loops( + const wuffs_targa__decoder* self); WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC uint64_t -wuffs_tga__decoder__num_decoded_frame_configs( - const wuffs_tga__decoder* self); +wuffs_targa__decoder__num_decoded_frame_configs( + const wuffs_targa__decoder* self); WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC uint64_t -wuffs_tga__decoder__num_decoded_frames( - const wuffs_tga__decoder* self); +wuffs_targa__decoder__num_decoded_frames( + const wuffs_targa__decoder* self); WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_tga__decoder__restart_frame( - wuffs_tga__decoder* self, +wuffs_targa__decoder__restart_frame( + wuffs_targa__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_tga__decoder__set_report_metadata( - wuffs_tga__decoder* self, +wuffs_targa__decoder__set_report_metadata( + wuffs_targa__decoder* self, uint32_t a_fourcc, bool a_report); WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_tga__decoder__tell_me_more( - wuffs_tga__decoder* self, +wuffs_targa__decoder__tell_me_more( + wuffs_targa__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_tga__decoder__workbuf_len( - const wuffs_tga__decoder* self); +wuffs_targa__decoder__workbuf_len( + const wuffs_targa__decoder* self); #ifdef __cplusplus } // extern "C" @@ -13505,7 +13964,7 @@ wuffs_tga__decoder__workbuf_len( #if defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION) -struct wuffs_tga__decoder__struct { +struct wuffs_targa__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. @@ -13569,19 +14028,19 @@ struct wuffs_tga__decoder__struct { #ifdef __cplusplus #if defined(WUFFS_BASE__HAVE_UNIQUE_PTR) - using unique_ptr = std::unique_ptr; + using unique_ptr = std::unique_ptr; // On failure, the alloc_etc functions return nullptr. They don't throw. static inline unique_ptr alloc() { - return unique_ptr(wuffs_tga__decoder__alloc()); + return unique_ptr(wuffs_targa__decoder__alloc()); } static inline wuffs_base__image_decoder::unique_ptr alloc_as__wuffs_base__image_decoder() { return wuffs_base__image_decoder::unique_ptr( - wuffs_tga__decoder__alloc_as__wuffs_base__image_decoder()); + wuffs_targa__decoder__alloc_as__wuffs_base__image_decoder()); } #endif // defined(WUFFS_BASE__HAVE_UNIQUE_PTR) @@ -13597,10 +14056,10 @@ struct wuffs_tga__decoder__struct { // 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_tga__decoder__struct() = delete; - wuffs_tga__decoder__struct(const wuffs_tga__decoder__struct&) = delete; - wuffs_tga__decoder__struct& operator=( - const wuffs_tga__decoder__struct&) = delete; + wuffs_targa__decoder__struct() = delete; + wuffs_targa__decoder__struct(const wuffs_targa__decoder__struct&) = delete; + wuffs_targa__decoder__struct& operator=( + const wuffs_targa__decoder__struct&) = delete; #endif // defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION) #if !defined(WUFFS_IMPLEMENTATION) @@ -13620,7 +14079,7 @@ struct wuffs_tga__decoder__struct { size_t sizeof_star_self, uint64_t wuffs_version, uint32_t options) { - return wuffs_tga__decoder__initialize( + return wuffs_targa__decoder__initialize( this, sizeof_star_self, wuffs_version, options); } @@ -13632,28 +14091,28 @@ struct wuffs_tga__decoder__struct { inline uint64_t get_quirk( uint32_t a_key) const { - return wuffs_tga__decoder__get_quirk(this, a_key); + return wuffs_targa__decoder__get_quirk(this, a_key); } inline wuffs_base__status set_quirk( uint32_t a_key, uint64_t a_value) { - return wuffs_tga__decoder__set_quirk(this, a_key, a_value); + return wuffs_targa__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_tga__decoder__decode_image_config(this, a_dst, a_src); + return wuffs_targa__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_tga__decoder__decode_frame_config(this, a_dst, a_src); + return wuffs_targa__decoder__decode_frame_config(this, a_dst, a_src); } inline wuffs_base__status @@ -13663,41 +14122,41 @@ struct wuffs_tga__decoder__struct { wuffs_base__pixel_blend a_blend, wuffs_base__slice_u8 a_workbuf, wuffs_base__decode_frame_options* a_opts) { - return wuffs_tga__decoder__decode_frame(this, a_dst, a_src, a_blend, a_workbuf, a_opts); + return wuffs_targa__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_tga__decoder__frame_dirty_rect(this); + return wuffs_targa__decoder__frame_dirty_rect(this); } inline uint32_t num_animation_loops() const { - return wuffs_tga__decoder__num_animation_loops(this); + return wuffs_targa__decoder__num_animation_loops(this); } inline uint64_t num_decoded_frame_configs() const { - return wuffs_tga__decoder__num_decoded_frame_configs(this); + return wuffs_targa__decoder__num_decoded_frame_configs(this); } inline uint64_t num_decoded_frames() const { - return wuffs_tga__decoder__num_decoded_frames(this); + return wuffs_targa__decoder__num_decoded_frames(this); } inline wuffs_base__status restart_frame( uint64_t a_index, uint64_t a_io_position) { - return wuffs_tga__decoder__restart_frame(this, a_index, a_io_position); + return wuffs_targa__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_tga__decoder__set_report_metadata(this, a_fourcc, a_report); + return wuffs_targa__decoder__set_report_metadata(this, a_fourcc, a_report); } inline wuffs_base__status @@ -13705,20 +14164,397 @@ struct wuffs_tga__decoder__struct { wuffs_base__io_buffer* a_dst, wuffs_base__more_information* a_minfo, wuffs_base__io_buffer* a_src) { - return wuffs_tga__decoder__tell_me_more(this, a_dst, a_minfo, a_src); + return wuffs_targa__decoder__tell_me_more(this, a_dst, a_minfo, a_src); } inline wuffs_base__range_ii_u64 workbuf_len() const { - return wuffs_tga__decoder__workbuf_len(this); + return wuffs_targa__decoder__workbuf_len(this); } #endif // __cplusplus -}; // struct wuffs_tga__decoder__struct +}; // struct wuffs_targa__decoder__struct #endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION) -#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA) || defined(WUFFS_NONMONOLITHIC) +#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TARGA) || 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__QUIRK_JUST_RAW_THUMBHASH 1712283648u + +#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. + +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; + uint8_t f_w_dimension_code; + uint8_t f_h_dimension_code; + uint8_t f_call_sequence; + uint8_t f_frame_config_io_position; + uint64_t f_l_dc; + uint64_t f_p_dc; + uint64_t f_q_dc; + uint64_t f_a_dc; + bool f_quirk_just_raw_thumbhash; + uint8_t f_l_scale; + uint8_t f_p_scale; + uint8_t f_q_scale; + uint8_t f_a_scale; + uint8_t f_has_alpha; + uint8_t f_l_count; + uint8_t f_is_landscape; + uint32_t f_lx; + uint32_t f_ly; + 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; + uint32_t p_from_src_to_coeffs; + } private_impl; + + struct { + uint32_t f_lac[32]; + uint32_t f_pac[8]; + uint32_t f_qac[8]; + uint32_t f_aac[16]; + uint8_t f_pixels[32][128]; + + struct { + uint64_t scratch; + } s_do_decode_image_config; + struct { + uint32_t v_cy; + uint32_t v_cx; + uint32_t v_i; + bool v_has_bits; + } s_from_src_to_coeffs; + } private_data; + +#ifdef __cplusplus +#if defined(WUFFS_BASE__HAVE_UNIQUE_PTR) + using unique_ptr = std::unique_ptr; + + // 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) @@ -15134,7 +15970,7 @@ extern const char wuffs_xz__error__unsupported_filter_combination[]; // ---------------- Public Consts -#define WUFFS_XZ__QUIRK_DECODE_STANDALONE_CONCATENATED_STREAMS 2021322752u +#define WUFFS_XZ__QUIRK_DECODE_STANDALONE_CONCATENATED_STREAMS 1963655168u #define WUFFS_XZ__DECODER_DST_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE 0u @@ -15723,19 +16559,26 @@ class DecodeImageCallbacks { // // The default SelectDecoder accepts the FOURCC codes listed below. For // modular builds (i.e. when #define'ing WUFFS_CONFIG__MODULES), acceptance - // of the ETC file format is optional (for each value of ETC) and depends on + // 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__ETC). + // WUFFS_CONFIG__MODULE__FOO). + // // - WUFFS_BASE__FOURCC__BMP + // - WUFFS_BASE__FOURCC__ETC2 // - WUFFS_BASE__FOURCC__GIF // - WUFFS_BASE__FOURCC__JPEG // - WUFFS_BASE__FOURCC__NIE // - WUFFS_BASE__FOURCC__NPBM // - WUFFS_BASE__FOURCC__PNG // - WUFFS_BASE__FOURCC__QOI - // - WUFFS_BASE__FOURCC__TGA + // - WUFFS_BASE__FOURCC__TARGA + // - 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, @@ -15744,8 +16587,8 @@ class DecodeImageCallbacks { // HandleMetadata acknowledges image metadata. minfo.flavor will be one of: // - WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH // - WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_PARSED - // If it is ETC__METADATA_RAW_ETC then raw contains the metadata bytes. Those - // bytes should not be retained beyond the the HandleMetadata call. + // If it is METADATA_RAW_PASSTHROUGH then raw contains the metadata bytes. + // Those bytes should not be retained beyond the the HandleMetadata call. // // minfo.metadata__fourcc() will typically match one of the // DecodeImageArgFlags bits. For example, if (REPORT_METADATA_CHRM | @@ -15759,6 +16602,7 @@ class DecodeImageCallbacks { // SelectPixfmt returns the destination pixel format for AllocPixbuf. It // should return wuffs_base__make_pixel_format(etc) called with one of: + // - WUFFS_BASE__PIXEL_FORMAT__Y // - WUFFS_BASE__PIXEL_FORMAT__BGR_565 // - WUFFS_BASE__PIXEL_FORMAT__BGR // - WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL @@ -15861,7 +16705,7 @@ struct DecodeImageArgFlags { // DefaultValue returns 0. static DecodeImageArgFlags DefaultValue(); - // TODO: support all of the REPORT_METADATA_ETC flags, not just CHRM, EXIF, + // TODO: support all of the REPORT_METADATA_FOO flags, not just CHRM, EXIF, // GAMA, ICCP, KVP, SRGB and XMP. // Background Color. @@ -16108,6 +16952,131 @@ DecodeJson(DecodeJsonCallbacks& callbacks, #endif // defined(__cplusplus) && defined(WUFFS_BASE__HAVE_UNIQUE_PTR) +// ---------------- Wuffs' reimplementation of the STB API. +// +// This is a drop-in replacement of that third-party library. +// +// Disabled by default, unless you #define the +// WUFFS_CONFIG__ENABLE_DROP_IN_REPLACEMENT__STB macro beforehand. +// +// For API docs, see https://github.com/nothings/stb + +#if defined(WUFFS_CONFIG__ENABLE_DROP_IN_REPLACEMENT__STB) + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(WUFFS_CONFIG__STATIC_FUNCTIONS) || defined(STB_IMAGE_STATIC) +#define WUFFS_DROP_IN__STB__MAYBE_STATIC static +#else +#define WUFFS_DROP_IN__STB__MAYBE_STATIC +#endif + +enum { + STBI_default = 0, + STBI_grey = 1, + STBI_grey_alpha = 2, + STBI_rgb = 3, + STBI_rgb_alpha = 4 +}; + +typedef unsigned char stbi_uc; +typedef unsigned short stbi_us; + +typedef struct { + int (*read)(void* user, char* data, int size); + void (*skip)(void* user, int n); + int (*eof)(void* user); +} stbi_io_callbacks; + +// -------- + +WUFFS_DROP_IN__STB__MAYBE_STATIC int // +stbi_info_from_memory( // + stbi_uc const* buffer, // + int len, // + int* x, // + int* y, // + int* comp); + +WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* // +stbi_load_from_memory( // + stbi_uc const* buffer, // + int len, // + int* x, // + int* y, // + int* channels_in_file, // + int desired_channels); + +WUFFS_DROP_IN__STB__MAYBE_STATIC int // +stbi_info_from_callbacks( // + stbi_io_callbacks const* clbk, // + void* user, // + int* x, // + int* y, // + int* comp); + +WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* // +stbi_load_from_callbacks( // + stbi_io_callbacks const* clbk, // + void* user, // + int* x, // + int* y, // + int* channels_in_file, // + int desired_channels); + +// -------- + +#if !defined(STBI_NO_STDIO) + +WUFFS_DROP_IN__STB__MAYBE_STATIC int // +stbi_info( // + char const* filename, // + int* x, // + int* y, // + int* comp); + +WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* // +stbi_load( // + char const* filename, // + int* x, // + int* y, // + int* channels_in_file, // + int desired_channels); + +WUFFS_DROP_IN__STB__MAYBE_STATIC int // +stbi_info_from_file( // + FILE* f, // + int* x, // + int* y, // + int* comp); + +WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* // +stbi_load_from_file( // + FILE* f, // + int* x, // + int* y, // + int* channels_in_file, // + int desired_channels); + +#endif // !defined(STBI_NO_STDIO) + +// -------- + +WUFFS_DROP_IN__STB__MAYBE_STATIC void // +stbi_image_free( // + void* retval_from_stbi_load); + +WUFFS_DROP_IN__STB__MAYBE_STATIC const char* // +stbi_failure_reason(void); + +#ifdef __cplusplus +} +#endif + +#endif // defined (WUFFS_CONFIG__ENABLE_DROP_IN_REPLACEMENT__STB) + // ‼ WUFFS C HEADER ENDS HERE. #ifdef WUFFS_IMPLEMENTATION @@ -16280,12 +17249,24 @@ wuffs_private_impl__u64__sat_sub_indirect(uint64_t* x, uint64_t y) { // ---------------- Numeric Types (Utility) +#define wuffs_base__utility__i64_divide(a, b) \ + ((uint64_t)(((int64_t)(a)) / ((int64_t)(b)))) + #define wuffs_base__utility__sign_extend_convert_u8_u32(a) \ ((uint32_t)(int32_t)(int8_t)(a)) +#define wuffs_base__utility__sign_extend_convert_u8_u64(a) \ + ((uint64_t)(int64_t)(int8_t)(a)) + #define wuffs_base__utility__sign_extend_convert_u16_u32(a) \ ((uint32_t)(int32_t)(int16_t)(a)) +#define wuffs_base__utility__sign_extend_convert_u16_u64(a) \ + ((uint64_t)(int64_t)(int16_t)(a)) + +#define wuffs_base__utility__sign_extend_convert_u32_u64(a) \ + ((uint64_t)(int64_t)(int32_t)(a)) + #define wuffs_base__utility__sign_extend_rshift_u32(a, n) \ ((uint32_t)(((int32_t)(a)) >> (n))) @@ -21993,26 +22974,31 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data, int32_t fourcc; const char* magic; } table[] = { - {-0x30302020, "\x01\x00\x00"}, // '00 'be - {+0x475A2020, "\x02\x1F\x8B\x08"}, // GZ - {+0x5A535444, "\x03\x28\xB5\x2F\xFD"}, // ZSTD - {+0x425A3220, "\x02\x42\x5A\x68"}, // BZ2 - {+0x424D5020, "\x01\x42\x4D"}, // BMP - {+0x47494620, "\x03\x47\x49\x46\x38"}, // GIF - {+0x54494646, "\x03\x49\x49\x2A\x00"}, // TIFF (little-endian) - {+0x4C5A4950, "\x04\x4C\x5A\x49\x50\x01"}, // LZIP - {+0x54494646, "\x03\x4D\x4D\x00\x2A"}, // TIFF (big-endian) - {+0x4E50424D, "\x02\x50\x35\x0A"}, // NPBM (P5; *.pgm) - {+0x4E50424D, "\x02\x50\x36\x0A"}, // NPBM (P6; *.ppm) - {-0x52494646, "\x03\x52\x49\x46\x46"}, // RIFF - {+0x4C5A4D41, "\x04\x5D\x00\x10\x00\x00"}, // LZMA - {+0x4C5A4D41, "\x02\x5D\x00\x00"}, // LZMA - {+0x4E494520, "\x02\x6E\xC3\xAF"}, // NIE - {+0x514F4920, "\x03\x71\x6F\x69\x66"}, // QOI - {+0x5A4C4942, "\x01\x78\x9C"}, // ZLIB - {+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG - {+0x585A2020, "\x04\xFD\x37\x7A\x58\x5A"}, // XZ - {+0x4A504547, "\x01\xFF\xD8"}, // JPEG + {-0x30302020, "\x01\x00\x00"}, // '00 'be + {+0x41425852, "\x03\x03\x00\x08\x00"}, // ABXR + {+0x475A2020, "\x02\x1F\x8B\x08"}, // GZ + {+0x5A535444, "\x03\x28\xB5\x2F\xFD"}, // ZSTD + {+0x584D4C20, "\x05\x3C\x3F\x78\x6D\x6C\x20"}, // XML + {+0x41425853, "\x03\x41\x42\x58\x00"}, // ABXS + {+0x425A3220, "\x02\x42\x5A\x68"}, // BZ2 + {+0x424D5020, "\x01\x42\x4D"}, // BMP + {+0x47494620, "\x03\x47\x49\x46\x38"}, // GIF + {+0x54494646, "\x03\x49\x49\x2A\x00"}, // TIFF (little-endian) + {+0x4C5A4950, "\x04\x4C\x5A\x49\x50\x01"}, // LZIP + {+0x54494646, "\x03\x4D\x4D\x00\x2A"}, // TIFF (big-endian) + {+0x45544332, "\x03\x50\x4B\x4D\x20"}, // ETC2 (*.pkm) + {+0x4E50424D, "\x02\x50\x35\x0A"}, // NPBM (P5; *.pgm) + {+0x4E50424D, "\x02\x50\x36\x0A"}, // NPBM (P6; *.ppm) + {-0x52494646, "\x03\x52\x49\x46\x46"}, // RIFF + {+0x4C5A4D41, "\x04\x5D\x00\x10\x00\x00"}, // LZMA + {+0x4C5A4D41, "\x02\x5D\x00\x00"}, // LZMA + {+0x4E494520, "\x02\x6E\xC3\xAF"}, // NIE + {+0x514F4920, "\x03\x71\x6F\x69\x66"}, // QOI + {+0x5A4C4942, "\x01\x78\x9C"}, // ZLIB + {+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG + {+0x54482020, "\x02\xC3\xBE\xFE"}, // TH + {+0x585A2020, "\x04\xFD\x37\x7A\x58\x5A"}, // XZ + {+0x4A504547, "\x01\xFF\xD8"}, // JPEG }; static const size_t table_len = sizeof(table) / sizeof(table[0]); @@ -22246,9 +23232,8 @@ wuffs_base__pixel_buffer__color_u32_at(const wuffs_base__pixel_buffer* pb, wuffs_base__peek_u32le__no_bounds_check(row + (4 * ((size_t)x))); case WUFFS_BASE__PIXEL_FORMAT__RGB: - return wuffs_private_impl__swap_u32_argb_abgr( - 0xFF000000 | - wuffs_base__peek_u24le__no_bounds_check(row + (3 * ((size_t)x)))); + return 0xFF000000 | + wuffs_base__peek_u24be__no_bounds_check(row + (3 * ((size_t)x))); case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL: return wuffs_private_impl__swap_u32_argb_abgr( wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul( @@ -22354,6 +23339,10 @@ wuffs_base__pixel_buffer__set_color_u32_at( wuffs_base__color_u32_argb_premul__as__color_u64_argb_nonpremul( color)); break; + case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY: + wuffs_base__poke_u32le__no_bounds_check( + row + (4 * ((size_t)x)), (color >> 31) ? (color | 0xFF000000) : 0); + break; case WUFFS_BASE__PIXEL_FORMAT__RGB: wuffs_base__poke_u24le__no_bounds_check( @@ -22959,6 +23948,34 @@ wuffs_private_impl__swizzle_squash_align4_bgr_565_8888(uint8_t* dst_ptr, // -------- +static uint64_t // +wuffs_private_impl__swizzle_squash_align4_y_8888(uint8_t* dst_ptr, + size_t dst_len, + const uint8_t* src_ptr, + size_t src_len, + bool nonpremul) { + size_t len = (dst_len < src_len ? dst_len : src_len) / 4; + uint8_t* d = dst_ptr; + const uint8_t* s = src_ptr; + + size_t n = len; + while (n--) { + uint32_t argb = wuffs_base__peek_u32le__no_bounds_check(s); + if (nonpremul) { + argb = + wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(argb); + } + uint32_t s0 = wuffs_base__color_u32_argb_premul__as__color_u8_gray(argb); + wuffs_base__poke_u32le__no_bounds_check( + d, (argb & 0xFF000000) | (s0 * 0x010101)); + s += 4; + d += 4; + } + return len; +} + +// -------- + static uint64_t // wuffs_private_impl__swizzle_swap_rgb_bgr(uint8_t* dst_ptr, size_t dst_len, @@ -26784,6 +27801,62 @@ wuffs_private_impl__swizzle_xxxxxxxx__y_16be(uint8_t* dst_ptr, // -------- +static uint64_t // +wuffs_private_impl__swizzle_y__bgr(uint8_t* dst_ptr, + size_t dst_len, + uint8_t* dst_palette_ptr, + size_t dst_palette_len, + const uint8_t* src_ptr, + size_t src_len) { + size_t src_len3 = src_len / 3; + size_t len = (dst_len < src_len3) ? dst_len : src_len3; + uint8_t* d = dst_ptr; + const uint8_t* s = src_ptr; + size_t n = len; + + // TODO: unroll. + + while (n >= 1) { + uint32_t s0 = + 0xFF000000 | wuffs_base__peek_u24le__no_bounds_check(s + (0 * 3)); + d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(s0); + + s += 1 * 3; + d += 1 * 1; + n -= 1; + } + + return len; +} + +static uint64_t // +wuffs_private_impl__swizzle_y__bgr_565(uint8_t* dst_ptr, + size_t dst_len, + uint8_t* dst_palette_ptr, + size_t dst_palette_len, + const uint8_t* src_ptr, + size_t src_len) { + size_t src_len2 = src_len / 2; + size_t len = (dst_len < src_len2) ? dst_len : src_len2; + uint8_t* d = dst_ptr; + const uint8_t* s = src_ptr; + size_t n = len; + + // TODO: unroll. + + while (n >= 1) { + uint32_t s0 = wuffs_base__color_u16_rgb_565__as__color_u32_argb_premul( + wuffs_base__peek_u16le__no_bounds_check(s + (0 * 2))); + d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(s0); + + s += 1 * 2; + d += 1 * 1; + n -= 1; + } + + return len; +} + static uint64_t // wuffs_private_impl__swizzle_y__bgra_nonpremul__src(uint8_t* dst_ptr, size_t dst_len, @@ -26797,6 +27870,8 @@ wuffs_private_impl__swizzle_y__bgra_nonpremul__src(uint8_t* dst_ptr, const uint8_t* s = src_ptr; size_t n = len; + // TODO: unroll. + while (n >= 1) { uint32_t s0 = wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul( @@ -26825,6 +27900,8 @@ wuffs_private_impl__swizzle_y__bgra_nonpremul__src_over( const uint8_t* s = src_ptr; size_t n = len; + // TODO: unroll. + while (n >= 1) { uint32_t d0 = 0xFF000000 | (0x00010101 * ((uint32_t)(d[0]))); uint32_t s0 = wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4)); @@ -26839,6 +27916,154 @@ wuffs_private_impl__swizzle_y__bgra_nonpremul__src_over( return len; } +static uint64_t // +wuffs_private_impl__swizzle_y__bgra_nonpremul_4x16le__src( + uint8_t* dst_ptr, + size_t dst_len, + uint8_t* dst_palette_ptr, + size_t dst_palette_len, + const uint8_t* src_ptr, + size_t src_len) { + size_t src_len8 = src_len / 8; + size_t len = (dst_len < src_len8) ? dst_len : src_len8; + uint8_t* d = dst_ptr; + const uint8_t* s = src_ptr; + size_t n = len; + + // TODO: unroll. + + while (n >= 1) { + d[0] = wuffs_base__color_u64_argb_nonpremul__as__color_u8_gray( + wuffs_base__peek_u64le__no_bounds_check(s + (0 * 8))); + + s += 1 * 8; + d += 1 * 1; + n -= 1; + } + + return len; +} + +static uint64_t // +wuffs_private_impl__swizzle_y__bgra_nonpremul_4x16le__src_over( + uint8_t* dst_ptr, + size_t dst_len, + uint8_t* dst_palette_ptr, + size_t dst_palette_len, + const uint8_t* src_ptr, + size_t src_len) { + size_t src_len8 = src_len / 8; + size_t len = (dst_len < src_len8) ? dst_len : src_len8; + uint8_t* d = dst_ptr; + const uint8_t* s = src_ptr; + size_t n = len; + + // TODO: unroll. + + while (n >= 1) { + // Extract 16-bit color components. + uint32_t dr = 0x101 * ((uint32_t)d[0]); + uint32_t dg = 0x101 * ((uint32_t)d[0]); + uint32_t db = 0x101 * ((uint32_t)d[0]); + uint32_t sa = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 6)); + uint32_t sr = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 4)); + uint32_t sg = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 2)); + uint32_t sb = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 0)); + + // Calculate the inverse of the src-alpha: how much of the dst to keep. + uint32_t ia = 0xFFFF - sa; + + // Composite src (nonpremul) over dst (premul). + dr = ((sr * sa) + (dr * ia)) / 0xFFFF; + dg = ((sg * sa) + (dg * ia)) / 0xFFFF; + db = ((sb * sa) + (db * ia)) / 0xFFFF; + + // Convert to 16-bit color to 8-bit gray. + uint32_t weighted_average = + (19595 * dr) + (38470 * dg) + (7471 * db) + 32768; + d[0] = (uint8_t)(weighted_average >> 24); + + s += 1 * 8; + d += 1 * 1; + n -= 1; + } + + return len; +} + +static uint64_t // +wuffs_private_impl__swizzle_y__bgra_premul__src(uint8_t* dst_ptr, + size_t dst_len, + uint8_t* dst_palette_ptr, + size_t dst_palette_len, + const uint8_t* src_ptr, + size_t src_len) { + size_t src_len4 = src_len / 4; + size_t len = (dst_len < src_len4) ? dst_len : src_len4; + uint8_t* d = dst_ptr; + const uint8_t* s = src_ptr; + size_t n = len; + + // TODO: unroll. + + while (n >= 1) { + uint32_t s0 = wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4)); + d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(s0); + + s += 1 * 4; + d += 1 * 1; + n -= 1; + } + + return len; +} + +static uint64_t // +wuffs_private_impl__swizzle_y__bgra_premul__src_over(uint8_t* dst_ptr, + size_t dst_len, + uint8_t* dst_palette_ptr, + size_t dst_palette_len, + const uint8_t* src_ptr, + size_t src_len) { + size_t src_len4 = src_len / 4; + size_t len = (dst_len < src_len4) ? dst_len : src_len4; + uint8_t* d = dst_ptr; + const uint8_t* s = src_ptr; + size_t n = len; + + // TODO: unroll. + + while (n >= 1) { + // Extract 16-bit color components. + uint32_t dr = 0x101 * ((uint32_t)d[0]); + uint32_t dg = 0x101 * ((uint32_t)d[0]); + uint32_t db = 0x101 * ((uint32_t)d[0]); + uint32_t sa = 0x101 * ((uint32_t)s[3]); + uint32_t sr = 0x101 * ((uint32_t)s[2]); + uint32_t sg = 0x101 * ((uint32_t)s[1]); + uint32_t sb = 0x101 * ((uint32_t)s[0]); + + // Calculate the inverse of the src-alpha: how much of the dst to keep. + uint32_t ia = 0xFFFF - sa; + + // Composite src (premul) over dst (premul). + dr = sr + ((dr * ia) / 0xFFFF); + dg = sg + ((dg * ia) / 0xFFFF); + db = sb + ((db * ia) / 0xFFFF); + + // Convert to 16-bit color to 8-bit gray. + uint32_t weighted_average = + (19595 * dr) + (38470 * dg) + (7471 * db) + 32768; + d[0] = (uint8_t)(weighted_average >> 24); + + s += 1 * 4; + d += 1 * 1; + n -= 1; + } + + return len; +} + static uint64_t // wuffs_private_impl__swizzle_y__bgrx(uint8_t* dst_ptr, size_t dst_len, @@ -26852,6 +28077,8 @@ wuffs_private_impl__swizzle_y__bgrx(uint8_t* dst_ptr, const uint8_t* s = src_ptr; size_t n = len; + // TODO: unroll. + while (n >= 1) { uint32_t s0 = 0xFF000000 | wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4)); @@ -26865,6 +28092,152 @@ wuffs_private_impl__swizzle_y__bgrx(uint8_t* dst_ptr, return len; } +static uint64_t // +wuffs_private_impl__swizzle_y__rgb(uint8_t* dst_ptr, + size_t dst_len, + uint8_t* dst_palette_ptr, + size_t dst_palette_len, + const uint8_t* src_ptr, + size_t src_len) { + size_t src_len3 = src_len / 3; + size_t len = (dst_len < src_len3) ? dst_len : src_len3; + uint8_t* d = dst_ptr; + const uint8_t* s = src_ptr; + size_t n = len; + + // TODO: unroll. + + while (n >= 1) { + uint32_t s0 = + 0xFF000000 | wuffs_base__peek_u24be__no_bounds_check(s + (0 * 3)); + d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(s0); + + s += 1 * 3; + d += 1 * 1; + n -= 1; + } + + return len; +} + +static uint64_t // +wuffs_private_impl__swizzle_y__rgba_nonpremul__src(uint8_t* dst_ptr, + size_t dst_len, + uint8_t* dst_palette_ptr, + size_t dst_palette_len, + const uint8_t* src_ptr, + size_t src_len) { + size_t src_len4 = src_len / 4; + size_t len = (dst_len < src_len4) ? dst_len : src_len4; + uint8_t* d = dst_ptr; + const uint8_t* s = src_ptr; + size_t n = len; + + // TODO: unroll. + + while (n >= 1) { + uint32_t s0 = wuffs_private_impl__swap_u32_argb_abgr( + wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul( + wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4)))); + d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(s0); + + s += 1 * 4; + d += 1 * 1; + n -= 1; + } + + return len; +} + +static uint64_t // +wuffs_private_impl__swizzle_y__rgba_nonpremul__src_over( + uint8_t* dst_ptr, + size_t dst_len, + uint8_t* dst_palette_ptr, + size_t dst_palette_len, + const uint8_t* src_ptr, + size_t src_len) { + size_t src_len4 = src_len / 4; + size_t len = (dst_len < src_len4) ? dst_len : src_len4; + uint8_t* d = dst_ptr; + const uint8_t* s = src_ptr; + size_t n = len; + + // TODO: unroll. + + while (n >= 1) { + uint32_t d0 = 0xFF000000 | (0x00010101 * ((uint32_t)(d[0]))); + uint32_t s0 = wuffs_private_impl__swap_u32_argb_abgr( + wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4))); + d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray( + wuffs_private_impl__composite_premul_nonpremul_u32_axxx(d0, s0)); + + s += 1 * 4; + d += 1 * 1; + n -= 1; + } + + return len; +} + +static uint64_t // +wuffs_private_impl__swizzle_y__rgba_premul__src(uint8_t* dst_ptr, + size_t dst_len, + uint8_t* dst_palette_ptr, + size_t dst_palette_len, + const uint8_t* src_ptr, + size_t src_len) { + size_t src_len4 = src_len / 4; + size_t len = (dst_len < src_len4) ? dst_len : src_len4; + uint8_t* d = dst_ptr; + const uint8_t* s = src_ptr; + size_t n = len; + + // TODO: unroll. + + while (n >= 1) { + uint32_t s0 = wuffs_private_impl__swap_u32_argb_abgr( + wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4))); + d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(s0); + + s += 1 * 4; + d += 1 * 1; + n -= 1; + } + + return len; +} + +static uint64_t // +wuffs_private_impl__swizzle_y__rgba_premul__src_over(uint8_t* dst_ptr, + size_t dst_len, + uint8_t* dst_palette_ptr, + size_t dst_palette_len, + const uint8_t* src_ptr, + size_t src_len) { + size_t src_len4 = src_len / 4; + size_t len = (dst_len < src_len4) ? dst_len : src_len4; + uint8_t* d = dst_ptr; + const uint8_t* s = src_ptr; + size_t n = len; + + // TODO: unroll. + + while (n >= 1) { + uint32_t d0 = 0xFF000000 | (0x00010101 * ((uint32_t)(d[0]))); + uint32_t s0 = wuffs_private_impl__swap_u32_argb_abgr( + wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4))); + d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray( + wuffs_private_impl__composite_premul_premul_u32_axxx(d0, s0)); + + s += 1 * 4; + d += 1 * 1; + n -= 1; + } + + return len; +} + static uint64_t // wuffs_private_impl__swizzle_y__y_16be(uint8_t* dst_ptr, size_t dst_len, @@ -26878,6 +28251,8 @@ wuffs_private_impl__swizzle_y__y_16be(uint8_t* dst_ptr, const uint8_t* s = src_ptr; size_t n = len; + // TODO: unroll. + while (n >= 1) { d[0] = s[0]; @@ -26890,98 +28265,254 @@ wuffs_private_impl__swizzle_y__y_16be(uint8_t* dst_ptr, } static uint64_t // -wuffs_private_impl__swizzle_y_16le__y_16be(uint8_t* dst_ptr, - size_t dst_len, - uint8_t* dst_palette_ptr, - size_t dst_palette_len, - const uint8_t* src_ptr, - size_t src_len) { - size_t dst_len2 = dst_len / 2; +wuffs_private_impl__swizzle_y__ya_nonpremul__src(uint8_t* dst_ptr, + size_t dst_len, + uint8_t* dst_palette_ptr, + size_t dst_palette_len, + const uint8_t* src_ptr, + size_t src_len) { size_t src_len2 = src_len / 2; - size_t len = (dst_len2 < src_len2) ? dst_len2 : src_len2; + size_t len = (dst_len < src_len2) ? dst_len : src_len2; uint8_t* d = dst_ptr; const uint8_t* s = src_ptr; size_t n = len; + // TODO: unroll. + while (n >= 1) { - uint8_t s0 = s[0]; - uint8_t s1 = s[1]; - d[0] = s1; - d[1] = s0; + uint32_t s0 = ((uint32_t)(s[1]) << 24) | ((uint32_t)(s[0]) * 0x010101); + d[0] = (uint8_t) + wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(s0); s += 1 * 2; - d += 1 * 2; + d += 1 * 1; n -= 1; } return len; } -// -------- - static uint64_t // -wuffs_private_impl__swizzle_ya_nonpremul__ya_nonpremul__src_over( - uint8_t* dst_ptr, - size_t dst_len, - uint8_t* dst_palette_ptr, - size_t dst_palette_len, - const uint8_t* src_ptr, - size_t src_len) { - size_t dst_len2 = dst_len / 2; +wuffs_private_impl__swizzle_y__ya_nonpremul__src_over(uint8_t* dst_ptr, + size_t dst_len, + uint8_t* dst_palette_ptr, + size_t dst_palette_len, + const uint8_t* src_ptr, + size_t src_len) { size_t src_len2 = src_len / 2; - size_t len = (dst_len2 < src_len2) ? dst_len2 : src_len2; + size_t len = (dst_len < src_len2) ? dst_len : src_len2; uint8_t* d = dst_ptr; const uint8_t* s = src_ptr; size_t n = len; + // TODO: unroll. + while (n >= 1) { - uint32_t d0 = ((uint32_t)(d[1]) << 24) | ((uint32_t)(d[0]) * 0x010101); + uint32_t d0 = 0xFF000000 | ((uint32_t)(d[0]) * 0x010101); uint32_t s0 = ((uint32_t)(s[1]) << 24) | ((uint32_t)(s[0]) * 0x010101); - uint32_t c0 = - wuffs_private_impl__composite_nonpremul_nonpremul_u32_axxx(d0, s0); - wuffs_base__poke_u16le__no_bounds_check(d + (0 * 2), (uint16_t)(c0 >> 16)); + d[0] = (uint8_t)wuffs_private_impl__composite_premul_nonpremul_u32_axxx(d0, + s0); s += 1 * 2; - d += 1 * 2; + d += 1 * 1; n -= 1; } return len; } -// -------- +static uint64_t // +wuffs_private_impl__swizzle_y__index__src(uint8_t* dst_ptr, + size_t dst_len, + uint8_t* dst_palette_ptr, + size_t dst_palette_len, + const uint8_t* src_ptr, + size_t src_len) { + if (dst_palette_len != + WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) { + return 0; + } + size_t len = (dst_len < src_len) ? dst_len : src_len; + uint8_t* d = dst_ptr; + const uint8_t* s = src_ptr; + size_t n = len; + + // TODO: unroll. + + while (n >= 1) { + d[0] = dst_palette_ptr[(size_t)s[0] * 4]; + + s += 1 * 1; + d += 1 * 1; + n -= 1; + } + + return len; +} static uint64_t // -wuffs_private_impl__swizzle_transparent_black_src( +wuffs_private_impl__swizzle_y__index_bgra_nonpremul__src_over( uint8_t* dst_ptr, size_t dst_len, uint8_t* dst_palette_ptr, size_t dst_palette_len, - uint64_t num_pixels, - uint32_t dst_pixfmt_bytes_per_pixel) { - uint64_t n = ((uint64_t)dst_len) / dst_pixfmt_bytes_per_pixel; - if (n > num_pixels) { - n = num_pixels; + const uint8_t* src_ptr, + size_t src_len) { + if (dst_palette_len != + WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) { + return 0; } - memset(dst_ptr, 0, ((size_t)(n * dst_pixfmt_bytes_per_pixel))); - return n; + size_t len = (dst_len < src_len) ? dst_len : src_len; + uint8_t* d = dst_ptr; + const uint8_t* s = src_ptr; + size_t n = len; + + // TODO: unroll. + + while (n >= 1) { + uint32_t d0 = 0xFF000000 | (0x00010101 * ((uint32_t)(d[0]))); + uint32_t s0 = wuffs_base__peek_u32le__no_bounds_check(dst_palette_ptr + + ((size_t)s[0] * 4)); + d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray( + wuffs_private_impl__composite_premul_nonpremul_u32_axxx(d0, s0)); + + s += 1 * 1; + d += 1 * 1; + n -= 1; + } + + return len; } static uint64_t // -wuffs_private_impl__swizzle_transparent_black_src_over( +wuffs_private_impl__swizzle_y__index_binary_alpha__src_over( uint8_t* dst_ptr, size_t dst_len, uint8_t* dst_palette_ptr, size_t dst_palette_len, - uint64_t num_pixels, - uint32_t dst_pixfmt_bytes_per_pixel) { - uint64_t n = ((uint64_t)dst_len) / dst_pixfmt_bytes_per_pixel; - if (n > num_pixels) { - n = num_pixels; - } - return n; -} - + const uint8_t* src_ptr, + size_t src_len) { + if (dst_palette_len != + WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) { + return 0; + } + size_t len = (dst_len < src_len) ? dst_len : src_len; + uint8_t* d = dst_ptr; + const uint8_t* s = src_ptr; + size_t n = len; + + // TODO: unroll. + + while (n >= 1) { + uint32_t s0 = wuffs_base__peek_u32le__no_bounds_check(dst_palette_ptr + + ((size_t)s[0] * 4)); + if (s0) { + d[0] = (uint8_t)s0; + } + + s += 1 * 1; + d += 1 * 1; + n -= 1; + } + + return len; +} + +// -------- + +static uint64_t // +wuffs_private_impl__swizzle_y_16le__y_16be(uint8_t* dst_ptr, + size_t dst_len, + uint8_t* dst_palette_ptr, + size_t dst_palette_len, + const uint8_t* src_ptr, + size_t src_len) { + size_t dst_len2 = dst_len / 2; + size_t src_len2 = src_len / 2; + size_t len = (dst_len2 < src_len2) ? dst_len2 : src_len2; + uint8_t* d = dst_ptr; + const uint8_t* s = src_ptr; + size_t n = len; + + while (n >= 1) { + uint8_t s0 = s[0]; + uint8_t s1 = s[1]; + d[0] = s1; + d[1] = s0; + + s += 1 * 2; + d += 1 * 2; + n -= 1; + } + + return len; +} + +// -------- + +static uint64_t // +wuffs_private_impl__swizzle_ya_nonpremul__ya_nonpremul__src_over( + uint8_t* dst_ptr, + size_t dst_len, + uint8_t* dst_palette_ptr, + size_t dst_palette_len, + const uint8_t* src_ptr, + size_t src_len) { + size_t dst_len2 = dst_len / 2; + size_t src_len2 = src_len / 2; + size_t len = (dst_len2 < src_len2) ? dst_len2 : src_len2; + uint8_t* d = dst_ptr; + const uint8_t* s = src_ptr; + size_t n = len; + + while (n >= 1) { + uint32_t d0 = ((uint32_t)(d[1]) << 24) | ((uint32_t)(d[0]) * 0x010101); + uint32_t s0 = ((uint32_t)(s[1]) << 24) | ((uint32_t)(s[0]) * 0x010101); + uint32_t c0 = + wuffs_private_impl__composite_nonpremul_nonpremul_u32_axxx(d0, s0); + wuffs_base__poke_u16le__no_bounds_check(d + (0 * 2), (uint16_t)(c0 >> 16)); + + s += 1 * 2; + d += 1 * 2; + n -= 1; + } + + return len; +} + +// -------- + +static uint64_t // +wuffs_private_impl__swizzle_transparent_black_src( + uint8_t* dst_ptr, + size_t dst_len, + uint8_t* dst_palette_ptr, + size_t dst_palette_len, + uint64_t num_pixels, + uint32_t dst_pixfmt_bytes_per_pixel) { + uint64_t n = ((uint64_t)dst_len) / dst_pixfmt_bytes_per_pixel; + if (n > num_pixels) { + n = num_pixels; + } + memset(dst_ptr, 0, ((size_t)(n * dst_pixfmt_bytes_per_pixel))); + return n; +} + +static uint64_t // +wuffs_private_impl__swizzle_transparent_black_src_over( + uint8_t* dst_ptr, + size_t dst_len, + uint8_t* dst_palette_ptr, + size_t dst_palette_len, + uint64_t num_pixels, + uint32_t dst_pixfmt_bytes_per_pixel) { + uint64_t n = ((uint64_t)dst_len) / dst_pixfmt_bytes_per_pixel; + if (n > num_pixels) { + n = num_pixels; + } + return n; +} + // -------- static inline WUFFS_BASE__FORCE_INLINE wuffs_base__pixel_swizzler__func // @@ -27077,6 +28608,15 @@ wuffs_private_impl__pixel_swizzler__prepare__ya_nonpremul( wuffs_base__slice_u8 src_palette, wuffs_base__pixel_blend blend) { switch (dst_pixfmt.repr) { + case WUFFS_BASE__PIXEL_FORMAT__Y: + switch (blend) { + case WUFFS_BASE__PIXEL_BLEND__SRC: + return wuffs_private_impl__swizzle_y__ya_nonpremul__src; + case WUFFS_BASE__PIXEL_BLEND__SRC_OVER: + return wuffs_private_impl__swizzle_y__ya_nonpremul__src_over; + } + return NULL; + case WUFFS_BASE__PIXEL_FORMAT__YA_NONPREMUL: switch (blend) { case WUFFS_BASE__PIXEL_BLEND__SRC: @@ -27146,6 +28686,26 @@ wuffs_private_impl__pixel_swizzler__prepare__indexed__bgra_nonpremul( wuffs_base__slice_u8 src_palette, wuffs_base__pixel_blend blend) { switch (dst_pixfmt.repr) { + case WUFFS_BASE__PIXEL_FORMAT__Y: + switch (blend) { + case WUFFS_BASE__PIXEL_BLEND__SRC: + if (wuffs_private_impl__swizzle_squash_align4_y_8888( + dst_palette.ptr, dst_palette.len, src_palette.ptr, + src_palette.len, true) != + (WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) { + return NULL; + } + return wuffs_private_impl__swizzle_y__index__src; + case WUFFS_BASE__PIXEL_BLEND__SRC_OVER: + if (wuffs_private_impl__slice_u8__copy_from_slice(dst_palette, + src_palette) != + WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) { + return NULL; + } + return wuffs_private_impl__swizzle_y__index_bgra_nonpremul__src_over; + } + return NULL; + case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL: if (wuffs_private_impl__slice_u8__copy_from_slice(dst_palette, src_palette) != @@ -27318,6 +28878,21 @@ wuffs_private_impl__pixel_swizzler__prepare__indexed__bgra_binary( wuffs_base__slice_u8 src_palette, wuffs_base__pixel_blend blend) { switch (dst_pixfmt.repr) { + case WUFFS_BASE__PIXEL_FORMAT__Y: + if (wuffs_private_impl__swizzle_squash_align4_y_8888( + dst_palette.ptr, dst_palette.len, src_palette.ptr, + src_palette.len, false) != + (WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) { + return NULL; + } + switch (blend) { + case WUFFS_BASE__PIXEL_BLEND__SRC: + return wuffs_private_impl__swizzle_y__index__src; + case WUFFS_BASE__PIXEL_BLEND__SRC_OVER: + return wuffs_private_impl__swizzle_y__index_binary_alpha__src_over; + } + return NULL; + case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL: case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_PREMUL: case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY: @@ -27435,6 +29010,9 @@ wuffs_private_impl__pixel_swizzler__prepare__bgr_565( wuffs_base__slice_u8 src_palette, wuffs_base__pixel_blend blend) { switch (dst_pixfmt.repr) { + case WUFFS_BASE__PIXEL_FORMAT__Y: + return wuffs_private_impl__swizzle_y__bgr_565; + case WUFFS_BASE__PIXEL_FORMAT__BGR_565: return wuffs_private_impl__swizzle_copy_2_2; @@ -27471,6 +29049,9 @@ wuffs_private_impl__pixel_swizzler__prepare__bgr( wuffs_base__slice_u8 src_palette, wuffs_base__pixel_blend blend) { switch (dst_pixfmt.repr) { + case WUFFS_BASE__PIXEL_FORMAT__Y: + return wuffs_private_impl__swizzle_y__bgr; + case WUFFS_BASE__PIXEL_FORMAT__BGR_565: return wuffs_private_impl__swizzle_bgr_565__bgr; @@ -27624,6 +29205,15 @@ wuffs_private_impl__pixel_swizzler__prepare__bgra_nonpremul_4x16le( wuffs_base__slice_u8 src_palette, wuffs_base__pixel_blend blend) { switch (dst_pixfmt.repr) { + case WUFFS_BASE__PIXEL_FORMAT__Y: + switch (blend) { + case WUFFS_BASE__PIXEL_BLEND__SRC: + return wuffs_private_impl__swizzle_y__bgra_nonpremul_4x16le__src; + case WUFFS_BASE__PIXEL_BLEND__SRC_OVER: + return wuffs_private_impl__swizzle_y__bgra_nonpremul_4x16le__src_over; + } + return NULL; + case WUFFS_BASE__PIXEL_FORMAT__BGR_565: switch (blend) { case WUFFS_BASE__PIXEL_BLEND__SRC: @@ -27717,6 +29307,15 @@ wuffs_private_impl__pixel_swizzler__prepare__bgra_premul( wuffs_base__slice_u8 src_palette, wuffs_base__pixel_blend blend) { switch (dst_pixfmt.repr) { + case WUFFS_BASE__PIXEL_FORMAT__Y: + switch (blend) { + case WUFFS_BASE__PIXEL_BLEND__SRC: + return wuffs_private_impl__swizzle_y__bgra_premul__src; + case WUFFS_BASE__PIXEL_BLEND__SRC_OVER: + return wuffs_private_impl__swizzle_y__bgra_premul__src_over; + } + return NULL; + case WUFFS_BASE__PIXEL_FORMAT__BGR_565: switch (blend) { case WUFFS_BASE__PIXEL_BLEND__SRC: @@ -27797,6 +29396,109 @@ wuffs_private_impl__pixel_swizzler__prepare__bgra_premul( return NULL; } +static inline WUFFS_BASE__FORCE_INLINE wuffs_base__pixel_swizzler__func // +wuffs_private_impl__pixel_swizzler__prepare__bgra_binary( + wuffs_base__pixel_swizzler* p, + wuffs_base__pixel_format dst_pixfmt, + wuffs_base__slice_u8 dst_palette, + wuffs_base__slice_u8 src_palette, + wuffs_base__pixel_blend blend) { + switch (dst_pixfmt.repr) { + case WUFFS_BASE__PIXEL_FORMAT__Y: + switch (blend) { + case WUFFS_BASE__PIXEL_BLEND__SRC: + return wuffs_private_impl__swizzle_y__bgra_premul__src; + case WUFFS_BASE__PIXEL_BLEND__SRC_OVER: + return wuffs_private_impl__swizzle_y__bgra_premul__src_over; + } + return NULL; + + case WUFFS_BASE__PIXEL_FORMAT__BGR_565: + switch (blend) { + case WUFFS_BASE__PIXEL_BLEND__SRC: + return wuffs_private_impl__swizzle_bgr_565__bgra_premul__src; + case WUFFS_BASE__PIXEL_BLEND__SRC_OVER: + return wuffs_private_impl__swizzle_bgr_565__bgra_premul__src_over; + } + return NULL; + + case WUFFS_BASE__PIXEL_FORMAT__BGR: + switch (blend) { + case WUFFS_BASE__PIXEL_BLEND__SRC: + return wuffs_private_impl__swizzle_bgr__bgra_premul__src; + case WUFFS_BASE__PIXEL_BLEND__SRC_OVER: + return wuffs_private_impl__swizzle_bgr__bgra_premul__src_over; + } + return NULL; + + case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL: + switch (blend) { + case WUFFS_BASE__PIXEL_BLEND__SRC: + return wuffs_private_impl__swizzle_copy_4_4; + case WUFFS_BASE__PIXEL_BLEND__SRC_OVER: + return wuffs_private_impl__swizzle_bgra_nonpremul__bgra_premul__src_over; + } + return NULL; + + case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE: + switch (blend) { + case WUFFS_BASE__PIXEL_BLEND__SRC: + return wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__bgra_premul__src; + case WUFFS_BASE__PIXEL_BLEND__SRC_OVER: + return wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__bgra_premul__src_over; + } + return NULL; + + case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL: + case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY: + switch (blend) { + case WUFFS_BASE__PIXEL_BLEND__SRC: + return wuffs_private_impl__swizzle_copy_4_4; + case WUFFS_BASE__PIXEL_BLEND__SRC_OVER: + return wuffs_private_impl__swizzle_bgra_premul__bgra_premul__src_over; + } + return NULL; + + case WUFFS_BASE__PIXEL_FORMAT__RGB: + switch (blend) { + case WUFFS_BASE__PIXEL_BLEND__SRC: + return wuffs_private_impl__swizzle_bgr__rgba_premul__src; + case WUFFS_BASE__PIXEL_BLEND__SRC_OVER: + return wuffs_private_impl__swizzle_bgr__rgba_premul__src_over; + } + return NULL; + + case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL: + switch (blend) { + case WUFFS_BASE__PIXEL_BLEND__SRC: +#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) + if (wuffs_base__cpu_arch__have_x86_sse42()) { + return wuffs_private_impl__swizzle_swap_rgbx_bgrx__x86_sse42; + } +#endif + return wuffs_private_impl__swizzle_swap_rgbx_bgrx; + case WUFFS_BASE__PIXEL_BLEND__SRC_OVER: + return wuffs_private_impl__swizzle_bgra_nonpremul__rgba_premul__src_over; + } + return NULL; + + case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL: + switch (blend) { + case WUFFS_BASE__PIXEL_BLEND__SRC: +#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) + if (wuffs_base__cpu_arch__have_x86_sse42()) { + return wuffs_private_impl__swizzle_swap_rgbx_bgrx__x86_sse42; + } +#endif + return wuffs_private_impl__swizzle_swap_rgbx_bgrx; + case WUFFS_BASE__PIXEL_BLEND__SRC_OVER: + return wuffs_private_impl__swizzle_bgra_premul__rgba_premul__src_over; + } + return NULL; + } + return NULL; +} + static inline WUFFS_BASE__FORCE_INLINE wuffs_base__pixel_swizzler__func // wuffs_private_impl__pixel_swizzler__prepare__bgrx( wuffs_base__pixel_swizzler* p, @@ -27845,6 +29547,9 @@ wuffs_private_impl__pixel_swizzler__prepare__rgb( wuffs_base__slice_u8 src_palette, wuffs_base__pixel_blend blend) { switch (dst_pixfmt.repr) { + case WUFFS_BASE__PIXEL_FORMAT__Y: + return wuffs_private_impl__swizzle_y__rgb; + case WUFFS_BASE__PIXEL_FORMAT__BGR_565: return wuffs_private_impl__swizzle_bgr_565__rgb; @@ -27890,6 +29595,15 @@ wuffs_private_impl__pixel_swizzler__prepare__rgba_nonpremul( wuffs_base__slice_u8 src_palette, wuffs_base__pixel_blend blend) { switch (dst_pixfmt.repr) { + case WUFFS_BASE__PIXEL_FORMAT__Y: + switch (blend) { + case WUFFS_BASE__PIXEL_BLEND__SRC: + return wuffs_private_impl__swizzle_y__rgba_nonpremul__src; + case WUFFS_BASE__PIXEL_BLEND__SRC_OVER: + return wuffs_private_impl__swizzle_y__rgba_nonpremul__src_over; + } + return NULL; + case WUFFS_BASE__PIXEL_FORMAT__BGR_565: switch (blend) { case WUFFS_BASE__PIXEL_BLEND__SRC: @@ -27988,6 +29702,15 @@ wuffs_private_impl__pixel_swizzler__prepare__rgba_premul( wuffs_base__slice_u8 src_palette, wuffs_base__pixel_blend blend) { switch (dst_pixfmt.repr) { + case WUFFS_BASE__PIXEL_FORMAT__Y: + switch (blend) { + case WUFFS_BASE__PIXEL_BLEND__SRC: + return wuffs_private_impl__swizzle_y__rgba_premul__src; + case WUFFS_BASE__PIXEL_BLEND__SRC_OVER: + return wuffs_private_impl__swizzle_y__rgba_premul__src_over; + } + return NULL; + case WUFFS_BASE__PIXEL_FORMAT__BGR_565: switch (blend) { case WUFFS_BASE__PIXEL_BLEND__SRC: @@ -28089,6 +29812,10 @@ wuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swizzler* p, #if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST) switch (dst_pixfmt.repr) { +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_Y) + case WUFFS_BASE__PIXEL_FORMAT__Y: + break; +#endif #if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGR_565) case WUFFS_BASE__PIXEL_FORMAT__BGR_565: break; @@ -28215,6 +29942,11 @@ wuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swizzler* p, p, dst_pixfmt, dst_palette, src_palette, blend); break; + case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY: + func = wuffs_private_impl__pixel_swizzler__prepare__bgra_binary( + p, dst_pixfmt, dst_palette, src_palette, blend); + break; + case WUFFS_BASE__PIXEL_FORMAT__BGRX: func = wuffs_private_impl__pixel_swizzler__prepare__bgrx( p, dst_pixfmt, dst_palette, src_palette, blend); @@ -29669,6 +31401,10 @@ wuffs_base__pixel_swizzler__swizzle_ycck( #if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST) switch (dst->pixcfg.private_impl.pixfmt.repr) { +#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_Y) + case WUFFS_BASE__PIXEL_FORMAT__Y: + break; +#endif #if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGR_565) case WUFFS_BASE__PIXEL_FORMAT__BGR_565: break; @@ -36060,7 +37796,7 @@ wuffs_cbor__decoder__decode_tokens( (((uint64_t)(((uint32_t)(WUFFS_CBOR__TOKEN_LENGTHS[v_c_minor])))) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); } else { *iop_a_dst++ = wuffs_base__make_token( - (((uint64_t)(787997u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) | + (((uint64_t)(731642u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) | (((uint64_t)(16777216u)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | (((uint64_t)(9u)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); } @@ -36284,12 +38020,12 @@ wuffs_cbor__decoder__decode_tokens( } if (v_string_length < 262144u) { *iop_a_dst++ = wuffs_base__make_token( - (((uint64_t)(787997u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) | + (((uint64_t)(731642u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) | (((uint64_t)((4194304u | ((uint32_t)(v_string_length))))) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | (((uint64_t)(((uint32_t)(WUFFS_CBOR__TOKEN_LENGTHS[v_c_minor])))) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); } else { *iop_a_dst++ = wuffs_base__make_token( - (((uint64_t)(787997u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) | + (((uint64_t)(731642u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) | (((uint64_t)((4194304u | ((uint32_t)((v_string_length >> 46u)))))) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | (((uint64_t)(1u)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) | (((uint64_t)(0u)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); @@ -36302,7 +38038,7 @@ wuffs_cbor__decoder__decode_tokens( } else if (v_c_major == 7u) { if (v_c_minor < 20u) { *iop_a_dst++ = wuffs_base__make_token( - (((uint64_t)(787997u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) | + (((uint64_t)(731642u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) | (((uint64_t)((8388608u | ((uint32_t)((v_string_length & 255u)))))) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | (((uint64_t)(1u)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); goto label__goto_parsed_a_leaf_value__break; @@ -36321,7 +38057,7 @@ wuffs_cbor__decoder__decode_tokens( break; } *iop_a_dst++ = wuffs_base__make_token( - (((uint64_t)(787997u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) | + (((uint64_t)(731642u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) | (((uint64_t)((8388608u | ((uint32_t)((v_string_length & 255u)))))) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | (((uint64_t)(2u)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); goto label__goto_parsed_a_leaf_value__break; @@ -40619,237 +42355,364 @@ wuffs_deflate__decoder__decode_huffman_slow( #endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__DEFLATE) -#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GIF) +#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ETC2) // ---------------- Status Codes Implementations -const char wuffs_gif__error__bad_lzw_code[] = "#gif: bad LZW code"; -const char wuffs_gif__error__bad_extension_label[] = "#gif: bad extension label"; -const char wuffs_gif__error__bad_frame_size[] = "#gif: bad frame size"; -const char wuffs_gif__error__bad_graphic_control[] = "#gif: bad graphic control"; -const char wuffs_gif__error__bad_header[] = "#gif: bad header"; -const char wuffs_gif__error__bad_literal_width[] = "#gif: bad literal width"; -const char wuffs_gif__error__bad_palette[] = "#gif: bad palette"; -const char wuffs_gif__error__truncated_input[] = "#gif: truncated input"; -const char wuffs_gif__error__internal_error_inconsistent_i_o[] = "#gif: internal error: inconsistent I/O"; +const char wuffs_etc2__error__bad_header[] = "#etc2: bad header"; +const char wuffs_etc2__error__truncated_input[] = "#etc2: truncated input"; +const char wuffs_etc2__error__unsupported_etc2_file[] = "#etc2: unsupported ETC2 file"; // ---------------- Private Consts static const uint32_t -WUFFS_GIF__INTERLACE_START[5] WUFFS_BASE__POTENTIALLY_UNUSED = { - 4294967295u, 1u, 2u, 4u, 0u, -}; - -static const uint8_t -WUFFS_GIF__INTERLACE_DELTA[5] WUFFS_BASE__POTENTIALLY_UNUSED = { - 1u, 2u, 4u, 8u, 8u, +WUFFS_ETC2__DIFFS[8] WUFFS_BASE__POTENTIALLY_UNUSED = { + 0u, 1u, 2u, 3u, 4294967292u, 4294967293u, 4294967294u, 4294967295u, }; -static const uint8_t -WUFFS_GIF__INTERLACE_COUNT[5] WUFFS_BASE__POTENTIALLY_UNUSED = { - 0u, 1u, 2u, 4u, 8u, -}; - -static const uint8_t -WUFFS_GIF__ANIMEXTS1DOT0[11] WUFFS_BASE__POTENTIALLY_UNUSED = { - 65u, 78u, 73u, 77u, 69u, 88u, 84u, 83u, - 49u, 46u, 48u, +static const uint32_t +WUFFS_ETC2__MODIFIERS[16][4] WUFFS_BASE__POTENTIALLY_UNUSED = { + { + 2u, 8u, 4294967294u, 4294967288u, + }, { + 5u, 17u, 4294967291u, 4294967279u, + }, { + 9u, 29u, 4294967287u, 4294967267u, + }, { + 13u, 42u, 4294967283u, 4294967254u, + }, { + 18u, 60u, 4294967278u, 4294967236u, + }, { + 24u, 80u, 4294967272u, 4294967216u, + }, { + 33u, 106u, 4294967263u, 4294967190u, + }, { + 47u, 183u, 4294967249u, 4294967113u, + }, + { + 0u, 8u, 0u, 4294967288u, + }, { + 0u, 17u, 0u, 4294967279u, + }, { + 0u, 29u, 0u, 4294967267u, + }, { + 0u, 42u, 0u, 4294967254u, + }, { + 0u, 60u, 0u, 4294967236u, + }, { + 0u, 80u, 0u, 4294967216u, + }, { + 0u, 106u, 0u, 4294967190u, + }, { + 0u, 183u, 0u, 4294967113u, + }, }; static const uint8_t -WUFFS_GIF__NETSCAPE2DOT0[11] WUFFS_BASE__POTENTIALLY_UNUSED = { - 78u, 69u, 84u, 83u, 67u, 65u, 80u, 69u, - 50u, 46u, 48u, +WUFFS_ETC2__T_H_MODIFIERS[8] WUFFS_BASE__POTENTIALLY_UNUSED = { + 3u, 6u, 11u, 16u, 23u, 32u, 41u, 64u, }; -static const uint8_t -WUFFS_GIF__ICCRGBG1012[11] WUFFS_BASE__POTENTIALLY_UNUSED = { - 73u, 67u, 67u, 82u, 71u, 66u, 71u, 49u, - 48u, 49u, 50u, +static const uint32_t +WUFFS_ETC2__ALPHA_MODIFIERS[16][8] WUFFS_BASE__POTENTIALLY_UNUSED = { + { + 4294967293u, 4294967290u, 4294967287u, 4294967281u, 2u, 5u, 8u, 14u, + }, { + 4294967293u, 4294967289u, 4294967286u, 4294967283u, 2u, 6u, 9u, 12u, + }, { + 4294967294u, 4294967291u, 4294967288u, 4294967283u, 1u, 4u, 7u, 12u, + }, { + 4294967294u, 4294967292u, 4294967290u, 4294967283u, 1u, 3u, 5u, 12u, + }, { + 4294967293u, 4294967290u, 4294967288u, 4294967284u, 2u, 5u, 7u, 11u, + }, { + 4294967293u, 4294967289u, 4294967287u, 4294967285u, 2u, 6u, 8u, 10u, + }, { + 4294967292u, 4294967289u, 4294967288u, 4294967285u, 3u, 6u, 7u, 10u, + }, { + 4294967293u, 4294967291u, 4294967288u, 4294967285u, 2u, 4u, 7u, 10u, + }, + { + 4294967294u, 4294967290u, 4294967288u, 4294967286u, 1u, 5u, 7u, 9u, + }, { + 4294967294u, 4294967291u, 4294967288u, 4294967286u, 1u, 4u, 7u, 9u, + }, { + 4294967294u, 4294967292u, 4294967288u, 4294967286u, 1u, 3u, 7u, 9u, + }, { + 4294967294u, 4294967291u, 4294967289u, 4294967286u, 1u, 4u, 6u, 9u, + }, { + 4294967293u, 4294967292u, 4294967289u, 4294967286u, 2u, 3u, 6u, 9u, + }, { + 4294967295u, 4294967294u, 4294967293u, 4294967286u, 0u, 1u, 2u, 9u, + }, { + 4294967292u, 4294967290u, 4294967288u, 4294967287u, 3u, 5u, 7u, 8u, + }, { + 4294967293u, 4294967291u, 4294967289u, 4294967287u, 2u, 4u, 6u, 8u, + }, }; static const uint8_t -WUFFS_GIF__XMPDATAXMP[11] WUFFS_BASE__POTENTIALLY_UNUSED = { - 88u, 77u, 80u, 32u, 68u, 97u, 116u, 97u, - 88u, 77u, 80u, +WUFFS_ETC2__CLAMP[1024] WUFFS_BASE__POTENTIALLY_UNUSED = { + 0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u, + 8u, 9u, 10u, 11u, 12u, 13u, 14u, 15u, + 16u, 17u, 18u, 19u, 20u, 21u, 22u, 23u, + 24u, 25u, 26u, 27u, 28u, 29u, 30u, 31u, + 32u, 33u, 34u, 35u, 36u, 37u, 38u, 39u, + 40u, 41u, 42u, 43u, 44u, 45u, 46u, 47u, + 48u, 49u, 50u, 51u, 52u, 53u, 54u, 55u, + 56u, 57u, 58u, 59u, 60u, 61u, 62u, 63u, + 64u, 65u, 66u, 67u, 68u, 69u, 70u, 71u, + 72u, 73u, 74u, 75u, 76u, 77u, 78u, 79u, + 80u, 81u, 82u, 83u, 84u, 85u, 86u, 87u, + 88u, 89u, 90u, 91u, 92u, 93u, 94u, 95u, + 96u, 97u, 98u, 99u, 100u, 101u, 102u, 103u, + 104u, 105u, 106u, 107u, 108u, 109u, 110u, 111u, + 112u, 113u, 114u, 115u, 116u, 117u, 118u, 119u, + 120u, 121u, 122u, 123u, 124u, 125u, 126u, 127u, + 128u, 129u, 130u, 131u, 132u, 133u, 134u, 135u, + 136u, 137u, 138u, 139u, 140u, 141u, 142u, 143u, + 144u, 145u, 146u, 147u, 148u, 149u, 150u, 151u, + 152u, 153u, 154u, 155u, 156u, 157u, 158u, 159u, + 160u, 161u, 162u, 163u, 164u, 165u, 166u, 167u, + 168u, 169u, 170u, 171u, 172u, 173u, 174u, 175u, + 176u, 177u, 178u, 179u, 180u, 181u, 182u, 183u, + 184u, 185u, 186u, 187u, 188u, 189u, 190u, 191u, + 192u, 193u, 194u, 195u, 196u, 197u, 198u, 199u, + 200u, 201u, 202u, 203u, 204u, 205u, 206u, 207u, + 208u, 209u, 210u, 211u, 212u, 213u, 214u, 215u, + 216u, 217u, 218u, 219u, 220u, 221u, 222u, 223u, + 224u, 225u, 226u, 227u, 228u, 229u, 230u, 231u, + 232u, 233u, 234u, 235u, 236u, 237u, 238u, 239u, + 240u, 241u, 242u, 243u, 244u, 245u, 246u, 247u, + 248u, 249u, 250u, 251u, 252u, 253u, 254u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, }; -#define WUFFS_GIF__QUIRKS_BASE 1041635328u - -#define WUFFS_GIF__QUIRKS_COUNT 7u - // ---------------- Private Initializer Prototypes // ---------------- Private Function Prototypes WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_gif__decoder__do_decode_image_config( - wuffs_gif__decoder* self, +wuffs_etc2__decoder__do_decode_image_config( + wuffs_etc2__decoder* self, wuffs_base__image_config* a_dst, wuffs_base__io_buffer* a_src); WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_gif__decoder__do_tell_me_more( - wuffs_gif__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 -static wuffs_base__status -wuffs_gif__decoder__do_decode_frame_config( - wuffs_gif__decoder* self, +wuffs_etc2__decoder__do_decode_frame_config( + wuffs_etc2__decoder* self, wuffs_base__frame_config* a_dst, wuffs_base__io_buffer* a_src); WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_gif__decoder__skip_frame( - wuffs_gif__decoder* self, - wuffs_base__io_buffer* a_src); - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_gif__decoder__do_decode_frame( - wuffs_gif__decoder* self, +wuffs_etc2__decoder__do_decode_frame( + wuffs_etc2__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__empty_struct -wuffs_gif__decoder__reset_gc( - wuffs_gif__decoder* self); - WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_gif__decoder__decode_up_to_id_part1( - wuffs_gif__decoder* self, +wuffs_etc2__decoder__from_src_to_colors( + wuffs_etc2__decoder* self, wuffs_base__io_buffer* a_src); WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_gif__decoder__decode_header( - wuffs_gif__decoder* self, - wuffs_base__io_buffer* a_src); - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_gif__decoder__decode_lsd( - wuffs_gif__decoder* self, - wuffs_base__io_buffer* a_src); - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_gif__decoder__decode_extension( - wuffs_gif__decoder* self, - wuffs_base__io_buffer* a_src); - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_gif__decoder__skip_blocks( - wuffs_gif__decoder* self, - wuffs_base__io_buffer* a_src); - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_gif__decoder__decode_ae( - wuffs_gif__decoder* self, - wuffs_base__io_buffer* a_src); - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_gif__decoder__decode_gc( - wuffs_gif__decoder* self, - wuffs_base__io_buffer* a_src); +static wuffs_base__empty_struct +wuffs_etc2__decoder__from_colors_to_buffer( + wuffs_etc2__decoder* self); WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_gif__decoder__decode_id_part0( - wuffs_gif__decoder* self, - wuffs_base__io_buffer* a_src); +static wuffs_base__empty_struct +wuffs_etc2__decoder__decode_t_mode( + wuffs_etc2__decoder* self, + uint64_t a_bits, + uint32_t a_offset, + bool a_transparent); WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_gif__decoder__decode_id_part1( - wuffs_gif__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__io_buffer* a_src, - wuffs_base__pixel_blend a_blend); +static wuffs_base__empty_struct +wuffs_etc2__decoder__decode_h_mode( + wuffs_etc2__decoder* self, + uint64_t a_bits, + uint32_t a_offset, + bool a_transparent); WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_gif__decoder__decode_id_part2( - wuffs_gif__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__io_buffer* a_src, - wuffs_base__slice_u8 a_workbuf); +static wuffs_base__empty_struct +wuffs_etc2__decoder__decode_planar_mode( + wuffs_etc2__decoder* self, + uint64_t a_bits, + uint32_t a_offset); WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_gif__decoder__copy_to_image_buffer( - wuffs_gif__decoder* self, - wuffs_base__pixel_buffer* a_pb, - wuffs_base__slice_u8 a_src); +static wuffs_base__empty_struct +wuffs_etc2__decoder__decode_half_block( + wuffs_etc2__decoder* self, + uint32_t a_bits, + uint32_t a_offset, + uint32_t a_which, + uint32_t a_r, + uint32_t a_g, + uint32_t a_b, + bool a_flip, + bool a_transparent, + bool a_second); WUFFS_BASE__GENERATED_C_CODE static wuffs_base__empty_struct -wuffs_gif__decoder__lzw_init( - wuffs_gif__decoder* self); +wuffs_etc2__decoder__from_alphas_to_buffer( + wuffs_etc2__decoder* self); WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_gif__decoder__lzw_read_from( - wuffs_gif__decoder* self, - wuffs_base__io_buffer* a_src); +static wuffs_base__status +wuffs_etc2__decoder__from_buffer_to_dst( + wuffs_etc2__decoder* self, + wuffs_base__pixel_buffer* a_dst); // ---------------- VTables const wuffs_base__image_decoder__func_ptrs -wuffs_gif__decoder__func_ptrs_for__wuffs_base__image_decoder = { +wuffs_etc2__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_gif__decoder__decode_frame), + wuffs_base__decode_frame_options*))(&wuffs_etc2__decoder__decode_frame), (wuffs_base__status(*)(void*, wuffs_base__frame_config*, - wuffs_base__io_buffer*))(&wuffs_gif__decoder__decode_frame_config), + wuffs_base__io_buffer*))(&wuffs_etc2__decoder__decode_frame_config), (wuffs_base__status(*)(void*, wuffs_base__image_config*, - wuffs_base__io_buffer*))(&wuffs_gif__decoder__decode_image_config), - (wuffs_base__rect_ie_u32(*)(const void*))(&wuffs_gif__decoder__frame_dirty_rect), + wuffs_base__io_buffer*))(&wuffs_etc2__decoder__decode_image_config), + (wuffs_base__rect_ie_u32(*)(const void*))(&wuffs_etc2__decoder__frame_dirty_rect), (uint64_t(*)(const void*, - uint32_t))(&wuffs_gif__decoder__get_quirk), - (uint32_t(*)(const void*))(&wuffs_gif__decoder__num_animation_loops), - (uint64_t(*)(const void*))(&wuffs_gif__decoder__num_decoded_frame_configs), - (uint64_t(*)(const void*))(&wuffs_gif__decoder__num_decoded_frames), + uint32_t))(&wuffs_etc2__decoder__get_quirk), + (uint32_t(*)(const void*))(&wuffs_etc2__decoder__num_animation_loops), + (uint64_t(*)(const void*))(&wuffs_etc2__decoder__num_decoded_frame_configs), + (uint64_t(*)(const void*))(&wuffs_etc2__decoder__num_decoded_frames), (wuffs_base__status(*)(void*, uint64_t, - uint64_t))(&wuffs_gif__decoder__restart_frame), + uint64_t))(&wuffs_etc2__decoder__restart_frame), (wuffs_base__status(*)(void*, uint32_t, - uint64_t))(&wuffs_gif__decoder__set_quirk), + uint64_t))(&wuffs_etc2__decoder__set_quirk), (wuffs_base__empty_struct(*)(void*, uint32_t, - bool))(&wuffs_gif__decoder__set_report_metadata), + bool))(&wuffs_etc2__decoder__set_report_metadata), (wuffs_base__status(*)(void*, wuffs_base__io_buffer*, wuffs_base__more_information*, - wuffs_base__io_buffer*))(&wuffs_gif__decoder__tell_me_more), - (wuffs_base__range_ii_u64(*)(const void*))(&wuffs_gif__decoder__workbuf_len), + wuffs_base__io_buffer*))(&wuffs_etc2__decoder__tell_me_more), + (wuffs_base__range_ii_u64(*)(const void*))(&wuffs_etc2__decoder__workbuf_len), }; // ---------------- Initializer Implementations wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT -wuffs_gif__decoder__initialize( - wuffs_gif__decoder* self, +wuffs_etc2__decoder__initialize( + wuffs_etc2__decoder* self, size_t sizeof_star_self, uint64_t wuffs_version, uint32_t options){ @@ -40890,19 +42753,19 @@ wuffs_gif__decoder__initialize( 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_gif__decoder__func_ptrs_for__wuffs_base__image_decoder); + (const void*)(&wuffs_etc2__decoder__func_ptrs_for__wuffs_base__image_decoder); return wuffs_base__make_status(NULL); } -wuffs_gif__decoder* -wuffs_gif__decoder__alloc(void) { - wuffs_gif__decoder* x = - (wuffs_gif__decoder*)(calloc(1, sizeof(wuffs_gif__decoder))); +wuffs_etc2__decoder* +wuffs_etc2__decoder__alloc(void) { + wuffs_etc2__decoder* x = + (wuffs_etc2__decoder*)(calloc(1, sizeof(wuffs_etc2__decoder))); if (!x) { return NULL; } - if (wuffs_gif__decoder__initialize( - x, sizeof(wuffs_gif__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) { + if (wuffs_etc2__decoder__initialize( + x, sizeof(wuffs_etc2__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) { free(x); return NULL; } @@ -40910,18 +42773,18 @@ wuffs_gif__decoder__alloc(void) { } size_t -sizeof__wuffs_gif__decoder(void) { - return sizeof(wuffs_gif__decoder); +sizeof__wuffs_etc2__decoder(void) { + return sizeof(wuffs_etc2__decoder); } // ---------------- Function Implementations -// -------- func gif.decoder.get_quirk +// -------- func etc2.decoder.get_quirk WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC uint64_t -wuffs_gif__decoder__get_quirk( - const wuffs_gif__decoder* self, +wuffs_etc2__decoder__get_quirk( + const wuffs_etc2__decoder* self, uint32_t a_key) { if (!self) { return 0; @@ -40931,25 +42794,15 @@ wuffs_gif__decoder__get_quirk( return 0; } - uint32_t v_key = 0; - - if (a_key >= 1041635328u) { - v_key = (a_key - 1041635328u); - if (v_key < 7u) { - if (self->private_impl.f_quirks[v_key]) { - return 1u; - } - } - } return 0u; } -// -------- func gif.decoder.set_quirk +// -------- func etc2.decoder.set_quirk WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_gif__decoder__set_quirk( - wuffs_gif__decoder* self, +wuffs_etc2__decoder__set_quirk( + wuffs_etc2__decoder* self, uint32_t a_key, uint64_t a_value) { if (!self) { @@ -40962,22 +42815,15 @@ wuffs_gif__decoder__set_quirk( : wuffs_base__error__initialize_not_called); } - if ((self->private_impl.f_call_sequence == 0u) && (a_key >= 1041635328u)) { - a_key -= 1041635328u; - if (a_key < 7u) { - self->private_impl.f_quirks[a_key] = (a_value > 0u); - return wuffs_base__make_status(NULL); - } - } return wuffs_base__make_status(wuffs_base__error__unsupported_option); } -// -------- func gif.decoder.decode_image_config +// -------- func etc2.decoder.decode_image_config WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_gif__decoder__decode_image_config( - wuffs_gif__decoder* self, +wuffs_etc2__decoder__decode_image_config( + wuffs_etc2__decoder* self, wuffs_base__image_config* a_dst, wuffs_base__io_buffer* a_src) { if (!self) { @@ -41009,11 +42855,11 @@ wuffs_gif__decoder__decode_image_config( while (true) { { - wuffs_base__status t_0 = wuffs_gif__decoder__do_decode_image_config(self, a_dst, a_src); + wuffs_base__status t_0 = wuffs_etc2__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_gif__error__truncated_input); + status = wuffs_base__make_status(wuffs_etc2__error__truncated_input); goto exit; } status = v_status; @@ -41038,69 +42884,256 @@ wuffs_gif__decoder__decode_image_config( return status; } -// -------- func gif.decoder.do_decode_image_config +// -------- func etc2.decoder.do_decode_image_config WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_gif__decoder__do_decode_image_config( - wuffs_gif__decoder* self, +wuffs_etc2__decoder__do_decode_image_config( + wuffs_etc2__decoder* self, wuffs_base__image_config* a_dst, wuffs_base__io_buffer* a_src) { wuffs_base__status status = wuffs_base__make_status(NULL); - bool v_ffio = false; + uint32_t v_c32 = 0; + uint16_t v_rounded_up_width = 0; + uint16_t v_rounded_up_height = 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; + if (coro_susp_point) { + v_rounded_up_width = self->private_data.s_do_decode_image_config.v_rounded_up_width; + v_rounded_up_height = self->private_data.s_do_decode_image_config.v_rounded_up_height; + } 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; - } else if ( ! self->private_impl.f_seen_header) { + } + { WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - status = wuffs_gif__decoder__decode_header(self, a_src); - if (status.repr) { - goto suspend; + uint32_t t_0; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_0 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src); + iop_a_src += 4; + } 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 == 24) { + t_0 = ((uint32_t)(*scratch)); + break; + } + num_bits_0 += 8u; + *scratch |= ((uint64_t)(num_bits_0)) << 56; + } } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); - status = wuffs_gif__decoder__decode_lsd(self, a_src); - if (status.repr) { - goto suspend; + v_c32 = t_0; + } + if (v_c32 != 541936464u) { + status = wuffs_base__make_status(wuffs_etc2__error__bad_header); + goto exit; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + uint32_t t_1; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_1 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src); + iop_a_src += 4; + } else { + self->private_data.s_do_decode_image_config.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + 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_1 = ((uint32_t)(*scratch >> 56)); + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_1; + if (num_bits_1 == 24) { + t_1 = ((uint32_t)(*scratch)); + break; + } + num_bits_1 += 8u; + *scratch |= ((uint64_t)(num_bits_1)) << 56; + } } - self->private_impl.f_seen_header = true; + v_c32 = t_1; } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - status = wuffs_gif__decoder__decode_up_to_id_part1(self, a_src); - if (status.repr) { - goto suspend; + if ((v_c32 == 12337u) || (v_c32 == 16789554u) || (v_c32 == 151007282u)) { + self->private_impl.f_pixfmt = 2415954056u; + } else if ((v_c32 == 50343986u) || (v_c32 == 167784498u)) { + self->private_impl.f_pixfmt = 2164295816u; + } else if ((v_c32 == 67121202u) || (v_c32 == 184561714u)) { + self->private_impl.f_pixfmt = 2197850248u; + } else if ((v_c32 & 65535u) == 12338u) { + status = wuffs_base__make_status(wuffs_etc2__error__unsupported_etc2_file); + goto exit; + } else { + status = wuffs_base__make_status(wuffs_etc2__error__bad_header); + goto exit; } - v_ffio = ! self->private_impl.f_gc_has_transparent_index; - if ( ! self->private_impl.f_quirks[2u]) { - v_ffio = (v_ffio && - (self->private_impl.f_frame_rect_x0 == 0u) && - (self->private_impl.f_frame_rect_y0 == 0u) && - (self->private_impl.f_frame_rect_x1 == self->private_impl.f_width) && - (self->private_impl.f_frame_rect_y1 == self->private_impl.f_height)); - } else if (v_ffio) { - self->private_impl.f_black_color_u32_argb_premul = 4278190080u; + self->private_impl.f_srgb = ((v_c32 >> 24u) >= 9u); + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); + uint16_t t_2; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { + t_2 = wuffs_base__peek_u16be__no_bounds_check(iop_a_src); + iop_a_src += 2; + } else { + self->private_data.s_do_decode_image_config.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); + 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_2 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_2); + if (num_bits_2 == 8) { + t_2 = ((uint16_t)(*scratch >> 48)); + break; + } + num_bits_2 += 8u; + *scratch |= ((uint64_t)(num_bits_2)); + } + } + v_rounded_up_width = t_2; } - if (self->private_impl.f_background_color_u32_argb_premul == 77u) { - self->private_impl.f_background_color_u32_argb_premul = self->private_impl.f_black_color_u32_argb_premul; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); + uint16_t t_3; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { + t_3 = wuffs_base__peek_u16be__no_bounds_check(iop_a_src); + iop_a_src += 2; + } else { + self->private_data.s_do_decode_image_config.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); + 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_3 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3); + if (num_bits_3 == 8) { + t_3 = ((uint16_t)(*scratch >> 48)); + break; + } + num_bits_3 += 8u; + *scratch |= ((uint64_t)(num_bits_3)); + } + } + v_rounded_up_height = t_3; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); + uint32_t t_4; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { + t_4 = ((uint32_t)(wuffs_base__peek_u16be__no_bounds_check(iop_a_src))); + iop_a_src += 2; + } else { + self->private_data.s_do_decode_image_config.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10); + 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_4 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_4); + if (num_bits_4 == 8) { + t_4 = ((uint32_t)(*scratch >> 48)); + break; + } + num_bits_4 += 8u; + *scratch |= ((uint64_t)(num_bits_4)); + } + } + v_c32 = t_4; + } + if (((v_c32 + 3u) & 4294967292u) != ((uint32_t)(v_rounded_up_width))) { + status = wuffs_base__make_status(wuffs_etc2__error__bad_header); + goto exit; + } + self->private_impl.f_width = v_c32; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11); + uint32_t t_5; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { + t_5 = ((uint32_t)(wuffs_base__peek_u16be__no_bounds_check(iop_a_src))); + iop_a_src += 2; + } else { + self->private_data.s_do_decode_image_config.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12); + 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_5 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_5); + if (num_bits_5 == 8) { + t_5 = ((uint32_t)(*scratch >> 48)); + break; + } + num_bits_5 += 8u; + *scratch |= ((uint64_t)(num_bits_5)); + } + } + v_c32 = t_5; + } + if (((v_c32 + 3u) & 4294967292u) != ((uint32_t)(v_rounded_up_height))) { + status = wuffs_base__make_status(wuffs_etc2__error__bad_header); + goto exit; } + self->private_impl.f_height = v_c32; if (a_dst != NULL) { wuffs_base__image_config__set( a_dst, - 2198077448u, + self->private_impl.f_pixfmt, 0u, self->private_impl.f_width, self->private_impl.f_height, - self->private_impl.f_frame_config_io_position, - v_ffio); - } - if (self->private_impl.f_call_sequence == 0u) { - self->private_impl.f_call_sequence = 32u; + 16u, + (self->private_impl.f_pixfmt == 2415954056u)); } + self->private_impl.f_call_sequence = 32u; goto ok; ok: @@ -41111,43 +43144,25 @@ wuffs_gif__decoder__do_decode_image_config( goto suspend; suspend: self->private_impl.p_do_decode_image_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_data.s_do_decode_image_config.v_rounded_up_width = v_rounded_up_width; + self->private_data.s_do_decode_image_config.v_rounded_up_height = v_rounded_up_height; goto exit; exit: - return status; -} - -// -------- func gif.decoder.set_report_metadata - -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct -wuffs_gif__decoder__set_report_metadata( - wuffs_gif__decoder* self, - uint32_t a_fourcc, - bool a_report) { - if (!self) { - return wuffs_base__make_empty_struct(); - } - if (self->private_impl.magic != WUFFS_BASE__MAGIC) { - return wuffs_base__make_empty_struct(); + if (a_src && a_src->data.ptr) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); } - if (a_fourcc == 1229144912u) { - self->private_impl.f_report_metadata_iccp = a_report; - } else if (a_fourcc == 1481461792u) { - self->private_impl.f_report_metadata_xmp = a_report; - } - return wuffs_base__make_empty_struct(); + return status; } -// -------- func gif.decoder.tell_me_more +// -------- func etc2.decoder.decode_frame_config WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_gif__decoder__tell_me_more( - wuffs_gif__decoder* self, - wuffs_base__io_buffer* a_dst, - wuffs_base__more_information* a_minfo, +wuffs_etc2__decoder__decode_frame_config( + wuffs_etc2__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); @@ -41158,7 +43173,7 @@ wuffs_gif__decoder__tell_me_more( ? wuffs_base__error__disabled_by_previous_error : wuffs_base__error__initialize_not_called); } - if (!a_dst || !a_src) { + if (!a_src) { self->private_impl.magic = WUFFS_BASE__DISABLED; return wuffs_base__make_status(wuffs_base__error__bad_argument); } @@ -41172,17 +43187,17 @@ wuffs_gif__decoder__tell_me_more( wuffs_base__status v_status = wuffs_base__make_status(NULL); - uint32_t coro_susp_point = self->private_impl.p_tell_me_more; + 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_gif__decoder__do_tell_me_more(self, a_dst, a_minfo, a_src); + wuffs_base__status t_0 = wuffs_etc2__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_gif__error__truncated_input); + status = wuffs_base__make_status(wuffs_etc2__error__truncated_input); goto exit; } status = v_status; @@ -41190,13 +43205,13 @@ wuffs_gif__decoder__tell_me_more( } ok: - self->private_impl.p_tell_me_more = 0; + self->private_impl.p_decode_frame_config = 0; goto exit; } goto suspend; suspend: - self->private_impl.p_tell_me_more = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + 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; @@ -41207,19 +43222,16 @@ wuffs_gif__decoder__tell_me_more( return status; } -// -------- func gif.decoder.do_tell_me_more +// -------- func etc2.decoder.do_decode_frame_config WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_gif__decoder__do_tell_me_more( - wuffs_gif__decoder* self, - wuffs_base__io_buffer* a_dst, - wuffs_base__more_information* a_minfo, +wuffs_etc2__decoder__do_decode_frame_config( + wuffs_etc2__decoder* self, + wuffs_base__frame_config* a_dst, wuffs_base__io_buffer* a_src) { wuffs_base__status status = wuffs_base__make_status(NULL); - uint64_t v_chunk_length = 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; @@ -41231,92 +43243,62 @@ wuffs_gif__decoder__do_tell_me_more( io2_a_src = io0_a_src + a_src->meta.wi; } - uint32_t coro_susp_point = self->private_impl.p_do_tell_me_more; + uint32_t coro_susp_point = self->private_impl.p_do_decode_frame_config; switch (coro_susp_point) { WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - if (((uint8_t)(self->private_impl.f_call_sequence & 16u)) == 0u) { - status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence); - goto exit; - } - if (self->private_impl.f_metadata_fourcc == 0u) { - status = wuffs_base__make_status(wuffs_base__error__no_more_information); - goto exit; - } - while (true) { - while (true) { - if (wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))) != self->private_impl.f_metadata_io_position) { - if (a_minfo != NULL) { - wuffs_base__more_information__set(a_minfo, - 2u, - 0u, - self->private_impl.f_metadata_io_position, - 0u, - 0u); - } - status = wuffs_base__make_status(wuffs_base__suspension__mispositioned_read); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1); - continue; - } - if (((uint64_t)(io2_a_src - iop_a_src)) <= 0u) { - if (a_minfo != NULL) { - wuffs_base__more_information__set(a_minfo, - 0u, - 0u, - 0u, - 0u, - 0u); - } - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2); - continue; - } - break; + 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)); } - v_chunk_length = ((uint64_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))); - if (v_chunk_length <= 0u) { - iop_a_src += 1u; - break; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + status = wuffs_etc2__decoder__do_decode_image_config(self, NULL, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; } - if (self->private_impl.f_metadata_fourcc == 1481461792u) { - v_chunk_length += 1u; - } else { - iop_a_src += 1u; + if (status.repr) { + goto suspend; } - self->private_impl.f_metadata_io_position = wuffs_base__u64__sat_add(wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))), v_chunk_length); - if (a_minfo != NULL) { - wuffs_base__more_information__set(a_minfo, - 3u, - self->private_impl.f_metadata_fourcc, - 0u, - wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))), - self->private_impl.f_metadata_io_position); + } else if (self->private_impl.f_call_sequence == 40u) { + if (16u != 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; } - status = wuffs_base__make_status(wuffs_base__suspension__even_more_information); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3); + } 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_minfo != NULL) { - wuffs_base__more_information__set(a_minfo, - 3u, - self->private_impl.f_metadata_fourcc, + if (a_dst != NULL) { + wuffs_base__frame_config__set( + a_dst, + wuffs_base__utility__make_rect_ie_u32( 0u, - self->private_impl.f_metadata_io_position, - self->private_impl.f_metadata_io_position); + 0u, + self->private_impl.f_width, + self->private_impl.f_height), + ((wuffs_base__flicks)(0u)), + 0u, + 16u, + 0u, + (self->private_impl.f_pixfmt == 2415954056u), + false, + 4278190080u); } - self->private_impl.f_call_sequence &= 239u; - self->private_impl.f_metadata_fourcc = 0u; - self->private_impl.f_metadata_io_position = 0u; - status = wuffs_base__make_status(NULL); - goto ok; + self->private_impl.f_call_sequence = 64u; ok: - self->private_impl.p_do_tell_me_more = 0; + self->private_impl.p_do_decode_frame_config = 0; goto exit; } goto suspend; suspend: - self->private_impl.p_do_tell_me_more = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_impl.p_do_decode_frame_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; goto exit; exit: @@ -41327,352 +43309,188 @@ wuffs_gif__decoder__do_tell_me_more( return status; } -// -------- func gif.decoder.num_animation_loops +// -------- func etc2.decoder.decode_frame WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC uint32_t -wuffs_gif__decoder__num_animation_loops( - const wuffs_gif__decoder* self) { +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_etc2__decoder__decode_frame( + wuffs_etc2__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 0; + return wuffs_base__make_status(wuffs_base__error__bad_receiver); } - if ((self->private_impl.magic != WUFFS_BASE__MAGIC) && - (self->private_impl.magic != WUFFS_BASE__DISABLED)) { - return 0; + 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_seen_num_animation_loops_value) { - return self->private_impl.f_num_animation_loops_value; + 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.f_num_decoded_frame_configs_value > 1u) { - return 1u; + 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); } - return 0u; -} - -// -------- func gif.decoder.num_decoded_frame_configs + self->private_impl.active_coroutine = 0; + wuffs_base__status status = wuffs_base__make_status(NULL); -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC uint64_t -wuffs_gif__decoder__num_decoded_frame_configs( - const wuffs_gif__decoder* self) { - if (!self) { - return 0; - } - if ((self->private_impl.magic != WUFFS_BASE__MAGIC) && - (self->private_impl.magic != WUFFS_BASE__DISABLED)) { - return 0; - } + wuffs_base__status v_status = wuffs_base__make_status(NULL); - return self->private_impl.f_num_decoded_frame_configs_value; -} + uint32_t coro_susp_point = self->private_impl.p_decode_frame; + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; -// -------- func gif.decoder.num_decoded_frames + while (true) { + { + wuffs_base__status t_0 = wuffs_etc2__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_etc2__error__truncated_input); + goto exit; + } + status = v_status; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1); + } -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC uint64_t -wuffs_gif__decoder__num_decoded_frames( - const wuffs_gif__decoder* self) { - if (!self) { - return 0; - } - if ((self->private_impl.magic != WUFFS_BASE__MAGIC) && - (self->private_impl.magic != WUFFS_BASE__DISABLED)) { - return 0; + ok: + self->private_impl.p_decode_frame = 0; + goto exit; } - return self->private_impl.f_num_decoded_frames_value; + 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 gif.decoder.frame_dirty_rect - -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32 -wuffs_gif__decoder__frame_dirty_rect( - const wuffs_gif__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( - wuffs_base__u32__min(self->private_impl.f_frame_rect_x0, self->private_impl.f_width), - wuffs_base__u32__min(self->private_impl.f_frame_rect_y0, self->private_impl.f_height), - wuffs_base__u32__min(self->private_impl.f_frame_rect_x1, self->private_impl.f_width), - wuffs_base__u32__min(self->private_impl.f_dirty_max_excl_y, self->private_impl.f_height)); -} - -// -------- func gif.decoder.workbuf_len - -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 -wuffs_gif__decoder__workbuf_len( - const wuffs_gif__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); -} - -// -------- func gif.decoder.restart_frame - -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_gif__decoder__restart_frame( - wuffs_gif__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); - } else if (a_io_position == 0u) { - return wuffs_base__make_status(wuffs_base__error__bad_argument); - } - self->private_impl.f_delayed_num_decoded_frames = false; - self->private_impl.f_frame_config_io_position = a_io_position; - self->private_impl.f_num_decoded_frame_configs_value = a_index; - self->private_impl.f_num_decoded_frames_value = a_index; - wuffs_gif__decoder__reset_gc(self); - self->private_impl.f_call_sequence = 40u; - return wuffs_base__make_status(NULL); -} - -// -------- func gif.decoder.decode_frame_config - -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_gif__decoder__decode_frame_config( - wuffs_gif__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 != 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_config; - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - - while (true) { - { - wuffs_base__status t_0 = wuffs_gif__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_gif__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) ? 3 : 0; - - goto exit; - exit: - if (wuffs_base__status__is_error(&status)) { - self->private_impl.magic = WUFFS_BASE__DISABLED; - } - return status; -} - -// -------- func gif.decoder.do_decode_frame_config +// -------- func etc2.decoder.do_decode_frame WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_gif__decoder__do_decode_frame_config( - wuffs_gif__decoder* self, - wuffs_base__frame_config* a_dst, - wuffs_base__io_buffer* a_src) { +wuffs_etc2__decoder__do_decode_frame( + wuffs_etc2__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); - uint32_t v_background_color = 0; - uint8_t v_flags = 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 v_remaining = 0; + wuffs_base__status v_status = wuffs_base__make_status(NULL); - uint32_t coro_susp_point = self->private_impl.p_do_decode_frame_config; + uint32_t coro_susp_point = self->private_impl.p_do_decode_frame; if (coro_susp_point) { - v_background_color = self->private_data.s_do_decode_frame_config.v_background_color; + v_remaining = self->private_data.s_do_decode_frame.v_remaining; } switch (coro_susp_point) { WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - self->private_impl.f_dirty_max_excl_y = 0u; - if (((uint8_t)(self->private_impl.f_call_sequence & 16u)) != 0u) { - status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence); - goto exit; - } else 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)); - } + 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_gif__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 (self->private_impl.f_frame_config_io_position != 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) { - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); - status = wuffs_gif__decoder__skip_frame(self, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } + status = wuffs_etc2__decoder__do_decode_frame_config(self, NULL, a_src); if (status.repr) { goto suspend; } - if (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 ((self->private_impl.f_num_decoded_frame_configs_value > 0u) || (self->private_impl.f_call_sequence == 40u)) { - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + 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; } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - status = wuffs_gif__decoder__decode_up_to_id_part1(self, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; + goto ok; + } + self->private_impl.f_dst_x = 0u; + self->private_impl.f_dst_y = 0u; + v_remaining = (((self->private_impl.f_width + 3u) / 4u) * ((self->private_impl.f_height + 3u) / 4u)); + while (v_remaining > 0u) { + self->private_impl.f_num_buffered_blocks = wuffs_base__u32__min(v_remaining, 64u); + if (v_remaining < self->private_impl.f_num_buffered_blocks) { + status = wuffs_base__make_status(wuffs_base__error__too_much_data); + goto exit; } + v_remaining -= self->private_impl.f_num_buffered_blocks; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); + status = wuffs_etc2__decoder__from_src_to_colors(self, a_src); if (status.repr) { goto suspend; } - if (self->private_impl.f_call_sequence >= 96u) { - status = wuffs_base__make_status(wuffs_base__note__end_of_data); - goto ok; + wuffs_etc2__decoder__from_colors_to_buffer(self); + if (self->private_impl.f_pixfmt == 2164295816u) { + wuffs_etc2__decoder__from_alphas_to_buffer(self); } - } - v_background_color = self->private_impl.f_black_color_u32_argb_premul; - if ( ! self->private_impl.f_gc_has_transparent_index) { - v_background_color = self->private_impl.f_background_color_u32_argb_premul; - if (self->private_impl.f_quirks[1u] && (self->private_impl.f_num_decoded_frame_configs_value == 0u)) { - while (((uint64_t)(io2_a_src - iop_a_src)) <= 0u) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4); - } - v_flags = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); - if (((uint8_t)(v_flags & 128u)) != 0u) { - v_background_color = self->private_impl.f_black_color_u32_argb_premul; + v_status = wuffs_etc2__decoder__from_buffer_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; } } - if (a_dst != NULL) { - wuffs_base__frame_config__set( - a_dst, - wuffs_base__utility__make_rect_ie_u32( - wuffs_base__u32__min(self->private_impl.f_frame_rect_x0, self->private_impl.f_width), - wuffs_base__u32__min(self->private_impl.f_frame_rect_y0, self->private_impl.f_height), - wuffs_base__u32__min(self->private_impl.f_frame_rect_x1, self->private_impl.f_width), - wuffs_base__u32__min(self->private_impl.f_frame_rect_y1, self->private_impl.f_height)), - ((wuffs_base__flicks)(self->private_impl.f_gc_duration)), - self->private_impl.f_num_decoded_frame_configs_value, - self->private_impl.f_frame_config_io_position, - self->private_impl.f_gc_disposal, - ! self->private_impl.f_gc_has_transparent_index, - false, - v_background_color); - } - wuffs_private_impl__u64__sat_add_indirect(&self->private_impl.f_num_decoded_frame_configs_value, 1u); - self->private_impl.f_call_sequence = 64u; + self->private_impl.f_call_sequence = 96u; ok: - self->private_impl.p_do_decode_frame_config = 0; + self->private_impl.p_do_decode_frame = 0; goto exit; } goto suspend; suspend: - self->private_impl.p_do_decode_frame_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; - self->private_data.s_do_decode_frame_config.v_background_color = v_background_color; + self->private_impl.p_do_decode_frame = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_data.s_do_decode_frame.v_remaining = v_remaining; 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 gif.decoder.skip_frame +// -------- func etc2.decoder.from_src_to_colors WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_gif__decoder__skip_frame( - wuffs_gif__decoder* self, +wuffs_etc2__decoder__from_src_to_colors( + wuffs_etc2__decoder* self, wuffs_base__io_buffer* a_src) { wuffs_base__status status = wuffs_base__make_status(NULL); - uint8_t v_flags = 0; - uint8_t v_lw = 0; + uint32_t v_bi = 0; const uint8_t* iop_a_src = NULL; const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL; @@ -41685,71 +43503,87 @@ wuffs_gif__decoder__skip_frame( io2_a_src = io0_a_src + a_src->meta.wi; } - uint32_t coro_susp_point = self->private_impl.p_skip_frame; + uint32_t coro_susp_point = self->private_impl.p_from_src_to_colors; + if (coro_susp_point) { + v_bi = self->private_data.s_from_src_to_colors.v_bi; + } switch (coro_susp_point) { WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_0 = *iop_a_src++; - v_flags = t_0; - } - if (((uint8_t)(v_flags & 128u)) != 0u) { - self->private_data.s_skip_frame.scratch = (((uint32_t)(3u)) << ((uint8_t)(1u + ((uint8_t)(v_flags & 7u))))); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); - if (self->private_data.s_skip_frame.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { - self->private_data.s_skip_frame.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); - iop_a_src = io2_a_src; - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; + while (v_bi < self->private_impl.f_num_buffered_blocks) { + if (self->private_impl.f_pixfmt == 2164295816u) { + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + uint64_t t_0; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 8)) { + t_0 = wuffs_base__peek_u64be__no_bounds_check(iop_a_src); + iop_a_src += 8; + } else { + self->private_data.s_from_src_to_colors.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_from_src_to_colors.scratch; + uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0); + if (num_bits_0 == 56) { + t_0 = ((uint64_t)(*scratch >> 0)); + break; + } + num_bits_0 += 8u; + *scratch |= ((uint64_t)(num_bits_0)); + } + } + self->private_data.f_alphas[v_bi] = t_0; + } } - iop_a_src += self->private_data.s_skip_frame.scratch; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + uint64_t t_1; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 8)) { + t_1 = wuffs_base__peek_u64be__no_bounds_check(iop_a_src); + iop_a_src += 8; + } else { + self->private_data.s_from_src_to_colors.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + 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_from_src_to_colors.scratch; + uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1); + if (num_bits_1 == 56) { + t_1 = ((uint64_t)(*scratch >> 0)); + break; + } + num_bits_1 += 8u; + *scratch |= ((uint64_t)(num_bits_1)); + } + } + self->private_data.f_colors[v_bi] = t_1; } - uint8_t t_1 = *iop_a_src++; - v_lw = t_1; - } - if (v_lw > 8u) { - status = wuffs_base__make_status(wuffs_gif__error__bad_literal_width); - goto exit; - } - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); - status = wuffs_gif__decoder__skip_blocks(self, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; + v_bi += 1u; } - if (self->private_impl.f_quirks[0u]) { - self->private_impl.f_delayed_num_decoded_frames = true; - } else { - wuffs_private_impl__u64__sat_add_indirect(&self->private_impl.f_num_decoded_frames_value, 1u); - } - wuffs_gif__decoder__reset_gc(self); - self->private_impl.f_call_sequence = 32u; goto ok; ok: - self->private_impl.p_skip_frame = 0; + self->private_impl.p_from_src_to_colors = 0; goto exit; } goto suspend; suspend: - self->private_impl.p_skip_frame = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_impl.p_from_src_to_colors = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_data.s_from_src_to_colors.v_bi = v_bi; goto exit; exit: @@ -41760,1409 +43594,1269 @@ wuffs_gif__decoder__skip_frame( return status; } -// -------- func gif.decoder.decode_frame +// -------- func etc2.decoder.from_colors_to_buffer WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_gif__decoder__decode_frame( - wuffs_gif__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 != 4)) { - self->private_impl.magic = WUFFS_BASE__DISABLED; - return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls); +static wuffs_base__empty_struct +wuffs_etc2__decoder__from_colors_to_buffer( + wuffs_etc2__decoder* self) { + uint32_t v_bi = 0; + uint64_t v_color = 0; + uint32_t v_r0 = 0; + uint32_t v_r1 = 0; + uint32_t v_g0 = 0; + uint32_t v_g1 = 0; + uint32_t v_b0 = 0; + uint32_t v_b1 = 0; + bool v_diff = false; + bool v_tran = false; + bool v_flip = false; + + while (v_bi < self->private_impl.f_num_buffered_blocks) { + v_color = self->private_data.f_colors[v_bi]; + v_diff = ((v_color & 8589934592u) != 0u); + v_tran = ( ! v_diff && (self->private_impl.f_pixfmt == 2197850248u)); + if ( ! v_diff && (self->private_impl.f_pixfmt != 2197850248u)) { + v_r0 = ((uint32_t)((15u & (v_color >> 60u)))); + v_r0 = ((v_r0 << 4u) | v_r0); + v_r1 = ((uint32_t)((15u & (v_color >> 56u)))); + v_r1 = ((v_r1 << 4u) | v_r1); + v_g0 = ((uint32_t)((15u & (v_color >> 52u)))); + v_g0 = ((v_g0 << 4u) | v_g0); + v_g1 = ((uint32_t)((15u & (v_color >> 48u)))); + v_g1 = ((v_g1 << 4u) | v_g1); + v_b0 = ((uint32_t)((15u & (v_color >> 44u)))); + v_b0 = ((v_b0 << 4u) | v_b0); + v_b1 = ((uint32_t)((15u & (v_color >> 40u)))); + v_b1 = ((v_b1 << 4u) | v_b1); + } else { + v_r0 = ((uint32_t)((31u & (v_color >> 59u)))); + v_r1 = ((uint32_t)(v_r0 + WUFFS_ETC2__DIFFS[(7u & (v_color >> 56u))])); + if ((v_r1 >> 5u) != 0u) { + wuffs_etc2__decoder__decode_t_mode(self, v_color, (16u * v_bi), v_tran); + v_bi += 1u; + continue; + } + v_r0 = (((uint32_t)(v_r0 << 3u)) | (v_r0 >> 2u)); + v_r1 = (((uint32_t)(v_r1 << 3u)) | (v_r1 >> 2u)); + v_g0 = ((uint32_t)((31u & (v_color >> 51u)))); + v_g1 = ((uint32_t)(v_g0 + WUFFS_ETC2__DIFFS[(7u & (v_color >> 48u))])); + if ((v_g1 >> 5u) != 0u) { + wuffs_etc2__decoder__decode_h_mode(self, v_color, (16u * v_bi), v_tran); + v_bi += 1u; + continue; + } + v_g0 = (((uint32_t)(v_g0 << 3u)) | (v_g0 >> 2u)); + v_g1 = (((uint32_t)(v_g1 << 3u)) | (v_g1 >> 2u)); + v_b0 = ((uint32_t)((31u & (v_color >> 43u)))); + v_b1 = ((uint32_t)(v_b0 + WUFFS_ETC2__DIFFS[(7u & (v_color >> 40u))])); + if ((v_b1 >> 5u) != 0u) { + wuffs_etc2__decoder__decode_planar_mode(self, v_color, (16u * v_bi)); + v_bi += 1u; + continue; + } + v_b0 = (((uint32_t)(v_b0 << 3u)) | (v_b0 >> 2u)); + v_b1 = (((uint32_t)(v_b1 << 3u)) | (v_b1 >> 2u)); + } + v_flip = ((v_color & 4294967296u) != 0u); + wuffs_etc2__decoder__decode_half_block(self, + ((uint32_t)(v_color)), + (16u * v_bi), + ((uint32_t)(((v_color >> 37u) & 7u))), + v_r0, + v_g0, + v_b0, + v_flip, + v_tran, + false); + wuffs_etc2__decoder__decode_half_block(self, + ((uint32_t)(v_color)), + (16u * v_bi), + ((uint32_t)(((v_color >> 34u) & 7u))), + v_r1, + v_g1, + v_b1, + v_flip, + v_tran, + true); + v_bi += 1u; } - self->private_impl.active_coroutine = 0; - wuffs_base__status status = wuffs_base__make_status(NULL); + return wuffs_base__make_empty_struct(); +} - wuffs_base__status v_status = wuffs_base__make_status(NULL); +// -------- func etc2.decoder.decode_t_mode - uint32_t coro_susp_point = self->private_impl.p_decode_frame; - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_etc2__decoder__decode_t_mode( + wuffs_etc2__decoder* self, + uint64_t a_bits, + uint32_t a_offset, + bool a_transparent) { + uint8_t v_r[4] = {0}; + uint8_t v_g[4] = {0}; + uint8_t v_b[4] = {0}; + uint8_t v_a[4] = {0}; + uint32_t v_which = 0; + uint32_t v_delta = 0; + uint32_t v_y = 0; + uint32_t v_x = 0; + uint32_t v_x4y = 0; + uint32_t v_index = 0; + uint32_t v_o = 0; - while (true) { - { - wuffs_base__status t_0 = wuffs_gif__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_gif__error__truncated_input); - goto exit; - } - status = v_status; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1); + v_r[0u] = ((uint8_t)(((uint8_t)((12u & (a_bits >> 57u)))) | ((uint8_t)((3u & (a_bits >> 56u)))))); + v_r[0u] = ((uint8_t)(((uint8_t)(v_r[0u] << 4u)) | v_r[0u])); + v_g[0u] = ((uint8_t)((15u & (a_bits >> 52u)))); + v_g[0u] = ((uint8_t)(((uint8_t)(v_g[0u] << 4u)) | v_g[0u])); + v_b[0u] = ((uint8_t)((15u & (a_bits >> 48u)))); + v_b[0u] = ((uint8_t)(((uint8_t)(v_b[0u] << 4u)) | v_b[0u])); + v_a[0u] = 255u; + v_r[2u] = ((uint8_t)((15u & (a_bits >> 44u)))); + v_r[2u] = ((uint8_t)(((uint8_t)(v_r[2u] << 4u)) | v_r[2u])); + v_g[2u] = ((uint8_t)((15u & (a_bits >> 40u)))); + v_g[2u] = ((uint8_t)(((uint8_t)(v_g[2u] << 4u)) | v_g[2u])); + v_b[2u] = ((uint8_t)((15u & (a_bits >> 36u)))); + v_b[2u] = ((uint8_t)(((uint8_t)(v_b[2u] << 4u)) | v_b[2u])); + v_a[2u] = 255u; + v_which = (((uint32_t)((6u & (a_bits >> 33u)))) | ((uint32_t)((1u & (a_bits >> 32u))))); + v_delta = ((uint32_t)(WUFFS_ETC2__T_H_MODIFIERS[v_which])); + v_r[1u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_r[2u])) + v_delta)) & 1023u)]; + v_g[1u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_g[2u])) + v_delta)) & 1023u)]; + v_b[1u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_b[2u])) + v_delta)) & 1023u)]; + v_a[1u] = 255u; + v_r[3u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_r[2u])) - v_delta)) & 1023u)]; + v_g[3u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_g[2u])) - v_delta)) & 1023u)]; + v_b[3u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_b[2u])) - v_delta)) & 1023u)]; + v_a[3u] = 255u; + if (a_transparent) { + v_r[2u] = 0u; + v_g[2u] = 0u; + v_b[2u] = 0u; + v_a[2u] = 0u; + } + while (v_y < 4u) { + v_x = 0u; + while (v_x < 4u) { + v_x4y = ((v_x * 4u) | v_y); + v_index = (((uint32_t)(((a_bits >> v_x4y) & 1u))) | ((uint32_t)(((a_bits >> (v_x4y + 15u)) & 2u)))); + v_o = (a_offset + (v_x * 4u) + (v_y * 1024u)); + self->private_data.f_buffer[(v_o + 0u)] = v_b[v_index]; + self->private_data.f_buffer[(v_o + 1u)] = v_g[v_index]; + self->private_data.f_buffer[(v_o + 2u)] = v_r[v_index]; + self->private_data.f_buffer[(v_o + 3u)] = v_a[v_index]; + v_x += 1u; } - - ok: - self->private_impl.p_decode_frame = 0; - goto exit; + v_y += 1u; } + return wuffs_base__make_empty_struct(); +} - 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) ? 4 : 0; +// -------- func etc2.decoder.decode_h_mode - goto exit; - exit: - if (wuffs_base__status__is_error(&status)) { - self->private_impl.magic = WUFFS_BASE__DISABLED; +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_etc2__decoder__decode_h_mode( + wuffs_etc2__decoder* self, + uint64_t a_bits, + uint32_t a_offset, + bool a_transparent) { + uint8_t v_r[4] = {0}; + uint8_t v_g[4] = {0}; + uint8_t v_b[4] = {0}; + uint8_t v_a[4] = {0}; + uint32_t v_rgb0 = 0; + uint32_t v_rgb2 = 0; + uint32_t v_which = 0; + uint32_t v_delta = 0; + uint32_t v_y = 0; + uint32_t v_x = 0; + uint32_t v_x4y = 0; + uint32_t v_index = 0; + uint32_t v_o = 0; + + v_r[0u] = ((uint8_t)((15u & (a_bits >> 59u)))); + v_r[0u] = ((uint8_t)(((uint8_t)(v_r[0u] << 4u)) | v_r[0u])); + v_g[0u] = ((uint8_t)(((uint8_t)((14u & (a_bits >> 55u)))) | ((uint8_t)((1u & (a_bits >> 52u)))))); + v_g[0u] = ((uint8_t)(((uint8_t)(v_g[0u] << 4u)) | v_g[0u])); + v_b[0u] = ((uint8_t)(((uint8_t)((8u & (a_bits >> 48u)))) | ((uint8_t)((7u & (a_bits >> 47u)))))); + v_b[0u] = ((uint8_t)(((uint8_t)(v_b[0u] << 4u)) | v_b[0u])); + v_r[2u] = ((uint8_t)((15u & (a_bits >> 43u)))); + v_r[2u] = ((uint8_t)(((uint8_t)(v_r[2u] << 4u)) | v_r[2u])); + v_g[2u] = ((uint8_t)((15u & (a_bits >> 39u)))); + v_g[2u] = ((uint8_t)(((uint8_t)(v_g[2u] << 4u)) | v_g[2u])); + v_b[2u] = ((uint8_t)((15u & (a_bits >> 35u)))); + v_b[2u] = ((uint8_t)(((uint8_t)(v_b[2u] << 4u)) | v_b[2u])); + v_rgb0 = ((((uint32_t)(v_r[0u])) << 16u) | (((uint32_t)(v_g[0u])) << 8u) | (((uint32_t)(v_b[0u])) << 0u)); + v_rgb2 = ((((uint32_t)(v_r[2u])) << 16u) | (((uint32_t)(v_g[2u])) << 8u) | (((uint32_t)(v_b[2u])) << 0u)); + v_which = (((uint32_t)((4u & (a_bits >> 32u)))) | ((uint32_t)((2u & (a_bits >> 31u))))); + if (v_rgb0 >= v_rgb2) { + v_which |= 1u; + } + v_delta = ((uint32_t)(WUFFS_ETC2__T_H_MODIFIERS[v_which])); + v_r[1u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_r[0u])) - v_delta)) & 1023u)]; + v_g[1u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_g[0u])) - v_delta)) & 1023u)]; + v_b[1u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_b[0u])) - v_delta)) & 1023u)]; + v_a[1u] = 255u; + v_r[0u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_r[0u])) + v_delta)) & 1023u)]; + v_g[0u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_g[0u])) + v_delta)) & 1023u)]; + v_b[0u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_b[0u])) + v_delta)) & 1023u)]; + v_a[0u] = 255u; + v_r[3u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_r[2u])) - v_delta)) & 1023u)]; + v_g[3u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_g[2u])) - v_delta)) & 1023u)]; + v_b[3u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_b[2u])) - v_delta)) & 1023u)]; + v_a[3u] = 255u; + v_r[2u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_r[2u])) + v_delta)) & 1023u)]; + v_g[2u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_g[2u])) + v_delta)) & 1023u)]; + v_b[2u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_b[2u])) + v_delta)) & 1023u)]; + v_a[2u] = 255u; + if (a_transparent) { + v_r[2u] = 0u; + v_g[2u] = 0u; + v_b[2u] = 0u; + v_a[2u] = 0u; + } + while (v_y < 4u) { + v_x = 0u; + while (v_x < 4u) { + v_x4y = ((v_x * 4u) | v_y); + v_index = (((uint32_t)(((a_bits >> v_x4y) & 1u))) | ((uint32_t)(((a_bits >> (v_x4y + 15u)) & 2u)))); + v_o = (a_offset + (v_x * 4u) + (v_y * 1024u)); + self->private_data.f_buffer[(v_o + 0u)] = v_b[v_index]; + self->private_data.f_buffer[(v_o + 1u)] = v_g[v_index]; + self->private_data.f_buffer[(v_o + 2u)] = v_r[v_index]; + self->private_data.f_buffer[(v_o + 3u)] = v_a[v_index]; + v_x += 1u; + } + v_y += 1u; } - return status; + return wuffs_base__make_empty_struct(); } -// -------- func gif.decoder.do_decode_frame +// -------- func etc2.decoder.decode_planar_mode WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_gif__decoder__do_decode_frame( - wuffs_gif__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); +static wuffs_base__empty_struct +wuffs_etc2__decoder__decode_planar_mode( + wuffs_etc2__decoder* self, + uint64_t a_bits, + uint32_t a_offset) { + uint32_t v_ro = 0; + uint32_t v_go = 0; + uint32_t v_bo = 0; + uint32_t v_rh = 0; + uint32_t v_gh = 0; + uint32_t v_bh = 0; + uint32_t v_rv = 0; + uint32_t v_gv = 0; + uint32_t v_bv = 0; + uint32_t v_y = 0; + uint32_t v_x = 0; + uint32_t v_o = 0; + uint32_t v_rp = 0; + uint32_t v_gp = 0; + uint32_t v_bp = 0; + + v_ro = ((uint32_t)((63u & (a_bits >> 57u)))); + v_ro = (((uint32_t)(v_ro << 2u)) | (v_ro >> 4u)); + v_go = (((uint32_t)((64u & (a_bits >> 50u)))) | ((uint32_t)((63u & (a_bits >> 49u))))); + v_go = (((uint32_t)(v_go << 1u)) | (v_go >> 6u)); + v_bo = (((uint32_t)((32u & (a_bits >> 43u)))) | ((uint32_t)((24u & (a_bits >> 40u)))) | ((uint32_t)((7u & (a_bits >> 39u))))); + v_bo = (((uint32_t)(v_bo << 2u)) | (v_bo >> 4u)); + v_rh = (((uint32_t)((62u & (a_bits >> 33u)))) | ((uint32_t)((1u & (a_bits >> 32u))))); + v_rh = (((uint32_t)(v_rh << 2u)) | (v_rh >> 4u)); + v_gh = ((uint32_t)((127u & (a_bits >> 25u)))); + v_gh = (((uint32_t)(v_gh << 1u)) | (v_gh >> 6u)); + v_bh = ((uint32_t)((63u & (a_bits >> 19u)))); + v_bh = (((uint32_t)(v_bh << 2u)) | (v_bh >> 4u)); + v_rv = ((uint32_t)((63u & (a_bits >> 13u)))); + v_rv = (((uint32_t)(v_rv << 2u)) | (v_rv >> 4u)); + v_gv = ((uint32_t)((127u & (a_bits >> 6u)))); + v_gv = (((uint32_t)(v_gv << 1u)) | (v_gv >> 6u)); + v_bv = ((uint32_t)((63u & (a_bits >> 0u)))); + v_bv = (((uint32_t)(v_bv << 2u)) | (v_bv >> 4u)); + v_rh -= v_ro; + v_gh -= v_go; + v_bh -= v_bo; + v_rv -= v_ro; + v_gv -= v_go; + v_bv -= v_bo; + v_ro *= 4u; + v_go *= 4u; + v_bo *= 4u; + while (v_y < 4u) { + v_x = 0u; + while (v_x < 4u) { + v_o = (a_offset + (v_x * 4u) + (v_y * 1024u)); + v_bp = ((uint32_t)(((uint32_t)(((uint32_t)(v_x * v_bh)) + ((uint32_t)(v_y * v_bv)))) + v_bo)); + self->private_data.f_buffer[(v_o + 0u)] = WUFFS_ETC2__CLAMP[((((uint32_t)(v_bp + 2u)) / 4u) & 1023u)]; + v_gp = ((uint32_t)(((uint32_t)(((uint32_t)(v_x * v_gh)) + ((uint32_t)(v_y * v_gv)))) + v_go)); + self->private_data.f_buffer[(v_o + 1u)] = WUFFS_ETC2__CLAMP[((((uint32_t)(v_gp + 2u)) / 4u) & 1023u)]; + v_rp = ((uint32_t)(((uint32_t)(((uint32_t)(v_x * v_rh)) + ((uint32_t)(v_y * v_rv)))) + v_ro)); + self->private_data.f_buffer[(v_o + 2u)] = WUFFS_ETC2__CLAMP[((((uint32_t)(v_rp + 2u)) / 4u) & 1023u)]; + v_x += 1u; + self->private_data.f_buffer[(v_o + 3u)] = 255u; + } + v_y += 1u; + } + return wuffs_base__make_empty_struct(); +} - uint32_t coro_susp_point = self->private_impl.p_do_decode_frame; - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; +// -------- func etc2.decoder.decode_half_block - 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_gif__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; - } - if (self->private_impl.f_quirks[5u] && ((self->private_impl.f_frame_rect_x0 == self->private_impl.f_frame_rect_x1) || (self->private_impl.f_frame_rect_y0 == self->private_impl.f_frame_rect_y1))) { - status = wuffs_base__make_status(wuffs_gif__error__bad_frame_size); - goto exit; - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); - status = wuffs_gif__decoder__decode_id_part1(self, a_dst, a_src, a_blend); - if (status.repr) { - goto suspend; - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - status = wuffs_gif__decoder__decode_id_part2(self, a_dst, a_src, a_workbuf); - if (status.repr) { - goto suspend; - } - wuffs_private_impl__u64__sat_add_indirect(&self->private_impl.f_num_decoded_frames_value, 1u); - wuffs_gif__decoder__reset_gc(self); - self->private_impl.f_call_sequence = 32u; +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_etc2__decoder__decode_half_block( + wuffs_etc2__decoder* self, + uint32_t a_bits, + uint32_t a_offset, + uint32_t a_which, + uint32_t a_r, + uint32_t a_g, + uint32_t a_b, + bool a_flip, + bool a_transparent, + bool a_second) { + uint32_t v_which = 0; + uint32_t v_x0 = 0; + uint32_t v_y0 = 0; + uint32_t v_x = 0; + uint32_t v_y = 0; + uint32_t v_i = 0; + uint32_t v_x4y = 0; + uint32_t v_index = 0; + uint32_t v_modif = 0; + uint32_t v_o = 0; - ok: - self->private_impl.p_do_decode_frame = 0; - goto exit; + v_which = a_which; + if (a_transparent) { + v_which |= 8u; } - - 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; + if ( ! a_second) { + } else if (a_flip) { + v_y0 = 2u; + } else { + v_x0 = 2u; + } + while (v_i < 8u) { + if (a_flip) { + v_x = ((v_x0 + (v_i / 2u)) & 3u); + v_y = (v_y0 + (v_i & 1u)); + } else { + v_x = (v_x0 + (v_i / 4u)); + v_y = ((v_y0 + v_i) & 3u); + } + v_x4y = ((v_x * 4u) | v_y); + v_index = (((a_bits >> v_x4y) & 1u) | ((a_bits >> (v_x4y + 15u)) & 2u)); + v_modif = WUFFS_ETC2__MODIFIERS[v_which][v_index]; + v_o = (a_offset + (v_x * 4u) + (v_y * 1024u)); + if (a_transparent && (v_index == 2u)) { + self->private_data.f_buffer[(v_o + 0u)] = 0u; + self->private_data.f_buffer[(v_o + 1u)] = 0u; + self->private_data.f_buffer[(v_o + 2u)] = 0u; + self->private_data.f_buffer[(v_o + 3u)] = 0u; + } else { + self->private_data.f_buffer[(v_o + 0u)] = WUFFS_ETC2__CLAMP[(((uint32_t)(a_b + v_modif)) & 1023u)]; + self->private_data.f_buffer[(v_o + 1u)] = WUFFS_ETC2__CLAMP[(((uint32_t)(a_g + v_modif)) & 1023u)]; + self->private_data.f_buffer[(v_o + 2u)] = WUFFS_ETC2__CLAMP[(((uint32_t)(a_r + v_modif)) & 1023u)]; + self->private_data.f_buffer[(v_o + 3u)] = 255u; + } + v_i += 1u; + } + return wuffs_base__make_empty_struct(); } -// -------- func gif.decoder.reset_gc +// -------- func etc2.decoder.from_alphas_to_buffer WUFFS_BASE__GENERATED_C_CODE static wuffs_base__empty_struct -wuffs_gif__decoder__reset_gc( - wuffs_gif__decoder* self) { - self->private_impl.f_gc_has_transparent_index = false; - self->private_impl.f_gc_transparent_index = 0u; - self->private_impl.f_gc_disposal = 0u; - self->private_impl.f_gc_duration = 0u; +wuffs_etc2__decoder__from_alphas_to_buffer( + wuffs_etc2__decoder* self) { + uint32_t v_bi = 0; + uint64_t v_alpha = 0; + uint32_t v_a0 = 0; + uint32_t v_multiplier = 0; + uint32_t v_which = 0; + uint32_t v_offset = 0; + uint32_t v_y = 0; + uint32_t v_x = 0; + uint32_t v_shift = 0; + uint32_t v_delta = 0; + uint32_t v_o = 0; + + while (v_bi < self->private_impl.f_num_buffered_blocks) { + v_alpha = self->private_data.f_alphas[v_bi]; + v_a0 = ((uint32_t)((v_alpha >> 56u))); + v_multiplier = ((uint32_t)(((v_alpha >> 52u) & 15u))); + v_which = ((uint32_t)(((v_alpha >> 48u) & 15u))); + v_offset = (16u * v_bi); + v_y = 0u; + while (v_y < 4u) { + v_x = 0u; + while (v_x < 4u) { + v_shift = ((((v_x ^ 3u) * 4u) | (v_y ^ 3u)) * 3u); + v_delta = ((uint32_t)(v_multiplier * WUFFS_ETC2__ALPHA_MODIFIERS[v_which][(7u & (v_alpha >> v_shift))])); + v_o = (v_offset + (v_x * 4u) + (v_y * 1024u)); + self->private_data.f_buffer[(v_o + 3u)] = WUFFS_ETC2__CLAMP[(((uint32_t)(v_a0 + v_delta)) & 1023u)]; + v_x += 1u; + } + v_y += 1u; + } + v_bi += 1u; + } return wuffs_base__make_empty_struct(); } -// -------- func gif.decoder.decode_up_to_id_part1 +// -------- func etc2.decoder.from_buffer_to_dst WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_gif__decoder__decode_up_to_id_part1( - wuffs_gif__decoder* self, - wuffs_base__io_buffer* a_src) { - wuffs_base__status status = wuffs_base__make_status(NULL); - - uint8_t v_block_type = 0; +wuffs_etc2__decoder__from_buffer_to_dst( + wuffs_etc2__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_bi = 0; + uint32_t v_rem_x = 0; + uint32_t v_dy = 0; + wuffs_base__slice_u8 v_dst = {0}; + wuffs_base__slice_u8 v_src = {0}; + uint32_t v_si = 0; + uint32_t v_sj = 0; + uint64_t v_i = 0; + uint32_t v_num_src_pixels = 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; + 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); } - - uint32_t coro_susp_point = self->private_impl.p_decode_up_to_id_part1; - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - - if ((self->private_impl.f_frame_config_io_position == 0u) || (self->private_impl.f_num_decoded_frame_configs_value > 0u)) { - self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))); + 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_bi < self->private_impl.f_num_buffered_blocks) { + if (self->private_impl.f_width <= self->private_impl.f_dst_x) { + self->private_impl.f_dst_x = 0u; + self->private_impl.f_dst_y += 4u; + if (self->private_impl.f_dst_y >= self->private_impl.f_height) { + break; + } + v_rem_x = self->private_impl.f_width; + } else { + v_rem_x = (self->private_impl.f_width - self->private_impl.f_dst_x); } - while (true) { - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_0 = *iop_a_src++; - v_block_type = t_0; + v_dy = 0u; + while (v_dy < 4u) { + v_si = ((1024u * v_dy) + (16u * v_bi)); + v_sj = ((1024u * v_dy) + 1024u); + if (v_si < v_sj) { + v_src = wuffs_base__make_slice_u8_ij(self->private_data.f_buffer, v_si, v_sj); } - if (v_block_type == 33u) { - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); - status = wuffs_gif__decoder__decode_extension(self, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; - } - } else if (v_block_type == 44u) { - if (self->private_impl.f_delayed_num_decoded_frames) { - self->private_impl.f_delayed_num_decoded_frames = false; - wuffs_private_impl__u64__sat_add_indirect(&self->private_impl.f_num_decoded_frames_value, 1u); - } - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - status = wuffs_gif__decoder__decode_id_part0(self, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; - } - break; - } else { - if (self->private_impl.f_delayed_num_decoded_frames) { - self->private_impl.f_delayed_num_decoded_frames = false; - wuffs_private_impl__u64__sat_add_indirect(&self->private_impl.f_num_decoded_frames_value, 1u); - } - self->private_impl.f_call_sequence = 96u; + if (((uint64_t)((4u * v_rem_x))) < ((uint64_t)(v_src.len))) { + v_src = wuffs_base__slice_u8__subslice_j(v_src, ((uint64_t)((4u * v_rem_x)))); + } + if (((uint32_t)(self->private_impl.f_dst_y + v_dy)) >= self->private_impl.f_height) { break; } + v_dst = wuffs_private_impl__table_u8__row_u32(v_tab, ((uint32_t)(self->private_impl.f_dst_y + v_dy))); + 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); + } + v_i = (((uint64_t)(self->private_impl.f_dst_x)) * ((uint64_t)(v_dst_bytes_per_pixel))); + if (v_i < ((uint64_t)(v_dst.len))) { + wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), wuffs_base__pixel_buffer__palette(a_dst), v_src); + } + v_dy += 1u; } - - goto ok; - ok: - self->private_impl.p_decode_up_to_id_part1 = 0; - goto exit; + v_num_src_pixels = (((uint32_t)(((uint64_t)(v_src.len)))) / 4u); + self->private_impl.f_dst_x += v_num_src_pixels; + v_bi += ((v_num_src_pixels + 3u) / 4u); } + return wuffs_base__make_status(NULL); +} - goto suspend; - suspend: - self->private_impl.p_decode_up_to_id_part1 = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; +// -------- func etc2.decoder.frame_dirty_rect - goto exit; - exit: - if (a_src && a_src->data.ptr) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32 +wuffs_etc2__decoder__frame_dirty_rect( + const wuffs_etc2__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 status; + return wuffs_base__utility__make_rect_ie_u32( + 0u, + 0u, + self->private_impl.f_width, + self->private_impl.f_height); } -// -------- func gif.decoder.decode_header +// -------- func etc2.decoder.num_animation_loops WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_gif__decoder__decode_header( - wuffs_gif__decoder* self, - wuffs_base__io_buffer* a_src) { - wuffs_base__status status = wuffs_base__make_status(NULL); - - uint64_t v_c48 = 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; +WUFFS_BASE__MAYBE_STATIC uint32_t +wuffs_etc2__decoder__num_animation_loops( + const wuffs_etc2__decoder* self) { + if (!self) { + return 0; + } + if ((self->private_impl.magic != WUFFS_BASE__MAGIC) && + (self->private_impl.magic != WUFFS_BASE__DISABLED)) { + return 0; } - uint32_t coro_susp_point = self->private_impl.p_decode_header; - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + return 0u; +} - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - uint64_t t_0; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 6)) { - t_0 = ((uint64_t)(wuffs_base__peek_u48le__no_bounds_check(iop_a_src))); - iop_a_src += 6; - } else { - self->private_data.s_decode_header.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_decode_header.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 == 40) { - t_0 = ((uint64_t)(*scratch)); - break; - } - num_bits_0 += 8u; - *scratch |= ((uint64_t)(num_bits_0)) << 56; - } - } - v_c48 = t_0; - } - if ((v_c48 != 106889795225927u) && (v_c48 != 106898385160519u)) { - status = wuffs_base__make_status(wuffs_gif__error__bad_header); - goto exit; - } +// -------- func etc2.decoder.num_decoded_frame_configs - goto ok; - ok: - self->private_impl.p_decode_header = 0; - goto exit; +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC uint64_t +wuffs_etc2__decoder__num_decoded_frame_configs( + const wuffs_etc2__decoder* self) { + if (!self) { + return 0; } - - goto suspend; - suspend: - self->private_impl.p_decode_header = 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)); + if ((self->private_impl.magic != WUFFS_BASE__MAGIC) && + (self->private_impl.magic != WUFFS_BASE__DISABLED)) { + return 0; } - return status; + if (self->private_impl.f_call_sequence > 32u) { + return 1u; + } + return 0u; } -// -------- func gif.decoder.decode_lsd +// -------- func etc2.decoder.num_decoded_frames WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_gif__decoder__decode_lsd( - wuffs_gif__decoder* self, - wuffs_base__io_buffer* a_src) { - wuffs_base__status status = wuffs_base__make_status(NULL); - - uint8_t v_flags = 0; - uint8_t v_background_color_index = 0; - uint32_t v_num_palette_entries = 0; - uint32_t v_i = 0; - uint32_t v_j = 0; - uint32_t v_argb = 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; +WUFFS_BASE__MAYBE_STATIC uint64_t +wuffs_etc2__decoder__num_decoded_frames( + const wuffs_etc2__decoder* self) { + if (!self) { + return 0; } - - uint32_t coro_susp_point = self->private_impl.p_decode_lsd; - if (coro_susp_point) { - v_flags = self->private_data.s_decode_lsd.v_flags; - v_background_color_index = self->private_data.s_decode_lsd.v_background_color_index; - v_num_palette_entries = self->private_data.s_decode_lsd.v_num_palette_entries; - v_i = self->private_data.s_decode_lsd.v_i; + if ((self->private_impl.magic != WUFFS_BASE__MAGIC) && + (self->private_impl.magic != WUFFS_BASE__DISABLED)) { + return 0; } - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - uint32_t t_0; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { - t_0 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src))); - iop_a_src += 2; - } else { - self->private_data.s_decode_lsd.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_decode_lsd.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 == 8) { - t_0 = ((uint32_t)(*scratch)); - break; - } - num_bits_0 += 8u; - *scratch |= ((uint64_t)(num_bits_0)) << 56; - } - } - self->private_impl.f_width = t_0; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - uint32_t t_1; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { - t_1 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src))); - iop_a_src += 2; - } else { - self->private_data.s_decode_lsd.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); - 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_decode_lsd.scratch; - uint32_t num_bits_1 = ((uint32_t)(*scratch >> 56)); - *scratch <<= 8; - *scratch >>= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_1; - if (num_bits_1 == 8) { - t_1 = ((uint32_t)(*scratch)); - break; - } - num_bits_1 += 8u; - *scratch |= ((uint64_t)(num_bits_1)) << 56; - } - } - self->private_impl.f_height = t_1; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_2 = *iop_a_src++; - v_flags = t_2; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_3 = *iop_a_src++; - v_background_color_index = t_3; - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - iop_a_src++; - v_i = 0u; - self->private_impl.f_has_global_palette = (((uint8_t)(v_flags & 128u)) != 0u); - if (self->private_impl.f_has_global_palette) { - v_num_palette_entries = (((uint32_t)(1u)) << ((uint8_t)(1u + ((uint8_t)(v_flags & 7u))))); - while (v_i < v_num_palette_entries) { - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); - uint32_t t_4; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 3)) { - t_4 = ((uint32_t)(wuffs_base__peek_u24be__no_bounds_check(iop_a_src))); - iop_a_src += 3; - } else { - self->private_data.s_decode_lsd.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); - 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_decode_lsd.scratch; - uint32_t num_bits_4 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_4); - if (num_bits_4 == 16) { - t_4 = ((uint32_t)(*scratch >> 40)); - break; - } - num_bits_4 += 8u; - *scratch |= ((uint64_t)(num_bits_4)); - } - } - v_argb = t_4; - } - v_argb |= 4278190080u; - self->private_data.f_palettes[0u][((4u * v_i) + 0u)] = ((uint8_t)((v_argb >> 0u))); - self->private_data.f_palettes[0u][((4u * v_i) + 1u)] = ((uint8_t)((v_argb >> 8u))); - self->private_data.f_palettes[0u][((4u * v_i) + 2u)] = ((uint8_t)((v_argb >> 16u))); - self->private_data.f_palettes[0u][((4u * v_i) + 3u)] = ((uint8_t)((v_argb >> 24u))); - v_i += 1u; - } - if (self->private_impl.f_quirks[2u]) { - if ((v_background_color_index != 0u) && (((uint32_t)(v_background_color_index)) < v_num_palette_entries)) { - v_j = (4u * ((uint32_t)(v_background_color_index))); - self->private_impl.f_background_color_u32_argb_premul = ((((uint32_t)(self->private_data.f_palettes[0u][(v_j + 0u)])) << 0u) | - (((uint32_t)(self->private_data.f_palettes[0u][(v_j + 1u)])) << 8u) | - (((uint32_t)(self->private_data.f_palettes[0u][(v_j + 2u)])) << 16u) | - (((uint32_t)(self->private_data.f_palettes[0u][(v_j + 3u)])) << 24u)); - } else { - self->private_impl.f_background_color_u32_argb_premul = 77u; - } - } - } - while (v_i < 256u) { - self->private_data.f_palettes[0u][((4u * v_i) + 0u)] = 0u; - self->private_data.f_palettes[0u][((4u * v_i) + 1u)] = 0u; - self->private_data.f_palettes[0u][((4u * v_i) + 2u)] = 0u; - self->private_data.f_palettes[0u][((4u * v_i) + 3u)] = 255u; - v_i += 1u; - } - goto ok; - ok: - self->private_impl.p_decode_lsd = 0; - goto exit; + if (self->private_impl.f_call_sequence > 64u) { + return 1u; } + return 0u; +} - goto suspend; - suspend: - self->private_impl.p_decode_lsd = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; - self->private_data.s_decode_lsd.v_flags = v_flags; - self->private_data.s_decode_lsd.v_background_color_index = v_background_color_index; - self->private_data.s_decode_lsd.v_num_palette_entries = v_num_palette_entries; - self->private_data.s_decode_lsd.v_i = v_i; +// -------- func etc2.decoder.restart_frame - goto exit; - exit: - if (a_src && a_src->data.ptr) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_etc2__decoder__restart_frame( + wuffs_etc2__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); } - return status; + 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 != 16u)) { + return wuffs_base__make_status(wuffs_base__error__bad_argument); + } + self->private_impl.f_call_sequence = 40u; + return wuffs_base__make_status(NULL); } -// -------- func gif.decoder.decode_extension +// -------- func etc2.decoder.set_report_metadata WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_gif__decoder__decode_extension( - wuffs_gif__decoder* self, - wuffs_base__io_buffer* a_src) { - wuffs_base__status status = wuffs_base__make_status(NULL); +WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct +wuffs_etc2__decoder__set_report_metadata( + wuffs_etc2__decoder* self, + uint32_t a_fourcc, + bool a_report) { + return wuffs_base__make_empty_struct(); +} - uint8_t v_label = 0; +// -------- func etc2.decoder.tell_me_more - 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; +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_etc2__decoder__tell_me_more( + wuffs_etc2__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); } - - uint32_t coro_susp_point = self->private_impl.p_decode_extension; - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_0 = *iop_a_src++; - v_label = t_0; - } - if (v_label == 249u) { - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); - status = wuffs_gif__decoder__decode_gc(self, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; - } - status = wuffs_base__make_status(NULL); - goto ok; - } else if (v_label == 255u) { - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - status = wuffs_gif__decoder__decode_ae(self, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; - } - status = wuffs_base__make_status(NULL); - goto ok; - } - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); - status = wuffs_gif__decoder__skip_blocks(self, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; - } - - ok: - self->private_impl.p_decode_extension = 0; - goto exit; + 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); - goto suspend; - suspend: - self->private_impl.p_decode_extension = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + status = wuffs_base__make_status(wuffs_base__error__no_more_information); + goto exit; + goto ok; + ok: goto exit; exit: - if (a_src && a_src->data.ptr) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + if (wuffs_base__status__is_error(&status)) { + self->private_impl.magic = WUFFS_BASE__DISABLED; } - return status; } -// -------- func gif.decoder.skip_blocks +// -------- func etc2.decoder.workbuf_len WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_gif__decoder__skip_blocks( - wuffs_gif__decoder* self, - wuffs_base__io_buffer* a_src) { - wuffs_base__status status = wuffs_base__make_status(NULL); +WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 +wuffs_etc2__decoder__workbuf_len( + const wuffs_etc2__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(); + } - uint8_t v_block_size = 0; + return wuffs_base__utility__make_range_ii_u64(0u, 0u); +} - 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; - } +#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ETC2) - uint32_t coro_susp_point = self->private_impl.p_skip_blocks; - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; +#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GIF) - while (true) { - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_0 = *iop_a_src++; - v_block_size = t_0; - } - if (v_block_size == 0u) { - status = wuffs_base__make_status(NULL); - goto ok; - } - self->private_data.s_skip_blocks.scratch = ((uint32_t)(v_block_size)); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); - if (self->private_data.s_skip_blocks.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { - self->private_data.s_skip_blocks.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); - iop_a_src = io2_a_src; - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - iop_a_src += self->private_data.s_skip_blocks.scratch; - } +// ---------------- Status Codes Implementations - ok: - self->private_impl.p_skip_blocks = 0; - goto exit; - } +const char wuffs_gif__error__bad_lzw_code[] = "#gif: bad LZW code"; +const char wuffs_gif__error__bad_extension_label[] = "#gif: bad extension label"; +const char wuffs_gif__error__bad_frame_size[] = "#gif: bad frame size"; +const char wuffs_gif__error__bad_graphic_control[] = "#gif: bad graphic control"; +const char wuffs_gif__error__bad_header[] = "#gif: bad header"; +const char wuffs_gif__error__bad_literal_width[] = "#gif: bad literal width"; +const char wuffs_gif__error__bad_palette[] = "#gif: bad palette"; +const char wuffs_gif__error__truncated_input[] = "#gif: truncated input"; +const char wuffs_gif__error__internal_error_inconsistent_i_o[] = "#gif: internal error: inconsistent I/O"; - goto suspend; - suspend: - self->private_impl.p_skip_blocks = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; +// ---------------- Private Consts - goto exit; - exit: - if (a_src && a_src->data.ptr) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } +static const uint32_t +WUFFS_GIF__INTERLACE_START[5] WUFFS_BASE__POTENTIALLY_UNUSED = { + 4294967295u, 1u, 2u, 4u, 0u, +}; - return status; -} +static const uint8_t +WUFFS_GIF__INTERLACE_DELTA[5] WUFFS_BASE__POTENTIALLY_UNUSED = { + 1u, 2u, 4u, 8u, 8u, +}; -// -------- func gif.decoder.decode_ae +static const uint8_t +WUFFS_GIF__INTERLACE_COUNT[5] WUFFS_BASE__POTENTIALLY_UNUSED = { + 0u, 1u, 2u, 4u, 8u, +}; + +static const uint8_t +WUFFS_GIF__ANIMEXTS1DOT0[11] WUFFS_BASE__POTENTIALLY_UNUSED = { + 65u, 78u, 73u, 77u, 69u, 88u, 84u, 83u, + 49u, 46u, 48u, +}; + +static const uint8_t +WUFFS_GIF__NETSCAPE2DOT0[11] WUFFS_BASE__POTENTIALLY_UNUSED = { + 78u, 69u, 84u, 83u, 67u, 65u, 80u, 69u, + 50u, 46u, 48u, +}; + +static const uint8_t +WUFFS_GIF__ICCRGBG1012[11] WUFFS_BASE__POTENTIALLY_UNUSED = { + 73u, 67u, 67u, 82u, 71u, 66u, 71u, 49u, + 48u, 49u, 50u, +}; + +static const uint8_t +WUFFS_GIF__XMPDATAXMP[11] WUFFS_BASE__POTENTIALLY_UNUSED = { + 88u, 77u, 80u, 32u, 68u, 97u, 116u, 97u, + 88u, 77u, 80u, +}; + +#define WUFFS_GIF__QUIRKS_BASE 983928832u + +#define WUFFS_GIF__QUIRKS_COUNT 7u + +// ---------------- Private Initializer Prototypes + +// ---------------- Private Function Prototypes WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_gif__decoder__decode_ae( +wuffs_gif__decoder__do_decode_image_config( wuffs_gif__decoder* self, - wuffs_base__io_buffer* a_src) { - wuffs_base__status status = wuffs_base__make_status(NULL); + wuffs_base__image_config* a_dst, + wuffs_base__io_buffer* a_src); - uint8_t v_c8 = 0; - uint8_t v_block_size = 0; - bool v_is_animexts = false; - bool v_is_netscape = false; - bool v_is_iccp = false; - bool v_is_xmp = false; +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_gif__decoder__do_tell_me_more( + wuffs_gif__decoder* self, + wuffs_base__io_buffer* a_dst, + wuffs_base__more_information* a_minfo, + wuffs_base__io_buffer* a_src); - 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; - } +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_gif__decoder__do_decode_frame_config( + wuffs_gif__decoder* self, + wuffs_base__frame_config* a_dst, + wuffs_base__io_buffer* a_src); - uint32_t coro_susp_point = self->private_impl.p_decode_ae; - if (coro_susp_point) { - v_block_size = self->private_data.s_decode_ae.v_block_size; - v_is_animexts = self->private_data.s_decode_ae.v_is_animexts; - v_is_netscape = self->private_data.s_decode_ae.v_is_netscape; - v_is_iccp = self->private_data.s_decode_ae.v_is_iccp; - v_is_xmp = self->private_data.s_decode_ae.v_is_xmp; - } - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_gif__decoder__skip_frame( + wuffs_gif__decoder* self, + wuffs_base__io_buffer* a_src); - do { - if (self->private_impl.f_metadata_fourcc != 0u) { - status = wuffs_base__make_status(wuffs_base__note__metadata_reported); - goto ok; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_0 = *iop_a_src++; - v_block_size = t_0; - } - if (v_block_size == 0u) { - status = wuffs_base__make_status(NULL); - goto ok; - } - if (v_block_size != 11u) { - self->private_data.s_decode_ae.scratch = ((uint32_t)(v_block_size)); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); - if (self->private_data.s_decode_ae.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { - self->private_data.s_decode_ae.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); - iop_a_src = io2_a_src; - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - iop_a_src += self->private_data.s_decode_ae.scratch; - break; - } - v_is_animexts = true; - v_is_netscape = true; - v_is_iccp = true; - v_is_xmp = true; - v_block_size = 0u; - while (v_block_size < 11u) { - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_1 = *iop_a_src++; - v_c8 = t_1; - } - v_is_animexts = (v_is_animexts && (v_c8 == WUFFS_GIF__ANIMEXTS1DOT0[v_block_size])); - v_is_netscape = (v_is_netscape && (v_c8 == WUFFS_GIF__NETSCAPE2DOT0[v_block_size])); - v_is_iccp = (v_is_iccp && (v_c8 == WUFFS_GIF__ICCRGBG1012[v_block_size])); - v_is_xmp = (v_is_xmp && (v_c8 == WUFFS_GIF__XMPDATAXMP[v_block_size])); -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - v_block_size += 1u; -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - } - if (v_is_animexts || v_is_netscape) { - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_2 = *iop_a_src++; - v_block_size = t_2; - } - if (v_block_size != 3u) { - self->private_data.s_decode_ae.scratch = ((uint32_t)(v_block_size)); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); - if (self->private_data.s_decode_ae.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { - self->private_data.s_decode_ae.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); - iop_a_src = io2_a_src; - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - iop_a_src += self->private_data.s_decode_ae.scratch; - break; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_3 = *iop_a_src++; - v_c8 = t_3; - } - if (v_c8 != 1u) { - self->private_data.s_decode_ae.scratch = 2u; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); - if (self->private_data.s_decode_ae.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { - self->private_data.s_decode_ae.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); - iop_a_src = io2_a_src; - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - iop_a_src += self->private_data.s_decode_ae.scratch; - break; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); - uint32_t t_4; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { - t_4 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src))); - iop_a_src += 2; - } else { - self->private_data.s_decode_ae.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); - 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_decode_ae.scratch; - uint32_t num_bits_4 = ((uint32_t)(*scratch >> 56)); - *scratch <<= 8; - *scratch >>= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_4; - if (num_bits_4 == 8) { - t_4 = ((uint32_t)(*scratch)); - break; - } - num_bits_4 += 8u; - *scratch |= ((uint64_t)(num_bits_4)) << 56; - } - } - self->private_impl.f_num_animation_loops_value = t_4; - } - self->private_impl.f_seen_num_animation_loops_value = true; - if ((0u < self->private_impl.f_num_animation_loops_value) && (self->private_impl.f_num_animation_loops_value <= 65535u)) { - self->private_impl.f_num_animation_loops_value += 1u; - } - } else if (self->private_impl.f_call_sequence >= 32u) { - } else if (v_is_iccp && self->private_impl.f_report_metadata_iccp) { - self->private_impl.f_metadata_fourcc = 1229144912u; - self->private_impl.f_metadata_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))); - self->private_impl.f_call_sequence = 16u; - status = wuffs_base__make_status(wuffs_base__note__metadata_reported); - goto ok; - } else if (v_is_xmp && self->private_impl.f_report_metadata_xmp) { - self->private_impl.f_metadata_fourcc = 1481461792u; - self->private_impl.f_metadata_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))); - self->private_impl.f_call_sequence = 16u; - status = wuffs_base__make_status(wuffs_base__note__metadata_reported); - goto ok; - } - } while (0); - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10); - status = wuffs_gif__decoder__skip_blocks(self, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; - } +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_gif__decoder__do_decode_frame( + wuffs_gif__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); - ok: - self->private_impl.p_decode_ae = 0; - goto exit; - } +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_gif__decoder__reset_gc( + wuffs_gif__decoder* self); - goto suspend; - suspend: - self->private_impl.p_decode_ae = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; - self->private_data.s_decode_ae.v_block_size = v_block_size; - self->private_data.s_decode_ae.v_is_animexts = v_is_animexts; - self->private_data.s_decode_ae.v_is_netscape = v_is_netscape; - self->private_data.s_decode_ae.v_is_iccp = v_is_iccp; - self->private_data.s_decode_ae.v_is_xmp = v_is_xmp; +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_gif__decoder__decode_up_to_id_part1( + wuffs_gif__decoder* self, + wuffs_base__io_buffer* a_src); - goto exit; - exit: - if (a_src && a_src->data.ptr) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_gif__decoder__decode_header( + wuffs_gif__decoder* self, + wuffs_base__io_buffer* a_src); - return status; -} +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_gif__decoder__decode_lsd( + wuffs_gif__decoder* self, + wuffs_base__io_buffer* a_src); -// -------- func gif.decoder.decode_gc +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_gif__decoder__decode_extension( + wuffs_gif__decoder* self, + wuffs_base__io_buffer* a_src); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_gif__decoder__skip_blocks( + wuffs_gif__decoder* self, + wuffs_base__io_buffer* a_src); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_gif__decoder__decode_ae( + wuffs_gif__decoder* self, + wuffs_base__io_buffer* a_src); WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status wuffs_gif__decoder__decode_gc( wuffs_gif__decoder* self, - wuffs_base__io_buffer* a_src) { - wuffs_base__status status = wuffs_base__make_status(NULL); + wuffs_base__io_buffer* a_src); - uint8_t v_c8 = 0; - uint8_t v_flags = 0; - uint16_t v_gc_duration_centiseconds = 0; +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_gif__decoder__decode_id_part0( + wuffs_gif__decoder* self, + wuffs_base__io_buffer* a_src); - 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; - } +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_gif__decoder__decode_id_part1( + wuffs_gif__decoder* self, + wuffs_base__pixel_buffer* a_dst, + wuffs_base__io_buffer* a_src, + wuffs_base__pixel_blend a_blend); - uint32_t coro_susp_point = self->private_impl.p_decode_gc; - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_gif__decoder__decode_id_part2( + wuffs_gif__decoder* self, + wuffs_base__pixel_buffer* a_dst, + wuffs_base__io_buffer* a_src, + wuffs_base__slice_u8 a_workbuf); - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_0 = *iop_a_src++; - v_c8 = t_0; - } - if (v_c8 != 4u) { - status = wuffs_base__make_status(wuffs_gif__error__bad_graphic_control); - goto exit; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_1 = *iop_a_src++; - v_flags = t_1; +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_gif__decoder__copy_to_image_buffer( + wuffs_gif__decoder* self, + wuffs_base__pixel_buffer* a_pb, + wuffs_base__slice_u8 a_src); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_gif__decoder__lzw_init( + wuffs_gif__decoder* self); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_gif__decoder__lzw_read_from( + wuffs_gif__decoder* self, + wuffs_base__io_buffer* a_src); + +// ---------------- VTables + +const wuffs_base__image_decoder__func_ptrs +wuffs_gif__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_gif__decoder__decode_frame), + (wuffs_base__status(*)(void*, + wuffs_base__frame_config*, + wuffs_base__io_buffer*))(&wuffs_gif__decoder__decode_frame_config), + (wuffs_base__status(*)(void*, + wuffs_base__image_config*, + wuffs_base__io_buffer*))(&wuffs_gif__decoder__decode_image_config), + (wuffs_base__rect_ie_u32(*)(const void*))(&wuffs_gif__decoder__frame_dirty_rect), + (uint64_t(*)(const void*, + uint32_t))(&wuffs_gif__decoder__get_quirk), + (uint32_t(*)(const void*))(&wuffs_gif__decoder__num_animation_loops), + (uint64_t(*)(const void*))(&wuffs_gif__decoder__num_decoded_frame_configs), + (uint64_t(*)(const void*))(&wuffs_gif__decoder__num_decoded_frames), + (wuffs_base__status(*)(void*, + uint64_t, + uint64_t))(&wuffs_gif__decoder__restart_frame), + (wuffs_base__status(*)(void*, + uint32_t, + uint64_t))(&wuffs_gif__decoder__set_quirk), + (wuffs_base__empty_struct(*)(void*, + uint32_t, + bool))(&wuffs_gif__decoder__set_report_metadata), + (wuffs_base__status(*)(void*, + wuffs_base__io_buffer*, + wuffs_base__more_information*, + wuffs_base__io_buffer*))(&wuffs_gif__decoder__tell_me_more), + (wuffs_base__range_ii_u64(*)(const void*))(&wuffs_gif__decoder__workbuf_len), +}; + +// ---------------- Initializer Implementations + +wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT +wuffs_gif__decoder__initialize( + wuffs_gif__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); } - self->private_impl.f_gc_has_transparent_index = (((uint8_t)(v_flags & 1u)) != 0u); - v_flags = ((uint8_t)(((uint8_t)(v_flags >> 2u)) & 7u)); - if (v_flags == 2u) { - self->private_impl.f_gc_disposal = 1u; - } else if ((v_flags == 3u) || (v_flags == 4u)) { - self->private_impl.f_gc_disposal = 2u; +#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 { - self->private_impl.f_gc_disposal = 0u; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - uint16_t t_2; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { - t_2 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src); - iop_a_src += 2; - } else { - self->private_data.s_decode_gc.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); - 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_decode_gc.scratch; - uint32_t num_bits_2 = ((uint32_t)(*scratch >> 56)); - *scratch <<= 8; - *scratch >>= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_2; - if (num_bits_2 == 8) { - t_2 = ((uint16_t)(*scratch)); - break; - } - num_bits_2 += 8u; - *scratch |= ((uint64_t)(num_bits_2)) << 56; - } - } - v_gc_duration_centiseconds = t_2; - } - self->private_impl.f_gc_duration = (((uint64_t)(v_gc_duration_centiseconds)) * 7056000u); - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_3 = *iop_a_src++; - self->private_impl.f_gc_transparent_index = t_3; + memset(&(self->private_impl), 0, sizeof(self->private_impl)); } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; + } + + 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_gif__decoder__func_ptrs_for__wuffs_base__image_decoder); + return wuffs_base__make_status(NULL); +} + +wuffs_gif__decoder* +wuffs_gif__decoder__alloc(void) { + wuffs_gif__decoder* x = + (wuffs_gif__decoder*)(calloc(1, sizeof(wuffs_gif__decoder))); + if (!x) { + return NULL; + } + if (wuffs_gif__decoder__initialize( + x, sizeof(wuffs_gif__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) { + free(x); + return NULL; + } + return x; +} + +size_t +sizeof__wuffs_gif__decoder(void) { + return sizeof(wuffs_gif__decoder); +} + +// ---------------- Function Implementations + +// -------- func gif.decoder.get_quirk + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC uint64_t +wuffs_gif__decoder__get_quirk( + const wuffs_gif__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; + } + + uint32_t v_key = 0; + + if (a_key >= 983928832u) { + v_key = (a_key - 983928832u); + if (v_key < 7u) { + if (self->private_impl.f_quirks[v_key]) { + return 1u; } - uint8_t t_4 = *iop_a_src++; - v_c8 = t_4; - } - if (v_c8 != 0u) { - status = wuffs_base__make_status(wuffs_gif__error__bad_graphic_control); - goto exit; } - - goto ok; - ok: - self->private_impl.p_decode_gc = 0; - goto exit; } + return 0u; +} - goto suspend; - suspend: - self->private_impl.p_decode_gc = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; +// -------- func gif.decoder.set_quirk - goto exit; - exit: - if (a_src && a_src->data.ptr) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_gif__decoder__set_quirk( + wuffs_gif__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 status; + if ((self->private_impl.f_call_sequence == 0u) && (a_key >= 983928832u)) { + a_key -= 983928832u; + if (a_key < 7u) { + self->private_impl.f_quirks[a_key] = (a_value > 0u); + return wuffs_base__make_status(NULL); + } + } + return wuffs_base__make_status(wuffs_base__error__unsupported_option); } -// -------- func gif.decoder.decode_id_part0 +// -------- func gif.decoder.decode_image_config WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_gif__decoder__decode_id_part0( +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_gif__decoder__decode_image_config( wuffs_gif__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); - 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; - } + wuffs_base__status v_status = wuffs_base__make_status(NULL); - uint32_t coro_susp_point = self->private_impl.p_decode_id_part0; + uint32_t coro_susp_point = self->private_impl.p_decode_image_config; switch (coro_susp_point) { WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - uint32_t t_0; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { - t_0 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src))); - iop_a_src += 2; - } else { - self->private_data.s_decode_id_part0.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_decode_id_part0.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 == 8) { - t_0 = ((uint32_t)(*scratch)); - break; - } - num_bits_0 += 8u; - *scratch |= ((uint64_t)(num_bits_0)) << 56; - } - } - self->private_impl.f_frame_rect_x0 = t_0; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - uint32_t t_1; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { - t_1 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src))); - iop_a_src += 2; - } else { - self->private_data.s_decode_id_part0.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); - 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_decode_id_part0.scratch; - uint32_t num_bits_1 = ((uint32_t)(*scratch >> 56)); - *scratch <<= 8; - *scratch >>= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_1; - if (num_bits_1 == 8) { - t_1 = ((uint32_t)(*scratch)); - break; - } - num_bits_1 += 8u; - *scratch |= ((uint64_t)(num_bits_1)) << 56; - } - } - self->private_impl.f_frame_rect_y0 = t_1; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); - uint32_t t_2; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { - t_2 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src))); - iop_a_src += 2; - } else { - self->private_data.s_decode_id_part0.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); - 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_decode_id_part0.scratch; - uint32_t num_bits_2 = ((uint32_t)(*scratch >> 56)); - *scratch <<= 8; - *scratch >>= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_2; - if (num_bits_2 == 8) { - t_2 = ((uint32_t)(*scratch)); - break; - } - num_bits_2 += 8u; - *scratch |= ((uint64_t)(num_bits_2)) << 56; - } + while (true) { + { + wuffs_base__status t_0 = wuffs_gif__decoder__do_decode_image_config(self, a_dst, a_src); + v_status = t_0; } - self->private_impl.f_frame_rect_x1 = t_2; - } - self->private_impl.f_frame_rect_x1 += self->private_impl.f_frame_rect_x0; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); - uint32_t t_3; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { - t_3 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src))); - iop_a_src += 2; - } else { - self->private_data.s_decode_id_part0.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); - 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_decode_id_part0.scratch; - uint32_t num_bits_3 = ((uint32_t)(*scratch >> 56)); - *scratch <<= 8; - *scratch >>= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_3; - if (num_bits_3 == 8) { - t_3 = ((uint32_t)(*scratch)); - break; - } - num_bits_3 += 8u; - *scratch |= ((uint64_t)(num_bits_3)) << 56; - } + if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) { + status = wuffs_base__make_status(wuffs_gif__error__truncated_input); + goto exit; } - self->private_impl.f_frame_rect_y1 = t_3; - } - self->private_impl.f_frame_rect_y1 += self->private_impl.f_frame_rect_y0; - self->private_impl.f_dst_x = self->private_impl.f_frame_rect_x0; - self->private_impl.f_dst_y = self->private_impl.f_frame_rect_y0; - if ((self->private_impl.f_num_decoded_frame_configs_value == 0u) && ! self->private_impl.f_quirks[4u]) { - self->private_impl.f_width = wuffs_base__u32__max(self->private_impl.f_width, self->private_impl.f_frame_rect_x1); - self->private_impl.f_height = wuffs_base__u32__max(self->private_impl.f_height, self->private_impl.f_frame_rect_y1); + status = v_status; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1); } - goto ok; ok: - self->private_impl.p_decode_id_part0 = 0; + self->private_impl.p_decode_image_config = 0; goto exit; } goto suspend; suspend: - self->private_impl.p_decode_id_part0 = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + 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 (a_src && a_src->data.ptr) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + if (wuffs_base__status__is_error(&status)) { + self->private_impl.magic = WUFFS_BASE__DISABLED; } - return status; } -// -------- func gif.decoder.decode_id_part1 +// -------- func gif.decoder.do_decode_image_config WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_gif__decoder__decode_id_part1( +wuffs_gif__decoder__do_decode_image_config( wuffs_gif__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__io_buffer* a_src, - wuffs_base__pixel_blend a_blend) { + wuffs_base__image_config* a_dst, + wuffs_base__io_buffer* a_src) { wuffs_base__status status = wuffs_base__make_status(NULL); - uint8_t v_flags = 0; - uint8_t v_which_palette = 0; - uint32_t v_num_palette_entries = 0; - uint32_t v_i = 0; - uint32_t v_argb = 0; - wuffs_base__status v_status = wuffs_base__make_status(NULL); - uint8_t v_lw = 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; - } + bool v_ffio = false; - uint32_t coro_susp_point = self->private_impl.p_decode_id_part1; - if (coro_susp_point) { - v_which_palette = self->private_data.s_decode_id_part1.v_which_palette; - v_num_palette_entries = self->private_data.s_decode_id_part1.v_num_palette_entries; - v_i = self->private_data.s_decode_id_part1.v_i; - } + 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; + } else if ( ! self->private_impl.f_seen_header) { WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); + status = wuffs_gif__decoder__decode_header(self, a_src); + if (status.repr) { goto suspend; } - uint8_t t_0 = *iop_a_src++; - v_flags = t_0; - } - if (((uint8_t)(v_flags & 64u)) != 0u) { - self->private_impl.f_interlace = 4u; - } else { - self->private_impl.f_interlace = 0u; - } - v_which_palette = 1u; - if (((uint8_t)(v_flags & 128u)) != 0u) { - v_num_palette_entries = (((uint32_t)(1u)) << ((uint8_t)(1u + ((uint8_t)(v_flags & 7u))))); - v_i = 0u; - while (v_i < v_num_palette_entries) { - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); - uint32_t t_1; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 3)) { - t_1 = ((uint32_t)(wuffs_base__peek_u24be__no_bounds_check(iop_a_src))); - iop_a_src += 3; - } else { - self->private_data.s_decode_id_part1.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - 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_decode_id_part1.scratch; - uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1); - if (num_bits_1 == 16) { - t_1 = ((uint32_t)(*scratch >> 40)); - break; - } - num_bits_1 += 8u; - *scratch |= ((uint64_t)(num_bits_1)); - } - } - v_argb = t_1; - } - v_argb |= 4278190080u; - self->private_data.f_palettes[1u][((4u * v_i) + 0u)] = ((uint8_t)((v_argb >> 0u))); - self->private_data.f_palettes[1u][((4u * v_i) + 1u)] = ((uint8_t)((v_argb >> 8u))); - self->private_data.f_palettes[1u][((4u * v_i) + 2u)] = ((uint8_t)((v_argb >> 16u))); - self->private_data.f_palettes[1u][((4u * v_i) + 3u)] = ((uint8_t)((v_argb >> 24u))); - v_i += 1u; - } - while (v_i < 256u) { - self->private_data.f_palettes[1u][((4u * v_i) + 0u)] = 0u; - self->private_data.f_palettes[1u][((4u * v_i) + 1u)] = 0u; - self->private_data.f_palettes[1u][((4u * v_i) + 2u)] = 0u; - self->private_data.f_palettes[1u][((4u * v_i) + 3u)] = 255u; - v_i += 1u; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); + status = wuffs_gif__decoder__decode_lsd(self, a_src); + if (status.repr) { + goto suspend; } - } else if (self->private_impl.f_quirks[6u] && ! self->private_impl.f_has_global_palette) { - status = wuffs_base__make_status(wuffs_gif__error__bad_palette); - goto exit; - } else if (self->private_impl.f_gc_has_transparent_index) { - wuffs_private_impl__slice_u8__copy_from_slice(wuffs_base__make_slice_u8(self->private_data.f_palettes[1u], 1024), wuffs_base__make_slice_u8(self->private_data.f_palettes[0u], 1024)); - } else { - v_which_palette = 0u; + self->private_impl.f_seen_header = true; } - if (self->private_impl.f_gc_has_transparent_index) { - self->private_data.f_palettes[1u][((4u * ((uint32_t)(self->private_impl.f_gc_transparent_index))) + 0u)] = 0u; - self->private_data.f_palettes[1u][((4u * ((uint32_t)(self->private_impl.f_gc_transparent_index))) + 1u)] = 0u; - self->private_data.f_palettes[1u][((4u * ((uint32_t)(self->private_impl.f_gc_transparent_index))) + 2u)] = 0u; - self->private_data.f_palettes[1u][((4u * ((uint32_t)(self->private_impl.f_gc_transparent_index))) + 3u)] = 0u; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + status = wuffs_gif__decoder__decode_up_to_id_part1(self, a_src); + if (status.repr) { + goto suspend; } - 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_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024)), - wuffs_base__utility__make_pixel_format(2198077448u), - wuffs_base__make_slice_u8(self->private_data.f_palettes[v_which_palette], 1024), - 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; + v_ffio = ! self->private_impl.f_gc_has_transparent_index; + if ( ! self->private_impl.f_quirks[2u]) { + v_ffio = (v_ffio && + (self->private_impl.f_frame_rect_x0 == 0u) && + (self->private_impl.f_frame_rect_y0 == 0u) && + (self->private_impl.f_frame_rect_x1 == self->private_impl.f_width) && + (self->private_impl.f_frame_rect_y1 == self->private_impl.f_height)); + } else if (v_ffio) { + self->private_impl.f_black_color_u32_argb_premul = 4278190080u; } - if (self->private_impl.f_ignored_but_affects_benchmarks) { + if (self->private_impl.f_background_color_u32_argb_premul == 77u) { + self->private_impl.f_background_color_u32_argb_premul = self->private_impl.f_black_color_u32_argb_premul; } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_2 = *iop_a_src++; - v_lw = t_2; + if (a_dst != NULL) { + wuffs_base__image_config__set( + a_dst, + 2198077448u, + 0u, + self->private_impl.f_width, + self->private_impl.f_height, + self->private_impl.f_frame_config_io_position, + v_ffio); } - if (v_lw > 8u) { - status = wuffs_base__make_status(wuffs_gif__error__bad_literal_width); - goto exit; + if (self->private_impl.f_call_sequence == 0u) { + self->private_impl.f_call_sequence = 32u; } - self->private_impl.f_lzw_pending_literal_width_plus_one = ((uint32_t)(((uint8_t)(1u + v_lw)))); - self->private_impl.f_ignored_but_affects_benchmarks = true; + goto ok; ok: - self->private_impl.p_decode_id_part1 = 0; + self->private_impl.p_do_decode_image_config = 0; goto exit; } goto suspend; suspend: - self->private_impl.p_decode_id_part1 = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; - self->private_data.s_decode_id_part1.v_which_palette = v_which_palette; - self->private_data.s_decode_id_part1.v_num_palette_entries = v_num_palette_entries; - self->private_data.s_decode_id_part1.v_i = v_i; + 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 gif.decoder.set_report_metadata + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct +wuffs_gif__decoder__set_report_metadata( + wuffs_gif__decoder* self, + uint32_t a_fourcc, + bool a_report) { + if (!self) { + return wuffs_base__make_empty_struct(); + } + if (self->private_impl.magic != WUFFS_BASE__MAGIC) { + return wuffs_base__make_empty_struct(); + } + + if (a_fourcc == 1229144912u) { + self->private_impl.f_report_metadata_iccp = a_report; + } else if (a_fourcc == 1481461792u) { + self->private_impl.f_report_metadata_xmp = a_report; + } + return wuffs_base__make_empty_struct(); +} + +// -------- func gif.decoder.tell_me_more + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_gif__decoder__tell_me_more( + wuffs_gif__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 != 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_tell_me_more; + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + + while (true) { + { + wuffs_base__status t_0 = wuffs_gif__decoder__do_tell_me_more(self, a_dst, a_minfo, 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_gif__error__truncated_input); + goto exit; + } + status = v_status; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1); + } + + ok: + self->private_impl.p_tell_me_more = 0; + goto exit; } + goto suspend; + suspend: + self->private_impl.p_tell_me_more = 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 gif.decoder.decode_id_part2 +// -------- func gif.decoder.do_tell_me_more WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_gif__decoder__decode_id_part2( +wuffs_gif__decoder__do_tell_me_more( wuffs_gif__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__io_buffer* a_src, - wuffs_base__slice_u8 a_workbuf) { + wuffs_base__io_buffer* a_dst, + wuffs_base__more_information* a_minfo, + wuffs_base__io_buffer* a_src) { wuffs_base__status status = wuffs_base__make_status(NULL); - uint64_t v_block_size = 0; - bool v_need_block_size = false; - uint32_t v_n_copied = 0; - uint64_t v_n_compressed = 0; - wuffs_base__io_buffer u_r = wuffs_base__empty_io_buffer(); - wuffs_base__io_buffer* v_r = &u_r; - const uint8_t* iop_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - const uint8_t* io0_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - const uint8_t* io1_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - const uint8_t* io2_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - uint64_t v_mark = 0; - wuffs_base__status v_copy_status = wuffs_base__make_status(NULL); + uint64_t v_chunk_length = 0; const uint8_t* iop_a_src = NULL; const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL; @@ -43175,185 +44869,92 @@ wuffs_gif__decoder__decode_id_part2( io2_a_src = io0_a_src + a_src->meta.wi; } - uint32_t coro_susp_point = self->private_impl.p_decode_id_part2; - if (coro_susp_point) { - v_block_size = self->private_data.s_decode_id_part2.v_block_size; - v_need_block_size = self->private_data.s_decode_id_part2.v_need_block_size; - } + uint32_t coro_susp_point = self->private_impl.p_do_tell_me_more; switch (coro_susp_point) { WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - wuffs_gif__decoder__lzw_init(self); - v_need_block_size = true; - label__outer__continue:; + if (((uint8_t)(self->private_impl.f_call_sequence & 16u)) == 0u) { + status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence); + goto exit; + } + if (self->private_impl.f_metadata_fourcc == 0u) { + status = wuffs_base__make_status(wuffs_base__error__no_more_information); + goto exit; + } while (true) { - if (v_need_block_size) { - v_need_block_size = false; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; + while (true) { + if (wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))) != self->private_impl.f_metadata_io_position) { + if (a_minfo != NULL) { + wuffs_base__more_information__set(a_minfo, + 2u, + 0u, + self->private_impl.f_metadata_io_position, + 0u, + 0u); } - uint64_t t_0 = *iop_a_src++; - v_block_size = t_0; + status = wuffs_base__make_status(wuffs_base__suspension__mispositioned_read); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1); + continue; + } + if (((uint64_t)(io2_a_src - iop_a_src)) <= 0u) { + if (a_minfo != NULL) { + wuffs_base__more_information__set(a_minfo, + 0u, + 0u, + 0u, + 0u, + 0u); + } + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2); + continue; } - } - if (v_block_size == 0u) { break; } - while (((uint64_t)(io2_a_src - iop_a_src)) == 0u) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2); - } - if (self->private_impl.f_compressed_ri == self->private_impl.f_compressed_wi) { - self->private_impl.f_compressed_ri = 0u; - self->private_impl.f_compressed_wi = 0u; + v_chunk_length = ((uint64_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))); + if (v_chunk_length <= 0u) { + iop_a_src += 1u; + break; } - while (self->private_impl.f_compressed_wi <= 3841u) { - v_n_compressed = wuffs_base__u64__min(v_block_size, ((uint64_t)(io2_a_src - iop_a_src))); - if (v_n_compressed <= 0u) { - break; - } - v_n_copied = wuffs_private_impl__io_reader__limited_copy_u32_to_slice( - &iop_a_src, io2_a_src,((uint32_t)(v_n_compressed)), wuffs_base__make_slice_u8_ij(self->private_data.f_compressed, self->private_impl.f_compressed_wi, 4096)); - wuffs_private_impl__u64__sat_add_indirect(&self->private_impl.f_compressed_wi, ((uint64_t)(v_n_copied))); - wuffs_private_impl__u64__sat_sub_indirect(&v_block_size, ((uint64_t)(v_n_copied))); - if (v_block_size > 0u) { - break; - } - if (((uint64_t)(io2_a_src - iop_a_src)) <= 0u) { - v_need_block_size = true; - break; - } - v_block_size = ((uint64_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))); + if (self->private_impl.f_metadata_fourcc == 1481461792u) { + v_chunk_length += 1u; + } else { iop_a_src += 1u; } - while (true) { - if ((self->private_impl.f_compressed_ri > self->private_impl.f_compressed_wi) || (self->private_impl.f_compressed_wi > 4096u)) { - status = wuffs_base__make_status(wuffs_gif__error__internal_error_inconsistent_i_o); - goto exit; - } - { - wuffs_base__io_buffer* o_0_v_r = v_r; - const uint8_t* o_0_iop_v_r = iop_v_r; - const uint8_t* o_0_io0_v_r = io0_v_r; - const uint8_t* o_0_io1_v_r = io1_v_r; - const uint8_t* o_0_io2_v_r = io2_v_r; - v_r = wuffs_private_impl__io_reader__set( - &u_r, - &iop_v_r, - &io0_v_r, - &io1_v_r, - &io2_v_r, - wuffs_base__make_slice_u8_ij(self->private_data.f_compressed, - self->private_impl.f_compressed_ri, - self->private_impl.f_compressed_wi), - 0u); - v_mark = ((uint64_t)(iop_v_r - io0_v_r)); - u_r.meta.ri = ((size_t)(iop_v_r - u_r.data.ptr)); - wuffs_gif__decoder__lzw_read_from(self, v_r); - iop_v_r = u_r.data.ptr + u_r.meta.ri; - wuffs_private_impl__u64__sat_add_indirect(&self->private_impl.f_compressed_ri, wuffs_private_impl__io__count_since(v_mark, ((uint64_t)(iop_v_r - io0_v_r)))); - v_r = o_0_v_r; - iop_v_r = o_0_iop_v_r; - io0_v_r = o_0_io0_v_r; - io1_v_r = o_0_io1_v_r; - io2_v_r = o_0_io2_v_r; - } - if (self->private_impl.f_lzw_output_ri < self->private_impl.f_lzw_output_wi) { - v_copy_status = wuffs_gif__decoder__copy_to_image_buffer(self, a_dst, wuffs_base__make_slice_u8_ij(self->private_data.f_lzw_output, - self->private_impl.f_lzw_output_ri, - self->private_impl.f_lzw_output_wi)); - if (wuffs_base__status__is_error(&v_copy_status)) { - status = v_copy_status; - goto exit; - } - self->private_impl.f_lzw_output_ri = 0u; - self->private_impl.f_lzw_output_wi = 0u; - } - if (self->private_impl.f_lzw_read_from_return_value == 0u) { - self->private_impl.f_ignored_but_affects_benchmarks = false; - if (v_need_block_size || (v_block_size > 0u)) { - self->private_data.s_decode_id_part2.scratch = ((uint32_t)(v_block_size)); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - if (self->private_data.s_decode_id_part2.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { - self->private_data.s_decode_id_part2.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); - iop_a_src = io2_a_src; - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - iop_a_src += self->private_data.s_decode_id_part2.scratch; - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); - status = wuffs_gif__decoder__skip_blocks(self, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; - } - } - goto label__outer__break; - } else if (self->private_impl.f_lzw_read_from_return_value == 1u) { - continue; - } else if (self->private_impl.f_lzw_read_from_return_value == 2u) { - goto label__outer__continue; - } else if (self->private_impl.f_quirks[3u] && (self->private_impl.f_dst_y >= self->private_impl.f_frame_rect_y1) && (self->private_impl.f_interlace == 0u)) { - if (v_need_block_size || (v_block_size > 0u)) { - self->private_data.s_decode_id_part2.scratch = ((uint32_t)(v_block_size)); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); - if (self->private_data.s_decode_id_part2.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { - self->private_data.s_decode_id_part2.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); - iop_a_src = io2_a_src; - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - iop_a_src += self->private_data.s_decode_id_part2.scratch; - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); - status = wuffs_gif__decoder__skip_blocks(self, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; - } - } - goto label__outer__break; - } else if (self->private_impl.f_lzw_read_from_return_value == 3u) { - status = wuffs_base__make_status(wuffs_gif__error__truncated_input); - goto exit; - } else if (self->private_impl.f_lzw_read_from_return_value == 4u) { - status = wuffs_base__make_status(wuffs_gif__error__bad_lzw_code); - goto exit; - } - status = wuffs_base__make_status(wuffs_gif__error__internal_error_inconsistent_i_o); - goto exit; + self->private_impl.f_metadata_io_position = wuffs_base__u64__sat_add(wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))), v_chunk_length); + if (a_minfo != NULL) { + wuffs_base__more_information__set(a_minfo, + 3u, + self->private_impl.f_metadata_fourcc, + 0u, + wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))), + self->private_impl.f_metadata_io_position); } + status = wuffs_base__make_status(wuffs_base__suspension__even_more_information); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3); } - label__outer__break:; - self->private_impl.f_compressed_ri = 0u; - self->private_impl.f_compressed_wi = 0u; - if ((self->private_impl.f_dst_y < self->private_impl.f_frame_rect_y1) && (self->private_impl.f_frame_rect_x0 != self->private_impl.f_frame_rect_x1) && (self->private_impl.f_frame_rect_y0 != self->private_impl.f_frame_rect_y1)) { - status = wuffs_base__make_status(wuffs_base__error__not_enough_data); - goto exit; + if (a_minfo != NULL) { + wuffs_base__more_information__set(a_minfo, + 3u, + self->private_impl.f_metadata_fourcc, + 0u, + self->private_impl.f_metadata_io_position, + self->private_impl.f_metadata_io_position); } + self->private_impl.f_call_sequence &= 239u; + self->private_impl.f_metadata_fourcc = 0u; + self->private_impl.f_metadata_io_position = 0u; + status = wuffs_base__make_status(NULL); + goto ok; ok: - self->private_impl.p_decode_id_part2 = 0; + self->private_impl.p_do_tell_me_more = 0; goto exit; } goto suspend; suspend: - self->private_impl.p_decode_id_part2 = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; - self->private_data.s_decode_id_part2.v_block_size = v_block_size; - self->private_data.s_decode_id_part2.v_need_block_size = v_need_block_size; + self->private_impl.p_do_tell_me_more = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; goto exit; exit: @@ -43364,476 +44965,35 @@ wuffs_gif__decoder__decode_id_part2( return status; } -// -------- func gif.decoder.copy_to_image_buffer +// -------- func gif.decoder.num_animation_loops WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_gif__decoder__copy_to_image_buffer( - wuffs_gif__decoder* self, - wuffs_base__pixel_buffer* a_pb, - wuffs_base__slice_u8 a_src) { - wuffs_base__slice_u8 v_dst = {0}; - wuffs_base__slice_u8 v_src = {0}; - uint64_t v_width_in_bytes = 0; - uint64_t v_n = 0; - uint64_t v_src_ri = 0; - wuffs_base__pixel_format v_pixfmt = {0}; - uint32_t v_bytes_per_pixel = 0; - uint32_t v_bits_per_pixel = 0; - wuffs_base__table_u8 v_tab = {0}; - uint64_t v_i = 0; - uint64_t v_j = 0; - uint32_t v_replicate_y0 = 0; - uint32_t v_replicate_y1 = 0; - wuffs_base__slice_u8 v_replicate_dst = {0}; - wuffs_base__slice_u8 v_replicate_src = {0}; +WUFFS_BASE__MAYBE_STATIC uint32_t +wuffs_gif__decoder__num_animation_loops( + const wuffs_gif__decoder* self) { + if (!self) { + return 0; + } + if ((self->private_impl.magic != WUFFS_BASE__MAGIC) && + (self->private_impl.magic != WUFFS_BASE__DISABLED)) { + return 0; + } - v_pixfmt = wuffs_base__pixel_buffer__pixel_format(a_pb); - v_bits_per_pixel = wuffs_base__pixel_format__bits_per_pixel(&v_pixfmt); - if ((v_bits_per_pixel & 7u) != 0u) { - return wuffs_base__make_status(wuffs_base__error__unsupported_option); + if (self->private_impl.f_seen_num_animation_loops_value) { + return self->private_impl.f_num_animation_loops_value; } - v_bytes_per_pixel = (v_bits_per_pixel >> 3u); - v_width_in_bytes = ((uint64_t)((self->private_impl.f_width * v_bytes_per_pixel))); - v_tab = wuffs_base__pixel_buffer__plane(a_pb, 0u); - while (v_src_ri < ((uint64_t)(a_src.len))) { - v_src = wuffs_base__slice_u8__subslice_i(a_src, v_src_ri); - if (self->private_impl.f_dst_y >= self->private_impl.f_frame_rect_y1) { - if (self->private_impl.f_quirks[3u]) { - return wuffs_base__make_status(NULL); - } - return wuffs_base__make_status(wuffs_base__error__too_much_data); - } - v_dst = wuffs_private_impl__table_u8__row_u32(v_tab, self->private_impl.f_dst_y); - if (self->private_impl.f_dst_y >= self->private_impl.f_height) { - v_dst = wuffs_base__slice_u8__subslice_j(v_dst, 0u); - } else if (v_width_in_bytes < ((uint64_t)(v_dst.len))) { - v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_width_in_bytes); - } - v_i = (((uint64_t)(self->private_impl.f_dst_x)) * ((uint64_t)(v_bytes_per_pixel))); - if (v_i < ((uint64_t)(v_dst.len))) { - v_j = (((uint64_t)(self->private_impl.f_frame_rect_x1)) * ((uint64_t)(v_bytes_per_pixel))); - if ((v_i <= v_j) && (v_j <= ((uint64_t)(v_dst.len)))) { - v_dst = wuffs_base__slice_u8__subslice_ij(v_dst, v_i, v_j); - } else { - v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_i); - } - v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024), v_src); - wuffs_private_impl__u64__sat_add_indirect(&v_src_ri, v_n); - wuffs_private_impl__u32__sat_add_indirect(&self->private_impl.f_dst_x, ((uint32_t)(v_n))); - self->private_impl.f_dirty_max_excl_y = wuffs_base__u32__max(self->private_impl.f_dirty_max_excl_y, wuffs_base__u32__sat_add(self->private_impl.f_dst_y, 1u)); - } - if (self->private_impl.f_frame_rect_x1 <= self->private_impl.f_dst_x) { - self->private_impl.f_dst_x = self->private_impl.f_frame_rect_x0; - if (self->private_impl.f_interlace == 0u) { - wuffs_private_impl__u32__sat_add_indirect(&self->private_impl.f_dst_y, 1u); - continue; - } - if ((self->private_impl.f_num_decoded_frames_value == 0u) && ! self->private_impl.f_gc_has_transparent_index && (self->private_impl.f_interlace > 1u)) { - v_replicate_src = wuffs_private_impl__table_u8__row_u32(v_tab, self->private_impl.f_dst_y); - v_replicate_y0 = wuffs_base__u32__sat_add(self->private_impl.f_dst_y, 1u); - v_replicate_y1 = wuffs_base__u32__sat_add(self->private_impl.f_dst_y, ((uint32_t)(WUFFS_GIF__INTERLACE_COUNT[self->private_impl.f_interlace]))); - v_replicate_y1 = wuffs_base__u32__min(v_replicate_y1, self->private_impl.f_frame_rect_y1); - while (v_replicate_y0 < v_replicate_y1) { - v_replicate_dst = wuffs_private_impl__table_u8__row_u32(v_tab, v_replicate_y0); - wuffs_private_impl__slice_u8__copy_from_slice(v_replicate_dst, v_replicate_src); - v_replicate_y0 += 1u; - } - self->private_impl.f_dirty_max_excl_y = wuffs_base__u32__max(self->private_impl.f_dirty_max_excl_y, v_replicate_y1); - } - wuffs_private_impl__u32__sat_add_indirect(&self->private_impl.f_dst_y, ((uint32_t)(WUFFS_GIF__INTERLACE_DELTA[self->private_impl.f_interlace]))); - while ((self->private_impl.f_interlace > 0u) && (self->private_impl.f_dst_y >= self->private_impl.f_frame_rect_y1)) { -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - self->private_impl.f_interlace -= 1u; -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - self->private_impl.f_dst_y = wuffs_base__u32__sat_add(self->private_impl.f_frame_rect_y0, WUFFS_GIF__INTERLACE_START[self->private_impl.f_interlace]); - } - continue; - } - if (((uint64_t)(a_src.len)) == v_src_ri) { - break; - } else if (((uint64_t)(a_src.len)) < v_src_ri) { - return wuffs_base__make_status(wuffs_gif__error__internal_error_inconsistent_i_o); - } - v_n = ((uint64_t)((self->private_impl.f_frame_rect_x1 - self->private_impl.f_dst_x))); - v_n = wuffs_base__u64__min(v_n, (((uint64_t)(a_src.len)) - v_src_ri)); - wuffs_private_impl__u64__sat_add_indirect(&v_src_ri, v_n); - wuffs_private_impl__u32__sat_add_indirect(&self->private_impl.f_dst_x, ((uint32_t)(v_n))); - if (self->private_impl.f_frame_rect_x1 <= self->private_impl.f_dst_x) { - self->private_impl.f_dst_x = self->private_impl.f_frame_rect_x0; - wuffs_private_impl__u32__sat_add_indirect(&self->private_impl.f_dst_y, ((uint32_t)(WUFFS_GIF__INTERLACE_DELTA[self->private_impl.f_interlace]))); - while ((self->private_impl.f_interlace > 0u) && (self->private_impl.f_dst_y >= self->private_impl.f_frame_rect_y1)) { -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - self->private_impl.f_interlace -= 1u; -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - self->private_impl.f_dst_y = wuffs_base__u32__sat_add(self->private_impl.f_frame_rect_y0, WUFFS_GIF__INTERLACE_START[self->private_impl.f_interlace]); - } - continue; - } - if (v_src_ri != ((uint64_t)(a_src.len))) { - return wuffs_base__make_status(wuffs_gif__error__internal_error_inconsistent_i_o); - } - break; - } - return wuffs_base__make_status(NULL); -} - -// -------- func gif.decoder.lzw_init - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_gif__decoder__lzw_init( - wuffs_gif__decoder* self) { - uint32_t v_i = 0; - - self->private_impl.f_lzw_literal_width = 8u; - if (self->private_impl.f_lzw_pending_literal_width_plus_one > 0u) { - self->private_impl.f_lzw_literal_width = (self->private_impl.f_lzw_pending_literal_width_plus_one - 1u); - } - self->private_impl.f_lzw_clear_code = (((uint32_t)(1u)) << self->private_impl.f_lzw_literal_width); - self->private_impl.f_lzw_end_code = (self->private_impl.f_lzw_clear_code + 1u); - self->private_impl.f_lzw_save_code = self->private_impl.f_lzw_end_code; - self->private_impl.f_lzw_prev_code = self->private_impl.f_lzw_end_code; - self->private_impl.f_lzw_width = (self->private_impl.f_lzw_literal_width + 1u); - self->private_impl.f_lzw_bits = 0u; - self->private_impl.f_lzw_n_bits = 0u; - self->private_impl.f_lzw_output_ri = 0u; - self->private_impl.f_lzw_output_wi = 0u; - v_i = 0u; - while (v_i < self->private_impl.f_lzw_clear_code) { - self->private_data.f_lzw_lm1s[v_i] = 0u; - self->private_data.f_lzw_suffixes[v_i][0u] = ((uint8_t)(v_i)); - v_i += 1u; - } - return wuffs_base__make_empty_struct(); -} - -// -------- func gif.decoder.lzw_read_from - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_gif__decoder__lzw_read_from( - wuffs_gif__decoder* self, - wuffs_base__io_buffer* a_src) { - uint32_t v_clear_code = 0; - uint32_t v_end_code = 0; - uint32_t v_save_code = 0; - uint32_t v_prev_code = 0; - uint32_t v_width = 0; - uint32_t v_bits = 0; - uint32_t v_n_bits = 0; - uint32_t v_output_wi = 0; - uint32_t v_code = 0; - uint32_t v_c = 0; - uint32_t v_o = 0; - uint32_t v_steps = 0; - uint8_t v_first_byte = 0; - uint16_t v_lm1_b = 0; - uint16_t v_lm1_a = 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; - } - - v_clear_code = self->private_impl.f_lzw_clear_code; - v_end_code = self->private_impl.f_lzw_end_code; - v_save_code = self->private_impl.f_lzw_save_code; - v_prev_code = self->private_impl.f_lzw_prev_code; - v_width = self->private_impl.f_lzw_width; - v_bits = self->private_impl.f_lzw_bits; - v_n_bits = self->private_impl.f_lzw_n_bits; - v_output_wi = self->private_impl.f_lzw_output_wi; - while (true) { - if (v_n_bits < v_width) { - if (((uint64_t)(io2_a_src - iop_a_src)) >= 4u) { - v_bits |= ((uint32_t)(wuffs_base__peek_u32le__no_bounds_check(iop_a_src) << v_n_bits)); - iop_a_src += ((31u - v_n_bits) >> 3u); - v_n_bits |= 24u; - } else if (((uint64_t)(io2_a_src - iop_a_src)) <= 0u) { - if (a_src && a_src->meta.closed) { - self->private_impl.f_lzw_read_from_return_value = 3u; - } else { - self->private_impl.f_lzw_read_from_return_value = 2u; - } - break; - } else { - v_bits |= (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) << v_n_bits); - iop_a_src += 1u; - v_n_bits += 8u; - if (v_n_bits >= v_width) { - } else if (((uint64_t)(io2_a_src - iop_a_src)) <= 0u) { - if (a_src && a_src->meta.closed) { - self->private_impl.f_lzw_read_from_return_value = 3u; - } else { - self->private_impl.f_lzw_read_from_return_value = 2u; - } - break; - } else { - v_bits |= (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) << v_n_bits); - iop_a_src += 1u; - v_n_bits += 8u; - if (v_n_bits < v_width) { - self->private_impl.f_lzw_read_from_return_value = 5u; - break; - } - } - } - } - v_code = ((v_bits) & WUFFS_PRIVATE_IMPL__LOW_BITS_MASK__U32(v_width)); - v_bits >>= v_width; - v_n_bits -= v_width; - if (v_code < v_clear_code) { - self->private_data.f_lzw_output[v_output_wi] = ((uint8_t)(v_code)); - v_output_wi = ((v_output_wi + 1u) & 8191u); - if (v_save_code <= 4095u) { - v_lm1_a = ((uint16_t)(((uint16_t)(self->private_data.f_lzw_lm1s[v_prev_code] + 1u)) & 4095u)); - self->private_data.f_lzw_lm1s[v_save_code] = v_lm1_a; - if (((uint16_t)(v_lm1_a % 8u)) != 0u) { - self->private_impl.f_lzw_prefixes[v_save_code] = self->private_impl.f_lzw_prefixes[v_prev_code]; - memcpy(self->private_data.f_lzw_suffixes[v_save_code],self->private_data.f_lzw_suffixes[v_prev_code], sizeof(self->private_data.f_lzw_suffixes[v_save_code])); - self->private_data.f_lzw_suffixes[v_save_code][((uint16_t)(v_lm1_a % 8u))] = ((uint8_t)(v_code)); - } else { - self->private_impl.f_lzw_prefixes[v_save_code] = ((uint16_t)(v_prev_code)); - self->private_data.f_lzw_suffixes[v_save_code][0u] = ((uint8_t)(v_code)); - } - v_save_code += 1u; - if (v_width < 12u) { - v_width += (1u & (v_save_code >> v_width)); - } - v_prev_code = v_code; - } - } else if (v_code <= v_end_code) { - if (v_code == v_end_code) { - self->private_impl.f_lzw_read_from_return_value = 0u; - break; - } - v_save_code = v_end_code; - v_prev_code = v_end_code; - v_width = (self->private_impl.f_lzw_literal_width + 1u); - } else if (v_code <= v_save_code) { - v_c = v_code; - if (v_code == v_save_code) { - v_c = v_prev_code; - } - v_o = ((v_output_wi + (((uint32_t)(self->private_data.f_lzw_lm1s[v_c])) & 4294967288u)) & 8191u); - v_output_wi = ((v_output_wi + 1u + ((uint32_t)(self->private_data.f_lzw_lm1s[v_c]))) & 8191u); - v_steps = (((uint32_t)(self->private_data.f_lzw_lm1s[v_c])) >> 3u); - while (true) { - memcpy((self->private_data.f_lzw_output)+(v_o), (self->private_data.f_lzw_suffixes[v_c]), 8u); - if (v_steps <= 0u) { - break; - } - v_steps -= 1u; - v_o = (((uint32_t)(v_o - 8u)) & 8191u); - v_c = ((uint32_t)(self->private_impl.f_lzw_prefixes[v_c])); - } - v_first_byte = self->private_data.f_lzw_suffixes[v_c][0u]; - if (v_code == v_save_code) { - self->private_data.f_lzw_output[v_output_wi] = v_first_byte; - v_output_wi = ((v_output_wi + 1u) & 8191u); - } - if (v_save_code <= 4095u) { - v_lm1_b = ((uint16_t)(((uint16_t)(self->private_data.f_lzw_lm1s[v_prev_code] + 1u)) & 4095u)); - self->private_data.f_lzw_lm1s[v_save_code] = v_lm1_b; - if (((uint16_t)(v_lm1_b % 8u)) != 0u) { - self->private_impl.f_lzw_prefixes[v_save_code] = self->private_impl.f_lzw_prefixes[v_prev_code]; - memcpy(self->private_data.f_lzw_suffixes[v_save_code],self->private_data.f_lzw_suffixes[v_prev_code], sizeof(self->private_data.f_lzw_suffixes[v_save_code])); - self->private_data.f_lzw_suffixes[v_save_code][((uint16_t)(v_lm1_b % 8u))] = v_first_byte; - } else { - self->private_impl.f_lzw_prefixes[v_save_code] = ((uint16_t)(v_prev_code)); - self->private_data.f_lzw_suffixes[v_save_code][0u] = ((uint8_t)(v_first_byte)); - } - v_save_code += 1u; - if (v_width < 12u) { - v_width += (1u & (v_save_code >> v_width)); - } - v_prev_code = v_code; - } - } else { - self->private_impl.f_lzw_read_from_return_value = 4u; - break; - } - if (v_output_wi > 4095u) { - self->private_impl.f_lzw_read_from_return_value = 1u; - break; - } - } - if (self->private_impl.f_lzw_read_from_return_value != 2u) { - while (v_n_bits >= 8u) { - v_n_bits -= 8u; - if (iop_a_src > io1_a_src) { - iop_a_src--; - } else { - self->private_impl.f_lzw_read_from_return_value = 5u; - break; - } - } - } - self->private_impl.f_lzw_save_code = v_save_code; - self->private_impl.f_lzw_prev_code = v_prev_code; - self->private_impl.f_lzw_width = v_width; - self->private_impl.f_lzw_bits = v_bits; - self->private_impl.f_lzw_n_bits = v_n_bits; - self->private_impl.f_lzw_output_wi = v_output_wi; - if (a_src && a_src->data.ptr) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - - return wuffs_base__make_empty_struct(); -} - -#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GIF) - -#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GZIP) - -// ---------------- Status Codes Implementations - -const char wuffs_gzip__error__bad_checksum[] = "#gzip: bad checksum"; -const char wuffs_gzip__error__bad_compression_method[] = "#gzip: bad compression method"; -const char wuffs_gzip__error__bad_encoding_flags[] = "#gzip: bad encoding flags"; -const char wuffs_gzip__error__bad_header[] = "#gzip: bad header"; -const char wuffs_gzip__error__truncated_input[] = "#gzip: truncated input"; - -// ---------------- Private Consts - -// ---------------- Private Initializer Prototypes - -// ---------------- Private Function Prototypes - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_gzip__decoder__do_transform_io( - wuffs_gzip__decoder* self, - wuffs_base__io_buffer* a_dst, - wuffs_base__io_buffer* a_src, - wuffs_base__slice_u8 a_workbuf); - -// ---------------- VTables - -const wuffs_base__io_transformer__func_ptrs -wuffs_gzip__decoder__func_ptrs_for__wuffs_base__io_transformer = { - (wuffs_base__optional_u63(*)(const void*))(&wuffs_gzip__decoder__dst_history_retain_length), - (uint64_t(*)(const void*, - uint32_t))(&wuffs_gzip__decoder__get_quirk), - (wuffs_base__status(*)(void*, - uint32_t, - uint64_t))(&wuffs_gzip__decoder__set_quirk), - (wuffs_base__status(*)(void*, - wuffs_base__io_buffer*, - wuffs_base__io_buffer*, - wuffs_base__slice_u8))(&wuffs_gzip__decoder__transform_io), - (wuffs_base__range_ii_u64(*)(const void*))(&wuffs_gzip__decoder__workbuf_len), -}; - -// ---------------- Initializer Implementations - -wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT -wuffs_gzip__decoder__initialize( - wuffs_gzip__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)); - } - } - - { - wuffs_base__status z = wuffs_crc32__ieee_hasher__initialize( - &self->private_data.f_checksum, sizeof(self->private_data.f_checksum), WUFFS_VERSION, options); - if (z.repr) { - return z; - } - } - { - wuffs_base__status z = wuffs_deflate__decoder__initialize( - &self->private_data.f_flate, sizeof(self->private_data.f_flate), WUFFS_VERSION, options); - if (z.repr) { - return z; - } - } - self->private_impl.magic = WUFFS_BASE__MAGIC; - self->private_impl.vtable_for__wuffs_base__io_transformer.vtable_name = - wuffs_base__io_transformer__vtable_name; - self->private_impl.vtable_for__wuffs_base__io_transformer.function_pointers = - (const void*)(&wuffs_gzip__decoder__func_ptrs_for__wuffs_base__io_transformer); - return wuffs_base__make_status(NULL); -} - -wuffs_gzip__decoder* -wuffs_gzip__decoder__alloc(void) { - wuffs_gzip__decoder* x = - (wuffs_gzip__decoder*)(calloc(1, sizeof(wuffs_gzip__decoder))); - if (!x) { - return NULL; - } - if (wuffs_gzip__decoder__initialize( - x, sizeof(wuffs_gzip__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) { - free(x); - return NULL; + if (self->private_impl.f_num_decoded_frame_configs_value > 1u) { + return 1u; } - return x; -} - -size_t -sizeof__wuffs_gzip__decoder(void) { - return sizeof(wuffs_gzip__decoder); + return 0u; } -// ---------------- Function Implementations - -// -------- func gzip.decoder.get_quirk +// -------- func gif.decoder.num_decoded_frame_configs WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC uint64_t -wuffs_gzip__decoder__get_quirk( - const wuffs_gzip__decoder* self, - uint32_t a_key) { +wuffs_gif__decoder__num_decoded_frame_configs( + const wuffs_gif__decoder* self) { if (!self) { return 0; } @@ -43842,60 +45002,53 @@ wuffs_gzip__decoder__get_quirk( return 0; } - if ((a_key == 1u) && self->private_impl.f_ignore_checksum) { - return 1u; - } - return 0u; + return self->private_impl.f_num_decoded_frame_configs_value; } -// -------- func gzip.decoder.set_quirk +// -------- func gif.decoder.num_decoded_frames WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_gzip__decoder__set_quirk( - wuffs_gzip__decoder* self, - uint32_t a_key, - uint64_t a_value) { +WUFFS_BASE__MAYBE_STATIC uint64_t +wuffs_gif__decoder__num_decoded_frames( + const wuffs_gif__decoder* self) { if (!self) { - return wuffs_base__make_status(wuffs_base__error__bad_receiver); + return 0; } - 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.magic != WUFFS_BASE__MAGIC) && + (self->private_impl.magic != WUFFS_BASE__DISABLED)) { + return 0; } - if (a_key == 1u) { - self->private_impl.f_ignore_checksum = (a_value > 0u); - return wuffs_base__make_status(NULL); - } - return wuffs_base__make_status(wuffs_base__error__unsupported_option); + return self->private_impl.f_num_decoded_frames_value; } -// -------- func gzip.decoder.dst_history_retain_length +// -------- func gif.decoder.frame_dirty_rect WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__optional_u63 -wuffs_gzip__decoder__dst_history_retain_length( - const wuffs_gzip__decoder* self) { +WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32 +wuffs_gif__decoder__frame_dirty_rect( + const wuffs_gif__decoder* self) { if (!self) { - return wuffs_base__utility__make_optional_u63(false, 0u); + 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__make_optional_u63(false, 0u); + return wuffs_base__utility__empty_rect_ie_u32(); } - return wuffs_base__utility__make_optional_u63(true, 0u); + return wuffs_base__utility__make_rect_ie_u32( + wuffs_base__u32__min(self->private_impl.f_frame_rect_x0, self->private_impl.f_width), + wuffs_base__u32__min(self->private_impl.f_frame_rect_y0, self->private_impl.f_height), + wuffs_base__u32__min(self->private_impl.f_frame_rect_x1, self->private_impl.f_width), + wuffs_base__u32__min(self->private_impl.f_dirty_max_excl_y, self->private_impl.f_height)); } -// -------- func gzip.decoder.workbuf_len +// -------- func gif.decoder.workbuf_len WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 -wuffs_gzip__decoder__workbuf_len( - const wuffs_gzip__decoder* self) { +wuffs_gif__decoder__workbuf_len( + const wuffs_gif__decoder* self) { if (!self) { return wuffs_base__utility__empty_range_ii_u64(); } @@ -43904,18 +45057,17 @@ wuffs_gzip__decoder__workbuf_len( return wuffs_base__utility__empty_range_ii_u64(); } - return wuffs_base__utility__make_range_ii_u64(1u, 1u); + return wuffs_base__utility__make_range_ii_u64(0u, 0u); } -// -------- func gzip.decoder.transform_io +// -------- func gif.decoder.restart_frame WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_gzip__decoder__transform_io( - wuffs_gzip__decoder* self, - wuffs_base__io_buffer* a_dst, - wuffs_base__io_buffer* a_src, - wuffs_base__slice_u8 a_workbuf) { +wuffs_gif__decoder__restart_frame( + wuffs_gif__decoder* self, + uint64_t a_index, + uint64_t a_io_position) { if (!self) { return wuffs_base__make_status(wuffs_base__error__bad_receiver); } @@ -43925,31 +45077,63 @@ wuffs_gzip__decoder__transform_io( ? 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; + + if (self->private_impl.f_call_sequence < 32u) { + return wuffs_base__make_status(wuffs_base__error__bad_call_sequence); + } else if (a_io_position == 0u) { 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.f_delayed_num_decoded_frames = false; + self->private_impl.f_frame_config_io_position = a_io_position; + self->private_impl.f_num_decoded_frame_configs_value = a_index; + self->private_impl.f_num_decoded_frames_value = a_index; + wuffs_gif__decoder__reset_gc(self); + self->private_impl.f_call_sequence = 40u; + return wuffs_base__make_status(NULL); +} + +// -------- func gif.decoder.decode_frame_config + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_gif__decoder__decode_frame_config( + wuffs_gif__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 != 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_transform_io; + 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_gzip__decoder__do_transform_io(self, a_dst, a_src, a_workbuf); + wuffs_base__status t_0 = wuffs_gif__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_gzip__error__truncated_input); + status = wuffs_base__make_status(wuffs_gif__error__truncated_input); goto exit; } status = v_status; @@ -43957,14 +45141,14 @@ wuffs_gzip__decoder__transform_io( } ok: - self->private_impl.p_transform_io = 0; + self->private_impl.p_decode_frame_config = 0; goto exit; } goto suspend; suspend: - self->private_impl.p_transform_io = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; - self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0; + 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) ? 3 : 0; goto exit; exit: @@ -43974,40 +45158,19 @@ wuffs_gzip__decoder__transform_io( return status; } -// -------- func gzip.decoder.do_transform_io +// -------- func gif.decoder.do_decode_frame_config WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_gzip__decoder__do_transform_io( - wuffs_gzip__decoder* self, - wuffs_base__io_buffer* a_dst, - wuffs_base__io_buffer* a_src, - wuffs_base__slice_u8 a_workbuf) { +wuffs_gif__decoder__do_decode_frame_config( + wuffs_gif__decoder* self, + wuffs_base__frame_config* a_dst, + wuffs_base__io_buffer* a_src) { wuffs_base__status status = wuffs_base__make_status(NULL); - uint8_t v_c8 = 0; + uint32_t v_background_color = 0; uint8_t v_flags = 0; - uint16_t v_xlen = 0; - uint64_t v_mark = 0; - uint32_t v_checksum_have = 0; - uint32_t v_decoded_length_have = 0; - wuffs_base__status v_status = wuffs_base__make_status(NULL); - uint32_t v_checksum_want = 0; - uint32_t v_decoded_length_want = 0; - uint8_t* iop_a_dst = NULL; - uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - if (a_dst && a_dst->data.ptr) { - io0_a_dst = a_dst->data.ptr; - io1_a_dst = io0_a_dst + a_dst->meta.wi; - iop_a_dst = io1_a_dst; - io2_a_dst = io0_a_dst + a_dst->data.len; - if (a_dst->meta.closed) { - io2_a_dst = iop_a_dst; - } - } 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; @@ -44019,269 +45182,215 @@ wuffs_gzip__decoder__do_transform_io( io2_a_src = io0_a_src + a_src->meta.wi; } - uint32_t coro_susp_point = self->private_impl.p_do_transform_io; + uint32_t coro_susp_point = self->private_impl.p_do_decode_frame_config; if (coro_susp_point) { - v_flags = self->private_data.s_do_transform_io.v_flags; - v_checksum_have = self->private_data.s_do_transform_io.v_checksum_have; - v_decoded_length_have = self->private_data.s_do_transform_io.v_decoded_length_have; - v_checksum_want = self->private_data.s_do_transform_io.v_checksum_want; + v_background_color = self->private_data.s_do_decode_frame_config.v_background_color; } switch (coro_susp_point) { WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - { + self->private_impl.f_dirty_max_excl_y = 0u; + if (((uint8_t)(self->private_impl.f_call_sequence & 16u)) != 0u) { + status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence); + goto exit; + } else 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); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); + status = wuffs_gif__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; } - uint8_t t_0 = *iop_a_src++; - v_c8 = t_0; - } - if (v_c8 != 31u) { - status = wuffs_base__make_status(wuffs_gzip__error__bad_header); - goto exit; - } - { + } else if (self->private_impl.f_call_sequence == 40u) { + if (self->private_impl.f_frame_config_io_position != 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) { + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); + status = wuffs_gif__decoder__skip_frame(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { goto suspend; } - uint8_t t_1 = *iop_a_src++; - v_c8 = t_1; - } - if (v_c8 != 139u) { - status = wuffs_base__make_status(wuffs_gzip__error__bad_header); - goto exit; + if (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 ((self->private_impl.f_num_decoded_frame_configs_value > 0u) || (self->private_impl.f_call_sequence == 40u)) { + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); + status = wuffs_gif__decoder__decode_up_to_id_part1(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { goto suspend; } - uint8_t t_2 = *iop_a_src++; - v_c8 = t_2; + if (self->private_impl.f_call_sequence >= 96u) { + status = wuffs_base__make_status(wuffs_base__note__end_of_data); + goto ok; + } } - if (v_c8 != 8u) { - status = wuffs_base__make_status(wuffs_gzip__error__bad_compression_method); - goto exit; + v_background_color = self->private_impl.f_black_color_u32_argb_premul; + if ( ! self->private_impl.f_gc_has_transparent_index) { + v_background_color = self->private_impl.f_background_color_u32_argb_premul; + if (self->private_impl.f_quirks[1u] && (self->private_impl.f_num_decoded_frame_configs_value == 0u)) { + while (((uint64_t)(io2_a_src - iop_a_src)) <= 0u) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4); + } + v_flags = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); + if (((uint8_t)(v_flags & 128u)) != 0u) { + v_background_color = self->private_impl.f_black_color_u32_argb_premul; + } + } + } + if (a_dst != NULL) { + wuffs_base__frame_config__set( + a_dst, + wuffs_base__utility__make_rect_ie_u32( + wuffs_base__u32__min(self->private_impl.f_frame_rect_x0, self->private_impl.f_width), + wuffs_base__u32__min(self->private_impl.f_frame_rect_y0, self->private_impl.f_height), + wuffs_base__u32__min(self->private_impl.f_frame_rect_x1, self->private_impl.f_width), + wuffs_base__u32__min(self->private_impl.f_frame_rect_y1, self->private_impl.f_height)), + ((wuffs_base__flicks)(self->private_impl.f_gc_duration)), + self->private_impl.f_num_decoded_frame_configs_value, + self->private_impl.f_frame_config_io_position, + self->private_impl.f_gc_disposal, + ! self->private_impl.f_gc_has_transparent_index, + false, + v_background_color); } + wuffs_private_impl__u64__sat_add_indirect(&self->private_impl.f_num_decoded_frame_configs_value, 1u); + 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; + self->private_data.s_do_decode_frame_config.v_background_color = v_background_color; + + 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 gif.decoder.skip_frame + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_gif__decoder__skip_frame( + wuffs_gif__decoder* self, + wuffs_base__io_buffer* a_src) { + wuffs_base__status status = wuffs_base__make_status(NULL); + + uint8_t v_flags = 0; + uint8_t v_lw = 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_skip_frame; + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { status = wuffs_base__make_status(wuffs_base__suspension__short_read); goto suspend; } - uint8_t t_3 = *iop_a_src++; - v_flags = t_3; - } - self->private_data.s_do_transform_io.scratch = 6u; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); - if (self->private_data.s_do_transform_io.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { - self->private_data.s_do_transform_io.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); - iop_a_src = io2_a_src; - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; + uint8_t t_0 = *iop_a_src++; + v_flags = t_0; } - iop_a_src += self->private_data.s_do_transform_io.scratch; - if (((uint8_t)(v_flags & 4u)) != 0u) { - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); - uint16_t t_4; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { - t_4 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src); - iop_a_src += 2; - } else { - self->private_data.s_do_transform_io.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); - 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_transform_io.scratch; - uint32_t num_bits_4 = ((uint32_t)(*scratch >> 56)); - *scratch <<= 8; - *scratch >>= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_4; - if (num_bits_4 == 8) { - t_4 = ((uint16_t)(*scratch)); - break; - } - num_bits_4 += 8u; - *scratch |= ((uint64_t)(num_bits_4)) << 56; - } - } - v_xlen = t_4; - } - self->private_data.s_do_transform_io.scratch = ((uint32_t)(v_xlen)); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); - if (self->private_data.s_do_transform_io.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { - self->private_data.s_do_transform_io.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); + if (((uint8_t)(v_flags & 128u)) != 0u) { + self->private_data.s_skip_frame.scratch = (((uint32_t)(3u)) << ((uint8_t)(1u + ((uint8_t)(v_flags & 7u))))); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); + if (self->private_data.s_skip_frame.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { + self->private_data.s_skip_frame.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); iop_a_src = io2_a_src; status = wuffs_base__make_status(wuffs_base__suspension__short_read); goto suspend; } - iop_a_src += self->private_data.s_do_transform_io.scratch; - } - if (((uint8_t)(v_flags & 8u)) != 0u) { - while (true) { - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_5 = *iop_a_src++; - v_c8 = t_5; - } - if (v_c8 == 0u) { - break; - } - } - } - if (((uint8_t)(v_flags & 16u)) != 0u) { - while (true) { - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_6 = *iop_a_src++; - v_c8 = t_6; - } - if (v_c8 == 0u) { - break; - } - } + iop_a_src += self->private_data.s_skip_frame.scratch; } - if (((uint8_t)(v_flags & 2u)) != 0u) { - self->private_data.s_do_transform_io.scratch = 2u; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11); - if (self->private_data.s_do_transform_io.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { - self->private_data.s_do_transform_io.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); - iop_a_src = io2_a_src; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { status = wuffs_base__make_status(wuffs_base__suspension__short_read); goto suspend; } - iop_a_src += self->private_data.s_do_transform_io.scratch; + uint8_t t_1 = *iop_a_src++; + v_lw = t_1; } - if (((uint8_t)(v_flags & 224u)) != 0u) { - status = wuffs_base__make_status(wuffs_gzip__error__bad_encoding_flags); + if (v_lw > 8u) { + status = wuffs_base__make_status(wuffs_gif__error__bad_literal_width); goto exit; } - while (true) { - v_mark = ((uint64_t)(iop_a_dst - io0_a_dst)); - { - if (a_dst) { - a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr)); - } - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - wuffs_base__status t_7 = wuffs_deflate__decoder__transform_io(&self->private_data.f_flate, a_dst, a_src, a_workbuf); - v_status = t_7; - if (a_dst) { - iop_a_dst = a_dst->data.ptr + a_dst->meta.wi; - } - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - } - if ( ! self->private_impl.f_ignore_checksum) { - v_checksum_have = wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_checksum, wuffs_private_impl__io__since(v_mark, ((uint64_t)(iop_a_dst - io0_a_dst)), io0_a_dst)); - v_decoded_length_have += ((uint32_t)(wuffs_private_impl__io__count_since(v_mark, ((uint64_t)(iop_a_dst - io0_a_dst))))); - } - if (wuffs_base__status__is_ok(&v_status)) { - break; - } - status = v_status; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(12); + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13); - uint32_t t_8; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_8 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_do_transform_io.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(14); - 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_transform_io.scratch; - uint32_t num_bits_8 = ((uint32_t)(*scratch >> 56)); - *scratch <<= 8; - *scratch >>= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_8; - if (num_bits_8 == 24) { - t_8 = ((uint32_t)(*scratch)); - break; - } - num_bits_8 += 8u; - *scratch |= ((uint64_t)(num_bits_8)) << 56; - } - } - v_checksum_want = t_8; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + status = wuffs_gif__decoder__skip_blocks(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15); - uint32_t t_9; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_9 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_do_transform_io.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16); - 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_transform_io.scratch; - uint32_t num_bits_9 = ((uint32_t)(*scratch >> 56)); - *scratch <<= 8; - *scratch >>= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_9; - if (num_bits_9 == 24) { - t_9 = ((uint32_t)(*scratch)); - break; - } - num_bits_9 += 8u; - *scratch |= ((uint64_t)(num_bits_9)) << 56; - } - } - v_decoded_length_want = t_9; + if (status.repr) { + goto suspend; } - if ( ! self->private_impl.f_ignore_checksum && ((v_checksum_have != v_checksum_want) || (v_decoded_length_have != v_decoded_length_want))) { - status = wuffs_base__make_status(wuffs_gzip__error__bad_checksum); - goto exit; + if (self->private_impl.f_quirks[0u]) { + self->private_impl.f_delayed_num_decoded_frames = true; + } else { + wuffs_private_impl__u64__sat_add_indirect(&self->private_impl.f_num_decoded_frames_value, 1u); } + wuffs_gif__decoder__reset_gc(self); + self->private_impl.f_call_sequence = 32u; + goto ok; ok: - self->private_impl.p_do_transform_io = 0; + self->private_impl.p_skip_frame = 0; goto exit; } goto suspend; suspend: - self->private_impl.p_do_transform_io = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; - self->private_data.s_do_transform_io.v_flags = v_flags; - self->private_data.s_do_transform_io.v_checksum_have = v_checksum_have; - self->private_data.s_do_transform_io.v_decoded_length_have = v_decoded_length_have; - self->private_data.s_do_transform_io.v_checksum_want = v_checksum_want; + self->private_impl.p_skip_frame = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; goto exit; exit: - if (a_dst && a_dst->data.ptr) { - a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr)); - } if (a_src && a_src->data.ptr) { a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); } @@ -44289,2295 +45398,1409 @@ wuffs_gzip__decoder__do_transform_io( return status; } -#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GZIP) +// -------- func gif.decoder.decode_frame -#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__JPEG) +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_gif__decoder__decode_frame( + wuffs_gif__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 != 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 Codes Implementations + wuffs_base__status v_status = wuffs_base__make_status(NULL); -const char wuffs_jpeg__error__bad_dht_marker[] = "#jpeg: bad DHT marker"; -const char wuffs_jpeg__error__bad_dqt_marker[] = "#jpeg: bad DQT marker"; -const char wuffs_jpeg__error__bad_dri_marker[] = "#jpeg: bad DRI marker"; -const char wuffs_jpeg__error__bad_sof_marker[] = "#jpeg: bad SOF marker"; -const char wuffs_jpeg__error__bad_sos_marker[] = "#jpeg: bad SOS marker"; -const char wuffs_jpeg__error__bad_header[] = "#jpeg: bad header"; -const char wuffs_jpeg__error__bad_marker[] = "#jpeg: bad marker"; -const char wuffs_jpeg__error__bad_scan_count[] = "#jpeg: bad scan count"; -const char wuffs_jpeg__error__missing_huffman_table[] = "#jpeg: missing Huffman table"; -const char wuffs_jpeg__error__missing_quantization_table[] = "#jpeg: missing Quantization table"; -const char wuffs_jpeg__error__rejected_progressive_jpeg[] = "#jpeg: rejected progressive JPEG"; -const char wuffs_jpeg__error__truncated_input[] = "#jpeg: truncated input"; -const char wuffs_jpeg__error__unsupported_arithmetic_coding[] = "#jpeg: unsupported arithmetic coding"; -const char wuffs_jpeg__error__unsupported_color_model[] = "#jpeg: unsupported color model"; -const char wuffs_jpeg__error__unsupported_fractional_sampling[] = "#jpeg: unsupported fractional sampling"; -const char wuffs_jpeg__error__unsupported_hierarchical_coding[] = "#jpeg: unsupported hierarchical coding"; -const char wuffs_jpeg__error__unsupported_implicit_height[] = "#jpeg: unsupported implicit height"; -const char wuffs_jpeg__error__unsupported_lossless_coding[] = "#jpeg: unsupported lossless coding"; -const char wuffs_jpeg__error__unsupported_marker[] = "#jpeg: unsupported marker"; -const char wuffs_jpeg__error__unsupported_precision_12_bits[] = "#jpeg: unsupported precision (12 bits)"; -const char wuffs_jpeg__error__unsupported_precision_16_bits[] = "#jpeg: unsupported precision (16 bits)"; -const char wuffs_jpeg__error__unsupported_precision[] = "#jpeg: unsupported precision"; -const char wuffs_jpeg__error__unsupported_scan_count[] = "#jpeg: unsupported scan count"; -const char wuffs_jpeg__error__internal_error_inconsistent_decoder_state[] = "#jpeg: internal error: inconsistent decoder state"; + uint32_t coro_susp_point = self->private_impl.p_decode_frame; + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; -// ---------------- Private Consts + while (true) { + { + wuffs_base__status t_0 = wuffs_gif__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_gif__error__truncated_input); + goto exit; + } + status = v_status; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1); + } -static const uint8_t -WUFFS_JPEG__UNZIG[80] WUFFS_BASE__POTENTIALLY_UNUSED = { - 0u, 0u, 1u, 8u, 16u, 9u, 2u, 3u, - 10u, 17u, 24u, 32u, 25u, 18u, 11u, 4u, - 5u, 12u, 19u, 26u, 33u, 40u, 48u, 41u, - 34u, 27u, 20u, 13u, 6u, 7u, 14u, 21u, - 28u, 35u, 42u, 49u, 56u, 57u, 50u, 43u, - 36u, 29u, 22u, 15u, 23u, 30u, 37u, 44u, - 51u, 58u, 59u, 52u, 45u, 38u, 31u, 39u, - 46u, 53u, 60u, 61u, 54u, 47u, 55u, 62u, - 63u, 63u, 63u, 63u, 63u, 63u, 63u, 63u, - 63u, 63u, 63u, 63u, 63u, 63u, 63u, 63u, -}; + ok: + self->private_impl.p_decode_frame = 0; + goto exit; + } -static const uint8_t -WUFFS_JPEG__BIAS_AND_CLAMP[1024] WUFFS_BASE__POTENTIALLY_UNUSED = { - 128u, 129u, 130u, 131u, 132u, 133u, 134u, 135u, - 136u, 137u, 138u, 139u, 140u, 141u, 142u, 143u, - 144u, 145u, 146u, 147u, 148u, 149u, 150u, 151u, - 152u, 153u, 154u, 155u, 156u, 157u, 158u, 159u, - 160u, 161u, 162u, 163u, 164u, 165u, 166u, 167u, - 168u, 169u, 170u, 171u, 172u, 173u, 174u, 175u, - 176u, 177u, 178u, 179u, 180u, 181u, 182u, 183u, - 184u, 185u, 186u, 187u, 188u, 189u, 190u, 191u, - 192u, 193u, 194u, 195u, 196u, 197u, 198u, 199u, - 200u, 201u, 202u, 203u, 204u, 205u, 206u, 207u, - 208u, 209u, 210u, 211u, 212u, 213u, 214u, 215u, - 216u, 217u, 218u, 219u, 220u, 221u, 222u, 223u, - 224u, 225u, 226u, 227u, 228u, 229u, 230u, 231u, - 232u, 233u, 234u, 235u, 236u, 237u, 238u, 239u, - 240u, 241u, 242u, 243u, 244u, 245u, 246u, 247u, - 248u, 249u, 250u, 251u, 252u, 253u, 254u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u, - 8u, 9u, 10u, 11u, 12u, 13u, 14u, 15u, - 16u, 17u, 18u, 19u, 20u, 21u, 22u, 23u, - 24u, 25u, 26u, 27u, 28u, 29u, 30u, 31u, - 32u, 33u, 34u, 35u, 36u, 37u, 38u, 39u, - 40u, 41u, 42u, 43u, 44u, 45u, 46u, 47u, - 48u, 49u, 50u, 51u, 52u, 53u, 54u, 55u, - 56u, 57u, 58u, 59u, 60u, 61u, 62u, 63u, - 64u, 65u, 66u, 67u, 68u, 69u, 70u, 71u, - 72u, 73u, 74u, 75u, 76u, 77u, 78u, 79u, - 80u, 81u, 82u, 83u, 84u, 85u, 86u, 87u, - 88u, 89u, 90u, 91u, 92u, 93u, 94u, 95u, - 96u, 97u, 98u, 99u, 100u, 101u, 102u, 103u, - 104u, 105u, 106u, 107u, 108u, 109u, 110u, 111u, - 112u, 113u, 114u, 115u, 116u, 117u, 118u, 119u, - 120u, 121u, 122u, 123u, 124u, 125u, 126u, 127u, -}; + 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) ? 4 : 0; -static const uint16_t -WUFFS_JPEG__EXTEND[16] WUFFS_BASE__POTENTIALLY_UNUSED = { - 0u, 65535u, 65533u, 65529u, 65521u, 65505u, 65473u, 65409u, - 65281u, 65025u, 64513u, 63489u, 61441u, 57345u, 49153u, 32769u, -}; + goto exit; + exit: + if (wuffs_base__status__is_error(&status)) { + self->private_impl.magic = WUFFS_BASE__DISABLED; + } + return status; +} -static const uint8_t -WUFFS_JPEG__DEFAULT_HUFF_TABLE_DC_LUMA[29] WUFFS_BASE__POTENTIALLY_UNUSED = { - 0u, 0u, 1u, 5u, 1u, 1u, 1u, 1u, - 1u, 1u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 1u, 2u, 3u, 4u, 5u, 6u, - 7u, 8u, 9u, 10u, 11u, -}; +// -------- func gif.decoder.do_decode_frame -static const uint8_t -WUFFS_JPEG__DEFAULT_HUFF_TABLE_DC_CHROMA[29] WUFFS_BASE__POTENTIALLY_UNUSED = { - 1u, 0u, 3u, 1u, 1u, 1u, 1u, 1u, - 1u, 1u, 1u, 1u, 0u, 0u, 0u, 0u, - 0u, 0u, 1u, 2u, 3u, 4u, 5u, 6u, - 7u, 8u, 9u, 10u, 11u, -}; +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_gif__decoder__do_decode_frame( + wuffs_gif__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); -static const uint8_t -WUFFS_JPEG__DEFAULT_HUFF_TABLE_AC_LUMA[179] WUFFS_BASE__POTENTIALLY_UNUSED = { - 16u, 0u, 2u, 1u, 3u, 3u, 2u, 4u, - 3u, 5u, 5u, 4u, 4u, 0u, 0u, 1u, - 125u, 1u, 2u, 3u, 0u, 4u, 17u, 5u, - 18u, 33u, 49u, 65u, 6u, 19u, 81u, 97u, - 7u, 34u, 113u, 20u, 50u, 129u, 145u, 161u, - 8u, 35u, 66u, 177u, 193u, 21u, 82u, 209u, - 240u, 36u, 51u, 98u, 114u, 130u, 9u, 10u, - 22u, 23u, 24u, 25u, 26u, 37u, 38u, 39u, - 40u, 41u, 42u, 52u, 53u, 54u, 55u, 56u, - 57u, 58u, 67u, 68u, 69u, 70u, 71u, 72u, - 73u, 74u, 83u, 84u, 85u, 86u, 87u, 88u, - 89u, 90u, 99u, 100u, 101u, 102u, 103u, 104u, - 105u, 106u, 115u, 116u, 117u, 118u, 119u, 120u, - 121u, 122u, 131u, 132u, 133u, 134u, 135u, 136u, - 137u, 138u, 146u, 147u, 148u, 149u, 150u, 151u, - 152u, 153u, 154u, 162u, 163u, 164u, 165u, 166u, - 167u, 168u, 169u, 170u, 178u, 179u, 180u, 181u, - 182u, 183u, 184u, 185u, 186u, 194u, 195u, 196u, - 197u, 198u, 199u, 200u, 201u, 202u, 210u, 211u, - 212u, 213u, 214u, 215u, 216u, 217u, 218u, 225u, - 226u, 227u, 228u, 229u, 230u, 231u, 232u, 233u, - 234u, 241u, 242u, 243u, 244u, 245u, 246u, 247u, - 248u, 249u, 250u, -}; + uint32_t coro_susp_point = self->private_impl.p_do_decode_frame; + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; -static const uint8_t -WUFFS_JPEG__DEFAULT_HUFF_TABLE_AC_CHROMA[179] WUFFS_BASE__POTENTIALLY_UNUSED = { - 17u, 0u, 2u, 1u, 2u, 4u, 4u, 3u, - 4u, 7u, 5u, 4u, 4u, 0u, 1u, 2u, - 119u, 0u, 1u, 2u, 3u, 17u, 4u, 5u, - 33u, 49u, 6u, 18u, 65u, 81u, 7u, 97u, - 113u, 19u, 34u, 50u, 129u, 8u, 20u, 66u, - 145u, 161u, 177u, 193u, 9u, 35u, 51u, 82u, - 240u, 21u, 98u, 114u, 209u, 10u, 22u, 36u, - 52u, 225u, 37u, 241u, 23u, 24u, 25u, 26u, - 38u, 39u, 40u, 41u, 42u, 53u, 54u, 55u, - 56u, 57u, 58u, 67u, 68u, 69u, 70u, 71u, - 72u, 73u, 74u, 83u, 84u, 85u, 86u, 87u, - 88u, 89u, 90u, 99u, 100u, 101u, 102u, 103u, - 104u, 105u, 106u, 115u, 116u, 117u, 118u, 119u, - 120u, 121u, 122u, 130u, 131u, 132u, 133u, 134u, - 135u, 136u, 137u, 138u, 146u, 147u, 148u, 149u, - 150u, 151u, 152u, 153u, 154u, 162u, 163u, 164u, - 165u, 166u, 167u, 168u, 169u, 170u, 178u, 179u, - 180u, 181u, 182u, 183u, 184u, 185u, 186u, 194u, - 195u, 196u, 197u, 198u, 199u, 200u, 201u, 202u, - 210u, 211u, 212u, 213u, 214u, 215u, 216u, 217u, - 218u, 226u, 227u, 228u, 229u, 230u, 231u, 232u, - 233u, 234u, 242u, 243u, 244u, 245u, 246u, 247u, - 248u, 249u, 250u, -}; + 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_gif__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; + } + if (self->private_impl.f_quirks[5u] && ((self->private_impl.f_frame_rect_x0 == self->private_impl.f_frame_rect_x1) || (self->private_impl.f_frame_rect_y0 == self->private_impl.f_frame_rect_y1))) { + status = wuffs_base__make_status(wuffs_gif__error__bad_frame_size); + goto exit; + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); + status = wuffs_gif__decoder__decode_id_part1(self, a_dst, a_src, a_blend); + if (status.repr) { + goto suspend; + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + status = wuffs_gif__decoder__decode_id_part2(self, a_dst, a_src, a_workbuf); + if (status.repr) { + goto suspend; + } + wuffs_private_impl__u64__sat_add_indirect(&self->private_impl.f_num_decoded_frames_value, 1u); + wuffs_gif__decoder__reset_gc(self); + self->private_impl.f_call_sequence = 32u; -#define WUFFS_JPEG__QUIRKS_BASE 1220532224u + ok: + self->private_impl.p_do_decode_frame = 0; + goto exit; + } -// ---------------- Private Initializer Prototypes + goto suspend; + suspend: + self->private_impl.p_do_decode_frame = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; -// ---------------- Private Function Prototypes + goto exit; + exit: + return status; +} -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_jpeg__decoder__decode_idct( - wuffs_jpeg__decoder* self, - wuffs_base__slice_u8 a_dst_buffer, - uint64_t a_dst_stride, - uint32_t a_q); +// -------- func gif.decoder.reset_gc WUFFS_BASE__GENERATED_C_CODE static wuffs_base__empty_struct -wuffs_jpeg__decoder__decode_idct__choosy_default( - wuffs_jpeg__decoder* self, - wuffs_base__slice_u8 a_dst_buffer, - uint64_t a_dst_stride, - uint32_t a_q); +wuffs_gif__decoder__reset_gc( + wuffs_gif__decoder* self) { + self->private_impl.f_gc_has_transparent_index = false; + self->private_impl.f_gc_transparent_index = 0u; + self->private_impl.f_gc_disposal = 0u; + self->private_impl.f_gc_duration = 0u; + return wuffs_base__make_empty_struct(); +} -#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V3) -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_jpeg__decoder__decode_idct_x86_avx2( - wuffs_jpeg__decoder* self, - wuffs_base__slice_u8 a_dst_buffer, - uint64_t a_dst_stride, - uint32_t a_q); -#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V3) +// -------- func gif.decoder.decode_up_to_id_part1 WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_jpeg__decoder__do_decode_image_config( - wuffs_jpeg__decoder* self, - wuffs_base__image_config* a_dst, - wuffs_base__io_buffer* a_src); +wuffs_gif__decoder__decode_up_to_id_part1( + wuffs_gif__decoder* self, + wuffs_base__io_buffer* a_src) { + wuffs_base__status status = wuffs_base__make_status(NULL); -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_jpeg__decoder__decode_dqt( - wuffs_jpeg__decoder* self, - wuffs_base__io_buffer* a_src); + uint8_t v_block_type = 0; -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_jpeg__decoder__decode_dri( - wuffs_jpeg__decoder* self, - wuffs_base__io_buffer* a_src); + 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; + } -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_jpeg__decoder__decode_appn( - wuffs_jpeg__decoder* self, - wuffs_base__io_buffer* a_src, - uint8_t a_marker); + uint32_t coro_susp_point = self->private_impl.p_decode_up_to_id_part1; + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_jpeg__decoder__decode_sof( - wuffs_jpeg__decoder* self, - wuffs_base__io_buffer* a_src); + if ((self->private_impl.f_frame_config_io_position == 0u) || (self->private_impl.f_num_decoded_frame_configs_value > 0u)) { + self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))); + } + while (true) { + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_0 = *iop_a_src++; + v_block_type = t_0; + } + if (v_block_type == 33u) { + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); + status = wuffs_gif__decoder__decode_extension(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } + } else if (v_block_type == 44u) { + if (self->private_impl.f_delayed_num_decoded_frames) { + self->private_impl.f_delayed_num_decoded_frames = false; + wuffs_private_impl__u64__sat_add_indirect(&self->private_impl.f_num_decoded_frames_value, 1u); + } + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + status = wuffs_gif__decoder__decode_id_part0(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } + break; + } else { + if (self->private_impl.f_delayed_num_decoded_frames) { + self->private_impl.f_delayed_num_decoded_frames = false; + wuffs_private_impl__u64__sat_add_indirect(&self->private_impl.f_num_decoded_frames_value, 1u); + } + self->private_impl.f_call_sequence = 96u; + break; + } + } -WUFFS_BASE__GENERATED_C_CODE -static uint32_t -wuffs_jpeg__decoder__quantize_dimension( - const wuffs_jpeg__decoder* self, - uint32_t a_width, - uint8_t a_h, - uint8_t a_max_incl_h); + goto ok; + ok: + self->private_impl.p_decode_up_to_id_part1 = 0; + goto exit; + } -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_jpeg__decoder__do_decode_frame_config( - wuffs_jpeg__decoder* self, - wuffs_base__frame_config* a_dst, - wuffs_base__io_buffer* a_src); + goto suspend; + suspend: + self->private_impl.p_decode_up_to_id_part1 = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_jpeg__decoder__do_decode_frame( - wuffs_jpeg__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); + goto exit; + exit: + if (a_src && a_src->data.ptr) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_jpeg__decoder__decode_dht( - wuffs_jpeg__decoder* self, - wuffs_base__io_buffer* a_src); + return status; +} -WUFFS_BASE__GENERATED_C_CODE -static bool -wuffs_jpeg__decoder__calculate_huff_tables( - wuffs_jpeg__decoder* self, - uint8_t a_tc4_th, - uint32_t a_total_count); +// -------- func gif.decoder.decode_header WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_jpeg__decoder__decode_sos( - wuffs_jpeg__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__io_buffer* a_src, - wuffs_base__slice_u8 a_workbuf); +wuffs_gif__decoder__decode_header( + wuffs_gif__decoder* self, + wuffs_base__io_buffer* a_src) { + wuffs_base__status status = wuffs_base__make_status(NULL); -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_jpeg__decoder__prepare_scan( - wuffs_jpeg__decoder* self, - wuffs_base__io_buffer* a_src); + uint64_t v_c48 = 0; -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_jpeg__decoder__use_default_huffman_table( - wuffs_jpeg__decoder* self, - uint8_t a_tc4_th); + 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; + } -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_jpeg__decoder__calculate_single_component_scan_fields( - wuffs_jpeg__decoder* self); + uint32_t coro_susp_point = self->private_impl.p_decode_header; + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; -WUFFS_BASE__GENERATED_C_CODE -static bool -wuffs_jpeg__decoder__calculate_multiple_component_scan_fields( - wuffs_jpeg__decoder* self); + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + uint64_t t_0; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 6)) { + t_0 = ((uint64_t)(wuffs_base__peek_u48le__no_bounds_check(iop_a_src))); + iop_a_src += 6; + } else { + self->private_data.s_decode_header.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_decode_header.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 == 40) { + t_0 = ((uint64_t)(*scratch)); + break; + } + num_bits_0 += 8u; + *scratch |= ((uint64_t)(num_bits_0)) << 56; + } + } + v_c48 = t_0; + } + if ((v_c48 != 106889795225927u) && (v_c48 != 106898385160519u)) { + status = wuffs_base__make_status(wuffs_gif__error__bad_header); + goto exit; + } -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_jpeg__decoder__fill_bitstream( - wuffs_jpeg__decoder* self, - wuffs_base__io_buffer* a_src); + goto ok; + ok: + self->private_impl.p_decode_header = 0; + goto exit; + } -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_jpeg__decoder__load_mcu_blocks_for_single_component( - wuffs_jpeg__decoder* self, - uint32_t a_mx, - uint32_t a_my, - wuffs_base__slice_u8 a_workbuf, - uint32_t a_csel); + goto suspend; + suspend: + self->private_impl.p_decode_header = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_jpeg__decoder__load_mcu_blocks_for_single_component__choosy_default( - wuffs_jpeg__decoder* self, - uint32_t a_mx, - uint32_t a_my, - wuffs_base__slice_u8 a_workbuf, - uint32_t a_csel); + goto exit; + exit: + if (a_src && a_src->data.ptr) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_jpeg__decoder__load_mcu_blocks( - wuffs_jpeg__decoder* self, - uint32_t a_mx, - uint32_t a_my, - wuffs_base__slice_u8 a_workbuf); + return status; +} -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_jpeg__decoder__save_mcu_blocks( - wuffs_jpeg__decoder* self, - uint32_t a_mx, - uint32_t a_my, - wuffs_base__slice_u8 a_workbuf); +// -------- func gif.decoder.decode_lsd WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_jpeg__decoder__skip_past_the_next_restart_marker( - wuffs_jpeg__decoder* self, - wuffs_base__io_buffer* a_src); +wuffs_gif__decoder__decode_lsd( + wuffs_gif__decoder* self, + wuffs_base__io_buffer* a_src) { + wuffs_base__status status = wuffs_base__make_status(NULL); -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_jpeg__decoder__apply_progressive_idct( - wuffs_jpeg__decoder* self, - wuffs_base__slice_u8 a_workbuf); + uint8_t v_flags = 0; + uint8_t v_background_color_index = 0; + uint32_t v_num_palette_entries = 0; + uint32_t v_i = 0; + uint32_t v_j = 0; + uint32_t v_argb = 0; -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_jpeg__decoder__swizzle_gray( - wuffs_jpeg__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__slice_u8 a_workbuf, - uint32_t a_x0, - uint32_t a_x1, - uint32_t a_y0, - uint32_t a_y1, - uint64_t a_stride); + 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; + } -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_jpeg__decoder__swizzle_colorful( - wuffs_jpeg__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__slice_u8 a_workbuf, - uint32_t a_x0, - uint32_t a_x1, - uint32_t a_y0, - uint32_t a_y1); + uint32_t coro_susp_point = self->private_impl.p_decode_lsd; + if (coro_susp_point) { + v_flags = self->private_data.s_decode_lsd.v_flags; + v_background_color_index = self->private_data.s_decode_lsd.v_background_color_index; + v_num_palette_entries = self->private_data.s_decode_lsd.v_num_palette_entries; + v_i = self->private_data.s_decode_lsd.v_i; + } + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; -WUFFS_BASE__GENERATED_C_CODE -static bool -wuffs_jpeg__decoder__top_left_quants_has_zero( - const wuffs_jpeg__decoder* self, - uint32_t a_q); + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + uint32_t t_0; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { + t_0 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src))); + iop_a_src += 2; + } else { + self->private_data.s_decode_lsd.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_decode_lsd.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 == 8) { + t_0 = ((uint32_t)(*scratch)); + break; + } + num_bits_0 += 8u; + *scratch |= ((uint64_t)(num_bits_0)) << 56; + } + } + self->private_impl.f_width = t_0; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + uint32_t t_1; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { + t_1 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src))); + iop_a_src += 2; + } else { + self->private_data.s_decode_lsd.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + 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_decode_lsd.scratch; + uint32_t num_bits_1 = ((uint32_t)(*scratch >> 56)); + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_1; + if (num_bits_1 == 8) { + t_1 = ((uint32_t)(*scratch)); + break; + } + num_bits_1 += 8u; + *scratch |= ((uint64_t)(num_bits_1)) << 56; + } + } + self->private_impl.f_height = t_1; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_2 = *iop_a_src++; + v_flags = t_2; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_3 = *iop_a_src++; + v_background_color_index = t_3; + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + iop_a_src++; + v_i = 0u; + self->private_impl.f_has_global_palette = (((uint8_t)(v_flags & 128u)) != 0u); + if (self->private_impl.f_has_global_palette) { + v_num_palette_entries = (((uint32_t)(1u)) << ((uint8_t)(1u + ((uint8_t)(v_flags & 7u))))); + while (v_i < v_num_palette_entries) { + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); + uint32_t t_4; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 3)) { + t_4 = ((uint32_t)(wuffs_base__peek_u24be__no_bounds_check(iop_a_src))); + iop_a_src += 3; + } else { + self->private_data.s_decode_lsd.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); + 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_decode_lsd.scratch; + uint32_t num_bits_4 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_4); + if (num_bits_4 == 16) { + t_4 = ((uint32_t)(*scratch >> 40)); + break; + } + num_bits_4 += 8u; + *scratch |= ((uint64_t)(num_bits_4)); + } + } + v_argb = t_4; + } + v_argb |= 4278190080u; + self->private_data.f_palettes[0u][((4u * v_i) + 0u)] = ((uint8_t)((v_argb >> 0u))); + self->private_data.f_palettes[0u][((4u * v_i) + 1u)] = ((uint8_t)((v_argb >> 8u))); + self->private_data.f_palettes[0u][((4u * v_i) + 2u)] = ((uint8_t)((v_argb >> 16u))); + self->private_data.f_palettes[0u][((4u * v_i) + 3u)] = ((uint8_t)((v_argb >> 24u))); + v_i += 1u; + } + if (self->private_impl.f_quirks[2u]) { + if ((v_background_color_index != 0u) && (((uint32_t)(v_background_color_index)) < v_num_palette_entries)) { + v_j = (4u * ((uint32_t)(v_background_color_index))); + self->private_impl.f_background_color_u32_argb_premul = ((((uint32_t)(self->private_data.f_palettes[0u][(v_j + 0u)])) << 0u) | + (((uint32_t)(self->private_data.f_palettes[0u][(v_j + 1u)])) << 8u) | + (((uint32_t)(self->private_data.f_palettes[0u][(v_j + 2u)])) << 16u) | + (((uint32_t)(self->private_data.f_palettes[0u][(v_j + 3u)])) << 24u)); + } else { + self->private_impl.f_background_color_u32_argb_premul = 77u; + } + } + } + while (v_i < 256u) { + self->private_data.f_palettes[0u][((4u * v_i) + 0u)] = 0u; + self->private_data.f_palettes[0u][((4u * v_i) + 1u)] = 0u; + self->private_data.f_palettes[0u][((4u * v_i) + 2u)] = 0u; + self->private_data.f_palettes[0u][((4u * v_i) + 3u)] = 255u; + v_i += 1u; + } -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_jpeg__decoder__load_mcu_blocks_for_single_component_smooth( - wuffs_jpeg__decoder* self, - uint32_t a_mx, - uint32_t a_my, - wuffs_base__slice_u8 a_workbuf, - uint32_t a_csel); + goto ok; + ok: + self->private_impl.p_decode_lsd = 0; + goto exit; + } -WUFFS_BASE__GENERATED_C_CODE -static uint32_t -wuffs_jpeg__decoder__decode_mcu( - wuffs_jpeg__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__slice_u8 a_workbuf, - uint32_t a_mx, - uint32_t a_my); + goto suspend; + suspend: + self->private_impl.p_decode_lsd = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_data.s_decode_lsd.v_flags = v_flags; + self->private_data.s_decode_lsd.v_background_color_index = v_background_color_index; + self->private_data.s_decode_lsd.v_num_palette_entries = v_num_palette_entries; + self->private_data.s_decode_lsd.v_i = v_i; -WUFFS_BASE__GENERATED_C_CODE -static uint32_t -wuffs_jpeg__decoder__decode_mcu__choosy_default( - wuffs_jpeg__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__slice_u8 a_workbuf, - uint32_t a_mx, - uint32_t a_my); + goto exit; + exit: + if (a_src && a_src->data.ptr) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } -WUFFS_BASE__GENERATED_C_CODE -static uint32_t -wuffs_jpeg__decoder__decode_mcu_progressive_ac_high_bits( - wuffs_jpeg__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__slice_u8 a_workbuf, - uint32_t a_mx, - uint32_t a_my); + return status; +} -WUFFS_BASE__GENERATED_C_CODE -static uint32_t -wuffs_jpeg__decoder__decode_mcu_progressive_ac_low_bit( - wuffs_jpeg__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__slice_u8 a_workbuf, - uint32_t a_mx, - uint32_t a_my); +// -------- func gif.decoder.decode_extension WUFFS_BASE__GENERATED_C_CODE -static uint32_t -wuffs_jpeg__decoder__decode_mcu_progressive_dc_high_bits( - wuffs_jpeg__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__slice_u8 a_workbuf, - uint32_t a_mx, - uint32_t a_my); +static wuffs_base__status +wuffs_gif__decoder__decode_extension( + wuffs_gif__decoder* self, + wuffs_base__io_buffer* a_src) { + wuffs_base__status status = wuffs_base__make_status(NULL); -WUFFS_BASE__GENERATED_C_CODE -static uint32_t -wuffs_jpeg__decoder__decode_mcu_progressive_dc_low_bit( - wuffs_jpeg__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__slice_u8 a_workbuf, - uint32_t a_mx, - uint32_t a_my); + uint8_t v_label = 0; -// ---------------- VTables + 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; + } -const wuffs_base__image_decoder__func_ptrs -wuffs_jpeg__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_jpeg__decoder__decode_frame), - (wuffs_base__status(*)(void*, - wuffs_base__frame_config*, - wuffs_base__io_buffer*))(&wuffs_jpeg__decoder__decode_frame_config), - (wuffs_base__status(*)(void*, - wuffs_base__image_config*, - wuffs_base__io_buffer*))(&wuffs_jpeg__decoder__decode_image_config), - (wuffs_base__rect_ie_u32(*)(const void*))(&wuffs_jpeg__decoder__frame_dirty_rect), - (uint64_t(*)(const void*, - uint32_t))(&wuffs_jpeg__decoder__get_quirk), - (uint32_t(*)(const void*))(&wuffs_jpeg__decoder__num_animation_loops), - (uint64_t(*)(const void*))(&wuffs_jpeg__decoder__num_decoded_frame_configs), - (uint64_t(*)(const void*))(&wuffs_jpeg__decoder__num_decoded_frames), - (wuffs_base__status(*)(void*, - uint64_t, - uint64_t))(&wuffs_jpeg__decoder__restart_frame), - (wuffs_base__status(*)(void*, - uint32_t, - uint64_t))(&wuffs_jpeg__decoder__set_quirk), - (wuffs_base__empty_struct(*)(void*, - uint32_t, - bool))(&wuffs_jpeg__decoder__set_report_metadata), - (wuffs_base__status(*)(void*, - wuffs_base__io_buffer*, - wuffs_base__more_information*, - wuffs_base__io_buffer*))(&wuffs_jpeg__decoder__tell_me_more), - (wuffs_base__range_ii_u64(*)(const void*))(&wuffs_jpeg__decoder__workbuf_len), -}; + uint32_t coro_susp_point = self->private_impl.p_decode_extension; + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; -// ---------------- Initializer Implementations + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_0 = *iop_a_src++; + v_label = t_0; + } + if (v_label == 249u) { + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); + status = wuffs_gif__decoder__decode_gc(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } + status = wuffs_base__make_status(NULL); + goto ok; + } else if (v_label == 255u) { + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + status = wuffs_gif__decoder__decode_ae(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } + status = wuffs_base__make_status(NULL); + goto ok; + } + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + status = wuffs_gif__decoder__skip_blocks(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } -wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT -wuffs_jpeg__decoder__initialize( - wuffs_jpeg__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); + ok: + self->private_impl.p_decode_extension = 0; + goto exit; } - 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); + + goto suspend; + suspend: + self->private_impl.p_decode_extension = 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)); } - 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)); + return status; +} + +// -------- func gif.decoder.skip_blocks + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_gif__decoder__skip_blocks( + wuffs_gif__decoder* self, + wuffs_base__io_buffer* a_src) { + wuffs_base__status status = wuffs_base__make_status(NULL); + + uint8_t v_block_size = 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_skip_blocks; + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + + while (true) { + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_0 = *iop_a_src++; + v_block_size = t_0; + } + if (v_block_size == 0u) { + status = wuffs_base__make_status(NULL); + goto ok; + } + self->private_data.s_skip_blocks.scratch = ((uint32_t)(v_block_size)); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); + if (self->private_data.s_skip_blocks.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { + self->private_data.s_skip_blocks.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); + iop_a_src = io2_a_src; + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + iop_a_src += self->private_data.s_skip_blocks.scratch; } + + ok: + self->private_impl.p_skip_blocks = 0; + goto exit; } - self->private_impl.choosy_decode_idct = &wuffs_jpeg__decoder__decode_idct__choosy_default; - self->private_impl.choosy_load_mcu_blocks_for_single_component = &wuffs_jpeg__decoder__load_mcu_blocks_for_single_component__choosy_default; - self->private_impl.choosy_decode_mcu = &wuffs_jpeg__decoder__decode_mcu__choosy_default; + goto suspend; + suspend: + self->private_impl.p_skip_blocks = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; - 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_jpeg__decoder__func_ptrs_for__wuffs_base__image_decoder); - return wuffs_base__make_status(NULL); + 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; } -wuffs_jpeg__decoder* -wuffs_jpeg__decoder__alloc(void) { - wuffs_jpeg__decoder* x = - (wuffs_jpeg__decoder*)(calloc(1, sizeof(wuffs_jpeg__decoder))); - if (!x) { - return NULL; +// -------- func gif.decoder.decode_ae + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_gif__decoder__decode_ae( + wuffs_gif__decoder* self, + wuffs_base__io_buffer* a_src) { + wuffs_base__status status = wuffs_base__make_status(NULL); + + uint8_t v_c8 = 0; + uint8_t v_block_size = 0; + bool v_is_animexts = false; + bool v_is_netscape = false; + bool v_is_iccp = false; + bool v_is_xmp = false; + + 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; } - if (wuffs_jpeg__decoder__initialize( - x, sizeof(wuffs_jpeg__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) { - free(x); - return NULL; + + uint32_t coro_susp_point = self->private_impl.p_decode_ae; + if (coro_susp_point) { + v_block_size = self->private_data.s_decode_ae.v_block_size; + v_is_animexts = self->private_data.s_decode_ae.v_is_animexts; + v_is_netscape = self->private_data.s_decode_ae.v_is_netscape; + v_is_iccp = self->private_data.s_decode_ae.v_is_iccp; + v_is_xmp = self->private_data.s_decode_ae.v_is_xmp; } - return x; -} + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; -size_t -sizeof__wuffs_jpeg__decoder(void) { - return sizeof(wuffs_jpeg__decoder); -} + do { + if (self->private_impl.f_metadata_fourcc != 0u) { + status = wuffs_base__make_status(wuffs_base__note__metadata_reported); + goto ok; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_0 = *iop_a_src++; + v_block_size = t_0; + } + if (v_block_size == 0u) { + status = wuffs_base__make_status(NULL); + goto ok; + } + if (v_block_size != 11u) { + self->private_data.s_decode_ae.scratch = ((uint32_t)(v_block_size)); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); + if (self->private_data.s_decode_ae.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { + self->private_data.s_decode_ae.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); + iop_a_src = io2_a_src; + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + iop_a_src += self->private_data.s_decode_ae.scratch; + break; + } + v_is_animexts = true; + v_is_netscape = true; + v_is_iccp = true; + v_is_xmp = true; + v_block_size = 0u; + while (v_block_size < 11u) { + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_1 = *iop_a_src++; + v_c8 = t_1; + } + v_is_animexts = (v_is_animexts && (v_c8 == WUFFS_GIF__ANIMEXTS1DOT0[v_block_size])); + v_is_netscape = (v_is_netscape && (v_c8 == WUFFS_GIF__NETSCAPE2DOT0[v_block_size])); + v_is_iccp = (v_is_iccp && (v_c8 == WUFFS_GIF__ICCRGBG1012[v_block_size])); + v_is_xmp = (v_is_xmp && (v_c8 == WUFFS_GIF__XMPDATAXMP[v_block_size])); +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + v_block_size += 1u; +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + } + if (v_is_animexts || v_is_netscape) { + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_2 = *iop_a_src++; + v_block_size = t_2; + } + if (v_block_size != 3u) { + self->private_data.s_decode_ae.scratch = ((uint32_t)(v_block_size)); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); + if (self->private_data.s_decode_ae.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { + self->private_data.s_decode_ae.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); + iop_a_src = io2_a_src; + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + iop_a_src += self->private_data.s_decode_ae.scratch; + break; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_3 = *iop_a_src++; + v_c8 = t_3; + } + if (v_c8 != 1u) { + self->private_data.s_decode_ae.scratch = 2u; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); + if (self->private_data.s_decode_ae.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { + self->private_data.s_decode_ae.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); + iop_a_src = io2_a_src; + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + iop_a_src += self->private_data.s_decode_ae.scratch; + break; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); + uint32_t t_4; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { + t_4 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src))); + iop_a_src += 2; + } else { + self->private_data.s_decode_ae.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); + 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_decode_ae.scratch; + uint32_t num_bits_4 = ((uint32_t)(*scratch >> 56)); + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_4; + if (num_bits_4 == 8) { + t_4 = ((uint32_t)(*scratch)); + break; + } + num_bits_4 += 8u; + *scratch |= ((uint64_t)(num_bits_4)) << 56; + } + } + self->private_impl.f_num_animation_loops_value = t_4; + } + self->private_impl.f_seen_num_animation_loops_value = true; + if ((0u < self->private_impl.f_num_animation_loops_value) && (self->private_impl.f_num_animation_loops_value <= 65535u)) { + self->private_impl.f_num_animation_loops_value += 1u; + } + } else if (self->private_impl.f_call_sequence >= 32u) { + } else if (v_is_iccp && self->private_impl.f_report_metadata_iccp) { + self->private_impl.f_metadata_fourcc = 1229144912u; + self->private_impl.f_metadata_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))); + self->private_impl.f_call_sequence = 16u; + status = wuffs_base__make_status(wuffs_base__note__metadata_reported); + goto ok; + } else if (v_is_xmp && self->private_impl.f_report_metadata_xmp) { + self->private_impl.f_metadata_fourcc = 1481461792u; + self->private_impl.f_metadata_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))); + self->private_impl.f_call_sequence = 16u; + status = wuffs_base__make_status(wuffs_base__note__metadata_reported); + goto ok; + } + } while (0); + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10); + status = wuffs_gif__decoder__skip_blocks(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } -// ---------------- Function Implementations + ok: + self->private_impl.p_decode_ae = 0; + goto exit; + } -// -------- func jpeg.decoder.decode_idct + goto suspend; + suspend: + self->private_impl.p_decode_ae = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_data.s_decode_ae.v_block_size = v_block_size; + self->private_data.s_decode_ae.v_is_animexts = v_is_animexts; + self->private_data.s_decode_ae.v_is_netscape = v_is_netscape; + self->private_data.s_decode_ae.v_is_iccp = v_is_iccp; + self->private_data.s_decode_ae.v_is_xmp = v_is_xmp; -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_jpeg__decoder__decode_idct( - wuffs_jpeg__decoder* self, - wuffs_base__slice_u8 a_dst_buffer, - uint64_t a_dst_stride, - uint32_t a_q) { - return (*self->private_impl.choosy_decode_idct)(self, a_dst_buffer, a_dst_stride, a_q); + 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 gif.decoder.decode_gc + WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_jpeg__decoder__decode_idct__choosy_default( - wuffs_jpeg__decoder* self, - wuffs_base__slice_u8 a_dst_buffer, - uint64_t a_dst_stride, - uint32_t a_q) { - uint32_t v_bq0 = 0; - uint32_t v_bq2 = 0; - uint32_t v_bq4 = 0; - uint32_t v_bq6 = 0; - uint32_t v_ca = 0; - uint32_t v_cb2 = 0; - uint32_t v_cb6 = 0; - uint32_t v_ccp = 0; - uint32_t v_ccm = 0; - uint32_t v_cd0 = 0; - uint32_t v_cd1 = 0; - uint32_t v_cd2 = 0; - uint32_t v_cd3 = 0; - uint32_t v_bq1 = 0; - uint32_t v_bq3 = 0; - uint32_t v_bq5 = 0; - uint32_t v_bq7 = 0; - uint32_t v_ci51 = 0; - uint32_t v_ci53 = 0; - uint32_t v_ci71 = 0; - uint32_t v_ci73 = 0; - uint32_t v_cj = 0; - uint32_t v_ck1 = 0; - uint32_t v_ck3 = 0; - uint32_t v_ck5 = 0; - uint32_t v_ck7 = 0; - uint32_t v_cl51 = 0; - uint32_t v_cl73 = 0; - uint32_t v_in0 = 0; - uint32_t v_in2 = 0; - uint32_t v_in4 = 0; - uint32_t v_in6 = 0; - uint32_t v_ra = 0; - uint32_t v_rb2 = 0; - uint32_t v_rb6 = 0; - uint32_t v_rcp = 0; - uint32_t v_rcm = 0; - uint32_t v_rd0 = 0; - uint32_t v_rd1 = 0; - uint32_t v_rd2 = 0; - uint32_t v_rd3 = 0; - uint32_t v_in1 = 0; - uint32_t v_in3 = 0; - uint32_t v_in5 = 0; - uint32_t v_in7 = 0; - uint32_t v_ri51 = 0; - uint32_t v_ri53 = 0; - uint32_t v_ri71 = 0; - uint32_t v_ri73 = 0; - uint32_t v_rj = 0; - uint32_t v_rk1 = 0; - uint32_t v_rk3 = 0; - uint32_t v_rk5 = 0; - uint32_t v_rk7 = 0; - uint32_t v_rl51 = 0; - uint32_t v_rl73 = 0; - uint32_t v_intermediate[64] = {0}; +static wuffs_base__status +wuffs_gif__decoder__decode_gc( + wuffs_gif__decoder* self, + wuffs_base__io_buffer* a_src) { + wuffs_base__status status = wuffs_base__make_status(NULL); - if (8u > a_dst_stride) { - return wuffs_base__make_empty_struct(); - } - if (0u == (self->private_data.f_mcu_blocks[0u][8u] | - self->private_data.f_mcu_blocks[0u][16u] | - self->private_data.f_mcu_blocks[0u][24u] | - self->private_data.f_mcu_blocks[0u][32u] | - self->private_data.f_mcu_blocks[0u][40u] | - self->private_data.f_mcu_blocks[0u][48u] | - self->private_data.f_mcu_blocks[0u][56u])) { - v_intermediate[0u] = ((uint32_t)(((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][0u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][0u])))) << 2u)); - v_intermediate[8u] = v_intermediate[0u]; - v_intermediate[16u] = v_intermediate[0u]; - v_intermediate[24u] = v_intermediate[0u]; - v_intermediate[32u] = v_intermediate[0u]; - v_intermediate[40u] = v_intermediate[0u]; - v_intermediate[48u] = v_intermediate[0u]; - v_intermediate[56u] = v_intermediate[0u]; - } else { - v_bq2 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][16u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][16u])))); - v_bq6 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][48u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][48u])))); - v_ca = ((uint32_t)(((uint32_t)(v_bq2 + v_bq6)) * 4433u)); - v_cb2 = ((uint32_t)(v_ca + ((uint32_t)(v_bq2 * 6270u)))); - v_cb6 = ((uint32_t)(v_ca - ((uint32_t)(v_bq6 * 15137u)))); - v_bq0 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][0u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][0u])))); - v_bq4 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][32u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][32u])))); - v_ccp = ((uint32_t)(((uint32_t)(v_bq0 + v_bq4)) << 13u)); - v_ccm = ((uint32_t)(((uint32_t)(v_bq0 - v_bq4)) << 13u)); - v_cd0 = ((uint32_t)(v_ccp + v_cb2)); - v_cd1 = ((uint32_t)(v_ccm + v_cb6)); - v_cd2 = ((uint32_t)(v_ccm - v_cb6)); - v_cd3 = ((uint32_t)(v_ccp - v_cb2)); - v_bq1 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][8u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][8u])))); - v_bq3 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][24u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][24u])))); - v_bq5 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][40u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][40u])))); - v_bq7 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][56u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][56u])))); - v_ci51 = ((uint32_t)(v_bq5 + v_bq1)); - v_ci53 = ((uint32_t)(v_bq5 + v_bq3)); - v_ci71 = ((uint32_t)(v_bq7 + v_bq1)); - v_ci73 = ((uint32_t)(v_bq7 + v_bq3)); - v_cj = ((uint32_t)(((uint32_t)(v_ci73 + v_ci51)) * 9633u)); - v_ck1 = ((uint32_t)(v_bq1 * 12299u)); - v_ck3 = ((uint32_t)(v_bq3 * 25172u)); - v_ck5 = ((uint32_t)(v_bq5 * 16819u)); - v_ck7 = ((uint32_t)(v_bq7 * 2446u)); - v_ci51 *= 4294964100u; - v_ci53 *= 4294946301u; - v_ci71 *= 4294959923u; - v_ci73 *= 4294951227u; - v_cl51 = ((uint32_t)(v_ci51 + v_cj)); - v_cl73 = ((uint32_t)(v_ci73 + v_cj)); - v_ck1 += ((uint32_t)(v_ci71 + v_cl51)); - v_ck3 += ((uint32_t)(v_ci53 + v_cl73)); - v_ck5 += ((uint32_t)(v_ci53 + v_cl51)); - v_ck7 += ((uint32_t)(v_ci71 + v_cl73)); - v_intermediate[0u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 + v_ck1)) + 1024u)), 11u); - v_intermediate[56u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 - v_ck1)) + 1024u)), 11u); - v_intermediate[8u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 + v_ck3)) + 1024u)), 11u); - v_intermediate[48u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 - v_ck3)) + 1024u)), 11u); - v_intermediate[16u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 + v_ck5)) + 1024u)), 11u); - v_intermediate[40u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 - v_ck5)) + 1024u)), 11u); - v_intermediate[24u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 + v_ck7)) + 1024u)), 11u); - v_intermediate[32u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 - v_ck7)) + 1024u)), 11u); + uint8_t v_c8 = 0; + uint8_t v_flags = 0; + uint16_t v_gc_duration_centiseconds = 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; } - if (0u == (self->private_data.f_mcu_blocks[0u][9u] | - self->private_data.f_mcu_blocks[0u][17u] | - self->private_data.f_mcu_blocks[0u][25u] | - self->private_data.f_mcu_blocks[0u][33u] | - self->private_data.f_mcu_blocks[0u][41u] | - self->private_data.f_mcu_blocks[0u][49u] | - self->private_data.f_mcu_blocks[0u][57u])) { - v_intermediate[1u] = ((uint32_t)(((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][1u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][1u])))) << 2u)); - v_intermediate[9u] = v_intermediate[1u]; - v_intermediate[17u] = v_intermediate[1u]; - v_intermediate[25u] = v_intermediate[1u]; - v_intermediate[33u] = v_intermediate[1u]; - v_intermediate[41u] = v_intermediate[1u]; - v_intermediate[49u] = v_intermediate[1u]; - v_intermediate[57u] = v_intermediate[1u]; - } else { - v_bq2 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][17u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][17u])))); - v_bq6 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][49u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][49u])))); - v_ca = ((uint32_t)(((uint32_t)(v_bq2 + v_bq6)) * 4433u)); - v_cb2 = ((uint32_t)(v_ca + ((uint32_t)(v_bq2 * 6270u)))); - v_cb6 = ((uint32_t)(v_ca - ((uint32_t)(v_bq6 * 15137u)))); - v_bq0 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][1u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][1u])))); - v_bq4 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][33u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][33u])))); - v_ccp = ((uint32_t)(((uint32_t)(v_bq0 + v_bq4)) << 13u)); - v_ccm = ((uint32_t)(((uint32_t)(v_bq0 - v_bq4)) << 13u)); - v_cd0 = ((uint32_t)(v_ccp + v_cb2)); - v_cd1 = ((uint32_t)(v_ccm + v_cb6)); - v_cd2 = ((uint32_t)(v_ccm - v_cb6)); - v_cd3 = ((uint32_t)(v_ccp - v_cb2)); - v_bq1 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][9u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][9u])))); - v_bq3 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][25u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][25u])))); - v_bq5 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][41u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][41u])))); - v_bq7 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][57u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][57u])))); - v_ci51 = ((uint32_t)(v_bq5 + v_bq1)); - v_ci53 = ((uint32_t)(v_bq5 + v_bq3)); - v_ci71 = ((uint32_t)(v_bq7 + v_bq1)); - v_ci73 = ((uint32_t)(v_bq7 + v_bq3)); - v_cj = ((uint32_t)(((uint32_t)(v_ci73 + v_ci51)) * 9633u)); - v_ck1 = ((uint32_t)(v_bq1 * 12299u)); - v_ck3 = ((uint32_t)(v_bq3 * 25172u)); - v_ck5 = ((uint32_t)(v_bq5 * 16819u)); - v_ck7 = ((uint32_t)(v_bq7 * 2446u)); - v_ci51 *= 4294964100u; - v_ci53 *= 4294946301u; - v_ci71 *= 4294959923u; - v_ci73 *= 4294951227u; - v_cl51 = ((uint32_t)(v_ci51 + v_cj)); - v_cl73 = ((uint32_t)(v_ci73 + v_cj)); - v_ck1 += ((uint32_t)(v_ci71 + v_cl51)); - v_ck3 += ((uint32_t)(v_ci53 + v_cl73)); - v_ck5 += ((uint32_t)(v_ci53 + v_cl51)); - v_ck7 += ((uint32_t)(v_ci71 + v_cl73)); - v_intermediate[1u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 + v_ck1)) + 1024u)), 11u); - v_intermediate[57u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 - v_ck1)) + 1024u)), 11u); - v_intermediate[9u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 + v_ck3)) + 1024u)), 11u); - v_intermediate[49u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 - v_ck3)) + 1024u)), 11u); - v_intermediate[17u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 + v_ck5)) + 1024u)), 11u); - v_intermediate[41u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 - v_ck5)) + 1024u)), 11u); - v_intermediate[25u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 + v_ck7)) + 1024u)), 11u); - v_intermediate[33u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 - v_ck7)) + 1024u)), 11u); + + uint32_t coro_susp_point = self->private_impl.p_decode_gc; + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_0 = *iop_a_src++; + v_c8 = t_0; + } + if (v_c8 != 4u) { + status = wuffs_base__make_status(wuffs_gif__error__bad_graphic_control); + goto exit; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_1 = *iop_a_src++; + v_flags = t_1; + } + self->private_impl.f_gc_has_transparent_index = (((uint8_t)(v_flags & 1u)) != 0u); + v_flags = ((uint8_t)(((uint8_t)(v_flags >> 2u)) & 7u)); + if (v_flags == 2u) { + self->private_impl.f_gc_disposal = 1u; + } else if ((v_flags == 3u) || (v_flags == 4u)) { + self->private_impl.f_gc_disposal = 2u; + } else { + self->private_impl.f_gc_disposal = 0u; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + uint16_t t_2; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { + t_2 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src); + iop_a_src += 2; + } else { + self->private_data.s_decode_gc.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + 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_decode_gc.scratch; + uint32_t num_bits_2 = ((uint32_t)(*scratch >> 56)); + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_2; + if (num_bits_2 == 8) { + t_2 = ((uint16_t)(*scratch)); + break; + } + num_bits_2 += 8u; + *scratch |= ((uint64_t)(num_bits_2)) << 56; + } + } + v_gc_duration_centiseconds = t_2; + } + self->private_impl.f_gc_duration = (((uint64_t)(v_gc_duration_centiseconds)) * 7056000u); + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_3 = *iop_a_src++; + self->private_impl.f_gc_transparent_index = t_3; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_4 = *iop_a_src++; + v_c8 = t_4; + } + if (v_c8 != 0u) { + status = wuffs_base__make_status(wuffs_gif__error__bad_graphic_control); + goto exit; + } + + goto ok; + ok: + self->private_impl.p_decode_gc = 0; + goto exit; } - if (0u == (self->private_data.f_mcu_blocks[0u][10u] | - self->private_data.f_mcu_blocks[0u][18u] | - self->private_data.f_mcu_blocks[0u][26u] | - self->private_data.f_mcu_blocks[0u][34u] | - self->private_data.f_mcu_blocks[0u][42u] | - self->private_data.f_mcu_blocks[0u][50u] | - self->private_data.f_mcu_blocks[0u][58u])) { - v_intermediate[2u] = ((uint32_t)(((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][2u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][2u])))) << 2u)); - v_intermediate[10u] = v_intermediate[2u]; - v_intermediate[18u] = v_intermediate[2u]; - v_intermediate[26u] = v_intermediate[2u]; - v_intermediate[34u] = v_intermediate[2u]; - v_intermediate[42u] = v_intermediate[2u]; - v_intermediate[50u] = v_intermediate[2u]; - v_intermediate[58u] = v_intermediate[2u]; - } else { - v_bq2 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][18u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][18u])))); - v_bq6 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][50u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][50u])))); - v_ca = ((uint32_t)(((uint32_t)(v_bq2 + v_bq6)) * 4433u)); - v_cb2 = ((uint32_t)(v_ca + ((uint32_t)(v_bq2 * 6270u)))); - v_cb6 = ((uint32_t)(v_ca - ((uint32_t)(v_bq6 * 15137u)))); - v_bq0 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][2u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][2u])))); - v_bq4 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][34u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][34u])))); - v_ccp = ((uint32_t)(((uint32_t)(v_bq0 + v_bq4)) << 13u)); - v_ccm = ((uint32_t)(((uint32_t)(v_bq0 - v_bq4)) << 13u)); - v_cd0 = ((uint32_t)(v_ccp + v_cb2)); - v_cd1 = ((uint32_t)(v_ccm + v_cb6)); - v_cd2 = ((uint32_t)(v_ccm - v_cb6)); - v_cd3 = ((uint32_t)(v_ccp - v_cb2)); - v_bq1 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][10u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][10u])))); - v_bq3 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][26u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][26u])))); - v_bq5 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][42u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][42u])))); - v_bq7 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][58u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][58u])))); - v_ci51 = ((uint32_t)(v_bq5 + v_bq1)); - v_ci53 = ((uint32_t)(v_bq5 + v_bq3)); - v_ci71 = ((uint32_t)(v_bq7 + v_bq1)); - v_ci73 = ((uint32_t)(v_bq7 + v_bq3)); - v_cj = ((uint32_t)(((uint32_t)(v_ci73 + v_ci51)) * 9633u)); - v_ck1 = ((uint32_t)(v_bq1 * 12299u)); - v_ck3 = ((uint32_t)(v_bq3 * 25172u)); - v_ck5 = ((uint32_t)(v_bq5 * 16819u)); - v_ck7 = ((uint32_t)(v_bq7 * 2446u)); - v_ci51 *= 4294964100u; - v_ci53 *= 4294946301u; - v_ci71 *= 4294959923u; - v_ci73 *= 4294951227u; - v_cl51 = ((uint32_t)(v_ci51 + v_cj)); - v_cl73 = ((uint32_t)(v_ci73 + v_cj)); - v_ck1 += ((uint32_t)(v_ci71 + v_cl51)); - v_ck3 += ((uint32_t)(v_ci53 + v_cl73)); - v_ck5 += ((uint32_t)(v_ci53 + v_cl51)); - v_ck7 += ((uint32_t)(v_ci71 + v_cl73)); - v_intermediate[2u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 + v_ck1)) + 1024u)), 11u); - v_intermediate[58u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 - v_ck1)) + 1024u)), 11u); - v_intermediate[10u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 + v_ck3)) + 1024u)), 11u); - v_intermediate[50u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 - v_ck3)) + 1024u)), 11u); - v_intermediate[18u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 + v_ck5)) + 1024u)), 11u); - v_intermediate[42u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 - v_ck5)) + 1024u)), 11u); - v_intermediate[26u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 + v_ck7)) + 1024u)), 11u); - v_intermediate[34u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 - v_ck7)) + 1024u)), 11u); + + goto suspend; + suspend: + self->private_impl.p_decode_gc = 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)); } - if (0u == (self->private_data.f_mcu_blocks[0u][11u] | - self->private_data.f_mcu_blocks[0u][19u] | - self->private_data.f_mcu_blocks[0u][27u] | - self->private_data.f_mcu_blocks[0u][35u] | - self->private_data.f_mcu_blocks[0u][43u] | - self->private_data.f_mcu_blocks[0u][51u] | - self->private_data.f_mcu_blocks[0u][59u])) { - v_intermediate[3u] = ((uint32_t)(((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][3u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][3u])))) << 2u)); - v_intermediate[11u] = v_intermediate[3u]; - v_intermediate[19u] = v_intermediate[3u]; - v_intermediate[27u] = v_intermediate[3u]; - v_intermediate[35u] = v_intermediate[3u]; - v_intermediate[43u] = v_intermediate[3u]; - v_intermediate[51u] = v_intermediate[3u]; - v_intermediate[59u] = v_intermediate[3u]; - } else { - v_bq2 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][19u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][19u])))); - v_bq6 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][51u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][51u])))); - v_ca = ((uint32_t)(((uint32_t)(v_bq2 + v_bq6)) * 4433u)); - v_cb2 = ((uint32_t)(v_ca + ((uint32_t)(v_bq2 * 6270u)))); - v_cb6 = ((uint32_t)(v_ca - ((uint32_t)(v_bq6 * 15137u)))); - v_bq0 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][3u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][3u])))); - v_bq4 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][35u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][35u])))); - v_ccp = ((uint32_t)(((uint32_t)(v_bq0 + v_bq4)) << 13u)); - v_ccm = ((uint32_t)(((uint32_t)(v_bq0 - v_bq4)) << 13u)); - v_cd0 = ((uint32_t)(v_ccp + v_cb2)); - v_cd1 = ((uint32_t)(v_ccm + v_cb6)); - v_cd2 = ((uint32_t)(v_ccm - v_cb6)); - v_cd3 = ((uint32_t)(v_ccp - v_cb2)); - v_bq1 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][11u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][11u])))); - v_bq3 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][27u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][27u])))); - v_bq5 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][43u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][43u])))); - v_bq7 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][59u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][59u])))); - v_ci51 = ((uint32_t)(v_bq5 + v_bq1)); - v_ci53 = ((uint32_t)(v_bq5 + v_bq3)); - v_ci71 = ((uint32_t)(v_bq7 + v_bq1)); - v_ci73 = ((uint32_t)(v_bq7 + v_bq3)); - v_cj = ((uint32_t)(((uint32_t)(v_ci73 + v_ci51)) * 9633u)); - v_ck1 = ((uint32_t)(v_bq1 * 12299u)); - v_ck3 = ((uint32_t)(v_bq3 * 25172u)); - v_ck5 = ((uint32_t)(v_bq5 * 16819u)); - v_ck7 = ((uint32_t)(v_bq7 * 2446u)); - v_ci51 *= 4294964100u; - v_ci53 *= 4294946301u; - v_ci71 *= 4294959923u; - v_ci73 *= 4294951227u; - v_cl51 = ((uint32_t)(v_ci51 + v_cj)); - v_cl73 = ((uint32_t)(v_ci73 + v_cj)); - v_ck1 += ((uint32_t)(v_ci71 + v_cl51)); - v_ck3 += ((uint32_t)(v_ci53 + v_cl73)); - v_ck5 += ((uint32_t)(v_ci53 + v_cl51)); - v_ck7 += ((uint32_t)(v_ci71 + v_cl73)); - v_intermediate[3u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 + v_ck1)) + 1024u)), 11u); - v_intermediate[59u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 - v_ck1)) + 1024u)), 11u); - v_intermediate[11u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 + v_ck3)) + 1024u)), 11u); - v_intermediate[51u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 - v_ck3)) + 1024u)), 11u); - v_intermediate[19u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 + v_ck5)) + 1024u)), 11u); - v_intermediate[43u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 - v_ck5)) + 1024u)), 11u); - v_intermediate[27u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 + v_ck7)) + 1024u)), 11u); - v_intermediate[35u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 - v_ck7)) + 1024u)), 11u); + + return status; +} + +// -------- func gif.decoder.decode_id_part0 + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_gif__decoder__decode_id_part0( + wuffs_gif__decoder* self, + 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; } - if (0u == (self->private_data.f_mcu_blocks[0u][12u] | - self->private_data.f_mcu_blocks[0u][20u] | - self->private_data.f_mcu_blocks[0u][28u] | - self->private_data.f_mcu_blocks[0u][36u] | - self->private_data.f_mcu_blocks[0u][44u] | - self->private_data.f_mcu_blocks[0u][52u] | - self->private_data.f_mcu_blocks[0u][60u])) { - v_intermediate[4u] = ((uint32_t)(((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][4u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][4u])))) << 2u)); - v_intermediate[12u] = v_intermediate[4u]; - v_intermediate[20u] = v_intermediate[4u]; - v_intermediate[28u] = v_intermediate[4u]; - v_intermediate[36u] = v_intermediate[4u]; - v_intermediate[44u] = v_intermediate[4u]; - v_intermediate[52u] = v_intermediate[4u]; - v_intermediate[60u] = v_intermediate[4u]; - } else { - v_bq2 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][20u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][20u])))); - v_bq6 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][52u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][52u])))); - v_ca = ((uint32_t)(((uint32_t)(v_bq2 + v_bq6)) * 4433u)); - v_cb2 = ((uint32_t)(v_ca + ((uint32_t)(v_bq2 * 6270u)))); - v_cb6 = ((uint32_t)(v_ca - ((uint32_t)(v_bq6 * 15137u)))); - v_bq0 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][4u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][4u])))); - v_bq4 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][36u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][36u])))); - v_ccp = ((uint32_t)(((uint32_t)(v_bq0 + v_bq4)) << 13u)); - v_ccm = ((uint32_t)(((uint32_t)(v_bq0 - v_bq4)) << 13u)); - v_cd0 = ((uint32_t)(v_ccp + v_cb2)); - v_cd1 = ((uint32_t)(v_ccm + v_cb6)); - v_cd2 = ((uint32_t)(v_ccm - v_cb6)); - v_cd3 = ((uint32_t)(v_ccp - v_cb2)); - v_bq1 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][12u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][12u])))); - v_bq3 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][28u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][28u])))); - v_bq5 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][44u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][44u])))); - v_bq7 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][60u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][60u])))); - v_ci51 = ((uint32_t)(v_bq5 + v_bq1)); - v_ci53 = ((uint32_t)(v_bq5 + v_bq3)); - v_ci71 = ((uint32_t)(v_bq7 + v_bq1)); - v_ci73 = ((uint32_t)(v_bq7 + v_bq3)); - v_cj = ((uint32_t)(((uint32_t)(v_ci73 + v_ci51)) * 9633u)); - v_ck1 = ((uint32_t)(v_bq1 * 12299u)); - v_ck3 = ((uint32_t)(v_bq3 * 25172u)); - v_ck5 = ((uint32_t)(v_bq5 * 16819u)); - v_ck7 = ((uint32_t)(v_bq7 * 2446u)); - v_ci51 *= 4294964100u; - v_ci53 *= 4294946301u; - v_ci71 *= 4294959923u; - v_ci73 *= 4294951227u; - v_cl51 = ((uint32_t)(v_ci51 + v_cj)); - v_cl73 = ((uint32_t)(v_ci73 + v_cj)); - v_ck1 += ((uint32_t)(v_ci71 + v_cl51)); - v_ck3 += ((uint32_t)(v_ci53 + v_cl73)); - v_ck5 += ((uint32_t)(v_ci53 + v_cl51)); - v_ck7 += ((uint32_t)(v_ci71 + v_cl73)); - v_intermediate[4u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 + v_ck1)) + 1024u)), 11u); - v_intermediate[60u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 - v_ck1)) + 1024u)), 11u); - v_intermediate[12u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 + v_ck3)) + 1024u)), 11u); - v_intermediate[52u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 - v_ck3)) + 1024u)), 11u); - v_intermediate[20u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 + v_ck5)) + 1024u)), 11u); - v_intermediate[44u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 - v_ck5)) + 1024u)), 11u); - v_intermediate[28u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 + v_ck7)) + 1024u)), 11u); - v_intermediate[36u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 - v_ck7)) + 1024u)), 11u); + + uint32_t coro_susp_point = self->private_impl.p_decode_id_part0; + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + uint32_t t_0; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { + t_0 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src))); + iop_a_src += 2; + } else { + self->private_data.s_decode_id_part0.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_decode_id_part0.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 == 8) { + t_0 = ((uint32_t)(*scratch)); + break; + } + num_bits_0 += 8u; + *scratch |= ((uint64_t)(num_bits_0)) << 56; + } + } + self->private_impl.f_frame_rect_x0 = t_0; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + uint32_t t_1; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { + t_1 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src))); + iop_a_src += 2; + } else { + self->private_data.s_decode_id_part0.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + 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_decode_id_part0.scratch; + uint32_t num_bits_1 = ((uint32_t)(*scratch >> 56)); + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_1; + if (num_bits_1 == 8) { + t_1 = ((uint32_t)(*scratch)); + break; + } + num_bits_1 += 8u; + *scratch |= ((uint64_t)(num_bits_1)) << 56; + } + } + self->private_impl.f_frame_rect_y0 = t_1; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); + uint32_t t_2; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { + t_2 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src))); + iop_a_src += 2; + } else { + self->private_data.s_decode_id_part0.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); + 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_decode_id_part0.scratch; + uint32_t num_bits_2 = ((uint32_t)(*scratch >> 56)); + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_2; + if (num_bits_2 == 8) { + t_2 = ((uint32_t)(*scratch)); + break; + } + num_bits_2 += 8u; + *scratch |= ((uint64_t)(num_bits_2)) << 56; + } + } + self->private_impl.f_frame_rect_x1 = t_2; + } + self->private_impl.f_frame_rect_x1 += self->private_impl.f_frame_rect_x0; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); + uint32_t t_3; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { + t_3 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src))); + iop_a_src += 2; + } else { + self->private_data.s_decode_id_part0.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); + 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_decode_id_part0.scratch; + uint32_t num_bits_3 = ((uint32_t)(*scratch >> 56)); + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_3; + if (num_bits_3 == 8) { + t_3 = ((uint32_t)(*scratch)); + break; + } + num_bits_3 += 8u; + *scratch |= ((uint64_t)(num_bits_3)) << 56; + } + } + self->private_impl.f_frame_rect_y1 = t_3; + } + self->private_impl.f_frame_rect_y1 += self->private_impl.f_frame_rect_y0; + self->private_impl.f_dst_x = self->private_impl.f_frame_rect_x0; + self->private_impl.f_dst_y = self->private_impl.f_frame_rect_y0; + if ((self->private_impl.f_num_decoded_frame_configs_value == 0u) && ! self->private_impl.f_quirks[4u]) { + self->private_impl.f_width = wuffs_base__u32__max(self->private_impl.f_width, self->private_impl.f_frame_rect_x1); + self->private_impl.f_height = wuffs_base__u32__max(self->private_impl.f_height, self->private_impl.f_frame_rect_y1); + } + + goto ok; + ok: + self->private_impl.p_decode_id_part0 = 0; + goto exit; } - if (0u == (self->private_data.f_mcu_blocks[0u][13u] | - self->private_data.f_mcu_blocks[0u][21u] | - self->private_data.f_mcu_blocks[0u][29u] | - self->private_data.f_mcu_blocks[0u][37u] | - self->private_data.f_mcu_blocks[0u][45u] | - self->private_data.f_mcu_blocks[0u][53u] | - self->private_data.f_mcu_blocks[0u][61u])) { - v_intermediate[5u] = ((uint32_t)(((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][5u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][5u])))) << 2u)); - v_intermediate[13u] = v_intermediate[5u]; - v_intermediate[21u] = v_intermediate[5u]; - v_intermediate[29u] = v_intermediate[5u]; - v_intermediate[37u] = v_intermediate[5u]; - v_intermediate[45u] = v_intermediate[5u]; - v_intermediate[53u] = v_intermediate[5u]; - v_intermediate[61u] = v_intermediate[5u]; - } else { - v_bq2 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][21u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][21u])))); - v_bq6 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][53u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][53u])))); - v_ca = ((uint32_t)(((uint32_t)(v_bq2 + v_bq6)) * 4433u)); - v_cb2 = ((uint32_t)(v_ca + ((uint32_t)(v_bq2 * 6270u)))); - v_cb6 = ((uint32_t)(v_ca - ((uint32_t)(v_bq6 * 15137u)))); - v_bq0 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][5u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][5u])))); - v_bq4 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][37u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][37u])))); - v_ccp = ((uint32_t)(((uint32_t)(v_bq0 + v_bq4)) << 13u)); - v_ccm = ((uint32_t)(((uint32_t)(v_bq0 - v_bq4)) << 13u)); - v_cd0 = ((uint32_t)(v_ccp + v_cb2)); - v_cd1 = ((uint32_t)(v_ccm + v_cb6)); - v_cd2 = ((uint32_t)(v_ccm - v_cb6)); - v_cd3 = ((uint32_t)(v_ccp - v_cb2)); - v_bq1 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][13u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][13u])))); - v_bq3 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][29u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][29u])))); - v_bq5 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][45u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][45u])))); - v_bq7 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][61u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][61u])))); - v_ci51 = ((uint32_t)(v_bq5 + v_bq1)); - v_ci53 = ((uint32_t)(v_bq5 + v_bq3)); - v_ci71 = ((uint32_t)(v_bq7 + v_bq1)); - v_ci73 = ((uint32_t)(v_bq7 + v_bq3)); - v_cj = ((uint32_t)(((uint32_t)(v_ci73 + v_ci51)) * 9633u)); - v_ck1 = ((uint32_t)(v_bq1 * 12299u)); - v_ck3 = ((uint32_t)(v_bq3 * 25172u)); - v_ck5 = ((uint32_t)(v_bq5 * 16819u)); - v_ck7 = ((uint32_t)(v_bq7 * 2446u)); - v_ci51 *= 4294964100u; - v_ci53 *= 4294946301u; - v_ci71 *= 4294959923u; - v_ci73 *= 4294951227u; - v_cl51 = ((uint32_t)(v_ci51 + v_cj)); - v_cl73 = ((uint32_t)(v_ci73 + v_cj)); - v_ck1 += ((uint32_t)(v_ci71 + v_cl51)); - v_ck3 += ((uint32_t)(v_ci53 + v_cl73)); - v_ck5 += ((uint32_t)(v_ci53 + v_cl51)); - v_ck7 += ((uint32_t)(v_ci71 + v_cl73)); - v_intermediate[5u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 + v_ck1)) + 1024u)), 11u); - v_intermediate[61u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 - v_ck1)) + 1024u)), 11u); - v_intermediate[13u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 + v_ck3)) + 1024u)), 11u); - v_intermediate[53u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 - v_ck3)) + 1024u)), 11u); - v_intermediate[21u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 + v_ck5)) + 1024u)), 11u); - v_intermediate[45u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 - v_ck5)) + 1024u)), 11u); - v_intermediate[29u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 + v_ck7)) + 1024u)), 11u); - v_intermediate[37u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 - v_ck7)) + 1024u)), 11u); + + goto suspend; + suspend: + self->private_impl.p_decode_id_part0 = 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)); } - if (0u == (self->private_data.f_mcu_blocks[0u][14u] | - self->private_data.f_mcu_blocks[0u][22u] | - self->private_data.f_mcu_blocks[0u][30u] | - self->private_data.f_mcu_blocks[0u][38u] | - self->private_data.f_mcu_blocks[0u][46u] | - self->private_data.f_mcu_blocks[0u][54u] | - self->private_data.f_mcu_blocks[0u][62u])) { - v_intermediate[6u] = ((uint32_t)(((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][6u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][6u])))) << 2u)); - v_intermediate[14u] = v_intermediate[6u]; - v_intermediate[22u] = v_intermediate[6u]; - v_intermediate[30u] = v_intermediate[6u]; - v_intermediate[38u] = v_intermediate[6u]; - v_intermediate[46u] = v_intermediate[6u]; - v_intermediate[54u] = v_intermediate[6u]; - v_intermediate[62u] = v_intermediate[6u]; - } else { - v_bq2 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][22u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][22u])))); - v_bq6 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][54u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][54u])))); - v_ca = ((uint32_t)(((uint32_t)(v_bq2 + v_bq6)) * 4433u)); - v_cb2 = ((uint32_t)(v_ca + ((uint32_t)(v_bq2 * 6270u)))); - v_cb6 = ((uint32_t)(v_ca - ((uint32_t)(v_bq6 * 15137u)))); - v_bq0 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][6u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][6u])))); - v_bq4 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][38u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][38u])))); - v_ccp = ((uint32_t)(((uint32_t)(v_bq0 + v_bq4)) << 13u)); - v_ccm = ((uint32_t)(((uint32_t)(v_bq0 - v_bq4)) << 13u)); - v_cd0 = ((uint32_t)(v_ccp + v_cb2)); - v_cd1 = ((uint32_t)(v_ccm + v_cb6)); - v_cd2 = ((uint32_t)(v_ccm - v_cb6)); - v_cd3 = ((uint32_t)(v_ccp - v_cb2)); - v_bq1 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][14u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][14u])))); - v_bq3 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][30u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][30u])))); - v_bq5 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][46u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][46u])))); - v_bq7 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][62u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][62u])))); - v_ci51 = ((uint32_t)(v_bq5 + v_bq1)); - v_ci53 = ((uint32_t)(v_bq5 + v_bq3)); - v_ci71 = ((uint32_t)(v_bq7 + v_bq1)); - v_ci73 = ((uint32_t)(v_bq7 + v_bq3)); - v_cj = ((uint32_t)(((uint32_t)(v_ci73 + v_ci51)) * 9633u)); - v_ck1 = ((uint32_t)(v_bq1 * 12299u)); - v_ck3 = ((uint32_t)(v_bq3 * 25172u)); - v_ck5 = ((uint32_t)(v_bq5 * 16819u)); - v_ck7 = ((uint32_t)(v_bq7 * 2446u)); - v_ci51 *= 4294964100u; - v_ci53 *= 4294946301u; - v_ci71 *= 4294959923u; - v_ci73 *= 4294951227u; - v_cl51 = ((uint32_t)(v_ci51 + v_cj)); - v_cl73 = ((uint32_t)(v_ci73 + v_cj)); - v_ck1 += ((uint32_t)(v_ci71 + v_cl51)); - v_ck3 += ((uint32_t)(v_ci53 + v_cl73)); - v_ck5 += ((uint32_t)(v_ci53 + v_cl51)); - v_ck7 += ((uint32_t)(v_ci71 + v_cl73)); - v_intermediate[6u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 + v_ck1)) + 1024u)), 11u); - v_intermediate[62u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 - v_ck1)) + 1024u)), 11u); - v_intermediate[14u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 + v_ck3)) + 1024u)), 11u); - v_intermediate[54u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 - v_ck3)) + 1024u)), 11u); - v_intermediate[22u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 + v_ck5)) + 1024u)), 11u); - v_intermediate[46u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 - v_ck5)) + 1024u)), 11u); - v_intermediate[30u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 + v_ck7)) + 1024u)), 11u); - v_intermediate[38u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 - v_ck7)) + 1024u)), 11u); + + return status; +} + +// -------- func gif.decoder.decode_id_part1 + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_gif__decoder__decode_id_part1( + wuffs_gif__decoder* self, + wuffs_base__pixel_buffer* a_dst, + wuffs_base__io_buffer* a_src, + wuffs_base__pixel_blend a_blend) { + wuffs_base__status status = wuffs_base__make_status(NULL); + + uint8_t v_flags = 0; + uint8_t v_which_palette = 0; + uint32_t v_num_palette_entries = 0; + uint32_t v_i = 0; + uint32_t v_argb = 0; + wuffs_base__status v_status = wuffs_base__make_status(NULL); + uint8_t v_lw = 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; } - if (0u == (self->private_data.f_mcu_blocks[0u][15u] | - self->private_data.f_mcu_blocks[0u][23u] | - self->private_data.f_mcu_blocks[0u][31u] | - self->private_data.f_mcu_blocks[0u][39u] | - self->private_data.f_mcu_blocks[0u][47u] | - self->private_data.f_mcu_blocks[0u][55u] | - self->private_data.f_mcu_blocks[0u][63u])) { - v_intermediate[7u] = ((uint32_t)(((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][7u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][7u])))) << 2u)); - v_intermediate[15u] = v_intermediate[7u]; - v_intermediate[23u] = v_intermediate[7u]; - v_intermediate[31u] = v_intermediate[7u]; - v_intermediate[39u] = v_intermediate[7u]; - v_intermediate[47u] = v_intermediate[7u]; - v_intermediate[55u] = v_intermediate[7u]; - v_intermediate[63u] = v_intermediate[7u]; - } else { - v_bq2 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][23u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][23u])))); - v_bq6 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][55u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][55u])))); - v_ca = ((uint32_t)(((uint32_t)(v_bq2 + v_bq6)) * 4433u)); - v_cb2 = ((uint32_t)(v_ca + ((uint32_t)(v_bq2 * 6270u)))); - v_cb6 = ((uint32_t)(v_ca - ((uint32_t)(v_bq6 * 15137u)))); - v_bq0 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][7u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][7u])))); - v_bq4 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][39u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][39u])))); - v_ccp = ((uint32_t)(((uint32_t)(v_bq0 + v_bq4)) << 13u)); - v_ccm = ((uint32_t)(((uint32_t)(v_bq0 - v_bq4)) << 13u)); - v_cd0 = ((uint32_t)(v_ccp + v_cb2)); - v_cd1 = ((uint32_t)(v_ccm + v_cb6)); - v_cd2 = ((uint32_t)(v_ccm - v_cb6)); - v_cd3 = ((uint32_t)(v_ccp - v_cb2)); - v_bq1 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][15u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][15u])))); - v_bq3 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][31u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][31u])))); - v_bq5 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][47u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][47u])))); - v_bq7 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][63u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][63u])))); - v_ci51 = ((uint32_t)(v_bq5 + v_bq1)); - v_ci53 = ((uint32_t)(v_bq5 + v_bq3)); - v_ci71 = ((uint32_t)(v_bq7 + v_bq1)); - v_ci73 = ((uint32_t)(v_bq7 + v_bq3)); - v_cj = ((uint32_t)(((uint32_t)(v_ci73 + v_ci51)) * 9633u)); - v_ck1 = ((uint32_t)(v_bq1 * 12299u)); - v_ck3 = ((uint32_t)(v_bq3 * 25172u)); - v_ck5 = ((uint32_t)(v_bq5 * 16819u)); - v_ck7 = ((uint32_t)(v_bq7 * 2446u)); - v_ci51 *= 4294964100u; - v_ci53 *= 4294946301u; - v_ci71 *= 4294959923u; - v_ci73 *= 4294951227u; - v_cl51 = ((uint32_t)(v_ci51 + v_cj)); - v_cl73 = ((uint32_t)(v_ci73 + v_cj)); - v_ck1 += ((uint32_t)(v_ci71 + v_cl51)); - v_ck3 += ((uint32_t)(v_ci53 + v_cl73)); - v_ck5 += ((uint32_t)(v_ci53 + v_cl51)); - v_ck7 += ((uint32_t)(v_ci71 + v_cl73)); - v_intermediate[7u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 + v_ck1)) + 1024u)), 11u); - v_intermediate[63u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 - v_ck1)) + 1024u)), 11u); - v_intermediate[15u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 + v_ck3)) + 1024u)), 11u); - v_intermediate[55u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 - v_ck3)) + 1024u)), 11u); - v_intermediate[23u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 + v_ck5)) + 1024u)), 11u); - v_intermediate[47u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 - v_ck5)) + 1024u)), 11u); - v_intermediate[31u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 + v_ck7)) + 1024u)), 11u); - v_intermediate[39u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 - v_ck7)) + 1024u)), 11u); + + uint32_t coro_susp_point = self->private_impl.p_decode_id_part1; + if (coro_susp_point) { + v_which_palette = self->private_data.s_decode_id_part1.v_which_palette; + v_num_palette_entries = self->private_data.s_decode_id_part1.v_num_palette_entries; + v_i = self->private_data.s_decode_id_part1.v_i; } - if (0u == (v_intermediate[1u] | - v_intermediate[2u] | - v_intermediate[3u] | - v_intermediate[4u] | - v_intermediate[5u] | - v_intermediate[6u] | - v_intermediate[7u])) { - if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { - return wuffs_base__make_empty_struct(); + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_0 = *iop_a_src++; + v_flags = t_0; } - a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(v_intermediate[0u] + 16u)) >> 5u) & 1023u)]; - a_dst_buffer.ptr[1u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[2u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[3u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[4u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[5u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[6u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[7u] = a_dst_buffer.ptr[0u]; - a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); - } else { - v_in2 = v_intermediate[2u]; - v_in6 = v_intermediate[6u]; - v_ra = ((uint32_t)(((uint32_t)(v_in2 + v_in6)) * 4433u)); - v_rb2 = ((uint32_t)(v_ra + ((uint32_t)(v_in2 * 6270u)))); - v_rb6 = ((uint32_t)(v_ra - ((uint32_t)(v_in6 * 15137u)))); - v_in0 = v_intermediate[0u]; - v_in4 = v_intermediate[4u]; - v_rcp = ((uint32_t)(((uint32_t)(v_in0 + v_in4)) << 13u)); - v_rcm = ((uint32_t)(((uint32_t)(v_in0 - v_in4)) << 13u)); - v_rd0 = ((uint32_t)(v_rcp + v_rb2)); - v_rd1 = ((uint32_t)(v_rcm + v_rb6)); - v_rd2 = ((uint32_t)(v_rcm - v_rb6)); - v_rd3 = ((uint32_t)(v_rcp - v_rb2)); - v_in1 = v_intermediate[1u]; - v_in3 = v_intermediate[3u]; - v_in5 = v_intermediate[5u]; - v_in7 = v_intermediate[7u]; - v_ri51 = ((uint32_t)(v_in5 + v_in1)); - v_ri53 = ((uint32_t)(v_in5 + v_in3)); - v_ri71 = ((uint32_t)(v_in7 + v_in1)); - v_ri73 = ((uint32_t)(v_in7 + v_in3)); - v_rj = ((uint32_t)(((uint32_t)(v_ri73 + v_ri51)) * 9633u)); - v_rk1 = ((uint32_t)(v_in1 * 12299u)); - v_rk3 = ((uint32_t)(v_in3 * 25172u)); - v_rk5 = ((uint32_t)(v_in5 * 16819u)); - v_rk7 = ((uint32_t)(v_in7 * 2446u)); - v_ri51 *= 4294964100u; - v_ri53 *= 4294946301u; - v_ri71 *= 4294959923u; - v_ri73 *= 4294951227u; - v_rl51 = ((uint32_t)(v_ri51 + v_rj)); - v_rl73 = ((uint32_t)(v_ri73 + v_rj)); - v_rk1 += ((uint32_t)(v_ri71 + v_rl51)); - v_rk3 += ((uint32_t)(v_ri53 + v_rl73)); - v_rk5 += ((uint32_t)(v_ri53 + v_rl51)); - v_rk7 += ((uint32_t)(v_ri71 + v_rl73)); - if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { - return wuffs_base__make_empty_struct(); + if (((uint8_t)(v_flags & 64u)) != 0u) { + self->private_impl.f_interlace = 4u; + } else { + self->private_impl.f_interlace = 0u; } - a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 + v_rk1)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[7u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 - v_rk1)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[1u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 + v_rk3)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[6u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 - v_rk3)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[2u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 + v_rk5)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[5u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 - v_rk5)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[3u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 + v_rk7)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[4u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 - v_rk7)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); - } - if (0u == (v_intermediate[9u] | - v_intermediate[10u] | - v_intermediate[11u] | - v_intermediate[12u] | - v_intermediate[13u] | - v_intermediate[14u] | - v_intermediate[15u])) { - if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { - return wuffs_base__make_empty_struct(); + v_which_palette = 1u; + if (((uint8_t)(v_flags & 128u)) != 0u) { + v_num_palette_entries = (((uint32_t)(1u)) << ((uint8_t)(1u + ((uint8_t)(v_flags & 7u))))); + v_i = 0u; + while (v_i < v_num_palette_entries) { + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); + uint32_t t_1; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 3)) { + t_1 = ((uint32_t)(wuffs_base__peek_u24be__no_bounds_check(iop_a_src))); + iop_a_src += 3; + } else { + self->private_data.s_decode_id_part1.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + 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_decode_id_part1.scratch; + uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1); + if (num_bits_1 == 16) { + t_1 = ((uint32_t)(*scratch >> 40)); + break; + } + num_bits_1 += 8u; + *scratch |= ((uint64_t)(num_bits_1)); + } + } + v_argb = t_1; + } + v_argb |= 4278190080u; + self->private_data.f_palettes[1u][((4u * v_i) + 0u)] = ((uint8_t)((v_argb >> 0u))); + self->private_data.f_palettes[1u][((4u * v_i) + 1u)] = ((uint8_t)((v_argb >> 8u))); + self->private_data.f_palettes[1u][((4u * v_i) + 2u)] = ((uint8_t)((v_argb >> 16u))); + self->private_data.f_palettes[1u][((4u * v_i) + 3u)] = ((uint8_t)((v_argb >> 24u))); + v_i += 1u; + } + while (v_i < 256u) { + self->private_data.f_palettes[1u][((4u * v_i) + 0u)] = 0u; + self->private_data.f_palettes[1u][((4u * v_i) + 1u)] = 0u; + self->private_data.f_palettes[1u][((4u * v_i) + 2u)] = 0u; + self->private_data.f_palettes[1u][((4u * v_i) + 3u)] = 255u; + v_i += 1u; + } + } else if (self->private_impl.f_quirks[6u] && ! self->private_impl.f_has_global_palette) { + status = wuffs_base__make_status(wuffs_gif__error__bad_palette); + goto exit; + } else if (self->private_impl.f_gc_has_transparent_index) { + wuffs_private_impl__slice_u8__copy_from_slice(wuffs_base__make_slice_u8(self->private_data.f_palettes[1u], 1024), wuffs_base__make_slice_u8(self->private_data.f_palettes[0u], 1024)); + } else { + v_which_palette = 0u; } - a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(v_intermediate[8u] + 16u)) >> 5u) & 1023u)]; - a_dst_buffer.ptr[1u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[2u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[3u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[4u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[5u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[6u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[7u] = a_dst_buffer.ptr[0u]; - a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); - } else { - v_in2 = v_intermediate[10u]; - v_in6 = v_intermediate[14u]; - v_ra = ((uint32_t)(((uint32_t)(v_in2 + v_in6)) * 4433u)); - v_rb2 = ((uint32_t)(v_ra + ((uint32_t)(v_in2 * 6270u)))); - v_rb6 = ((uint32_t)(v_ra - ((uint32_t)(v_in6 * 15137u)))); - v_in0 = v_intermediate[8u]; - v_in4 = v_intermediate[12u]; - v_rcp = ((uint32_t)(((uint32_t)(v_in0 + v_in4)) << 13u)); - v_rcm = ((uint32_t)(((uint32_t)(v_in0 - v_in4)) << 13u)); - v_rd0 = ((uint32_t)(v_rcp + v_rb2)); - v_rd1 = ((uint32_t)(v_rcm + v_rb6)); - v_rd2 = ((uint32_t)(v_rcm - v_rb6)); - v_rd3 = ((uint32_t)(v_rcp - v_rb2)); - v_in1 = v_intermediate[9u]; - v_in3 = v_intermediate[11u]; - v_in5 = v_intermediate[13u]; - v_in7 = v_intermediate[15u]; - v_ri51 = ((uint32_t)(v_in5 + v_in1)); - v_ri53 = ((uint32_t)(v_in5 + v_in3)); - v_ri71 = ((uint32_t)(v_in7 + v_in1)); - v_ri73 = ((uint32_t)(v_in7 + v_in3)); - v_rj = ((uint32_t)(((uint32_t)(v_ri73 + v_ri51)) * 9633u)); - v_rk1 = ((uint32_t)(v_in1 * 12299u)); - v_rk3 = ((uint32_t)(v_in3 * 25172u)); - v_rk5 = ((uint32_t)(v_in5 * 16819u)); - v_rk7 = ((uint32_t)(v_in7 * 2446u)); - v_ri51 *= 4294964100u; - v_ri53 *= 4294946301u; - v_ri71 *= 4294959923u; - v_ri73 *= 4294951227u; - v_rl51 = ((uint32_t)(v_ri51 + v_rj)); - v_rl73 = ((uint32_t)(v_ri73 + v_rj)); - v_rk1 += ((uint32_t)(v_ri71 + v_rl51)); - v_rk3 += ((uint32_t)(v_ri53 + v_rl73)); - v_rk5 += ((uint32_t)(v_ri53 + v_rl51)); - v_rk7 += ((uint32_t)(v_ri71 + v_rl73)); - if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { - return wuffs_base__make_empty_struct(); + if (self->private_impl.f_gc_has_transparent_index) { + self->private_data.f_palettes[1u][((4u * ((uint32_t)(self->private_impl.f_gc_transparent_index))) + 0u)] = 0u; + self->private_data.f_palettes[1u][((4u * ((uint32_t)(self->private_impl.f_gc_transparent_index))) + 1u)] = 0u; + self->private_data.f_palettes[1u][((4u * ((uint32_t)(self->private_impl.f_gc_transparent_index))) + 2u)] = 0u; + self->private_data.f_palettes[1u][((4u * ((uint32_t)(self->private_impl.f_gc_transparent_index))) + 3u)] = 0u; } - a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 + v_rk1)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[7u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 - v_rk1)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[1u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 + v_rk3)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[6u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 - v_rk3)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[2u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 + v_rk5)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[5u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 - v_rk5)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[3u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 + v_rk7)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[4u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 - v_rk7)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); - } - if (0u == (v_intermediate[17u] | - v_intermediate[18u] | - v_intermediate[19u] | - v_intermediate[20u] | - v_intermediate[21u] | - v_intermediate[22u] | - v_intermediate[23u])) { - if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { - return wuffs_base__make_empty_struct(); + 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_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024)), + wuffs_base__utility__make_pixel_format(2198077448u), + wuffs_base__make_slice_u8(self->private_data.f_palettes[v_which_palette], 1024), + 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; } - a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(v_intermediate[16u] + 16u)) >> 5u) & 1023u)]; - a_dst_buffer.ptr[1u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[2u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[3u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[4u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[5u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[6u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[7u] = a_dst_buffer.ptr[0u]; - a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); - } else { - v_in2 = v_intermediate[18u]; - v_in6 = v_intermediate[22u]; - v_ra = ((uint32_t)(((uint32_t)(v_in2 + v_in6)) * 4433u)); - v_rb2 = ((uint32_t)(v_ra + ((uint32_t)(v_in2 * 6270u)))); - v_rb6 = ((uint32_t)(v_ra - ((uint32_t)(v_in6 * 15137u)))); - v_in0 = v_intermediate[16u]; - v_in4 = v_intermediate[20u]; - v_rcp = ((uint32_t)(((uint32_t)(v_in0 + v_in4)) << 13u)); - v_rcm = ((uint32_t)(((uint32_t)(v_in0 - v_in4)) << 13u)); - v_rd0 = ((uint32_t)(v_rcp + v_rb2)); - v_rd1 = ((uint32_t)(v_rcm + v_rb6)); - v_rd2 = ((uint32_t)(v_rcm - v_rb6)); - v_rd3 = ((uint32_t)(v_rcp - v_rb2)); - v_in1 = v_intermediate[17u]; - v_in3 = v_intermediate[19u]; - v_in5 = v_intermediate[21u]; - v_in7 = v_intermediate[23u]; - v_ri51 = ((uint32_t)(v_in5 + v_in1)); - v_ri53 = ((uint32_t)(v_in5 + v_in3)); - v_ri71 = ((uint32_t)(v_in7 + v_in1)); - v_ri73 = ((uint32_t)(v_in7 + v_in3)); - v_rj = ((uint32_t)(((uint32_t)(v_ri73 + v_ri51)) * 9633u)); - v_rk1 = ((uint32_t)(v_in1 * 12299u)); - v_rk3 = ((uint32_t)(v_in3 * 25172u)); - v_rk5 = ((uint32_t)(v_in5 * 16819u)); - v_rk7 = ((uint32_t)(v_in7 * 2446u)); - v_ri51 *= 4294964100u; - v_ri53 *= 4294946301u; - v_ri71 *= 4294959923u; - v_ri73 *= 4294951227u; - v_rl51 = ((uint32_t)(v_ri51 + v_rj)); - v_rl73 = ((uint32_t)(v_ri73 + v_rj)); - v_rk1 += ((uint32_t)(v_ri71 + v_rl51)); - v_rk3 += ((uint32_t)(v_ri53 + v_rl73)); - v_rk5 += ((uint32_t)(v_ri53 + v_rl51)); - v_rk7 += ((uint32_t)(v_ri71 + v_rl73)); - if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { - return wuffs_base__make_empty_struct(); + if (self->private_impl.f_ignored_but_affects_benchmarks) { } - a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 + v_rk1)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[7u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 - v_rk1)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[1u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 + v_rk3)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[6u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 - v_rk3)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[2u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 + v_rk5)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[5u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 - v_rk5)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[3u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 + v_rk7)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[4u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 - v_rk7)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); - } - if (0u == (v_intermediate[25u] | - v_intermediate[26u] | - v_intermediate[27u] | - v_intermediate[28u] | - v_intermediate[29u] | - v_intermediate[30u] | - v_intermediate[31u])) { - if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { - return wuffs_base__make_empty_struct(); + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_2 = *iop_a_src++; + v_lw = t_2; } - a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(v_intermediate[24u] + 16u)) >> 5u) & 1023u)]; - a_dst_buffer.ptr[1u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[2u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[3u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[4u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[5u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[6u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[7u] = a_dst_buffer.ptr[0u]; - a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); - } else { - v_in2 = v_intermediate[26u]; - v_in6 = v_intermediate[30u]; - v_ra = ((uint32_t)(((uint32_t)(v_in2 + v_in6)) * 4433u)); - v_rb2 = ((uint32_t)(v_ra + ((uint32_t)(v_in2 * 6270u)))); - v_rb6 = ((uint32_t)(v_ra - ((uint32_t)(v_in6 * 15137u)))); - v_in0 = v_intermediate[24u]; - v_in4 = v_intermediate[28u]; - v_rcp = ((uint32_t)(((uint32_t)(v_in0 + v_in4)) << 13u)); - v_rcm = ((uint32_t)(((uint32_t)(v_in0 - v_in4)) << 13u)); - v_rd0 = ((uint32_t)(v_rcp + v_rb2)); - v_rd1 = ((uint32_t)(v_rcm + v_rb6)); - v_rd2 = ((uint32_t)(v_rcm - v_rb6)); - v_rd3 = ((uint32_t)(v_rcp - v_rb2)); - v_in1 = v_intermediate[25u]; - v_in3 = v_intermediate[27u]; - v_in5 = v_intermediate[29u]; - v_in7 = v_intermediate[31u]; - v_ri51 = ((uint32_t)(v_in5 + v_in1)); - v_ri53 = ((uint32_t)(v_in5 + v_in3)); - v_ri71 = ((uint32_t)(v_in7 + v_in1)); - v_ri73 = ((uint32_t)(v_in7 + v_in3)); - v_rj = ((uint32_t)(((uint32_t)(v_ri73 + v_ri51)) * 9633u)); - v_rk1 = ((uint32_t)(v_in1 * 12299u)); - v_rk3 = ((uint32_t)(v_in3 * 25172u)); - v_rk5 = ((uint32_t)(v_in5 * 16819u)); - v_rk7 = ((uint32_t)(v_in7 * 2446u)); - v_ri51 *= 4294964100u; - v_ri53 *= 4294946301u; - v_ri71 *= 4294959923u; - v_ri73 *= 4294951227u; - v_rl51 = ((uint32_t)(v_ri51 + v_rj)); - v_rl73 = ((uint32_t)(v_ri73 + v_rj)); - v_rk1 += ((uint32_t)(v_ri71 + v_rl51)); - v_rk3 += ((uint32_t)(v_ri53 + v_rl73)); - v_rk5 += ((uint32_t)(v_ri53 + v_rl51)); - v_rk7 += ((uint32_t)(v_ri71 + v_rl73)); - if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { - return wuffs_base__make_empty_struct(); - } - a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 + v_rk1)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[7u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 - v_rk1)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[1u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 + v_rk3)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[6u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 - v_rk3)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[2u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 + v_rk5)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[5u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 - v_rk5)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[3u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 + v_rk7)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[4u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 - v_rk7)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); - } - if (0u == (v_intermediate[33u] | - v_intermediate[34u] | - v_intermediate[35u] | - v_intermediate[36u] | - v_intermediate[37u] | - v_intermediate[38u] | - v_intermediate[39u])) { - if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { - return wuffs_base__make_empty_struct(); - } - a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(v_intermediate[32u] + 16u)) >> 5u) & 1023u)]; - a_dst_buffer.ptr[1u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[2u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[3u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[4u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[5u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[6u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[7u] = a_dst_buffer.ptr[0u]; - a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); - } else { - v_in2 = v_intermediate[34u]; - v_in6 = v_intermediate[38u]; - v_ra = ((uint32_t)(((uint32_t)(v_in2 + v_in6)) * 4433u)); - v_rb2 = ((uint32_t)(v_ra + ((uint32_t)(v_in2 * 6270u)))); - v_rb6 = ((uint32_t)(v_ra - ((uint32_t)(v_in6 * 15137u)))); - v_in0 = v_intermediate[32u]; - v_in4 = v_intermediate[36u]; - v_rcp = ((uint32_t)(((uint32_t)(v_in0 + v_in4)) << 13u)); - v_rcm = ((uint32_t)(((uint32_t)(v_in0 - v_in4)) << 13u)); - v_rd0 = ((uint32_t)(v_rcp + v_rb2)); - v_rd1 = ((uint32_t)(v_rcm + v_rb6)); - v_rd2 = ((uint32_t)(v_rcm - v_rb6)); - v_rd3 = ((uint32_t)(v_rcp - v_rb2)); - v_in1 = v_intermediate[33u]; - v_in3 = v_intermediate[35u]; - v_in5 = v_intermediate[37u]; - v_in7 = v_intermediate[39u]; - v_ri51 = ((uint32_t)(v_in5 + v_in1)); - v_ri53 = ((uint32_t)(v_in5 + v_in3)); - v_ri71 = ((uint32_t)(v_in7 + v_in1)); - v_ri73 = ((uint32_t)(v_in7 + v_in3)); - v_rj = ((uint32_t)(((uint32_t)(v_ri73 + v_ri51)) * 9633u)); - v_rk1 = ((uint32_t)(v_in1 * 12299u)); - v_rk3 = ((uint32_t)(v_in3 * 25172u)); - v_rk5 = ((uint32_t)(v_in5 * 16819u)); - v_rk7 = ((uint32_t)(v_in7 * 2446u)); - v_ri51 *= 4294964100u; - v_ri53 *= 4294946301u; - v_ri71 *= 4294959923u; - v_ri73 *= 4294951227u; - v_rl51 = ((uint32_t)(v_ri51 + v_rj)); - v_rl73 = ((uint32_t)(v_ri73 + v_rj)); - v_rk1 += ((uint32_t)(v_ri71 + v_rl51)); - v_rk3 += ((uint32_t)(v_ri53 + v_rl73)); - v_rk5 += ((uint32_t)(v_ri53 + v_rl51)); - v_rk7 += ((uint32_t)(v_ri71 + v_rl73)); - if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { - return wuffs_base__make_empty_struct(); - } - a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 + v_rk1)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[7u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 - v_rk1)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[1u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 + v_rk3)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[6u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 - v_rk3)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[2u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 + v_rk5)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[5u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 - v_rk5)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[3u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 + v_rk7)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[4u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 - v_rk7)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); - } - if (0u == (v_intermediate[41u] | - v_intermediate[42u] | - v_intermediate[43u] | - v_intermediate[44u] | - v_intermediate[45u] | - v_intermediate[46u] | - v_intermediate[47u])) { - if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { - return wuffs_base__make_empty_struct(); - } - a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(v_intermediate[40u] + 16u)) >> 5u) & 1023u)]; - a_dst_buffer.ptr[1u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[2u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[3u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[4u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[5u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[6u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[7u] = a_dst_buffer.ptr[0u]; - a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); - } else { - v_in2 = v_intermediate[42u]; - v_in6 = v_intermediate[46u]; - v_ra = ((uint32_t)(((uint32_t)(v_in2 + v_in6)) * 4433u)); - v_rb2 = ((uint32_t)(v_ra + ((uint32_t)(v_in2 * 6270u)))); - v_rb6 = ((uint32_t)(v_ra - ((uint32_t)(v_in6 * 15137u)))); - v_in0 = v_intermediate[40u]; - v_in4 = v_intermediate[44u]; - v_rcp = ((uint32_t)(((uint32_t)(v_in0 + v_in4)) << 13u)); - v_rcm = ((uint32_t)(((uint32_t)(v_in0 - v_in4)) << 13u)); - v_rd0 = ((uint32_t)(v_rcp + v_rb2)); - v_rd1 = ((uint32_t)(v_rcm + v_rb6)); - v_rd2 = ((uint32_t)(v_rcm - v_rb6)); - v_rd3 = ((uint32_t)(v_rcp - v_rb2)); - v_in1 = v_intermediate[41u]; - v_in3 = v_intermediate[43u]; - v_in5 = v_intermediate[45u]; - v_in7 = v_intermediate[47u]; - v_ri51 = ((uint32_t)(v_in5 + v_in1)); - v_ri53 = ((uint32_t)(v_in5 + v_in3)); - v_ri71 = ((uint32_t)(v_in7 + v_in1)); - v_ri73 = ((uint32_t)(v_in7 + v_in3)); - v_rj = ((uint32_t)(((uint32_t)(v_ri73 + v_ri51)) * 9633u)); - v_rk1 = ((uint32_t)(v_in1 * 12299u)); - v_rk3 = ((uint32_t)(v_in3 * 25172u)); - v_rk5 = ((uint32_t)(v_in5 * 16819u)); - v_rk7 = ((uint32_t)(v_in7 * 2446u)); - v_ri51 *= 4294964100u; - v_ri53 *= 4294946301u; - v_ri71 *= 4294959923u; - v_ri73 *= 4294951227u; - v_rl51 = ((uint32_t)(v_ri51 + v_rj)); - v_rl73 = ((uint32_t)(v_ri73 + v_rj)); - v_rk1 += ((uint32_t)(v_ri71 + v_rl51)); - v_rk3 += ((uint32_t)(v_ri53 + v_rl73)); - v_rk5 += ((uint32_t)(v_ri53 + v_rl51)); - v_rk7 += ((uint32_t)(v_ri71 + v_rl73)); - if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { - return wuffs_base__make_empty_struct(); - } - a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 + v_rk1)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[7u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 - v_rk1)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[1u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 + v_rk3)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[6u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 - v_rk3)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[2u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 + v_rk5)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[5u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 - v_rk5)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[3u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 + v_rk7)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[4u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 - v_rk7)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); - } - if (0u == (v_intermediate[49u] | - v_intermediate[50u] | - v_intermediate[51u] | - v_intermediate[52u] | - v_intermediate[53u] | - v_intermediate[54u] | - v_intermediate[55u])) { - if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { - return wuffs_base__make_empty_struct(); - } - a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(v_intermediate[48u] + 16u)) >> 5u) & 1023u)]; - a_dst_buffer.ptr[1u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[2u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[3u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[4u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[5u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[6u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[7u] = a_dst_buffer.ptr[0u]; - a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); - } else { - v_in2 = v_intermediate[50u]; - v_in6 = v_intermediate[54u]; - v_ra = ((uint32_t)(((uint32_t)(v_in2 + v_in6)) * 4433u)); - v_rb2 = ((uint32_t)(v_ra + ((uint32_t)(v_in2 * 6270u)))); - v_rb6 = ((uint32_t)(v_ra - ((uint32_t)(v_in6 * 15137u)))); - v_in0 = v_intermediate[48u]; - v_in4 = v_intermediate[52u]; - v_rcp = ((uint32_t)(((uint32_t)(v_in0 + v_in4)) << 13u)); - v_rcm = ((uint32_t)(((uint32_t)(v_in0 - v_in4)) << 13u)); - v_rd0 = ((uint32_t)(v_rcp + v_rb2)); - v_rd1 = ((uint32_t)(v_rcm + v_rb6)); - v_rd2 = ((uint32_t)(v_rcm - v_rb6)); - v_rd3 = ((uint32_t)(v_rcp - v_rb2)); - v_in1 = v_intermediate[49u]; - v_in3 = v_intermediate[51u]; - v_in5 = v_intermediate[53u]; - v_in7 = v_intermediate[55u]; - v_ri51 = ((uint32_t)(v_in5 + v_in1)); - v_ri53 = ((uint32_t)(v_in5 + v_in3)); - v_ri71 = ((uint32_t)(v_in7 + v_in1)); - v_ri73 = ((uint32_t)(v_in7 + v_in3)); - v_rj = ((uint32_t)(((uint32_t)(v_ri73 + v_ri51)) * 9633u)); - v_rk1 = ((uint32_t)(v_in1 * 12299u)); - v_rk3 = ((uint32_t)(v_in3 * 25172u)); - v_rk5 = ((uint32_t)(v_in5 * 16819u)); - v_rk7 = ((uint32_t)(v_in7 * 2446u)); - v_ri51 *= 4294964100u; - v_ri53 *= 4294946301u; - v_ri71 *= 4294959923u; - v_ri73 *= 4294951227u; - v_rl51 = ((uint32_t)(v_ri51 + v_rj)); - v_rl73 = ((uint32_t)(v_ri73 + v_rj)); - v_rk1 += ((uint32_t)(v_ri71 + v_rl51)); - v_rk3 += ((uint32_t)(v_ri53 + v_rl73)); - v_rk5 += ((uint32_t)(v_ri53 + v_rl51)); - v_rk7 += ((uint32_t)(v_ri71 + v_rl73)); - if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { - return wuffs_base__make_empty_struct(); + if (v_lw > 8u) { + status = wuffs_base__make_status(wuffs_gif__error__bad_literal_width); + goto exit; } - a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 + v_rk1)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[7u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 - v_rk1)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[1u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 + v_rk3)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[6u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 - v_rk3)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[2u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 + v_rk5)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[5u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 - v_rk5)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[3u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 + v_rk7)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[4u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 - v_rk7)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); + self->private_impl.f_lzw_pending_literal_width_plus_one = ((uint32_t)(((uint8_t)(1u + v_lw)))); + self->private_impl.f_ignored_but_affects_benchmarks = true; + + ok: + self->private_impl.p_decode_id_part1 = 0; + goto exit; } - if (0u == (v_intermediate[57u] | - v_intermediate[58u] | - v_intermediate[59u] | - v_intermediate[60u] | - v_intermediate[61u] | - v_intermediate[62u] | - v_intermediate[63u])) { - if (8u > ((uint64_t)(a_dst_buffer.len))) { - return wuffs_base__make_empty_struct(); - } - a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(v_intermediate[56u] + 16u)) >> 5u) & 1023u)]; - a_dst_buffer.ptr[1u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[2u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[3u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[4u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[5u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[6u] = a_dst_buffer.ptr[0u]; - a_dst_buffer.ptr[7u] = a_dst_buffer.ptr[0u]; - } else { - v_in2 = v_intermediate[58u]; - v_in6 = v_intermediate[62u]; - v_ra = ((uint32_t)(((uint32_t)(v_in2 + v_in6)) * 4433u)); - v_rb2 = ((uint32_t)(v_ra + ((uint32_t)(v_in2 * 6270u)))); - v_rb6 = ((uint32_t)(v_ra - ((uint32_t)(v_in6 * 15137u)))); - v_in0 = v_intermediate[56u]; - v_in4 = v_intermediate[60u]; - v_rcp = ((uint32_t)(((uint32_t)(v_in0 + v_in4)) << 13u)); - v_rcm = ((uint32_t)(((uint32_t)(v_in0 - v_in4)) << 13u)); - v_rd0 = ((uint32_t)(v_rcp + v_rb2)); - v_rd1 = ((uint32_t)(v_rcm + v_rb6)); - v_rd2 = ((uint32_t)(v_rcm - v_rb6)); - v_rd3 = ((uint32_t)(v_rcp - v_rb2)); - v_in1 = v_intermediate[57u]; - v_in3 = v_intermediate[59u]; - v_in5 = v_intermediate[61u]; - v_in7 = v_intermediate[63u]; - v_ri51 = ((uint32_t)(v_in5 + v_in1)); - v_ri53 = ((uint32_t)(v_in5 + v_in3)); - v_ri71 = ((uint32_t)(v_in7 + v_in1)); - v_ri73 = ((uint32_t)(v_in7 + v_in3)); - v_rj = ((uint32_t)(((uint32_t)(v_ri73 + v_ri51)) * 9633u)); - v_rk1 = ((uint32_t)(v_in1 * 12299u)); - v_rk3 = ((uint32_t)(v_in3 * 25172u)); - v_rk5 = ((uint32_t)(v_in5 * 16819u)); - v_rk7 = ((uint32_t)(v_in7 * 2446u)); - v_ri51 *= 4294964100u; - v_ri53 *= 4294946301u; - v_ri71 *= 4294959923u; - v_ri73 *= 4294951227u; - v_rl51 = ((uint32_t)(v_ri51 + v_rj)); - v_rl73 = ((uint32_t)(v_ri73 + v_rj)); - v_rk1 += ((uint32_t)(v_ri71 + v_rl51)); - v_rk3 += ((uint32_t)(v_ri53 + v_rl73)); - v_rk5 += ((uint32_t)(v_ri53 + v_rl51)); - v_rk7 += ((uint32_t)(v_ri71 + v_rl73)); - if (8u > ((uint64_t)(a_dst_buffer.len))) { - return wuffs_base__make_empty_struct(); - } - a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 + v_rk1)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[7u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 - v_rk1)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[1u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 + v_rk3)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[6u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 - v_rk3)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[2u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 + v_rk5)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[5u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 - v_rk5)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[3u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 + v_rk7)) + 131072u)) >> 18u) & 1023u)]; - a_dst_buffer.ptr[4u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 - v_rk7)) + 131072u)) >> 18u) & 1023u)]; + + goto suspend; + suspend: + self->private_impl.p_decode_id_part1 = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_data.s_decode_id_part1.v_which_palette = v_which_palette; + self->private_data.s_decode_id_part1.v_num_palette_entries = v_num_palette_entries; + self->private_data.s_decode_id_part1.v_i = v_i; + + goto exit; + exit: + if (a_src && a_src->data.ptr) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); } - return wuffs_base__make_empty_struct(); + + return status; } -// ‼ WUFFS MULTI-FILE SECTION +x86_avx2 -// -------- func jpeg.decoder.decode_idct_x86_avx2 +// -------- func gif.decoder.decode_id_part2 -#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V3) -WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2,avx2") WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_jpeg__decoder__decode_idct_x86_avx2( - wuffs_jpeg__decoder* self, - wuffs_base__slice_u8 a_dst_buffer, - uint64_t a_dst_stride, - uint32_t a_q) { - __m256i v_k_0000 = {0}; - __m256i v_k_8080 = {0}; - __m256i v_k_0000_0002 = {0}; - __m256i v_k_0001_FFFF = {0}; - __m256i v_k_0400_0000 = {0}; - __m256i v_k_29CF_1151_D630_1151 = {0}; - __m256i v_k_E333_133E_ADFD_1051 = {0}; - __m256i v_k_E6DC_25A1_1925_25A1 = {0}; - __m256i v_k_ECC1_E333_EFB0_ADFD = {0}; - __m128i v_az_coeffs = {0}; - __m256i v_az_ah00 = {0}; - __m256i v_az_ad00 = {0}; - __m256i v_az_eh00 = {0}; - __m256i v_az_adeh = {0}; - __m256i v_rows01 = {0}; - __m256i v_rows23 = {0}; - __m256i v_rows45 = {0}; - __m256i v_rows67 = {0}; - __m256i v_quants01 = {0}; - __m256i v_quants23 = {0}; - __m256i v_quants45 = {0}; - __m256i v_quants67 = {0}; - __m256i v_rows04 = {0}; - __m256i v_rows31 = {0}; - __m256i v_rows26 = {0}; - __m256i v_rows75 = {0}; - __m256i v_fp_rows62 = {0}; - __m256i v_fp_bq2662ad = {0}; - __m256i v_fp_bq2662eh = {0}; - __m256i v_fp_cb26ad = {0}; - __m256i v_fp_cb26eh = {0}; - __m256i v_fp_rows40pos = {0}; - __m256i v_fp_rows04neg = {0}; - __m256i v_fp_rows0pm4 = {0}; - __m256i v_fp_ccpmad = {0}; - __m256i v_fp_ccpmeh = {0}; - __m256i v_fp_cd01ad = {0}; - __m256i v_fp_cd01eh = {0}; - __m256i v_fp_cd32ad = {0}; - __m256i v_fp_cd32eh = {0}; - __m256i v_fp_sums7351 = {0}; - __m256i v_fp_sums5173 = {0}; - __m256i v_fp_ci73515173ad = {0}; - __m256i v_fp_ci73515173eh = {0}; - __m256i v_fp_cl7351ad = {0}; - __m256i v_fp_cl7351eh = {0}; - __m256i v_fp_rows13 = {0}; - __m256i v_fp_bq7153ad = {0}; - __m256i v_fp_bq7153eh = {0}; - __m256i v_fp_ck75ad = {0}; - __m256i v_fp_ck75eh = {0}; - __m256i v_fp_cl5173ad = {0}; - __m256i v_fp_cl5173eh = {0}; - __m256i v_fp_ck13ad = {0}; - __m256i v_fp_ck13eh = {0}; - __m256i v_intermediate01ad = {0}; - __m256i v_intermediate01eh = {0}; - __m256i v_intermediate01 = {0}; - __m256i v_intermediate32ad = {0}; - __m256i v_intermediate32eh = {0}; - __m256i v_intermediate32 = {0}; - __m256i v_intermediate45ad = {0}; - __m256i v_intermediate45eh = {0}; - __m256i v_intermediate45 = {0}; - __m256i v_intermediate76ad = {0}; - __m256i v_intermediate76eh = {0}; - __m256i v_intermediate76 = {0}; - __m256i v_ita0a1e0e1 = {0}; - __m256i v_ita2a3e2e3 = {0}; - __m256i v_ita4a5e4e5 = {0}; - __m256i v_ita6a7e6e7 = {0}; - __m256i v_ita0c0e0g0 = {0}; - __m256i v_ita1c1e1g1 = {0}; - __m256i v_ita4c4e4g4 = {0}; - __m256i v_ita5c5e5g5 = {0}; - __m256i v_ita0b0e0f0 = {0}; - __m256i v_ita4b4e4f4 = {0}; - __m256i v_itc0d0g0h0 = {0}; - __m256i v_itc4d4g4h4 = {0}; - __m256i v_intermediateae = {0}; - __m256i v_intermediatebf = {0}; - __m256i v_intermediatecg = {0}; - __m256i v_intermediatedh = {0}; - __m256i v_intermediatedb = {0}; - __m256i v_intermediatehf = {0}; - __m256i v_sp_cols62 = {0}; - __m256i v_sp_bq2662ad = {0}; - __m256i v_sp_bq2662eh = {0}; - __m256i v_sp_rb26ad = {0}; - __m256i v_sp_rb26eh = {0}; - __m256i v_sp_cols40pos = {0}; - __m256i v_sp_cols04neg = {0}; - __m256i v_sp_cols0pm4 = {0}; - __m256i v_sp_rcpmad = {0}; - __m256i v_sp_rcpmeh = {0}; - __m256i v_sp_rd01ad = {0}; - __m256i v_sp_rd01eh = {0}; - __m256i v_sp_rd32ad = {0}; - __m256i v_sp_rd32eh = {0}; - __m256i v_sp_sums7351 = {0}; - __m256i v_sp_sums5173 = {0}; - __m256i v_sp_ri73515173ad = {0}; - __m256i v_sp_ri73515173eh = {0}; - __m256i v_sp_rl7351ad = {0}; - __m256i v_sp_rl7351eh = {0}; - __m256i v_sp_cols13 = {0}; - __m256i v_sp_bq7153ad = {0}; - __m256i v_sp_bq7153eh = {0}; - __m256i v_sp_rk75ad = {0}; - __m256i v_sp_rk75eh = {0}; - __m256i v_sp_rl5173ad = {0}; - __m256i v_sp_rl5173eh = {0}; - __m256i v_sp_rk13ad = {0}; - __m256i v_sp_rk13eh = {0}; - __m256i v_final01ad = {0}; - __m256i v_final01eh = {0}; - __m256i v_final01 = {0}; - __m256i v_final32ad = {0}; - __m256i v_final32eh = {0}; - __m256i v_final32 = {0}; - __m256i v_final45ad = {0}; - __m256i v_final45eh = {0}; - __m256i v_final45 = {0}; - __m256i v_final76ad = {0}; - __m256i v_final76eh = {0}; - __m256i v_final76 = {0}; - __m256i v_fta0a1e0e1 = {0}; - __m256i v_fta2a3e2e3 = {0}; - __m256i v_fta4a5e4e5 = {0}; - __m256i v_fta6a7e6e7 = {0}; - __m256i v_fta0c0e0g0 = {0}; - __m256i v_fta1c1e1g1 = {0}; - __m256i v_fta4c4e4g4 = {0}; - __m256i v_fta5c5e5g5 = {0}; - __m256i v_fta0b0e0f0 = {0}; - __m256i v_ftc0d0g0h0 = {0}; - __m256i v_fta4b4e4f4 = {0}; - __m256i v_ftc4d4g4h4 = {0}; - __m256i v_finalae = {0}; - __m256i v_finalbf = {0}; - __m256i v_finalcg = {0}; - __m256i v_finaldh = {0}; - __m256i v_final0145 = {0}; - __m256i v_final2367 = {0}; - uint64_t v_final0 = 0; - uint64_t v_final1 = 0; - uint64_t v_final2 = 0; - uint64_t v_final3 = 0; - uint64_t v_final4 = 0; - uint64_t v_final5 = 0; - uint64_t v_final6 = 0; - uint64_t v_final7 = 0; - wuffs_base__slice_u8 v_remaining = {0}; +static wuffs_base__status +wuffs_gif__decoder__decode_id_part2( + wuffs_gif__decoder* self, + wuffs_base__pixel_buffer* a_dst, + wuffs_base__io_buffer* a_src, + wuffs_base__slice_u8 a_workbuf) { + wuffs_base__status status = wuffs_base__make_status(NULL); - if (8u > a_dst_stride) { - return wuffs_base__make_empty_struct(); - } - v_k_0000 = _mm256_set_epi16((int16_t)(0u), (int16_t)(0u), (int16_t)(0u), (int16_t)(0u), (int16_t)(0u), (int16_t)(0u), (int16_t)(0u), (int16_t)(0u), (int16_t)(0u), (int16_t)(0u), (int16_t)(0u), (int16_t)(0u), (int16_t)(0u), (int16_t)(0u), (int16_t)(0u), (int16_t)(0u)); - v_k_8080 = _mm256_set_epi16((int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u)); - v_k_0000_0002 = _mm256_set_epi16((int16_t)(2u), (int16_t)(0u), (int16_t)(2u), (int16_t)(0u), (int16_t)(2u), (int16_t)(0u), (int16_t)(2u), (int16_t)(0u), (int16_t)(2u), (int16_t)(0u), (int16_t)(2u), (int16_t)(0u), (int16_t)(2u), (int16_t)(0u), (int16_t)(2u), (int16_t)(0u)); - v_k_0001_FFFF = _mm256_set_epi16((int16_t)(65535u), (int16_t)(65535u), (int16_t)(65535u), (int16_t)(65535u), (int16_t)(65535u), (int16_t)(65535u), (int16_t)(65535u), (int16_t)(65535u), (int16_t)(1u), (int16_t)(1u), (int16_t)(1u), (int16_t)(1u), (int16_t)(1u), (int16_t)(1u), (int16_t)(1u), (int16_t)(1u)); - v_k_0400_0000 = _mm256_set_epi16((int16_t)(0u), (int16_t)(1024u), (int16_t)(0u), (int16_t)(1024u), (int16_t)(0u), (int16_t)(1024u), (int16_t)(0u), (int16_t)(1024u), (int16_t)(0u), (int16_t)(1024u), (int16_t)(0u), (int16_t)(1024u), (int16_t)(0u), (int16_t)(1024u), (int16_t)(0u), (int16_t)(1024u)); - v_k_29CF_1151_D630_1151 = _mm256_set_epi16((int16_t)(4433u), (int16_t)(54832u), (int16_t)(4433u), (int16_t)(54832u), (int16_t)(4433u), (int16_t)(54832u), (int16_t)(4433u), (int16_t)(54832u), (int16_t)(4433u), (int16_t)(10703u), (int16_t)(4433u), (int16_t)(10703u), (int16_t)(4433u), (int16_t)(10703u), (int16_t)(4433u), (int16_t)(10703u)); - v_k_E333_133E_ADFD_1051 = _mm256_set_epi16((int16_t)(4177u), (int16_t)(44541u), (int16_t)(4177u), (int16_t)(44541u), (int16_t)(4177u), (int16_t)(44541u), (int16_t)(4177u), (int16_t)(44541u), (int16_t)(4926u), (int16_t)(58163u), (int16_t)(4926u), (int16_t)(58163u), (int16_t)(4926u), (int16_t)(58163u), (int16_t)(4926u), (int16_t)(58163u)); - v_k_E6DC_25A1_1925_25A1 = _mm256_set_epi16((int16_t)(9633u), (int16_t)(6437u), (int16_t)(9633u), (int16_t)(6437u), (int16_t)(9633u), (int16_t)(6437u), (int16_t)(9633u), (int16_t)(6437u), (int16_t)(9633u), (int16_t)(59100u), (int16_t)(9633u), (int16_t)(59100u), (int16_t)(9633u), (int16_t)(59100u), (int16_t)(9633u), (int16_t)(59100u)); - v_k_ECC1_E333_EFB0_ADFD = _mm256_set_epi16((int16_t)(44541u), (int16_t)(61360u), (int16_t)(44541u), (int16_t)(61360u), (int16_t)(44541u), (int16_t)(61360u), (int16_t)(44541u), (int16_t)(61360u), (int16_t)(58163u), (int16_t)(60609u), (int16_t)(58163u), (int16_t)(60609u), (int16_t)(58163u), (int16_t)(60609u), (int16_t)(58163u), (int16_t)(60609u)); - do { - if (0u == (wuffs_base__peek_u64le__no_bounds_check((const uint8_t*)(const void*)(self->private_data.f_mcu_blocks[0u] + 8u)) | wuffs_base__peek_u64le__no_bounds_check((const uint8_t*)(const void*)(self->private_data.f_mcu_blocks[0u] + 16u)))) { - v_az_coeffs = _mm_or_si128(_mm_or_si128(_mm_or_si128(_mm_or_si128(_mm_or_si128(_mm_or_si128(_mm_lddqu_si128((const __m128i*)(const void*)(self->private_data.f_mcu_blocks[0u] + 8u)), _mm_lddqu_si128((const __m128i*)(const void*)(self->private_data.f_mcu_blocks[0u] + 16u))), _mm_lddqu_si128((const __m128i*)(const void*)(self->private_data.f_mcu_blocks[0u] + 24u))), _mm_lddqu_si128((const __m128i*)(const void*)(self->private_data.f_mcu_blocks[0u] + 32u))), _mm_lddqu_si128((const __m128i*)(const void*)(self->private_data.f_mcu_blocks[0u] + 40u))), _mm_lddqu_si128((const __m128i*)(const void*)(self->private_data.f_mcu_blocks[0u] + 48u))), _mm_lddqu_si128((const __m128i*)(const void*)(self->private_data.f_mcu_blocks[0u] + 56u))); - if (0u == ((uint64_t)(_mm_cvtsi128_si64(_mm_packs_epi16(v_az_coeffs, v_az_coeffs))))) { - v_rows01 = _mm256_lddqu_si256((const __m256i*)(const void*)(self->private_data.f_mcu_blocks[0u] + 0u)); - v_quants01 = _mm256_lddqu_si256((const __m256i*)(const void*)(self->private_impl.f_quant_tables[a_q] + 0u)); - v_rows01 = _mm256_mullo_epi16(v_rows01, v_quants01); - v_az_ah00 = _mm256_slli_epi16(v_rows01, (int32_t)(2u)); - v_az_ad00 = _mm256_unpacklo_epi16(v_az_ah00, v_az_ah00); - v_az_eh00 = _mm256_unpackhi_epi16(v_az_ah00, v_az_ah00); - v_az_adeh = _mm256_inserti128_si256(v_az_ad00, _mm256_castsi256_si128(v_az_eh00), (int32_t)(1u)); - v_intermediateae = _mm256_shuffle_epi32(v_az_adeh, (int32_t)(0u)); - v_intermediatebf = _mm256_shuffle_epi32(v_az_adeh, (int32_t)(85u)); - v_intermediatecg = _mm256_shuffle_epi32(v_az_adeh, (int32_t)(170u)); - v_intermediatedh = _mm256_shuffle_epi32(v_az_adeh, (int32_t)(255u)); - break; - } - } - v_rows01 = _mm256_lddqu_si256((const __m256i*)(const void*)(self->private_data.f_mcu_blocks[0u] + 0u)); - v_rows23 = _mm256_lddqu_si256((const __m256i*)(const void*)(self->private_data.f_mcu_blocks[0u] + 16u)); - v_rows45 = _mm256_lddqu_si256((const __m256i*)(const void*)(self->private_data.f_mcu_blocks[0u] + 32u)); - v_rows67 = _mm256_lddqu_si256((const __m256i*)(const void*)(self->private_data.f_mcu_blocks[0u] + 48u)); - v_quants01 = _mm256_lddqu_si256((const __m256i*)(const void*)(self->private_impl.f_quant_tables[a_q] + 0u)); - v_quants23 = _mm256_lddqu_si256((const __m256i*)(const void*)(self->private_impl.f_quant_tables[a_q] + 16u)); - v_quants45 = _mm256_lddqu_si256((const __m256i*)(const void*)(self->private_impl.f_quant_tables[a_q] + 32u)); - v_quants67 = _mm256_lddqu_si256((const __m256i*)(const void*)(self->private_impl.f_quant_tables[a_q] + 48u)); - v_rows01 = _mm256_mullo_epi16(v_rows01, v_quants01); - v_rows23 = _mm256_mullo_epi16(v_rows23, v_quants23); - v_rows45 = _mm256_mullo_epi16(v_rows45, v_quants45); - v_rows67 = _mm256_mullo_epi16(v_rows67, v_quants67); - v_rows04 = _mm256_permute2x128_si256(v_rows01, v_rows45, (int32_t)(32u)); - v_rows31 = _mm256_permute2x128_si256(v_rows23, v_rows01, (int32_t)(49u)); - v_rows26 = _mm256_permute2x128_si256(v_rows23, v_rows67, (int32_t)(32u)); - v_rows75 = _mm256_permute2x128_si256(v_rows67, v_rows45, (int32_t)(49u)); - v_fp_rows62 = _mm256_permute2x128_si256(v_rows26, v_rows26, (int32_t)(1u)); - v_fp_bq2662ad = _mm256_unpacklo_epi16(v_rows26, v_fp_rows62); - v_fp_bq2662eh = _mm256_unpackhi_epi16(v_rows26, v_fp_rows62); - v_fp_cb26ad = _mm256_madd_epi16(v_fp_bq2662ad, v_k_29CF_1151_D630_1151); - v_fp_cb26eh = _mm256_madd_epi16(v_fp_bq2662eh, v_k_29CF_1151_D630_1151); - v_fp_rows40pos = _mm256_permute2x128_si256(v_rows04, v_rows04, (int32_t)(1u)); - v_fp_rows04neg = _mm256_sign_epi16(v_rows04, v_k_0001_FFFF); - v_fp_rows0pm4 = _mm256_add_epi16(v_fp_rows40pos, v_fp_rows04neg); - v_fp_ccpmad = _mm256_srai_epi32(_mm256_unpacklo_epi16(v_k_0000, v_fp_rows0pm4), (int32_t)(3u)); - v_fp_ccpmeh = _mm256_srai_epi32(_mm256_unpackhi_epi16(v_k_0000, v_fp_rows0pm4), (int32_t)(3u)); - v_fp_cd01ad = _mm256_add_epi32(v_fp_ccpmad, v_fp_cb26ad); - v_fp_cd01eh = _mm256_add_epi32(v_fp_ccpmeh, v_fp_cb26eh); - v_fp_cd32ad = _mm256_sub_epi32(v_fp_ccpmad, v_fp_cb26ad); - v_fp_cd32eh = _mm256_sub_epi32(v_fp_ccpmeh, v_fp_cb26eh); - v_fp_sums7351 = _mm256_add_epi16(v_rows75, v_rows31); - v_fp_sums5173 = _mm256_permute2x128_si256(v_fp_sums7351, v_fp_sums7351, (int32_t)(1u)); - v_fp_ci73515173ad = _mm256_unpacklo_epi16(v_fp_sums7351, v_fp_sums5173); - v_fp_ci73515173eh = _mm256_unpackhi_epi16(v_fp_sums7351, v_fp_sums5173); - v_fp_cl7351ad = _mm256_madd_epi16(v_fp_ci73515173ad, v_k_E6DC_25A1_1925_25A1); - v_fp_cl7351eh = _mm256_madd_epi16(v_fp_ci73515173eh, v_k_E6DC_25A1_1925_25A1); - v_fp_rows13 = _mm256_permute2x128_si256(v_rows31, v_rows31, (int32_t)(1u)); - v_fp_bq7153ad = _mm256_unpacklo_epi16(v_rows75, v_fp_rows13); - v_fp_bq7153eh = _mm256_unpackhi_epi16(v_rows75, v_fp_rows13); - v_fp_ck75ad = _mm256_add_epi32(_mm256_madd_epi16(v_fp_bq7153ad, v_k_ECC1_E333_EFB0_ADFD), v_fp_cl7351ad); - v_fp_ck75eh = _mm256_add_epi32(_mm256_madd_epi16(v_fp_bq7153eh, v_k_ECC1_E333_EFB0_ADFD), v_fp_cl7351eh); - v_fp_cl5173ad = _mm256_permute2x128_si256(v_fp_cl7351ad, v_fp_cl7351ad, (int32_t)(1u)); - v_fp_cl5173eh = _mm256_permute2x128_si256(v_fp_cl7351eh, v_fp_cl7351eh, (int32_t)(1u)); - v_fp_ck13ad = _mm256_add_epi32(v_fp_cl5173ad, _mm256_madd_epi16(v_fp_bq7153ad, v_k_E333_133E_ADFD_1051)); - v_fp_ck13eh = _mm256_add_epi32(v_fp_cl5173eh, _mm256_madd_epi16(v_fp_bq7153eh, v_k_E333_133E_ADFD_1051)); - v_intermediate01ad = _mm256_srai_epi32(_mm256_add_epi32(_mm256_add_epi32(v_fp_cd01ad, v_fp_ck13ad), v_k_0400_0000), (int32_t)(11u)); - v_intermediate01eh = _mm256_srai_epi32(_mm256_add_epi32(_mm256_add_epi32(v_fp_cd01eh, v_fp_ck13eh), v_k_0400_0000), (int32_t)(11u)); - v_intermediate01 = _mm256_packs_epi32(v_intermediate01ad, v_intermediate01eh); - v_intermediate32ad = _mm256_srai_epi32(_mm256_add_epi32(_mm256_add_epi32(v_fp_cd32ad, v_fp_ck75ad), v_k_0400_0000), (int32_t)(11u)); - v_intermediate32eh = _mm256_srai_epi32(_mm256_add_epi32(_mm256_add_epi32(v_fp_cd32eh, v_fp_ck75eh), v_k_0400_0000), (int32_t)(11u)); - v_intermediate32 = _mm256_packs_epi32(v_intermediate32ad, v_intermediate32eh); - v_intermediate45ad = _mm256_srai_epi32(_mm256_add_epi32(_mm256_sub_epi32(v_fp_cd32ad, v_fp_ck75ad), v_k_0400_0000), (int32_t)(11u)); - v_intermediate45eh = _mm256_srai_epi32(_mm256_add_epi32(_mm256_sub_epi32(v_fp_cd32eh, v_fp_ck75eh), v_k_0400_0000), (int32_t)(11u)); - v_intermediate45 = _mm256_packs_epi32(v_intermediate45ad, v_intermediate45eh); - v_intermediate76ad = _mm256_srai_epi32(_mm256_add_epi32(_mm256_sub_epi32(v_fp_cd01ad, v_fp_ck13ad), v_k_0400_0000), (int32_t)(11u)); - v_intermediate76eh = _mm256_srai_epi32(_mm256_add_epi32(_mm256_sub_epi32(v_fp_cd01eh, v_fp_ck13eh), v_k_0400_0000), (int32_t)(11u)); - v_intermediate76 = _mm256_packs_epi32(v_intermediate76ad, v_intermediate76eh); - v_ita0a1e0e1 = _mm256_permute4x64_epi64(v_intermediate01, (int32_t)(216u)); - v_ita2a3e2e3 = _mm256_permute4x64_epi64(v_intermediate32, (int32_t)(114u)); - v_ita4a5e4e5 = _mm256_permute4x64_epi64(v_intermediate45, (int32_t)(216u)); - v_ita6a7e6e7 = _mm256_permute4x64_epi64(v_intermediate76, (int32_t)(114u)); - v_ita0c0e0g0 = _mm256_unpacklo_epi16(v_ita0a1e0e1, v_ita2a3e2e3); - v_ita1c1e1g1 = _mm256_unpackhi_epi16(v_ita0a1e0e1, v_ita2a3e2e3); - v_ita4c4e4g4 = _mm256_unpacklo_epi16(v_ita4a5e4e5, v_ita6a7e6e7); - v_ita5c5e5g5 = _mm256_unpackhi_epi16(v_ita4a5e4e5, v_ita6a7e6e7); - v_ita0b0e0f0 = _mm256_unpacklo_epi16(v_ita0c0e0g0, v_ita1c1e1g1); - v_itc0d0g0h0 = _mm256_unpackhi_epi16(v_ita0c0e0g0, v_ita1c1e1g1); - v_ita4b4e4f4 = _mm256_unpacklo_epi16(v_ita4c4e4g4, v_ita5c5e5g5); - v_itc4d4g4h4 = _mm256_unpackhi_epi16(v_ita4c4e4g4, v_ita5c5e5g5); - v_intermediateae = _mm256_unpacklo_epi64(v_ita0b0e0f0, v_ita4b4e4f4); - v_intermediatebf = _mm256_unpackhi_epi64(v_ita0b0e0f0, v_ita4b4e4f4); - v_intermediatecg = _mm256_unpacklo_epi64(v_itc0d0g0h0, v_itc4d4g4h4); - v_intermediatedh = _mm256_unpackhi_epi64(v_itc0d0g0h0, v_itc4d4g4h4); - } while (0); - v_intermediatedb = _mm256_permute2x128_si256(v_intermediatedh, v_intermediatebf, (int32_t)(32u)); - v_intermediatehf = _mm256_permute2x128_si256(v_intermediatedh, v_intermediatebf, (int32_t)(49u)); - v_sp_cols62 = _mm256_permute2x128_si256(v_intermediatecg, v_intermediatecg, (int32_t)(1u)); - v_sp_bq2662ad = _mm256_unpacklo_epi16(v_intermediatecg, v_sp_cols62); - v_sp_bq2662eh = _mm256_unpackhi_epi16(v_intermediatecg, v_sp_cols62); - v_sp_rb26ad = _mm256_madd_epi16(v_sp_bq2662ad, v_k_29CF_1151_D630_1151); - v_sp_rb26eh = _mm256_madd_epi16(v_sp_bq2662eh, v_k_29CF_1151_D630_1151); - v_sp_cols40pos = _mm256_permute2x128_si256(v_intermediateae, v_intermediateae, (int32_t)(1u)); - v_sp_cols04neg = _mm256_sign_epi16(v_intermediateae, v_k_0001_FFFF); - v_sp_cols0pm4 = _mm256_add_epi16(v_sp_cols40pos, v_sp_cols04neg); - v_sp_rcpmad = _mm256_srai_epi32(_mm256_unpacklo_epi16(v_k_0000, v_sp_cols0pm4), (int32_t)(3u)); - v_sp_rcpmeh = _mm256_srai_epi32(_mm256_unpackhi_epi16(v_k_0000, v_sp_cols0pm4), (int32_t)(3u)); - v_sp_rd01ad = _mm256_add_epi32(v_sp_rcpmad, v_sp_rb26ad); - v_sp_rd01eh = _mm256_add_epi32(v_sp_rcpmeh, v_sp_rb26eh); - v_sp_rd32ad = _mm256_sub_epi32(v_sp_rcpmad, v_sp_rb26ad); - v_sp_rd32eh = _mm256_sub_epi32(v_sp_rcpmeh, v_sp_rb26eh); - v_sp_sums7351 = _mm256_add_epi16(v_intermediatehf, v_intermediatedb); - v_sp_sums5173 = _mm256_permute2x128_si256(v_sp_sums7351, v_sp_sums7351, (int32_t)(1u)); - v_sp_ri73515173ad = _mm256_unpacklo_epi16(v_sp_sums7351, v_sp_sums5173); - v_sp_ri73515173eh = _mm256_unpackhi_epi16(v_sp_sums7351, v_sp_sums5173); - v_sp_rl7351ad = _mm256_madd_epi16(v_sp_ri73515173ad, v_k_E6DC_25A1_1925_25A1); - v_sp_rl7351eh = _mm256_madd_epi16(v_sp_ri73515173eh, v_k_E6DC_25A1_1925_25A1); - v_sp_cols13 = _mm256_permute2x128_si256(v_intermediatedb, v_intermediatedb, (int32_t)(1u)); - v_sp_bq7153ad = _mm256_unpacklo_epi16(v_intermediatehf, v_sp_cols13); - v_sp_bq7153eh = _mm256_unpackhi_epi16(v_intermediatehf, v_sp_cols13); - v_sp_rk75ad = _mm256_add_epi32(_mm256_madd_epi16(v_sp_bq7153ad, v_k_ECC1_E333_EFB0_ADFD), v_sp_rl7351ad); - v_sp_rk75eh = _mm256_add_epi32(_mm256_madd_epi16(v_sp_bq7153eh, v_k_ECC1_E333_EFB0_ADFD), v_sp_rl7351eh); - v_sp_rl5173ad = _mm256_permute2x128_si256(v_sp_rl7351ad, v_sp_rl7351ad, (int32_t)(1u)); - v_sp_rl5173eh = _mm256_permute2x128_si256(v_sp_rl7351eh, v_sp_rl7351eh, (int32_t)(1u)); - v_sp_rk13ad = _mm256_add_epi32(v_sp_rl5173ad, _mm256_madd_epi16(v_sp_bq7153ad, v_k_E333_133E_ADFD_1051)); - v_sp_rk13eh = _mm256_add_epi32(v_sp_rl5173eh, _mm256_madd_epi16(v_sp_bq7153eh, v_k_E333_133E_ADFD_1051)); - v_final01ad = _mm256_srai_epi32(_mm256_add_epi32(_mm256_add_epi32(v_sp_rd01ad, v_sp_rk13ad), v_k_0000_0002), (int32_t)(18u)); - v_final01eh = _mm256_srai_epi32(_mm256_add_epi32(_mm256_add_epi32(v_sp_rd01eh, v_sp_rk13eh), v_k_0000_0002), (int32_t)(18u)); - v_final01 = _mm256_packs_epi32(v_final01ad, v_final01eh); - v_final32ad = _mm256_srai_epi32(_mm256_add_epi32(_mm256_add_epi32(v_sp_rd32ad, v_sp_rk75ad), v_k_0000_0002), (int32_t)(18u)); - v_final32eh = _mm256_srai_epi32(_mm256_add_epi32(_mm256_add_epi32(v_sp_rd32eh, v_sp_rk75eh), v_k_0000_0002), (int32_t)(18u)); - v_final32 = _mm256_packs_epi32(v_final32ad, v_final32eh); - v_final45ad = _mm256_srai_epi32(_mm256_add_epi32(_mm256_sub_epi32(v_sp_rd32ad, v_sp_rk75ad), v_k_0000_0002), (int32_t)(18u)); - v_final45eh = _mm256_srai_epi32(_mm256_add_epi32(_mm256_sub_epi32(v_sp_rd32eh, v_sp_rk75eh), v_k_0000_0002), (int32_t)(18u)); - v_final45 = _mm256_packs_epi32(v_final45ad, v_final45eh); - v_final76ad = _mm256_srai_epi32(_mm256_add_epi32(_mm256_sub_epi32(v_sp_rd01ad, v_sp_rk13ad), v_k_0000_0002), (int32_t)(18u)); - v_final76eh = _mm256_srai_epi32(_mm256_add_epi32(_mm256_sub_epi32(v_sp_rd01eh, v_sp_rk13eh), v_k_0000_0002), (int32_t)(18u)); - v_final76 = _mm256_packs_epi32(v_final76ad, v_final76eh); - v_fta0a1e0e1 = _mm256_permute4x64_epi64(v_final01, (int32_t)(216u)); - v_fta2a3e2e3 = _mm256_permute4x64_epi64(v_final32, (int32_t)(114u)); - v_fta4a5e4e5 = _mm256_permute4x64_epi64(v_final45, (int32_t)(216u)); - v_fta6a7e6e7 = _mm256_permute4x64_epi64(v_final76, (int32_t)(114u)); - v_fta0c0e0g0 = _mm256_unpacklo_epi16(v_fta0a1e0e1, v_fta2a3e2e3); - v_fta1c1e1g1 = _mm256_unpackhi_epi16(v_fta0a1e0e1, v_fta2a3e2e3); - v_fta4c4e4g4 = _mm256_unpacklo_epi16(v_fta4a5e4e5, v_fta6a7e6e7); - v_fta5c5e5g5 = _mm256_unpackhi_epi16(v_fta4a5e4e5, v_fta6a7e6e7); - v_fta0b0e0f0 = _mm256_unpacklo_epi16(v_fta0c0e0g0, v_fta1c1e1g1); - v_ftc0d0g0h0 = _mm256_unpackhi_epi16(v_fta0c0e0g0, v_fta1c1e1g1); - v_fta4b4e4f4 = _mm256_unpacklo_epi16(v_fta4c4e4g4, v_fta5c5e5g5); - v_ftc4d4g4h4 = _mm256_unpackhi_epi16(v_fta4c4e4g4, v_fta5c5e5g5); - v_finalae = _mm256_unpacklo_epi64(v_fta0b0e0f0, v_fta4b4e4f4); - v_finalbf = _mm256_unpackhi_epi64(v_fta0b0e0f0, v_fta4b4e4f4); - v_finalcg = _mm256_unpacklo_epi64(v_ftc0d0g0h0, v_ftc4d4g4h4); - v_finaldh = _mm256_unpackhi_epi64(v_ftc0d0g0h0, v_ftc4d4g4h4); - v_final0145 = _mm256_add_epi8(_mm256_packs_epi16(v_finalae, v_finalbf), v_k_8080); - v_final2367 = _mm256_add_epi8(_mm256_packs_epi16(v_finalcg, v_finaldh), v_k_8080); - v_final0 = ((uint64_t)(_mm256_extract_epi64(v_final0145, (int32_t)(0u)))); - v_final1 = ((uint64_t)(_mm256_extract_epi64(v_final0145, (int32_t)(1u)))); - v_final2 = ((uint64_t)(_mm256_extract_epi64(v_final2367, (int32_t)(0u)))); - v_final3 = ((uint64_t)(_mm256_extract_epi64(v_final2367, (int32_t)(1u)))); - v_final4 = ((uint64_t)(_mm256_extract_epi64(v_final0145, (int32_t)(2u)))); - v_final5 = ((uint64_t)(_mm256_extract_epi64(v_final0145, (int32_t)(3u)))); - v_final6 = ((uint64_t)(_mm256_extract_epi64(v_final2367, (int32_t)(2u)))); - v_final7 = ((uint64_t)(_mm256_extract_epi64(v_final2367, (int32_t)(3u)))); - if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { - return wuffs_base__make_empty_struct(); - } - v_remaining = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); - wuffs_base__poke_u64le__no_bounds_check(a_dst_buffer.ptr, v_final0); - a_dst_buffer = v_remaining; - if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { - return wuffs_base__make_empty_struct(); - } - v_remaining = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); - wuffs_base__poke_u64le__no_bounds_check(a_dst_buffer.ptr, v_final1); - a_dst_buffer = v_remaining; - if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { - return wuffs_base__make_empty_struct(); - } - v_remaining = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); - wuffs_base__poke_u64le__no_bounds_check(a_dst_buffer.ptr, v_final2); - a_dst_buffer = v_remaining; - if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { - return wuffs_base__make_empty_struct(); - } - v_remaining = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); - wuffs_base__poke_u64le__no_bounds_check(a_dst_buffer.ptr, v_final3); - a_dst_buffer = v_remaining; - if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { - return wuffs_base__make_empty_struct(); - } - v_remaining = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); - wuffs_base__poke_u64le__no_bounds_check(a_dst_buffer.ptr, v_final4); - a_dst_buffer = v_remaining; - if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { - return wuffs_base__make_empty_struct(); - } - v_remaining = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); - wuffs_base__poke_u64le__no_bounds_check(a_dst_buffer.ptr, v_final5); - a_dst_buffer = v_remaining; - if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { - return wuffs_base__make_empty_struct(); - } - v_remaining = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); - wuffs_base__poke_u64le__no_bounds_check(a_dst_buffer.ptr, v_final6); - a_dst_buffer = v_remaining; - if (8u > ((uint64_t)(a_dst_buffer.len))) { - return wuffs_base__make_empty_struct(); - } - wuffs_base__poke_u64le__no_bounds_check(a_dst_buffer.ptr, v_final7); - return wuffs_base__make_empty_struct(); -} -#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V3) -// ‼ WUFFS MULTI-FILE SECTION -x86_avx2 - -// -------- func jpeg.decoder.get_quirk - -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC uint64_t -wuffs_jpeg__decoder__get_quirk( - const wuffs_jpeg__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; - } - - if (a_key == 2u) { - if (self->private_impl.f_use_lower_quality) { - return 18446744073709551615u; - } - } else if (a_key == 1220532224u) { - if (self->private_impl.f_reject_progressive_jpegs) { - return 1u; - } - } - return 0u; -} - -// -------- func jpeg.decoder.set_quirk - -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_jpeg__decoder__set_quirk( - wuffs_jpeg__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); - } - - if (a_key == 2u) { - self->private_impl.f_use_lower_quality = (a_value >= 9223372036854775808u); - return wuffs_base__make_status(NULL); - } else if (a_key == 1220532224u) { - self->private_impl.f_reject_progressive_jpegs = (a_value != 0u); - return wuffs_base__make_status(NULL); - } - return wuffs_base__make_status(wuffs_base__error__unsupported_option); -} - -// -------- func jpeg.decoder.decode_image_config - -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_jpeg__decoder__decode_image_config( - wuffs_jpeg__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_jpeg__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_jpeg__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 jpeg.decoder.do_decode_image_config - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_jpeg__decoder__do_decode_image_config( - wuffs_jpeg__decoder* self, - wuffs_base__image_config* a_dst, - wuffs_base__io_buffer* a_src) { - wuffs_base__status status = wuffs_base__make_status(NULL); - - uint8_t v_c8 = 0; - uint8_t v_marker = 0; - uint32_t v_pixfmt = 0; + uint64_t v_block_size = 0; + bool v_need_block_size = false; + uint32_t v_n_copied = 0; + uint64_t v_n_compressed = 0; + wuffs_base__io_buffer u_r = wuffs_base__empty_io_buffer(); + wuffs_base__io_buffer* v_r = &u_r; + const uint8_t* iop_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + const uint8_t* io0_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + const uint8_t* io1_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + const uint8_t* io2_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + uint64_t v_mark = 0; + wuffs_base__status v_copy_status = wuffs_base__make_status(NULL); const uint8_t* iop_a_src = NULL; const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL; @@ -46590,256 +46813,185 @@ wuffs_jpeg__decoder__do_decode_image_config( io2_a_src = io0_a_src + a_src->meta.wi; } - uint32_t coro_susp_point = self->private_impl.p_do_decode_image_config; + uint32_t coro_susp_point = self->private_impl.p_decode_id_part2; if (coro_susp_point) { - v_marker = self->private_data.s_do_decode_image_config.v_marker; + v_block_size = self->private_data.s_decode_id_part2.v_block_size; + v_need_block_size = self->private_data.s_decode_id_part2.v_need_block_size; } 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); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_0 = *iop_a_src++; - v_c8 = t_0; - } - if (v_c8 != 255u) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_header); - goto exit; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_1 = *iop_a_src++; - v_c8 = t_1; - } - if (v_c8 != 216u) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_header); - goto exit; - } + wuffs_gif__decoder__lzw_init(self); + v_need_block_size = true; + label__outer__continue:; while (true) { - while (true) { + if (v_need_block_size) { + v_need_block_size = false; { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { status = wuffs_base__make_status(wuffs_base__suspension__short_read); goto suspend; } - uint8_t t_2 = *iop_a_src++; - v_c8 = t_2; + uint64_t t_0 = *iop_a_src++; + v_block_size = t_0; } - if (v_c8 == 255u) { + } + if (v_block_size == 0u) { + break; + } + while (((uint64_t)(io2_a_src - iop_a_src)) == 0u) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2); + } + if (self->private_impl.f_compressed_ri == self->private_impl.f_compressed_wi) { + self->private_impl.f_compressed_ri = 0u; + self->private_impl.f_compressed_wi = 0u; + } + while (self->private_impl.f_compressed_wi <= 3841u) { + v_n_compressed = wuffs_base__u64__min(v_block_size, ((uint64_t)(io2_a_src - iop_a_src))); + if (v_n_compressed <= 0u) { break; } - } - while (true) { - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_3 = *iop_a_src++; - v_c8 = t_3; + v_n_copied = wuffs_private_impl__io_reader__limited_copy_u32_to_slice( + &iop_a_src, io2_a_src,((uint32_t)(v_n_compressed)), wuffs_base__make_slice_u8_ij(self->private_data.f_compressed, self->private_impl.f_compressed_wi, 4096)); + wuffs_private_impl__u64__sat_add_indirect(&self->private_impl.f_compressed_wi, ((uint64_t)(v_n_copied))); + wuffs_private_impl__u64__sat_sub_indirect(&v_block_size, ((uint64_t)(v_n_copied))); + if (v_block_size > 0u) { + break; } - if (v_c8 != 255u) { - v_marker = v_c8; + if (((uint64_t)(io2_a_src - iop_a_src)) <= 0u) { + v_need_block_size = true; break; } + v_block_size = ((uint64_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))); + iop_a_src += 1u; } - if (v_marker == 0u) { - continue; - } else if ((208u <= v_marker) && (v_marker <= 217u)) { - if (v_marker <= 215u) { - continue; + while (true) { + if ((self->private_impl.f_compressed_ri > self->private_impl.f_compressed_wi) || (self->private_impl.f_compressed_wi > 4096u)) { + status = wuffs_base__make_status(wuffs_gif__error__internal_error_inconsistent_i_o); + goto exit; } - } else { { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); - uint32_t t_4; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { - t_4 = ((uint32_t)(wuffs_base__peek_u16be__no_bounds_check(iop_a_src))); - iop_a_src += 2; - } else { - self->private_data.s_do_decode_image_config.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); - 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_4 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_4); - if (num_bits_4 == 8) { - t_4 = ((uint32_t)(*scratch >> 48)); - break; - } - num_bits_4 += 8u; - *scratch |= ((uint64_t)(num_bits_4)); - } - } - self->private_impl.f_payload_length = t_4; + wuffs_base__io_buffer* o_0_v_r = v_r; + const uint8_t* o_0_iop_v_r = iop_v_r; + const uint8_t* o_0_io0_v_r = io0_v_r; + const uint8_t* o_0_io1_v_r = io1_v_r; + const uint8_t* o_0_io2_v_r = io2_v_r; + v_r = wuffs_private_impl__io_reader__set( + &u_r, + &iop_v_r, + &io0_v_r, + &io1_v_r, + &io2_v_r, + wuffs_base__make_slice_u8_ij(self->private_data.f_compressed, + self->private_impl.f_compressed_ri, + self->private_impl.f_compressed_wi), + 0u); + v_mark = ((uint64_t)(iop_v_r - io0_v_r)); + u_r.meta.ri = ((size_t)(iop_v_r - u_r.data.ptr)); + wuffs_gif__decoder__lzw_read_from(self, v_r); + iop_v_r = u_r.data.ptr + u_r.meta.ri; + wuffs_private_impl__u64__sat_add_indirect(&self->private_impl.f_compressed_ri, wuffs_private_impl__io__count_since(v_mark, ((uint64_t)(iop_v_r - io0_v_r)))); + v_r = o_0_v_r; + iop_v_r = o_0_iop_v_r; + io0_v_r = o_0_io0_v_r; + io1_v_r = o_0_io1_v_r; + io2_v_r = o_0_io2_v_r; } - if (self->private_impl.f_payload_length < 2u) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_marker); - goto exit; + if (self->private_impl.f_lzw_output_ri < self->private_impl.f_lzw_output_wi) { + v_copy_status = wuffs_gif__decoder__copy_to_image_buffer(self, a_dst, wuffs_base__make_slice_u8_ij(self->private_data.f_lzw_output, + self->private_impl.f_lzw_output_ri, + self->private_impl.f_lzw_output_wi)); + if (wuffs_base__status__is_error(&v_copy_status)) { + status = v_copy_status; + goto exit; + } + self->private_impl.f_lzw_output_ri = 0u; + self->private_impl.f_lzw_output_wi = 0u; } - self->private_impl.f_payload_length -= 2u; - } - if (v_marker < 192u) { - status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_marker); - goto exit; - } else if (v_marker < 208u) { - if (v_marker <= 194u) { - if ((v_marker == 194u) && self->private_impl.f_reject_progressive_jpegs) { - status = wuffs_base__make_status(wuffs_jpeg__error__rejected_progressive_jpeg); - goto exit; - } else if (self->private_impl.f_sof_marker != 0u) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_sof_marker); - goto exit; - } - self->private_impl.f_sof_marker = v_marker; - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); - status = wuffs_jpeg__decoder__decode_sof(self, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; - } - break; - } else if (v_marker == 195u) { - status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_lossless_coding); - goto exit; - } else if (v_marker == 196u) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_dht_marker); - goto exit; - } else if ((197u <= v_marker) && (v_marker <= 199u)) { - status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_hierarchical_coding); - goto exit; - } else if (v_marker == 200u) { - status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_marker); - goto exit; - } else { - status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_arithmetic_coding); - goto exit; - } - } else if (v_marker < 224u) { - if (v_marker < 218u) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_marker); - goto exit; - } else if (v_marker == 218u) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); - goto exit; - } else if (v_marker == 219u) { - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); - status = wuffs_jpeg__decoder__decode_dqt(self, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; + if (self->private_impl.f_lzw_read_from_return_value == 0u) { + self->private_impl.f_ignored_but_affects_benchmarks = false; + if (v_need_block_size || (v_block_size > 0u)) { + self->private_data.s_decode_id_part2.scratch = ((uint32_t)(v_block_size)); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + if (self->private_data.s_decode_id_part2.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { + self->private_data.s_decode_id_part2.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); + iop_a_src = io2_a_src; + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + iop_a_src += self->private_data.s_decode_id_part2.scratch; + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + status = wuffs_gif__decoder__skip_blocks(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } } + goto label__outer__break; + } else if (self->private_impl.f_lzw_read_from_return_value == 1u) { continue; - } else if (v_marker == 221u) { - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); - status = wuffs_jpeg__decoder__decode_dri(self, 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_lzw_read_from_return_value == 2u) { + goto label__outer__continue; + } else if (self->private_impl.f_quirks[3u] && (self->private_impl.f_dst_y >= self->private_impl.f_frame_rect_y1) && (self->private_impl.f_interlace == 0u)) { + if (v_need_block_size || (v_block_size > 0u)) { + self->private_data.s_decode_id_part2.scratch = ((uint32_t)(v_block_size)); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); + if (self->private_data.s_decode_id_part2.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { + self->private_data.s_decode_id_part2.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); + iop_a_src = io2_a_src; + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + iop_a_src += self->private_data.s_decode_id_part2.scratch; + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); + status = wuffs_gif__decoder__skip_blocks(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } } - continue; - } else { - status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_marker); + goto label__outer__break; + } else if (self->private_impl.f_lzw_read_from_return_value == 3u) { + status = wuffs_base__make_status(wuffs_gif__error__truncated_input); goto exit; - } - } else if (v_marker < 240u) { - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10); - status = wuffs_jpeg__decoder__decode_appn(self, a_src, v_marker); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; - } - continue; - } else { - if (v_marker == 254u) { - } else { - status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_marker); + } else if (self->private_impl.f_lzw_read_from_return_value == 4u) { + status = wuffs_base__make_status(wuffs_gif__error__bad_lzw_code); goto exit; } + status = wuffs_base__make_status(wuffs_gif__error__internal_error_inconsistent_i_o); + goto exit; } - self->private_data.s_do_decode_image_config.scratch = self->private_impl.f_payload_length; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11); - if (self->private_data.s_do_decode_image_config.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { - self->private_data.s_do_decode_image_config.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); - iop_a_src = io2_a_src; - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - iop_a_src += self->private_data.s_do_decode_image_config.scratch; - self->private_impl.f_payload_length = 0u; } - self->private_impl.choosy_decode_idct = ( -#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V3) - wuffs_base__cpu_arch__have_x86_avx2() ? &wuffs_jpeg__decoder__decode_idct_x86_avx2 : -#endif - self->private_impl.choosy_decode_idct); - self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))); - if (a_dst != NULL) { - v_pixfmt = 536870920u; - if (self->private_impl.f_num_components > 1u) { - v_pixfmt = 2415954056u; - } - wuffs_base__image_config__set( - a_dst, - v_pixfmt, - 0u, - self->private_impl.f_width, - self->private_impl.f_height, - self->private_impl.f_frame_config_io_position, - true); + label__outer__break:; + self->private_impl.f_compressed_ri = 0u; + self->private_impl.f_compressed_wi = 0u; + if ((self->private_impl.f_dst_y < self->private_impl.f_frame_rect_y1) && (self->private_impl.f_frame_rect_x0 != self->private_impl.f_frame_rect_x1) && (self->private_impl.f_frame_rect_y0 != self->private_impl.f_frame_rect_y1)) { + status = wuffs_base__make_status(wuffs_base__error__not_enough_data); + goto exit; } - self->private_impl.f_call_sequence = 32u; - goto ok; ok: - self->private_impl.p_do_decode_image_config = 0; + self->private_impl.p_decode_id_part2 = 0; goto exit; } goto suspend; suspend: - self->private_impl.p_do_decode_image_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; - self->private_data.s_do_decode_image_config.v_marker = v_marker; + self->private_impl.p_decode_id_part2 = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_data.s_decode_id_part2.v_block_size = v_block_size; + self->private_data.s_decode_id_part2.v_need_block_size = v_need_block_size; goto exit; exit: @@ -46850,115 +47002,182 @@ wuffs_jpeg__decoder__do_decode_image_config( return status; } -// -------- func jpeg.decoder.decode_dqt +// -------- func gif.decoder.copy_to_image_buffer WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_jpeg__decoder__decode_dqt( - wuffs_jpeg__decoder* self, - wuffs_base__io_buffer* a_src) { - wuffs_base__status status = wuffs_base__make_status(NULL); - - uint8_t v_c8 = 0; - uint8_t v_q = 0; - uint32_t v_i = 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; - } +wuffs_gif__decoder__copy_to_image_buffer( + wuffs_gif__decoder* self, + wuffs_base__pixel_buffer* a_pb, + wuffs_base__slice_u8 a_src) { + wuffs_base__slice_u8 v_dst = {0}; + wuffs_base__slice_u8 v_src = {0}; + uint64_t v_width_in_bytes = 0; + uint64_t v_n = 0; + uint64_t v_src_ri = 0; + wuffs_base__pixel_format v_pixfmt = {0}; + uint32_t v_bytes_per_pixel = 0; + uint32_t v_bits_per_pixel = 0; + wuffs_base__table_u8 v_tab = {0}; + uint64_t v_i = 0; + uint64_t v_j = 0; + uint32_t v_replicate_y0 = 0; + uint32_t v_replicate_y1 = 0; + wuffs_base__slice_u8 v_replicate_dst = {0}; + wuffs_base__slice_u8 v_replicate_src = {0}; - uint32_t coro_susp_point = self->private_impl.p_decode_dqt; - if (coro_susp_point) { - v_q = self->private_data.s_decode_dqt.v_q; - v_i = self->private_data.s_decode_dqt.v_i; + v_pixfmt = wuffs_base__pixel_buffer__pixel_format(a_pb); + v_bits_per_pixel = wuffs_base__pixel_format__bits_per_pixel(&v_pixfmt); + if ((v_bits_per_pixel & 7u) != 0u) { + return wuffs_base__make_status(wuffs_base__error__unsupported_option); } - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - - while (self->private_impl.f_payload_length > 0u) { - self->private_impl.f_payload_length -= 1u; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_0 = *iop_a_src++; - v_c8 = t_0; + v_bytes_per_pixel = (v_bits_per_pixel >> 3u); + v_width_in_bytes = ((uint64_t)((self->private_impl.f_width * v_bytes_per_pixel))); + v_tab = wuffs_base__pixel_buffer__plane(a_pb, 0u); + while (v_src_ri < ((uint64_t)(a_src.len))) { + v_src = wuffs_base__slice_u8__subslice_i(a_src, v_src_ri); + if (self->private_impl.f_dst_y >= self->private_impl.f_frame_rect_y1) { + if (self->private_impl.f_quirks[3u]) { + return wuffs_base__make_status(NULL); } - if (((uint8_t)(v_c8 & 15u)) > 3u) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_dqt_marker); - goto exit; + return wuffs_base__make_status(wuffs_base__error__too_much_data); + } + v_dst = wuffs_private_impl__table_u8__row_u32(v_tab, self->private_impl.f_dst_y); + if (self->private_impl.f_dst_y >= self->private_impl.f_height) { + v_dst = wuffs_base__slice_u8__subslice_j(v_dst, 0u); + } else if (v_width_in_bytes < ((uint64_t)(v_dst.len))) { + v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_width_in_bytes); + } + v_i = (((uint64_t)(self->private_impl.f_dst_x)) * ((uint64_t)(v_bytes_per_pixel))); + if (v_i < ((uint64_t)(v_dst.len))) { + v_j = (((uint64_t)(self->private_impl.f_frame_rect_x1)) * ((uint64_t)(v_bytes_per_pixel))); + if ((v_i <= v_j) && (v_j <= ((uint64_t)(v_dst.len)))) { + v_dst = wuffs_base__slice_u8__subslice_ij(v_dst, v_i, v_j); + } else { + v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_i); } - v_q = ((uint8_t)(v_c8 & 15u)); - if (((uint8_t)(v_c8 >> 4u)) == 1u) { - status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_precision); - goto exit; - } else if ((((uint8_t)(v_c8 >> 4u)) > 1u) || (self->private_impl.f_payload_length < 64u)) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_dqt_marker); - goto exit; + v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024), v_src); + wuffs_private_impl__u64__sat_add_indirect(&v_src_ri, v_n); + wuffs_private_impl__u32__sat_add_indirect(&self->private_impl.f_dst_x, ((uint32_t)(v_n))); + self->private_impl.f_dirty_max_excl_y = wuffs_base__u32__max(self->private_impl.f_dirty_max_excl_y, wuffs_base__u32__sat_add(self->private_impl.f_dst_y, 1u)); + } + if (self->private_impl.f_frame_rect_x1 <= self->private_impl.f_dst_x) { + self->private_impl.f_dst_x = self->private_impl.f_frame_rect_x0; + if (self->private_impl.f_interlace == 0u) { + wuffs_private_impl__u32__sat_add_indirect(&self->private_impl.f_dst_y, 1u); + continue; } - self->private_impl.f_payload_length -= 64u; - v_i = 0u; - while (v_i < 64u) { - v_i += 1u; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint16_t t_1 = *iop_a_src++; - self->private_impl.f_quant_tables[v_q][WUFFS_JPEG__UNZIG[v_i]] = t_1; + if ((self->private_impl.f_num_decoded_frames_value == 0u) && ! self->private_impl.f_gc_has_transparent_index && (self->private_impl.f_interlace > 1u)) { + v_replicate_src = wuffs_private_impl__table_u8__row_u32(v_tab, self->private_impl.f_dst_y); + v_replicate_y0 = wuffs_base__u32__sat_add(self->private_impl.f_dst_y, 1u); + v_replicate_y1 = wuffs_base__u32__sat_add(self->private_impl.f_dst_y, ((uint32_t)(WUFFS_GIF__INTERLACE_COUNT[self->private_impl.f_interlace]))); + v_replicate_y1 = wuffs_base__u32__min(v_replicate_y1, self->private_impl.f_frame_rect_y1); + while (v_replicate_y0 < v_replicate_y1) { + v_replicate_dst = wuffs_private_impl__table_u8__row_u32(v_tab, v_replicate_y0); + wuffs_private_impl__slice_u8__copy_from_slice(v_replicate_dst, v_replicate_src); + v_replicate_y0 += 1u; } + self->private_impl.f_dirty_max_excl_y = wuffs_base__u32__max(self->private_impl.f_dirty_max_excl_y, v_replicate_y1); } - self->private_impl.f_seen_dqt[v_q] = true; - if (self->private_impl.f_sof_marker == 0u) { - v_i = 0u; - while (v_i < 64u) { - self->private_impl.f_saved_quant_tables[v_q][v_i] = self->private_impl.f_quant_tables[v_q][v_i]; - v_i += 1u; - } - self->private_impl.f_saved_seen_dqt[v_q] = true; + wuffs_private_impl__u32__sat_add_indirect(&self->private_impl.f_dst_y, ((uint32_t)(WUFFS_GIF__INTERLACE_DELTA[self->private_impl.f_interlace]))); + while ((self->private_impl.f_interlace > 0u) && (self->private_impl.f_dst_y >= self->private_impl.f_frame_rect_y1)) { +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + self->private_impl.f_interlace -= 1u; +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + self->private_impl.f_dst_y = wuffs_base__u32__sat_add(self->private_impl.f_frame_rect_y0, WUFFS_GIF__INTERLACE_START[self->private_impl.f_interlace]); } + continue; } - - goto ok; - ok: - self->private_impl.p_decode_dqt = 0; - goto exit; + if (((uint64_t)(a_src.len)) == v_src_ri) { + break; + } else if (((uint64_t)(a_src.len)) < v_src_ri) { + return wuffs_base__make_status(wuffs_gif__error__internal_error_inconsistent_i_o); + } + v_n = ((uint64_t)((self->private_impl.f_frame_rect_x1 - self->private_impl.f_dst_x))); + v_n = wuffs_base__u64__min(v_n, (((uint64_t)(a_src.len)) - v_src_ri)); + wuffs_private_impl__u64__sat_add_indirect(&v_src_ri, v_n); + wuffs_private_impl__u32__sat_add_indirect(&self->private_impl.f_dst_x, ((uint32_t)(v_n))); + if (self->private_impl.f_frame_rect_x1 <= self->private_impl.f_dst_x) { + self->private_impl.f_dst_x = self->private_impl.f_frame_rect_x0; + wuffs_private_impl__u32__sat_add_indirect(&self->private_impl.f_dst_y, ((uint32_t)(WUFFS_GIF__INTERLACE_DELTA[self->private_impl.f_interlace]))); + while ((self->private_impl.f_interlace > 0u) && (self->private_impl.f_dst_y >= self->private_impl.f_frame_rect_y1)) { +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + self->private_impl.f_interlace -= 1u; +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + self->private_impl.f_dst_y = wuffs_base__u32__sat_add(self->private_impl.f_frame_rect_y0, WUFFS_GIF__INTERLACE_START[self->private_impl.f_interlace]); + } + continue; + } + if (v_src_ri != ((uint64_t)(a_src.len))) { + return wuffs_base__make_status(wuffs_gif__error__internal_error_inconsistent_i_o); + } + break; } + return wuffs_base__make_status(NULL); +} - goto suspend; - suspend: - self->private_impl.p_decode_dqt = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; - self->private_data.s_decode_dqt.v_q = v_q; - self->private_data.s_decode_dqt.v_i = v_i; +// -------- func gif.decoder.lzw_init - goto exit; - exit: - if (a_src && a_src->data.ptr) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_gif__decoder__lzw_init( + wuffs_gif__decoder* self) { + uint32_t v_i = 0; - return status; + self->private_impl.f_lzw_literal_width = 8u; + if (self->private_impl.f_lzw_pending_literal_width_plus_one > 0u) { + self->private_impl.f_lzw_literal_width = (self->private_impl.f_lzw_pending_literal_width_plus_one - 1u); + } + self->private_impl.f_lzw_clear_code = (((uint32_t)(1u)) << self->private_impl.f_lzw_literal_width); + self->private_impl.f_lzw_end_code = (self->private_impl.f_lzw_clear_code + 1u); + self->private_impl.f_lzw_save_code = self->private_impl.f_lzw_end_code; + self->private_impl.f_lzw_prev_code = self->private_impl.f_lzw_end_code; + self->private_impl.f_lzw_width = (self->private_impl.f_lzw_literal_width + 1u); + self->private_impl.f_lzw_bits = 0u; + self->private_impl.f_lzw_n_bits = 0u; + self->private_impl.f_lzw_output_ri = 0u; + self->private_impl.f_lzw_output_wi = 0u; + v_i = 0u; + while (v_i < self->private_impl.f_lzw_clear_code) { + self->private_data.f_lzw_lm1s[v_i] = 0u; + self->private_data.f_lzw_suffixes[v_i][0u] = ((uint8_t)(v_i)); + v_i += 1u; + } + return wuffs_base__make_empty_struct(); } -// -------- func jpeg.decoder.decode_dri +// -------- func gif.decoder.lzw_read_from WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_jpeg__decoder__decode_dri( - wuffs_jpeg__decoder* self, +static wuffs_base__empty_struct +wuffs_gif__decoder__lzw_read_from( + wuffs_gif__decoder* self, wuffs_base__io_buffer* a_src) { - wuffs_base__status status = wuffs_base__make_status(NULL); + uint32_t v_clear_code = 0; + uint32_t v_end_code = 0; + uint32_t v_save_code = 0; + uint32_t v_prev_code = 0; + uint32_t v_width = 0; + uint32_t v_bits = 0; + uint32_t v_n_bits = 0; + uint32_t v_output_wi = 0; + uint32_t v_code = 0; + uint32_t v_c = 0; + uint32_t v_o = 0; + uint32_t v_steps = 0; + uint8_t v_first_byte = 0; + uint16_t v_lm1_b = 0; + uint16_t v_lm1_a = 0; const uint8_t* iop_a_src = NULL; const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL; @@ -46971,80 +47190,462 @@ wuffs_jpeg__decoder__decode_dri( io2_a_src = io0_a_src + a_src->meta.wi; } - uint32_t coro_susp_point = self->private_impl.p_decode_dri; - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - - if (self->private_impl.f_payload_length != 2u) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_dri_marker); - goto exit; - } - self->private_impl.f_payload_length = 0u; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - uint16_t t_0; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { - t_0 = wuffs_base__peek_u16be__no_bounds_check(iop_a_src); - iop_a_src += 2; + v_clear_code = self->private_impl.f_lzw_clear_code; + v_end_code = self->private_impl.f_lzw_end_code; + v_save_code = self->private_impl.f_lzw_save_code; + v_prev_code = self->private_impl.f_lzw_prev_code; + v_width = self->private_impl.f_lzw_width; + v_bits = self->private_impl.f_lzw_bits; + v_n_bits = self->private_impl.f_lzw_n_bits; + v_output_wi = self->private_impl.f_lzw_output_wi; + while (true) { + if (v_n_bits < v_width) { + if (((uint64_t)(io2_a_src - iop_a_src)) >= 4u) { + v_bits |= ((uint32_t)(wuffs_base__peek_u32le__no_bounds_check(iop_a_src) << v_n_bits)); + iop_a_src += ((31u - v_n_bits) >> 3u); + v_n_bits |= 24u; + } else if (((uint64_t)(io2_a_src - iop_a_src)) <= 0u) { + if (a_src && a_src->meta.closed) { + self->private_impl.f_lzw_read_from_return_value = 3u; + } else { + self->private_impl.f_lzw_read_from_return_value = 2u; + } + break; } else { - self->private_data.s_decode_dri.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; + v_bits |= (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) << v_n_bits); + iop_a_src += 1u; + v_n_bits += 8u; + if (v_n_bits >= v_width) { + } else if (((uint64_t)(io2_a_src - iop_a_src)) <= 0u) { + if (a_src && a_src->meta.closed) { + self->private_impl.f_lzw_read_from_return_value = 3u; + } else { + self->private_impl.f_lzw_read_from_return_value = 2u; } - uint64_t* scratch = &self->private_data.s_decode_dri.scratch; - uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0); - if (num_bits_0 == 8) { - t_0 = ((uint16_t)(*scratch >> 48)); + break; + } else { + v_bits |= (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) << v_n_bits); + iop_a_src += 1u; + v_n_bits += 8u; + if (v_n_bits < v_width) { + self->private_impl.f_lzw_read_from_return_value = 5u; break; } - num_bits_0 += 8u; - *scratch |= ((uint64_t)(num_bits_0)); } } - self->private_impl.f_restart_interval = t_0; - } - if (self->private_impl.f_sof_marker == 0u) { - self->private_impl.f_saved_restart_interval = self->private_impl.f_restart_interval; } - - goto ok; - ok: - self->private_impl.p_decode_dri = 0; - goto exit; - } + v_code = ((v_bits) & WUFFS_PRIVATE_IMPL__LOW_BITS_MASK__U32(v_width)); + v_bits >>= v_width; + v_n_bits -= v_width; + if (v_code < v_clear_code) { + self->private_data.f_lzw_output[v_output_wi] = ((uint8_t)(v_code)); + v_output_wi = ((v_output_wi + 1u) & 8191u); + if (v_save_code <= 4095u) { + v_lm1_a = ((uint16_t)(((uint16_t)(self->private_data.f_lzw_lm1s[v_prev_code] + 1u)) & 4095u)); + self->private_data.f_lzw_lm1s[v_save_code] = v_lm1_a; + if (((uint16_t)(v_lm1_a % 8u)) != 0u) { + self->private_impl.f_lzw_prefixes[v_save_code] = self->private_impl.f_lzw_prefixes[v_prev_code]; + memcpy(self->private_data.f_lzw_suffixes[v_save_code],self->private_data.f_lzw_suffixes[v_prev_code], sizeof(self->private_data.f_lzw_suffixes[v_save_code])); + self->private_data.f_lzw_suffixes[v_save_code][((uint16_t)(v_lm1_a % 8u))] = ((uint8_t)(v_code)); + } else { + self->private_impl.f_lzw_prefixes[v_save_code] = ((uint16_t)(v_prev_code)); + self->private_data.f_lzw_suffixes[v_save_code][0u] = ((uint8_t)(v_code)); + } + v_save_code += 1u; + if (v_width < 12u) { + v_width += (1u & (v_save_code >> v_width)); + } + v_prev_code = v_code; + } + } else if (v_code <= v_end_code) { + if (v_code == v_end_code) { + self->private_impl.f_lzw_read_from_return_value = 0u; + break; + } + v_save_code = v_end_code; + v_prev_code = v_end_code; + v_width = (self->private_impl.f_lzw_literal_width + 1u); + } else if (v_code <= v_save_code) { + v_c = v_code; + if (v_code == v_save_code) { + v_c = v_prev_code; + } + v_o = ((v_output_wi + (((uint32_t)(self->private_data.f_lzw_lm1s[v_c])) & 4294967288u)) & 8191u); + v_output_wi = ((v_output_wi + 1u + ((uint32_t)(self->private_data.f_lzw_lm1s[v_c]))) & 8191u); + v_steps = (((uint32_t)(self->private_data.f_lzw_lm1s[v_c])) >> 3u); + while (true) { + memcpy((self->private_data.f_lzw_output)+(v_o), (self->private_data.f_lzw_suffixes[v_c]), 8u); + if (v_steps <= 0u) { + break; + } + v_steps -= 1u; + v_o = (((uint32_t)(v_o - 8u)) & 8191u); + v_c = ((uint32_t)(self->private_impl.f_lzw_prefixes[v_c])); + } + v_first_byte = self->private_data.f_lzw_suffixes[v_c][0u]; + if (v_code == v_save_code) { + self->private_data.f_lzw_output[v_output_wi] = v_first_byte; + v_output_wi = ((v_output_wi + 1u) & 8191u); + } + if (v_save_code <= 4095u) { + v_lm1_b = ((uint16_t)(((uint16_t)(self->private_data.f_lzw_lm1s[v_prev_code] + 1u)) & 4095u)); + self->private_data.f_lzw_lm1s[v_save_code] = v_lm1_b; + if (((uint16_t)(v_lm1_b % 8u)) != 0u) { + self->private_impl.f_lzw_prefixes[v_save_code] = self->private_impl.f_lzw_prefixes[v_prev_code]; + memcpy(self->private_data.f_lzw_suffixes[v_save_code],self->private_data.f_lzw_suffixes[v_prev_code], sizeof(self->private_data.f_lzw_suffixes[v_save_code])); + self->private_data.f_lzw_suffixes[v_save_code][((uint16_t)(v_lm1_b % 8u))] = v_first_byte; + } else { + self->private_impl.f_lzw_prefixes[v_save_code] = ((uint16_t)(v_prev_code)); + self->private_data.f_lzw_suffixes[v_save_code][0u] = ((uint8_t)(v_first_byte)); + } + v_save_code += 1u; + if (v_width < 12u) { + v_width += (1u & (v_save_code >> v_width)); + } + v_prev_code = v_code; + } + } else { + self->private_impl.f_lzw_read_from_return_value = 4u; + break; + } + if (v_output_wi > 4095u) { + self->private_impl.f_lzw_read_from_return_value = 1u; + break; + } + } + if (self->private_impl.f_lzw_read_from_return_value != 2u) { + while (v_n_bits >= 8u) { + v_n_bits -= 8u; + if (iop_a_src > io1_a_src) { + iop_a_src--; + } else { + self->private_impl.f_lzw_read_from_return_value = 5u; + break; + } + } + } + self->private_impl.f_lzw_save_code = v_save_code; + self->private_impl.f_lzw_prev_code = v_prev_code; + self->private_impl.f_lzw_width = v_width; + self->private_impl.f_lzw_bits = v_bits; + self->private_impl.f_lzw_n_bits = v_n_bits; + self->private_impl.f_lzw_output_wi = v_output_wi; + if (a_src && a_src->data.ptr) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + + return wuffs_base__make_empty_struct(); +} + +#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GIF) + +#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GZIP) + +// ---------------- Status Codes Implementations + +const char wuffs_gzip__error__bad_checksum[] = "#gzip: bad checksum"; +const char wuffs_gzip__error__bad_compression_method[] = "#gzip: bad compression method"; +const char wuffs_gzip__error__bad_encoding_flags[] = "#gzip: bad encoding flags"; +const char wuffs_gzip__error__bad_header[] = "#gzip: bad header"; +const char wuffs_gzip__error__truncated_input[] = "#gzip: truncated input"; + +// ---------------- Private Consts + +// ---------------- Private Initializer Prototypes + +// ---------------- Private Function Prototypes + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_gzip__decoder__do_transform_io( + wuffs_gzip__decoder* self, + wuffs_base__io_buffer* a_dst, + wuffs_base__io_buffer* a_src, + wuffs_base__slice_u8 a_workbuf); + +// ---------------- VTables + +const wuffs_base__io_transformer__func_ptrs +wuffs_gzip__decoder__func_ptrs_for__wuffs_base__io_transformer = { + (wuffs_base__optional_u63(*)(const void*))(&wuffs_gzip__decoder__dst_history_retain_length), + (uint64_t(*)(const void*, + uint32_t))(&wuffs_gzip__decoder__get_quirk), + (wuffs_base__status(*)(void*, + uint32_t, + uint64_t))(&wuffs_gzip__decoder__set_quirk), + (wuffs_base__status(*)(void*, + wuffs_base__io_buffer*, + wuffs_base__io_buffer*, + wuffs_base__slice_u8))(&wuffs_gzip__decoder__transform_io), + (wuffs_base__range_ii_u64(*)(const void*))(&wuffs_gzip__decoder__workbuf_len), +}; + +// ---------------- Initializer Implementations + +wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT +wuffs_gzip__decoder__initialize( + wuffs_gzip__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)); + } + } + + { + wuffs_base__status z = wuffs_crc32__ieee_hasher__initialize( + &self->private_data.f_checksum, sizeof(self->private_data.f_checksum), WUFFS_VERSION, options); + if (z.repr) { + return z; + } + } + { + wuffs_base__status z = wuffs_deflate__decoder__initialize( + &self->private_data.f_flate, sizeof(self->private_data.f_flate), WUFFS_VERSION, options); + if (z.repr) { + return z; + } + } + self->private_impl.magic = WUFFS_BASE__MAGIC; + self->private_impl.vtable_for__wuffs_base__io_transformer.vtable_name = + wuffs_base__io_transformer__vtable_name; + self->private_impl.vtable_for__wuffs_base__io_transformer.function_pointers = + (const void*)(&wuffs_gzip__decoder__func_ptrs_for__wuffs_base__io_transformer); + return wuffs_base__make_status(NULL); +} + +wuffs_gzip__decoder* +wuffs_gzip__decoder__alloc(void) { + wuffs_gzip__decoder* x = + (wuffs_gzip__decoder*)(calloc(1, sizeof(wuffs_gzip__decoder))); + if (!x) { + return NULL; + } + if (wuffs_gzip__decoder__initialize( + x, sizeof(wuffs_gzip__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) { + free(x); + return NULL; + } + return x; +} + +size_t +sizeof__wuffs_gzip__decoder(void) { + return sizeof(wuffs_gzip__decoder); +} + +// ---------------- Function Implementations + +// -------- func gzip.decoder.get_quirk + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC uint64_t +wuffs_gzip__decoder__get_quirk( + const wuffs_gzip__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; + } + + if ((a_key == 1u) && self->private_impl.f_ignore_checksum) { + return 1u; + } + return 0u; +} + +// -------- func gzip.decoder.set_quirk + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_gzip__decoder__set_quirk( + wuffs_gzip__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); + } + + if (a_key == 1u) { + self->private_impl.f_ignore_checksum = (a_value > 0u); + return wuffs_base__make_status(NULL); + } + return wuffs_base__make_status(wuffs_base__error__unsupported_option); +} + +// -------- func gzip.decoder.dst_history_retain_length + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__optional_u63 +wuffs_gzip__decoder__dst_history_retain_length( + const wuffs_gzip__decoder* self) { + if (!self) { + return wuffs_base__utility__make_optional_u63(false, 0u); + } + if ((self->private_impl.magic != WUFFS_BASE__MAGIC) && + (self->private_impl.magic != WUFFS_BASE__DISABLED)) { + return wuffs_base__utility__make_optional_u63(false, 0u); + } + + return wuffs_base__utility__make_optional_u63(true, 0u); +} + +// -------- func gzip.decoder.workbuf_len + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 +wuffs_gzip__decoder__workbuf_len( + const wuffs_gzip__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(1u, 1u); +} + +// -------- func gzip.decoder.transform_io + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_gzip__decoder__transform_io( + wuffs_gzip__decoder* self, + wuffs_base__io_buffer* a_dst, + wuffs_base__io_buffer* a_src, + wuffs_base__slice_u8 a_workbuf) { + 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 != 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_transform_io; + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + + while (true) { + { + wuffs_base__status t_0 = wuffs_gzip__decoder__do_transform_io(self, a_dst, a_src, a_workbuf); + 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_gzip__error__truncated_input); + goto exit; + } + status = v_status; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1); + } + + ok: + self->private_impl.p_transform_io = 0; + goto exit; + } goto suspend; suspend: - self->private_impl.p_decode_dri = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_impl.p_transform_io = 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 (a_src && a_src->data.ptr) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + if (wuffs_base__status__is_error(&status)) { + self->private_impl.magic = WUFFS_BASE__DISABLED; } - return status; } -// -------- func jpeg.decoder.decode_appn +// -------- func gzip.decoder.do_transform_io WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_jpeg__decoder__decode_appn( - wuffs_jpeg__decoder* self, +wuffs_gzip__decoder__do_transform_io( + wuffs_gzip__decoder* self, + wuffs_base__io_buffer* a_dst, wuffs_base__io_buffer* a_src, - uint8_t a_marker) { + wuffs_base__slice_u8 a_workbuf) { wuffs_base__status status = wuffs_base__make_status(NULL); uint8_t v_c8 = 0; - uint32_t v_c32 = 0; + uint8_t v_flags = 0; + uint16_t v_xlen = 0; + uint64_t v_mark = 0; + uint32_t v_checksum_have = 0; + uint32_t v_decoded_length_have = 0; + wuffs_base__status v_status = wuffs_base__make_status(NULL); + uint32_t v_checksum_want = 0; + uint32_t v_decoded_length_want = 0; + uint8_t* iop_a_dst = NULL; + uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + if (a_dst && a_dst->data.ptr) { + io0_a_dst = a_dst->data.ptr; + io1_a_dst = io0_a_dst + a_dst->meta.wi; + iop_a_dst = io1_a_dst; + io2_a_dst = io0_a_dst + a_dst->data.len; + if (a_dst->meta.closed) { + io2_a_dst = iop_a_dst; + } + } 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; @@ -47056,496 +47657,269 @@ wuffs_jpeg__decoder__decode_appn( io2_a_src = io0_a_src + a_src->meta.wi; } - uint32_t coro_susp_point = self->private_impl.p_decode_appn; + uint32_t coro_susp_point = self->private_impl.p_do_transform_io; + if (coro_susp_point) { + v_flags = self->private_data.s_do_transform_io.v_flags; + v_checksum_have = self->private_data.s_do_transform_io.v_checksum_have; + v_decoded_length_have = self->private_data.s_do_transform_io.v_decoded_length_have; + v_checksum_want = self->private_data.s_do_transform_io.v_checksum_want; + } switch (coro_susp_point) { WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - do { - if (a_marker == 224u) { - if (self->private_impl.f_payload_length >= 5u) { - self->private_impl.f_payload_length -= 5u; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - uint32_t t_0; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_0 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_decode_appn.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_decode_appn.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 == 24) { - t_0 = ((uint32_t)(*scratch)); - break; - } - num_bits_0 += 8u; - *scratch |= ((uint64_t)(num_bits_0)) << 56; - } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_0 = *iop_a_src++; + v_c8 = t_0; + } + if (v_c8 != 31u) { + status = wuffs_base__make_status(wuffs_gzip__error__bad_header); + goto exit; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_1 = *iop_a_src++; + v_c8 = t_1; + } + if (v_c8 != 139u) { + status = wuffs_base__make_status(wuffs_gzip__error__bad_header); + goto exit; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_2 = *iop_a_src++; + v_c8 = t_2; + } + if (v_c8 != 8u) { + status = wuffs_base__make_status(wuffs_gzip__error__bad_compression_method); + goto exit; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_3 = *iop_a_src++; + v_flags = t_3; + } + self->private_data.s_do_transform_io.scratch = 6u; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); + if (self->private_data.s_do_transform_io.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { + self->private_data.s_do_transform_io.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); + iop_a_src = io2_a_src; + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + iop_a_src += self->private_data.s_do_transform_io.scratch; + if (((uint8_t)(v_flags & 4u)) != 0u) { + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); + uint16_t t_4; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { + t_4 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src); + iop_a_src += 2; + } else { + self->private_data.s_do_transform_io.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); + while (true) { + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } - v_c32 = t_0; - } - if (v_c32 != 1179207242u) { - self->private_impl.f_payload_length = (65535u & (self->private_impl.f_payload_length + 1u)); - break; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_1 = *iop_a_src++; - v_c8 = t_1; - } - self->private_impl.f_is_jfif = (v_c8 == 0u); - } - } else if (a_marker == 238u) { - if (self->private_impl.f_payload_length >= 12u) { - self->private_impl.f_payload_length -= 12u; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); - uint32_t t_2; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_2 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_decode_appn.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); - 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_decode_appn.scratch; - uint32_t num_bits_2 = ((uint32_t)(*scratch >> 56)); - *scratch <<= 8; - *scratch >>= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_2; - if (num_bits_2 == 24) { - t_2 = ((uint32_t)(*scratch)); - break; - } - num_bits_2 += 8u; - *scratch |= ((uint64_t)(num_bits_2)) << 56; - } - } - v_c32 = t_2; - } - if (v_c32 != 1651467329u) { - self->private_impl.f_payload_length = (65535u & (self->private_impl.f_payload_length + 8u)); - break; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); - uint32_t t_3; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_3 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_decode_appn.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); - 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_decode_appn.scratch; - uint32_t num_bits_3 = ((uint32_t)(*scratch >> 56)); - *scratch <<= 8; - *scratch >>= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_3; - if (num_bits_3 == 24) { - t_3 = ((uint32_t)(*scratch)); - break; - } - num_bits_3 += 8u; - *scratch |= ((uint64_t)(num_bits_3)) << 56; - } - } - v_c32 = t_3; - } - if ((255u & v_c32) != 101u) { - self->private_impl.f_payload_length = (65535u & (self->private_impl.f_payload_length + 4u)); - break; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); - uint32_t t_4; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_4 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_decode_appn.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); - 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_decode_appn.scratch; - uint32_t num_bits_4 = ((uint32_t)(*scratch >> 56)); - *scratch <<= 8; - *scratch >>= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_4; - if (num_bits_4 == 24) { - t_4 = ((uint32_t)(*scratch)); - break; - } - num_bits_4 += 8u; - *scratch |= ((uint64_t)(num_bits_4)) << 56; - } + uint64_t* scratch = &self->private_data.s_do_transform_io.scratch; + uint32_t num_bits_4 = ((uint32_t)(*scratch >> 56)); + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_4; + if (num_bits_4 == 8) { + t_4 = ((uint16_t)(*scratch)); + break; } - v_c32 = t_4; - } - if ((v_c32 >> 24u) == 0u) { - self->private_impl.f_is_adobe = 1u; - } else { - self->private_impl.f_is_adobe = 2u; + num_bits_4 += 8u; + *scratch |= ((uint64_t)(num_bits_4)) << 56; } } + v_xlen = t_4; } - } while (0); - self->private_data.s_decode_appn.scratch = self->private_impl.f_payload_length; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10); - if (self->private_data.s_decode_appn.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { - self->private_data.s_decode_appn.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); - iop_a_src = io2_a_src; - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - iop_a_src += self->private_data.s_decode_appn.scratch; - self->private_impl.f_payload_length = 0u; - - goto ok; - ok: - self->private_impl.p_decode_appn = 0; - goto exit; - } - - goto suspend; - suspend: - self->private_impl.p_decode_appn = 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 jpeg.decoder.decode_sof - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_jpeg__decoder__decode_sof( - wuffs_jpeg__decoder* self, - wuffs_base__io_buffer* a_src) { - wuffs_base__status status = wuffs_base__make_status(NULL); - - uint8_t v_c8 = 0; - uint8_t v_comp_h = 0; - uint8_t v_comp_v = 0; - uint32_t v_i = 0; - uint32_t v_j = 0; - bool v_has_h24 = false; - bool v_has_h3 = false; - bool v_has_v24 = false; - bool v_has_v3 = false; - uint32_t v_upper_bound = 0; - uint64_t v_wh0 = 0; - uint64_t v_wh1 = 0; - uint64_t v_wh2 = 0; - uint64_t v_wh3 = 0; - uint64_t v_progressive = 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_decode_sof; - if (coro_susp_point) { - v_i = self->private_data.s_decode_sof.v_i; - } - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - - if (self->private_impl.f_payload_length < 6u) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_sof_marker); - goto exit; - } - self->private_impl.f_payload_length -= 6u; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + self->private_data.s_do_transform_io.scratch = ((uint32_t)(v_xlen)); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); + if (self->private_data.s_do_transform_io.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { + self->private_data.s_do_transform_io.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); + iop_a_src = io2_a_src; status = wuffs_base__make_status(wuffs_base__suspension__short_read); goto suspend; } - uint8_t t_0 = *iop_a_src++; - v_c8 = t_0; - } - if (v_c8 == 8u) { - } else if (v_c8 == 12u) { - status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_precision_12_bits); - goto exit; - } else if (v_c8 == 16u) { - status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_precision_16_bits); - goto exit; - } else { - status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_precision); - goto exit; + iop_a_src += self->private_data.s_do_transform_io.scratch; } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); - uint32_t t_1; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { - t_1 = ((uint32_t)(wuffs_base__peek_u16be__no_bounds_check(iop_a_src))); - iop_a_src += 2; - } else { - self->private_data.s_decode_sof.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - while (true) { + if (((uint8_t)(v_flags & 8u)) != 0u) { + while (true) { + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); 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_decode_sof.scratch; - uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1); - if (num_bits_1 == 8) { - t_1 = ((uint32_t)(*scratch >> 48)); - break; - } - num_bits_1 += 8u; - *scratch |= ((uint64_t)(num_bits_1)); + uint8_t t_5 = *iop_a_src++; + v_c8 = t_5; + } + if (v_c8 == 0u) { + break; } } - self->private_impl.f_height = t_1; - } - if (self->private_impl.f_height == 0u) { - status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_implicit_height); - goto exit; } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); - uint32_t t_2; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { - t_2 = ((uint32_t)(wuffs_base__peek_u16be__no_bounds_check(iop_a_src))); - iop_a_src += 2; - } else { - self->private_data.s_decode_sof.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); - while (true) { + if (((uint8_t)(v_flags & 16u)) != 0u) { + while (true) { + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10); 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_decode_sof.scratch; - uint32_t num_bits_2 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_2); - if (num_bits_2 == 8) { - t_2 = ((uint32_t)(*scratch >> 48)); - break; - } - num_bits_2 += 8u; - *scratch |= ((uint64_t)(num_bits_2)); + uint8_t t_6 = *iop_a_src++; + v_c8 = t_6; + } + if (v_c8 == 0u) { + break; } } - self->private_impl.f_width = t_2; } - if (self->private_impl.f_width == 0u) { - status = wuffs_base__make_status(wuffs_base__error__unsupported_image_dimension); - goto exit; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + if (((uint8_t)(v_flags & 2u)) != 0u) { + self->private_data.s_do_transform_io.scratch = 2u; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11); + if (self->private_data.s_do_transform_io.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { + self->private_data.s_do_transform_io.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); + iop_a_src = io2_a_src; status = wuffs_base__make_status(wuffs_base__suspension__short_read); goto suspend; } - uint8_t t_3 = *iop_a_src++; - v_c8 = t_3; - } - if ((v_c8 == 0u) || (v_c8 > 4u)) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_sof_marker); - goto exit; - } else if (v_c8 == 2u) { - status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_color_model); - goto exit; + iop_a_src += self->private_data.s_do_transform_io.scratch; } - self->private_impl.f_num_components = ((uint32_t)(v_c8)); - if (self->private_impl.f_payload_length != (3u * self->private_impl.f_num_components)) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_sof_marker); + if (((uint8_t)(v_flags & 224u)) != 0u) { + status = wuffs_base__make_status(wuffs_gzip__error__bad_encoding_flags); goto exit; } - self->private_impl.f_payload_length = 0u; - v_i = 0u; - while (v_i < self->private_impl.f_num_components) { + while (true) { + v_mark = ((uint64_t)(iop_a_dst - io0_a_dst)); { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; + if (a_dst) { + a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr)); } - uint8_t t_4 = *iop_a_src++; - self->private_impl.f_components_c[v_i] = t_4; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); } - uint8_t t_5 = *iop_a_src++; - v_c8 = t_5; - } - v_comp_h = ((uint8_t)(v_c8 >> 4u)); - v_comp_v = ((uint8_t)(v_c8 & 15u)); - if ((v_comp_h == 0u) || - (v_comp_h > 4u) || - (v_comp_v == 0u) || - (v_comp_v > 4u)) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_sof_marker); - goto exit; - } - self->private_impl.f_components_h[v_i] = v_comp_h; - if (self->private_impl.f_max_incl_components_h < self->private_impl.f_components_h[v_i]) { - self->private_impl.f_max_incl_components_h = self->private_impl.f_components_h[v_i]; - } - self->private_impl.f_components_v[v_i] = v_comp_v; - if (self->private_impl.f_max_incl_components_v < self->private_impl.f_components_v[v_i]) { - self->private_impl.f_max_incl_components_v = self->private_impl.f_components_v[v_i]; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; + wuffs_base__status t_7 = wuffs_deflate__decoder__transform_io(&self->private_data.f_flate, a_dst, a_src, a_workbuf); + v_status = t_7; + if (a_dst) { + iop_a_dst = a_dst->data.ptr + a_dst->meta.wi; } - uint8_t t_6 = *iop_a_src++; - v_c8 = t_6; - } - if (v_c8 >= 4u) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_sof_marker); - goto exit; - } - self->private_impl.f_components_tq[v_i] = v_c8; - v_j = 0u; - while (v_j < v_i) { - if (self->private_impl.f_components_c[v_j] == self->private_impl.f_components_c[v_i]) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_sof_marker); - goto exit; + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; } - v_j += 1u; } - v_i += 1u; - } - if (self->private_impl.f_num_components == 1u) { - self->private_impl.f_max_incl_components_h = 1u; - self->private_impl.f_max_incl_components_v = 1u; - self->private_impl.f_components_h[0u] = 1u; - self->private_impl.f_components_v[0u] = 1u; - } else { - v_has_h24 = false; - v_has_h3 = false; - v_has_v24 = false; - v_has_v3 = false; - v_i = 0u; - while (v_i < self->private_impl.f_num_components) { - v_has_h24 = (v_has_h24 || (self->private_impl.f_components_h[v_i] == 2u) || (self->private_impl.f_components_h[v_i] == 4u)); - v_has_h3 = (v_has_h3 || (self->private_impl.f_components_h[v_i] == 3u)); - v_has_v24 = (v_has_v24 || (self->private_impl.f_components_v[v_i] == 2u) || (self->private_impl.f_components_v[v_i] == 4u)); - v_has_v3 = (v_has_v3 || (self->private_impl.f_components_v[v_i] == 3u)); - v_i += 1u; + if ( ! self->private_impl.f_ignore_checksum) { + v_checksum_have = wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_checksum, wuffs_private_impl__io__since(v_mark, ((uint64_t)(iop_a_dst - io0_a_dst)), io0_a_dst)); + v_decoded_length_have += ((uint32_t)(wuffs_private_impl__io__count_since(v_mark, ((uint64_t)(iop_a_dst - io0_a_dst))))); } - if ((v_has_h24 && v_has_h3) || (v_has_v24 && v_has_v3)) { - status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_fractional_sampling); - goto exit; + if (wuffs_base__status__is_ok(&v_status)) { + break; } - if (self->private_impl.f_num_components == 4u) { - self->private_impl.f_is_rgb_or_cmyk = (self->private_impl.f_is_adobe < 2u); + status = v_status; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(12); + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13); + uint32_t t_8; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_8 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src); + iop_a_src += 4; } else { - if (self->private_impl.f_is_jfif) { - self->private_impl.f_is_rgb_or_cmyk = false; - } else if (self->private_impl.f_is_adobe > 0u) { - self->private_impl.f_is_rgb_or_cmyk = (self->private_impl.f_is_adobe == 1u); - } else { - self->private_impl.f_is_rgb_or_cmyk = ((self->private_impl.f_components_c[0u] == 82u) && (self->private_impl.f_components_c[1u] == 71u) && (self->private_impl.f_components_c[2u] == 66u)); + self->private_data.s_do_transform_io.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(14); + 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_transform_io.scratch; + uint32_t num_bits_8 = ((uint32_t)(*scratch >> 56)); + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_8; + if (num_bits_8 == 24) { + t_8 = ((uint32_t)(*scratch)); + break; + } + num_bits_8 += 8u; + *scratch |= ((uint64_t)(num_bits_8)) << 56; } } + v_checksum_want = t_8; } - self->private_impl.f_width_in_mcus = wuffs_jpeg__decoder__quantize_dimension(self, self->private_impl.f_width, 1u, self->private_impl.f_max_incl_components_h); - self->private_impl.f_height_in_mcus = wuffs_jpeg__decoder__quantize_dimension(self, self->private_impl.f_height, 1u, self->private_impl.f_max_incl_components_v); - v_upper_bound = 65544u; - self->private_impl.f_components_workbuf_widths[0u] = wuffs_base__u32__min(v_upper_bound, (8u * self->private_impl.f_width_in_mcus * ((uint32_t)(self->private_impl.f_components_h[0u])))); - self->private_impl.f_components_workbuf_widths[1u] = wuffs_base__u32__min(v_upper_bound, (8u * self->private_impl.f_width_in_mcus * ((uint32_t)(self->private_impl.f_components_h[1u])))); - self->private_impl.f_components_workbuf_widths[2u] = wuffs_base__u32__min(v_upper_bound, (8u * self->private_impl.f_width_in_mcus * ((uint32_t)(self->private_impl.f_components_h[2u])))); - self->private_impl.f_components_workbuf_widths[3u] = wuffs_base__u32__min(v_upper_bound, (8u * self->private_impl.f_width_in_mcus * ((uint32_t)(self->private_impl.f_components_h[3u])))); - self->private_impl.f_components_workbuf_heights[0u] = wuffs_base__u32__min(v_upper_bound, (8u * self->private_impl.f_height_in_mcus * ((uint32_t)(self->private_impl.f_components_v[0u])))); - self->private_impl.f_components_workbuf_heights[1u] = wuffs_base__u32__min(v_upper_bound, (8u * self->private_impl.f_height_in_mcus * ((uint32_t)(self->private_impl.f_components_v[1u])))); - self->private_impl.f_components_workbuf_heights[2u] = wuffs_base__u32__min(v_upper_bound, (8u * self->private_impl.f_height_in_mcus * ((uint32_t)(self->private_impl.f_components_v[2u])))); - self->private_impl.f_components_workbuf_heights[3u] = wuffs_base__u32__min(v_upper_bound, (8u * self->private_impl.f_height_in_mcus * ((uint32_t)(self->private_impl.f_components_v[3u])))); - v_wh0 = (((uint64_t)(self->private_impl.f_components_workbuf_widths[0u])) * ((uint64_t)(self->private_impl.f_components_workbuf_heights[0u]))); - v_wh1 = (((uint64_t)(self->private_impl.f_components_workbuf_widths[1u])) * ((uint64_t)(self->private_impl.f_components_workbuf_heights[1u]))); - v_wh2 = (((uint64_t)(self->private_impl.f_components_workbuf_widths[2u])) * ((uint64_t)(self->private_impl.f_components_workbuf_heights[2u]))); - v_wh3 = (((uint64_t)(self->private_impl.f_components_workbuf_widths[3u])) * ((uint64_t)(self->private_impl.f_components_workbuf_heights[3u]))); - v_progressive = 0u; - if (self->private_impl.f_sof_marker >= 194u) { - v_progressive = 2u; - v_i = 0u; - while (v_i < 4u) { - v_j = 0u; - while (v_j < 10u) { - self->private_impl.f_block_smoothing_lowest_scan_al[v_i][v_j] = 16u; - v_j += 1u; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15); + uint32_t t_9; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_9 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src); + iop_a_src += 4; + } else { + self->private_data.s_do_transform_io.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16); + 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_transform_io.scratch; + uint32_t num_bits_9 = ((uint32_t)(*scratch >> 56)); + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_9; + if (num_bits_9 == 24) { + t_9 = ((uint32_t)(*scratch)); + break; + } + num_bits_9 += 8u; + *scratch |= ((uint64_t)(num_bits_9)) << 56; } - v_i += 1u; } + v_decoded_length_want = t_9; + } + if ( ! self->private_impl.f_ignore_checksum && ((v_checksum_have != v_checksum_want) || (v_decoded_length_have != v_decoded_length_want))) { + status = wuffs_base__make_status(wuffs_gzip__error__bad_checksum); + goto exit; } - self->private_impl.f_components_workbuf_offsets[0u] = 0u; - self->private_impl.f_components_workbuf_offsets[1u] = (self->private_impl.f_components_workbuf_offsets[0u] + v_wh0); - self->private_impl.f_components_workbuf_offsets[2u] = (self->private_impl.f_components_workbuf_offsets[1u] + v_wh1); - self->private_impl.f_components_workbuf_offsets[3u] = (self->private_impl.f_components_workbuf_offsets[2u] + v_wh2); - self->private_impl.f_components_workbuf_offsets[4u] = (self->private_impl.f_components_workbuf_offsets[3u] + v_wh3); - self->private_impl.f_components_workbuf_offsets[5u] = (self->private_impl.f_components_workbuf_offsets[4u] + (v_wh0 * v_progressive)); - self->private_impl.f_components_workbuf_offsets[6u] = (self->private_impl.f_components_workbuf_offsets[5u] + (v_wh1 * v_progressive)); - self->private_impl.f_components_workbuf_offsets[7u] = (self->private_impl.f_components_workbuf_offsets[6u] + (v_wh2 * v_progressive)); - self->private_impl.f_components_workbuf_offsets[8u] = (self->private_impl.f_components_workbuf_offsets[7u] + (v_wh3 * v_progressive)); - goto ok; ok: - self->private_impl.p_decode_sof = 0; + self->private_impl.p_do_transform_io = 0; goto exit; } goto suspend; suspend: - self->private_impl.p_decode_sof = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; - self->private_data.s_decode_sof.v_i = v_i; + self->private_impl.p_do_transform_io = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_data.s_do_transform_io.v_flags = v_flags; + self->private_data.s_do_transform_io.v_checksum_have = v_checksum_have; + self->private_data.s_do_transform_io.v_decoded_length_have = v_decoded_length_have; + self->private_data.s_do_transform_io.v_checksum_want = v_checksum_want; goto exit; exit: + if (a_dst && a_dst->data.ptr) { + a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr)); + } if (a_src && a_src->data.ptr) { a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); } @@ -47553,2071 +47927,2224 @@ wuffs_jpeg__decoder__decode_sof( return status; } -// -------- func jpeg.decoder.quantize_dimension +#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GZIP) -WUFFS_BASE__GENERATED_C_CODE -static uint32_t -wuffs_jpeg__decoder__quantize_dimension( - const wuffs_jpeg__decoder* self, - uint32_t a_width, - uint8_t a_h, - uint8_t a_max_incl_h) { - uint32_t v_ratio = 0; +#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__JPEG) - v_ratio = 0u; - if (a_h > 0u) { - v_ratio = ((uint32_t)(((uint8_t)(a_max_incl_h / a_h)))); - } - if (v_ratio == 1u) { - return ((a_width + 7u) / 8u); - } else if (v_ratio == 2u) { - return ((a_width + 15u) / 16u); - } else if (v_ratio == 3u) { - return ((a_width + 23u) / 24u); - } - return ((a_width + 31u) / 32u); -} +// ---------------- Status Codes Implementations -// -------- func jpeg.decoder.decode_frame_config +const char wuffs_jpeg__error__bad_dht_marker[] = "#jpeg: bad DHT marker"; +const char wuffs_jpeg__error__bad_dqt_marker[] = "#jpeg: bad DQT marker"; +const char wuffs_jpeg__error__bad_dri_marker[] = "#jpeg: bad DRI marker"; +const char wuffs_jpeg__error__bad_sof_marker[] = "#jpeg: bad SOF marker"; +const char wuffs_jpeg__error__bad_sos_marker[] = "#jpeg: bad SOS marker"; +const char wuffs_jpeg__error__bad_header[] = "#jpeg: bad header"; +const char wuffs_jpeg__error__bad_marker[] = "#jpeg: bad marker"; +const char wuffs_jpeg__error__bad_scan_count[] = "#jpeg: bad scan count"; +const char wuffs_jpeg__error__missing_huffman_table[] = "#jpeg: missing Huffman table"; +const char wuffs_jpeg__error__missing_quantization_table[] = "#jpeg: missing Quantization table"; +const char wuffs_jpeg__error__rejected_progressive_jpeg[] = "#jpeg: rejected progressive JPEG"; +const char wuffs_jpeg__error__short_sos_bitstream[] = "#jpeg: short SOS bitstream"; +const char wuffs_jpeg__error__truncated_input[] = "#jpeg: truncated input"; +const char wuffs_jpeg__error__unsupported_arithmetic_coding[] = "#jpeg: unsupported arithmetic coding"; +const char wuffs_jpeg__error__unsupported_color_model[] = "#jpeg: unsupported color model"; +const char wuffs_jpeg__error__unsupported_fractional_sampling[] = "#jpeg: unsupported fractional sampling"; +const char wuffs_jpeg__error__unsupported_hierarchical_coding[] = "#jpeg: unsupported hierarchical coding"; +const char wuffs_jpeg__error__unsupported_implicit_height[] = "#jpeg: unsupported implicit height"; +const char wuffs_jpeg__error__unsupported_lossless_coding[] = "#jpeg: unsupported lossless coding"; +const char wuffs_jpeg__error__unsupported_marker[] = "#jpeg: unsupported marker"; +const char wuffs_jpeg__error__unsupported_precision_12_bits[] = "#jpeg: unsupported precision (12 bits)"; +const char wuffs_jpeg__error__unsupported_precision_16_bits[] = "#jpeg: unsupported precision (16 bits)"; +const char wuffs_jpeg__error__unsupported_precision[] = "#jpeg: unsupported precision"; +const char wuffs_jpeg__error__unsupported_scan_count[] = "#jpeg: unsupported scan count"; +const char wuffs_jpeg__error__internal_error_inconsistent_decoder_state[] = "#jpeg: internal error: inconsistent decoder state"; -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_jpeg__decoder__decode_frame_config( - wuffs_jpeg__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); +// ---------------- Private Consts - wuffs_base__status v_status = wuffs_base__make_status(NULL); +static const uint8_t +WUFFS_JPEG__UNZIG[80] WUFFS_BASE__POTENTIALLY_UNUSED = { + 0u, 0u, 1u, 8u, 16u, 9u, 2u, 3u, + 10u, 17u, 24u, 32u, 25u, 18u, 11u, 4u, + 5u, 12u, 19u, 26u, 33u, 40u, 48u, 41u, + 34u, 27u, 20u, 13u, 6u, 7u, 14u, 21u, + 28u, 35u, 42u, 49u, 56u, 57u, 50u, 43u, + 36u, 29u, 22u, 15u, 23u, 30u, 37u, 44u, + 51u, 58u, 59u, 52u, 45u, 38u, 31u, 39u, + 46u, 53u, 60u, 61u, 54u, 47u, 55u, 62u, + 63u, 63u, 63u, 63u, 63u, 63u, 63u, 63u, + 63u, 63u, 63u, 63u, 63u, 63u, 63u, 63u, +}; - uint32_t coro_susp_point = self->private_impl.p_decode_frame_config; - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; +static const uint8_t +WUFFS_JPEG__BIAS_AND_CLAMP[1024] WUFFS_BASE__POTENTIALLY_UNUSED = { + 128u, 129u, 130u, 131u, 132u, 133u, 134u, 135u, + 136u, 137u, 138u, 139u, 140u, 141u, 142u, 143u, + 144u, 145u, 146u, 147u, 148u, 149u, 150u, 151u, + 152u, 153u, 154u, 155u, 156u, 157u, 158u, 159u, + 160u, 161u, 162u, 163u, 164u, 165u, 166u, 167u, + 168u, 169u, 170u, 171u, 172u, 173u, 174u, 175u, + 176u, 177u, 178u, 179u, 180u, 181u, 182u, 183u, + 184u, 185u, 186u, 187u, 188u, 189u, 190u, 191u, + 192u, 193u, 194u, 195u, 196u, 197u, 198u, 199u, + 200u, 201u, 202u, 203u, 204u, 205u, 206u, 207u, + 208u, 209u, 210u, 211u, 212u, 213u, 214u, 215u, + 216u, 217u, 218u, 219u, 220u, 221u, 222u, 223u, + 224u, 225u, 226u, 227u, 228u, 229u, 230u, 231u, + 232u, 233u, 234u, 235u, 236u, 237u, 238u, 239u, + 240u, 241u, 242u, 243u, 244u, 245u, 246u, 247u, + 248u, 249u, 250u, 251u, 252u, 253u, 254u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u, + 8u, 9u, 10u, 11u, 12u, 13u, 14u, 15u, + 16u, 17u, 18u, 19u, 20u, 21u, 22u, 23u, + 24u, 25u, 26u, 27u, 28u, 29u, 30u, 31u, + 32u, 33u, 34u, 35u, 36u, 37u, 38u, 39u, + 40u, 41u, 42u, 43u, 44u, 45u, 46u, 47u, + 48u, 49u, 50u, 51u, 52u, 53u, 54u, 55u, + 56u, 57u, 58u, 59u, 60u, 61u, 62u, 63u, + 64u, 65u, 66u, 67u, 68u, 69u, 70u, 71u, + 72u, 73u, 74u, 75u, 76u, 77u, 78u, 79u, + 80u, 81u, 82u, 83u, 84u, 85u, 86u, 87u, + 88u, 89u, 90u, 91u, 92u, 93u, 94u, 95u, + 96u, 97u, 98u, 99u, 100u, 101u, 102u, 103u, + 104u, 105u, 106u, 107u, 108u, 109u, 110u, 111u, + 112u, 113u, 114u, 115u, 116u, 117u, 118u, 119u, + 120u, 121u, 122u, 123u, 124u, 125u, 126u, 127u, +}; - while (true) { - { - wuffs_base__status t_0 = wuffs_jpeg__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_jpeg__error__truncated_input); - goto exit; - } - status = v_status; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1); - } +static const uint16_t +WUFFS_JPEG__EXTEND[16] WUFFS_BASE__POTENTIALLY_UNUSED = { + 0u, 65535u, 65533u, 65529u, 65521u, 65505u, 65473u, 65409u, + 65281u, 65025u, 64513u, 63489u, 61441u, 57345u, 49153u, 32769u, +}; - ok: - self->private_impl.p_decode_frame_config = 0; - goto exit; - } +static const uint8_t +WUFFS_JPEG__DEFAULT_HUFF_TABLE_DC_LUMA[29] WUFFS_BASE__POTENTIALLY_UNUSED = { + 0u, 0u, 1u, 5u, 1u, 1u, 1u, 1u, + 1u, 1u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 1u, 2u, 3u, 4u, 5u, 6u, + 7u, 8u, 9u, 10u, 11u, +}; - 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; +static const uint8_t +WUFFS_JPEG__DEFAULT_HUFF_TABLE_DC_CHROMA[29] WUFFS_BASE__POTENTIALLY_UNUSED = { + 1u, 0u, 3u, 1u, 1u, 1u, 1u, 1u, + 1u, 1u, 1u, 1u, 0u, 0u, 0u, 0u, + 0u, 0u, 1u, 2u, 3u, 4u, 5u, 6u, + 7u, 8u, 9u, 10u, 11u, +}; - goto exit; - exit: - if (wuffs_base__status__is_error(&status)) { - self->private_impl.magic = WUFFS_BASE__DISABLED; - } - return status; -} +static const uint8_t +WUFFS_JPEG__DEFAULT_HUFF_TABLE_AC_LUMA[179] WUFFS_BASE__POTENTIALLY_UNUSED = { + 16u, 0u, 2u, 1u, 3u, 3u, 2u, 4u, + 3u, 5u, 5u, 4u, 4u, 0u, 0u, 1u, + 125u, 1u, 2u, 3u, 0u, 4u, 17u, 5u, + 18u, 33u, 49u, 65u, 6u, 19u, 81u, 97u, + 7u, 34u, 113u, 20u, 50u, 129u, 145u, 161u, + 8u, 35u, 66u, 177u, 193u, 21u, 82u, 209u, + 240u, 36u, 51u, 98u, 114u, 130u, 9u, 10u, + 22u, 23u, 24u, 25u, 26u, 37u, 38u, 39u, + 40u, 41u, 42u, 52u, 53u, 54u, 55u, 56u, + 57u, 58u, 67u, 68u, 69u, 70u, 71u, 72u, + 73u, 74u, 83u, 84u, 85u, 86u, 87u, 88u, + 89u, 90u, 99u, 100u, 101u, 102u, 103u, 104u, + 105u, 106u, 115u, 116u, 117u, 118u, 119u, 120u, + 121u, 122u, 131u, 132u, 133u, 134u, 135u, 136u, + 137u, 138u, 146u, 147u, 148u, 149u, 150u, 151u, + 152u, 153u, 154u, 162u, 163u, 164u, 165u, 166u, + 167u, 168u, 169u, 170u, 178u, 179u, 180u, 181u, + 182u, 183u, 184u, 185u, 186u, 194u, 195u, 196u, + 197u, 198u, 199u, 200u, 201u, 202u, 210u, 211u, + 212u, 213u, 214u, 215u, 216u, 217u, 218u, 225u, + 226u, 227u, 228u, 229u, 230u, 231u, 232u, 233u, + 234u, 241u, 242u, 243u, 244u, 245u, 246u, 247u, + 248u, 249u, 250u, +}; -// -------- func jpeg.decoder.do_decode_frame_config +static const uint8_t +WUFFS_JPEG__DEFAULT_HUFF_TABLE_AC_CHROMA[179] WUFFS_BASE__POTENTIALLY_UNUSED = { + 17u, 0u, 2u, 1u, 2u, 4u, 4u, 3u, + 4u, 7u, 5u, 4u, 4u, 0u, 1u, 2u, + 119u, 0u, 1u, 2u, 3u, 17u, 4u, 5u, + 33u, 49u, 6u, 18u, 65u, 81u, 7u, 97u, + 113u, 19u, 34u, 50u, 129u, 8u, 20u, 66u, + 145u, 161u, 177u, 193u, 9u, 35u, 51u, 82u, + 240u, 21u, 98u, 114u, 209u, 10u, 22u, 36u, + 52u, 225u, 37u, 241u, 23u, 24u, 25u, 26u, + 38u, 39u, 40u, 41u, 42u, 53u, 54u, 55u, + 56u, 57u, 58u, 67u, 68u, 69u, 70u, 71u, + 72u, 73u, 74u, 83u, 84u, 85u, 86u, 87u, + 88u, 89u, 90u, 99u, 100u, 101u, 102u, 103u, + 104u, 105u, 106u, 115u, 116u, 117u, 118u, 119u, + 120u, 121u, 122u, 130u, 131u, 132u, 133u, 134u, + 135u, 136u, 137u, 138u, 146u, 147u, 148u, 149u, + 150u, 151u, 152u, 153u, 154u, 162u, 163u, 164u, + 165u, 166u, 167u, 168u, 169u, 170u, 178u, 179u, + 180u, 181u, 182u, 183u, 184u, 185u, 186u, 194u, + 195u, 196u, 197u, 198u, 199u, 200u, 201u, 202u, + 210u, 211u, 212u, 213u, 214u, 215u, 216u, 217u, + 218u, 226u, 227u, 228u, 229u, 230u, 231u, 232u, + 233u, 234u, 242u, 243u, 244u, 245u, 246u, 247u, + 248u, 249u, 250u, +}; + +#define WUFFS_JPEG__QUIRKS_BASE 1162824704u + +// ---------------- Private Initializer Prototypes + +// ---------------- Private Function Prototypes WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_jpeg__decoder__do_decode_frame_config( +static wuffs_base__empty_struct +wuffs_jpeg__decoder__decode_idct( wuffs_jpeg__decoder* self, - wuffs_base__frame_config* a_dst, - wuffs_base__io_buffer* a_src) { - wuffs_base__status status = wuffs_base__make_status(NULL); + wuffs_base__slice_u8 a_dst_buffer, + uint64_t a_dst_stride, + uint32_t a_q); - 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; - } +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_jpeg__decoder__decode_idct__choosy_default( + wuffs_jpeg__decoder* self, + wuffs_base__slice_u8 a_dst_buffer, + uint64_t a_dst_stride, + uint32_t a_q); - uint32_t coro_susp_point = self->private_impl.p_do_decode_frame_config; - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; +#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V3) +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_jpeg__decoder__decode_idct_x86_avx2( + wuffs_jpeg__decoder* self, + wuffs_base__slice_u8 a_dst_buffer, + uint64_t a_dst_stride, + uint32_t a_q); +#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V3) - 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_jpeg__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 (self->private_impl.f_frame_config_io_position != 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, - self->private_impl.f_frame_config_io_position, - 0u, - true, - false, - 4278190080u); - } - self->private_impl.f_call_sequence = 64u; +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_jpeg__decoder__do_decode_image_config( + wuffs_jpeg__decoder* self, + wuffs_base__image_config* a_dst, + wuffs_base__io_buffer* a_src); - ok: - self->private_impl.p_do_decode_frame_config = 0; - goto exit; - } +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_jpeg__decoder__decode_dqt( + wuffs_jpeg__decoder* self, + wuffs_base__io_buffer* a_src); - goto suspend; - suspend: - self->private_impl.p_do_decode_frame_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_jpeg__decoder__decode_dri( + wuffs_jpeg__decoder* self, + wuffs_base__io_buffer* a_src); - goto exit; - exit: - if (a_src && a_src->data.ptr) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_jpeg__decoder__decode_appn( + wuffs_jpeg__decoder* self, + wuffs_base__io_buffer* a_src, + uint8_t a_marker); - return status; -} +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_jpeg__decoder__decode_sof( + wuffs_jpeg__decoder* self, + wuffs_base__io_buffer* a_src); -// -------- func jpeg.decoder.decode_frame +WUFFS_BASE__GENERATED_C_CODE +static uint32_t +wuffs_jpeg__decoder__quantize_dimension( + const wuffs_jpeg__decoder* self, + uint32_t a_width, + uint8_t a_h, + uint8_t a_max_incl_h); WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_jpeg__decoder__decode_frame( +static wuffs_base__status +wuffs_jpeg__decoder__do_decode_frame_config( + wuffs_jpeg__decoder* self, + wuffs_base__frame_config* a_dst, + wuffs_base__io_buffer* a_src); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_jpeg__decoder__do_decode_frame( wuffs_jpeg__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__decode_frame_options* a_opts); - wuffs_base__status v_ddf_status = wuffs_base__make_status(NULL); - wuffs_base__status v_swizzle_status = wuffs_base__make_status(NULL); - uint32_t v_scan_count = 0; +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_jpeg__decoder__decode_dht( + wuffs_jpeg__decoder* self, + wuffs_base__io_buffer* a_src); - uint32_t coro_susp_point = self->private_impl.p_decode_frame; - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; +WUFFS_BASE__GENERATED_C_CODE +static bool +wuffs_jpeg__decoder__calculate_huff_tables( + wuffs_jpeg__decoder* self, + uint8_t a_tc4_th, + uint32_t a_total_count); - while (true) { - v_scan_count = self->private_impl.f_scan_count; - { - wuffs_base__status t_0 = wuffs_jpeg__decoder__do_decode_frame(self, - a_dst, - a_src, - a_blend, - a_workbuf, - a_opts); - v_ddf_status = t_0; - } - if ((v_ddf_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) { - v_ddf_status = wuffs_base__make_status(wuffs_jpeg__error__truncated_input); - } - if ( ! self->private_impl.f_swizzle_immediately && (wuffs_base__status__is_error(&v_ddf_status) || (v_scan_count < self->private_impl.f_scan_count))) { - if (self->private_impl.f_sof_marker >= 194u) { - wuffs_jpeg__decoder__apply_progressive_idct(self, a_workbuf); - } - if (self->private_impl.f_num_components == 1u) { - v_swizzle_status = wuffs_jpeg__decoder__swizzle_gray(self, - a_dst, - a_workbuf, - 0u, - 4294967295u, - 0u, - 4294967295u, - ((uint64_t)(self->private_impl.f_components_workbuf_widths[0u]))); - } else { - v_swizzle_status = wuffs_jpeg__decoder__swizzle_colorful(self, - a_dst, - a_workbuf, - 0u, - 4294967295u, - 0u, - 4294967295u); - } - if (wuffs_base__status__is_error(&v_ddf_status)) { - status = v_ddf_status; - goto exit; - } else if (wuffs_base__status__is_error(&v_swizzle_status)) { - status = v_swizzle_status; - goto exit; - } - } - status = v_ddf_status; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1); - } +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_jpeg__decoder__decode_sos( + wuffs_jpeg__decoder* self, + wuffs_base__pixel_buffer* a_dst, + wuffs_base__io_buffer* a_src, + wuffs_base__slice_u8 a_workbuf); - ok: - self->private_impl.p_decode_frame = 0; - goto exit; - } +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_jpeg__decoder__prepare_scan( + wuffs_jpeg__decoder* self, + wuffs_base__io_buffer* a_src); - 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; +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_jpeg__decoder__use_default_huffman_table( + wuffs_jpeg__decoder* self, + uint8_t a_tc4_th); - goto exit; - exit: - if (wuffs_base__status__is_error(&status)) { - self->private_impl.magic = WUFFS_BASE__DISABLED; - } - return status; -} +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_jpeg__decoder__calculate_single_component_scan_fields( + wuffs_jpeg__decoder* self); -// -------- func jpeg.decoder.do_decode_frame +WUFFS_BASE__GENERATED_C_CODE +static bool +wuffs_jpeg__decoder__calculate_multiple_component_scan_fields( + wuffs_jpeg__decoder* self); WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_jpeg__decoder__do_decode_frame( +static wuffs_base__empty_struct +wuffs_jpeg__decoder__fill_bitstream( wuffs_jpeg__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__io_buffer* a_src, - wuffs_base__pixel_blend a_blend, + wuffs_base__io_buffer* a_src); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_jpeg__decoder__load_mcu_blocks_for_single_component( + wuffs_jpeg__decoder* self, + uint32_t a_mx, + uint32_t a_my, wuffs_base__slice_u8 a_workbuf, - wuffs_base__decode_frame_options* a_opts) { - wuffs_base__status status = wuffs_base__make_status(NULL); + uint32_t a_csel); - uint32_t v_pixfmt = 0; - wuffs_base__status v_status = wuffs_base__make_status(NULL); - uint8_t v_c8 = 0; - uint8_t v_marker = 0; +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_jpeg__decoder__load_mcu_blocks_for_single_component__choosy_default( + wuffs_jpeg__decoder* self, + uint32_t a_mx, + uint32_t a_my, + wuffs_base__slice_u8 a_workbuf, + uint32_t a_csel); - 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; - } +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_jpeg__decoder__load_mcu_blocks( + wuffs_jpeg__decoder* self, + uint32_t a_mx, + uint32_t a_my, + wuffs_base__slice_u8 a_workbuf); - uint32_t coro_susp_point = self->private_impl.p_do_decode_frame; - if (coro_susp_point) { - v_marker = self->private_data.s_do_decode_frame.v_marker; - } - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_jpeg__decoder__save_mcu_blocks( + wuffs_jpeg__decoder* self, + uint32_t a_mx, + uint32_t a_my, + wuffs_base__slice_u8 a_workbuf); - if (self->private_impl.f_call_sequence == 64u) { - } else if (self->private_impl.f_call_sequence < 64u) { - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - status = wuffs_jpeg__decoder__do_decode_frame_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 { - status = wuffs_base__make_status(wuffs_base__note__end_of_data); - goto ok; - } - v_pixfmt = 536870920u; - if (self->private_impl.f_num_components > 1u) { - v_pixfmt = 2415954056u; - } - 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_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024)), - wuffs_base__utility__make_pixel_format(v_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; - } - self->private_impl.f_swizzle_immediately = false; - if (self->private_impl.f_components_workbuf_offsets[8u] > ((uint64_t)(a_workbuf.len))) { - if (self->private_impl.f_sof_marker >= 194u) { - status = wuffs_base__make_status(wuffs_base__error__bad_workbuf_length); - goto exit; - } - self->private_impl.f_swizzle_immediately = self->private_impl.f_use_lower_quality; - self->private_impl.f_swizzle_immediately_status = wuffs_base__make_status(NULL); - } else if (self->private_impl.f_components_workbuf_offsets[4u] < self->private_impl.f_components_workbuf_offsets[8u]) { - wuffs_private_impl__bulk_memset(a_workbuf.ptr + self->private_impl.f_components_workbuf_offsets[4u], (self->private_impl.f_components_workbuf_offsets[8u] - self->private_impl.f_components_workbuf_offsets[4u]), 0u); - } - if (self->private_impl.f_components_workbuf_offsets[4u] <= ((uint64_t)(a_workbuf.len))) { - wuffs_private_impl__bulk_memset(a_workbuf.ptr, self->private_impl.f_components_workbuf_offsets[4u], 128u); - } - while (true) { - while (true) { - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_0 = *iop_a_src++; - v_c8 = t_0; - } - if (v_c8 == 255u) { - break; - } - } - while (true) { - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_1 = *iop_a_src++; - v_c8 = t_1; - } - if (v_c8 != 255u) { - v_marker = v_c8; - break; - } - } - if (v_marker == 0u) { - continue; - } else if ((208u <= v_marker) && (v_marker <= 217u)) { - if (v_marker <= 215u) { - continue; - } - } else { - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); - uint32_t t_2; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { - t_2 = ((uint32_t)(wuffs_base__peek_u16be__no_bounds_check(iop_a_src))); - iop_a_src += 2; - } else { - self->private_data.s_do_decode_frame.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); - 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_frame.scratch; - uint32_t num_bits_2 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_2); - if (num_bits_2 == 8) { - t_2 = ((uint32_t)(*scratch >> 48)); - break; - } - num_bits_2 += 8u; - *scratch |= ((uint64_t)(num_bits_2)); - } - } - self->private_impl.f_payload_length = t_2; - } - if (self->private_impl.f_payload_length < 2u) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_marker); - goto exit; - } - self->private_impl.f_payload_length -= 2u; - } - if (v_marker < 192u) { - status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_marker); - goto exit; - } else if (v_marker < 208u) { - if (v_marker == 196u) { - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); - status = wuffs_jpeg__decoder__decode_dht(self, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; - } - continue; - } else if (v_marker == 200u) { - status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_marker); - goto exit; - } - status = wuffs_base__make_status(wuffs_jpeg__error__bad_sof_marker); - goto exit; - } else if (v_marker < 224u) { - if (v_marker < 217u) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_marker); - goto exit; - } else if (v_marker == 217u) { - break; - } else if (v_marker == 218u) { - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); - status = wuffs_jpeg__decoder__decode_sos(self, a_dst, a_src, a_workbuf); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; - } - continue; - } else if (v_marker == 219u) { - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); - status = wuffs_jpeg__decoder__decode_dqt(self, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; - } - continue; - } else if (v_marker == 221u) { - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); - status = wuffs_jpeg__decoder__decode_dri(self, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; - } - continue; - } else { - status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_marker); - goto exit; - } - } else if (v_marker < 240u) { - } else { - if (v_marker == 254u) { - } else { - status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_marker); - goto exit; - } - } - self->private_data.s_do_decode_frame.scratch = self->private_impl.f_payload_length; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10); - if (self->private_data.s_do_decode_frame.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { - self->private_data.s_do_decode_frame.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); - iop_a_src = io2_a_src; - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - iop_a_src += self->private_data.s_do_decode_frame.scratch; - self->private_impl.f_payload_length = 0u; - } - self->private_impl.f_call_sequence = 96u; +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_jpeg__decoder__skip_past_the_next_restart_marker( + wuffs_jpeg__decoder* self, + wuffs_base__io_buffer* a_src); - ok: - self->private_impl.p_do_decode_frame = 0; - goto exit; - } +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_jpeg__decoder__apply_progressive_idct( + wuffs_jpeg__decoder* self, + wuffs_base__slice_u8 a_workbuf); - goto suspend; - suspend: - self->private_impl.p_do_decode_frame = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; - self->private_data.s_do_decode_frame.v_marker = v_marker; +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_jpeg__decoder__swizzle_gray( + wuffs_jpeg__decoder* self, + wuffs_base__pixel_buffer* a_dst, + wuffs_base__slice_u8 a_workbuf, + uint32_t a_x0, + uint32_t a_x1, + uint32_t a_y0, + uint32_t a_y1, + uint64_t a_stride); - goto exit; - exit: - if (a_src && a_src->data.ptr) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_jpeg__decoder__swizzle_colorful( + wuffs_jpeg__decoder* self, + wuffs_base__pixel_buffer* a_dst, + wuffs_base__slice_u8 a_workbuf, + uint32_t a_x0, + uint32_t a_x1, + uint32_t a_y0, + uint32_t a_y1); - return status; -} +WUFFS_BASE__GENERATED_C_CODE +static bool +wuffs_jpeg__decoder__top_left_quants_has_zero( + const wuffs_jpeg__decoder* self, + uint32_t a_q); -// -------- func jpeg.decoder.decode_dht +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_jpeg__decoder__load_mcu_blocks_for_single_component_smooth( + wuffs_jpeg__decoder* self, + uint32_t a_mx, + uint32_t a_my, + wuffs_base__slice_u8 a_workbuf, + uint32_t a_csel); WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_jpeg__decoder__decode_dht( +static uint32_t +wuffs_jpeg__decoder__decode_mcu( wuffs_jpeg__decoder* self, - wuffs_base__io_buffer* a_src) { - wuffs_base__status status = wuffs_base__make_status(NULL); + wuffs_base__pixel_buffer* a_dst, + wuffs_base__slice_u8 a_workbuf, + uint32_t a_mx, + uint32_t a_my); - uint8_t v_c8 = 0; - uint8_t v_tc = 0; - uint8_t v_th = 0; - uint8_t v_tc4_th = 0; - uint32_t v_working_total_count = 0; - uint32_t v_total_count = 0; - uint32_t v_i = 0; - bool v_failed = false; +WUFFS_BASE__GENERATED_C_CODE +static uint32_t +wuffs_jpeg__decoder__decode_mcu__choosy_default( + wuffs_jpeg__decoder* self, + wuffs_base__pixel_buffer* a_dst, + wuffs_base__slice_u8 a_workbuf, + uint32_t a_mx, + uint32_t a_my); - 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; - } +WUFFS_BASE__GENERATED_C_CODE +static uint32_t +wuffs_jpeg__decoder__decode_mcu_progressive_ac_high_bits( + wuffs_jpeg__decoder* self, + wuffs_base__pixel_buffer* a_dst, + wuffs_base__slice_u8 a_workbuf, + uint32_t a_mx, + uint32_t a_my); - uint32_t coro_susp_point = self->private_impl.p_decode_dht; - if (coro_susp_point) { - v_tc4_th = self->private_data.s_decode_dht.v_tc4_th; - v_total_count = self->private_data.s_decode_dht.v_total_count; - v_i = self->private_data.s_decode_dht.v_i; - } - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; +WUFFS_BASE__GENERATED_C_CODE +static uint32_t +wuffs_jpeg__decoder__decode_mcu_progressive_ac_low_bit( + wuffs_jpeg__decoder* self, + wuffs_base__pixel_buffer* a_dst, + wuffs_base__slice_u8 a_workbuf, + uint32_t a_mx, + uint32_t a_my); - if (self->private_impl.f_sof_marker == 0u) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_dht_marker); - goto exit; - } - while (self->private_impl.f_payload_length > 0u) { - if (self->private_impl.f_payload_length < 17u) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_dht_marker); - goto exit; - } - self->private_impl.f_payload_length -= 17u; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_0 = *iop_a_src++; - v_c8 = t_0; - } - if ((((uint8_t)(v_c8 >> 4u)) > 1u) || (((uint8_t)(v_c8 & 15u)) > 3u)) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_dht_marker); - goto exit; - } - v_tc = ((uint8_t)(v_c8 >> 4u)); - v_th = ((uint8_t)(v_c8 & 15u)); - v_tc4_th = ((uint8_t)(((uint8_t)(((uint8_t)(v_tc * 4u)) | v_th)))); - if ((self->private_impl.f_sof_marker == 192u) && (((uint8_t)(v_tc4_th & 3u)) > 1u)) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_dht_marker); - goto exit; - } - v_i = 0u; - while (v_i < 16u) { - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_1 = *iop_a_src++; - self->private_data.f_dht_temp_counts[v_i] = t_1; - } - v_i += 1u; - } - v_working_total_count = 0u; - v_i = 0u; - while (v_i < 16u) { - v_working_total_count = ((v_working_total_count + ((uint32_t)(self->private_data.f_dht_temp_counts[v_i]))) & 65535u); - v_i += 1u; - } - if ((v_working_total_count <= 0u) || (256u < v_working_total_count)) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_dht_marker); - goto exit; - } - v_total_count = v_working_total_count; - if (self->private_impl.f_payload_length < v_total_count) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_dht_marker); - goto exit; - } - self->private_impl.f_payload_length -= v_total_count; - v_i = 0u; - while (v_i < v_total_count) { - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_2 = *iop_a_src++; - self->private_impl.f_huff_tables_symbols[v_tc4_th][v_i] = t_2; - } - v_i += 1u; - } - while (v_i < 256u) { - self->private_impl.f_huff_tables_symbols[v_tc4_th][v_i] = 0u; - v_i += 1u; - } - if (((uint8_t)(v_tc4_th & 4u)) == 0u) { - v_i = 0u; - while (v_i < v_total_count) { - if (self->private_impl.f_huff_tables_symbols[v_tc4_th][v_i] > 15u) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_dht_marker); - goto exit; - } - v_i += 1u; - } - } - v_failed = wuffs_jpeg__decoder__calculate_huff_tables(self, v_tc4_th, v_total_count); - if (v_failed) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_dht_marker); - goto exit; - } - self->private_impl.f_seen_dht[v_tc4_th] = true; - } - - goto ok; - ok: - self->private_impl.p_decode_dht = 0; - goto exit; - } +WUFFS_BASE__GENERATED_C_CODE +static uint32_t +wuffs_jpeg__decoder__decode_mcu_progressive_dc_high_bits( + wuffs_jpeg__decoder* self, + wuffs_base__pixel_buffer* a_dst, + wuffs_base__slice_u8 a_workbuf, + uint32_t a_mx, + uint32_t a_my); - goto suspend; - suspend: - self->private_impl.p_decode_dht = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; - self->private_data.s_decode_dht.v_tc4_th = v_tc4_th; - self->private_data.s_decode_dht.v_total_count = v_total_count; - self->private_data.s_decode_dht.v_i = v_i; +WUFFS_BASE__GENERATED_C_CODE +static uint32_t +wuffs_jpeg__decoder__decode_mcu_progressive_dc_low_bit( + wuffs_jpeg__decoder* self, + wuffs_base__pixel_buffer* a_dst, + wuffs_base__slice_u8 a_workbuf, + uint32_t a_mx, + uint32_t a_my); - goto exit; - exit: - if (a_src && a_src->data.ptr) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } +// ---------------- VTables - return status; -} +const wuffs_base__image_decoder__func_ptrs +wuffs_jpeg__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_jpeg__decoder__decode_frame), + (wuffs_base__status(*)(void*, + wuffs_base__frame_config*, + wuffs_base__io_buffer*))(&wuffs_jpeg__decoder__decode_frame_config), + (wuffs_base__status(*)(void*, + wuffs_base__image_config*, + wuffs_base__io_buffer*))(&wuffs_jpeg__decoder__decode_image_config), + (wuffs_base__rect_ie_u32(*)(const void*))(&wuffs_jpeg__decoder__frame_dirty_rect), + (uint64_t(*)(const void*, + uint32_t))(&wuffs_jpeg__decoder__get_quirk), + (uint32_t(*)(const void*))(&wuffs_jpeg__decoder__num_animation_loops), + (uint64_t(*)(const void*))(&wuffs_jpeg__decoder__num_decoded_frame_configs), + (uint64_t(*)(const void*))(&wuffs_jpeg__decoder__num_decoded_frames), + (wuffs_base__status(*)(void*, + uint64_t, + uint64_t))(&wuffs_jpeg__decoder__restart_frame), + (wuffs_base__status(*)(void*, + uint32_t, + uint64_t))(&wuffs_jpeg__decoder__set_quirk), + (wuffs_base__empty_struct(*)(void*, + uint32_t, + bool))(&wuffs_jpeg__decoder__set_report_metadata), + (wuffs_base__status(*)(void*, + wuffs_base__io_buffer*, + wuffs_base__more_information*, + wuffs_base__io_buffer*))(&wuffs_jpeg__decoder__tell_me_more), + (wuffs_base__range_ii_u64(*)(const void*))(&wuffs_jpeg__decoder__workbuf_len), +}; -// -------- func jpeg.decoder.calculate_huff_tables +// ---------------- Initializer Implementations -WUFFS_BASE__GENERATED_C_CODE -static bool -wuffs_jpeg__decoder__calculate_huff_tables( +wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT +wuffs_jpeg__decoder__initialize( wuffs_jpeg__decoder* self, - uint8_t a_tc4_th, - uint32_t a_total_count) { - uint32_t v_i = 0; - uint8_t v_j = 0; - uint8_t v_k = 0; - uint32_t v_bit_length_minus_one = 0; - uint8_t v_bit_length = 0; - uint32_t v_bit_string = 0; - uint32_t v_slow = 0; - uint8_t v_prefix = 0; - uint16_t v_fast = 0; - uint32_t v_reps = 0; - - v_i = 0u; - v_k = 0u; - v_bit_length_minus_one = 0u; - while (v_i < a_total_count) { - while (v_k >= self->private_data.f_dht_temp_counts[v_bit_length_minus_one]) { - v_k = 0u; - v_bit_length_minus_one = ((v_bit_length_minus_one + 1u) & 15u); - } -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - v_k += 1u; -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - self->private_data.f_dht_temp_bit_lengths[v_i] = ((uint8_t)((v_bit_length_minus_one + 1u))); - v_i += 1u; - } - v_bit_length = 0u; - v_bit_string = 0u; - v_i = 0u; - while (v_i < a_total_count) { - while (v_bit_length < self->private_data.f_dht_temp_bit_lengths[v_i]) { - if (v_bit_length >= 16u) { - return true; - } -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - v_bit_length += 1u; -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - v_bit_string <<= 1u; - } - self->private_data.f_dht_temp_bit_strings[v_i] = ((uint16_t)(v_bit_string)); - v_bit_string += 1u; - if ((v_bit_string >> v_bit_length) > 0u) { - return true; - } - v_i += 1u; + size_t sizeof_star_self, + uint64_t wuffs_version, + uint32_t options){ + if (!self) { + return wuffs_base__make_status(wuffs_base__error__bad_receiver); } - v_k = 0u; - v_bit_length_minus_one = 0u; - while (true) { - if (self->private_data.f_dht_temp_counts[v_bit_length_minus_one] == 0u) { - self->private_impl.f_huff_tables_slow[a_tc4_th][v_bit_length_minus_one] = 0u; - } else { - v_slow = (255u & ((uint32_t)(((uint32_t)(v_k)) - ((uint32_t)(self->private_data.f_dht_temp_bit_strings[v_k]))))); -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - v_k += self->private_data.f_dht_temp_counts[v_bit_length_minus_one]; -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - self->private_impl.f_huff_tables_slow[a_tc4_th][v_bit_length_minus_one] = (v_slow | ((((uint32_t)(self->private_data.f_dht_temp_bit_strings[((uint8_t)(v_k - 1u))])) + 1u) << 8u)); - } - v_bit_length_minus_one = ((v_bit_length_minus_one + 1u) & 15u); - if (v_bit_length_minus_one == 0u) { - break; - } + if (sizeof(*self) != sizeof_star_self) { + return wuffs_base__make_status(wuffs_base__error__bad_sizeof_receiver); } - v_i = 0u; - while (v_i < 256u) { - self->private_impl.f_huff_tables_fast[a_tc4_th][v_i] = 65535u; - v_i += 1u; + 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); } - v_j = 0u; - v_bit_length_minus_one = 0u; - while (v_bit_length_minus_one < 8u) { - v_k = 0u; - while (v_k < self->private_data.f_dht_temp_counts[v_bit_length_minus_one]) { - v_prefix = ((uint8_t)((((uint32_t)(self->private_data.f_dht_temp_bit_strings[v_j])) << (7u - v_bit_length_minus_one)))); - v_fast = ((uint16_t)(((((uint32_t)((v_bit_length_minus_one + 1u))) << 8u) | ((uint32_t)(self->private_impl.f_huff_tables_symbols[a_tc4_th][v_j]))))); - v_reps = (((uint32_t)(1u)) << (7u - v_bit_length_minus_one)); - while (v_reps > 0u) { - self->private_impl.f_huff_tables_fast[a_tc4_th][v_prefix] = v_fast; -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - v_prefix += 1u; -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - v_reps -= 1u; - } -#if defined(__GNUC__) + + 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 "-Wconversion" +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" #endif - v_k += 1u; - v_j += 1u; -#if defined(__GNUC__) + 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)); } - v_bit_length_minus_one += 1u; } - return false; -} - -// -------- func jpeg.decoder.decode_sos -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_jpeg__decoder__decode_sos( - wuffs_jpeg__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__io_buffer* a_src, - wuffs_base__slice_u8 a_workbuf) { - wuffs_base__status status = wuffs_base__make_status(NULL); + self->private_impl.choosy_decode_idct = &wuffs_jpeg__decoder__decode_idct__choosy_default; + self->private_impl.choosy_load_mcu_blocks_for_single_component = &wuffs_jpeg__decoder__load_mcu_blocks_for_single_component__choosy_default; + self->private_impl.choosy_decode_mcu = &wuffs_jpeg__decoder__decode_mcu__choosy_default; - uint32_t v_my = 0; - uint32_t v_mx = 0; - uint32_t v_decode_mcu_result = 0; - uint32_t v_bitstream_length = 0; + 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_jpeg__decoder__func_ptrs_for__wuffs_base__image_decoder); + return wuffs_base__make_status(NULL); +} - uint32_t coro_susp_point = self->private_impl.p_decode_sos; - if (coro_susp_point) { - v_my = self->private_data.s_decode_sos.v_my; - v_mx = self->private_data.s_decode_sos.v_mx; +wuffs_jpeg__decoder* +wuffs_jpeg__decoder__alloc(void) { + wuffs_jpeg__decoder* x = + (wuffs_jpeg__decoder*)(calloc(1, sizeof(wuffs_jpeg__decoder))); + if (!x) { + return NULL; } - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - - if (self->private_impl.f_scan_count >= 32u) { - status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_scan_count); - goto exit; - } else if ((self->private_impl.f_scan_count > 0u) && ! self->private_impl.f_expect_multiple_scans) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_scan_count); - goto exit; - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - status = wuffs_jpeg__decoder__prepare_scan(self, a_src); - if (status.repr) { - goto suspend; - } - self->private_impl.f_next_restart_marker = 0u; - self->private_impl.f_mcu_previous_dc_values[0u] = 0u; - self->private_impl.f_mcu_previous_dc_values[1u] = 0u; - self->private_impl.f_mcu_previous_dc_values[2u] = 0u; - self->private_impl.f_mcu_previous_dc_values[3u] = 0u; - self->private_impl.f_restarts_remaining = self->private_impl.f_restart_interval; - self->private_impl.f_eob_run = 0u; - self->private_impl.f_bitstream_bits = 0u; - self->private_impl.f_bitstream_n_bits = 0u; - self->private_impl.f_bitstream_ri = 0u; - self->private_impl.f_bitstream_wi = 0u; - self->private_impl.f_bitstream_padding = 12345u; - wuffs_jpeg__decoder__fill_bitstream(self, a_src); - v_my = 0u; - while (v_my < self->private_impl.f_scan_height_in_mcus) { - v_mx = 0u; - while (v_mx < self->private_impl.f_scan_width_in_mcus) { - self->private_impl.f_mcu_current_block = 0u; - self->private_impl.f_mcu_zig_index = ((uint32_t)(self->private_impl.f_scan_ss)); - if (self->private_impl.f_sof_marker >= 194u) { - wuffs_jpeg__decoder__load_mcu_blocks(self, v_mx, v_my, a_workbuf); - } - while (true) { - v_decode_mcu_result = wuffs_jpeg__decoder__decode_mcu(self, - a_dst, - a_workbuf, - v_mx, - v_my); - if (v_decode_mcu_result == 0u) { - break; - } else if (v_decode_mcu_result == 1u) { - } else if (v_decode_mcu_result == 2u) { - status = wuffs_base__make_status(wuffs_jpeg__error__internal_error_inconsistent_decoder_state); - goto exit; - } else { - status = self->private_impl.f_swizzle_immediately_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; - } - while (true) { - v_bitstream_length = ((uint32_t)(self->private_impl.f_bitstream_wi - self->private_impl.f_bitstream_ri)); - wuffs_jpeg__decoder__fill_bitstream(self, a_src); - if (v_bitstream_length < ((uint32_t)(self->private_impl.f_bitstream_wi - self->private_impl.f_bitstream_ri))) { - break; - } else if (self->private_impl.f_bitstream_padding == 0u) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); - goto exit; - } else if ((a_src && a_src->meta.closed) && ! self->private_impl.f_bitstream_is_closed) { - if (self->private_impl.f_bitstream_wi < 1024u) { - wuffs_private_impl__bulk_memset(&self->private_data.f_bitstream_buffer[self->private_impl.f_bitstream_wi], 264u, 0u); - self->private_impl.f_bitstream_wi += 264u; - self->private_impl.f_bitstream_is_closed = true; - } - break; - } - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2); - } - } - if (self->private_impl.f_sof_marker >= 194u) { - wuffs_jpeg__decoder__save_mcu_blocks(self, v_mx, v_my, a_workbuf); - } - if (self->private_impl.f_restarts_remaining > 0u) { -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - self->private_impl.f_restarts_remaining -= 1u; -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - if (self->private_impl.f_restarts_remaining == 0u) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - status = wuffs_jpeg__decoder__skip_past_the_next_restart_marker(self, a_src); - if (status.repr) { - goto suspend; - } - self->private_impl.f_mcu_previous_dc_values[0u] = 0u; - self->private_impl.f_mcu_previous_dc_values[1u] = 0u; - self->private_impl.f_mcu_previous_dc_values[2u] = 0u; - self->private_impl.f_mcu_previous_dc_values[3u] = 0u; - self->private_impl.f_restarts_remaining = self->private_impl.f_restart_interval; - self->private_impl.f_eob_run = 0u; - self->private_impl.f_bitstream_bits = 0u; - self->private_impl.f_bitstream_n_bits = 0u; - self->private_impl.f_bitstream_ri = 0u; - self->private_impl.f_bitstream_wi = 0u; - self->private_impl.f_bitstream_padding = 12345u; - } - } - v_mx += 1u; - } - v_my += 1u; - } - wuffs_private_impl__u32__sat_add_indirect(&self->private_impl.f_scan_count, 1u); - - ok: - self->private_impl.p_decode_sos = 0; - goto exit; + if (wuffs_jpeg__decoder__initialize( + x, sizeof(wuffs_jpeg__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) { + free(x); + return NULL; } + return x; +} - goto suspend; - suspend: - self->private_impl.p_decode_sos = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; - self->private_data.s_decode_sos.v_my = v_my; - self->private_data.s_decode_sos.v_mx = v_mx; - - goto exit; - exit: - return status; +size_t +sizeof__wuffs_jpeg__decoder(void) { + return sizeof(wuffs_jpeg__decoder); } -// -------- func jpeg.decoder.prepare_scan +// ---------------- Function Implementations + +// -------- func jpeg.decoder.decode_idct WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_jpeg__decoder__prepare_scan( +static wuffs_base__empty_struct +wuffs_jpeg__decoder__decode_idct( wuffs_jpeg__decoder* self, - wuffs_base__io_buffer* a_src) { - wuffs_base__status status = wuffs_base__make_status(NULL); - - uint8_t v_c8 = 0; - uint32_t v_i = 0; - uint32_t v_j = 0; - uint32_t v_j_max_incl = 0; - bool v_failed = false; - - 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_prepare_scan; - if (coro_susp_point) { - v_i = self->private_data.s_prepare_scan.v_i; - } - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - - if ((self->private_impl.f_payload_length < 6u) || (self->private_impl.f_payload_length > 12u)) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); - goto exit; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_0 = *iop_a_src++; - v_c8 = t_0; - } - if ((v_c8 < 1u) || (v_c8 > 4u)) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); - goto exit; - } - self->private_impl.f_scan_num_components = ((uint32_t)(v_c8)); - if ((self->private_impl.f_scan_num_components > self->private_impl.f_num_components) || (self->private_impl.f_payload_length != (4u + (2u * self->private_impl.f_scan_num_components)))) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); - goto exit; - } - self->private_impl.f_payload_length = 0u; - v_i = 0u; - while (v_i < self->private_impl.f_scan_num_components) { - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_1 = *iop_a_src++; - v_c8 = t_1; - } - v_j = 0u; - while (true) { - if (v_j >= self->private_impl.f_num_components) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); - goto exit; - } - if (v_c8 == self->private_impl.f_components_c[v_j]) { - if ( ! self->private_impl.f_seen_dqt[self->private_impl.f_components_tq[v_j]]) { - status = wuffs_base__make_status(wuffs_jpeg__error__missing_quantization_table); - goto exit; - } - self->private_impl.f_scan_comps_cselector[v_i] = ((uint8_t)(v_j)); - break; - } - v_j += 1u; - } - v_j = 0u; - while (v_j < v_i) { - if (self->private_impl.f_scan_comps_cselector[v_i] == self->private_impl.f_scan_comps_cselector[v_j]) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); - goto exit; - } - v_j += 1u; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_2 = *iop_a_src++; - v_c8 = t_2; - } - if ((((uint8_t)(v_c8 >> 4u)) > 3u) || (((uint8_t)(v_c8 & 15u)) > 3u)) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); - goto exit; - } - self->private_impl.f_scan_comps_td[v_i] = ((uint8_t)(v_c8 >> 4u)); - self->private_impl.f_scan_comps_ta[v_i] = ((uint8_t)(v_c8 & 15u)); - if (self->private_impl.f_sof_marker == 192u) { - if ((self->private_impl.f_scan_comps_td[v_i] > 1u) || (self->private_impl.f_scan_comps_ta[v_i] > 1u)) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); - goto exit; - } - } - v_i += 1u; - } - if (self->private_impl.f_scan_count == 0u) { - self->private_impl.f_expect_multiple_scans = ((self->private_impl.f_sof_marker >= 194u) || (self->private_impl.f_scan_num_components < self->private_impl.f_num_components)); - } - if (self->private_impl.f_sof_marker < 194u) { - self->private_data.s_prepare_scan.scratch = 3u; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); - if (self->private_data.s_prepare_scan.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { - self->private_data.s_prepare_scan.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); - iop_a_src = io2_a_src; - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - iop_a_src += self->private_data.s_prepare_scan.scratch; - self->private_impl.f_scan_ss = 0u; - self->private_impl.f_scan_se = 63u; - self->private_impl.f_scan_ah = 0u; - self->private_impl.f_scan_al = 0u; - } else { - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_3 = *iop_a_src++; - v_c8 = t_3; - } - if (v_c8 > 63u) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); - goto exit; - } - self->private_impl.f_scan_ss = v_c8; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_4 = *iop_a_src++; - v_c8 = t_4; - } - if ((v_c8 > 63u) || (v_c8 < self->private_impl.f_scan_ss)) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); - goto exit; - } - self->private_impl.f_scan_se = v_c8; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_5 = *iop_a_src++; - v_c8 = t_5; - } - if ((((uint8_t)(v_c8 >> 4u)) > 14u) || (((uint8_t)(v_c8 & 15u)) > 13u)) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); - goto exit; - } - self->private_impl.f_scan_ah = ((uint8_t)(v_c8 >> 4u)); - self->private_impl.f_scan_al = ((uint8_t)(v_c8 & 15u)); - if (self->private_impl.f_scan_ah > 0u) { - if (((uint8_t)(self->private_impl.f_scan_ah - 1u)) != self->private_impl.f_scan_al) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); - goto exit; - } - } - if (self->private_impl.f_scan_ss == 0u) { - if (self->private_impl.f_scan_se != 0u) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); - goto exit; - } else if (self->private_impl.f_scan_ah == 0u) { - self->private_impl.choosy_decode_mcu = ( - &wuffs_jpeg__decoder__decode_mcu_progressive_dc_high_bits); - } else { - self->private_impl.choosy_decode_mcu = ( - &wuffs_jpeg__decoder__decode_mcu_progressive_dc_low_bit); - } - } else { - if (self->private_impl.f_scan_num_components != 1u) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); - goto exit; - } else if (self->private_impl.f_scan_ah == 0u) { - self->private_impl.choosy_decode_mcu = ( - &wuffs_jpeg__decoder__decode_mcu_progressive_ac_high_bits); - } else { - self->private_impl.choosy_decode_mcu = ( - &wuffs_jpeg__decoder__decode_mcu_progressive_ac_low_bit); - } - } - } - v_i = 0u; - while (v_i < self->private_impl.f_scan_num_components) { - if ((self->private_impl.f_scan_ss == 0u) && ! self->private_impl.f_seen_dht[((uint8_t)(0u | self->private_impl.f_scan_comps_td[v_i]))]) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); - status = wuffs_jpeg__decoder__use_default_huffman_table(self, ((uint8_t)(0u | self->private_impl.f_scan_comps_td[v_i]))); - if (status.repr) { - goto suspend; - } - } - if ((self->private_impl.f_scan_se != 0u) && ! self->private_impl.f_seen_dht[((uint8_t)(4u | self->private_impl.f_scan_comps_ta[v_i]))]) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); - status = wuffs_jpeg__decoder__use_default_huffman_table(self, ((uint8_t)(4u | self->private_impl.f_scan_comps_ta[v_i]))); - if (status.repr) { - goto suspend; - } - } - v_j = ((uint32_t)(self->private_impl.f_scan_ss)); - v_j_max_incl = ((uint32_t)(wuffs_base__u8__min(self->private_impl.f_scan_se, 9u))); - while (v_j <= v_j_max_incl) { - self->private_impl.f_block_smoothing_lowest_scan_al[self->private_impl.f_scan_comps_cselector[v_i]][v_j] = self->private_impl.f_scan_al; - v_j += 1u; - } - v_i += 1u; - } - if (self->private_impl.f_scan_num_components == 1u) { - wuffs_jpeg__decoder__calculate_single_component_scan_fields(self); - } else { - v_failed = wuffs_jpeg__decoder__calculate_multiple_component_scan_fields(self); - if (v_failed) { - status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); - goto exit; - } - } - - goto ok; - ok: - self->private_impl.p_prepare_scan = 0; - goto exit; - } - - goto suspend; - suspend: - self->private_impl.p_prepare_scan = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; - self->private_data.s_prepare_scan.v_i = v_i; - - 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 jpeg.decoder.use_default_huffman_table + wuffs_base__slice_u8 a_dst_buffer, + uint64_t a_dst_stride, + uint32_t a_q) { + return (*self->private_impl.choosy_decode_idct)(self, a_dst_buffer, a_dst_stride, a_q); +} WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_jpeg__decoder__use_default_huffman_table( +static wuffs_base__empty_struct +wuffs_jpeg__decoder__decode_idct__choosy_default( wuffs_jpeg__decoder* self, - uint8_t a_tc4_th) { - wuffs_base__status status = wuffs_base__make_status(NULL); - - wuffs_base__slice_u8 v_data = {0}; - wuffs_base__io_buffer u_r = wuffs_base__empty_io_buffer(); - wuffs_base__io_buffer* v_r = &u_r; - const uint8_t* iop_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - const uint8_t* io0_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - const uint8_t* io1_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - const uint8_t* io2_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - wuffs_base__status v_status = wuffs_base__make_status(NULL); + wuffs_base__slice_u8 a_dst_buffer, + uint64_t a_dst_stride, + uint32_t a_q) { + uint32_t v_bq0 = 0; + uint32_t v_bq2 = 0; + uint32_t v_bq4 = 0; + uint32_t v_bq6 = 0; + uint32_t v_ca = 0; + uint32_t v_cb2 = 0; + uint32_t v_cb6 = 0; + uint32_t v_ccp = 0; + uint32_t v_ccm = 0; + uint32_t v_cd0 = 0; + uint32_t v_cd1 = 0; + uint32_t v_cd2 = 0; + uint32_t v_cd3 = 0; + uint32_t v_bq1 = 0; + uint32_t v_bq3 = 0; + uint32_t v_bq5 = 0; + uint32_t v_bq7 = 0; + uint32_t v_ci51 = 0; + uint32_t v_ci53 = 0; + uint32_t v_ci71 = 0; + uint32_t v_ci73 = 0; + uint32_t v_cj = 0; + uint32_t v_ck1 = 0; + uint32_t v_ck3 = 0; + uint32_t v_ck5 = 0; + uint32_t v_ck7 = 0; + uint32_t v_cl51 = 0; + uint32_t v_cl73 = 0; + uint32_t v_in0 = 0; + uint32_t v_in2 = 0; + uint32_t v_in4 = 0; + uint32_t v_in6 = 0; + uint32_t v_ra = 0; + uint32_t v_rb2 = 0; + uint32_t v_rb6 = 0; + uint32_t v_rcp = 0; + uint32_t v_rcm = 0; + uint32_t v_rd0 = 0; + uint32_t v_rd1 = 0; + uint32_t v_rd2 = 0; + uint32_t v_rd3 = 0; + uint32_t v_in1 = 0; + uint32_t v_in3 = 0; + uint32_t v_in5 = 0; + uint32_t v_in7 = 0; + uint32_t v_ri51 = 0; + uint32_t v_ri53 = 0; + uint32_t v_ri71 = 0; + uint32_t v_ri73 = 0; + uint32_t v_rj = 0; + uint32_t v_rk1 = 0; + uint32_t v_rk3 = 0; + uint32_t v_rk5 = 0; + uint32_t v_rk7 = 0; + uint32_t v_rl51 = 0; + uint32_t v_rl73 = 0; + uint32_t v_intermediate[64] = {0}; - if (a_tc4_th == 0u) { - v_data = wuffs_base__make_slice_u8(wuffs_base__strip_const_from_u8_ptr(WUFFS_JPEG__DEFAULT_HUFF_TABLE_DC_LUMA), 29); - } else if (a_tc4_th == 1u) { - v_data = wuffs_base__make_slice_u8(wuffs_base__strip_const_from_u8_ptr(WUFFS_JPEG__DEFAULT_HUFF_TABLE_DC_CHROMA), 29); - } else if (a_tc4_th == 4u) { - v_data = wuffs_base__make_slice_u8(wuffs_base__strip_const_from_u8_ptr(WUFFS_JPEG__DEFAULT_HUFF_TABLE_AC_LUMA), 179); - } else if (a_tc4_th == 5u) { - v_data = wuffs_base__make_slice_u8(wuffs_base__strip_const_from_u8_ptr(WUFFS_JPEG__DEFAULT_HUFF_TABLE_AC_CHROMA), 179); + if (8u > a_dst_stride) { + return wuffs_base__make_empty_struct(); + } + if (0u == (self->private_data.f_mcu_blocks[0u][8u] | + self->private_data.f_mcu_blocks[0u][16u] | + self->private_data.f_mcu_blocks[0u][24u] | + self->private_data.f_mcu_blocks[0u][32u] | + self->private_data.f_mcu_blocks[0u][40u] | + self->private_data.f_mcu_blocks[0u][48u] | + self->private_data.f_mcu_blocks[0u][56u])) { + v_intermediate[0u] = ((uint32_t)(((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][0u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][0u])))) << 2u)); + v_intermediate[8u] = v_intermediate[0u]; + v_intermediate[16u] = v_intermediate[0u]; + v_intermediate[24u] = v_intermediate[0u]; + v_intermediate[32u] = v_intermediate[0u]; + v_intermediate[40u] = v_intermediate[0u]; + v_intermediate[48u] = v_intermediate[0u]; + v_intermediate[56u] = v_intermediate[0u]; } else { - status = wuffs_base__make_status(wuffs_jpeg__error__missing_huffman_table); - goto exit; + v_bq2 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][16u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][16u])))); + v_bq6 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][48u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][48u])))); + v_ca = ((uint32_t)(((uint32_t)(v_bq2 + v_bq6)) * 4433u)); + v_cb2 = ((uint32_t)(v_ca + ((uint32_t)(v_bq2 * 6270u)))); + v_cb6 = ((uint32_t)(v_ca - ((uint32_t)(v_bq6 * 15137u)))); + v_bq0 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][0u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][0u])))); + v_bq4 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][32u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][32u])))); + v_ccp = ((uint32_t)(((uint32_t)(v_bq0 + v_bq4)) << 13u)); + v_ccm = ((uint32_t)(((uint32_t)(v_bq0 - v_bq4)) << 13u)); + v_cd0 = ((uint32_t)(v_ccp + v_cb2)); + v_cd1 = ((uint32_t)(v_ccm + v_cb6)); + v_cd2 = ((uint32_t)(v_ccm - v_cb6)); + v_cd3 = ((uint32_t)(v_ccp - v_cb2)); + v_bq1 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][8u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][8u])))); + v_bq3 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][24u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][24u])))); + v_bq5 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][40u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][40u])))); + v_bq7 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][56u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][56u])))); + v_ci51 = ((uint32_t)(v_bq5 + v_bq1)); + v_ci53 = ((uint32_t)(v_bq5 + v_bq3)); + v_ci71 = ((uint32_t)(v_bq7 + v_bq1)); + v_ci73 = ((uint32_t)(v_bq7 + v_bq3)); + v_cj = ((uint32_t)(((uint32_t)(v_ci73 + v_ci51)) * 9633u)); + v_ck1 = ((uint32_t)(v_bq1 * 12299u)); + v_ck3 = ((uint32_t)(v_bq3 * 25172u)); + v_ck5 = ((uint32_t)(v_bq5 * 16819u)); + v_ck7 = ((uint32_t)(v_bq7 * 2446u)); + v_ci51 *= 4294964100u; + v_ci53 *= 4294946301u; + v_ci71 *= 4294959923u; + v_ci73 *= 4294951227u; + v_cl51 = ((uint32_t)(v_ci51 + v_cj)); + v_cl73 = ((uint32_t)(v_ci73 + v_cj)); + v_ck1 += ((uint32_t)(v_ci71 + v_cl51)); + v_ck3 += ((uint32_t)(v_ci53 + v_cl73)); + v_ck5 += ((uint32_t)(v_ci53 + v_cl51)); + v_ck7 += ((uint32_t)(v_ci71 + v_cl73)); + v_intermediate[0u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 + v_ck1)) + 1024u)), 11u); + v_intermediate[56u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 - v_ck1)) + 1024u)), 11u); + v_intermediate[8u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 + v_ck3)) + 1024u)), 11u); + v_intermediate[48u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 - v_ck3)) + 1024u)), 11u); + v_intermediate[16u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 + v_ck5)) + 1024u)), 11u); + v_intermediate[40u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 - v_ck5)) + 1024u)), 11u); + v_intermediate[24u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 + v_ck7)) + 1024u)), 11u); + v_intermediate[32u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 - v_ck7)) + 1024u)), 11u); } - { - wuffs_base__io_buffer* o_0_v_r = v_r; - const uint8_t* o_0_iop_v_r = iop_v_r; - const uint8_t* o_0_io0_v_r = io0_v_r; - const uint8_t* o_0_io1_v_r = io1_v_r; - const uint8_t* o_0_io2_v_r = io2_v_r; - v_r = wuffs_private_impl__io_reader__set( - &u_r, - &iop_v_r, - &io0_v_r, - &io1_v_r, - &io2_v_r, - v_data, - 0u); - self->private_impl.f_payload_length = ((uint32_t)((((uint64_t)(v_data.len)) & 65535u))); - { - wuffs_base__status t_0 = wuffs_jpeg__decoder__decode_dht(self, v_r); - v_status = t_0; - } - v_r = o_0_v_r; - iop_v_r = o_0_iop_v_r; - io0_v_r = o_0_io0_v_r; - io1_v_r = o_0_io1_v_r; - io2_v_r = o_0_io2_v_r; + if (0u == (self->private_data.f_mcu_blocks[0u][9u] | + self->private_data.f_mcu_blocks[0u][17u] | + self->private_data.f_mcu_blocks[0u][25u] | + self->private_data.f_mcu_blocks[0u][33u] | + self->private_data.f_mcu_blocks[0u][41u] | + self->private_data.f_mcu_blocks[0u][49u] | + self->private_data.f_mcu_blocks[0u][57u])) { + v_intermediate[1u] = ((uint32_t)(((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][1u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][1u])))) << 2u)); + v_intermediate[9u] = v_intermediate[1u]; + v_intermediate[17u] = v_intermediate[1u]; + v_intermediate[25u] = v_intermediate[1u]; + v_intermediate[33u] = v_intermediate[1u]; + v_intermediate[41u] = v_intermediate[1u]; + v_intermediate[49u] = v_intermediate[1u]; + v_intermediate[57u] = v_intermediate[1u]; + } else { + v_bq2 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][17u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][17u])))); + v_bq6 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][49u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][49u])))); + v_ca = ((uint32_t)(((uint32_t)(v_bq2 + v_bq6)) * 4433u)); + v_cb2 = ((uint32_t)(v_ca + ((uint32_t)(v_bq2 * 6270u)))); + v_cb6 = ((uint32_t)(v_ca - ((uint32_t)(v_bq6 * 15137u)))); + v_bq0 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][1u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][1u])))); + v_bq4 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][33u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][33u])))); + v_ccp = ((uint32_t)(((uint32_t)(v_bq0 + v_bq4)) << 13u)); + v_ccm = ((uint32_t)(((uint32_t)(v_bq0 - v_bq4)) << 13u)); + v_cd0 = ((uint32_t)(v_ccp + v_cb2)); + v_cd1 = ((uint32_t)(v_ccm + v_cb6)); + v_cd2 = ((uint32_t)(v_ccm - v_cb6)); + v_cd3 = ((uint32_t)(v_ccp - v_cb2)); + v_bq1 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][9u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][9u])))); + v_bq3 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][25u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][25u])))); + v_bq5 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][41u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][41u])))); + v_bq7 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][57u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][57u])))); + v_ci51 = ((uint32_t)(v_bq5 + v_bq1)); + v_ci53 = ((uint32_t)(v_bq5 + v_bq3)); + v_ci71 = ((uint32_t)(v_bq7 + v_bq1)); + v_ci73 = ((uint32_t)(v_bq7 + v_bq3)); + v_cj = ((uint32_t)(((uint32_t)(v_ci73 + v_ci51)) * 9633u)); + v_ck1 = ((uint32_t)(v_bq1 * 12299u)); + v_ck3 = ((uint32_t)(v_bq3 * 25172u)); + v_ck5 = ((uint32_t)(v_bq5 * 16819u)); + v_ck7 = ((uint32_t)(v_bq7 * 2446u)); + v_ci51 *= 4294964100u; + v_ci53 *= 4294946301u; + v_ci71 *= 4294959923u; + v_ci73 *= 4294951227u; + v_cl51 = ((uint32_t)(v_ci51 + v_cj)); + v_cl73 = ((uint32_t)(v_ci73 + v_cj)); + v_ck1 += ((uint32_t)(v_ci71 + v_cl51)); + v_ck3 += ((uint32_t)(v_ci53 + v_cl73)); + v_ck5 += ((uint32_t)(v_ci53 + v_cl51)); + v_ck7 += ((uint32_t)(v_ci71 + v_cl73)); + v_intermediate[1u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 + v_ck1)) + 1024u)), 11u); + v_intermediate[57u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 - v_ck1)) + 1024u)), 11u); + v_intermediate[9u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 + v_ck3)) + 1024u)), 11u); + v_intermediate[49u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 - v_ck3)) + 1024u)), 11u); + v_intermediate[17u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 + v_ck5)) + 1024u)), 11u); + v_intermediate[41u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 - v_ck5)) + 1024u)), 11u); + v_intermediate[25u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 + v_ck7)) + 1024u)), 11u); + v_intermediate[33u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 - v_ck7)) + 1024u)), 11u); } - 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; + if (0u == (self->private_data.f_mcu_blocks[0u][10u] | + self->private_data.f_mcu_blocks[0u][18u] | + self->private_data.f_mcu_blocks[0u][26u] | + self->private_data.f_mcu_blocks[0u][34u] | + self->private_data.f_mcu_blocks[0u][42u] | + self->private_data.f_mcu_blocks[0u][50u] | + self->private_data.f_mcu_blocks[0u][58u])) { + v_intermediate[2u] = ((uint32_t)(((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][2u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][2u])))) << 2u)); + v_intermediate[10u] = v_intermediate[2u]; + v_intermediate[18u] = v_intermediate[2u]; + v_intermediate[26u] = v_intermediate[2u]; + v_intermediate[34u] = v_intermediate[2u]; + v_intermediate[42u] = v_intermediate[2u]; + v_intermediate[50u] = v_intermediate[2u]; + v_intermediate[58u] = v_intermediate[2u]; + } else { + v_bq2 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][18u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][18u])))); + v_bq6 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][50u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][50u])))); + v_ca = ((uint32_t)(((uint32_t)(v_bq2 + v_bq6)) * 4433u)); + v_cb2 = ((uint32_t)(v_ca + ((uint32_t)(v_bq2 * 6270u)))); + v_cb6 = ((uint32_t)(v_ca - ((uint32_t)(v_bq6 * 15137u)))); + v_bq0 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][2u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][2u])))); + v_bq4 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][34u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][34u])))); + v_ccp = ((uint32_t)(((uint32_t)(v_bq0 + v_bq4)) << 13u)); + v_ccm = ((uint32_t)(((uint32_t)(v_bq0 - v_bq4)) << 13u)); + v_cd0 = ((uint32_t)(v_ccp + v_cb2)); + v_cd1 = ((uint32_t)(v_ccm + v_cb6)); + v_cd2 = ((uint32_t)(v_ccm - v_cb6)); + v_cd3 = ((uint32_t)(v_ccp - v_cb2)); + v_bq1 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][10u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][10u])))); + v_bq3 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][26u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][26u])))); + v_bq5 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][42u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][42u])))); + v_bq7 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][58u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][58u])))); + v_ci51 = ((uint32_t)(v_bq5 + v_bq1)); + v_ci53 = ((uint32_t)(v_bq5 + v_bq3)); + v_ci71 = ((uint32_t)(v_bq7 + v_bq1)); + v_ci73 = ((uint32_t)(v_bq7 + v_bq3)); + v_cj = ((uint32_t)(((uint32_t)(v_ci73 + v_ci51)) * 9633u)); + v_ck1 = ((uint32_t)(v_bq1 * 12299u)); + v_ck3 = ((uint32_t)(v_bq3 * 25172u)); + v_ck5 = ((uint32_t)(v_bq5 * 16819u)); + v_ck7 = ((uint32_t)(v_bq7 * 2446u)); + v_ci51 *= 4294964100u; + v_ci53 *= 4294946301u; + v_ci71 *= 4294959923u; + v_ci73 *= 4294951227u; + v_cl51 = ((uint32_t)(v_ci51 + v_cj)); + v_cl73 = ((uint32_t)(v_ci73 + v_cj)); + v_ck1 += ((uint32_t)(v_ci71 + v_cl51)); + v_ck3 += ((uint32_t)(v_ci53 + v_cl73)); + v_ck5 += ((uint32_t)(v_ci53 + v_cl51)); + v_ck7 += ((uint32_t)(v_ci71 + v_cl73)); + v_intermediate[2u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 + v_ck1)) + 1024u)), 11u); + v_intermediate[58u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 - v_ck1)) + 1024u)), 11u); + v_intermediate[10u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 + v_ck3)) + 1024u)), 11u); + v_intermediate[50u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 - v_ck3)) + 1024u)), 11u); + v_intermediate[18u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 + v_ck5)) + 1024u)), 11u); + v_intermediate[42u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 - v_ck5)) + 1024u)), 11u); + v_intermediate[26u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 + v_ck7)) + 1024u)), 11u); + v_intermediate[34u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 - v_ck7)) + 1024u)), 11u); } - goto ok; - - ok: - goto exit; - exit: - return status; -} - -// -------- func jpeg.decoder.calculate_single_component_scan_fields - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_jpeg__decoder__calculate_single_component_scan_fields( - wuffs_jpeg__decoder* self) { - uint8_t v_csel = 0; - - self->private_impl.f_scan_comps_bx_offset[0u] = 0u; - self->private_impl.f_scan_comps_by_offset[0u] = 0u; - self->private_impl.f_mcu_num_blocks = 1u; - self->private_impl.f_mcu_blocks_sselector[0u] = 0u; - v_csel = self->private_impl.f_scan_comps_cselector[0u]; - self->private_impl.f_mcu_blocks_offset[0u] = self->private_impl.f_components_workbuf_offsets[v_csel]; - self->private_impl.f_mcu_blocks_mx_mul[0u] = 8u; - self->private_impl.f_mcu_blocks_my_mul[0u] = (8u * self->private_impl.f_components_workbuf_widths[v_csel]); - self->private_impl.f_mcu_blocks_dc_hselector[0u] = ((uint8_t)(0u | self->private_impl.f_scan_comps_td[0u])); - self->private_impl.f_mcu_blocks_ac_hselector[0u] = ((uint8_t)(4u | self->private_impl.f_scan_comps_ta[0u])); - self->private_impl.f_scan_width_in_mcus = wuffs_jpeg__decoder__quantize_dimension(self, self->private_impl.f_width, self->private_impl.f_components_h[v_csel], self->private_impl.f_max_incl_components_h); - self->private_impl.f_scan_height_in_mcus = wuffs_jpeg__decoder__quantize_dimension(self, self->private_impl.f_height, self->private_impl.f_components_v[v_csel], self->private_impl.f_max_incl_components_v); - return wuffs_base__make_empty_struct(); -} - -// -------- func jpeg.decoder.calculate_multiple_component_scan_fields - -WUFFS_BASE__GENERATED_C_CODE -static bool -wuffs_jpeg__decoder__calculate_multiple_component_scan_fields( - wuffs_jpeg__decoder* self) { - uint32_t v_i = 0; - uint32_t v_h = 0; - uint32_t v_v = 0; - uint32_t v_hv = 0; - uint32_t v_total_hv = 0; - uint32_t v_b = 0; - uint32_t v_bx_offset = 0; - uint32_t v_by_offset = 0; - uint32_t v_sibo = 0; - uint8_t v_ssel = 0; - uint8_t v_csel = 0; - - v_total_hv = 0u; - v_i = 0u; - v_b = 0u; - v_bx_offset = 0u; - v_by_offset = 0u; - while (v_i < self->private_impl.f_scan_num_components) { - v_h = ((uint32_t)(self->private_impl.f_components_h[self->private_impl.f_scan_comps_cselector[v_i]])); - v_v = ((uint32_t)(self->private_impl.f_components_v[self->private_impl.f_scan_comps_cselector[v_i]])); - v_hv = (((uint32_t)(self->private_impl.f_components_h[self->private_impl.f_scan_comps_cselector[v_i]])) * ((uint32_t)(self->private_impl.f_components_v[self->private_impl.f_scan_comps_cselector[v_i]]))); - self->private_impl.f_swizzle_immediately_c_offsets[v_i] = ((uint32_t)(64u * v_total_hv)); - v_total_hv += v_hv; - while (v_hv > 0u) { - self->private_impl.f_scan_comps_bx_offset[(v_b & 15u)] = ((uint8_t)((v_bx_offset & 3u))); - self->private_impl.f_scan_comps_by_offset[(v_b & 15u)] = ((uint8_t)((v_by_offset & 3u))); - self->private_impl.f_mcu_blocks_sselector[(v_b & 15u)] = ((uint8_t)(v_i)); - v_b += 1u; - v_bx_offset += 1u; - if (v_bx_offset == v_h) { - v_bx_offset = 0u; - v_by_offset += 1u; - if (v_by_offset == v_v) { - v_by_offset = 0u; - } - } - v_hv -= 1u; - } - v_i += 1u; + if (0u == (self->private_data.f_mcu_blocks[0u][11u] | + self->private_data.f_mcu_blocks[0u][19u] | + self->private_data.f_mcu_blocks[0u][27u] | + self->private_data.f_mcu_blocks[0u][35u] | + self->private_data.f_mcu_blocks[0u][43u] | + self->private_data.f_mcu_blocks[0u][51u] | + self->private_data.f_mcu_blocks[0u][59u])) { + v_intermediate[3u] = ((uint32_t)(((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][3u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][3u])))) << 2u)); + v_intermediate[11u] = v_intermediate[3u]; + v_intermediate[19u] = v_intermediate[3u]; + v_intermediate[27u] = v_intermediate[3u]; + v_intermediate[35u] = v_intermediate[3u]; + v_intermediate[43u] = v_intermediate[3u]; + v_intermediate[51u] = v_intermediate[3u]; + v_intermediate[59u] = v_intermediate[3u]; + } else { + v_bq2 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][19u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][19u])))); + v_bq6 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][51u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][51u])))); + v_ca = ((uint32_t)(((uint32_t)(v_bq2 + v_bq6)) * 4433u)); + v_cb2 = ((uint32_t)(v_ca + ((uint32_t)(v_bq2 * 6270u)))); + v_cb6 = ((uint32_t)(v_ca - ((uint32_t)(v_bq6 * 15137u)))); + v_bq0 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][3u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][3u])))); + v_bq4 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][35u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][35u])))); + v_ccp = ((uint32_t)(((uint32_t)(v_bq0 + v_bq4)) << 13u)); + v_ccm = ((uint32_t)(((uint32_t)(v_bq0 - v_bq4)) << 13u)); + v_cd0 = ((uint32_t)(v_ccp + v_cb2)); + v_cd1 = ((uint32_t)(v_ccm + v_cb6)); + v_cd2 = ((uint32_t)(v_ccm - v_cb6)); + v_cd3 = ((uint32_t)(v_ccp - v_cb2)); + v_bq1 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][11u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][11u])))); + v_bq3 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][27u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][27u])))); + v_bq5 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][43u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][43u])))); + v_bq7 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][59u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][59u])))); + v_ci51 = ((uint32_t)(v_bq5 + v_bq1)); + v_ci53 = ((uint32_t)(v_bq5 + v_bq3)); + v_ci71 = ((uint32_t)(v_bq7 + v_bq1)); + v_ci73 = ((uint32_t)(v_bq7 + v_bq3)); + v_cj = ((uint32_t)(((uint32_t)(v_ci73 + v_ci51)) * 9633u)); + v_ck1 = ((uint32_t)(v_bq1 * 12299u)); + v_ck3 = ((uint32_t)(v_bq3 * 25172u)); + v_ck5 = ((uint32_t)(v_bq5 * 16819u)); + v_ck7 = ((uint32_t)(v_bq7 * 2446u)); + v_ci51 *= 4294964100u; + v_ci53 *= 4294946301u; + v_ci71 *= 4294959923u; + v_ci73 *= 4294951227u; + v_cl51 = ((uint32_t)(v_ci51 + v_cj)); + v_cl73 = ((uint32_t)(v_ci73 + v_cj)); + v_ck1 += ((uint32_t)(v_ci71 + v_cl51)); + v_ck3 += ((uint32_t)(v_ci53 + v_cl73)); + v_ck5 += ((uint32_t)(v_ci53 + v_cl51)); + v_ck7 += ((uint32_t)(v_ci71 + v_cl73)); + v_intermediate[3u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 + v_ck1)) + 1024u)), 11u); + v_intermediate[59u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 - v_ck1)) + 1024u)), 11u); + v_intermediate[11u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 + v_ck3)) + 1024u)), 11u); + v_intermediate[51u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 - v_ck3)) + 1024u)), 11u); + v_intermediate[19u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 + v_ck5)) + 1024u)), 11u); + v_intermediate[43u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 - v_ck5)) + 1024u)), 11u); + v_intermediate[27u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 + v_ck7)) + 1024u)), 11u); + v_intermediate[35u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 - v_ck7)) + 1024u)), 11u); } - if (v_total_hv > 10u) { - return true; + if (0u == (self->private_data.f_mcu_blocks[0u][12u] | + self->private_data.f_mcu_blocks[0u][20u] | + self->private_data.f_mcu_blocks[0u][28u] | + self->private_data.f_mcu_blocks[0u][36u] | + self->private_data.f_mcu_blocks[0u][44u] | + self->private_data.f_mcu_blocks[0u][52u] | + self->private_data.f_mcu_blocks[0u][60u])) { + v_intermediate[4u] = ((uint32_t)(((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][4u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][4u])))) << 2u)); + v_intermediate[12u] = v_intermediate[4u]; + v_intermediate[20u] = v_intermediate[4u]; + v_intermediate[28u] = v_intermediate[4u]; + v_intermediate[36u] = v_intermediate[4u]; + v_intermediate[44u] = v_intermediate[4u]; + v_intermediate[52u] = v_intermediate[4u]; + v_intermediate[60u] = v_intermediate[4u]; + } else { + v_bq2 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][20u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][20u])))); + v_bq6 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][52u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][52u])))); + v_ca = ((uint32_t)(((uint32_t)(v_bq2 + v_bq6)) * 4433u)); + v_cb2 = ((uint32_t)(v_ca + ((uint32_t)(v_bq2 * 6270u)))); + v_cb6 = ((uint32_t)(v_ca - ((uint32_t)(v_bq6 * 15137u)))); + v_bq0 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][4u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][4u])))); + v_bq4 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][36u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][36u])))); + v_ccp = ((uint32_t)(((uint32_t)(v_bq0 + v_bq4)) << 13u)); + v_ccm = ((uint32_t)(((uint32_t)(v_bq0 - v_bq4)) << 13u)); + v_cd0 = ((uint32_t)(v_ccp + v_cb2)); + v_cd1 = ((uint32_t)(v_ccm + v_cb6)); + v_cd2 = ((uint32_t)(v_ccm - v_cb6)); + v_cd3 = ((uint32_t)(v_ccp - v_cb2)); + v_bq1 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][12u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][12u])))); + v_bq3 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][28u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][28u])))); + v_bq5 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][44u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][44u])))); + v_bq7 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][60u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][60u])))); + v_ci51 = ((uint32_t)(v_bq5 + v_bq1)); + v_ci53 = ((uint32_t)(v_bq5 + v_bq3)); + v_ci71 = ((uint32_t)(v_bq7 + v_bq1)); + v_ci73 = ((uint32_t)(v_bq7 + v_bq3)); + v_cj = ((uint32_t)(((uint32_t)(v_ci73 + v_ci51)) * 9633u)); + v_ck1 = ((uint32_t)(v_bq1 * 12299u)); + v_ck3 = ((uint32_t)(v_bq3 * 25172u)); + v_ck5 = ((uint32_t)(v_bq5 * 16819u)); + v_ck7 = ((uint32_t)(v_bq7 * 2446u)); + v_ci51 *= 4294964100u; + v_ci53 *= 4294946301u; + v_ci71 *= 4294959923u; + v_ci73 *= 4294951227u; + v_cl51 = ((uint32_t)(v_ci51 + v_cj)); + v_cl73 = ((uint32_t)(v_ci73 + v_cj)); + v_ck1 += ((uint32_t)(v_ci71 + v_cl51)); + v_ck3 += ((uint32_t)(v_ci53 + v_cl73)); + v_ck5 += ((uint32_t)(v_ci53 + v_cl51)); + v_ck7 += ((uint32_t)(v_ci71 + v_cl73)); + v_intermediate[4u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 + v_ck1)) + 1024u)), 11u); + v_intermediate[60u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 - v_ck1)) + 1024u)), 11u); + v_intermediate[12u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 + v_ck3)) + 1024u)), 11u); + v_intermediate[52u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 - v_ck3)) + 1024u)), 11u); + v_intermediate[20u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 + v_ck5)) + 1024u)), 11u); + v_intermediate[44u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 - v_ck5)) + 1024u)), 11u); + v_intermediate[28u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 + v_ck7)) + 1024u)), 11u); + v_intermediate[36u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 - v_ck7)) + 1024u)), 11u); } - self->private_impl.f_mcu_num_blocks = v_total_hv; - self->private_impl.f_swizzle_immediately_c_offsets[self->private_impl.f_scan_num_components] = ((uint32_t)(64u * v_total_hv)); - v_b = 0u; - while (v_b < self->private_impl.f_mcu_num_blocks) { - v_ssel = self->private_impl.f_mcu_blocks_sselector[v_b]; - v_csel = self->private_impl.f_scan_comps_cselector[v_ssel]; - self->private_impl.f_mcu_blocks_offset[v_b] = (self->private_impl.f_components_workbuf_offsets[v_csel] + (8u * ((uint64_t)(self->private_impl.f_scan_comps_bx_offset[v_b]))) + (8u * ((uint64_t)(self->private_impl.f_scan_comps_by_offset[v_b])) * ((uint64_t)(self->private_impl.f_components_workbuf_widths[v_csel])))); - self->private_impl.f_mcu_blocks_mx_mul[v_b] = (8u * ((uint32_t)(self->private_impl.f_components_h[v_csel]))); - self->private_impl.f_mcu_blocks_my_mul[v_b] = (8u * ((uint32_t)(self->private_impl.f_components_v[v_csel])) * self->private_impl.f_components_workbuf_widths[v_csel]); - self->private_impl.f_mcu_blocks_dc_hselector[v_b] = ((uint8_t)(0u | self->private_impl.f_scan_comps_td[v_ssel])); - self->private_impl.f_mcu_blocks_ac_hselector[v_b] = ((uint8_t)(4u | self->private_impl.f_scan_comps_ta[v_ssel])); - v_sibo = ((uint32_t)(self->private_impl.f_swizzle_immediately_c_offsets[v_csel] + ((8u * ((uint32_t)(self->private_impl.f_scan_comps_bx_offset[v_b]))) + (64u * ((uint32_t)(self->private_impl.f_scan_comps_by_offset[v_b])) * ((uint32_t)(self->private_impl.f_components_h[v_csel])))))); - self->private_impl.f_swizzle_immediately_b_offsets[v_b] = wuffs_base__u32__min(v_sibo, 576u); - v_b += 1u; + if (0u == (self->private_data.f_mcu_blocks[0u][13u] | + self->private_data.f_mcu_blocks[0u][21u] | + self->private_data.f_mcu_blocks[0u][29u] | + self->private_data.f_mcu_blocks[0u][37u] | + self->private_data.f_mcu_blocks[0u][45u] | + self->private_data.f_mcu_blocks[0u][53u] | + self->private_data.f_mcu_blocks[0u][61u])) { + v_intermediate[5u] = ((uint32_t)(((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][5u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][5u])))) << 2u)); + v_intermediate[13u] = v_intermediate[5u]; + v_intermediate[21u] = v_intermediate[5u]; + v_intermediate[29u] = v_intermediate[5u]; + v_intermediate[37u] = v_intermediate[5u]; + v_intermediate[45u] = v_intermediate[5u]; + v_intermediate[53u] = v_intermediate[5u]; + v_intermediate[61u] = v_intermediate[5u]; + } else { + v_bq2 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][21u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][21u])))); + v_bq6 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][53u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][53u])))); + v_ca = ((uint32_t)(((uint32_t)(v_bq2 + v_bq6)) * 4433u)); + v_cb2 = ((uint32_t)(v_ca + ((uint32_t)(v_bq2 * 6270u)))); + v_cb6 = ((uint32_t)(v_ca - ((uint32_t)(v_bq6 * 15137u)))); + v_bq0 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][5u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][5u])))); + v_bq4 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][37u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][37u])))); + v_ccp = ((uint32_t)(((uint32_t)(v_bq0 + v_bq4)) << 13u)); + v_ccm = ((uint32_t)(((uint32_t)(v_bq0 - v_bq4)) << 13u)); + v_cd0 = ((uint32_t)(v_ccp + v_cb2)); + v_cd1 = ((uint32_t)(v_ccm + v_cb6)); + v_cd2 = ((uint32_t)(v_ccm - v_cb6)); + v_cd3 = ((uint32_t)(v_ccp - v_cb2)); + v_bq1 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][13u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][13u])))); + v_bq3 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][29u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][29u])))); + v_bq5 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][45u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][45u])))); + v_bq7 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][61u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][61u])))); + v_ci51 = ((uint32_t)(v_bq5 + v_bq1)); + v_ci53 = ((uint32_t)(v_bq5 + v_bq3)); + v_ci71 = ((uint32_t)(v_bq7 + v_bq1)); + v_ci73 = ((uint32_t)(v_bq7 + v_bq3)); + v_cj = ((uint32_t)(((uint32_t)(v_ci73 + v_ci51)) * 9633u)); + v_ck1 = ((uint32_t)(v_bq1 * 12299u)); + v_ck3 = ((uint32_t)(v_bq3 * 25172u)); + v_ck5 = ((uint32_t)(v_bq5 * 16819u)); + v_ck7 = ((uint32_t)(v_bq7 * 2446u)); + v_ci51 *= 4294964100u; + v_ci53 *= 4294946301u; + v_ci71 *= 4294959923u; + v_ci73 *= 4294951227u; + v_cl51 = ((uint32_t)(v_ci51 + v_cj)); + v_cl73 = ((uint32_t)(v_ci73 + v_cj)); + v_ck1 += ((uint32_t)(v_ci71 + v_cl51)); + v_ck3 += ((uint32_t)(v_ci53 + v_cl73)); + v_ck5 += ((uint32_t)(v_ci53 + v_cl51)); + v_ck7 += ((uint32_t)(v_ci71 + v_cl73)); + v_intermediate[5u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 + v_ck1)) + 1024u)), 11u); + v_intermediate[61u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 - v_ck1)) + 1024u)), 11u); + v_intermediate[13u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 + v_ck3)) + 1024u)), 11u); + v_intermediate[53u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 - v_ck3)) + 1024u)), 11u); + v_intermediate[21u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 + v_ck5)) + 1024u)), 11u); + v_intermediate[45u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 - v_ck5)) + 1024u)), 11u); + v_intermediate[29u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 + v_ck7)) + 1024u)), 11u); + v_intermediate[37u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 - v_ck7)) + 1024u)), 11u); } - self->private_impl.f_scan_width_in_mcus = self->private_impl.f_width_in_mcus; - self->private_impl.f_scan_height_in_mcus = self->private_impl.f_height_in_mcus; - return false; -} - -// -------- func jpeg.decoder.fill_bitstream - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_jpeg__decoder__fill_bitstream( - wuffs_jpeg__decoder* self, - wuffs_base__io_buffer* a_src) { - uint32_t v_wi = 0; - uint8_t v_c8 = 0; - uint32_t v_new_wi = 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; + if (0u == (self->private_data.f_mcu_blocks[0u][14u] | + self->private_data.f_mcu_blocks[0u][22u] | + self->private_data.f_mcu_blocks[0u][30u] | + self->private_data.f_mcu_blocks[0u][38u] | + self->private_data.f_mcu_blocks[0u][46u] | + self->private_data.f_mcu_blocks[0u][54u] | + self->private_data.f_mcu_blocks[0u][62u])) { + v_intermediate[6u] = ((uint32_t)(((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][6u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][6u])))) << 2u)); + v_intermediate[14u] = v_intermediate[6u]; + v_intermediate[22u] = v_intermediate[6u]; + v_intermediate[30u] = v_intermediate[6u]; + v_intermediate[38u] = v_intermediate[6u]; + v_intermediate[46u] = v_intermediate[6u]; + v_intermediate[54u] = v_intermediate[6u]; + v_intermediate[62u] = v_intermediate[6u]; + } else { + v_bq2 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][22u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][22u])))); + v_bq6 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][54u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][54u])))); + v_ca = ((uint32_t)(((uint32_t)(v_bq2 + v_bq6)) * 4433u)); + v_cb2 = ((uint32_t)(v_ca + ((uint32_t)(v_bq2 * 6270u)))); + v_cb6 = ((uint32_t)(v_ca - ((uint32_t)(v_bq6 * 15137u)))); + v_bq0 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][6u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][6u])))); + v_bq4 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][38u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][38u])))); + v_ccp = ((uint32_t)(((uint32_t)(v_bq0 + v_bq4)) << 13u)); + v_ccm = ((uint32_t)(((uint32_t)(v_bq0 - v_bq4)) << 13u)); + v_cd0 = ((uint32_t)(v_ccp + v_cb2)); + v_cd1 = ((uint32_t)(v_ccm + v_cb6)); + v_cd2 = ((uint32_t)(v_ccm - v_cb6)); + v_cd3 = ((uint32_t)(v_ccp - v_cb2)); + v_bq1 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][14u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][14u])))); + v_bq3 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][30u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][30u])))); + v_bq5 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][46u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][46u])))); + v_bq7 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][62u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][62u])))); + v_ci51 = ((uint32_t)(v_bq5 + v_bq1)); + v_ci53 = ((uint32_t)(v_bq5 + v_bq3)); + v_ci71 = ((uint32_t)(v_bq7 + v_bq1)); + v_ci73 = ((uint32_t)(v_bq7 + v_bq3)); + v_cj = ((uint32_t)(((uint32_t)(v_ci73 + v_ci51)) * 9633u)); + v_ck1 = ((uint32_t)(v_bq1 * 12299u)); + v_ck3 = ((uint32_t)(v_bq3 * 25172u)); + v_ck5 = ((uint32_t)(v_bq5 * 16819u)); + v_ck7 = ((uint32_t)(v_bq7 * 2446u)); + v_ci51 *= 4294964100u; + v_ci53 *= 4294946301u; + v_ci71 *= 4294959923u; + v_ci73 *= 4294951227u; + v_cl51 = ((uint32_t)(v_ci51 + v_cj)); + v_cl73 = ((uint32_t)(v_ci73 + v_cj)); + v_ck1 += ((uint32_t)(v_ci71 + v_cl51)); + v_ck3 += ((uint32_t)(v_ci53 + v_cl73)); + v_ck5 += ((uint32_t)(v_ci53 + v_cl51)); + v_ck7 += ((uint32_t)(v_ci71 + v_cl73)); + v_intermediate[6u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 + v_ck1)) + 1024u)), 11u); + v_intermediate[62u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 - v_ck1)) + 1024u)), 11u); + v_intermediate[14u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 + v_ck3)) + 1024u)), 11u); + v_intermediate[54u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 - v_ck3)) + 1024u)), 11u); + v_intermediate[22u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 + v_ck5)) + 1024u)), 11u); + v_intermediate[46u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 - v_ck5)) + 1024u)), 11u); + v_intermediate[30u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 + v_ck7)) + 1024u)), 11u); + v_intermediate[38u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 - v_ck7)) + 1024u)), 11u); } - - if (self->private_impl.f_bitstream_ri <= 0u) { - } else if (self->private_impl.f_bitstream_ri >= self->private_impl.f_bitstream_wi) { - self->private_impl.f_bitstream_ri = 0u; - self->private_impl.f_bitstream_wi = 0u; + if (0u == (self->private_data.f_mcu_blocks[0u][15u] | + self->private_data.f_mcu_blocks[0u][23u] | + self->private_data.f_mcu_blocks[0u][31u] | + self->private_data.f_mcu_blocks[0u][39u] | + self->private_data.f_mcu_blocks[0u][47u] | + self->private_data.f_mcu_blocks[0u][55u] | + self->private_data.f_mcu_blocks[0u][63u])) { + v_intermediate[7u] = ((uint32_t)(((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][7u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][7u])))) << 2u)); + v_intermediate[15u] = v_intermediate[7u]; + v_intermediate[23u] = v_intermediate[7u]; + v_intermediate[31u] = v_intermediate[7u]; + v_intermediate[39u] = v_intermediate[7u]; + v_intermediate[47u] = v_intermediate[7u]; + v_intermediate[55u] = v_intermediate[7u]; + v_intermediate[63u] = v_intermediate[7u]; } else { - v_wi = (self->private_impl.f_bitstream_wi - self->private_impl.f_bitstream_ri); - wuffs_private_impl__slice_u8__copy_from_slice(wuffs_base__make_slice_u8(self->private_data.f_bitstream_buffer, 2048), wuffs_base__make_slice_u8_ij(self->private_data.f_bitstream_buffer, - self->private_impl.f_bitstream_ri, - self->private_impl.f_bitstream_wi)); - self->private_impl.f_bitstream_ri = 0u; - self->private_impl.f_bitstream_wi = v_wi; + v_bq2 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][23u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][23u])))); + v_bq6 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][55u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][55u])))); + v_ca = ((uint32_t)(((uint32_t)(v_bq2 + v_bq6)) * 4433u)); + v_cb2 = ((uint32_t)(v_ca + ((uint32_t)(v_bq2 * 6270u)))); + v_cb6 = ((uint32_t)(v_ca - ((uint32_t)(v_bq6 * 15137u)))); + v_bq0 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][7u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][7u])))); + v_bq4 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][39u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][39u])))); + v_ccp = ((uint32_t)(((uint32_t)(v_bq0 + v_bq4)) << 13u)); + v_ccm = ((uint32_t)(((uint32_t)(v_bq0 - v_bq4)) << 13u)); + v_cd0 = ((uint32_t)(v_ccp + v_cb2)); + v_cd1 = ((uint32_t)(v_ccm + v_cb6)); + v_cd2 = ((uint32_t)(v_ccm - v_cb6)); + v_cd3 = ((uint32_t)(v_ccp - v_cb2)); + v_bq1 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][15u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][15u])))); + v_bq3 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][31u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][31u])))); + v_bq5 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][47u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][47u])))); + v_bq7 = ((uint32_t)(wuffs_base__utility__sign_extend_convert_u16_u32(self->private_data.f_mcu_blocks[0u][63u]) * ((uint32_t)(self->private_impl.f_quant_tables[a_q][63u])))); + v_ci51 = ((uint32_t)(v_bq5 + v_bq1)); + v_ci53 = ((uint32_t)(v_bq5 + v_bq3)); + v_ci71 = ((uint32_t)(v_bq7 + v_bq1)); + v_ci73 = ((uint32_t)(v_bq7 + v_bq3)); + v_cj = ((uint32_t)(((uint32_t)(v_ci73 + v_ci51)) * 9633u)); + v_ck1 = ((uint32_t)(v_bq1 * 12299u)); + v_ck3 = ((uint32_t)(v_bq3 * 25172u)); + v_ck5 = ((uint32_t)(v_bq5 * 16819u)); + v_ck7 = ((uint32_t)(v_bq7 * 2446u)); + v_ci51 *= 4294964100u; + v_ci53 *= 4294946301u; + v_ci71 *= 4294959923u; + v_ci73 *= 4294951227u; + v_cl51 = ((uint32_t)(v_ci51 + v_cj)); + v_cl73 = ((uint32_t)(v_ci73 + v_cj)); + v_ck1 += ((uint32_t)(v_ci71 + v_cl51)); + v_ck3 += ((uint32_t)(v_ci53 + v_cl73)); + v_ck5 += ((uint32_t)(v_ci53 + v_cl51)); + v_ck7 += ((uint32_t)(v_ci71 + v_cl73)); + v_intermediate[7u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 + v_ck1)) + 1024u)), 11u); + v_intermediate[63u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd0 - v_ck1)) + 1024u)), 11u); + v_intermediate[15u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 + v_ck3)) + 1024u)), 11u); + v_intermediate[55u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd1 - v_ck3)) + 1024u)), 11u); + v_intermediate[23u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 + v_ck5)) + 1024u)), 11u); + v_intermediate[47u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd2 - v_ck5)) + 1024u)), 11u); + v_intermediate[31u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 + v_ck7)) + 1024u)), 11u); + v_intermediate[39u] = wuffs_base__utility__sign_extend_rshift_u32(((uint32_t)(((uint32_t)(v_cd3 - v_ck7)) + 1024u)), 11u); } - v_wi = self->private_impl.f_bitstream_wi; - while ((v_wi < 2048u) && (((uint64_t)(io2_a_src - iop_a_src)) > 0u)) { - v_c8 = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); - if (v_c8 < 255u) { - self->private_data.f_bitstream_buffer[v_wi] = v_c8; - v_wi += 1u; - iop_a_src += 1u; - continue; - } else if (((uint64_t)(io2_a_src - iop_a_src)) <= 1u) { - break; - } else if (((uint16_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src) >> 8u)) > 0u) { - break; - } else { - self->private_data.f_bitstream_buffer[v_wi] = 255u; - v_wi += 1u; - iop_a_src += 2u; + if (0u == (v_intermediate[1u] | + v_intermediate[2u] | + v_intermediate[3u] | + v_intermediate[4u] | + v_intermediate[5u] | + v_intermediate[6u] | + v_intermediate[7u])) { + if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { + return wuffs_base__make_empty_struct(); } - } - if (((uint64_t)(io2_a_src - iop_a_src)) > 1u) { - if ((wuffs_base__peek_u8be__no_bounds_check(iop_a_src) >= 255u) && (((uint16_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src) >> 8u)) > 0u)) { - v_new_wi = (wuffs_base__u32__min(v_wi, 1784u) + 264u); - v_new_wi = wuffs_base__u32__min(v_new_wi, (v_wi + self->private_impl.f_bitstream_padding)); - if (v_wi < v_new_wi) { - wuffs_private_impl__u32__sat_sub_indirect(&self->private_impl.f_bitstream_padding, (v_new_wi - v_wi)); - wuffs_private_impl__bulk_memset(&self->private_data.f_bitstream_buffer[v_wi], (v_new_wi - v_wi), 0u); - v_wi = v_new_wi; - } + a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(v_intermediate[0u] + 16u)) >> 5u) & 1023u)]; + a_dst_buffer.ptr[1u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[2u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[3u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[4u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[5u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[6u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[7u] = a_dst_buffer.ptr[0u]; + a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); + } else { + v_in2 = v_intermediate[2u]; + v_in6 = v_intermediate[6u]; + v_ra = ((uint32_t)(((uint32_t)(v_in2 + v_in6)) * 4433u)); + v_rb2 = ((uint32_t)(v_ra + ((uint32_t)(v_in2 * 6270u)))); + v_rb6 = ((uint32_t)(v_ra - ((uint32_t)(v_in6 * 15137u)))); + v_in0 = v_intermediate[0u]; + v_in4 = v_intermediate[4u]; + v_rcp = ((uint32_t)(((uint32_t)(v_in0 + v_in4)) << 13u)); + v_rcm = ((uint32_t)(((uint32_t)(v_in0 - v_in4)) << 13u)); + v_rd0 = ((uint32_t)(v_rcp + v_rb2)); + v_rd1 = ((uint32_t)(v_rcm + v_rb6)); + v_rd2 = ((uint32_t)(v_rcm - v_rb6)); + v_rd3 = ((uint32_t)(v_rcp - v_rb2)); + v_in1 = v_intermediate[1u]; + v_in3 = v_intermediate[3u]; + v_in5 = v_intermediate[5u]; + v_in7 = v_intermediate[7u]; + v_ri51 = ((uint32_t)(v_in5 + v_in1)); + v_ri53 = ((uint32_t)(v_in5 + v_in3)); + v_ri71 = ((uint32_t)(v_in7 + v_in1)); + v_ri73 = ((uint32_t)(v_in7 + v_in3)); + v_rj = ((uint32_t)(((uint32_t)(v_ri73 + v_ri51)) * 9633u)); + v_rk1 = ((uint32_t)(v_in1 * 12299u)); + v_rk3 = ((uint32_t)(v_in3 * 25172u)); + v_rk5 = ((uint32_t)(v_in5 * 16819u)); + v_rk7 = ((uint32_t)(v_in7 * 2446u)); + v_ri51 *= 4294964100u; + v_ri53 *= 4294946301u; + v_ri71 *= 4294959923u; + v_ri73 *= 4294951227u; + v_rl51 = ((uint32_t)(v_ri51 + v_rj)); + v_rl73 = ((uint32_t)(v_ri73 + v_rj)); + v_rk1 += ((uint32_t)(v_ri71 + v_rl51)); + v_rk3 += ((uint32_t)(v_ri53 + v_rl73)); + v_rk5 += ((uint32_t)(v_ri53 + v_rl51)); + v_rk7 += ((uint32_t)(v_ri71 + v_rl73)); + if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { + return wuffs_base__make_empty_struct(); } + a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 + v_rk1)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[7u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 - v_rk1)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[1u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 + v_rk3)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[6u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 - v_rk3)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[2u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 + v_rk5)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[5u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 - v_rk5)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[3u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 + v_rk7)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[4u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 - v_rk7)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); } - self->private_impl.f_bitstream_wi = v_wi; - if (a_src && a_src->data.ptr) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - - return wuffs_base__make_empty_struct(); -} - -// -------- func jpeg.decoder.load_mcu_blocks_for_single_component - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_jpeg__decoder__load_mcu_blocks_for_single_component( - wuffs_jpeg__decoder* self, - uint32_t a_mx, - uint32_t a_my, - wuffs_base__slice_u8 a_workbuf, - uint32_t a_csel) { - return (*self->private_impl.choosy_load_mcu_blocks_for_single_component)(self, a_mx, a_my, a_workbuf, a_csel); -} - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_jpeg__decoder__load_mcu_blocks_for_single_component__choosy_default( - wuffs_jpeg__decoder* self, - uint32_t a_mx, - uint32_t a_my, - wuffs_base__slice_u8 a_workbuf, - uint32_t a_csel) { - uint64_t v_stride16 = 0; - uint64_t v_offset = 0; - - v_stride16 = ((uint64_t)((self->private_impl.f_components_workbuf_widths[a_csel] * 16u))); - v_offset = (self->private_impl.f_components_workbuf_offsets[(a_csel | 4u)] + (((uint64_t)(a_mx)) * 128u) + (((uint64_t)(a_my)) * v_stride16)); - if (v_offset <= ((uint64_t)(a_workbuf.len))) { - wuffs_private_impl__bulk_load_host_endian(&self->private_data.f_mcu_blocks[0], 1u * (size_t)128u, wuffs_base__slice_u8__subslice_i(a_workbuf, v_offset)); - } - return wuffs_base__make_empty_struct(); -} - -// -------- func jpeg.decoder.load_mcu_blocks - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_jpeg__decoder__load_mcu_blocks( - wuffs_jpeg__decoder* self, - uint32_t a_mx, - uint32_t a_my, - wuffs_base__slice_u8 a_workbuf) { - uint32_t v_b = 0; - uint8_t v_csel = 0; - uint64_t v_h = 0; - uint64_t v_v = 0; - uint64_t v_stride16 = 0; - uint64_t v_offset = 0; - - v_h = 1u; - v_v = 1u; - v_b = 0u; - while (v_b < self->private_impl.f_mcu_num_blocks) { - v_csel = self->private_impl.f_scan_comps_cselector[self->private_impl.f_mcu_blocks_sselector[v_b]]; - if (self->private_impl.f_scan_num_components > 1u) { - v_h = ((uint64_t)(self->private_impl.f_components_h[v_csel])); - v_v = ((uint64_t)(self->private_impl.f_components_v[v_csel])); + if (0u == (v_intermediate[9u] | + v_intermediate[10u] | + v_intermediate[11u] | + v_intermediate[12u] | + v_intermediate[13u] | + v_intermediate[14u] | + v_intermediate[15u])) { + if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { + return wuffs_base__make_empty_struct(); } - v_stride16 = ((uint64_t)((self->private_impl.f_components_workbuf_widths[v_csel] * 16u))); - v_offset = (self->private_impl.f_components_workbuf_offsets[((uint8_t)(v_csel | 4u))] + (((v_h * ((uint64_t)(a_mx))) + ((uint64_t)(self->private_impl.f_scan_comps_bx_offset[v_b]))) * 128u) + (((v_v * ((uint64_t)(a_my))) + ((uint64_t)(self->private_impl.f_scan_comps_by_offset[v_b]))) * v_stride16)); - if (v_offset <= ((uint64_t)(a_workbuf.len))) { - wuffs_private_impl__bulk_load_host_endian(&self->private_data.f_mcu_blocks[v_b], 1u * (size_t)128u, wuffs_base__slice_u8__subslice_i(a_workbuf, v_offset)); + a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(v_intermediate[8u] + 16u)) >> 5u) & 1023u)]; + a_dst_buffer.ptr[1u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[2u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[3u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[4u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[5u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[6u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[7u] = a_dst_buffer.ptr[0u]; + a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); + } else { + v_in2 = v_intermediate[10u]; + v_in6 = v_intermediate[14u]; + v_ra = ((uint32_t)(((uint32_t)(v_in2 + v_in6)) * 4433u)); + v_rb2 = ((uint32_t)(v_ra + ((uint32_t)(v_in2 * 6270u)))); + v_rb6 = ((uint32_t)(v_ra - ((uint32_t)(v_in6 * 15137u)))); + v_in0 = v_intermediate[8u]; + v_in4 = v_intermediate[12u]; + v_rcp = ((uint32_t)(((uint32_t)(v_in0 + v_in4)) << 13u)); + v_rcm = ((uint32_t)(((uint32_t)(v_in0 - v_in4)) << 13u)); + v_rd0 = ((uint32_t)(v_rcp + v_rb2)); + v_rd1 = ((uint32_t)(v_rcm + v_rb6)); + v_rd2 = ((uint32_t)(v_rcm - v_rb6)); + v_rd3 = ((uint32_t)(v_rcp - v_rb2)); + v_in1 = v_intermediate[9u]; + v_in3 = v_intermediate[11u]; + v_in5 = v_intermediate[13u]; + v_in7 = v_intermediate[15u]; + v_ri51 = ((uint32_t)(v_in5 + v_in1)); + v_ri53 = ((uint32_t)(v_in5 + v_in3)); + v_ri71 = ((uint32_t)(v_in7 + v_in1)); + v_ri73 = ((uint32_t)(v_in7 + v_in3)); + v_rj = ((uint32_t)(((uint32_t)(v_ri73 + v_ri51)) * 9633u)); + v_rk1 = ((uint32_t)(v_in1 * 12299u)); + v_rk3 = ((uint32_t)(v_in3 * 25172u)); + v_rk5 = ((uint32_t)(v_in5 * 16819u)); + v_rk7 = ((uint32_t)(v_in7 * 2446u)); + v_ri51 *= 4294964100u; + v_ri53 *= 4294946301u; + v_ri71 *= 4294959923u; + v_ri73 *= 4294951227u; + v_rl51 = ((uint32_t)(v_ri51 + v_rj)); + v_rl73 = ((uint32_t)(v_ri73 + v_rj)); + v_rk1 += ((uint32_t)(v_ri71 + v_rl51)); + v_rk3 += ((uint32_t)(v_ri53 + v_rl73)); + v_rk5 += ((uint32_t)(v_ri53 + v_rl51)); + v_rk7 += ((uint32_t)(v_ri71 + v_rl73)); + if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { + return wuffs_base__make_empty_struct(); } - v_b += 1u; + a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 + v_rk1)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[7u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 - v_rk1)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[1u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 + v_rk3)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[6u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 - v_rk3)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[2u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 + v_rk5)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[5u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 - v_rk5)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[3u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 + v_rk7)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[4u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 - v_rk7)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); } - return wuffs_base__make_empty_struct(); -} - -// -------- func jpeg.decoder.save_mcu_blocks - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_jpeg__decoder__save_mcu_blocks( - wuffs_jpeg__decoder* self, - uint32_t a_mx, - uint32_t a_my, - wuffs_base__slice_u8 a_workbuf) { - uint32_t v_b = 0; - uint8_t v_csel = 0; - uint64_t v_h = 0; - uint64_t v_v = 0; - uint64_t v_stride16 = 0; - uint64_t v_offset = 0; - - v_h = 1u; - v_v = 1u; - v_b = 0u; - while (v_b < self->private_impl.f_mcu_num_blocks) { - v_csel = self->private_impl.f_scan_comps_cselector[self->private_impl.f_mcu_blocks_sselector[v_b]]; - if (self->private_impl.f_scan_num_components > 1u) { - v_h = ((uint64_t)(self->private_impl.f_components_h[v_csel])); - v_v = ((uint64_t)(self->private_impl.f_components_v[v_csel])); + if (0u == (v_intermediate[17u] | + v_intermediate[18u] | + v_intermediate[19u] | + v_intermediate[20u] | + v_intermediate[21u] | + v_intermediate[22u] | + v_intermediate[23u])) { + if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { + return wuffs_base__make_empty_struct(); } - v_stride16 = ((uint64_t)((self->private_impl.f_components_workbuf_widths[v_csel] * 16u))); - v_offset = (self->private_impl.f_components_workbuf_offsets[((uint8_t)(v_csel | 4u))] + (((v_h * ((uint64_t)(a_mx))) + ((uint64_t)(self->private_impl.f_scan_comps_bx_offset[v_b]))) * 128u) + (((v_v * ((uint64_t)(a_my))) + ((uint64_t)(self->private_impl.f_scan_comps_by_offset[v_b]))) * v_stride16)); - if (v_offset <= ((uint64_t)(a_workbuf.len))) { - wuffs_private_impl__bulk_save_host_endian(&self->private_data.f_mcu_blocks[v_b], 1u * (size_t)128u, wuffs_base__slice_u8__subslice_i(a_workbuf, v_offset)); + a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(v_intermediate[16u] + 16u)) >> 5u) & 1023u)]; + a_dst_buffer.ptr[1u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[2u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[3u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[4u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[5u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[6u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[7u] = a_dst_buffer.ptr[0u]; + a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); + } else { + v_in2 = v_intermediate[18u]; + v_in6 = v_intermediate[22u]; + v_ra = ((uint32_t)(((uint32_t)(v_in2 + v_in6)) * 4433u)); + v_rb2 = ((uint32_t)(v_ra + ((uint32_t)(v_in2 * 6270u)))); + v_rb6 = ((uint32_t)(v_ra - ((uint32_t)(v_in6 * 15137u)))); + v_in0 = v_intermediate[16u]; + v_in4 = v_intermediate[20u]; + v_rcp = ((uint32_t)(((uint32_t)(v_in0 + v_in4)) << 13u)); + v_rcm = ((uint32_t)(((uint32_t)(v_in0 - v_in4)) << 13u)); + v_rd0 = ((uint32_t)(v_rcp + v_rb2)); + v_rd1 = ((uint32_t)(v_rcm + v_rb6)); + v_rd2 = ((uint32_t)(v_rcm - v_rb6)); + v_rd3 = ((uint32_t)(v_rcp - v_rb2)); + v_in1 = v_intermediate[17u]; + v_in3 = v_intermediate[19u]; + v_in5 = v_intermediate[21u]; + v_in7 = v_intermediate[23u]; + v_ri51 = ((uint32_t)(v_in5 + v_in1)); + v_ri53 = ((uint32_t)(v_in5 + v_in3)); + v_ri71 = ((uint32_t)(v_in7 + v_in1)); + v_ri73 = ((uint32_t)(v_in7 + v_in3)); + v_rj = ((uint32_t)(((uint32_t)(v_ri73 + v_ri51)) * 9633u)); + v_rk1 = ((uint32_t)(v_in1 * 12299u)); + v_rk3 = ((uint32_t)(v_in3 * 25172u)); + v_rk5 = ((uint32_t)(v_in5 * 16819u)); + v_rk7 = ((uint32_t)(v_in7 * 2446u)); + v_ri51 *= 4294964100u; + v_ri53 *= 4294946301u; + v_ri71 *= 4294959923u; + v_ri73 *= 4294951227u; + v_rl51 = ((uint32_t)(v_ri51 + v_rj)); + v_rl73 = ((uint32_t)(v_ri73 + v_rj)); + v_rk1 += ((uint32_t)(v_ri71 + v_rl51)); + v_rk3 += ((uint32_t)(v_ri53 + v_rl73)); + v_rk5 += ((uint32_t)(v_ri53 + v_rl51)); + v_rk7 += ((uint32_t)(v_ri71 + v_rl73)); + if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { + return wuffs_base__make_empty_struct(); } - v_b += 1u; - } - return wuffs_base__make_empty_struct(); -} - -// -------- func jpeg.decoder.skip_past_the_next_restart_marker - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_jpeg__decoder__skip_past_the_next_restart_marker( - wuffs_jpeg__decoder* self, - wuffs_base__io_buffer* a_src) { - wuffs_base__status status = wuffs_base__make_status(NULL); - - uint8_t v_c8 = 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; + a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 + v_rk1)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[7u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 - v_rk1)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[1u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 + v_rk3)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[6u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 - v_rk3)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[2u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 + v_rk5)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[5u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 - v_rk5)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[3u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 + v_rk7)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[4u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 - v_rk7)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); } - - uint32_t coro_susp_point = self->private_impl.p_skip_past_the_next_restart_marker; - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - - while (true) { - if (((uint64_t)(io2_a_src - iop_a_src)) < 2u) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1); - continue; - } else if (wuffs_base__peek_u8be__no_bounds_check(iop_a_src) < 255u) { - iop_a_src += 1u; - continue; - } - v_c8 = ((uint8_t)(((uint16_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src) >> 8u)))); - if (v_c8 < 192u) { - iop_a_src += 2u; - continue; - } else if ((v_c8 < 208u) || (215u < v_c8)) { - break; - } - v_c8 &= 7u; - if ((self->private_impl.f_next_restart_marker == ((uint8_t)(((uint8_t)(v_c8 + 1u)) & 7u))) || (self->private_impl.f_next_restart_marker == ((uint8_t)(((uint8_t)(v_c8 + 2u)) & 7u)))) { - break; - } else if ((self->private_impl.f_next_restart_marker == ((uint8_t)(((uint8_t)(v_c8 + 7u)) & 7u))) || (self->private_impl.f_next_restart_marker == ((uint8_t)(((uint8_t)(v_c8 + 6u)) & 7u)))) { - iop_a_src += 2u; - continue; - } else { - iop_a_src += 2u; - break; - } + if (0u == (v_intermediate[25u] | + v_intermediate[26u] | + v_intermediate[27u] | + v_intermediate[28u] | + v_intermediate[29u] | + v_intermediate[30u] | + v_intermediate[31u])) { + if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { + return wuffs_base__make_empty_struct(); } - self->private_impl.f_next_restart_marker = ((uint8_t)(((uint8_t)(self->private_impl.f_next_restart_marker + 1u)) & 7u)); - - ok: - self->private_impl.p_skip_past_the_next_restart_marker = 0; - goto exit; - } - - goto suspend; - suspend: - self->private_impl.p_skip_past_the_next_restart_marker = 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 jpeg.decoder.apply_progressive_idct - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_jpeg__decoder__apply_progressive_idct( - wuffs_jpeg__decoder* self, - wuffs_base__slice_u8 a_workbuf) { - uint32_t v_csel = 0; - bool v_block_smoothing_applicable = false; - uint32_t v_scan_width_in_mcus = 0; - uint32_t v_scan_height_in_mcus = 0; - uint32_t v_mcu_blocks_mx_mul_0 = 0; - uint32_t v_mcu_blocks_my_mul_0 = 0; - uint32_t v_my = 0; - uint32_t v_mx = 0; - uint64_t v_stride = 0; - uint64_t v_offset = 0; - uint8_t v_stashed_mcu_blocks_0[128] = {0}; - - wuffs_private_impl__bulk_save_host_endian(&self->private_data.f_mcu_blocks[0], 1u * (size_t)128u, wuffs_base__make_slice_u8(v_stashed_mcu_blocks_0, 128)); - v_block_smoothing_applicable = true; - v_csel = 0u; - while (v_csel < self->private_impl.f_num_components) { - if ((self->private_impl.f_block_smoothing_lowest_scan_al[v_csel][0u] >= 16u) || wuffs_jpeg__decoder__top_left_quants_has_zero(self, ((uint32_t)(self->private_impl.f_components_tq[v_csel])))) { - v_block_smoothing_applicable = false; + a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(v_intermediate[24u] + 16u)) >> 5u) & 1023u)]; + a_dst_buffer.ptr[1u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[2u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[3u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[4u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[5u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[6u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[7u] = a_dst_buffer.ptr[0u]; + a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); + } else { + v_in2 = v_intermediate[26u]; + v_in6 = v_intermediate[30u]; + v_ra = ((uint32_t)(((uint32_t)(v_in2 + v_in6)) * 4433u)); + v_rb2 = ((uint32_t)(v_ra + ((uint32_t)(v_in2 * 6270u)))); + v_rb6 = ((uint32_t)(v_ra - ((uint32_t)(v_in6 * 15137u)))); + v_in0 = v_intermediate[24u]; + v_in4 = v_intermediate[28u]; + v_rcp = ((uint32_t)(((uint32_t)(v_in0 + v_in4)) << 13u)); + v_rcm = ((uint32_t)(((uint32_t)(v_in0 - v_in4)) << 13u)); + v_rd0 = ((uint32_t)(v_rcp + v_rb2)); + v_rd1 = ((uint32_t)(v_rcm + v_rb6)); + v_rd2 = ((uint32_t)(v_rcm - v_rb6)); + v_rd3 = ((uint32_t)(v_rcp - v_rb2)); + v_in1 = v_intermediate[25u]; + v_in3 = v_intermediate[27u]; + v_in5 = v_intermediate[29u]; + v_in7 = v_intermediate[31u]; + v_ri51 = ((uint32_t)(v_in5 + v_in1)); + v_ri53 = ((uint32_t)(v_in5 + v_in3)); + v_ri71 = ((uint32_t)(v_in7 + v_in1)); + v_ri73 = ((uint32_t)(v_in7 + v_in3)); + v_rj = ((uint32_t)(((uint32_t)(v_ri73 + v_ri51)) * 9633u)); + v_rk1 = ((uint32_t)(v_in1 * 12299u)); + v_rk3 = ((uint32_t)(v_in3 * 25172u)); + v_rk5 = ((uint32_t)(v_in5 * 16819u)); + v_rk7 = ((uint32_t)(v_in7 * 2446u)); + v_ri51 *= 4294964100u; + v_ri53 *= 4294946301u; + v_ri71 *= 4294959923u; + v_ri73 *= 4294951227u; + v_rl51 = ((uint32_t)(v_ri51 + v_rj)); + v_rl73 = ((uint32_t)(v_ri73 + v_rj)); + v_rk1 += ((uint32_t)(v_ri71 + v_rl51)); + v_rk3 += ((uint32_t)(v_ri53 + v_rl73)); + v_rk5 += ((uint32_t)(v_ri53 + v_rl51)); + v_rk7 += ((uint32_t)(v_ri71 + v_rl73)); + if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { + return wuffs_base__make_empty_struct(); } - v_csel += 1u; + a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 + v_rk1)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[7u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 - v_rk1)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[1u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 + v_rk3)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[6u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 - v_rk3)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[2u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 + v_rk5)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[5u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 - v_rk5)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[3u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 + v_rk7)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[4u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 - v_rk7)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); } - v_csel = 0u; - while (v_csel < self->private_impl.f_num_components) { - v_scan_width_in_mcus = wuffs_jpeg__decoder__quantize_dimension(self, self->private_impl.f_width, self->private_impl.f_components_h[v_csel], self->private_impl.f_max_incl_components_h); - v_scan_height_in_mcus = wuffs_jpeg__decoder__quantize_dimension(self, self->private_impl.f_height, self->private_impl.f_components_v[v_csel], self->private_impl.f_max_incl_components_v); - v_mcu_blocks_mx_mul_0 = 8u; - v_mcu_blocks_my_mul_0 = (8u * self->private_impl.f_components_workbuf_widths[v_csel]); - if (v_block_smoothing_applicable && (0u != (self->private_impl.f_block_smoothing_lowest_scan_al[v_csel][1u] | - self->private_impl.f_block_smoothing_lowest_scan_al[v_csel][2u] | - self->private_impl.f_block_smoothing_lowest_scan_al[v_csel][3u] | - self->private_impl.f_block_smoothing_lowest_scan_al[v_csel][4u] | - self->private_impl.f_block_smoothing_lowest_scan_al[v_csel][5u] | - self->private_impl.f_block_smoothing_lowest_scan_al[v_csel][6u] | - self->private_impl.f_block_smoothing_lowest_scan_al[v_csel][8u] | - self->private_impl.f_block_smoothing_lowest_scan_al[v_csel][8u] | - self->private_impl.f_block_smoothing_lowest_scan_al[v_csel][9u]))) { - self->private_impl.choosy_load_mcu_blocks_for_single_component = ( - &wuffs_jpeg__decoder__load_mcu_blocks_for_single_component_smooth); - self->private_impl.f_block_smoothing_mx_max_incl = wuffs_base__u32__sat_sub(v_scan_width_in_mcus, 1u); - self->private_impl.f_block_smoothing_my_max_incl = wuffs_base__u32__sat_sub(v_scan_height_in_mcus, 1u); - } else { - self->private_impl.choosy_load_mcu_blocks_for_single_component = ( - &wuffs_jpeg__decoder__load_mcu_blocks_for_single_component__choosy_default); + if (0u == (v_intermediate[33u] | + v_intermediate[34u] | + v_intermediate[35u] | + v_intermediate[36u] | + v_intermediate[37u] | + v_intermediate[38u] | + v_intermediate[39u])) { + if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { + return wuffs_base__make_empty_struct(); } - v_my = 0u; - while (v_my < v_scan_height_in_mcus) { - v_mx = 0u; - while (v_mx < v_scan_width_in_mcus) { - wuffs_jpeg__decoder__load_mcu_blocks_for_single_component(self, - v_mx, - v_my, - a_workbuf, - v_csel); - v_stride = ((uint64_t)(self->private_impl.f_components_workbuf_widths[v_csel])); - v_offset = (self->private_impl.f_components_workbuf_offsets[v_csel] + (((uint64_t)(v_mcu_blocks_mx_mul_0)) * ((uint64_t)(v_mx))) + (((uint64_t)(v_mcu_blocks_my_mul_0)) * ((uint64_t)(v_my)))); - if (v_offset <= ((uint64_t)(a_workbuf.len))) { - wuffs_jpeg__decoder__decode_idct(self, wuffs_base__slice_u8__subslice_i(a_workbuf, v_offset), v_stride, ((uint32_t)(self->private_impl.f_components_tq[v_csel]))); - } - v_mx += 1u; - } - v_my += 1u; + a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(v_intermediate[32u] + 16u)) >> 5u) & 1023u)]; + a_dst_buffer.ptr[1u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[2u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[3u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[4u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[5u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[6u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[7u] = a_dst_buffer.ptr[0u]; + a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); + } else { + v_in2 = v_intermediate[34u]; + v_in6 = v_intermediate[38u]; + v_ra = ((uint32_t)(((uint32_t)(v_in2 + v_in6)) * 4433u)); + v_rb2 = ((uint32_t)(v_ra + ((uint32_t)(v_in2 * 6270u)))); + v_rb6 = ((uint32_t)(v_ra - ((uint32_t)(v_in6 * 15137u)))); + v_in0 = v_intermediate[32u]; + v_in4 = v_intermediate[36u]; + v_rcp = ((uint32_t)(((uint32_t)(v_in0 + v_in4)) << 13u)); + v_rcm = ((uint32_t)(((uint32_t)(v_in0 - v_in4)) << 13u)); + v_rd0 = ((uint32_t)(v_rcp + v_rb2)); + v_rd1 = ((uint32_t)(v_rcm + v_rb6)); + v_rd2 = ((uint32_t)(v_rcm - v_rb6)); + v_rd3 = ((uint32_t)(v_rcp - v_rb2)); + v_in1 = v_intermediate[33u]; + v_in3 = v_intermediate[35u]; + v_in5 = v_intermediate[37u]; + v_in7 = v_intermediate[39u]; + v_ri51 = ((uint32_t)(v_in5 + v_in1)); + v_ri53 = ((uint32_t)(v_in5 + v_in3)); + v_ri71 = ((uint32_t)(v_in7 + v_in1)); + v_ri73 = ((uint32_t)(v_in7 + v_in3)); + v_rj = ((uint32_t)(((uint32_t)(v_ri73 + v_ri51)) * 9633u)); + v_rk1 = ((uint32_t)(v_in1 * 12299u)); + v_rk3 = ((uint32_t)(v_in3 * 25172u)); + v_rk5 = ((uint32_t)(v_in5 * 16819u)); + v_rk7 = ((uint32_t)(v_in7 * 2446u)); + v_ri51 *= 4294964100u; + v_ri53 *= 4294946301u; + v_ri71 *= 4294959923u; + v_ri73 *= 4294951227u; + v_rl51 = ((uint32_t)(v_ri51 + v_rj)); + v_rl73 = ((uint32_t)(v_ri73 + v_rj)); + v_rk1 += ((uint32_t)(v_ri71 + v_rl51)); + v_rk3 += ((uint32_t)(v_ri53 + v_rl73)); + v_rk5 += ((uint32_t)(v_ri53 + v_rl51)); + v_rk7 += ((uint32_t)(v_ri71 + v_rl73)); + if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { + return wuffs_base__make_empty_struct(); } - v_csel += 1u; + a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 + v_rk1)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[7u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 - v_rk1)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[1u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 + v_rk3)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[6u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 - v_rk3)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[2u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 + v_rk5)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[5u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 - v_rk5)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[3u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 + v_rk7)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[4u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 - v_rk7)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); } - wuffs_private_impl__bulk_load_host_endian(&self->private_data.f_mcu_blocks[0], 1u * (size_t)128u, wuffs_base__make_slice_u8(v_stashed_mcu_blocks_0, 128)); - return wuffs_base__make_empty_struct(); -} - -// -------- func jpeg.decoder.swizzle_gray - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_jpeg__decoder__swizzle_gray( - wuffs_jpeg__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__slice_u8 a_workbuf, - uint32_t a_x0, - uint32_t a_x1, - uint32_t a_y0, - uint32_t a_y1, - uint64_t a_stride) { - 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_x0 = 0; - uint64_t v_x1 = 0; - wuffs_base__table_u8 v_tab = {0}; - wuffs_base__slice_u8 v_dst = {0}; - uint32_t v_y = 0; - uint32_t v_y1 = 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_x0 = ((uint64_t)((v_dst_bytes_per_pixel * wuffs_base__u32__min(a_x0, self->private_impl.f_width)))); - v_x1 = ((uint64_t)((v_dst_bytes_per_pixel * wuffs_base__u32__min(a_x1, self->private_impl.f_width)))); - v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0u); - v_y = a_y0; - v_y1 = wuffs_base__u32__min(a_y1, self->private_impl.f_height); - while (v_y < v_y1) { - v_dst = wuffs_private_impl__table_u8__row_u32(v_tab, v_y); - if (v_x1 < ((uint64_t)(v_dst.len))) { - v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_x1); - } - if (v_x0 < ((uint64_t)(v_dst.len))) { - v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_x0); - } else { - v_dst = wuffs_base__utility__empty_slice_u8(); + if (0u == (v_intermediate[41u] | + v_intermediate[42u] | + v_intermediate[43u] | + v_intermediate[44u] | + v_intermediate[45u] | + v_intermediate[46u] | + v_intermediate[47u])) { + if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { + return wuffs_base__make_empty_struct(); } - wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024)), a_workbuf); - if (a_stride <= ((uint64_t)(a_workbuf.len))) { - a_workbuf = wuffs_base__slice_u8__subslice_i(a_workbuf, a_stride); - } else { - a_workbuf = wuffs_base__utility__empty_slice_u8(); + a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(v_intermediate[40u] + 16u)) >> 5u) & 1023u)]; + a_dst_buffer.ptr[1u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[2u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[3u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[4u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[5u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[6u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[7u] = a_dst_buffer.ptr[0u]; + a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); + } else { + v_in2 = v_intermediate[42u]; + v_in6 = v_intermediate[46u]; + v_ra = ((uint32_t)(((uint32_t)(v_in2 + v_in6)) * 4433u)); + v_rb2 = ((uint32_t)(v_ra + ((uint32_t)(v_in2 * 6270u)))); + v_rb6 = ((uint32_t)(v_ra - ((uint32_t)(v_in6 * 15137u)))); + v_in0 = v_intermediate[40u]; + v_in4 = v_intermediate[44u]; + v_rcp = ((uint32_t)(((uint32_t)(v_in0 + v_in4)) << 13u)); + v_rcm = ((uint32_t)(((uint32_t)(v_in0 - v_in4)) << 13u)); + v_rd0 = ((uint32_t)(v_rcp + v_rb2)); + v_rd1 = ((uint32_t)(v_rcm + v_rb6)); + v_rd2 = ((uint32_t)(v_rcm - v_rb6)); + v_rd3 = ((uint32_t)(v_rcp - v_rb2)); + v_in1 = v_intermediate[41u]; + v_in3 = v_intermediate[43u]; + v_in5 = v_intermediate[45u]; + v_in7 = v_intermediate[47u]; + v_ri51 = ((uint32_t)(v_in5 + v_in1)); + v_ri53 = ((uint32_t)(v_in5 + v_in3)); + v_ri71 = ((uint32_t)(v_in7 + v_in1)); + v_ri73 = ((uint32_t)(v_in7 + v_in3)); + v_rj = ((uint32_t)(((uint32_t)(v_ri73 + v_ri51)) * 9633u)); + v_rk1 = ((uint32_t)(v_in1 * 12299u)); + v_rk3 = ((uint32_t)(v_in3 * 25172u)); + v_rk5 = ((uint32_t)(v_in5 * 16819u)); + v_rk7 = ((uint32_t)(v_in7 * 2446u)); + v_ri51 *= 4294964100u; + v_ri53 *= 4294946301u; + v_ri71 *= 4294959923u; + v_ri73 *= 4294951227u; + v_rl51 = ((uint32_t)(v_ri51 + v_rj)); + v_rl73 = ((uint32_t)(v_ri73 + v_rj)); + v_rk1 += ((uint32_t)(v_ri71 + v_rl51)); + v_rk3 += ((uint32_t)(v_ri53 + v_rl73)); + v_rk5 += ((uint32_t)(v_ri53 + v_rl51)); + v_rk7 += ((uint32_t)(v_ri71 + v_rl73)); + if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { + return wuffs_base__make_empty_struct(); } - v_y += 1u; + a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 + v_rk1)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[7u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 - v_rk1)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[1u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 + v_rk3)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[6u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 - v_rk3)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[2u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 + v_rk5)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[5u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 - v_rk5)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[3u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 + v_rk7)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[4u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 - v_rk7)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); } - return wuffs_base__make_status(NULL); -} - -// -------- func jpeg.decoder.swizzle_colorful - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_jpeg__decoder__swizzle_colorful( - wuffs_jpeg__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__slice_u8 a_workbuf, - uint32_t a_x0, - uint32_t a_x1, - uint32_t a_y0, - uint32_t a_y1) { - uint64_t v_i = 0; - uint64_t v_j = 0; - wuffs_base__slice_u8 v_src0 = {0}; - wuffs_base__slice_u8 v_src1 = {0}; - wuffs_base__slice_u8 v_src2 = {0}; - wuffs_base__slice_u8 v_src3 = {0}; - uint32_t v_width0 = 0; - uint32_t v_width1 = 0; - uint32_t v_width2 = 0; - uint32_t v_width3 = 0; - uint32_t v_height0 = 0; - uint32_t v_height1 = 0; - uint32_t v_height2 = 0; - uint32_t v_height3 = 0; - wuffs_base__status v_status = wuffs_base__make_status(NULL); - - if (self->private_impl.f_swizzle_immediately) { - v_i = ((uint64_t)(self->private_impl.f_swizzle_immediately_c_offsets[0u])); - v_j = ((uint64_t)(self->private_impl.f_swizzle_immediately_c_offsets[1u])); - if ((v_i <= v_j) && (v_j <= 640u)) { - v_src0 = wuffs_base__make_slice_u8_ij(self->private_data.f_swizzle_immediately_buffer, v_i, v_j); - v_width0 = (8u * ((uint32_t)(self->private_impl.f_components_h[0u]))); - v_height0 = (8u * ((uint32_t)(self->private_impl.f_components_v[0u]))); - } - v_i = ((uint64_t)(self->private_impl.f_swizzle_immediately_c_offsets[1u])); - v_j = ((uint64_t)(self->private_impl.f_swizzle_immediately_c_offsets[2u])); - if ((v_i <= v_j) && (v_j <= 640u)) { - v_src1 = wuffs_base__make_slice_u8_ij(self->private_data.f_swizzle_immediately_buffer, v_i, v_j); - v_width1 = (8u * ((uint32_t)(self->private_impl.f_components_h[1u]))); - v_height1 = (8u * ((uint32_t)(self->private_impl.f_components_v[1u]))); - } - v_i = ((uint64_t)(self->private_impl.f_swizzle_immediately_c_offsets[2u])); - v_j = ((uint64_t)(self->private_impl.f_swizzle_immediately_c_offsets[3u])); - if ((v_i <= v_j) && (v_j <= 640u)) { - v_src2 = wuffs_base__make_slice_u8_ij(self->private_data.f_swizzle_immediately_buffer, v_i, v_j); - v_width2 = (8u * ((uint32_t)(self->private_impl.f_components_h[2u]))); - v_height2 = (8u * ((uint32_t)(self->private_impl.f_components_v[2u]))); - } - v_i = ((uint64_t)(self->private_impl.f_swizzle_immediately_c_offsets[3u])); - v_j = ((uint64_t)(self->private_impl.f_swizzle_immediately_c_offsets[4u])); - if ((v_i <= v_j) && (v_j <= 640u)) { - v_src3 = wuffs_base__make_slice_u8_ij(self->private_data.f_swizzle_immediately_buffer, v_i, v_j); - v_width3 = (8u * ((uint32_t)(self->private_impl.f_components_h[3u]))); - v_height3 = (8u * ((uint32_t)(self->private_impl.f_components_v[3u]))); + if (0u == (v_intermediate[49u] | + v_intermediate[50u] | + v_intermediate[51u] | + v_intermediate[52u] | + v_intermediate[53u] | + v_intermediate[54u] | + v_intermediate[55u])) { + if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { + return wuffs_base__make_empty_struct(); } + a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(v_intermediate[48u] + 16u)) >> 5u) & 1023u)]; + a_dst_buffer.ptr[1u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[2u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[3u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[4u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[5u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[6u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[7u] = a_dst_buffer.ptr[0u]; + a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); } else { - if ((self->private_impl.f_components_workbuf_offsets[0u] <= self->private_impl.f_components_workbuf_offsets[1u]) && (self->private_impl.f_components_workbuf_offsets[1u] <= ((uint64_t)(a_workbuf.len)))) { - v_src0 = wuffs_base__slice_u8__subslice_ij(a_workbuf, - self->private_impl.f_components_workbuf_offsets[0u], - self->private_impl.f_components_workbuf_offsets[1u]); - v_width0 = self->private_impl.f_components_workbuf_widths[0u]; - v_height0 = self->private_impl.f_components_workbuf_heights[0u]; - } - if ((self->private_impl.f_components_workbuf_offsets[1u] <= self->private_impl.f_components_workbuf_offsets[2u]) && (self->private_impl.f_components_workbuf_offsets[2u] <= ((uint64_t)(a_workbuf.len)))) { - v_src1 = wuffs_base__slice_u8__subslice_ij(a_workbuf, - self->private_impl.f_components_workbuf_offsets[1u], - self->private_impl.f_components_workbuf_offsets[2u]); - v_width1 = self->private_impl.f_components_workbuf_widths[1u]; - v_height1 = self->private_impl.f_components_workbuf_heights[1u]; - } - if ((self->private_impl.f_components_workbuf_offsets[2u] <= self->private_impl.f_components_workbuf_offsets[3u]) && (self->private_impl.f_components_workbuf_offsets[3u] <= ((uint64_t)(a_workbuf.len)))) { - v_src2 = wuffs_base__slice_u8__subslice_ij(a_workbuf, - self->private_impl.f_components_workbuf_offsets[2u], - self->private_impl.f_components_workbuf_offsets[3u]); - v_width2 = self->private_impl.f_components_workbuf_widths[2u]; - v_height2 = self->private_impl.f_components_workbuf_heights[2u]; - } - if ((self->private_impl.f_components_workbuf_offsets[3u] <= self->private_impl.f_components_workbuf_offsets[4u]) && (self->private_impl.f_components_workbuf_offsets[4u] <= ((uint64_t)(a_workbuf.len)))) { - v_src3 = wuffs_base__slice_u8__subslice_ij(a_workbuf, - self->private_impl.f_components_workbuf_offsets[3u], - self->private_impl.f_components_workbuf_offsets[4u]); - v_width3 = self->private_impl.f_components_workbuf_widths[3u]; - v_height3 = self->private_impl.f_components_workbuf_heights[3u]; + v_in2 = v_intermediate[50u]; + v_in6 = v_intermediate[54u]; + v_ra = ((uint32_t)(((uint32_t)(v_in2 + v_in6)) * 4433u)); + v_rb2 = ((uint32_t)(v_ra + ((uint32_t)(v_in2 * 6270u)))); + v_rb6 = ((uint32_t)(v_ra - ((uint32_t)(v_in6 * 15137u)))); + v_in0 = v_intermediate[48u]; + v_in4 = v_intermediate[52u]; + v_rcp = ((uint32_t)(((uint32_t)(v_in0 + v_in4)) << 13u)); + v_rcm = ((uint32_t)(((uint32_t)(v_in0 - v_in4)) << 13u)); + v_rd0 = ((uint32_t)(v_rcp + v_rb2)); + v_rd1 = ((uint32_t)(v_rcm + v_rb6)); + v_rd2 = ((uint32_t)(v_rcm - v_rb6)); + v_rd3 = ((uint32_t)(v_rcp - v_rb2)); + v_in1 = v_intermediate[49u]; + v_in3 = v_intermediate[51u]; + v_in5 = v_intermediate[53u]; + v_in7 = v_intermediate[55u]; + v_ri51 = ((uint32_t)(v_in5 + v_in1)); + v_ri53 = ((uint32_t)(v_in5 + v_in3)); + v_ri71 = ((uint32_t)(v_in7 + v_in1)); + v_ri73 = ((uint32_t)(v_in7 + v_in3)); + v_rj = ((uint32_t)(((uint32_t)(v_ri73 + v_ri51)) * 9633u)); + v_rk1 = ((uint32_t)(v_in1 * 12299u)); + v_rk3 = ((uint32_t)(v_in3 * 25172u)); + v_rk5 = ((uint32_t)(v_in5 * 16819u)); + v_rk7 = ((uint32_t)(v_in7 * 2446u)); + v_ri51 *= 4294964100u; + v_ri53 *= 4294946301u; + v_ri71 *= 4294959923u; + v_ri73 *= 4294951227u; + v_rl51 = ((uint32_t)(v_ri51 + v_rj)); + v_rl73 = ((uint32_t)(v_ri73 + v_rj)); + v_rk1 += ((uint32_t)(v_ri71 + v_rl51)); + v_rk3 += ((uint32_t)(v_ri53 + v_rl73)); + v_rk5 += ((uint32_t)(v_ri53 + v_rl51)); + v_rk7 += ((uint32_t)(v_ri71 + v_rl73)); + if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { + return wuffs_base__make_empty_struct(); } + a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 + v_rk1)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[7u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 - v_rk1)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[1u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 + v_rk3)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[6u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 - v_rk3)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[2u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 + v_rk5)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[5u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 - v_rk5)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[3u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 + v_rk7)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[4u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 - v_rk7)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); } - v_status = wuffs_base__pixel_swizzler__swizzle_ycck(&self->private_impl.f_swizzler, - a_dst, - wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024)), - (a_x0 & 65535u), - wuffs_base__u32__min(a_x1, self->private_impl.f_width), - (a_y0 & 65535u), - wuffs_base__u32__min(a_y1, self->private_impl.f_height), - v_src0, - v_src1, - v_src2, - v_src3, - v_width0, - v_width1, - v_width2, - v_width3, - v_height0, - v_height1, - v_height2, - v_height3, - v_width0, - v_width1, - v_width2, - v_width3, - self->private_impl.f_components_h[0u], - self->private_impl.f_components_h[1u], - self->private_impl.f_components_h[2u], - self->private_impl.f_components_h[3u], - self->private_impl.f_components_v[0u], - self->private_impl.f_components_v[1u], - self->private_impl.f_components_v[2u], - self->private_impl.f_components_v[3u], - self->private_impl.f_is_rgb_or_cmyk, - ! self->private_impl.f_use_lower_quality, - wuffs_base__make_slice_u8(self->private_data.f_swizzle_ycck_scratch_buffer_2k, 2048)); - return wuffs_private_impl__status__ensure_not_a_suspension(v_status); -} - -// -------- func jpeg.decoder.frame_dirty_rect - -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32 -wuffs_jpeg__decoder__frame_dirty_rect( - const wuffs_jpeg__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 jpeg.decoder.num_animation_loops - -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC uint32_t -wuffs_jpeg__decoder__num_animation_loops( - const wuffs_jpeg__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 jpeg.decoder.num_decoded_frame_configs - -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC uint64_t -wuffs_jpeg__decoder__num_decoded_frame_configs( - const wuffs_jpeg__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 jpeg.decoder.num_decoded_frames - -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC uint64_t -wuffs_jpeg__decoder__num_decoded_frames( - const wuffs_jpeg__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 jpeg.decoder.restart_frame - -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_jpeg__decoder__restart_frame( - wuffs_jpeg__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); - } - - uint32_t v_i = 0; - uint32_t v_j = 0; - - if (self->private_impl.f_call_sequence < 32u) { - return wuffs_base__make_status(wuffs_base__error__bad_call_sequence); - } - if (a_index != 0u) { - return wuffs_base__make_status(wuffs_base__error__bad_argument); - } - self->private_impl.f_call_sequence = 40u; - self->private_impl.f_bitstream_is_closed = false; - self->private_impl.f_expect_multiple_scans = false; - self->private_impl.f_frame_config_io_position = a_io_position; - self->private_impl.f_scan_count = 0u; - self->private_impl.f_restart_interval = self->private_impl.f_saved_restart_interval; - v_i = 0u; - while (v_i < 4u) { - self->private_impl.f_seen_dqt[v_i] = self->private_impl.f_saved_seen_dqt[v_i]; - v_j = 0u; - while (v_j < 64u) { - self->private_impl.f_quant_tables[v_i][v_j] = self->private_impl.f_saved_quant_tables[v_i][v_j]; - v_j += 1u; + if (0u == (v_intermediate[57u] | + v_intermediate[58u] | + v_intermediate[59u] | + v_intermediate[60u] | + v_intermediate[61u] | + v_intermediate[62u] | + v_intermediate[63u])) { + if (8u > ((uint64_t)(a_dst_buffer.len))) { + return wuffs_base__make_empty_struct(); } - v_i += 1u; - } - v_i = 0u; - while (v_i < 4u) { - v_j = 0u; - while (v_j < 10u) { - self->private_impl.f_block_smoothing_lowest_scan_al[v_i][v_j] = 16u; - v_j += 1u; + a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(v_intermediate[56u] + 16u)) >> 5u) & 1023u)]; + a_dst_buffer.ptr[1u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[2u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[3u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[4u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[5u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[6u] = a_dst_buffer.ptr[0u]; + a_dst_buffer.ptr[7u] = a_dst_buffer.ptr[0u]; + } else { + v_in2 = v_intermediate[58u]; + v_in6 = v_intermediate[62u]; + v_ra = ((uint32_t)(((uint32_t)(v_in2 + v_in6)) * 4433u)); + v_rb2 = ((uint32_t)(v_ra + ((uint32_t)(v_in2 * 6270u)))); + v_rb6 = ((uint32_t)(v_ra - ((uint32_t)(v_in6 * 15137u)))); + v_in0 = v_intermediate[56u]; + v_in4 = v_intermediate[60u]; + v_rcp = ((uint32_t)(((uint32_t)(v_in0 + v_in4)) << 13u)); + v_rcm = ((uint32_t)(((uint32_t)(v_in0 - v_in4)) << 13u)); + v_rd0 = ((uint32_t)(v_rcp + v_rb2)); + v_rd1 = ((uint32_t)(v_rcm + v_rb6)); + v_rd2 = ((uint32_t)(v_rcm - v_rb6)); + v_rd3 = ((uint32_t)(v_rcp - v_rb2)); + v_in1 = v_intermediate[57u]; + v_in3 = v_intermediate[59u]; + v_in5 = v_intermediate[61u]; + v_in7 = v_intermediate[63u]; + v_ri51 = ((uint32_t)(v_in5 + v_in1)); + v_ri53 = ((uint32_t)(v_in5 + v_in3)); + v_ri71 = ((uint32_t)(v_in7 + v_in1)); + v_ri73 = ((uint32_t)(v_in7 + v_in3)); + v_rj = ((uint32_t)(((uint32_t)(v_ri73 + v_ri51)) * 9633u)); + v_rk1 = ((uint32_t)(v_in1 * 12299u)); + v_rk3 = ((uint32_t)(v_in3 * 25172u)); + v_rk5 = ((uint32_t)(v_in5 * 16819u)); + v_rk7 = ((uint32_t)(v_in7 * 2446u)); + v_ri51 *= 4294964100u; + v_ri53 *= 4294946301u; + v_ri71 *= 4294959923u; + v_ri73 *= 4294951227u; + v_rl51 = ((uint32_t)(v_ri51 + v_rj)); + v_rl73 = ((uint32_t)(v_ri73 + v_rj)); + v_rk1 += ((uint32_t)(v_ri71 + v_rl51)); + v_rk3 += ((uint32_t)(v_ri53 + v_rl73)); + v_rk5 += ((uint32_t)(v_ri53 + v_rl51)); + v_rk7 += ((uint32_t)(v_ri71 + v_rl73)); + if (8u > ((uint64_t)(a_dst_buffer.len))) { + return wuffs_base__make_empty_struct(); } - v_i += 1u; - } - v_i = 0u; - while (v_i < 8u) { - self->private_impl.f_seen_dht[v_i] = false; - v_i += 1u; + a_dst_buffer.ptr[0u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 + v_rk1)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[7u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd0 - v_rk1)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[1u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 + v_rk3)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[6u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd1 - v_rk3)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[2u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 + v_rk5)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[5u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd2 - v_rk5)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[3u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 + v_rk7)) + 131072u)) >> 18u) & 1023u)]; + a_dst_buffer.ptr[4u] = WUFFS_JPEG__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(v_rd3 - v_rk7)) + 131072u)) >> 18u) & 1023u)]; } - return wuffs_base__make_status(NULL); + return wuffs_base__make_empty_struct(); } -// -------- func jpeg.decoder.set_report_metadata +// ‼ WUFFS MULTI-FILE SECTION +x86_avx2 +// -------- func jpeg.decoder.decode_idct_x86_avx2 +#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V3) +WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2,avx2") WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct -wuffs_jpeg__decoder__set_report_metadata( +static wuffs_base__empty_struct +wuffs_jpeg__decoder__decode_idct_x86_avx2( wuffs_jpeg__decoder* self, - uint32_t a_fourcc, - bool a_report) { + wuffs_base__slice_u8 a_dst_buffer, + uint64_t a_dst_stride, + uint32_t a_q) { + __m256i v_k_0000 = {0}; + __m256i v_k_8080 = {0}; + __m256i v_k_0000_0002 = {0}; + __m256i v_k_0001_FFFF = {0}; + __m256i v_k_0400_0000 = {0}; + __m256i v_k_29CF_1151_D630_1151 = {0}; + __m256i v_k_E333_133E_ADFD_1051 = {0}; + __m256i v_k_E6DC_25A1_1925_25A1 = {0}; + __m256i v_k_ECC1_E333_EFB0_ADFD = {0}; + __m128i v_az_coeffs = {0}; + __m256i v_az_ah00 = {0}; + __m256i v_az_ad00 = {0}; + __m256i v_az_eh00 = {0}; + __m256i v_az_adeh = {0}; + __m256i v_rows01 = {0}; + __m256i v_rows23 = {0}; + __m256i v_rows45 = {0}; + __m256i v_rows67 = {0}; + __m256i v_quants01 = {0}; + __m256i v_quants23 = {0}; + __m256i v_quants45 = {0}; + __m256i v_quants67 = {0}; + __m256i v_rows04 = {0}; + __m256i v_rows31 = {0}; + __m256i v_rows26 = {0}; + __m256i v_rows75 = {0}; + __m256i v_fp_rows62 = {0}; + __m256i v_fp_bq2662ad = {0}; + __m256i v_fp_bq2662eh = {0}; + __m256i v_fp_cb26ad = {0}; + __m256i v_fp_cb26eh = {0}; + __m256i v_fp_rows40pos = {0}; + __m256i v_fp_rows04neg = {0}; + __m256i v_fp_rows0pm4 = {0}; + __m256i v_fp_ccpmad = {0}; + __m256i v_fp_ccpmeh = {0}; + __m256i v_fp_cd01ad = {0}; + __m256i v_fp_cd01eh = {0}; + __m256i v_fp_cd32ad = {0}; + __m256i v_fp_cd32eh = {0}; + __m256i v_fp_sums7351 = {0}; + __m256i v_fp_sums5173 = {0}; + __m256i v_fp_ci73515173ad = {0}; + __m256i v_fp_ci73515173eh = {0}; + __m256i v_fp_cl7351ad = {0}; + __m256i v_fp_cl7351eh = {0}; + __m256i v_fp_rows13 = {0}; + __m256i v_fp_bq7153ad = {0}; + __m256i v_fp_bq7153eh = {0}; + __m256i v_fp_ck75ad = {0}; + __m256i v_fp_ck75eh = {0}; + __m256i v_fp_cl5173ad = {0}; + __m256i v_fp_cl5173eh = {0}; + __m256i v_fp_ck13ad = {0}; + __m256i v_fp_ck13eh = {0}; + __m256i v_intermediate01ad = {0}; + __m256i v_intermediate01eh = {0}; + __m256i v_intermediate01 = {0}; + __m256i v_intermediate32ad = {0}; + __m256i v_intermediate32eh = {0}; + __m256i v_intermediate32 = {0}; + __m256i v_intermediate45ad = {0}; + __m256i v_intermediate45eh = {0}; + __m256i v_intermediate45 = {0}; + __m256i v_intermediate76ad = {0}; + __m256i v_intermediate76eh = {0}; + __m256i v_intermediate76 = {0}; + __m256i v_ita0a1e0e1 = {0}; + __m256i v_ita2a3e2e3 = {0}; + __m256i v_ita4a5e4e5 = {0}; + __m256i v_ita6a7e6e7 = {0}; + __m256i v_ita0c0e0g0 = {0}; + __m256i v_ita1c1e1g1 = {0}; + __m256i v_ita4c4e4g4 = {0}; + __m256i v_ita5c5e5g5 = {0}; + __m256i v_ita0b0e0f0 = {0}; + __m256i v_ita4b4e4f4 = {0}; + __m256i v_itc0d0g0h0 = {0}; + __m256i v_itc4d4g4h4 = {0}; + __m256i v_intermediateae = {0}; + __m256i v_intermediatebf = {0}; + __m256i v_intermediatecg = {0}; + __m256i v_intermediatedh = {0}; + __m256i v_intermediatedb = {0}; + __m256i v_intermediatehf = {0}; + __m256i v_sp_cols62 = {0}; + __m256i v_sp_bq2662ad = {0}; + __m256i v_sp_bq2662eh = {0}; + __m256i v_sp_rb26ad = {0}; + __m256i v_sp_rb26eh = {0}; + __m256i v_sp_cols40pos = {0}; + __m256i v_sp_cols04neg = {0}; + __m256i v_sp_cols0pm4 = {0}; + __m256i v_sp_rcpmad = {0}; + __m256i v_sp_rcpmeh = {0}; + __m256i v_sp_rd01ad = {0}; + __m256i v_sp_rd01eh = {0}; + __m256i v_sp_rd32ad = {0}; + __m256i v_sp_rd32eh = {0}; + __m256i v_sp_sums7351 = {0}; + __m256i v_sp_sums5173 = {0}; + __m256i v_sp_ri73515173ad = {0}; + __m256i v_sp_ri73515173eh = {0}; + __m256i v_sp_rl7351ad = {0}; + __m256i v_sp_rl7351eh = {0}; + __m256i v_sp_cols13 = {0}; + __m256i v_sp_bq7153ad = {0}; + __m256i v_sp_bq7153eh = {0}; + __m256i v_sp_rk75ad = {0}; + __m256i v_sp_rk75eh = {0}; + __m256i v_sp_rl5173ad = {0}; + __m256i v_sp_rl5173eh = {0}; + __m256i v_sp_rk13ad = {0}; + __m256i v_sp_rk13eh = {0}; + __m256i v_final01ad = {0}; + __m256i v_final01eh = {0}; + __m256i v_final01 = {0}; + __m256i v_final32ad = {0}; + __m256i v_final32eh = {0}; + __m256i v_final32 = {0}; + __m256i v_final45ad = {0}; + __m256i v_final45eh = {0}; + __m256i v_final45 = {0}; + __m256i v_final76ad = {0}; + __m256i v_final76eh = {0}; + __m256i v_final76 = {0}; + __m256i v_fta0a1e0e1 = {0}; + __m256i v_fta2a3e2e3 = {0}; + __m256i v_fta4a5e4e5 = {0}; + __m256i v_fta6a7e6e7 = {0}; + __m256i v_fta0c0e0g0 = {0}; + __m256i v_fta1c1e1g1 = {0}; + __m256i v_fta4c4e4g4 = {0}; + __m256i v_fta5c5e5g5 = {0}; + __m256i v_fta0b0e0f0 = {0}; + __m256i v_ftc0d0g0h0 = {0}; + __m256i v_fta4b4e4f4 = {0}; + __m256i v_ftc4d4g4h4 = {0}; + __m256i v_finalae = {0}; + __m256i v_finalbf = {0}; + __m256i v_finalcg = {0}; + __m256i v_finaldh = {0}; + __m256i v_final0145 = {0}; + __m256i v_final2367 = {0}; + uint64_t v_final0 = 0; + uint64_t v_final1 = 0; + uint64_t v_final2 = 0; + uint64_t v_final3 = 0; + uint64_t v_final4 = 0; + uint64_t v_final5 = 0; + uint64_t v_final6 = 0; + uint64_t v_final7 = 0; + wuffs_base__slice_u8 v_remaining = {0}; + + if (8u > a_dst_stride) { + return wuffs_base__make_empty_struct(); + } + v_k_0000 = _mm256_set_epi16((int16_t)(0u), (int16_t)(0u), (int16_t)(0u), (int16_t)(0u), (int16_t)(0u), (int16_t)(0u), (int16_t)(0u), (int16_t)(0u), (int16_t)(0u), (int16_t)(0u), (int16_t)(0u), (int16_t)(0u), (int16_t)(0u), (int16_t)(0u), (int16_t)(0u), (int16_t)(0u)); + v_k_8080 = _mm256_set_epi16((int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u), (int16_t)(32896u)); + v_k_0000_0002 = _mm256_set_epi16((int16_t)(2u), (int16_t)(0u), (int16_t)(2u), (int16_t)(0u), (int16_t)(2u), (int16_t)(0u), (int16_t)(2u), (int16_t)(0u), (int16_t)(2u), (int16_t)(0u), (int16_t)(2u), (int16_t)(0u), (int16_t)(2u), (int16_t)(0u), (int16_t)(2u), (int16_t)(0u)); + v_k_0001_FFFF = _mm256_set_epi16((int16_t)(65535u), (int16_t)(65535u), (int16_t)(65535u), (int16_t)(65535u), (int16_t)(65535u), (int16_t)(65535u), (int16_t)(65535u), (int16_t)(65535u), (int16_t)(1u), (int16_t)(1u), (int16_t)(1u), (int16_t)(1u), (int16_t)(1u), (int16_t)(1u), (int16_t)(1u), (int16_t)(1u)); + v_k_0400_0000 = _mm256_set_epi16((int16_t)(0u), (int16_t)(1024u), (int16_t)(0u), (int16_t)(1024u), (int16_t)(0u), (int16_t)(1024u), (int16_t)(0u), (int16_t)(1024u), (int16_t)(0u), (int16_t)(1024u), (int16_t)(0u), (int16_t)(1024u), (int16_t)(0u), (int16_t)(1024u), (int16_t)(0u), (int16_t)(1024u)); + v_k_29CF_1151_D630_1151 = _mm256_set_epi16((int16_t)(4433u), (int16_t)(54832u), (int16_t)(4433u), (int16_t)(54832u), (int16_t)(4433u), (int16_t)(54832u), (int16_t)(4433u), (int16_t)(54832u), (int16_t)(4433u), (int16_t)(10703u), (int16_t)(4433u), (int16_t)(10703u), (int16_t)(4433u), (int16_t)(10703u), (int16_t)(4433u), (int16_t)(10703u)); + v_k_E333_133E_ADFD_1051 = _mm256_set_epi16((int16_t)(4177u), (int16_t)(44541u), (int16_t)(4177u), (int16_t)(44541u), (int16_t)(4177u), (int16_t)(44541u), (int16_t)(4177u), (int16_t)(44541u), (int16_t)(4926u), (int16_t)(58163u), (int16_t)(4926u), (int16_t)(58163u), (int16_t)(4926u), (int16_t)(58163u), (int16_t)(4926u), (int16_t)(58163u)); + v_k_E6DC_25A1_1925_25A1 = _mm256_set_epi16((int16_t)(9633u), (int16_t)(6437u), (int16_t)(9633u), (int16_t)(6437u), (int16_t)(9633u), (int16_t)(6437u), (int16_t)(9633u), (int16_t)(6437u), (int16_t)(9633u), (int16_t)(59100u), (int16_t)(9633u), (int16_t)(59100u), (int16_t)(9633u), (int16_t)(59100u), (int16_t)(9633u), (int16_t)(59100u)); + v_k_ECC1_E333_EFB0_ADFD = _mm256_set_epi16((int16_t)(44541u), (int16_t)(61360u), (int16_t)(44541u), (int16_t)(61360u), (int16_t)(44541u), (int16_t)(61360u), (int16_t)(44541u), (int16_t)(61360u), (int16_t)(58163u), (int16_t)(60609u), (int16_t)(58163u), (int16_t)(60609u), (int16_t)(58163u), (int16_t)(60609u), (int16_t)(58163u), (int16_t)(60609u)); + do { + if (0u == (wuffs_base__peek_u64le__no_bounds_check((const uint8_t*)(const void*)(self->private_data.f_mcu_blocks[0u] + 8u)) | wuffs_base__peek_u64le__no_bounds_check((const uint8_t*)(const void*)(self->private_data.f_mcu_blocks[0u] + 16u)))) { + v_az_coeffs = _mm_or_si128(_mm_or_si128(_mm_or_si128(_mm_or_si128(_mm_or_si128(_mm_or_si128(_mm_lddqu_si128((const __m128i*)(const void*)(self->private_data.f_mcu_blocks[0u] + 8u)), _mm_lddqu_si128((const __m128i*)(const void*)(self->private_data.f_mcu_blocks[0u] + 16u))), _mm_lddqu_si128((const __m128i*)(const void*)(self->private_data.f_mcu_blocks[0u] + 24u))), _mm_lddqu_si128((const __m128i*)(const void*)(self->private_data.f_mcu_blocks[0u] + 32u))), _mm_lddqu_si128((const __m128i*)(const void*)(self->private_data.f_mcu_blocks[0u] + 40u))), _mm_lddqu_si128((const __m128i*)(const void*)(self->private_data.f_mcu_blocks[0u] + 48u))), _mm_lddqu_si128((const __m128i*)(const void*)(self->private_data.f_mcu_blocks[0u] + 56u))); + if (0u == ((uint64_t)(_mm_cvtsi128_si64(_mm_packs_epi16(v_az_coeffs, v_az_coeffs))))) { + v_rows01 = _mm256_lddqu_si256((const __m256i*)(const void*)(self->private_data.f_mcu_blocks[0u] + 0u)); + v_quants01 = _mm256_lddqu_si256((const __m256i*)(const void*)(self->private_impl.f_quant_tables[a_q] + 0u)); + v_rows01 = _mm256_mullo_epi16(v_rows01, v_quants01); + v_az_ah00 = _mm256_slli_epi16(v_rows01, (int32_t)(2u)); + v_az_ad00 = _mm256_unpacklo_epi16(v_az_ah00, v_az_ah00); + v_az_eh00 = _mm256_unpackhi_epi16(v_az_ah00, v_az_ah00); + v_az_adeh = _mm256_inserti128_si256(v_az_ad00, _mm256_castsi256_si128(v_az_eh00), (int32_t)(1u)); + v_intermediateae = _mm256_shuffle_epi32(v_az_adeh, (int32_t)(0u)); + v_intermediatebf = _mm256_shuffle_epi32(v_az_adeh, (int32_t)(85u)); + v_intermediatecg = _mm256_shuffle_epi32(v_az_adeh, (int32_t)(170u)); + v_intermediatedh = _mm256_shuffle_epi32(v_az_adeh, (int32_t)(255u)); + break; + } + } + v_rows01 = _mm256_lddqu_si256((const __m256i*)(const void*)(self->private_data.f_mcu_blocks[0u] + 0u)); + v_rows23 = _mm256_lddqu_si256((const __m256i*)(const void*)(self->private_data.f_mcu_blocks[0u] + 16u)); + v_rows45 = _mm256_lddqu_si256((const __m256i*)(const void*)(self->private_data.f_mcu_blocks[0u] + 32u)); + v_rows67 = _mm256_lddqu_si256((const __m256i*)(const void*)(self->private_data.f_mcu_blocks[0u] + 48u)); + v_quants01 = _mm256_lddqu_si256((const __m256i*)(const void*)(self->private_impl.f_quant_tables[a_q] + 0u)); + v_quants23 = _mm256_lddqu_si256((const __m256i*)(const void*)(self->private_impl.f_quant_tables[a_q] + 16u)); + v_quants45 = _mm256_lddqu_si256((const __m256i*)(const void*)(self->private_impl.f_quant_tables[a_q] + 32u)); + v_quants67 = _mm256_lddqu_si256((const __m256i*)(const void*)(self->private_impl.f_quant_tables[a_q] + 48u)); + v_rows01 = _mm256_mullo_epi16(v_rows01, v_quants01); + v_rows23 = _mm256_mullo_epi16(v_rows23, v_quants23); + v_rows45 = _mm256_mullo_epi16(v_rows45, v_quants45); + v_rows67 = _mm256_mullo_epi16(v_rows67, v_quants67); + v_rows04 = _mm256_permute2x128_si256(v_rows01, v_rows45, (int32_t)(32u)); + v_rows31 = _mm256_permute2x128_si256(v_rows23, v_rows01, (int32_t)(49u)); + v_rows26 = _mm256_permute2x128_si256(v_rows23, v_rows67, (int32_t)(32u)); + v_rows75 = _mm256_permute2x128_si256(v_rows67, v_rows45, (int32_t)(49u)); + v_fp_rows62 = _mm256_permute2x128_si256(v_rows26, v_rows26, (int32_t)(1u)); + v_fp_bq2662ad = _mm256_unpacklo_epi16(v_rows26, v_fp_rows62); + v_fp_bq2662eh = _mm256_unpackhi_epi16(v_rows26, v_fp_rows62); + v_fp_cb26ad = _mm256_madd_epi16(v_fp_bq2662ad, v_k_29CF_1151_D630_1151); + v_fp_cb26eh = _mm256_madd_epi16(v_fp_bq2662eh, v_k_29CF_1151_D630_1151); + v_fp_rows40pos = _mm256_permute2x128_si256(v_rows04, v_rows04, (int32_t)(1u)); + v_fp_rows04neg = _mm256_sign_epi16(v_rows04, v_k_0001_FFFF); + v_fp_rows0pm4 = _mm256_add_epi16(v_fp_rows40pos, v_fp_rows04neg); + v_fp_ccpmad = _mm256_srai_epi32(_mm256_unpacklo_epi16(v_k_0000, v_fp_rows0pm4), (int32_t)(3u)); + v_fp_ccpmeh = _mm256_srai_epi32(_mm256_unpackhi_epi16(v_k_0000, v_fp_rows0pm4), (int32_t)(3u)); + v_fp_cd01ad = _mm256_add_epi32(v_fp_ccpmad, v_fp_cb26ad); + v_fp_cd01eh = _mm256_add_epi32(v_fp_ccpmeh, v_fp_cb26eh); + v_fp_cd32ad = _mm256_sub_epi32(v_fp_ccpmad, v_fp_cb26ad); + v_fp_cd32eh = _mm256_sub_epi32(v_fp_ccpmeh, v_fp_cb26eh); + v_fp_sums7351 = _mm256_add_epi16(v_rows75, v_rows31); + v_fp_sums5173 = _mm256_permute2x128_si256(v_fp_sums7351, v_fp_sums7351, (int32_t)(1u)); + v_fp_ci73515173ad = _mm256_unpacklo_epi16(v_fp_sums7351, v_fp_sums5173); + v_fp_ci73515173eh = _mm256_unpackhi_epi16(v_fp_sums7351, v_fp_sums5173); + v_fp_cl7351ad = _mm256_madd_epi16(v_fp_ci73515173ad, v_k_E6DC_25A1_1925_25A1); + v_fp_cl7351eh = _mm256_madd_epi16(v_fp_ci73515173eh, v_k_E6DC_25A1_1925_25A1); + v_fp_rows13 = _mm256_permute2x128_si256(v_rows31, v_rows31, (int32_t)(1u)); + v_fp_bq7153ad = _mm256_unpacklo_epi16(v_rows75, v_fp_rows13); + v_fp_bq7153eh = _mm256_unpackhi_epi16(v_rows75, v_fp_rows13); + v_fp_ck75ad = _mm256_add_epi32(_mm256_madd_epi16(v_fp_bq7153ad, v_k_ECC1_E333_EFB0_ADFD), v_fp_cl7351ad); + v_fp_ck75eh = _mm256_add_epi32(_mm256_madd_epi16(v_fp_bq7153eh, v_k_ECC1_E333_EFB0_ADFD), v_fp_cl7351eh); + v_fp_cl5173ad = _mm256_permute2x128_si256(v_fp_cl7351ad, v_fp_cl7351ad, (int32_t)(1u)); + v_fp_cl5173eh = _mm256_permute2x128_si256(v_fp_cl7351eh, v_fp_cl7351eh, (int32_t)(1u)); + v_fp_ck13ad = _mm256_add_epi32(v_fp_cl5173ad, _mm256_madd_epi16(v_fp_bq7153ad, v_k_E333_133E_ADFD_1051)); + v_fp_ck13eh = _mm256_add_epi32(v_fp_cl5173eh, _mm256_madd_epi16(v_fp_bq7153eh, v_k_E333_133E_ADFD_1051)); + v_intermediate01ad = _mm256_srai_epi32(_mm256_add_epi32(_mm256_add_epi32(v_fp_cd01ad, v_fp_ck13ad), v_k_0400_0000), (int32_t)(11u)); + v_intermediate01eh = _mm256_srai_epi32(_mm256_add_epi32(_mm256_add_epi32(v_fp_cd01eh, v_fp_ck13eh), v_k_0400_0000), (int32_t)(11u)); + v_intermediate01 = _mm256_packs_epi32(v_intermediate01ad, v_intermediate01eh); + v_intermediate32ad = _mm256_srai_epi32(_mm256_add_epi32(_mm256_add_epi32(v_fp_cd32ad, v_fp_ck75ad), v_k_0400_0000), (int32_t)(11u)); + v_intermediate32eh = _mm256_srai_epi32(_mm256_add_epi32(_mm256_add_epi32(v_fp_cd32eh, v_fp_ck75eh), v_k_0400_0000), (int32_t)(11u)); + v_intermediate32 = _mm256_packs_epi32(v_intermediate32ad, v_intermediate32eh); + v_intermediate45ad = _mm256_srai_epi32(_mm256_add_epi32(_mm256_sub_epi32(v_fp_cd32ad, v_fp_ck75ad), v_k_0400_0000), (int32_t)(11u)); + v_intermediate45eh = _mm256_srai_epi32(_mm256_add_epi32(_mm256_sub_epi32(v_fp_cd32eh, v_fp_ck75eh), v_k_0400_0000), (int32_t)(11u)); + v_intermediate45 = _mm256_packs_epi32(v_intermediate45ad, v_intermediate45eh); + v_intermediate76ad = _mm256_srai_epi32(_mm256_add_epi32(_mm256_sub_epi32(v_fp_cd01ad, v_fp_ck13ad), v_k_0400_0000), (int32_t)(11u)); + v_intermediate76eh = _mm256_srai_epi32(_mm256_add_epi32(_mm256_sub_epi32(v_fp_cd01eh, v_fp_ck13eh), v_k_0400_0000), (int32_t)(11u)); + v_intermediate76 = _mm256_packs_epi32(v_intermediate76ad, v_intermediate76eh); + v_ita0a1e0e1 = _mm256_permute4x64_epi64(v_intermediate01, (int32_t)(216u)); + v_ita2a3e2e3 = _mm256_permute4x64_epi64(v_intermediate32, (int32_t)(114u)); + v_ita4a5e4e5 = _mm256_permute4x64_epi64(v_intermediate45, (int32_t)(216u)); + v_ita6a7e6e7 = _mm256_permute4x64_epi64(v_intermediate76, (int32_t)(114u)); + v_ita0c0e0g0 = _mm256_unpacklo_epi16(v_ita0a1e0e1, v_ita2a3e2e3); + v_ita1c1e1g1 = _mm256_unpackhi_epi16(v_ita0a1e0e1, v_ita2a3e2e3); + v_ita4c4e4g4 = _mm256_unpacklo_epi16(v_ita4a5e4e5, v_ita6a7e6e7); + v_ita5c5e5g5 = _mm256_unpackhi_epi16(v_ita4a5e4e5, v_ita6a7e6e7); + v_ita0b0e0f0 = _mm256_unpacklo_epi16(v_ita0c0e0g0, v_ita1c1e1g1); + v_itc0d0g0h0 = _mm256_unpackhi_epi16(v_ita0c0e0g0, v_ita1c1e1g1); + v_ita4b4e4f4 = _mm256_unpacklo_epi16(v_ita4c4e4g4, v_ita5c5e5g5); + v_itc4d4g4h4 = _mm256_unpackhi_epi16(v_ita4c4e4g4, v_ita5c5e5g5); + v_intermediateae = _mm256_unpacklo_epi64(v_ita0b0e0f0, v_ita4b4e4f4); + v_intermediatebf = _mm256_unpackhi_epi64(v_ita0b0e0f0, v_ita4b4e4f4); + v_intermediatecg = _mm256_unpacklo_epi64(v_itc0d0g0h0, v_itc4d4g4h4); + v_intermediatedh = _mm256_unpackhi_epi64(v_itc0d0g0h0, v_itc4d4g4h4); + } while (0); + v_intermediatedb = _mm256_permute2x128_si256(v_intermediatedh, v_intermediatebf, (int32_t)(32u)); + v_intermediatehf = _mm256_permute2x128_si256(v_intermediatedh, v_intermediatebf, (int32_t)(49u)); + v_sp_cols62 = _mm256_permute2x128_si256(v_intermediatecg, v_intermediatecg, (int32_t)(1u)); + v_sp_bq2662ad = _mm256_unpacklo_epi16(v_intermediatecg, v_sp_cols62); + v_sp_bq2662eh = _mm256_unpackhi_epi16(v_intermediatecg, v_sp_cols62); + v_sp_rb26ad = _mm256_madd_epi16(v_sp_bq2662ad, v_k_29CF_1151_D630_1151); + v_sp_rb26eh = _mm256_madd_epi16(v_sp_bq2662eh, v_k_29CF_1151_D630_1151); + v_sp_cols40pos = _mm256_permute2x128_si256(v_intermediateae, v_intermediateae, (int32_t)(1u)); + v_sp_cols04neg = _mm256_sign_epi16(v_intermediateae, v_k_0001_FFFF); + v_sp_cols0pm4 = _mm256_add_epi16(v_sp_cols40pos, v_sp_cols04neg); + v_sp_rcpmad = _mm256_srai_epi32(_mm256_unpacklo_epi16(v_k_0000, v_sp_cols0pm4), (int32_t)(3u)); + v_sp_rcpmeh = _mm256_srai_epi32(_mm256_unpackhi_epi16(v_k_0000, v_sp_cols0pm4), (int32_t)(3u)); + v_sp_rd01ad = _mm256_add_epi32(v_sp_rcpmad, v_sp_rb26ad); + v_sp_rd01eh = _mm256_add_epi32(v_sp_rcpmeh, v_sp_rb26eh); + v_sp_rd32ad = _mm256_sub_epi32(v_sp_rcpmad, v_sp_rb26ad); + v_sp_rd32eh = _mm256_sub_epi32(v_sp_rcpmeh, v_sp_rb26eh); + v_sp_sums7351 = _mm256_add_epi16(v_intermediatehf, v_intermediatedb); + v_sp_sums5173 = _mm256_permute2x128_si256(v_sp_sums7351, v_sp_sums7351, (int32_t)(1u)); + v_sp_ri73515173ad = _mm256_unpacklo_epi16(v_sp_sums7351, v_sp_sums5173); + v_sp_ri73515173eh = _mm256_unpackhi_epi16(v_sp_sums7351, v_sp_sums5173); + v_sp_rl7351ad = _mm256_madd_epi16(v_sp_ri73515173ad, v_k_E6DC_25A1_1925_25A1); + v_sp_rl7351eh = _mm256_madd_epi16(v_sp_ri73515173eh, v_k_E6DC_25A1_1925_25A1); + v_sp_cols13 = _mm256_permute2x128_si256(v_intermediatedb, v_intermediatedb, (int32_t)(1u)); + v_sp_bq7153ad = _mm256_unpacklo_epi16(v_intermediatehf, v_sp_cols13); + v_sp_bq7153eh = _mm256_unpackhi_epi16(v_intermediatehf, v_sp_cols13); + v_sp_rk75ad = _mm256_add_epi32(_mm256_madd_epi16(v_sp_bq7153ad, v_k_ECC1_E333_EFB0_ADFD), v_sp_rl7351ad); + v_sp_rk75eh = _mm256_add_epi32(_mm256_madd_epi16(v_sp_bq7153eh, v_k_ECC1_E333_EFB0_ADFD), v_sp_rl7351eh); + v_sp_rl5173ad = _mm256_permute2x128_si256(v_sp_rl7351ad, v_sp_rl7351ad, (int32_t)(1u)); + v_sp_rl5173eh = _mm256_permute2x128_si256(v_sp_rl7351eh, v_sp_rl7351eh, (int32_t)(1u)); + v_sp_rk13ad = _mm256_add_epi32(v_sp_rl5173ad, _mm256_madd_epi16(v_sp_bq7153ad, v_k_E333_133E_ADFD_1051)); + v_sp_rk13eh = _mm256_add_epi32(v_sp_rl5173eh, _mm256_madd_epi16(v_sp_bq7153eh, v_k_E333_133E_ADFD_1051)); + v_final01ad = _mm256_srai_epi32(_mm256_add_epi32(_mm256_add_epi32(v_sp_rd01ad, v_sp_rk13ad), v_k_0000_0002), (int32_t)(18u)); + v_final01eh = _mm256_srai_epi32(_mm256_add_epi32(_mm256_add_epi32(v_sp_rd01eh, v_sp_rk13eh), v_k_0000_0002), (int32_t)(18u)); + v_final01 = _mm256_packs_epi32(v_final01ad, v_final01eh); + v_final32ad = _mm256_srai_epi32(_mm256_add_epi32(_mm256_add_epi32(v_sp_rd32ad, v_sp_rk75ad), v_k_0000_0002), (int32_t)(18u)); + v_final32eh = _mm256_srai_epi32(_mm256_add_epi32(_mm256_add_epi32(v_sp_rd32eh, v_sp_rk75eh), v_k_0000_0002), (int32_t)(18u)); + v_final32 = _mm256_packs_epi32(v_final32ad, v_final32eh); + v_final45ad = _mm256_srai_epi32(_mm256_add_epi32(_mm256_sub_epi32(v_sp_rd32ad, v_sp_rk75ad), v_k_0000_0002), (int32_t)(18u)); + v_final45eh = _mm256_srai_epi32(_mm256_add_epi32(_mm256_sub_epi32(v_sp_rd32eh, v_sp_rk75eh), v_k_0000_0002), (int32_t)(18u)); + v_final45 = _mm256_packs_epi32(v_final45ad, v_final45eh); + v_final76ad = _mm256_srai_epi32(_mm256_add_epi32(_mm256_sub_epi32(v_sp_rd01ad, v_sp_rk13ad), v_k_0000_0002), (int32_t)(18u)); + v_final76eh = _mm256_srai_epi32(_mm256_add_epi32(_mm256_sub_epi32(v_sp_rd01eh, v_sp_rk13eh), v_k_0000_0002), (int32_t)(18u)); + v_final76 = _mm256_packs_epi32(v_final76ad, v_final76eh); + v_fta0a1e0e1 = _mm256_permute4x64_epi64(v_final01, (int32_t)(216u)); + v_fta2a3e2e3 = _mm256_permute4x64_epi64(v_final32, (int32_t)(114u)); + v_fta4a5e4e5 = _mm256_permute4x64_epi64(v_final45, (int32_t)(216u)); + v_fta6a7e6e7 = _mm256_permute4x64_epi64(v_final76, (int32_t)(114u)); + v_fta0c0e0g0 = _mm256_unpacklo_epi16(v_fta0a1e0e1, v_fta2a3e2e3); + v_fta1c1e1g1 = _mm256_unpackhi_epi16(v_fta0a1e0e1, v_fta2a3e2e3); + v_fta4c4e4g4 = _mm256_unpacklo_epi16(v_fta4a5e4e5, v_fta6a7e6e7); + v_fta5c5e5g5 = _mm256_unpackhi_epi16(v_fta4a5e4e5, v_fta6a7e6e7); + v_fta0b0e0f0 = _mm256_unpacklo_epi16(v_fta0c0e0g0, v_fta1c1e1g1); + v_ftc0d0g0h0 = _mm256_unpackhi_epi16(v_fta0c0e0g0, v_fta1c1e1g1); + v_fta4b4e4f4 = _mm256_unpacklo_epi16(v_fta4c4e4g4, v_fta5c5e5g5); + v_ftc4d4g4h4 = _mm256_unpackhi_epi16(v_fta4c4e4g4, v_fta5c5e5g5); + v_finalae = _mm256_unpacklo_epi64(v_fta0b0e0f0, v_fta4b4e4f4); + v_finalbf = _mm256_unpackhi_epi64(v_fta0b0e0f0, v_fta4b4e4f4); + v_finalcg = _mm256_unpacklo_epi64(v_ftc0d0g0h0, v_ftc4d4g4h4); + v_finaldh = _mm256_unpackhi_epi64(v_ftc0d0g0h0, v_ftc4d4g4h4); + v_final0145 = _mm256_add_epi8(_mm256_packs_epi16(v_finalae, v_finalbf), v_k_8080); + v_final2367 = _mm256_add_epi8(_mm256_packs_epi16(v_finalcg, v_finaldh), v_k_8080); + v_final0 = ((uint64_t)(_mm256_extract_epi64(v_final0145, (int32_t)(0u)))); + v_final1 = ((uint64_t)(_mm256_extract_epi64(v_final0145, (int32_t)(1u)))); + v_final2 = ((uint64_t)(_mm256_extract_epi64(v_final2367, (int32_t)(0u)))); + v_final3 = ((uint64_t)(_mm256_extract_epi64(v_final2367, (int32_t)(1u)))); + v_final4 = ((uint64_t)(_mm256_extract_epi64(v_final0145, (int32_t)(2u)))); + v_final5 = ((uint64_t)(_mm256_extract_epi64(v_final0145, (int32_t)(3u)))); + v_final6 = ((uint64_t)(_mm256_extract_epi64(v_final2367, (int32_t)(2u)))); + v_final7 = ((uint64_t)(_mm256_extract_epi64(v_final2367, (int32_t)(3u)))); + if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { + return wuffs_base__make_empty_struct(); + } + v_remaining = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); + wuffs_base__poke_u64le__no_bounds_check(a_dst_buffer.ptr, v_final0); + a_dst_buffer = v_remaining; + if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { + return wuffs_base__make_empty_struct(); + } + v_remaining = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); + wuffs_base__poke_u64le__no_bounds_check(a_dst_buffer.ptr, v_final1); + a_dst_buffer = v_remaining; + if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { + return wuffs_base__make_empty_struct(); + } + v_remaining = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); + wuffs_base__poke_u64le__no_bounds_check(a_dst_buffer.ptr, v_final2); + a_dst_buffer = v_remaining; + if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { + return wuffs_base__make_empty_struct(); + } + v_remaining = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); + wuffs_base__poke_u64le__no_bounds_check(a_dst_buffer.ptr, v_final3); + a_dst_buffer = v_remaining; + if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { + return wuffs_base__make_empty_struct(); + } + v_remaining = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); + wuffs_base__poke_u64le__no_bounds_check(a_dst_buffer.ptr, v_final4); + a_dst_buffer = v_remaining; + if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { + return wuffs_base__make_empty_struct(); + } + v_remaining = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); + wuffs_base__poke_u64le__no_bounds_check(a_dst_buffer.ptr, v_final5); + a_dst_buffer = v_remaining; + if (a_dst_stride > ((uint64_t)(a_dst_buffer.len))) { + return wuffs_base__make_empty_struct(); + } + v_remaining = wuffs_base__slice_u8__subslice_i(a_dst_buffer, a_dst_stride); + wuffs_base__poke_u64le__no_bounds_check(a_dst_buffer.ptr, v_final6); + a_dst_buffer = v_remaining; + if (8u > ((uint64_t)(a_dst_buffer.len))) { + return wuffs_base__make_empty_struct(); + } + wuffs_base__poke_u64le__no_bounds_check(a_dst_buffer.ptr, v_final7); return wuffs_base__make_empty_struct(); } +#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V3) +// ‼ WUFFS MULTI-FILE SECTION -x86_avx2 -// -------- func jpeg.decoder.tell_me_more +// -------- func jpeg.decoder.get_quirk + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC uint64_t +wuffs_jpeg__decoder__get_quirk( + const wuffs_jpeg__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; + } + + if (a_key == 2u) { + if (self->private_impl.f_use_lower_quality) { + return 18446744073709551615u; + } + } else if (a_key == 1162824704u) { + if (self->private_impl.f_reject_progressive_jpegs) { + return 1u; + } + } + return 0u; +} + +// -------- func jpeg.decoder.set_quirk WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_jpeg__decoder__tell_me_more( +wuffs_jpeg__decoder__set_quirk( wuffs_jpeg__decoder* self, - wuffs_base__io_buffer* a_dst, - wuffs_base__more_information* a_minfo, + 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); + } + + if (a_key == 2u) { + self->private_impl.f_use_lower_quality = (a_value >= 9223372036854775808u); + return wuffs_base__make_status(NULL); + } else if (a_key == 1162824704u) { + self->private_impl.f_reject_progressive_jpegs = (a_value != 0u); + return wuffs_base__make_status(NULL); + } + return wuffs_base__make_status(wuffs_base__error__unsupported_option); +} + +// -------- func jpeg.decoder.decode_image_config + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_jpeg__decoder__decode_image_config( + wuffs_jpeg__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); @@ -49628,23 +50155,47 @@ wuffs_jpeg__decoder__tell_me_more( ? wuffs_base__error__disabled_by_previous_error : wuffs_base__error__initialize_not_called); } - if (!a_dst || !a_src) { + 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 != 4)) { + (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); - status = wuffs_base__make_status(wuffs_base__error__no_more_information); - goto exit; + 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_jpeg__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_jpeg__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 ok; - ok: goto exit; exit: if (wuffs_base__status__is_error(&status)) { @@ -49653,2122 +50204,2013 @@ wuffs_jpeg__decoder__tell_me_more( return status; } -// -------- func jpeg.decoder.workbuf_len +// -------- func jpeg.decoder.do_decode_image_config WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 -wuffs_jpeg__decoder__workbuf_len( - const wuffs_jpeg__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(); - } - - if (self->private_impl.f_use_lower_quality && (self->private_impl.f_sof_marker < 194u)) { - return wuffs_base__utility__make_range_ii_u64(0u, self->private_impl.f_components_workbuf_offsets[8u]); - } - return wuffs_base__utility__make_range_ii_u64(self->private_impl.f_components_workbuf_offsets[8u], self->private_impl.f_components_workbuf_offsets[8u]); -} +static wuffs_base__status +wuffs_jpeg__decoder__do_decode_image_config( + wuffs_jpeg__decoder* self, + wuffs_base__image_config* a_dst, + wuffs_base__io_buffer* a_src) { + wuffs_base__status status = wuffs_base__make_status(NULL); -// -------- func jpeg.decoder.top_left_quants_has_zero + uint8_t v_c8 = 0; + uint8_t v_marker = 0; + uint32_t v_pixfmt = 0; -WUFFS_BASE__GENERATED_C_CODE -static bool -wuffs_jpeg__decoder__top_left_quants_has_zero( - const wuffs_jpeg__decoder* self, - uint32_t a_q) { - return ((self->private_impl.f_quant_tables[a_q][0u] == 0u) || - (self->private_impl.f_quant_tables[a_q][1u] == 0u) || - (self->private_impl.f_quant_tables[a_q][2u] == 0u) || - (self->private_impl.f_quant_tables[a_q][3u] == 0u) || - (self->private_impl.f_quant_tables[a_q][8u] == 0u) || - (self->private_impl.f_quant_tables[a_q][9u] == 0u) || - (self->private_impl.f_quant_tables[a_q][10u] == 0u) || - (self->private_impl.f_quant_tables[a_q][16u] == 0u) || - (self->private_impl.f_quant_tables[a_q][17u] == 0u) || - (self->private_impl.f_quant_tables[a_q][24u] == 0u)); -} - -// -------- func jpeg.decoder.load_mcu_blocks_for_single_component_smooth - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_jpeg__decoder__load_mcu_blocks_for_single_component_smooth( - wuffs_jpeg__decoder* self, - uint32_t a_mx, - uint32_t a_my, - wuffs_base__slice_u8 a_workbuf, - uint32_t a_csel) { - uint64_t v_stride16 = 0; - uint64_t v_offset = 0; - uint32_t v_dx = 0; - uint32_t v_dy = 0; - uint32_t v_mx = 0; - uint32_t v_my = 0; - uint8_t v_q = 0; - uint32_t v_q_00 = 0; - uint32_t v_q_xy = 0; - uint8_t v_al = 0; - uint32_t v_scratch = 0; - uint32_t v_limit = 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; + } - v_stride16 = ((uint64_t)((self->private_impl.f_components_workbuf_widths[a_csel] * 16u))); - v_offset = (self->private_impl.f_components_workbuf_offsets[(a_csel | 4u)] + (((uint64_t)(a_mx)) * 128u) + (((uint64_t)(a_my)) * v_stride16)); - if (v_offset <= ((uint64_t)(a_workbuf.len))) { - wuffs_private_impl__bulk_load_host_endian(&self->private_data.f_mcu_blocks[0], 1u * (size_t)128u, wuffs_base__slice_u8__subslice_i(a_workbuf, v_offset)); + uint32_t coro_susp_point = self->private_impl.p_do_decode_image_config; + if (coro_susp_point) { + v_marker = self->private_data.s_do_decode_image_config.v_marker; } - v_dy = 0u; - while (v_dy < 5u) { - v_my = wuffs_base__u32__min(self->private_impl.f_block_smoothing_my_max_incl, wuffs_base__u32__sat_sub((a_my + v_dy), 2u)); - v_dx = 0u; - while (v_dx < 5u) { - v_mx = wuffs_base__u32__min(self->private_impl.f_block_smoothing_mx_max_incl, wuffs_base__u32__sat_sub((a_mx + v_dx), 2u)); - v_offset = (self->private_impl.f_components_workbuf_offsets[(a_csel | 4u)] + (((uint64_t)(v_mx)) * 128u) + (((uint64_t)(v_my)) * v_stride16)); - if (v_offset <= ((uint64_t)(a_workbuf.len))) { - wuffs_private_impl__bulk_load_host_endian(&self->private_impl.f_block_smoothing_dc_values[v_dy][v_dx], 1u * (size_t)2u, wuffs_base__slice_u8__subslice_i(a_workbuf, v_offset)); + 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); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } - v_dx += 1u; + uint8_t t_0 = *iop_a_src++; + v_c8 = t_0; } - v_dy += 1u; - } - v_q = self->private_impl.f_components_tq[a_csel]; - v_q_00 = ((uint32_t)(self->private_impl.f_quant_tables[v_q][0u])); - if (v_q_00 <= 0u) { - return wuffs_base__make_empty_struct(); - } - if (0u != (16u & - self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][1u] & - self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][2u] & - self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][3u] & - self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][4u] & - self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][5u] & - self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][6u] & - self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][7u] & - self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][8u] & - self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][9u])) { - v_scratch = 0u; - v_scratch += ((uint32_t)(4294967294u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); - v_scratch += ((uint32_t)(4294967290u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); - v_scratch += ((uint32_t)(4294967288u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); - v_scratch += ((uint32_t)(4294967290u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); - v_scratch += ((uint32_t)(4294967294u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); - v_scratch += ((uint32_t)(4294967290u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); - v_scratch += ((uint32_t)(6u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); - v_scratch += ((uint32_t)(42u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); - v_scratch += ((uint32_t)(6u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); - v_scratch += ((uint32_t)(4294967290u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); - v_scratch += ((uint32_t)(4294967288u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); - v_scratch += ((uint32_t)(42u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); - v_scratch += ((uint32_t)(152u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); - v_scratch += ((uint32_t)(42u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); - v_scratch += ((uint32_t)(4294967288u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); - v_scratch += ((uint32_t)(4294967290u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); - v_scratch += ((uint32_t)(6u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); - v_scratch += ((uint32_t)(42u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); - v_scratch += ((uint32_t)(6u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); - v_scratch += ((uint32_t)(4294967290u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); - v_scratch += ((uint32_t)(4294967294u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); - v_scratch += ((uint32_t)(4294967290u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); - v_scratch += ((uint32_t)(4294967288u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); - v_scratch += ((uint32_t)(4294967290u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); - v_scratch += ((uint32_t)(4294967294u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); - if (v_scratch < 2147483648u) { - v_scratch = ((uint32_t)(0u + (((uint32_t)(((uint32_t)(0u + v_scratch)) + 128u)) / 256u))); - } else { - v_scratch = ((uint32_t)(0u - (((uint32_t)(((uint32_t)(0u - v_scratch)) + 128u)) / 256u))); + if (v_c8 != 255u) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_header); + goto exit; } - self->private_data.f_mcu_blocks[0u][0u] = ((uint16_t)(v_scratch)); - v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][1u])); - if ((v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][1u] == 0u)) { - v_scratch = 0u; - v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); - v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); - v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); - v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); - v_scratch += ((uint32_t)(4294967293u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); - v_scratch += ((uint32_t)(13u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); - v_scratch += ((uint32_t)(4294967283u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); - v_scratch += ((uint32_t)(3u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); - v_scratch += ((uint32_t)(4294967293u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); - v_scratch += ((uint32_t)(38u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); - v_scratch += ((uint32_t)(4294967258u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); - v_scratch += ((uint32_t)(3u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); - v_scratch += ((uint32_t)(4294967293u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); - v_scratch += ((uint32_t)(13u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); - v_scratch += ((uint32_t)(4294967283u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); - v_scratch += ((uint32_t)(3u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); - v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); - v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); - v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); - v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); - v_scratch *= v_q_00; - if (v_scratch < 2147483648u) { - v_scratch = ((uint32_t)(0u + (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); - } else { - v_scratch = ((uint32_t)(0u - (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } - self->private_data.f_mcu_blocks[0u][1u] = ((uint16_t)(v_scratch)); + uint8_t t_1 = *iop_a_src++; + v_c8 = t_1; } - v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][2u])); - if ((v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][2u] == 0u)) { - v_scratch = 0u; - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); - v_scratch += ((uint32_t)(2u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); - v_scratch += ((uint32_t)(4294967291u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); - v_scratch += ((uint32_t)(2u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); - v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); - v_scratch += ((uint32_t)(7u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); - v_scratch += ((uint32_t)(4294967282u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); - v_scratch += ((uint32_t)(7u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); - v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); - v_scratch += ((uint32_t)(2u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); - v_scratch += ((uint32_t)(4294967291u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); - v_scratch += ((uint32_t)(2u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); - v_scratch *= v_q_00; - if (v_scratch < 2147483648u) { - v_scratch = ((uint32_t)(0u + (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); - } else { - v_scratch = ((uint32_t)(0u - (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); - } - self->private_data.f_mcu_blocks[0u][2u] = ((uint16_t)(v_scratch)); + if (v_c8 != 216u) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_header); + goto exit; } - v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][3u])); - if ((v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][3u] == 0u)) { - v_scratch = 0u; - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); - v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); - v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); - v_scratch += ((uint32_t)(2u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); - v_scratch += ((uint32_t)(4294967294u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); - v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); - v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); - v_scratch *= v_q_00; - if (v_scratch < 2147483648u) { - v_scratch = ((uint32_t)(0u + (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); - } else { - v_scratch = ((uint32_t)(0u - (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); + while (true) { + while (true) { + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_2 = *iop_a_src++; + v_c8 = t_2; + } + if (v_c8 == 255u) { + break; + } } - self->private_data.f_mcu_blocks[0u][3u] = ((uint16_t)(v_scratch)); - } - v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][8u])); - if ((v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][8u] == 0u)) { - v_scratch = 0u; - v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); - v_scratch += ((uint32_t)(4294967293u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); - v_scratch += ((uint32_t)(4294967293u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); - v_scratch += ((uint32_t)(4294967293u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); - v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); - v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); - v_scratch += ((uint32_t)(13u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); - v_scratch += ((uint32_t)(38u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); - v_scratch += ((uint32_t)(13u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); - v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); - v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); - v_scratch += ((uint32_t)(4294967283u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); - v_scratch += ((uint32_t)(4294967258u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); - v_scratch += ((uint32_t)(4294967283u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); - v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); - v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); - v_scratch += ((uint32_t)(3u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); - v_scratch += ((uint32_t)(3u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); - v_scratch += ((uint32_t)(3u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); - v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); - v_scratch *= v_q_00; - if (v_scratch < 2147483648u) { - v_scratch = ((uint32_t)(0u + (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); + while (true) { + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_3 = *iop_a_src++; + v_c8 = t_3; + } + if (v_c8 != 255u) { + v_marker = v_c8; + break; + } + } + if (v_marker == 0u) { + continue; + } else if ((208u <= v_marker) && (v_marker <= 217u)) { + if (v_marker <= 215u) { + continue; + } } else { - v_scratch = ((uint32_t)(0u - (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); + uint32_t t_4; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { + t_4 = ((uint32_t)(wuffs_base__peek_u16be__no_bounds_check(iop_a_src))); + iop_a_src += 2; + } else { + self->private_data.s_do_decode_image_config.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); + 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_4 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_4); + if (num_bits_4 == 8) { + t_4 = ((uint32_t)(*scratch >> 48)); + break; + } + num_bits_4 += 8u; + *scratch |= ((uint64_t)(num_bits_4)); + } + } + self->private_impl.f_payload_length = t_4; + } + if (self->private_impl.f_payload_length < 2u) { + if ((v_marker == 254u) || ((224u <= v_marker) && (v_marker < 240u))) { + continue; + } + status = wuffs_base__make_status(wuffs_jpeg__error__bad_marker); + goto exit; + } + self->private_impl.f_payload_length -= 2u; } - self->private_data.f_mcu_blocks[0u][8u] = ((uint16_t)(v_scratch)); - } - v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][9u])); - if ((v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][9u] == 0u)) { - v_scratch = 0u; - v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); - v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); - v_scratch += ((uint32_t)(9u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); - v_scratch += ((uint32_t)(4294967287u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); - v_scratch += ((uint32_t)(4294967287u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); - v_scratch += ((uint32_t)(9u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); - v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); - v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); - v_scratch *= v_q_00; - if (v_scratch < 2147483648u) { - v_scratch = ((uint32_t)(0u + (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); + if (v_marker < 192u) { + status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_marker); + goto exit; + } else if (v_marker < 208u) { + if (v_marker <= 194u) { + if ((v_marker == 194u) && self->private_impl.f_reject_progressive_jpegs) { + status = wuffs_base__make_status(wuffs_jpeg__error__rejected_progressive_jpeg); + goto exit; + } else if (self->private_impl.f_sof_marker != 0u) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_sof_marker); + goto exit; + } else if (v_marker == 192u) { + if (self->private_impl.f_seen_dht[2u] || + self->private_impl.f_seen_dht[3u] || + self->private_impl.f_seen_dht[6u] || + self->private_impl.f_seen_dht[7u]) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_sof_marker); + goto exit; + } + } + self->private_impl.f_sof_marker = v_marker; + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); + status = wuffs_jpeg__decoder__decode_sof(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } + break; + } else if (v_marker == 195u) { + status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_lossless_coding); + goto exit; + } else if (v_marker == 196u) { + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); + status = wuffs_jpeg__decoder__decode_dht(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } + continue; + } else if ((197u <= v_marker) && (v_marker <= 199u)) { + status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_hierarchical_coding); + goto exit; + } else if (v_marker == 200u) { + status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_marker); + goto exit; + } else { + status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_arithmetic_coding); + goto exit; + } + } else if (v_marker < 224u) { + if (v_marker < 218u) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_marker); + goto exit; + } else if (v_marker == 218u) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); + goto exit; + } else if (v_marker == 219u) { + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); + status = wuffs_jpeg__decoder__decode_dqt(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } + continue; + } else if (v_marker == 221u) { + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10); + status = wuffs_jpeg__decoder__decode_dri(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } + continue; + } else { + status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_marker); + goto exit; + } + } else if (v_marker < 240u) { + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11); + status = wuffs_jpeg__decoder__decode_appn(self, a_src, v_marker); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } + continue; } else { - v_scratch = ((uint32_t)(0u - (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); + if (v_marker == 254u) { + } else { + status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_marker); + goto exit; + } } - self->private_data.f_mcu_blocks[0u][9u] = ((uint16_t)(v_scratch)); + self->private_data.s_do_decode_image_config.scratch = self->private_impl.f_payload_length; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12); + if (self->private_data.s_do_decode_image_config.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { + self->private_data.s_do_decode_image_config.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); + iop_a_src = io2_a_src; + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + iop_a_src += self->private_data.s_do_decode_image_config.scratch; + self->private_impl.f_payload_length = 0u; } - v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][10u])); - if ((v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][10u] == 0u)) { - v_scratch = 0u; - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); - v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); - v_scratch += ((uint32_t)(4294967293u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); - v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); - v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); - v_scratch += ((uint32_t)(3u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); - v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); - v_scratch *= v_q_00; - if (v_scratch < 2147483648u) { - v_scratch = ((uint32_t)(0u + (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); - } else { - v_scratch = ((uint32_t)(0u - (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); - } - self->private_data.f_mcu_blocks[0u][10u] = ((uint16_t)(v_scratch)); - } - v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][16u])); - if ((v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][16u] == 0u)) { - v_scratch = 0u; - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); - v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); - v_scratch += ((uint32_t)(2u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); - v_scratch += ((uint32_t)(7u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); - v_scratch += ((uint32_t)(2u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); - v_scratch += ((uint32_t)(4294967291u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); - v_scratch += ((uint32_t)(4294967282u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); - v_scratch += ((uint32_t)(4294967291u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); - v_scratch += ((uint32_t)(2u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); - v_scratch += ((uint32_t)(7u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); - v_scratch += ((uint32_t)(2u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); - v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); - v_scratch *= v_q_00; - if (v_scratch < 2147483648u) { - v_scratch = ((uint32_t)(0u + (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); - } else { - v_scratch = ((uint32_t)(0u - (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); - } - self->private_data.f_mcu_blocks[0u][16u] = ((uint16_t)(v_scratch)); - } - v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][17u])); - if ((v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][17u] == 0u)) { - v_scratch = 0u; - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); - v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); - v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); - v_scratch += ((uint32_t)(4294967293u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); - v_scratch += ((uint32_t)(3u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); - v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); - v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); - v_scratch *= v_q_00; - if (v_scratch < 2147483648u) { - v_scratch = ((uint32_t)(0u + (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); - } else { - v_scratch = ((uint32_t)(0u - (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); - } - self->private_data.f_mcu_blocks[0u][17u] = ((uint16_t)(v_scratch)); - } - v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][24u])); - if ((v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][24u] == 0u)) { - v_scratch = 0u; - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); - v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); - v_scratch += ((uint32_t)(2u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); - v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); - v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); - v_scratch += ((uint32_t)(4294967294u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); - v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); - v_scratch *= v_q_00; - if (v_scratch < 2147483648u) { - v_scratch = ((uint32_t)(0u + (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); - } else { - v_scratch = ((uint32_t)(0u - (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); + self->private_impl.choosy_decode_idct = ( +#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V3) + wuffs_base__cpu_arch__have_x86_avx2() ? &wuffs_jpeg__decoder__decode_idct_x86_avx2 : +#endif + self->private_impl.choosy_decode_idct); + self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))); + if (a_dst != NULL) { + v_pixfmt = 536870920u; + if (self->private_impl.f_num_components > 1u) { + v_pixfmt = 2415954056u; } - self->private_data.f_mcu_blocks[0u][24u] = ((uint16_t)(v_scratch)); + wuffs_base__image_config__set( + a_dst, + v_pixfmt, + 0u, + self->private_impl.f_width, + self->private_impl.f_height, + self->private_impl.f_frame_config_io_position, + true); } - } else { - v_al = self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][1u]; - v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][1u])); - if ((v_al > 0u) && (v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][1u] == 0u)) { - v_limit = ((((uint32_t)(1u)) << v_al) - 1u); - v_scratch = 0u; - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); - v_scratch += ((uint32_t)(4294967289u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); - v_scratch += ((uint32_t)(50u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); - v_scratch += ((uint32_t)(4294967246u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); - v_scratch += ((uint32_t)(7u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); - v_scratch *= v_q_00; - if (v_scratch < 2147483648u) { - v_scratch = ((uint32_t)(0u + wuffs_base__u32__min(v_limit, (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u))))); - } else { - v_scratch = ((uint32_t)(0u - wuffs_base__u32__min(v_limit, (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u))))); + 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; + self->private_data.s_do_decode_image_config.v_marker = v_marker; + + 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 jpeg.decoder.decode_dqt + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_jpeg__decoder__decode_dqt( + wuffs_jpeg__decoder* self, + wuffs_base__io_buffer* a_src) { + wuffs_base__status status = wuffs_base__make_status(NULL); + + uint8_t v_c8 = 0; + uint8_t v_q = 0; + uint32_t v_i = 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_decode_dqt; + if (coro_susp_point) { + v_q = self->private_data.s_decode_dqt.v_q; + v_i = self->private_data.s_decode_dqt.v_i; + } + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + + while (self->private_impl.f_payload_length > 0u) { + self->private_impl.f_payload_length -= 1u; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_0 = *iop_a_src++; + v_c8 = t_0; } - self->private_data.f_mcu_blocks[0u][1u] = ((uint16_t)(v_scratch)); - } - v_al = self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][5u]; - v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][2u])); - if ((v_al > 0u) && (v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][2u] == 0u)) { - v_limit = ((((uint32_t)(1u)) << v_al) - 1u); - v_scratch = 0u; - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); - v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); - v_scratch += ((uint32_t)(13u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); - v_scratch += ((uint32_t)(4294967272u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); - v_scratch += ((uint32_t)(13u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); - v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); - v_scratch *= v_q_00; - if (v_scratch < 2147483648u) { - v_scratch = ((uint32_t)(0u + wuffs_base__u32__min(v_limit, (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u))))); - } else { - v_scratch = ((uint32_t)(0u - wuffs_base__u32__min(v_limit, (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u))))); + if (((uint8_t)(v_c8 & 15u)) > 3u) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_dqt_marker); + goto exit; } - self->private_data.f_mcu_blocks[0u][2u] = ((uint16_t)(v_scratch)); - } - v_al = self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][2u]; - v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][8u])); - if ((v_al > 0u) && (v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][8u] == 0u)) { - v_limit = ((((uint32_t)(1u)) << v_al) - 1u); - v_scratch = 0u; - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); - v_scratch += ((uint32_t)(4294967289u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); - v_scratch += ((uint32_t)(50u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); - v_scratch += ((uint32_t)(4294967246u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); - v_scratch += ((uint32_t)(7u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); - v_scratch *= v_q_00; - if (v_scratch < 2147483648u) { - v_scratch = ((uint32_t)(0u + wuffs_base__u32__min(v_limit, (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u))))); - } else { - v_scratch = ((uint32_t)(0u - wuffs_base__u32__min(v_limit, (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u))))); + v_q = ((uint8_t)(v_c8 & 15u)); + if (((uint8_t)(v_c8 >> 4u)) == 1u) { + status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_precision); + goto exit; + } else if ((((uint8_t)(v_c8 >> 4u)) > 1u) || (self->private_impl.f_payload_length < 64u)) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_dqt_marker); + goto exit; } - self->private_data.f_mcu_blocks[0u][8u] = ((uint16_t)(v_scratch)); - } - v_al = self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][4u]; - v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][9u])); - if ((v_al > 0u) && (v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][9u] == 0u)) { - v_limit = ((((uint32_t)(1u)) << v_al) - 1u); - v_scratch = 0u; - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); - v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); - v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); - v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); - v_scratch += ((uint32_t)(10u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); - v_scratch += ((uint32_t)(4294967286u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); - v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); - v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); - v_scratch += ((uint32_t)(4294967286u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); - v_scratch += ((uint32_t)(10u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); - v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); - v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); - v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); - v_scratch *= v_q_00; - if (v_scratch < 2147483648u) { - v_scratch = ((uint32_t)(0u + wuffs_base__u32__min(v_limit, (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u))))); - } else { - v_scratch = ((uint32_t)(0u - wuffs_base__u32__min(v_limit, (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u))))); + self->private_impl.f_payload_length -= 64u; + v_i = 0u; + while (v_i < 64u) { + v_i += 1u; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint16_t t_1 = *iop_a_src++; + self->private_impl.f_quant_tables[v_q][WUFFS_JPEG__UNZIG[v_i]] = t_1; + } } - self->private_data.f_mcu_blocks[0u][9u] = ((uint16_t)(v_scratch)); - } - v_al = self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][3u]; - v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][16u])); - if ((v_al > 0u) && (v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][16u] == 0u)) { - v_limit = ((((uint32_t)(1u)) << v_al) - 1u); - v_scratch = 0u; - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); - v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); - v_scratch += ((uint32_t)(13u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); - v_scratch += ((uint32_t)(4294967272u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); - v_scratch += ((uint32_t)(13u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); - v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); - v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); - v_scratch *= v_q_00; - if (v_scratch < 2147483648u) { - v_scratch = ((uint32_t)(0u + wuffs_base__u32__min(v_limit, (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u))))); - } else { - v_scratch = ((uint32_t)(0u - wuffs_base__u32__min(v_limit, (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u))))); + self->private_impl.f_seen_dqt[v_q] = true; + if (self->private_impl.f_sof_marker == 0u) { + v_i = 0u; + while (v_i < 64u) { + self->private_impl.f_saved_quant_tables[v_q][v_i] = self->private_impl.f_quant_tables[v_q][v_i]; + v_i += 1u; + } + self->private_impl.f_saved_seen_dqt[v_q] = true; } - self->private_data.f_mcu_blocks[0u][16u] = ((uint16_t)(v_scratch)); } + + goto ok; + ok: + self->private_impl.p_decode_dqt = 0; + goto exit; } - return wuffs_base__make_empty_struct(); -} -// -------- func jpeg.decoder.decode_mcu + goto suspend; + suspend: + self->private_impl.p_decode_dqt = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_data.s_decode_dqt.v_q = v_q; + self->private_data.s_decode_dqt.v_i = v_i; -WUFFS_BASE__GENERATED_C_CODE -static uint32_t -wuffs_jpeg__decoder__decode_mcu( - wuffs_jpeg__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__slice_u8 a_workbuf, - uint32_t a_mx, - uint32_t a_my) { - return (*self->private_impl.choosy_decode_mcu)(self, a_dst, a_workbuf, a_mx, a_my); + 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 jpeg.decoder.decode_dri + WUFFS_BASE__GENERATED_C_CODE -static uint32_t -wuffs_jpeg__decoder__decode_mcu__choosy_default( +static wuffs_base__status +wuffs_jpeg__decoder__decode_dri( wuffs_jpeg__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__slice_u8 a_workbuf, - uint32_t a_mx, - uint32_t a_my) { - uint32_t v_ret = 0; - uint64_t v_bits = 0; - uint32_t v_n_bits = 0; - uint8_t v_csel = 0; - wuffs_base__io_buffer u_r = wuffs_base__empty_io_buffer(); - wuffs_base__io_buffer* v_r = &u_r; - const uint8_t* iop_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - const uint8_t* io0_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - const uint8_t* io1_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - const uint8_t* io2_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - uint32_t v_pos = 0; - uint8_t v_dc_h = 0; - uint32_t v_dc_symbol = 0; - uint32_t v_dc_ht_fast = 0; - uint32_t v_dc_bl = 0; - uint32_t v_dc_code = 0; - uint32_t v_dc_blm1 = 0; - uint32_t v_dc_ht_slow = 0; - uint16_t v_dc_value = 0; - uint16_t v_dc_extend = 0; - const uint16_t* v_ac_huff_table_fast = NULL; - uint8_t v_ac_h = 0; - uint32_t v_ac_symbol = 0; - uint32_t v_ac_ht_fast = 0; - uint32_t v_ac_bl = 0; - uint32_t v_ac_code = 0; - uint32_t v_ac_blm1 = 0; - uint32_t v_ac_ht_slow = 0; - uint16_t v_ac_value = 0; - uint16_t v_ac_extend = 0; - uint32_t v_ac_rrrr = 0; - uint32_t v_ac_ssss = 0; - uint32_t v_z = 0; - uint32_t v_mcb = 0; - uint64_t v_stride = 0; - uint64_t v_offset = 0; + wuffs_base__io_buffer* a_src) { + wuffs_base__status status = wuffs_base__make_status(NULL); - v_bits = self->private_impl.f_bitstream_bits; - v_n_bits = self->private_impl.f_bitstream_n_bits; - if (self->private_impl.f_bitstream_ri > self->private_impl.f_bitstream_wi) { - return 2u; - } - { - wuffs_base__io_buffer* o_0_v_r = v_r; - const uint8_t* o_0_iop_v_r = iop_v_r; - const uint8_t* o_0_io0_v_r = io0_v_r; - const uint8_t* o_0_io1_v_r = io1_v_r; - const uint8_t* o_0_io2_v_r = io2_v_r; - v_r = wuffs_private_impl__io_reader__set( - &u_r, - &iop_v_r, - &io0_v_r, - &io1_v_r, - &io2_v_r, - wuffs_base__make_slice_u8_ij(self->private_data.f_bitstream_buffer, - self->private_impl.f_bitstream_ri, - self->private_impl.f_bitstream_wi), - ((uint64_t)(self->private_impl.f_bitstream_ri))); - do { - while (self->private_impl.f_mcu_current_block < self->private_impl.f_mcu_num_blocks) { - while (self->private_impl.f_mcu_zig_index <= 0u) { - wuffs_private_impl__bulk_memset(&self->private_data.f_mcu_blocks[0], 1u * (size_t)128u, 0u); - if (((uint64_t)(io2_v_r - iop_v_r)) < 264u) { - v_ret = 1u; - goto label__goto_done__break; + 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_decode_dri; + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + + if (self->private_impl.f_payload_length != 2u) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_dri_marker); + goto exit; + } + self->private_impl.f_payload_length = 0u; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + uint16_t t_0; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { + t_0 = wuffs_base__peek_u16be__no_bounds_check(iop_a_src); + iop_a_src += 2; + } else { + self->private_data.s_decode_dri.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; } - v_bits |= (wuffs_base__peek_u64be__no_bounds_check(iop_v_r) >> (v_n_bits & 63u)); - iop_v_r += ((63u - (v_n_bits & 63u)) >> 3u); - v_n_bits |= 56u; - v_dc_h = self->private_impl.f_mcu_blocks_dc_hselector[self->private_impl.f_mcu_current_block]; - v_dc_ht_fast = ((uint32_t)(self->private_impl.f_huff_tables_fast[v_dc_h][(v_bits >> 56u)])); - v_dc_bl = (v_dc_ht_fast >> 8u); - if (v_n_bits >= v_dc_bl) { - v_dc_symbol = (15u & v_dc_ht_fast); - v_dc_extend = WUFFS_JPEG__EXTEND[v_dc_symbol]; - v_bits <<= (v_dc_bl & 63u); - v_n_bits -= v_dc_bl; - } else { - v_dc_code = ((uint32_t)((v_bits >> 55u))); - v_dc_blm1 = 8u; - v_bits <<= 9u; - v_n_bits -= 9u; - while (true) { - v_dc_ht_slow = self->private_impl.f_huff_tables_slow[v_dc_h][v_dc_blm1]; - if (v_dc_code < (v_dc_ht_slow >> 8u)) { - v_dc_symbol = (15u & ((uint32_t)(self->private_impl.f_huff_tables_symbols[v_dc_h][(255u & ((uint32_t)(v_dc_code + v_dc_ht_slow)))]))); - v_dc_extend = WUFFS_JPEG__EXTEND[v_dc_symbol]; - break; - } - v_dc_code = (((uint32_t)(v_dc_code << 1u)) | ((uint32_t)((v_bits >> 63u)))); - v_bits <<= 1u; - v_n_bits -= 1u; - v_dc_blm1 = ((v_dc_blm1 + 1u) & 15u); - if (v_dc_blm1 == 0u) { - v_dc_symbol = 0u; - v_dc_extend = WUFFS_JPEG__EXTEND[v_dc_symbol]; - break; + uint64_t* scratch = &self->private_data.s_decode_dri.scratch; + uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0); + if (num_bits_0 == 8) { + t_0 = ((uint16_t)(*scratch >> 48)); + break; + } + num_bits_0 += 8u; + *scratch |= ((uint64_t)(num_bits_0)); + } + } + self->private_impl.f_restart_interval = t_0; + } + if (self->private_impl.f_sof_marker == 0u) { + self->private_impl.f_saved_restart_interval = self->private_impl.f_restart_interval; + } + + goto ok; + ok: + self->private_impl.p_decode_dri = 0; + goto exit; + } + + goto suspend; + suspend: + self->private_impl.p_decode_dri = 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 jpeg.decoder.decode_appn + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_jpeg__decoder__decode_appn( + wuffs_jpeg__decoder* self, + wuffs_base__io_buffer* a_src, + uint8_t a_marker) { + wuffs_base__status status = wuffs_base__make_status(NULL); + + uint8_t v_c8 = 0; + 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_decode_appn; + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + + do { + if (a_marker == 224u) { + if (self->private_impl.f_payload_length >= 5u) { + self->private_impl.f_payload_length -= 5u; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + uint32_t t_0; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_0 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src); + iop_a_src += 4; + } else { + self->private_data.s_decode_appn.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_decode_appn.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 == 24) { + t_0 = ((uint32_t)(*scratch)); + break; + } + num_bits_0 += 8u; + *scratch |= ((uint64_t)(num_bits_0)) << 56; } } + v_c32 = t_0; } - v_dc_value = ((uint16_t)(((v_bits >> 32u) >> (32u - v_dc_symbol)))); -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - v_dc_value += ((uint16_t)(v_dc_extend & ((uint16_t)(((uint16_t)(wuffs_base__utility__sign_extend_rshift_u64(v_bits, 63u))) ^ 65535u)))); -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - v_bits <<= v_dc_symbol; - v_n_bits -= v_dc_symbol; - v_csel = self->private_impl.f_scan_comps_cselector[self->private_impl.f_mcu_blocks_sselector[self->private_impl.f_mcu_current_block]]; -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - self->private_impl.f_mcu_previous_dc_values[v_csel] += v_dc_value; -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - self->private_data.f_mcu_blocks[0u][0u] = self->private_impl.f_mcu_previous_dc_values[v_csel]; - self->private_impl.f_mcu_zig_index = 1u; - break; - } - if (((uint64_t)(io2_v_r - iop_v_r)) < 264u) { - v_ret = 1u; - goto label__goto_done__break; - } - if (v_n_bits < 16u) { - v_bits |= (wuffs_base__peek_u64be__no_bounds_check(iop_v_r) >> (v_n_bits & 63u)); - } - v_z = 1u; - self->private_impl.f_mcu_zig_index = 0u; - v_ac_h = self->private_impl.f_mcu_blocks_ac_hselector[self->private_impl.f_mcu_current_block]; - v_ac_huff_table_fast = &self->private_impl.f_huff_tables_fast[v_ac_h][0u]; - while (v_z < 64u) { - v_ac_ht_fast = ((uint32_t)(v_ac_huff_table_fast[(v_bits >> 56u)])); - if (((uint64_t)(io2_v_r - iop_v_r)) < 8u) { - v_ret = 2u; - goto label__goto_done__break; + if (v_c32 != 1179207242u) { + self->private_impl.f_payload_length = (65535u & (self->private_impl.f_payload_length + 1u)); + break; } - v_bits |= (wuffs_base__peek_u64be__no_bounds_check(iop_v_r) >> (v_n_bits & 63u)); - iop_v_r += ((63u - (v_n_bits & 63u)) >> 3u); - v_n_bits |= 56u; - v_ac_bl = (v_ac_ht_fast >> 8u); - if (v_n_bits >= v_ac_bl) { - v_ac_symbol = (255u & v_ac_ht_fast); - v_bits <<= (v_ac_bl & 63u); - v_n_bits -= v_ac_bl; - } else { - v_ac_code = ((uint32_t)((v_bits >> 55u))); - v_ac_blm1 = 8u; - v_bits <<= 9u; - v_n_bits -= 9u; - while (true) { - v_ac_ht_slow = self->private_impl.f_huff_tables_slow[v_ac_h][v_ac_blm1]; - if (v_ac_code < (v_ac_ht_slow >> 8u)) { - v_ac_symbol = ((uint32_t)(self->private_impl.f_huff_tables_symbols[v_ac_h][(255u & ((uint32_t)(v_ac_code + v_ac_ht_slow)))])); - break; - } - v_ac_code = (((uint32_t)(v_ac_code << 1u)) | ((uint32_t)((v_bits >> 63u)))); - v_bits <<= 1u; - v_n_bits -= 1u; - v_ac_blm1 = ((v_ac_blm1 + 1u) & 15u); - if (v_ac_blm1 == 0u) { - v_ac_symbol = 0u; - break; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_1 = *iop_a_src++; + v_c8 = t_1; + } + self->private_impl.f_is_jfif = (v_c8 == 0u); + } + } else if (a_marker == 238u) { + if (self->private_impl.f_payload_length >= 12u) { + self->private_impl.f_payload_length -= 12u; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + uint32_t t_2; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_2 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src); + iop_a_src += 4; + } else { + self->private_data.s_decode_appn.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); + 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_decode_appn.scratch; + uint32_t num_bits_2 = ((uint32_t)(*scratch >> 56)); + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_2; + if (num_bits_2 == 24) { + t_2 = ((uint32_t)(*scratch)); + break; + } + num_bits_2 += 8u; + *scratch |= ((uint64_t)(num_bits_2)) << 56; } } + v_c32 = t_2; } - v_ac_rrrr = (v_ac_symbol >> 4u); - v_z += (v_ac_rrrr + 1u); - v_ac_ssss = (v_ac_symbol & 15u); - v_ac_extend = WUFFS_JPEG__EXTEND[v_ac_ssss]; - if (v_ac_ssss > 0u) { - v_ac_value = ((uint16_t)((v_bits >> (64u - v_ac_ssss)))); -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - v_ac_value += ((uint16_t)(v_ac_extend & ((uint16_t)(((uint16_t)(wuffs_base__utility__sign_extend_rshift_u64(v_bits, 63u))) ^ 65535u)))); -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - v_bits <<= v_ac_ssss; - v_n_bits -= v_ac_ssss; - self->private_data.f_mcu_blocks[0u][WUFFS_JPEG__UNZIG[v_z]] = v_ac_value; - } else if (v_ac_rrrr < 15u) { + if (v_c32 != 1651467329u) { + self->private_impl.f_payload_length = (65535u & (self->private_impl.f_payload_length + 8u)); break; } - } - v_mcb = self->private_impl.f_mcu_current_block; - self->private_impl.f_mcu_current_block += 1u; - if (self->private_impl.f_test_only_interrupt_decode_mcu) { - goto label__goto_done__break; - } - if ( ! self->private_impl.f_swizzle_immediately) { - v_csel = self->private_impl.f_scan_comps_cselector[self->private_impl.f_mcu_blocks_sselector[v_mcb]]; - v_stride = ((uint64_t)(self->private_impl.f_components_workbuf_widths[v_csel])); - v_offset = (self->private_impl.f_mcu_blocks_offset[v_mcb] + (((uint64_t)(self->private_impl.f_mcu_blocks_mx_mul[v_mcb])) * ((uint64_t)(a_mx))) + (((uint64_t)(self->private_impl.f_mcu_blocks_my_mul[v_mcb])) * ((uint64_t)(a_my)))); - if (v_offset <= ((uint64_t)(a_workbuf.len))) { - wuffs_jpeg__decoder__decode_idct(self, wuffs_base__slice_u8__subslice_i(a_workbuf, v_offset), v_stride, ((uint32_t)(self->private_impl.f_components_tq[v_csel]))); + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); + uint32_t t_3; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_3 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src); + iop_a_src += 4; + } else { + self->private_data.s_decode_appn.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); + 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_decode_appn.scratch; + uint32_t num_bits_3 = ((uint32_t)(*scratch >> 56)); + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_3; + if (num_bits_3 == 24) { + t_3 = ((uint32_t)(*scratch)); + break; + } + num_bits_3 += 8u; + *scratch |= ((uint64_t)(num_bits_3)) << 56; + } + } + v_c32 = t_3; } - } else if (self->private_impl.f_num_components == 1u) { - wuffs_jpeg__decoder__decode_idct(self, wuffs_base__make_slice_u8(self->private_data.f_swizzle_immediately_buffer, 64), 8u, ((uint32_t)(self->private_impl.f_components_tq[v_csel]))); - self->private_impl.f_swizzle_immediately_status = wuffs_jpeg__decoder__swizzle_gray(self, - a_dst, - wuffs_base__make_slice_u8(self->private_data.f_swizzle_immediately_buffer, 64), - ((a_mx + 0u) * 8u), - ((a_mx + 1u) * 8u), - ((a_my + 0u) * 8u), - ((a_my + 1u) * 8u), - 8u); - if ( ! wuffs_base__status__is_ok(&self->private_impl.f_swizzle_immediately_status)) { - v_ret = 3u; - goto label__goto_done__break; + if ((255u & v_c32) != 101u) { + self->private_impl.f_payload_length = (65535u & (self->private_impl.f_payload_length + 4u)); + break; } - break; - } else { - v_csel = self->private_impl.f_scan_comps_cselector[self->private_impl.f_mcu_blocks_sselector[v_mcb]]; - v_stride = (8u * ((uint64_t)(self->private_impl.f_components_h[v_csel]))); - wuffs_jpeg__decoder__decode_idct(self, wuffs_base__make_slice_u8_ij(self->private_data.f_swizzle_immediately_buffer, self->private_impl.f_swizzle_immediately_b_offsets[v_mcb], 640), v_stride, ((uint32_t)(self->private_impl.f_components_tq[v_csel]))); - if (self->private_impl.f_mcu_current_block < self->private_impl.f_mcu_num_blocks) { - continue; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); + uint32_t t_4; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_4 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src); + iop_a_src += 4; + } else { + self->private_data.s_decode_appn.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); + 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_decode_appn.scratch; + uint32_t num_bits_4 = ((uint32_t)(*scratch >> 56)); + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_4; + if (num_bits_4 == 24) { + t_4 = ((uint32_t)(*scratch)); + break; + } + num_bits_4 += 8u; + *scratch |= ((uint64_t)(num_bits_4)) << 56; + } + } + v_c32 = t_4; } - self->private_impl.f_swizzle_immediately_status = wuffs_jpeg__decoder__swizzle_colorful(self, - a_dst, - wuffs_base__utility__empty_slice_u8(), - ((a_mx + 0u) * 8u * ((uint32_t)(self->private_impl.f_max_incl_components_h))), - ((a_mx + 1u) * 8u * ((uint32_t)(self->private_impl.f_max_incl_components_h))), - ((a_my + 0u) * 8u * ((uint32_t)(self->private_impl.f_max_incl_components_v))), - ((a_my + 1u) * 8u * ((uint32_t)(self->private_impl.f_max_incl_components_v)))); - if ( ! wuffs_base__status__is_ok(&self->private_impl.f_swizzle_immediately_status)) { - v_ret = 3u; - goto label__goto_done__break; + if ((v_c32 >> 24u) == 0u) { + self->private_impl.f_is_adobe = 1u; + } else { + self->private_impl.f_is_adobe = 2u; } - break; } } - self->private_impl.f_mcu_current_block = 0u; } while (0); - label__goto_done__break:; - v_pos = ((uint32_t)(wuffs_base__u64__sat_add((v_r ? v_r->meta.pos : 0), ((uint64_t)(iop_v_r - io0_v_r))))); - if (v_pos > self->private_impl.f_bitstream_wi) { - v_ret = 2u; - } else { - self->private_impl.f_bitstream_ri = v_pos; + self->private_data.s_decode_appn.scratch = self->private_impl.f_payload_length; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10); + if (self->private_data.s_decode_appn.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { + self->private_data.s_decode_appn.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); + iop_a_src = io2_a_src; + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } - v_r = o_0_v_r; - iop_v_r = o_0_iop_v_r; - io0_v_r = o_0_io0_v_r; - io1_v_r = o_0_io1_v_r; - io2_v_r = o_0_io2_v_r; + iop_a_src += self->private_data.s_decode_appn.scratch; + self->private_impl.f_payload_length = 0u; + + goto ok; + ok: + self->private_impl.p_decode_appn = 0; + goto exit; } - self->private_impl.f_bitstream_bits = v_bits; - self->private_impl.f_bitstream_n_bits = v_n_bits; - return v_ret; + + goto suspend; + suspend: + self->private_impl.p_decode_appn = 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 jpeg.decoder.decode_mcu_progressive_ac_high_bits +// -------- func jpeg.decoder.decode_sof WUFFS_BASE__GENERATED_C_CODE -static uint32_t -wuffs_jpeg__decoder__decode_mcu_progressive_ac_high_bits( +static wuffs_base__status +wuffs_jpeg__decoder__decode_sof( wuffs_jpeg__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__slice_u8 a_workbuf, - uint32_t a_mx, - uint32_t a_my) { - uint32_t v_ret = 0; - uint64_t v_bits = 0; - uint32_t v_n_bits = 0; - wuffs_base__io_buffer u_r = wuffs_base__empty_io_buffer(); - wuffs_base__io_buffer* v_r = &u_r; - const uint8_t* iop_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - const uint8_t* io0_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - const uint8_t* io1_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - const uint8_t* io2_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - uint32_t v_pos = 0; - const uint16_t* v_ac_huff_table_fast = NULL; - uint8_t v_ac_h = 0; - uint32_t v_ac_symbol = 0; - uint32_t v_ac_ht_fast = 0; - uint32_t v_ac_bl = 0; - uint32_t v_ac_code = 0; - uint32_t v_ac_blm1 = 0; - uint32_t v_ac_ht_slow = 0; - uint16_t v_ac_value = 0; - uint16_t v_ac_extend = 0; - uint32_t v_ac_rrrr = 0; - uint32_t v_ac_ssss = 0; - uint32_t v_z = 0; + wuffs_base__io_buffer* a_src) { + wuffs_base__status status = wuffs_base__make_status(NULL); - if (self->private_impl.f_eob_run > 0u) { -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - self->private_impl.f_eob_run -= 1u; -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - return 0u; - } - v_bits = self->private_impl.f_bitstream_bits; - v_n_bits = self->private_impl.f_bitstream_n_bits; - if (self->private_impl.f_bitstream_ri > self->private_impl.f_bitstream_wi) { - return 2u; - } - { - wuffs_base__io_buffer* o_0_v_r = v_r; - const uint8_t* o_0_iop_v_r = iop_v_r; - const uint8_t* o_0_io0_v_r = io0_v_r; - const uint8_t* o_0_io1_v_r = io1_v_r; - const uint8_t* o_0_io2_v_r = io2_v_r; - v_r = wuffs_private_impl__io_reader__set( - &u_r, - &iop_v_r, - &io0_v_r, - &io1_v_r, - &io2_v_r, - wuffs_base__make_slice_u8_ij(self->private_data.f_bitstream_buffer, - self->private_impl.f_bitstream_ri, - self->private_impl.f_bitstream_wi), - ((uint64_t)(self->private_impl.f_bitstream_ri))); - do { - do { - if (((uint64_t)(io2_v_r - iop_v_r)) < 264u) { - v_ret = 1u; - goto label__goto_done__break; - } - if (v_n_bits < 16u) { - v_bits |= (wuffs_base__peek_u64be__no_bounds_check(iop_v_r) >> (v_n_bits & 63u)); - } - v_z = self->private_impl.f_mcu_zig_index; - self->private_impl.f_mcu_zig_index = 0u; - v_ac_h = self->private_impl.f_mcu_blocks_ac_hselector[0u]; - v_ac_huff_table_fast = &self->private_impl.f_huff_tables_fast[v_ac_h][0u]; - while (v_z <= ((uint32_t)(self->private_impl.f_scan_se))) { - v_ac_ht_fast = ((uint32_t)(v_ac_huff_table_fast[(v_bits >> 56u)])); - if (((uint64_t)(io2_v_r - iop_v_r)) < 8u) { - v_ret = 2u; - goto label__goto_done__break; + uint8_t v_c8 = 0; + uint8_t v_comp_h = 0; + uint8_t v_comp_v = 0; + uint32_t v_i = 0; + uint32_t v_j = 0; + bool v_has_h24 = false; + bool v_has_h3 = false; + bool v_has_v24 = false; + bool v_has_v3 = false; + uint32_t v_upper_bound = 0; + uint64_t v_wh0 = 0; + uint64_t v_wh1 = 0; + uint64_t v_wh2 = 0; + uint64_t v_wh3 = 0; + uint64_t v_progressive = 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_decode_sof; + if (coro_susp_point) { + v_i = self->private_data.s_decode_sof.v_i; + } + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + + if (self->private_impl.f_payload_length < 6u) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_sof_marker); + goto exit; + } + self->private_impl.f_payload_length -= 6u; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_0 = *iop_a_src++; + v_c8 = t_0; + } + if (v_c8 == 8u) { + } else if (v_c8 == 12u) { + status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_precision_12_bits); + goto exit; + } else if (v_c8 == 16u) { + status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_precision_16_bits); + goto exit; + } else { + status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_precision); + goto exit; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); + uint32_t t_1; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { + t_1 = ((uint32_t)(wuffs_base__peek_u16be__no_bounds_check(iop_a_src))); + iop_a_src += 2; + } else { + self->private_data.s_decode_sof.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + while (true) { + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } - v_bits |= (wuffs_base__peek_u64be__no_bounds_check(iop_v_r) >> (v_n_bits & 63u)); - iop_v_r += ((63u - (v_n_bits & 63u)) >> 3u); - v_n_bits |= 56u; - v_ac_bl = (v_ac_ht_fast >> 8u); - if (v_n_bits >= v_ac_bl) { - v_ac_symbol = (255u & v_ac_ht_fast); - v_bits <<= (v_ac_bl & 63u); - v_n_bits -= v_ac_bl; - } else { - v_ac_code = ((uint32_t)((v_bits >> 55u))); - v_ac_blm1 = 8u; - v_bits <<= 9u; - v_n_bits -= 9u; - while (true) { - v_ac_ht_slow = self->private_impl.f_huff_tables_slow[v_ac_h][v_ac_blm1]; - if (v_ac_code < (v_ac_ht_slow >> 8u)) { - v_ac_symbol = ((uint32_t)(self->private_impl.f_huff_tables_symbols[v_ac_h][(255u & ((uint32_t)(v_ac_code + v_ac_ht_slow)))])); - break; - } - v_ac_code = (((uint32_t)(v_ac_code << 1u)) | ((uint32_t)((v_bits >> 63u)))); - v_bits <<= 1u; - v_n_bits -= 1u; - v_ac_blm1 = ((v_ac_blm1 + 1u) & 15u); - if (v_ac_blm1 == 0u) { - v_ac_symbol = 0u; - break; - } - } + uint64_t* scratch = &self->private_data.s_decode_sof.scratch; + uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1); + if (num_bits_1 == 8) { + t_1 = ((uint32_t)(*scratch >> 48)); + break; } - v_ac_rrrr = (v_ac_symbol >> 4u); - v_z += (v_ac_rrrr + 1u); - v_ac_ssss = (v_ac_symbol & 15u); - v_ac_extend = WUFFS_JPEG__EXTEND[v_ac_ssss]; - if (v_ac_ssss > 0u) { - v_ac_value = ((uint16_t)((v_bits >> (64u - v_ac_ssss)))); -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - v_ac_value += ((uint16_t)(v_ac_extend & ((uint16_t)(((uint16_t)(wuffs_base__utility__sign_extend_rshift_u64(v_bits, 63u))) ^ 65535u)))); -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - v_bits <<= v_ac_ssss; - v_n_bits -= v_ac_ssss; - self->private_data.f_mcu_blocks[0u][WUFFS_JPEG__UNZIG[v_z]] = ((uint16_t)(((uint16_t)(v_ac_value << self->private_impl.f_scan_al)))); - } else if (v_ac_rrrr < 15u) { - self->private_impl.f_eob_run = ((uint16_t)(((uint16_t)(((uint16_t)(((uint16_t)(1u)) << v_ac_rrrr)) - 1u)))); - if (v_ac_rrrr > 0u) { -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - self->private_impl.f_eob_run += ((uint16_t)((v_bits >> (64u - v_ac_rrrr)))); -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - v_bits <<= v_ac_rrrr; - v_n_bits -= v_ac_rrrr; - } + num_bits_1 += 8u; + *scratch |= ((uint64_t)(num_bits_1)); + } + } + self->private_impl.f_height = t_1; + } + if (self->private_impl.f_height == 0u) { + status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_implicit_height); + goto exit; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + uint32_t t_2; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { + t_2 = ((uint32_t)(wuffs_base__peek_u16be__no_bounds_check(iop_a_src))); + iop_a_src += 2; + } else { + self->private_data.s_decode_sof.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); + 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_decode_sof.scratch; + uint32_t num_bits_2 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_2); + if (num_bits_2 == 8) { + t_2 = ((uint32_t)(*scratch >> 48)); break; } + num_bits_2 += 8u; + *scratch |= ((uint64_t)(num_bits_2)); } - } while (0); - } while (0); - label__goto_done__break:; - v_pos = ((uint32_t)(wuffs_base__u64__sat_add((v_r ? v_r->meta.pos : 0), ((uint64_t)(iop_v_r - io0_v_r))))); - if (v_pos > self->private_impl.f_bitstream_wi) { - v_ret = 2u; + } + self->private_impl.f_width = t_2; + } + if (self->private_impl.f_width == 0u) { + status = wuffs_base__make_status(wuffs_base__error__unsupported_image_dimension); + goto exit; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_3 = *iop_a_src++; + v_c8 = t_3; + } + if ((v_c8 == 0u) || (v_c8 > 4u)) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_sof_marker); + goto exit; + } else if (v_c8 == 2u) { + status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_color_model); + goto exit; + } + self->private_impl.f_num_components = ((uint32_t)(v_c8)); + if (self->private_impl.f_payload_length != (3u * self->private_impl.f_num_components)) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_sof_marker); + goto exit; + } + self->private_impl.f_payload_length = 0u; + v_i = 0u; + while (v_i < self->private_impl.f_num_components) { + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_4 = *iop_a_src++; + self->private_impl.f_components_c[v_i] = t_4; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_5 = *iop_a_src++; + v_c8 = t_5; + } + v_comp_h = ((uint8_t)(v_c8 >> 4u)); + v_comp_v = ((uint8_t)(v_c8 & 15u)); + if ((v_comp_h == 0u) || + (v_comp_h > 4u) || + (v_comp_v == 0u) || + (v_comp_v > 4u)) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_sof_marker); + goto exit; + } + self->private_impl.f_components_h[v_i] = v_comp_h; + if (self->private_impl.f_max_incl_components_h < self->private_impl.f_components_h[v_i]) { + self->private_impl.f_max_incl_components_h = self->private_impl.f_components_h[v_i]; + } + self->private_impl.f_components_v[v_i] = v_comp_v; + if (self->private_impl.f_max_incl_components_v < self->private_impl.f_components_v[v_i]) { + self->private_impl.f_max_incl_components_v = self->private_impl.f_components_v[v_i]; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_6 = *iop_a_src++; + v_c8 = t_6; + } + if (v_c8 >= 4u) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_sof_marker); + goto exit; + } + self->private_impl.f_components_tq[v_i] = v_c8; + v_j = 0u; + while (v_j < v_i) { + if (self->private_impl.f_components_c[v_j] == self->private_impl.f_components_c[v_i]) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_sof_marker); + goto exit; + } + v_j += 1u; + } + v_i += 1u; + } + if (self->private_impl.f_num_components == 1u) { + self->private_impl.f_max_incl_components_h = 1u; + self->private_impl.f_max_incl_components_v = 1u; + self->private_impl.f_components_h[0u] = 1u; + self->private_impl.f_components_v[0u] = 1u; } else { - self->private_impl.f_bitstream_ri = v_pos; + v_has_h24 = false; + v_has_h3 = false; + v_has_v24 = false; + v_has_v3 = false; + v_i = 0u; + while (v_i < self->private_impl.f_num_components) { + v_has_h24 = (v_has_h24 || (self->private_impl.f_components_h[v_i] == 2u) || (self->private_impl.f_components_h[v_i] == 4u)); + v_has_h3 = (v_has_h3 || (self->private_impl.f_components_h[v_i] == 3u)); + v_has_v24 = (v_has_v24 || (self->private_impl.f_components_v[v_i] == 2u) || (self->private_impl.f_components_v[v_i] == 4u)); + v_has_v3 = (v_has_v3 || (self->private_impl.f_components_v[v_i] == 3u)); + v_i += 1u; + } + if ((v_has_h24 && v_has_h3) || (v_has_v24 && v_has_v3)) { + status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_fractional_sampling); + goto exit; + } + if (self->private_impl.f_num_components == 4u) { + self->private_impl.f_is_rgb_or_cmyk = (self->private_impl.f_is_adobe < 2u); + } else { + if (self->private_impl.f_is_jfif) { + self->private_impl.f_is_rgb_or_cmyk = false; + } else if (self->private_impl.f_is_adobe > 0u) { + self->private_impl.f_is_rgb_or_cmyk = (self->private_impl.f_is_adobe == 1u); + } else { + self->private_impl.f_is_rgb_or_cmyk = ((self->private_impl.f_components_c[0u] == 82u) && (self->private_impl.f_components_c[1u] == 71u) && (self->private_impl.f_components_c[2u] == 66u)); + } + } } - v_r = o_0_v_r; - iop_v_r = o_0_iop_v_r; - io0_v_r = o_0_io0_v_r; - io1_v_r = o_0_io1_v_r; - io2_v_r = o_0_io2_v_r; + self->private_impl.f_width_in_mcus = wuffs_jpeg__decoder__quantize_dimension(self, self->private_impl.f_width, 1u, self->private_impl.f_max_incl_components_h); + self->private_impl.f_height_in_mcus = wuffs_jpeg__decoder__quantize_dimension(self, self->private_impl.f_height, 1u, self->private_impl.f_max_incl_components_v); + v_upper_bound = 65544u; + self->private_impl.f_components_workbuf_widths[0u] = wuffs_base__u32__min(v_upper_bound, (8u * self->private_impl.f_width_in_mcus * ((uint32_t)(self->private_impl.f_components_h[0u])))); + self->private_impl.f_components_workbuf_widths[1u] = wuffs_base__u32__min(v_upper_bound, (8u * self->private_impl.f_width_in_mcus * ((uint32_t)(self->private_impl.f_components_h[1u])))); + self->private_impl.f_components_workbuf_widths[2u] = wuffs_base__u32__min(v_upper_bound, (8u * self->private_impl.f_width_in_mcus * ((uint32_t)(self->private_impl.f_components_h[2u])))); + self->private_impl.f_components_workbuf_widths[3u] = wuffs_base__u32__min(v_upper_bound, (8u * self->private_impl.f_width_in_mcus * ((uint32_t)(self->private_impl.f_components_h[3u])))); + self->private_impl.f_components_workbuf_heights[0u] = wuffs_base__u32__min(v_upper_bound, (8u * self->private_impl.f_height_in_mcus * ((uint32_t)(self->private_impl.f_components_v[0u])))); + self->private_impl.f_components_workbuf_heights[1u] = wuffs_base__u32__min(v_upper_bound, (8u * self->private_impl.f_height_in_mcus * ((uint32_t)(self->private_impl.f_components_v[1u])))); + self->private_impl.f_components_workbuf_heights[2u] = wuffs_base__u32__min(v_upper_bound, (8u * self->private_impl.f_height_in_mcus * ((uint32_t)(self->private_impl.f_components_v[2u])))); + self->private_impl.f_components_workbuf_heights[3u] = wuffs_base__u32__min(v_upper_bound, (8u * self->private_impl.f_height_in_mcus * ((uint32_t)(self->private_impl.f_components_v[3u])))); + v_wh0 = (((uint64_t)(self->private_impl.f_components_workbuf_widths[0u])) * ((uint64_t)(self->private_impl.f_components_workbuf_heights[0u]))); + v_wh1 = (((uint64_t)(self->private_impl.f_components_workbuf_widths[1u])) * ((uint64_t)(self->private_impl.f_components_workbuf_heights[1u]))); + v_wh2 = (((uint64_t)(self->private_impl.f_components_workbuf_widths[2u])) * ((uint64_t)(self->private_impl.f_components_workbuf_heights[2u]))); + v_wh3 = (((uint64_t)(self->private_impl.f_components_workbuf_widths[3u])) * ((uint64_t)(self->private_impl.f_components_workbuf_heights[3u]))); + v_progressive = 0u; + if (self->private_impl.f_sof_marker >= 194u) { + v_progressive = 2u; + v_i = 0u; + while (v_i < 4u) { + v_j = 0u; + while (v_j < 10u) { + self->private_impl.f_block_smoothing_lowest_scan_al[v_i][v_j] = 16u; + v_j += 1u; + } + v_i += 1u; + } + } + self->private_impl.f_components_workbuf_offsets[0u] = 0u; + self->private_impl.f_components_workbuf_offsets[1u] = (self->private_impl.f_components_workbuf_offsets[0u] + v_wh0); + self->private_impl.f_components_workbuf_offsets[2u] = (self->private_impl.f_components_workbuf_offsets[1u] + v_wh1); + self->private_impl.f_components_workbuf_offsets[3u] = (self->private_impl.f_components_workbuf_offsets[2u] + v_wh2); + self->private_impl.f_components_workbuf_offsets[4u] = (self->private_impl.f_components_workbuf_offsets[3u] + v_wh3); + self->private_impl.f_components_workbuf_offsets[5u] = (self->private_impl.f_components_workbuf_offsets[4u] + (v_wh0 * v_progressive)); + self->private_impl.f_components_workbuf_offsets[6u] = (self->private_impl.f_components_workbuf_offsets[5u] + (v_wh1 * v_progressive)); + self->private_impl.f_components_workbuf_offsets[7u] = (self->private_impl.f_components_workbuf_offsets[6u] + (v_wh2 * v_progressive)); + self->private_impl.f_components_workbuf_offsets[8u] = (self->private_impl.f_components_workbuf_offsets[7u] + (v_wh3 * v_progressive)); + + goto ok; + ok: + self->private_impl.p_decode_sof = 0; + goto exit; } - self->private_impl.f_bitstream_bits = v_bits; - self->private_impl.f_bitstream_n_bits = v_n_bits; - return v_ret; + + goto suspend; + suspend: + self->private_impl.p_decode_sof = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_data.s_decode_sof.v_i = v_i; + + 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 jpeg.decoder.decode_mcu_progressive_ac_low_bit +// -------- func jpeg.decoder.quantize_dimension WUFFS_BASE__GENERATED_C_CODE static uint32_t -wuffs_jpeg__decoder__decode_mcu_progressive_ac_low_bit( +wuffs_jpeg__decoder__quantize_dimension( + const wuffs_jpeg__decoder* self, + uint32_t a_width, + uint8_t a_h, + uint8_t a_max_incl_h) { + uint32_t v_ratio = 0; + + v_ratio = 0u; + if (a_h > 0u) { + v_ratio = ((uint32_t)(((uint8_t)(a_max_incl_h / a_h)))); + } + if (v_ratio == 1u) { + return ((a_width + 7u) / 8u); + } else if (v_ratio == 2u) { + return ((a_width + 15u) / 16u); + } else if (v_ratio == 3u) { + return ((a_width + 23u) / 24u); + } + return ((a_width + 31u) / 32u); +} + +// -------- func jpeg.decoder.decode_frame_config + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_jpeg__decoder__decode_frame_config( wuffs_jpeg__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__slice_u8 a_workbuf, - uint32_t a_mx, - uint32_t a_my) { - uint32_t v_ret = 0; - uint64_t v_bits = 0; - uint32_t v_n_bits = 0; - uint16_t v_one_lshift_scan_al = 0; - wuffs_base__io_buffer u_r = wuffs_base__empty_io_buffer(); - wuffs_base__io_buffer* v_r = &u_r; - const uint8_t* iop_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - const uint8_t* io0_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - const uint8_t* io1_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - const uint8_t* io2_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - uint32_t v_pos = 0; - const uint16_t* v_ac_huff_table_fast = NULL; - uint8_t v_ac_h = 0; - uint32_t v_ac_symbol = 0; - uint32_t v_ac_ht_fast = 0; - uint32_t v_ac_bl = 0; - uint32_t v_ac_code = 0; - uint32_t v_ac_blm1 = 0; - uint32_t v_ac_ht_slow = 0; - uint16_t v_ac_value = 0; - uint32_t v_ac_rrrr = 0; - uint32_t v_ac_ssss = 0; - uint8_t v_unzig = 0; - bool v_bit = false; + 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); - v_bits = self->private_impl.f_bitstream_bits; - v_n_bits = self->private_impl.f_bitstream_n_bits; - v_one_lshift_scan_al = ((uint16_t)(((uint16_t)(1u)) << self->private_impl.f_scan_al)); - if (self->private_impl.f_bitstream_ri > self->private_impl.f_bitstream_wi) { - return 2u; + 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_jpeg__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_jpeg__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; } - { - wuffs_base__io_buffer* o_0_v_r = v_r; - const uint8_t* o_0_iop_v_r = iop_v_r; - const uint8_t* o_0_io0_v_r = io0_v_r; - const uint8_t* o_0_io1_v_r = io1_v_r; - const uint8_t* o_0_io2_v_r = io2_v_r; - v_r = wuffs_private_impl__io_reader__set( - &u_r, - &iop_v_r, - &io0_v_r, - &io1_v_r, - &io2_v_r, - wuffs_base__make_slice_u8_ij(self->private_data.f_bitstream_buffer, - self->private_impl.f_bitstream_ri, - self->private_impl.f_bitstream_wi), - ((uint64_t)(self->private_impl.f_bitstream_ri))); - do { - do { - if (((uint64_t)(io2_v_r - iop_v_r)) < 264u) { - v_ret = 1u; - goto label__goto_done__break; - } - while (true) { - if (self->private_impl.f_eob_run > 0u) { - break; - } - v_ac_h = self->private_impl.f_mcu_blocks_ac_hselector[0u]; - v_ac_huff_table_fast = &self->private_impl.f_huff_tables_fast[v_ac_h][0u]; - while (true) { - if (((uint64_t)(io2_v_r - iop_v_r)) < 8u) { - v_ret = 2u; - goto label__goto_done__break; - } - v_bits |= (wuffs_base__peek_u64be__no_bounds_check(iop_v_r) >> (v_n_bits & 63u)); - iop_v_r += ((63u - (v_n_bits & 63u)) >> 3u); - v_n_bits |= 56u; - v_ac_ht_fast = ((uint32_t)(v_ac_huff_table_fast[(v_bits >> 56u)])); - v_ac_bl = (v_ac_ht_fast >> 8u); - if (v_n_bits >= v_ac_bl) { - v_ac_symbol = (255u & v_ac_ht_fast); - v_bits <<= (v_ac_bl & 63u); - v_n_bits -= v_ac_bl; - } else { - v_ac_code = ((uint32_t)((v_bits >> 55u))); - v_ac_blm1 = 8u; - v_bits <<= 9u; - v_n_bits -= 9u; - while (true) { - v_ac_ht_slow = self->private_impl.f_huff_tables_slow[v_ac_h][v_ac_blm1]; - if (v_ac_code < (v_ac_ht_slow >> 8u)) { - v_ac_symbol = ((uint32_t)(self->private_impl.f_huff_tables_symbols[v_ac_h][(255u & ((uint32_t)(v_ac_code + v_ac_ht_slow)))])); - break; - } - v_ac_code = (((uint32_t)(v_ac_code << 1u)) | ((uint32_t)((v_bits >> 63u)))); - v_bits <<= 1u; - v_n_bits -= 1u; - v_ac_blm1 = ((v_ac_blm1 + 1u) & 15u); - if (v_ac_blm1 == 0u) { - v_ac_symbol = 0u; - break; - } - } - } - v_ac_rrrr = (v_ac_symbol >> 4u); - v_ac_ssss = (v_ac_symbol & 15u); - v_ac_value = 0u; - if (v_ac_ssss > 0u) { - v_ac_value = ((uint16_t)(((uint16_t)(1u)) << self->private_impl.f_scan_al)); - if ((v_bits >> 63u) == 0u) { - v_ac_value = ((uint16_t)(((uint16_t)(65535u)) << self->private_impl.f_scan_al)); - } - v_bits <<= 1u; - v_n_bits -= 1u; - } else if (v_ac_rrrr < 15u) { - self->private_impl.f_eob_run = ((uint16_t)(((uint16_t)(1u)) << v_ac_rrrr)); - if (v_ac_rrrr > 0u) { -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - self->private_impl.f_eob_run += ((uint16_t)((v_bits >> (64u - v_ac_rrrr)))); -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - v_bits <<= v_ac_rrrr; - v_n_bits -= v_ac_rrrr; - } - goto label__goto_do_eob__break; - } - while (true) { - v_unzig = WUFFS_JPEG__UNZIG[(1u + self->private_impl.f_mcu_zig_index)]; - if (self->private_data.f_mcu_blocks[0u][v_unzig] != 0u) { - if (v_n_bits == 0u) { - if (((uint64_t)(io2_v_r - iop_v_r)) < 8u) { - v_ret = 2u; - goto label__goto_done__break; - } - v_bits |= (wuffs_base__peek_u64be__no_bounds_check(iop_v_r) >> (v_n_bits & 63u)); - iop_v_r += ((63u - (v_n_bits & 63u)) >> 3u); - v_n_bits |= 56u; - } - v_bit = ((v_bits >> 63u) > 0u); - v_bits <<= 1u; - v_n_bits -= 1u; - if (v_bit) { - if (self->private_data.f_mcu_blocks[0u][v_unzig] < 32768u) { -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - self->private_data.f_mcu_blocks[0u][v_unzig] += v_one_lshift_scan_al; -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - } else { -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - self->private_data.f_mcu_blocks[0u][v_unzig] -= v_one_lshift_scan_al; -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - } - } - } else if (v_ac_rrrr <= 0u) { - break; - } else { - v_ac_rrrr -= 1u; - } - if (self->private_impl.f_mcu_zig_index >= ((uint32_t)(self->private_impl.f_scan_se))) { - break; - } - self->private_impl.f_mcu_zig_index += 1u; - } - if (v_ac_value != 0u) { - self->private_data.f_mcu_blocks[0u][WUFFS_JPEG__UNZIG[(1u + self->private_impl.f_mcu_zig_index)]] = v_ac_value; - } - if (self->private_impl.f_mcu_zig_index >= ((uint32_t)(self->private_impl.f_scan_se))) { - break; - } - self->private_impl.f_mcu_zig_index += 1u; - } - goto label__block__break; - } - label__goto_do_eob__break:; - if (self->private_impl.f_eob_run <= 0u) { - v_ret = 2u; - goto label__goto_done__break; - } - while (true) { - v_unzig = WUFFS_JPEG__UNZIG[(1u + self->private_impl.f_mcu_zig_index)]; - if (self->private_data.f_mcu_blocks[0u][v_unzig] != 0u) { - if (v_n_bits == 0u) { - if (((uint64_t)(io2_v_r - iop_v_r)) < 8u) { - v_ret = 2u; - goto label__goto_done__break; - } - v_bits |= (wuffs_base__peek_u64be__no_bounds_check(iop_v_r) >> (v_n_bits & 63u)); - iop_v_r += ((63u - (v_n_bits & 63u)) >> 3u); - v_n_bits |= 56u; - } - v_bit = ((v_bits >> 63u) > 0u); - v_bits <<= 1u; - v_n_bits -= 1u; - if (v_bit) { - if (self->private_data.f_mcu_blocks[0u][v_unzig] < 32768u) { -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - self->private_data.f_mcu_blocks[0u][v_unzig] += v_one_lshift_scan_al; -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - } else { -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - self->private_data.f_mcu_blocks[0u][v_unzig] -= v_one_lshift_scan_al; -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - } - } - } - if (self->private_impl.f_mcu_zig_index >= ((uint32_t)(self->private_impl.f_scan_se))) { - break; - } - self->private_impl.f_mcu_zig_index += 1u; - } -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - self->private_impl.f_eob_run -= 1u; -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - } while (0); - label__block__break:; - } while (0); - label__goto_done__break:; - v_pos = ((uint32_t)(wuffs_base__u64__sat_add((v_r ? v_r->meta.pos : 0), ((uint64_t)(iop_v_r - io0_v_r))))); - if (v_pos > self->private_impl.f_bitstream_wi) { - v_ret = 2u; - } else { - self->private_impl.f_bitstream_ri = v_pos; - } - v_r = o_0_v_r; - iop_v_r = o_0_iop_v_r; - io0_v_r = o_0_io0_v_r; - io1_v_r = o_0_io1_v_r; - io2_v_r = o_0_io2_v_r; + + 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; } - self->private_impl.f_bitstream_bits = v_bits; - self->private_impl.f_bitstream_n_bits = v_n_bits; - return v_ret; + return status; } -// -------- func jpeg.decoder.decode_mcu_progressive_dc_high_bits +// -------- func jpeg.decoder.do_decode_frame_config WUFFS_BASE__GENERATED_C_CODE -static uint32_t -wuffs_jpeg__decoder__decode_mcu_progressive_dc_high_bits( +static wuffs_base__status +wuffs_jpeg__decoder__do_decode_frame_config( wuffs_jpeg__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__slice_u8 a_workbuf, - uint32_t a_mx, - uint32_t a_my) { - uint32_t v_ret = 0; - uint64_t v_bits = 0; - uint32_t v_n_bits = 0; - uint8_t v_csel = 0; - wuffs_base__io_buffer u_r = wuffs_base__empty_io_buffer(); - wuffs_base__io_buffer* v_r = &u_r; - const uint8_t* iop_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - const uint8_t* io0_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - const uint8_t* io1_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - const uint8_t* io2_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - uint32_t v_pos = 0; - uint8_t v_dc_h = 0; - uint32_t v_dc_symbol = 0; - uint32_t v_dc_ht_fast = 0; - uint32_t v_dc_bl = 0; - uint32_t v_dc_code = 0; - uint32_t v_dc_blm1 = 0; - uint32_t v_dc_ht_slow = 0; - uint16_t v_dc_value = 0; - uint16_t v_dc_extend = 0; + wuffs_base__frame_config* a_dst, + wuffs_base__io_buffer* a_src) { + wuffs_base__status status = wuffs_base__make_status(NULL); - v_bits = self->private_impl.f_bitstream_bits; - v_n_bits = self->private_impl.f_bitstream_n_bits; - if (self->private_impl.f_bitstream_ri > self->private_impl.f_bitstream_wi) { - return 2u; + 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; } - { - wuffs_base__io_buffer* o_0_v_r = v_r; - const uint8_t* o_0_iop_v_r = iop_v_r; - const uint8_t* o_0_io0_v_r = io0_v_r; - const uint8_t* o_0_io1_v_r = io1_v_r; - const uint8_t* o_0_io2_v_r = io2_v_r; - v_r = wuffs_private_impl__io_reader__set( - &u_r, - &iop_v_r, - &io0_v_r, - &io1_v_r, - &io2_v_r, - wuffs_base__make_slice_u8_ij(self->private_data.f_bitstream_buffer, - self->private_impl.f_bitstream_ri, - self->private_impl.f_bitstream_wi), - ((uint64_t)(self->private_impl.f_bitstream_ri))); - do { - while (self->private_impl.f_mcu_current_block < self->private_impl.f_mcu_num_blocks) { - if (((uint64_t)(io2_v_r - iop_v_r)) < 264u) { - v_ret = 1u; - goto label__goto_done__break; - } - do { - if (((uint64_t)(io2_v_r - iop_v_r)) < 8u) { - v_ret = 2u; - goto label__goto_done__break; - } - v_bits |= (wuffs_base__peek_u64be__no_bounds_check(iop_v_r) >> (v_n_bits & 63u)); - iop_v_r += ((63u - (v_n_bits & 63u)) >> 3u); - v_n_bits |= 56u; - v_dc_h = self->private_impl.f_mcu_blocks_dc_hselector[self->private_impl.f_mcu_current_block]; - v_dc_ht_fast = ((uint32_t)(self->private_impl.f_huff_tables_fast[v_dc_h][(v_bits >> 56u)])); - v_dc_bl = (v_dc_ht_fast >> 8u); - if (v_n_bits >= v_dc_bl) { - v_dc_symbol = (15u & v_dc_ht_fast); - v_dc_extend = WUFFS_JPEG__EXTEND[v_dc_symbol]; - v_bits <<= (v_dc_bl & 63u); - v_n_bits -= v_dc_bl; - } else { - v_dc_code = ((uint32_t)((v_bits >> 55u))); - v_dc_blm1 = 8u; - v_bits <<= 9u; - v_n_bits -= 9u; - while (true) { - v_dc_ht_slow = self->private_impl.f_huff_tables_slow[v_dc_h][v_dc_blm1]; - if (v_dc_code < (v_dc_ht_slow >> 8u)) { - v_dc_symbol = (15u & ((uint32_t)(self->private_impl.f_huff_tables_symbols[v_dc_h][(255u & ((uint32_t)(v_dc_code + v_dc_ht_slow)))]))); - v_dc_extend = WUFFS_JPEG__EXTEND[v_dc_symbol]; - break; - } - v_dc_code = (((uint32_t)(v_dc_code << 1u)) | ((uint32_t)((v_bits >> 63u)))); - v_bits <<= 1u; - v_n_bits -= 1u; - v_dc_blm1 = ((v_dc_blm1 + 1u) & 15u); - if (v_dc_blm1 == 0u) { - v_dc_symbol = 0u; - v_dc_extend = WUFFS_JPEG__EXTEND[v_dc_symbol]; - break; - } - } - } - v_dc_value = ((uint16_t)(((v_bits >> 32u) >> (32u - v_dc_symbol)))); -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - v_dc_value += ((uint16_t)(v_dc_extend & ((uint16_t)(((uint16_t)(wuffs_base__utility__sign_extend_rshift_u64(v_bits, 63u))) ^ 65535u)))); -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - v_bits <<= v_dc_symbol; - v_n_bits -= v_dc_symbol; - v_csel = self->private_impl.f_scan_comps_cselector[self->private_impl.f_mcu_blocks_sselector[self->private_impl.f_mcu_current_block]]; -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - self->private_impl.f_mcu_previous_dc_values[v_csel] += v_dc_value; -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - self->private_data.f_mcu_blocks[self->private_impl.f_mcu_current_block][0u] = ((uint16_t)(self->private_impl.f_mcu_previous_dc_values[v_csel] << self->private_impl.f_scan_al)); - } while (0); - self->private_impl.f_mcu_current_block += 1u; + + 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)); } - self->private_impl.f_mcu_current_block = 0u; - } while (0); - label__goto_done__break:; - v_pos = ((uint32_t)(wuffs_base__u64__sat_add((v_r ? v_r->meta.pos : 0), ((uint64_t)(iop_v_r - io0_v_r))))); - if (v_pos > self->private_impl.f_bitstream_wi) { - v_ret = 2u; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + status = wuffs_jpeg__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 (self->private_impl.f_frame_config_io_position != 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 { - self->private_impl.f_bitstream_ri = v_pos; + status = wuffs_base__make_status(wuffs_base__note__end_of_data); + goto ok; } - v_r = o_0_v_r; - iop_v_r = o_0_iop_v_r; - io0_v_r = o_0_io0_v_r; - io1_v_r = o_0_io1_v_r; - io2_v_r = o_0_io2_v_r; + 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, + self->private_impl.f_frame_config_io_position, + 0u, + true, + false, + 4278190080u); + } + self->private_impl.f_call_sequence = 64u; + + ok: + self->private_impl.p_do_decode_frame_config = 0; + goto exit; } - self->private_impl.f_bitstream_bits = v_bits; - self->private_impl.f_bitstream_n_bits = v_n_bits; - return v_ret; + + 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 jpeg.decoder.decode_mcu_progressive_dc_low_bit +// -------- func jpeg.decoder.decode_frame WUFFS_BASE__GENERATED_C_CODE -static uint32_t -wuffs_jpeg__decoder__decode_mcu_progressive_dc_low_bit( +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_jpeg__decoder__decode_frame( wuffs_jpeg__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, - uint32_t a_mx, - uint32_t a_my) { - uint32_t v_ret = 0; - uint64_t v_bits = 0; - uint32_t v_n_bits = 0; - uint16_t v_one_lshift_scan_al = 0; - wuffs_base__io_buffer u_r = wuffs_base__empty_io_buffer(); - wuffs_base__io_buffer* v_r = &u_r; - const uint8_t* iop_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - const uint8_t* io0_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - const uint8_t* io1_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - const uint8_t* io2_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - uint32_t v_pos = 0; - - v_bits = self->private_impl.f_bitstream_bits; - v_n_bits = self->private_impl.f_bitstream_n_bits; - v_one_lshift_scan_al = ((uint16_t)(((uint16_t)(1u)) << self->private_impl.f_scan_al)); - if (self->private_impl.f_bitstream_ri > self->private_impl.f_bitstream_wi) { - return 2u; + wuffs_base__decode_frame_options* a_opts) { + if (!self) { + return wuffs_base__make_status(wuffs_base__error__bad_receiver); } - { - wuffs_base__io_buffer* o_0_v_r = v_r; - const uint8_t* o_0_iop_v_r = iop_v_r; - const uint8_t* o_0_io0_v_r = io0_v_r; - const uint8_t* o_0_io1_v_r = io1_v_r; - const uint8_t* o_0_io2_v_r = io2_v_r; - v_r = wuffs_private_impl__io_reader__set( - &u_r, - &iop_v_r, - &io0_v_r, - &io1_v_r, - &io2_v_r, - wuffs_base__make_slice_u8_ij(self->private_data.f_bitstream_buffer, - self->private_impl.f_bitstream_ri, - self->private_impl.f_bitstream_wi), - ((uint64_t)(self->private_impl.f_bitstream_ri))); - do { - while (self->private_impl.f_mcu_current_block < self->private_impl.f_mcu_num_blocks) { - if (((uint64_t)(io2_v_r - iop_v_r)) < 264u) { - v_ret = 1u; - goto label__goto_done__break; - } - do { - if (((uint64_t)(io2_v_r - iop_v_r)) < 8u) { - v_ret = 2u; - goto label__goto_done__break; - } - v_bits |= (wuffs_base__peek_u64be__no_bounds_check(iop_v_r) >> (v_n_bits & 63u)); - iop_v_r += ((63u - (v_n_bits & 63u)) >> 3u); - v_n_bits |= 56u; - if ((v_bits >> 63u) != 0u) { - self->private_data.f_mcu_blocks[self->private_impl.f_mcu_current_block][0u] |= v_one_lshift_scan_al; - } - v_bits <<= 1u; - v_n_bits -= 1u; - } while (0); - self->private_impl.f_mcu_current_block += 1u; - } - self->private_impl.f_mcu_current_block = 0u; - } while (0); - label__goto_done__break:; - v_pos = ((uint32_t)(wuffs_base__u64__sat_add((v_r ? v_r->meta.pos : 0), ((uint64_t)(iop_v_r - io0_v_r))))); - if (v_pos > self->private_impl.f_bitstream_wi) { - v_ret = 2u; - } else { - self->private_impl.f_bitstream_ri = v_pos; - } - v_r = o_0_v_r; - iop_v_r = o_0_iop_v_r; - io0_v_r = o_0_io0_v_r; - io1_v_r = o_0_io1_v_r; - io2_v_r = o_0_io2_v_r; + 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); } - self->private_impl.f_bitstream_bits = v_bits; - self->private_impl.f_bitstream_n_bits = v_n_bits; - return v_ret; -} - -#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__JPEG) - -#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__JSON) - -// ---------------- Status Codes Implementations - -const char wuffs_json__error__bad_c0_control_code[] = "#json: bad C0 control code"; -const char wuffs_json__error__bad_utf_8[] = "#json: bad UTF-8"; -const char wuffs_json__error__bad_backslash_escape[] = "#json: bad backslash-escape"; -const char wuffs_json__error__bad_input[] = "#json: bad input"; -const char wuffs_json__error__bad_new_line_in_a_string[] = "#json: bad new-line in a string"; -const char wuffs_json__error__bad_quirk_combination[] = "#json: bad quirk combination"; -const char wuffs_json__error__unsupported_number_length[] = "#json: unsupported number length"; -const char wuffs_json__error__unsupported_recursion_depth[] = "#json: unsupported recursion depth"; -const char wuffs_json__error__internal_error_inconsistent_i_o[] = "#json: internal error: inconsistent I/O"; - -// ---------------- Private Consts - -#define WUFFS_JSON__DECODER_NUMBER_LENGTH_MAX_INCL 99u - -static const uint8_t -WUFFS_JSON__LUT_BACKSLASHES[256] WUFFS_BASE__POTENTIALLY_UNUSED = { - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 3u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 162u, 0u, 0u, 0u, 0u, 5u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 175u, - 7u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 4u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 220u, 0u, 0u, 0u, - 0u, 1u, 136u, 0u, 0u, 2u, 140u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 138u, 0u, - 0u, 0u, 141u, 0u, 137u, 0u, 6u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, -}; - -static const uint8_t -WUFFS_JSON__LUT_QUIRKY_BACKSLASHES_QUIRKS[8] WUFFS_BASE__POTENTIALLY_UNUSED = { - 0u, 1u, 3u, 4u, 5u, 6u, 7u, 10u, -}; - -static const uint8_t -WUFFS_JSON__LUT_QUIRKY_BACKSLASHES_CHARS[8] WUFFS_BASE__POTENTIALLY_UNUSED = { - 0u, 7u, 27u, 10u, 63u, 39u, 11u, 0u, -}; - -static const uint8_t -WUFFS_JSON__LUT_CHARS[256] WUFFS_BASE__POTENTIALLY_UNUSED = { - 128u, 129u, 130u, 131u, 132u, 133u, 134u, 135u, - 136u, 137u, 138u, 139u, 140u, 141u, 142u, 143u, - 144u, 145u, 146u, 147u, 148u, 149u, 150u, 151u, - 152u, 153u, 154u, 155u, 156u, 157u, 158u, 159u, - 0u, 0u, 1u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 2u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, - 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, - 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, - 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, - 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, - 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, - 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, - 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, - 32u, 32u, 3u, 3u, 3u, 3u, 3u, 3u, - 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, - 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, - 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, - 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, - 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, - 5u, 5u, 5u, 5u, 5u, 32u, 32u, 32u, - 32u, 32u, 32u, 32u, 32u, 32u, 32u, 32u, -}; + 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); -#define WUFFS_JSON__CLASS_WHITESPACE 0u + wuffs_base__status v_ddf_status = wuffs_base__make_status(NULL); + wuffs_base__status v_swizzle_status = wuffs_base__make_status(NULL); + uint32_t v_scan_count = 0; -#define WUFFS_JSON__CLASS_STRING 1u + uint32_t coro_susp_point = self->private_impl.p_decode_frame; + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; -#define WUFFS_JSON__CLASS_COMMA 2u + while (true) { + v_scan_count = self->private_impl.f_scan_count; + { + wuffs_base__status t_0 = wuffs_jpeg__decoder__do_decode_frame(self, + a_dst, + a_src, + a_blend, + a_workbuf, + a_opts); + v_ddf_status = t_0; + } + if ((v_ddf_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) { + v_ddf_status = wuffs_base__make_status(wuffs_jpeg__error__truncated_input); + } + if ( ! self->private_impl.f_swizzle_immediately && (wuffs_base__status__is_error(&v_ddf_status) || (v_scan_count < self->private_impl.f_scan_count))) { + if (self->private_impl.f_sof_marker >= 194u) { + wuffs_jpeg__decoder__apply_progressive_idct(self, a_workbuf); + } + if (self->private_impl.f_num_components == 1u) { + v_swizzle_status = wuffs_jpeg__decoder__swizzle_gray(self, + a_dst, + a_workbuf, + 0u, + 4294967295u, + 0u, + 4294967295u, + ((uint64_t)(self->private_impl.f_components_workbuf_widths[0u]))); + } else { + v_swizzle_status = wuffs_jpeg__decoder__swizzle_colorful(self, + a_dst, + a_workbuf, + 0u, + 4294967295u, + 0u, + 4294967295u); + } + if (wuffs_base__status__is_error(&v_ddf_status)) { + status = v_ddf_status; + goto exit; + } else if (wuffs_base__status__is_error(&v_swizzle_status)) { + status = v_swizzle_status; + goto exit; + } + } + status = v_ddf_status; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1); + } -#define WUFFS_JSON__CLASS_COLON 3u + ok: + self->private_impl.p_decode_frame = 0; + goto exit; + } -#define WUFFS_JSON__CLASS_NUMBER 4u + 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; -#define WUFFS_JSON__CLASS_OPEN_CURLY_BRACE 5u + goto exit; + exit: + if (wuffs_base__status__is_error(&status)) { + self->private_impl.magic = WUFFS_BASE__DISABLED; + } + return status; +} -#define WUFFS_JSON__CLASS_CLOSE_CURLY_BRACE 6u +// -------- func jpeg.decoder.do_decode_frame -#define WUFFS_JSON__CLASS_OPEN_SQUARE_BRACKET 7u +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_jpeg__decoder__do_decode_frame( + wuffs_jpeg__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); -#define WUFFS_JSON__CLASS_CLOSE_SQUARE_BRACKET 8u + uint32_t v_pixfmt = 0; + wuffs_base__status v_status = wuffs_base__make_status(NULL); + uint8_t v_c8 = 0; + uint8_t v_marker = 0; -#define WUFFS_JSON__CLASS_FALSE 9u + 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; + } -#define WUFFS_JSON__CLASS_TRUE 10u + uint32_t coro_susp_point = self->private_impl.p_do_decode_frame; + if (coro_susp_point) { + v_marker = self->private_data.s_do_decode_frame.v_marker; + } + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; -#define WUFFS_JSON__CLASS_NULL_NAN_INF 11u + if (self->private_impl.f_call_sequence == 64u) { + } else if (self->private_impl.f_call_sequence < 64u) { + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + status = wuffs_jpeg__decoder__do_decode_frame_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 { + status = wuffs_base__make_status(wuffs_base__note__end_of_data); + goto ok; + } + v_pixfmt = 536870920u; + if (self->private_impl.f_num_components > 1u) { + v_pixfmt = 2415954056u; + } + 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_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024)), + wuffs_base__utility__make_pixel_format(v_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; + } + self->private_impl.f_swizzle_immediately = false; + if (self->private_impl.f_components_workbuf_offsets[8u] > ((uint64_t)(a_workbuf.len))) { + if ((self->private_impl.f_sof_marker >= 194u) || ! self->private_impl.f_use_lower_quality) { + status = wuffs_base__make_status(wuffs_base__error__bad_workbuf_length); + goto exit; + } + self->private_impl.f_swizzle_immediately = true; + self->private_impl.f_swizzle_immediately_status = wuffs_base__make_status(NULL); + } else if (self->private_impl.f_components_workbuf_offsets[4u] < self->private_impl.f_components_workbuf_offsets[8u]) { + wuffs_private_impl__bulk_memset(a_workbuf.ptr + self->private_impl.f_components_workbuf_offsets[4u], (self->private_impl.f_components_workbuf_offsets[8u] - self->private_impl.f_components_workbuf_offsets[4u]), 0u); + } + if (self->private_impl.f_components_workbuf_offsets[4u] <= ((uint64_t)(a_workbuf.len))) { + wuffs_private_impl__bulk_memset(a_workbuf.ptr, self->private_impl.f_components_workbuf_offsets[4u], 128u); + } + while (true) { + while (true) { + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_0 = *iop_a_src++; + v_c8 = t_0; + } + if (v_c8 == 255u) { + break; + } + } + while (true) { + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_1 = *iop_a_src++; + v_c8 = t_1; + } + if (v_c8 != 255u) { + v_marker = v_c8; + break; + } + } + if (v_marker == 0u) { + continue; + } else if ((208u <= v_marker) && (v_marker <= 217u)) { + if (v_marker <= 215u) { + continue; + } + } else { + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + uint32_t t_2; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { + t_2 = ((uint32_t)(wuffs_base__peek_u16be__no_bounds_check(iop_a_src))); + iop_a_src += 2; + } else { + self->private_data.s_do_decode_frame.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); + 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_frame.scratch; + uint32_t num_bits_2 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_2); + if (num_bits_2 == 8) { + t_2 = ((uint32_t)(*scratch >> 48)); + break; + } + num_bits_2 += 8u; + *scratch |= ((uint64_t)(num_bits_2)); + } + } + self->private_impl.f_payload_length = t_2; + } + if (self->private_impl.f_payload_length < 2u) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_marker); + goto exit; + } + self->private_impl.f_payload_length -= 2u; + } + if (v_marker < 192u) { + status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_marker); + goto exit; + } else if (v_marker < 208u) { + if (v_marker == 196u) { + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); + status = wuffs_jpeg__decoder__decode_dht(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } + continue; + } else if (v_marker == 200u) { + status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_marker); + goto exit; + } + status = wuffs_base__make_status(wuffs_jpeg__error__bad_sof_marker); + goto exit; + } else if (v_marker < 224u) { + if (v_marker < 217u) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_marker); + goto exit; + } else if (v_marker == 217u) { + break; + } else if (v_marker == 218u) { + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); + status = wuffs_jpeg__decoder__decode_sos(self, a_dst, a_src, a_workbuf); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } + continue; + } else if (v_marker == 219u) { + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); + status = wuffs_jpeg__decoder__decode_dqt(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } + continue; + } else if (v_marker == 221u) { + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); + status = wuffs_jpeg__decoder__decode_dri(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } + continue; + } else { + status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_marker); + goto exit; + } + } else if (v_marker < 240u) { + } else { + if (v_marker == 254u) { + } else { + status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_marker); + goto exit; + } + } + self->private_data.s_do_decode_frame.scratch = self->private_impl.f_payload_length; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10); + if (self->private_data.s_do_decode_frame.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { + self->private_data.s_do_decode_frame.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); + iop_a_src = io2_a_src; + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + iop_a_src += self->private_data.s_do_decode_frame.scratch; + self->private_impl.f_payload_length = 0u; + } + self->private_impl.f_call_sequence = 96u; -#define WUFFS_JSON__CLASS_COMMENT 12u + ok: + self->private_impl.p_do_decode_frame = 0; + goto exit; + } -#define WUFFS_JSON__EXPECT_VALUE 7858u + goto suspend; + suspend: + self->private_impl.p_do_decode_frame = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_data.s_do_decode_frame.v_marker = v_marker; -#define WUFFS_JSON__EXPECT_NON_STRING_VALUE 7856u + goto exit; + exit: + if (a_src && a_src->data.ptr) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } -#define WUFFS_JSON__EXPECT_STRING 4098u + return status; +} -#define WUFFS_JSON__EXPECT_COMMA 4100u +// -------- func jpeg.decoder.decode_dht -#define WUFFS_JSON__EXPECT_COLON 4104u +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_jpeg__decoder__decode_dht( + wuffs_jpeg__decoder* self, + wuffs_base__io_buffer* a_src) { + wuffs_base__status status = wuffs_base__make_status(NULL); -#define WUFFS_JSON__EXPECT_NUMBER 4112u + uint8_t v_c8 = 0; + uint8_t v_tc = 0; + uint8_t v_th = 0; + uint8_t v_tc4_th = 0; + uint32_t v_working_total_count = 0; + uint32_t v_total_count = 0; + uint32_t v_i = 0; + bool v_failed = false; -#define WUFFS_JSON__EXPECT_CLOSE_CURLY_BRACE 4160u + 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; + } -#define WUFFS_JSON__EXPECT_CLOSE_SQUARE_BRACKET 4352u + uint32_t coro_susp_point = self->private_impl.p_decode_dht; + if (coro_susp_point) { + v_tc4_th = self->private_data.s_decode_dht.v_tc4_th; + v_total_count = self->private_data.s_decode_dht.v_total_count; + v_i = self->private_data.s_decode_dht.v_i; + } + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; -static const uint8_t -WUFFS_JSON__LUT_CLASSES[256] WUFFS_BASE__POTENTIALLY_UNUSED = { - 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, - 15u, 0u, 0u, 15u, 15u, 0u, 15u, 15u, - 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, - 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, - 0u, 15u, 1u, 15u, 15u, 15u, 15u, 15u, - 15u, 15u, 15u, 11u, 2u, 4u, 15u, 12u, - 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, - 4u, 4u, 3u, 15u, 15u, 15u, 15u, 15u, - 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, - 15u, 11u, 15u, 15u, 15u, 15u, 11u, 15u, - 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, - 15u, 15u, 15u, 7u, 15u, 8u, 15u, 15u, - 15u, 15u, 15u, 15u, 15u, 15u, 9u, 15u, - 15u, 11u, 15u, 15u, 15u, 15u, 11u, 15u, - 15u, 15u, 15u, 15u, 10u, 15u, 15u, 15u, - 15u, 15u, 15u, 5u, 15u, 6u, 15u, 15u, - 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, - 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, - 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, - 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, - 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, - 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, - 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, - 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, - 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, - 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, - 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, - 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, - 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, - 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, - 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, - 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, -}; - -static const uint8_t -WUFFS_JSON__LUT_DECIMAL_DIGITS[256] WUFFS_BASE__POTENTIALLY_UNUSED = { - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 128u, 129u, 130u, 131u, 132u, 133u, 134u, 135u, - 136u, 137u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, -}; - -static const uint8_t -WUFFS_JSON__LUT_HEXADECIMAL_DIGITS[256] WUFFS_BASE__POTENTIALLY_UNUSED = { - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 128u, 129u, 130u, 131u, 132u, 133u, 134u, 135u, - 136u, 137u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 138u, 139u, 140u, 141u, 142u, 143u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 138u, 139u, 140u, 141u, 142u, 143u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, -}; - -#define WUFFS_JSON__QUIRKS_BASE 1225364480u - -#define WUFFS_JSON__QUIRKS_COUNT 21u - -// ---------------- Private Initializer Prototypes - -// ---------------- Private Function Prototypes + while (self->private_impl.f_payload_length > 0u) { + if (self->private_impl.f_payload_length < 17u) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_dht_marker); + goto exit; + } + self->private_impl.f_payload_length -= 17u; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_0 = *iop_a_src++; + v_c8 = t_0; + } + if ((((uint8_t)(v_c8 >> 4u)) > 1u) || (((uint8_t)(v_c8 & 15u)) > 3u)) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_dht_marker); + goto exit; + } + v_tc = ((uint8_t)(v_c8 >> 4u)); + v_th = ((uint8_t)(v_c8 & 15u)); + v_tc4_th = ((uint8_t)(((uint8_t)(((uint8_t)(v_tc * 4u)) | v_th)))); + if ((self->private_impl.f_sof_marker == 192u) && (((uint8_t)(v_tc4_th & 3u)) > 1u)) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_dht_marker); + goto exit; + } + v_i = 0u; + while (v_i < 16u) { + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_1 = *iop_a_src++; + self->private_data.f_dht_temp_counts[v_i] = t_1; + } + v_i += 1u; + } + v_working_total_count = 0u; + v_i = 0u; + while (v_i < 16u) { + v_working_total_count = ((v_working_total_count + ((uint32_t)(self->private_data.f_dht_temp_counts[v_i]))) & 65535u); + v_i += 1u; + } + if ((v_working_total_count <= 0u) || (256u < v_working_total_count)) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_dht_marker); + goto exit; + } + v_total_count = v_working_total_count; + if (self->private_impl.f_payload_length < v_total_count) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_dht_marker); + goto exit; + } + self->private_impl.f_payload_length -= v_total_count; + v_i = 0u; + while (v_i < v_total_count) { + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_2 = *iop_a_src++; + self->private_impl.f_huff_tables_symbols[v_tc4_th][v_i] = t_2; + } + v_i += 1u; + } + while (v_i < 256u) { + self->private_impl.f_huff_tables_symbols[v_tc4_th][v_i] = 0u; + v_i += 1u; + } + if (((uint8_t)(v_tc4_th & 4u)) == 0u) { + v_i = 0u; + while (v_i < v_total_count) { + if (self->private_impl.f_huff_tables_symbols[v_tc4_th][v_i] > 15u) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_dht_marker); + goto exit; + } + v_i += 1u; + } + } + v_failed = wuffs_jpeg__decoder__calculate_huff_tables(self, v_tc4_th, v_total_count); + if (v_failed) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_dht_marker); + goto exit; + } + self->private_impl.f_seen_dht[v_tc4_th] = true; + } -WUFFS_BASE__GENERATED_C_CODE -static uint32_t -wuffs_json__decoder__decode_number( - wuffs_json__decoder* self, - wuffs_base__io_buffer* a_src); + goto ok; + ok: + self->private_impl.p_decode_dht = 0; + goto exit; + } -WUFFS_BASE__GENERATED_C_CODE -static uint32_t -wuffs_json__decoder__decode_digits( - wuffs_json__decoder* self, - wuffs_base__io_buffer* a_src, - uint32_t a_n); + goto suspend; + suspend: + self->private_impl.p_decode_dht = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_data.s_decode_dht.v_tc4_th = v_tc4_th; + self->private_data.s_decode_dht.v_total_count = v_total_count; + self->private_data.s_decode_dht.v_i = v_i; -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_json__decoder__decode_leading( - wuffs_json__decoder* self, - wuffs_base__token_buffer* a_dst, - wuffs_base__io_buffer* a_src); + goto exit; + exit: + if (a_src && a_src->data.ptr) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_json__decoder__decode_comment( - wuffs_json__decoder* self, - wuffs_base__token_buffer* a_dst, - wuffs_base__io_buffer* a_src); + return status; +} -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_json__decoder__decode_inf_nan( - wuffs_json__decoder* self, - wuffs_base__token_buffer* a_dst, - wuffs_base__io_buffer* a_src); +// -------- func jpeg.decoder.calculate_huff_tables WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_json__decoder__decode_trailer( - wuffs_json__decoder* self, - wuffs_base__token_buffer* a_dst, - wuffs_base__io_buffer* a_src); - -// ---------------- VTables - -const wuffs_base__token_decoder__func_ptrs -wuffs_json__decoder__func_ptrs_for__wuffs_base__token_decoder = { - (wuffs_base__status(*)(void*, - wuffs_base__token_buffer*, - wuffs_base__io_buffer*, - wuffs_base__slice_u8))(&wuffs_json__decoder__decode_tokens), - (uint64_t(*)(const void*, - uint32_t))(&wuffs_json__decoder__get_quirk), - (wuffs_base__status(*)(void*, - uint32_t, - uint64_t))(&wuffs_json__decoder__set_quirk), - (wuffs_base__range_ii_u64(*)(const void*))(&wuffs_json__decoder__workbuf_len), -}; - -// ---------------- Initializer Implementations +static bool +wuffs_jpeg__decoder__calculate_huff_tables( + wuffs_jpeg__decoder* self, + uint8_t a_tc4_th, + uint32_t a_total_count) { + uint32_t v_i = 0; + uint8_t v_j = 0; + uint8_t v_k = 0; + uint32_t v_bit_length_minus_one = 0; + uint8_t v_bit_length = 0; + uint32_t v_bit_string = 0; + uint32_t v_slow = 0; + uint8_t v_prefix = 0; + uint16_t v_fast = 0; + uint32_t v_reps = 0; -wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT -wuffs_json__decoder__initialize( - wuffs_json__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); + v_i = 0u; + v_k = 0u; + v_bit_length_minus_one = 0u; + while (v_i < a_total_count) { + while (v_k >= self->private_data.f_dht_temp_counts[v_bit_length_minus_one]) { + v_k = 0u; + v_bit_length_minus_one = ((v_bit_length_minus_one + 1u) & 15u); + } +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + v_k += 1u; +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + self->private_data.f_dht_temp_bit_lengths[v_i] = ((uint8_t)((v_bit_length_minus_one + 1u))); + v_i += 1u; } - - 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__) + v_bit_length = 0u; + v_bit_string = 0u; + v_i = 0u; + while (v_i < a_total_count) { + while (v_bit_length < self->private_data.f_dht_temp_bit_lengths[v_i]) { + if (v_bit_length >= 16u) { + return true; + } +#if defined(__GNUC__) #pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#pragma GCC diagnostic ignored "-Wconversion" #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__) + v_bit_length += 1u; +#if 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)); + v_bit_string <<= 1u; } + self->private_data.f_dht_temp_bit_strings[v_i] = ((uint16_t)(v_bit_string)); + v_bit_string += 1u; + if ((v_bit_string >> v_bit_length) > 0u) { + return true; + } + v_i += 1u; } - - self->private_impl.magic = WUFFS_BASE__MAGIC; - self->private_impl.vtable_for__wuffs_base__token_decoder.vtable_name = - wuffs_base__token_decoder__vtable_name; - self->private_impl.vtable_for__wuffs_base__token_decoder.function_pointers = - (const void*)(&wuffs_json__decoder__func_ptrs_for__wuffs_base__token_decoder); - return wuffs_base__make_status(NULL); -} - -wuffs_json__decoder* -wuffs_json__decoder__alloc(void) { - wuffs_json__decoder* x = - (wuffs_json__decoder*)(calloc(1, sizeof(wuffs_json__decoder))); - if (!x) { - return NULL; - } - if (wuffs_json__decoder__initialize( - x, sizeof(wuffs_json__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) { - free(x); - return NULL; - } - return x; -} - -size_t -sizeof__wuffs_json__decoder(void) { - return sizeof(wuffs_json__decoder); -} - -// ---------------- Function Implementations - -// -------- func json.decoder.get_quirk - -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC uint64_t -wuffs_json__decoder__get_quirk( - const wuffs_json__decoder* self, - uint32_t a_key) { - if (!self) { - return 0; + v_k = 0u; + v_bit_length_minus_one = 0u; + while (true) { + if (self->private_data.f_dht_temp_counts[v_bit_length_minus_one] == 0u) { + self->private_impl.f_huff_tables_slow[a_tc4_th][v_bit_length_minus_one] = 0u; + } else { + v_slow = (255u & ((uint32_t)(((uint32_t)(v_k)) - ((uint32_t)(self->private_data.f_dht_temp_bit_strings[v_k]))))); +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + v_k += self->private_data.f_dht_temp_counts[v_bit_length_minus_one]; +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + self->private_impl.f_huff_tables_slow[a_tc4_th][v_bit_length_minus_one] = (v_slow | ((((uint32_t)(self->private_data.f_dht_temp_bit_strings[((uint8_t)(v_k - 1u))])) + 1u) << 8u)); + } + v_bit_length_minus_one = ((v_bit_length_minus_one + 1u) & 15u); + if (v_bit_length_minus_one == 0u) { + break; + } } - if ((self->private_impl.magic != WUFFS_BASE__MAGIC) && - (self->private_impl.magic != WUFFS_BASE__DISABLED)) { - return 0; + v_i = 0u; + while (v_i < 256u) { + self->private_impl.f_huff_tables_fast[a_tc4_th][v_i] = 65535u; + v_i += 1u; } - - uint32_t v_key = 0; - - if (a_key >= 1225364480u) { - v_key = (a_key - 1225364480u); - if (v_key < 21u) { - if (self->private_impl.f_quirks[v_key]) { - return 1u; + v_j = 0u; + v_bit_length_minus_one = 0u; + while (v_bit_length_minus_one < 8u) { + v_k = 0u; + while (v_k < self->private_data.f_dht_temp_counts[v_bit_length_minus_one]) { + v_prefix = ((uint8_t)((((uint32_t)(self->private_data.f_dht_temp_bit_strings[v_j])) << (7u - v_bit_length_minus_one)))); + v_fast = ((uint16_t)(((((uint32_t)((v_bit_length_minus_one + 1u))) << 8u) | ((uint32_t)(self->private_impl.f_huff_tables_symbols[a_tc4_th][v_j]))))); + v_reps = (((uint32_t)(1u)) << (7u - v_bit_length_minus_one)); + while (v_reps > 0u) { + self->private_impl.f_huff_tables_fast[a_tc4_th][v_prefix] = v_fast; +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + v_prefix += 1u; +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + v_reps -= 1u; } +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + v_k += 1u; + v_j += 1u; +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif } + v_bit_length_minus_one += 1u; } - return 0u; + return false; } -// -------- func json.decoder.set_quirk +// -------- func jpeg.decoder.decode_sos WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_json__decoder__set_quirk( - wuffs_json__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); - } - - if (a_key >= 1225364480u) { - a_key -= 1225364480u; - if (a_key < 21u) { - self->private_impl.f_quirks[a_key] = (a_value > 0u); - return wuffs_base__make_status(NULL); - } - } - return wuffs_base__make_status(wuffs_base__error__unsupported_option); -} +static wuffs_base__status +wuffs_jpeg__decoder__decode_sos( + wuffs_jpeg__decoder* self, + wuffs_base__pixel_buffer* a_dst, + wuffs_base__io_buffer* a_src, + wuffs_base__slice_u8 a_workbuf) { + wuffs_base__status status = wuffs_base__make_status(NULL); -// -------- func json.decoder.workbuf_len + uint32_t v_my = 0; + uint32_t v_mx = 0; + uint32_t v_decode_mcu_result = 0; + uint32_t v_bitstream_length = 0; -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 -wuffs_json__decoder__workbuf_len( - const wuffs_json__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(); + uint32_t coro_susp_point = self->private_impl.p_decode_sos; + if (coro_susp_point) { + v_my = self->private_data.s_decode_sos.v_my; + v_mx = self->private_data.s_decode_sos.v_mx; } + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - return wuffs_base__utility__empty_range_ii_u64(); -} - -// -------- func json.decoder.decode_tokens - -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_json__decoder__decode_tokens( - wuffs_json__decoder* self, - wuffs_base__token_buffer* a_dst, - wuffs_base__io_buffer* a_src, - wuffs_base__slice_u8 a_workbuf) { - 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 != 1)) { - self->private_impl.magic = WUFFS_BASE__DISABLED; - return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls); + if (self->private_impl.f_scan_count >= 32u) { + status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_scan_count); + goto exit; + } else if ((self->private_impl.f_scan_count > 0u) && ! self->private_impl.f_expect_multiple_scans) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_scan_count); + goto exit; + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + status = wuffs_jpeg__decoder__prepare_scan(self, a_src); + if (status.repr) { + goto suspend; + } + self->private_impl.f_next_restart_marker = 0u; + self->private_impl.f_mcu_previous_dc_values[0u] = 0u; + self->private_impl.f_mcu_previous_dc_values[1u] = 0u; + self->private_impl.f_mcu_previous_dc_values[2u] = 0u; + self->private_impl.f_mcu_previous_dc_values[3u] = 0u; + self->private_impl.f_restarts_remaining = self->private_impl.f_restart_interval; + self->private_impl.f_eob_run = 0u; + self->private_impl.f_bitstream_bits = 0u; + self->private_impl.f_bitstream_n_bits = 0u; + self->private_impl.f_bitstream_ri = 0u; + self->private_impl.f_bitstream_wi = 0u; + self->private_impl.f_bitstream_padding = 12345u; + wuffs_jpeg__decoder__fill_bitstream(self, a_src); + v_my = 0u; + while (v_my < self->private_impl.f_scan_height_in_mcus) { + v_mx = 0u; + while (v_mx < self->private_impl.f_scan_width_in_mcus) { + self->private_impl.f_mcu_current_block = 0u; + self->private_impl.f_mcu_zig_index = ((uint32_t)(self->private_impl.f_scan_ss)); + if (self->private_impl.f_sof_marker >= 194u) { + wuffs_jpeg__decoder__load_mcu_blocks(self, v_mx, v_my, a_workbuf); + } + while (true) { + v_decode_mcu_result = wuffs_jpeg__decoder__decode_mcu(self, + a_dst, + a_workbuf, + v_mx, + v_my); + if (v_decode_mcu_result == 0u) { + break; + } else if (v_decode_mcu_result == 1u) { + } else if (v_decode_mcu_result == 2u) { + status = wuffs_base__make_status(wuffs_jpeg__error__internal_error_inconsistent_decoder_state); + goto exit; + } else { + status = self->private_impl.f_swizzle_immediately_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; + } + while (true) { + v_bitstream_length = ((uint32_t)(self->private_impl.f_bitstream_wi - self->private_impl.f_bitstream_ri)); + wuffs_jpeg__decoder__fill_bitstream(self, a_src); + if (v_bitstream_length < ((uint32_t)(self->private_impl.f_bitstream_wi - self->private_impl.f_bitstream_ri))) { + break; + } else if (self->private_impl.f_bitstream_padding == 0u) { + status = wuffs_base__make_status(wuffs_jpeg__error__short_sos_bitstream); + goto exit; + } else if ((a_src && a_src->meta.closed) && ! self->private_impl.f_bitstream_is_closed) { + if (self->private_impl.f_bitstream_wi < 1024u) { + wuffs_private_impl__bulk_memset(&self->private_data.f_bitstream_buffer[self->private_impl.f_bitstream_wi], 264u, 0u); + self->private_impl.f_bitstream_wi += 264u; + self->private_impl.f_bitstream_is_closed = true; + } + break; + } + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2); + } + } + if (self->private_impl.f_sof_marker >= 194u) { + wuffs_jpeg__decoder__save_mcu_blocks(self, v_mx, v_my, a_workbuf); + } + if (self->private_impl.f_restarts_remaining > 0u) { +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + self->private_impl.f_restarts_remaining -= 1u; +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + if (self->private_impl.f_restarts_remaining == 0u) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + status = wuffs_jpeg__decoder__skip_past_the_next_restart_marker(self, a_src); + if (status.repr) { + goto suspend; + } + self->private_impl.f_mcu_previous_dc_values[0u] = 0u; + self->private_impl.f_mcu_previous_dc_values[1u] = 0u; + self->private_impl.f_mcu_previous_dc_values[2u] = 0u; + self->private_impl.f_mcu_previous_dc_values[3u] = 0u; + self->private_impl.f_restarts_remaining = self->private_impl.f_restart_interval; + self->private_impl.f_eob_run = 0u; + self->private_impl.f_bitstream_bits = 0u; + self->private_impl.f_bitstream_n_bits = 0u; + self->private_impl.f_bitstream_ri = 0u; + self->private_impl.f_bitstream_wi = 0u; + self->private_impl.f_bitstream_padding = 12345u; + } + } + v_mx += 1u; + } + v_my += 1u; + } + wuffs_private_impl__u32__sat_add_indirect(&self->private_impl.f_scan_count, 1u); + + ok: + self->private_impl.p_decode_sos = 0; + goto exit; } - self->private_impl.active_coroutine = 0; + + goto suspend; + suspend: + self->private_impl.p_decode_sos = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_data.s_decode_sos.v_my = v_my; + self->private_data.s_decode_sos.v_mx = v_mx; + + goto exit; + exit: + return status; +} + +// -------- func jpeg.decoder.prepare_scan + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_jpeg__decoder__prepare_scan( + wuffs_jpeg__decoder* self, + wuffs_base__io_buffer* a_src) { wuffs_base__status status = wuffs_base__make_status(NULL); - uint32_t v_vminor = 0; - uint32_t v_number_length = 0; - uint32_t v_number_status = 0; - uint32_t v_string_length = 0; - uint32_t v_whitespace_length = 0; - uint32_t v_depth = 0; - uint32_t v_stack_byte = 0; - uint32_t v_stack_bit = 0; - uint32_t v_match = 0; - uint32_t v_c32 = 0; uint8_t v_c8 = 0; - uint8_t v_backslash = 0; - uint8_t v_char = 0; - uint8_t v_class = 0; - uint32_t v_multi_byte_utf8 = 0; - uint8_t v_backslash_x_ok = 0; - uint8_t v_backslash_x_value = 0; - uint32_t v_backslash_x_string = 0; - uint8_t v_uni4_ok = 0; - uint64_t v_uni4_string = 0; - uint32_t v_uni4_value = 0; - uint32_t v_uni4_high_surrogate = 0; - uint8_t v_uni8_ok = 0; - uint64_t v_uni8_string = 0; - uint32_t v_uni8_value = 0; - uint32_t v_expect = 0; - uint32_t v_expect_after_value = 0; + uint32_t v_i = 0; + uint32_t v_j = 0; + uint32_t v_j_max_incl = 0; + bool v_failed = false; - wuffs_base__token* iop_a_dst = NULL; - wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - wuffs_base__token* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - wuffs_base__token* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - if (a_dst && a_dst->data.ptr) { - io0_a_dst = a_dst->data.ptr; - io1_a_dst = io0_a_dst + a_dst->meta.wi; - iop_a_dst = io1_a_dst; - io2_a_dst = io0_a_dst + a_dst->data.len; - if (a_dst->meta.closed) { - io2_a_dst = iop_a_dst; - } - } 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; @@ -51780,214 +52222,3432 @@ wuffs_json__decoder__decode_tokens( io2_a_src = io0_a_src + a_src->meta.wi; } - uint32_t coro_susp_point = self->private_impl.p_decode_tokens; + uint32_t coro_susp_point = self->private_impl.p_prepare_scan; if (coro_susp_point) { - v_depth = self->private_data.s_decode_tokens.v_depth; - v_expect = self->private_data.s_decode_tokens.v_expect; - v_expect_after_value = self->private_data.s_decode_tokens.v_expect_after_value; + v_i = self->private_data.s_prepare_scan.v_i; } switch (coro_susp_point) { WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - if (self->private_impl.f_end_of_data) { - status = wuffs_base__make_status(wuffs_base__note__end_of_data); - goto ok; + if ((self->private_impl.f_payload_length < 6u) || (self->private_impl.f_payload_length > 12u)) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); + goto exit; } - if (self->private_impl.f_quirks[18u]) { - if (self->private_impl.f_quirks[11u] || self->private_impl.f_quirks[12u] || self->private_impl.f_quirks[17u]) { - status = wuffs_base__make_status(wuffs_json__error__bad_quirk_combination); - goto exit; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } + uint8_t t_0 = *iop_a_src++; + v_c8 = t_0; } - if (self->private_impl.f_quirks[15u] || self->private_impl.f_quirks[16u]) { - if (a_dst) { - a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr)); + if ((v_c8 < 1u) || (v_c8 > 4u)) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); + goto exit; + } + self->private_impl.f_scan_num_components = ((uint32_t)(v_c8)); + if ((self->private_impl.f_scan_num_components > self->private_impl.f_num_components) || (self->private_impl.f_payload_length != (4u + (2u * self->private_impl.f_scan_num_components)))) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); + goto exit; + } + self->private_impl.f_payload_length = 0u; + v_i = 0u; + while (v_i < self->private_impl.f_scan_num_components) { + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_1 = *iop_a_src++; + v_c8 = t_1; } - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + v_j = 0u; + while (true) { + if (v_j >= self->private_impl.f_num_components) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); + goto exit; + } + if (v_c8 == self->private_impl.f_components_c[v_j]) { + if ( ! self->private_impl.f_seen_dqt[self->private_impl.f_components_tq[v_j]]) { + status = wuffs_base__make_status(wuffs_jpeg__error__missing_quantization_table); + goto exit; + } + self->private_impl.f_scan_comps_cselector[v_i] = ((uint8_t)(v_j)); + break; + } + v_j += 1u; } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - status = wuffs_json__decoder__decode_leading(self, a_dst, a_src); - if (a_dst) { - iop_a_dst = a_dst->data.ptr + a_dst->meta.wi; + v_j = 0u; + while (v_j < v_i) { + if (self->private_impl.f_scan_comps_cselector[v_i] == self->private_impl.f_scan_comps_cselector[v_j]) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); + goto exit; + } + v_j += 1u; } - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_2 = *iop_a_src++; + v_c8 = t_2; } - if (status.repr) { - goto suspend; + if ((((uint8_t)(v_c8 >> 4u)) > 3u) || (((uint8_t)(v_c8 & 15u)) > 3u)) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); + goto exit; + } + self->private_impl.f_scan_comps_td[v_i] = ((uint8_t)(v_c8 >> 4u)); + self->private_impl.f_scan_comps_ta[v_i] = ((uint8_t)(v_c8 & 15u)); + if (self->private_impl.f_sof_marker == 192u) { + if ((self->private_impl.f_scan_comps_td[v_i] > 1u) || (self->private_impl.f_scan_comps_ta[v_i] > 1u)) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); + goto exit; + } } + v_i += 1u; } - v_expect = 7858u; - label__outer__continue:; - while (true) { - while (true) { - if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0u) { - status = wuffs_base__make_status(wuffs_base__suspension__short_write); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2); - goto label__outer__continue; + if (self->private_impl.f_scan_count == 0u) { + self->private_impl.f_expect_multiple_scans = ((self->private_impl.f_sof_marker >= 194u) || (self->private_impl.f_scan_num_components < self->private_impl.f_num_components)); + } + if (self->private_impl.f_sof_marker < 194u) { + self->private_data.s_prepare_scan.scratch = 3u; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + if (self->private_data.s_prepare_scan.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { + self->private_data.s_prepare_scan.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); + iop_a_src = io2_a_src; + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + iop_a_src += self->private_data.s_prepare_scan.scratch; + self->private_impl.f_scan_ss = 0u; + self->private_impl.f_scan_se = 63u; + self->private_impl.f_scan_ah = 0u; + self->private_impl.f_scan_al = 0u; + } else { + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } - v_whitespace_length = 0u; - v_c8 = 0u; - v_class = 0u; - while (true) { - if (((uint64_t)(io2_a_src - iop_a_src)) <= 0u) { - if (v_whitespace_length > 0u) { - *iop_a_dst++ = wuffs_base__make_token( - (((uint64_t)(0u)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | - (((uint64_t)(v_whitespace_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); - v_whitespace_length = 0u; - } - if (a_src && a_src->meta.closed) { - status = wuffs_base__make_status(wuffs_json__error__bad_input); - goto exit; - } - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3); - goto label__outer__continue; - } - v_c8 = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); - v_class = WUFFS_JSON__LUT_CLASSES[v_c8]; - if (v_class != 0u) { - break; - } - iop_a_src += 1u; - if (v_whitespace_length >= 65534u) { - *iop_a_dst++ = wuffs_base__make_token( - (((uint64_t)(0u)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | - (((uint64_t)(65535u)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); - v_whitespace_length = 0u; - goto label__outer__continue; - } - v_whitespace_length += 1u; + uint8_t t_3 = *iop_a_src++; + v_c8 = t_3; + } + if (v_c8 > 63u) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); + goto exit; + } + self->private_impl.f_scan_ss = v_c8; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } - if (v_whitespace_length > 0u) { - *iop_a_dst++ = wuffs_base__make_token( - (((uint64_t)(0u)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | - (((uint64_t)(v_whitespace_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); - v_whitespace_length = 0u; - if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0u) { - goto label__outer__continue; - } + uint8_t t_4 = *iop_a_src++; + v_c8 = t_4; + } + if ((v_c8 > 63u) || (v_c8 < self->private_impl.f_scan_ss)) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); + goto exit; + } + self->private_impl.f_scan_se = v_c8; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } - if (0u == (v_expect & (((uint32_t)(1u)) << v_class))) { - status = wuffs_base__make_status(wuffs_json__error__bad_input); + uint8_t t_5 = *iop_a_src++; + v_c8 = t_5; + } + if ((((uint8_t)(v_c8 >> 4u)) > 14u) || (((uint8_t)(v_c8 & 15u)) > 13u)) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); + goto exit; + } + self->private_impl.f_scan_ah = ((uint8_t)(v_c8 >> 4u)); + self->private_impl.f_scan_al = ((uint8_t)(v_c8 & 15u)); + if (self->private_impl.f_scan_ah > 0u) { + if (((uint8_t)(self->private_impl.f_scan_ah - 1u)) != self->private_impl.f_scan_al) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); goto exit; } - if (v_class == 1u) { - *iop_a_dst++ = wuffs_base__make_token( - (((uint64_t)(4194579u)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | - (((uint64_t)(1u)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) | - (((uint64_t)(1u)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); - iop_a_src += 1u; - label__string_loop_outer__continue:; - while (true) { - if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0u) { - status = wuffs_base__make_status(wuffs_base__suspension__short_write); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4); - continue; - } - v_string_length = 0u; - while (true) { - if (((uint64_t)(io2_a_src - iop_a_src)) <= 0u) { - if (v_string_length > 0u) { - *iop_a_dst++ = wuffs_base__make_token( - (((uint64_t)(4194819u)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | - (((uint64_t)(1u)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) | - (((uint64_t)(v_string_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); - v_string_length = 0u; - } - if (a_src && a_src->meta.closed) { - status = wuffs_base__make_status(wuffs_json__error__bad_input); - goto exit; - } - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5); - goto label__string_loop_outer__continue; - } - while (((uint64_t)(io2_a_src - iop_a_src)) > 4u) { - v_c32 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src); - if (0u != (WUFFS_JSON__LUT_CHARS[(255u & (v_c32 >> 0u))] | - WUFFS_JSON__LUT_CHARS[(255u & (v_c32 >> 8u))] | - WUFFS_JSON__LUT_CHARS[(255u & (v_c32 >> 16u))] | - WUFFS_JSON__LUT_CHARS[(255u & (v_c32 >> 24u))])) { - break; - } - iop_a_src += 4u; - if (v_string_length > 65527u) { - *iop_a_dst++ = wuffs_base__make_token( - (((uint64_t)(4194819u)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | - (((uint64_t)(1u)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) | - (((uint64_t)((v_string_length + 4u))) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); - v_string_length = 0u; - goto label__string_loop_outer__continue; - } - v_string_length += 4u; - } - v_c8 = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); - v_char = WUFFS_JSON__LUT_CHARS[v_c8]; - if (v_char == 0u) { - iop_a_src += 1u; - if (v_string_length >= 65531u) { - *iop_a_dst++ = wuffs_base__make_token( - (((uint64_t)(4194819u)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | - (((uint64_t)(1u)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) | - (((uint64_t)(65532u)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); - v_string_length = 0u; - goto label__string_loop_outer__continue; - } - v_string_length += 1u; - continue; - } else if (v_char == 1u) { - if (v_string_length != 0u) { - *iop_a_dst++ = wuffs_base__make_token( - (((uint64_t)(4194819u)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | - (((uint64_t)(1u)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) | - (((uint64_t)(v_string_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); - v_string_length = 0u; - } - goto label__string_loop_outer__break; - } else if (v_char == 2u) { - if (v_string_length > 0u) { - *iop_a_dst++ = wuffs_base__make_token( - (((uint64_t)(4194819u)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | - (((uint64_t)(1u)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) | - (((uint64_t)(v_string_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); - v_string_length = 0u; - if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0u) { - goto label__string_loop_outer__continue; - } - } - if (((uint64_t)(io2_a_src - iop_a_src)) < 2u) { - if (a_src && a_src->meta.closed) { - status = wuffs_base__make_status(wuffs_json__error__bad_backslash_escape); - goto exit; - } - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6); - goto label__string_loop_outer__continue; - } - v_c8 = ((uint8_t)(((uint16_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src) >> 8u)))); - v_backslash = WUFFS_JSON__LUT_BACKSLASHES[v_c8]; - if (((uint8_t)(v_backslash & 128u)) != 0u) { - iop_a_src += 2u; - *iop_a_dst++ = wuffs_base__make_token( - (((uint64_t)((6291456u | ((uint32_t)(((uint8_t)(v_backslash & 127u))))))) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | - (((uint64_t)(1u)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) | - (((uint64_t)(2u)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); - goto label__string_loop_outer__continue; - } else if (v_backslash != 0u) { - if (self->private_impl.f_quirks[WUFFS_JSON__LUT_QUIRKY_BACKSLASHES_QUIRKS[((uint8_t)(v_backslash & 7u))]]) { - iop_a_src += 2u; - *iop_a_dst++ = wuffs_base__make_token( - (((uint64_t)((6291456u | ((uint32_t)(WUFFS_JSON__LUT_QUIRKY_BACKSLASHES_CHARS[((uint8_t)(v_backslash & 7u))]))))) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | - (((uint64_t)(1u)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) | - (((uint64_t)(2u)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); - goto label__string_loop_outer__continue; - } - } else if (v_c8 == 117u) { - if (((uint64_t)(io2_a_src - iop_a_src)) < 6u) { - if (a_src && a_src->meta.closed) { + } + if (self->private_impl.f_scan_ss == 0u) { + if (self->private_impl.f_scan_se != 0u) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); + goto exit; + } else if (self->private_impl.f_scan_ah == 0u) { + self->private_impl.choosy_decode_mcu = ( + &wuffs_jpeg__decoder__decode_mcu_progressive_dc_high_bits); + } else { + self->private_impl.choosy_decode_mcu = ( + &wuffs_jpeg__decoder__decode_mcu_progressive_dc_low_bit); + } + } else { + if (self->private_impl.f_scan_num_components != 1u) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); + goto exit; + } else if (self->private_impl.f_scan_ah == 0u) { + self->private_impl.choosy_decode_mcu = ( + &wuffs_jpeg__decoder__decode_mcu_progressive_ac_high_bits); + } else { + self->private_impl.choosy_decode_mcu = ( + &wuffs_jpeg__decoder__decode_mcu_progressive_ac_low_bit); + } + } + } + v_i = 0u; + while (v_i < self->private_impl.f_scan_num_components) { + if ((self->private_impl.f_scan_ss == 0u) && ! self->private_impl.f_seen_dht[((uint8_t)(0u | self->private_impl.f_scan_comps_td[v_i]))]) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); + status = wuffs_jpeg__decoder__use_default_huffman_table(self, ((uint8_t)(0u | self->private_impl.f_scan_comps_td[v_i]))); + if (status.repr) { + goto suspend; + } + } + if ((self->private_impl.f_scan_se != 0u) && ! self->private_impl.f_seen_dht[((uint8_t)(4u | self->private_impl.f_scan_comps_ta[v_i]))]) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); + status = wuffs_jpeg__decoder__use_default_huffman_table(self, ((uint8_t)(4u | self->private_impl.f_scan_comps_ta[v_i]))); + if (status.repr) { + goto suspend; + } + } + v_j = ((uint32_t)(self->private_impl.f_scan_ss)); + v_j_max_incl = ((uint32_t)(wuffs_base__u8__min(self->private_impl.f_scan_se, 9u))); + while (v_j <= v_j_max_incl) { + self->private_impl.f_block_smoothing_lowest_scan_al[self->private_impl.f_scan_comps_cselector[v_i]][v_j] = self->private_impl.f_scan_al; + v_j += 1u; + } + v_i += 1u; + } + if (self->private_impl.f_scan_num_components == 1u) { + wuffs_jpeg__decoder__calculate_single_component_scan_fields(self); + } else { + v_failed = wuffs_jpeg__decoder__calculate_multiple_component_scan_fields(self); + if (v_failed) { + status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker); + goto exit; + } + } + + goto ok; + ok: + self->private_impl.p_prepare_scan = 0; + goto exit; + } + + goto suspend; + suspend: + self->private_impl.p_prepare_scan = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_data.s_prepare_scan.v_i = v_i; + + 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 jpeg.decoder.use_default_huffman_table + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_jpeg__decoder__use_default_huffman_table( + wuffs_jpeg__decoder* self, + uint8_t a_tc4_th) { + wuffs_base__status status = wuffs_base__make_status(NULL); + + wuffs_base__slice_u8 v_data = {0}; + wuffs_base__io_buffer u_r = wuffs_base__empty_io_buffer(); + wuffs_base__io_buffer* v_r = &u_r; + const uint8_t* iop_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + const uint8_t* io0_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + const uint8_t* io1_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + const uint8_t* io2_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + wuffs_base__status v_status = wuffs_base__make_status(NULL); + + if (a_tc4_th == 0u) { + v_data = wuffs_base__make_slice_u8(wuffs_base__strip_const_from_u8_ptr(WUFFS_JPEG__DEFAULT_HUFF_TABLE_DC_LUMA), 29); + } else if (a_tc4_th == 1u) { + v_data = wuffs_base__make_slice_u8(wuffs_base__strip_const_from_u8_ptr(WUFFS_JPEG__DEFAULT_HUFF_TABLE_DC_CHROMA), 29); + } else if (a_tc4_th == 4u) { + v_data = wuffs_base__make_slice_u8(wuffs_base__strip_const_from_u8_ptr(WUFFS_JPEG__DEFAULT_HUFF_TABLE_AC_LUMA), 179); + } else if (a_tc4_th == 5u) { + v_data = wuffs_base__make_slice_u8(wuffs_base__strip_const_from_u8_ptr(WUFFS_JPEG__DEFAULT_HUFF_TABLE_AC_CHROMA), 179); + } else { + status = wuffs_base__make_status(wuffs_jpeg__error__missing_huffman_table); + goto exit; + } + { + wuffs_base__io_buffer* o_0_v_r = v_r; + const uint8_t* o_0_iop_v_r = iop_v_r; + const uint8_t* o_0_io0_v_r = io0_v_r; + const uint8_t* o_0_io1_v_r = io1_v_r; + const uint8_t* o_0_io2_v_r = io2_v_r; + v_r = wuffs_private_impl__io_reader__set( + &u_r, + &iop_v_r, + &io0_v_r, + &io1_v_r, + &io2_v_r, + v_data, + 0u); + self->private_impl.f_payload_length = ((uint32_t)((((uint64_t)(v_data.len)) & 65535u))); + { + wuffs_base__status t_0 = wuffs_jpeg__decoder__decode_dht(self, v_r); + v_status = t_0; + } + v_r = o_0_v_r; + iop_v_r = o_0_iop_v_r; + io0_v_r = o_0_io0_v_r; + io1_v_r = o_0_io1_v_r; + io2_v_r = o_0_io2_v_r; + } + 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; + + ok: + goto exit; + exit: + return status; +} + +// -------- func jpeg.decoder.calculate_single_component_scan_fields + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_jpeg__decoder__calculate_single_component_scan_fields( + wuffs_jpeg__decoder* self) { + uint8_t v_csel = 0; + + self->private_impl.f_scan_comps_bx_offset[0u] = 0u; + self->private_impl.f_scan_comps_by_offset[0u] = 0u; + self->private_impl.f_mcu_num_blocks = 1u; + self->private_impl.f_mcu_blocks_sselector[0u] = 0u; + v_csel = self->private_impl.f_scan_comps_cselector[0u]; + self->private_impl.f_mcu_blocks_offset[0u] = self->private_impl.f_components_workbuf_offsets[v_csel]; + self->private_impl.f_mcu_blocks_mx_mul[0u] = 8u; + self->private_impl.f_mcu_blocks_my_mul[0u] = (8u * self->private_impl.f_components_workbuf_widths[v_csel]); + self->private_impl.f_mcu_blocks_dc_hselector[0u] = ((uint8_t)(0u | self->private_impl.f_scan_comps_td[0u])); + self->private_impl.f_mcu_blocks_ac_hselector[0u] = ((uint8_t)(4u | self->private_impl.f_scan_comps_ta[0u])); + self->private_impl.f_scan_width_in_mcus = wuffs_jpeg__decoder__quantize_dimension(self, self->private_impl.f_width, self->private_impl.f_components_h[v_csel], self->private_impl.f_max_incl_components_h); + self->private_impl.f_scan_height_in_mcus = wuffs_jpeg__decoder__quantize_dimension(self, self->private_impl.f_height, self->private_impl.f_components_v[v_csel], self->private_impl.f_max_incl_components_v); + return wuffs_base__make_empty_struct(); +} + +// -------- func jpeg.decoder.calculate_multiple_component_scan_fields + +WUFFS_BASE__GENERATED_C_CODE +static bool +wuffs_jpeg__decoder__calculate_multiple_component_scan_fields( + wuffs_jpeg__decoder* self) { + uint32_t v_i = 0; + uint32_t v_h = 0; + uint32_t v_v = 0; + uint32_t v_hv = 0; + uint32_t v_total_hv = 0; + uint32_t v_b = 0; + uint32_t v_bx_offset = 0; + uint32_t v_by_offset = 0; + uint32_t v_sibo = 0; + uint8_t v_ssel = 0; + uint8_t v_csel = 0; + + v_total_hv = 0u; + v_i = 0u; + v_b = 0u; + v_bx_offset = 0u; + v_by_offset = 0u; + while (v_i < self->private_impl.f_scan_num_components) { + v_h = ((uint32_t)(self->private_impl.f_components_h[self->private_impl.f_scan_comps_cselector[v_i]])); + v_v = ((uint32_t)(self->private_impl.f_components_v[self->private_impl.f_scan_comps_cselector[v_i]])); + v_hv = (((uint32_t)(self->private_impl.f_components_h[self->private_impl.f_scan_comps_cselector[v_i]])) * ((uint32_t)(self->private_impl.f_components_v[self->private_impl.f_scan_comps_cselector[v_i]]))); + self->private_impl.f_swizzle_immediately_c_offsets[v_i] = ((uint32_t)(64u * v_total_hv)); + v_total_hv += v_hv; + while (v_hv > 0u) { + self->private_impl.f_scan_comps_bx_offset[(v_b & 15u)] = ((uint8_t)((v_bx_offset & 3u))); + self->private_impl.f_scan_comps_by_offset[(v_b & 15u)] = ((uint8_t)((v_by_offset & 3u))); + self->private_impl.f_mcu_blocks_sselector[(v_b & 15u)] = ((uint8_t)(v_i)); + v_b += 1u; + v_bx_offset += 1u; + if (v_bx_offset == v_h) { + v_bx_offset = 0u; + v_by_offset += 1u; + if (v_by_offset == v_v) { + v_by_offset = 0u; + } + } + v_hv -= 1u; + } + v_i += 1u; + } + if (v_total_hv > 10u) { + return true; + } + self->private_impl.f_mcu_num_blocks = v_total_hv; + self->private_impl.f_swizzle_immediately_c_offsets[self->private_impl.f_scan_num_components] = ((uint32_t)(64u * v_total_hv)); + v_b = 0u; + while (v_b < self->private_impl.f_mcu_num_blocks) { + v_ssel = self->private_impl.f_mcu_blocks_sselector[v_b]; + v_csel = self->private_impl.f_scan_comps_cselector[v_ssel]; + self->private_impl.f_mcu_blocks_offset[v_b] = (self->private_impl.f_components_workbuf_offsets[v_csel] + (8u * ((uint64_t)(self->private_impl.f_scan_comps_bx_offset[v_b]))) + (8u * ((uint64_t)(self->private_impl.f_scan_comps_by_offset[v_b])) * ((uint64_t)(self->private_impl.f_components_workbuf_widths[v_csel])))); + self->private_impl.f_mcu_blocks_mx_mul[v_b] = (8u * ((uint32_t)(self->private_impl.f_components_h[v_csel]))); + self->private_impl.f_mcu_blocks_my_mul[v_b] = (8u * ((uint32_t)(self->private_impl.f_components_v[v_csel])) * self->private_impl.f_components_workbuf_widths[v_csel]); + self->private_impl.f_mcu_blocks_dc_hselector[v_b] = ((uint8_t)(0u | self->private_impl.f_scan_comps_td[v_ssel])); + self->private_impl.f_mcu_blocks_ac_hselector[v_b] = ((uint8_t)(4u | self->private_impl.f_scan_comps_ta[v_ssel])); + v_sibo = ((uint32_t)(self->private_impl.f_swizzle_immediately_c_offsets[v_csel] + ((8u * ((uint32_t)(self->private_impl.f_scan_comps_bx_offset[v_b]))) + (64u * ((uint32_t)(self->private_impl.f_scan_comps_by_offset[v_b])) * ((uint32_t)(self->private_impl.f_components_h[v_csel])))))); + self->private_impl.f_swizzle_immediately_b_offsets[v_b] = wuffs_base__u32__min(v_sibo, 576u); + v_b += 1u; + } + self->private_impl.f_scan_width_in_mcus = self->private_impl.f_width_in_mcus; + self->private_impl.f_scan_height_in_mcus = self->private_impl.f_height_in_mcus; + return false; +} + +// -------- func jpeg.decoder.fill_bitstream + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_jpeg__decoder__fill_bitstream( + wuffs_jpeg__decoder* self, + wuffs_base__io_buffer* a_src) { + uint32_t v_wi = 0; + uint8_t v_c8 = 0; + uint32_t v_new_wi = 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; + } + + if (self->private_impl.f_bitstream_ri <= 0u) { + } else if (self->private_impl.f_bitstream_ri >= self->private_impl.f_bitstream_wi) { + self->private_impl.f_bitstream_ri = 0u; + self->private_impl.f_bitstream_wi = 0u; + } else { + v_wi = (self->private_impl.f_bitstream_wi - self->private_impl.f_bitstream_ri); + wuffs_private_impl__slice_u8__copy_from_slice(wuffs_base__make_slice_u8(self->private_data.f_bitstream_buffer, 2048), wuffs_base__make_slice_u8_ij(self->private_data.f_bitstream_buffer, + self->private_impl.f_bitstream_ri, + self->private_impl.f_bitstream_wi)); + self->private_impl.f_bitstream_ri = 0u; + self->private_impl.f_bitstream_wi = v_wi; + } + v_wi = self->private_impl.f_bitstream_wi; + while ((v_wi < 2048u) && (((uint64_t)(io2_a_src - iop_a_src)) > 0u)) { + v_c8 = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); + if (v_c8 < 255u) { + self->private_data.f_bitstream_buffer[v_wi] = v_c8; + v_wi += 1u; + iop_a_src += 1u; + continue; + } else if (((uint64_t)(io2_a_src - iop_a_src)) <= 1u) { + break; + } + v_c8 = iop_a_src[1u]; + if (v_c8 == 0u) { + self->private_data.f_bitstream_buffer[v_wi] = 255u; + v_wi += 1u; + iop_a_src += 2u; + continue; + } else if (v_c8 < 255u) { + break; + } + iop_a_src += 1u; + } + if (((uint64_t)(io2_a_src - iop_a_src)) > 1u) { + if ((wuffs_base__peek_u8be__no_bounds_check(iop_a_src) >= 255u) && (((uint16_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src) >> 8u)) > 0u)) { + v_new_wi = (wuffs_base__u32__min(v_wi, 1784u) + 264u); + v_new_wi = wuffs_base__u32__min(v_new_wi, (v_wi + self->private_impl.f_bitstream_padding)); + if (v_wi < v_new_wi) { + wuffs_private_impl__u32__sat_sub_indirect(&self->private_impl.f_bitstream_padding, (v_new_wi - v_wi)); + wuffs_private_impl__bulk_memset(&self->private_data.f_bitstream_buffer[v_wi], (v_new_wi - v_wi), 0u); + v_wi = v_new_wi; + } + } + } + self->private_impl.f_bitstream_wi = v_wi; + if (a_src && a_src->data.ptr) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + + return wuffs_base__make_empty_struct(); +} + +// -------- func jpeg.decoder.load_mcu_blocks_for_single_component + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_jpeg__decoder__load_mcu_blocks_for_single_component( + wuffs_jpeg__decoder* self, + uint32_t a_mx, + uint32_t a_my, + wuffs_base__slice_u8 a_workbuf, + uint32_t a_csel) { + return (*self->private_impl.choosy_load_mcu_blocks_for_single_component)(self, a_mx, a_my, a_workbuf, a_csel); +} + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_jpeg__decoder__load_mcu_blocks_for_single_component__choosy_default( + wuffs_jpeg__decoder* self, + uint32_t a_mx, + uint32_t a_my, + wuffs_base__slice_u8 a_workbuf, + uint32_t a_csel) { + uint64_t v_stride16 = 0; + uint64_t v_offset = 0; + + v_stride16 = ((uint64_t)((self->private_impl.f_components_workbuf_widths[a_csel] * 16u))); + v_offset = (self->private_impl.f_components_workbuf_offsets[(a_csel | 4u)] + (((uint64_t)(a_mx)) * 128u) + (((uint64_t)(a_my)) * v_stride16)); + if (v_offset <= ((uint64_t)(a_workbuf.len))) { + wuffs_private_impl__bulk_load_host_endian(&self->private_data.f_mcu_blocks[0], 1u * (size_t)128u, wuffs_base__slice_u8__subslice_i(a_workbuf, v_offset)); + } + return wuffs_base__make_empty_struct(); +} + +// -------- func jpeg.decoder.load_mcu_blocks + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_jpeg__decoder__load_mcu_blocks( + wuffs_jpeg__decoder* self, + uint32_t a_mx, + uint32_t a_my, + wuffs_base__slice_u8 a_workbuf) { + uint32_t v_b = 0; + uint8_t v_csel = 0; + uint64_t v_h = 0; + uint64_t v_v = 0; + uint64_t v_stride16 = 0; + uint64_t v_offset = 0; + + v_h = 1u; + v_v = 1u; + v_b = 0u; + while (v_b < self->private_impl.f_mcu_num_blocks) { + v_csel = self->private_impl.f_scan_comps_cselector[self->private_impl.f_mcu_blocks_sselector[v_b]]; + if (self->private_impl.f_scan_num_components > 1u) { + v_h = ((uint64_t)(self->private_impl.f_components_h[v_csel])); + v_v = ((uint64_t)(self->private_impl.f_components_v[v_csel])); + } + v_stride16 = ((uint64_t)((self->private_impl.f_components_workbuf_widths[v_csel] * 16u))); + v_offset = (self->private_impl.f_components_workbuf_offsets[((uint8_t)(v_csel | 4u))] + (((v_h * ((uint64_t)(a_mx))) + ((uint64_t)(self->private_impl.f_scan_comps_bx_offset[v_b]))) * 128u) + (((v_v * ((uint64_t)(a_my))) + ((uint64_t)(self->private_impl.f_scan_comps_by_offset[v_b]))) * v_stride16)); + if (v_offset <= ((uint64_t)(a_workbuf.len))) { + wuffs_private_impl__bulk_load_host_endian(&self->private_data.f_mcu_blocks[v_b], 1u * (size_t)128u, wuffs_base__slice_u8__subslice_i(a_workbuf, v_offset)); + } + v_b += 1u; + } + return wuffs_base__make_empty_struct(); +} + +// -------- func jpeg.decoder.save_mcu_blocks + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_jpeg__decoder__save_mcu_blocks( + wuffs_jpeg__decoder* self, + uint32_t a_mx, + uint32_t a_my, + wuffs_base__slice_u8 a_workbuf) { + uint32_t v_b = 0; + uint8_t v_csel = 0; + uint64_t v_h = 0; + uint64_t v_v = 0; + uint64_t v_stride16 = 0; + uint64_t v_offset = 0; + + v_h = 1u; + v_v = 1u; + v_b = 0u; + while (v_b < self->private_impl.f_mcu_num_blocks) { + v_csel = self->private_impl.f_scan_comps_cselector[self->private_impl.f_mcu_blocks_sselector[v_b]]; + if (self->private_impl.f_scan_num_components > 1u) { + v_h = ((uint64_t)(self->private_impl.f_components_h[v_csel])); + v_v = ((uint64_t)(self->private_impl.f_components_v[v_csel])); + } + v_stride16 = ((uint64_t)((self->private_impl.f_components_workbuf_widths[v_csel] * 16u))); + v_offset = (self->private_impl.f_components_workbuf_offsets[((uint8_t)(v_csel | 4u))] + (((v_h * ((uint64_t)(a_mx))) + ((uint64_t)(self->private_impl.f_scan_comps_bx_offset[v_b]))) * 128u) + (((v_v * ((uint64_t)(a_my))) + ((uint64_t)(self->private_impl.f_scan_comps_by_offset[v_b]))) * v_stride16)); + if (v_offset <= ((uint64_t)(a_workbuf.len))) { + wuffs_private_impl__bulk_save_host_endian(&self->private_data.f_mcu_blocks[v_b], 1u * (size_t)128u, wuffs_base__slice_u8__subslice_i(a_workbuf, v_offset)); + } + v_b += 1u; + } + return wuffs_base__make_empty_struct(); +} + +// -------- func jpeg.decoder.skip_past_the_next_restart_marker + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_jpeg__decoder__skip_past_the_next_restart_marker( + wuffs_jpeg__decoder* self, + wuffs_base__io_buffer* a_src) { + wuffs_base__status status = wuffs_base__make_status(NULL); + + uint8_t v_c8 = 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_skip_past_the_next_restart_marker; + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + + while (true) { + if (((uint64_t)(io2_a_src - iop_a_src)) < 2u) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1); + continue; + } else if (wuffs_base__peek_u8be__no_bounds_check(iop_a_src) < 255u) { + iop_a_src += 1u; + continue; + } + v_c8 = ((uint8_t)(((uint16_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src) >> 8u)))); + if (v_c8 < 192u) { + iop_a_src += 2u; + continue; + } else if ((v_c8 < 208u) || (215u < v_c8)) { + break; + } + v_c8 &= 7u; + if ((self->private_impl.f_next_restart_marker == ((uint8_t)(((uint8_t)(v_c8 + 1u)) & 7u))) || (self->private_impl.f_next_restart_marker == ((uint8_t)(((uint8_t)(v_c8 + 2u)) & 7u)))) { + break; + } else if ((self->private_impl.f_next_restart_marker == ((uint8_t)(((uint8_t)(v_c8 + 7u)) & 7u))) || (self->private_impl.f_next_restart_marker == ((uint8_t)(((uint8_t)(v_c8 + 6u)) & 7u)))) { + iop_a_src += 2u; + continue; + } else { + iop_a_src += 2u; + break; + } + } + self->private_impl.f_next_restart_marker = ((uint8_t)(((uint8_t)(self->private_impl.f_next_restart_marker + 1u)) & 7u)); + + ok: + self->private_impl.p_skip_past_the_next_restart_marker = 0; + goto exit; + } + + goto suspend; + suspend: + self->private_impl.p_skip_past_the_next_restart_marker = 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 jpeg.decoder.apply_progressive_idct + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_jpeg__decoder__apply_progressive_idct( + wuffs_jpeg__decoder* self, + wuffs_base__slice_u8 a_workbuf) { + uint32_t v_csel = 0; + bool v_block_smoothing_applicable = false; + uint32_t v_scan_width_in_mcus = 0; + uint32_t v_scan_height_in_mcus = 0; + uint32_t v_mcu_blocks_mx_mul_0 = 0; + uint32_t v_mcu_blocks_my_mul_0 = 0; + uint32_t v_my = 0; + uint32_t v_mx = 0; + uint64_t v_stride = 0; + uint64_t v_offset = 0; + uint8_t v_stashed_mcu_blocks_0[128] = {0}; + + wuffs_private_impl__bulk_save_host_endian(&self->private_data.f_mcu_blocks[0], 1u * (size_t)128u, wuffs_base__make_slice_u8(v_stashed_mcu_blocks_0, 128)); + v_block_smoothing_applicable = true; + v_csel = 0u; + while (v_csel < self->private_impl.f_num_components) { + if ((self->private_impl.f_block_smoothing_lowest_scan_al[v_csel][0u] >= 16u) || wuffs_jpeg__decoder__top_left_quants_has_zero(self, ((uint32_t)(self->private_impl.f_components_tq[v_csel])))) { + v_block_smoothing_applicable = false; + } + v_csel += 1u; + } + v_csel = 0u; + while (v_csel < self->private_impl.f_num_components) { + v_scan_width_in_mcus = wuffs_jpeg__decoder__quantize_dimension(self, self->private_impl.f_width, self->private_impl.f_components_h[v_csel], self->private_impl.f_max_incl_components_h); + v_scan_height_in_mcus = wuffs_jpeg__decoder__quantize_dimension(self, self->private_impl.f_height, self->private_impl.f_components_v[v_csel], self->private_impl.f_max_incl_components_v); + v_mcu_blocks_mx_mul_0 = 8u; + v_mcu_blocks_my_mul_0 = (8u * self->private_impl.f_components_workbuf_widths[v_csel]); + if (v_block_smoothing_applicable && (0u != (self->private_impl.f_block_smoothing_lowest_scan_al[v_csel][1u] | + self->private_impl.f_block_smoothing_lowest_scan_al[v_csel][2u] | + self->private_impl.f_block_smoothing_lowest_scan_al[v_csel][3u] | + self->private_impl.f_block_smoothing_lowest_scan_al[v_csel][4u] | + self->private_impl.f_block_smoothing_lowest_scan_al[v_csel][5u] | + self->private_impl.f_block_smoothing_lowest_scan_al[v_csel][6u] | + self->private_impl.f_block_smoothing_lowest_scan_al[v_csel][8u] | + self->private_impl.f_block_smoothing_lowest_scan_al[v_csel][8u] | + self->private_impl.f_block_smoothing_lowest_scan_al[v_csel][9u]))) { + self->private_impl.choosy_load_mcu_blocks_for_single_component = ( + &wuffs_jpeg__decoder__load_mcu_blocks_for_single_component_smooth); + self->private_impl.f_block_smoothing_mx_max_incl = wuffs_base__u32__sat_sub(v_scan_width_in_mcus, 1u); + self->private_impl.f_block_smoothing_my_max_incl = wuffs_base__u32__sat_sub(v_scan_height_in_mcus, 1u); + } else { + self->private_impl.choosy_load_mcu_blocks_for_single_component = ( + &wuffs_jpeg__decoder__load_mcu_blocks_for_single_component__choosy_default); + } + v_my = 0u; + while (v_my < v_scan_height_in_mcus) { + v_mx = 0u; + while (v_mx < v_scan_width_in_mcus) { + wuffs_jpeg__decoder__load_mcu_blocks_for_single_component(self, + v_mx, + v_my, + a_workbuf, + v_csel); + v_stride = ((uint64_t)(self->private_impl.f_components_workbuf_widths[v_csel])); + v_offset = (self->private_impl.f_components_workbuf_offsets[v_csel] + (((uint64_t)(v_mcu_blocks_mx_mul_0)) * ((uint64_t)(v_mx))) + (((uint64_t)(v_mcu_blocks_my_mul_0)) * ((uint64_t)(v_my)))); + if (v_offset <= ((uint64_t)(a_workbuf.len))) { + wuffs_jpeg__decoder__decode_idct(self, wuffs_base__slice_u8__subslice_i(a_workbuf, v_offset), v_stride, ((uint32_t)(self->private_impl.f_components_tq[v_csel]))); + } + v_mx += 1u; + } + v_my += 1u; + } + v_csel += 1u; + } + wuffs_private_impl__bulk_load_host_endian(&self->private_data.f_mcu_blocks[0], 1u * (size_t)128u, wuffs_base__make_slice_u8(v_stashed_mcu_blocks_0, 128)); + return wuffs_base__make_empty_struct(); +} + +// -------- func jpeg.decoder.swizzle_gray + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_jpeg__decoder__swizzle_gray( + wuffs_jpeg__decoder* self, + wuffs_base__pixel_buffer* a_dst, + wuffs_base__slice_u8 a_workbuf, + uint32_t a_x0, + uint32_t a_x1, + uint32_t a_y0, + uint32_t a_y1, + uint64_t a_stride) { + 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_x0 = 0; + uint64_t v_x1 = 0; + wuffs_base__table_u8 v_tab = {0}; + wuffs_base__slice_u8 v_dst = {0}; + uint32_t v_y = 0; + uint32_t v_y1 = 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_x0 = ((uint64_t)((v_dst_bytes_per_pixel * wuffs_base__u32__min(a_x0, self->private_impl.f_width)))); + v_x1 = ((uint64_t)((v_dst_bytes_per_pixel * wuffs_base__u32__min(a_x1, self->private_impl.f_width)))); + v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0u); + v_y = a_y0; + v_y1 = wuffs_base__u32__min(a_y1, self->private_impl.f_height); + while (v_y < v_y1) { + v_dst = wuffs_private_impl__table_u8__row_u32(v_tab, v_y); + if (v_x1 < ((uint64_t)(v_dst.len))) { + v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_x1); + } + if (v_x0 < ((uint64_t)(v_dst.len))) { + v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_x0); + } else { + v_dst = wuffs_base__utility__empty_slice_u8(); + } + wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024)), a_workbuf); + if (a_stride <= ((uint64_t)(a_workbuf.len))) { + a_workbuf = wuffs_base__slice_u8__subslice_i(a_workbuf, a_stride); + } else { + a_workbuf = wuffs_base__utility__empty_slice_u8(); + } + v_y += 1u; + } + return wuffs_base__make_status(NULL); +} + +// -------- func jpeg.decoder.swizzle_colorful + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_jpeg__decoder__swizzle_colorful( + wuffs_jpeg__decoder* self, + wuffs_base__pixel_buffer* a_dst, + wuffs_base__slice_u8 a_workbuf, + uint32_t a_x0, + uint32_t a_x1, + uint32_t a_y0, + uint32_t a_y1) { + uint64_t v_i = 0; + uint64_t v_j = 0; + wuffs_base__slice_u8 v_src0 = {0}; + wuffs_base__slice_u8 v_src1 = {0}; + wuffs_base__slice_u8 v_src2 = {0}; + wuffs_base__slice_u8 v_src3 = {0}; + uint32_t v_width0 = 0; + uint32_t v_width1 = 0; + uint32_t v_width2 = 0; + uint32_t v_width3 = 0; + uint32_t v_height0 = 0; + uint32_t v_height1 = 0; + uint32_t v_height2 = 0; + uint32_t v_height3 = 0; + wuffs_base__status v_status = wuffs_base__make_status(NULL); + + if (self->private_impl.f_swizzle_immediately) { + v_i = ((uint64_t)(self->private_impl.f_swizzle_immediately_c_offsets[0u])); + v_j = ((uint64_t)(self->private_impl.f_swizzle_immediately_c_offsets[1u])); + if ((v_i <= v_j) && (v_j <= 640u)) { + v_src0 = wuffs_base__make_slice_u8_ij(self->private_data.f_swizzle_immediately_buffer, v_i, v_j); + v_width0 = (8u * ((uint32_t)(self->private_impl.f_components_h[0u]))); + v_height0 = (8u * ((uint32_t)(self->private_impl.f_components_v[0u]))); + } + v_i = ((uint64_t)(self->private_impl.f_swizzle_immediately_c_offsets[1u])); + v_j = ((uint64_t)(self->private_impl.f_swizzle_immediately_c_offsets[2u])); + if ((v_i <= v_j) && (v_j <= 640u)) { + v_src1 = wuffs_base__make_slice_u8_ij(self->private_data.f_swizzle_immediately_buffer, v_i, v_j); + v_width1 = (8u * ((uint32_t)(self->private_impl.f_components_h[1u]))); + v_height1 = (8u * ((uint32_t)(self->private_impl.f_components_v[1u]))); + } + v_i = ((uint64_t)(self->private_impl.f_swizzle_immediately_c_offsets[2u])); + v_j = ((uint64_t)(self->private_impl.f_swizzle_immediately_c_offsets[3u])); + if ((v_i <= v_j) && (v_j <= 640u)) { + v_src2 = wuffs_base__make_slice_u8_ij(self->private_data.f_swizzle_immediately_buffer, v_i, v_j); + v_width2 = (8u * ((uint32_t)(self->private_impl.f_components_h[2u]))); + v_height2 = (8u * ((uint32_t)(self->private_impl.f_components_v[2u]))); + } + v_i = ((uint64_t)(self->private_impl.f_swizzle_immediately_c_offsets[3u])); + v_j = ((uint64_t)(self->private_impl.f_swizzle_immediately_c_offsets[4u])); + if ((v_i <= v_j) && (v_j <= 640u)) { + v_src3 = wuffs_base__make_slice_u8_ij(self->private_data.f_swizzle_immediately_buffer, v_i, v_j); + v_width3 = (8u * ((uint32_t)(self->private_impl.f_components_h[3u]))); + v_height3 = (8u * ((uint32_t)(self->private_impl.f_components_v[3u]))); + } + } else { + if ((self->private_impl.f_components_workbuf_offsets[0u] <= self->private_impl.f_components_workbuf_offsets[1u]) && (self->private_impl.f_components_workbuf_offsets[1u] <= ((uint64_t)(a_workbuf.len)))) { + v_src0 = wuffs_base__slice_u8__subslice_ij(a_workbuf, + self->private_impl.f_components_workbuf_offsets[0u], + self->private_impl.f_components_workbuf_offsets[1u]); + v_width0 = self->private_impl.f_components_workbuf_widths[0u]; + v_height0 = self->private_impl.f_components_workbuf_heights[0u]; + } + if ((self->private_impl.f_components_workbuf_offsets[1u] <= self->private_impl.f_components_workbuf_offsets[2u]) && (self->private_impl.f_components_workbuf_offsets[2u] <= ((uint64_t)(a_workbuf.len)))) { + v_src1 = wuffs_base__slice_u8__subslice_ij(a_workbuf, + self->private_impl.f_components_workbuf_offsets[1u], + self->private_impl.f_components_workbuf_offsets[2u]); + v_width1 = self->private_impl.f_components_workbuf_widths[1u]; + v_height1 = self->private_impl.f_components_workbuf_heights[1u]; + } + if ((self->private_impl.f_components_workbuf_offsets[2u] <= self->private_impl.f_components_workbuf_offsets[3u]) && (self->private_impl.f_components_workbuf_offsets[3u] <= ((uint64_t)(a_workbuf.len)))) { + v_src2 = wuffs_base__slice_u8__subslice_ij(a_workbuf, + self->private_impl.f_components_workbuf_offsets[2u], + self->private_impl.f_components_workbuf_offsets[3u]); + v_width2 = self->private_impl.f_components_workbuf_widths[2u]; + v_height2 = self->private_impl.f_components_workbuf_heights[2u]; + } + if ((self->private_impl.f_components_workbuf_offsets[3u] <= self->private_impl.f_components_workbuf_offsets[4u]) && (self->private_impl.f_components_workbuf_offsets[4u] <= ((uint64_t)(a_workbuf.len)))) { + v_src3 = wuffs_base__slice_u8__subslice_ij(a_workbuf, + self->private_impl.f_components_workbuf_offsets[3u], + self->private_impl.f_components_workbuf_offsets[4u]); + v_width3 = self->private_impl.f_components_workbuf_widths[3u]; + v_height3 = self->private_impl.f_components_workbuf_heights[3u]; + } + } + v_status = wuffs_base__pixel_swizzler__swizzle_ycck(&self->private_impl.f_swizzler, + a_dst, + wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024)), + (a_x0 & 65535u), + wuffs_base__u32__min(a_x1, self->private_impl.f_width), + (a_y0 & 65535u), + wuffs_base__u32__min(a_y1, self->private_impl.f_height), + v_src0, + v_src1, + v_src2, + v_src3, + v_width0, + v_width1, + v_width2, + v_width3, + v_height0, + v_height1, + v_height2, + v_height3, + v_width0, + v_width1, + v_width2, + v_width3, + self->private_impl.f_components_h[0u], + self->private_impl.f_components_h[1u], + self->private_impl.f_components_h[2u], + self->private_impl.f_components_h[3u], + self->private_impl.f_components_v[0u], + self->private_impl.f_components_v[1u], + self->private_impl.f_components_v[2u], + self->private_impl.f_components_v[3u], + self->private_impl.f_is_rgb_or_cmyk, + ! self->private_impl.f_use_lower_quality, + wuffs_base__make_slice_u8(self->private_data.f_swizzle_ycck_scratch_buffer_2k, 2048)); + return wuffs_private_impl__status__ensure_not_a_suspension(v_status); +} + +// -------- func jpeg.decoder.frame_dirty_rect + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32 +wuffs_jpeg__decoder__frame_dirty_rect( + const wuffs_jpeg__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 jpeg.decoder.num_animation_loops + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC uint32_t +wuffs_jpeg__decoder__num_animation_loops( + const wuffs_jpeg__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 jpeg.decoder.num_decoded_frame_configs + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC uint64_t +wuffs_jpeg__decoder__num_decoded_frame_configs( + const wuffs_jpeg__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 jpeg.decoder.num_decoded_frames + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC uint64_t +wuffs_jpeg__decoder__num_decoded_frames( + const wuffs_jpeg__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 jpeg.decoder.restart_frame + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_jpeg__decoder__restart_frame( + wuffs_jpeg__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); + } + + uint32_t v_i = 0; + uint32_t v_j = 0; + + if (self->private_impl.f_call_sequence < 32u) { + return wuffs_base__make_status(wuffs_base__error__bad_call_sequence); + } + if (a_index != 0u) { + return wuffs_base__make_status(wuffs_base__error__bad_argument); + } + self->private_impl.f_call_sequence = 40u; + self->private_impl.f_bitstream_is_closed = false; + self->private_impl.f_expect_multiple_scans = false; + self->private_impl.f_frame_config_io_position = a_io_position; + self->private_impl.f_scan_count = 0u; + self->private_impl.f_restart_interval = self->private_impl.f_saved_restart_interval; + v_i = 0u; + while (v_i < 4u) { + self->private_impl.f_seen_dqt[v_i] = self->private_impl.f_saved_seen_dqt[v_i]; + v_j = 0u; + while (v_j < 64u) { + self->private_impl.f_quant_tables[v_i][v_j] = self->private_impl.f_saved_quant_tables[v_i][v_j]; + v_j += 1u; + } + v_i += 1u; + } + v_i = 0u; + while (v_i < 4u) { + v_j = 0u; + while (v_j < 10u) { + self->private_impl.f_block_smoothing_lowest_scan_al[v_i][v_j] = 16u; + v_j += 1u; + } + v_i += 1u; + } + v_i = 0u; + while (v_i < 8u) { + self->private_impl.f_seen_dht[v_i] = false; + v_i += 1u; + } + return wuffs_base__make_status(NULL); +} + +// -------- func jpeg.decoder.set_report_metadata + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct +wuffs_jpeg__decoder__set_report_metadata( + wuffs_jpeg__decoder* self, + uint32_t a_fourcc, + bool a_report) { + return wuffs_base__make_empty_struct(); +} + +// -------- func jpeg.decoder.tell_me_more + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_jpeg__decoder__tell_me_more( + wuffs_jpeg__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 jpeg.decoder.workbuf_len + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 +wuffs_jpeg__decoder__workbuf_len( + const wuffs_jpeg__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(); + } + + if (self->private_impl.f_use_lower_quality && (self->private_impl.f_sof_marker < 194u)) { + return wuffs_base__utility__make_range_ii_u64(0u, self->private_impl.f_components_workbuf_offsets[8u]); + } + return wuffs_base__utility__make_range_ii_u64(self->private_impl.f_components_workbuf_offsets[8u], self->private_impl.f_components_workbuf_offsets[8u]); +} + +// -------- func jpeg.decoder.top_left_quants_has_zero + +WUFFS_BASE__GENERATED_C_CODE +static bool +wuffs_jpeg__decoder__top_left_quants_has_zero( + const wuffs_jpeg__decoder* self, + uint32_t a_q) { + return ((self->private_impl.f_quant_tables[a_q][0u] == 0u) || + (self->private_impl.f_quant_tables[a_q][1u] == 0u) || + (self->private_impl.f_quant_tables[a_q][2u] == 0u) || + (self->private_impl.f_quant_tables[a_q][3u] == 0u) || + (self->private_impl.f_quant_tables[a_q][8u] == 0u) || + (self->private_impl.f_quant_tables[a_q][9u] == 0u) || + (self->private_impl.f_quant_tables[a_q][10u] == 0u) || + (self->private_impl.f_quant_tables[a_q][16u] == 0u) || + (self->private_impl.f_quant_tables[a_q][17u] == 0u) || + (self->private_impl.f_quant_tables[a_q][24u] == 0u)); +} + +// -------- func jpeg.decoder.load_mcu_blocks_for_single_component_smooth + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_jpeg__decoder__load_mcu_blocks_for_single_component_smooth( + wuffs_jpeg__decoder* self, + uint32_t a_mx, + uint32_t a_my, + wuffs_base__slice_u8 a_workbuf, + uint32_t a_csel) { + uint64_t v_stride16 = 0; + uint64_t v_offset = 0; + uint32_t v_dx = 0; + uint32_t v_dy = 0; + uint32_t v_mx = 0; + uint32_t v_my = 0; + uint8_t v_q = 0; + uint32_t v_q_00 = 0; + uint32_t v_q_xy = 0; + uint8_t v_al = 0; + uint32_t v_scratch = 0; + uint32_t v_limit = 0; + + v_stride16 = ((uint64_t)((self->private_impl.f_components_workbuf_widths[a_csel] * 16u))); + v_offset = (self->private_impl.f_components_workbuf_offsets[(a_csel | 4u)] + (((uint64_t)(a_mx)) * 128u) + (((uint64_t)(a_my)) * v_stride16)); + if (v_offset <= ((uint64_t)(a_workbuf.len))) { + wuffs_private_impl__bulk_load_host_endian(&self->private_data.f_mcu_blocks[0], 1u * (size_t)128u, wuffs_base__slice_u8__subslice_i(a_workbuf, v_offset)); + } + v_dy = 0u; + while (v_dy < 5u) { + v_my = wuffs_base__u32__min(self->private_impl.f_block_smoothing_my_max_incl, wuffs_base__u32__sat_sub((a_my + v_dy), 2u)); + v_dx = 0u; + while (v_dx < 5u) { + v_mx = wuffs_base__u32__min(self->private_impl.f_block_smoothing_mx_max_incl, wuffs_base__u32__sat_sub((a_mx + v_dx), 2u)); + v_offset = (self->private_impl.f_components_workbuf_offsets[(a_csel | 4u)] + (((uint64_t)(v_mx)) * 128u) + (((uint64_t)(v_my)) * v_stride16)); + if (v_offset <= ((uint64_t)(a_workbuf.len))) { + wuffs_private_impl__bulk_load_host_endian(&self->private_impl.f_block_smoothing_dc_values[v_dy][v_dx], 1u * (size_t)2u, wuffs_base__slice_u8__subslice_i(a_workbuf, v_offset)); + } + v_dx += 1u; + } + v_dy += 1u; + } + v_q = self->private_impl.f_components_tq[a_csel]; + v_q_00 = ((uint32_t)(self->private_impl.f_quant_tables[v_q][0u])); + if (v_q_00 <= 0u) { + return wuffs_base__make_empty_struct(); + } + if (0u != (16u & + self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][1u] & + self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][2u] & + self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][3u] & + self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][4u] & + self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][5u] & + self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][6u] & + self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][7u] & + self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][8u] & + self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][9u])) { + v_scratch = 0u; + v_scratch += ((uint32_t)(4294967294u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); + v_scratch += ((uint32_t)(4294967290u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); + v_scratch += ((uint32_t)(4294967288u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); + v_scratch += ((uint32_t)(4294967290u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); + v_scratch += ((uint32_t)(4294967294u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); + v_scratch += ((uint32_t)(4294967290u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); + v_scratch += ((uint32_t)(6u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); + v_scratch += ((uint32_t)(42u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); + v_scratch += ((uint32_t)(6u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); + v_scratch += ((uint32_t)(4294967290u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); + v_scratch += ((uint32_t)(4294967288u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); + v_scratch += ((uint32_t)(42u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); + v_scratch += ((uint32_t)(152u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); + v_scratch += ((uint32_t)(42u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); + v_scratch += ((uint32_t)(4294967288u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); + v_scratch += ((uint32_t)(4294967290u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); + v_scratch += ((uint32_t)(6u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); + v_scratch += ((uint32_t)(42u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); + v_scratch += ((uint32_t)(6u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); + v_scratch += ((uint32_t)(4294967290u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); + v_scratch += ((uint32_t)(4294967294u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); + v_scratch += ((uint32_t)(4294967290u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); + v_scratch += ((uint32_t)(4294967288u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); + v_scratch += ((uint32_t)(4294967290u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); + v_scratch += ((uint32_t)(4294967294u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); + if (v_scratch < 2147483648u) { + v_scratch = ((uint32_t)(0u + (((uint32_t)(((uint32_t)(0u + v_scratch)) + 128u)) / 256u))); + } else { + v_scratch = ((uint32_t)(0u - (((uint32_t)(((uint32_t)(0u - v_scratch)) + 128u)) / 256u))); + } + self->private_data.f_mcu_blocks[0u][0u] = ((uint16_t)(v_scratch)); + v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][1u])); + if ((v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][1u] == 0u)) { + v_scratch = 0u; + v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); + v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); + v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); + v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); + v_scratch += ((uint32_t)(4294967293u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); + v_scratch += ((uint32_t)(13u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); + v_scratch += ((uint32_t)(4294967283u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); + v_scratch += ((uint32_t)(3u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); + v_scratch += ((uint32_t)(4294967293u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); + v_scratch += ((uint32_t)(38u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); + v_scratch += ((uint32_t)(4294967258u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); + v_scratch += ((uint32_t)(3u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); + v_scratch += ((uint32_t)(4294967293u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); + v_scratch += ((uint32_t)(13u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); + v_scratch += ((uint32_t)(4294967283u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); + v_scratch += ((uint32_t)(3u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); + v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); + v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); + v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); + v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); + v_scratch *= v_q_00; + if (v_scratch < 2147483648u) { + v_scratch = ((uint32_t)(0u + (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); + } else { + v_scratch = ((uint32_t)(0u - (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); + } + self->private_data.f_mcu_blocks[0u][1u] = ((uint16_t)(v_scratch)); + } + v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][2u])); + if ((v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][2u] == 0u)) { + v_scratch = 0u; + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); + v_scratch += ((uint32_t)(2u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); + v_scratch += ((uint32_t)(4294967291u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); + v_scratch += ((uint32_t)(2u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); + v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); + v_scratch += ((uint32_t)(7u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); + v_scratch += ((uint32_t)(4294967282u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); + v_scratch += ((uint32_t)(7u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); + v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); + v_scratch += ((uint32_t)(2u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); + v_scratch += ((uint32_t)(4294967291u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); + v_scratch += ((uint32_t)(2u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); + v_scratch *= v_q_00; + if (v_scratch < 2147483648u) { + v_scratch = ((uint32_t)(0u + (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); + } else { + v_scratch = ((uint32_t)(0u - (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); + } + self->private_data.f_mcu_blocks[0u][2u] = ((uint16_t)(v_scratch)); + } + v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][3u])); + if ((v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][3u] == 0u)) { + v_scratch = 0u; + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); + v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); + v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); + v_scratch += ((uint32_t)(2u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); + v_scratch += ((uint32_t)(4294967294u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); + v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); + v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); + v_scratch *= v_q_00; + if (v_scratch < 2147483648u) { + v_scratch = ((uint32_t)(0u + (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); + } else { + v_scratch = ((uint32_t)(0u - (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); + } + self->private_data.f_mcu_blocks[0u][3u] = ((uint16_t)(v_scratch)); + } + v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][8u])); + if ((v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][8u] == 0u)) { + v_scratch = 0u; + v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); + v_scratch += ((uint32_t)(4294967293u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); + v_scratch += ((uint32_t)(4294967293u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); + v_scratch += ((uint32_t)(4294967293u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); + v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); + v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); + v_scratch += ((uint32_t)(13u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); + v_scratch += ((uint32_t)(38u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); + v_scratch += ((uint32_t)(13u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); + v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); + v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); + v_scratch += ((uint32_t)(4294967283u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); + v_scratch += ((uint32_t)(4294967258u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); + v_scratch += ((uint32_t)(4294967283u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); + v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); + v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); + v_scratch += ((uint32_t)(3u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); + v_scratch += ((uint32_t)(3u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); + v_scratch += ((uint32_t)(3u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); + v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); + v_scratch *= v_q_00; + if (v_scratch < 2147483648u) { + v_scratch = ((uint32_t)(0u + (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); + } else { + v_scratch = ((uint32_t)(0u - (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); + } + self->private_data.f_mcu_blocks[0u][8u] = ((uint16_t)(v_scratch)); + } + v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][9u])); + if ((v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][9u] == 0u)) { + v_scratch = 0u; + v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); + v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); + v_scratch += ((uint32_t)(9u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); + v_scratch += ((uint32_t)(4294967287u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); + v_scratch += ((uint32_t)(4294967287u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); + v_scratch += ((uint32_t)(9u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); + v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); + v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); + v_scratch *= v_q_00; + if (v_scratch < 2147483648u) { + v_scratch = ((uint32_t)(0u + (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); + } else { + v_scratch = ((uint32_t)(0u - (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); + } + self->private_data.f_mcu_blocks[0u][9u] = ((uint16_t)(v_scratch)); + } + v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][10u])); + if ((v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][10u] == 0u)) { + v_scratch = 0u; + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); + v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); + v_scratch += ((uint32_t)(4294967293u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); + v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); + v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); + v_scratch += ((uint32_t)(3u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); + v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); + v_scratch *= v_q_00; + if (v_scratch < 2147483648u) { + v_scratch = ((uint32_t)(0u + (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); + } else { + v_scratch = ((uint32_t)(0u - (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); + } + self->private_data.f_mcu_blocks[0u][10u] = ((uint16_t)(v_scratch)); + } + v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][16u])); + if ((v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][16u] == 0u)) { + v_scratch = 0u; + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); + v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); + v_scratch += ((uint32_t)(2u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); + v_scratch += ((uint32_t)(7u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); + v_scratch += ((uint32_t)(2u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); + v_scratch += ((uint32_t)(4294967291u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); + v_scratch += ((uint32_t)(4294967282u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); + v_scratch += ((uint32_t)(4294967291u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); + v_scratch += ((uint32_t)(2u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); + v_scratch += ((uint32_t)(7u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); + v_scratch += ((uint32_t)(2u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); + v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); + v_scratch *= v_q_00; + if (v_scratch < 2147483648u) { + v_scratch = ((uint32_t)(0u + (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); + } else { + v_scratch = ((uint32_t)(0u - (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); + } + self->private_data.f_mcu_blocks[0u][16u] = ((uint16_t)(v_scratch)); + } + v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][17u])); + if ((v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][17u] == 0u)) { + v_scratch = 0u; + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); + v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); + v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); + v_scratch += ((uint32_t)(4294967293u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); + v_scratch += ((uint32_t)(3u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); + v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); + v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); + v_scratch *= v_q_00; + if (v_scratch < 2147483648u) { + v_scratch = ((uint32_t)(0u + (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); + } else { + v_scratch = ((uint32_t)(0u - (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); + } + self->private_data.f_mcu_blocks[0u][17u] = ((uint16_t)(v_scratch)); + } + v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][24u])); + if ((v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][24u] == 0u)) { + v_scratch = 0u; + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); + v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); + v_scratch += ((uint32_t)(2u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); + v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); + v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); + v_scratch += ((uint32_t)(4294967294u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); + v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); + v_scratch *= v_q_00; + if (v_scratch < 2147483648u) { + v_scratch = ((uint32_t)(0u + (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); + } else { + v_scratch = ((uint32_t)(0u - (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u)))); + } + self->private_data.f_mcu_blocks[0u][24u] = ((uint16_t)(v_scratch)); + } + } else { + v_al = self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][1u]; + v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][1u])); + if ((v_al > 0u) && (v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][1u] == 0u)) { + v_limit = ((((uint32_t)(1u)) << v_al) - 1u); + v_scratch = 0u; + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); + v_scratch += ((uint32_t)(4294967289u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); + v_scratch += ((uint32_t)(50u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); + v_scratch += ((uint32_t)(4294967246u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); + v_scratch += ((uint32_t)(7u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); + v_scratch *= v_q_00; + if (v_scratch < 2147483648u) { + v_scratch = ((uint32_t)(0u + wuffs_base__u32__min(v_limit, (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u))))); + } else { + v_scratch = ((uint32_t)(0u - wuffs_base__u32__min(v_limit, (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u))))); + } + self->private_data.f_mcu_blocks[0u][1u] = ((uint16_t)(v_scratch)); + } + v_al = self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][5u]; + v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][2u])); + if ((v_al > 0u) && (v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][2u] == 0u)) { + v_limit = ((((uint32_t)(1u)) << v_al) - 1u); + v_scratch = 0u; + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); + v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); + v_scratch += ((uint32_t)(13u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); + v_scratch += ((uint32_t)(4294967272u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); + v_scratch += ((uint32_t)(13u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); + v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); + v_scratch *= v_q_00; + if (v_scratch < 2147483648u) { + v_scratch = ((uint32_t)(0u + wuffs_base__u32__min(v_limit, (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u))))); + } else { + v_scratch = ((uint32_t)(0u - wuffs_base__u32__min(v_limit, (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u))))); + } + self->private_data.f_mcu_blocks[0u][2u] = ((uint16_t)(v_scratch)); + } + v_al = self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][2u]; + v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][8u])); + if ((v_al > 0u) && (v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][8u] == 0u)) { + v_limit = ((((uint32_t)(1u)) << v_al) - 1u); + v_scratch = 0u; + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); + v_scratch += ((uint32_t)(4294967289u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); + v_scratch += ((uint32_t)(50u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); + v_scratch += ((uint32_t)(4294967246u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); + v_scratch += ((uint32_t)(7u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); + v_scratch *= v_q_00; + if (v_scratch < 2147483648u) { + v_scratch = ((uint32_t)(0u + wuffs_base__u32__min(v_limit, (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u))))); + } else { + v_scratch = ((uint32_t)(0u - wuffs_base__u32__min(v_limit, (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u))))); + } + self->private_data.f_mcu_blocks[0u][8u] = ((uint16_t)(v_scratch)); + } + v_al = self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][4u]; + v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][9u])); + if ((v_al > 0u) && (v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][9u] == 0u)) { + v_limit = ((((uint32_t)(1u)) << v_al) - 1u); + v_scratch = 0u; + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); + v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); + v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); + v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); + v_scratch += ((uint32_t)(10u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); + v_scratch += ((uint32_t)(4294967286u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); + v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); + v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); + v_scratch += ((uint32_t)(4294967286u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); + v_scratch += ((uint32_t)(10u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); + v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); + v_scratch += ((uint32_t)(1u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); + v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); + v_scratch *= v_q_00; + if (v_scratch < 2147483648u) { + v_scratch = ((uint32_t)(0u + wuffs_base__u32__min(v_limit, (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u))))); + } else { + v_scratch = ((uint32_t)(0u - wuffs_base__u32__min(v_limit, (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u))))); + } + self->private_data.f_mcu_blocks[0u][9u] = ((uint16_t)(v_scratch)); + } + v_al = self->private_impl.f_block_smoothing_lowest_scan_al[a_csel][3u]; + v_q_xy = ((uint32_t)(self->private_impl.f_quant_tables[v_q][16u])); + if ((v_al > 0u) && (v_q_xy > 0u) && (self->private_data.f_mcu_blocks[0u][16u] == 0u)) { + v_limit = ((((uint32_t)(1u)) << v_al) - 1u); + v_scratch = 0u; + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][1u]))); + v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[0u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][1u]))); + v_scratch += ((uint32_t)(13u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[1u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][1u]))); + v_scratch += ((uint32_t)(4294967272u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[2u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][1u]))); + v_scratch += ((uint32_t)(13u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[3u][4u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][0u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][1u]))); + v_scratch += ((uint32_t)(4294967295u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][2u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][3u]))); + v_scratch += ((uint32_t)(0u * wuffs_base__utility__sign_extend_convert_u16_u32(self->private_impl.f_block_smoothing_dc_values[4u][4u]))); + v_scratch *= v_q_00; + if (v_scratch < 2147483648u) { + v_scratch = ((uint32_t)(0u + wuffs_base__u32__min(v_limit, (((uint32_t)(((uint32_t)(0u + v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u))))); + } else { + v_scratch = ((uint32_t)(0u - wuffs_base__u32__min(v_limit, (((uint32_t)(((uint32_t)(0u - v_scratch)) + (v_q_xy << 7u))) / (v_q_xy << 8u))))); + } + self->private_data.f_mcu_blocks[0u][16u] = ((uint16_t)(v_scratch)); + } + } + return wuffs_base__make_empty_struct(); +} + +// -------- func jpeg.decoder.decode_mcu + +WUFFS_BASE__GENERATED_C_CODE +static uint32_t +wuffs_jpeg__decoder__decode_mcu( + wuffs_jpeg__decoder* self, + wuffs_base__pixel_buffer* a_dst, + wuffs_base__slice_u8 a_workbuf, + uint32_t a_mx, + uint32_t a_my) { + return (*self->private_impl.choosy_decode_mcu)(self, a_dst, a_workbuf, a_mx, a_my); +} + +WUFFS_BASE__GENERATED_C_CODE +static uint32_t +wuffs_jpeg__decoder__decode_mcu__choosy_default( + wuffs_jpeg__decoder* self, + wuffs_base__pixel_buffer* a_dst, + wuffs_base__slice_u8 a_workbuf, + uint32_t a_mx, + uint32_t a_my) { + uint32_t v_ret = 0; + uint64_t v_bits = 0; + uint32_t v_n_bits = 0; + uint8_t v_csel = 0; + wuffs_base__io_buffer u_r = wuffs_base__empty_io_buffer(); + wuffs_base__io_buffer* v_r = &u_r; + const uint8_t* iop_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + const uint8_t* io0_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + const uint8_t* io1_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + const uint8_t* io2_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + uint32_t v_pos = 0; + uint8_t v_dc_h = 0; + uint32_t v_dc_symbol = 0; + uint32_t v_dc_ht_fast = 0; + uint32_t v_dc_bl = 0; + uint32_t v_dc_code = 0; + uint32_t v_dc_blm1 = 0; + uint32_t v_dc_ht_slow = 0; + uint16_t v_dc_value = 0; + uint16_t v_dc_extend = 0; + const uint16_t* v_ac_huff_table_fast = NULL; + uint8_t v_ac_h = 0; + uint32_t v_ac_symbol = 0; + uint32_t v_ac_ht_fast = 0; + uint32_t v_ac_bl = 0; + uint32_t v_ac_code = 0; + uint32_t v_ac_blm1 = 0; + uint32_t v_ac_ht_slow = 0; + uint16_t v_ac_value = 0; + uint16_t v_ac_extend = 0; + uint32_t v_ac_rrrr = 0; + uint32_t v_ac_ssss = 0; + uint32_t v_z = 0; + uint32_t v_mcb = 0; + uint64_t v_stride = 0; + uint64_t v_offset = 0; + + v_bits = self->private_impl.f_bitstream_bits; + v_n_bits = self->private_impl.f_bitstream_n_bits; + if (self->private_impl.f_bitstream_ri > self->private_impl.f_bitstream_wi) { + return 2u; + } + { + wuffs_base__io_buffer* o_0_v_r = v_r; + const uint8_t* o_0_iop_v_r = iop_v_r; + const uint8_t* o_0_io0_v_r = io0_v_r; + const uint8_t* o_0_io1_v_r = io1_v_r; + const uint8_t* o_0_io2_v_r = io2_v_r; + v_r = wuffs_private_impl__io_reader__set( + &u_r, + &iop_v_r, + &io0_v_r, + &io1_v_r, + &io2_v_r, + wuffs_base__make_slice_u8_ij(self->private_data.f_bitstream_buffer, + self->private_impl.f_bitstream_ri, + self->private_impl.f_bitstream_wi), + ((uint64_t)(self->private_impl.f_bitstream_ri))); + do { + while (self->private_impl.f_mcu_current_block < self->private_impl.f_mcu_num_blocks) { + while (self->private_impl.f_mcu_zig_index <= 0u) { + wuffs_private_impl__bulk_memset(&self->private_data.f_mcu_blocks[0], 1u * (size_t)128u, 0u); + if (((uint64_t)(io2_v_r - iop_v_r)) < 264u) { + v_ret = 1u; + goto label__goto_done__break; + } + v_bits |= (wuffs_base__peek_u64be__no_bounds_check(iop_v_r) >> (v_n_bits & 63u)); + iop_v_r += ((63u - (v_n_bits & 63u)) >> 3u); + v_n_bits |= 56u; + v_dc_h = self->private_impl.f_mcu_blocks_dc_hselector[self->private_impl.f_mcu_current_block]; + v_dc_ht_fast = ((uint32_t)(self->private_impl.f_huff_tables_fast[v_dc_h][(v_bits >> 56u)])); + v_dc_bl = (v_dc_ht_fast >> 8u); + if (v_n_bits >= v_dc_bl) { + v_dc_symbol = (15u & v_dc_ht_fast); + v_dc_extend = WUFFS_JPEG__EXTEND[v_dc_symbol]; + v_bits <<= (v_dc_bl & 63u); + v_n_bits -= v_dc_bl; + } else { + v_dc_code = ((uint32_t)((v_bits >> 55u))); + v_dc_blm1 = 8u; + v_bits <<= 9u; + v_n_bits -= 9u; + while (true) { + v_dc_ht_slow = self->private_impl.f_huff_tables_slow[v_dc_h][v_dc_blm1]; + if (v_dc_code < (v_dc_ht_slow >> 8u)) { + v_dc_symbol = (15u & ((uint32_t)(self->private_impl.f_huff_tables_symbols[v_dc_h][(255u & ((uint32_t)(v_dc_code + v_dc_ht_slow)))]))); + v_dc_extend = WUFFS_JPEG__EXTEND[v_dc_symbol]; + break; + } + v_dc_code = (((uint32_t)(v_dc_code << 1u)) | ((uint32_t)((v_bits >> 63u)))); + v_bits <<= 1u; + v_n_bits -= 1u; + v_dc_blm1 = ((v_dc_blm1 + 1u) & 15u); + if (v_dc_blm1 == 0u) { + v_dc_symbol = 0u; + v_dc_extend = WUFFS_JPEG__EXTEND[v_dc_symbol]; + break; + } + } + } + v_dc_value = ((uint16_t)(((v_bits >> 32u) >> (32u - v_dc_symbol)))); +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + v_dc_value += ((uint16_t)(v_dc_extend & ((uint16_t)(((uint16_t)(wuffs_base__utility__sign_extend_rshift_u64(v_bits, 63u))) ^ 65535u)))); +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + v_bits <<= v_dc_symbol; + v_n_bits -= v_dc_symbol; + v_csel = self->private_impl.f_scan_comps_cselector[self->private_impl.f_mcu_blocks_sselector[self->private_impl.f_mcu_current_block]]; +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + self->private_impl.f_mcu_previous_dc_values[v_csel] += v_dc_value; +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + self->private_data.f_mcu_blocks[0u][0u] = self->private_impl.f_mcu_previous_dc_values[v_csel]; + self->private_impl.f_mcu_zig_index = 1u; + break; + } + if (((uint64_t)(io2_v_r - iop_v_r)) < 264u) { + v_ret = 1u; + goto label__goto_done__break; + } + if (v_n_bits < 16u) { + v_bits |= (wuffs_base__peek_u64be__no_bounds_check(iop_v_r) >> (v_n_bits & 63u)); + } + v_z = 1u; + self->private_impl.f_mcu_zig_index = 0u; + v_ac_h = self->private_impl.f_mcu_blocks_ac_hselector[self->private_impl.f_mcu_current_block]; + v_ac_huff_table_fast = &self->private_impl.f_huff_tables_fast[v_ac_h][0u]; + while (v_z < 64u) { + v_ac_ht_fast = ((uint32_t)(v_ac_huff_table_fast[(v_bits >> 56u)])); + if (((uint64_t)(io2_v_r - iop_v_r)) < 8u) { + v_ret = 2u; + goto label__goto_done__break; + } + v_bits |= (wuffs_base__peek_u64be__no_bounds_check(iop_v_r) >> (v_n_bits & 63u)); + iop_v_r += ((63u - (v_n_bits & 63u)) >> 3u); + v_n_bits |= 56u; + v_ac_bl = (v_ac_ht_fast >> 8u); + if (v_n_bits >= v_ac_bl) { + v_ac_symbol = (255u & v_ac_ht_fast); + v_bits <<= (v_ac_bl & 63u); + v_n_bits -= v_ac_bl; + } else { + v_ac_code = ((uint32_t)((v_bits >> 55u))); + v_ac_blm1 = 8u; + v_bits <<= 9u; + v_n_bits -= 9u; + while (true) { + v_ac_ht_slow = self->private_impl.f_huff_tables_slow[v_ac_h][v_ac_blm1]; + if (v_ac_code < (v_ac_ht_slow >> 8u)) { + v_ac_symbol = ((uint32_t)(self->private_impl.f_huff_tables_symbols[v_ac_h][(255u & ((uint32_t)(v_ac_code + v_ac_ht_slow)))])); + break; + } + v_ac_code = (((uint32_t)(v_ac_code << 1u)) | ((uint32_t)((v_bits >> 63u)))); + v_bits <<= 1u; + v_n_bits -= 1u; + v_ac_blm1 = ((v_ac_blm1 + 1u) & 15u); + if (v_ac_blm1 == 0u) { + v_ac_symbol = 0u; + break; + } + } + } + v_ac_rrrr = (v_ac_symbol >> 4u); + v_z += (v_ac_rrrr + 1u); + v_ac_ssss = (v_ac_symbol & 15u); + v_ac_extend = WUFFS_JPEG__EXTEND[v_ac_ssss]; + if (v_ac_ssss > 0u) { + v_ac_value = ((uint16_t)((v_bits >> (64u - v_ac_ssss)))); +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + v_ac_value += ((uint16_t)(v_ac_extend & ((uint16_t)(((uint16_t)(wuffs_base__utility__sign_extend_rshift_u64(v_bits, 63u))) ^ 65535u)))); +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + v_bits <<= v_ac_ssss; + v_n_bits -= v_ac_ssss; + self->private_data.f_mcu_blocks[0u][WUFFS_JPEG__UNZIG[v_z]] = v_ac_value; + } else if (v_ac_rrrr < 15u) { + break; + } + } + v_mcb = self->private_impl.f_mcu_current_block; + self->private_impl.f_mcu_current_block += 1u; + if (self->private_impl.f_test_only_interrupt_decode_mcu) { + goto label__goto_done__break; + } + if ( ! self->private_impl.f_swizzle_immediately) { + v_csel = self->private_impl.f_scan_comps_cselector[self->private_impl.f_mcu_blocks_sselector[v_mcb]]; + v_stride = ((uint64_t)(self->private_impl.f_components_workbuf_widths[v_csel])); + v_offset = (self->private_impl.f_mcu_blocks_offset[v_mcb] + (((uint64_t)(self->private_impl.f_mcu_blocks_mx_mul[v_mcb])) * ((uint64_t)(a_mx))) + (((uint64_t)(self->private_impl.f_mcu_blocks_my_mul[v_mcb])) * ((uint64_t)(a_my)))); + if (v_offset <= ((uint64_t)(a_workbuf.len))) { + wuffs_jpeg__decoder__decode_idct(self, wuffs_base__slice_u8__subslice_i(a_workbuf, v_offset), v_stride, ((uint32_t)(self->private_impl.f_components_tq[v_csel]))); + } + } else if (self->private_impl.f_num_components == 1u) { + wuffs_jpeg__decoder__decode_idct(self, wuffs_base__make_slice_u8(self->private_data.f_swizzle_immediately_buffer, 64), 8u, ((uint32_t)(self->private_impl.f_components_tq[v_csel]))); + self->private_impl.f_swizzle_immediately_status = wuffs_jpeg__decoder__swizzle_gray(self, + a_dst, + wuffs_base__make_slice_u8(self->private_data.f_swizzle_immediately_buffer, 64), + ((a_mx + 0u) * 8u), + ((a_mx + 1u) * 8u), + ((a_my + 0u) * 8u), + ((a_my + 1u) * 8u), + 8u); + if ( ! wuffs_base__status__is_ok(&self->private_impl.f_swizzle_immediately_status)) { + v_ret = 3u; + goto label__goto_done__break; + } + break; + } else { + v_csel = self->private_impl.f_scan_comps_cselector[self->private_impl.f_mcu_blocks_sselector[v_mcb]]; + v_stride = (8u * ((uint64_t)(self->private_impl.f_components_h[v_csel]))); + wuffs_jpeg__decoder__decode_idct(self, wuffs_base__make_slice_u8_ij(self->private_data.f_swizzle_immediately_buffer, self->private_impl.f_swizzle_immediately_b_offsets[v_mcb], 640), v_stride, ((uint32_t)(self->private_impl.f_components_tq[v_csel]))); + if (self->private_impl.f_mcu_current_block < self->private_impl.f_mcu_num_blocks) { + continue; + } + self->private_impl.f_swizzle_immediately_status = wuffs_jpeg__decoder__swizzle_colorful(self, + a_dst, + wuffs_base__utility__empty_slice_u8(), + ((a_mx + 0u) * 8u * ((uint32_t)(self->private_impl.f_max_incl_components_h))), + ((a_mx + 1u) * 8u * ((uint32_t)(self->private_impl.f_max_incl_components_h))), + ((a_my + 0u) * 8u * ((uint32_t)(self->private_impl.f_max_incl_components_v))), + ((a_my + 1u) * 8u * ((uint32_t)(self->private_impl.f_max_incl_components_v)))); + if ( ! wuffs_base__status__is_ok(&self->private_impl.f_swizzle_immediately_status)) { + v_ret = 3u; + goto label__goto_done__break; + } + break; + } + } + self->private_impl.f_mcu_current_block = 0u; + } while (0); + label__goto_done__break:; + v_pos = ((uint32_t)(wuffs_base__u64__sat_add((v_r ? v_r->meta.pos : 0), ((uint64_t)(iop_v_r - io0_v_r))))); + if (v_pos > self->private_impl.f_bitstream_wi) { + v_ret = 2u; + } else { + self->private_impl.f_bitstream_ri = v_pos; + } + v_r = o_0_v_r; + iop_v_r = o_0_iop_v_r; + io0_v_r = o_0_io0_v_r; + io1_v_r = o_0_io1_v_r; + io2_v_r = o_0_io2_v_r; + } + self->private_impl.f_bitstream_bits = v_bits; + self->private_impl.f_bitstream_n_bits = v_n_bits; + return v_ret; +} + +// -------- func jpeg.decoder.decode_mcu_progressive_ac_high_bits + +WUFFS_BASE__GENERATED_C_CODE +static uint32_t +wuffs_jpeg__decoder__decode_mcu_progressive_ac_high_bits( + wuffs_jpeg__decoder* self, + wuffs_base__pixel_buffer* a_dst, + wuffs_base__slice_u8 a_workbuf, + uint32_t a_mx, + uint32_t a_my) { + uint32_t v_ret = 0; + uint64_t v_bits = 0; + uint32_t v_n_bits = 0; + wuffs_base__io_buffer u_r = wuffs_base__empty_io_buffer(); + wuffs_base__io_buffer* v_r = &u_r; + const uint8_t* iop_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + const uint8_t* io0_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + const uint8_t* io1_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + const uint8_t* io2_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + uint32_t v_pos = 0; + const uint16_t* v_ac_huff_table_fast = NULL; + uint8_t v_ac_h = 0; + uint32_t v_ac_symbol = 0; + uint32_t v_ac_ht_fast = 0; + uint32_t v_ac_bl = 0; + uint32_t v_ac_code = 0; + uint32_t v_ac_blm1 = 0; + uint32_t v_ac_ht_slow = 0; + uint16_t v_ac_value = 0; + uint16_t v_ac_extend = 0; + uint32_t v_ac_rrrr = 0; + uint32_t v_ac_ssss = 0; + uint32_t v_z = 0; + + if (self->private_impl.f_eob_run > 0u) { +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + self->private_impl.f_eob_run -= 1u; +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + return 0u; + } + v_bits = self->private_impl.f_bitstream_bits; + v_n_bits = self->private_impl.f_bitstream_n_bits; + if (self->private_impl.f_bitstream_ri > self->private_impl.f_bitstream_wi) { + return 2u; + } + { + wuffs_base__io_buffer* o_0_v_r = v_r; + const uint8_t* o_0_iop_v_r = iop_v_r; + const uint8_t* o_0_io0_v_r = io0_v_r; + const uint8_t* o_0_io1_v_r = io1_v_r; + const uint8_t* o_0_io2_v_r = io2_v_r; + v_r = wuffs_private_impl__io_reader__set( + &u_r, + &iop_v_r, + &io0_v_r, + &io1_v_r, + &io2_v_r, + wuffs_base__make_slice_u8_ij(self->private_data.f_bitstream_buffer, + self->private_impl.f_bitstream_ri, + self->private_impl.f_bitstream_wi), + ((uint64_t)(self->private_impl.f_bitstream_ri))); + do { + do { + if (((uint64_t)(io2_v_r - iop_v_r)) < 264u) { + v_ret = 1u; + goto label__goto_done__break; + } + if (v_n_bits < 16u) { + v_bits |= (wuffs_base__peek_u64be__no_bounds_check(iop_v_r) >> (v_n_bits & 63u)); + } + v_z = self->private_impl.f_mcu_zig_index; + self->private_impl.f_mcu_zig_index = 0u; + v_ac_h = self->private_impl.f_mcu_blocks_ac_hselector[0u]; + v_ac_huff_table_fast = &self->private_impl.f_huff_tables_fast[v_ac_h][0u]; + while (v_z <= ((uint32_t)(self->private_impl.f_scan_se))) { + v_ac_ht_fast = ((uint32_t)(v_ac_huff_table_fast[(v_bits >> 56u)])); + if (((uint64_t)(io2_v_r - iop_v_r)) < 8u) { + v_ret = 2u; + goto label__goto_done__break; + } + v_bits |= (wuffs_base__peek_u64be__no_bounds_check(iop_v_r) >> (v_n_bits & 63u)); + iop_v_r += ((63u - (v_n_bits & 63u)) >> 3u); + v_n_bits |= 56u; + v_ac_bl = (v_ac_ht_fast >> 8u); + if (v_n_bits >= v_ac_bl) { + v_ac_symbol = (255u & v_ac_ht_fast); + v_bits <<= (v_ac_bl & 63u); + v_n_bits -= v_ac_bl; + } else { + v_ac_code = ((uint32_t)((v_bits >> 55u))); + v_ac_blm1 = 8u; + v_bits <<= 9u; + v_n_bits -= 9u; + while (true) { + v_ac_ht_slow = self->private_impl.f_huff_tables_slow[v_ac_h][v_ac_blm1]; + if (v_ac_code < (v_ac_ht_slow >> 8u)) { + v_ac_symbol = ((uint32_t)(self->private_impl.f_huff_tables_symbols[v_ac_h][(255u & ((uint32_t)(v_ac_code + v_ac_ht_slow)))])); + break; + } + v_ac_code = (((uint32_t)(v_ac_code << 1u)) | ((uint32_t)((v_bits >> 63u)))); + v_bits <<= 1u; + v_n_bits -= 1u; + v_ac_blm1 = ((v_ac_blm1 + 1u) & 15u); + if (v_ac_blm1 == 0u) { + v_ac_symbol = 0u; + break; + } + } + } + v_ac_rrrr = (v_ac_symbol >> 4u); + v_z += (v_ac_rrrr + 1u); + v_ac_ssss = (v_ac_symbol & 15u); + v_ac_extend = WUFFS_JPEG__EXTEND[v_ac_ssss]; + if (v_ac_ssss > 0u) { + v_ac_value = ((uint16_t)((v_bits >> (64u - v_ac_ssss)))); +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + v_ac_value += ((uint16_t)(v_ac_extend & ((uint16_t)(((uint16_t)(wuffs_base__utility__sign_extend_rshift_u64(v_bits, 63u))) ^ 65535u)))); +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + v_bits <<= v_ac_ssss; + v_n_bits -= v_ac_ssss; + self->private_data.f_mcu_blocks[0u][WUFFS_JPEG__UNZIG[v_z]] = ((uint16_t)(((uint16_t)(v_ac_value << self->private_impl.f_scan_al)))); + } else if (v_ac_rrrr < 15u) { + self->private_impl.f_eob_run = ((uint16_t)(((uint16_t)(((uint16_t)(((uint16_t)(1u)) << v_ac_rrrr)) - 1u)))); + if (v_ac_rrrr > 0u) { +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + self->private_impl.f_eob_run += ((uint16_t)((v_bits >> (64u - v_ac_rrrr)))); +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + v_bits <<= v_ac_rrrr; + v_n_bits -= v_ac_rrrr; + } + break; + } + } + } while (0); + } while (0); + label__goto_done__break:; + v_pos = ((uint32_t)(wuffs_base__u64__sat_add((v_r ? v_r->meta.pos : 0), ((uint64_t)(iop_v_r - io0_v_r))))); + if (v_pos > self->private_impl.f_bitstream_wi) { + v_ret = 2u; + } else { + self->private_impl.f_bitstream_ri = v_pos; + } + v_r = o_0_v_r; + iop_v_r = o_0_iop_v_r; + io0_v_r = o_0_io0_v_r; + io1_v_r = o_0_io1_v_r; + io2_v_r = o_0_io2_v_r; + } + self->private_impl.f_bitstream_bits = v_bits; + self->private_impl.f_bitstream_n_bits = v_n_bits; + return v_ret; +} + +// -------- func jpeg.decoder.decode_mcu_progressive_ac_low_bit + +WUFFS_BASE__GENERATED_C_CODE +static uint32_t +wuffs_jpeg__decoder__decode_mcu_progressive_ac_low_bit( + wuffs_jpeg__decoder* self, + wuffs_base__pixel_buffer* a_dst, + wuffs_base__slice_u8 a_workbuf, + uint32_t a_mx, + uint32_t a_my) { + uint32_t v_ret = 0; + uint64_t v_bits = 0; + uint32_t v_n_bits = 0; + uint16_t v_one_lshift_scan_al = 0; + wuffs_base__io_buffer u_r = wuffs_base__empty_io_buffer(); + wuffs_base__io_buffer* v_r = &u_r; + const uint8_t* iop_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + const uint8_t* io0_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + const uint8_t* io1_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + const uint8_t* io2_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + uint32_t v_pos = 0; + const uint16_t* v_ac_huff_table_fast = NULL; + uint8_t v_ac_h = 0; + uint32_t v_ac_symbol = 0; + uint32_t v_ac_ht_fast = 0; + uint32_t v_ac_bl = 0; + uint32_t v_ac_code = 0; + uint32_t v_ac_blm1 = 0; + uint32_t v_ac_ht_slow = 0; + uint16_t v_ac_value = 0; + uint32_t v_ac_rrrr = 0; + uint32_t v_ac_ssss = 0; + uint8_t v_unzig = 0; + bool v_bit = false; + + v_bits = self->private_impl.f_bitstream_bits; + v_n_bits = self->private_impl.f_bitstream_n_bits; + v_one_lshift_scan_al = ((uint16_t)(((uint16_t)(1u)) << self->private_impl.f_scan_al)); + if (self->private_impl.f_bitstream_ri > self->private_impl.f_bitstream_wi) { + return 2u; + } + { + wuffs_base__io_buffer* o_0_v_r = v_r; + const uint8_t* o_0_iop_v_r = iop_v_r; + const uint8_t* o_0_io0_v_r = io0_v_r; + const uint8_t* o_0_io1_v_r = io1_v_r; + const uint8_t* o_0_io2_v_r = io2_v_r; + v_r = wuffs_private_impl__io_reader__set( + &u_r, + &iop_v_r, + &io0_v_r, + &io1_v_r, + &io2_v_r, + wuffs_base__make_slice_u8_ij(self->private_data.f_bitstream_buffer, + self->private_impl.f_bitstream_ri, + self->private_impl.f_bitstream_wi), + ((uint64_t)(self->private_impl.f_bitstream_ri))); + do { + do { + if (((uint64_t)(io2_v_r - iop_v_r)) < 264u) { + v_ret = 1u; + goto label__goto_done__break; + } + while (true) { + if (self->private_impl.f_eob_run > 0u) { + break; + } + v_ac_h = self->private_impl.f_mcu_blocks_ac_hselector[0u]; + v_ac_huff_table_fast = &self->private_impl.f_huff_tables_fast[v_ac_h][0u]; + while (true) { + if (((uint64_t)(io2_v_r - iop_v_r)) < 8u) { + v_ret = 2u; + goto label__goto_done__break; + } + v_bits |= (wuffs_base__peek_u64be__no_bounds_check(iop_v_r) >> (v_n_bits & 63u)); + iop_v_r += ((63u - (v_n_bits & 63u)) >> 3u); + v_n_bits |= 56u; + v_ac_ht_fast = ((uint32_t)(v_ac_huff_table_fast[(v_bits >> 56u)])); + v_ac_bl = (v_ac_ht_fast >> 8u); + if (v_n_bits >= v_ac_bl) { + v_ac_symbol = (255u & v_ac_ht_fast); + v_bits <<= (v_ac_bl & 63u); + v_n_bits -= v_ac_bl; + } else { + v_ac_code = ((uint32_t)((v_bits >> 55u))); + v_ac_blm1 = 8u; + v_bits <<= 9u; + v_n_bits -= 9u; + while (true) { + v_ac_ht_slow = self->private_impl.f_huff_tables_slow[v_ac_h][v_ac_blm1]; + if (v_ac_code < (v_ac_ht_slow >> 8u)) { + v_ac_symbol = ((uint32_t)(self->private_impl.f_huff_tables_symbols[v_ac_h][(255u & ((uint32_t)(v_ac_code + v_ac_ht_slow)))])); + break; + } + v_ac_code = (((uint32_t)(v_ac_code << 1u)) | ((uint32_t)((v_bits >> 63u)))); + v_bits <<= 1u; + v_n_bits -= 1u; + v_ac_blm1 = ((v_ac_blm1 + 1u) & 15u); + if (v_ac_blm1 == 0u) { + v_ac_symbol = 0u; + break; + } + } + } + v_ac_rrrr = (v_ac_symbol >> 4u); + v_ac_ssss = (v_ac_symbol & 15u); + v_ac_value = 0u; + if (v_ac_ssss > 0u) { + v_ac_value = ((uint16_t)(((uint16_t)(1u)) << self->private_impl.f_scan_al)); + if ((v_bits >> 63u) == 0u) { + v_ac_value = ((uint16_t)(((uint16_t)(65535u)) << self->private_impl.f_scan_al)); + } + v_bits <<= 1u; + v_n_bits -= 1u; + } else if (v_ac_rrrr < 15u) { + self->private_impl.f_eob_run = ((uint16_t)(((uint16_t)(1u)) << v_ac_rrrr)); + if (v_ac_rrrr > 0u) { +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + self->private_impl.f_eob_run += ((uint16_t)((v_bits >> (64u - v_ac_rrrr)))); +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + v_bits <<= v_ac_rrrr; + v_n_bits -= v_ac_rrrr; + } + goto label__goto_do_eob__break; + } + while (true) { + v_unzig = WUFFS_JPEG__UNZIG[(1u + self->private_impl.f_mcu_zig_index)]; + if (self->private_data.f_mcu_blocks[0u][v_unzig] != 0u) { + if (v_n_bits == 0u) { + if (((uint64_t)(io2_v_r - iop_v_r)) < 8u) { + v_ret = 2u; + goto label__goto_done__break; + } + v_bits |= (wuffs_base__peek_u64be__no_bounds_check(iop_v_r) >> (v_n_bits & 63u)); + iop_v_r += ((63u - (v_n_bits & 63u)) >> 3u); + v_n_bits |= 56u; + } + v_bit = ((v_bits >> 63u) > 0u); + v_bits <<= 1u; + v_n_bits -= 1u; + if (v_bit) { + if (self->private_data.f_mcu_blocks[0u][v_unzig] < 32768u) { +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + self->private_data.f_mcu_blocks[0u][v_unzig] += v_one_lshift_scan_al; +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + } else { +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + self->private_data.f_mcu_blocks[0u][v_unzig] -= v_one_lshift_scan_al; +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + } + } + } else if (v_ac_rrrr <= 0u) { + break; + } else { + v_ac_rrrr -= 1u; + } + if (self->private_impl.f_mcu_zig_index >= ((uint32_t)(self->private_impl.f_scan_se))) { + break; + } + self->private_impl.f_mcu_zig_index += 1u; + } + if (v_ac_value != 0u) { + self->private_data.f_mcu_blocks[0u][WUFFS_JPEG__UNZIG[(1u + self->private_impl.f_mcu_zig_index)]] = v_ac_value; + } + if (self->private_impl.f_mcu_zig_index >= ((uint32_t)(self->private_impl.f_scan_se))) { + break; + } + self->private_impl.f_mcu_zig_index += 1u; + } + goto label__block__break; + } + label__goto_do_eob__break:; + if (self->private_impl.f_eob_run <= 0u) { + v_ret = 2u; + goto label__goto_done__break; + } + while (true) { + v_unzig = WUFFS_JPEG__UNZIG[(1u + self->private_impl.f_mcu_zig_index)]; + if (self->private_data.f_mcu_blocks[0u][v_unzig] != 0u) { + if (v_n_bits == 0u) { + if (((uint64_t)(io2_v_r - iop_v_r)) < 8u) { + v_ret = 2u; + goto label__goto_done__break; + } + v_bits |= (wuffs_base__peek_u64be__no_bounds_check(iop_v_r) >> (v_n_bits & 63u)); + iop_v_r += ((63u - (v_n_bits & 63u)) >> 3u); + v_n_bits |= 56u; + } + v_bit = ((v_bits >> 63u) > 0u); + v_bits <<= 1u; + v_n_bits -= 1u; + if (v_bit) { + if (self->private_data.f_mcu_blocks[0u][v_unzig] < 32768u) { +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + self->private_data.f_mcu_blocks[0u][v_unzig] += v_one_lshift_scan_al; +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + } else { +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + self->private_data.f_mcu_blocks[0u][v_unzig] -= v_one_lshift_scan_al; +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + } + } + } + if (self->private_impl.f_mcu_zig_index >= ((uint32_t)(self->private_impl.f_scan_se))) { + break; + } + self->private_impl.f_mcu_zig_index += 1u; + } +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + self->private_impl.f_eob_run -= 1u; +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + } while (0); + label__block__break:; + } while (0); + label__goto_done__break:; + v_pos = ((uint32_t)(wuffs_base__u64__sat_add((v_r ? v_r->meta.pos : 0), ((uint64_t)(iop_v_r - io0_v_r))))); + if (v_pos > self->private_impl.f_bitstream_wi) { + v_ret = 2u; + } else { + self->private_impl.f_bitstream_ri = v_pos; + } + v_r = o_0_v_r; + iop_v_r = o_0_iop_v_r; + io0_v_r = o_0_io0_v_r; + io1_v_r = o_0_io1_v_r; + io2_v_r = o_0_io2_v_r; + } + self->private_impl.f_bitstream_bits = v_bits; + self->private_impl.f_bitstream_n_bits = v_n_bits; + return v_ret; +} + +// -------- func jpeg.decoder.decode_mcu_progressive_dc_high_bits + +WUFFS_BASE__GENERATED_C_CODE +static uint32_t +wuffs_jpeg__decoder__decode_mcu_progressive_dc_high_bits( + wuffs_jpeg__decoder* self, + wuffs_base__pixel_buffer* a_dst, + wuffs_base__slice_u8 a_workbuf, + uint32_t a_mx, + uint32_t a_my) { + uint32_t v_ret = 0; + uint64_t v_bits = 0; + uint32_t v_n_bits = 0; + uint8_t v_csel = 0; + wuffs_base__io_buffer u_r = wuffs_base__empty_io_buffer(); + wuffs_base__io_buffer* v_r = &u_r; + const uint8_t* iop_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + const uint8_t* io0_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + const uint8_t* io1_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + const uint8_t* io2_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + uint32_t v_pos = 0; + uint8_t v_dc_h = 0; + uint32_t v_dc_symbol = 0; + uint32_t v_dc_ht_fast = 0; + uint32_t v_dc_bl = 0; + uint32_t v_dc_code = 0; + uint32_t v_dc_blm1 = 0; + uint32_t v_dc_ht_slow = 0; + uint16_t v_dc_value = 0; + uint16_t v_dc_extend = 0; + + v_bits = self->private_impl.f_bitstream_bits; + v_n_bits = self->private_impl.f_bitstream_n_bits; + if (self->private_impl.f_bitstream_ri > self->private_impl.f_bitstream_wi) { + return 2u; + } + { + wuffs_base__io_buffer* o_0_v_r = v_r; + const uint8_t* o_0_iop_v_r = iop_v_r; + const uint8_t* o_0_io0_v_r = io0_v_r; + const uint8_t* o_0_io1_v_r = io1_v_r; + const uint8_t* o_0_io2_v_r = io2_v_r; + v_r = wuffs_private_impl__io_reader__set( + &u_r, + &iop_v_r, + &io0_v_r, + &io1_v_r, + &io2_v_r, + wuffs_base__make_slice_u8_ij(self->private_data.f_bitstream_buffer, + self->private_impl.f_bitstream_ri, + self->private_impl.f_bitstream_wi), + ((uint64_t)(self->private_impl.f_bitstream_ri))); + do { + while (self->private_impl.f_mcu_current_block < self->private_impl.f_mcu_num_blocks) { + if (((uint64_t)(io2_v_r - iop_v_r)) < 264u) { + v_ret = 1u; + goto label__goto_done__break; + } + do { + if (((uint64_t)(io2_v_r - iop_v_r)) < 8u) { + v_ret = 2u; + goto label__goto_done__break; + } + v_bits |= (wuffs_base__peek_u64be__no_bounds_check(iop_v_r) >> (v_n_bits & 63u)); + iop_v_r += ((63u - (v_n_bits & 63u)) >> 3u); + v_n_bits |= 56u; + v_dc_h = self->private_impl.f_mcu_blocks_dc_hselector[self->private_impl.f_mcu_current_block]; + v_dc_ht_fast = ((uint32_t)(self->private_impl.f_huff_tables_fast[v_dc_h][(v_bits >> 56u)])); + v_dc_bl = (v_dc_ht_fast >> 8u); + if (v_n_bits >= v_dc_bl) { + v_dc_symbol = (15u & v_dc_ht_fast); + v_dc_extend = WUFFS_JPEG__EXTEND[v_dc_symbol]; + v_bits <<= (v_dc_bl & 63u); + v_n_bits -= v_dc_bl; + } else { + v_dc_code = ((uint32_t)((v_bits >> 55u))); + v_dc_blm1 = 8u; + v_bits <<= 9u; + v_n_bits -= 9u; + while (true) { + v_dc_ht_slow = self->private_impl.f_huff_tables_slow[v_dc_h][v_dc_blm1]; + if (v_dc_code < (v_dc_ht_slow >> 8u)) { + v_dc_symbol = (15u & ((uint32_t)(self->private_impl.f_huff_tables_symbols[v_dc_h][(255u & ((uint32_t)(v_dc_code + v_dc_ht_slow)))]))); + v_dc_extend = WUFFS_JPEG__EXTEND[v_dc_symbol]; + break; + } + v_dc_code = (((uint32_t)(v_dc_code << 1u)) | ((uint32_t)((v_bits >> 63u)))); + v_bits <<= 1u; + v_n_bits -= 1u; + v_dc_blm1 = ((v_dc_blm1 + 1u) & 15u); + if (v_dc_blm1 == 0u) { + v_dc_symbol = 0u; + v_dc_extend = WUFFS_JPEG__EXTEND[v_dc_symbol]; + break; + } + } + } + v_dc_value = ((uint16_t)(((v_bits >> 32u) >> (32u - v_dc_symbol)))); +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + v_dc_value += ((uint16_t)(v_dc_extend & ((uint16_t)(((uint16_t)(wuffs_base__utility__sign_extend_rshift_u64(v_bits, 63u))) ^ 65535u)))); +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + v_bits <<= v_dc_symbol; + v_n_bits -= v_dc_symbol; + v_csel = self->private_impl.f_scan_comps_cselector[self->private_impl.f_mcu_blocks_sselector[self->private_impl.f_mcu_current_block]]; +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + self->private_impl.f_mcu_previous_dc_values[v_csel] += v_dc_value; +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + self->private_data.f_mcu_blocks[self->private_impl.f_mcu_current_block][0u] = ((uint16_t)(self->private_impl.f_mcu_previous_dc_values[v_csel] << self->private_impl.f_scan_al)); + } while (0); + self->private_impl.f_mcu_current_block += 1u; + } + self->private_impl.f_mcu_current_block = 0u; + } while (0); + label__goto_done__break:; + v_pos = ((uint32_t)(wuffs_base__u64__sat_add((v_r ? v_r->meta.pos : 0), ((uint64_t)(iop_v_r - io0_v_r))))); + if (v_pos > self->private_impl.f_bitstream_wi) { + v_ret = 2u; + } else { + self->private_impl.f_bitstream_ri = v_pos; + } + v_r = o_0_v_r; + iop_v_r = o_0_iop_v_r; + io0_v_r = o_0_io0_v_r; + io1_v_r = o_0_io1_v_r; + io2_v_r = o_0_io2_v_r; + } + self->private_impl.f_bitstream_bits = v_bits; + self->private_impl.f_bitstream_n_bits = v_n_bits; + return v_ret; +} + +// -------- func jpeg.decoder.decode_mcu_progressive_dc_low_bit + +WUFFS_BASE__GENERATED_C_CODE +static uint32_t +wuffs_jpeg__decoder__decode_mcu_progressive_dc_low_bit( + wuffs_jpeg__decoder* self, + wuffs_base__pixel_buffer* a_dst, + wuffs_base__slice_u8 a_workbuf, + uint32_t a_mx, + uint32_t a_my) { + uint32_t v_ret = 0; + uint64_t v_bits = 0; + uint32_t v_n_bits = 0; + uint16_t v_one_lshift_scan_al = 0; + wuffs_base__io_buffer u_r = wuffs_base__empty_io_buffer(); + wuffs_base__io_buffer* v_r = &u_r; + const uint8_t* iop_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + const uint8_t* io0_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + const uint8_t* io1_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + const uint8_t* io2_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + uint32_t v_pos = 0; + + v_bits = self->private_impl.f_bitstream_bits; + v_n_bits = self->private_impl.f_bitstream_n_bits; + v_one_lshift_scan_al = ((uint16_t)(((uint16_t)(1u)) << self->private_impl.f_scan_al)); + if (self->private_impl.f_bitstream_ri > self->private_impl.f_bitstream_wi) { + return 2u; + } + { + wuffs_base__io_buffer* o_0_v_r = v_r; + const uint8_t* o_0_iop_v_r = iop_v_r; + const uint8_t* o_0_io0_v_r = io0_v_r; + const uint8_t* o_0_io1_v_r = io1_v_r; + const uint8_t* o_0_io2_v_r = io2_v_r; + v_r = wuffs_private_impl__io_reader__set( + &u_r, + &iop_v_r, + &io0_v_r, + &io1_v_r, + &io2_v_r, + wuffs_base__make_slice_u8_ij(self->private_data.f_bitstream_buffer, + self->private_impl.f_bitstream_ri, + self->private_impl.f_bitstream_wi), + ((uint64_t)(self->private_impl.f_bitstream_ri))); + do { + while (self->private_impl.f_mcu_current_block < self->private_impl.f_mcu_num_blocks) { + if (((uint64_t)(io2_v_r - iop_v_r)) < 264u) { + v_ret = 1u; + goto label__goto_done__break; + } + do { + if (((uint64_t)(io2_v_r - iop_v_r)) < 8u) { + v_ret = 2u; + goto label__goto_done__break; + } + v_bits |= (wuffs_base__peek_u64be__no_bounds_check(iop_v_r) >> (v_n_bits & 63u)); + iop_v_r += ((63u - (v_n_bits & 63u)) >> 3u); + v_n_bits |= 56u; + if ((v_bits >> 63u) != 0u) { + self->private_data.f_mcu_blocks[self->private_impl.f_mcu_current_block][0u] |= v_one_lshift_scan_al; + } + v_bits <<= 1u; + v_n_bits -= 1u; + } while (0); + self->private_impl.f_mcu_current_block += 1u; + } + self->private_impl.f_mcu_current_block = 0u; + } while (0); + label__goto_done__break:; + v_pos = ((uint32_t)(wuffs_base__u64__sat_add((v_r ? v_r->meta.pos : 0), ((uint64_t)(iop_v_r - io0_v_r))))); + if (v_pos > self->private_impl.f_bitstream_wi) { + v_ret = 2u; + } else { + self->private_impl.f_bitstream_ri = v_pos; + } + v_r = o_0_v_r; + iop_v_r = o_0_iop_v_r; + io0_v_r = o_0_io0_v_r; + io1_v_r = o_0_io1_v_r; + io2_v_r = o_0_io2_v_r; + } + self->private_impl.f_bitstream_bits = v_bits; + self->private_impl.f_bitstream_n_bits = v_n_bits; + return v_ret; +} + +#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__JPEG) + +#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__JSON) + +// ---------------- Status Codes Implementations + +const char wuffs_json__error__bad_c0_control_code[] = "#json: bad C0 control code"; +const char wuffs_json__error__bad_utf_8[] = "#json: bad UTF-8"; +const char wuffs_json__error__bad_backslash_escape[] = "#json: bad backslash-escape"; +const char wuffs_json__error__bad_input[] = "#json: bad input"; +const char wuffs_json__error__bad_new_line_in_a_string[] = "#json: bad new-line in a string"; +const char wuffs_json__error__bad_quirk_combination[] = "#json: bad quirk combination"; +const char wuffs_json__error__unsupported_number_length[] = "#json: unsupported number length"; +const char wuffs_json__error__unsupported_recursion_depth[] = "#json: unsupported recursion depth"; +const char wuffs_json__error__internal_error_inconsistent_i_o[] = "#json: internal error: inconsistent I/O"; + +// ---------------- Private Consts + +#define WUFFS_JSON__DECODER_NUMBER_LENGTH_MAX_INCL 99u + +static const uint8_t +WUFFS_JSON__LUT_BACKSLASHES[256] WUFFS_BASE__POTENTIALLY_UNUSED = { + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 3u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 162u, 0u, 0u, 0u, 0u, 5u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 175u, + 7u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 4u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 220u, 0u, 0u, 0u, + 0u, 1u, 136u, 0u, 0u, 2u, 140u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 138u, 0u, + 0u, 0u, 141u, 0u, 137u, 0u, 6u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, +}; + +static const uint8_t +WUFFS_JSON__LUT_QUIRKY_BACKSLASHES_QUIRKS[8] WUFFS_BASE__POTENTIALLY_UNUSED = { + 0u, 1u, 3u, 4u, 5u, 6u, 7u, 10u, +}; + +static const uint8_t +WUFFS_JSON__LUT_QUIRKY_BACKSLASHES_CHARS[8] WUFFS_BASE__POTENTIALLY_UNUSED = { + 0u, 7u, 27u, 10u, 63u, 39u, 11u, 0u, +}; + +static const uint8_t +WUFFS_JSON__LUT_CHARS[256] WUFFS_BASE__POTENTIALLY_UNUSED = { + 128u, 129u, 130u, 131u, 132u, 133u, 134u, 135u, + 136u, 137u, 138u, 139u, 140u, 141u, 142u, 143u, + 144u, 145u, 146u, 147u, 148u, 149u, 150u, 151u, + 152u, 153u, 154u, 155u, 156u, 157u, 158u, 159u, + 0u, 0u, 1u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 2u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, + 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, + 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, + 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, + 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, + 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, + 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, + 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, + 32u, 32u, 3u, 3u, 3u, 3u, 3u, 3u, + 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, + 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, + 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, + 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, + 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, + 5u, 5u, 5u, 5u, 5u, 32u, 32u, 32u, + 32u, 32u, 32u, 32u, 32u, 32u, 32u, 32u, +}; + +#define WUFFS_JSON__CLASS_WHITESPACE 0u + +#define WUFFS_JSON__CLASS_STRING 1u + +#define WUFFS_JSON__CLASS_COMMA 2u + +#define WUFFS_JSON__CLASS_COLON 3u + +#define WUFFS_JSON__CLASS_NUMBER 4u + +#define WUFFS_JSON__CLASS_OPEN_CURLY_BRACE 5u + +#define WUFFS_JSON__CLASS_CLOSE_CURLY_BRACE 6u + +#define WUFFS_JSON__CLASS_OPEN_SQUARE_BRACKET 7u + +#define WUFFS_JSON__CLASS_CLOSE_SQUARE_BRACKET 8u + +#define WUFFS_JSON__CLASS_FALSE 9u + +#define WUFFS_JSON__CLASS_TRUE 10u + +#define WUFFS_JSON__CLASS_NULL_NAN_INF 11u + +#define WUFFS_JSON__CLASS_COMMENT 12u + +#define WUFFS_JSON__EXPECT_VALUE 7858u + +#define WUFFS_JSON__EXPECT_NON_STRING_VALUE 7856u + +#define WUFFS_JSON__EXPECT_STRING 4098u + +#define WUFFS_JSON__EXPECT_COMMA 4100u + +#define WUFFS_JSON__EXPECT_COLON 4104u + +#define WUFFS_JSON__EXPECT_NUMBER 4112u + +#define WUFFS_JSON__EXPECT_CLOSE_CURLY_BRACE 4160u + +#define WUFFS_JSON__EXPECT_CLOSE_SQUARE_BRACKET 4352u + +static const uint8_t +WUFFS_JSON__LUT_CLASSES[256] WUFFS_BASE__POTENTIALLY_UNUSED = { + 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, + 15u, 0u, 0u, 15u, 15u, 0u, 15u, 15u, + 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, + 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, + 0u, 15u, 1u, 15u, 15u, 15u, 15u, 15u, + 15u, 15u, 15u, 11u, 2u, 4u, 15u, 12u, + 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, + 4u, 4u, 3u, 15u, 15u, 15u, 15u, 15u, + 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, + 15u, 11u, 15u, 15u, 15u, 15u, 11u, 15u, + 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, + 15u, 15u, 15u, 7u, 15u, 8u, 15u, 15u, + 15u, 15u, 15u, 15u, 15u, 15u, 9u, 15u, + 15u, 11u, 15u, 15u, 15u, 15u, 11u, 15u, + 15u, 15u, 15u, 15u, 10u, 15u, 15u, 15u, + 15u, 15u, 15u, 5u, 15u, 6u, 15u, 15u, + 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, + 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, + 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, + 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, + 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, + 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, + 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, + 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, + 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, + 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, + 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, + 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, + 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, + 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, + 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, + 15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u, +}; + +static const uint8_t +WUFFS_JSON__LUT_DECIMAL_DIGITS[256] WUFFS_BASE__POTENTIALLY_UNUSED = { + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 128u, 129u, 130u, 131u, 132u, 133u, 134u, 135u, + 136u, 137u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, +}; + +static const uint8_t +WUFFS_JSON__LUT_HEXADECIMAL_DIGITS[256] WUFFS_BASE__POTENTIALLY_UNUSED = { + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 128u, 129u, 130u, 131u, 132u, 133u, 134u, 135u, + 136u, 137u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 138u, 139u, 140u, 141u, 142u, 143u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 138u, 139u, 140u, 141u, 142u, 143u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, +}; + +#define WUFFS_JSON__QUIRKS_BASE 1167656960u + +#define WUFFS_JSON__QUIRKS_COUNT 21u + +// ---------------- Private Initializer Prototypes + +// ---------------- Private Function Prototypes + +WUFFS_BASE__GENERATED_C_CODE +static uint32_t +wuffs_json__decoder__decode_number( + wuffs_json__decoder* self, + wuffs_base__io_buffer* a_src); + +WUFFS_BASE__GENERATED_C_CODE +static uint32_t +wuffs_json__decoder__decode_digits( + wuffs_json__decoder* self, + wuffs_base__io_buffer* a_src, + uint32_t a_n); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_json__decoder__decode_leading( + wuffs_json__decoder* self, + wuffs_base__token_buffer* a_dst, + wuffs_base__io_buffer* a_src); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_json__decoder__decode_comment( + wuffs_json__decoder* self, + wuffs_base__token_buffer* a_dst, + wuffs_base__io_buffer* a_src); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_json__decoder__decode_inf_nan( + wuffs_json__decoder* self, + wuffs_base__token_buffer* a_dst, + wuffs_base__io_buffer* a_src); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_json__decoder__decode_trailer( + wuffs_json__decoder* self, + wuffs_base__token_buffer* a_dst, + wuffs_base__io_buffer* a_src); + +// ---------------- VTables + +const wuffs_base__token_decoder__func_ptrs +wuffs_json__decoder__func_ptrs_for__wuffs_base__token_decoder = { + (wuffs_base__status(*)(void*, + wuffs_base__token_buffer*, + wuffs_base__io_buffer*, + wuffs_base__slice_u8))(&wuffs_json__decoder__decode_tokens), + (uint64_t(*)(const void*, + uint32_t))(&wuffs_json__decoder__get_quirk), + (wuffs_base__status(*)(void*, + uint32_t, + uint64_t))(&wuffs_json__decoder__set_quirk), + (wuffs_base__range_ii_u64(*)(const void*))(&wuffs_json__decoder__workbuf_len), +}; + +// ---------------- Initializer Implementations + +wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT +wuffs_json__decoder__initialize( + wuffs_json__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__token_decoder.vtable_name = + wuffs_base__token_decoder__vtable_name; + self->private_impl.vtable_for__wuffs_base__token_decoder.function_pointers = + (const void*)(&wuffs_json__decoder__func_ptrs_for__wuffs_base__token_decoder); + return wuffs_base__make_status(NULL); +} + +wuffs_json__decoder* +wuffs_json__decoder__alloc(void) { + wuffs_json__decoder* x = + (wuffs_json__decoder*)(calloc(1, sizeof(wuffs_json__decoder))); + if (!x) { + return NULL; + } + if (wuffs_json__decoder__initialize( + x, sizeof(wuffs_json__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) { + free(x); + return NULL; + } + return x; +} + +size_t +sizeof__wuffs_json__decoder(void) { + return sizeof(wuffs_json__decoder); +} + +// ---------------- Function Implementations + +// -------- func json.decoder.get_quirk + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC uint64_t +wuffs_json__decoder__get_quirk( + const wuffs_json__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; + } + + uint32_t v_key = 0; + + if (a_key >= 1167656960u) { + v_key = (a_key - 1167656960u); + if (v_key < 21u) { + if (self->private_impl.f_quirks[v_key]) { + return 1u; + } + } + } + return 0u; +} + +// -------- func json.decoder.set_quirk + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_json__decoder__set_quirk( + wuffs_json__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); + } + + if (a_key >= 1167656960u) { + a_key -= 1167656960u; + if (a_key < 21u) { + self->private_impl.f_quirks[a_key] = (a_value > 0u); + return wuffs_base__make_status(NULL); + } + } + return wuffs_base__make_status(wuffs_base__error__unsupported_option); +} + +// -------- func json.decoder.workbuf_len + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 +wuffs_json__decoder__workbuf_len( + const wuffs_json__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__empty_range_ii_u64(); +} + +// -------- func json.decoder.decode_tokens + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_json__decoder__decode_tokens( + wuffs_json__decoder* self, + wuffs_base__token_buffer* a_dst, + wuffs_base__io_buffer* a_src, + wuffs_base__slice_u8 a_workbuf) { + 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 != 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); + + uint32_t v_vminor = 0; + uint32_t v_number_length = 0; + uint32_t v_number_status = 0; + uint32_t v_string_length = 0; + uint32_t v_whitespace_length = 0; + uint32_t v_depth = 0; + uint32_t v_stack_byte = 0; + uint32_t v_stack_bit = 0; + uint32_t v_match = 0; + uint32_t v_c32 = 0; + uint8_t v_c8 = 0; + uint8_t v_backslash = 0; + uint8_t v_char = 0; + uint8_t v_class = 0; + uint32_t v_multi_byte_utf8 = 0; + uint8_t v_backslash_x_ok = 0; + uint8_t v_backslash_x_value = 0; + uint32_t v_backslash_x_string = 0; + uint8_t v_uni4_ok = 0; + uint64_t v_uni4_string = 0; + uint32_t v_uni4_value = 0; + uint32_t v_uni4_high_surrogate = 0; + uint8_t v_uni8_ok = 0; + uint64_t v_uni8_string = 0; + uint32_t v_uni8_value = 0; + uint32_t v_expect = 0; + uint32_t v_expect_after_value = 0; + + wuffs_base__token* iop_a_dst = NULL; + wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + wuffs_base__token* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + wuffs_base__token* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + if (a_dst && a_dst->data.ptr) { + io0_a_dst = a_dst->data.ptr; + io1_a_dst = io0_a_dst + a_dst->meta.wi; + iop_a_dst = io1_a_dst; + io2_a_dst = io0_a_dst + a_dst->data.len; + if (a_dst->meta.closed) { + io2_a_dst = iop_a_dst; + } + } + 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_decode_tokens; + if (coro_susp_point) { + v_depth = self->private_data.s_decode_tokens.v_depth; + v_expect = self->private_data.s_decode_tokens.v_expect; + v_expect_after_value = self->private_data.s_decode_tokens.v_expect_after_value; + } + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + + if (self->private_impl.f_end_of_data) { + status = wuffs_base__make_status(wuffs_base__note__end_of_data); + goto ok; + } + if (self->private_impl.f_quirks[18u]) { + if (self->private_impl.f_quirks[11u] || self->private_impl.f_quirks[12u] || self->private_impl.f_quirks[17u]) { + status = wuffs_base__make_status(wuffs_json__error__bad_quirk_combination); + goto exit; + } + } + if (self->private_impl.f_quirks[15u] || self->private_impl.f_quirks[16u]) { + if (a_dst) { + a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr)); + } + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + status = wuffs_json__decoder__decode_leading(self, a_dst, a_src); + if (a_dst) { + iop_a_dst = a_dst->data.ptr + a_dst->meta.wi; + } + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } + } + v_expect = 7858u; + label__outer__continue:; + while (true) { + while (true) { + if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0u) { + status = wuffs_base__make_status(wuffs_base__suspension__short_write); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2); + goto label__outer__continue; + } + v_whitespace_length = 0u; + v_c8 = 0u; + v_class = 0u; + while (true) { + if (((uint64_t)(io2_a_src - iop_a_src)) <= 0u) { + if (v_whitespace_length > 0u) { + *iop_a_dst++ = wuffs_base__make_token( + (((uint64_t)(0u)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | + (((uint64_t)(v_whitespace_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); + v_whitespace_length = 0u; + } + if (a_src && a_src->meta.closed) { + status = wuffs_base__make_status(wuffs_json__error__bad_input); + goto exit; + } + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3); + goto label__outer__continue; + } + v_c8 = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); + v_class = WUFFS_JSON__LUT_CLASSES[v_c8]; + if (v_class != 0u) { + break; + } + iop_a_src += 1u; + if (v_whitespace_length >= 65534u) { + *iop_a_dst++ = wuffs_base__make_token( + (((uint64_t)(0u)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | + (((uint64_t)(65535u)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); + v_whitespace_length = 0u; + goto label__outer__continue; + } + v_whitespace_length += 1u; + } + if (v_whitespace_length > 0u) { + *iop_a_dst++ = wuffs_base__make_token( + (((uint64_t)(0u)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | + (((uint64_t)(v_whitespace_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); + v_whitespace_length = 0u; + if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0u) { + goto label__outer__continue; + } + } + if (0u == (v_expect & (((uint32_t)(1u)) << v_class))) { + status = wuffs_base__make_status(wuffs_json__error__bad_input); + goto exit; + } + if (v_class == 1u) { + *iop_a_dst++ = wuffs_base__make_token( + (((uint64_t)(4194579u)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | + (((uint64_t)(1u)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) | + (((uint64_t)(1u)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); + iop_a_src += 1u; + label__string_loop_outer__continue:; + while (true) { + if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0u) { + status = wuffs_base__make_status(wuffs_base__suspension__short_write); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4); + continue; + } + v_string_length = 0u; + while (true) { + if (((uint64_t)(io2_a_src - iop_a_src)) <= 0u) { + if (v_string_length > 0u) { + *iop_a_dst++ = wuffs_base__make_token( + (((uint64_t)(4194819u)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | + (((uint64_t)(1u)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) | + (((uint64_t)(v_string_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); + v_string_length = 0u; + } + if (a_src && a_src->meta.closed) { + status = wuffs_base__make_status(wuffs_json__error__bad_input); + goto exit; + } + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5); + goto label__string_loop_outer__continue; + } + while (((uint64_t)(io2_a_src - iop_a_src)) > 4u) { + v_c32 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src); + if (0u != (WUFFS_JSON__LUT_CHARS[(255u & (v_c32 >> 0u))] | + WUFFS_JSON__LUT_CHARS[(255u & (v_c32 >> 8u))] | + WUFFS_JSON__LUT_CHARS[(255u & (v_c32 >> 16u))] | + WUFFS_JSON__LUT_CHARS[(255u & (v_c32 >> 24u))])) { + break; + } + iop_a_src += 4u; + if (v_string_length > 65527u) { + *iop_a_dst++ = wuffs_base__make_token( + (((uint64_t)(4194819u)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | + (((uint64_t)(1u)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) | + (((uint64_t)((v_string_length + 4u))) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); + v_string_length = 0u; + goto label__string_loop_outer__continue; + } + v_string_length += 4u; + } + v_c8 = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); + v_char = WUFFS_JSON__LUT_CHARS[v_c8]; + if (v_char == 0u) { + iop_a_src += 1u; + if (v_string_length >= 65531u) { + *iop_a_dst++ = wuffs_base__make_token( + (((uint64_t)(4194819u)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | + (((uint64_t)(1u)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) | + (((uint64_t)(65532u)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); + v_string_length = 0u; + goto label__string_loop_outer__continue; + } + v_string_length += 1u; + continue; + } else if (v_char == 1u) { + if (v_string_length != 0u) { + *iop_a_dst++ = wuffs_base__make_token( + (((uint64_t)(4194819u)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | + (((uint64_t)(1u)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) | + (((uint64_t)(v_string_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); + v_string_length = 0u; + } + goto label__string_loop_outer__break; + } else if (v_char == 2u) { + if (v_string_length > 0u) { + *iop_a_dst++ = wuffs_base__make_token( + (((uint64_t)(4194819u)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | + (((uint64_t)(1u)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) | + (((uint64_t)(v_string_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); + v_string_length = 0u; + if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0u) { + goto label__string_loop_outer__continue; + } + } + if (((uint64_t)(io2_a_src - iop_a_src)) < 2u) { + if (a_src && a_src->meta.closed) { + status = wuffs_base__make_status(wuffs_json__error__bad_backslash_escape); + goto exit; + } + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6); + goto label__string_loop_outer__continue; + } + v_c8 = ((uint8_t)(((uint16_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src) >> 8u)))); + v_backslash = WUFFS_JSON__LUT_BACKSLASHES[v_c8]; + if (((uint8_t)(v_backslash & 128u)) != 0u) { + iop_a_src += 2u; + *iop_a_dst++ = wuffs_base__make_token( + (((uint64_t)((6291456u | ((uint32_t)(((uint8_t)(v_backslash & 127u))))))) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | + (((uint64_t)(1u)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) | + (((uint64_t)(2u)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); + goto label__string_loop_outer__continue; + } else if (v_backslash != 0u) { + if (self->private_impl.f_quirks[WUFFS_JSON__LUT_QUIRKY_BACKSLASHES_QUIRKS[((uint8_t)(v_backslash & 7u))]]) { + iop_a_src += 2u; + *iop_a_dst++ = wuffs_base__make_token( + (((uint64_t)((6291456u | ((uint32_t)(WUFFS_JSON__LUT_QUIRKY_BACKSLASHES_CHARS[((uint8_t)(v_backslash & 7u))]))))) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | + (((uint64_t)(1u)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) | + (((uint64_t)(2u)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); + goto label__string_loop_outer__continue; + } + } else if (v_c8 == 117u) { + if (((uint64_t)(io2_a_src - iop_a_src)) < 6u) { + if (a_src && a_src->meta.closed) { status = wuffs_base__make_status(wuffs_json__error__bad_backslash_escape); goto exit; } @@ -53526,7 +57186,7 @@ WUFFS_LZMA__CLAMP_NO_MORE_THAN_3[8] WUFFS_BASE__POTENTIALLY_UNUSED = { 0u, 1u, 2u, 3u, 3u, 3u, 3u, 3u, }; -#define WUFFS_LZMA__QUIRKS_BASE 1348001792u +#define WUFFS_LZMA__QUIRKS_BASE 1290294272u // ---------------- Private Initializer Prototypes @@ -55693,11 +59353,11 @@ wuffs_lzma__decoder__get_quirk( return 0; } - if (a_key == 1348001792u) { + if (a_key == 1290294272u) { if (self->private_impl.f_allow_non_zero_initial_byte) { return 1u; } - } else if (a_key == 1348001793u) { + } else if (a_key == 1290294273u) { return ((uint64_t)(self->private_impl.f_format_extension)); } return 0u; @@ -55724,9 +59384,9 @@ wuffs_lzma__decoder__set_quirk( uint32_t v_v = 0; uint32_t v_n = 0; - if (a_key == 1348001792u) { + if (a_key == 1290294272u) { self->private_impl.f_allow_non_zero_initial_byte = (a_value > 0u); - } else if (a_key == 1348001793u) { + } else if (a_key == 1290294273u) { if (a_value == 0u) { self->private_impl.f_format_extension = 0u; return wuffs_base__make_status(NULL); @@ -57113,7 +60773,7 @@ wuffs_lzip__decoder__do_transform_io( uint8_t t_1 = *iop_a_src++; v_c8 = t_1; } - v_status = wuffs_lzma__decoder__set_quirk(&self->private_data.f_lzma, 1348001793u, (1u | (((uint64_t)(v_c8)) << 8u))); + v_status = wuffs_lzma__decoder__set_quirk(&self->private_data.f_lzma, 1290294273u, (1u | (((uint64_t)(v_c8)) << 8u))); if ( ! wuffs_base__status__is_ok(&v_status)) { if (v_status.repr == wuffs_base__error__bad_argument) { status = wuffs_base__make_status(wuffs_lzip__error__bad_header); @@ -57130,7 +60790,7 @@ wuffs_lzip__decoder__do_transform_io( } self->private_impl.f_ssize_have = 0u; self->private_impl.f_dsize_have = 0u; - wuffs_lzma__decoder__set_quirk(&self->private_data.f_lzma, 1348001792u, 1u); + wuffs_lzma__decoder__set_quirk(&self->private_data.f_lzma, 1290294272u, 1u); while (true) { v_dmark = ((uint64_t)(iop_a_dst - io0_a_dst)); v_smark = ((uint64_t)(iop_a_src - io0_a_src)); @@ -57317,7 +60977,7 @@ const char wuffs_lzw__error__internal_error_inconsistent_i_o[] = "#lzw: internal // ---------------- Private Consts -#define WUFFS_LZW__QUIRKS_BASE 1348378624u +#define WUFFS_LZW__QUIRKS_BASE 1290672128u // ---------------- Private Initializer Prototypes @@ -57438,7 +61098,7 @@ wuffs_lzw__decoder__get_quirk( return 0; } - if (a_key == 1348378624u) { + if (a_key == 1290672128u) { return ((uint64_t)(self->private_impl.f_pending_literal_width_plus_one)); } return 0u; @@ -57462,7 +61122,7 @@ wuffs_lzw__decoder__set_quirk( : wuffs_base__error__initialize_not_called); } - if (a_key == 1348378624u) { + if (a_key == 1290672128u) { if (a_value > 9u) { return wuffs_base__make_status(wuffs_base__error__bad_argument); } @@ -60098,7 +63758,7 @@ const char wuffs_zlib__error__truncated_input[] = "#zlib: truncated input"; // ---------------- Private Consts -#define WUFFS_ZLIB__QUIRKS_BASE 2113790976u +#define WUFFS_ZLIB__QUIRKS_BASE 2056083456u #define WUFFS_ZLIB__QUIRKS_COUNT 1u @@ -60283,8 +63943,8 @@ wuffs_zlib__decoder__get_quirk( if ((a_key == 1u) && self->private_impl.f_ignore_checksum) { return 1u; - } else if (a_key >= 2113790976u) { - v_key = (a_key - 2113790976u); + } else if (a_key >= 2056083456u) { + v_key = (a_key - 2056083456u); if (v_key < 1u) { if (self->private_impl.f_quirks[v_key]) { return 1u; @@ -60318,8 +63978,8 @@ wuffs_zlib__decoder__set_quirk( } else if (a_key == 1u) { self->private_impl.f_ignore_checksum = (a_value > 0u); return wuffs_base__make_status(NULL); - } else if (a_key >= 2113790976u) { - a_key -= 2113790976u; + } else if (a_key >= 2056083456u) { + a_key -= 2056083456u; if (a_key < 1u) { self->private_impl.f_quirks[a_key] = (a_value > 0u); return wuffs_base__make_status(NULL); @@ -60792,417 +64452,1455 @@ wuffs_png__decoder__filter_4_distance_4_arm_neon( wuffs_base__slice_u8 a_prev); #endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON) -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__filter_1( - wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr); - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__filter_1__choosy_default( - wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr); - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__filter_1_distance_3_fallback( - wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr); - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__filter_1_distance_4_fallback( - wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr); - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__filter_2( - wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr, - wuffs_base__slice_u8 a_prev); +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_png__decoder__filter_1( + wuffs_png__decoder* self, + wuffs_base__slice_u8 a_curr); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_png__decoder__filter_1__choosy_default( + wuffs_png__decoder* self, + wuffs_base__slice_u8 a_curr); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_png__decoder__filter_1_distance_3_fallback( + wuffs_png__decoder* self, + wuffs_base__slice_u8 a_curr); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_png__decoder__filter_1_distance_4_fallback( + wuffs_png__decoder* self, + wuffs_base__slice_u8 a_curr); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_png__decoder__filter_2( + wuffs_png__decoder* self, + wuffs_base__slice_u8 a_curr, + wuffs_base__slice_u8 a_prev); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_png__decoder__filter_3( + wuffs_png__decoder* self, + wuffs_base__slice_u8 a_curr, + wuffs_base__slice_u8 a_prev); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_png__decoder__filter_3__choosy_default( + wuffs_png__decoder* self, + wuffs_base__slice_u8 a_curr, + wuffs_base__slice_u8 a_prev); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_png__decoder__filter_3_distance_3_fallback( + wuffs_png__decoder* self, + wuffs_base__slice_u8 a_curr, + wuffs_base__slice_u8 a_prev); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_png__decoder__filter_3_distance_4_fallback( + wuffs_png__decoder* self, + wuffs_base__slice_u8 a_curr, + wuffs_base__slice_u8 a_prev); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_png__decoder__filter_4( + wuffs_png__decoder* self, + wuffs_base__slice_u8 a_curr, + wuffs_base__slice_u8 a_prev); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_png__decoder__filter_4__choosy_default( + wuffs_png__decoder* self, + wuffs_base__slice_u8 a_curr, + wuffs_base__slice_u8 a_prev); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_png__decoder__filter_4_distance_3_fallback( + wuffs_png__decoder* self, + wuffs_base__slice_u8 a_curr, + wuffs_base__slice_u8 a_prev); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_png__decoder__filter_4_distance_4_fallback( + wuffs_png__decoder* self, + wuffs_base__slice_u8 a_curr, + wuffs_base__slice_u8 a_prev); + +#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_png__decoder__filter_1_distance_4_x86_sse42( + wuffs_png__decoder* self, + wuffs_base__slice_u8 a_curr); +#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) + +#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_png__decoder__filter_3_distance_4_x86_sse42( + wuffs_png__decoder* self, + wuffs_base__slice_u8 a_curr, + wuffs_base__slice_u8 a_prev); +#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) + +#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_png__decoder__filter_4_distance_3_x86_sse42( + wuffs_png__decoder* self, + wuffs_base__slice_u8 a_curr, + wuffs_base__slice_u8 a_prev); +#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) + +#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_png__decoder__filter_4_distance_4_x86_sse42( + wuffs_png__decoder* self, + wuffs_base__slice_u8 a_curr, + wuffs_base__slice_u8 a_prev); +#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_png__decoder__do_decode_image_config( + wuffs_png__decoder* self, + wuffs_base__image_config* a_dst, + wuffs_base__io_buffer* a_src); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_png__decoder__decode_ihdr( + wuffs_png__decoder* self, + wuffs_base__io_buffer* a_src); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_png__decoder__assign_filter_distance( + wuffs_png__decoder* self); + +WUFFS_BASE__GENERATED_C_CODE +static uint64_t +wuffs_png__decoder__calculate_bytes_per_row( + const wuffs_png__decoder* self, + uint32_t a_width); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_png__decoder__choose_filter_implementations( + wuffs_png__decoder* self); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_png__decoder__decode_other_chunk( + wuffs_png__decoder* self, + wuffs_base__io_buffer* a_src, + bool a_framy); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_png__decoder__decode_actl( + wuffs_png__decoder* self, + wuffs_base__io_buffer* a_src); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_png__decoder__decode_chrm( + wuffs_png__decoder* self, + wuffs_base__io_buffer* a_src); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_png__decoder__decode_exif( + wuffs_png__decoder* self, + wuffs_base__io_buffer* a_src); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_png__decoder__decode_fctl( + wuffs_png__decoder* self, + wuffs_base__io_buffer* a_src); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_png__decoder__decode_gama( + wuffs_png__decoder* self, + wuffs_base__io_buffer* a_src); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_png__decoder__decode_iccp( + wuffs_png__decoder* self, + wuffs_base__io_buffer* a_src); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_png__decoder__decode_plte( + wuffs_png__decoder* self, + wuffs_base__io_buffer* a_src); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_png__decoder__decode_srgb( + wuffs_png__decoder* self, + wuffs_base__io_buffer* a_src); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_png__decoder__decode_trns( + wuffs_png__decoder* self, + wuffs_base__io_buffer* a_src); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_png__decoder__do_decode_frame_config( + wuffs_png__decoder* self, + wuffs_base__frame_config* a_dst, + wuffs_base__io_buffer* a_src); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_png__decoder__skip_frame( + wuffs_png__decoder* self, + wuffs_base__io_buffer* a_src); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_png__decoder__do_decode_frame( + wuffs_png__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_png__decoder__decode_pass( + wuffs_png__decoder* self, + wuffs_base__io_buffer* a_src, + wuffs_base__slice_u8 a_workbuf); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_png__decoder__do_tell_me_more( + wuffs_png__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 +static wuffs_base__status +wuffs_png__decoder__filter_and_swizzle( + wuffs_png__decoder* self, + wuffs_base__pixel_buffer* a_dst, + wuffs_base__slice_u8 a_workbuf); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_png__decoder__filter_and_swizzle__choosy_default( + wuffs_png__decoder* self, + wuffs_base__pixel_buffer* a_dst, + wuffs_base__slice_u8 a_workbuf); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_png__decoder__filter_and_swizzle_tricky( + wuffs_png__decoder* self, + wuffs_base__pixel_buffer* a_dst, + wuffs_base__slice_u8 a_workbuf); + +// ---------------- VTables + +const wuffs_base__image_decoder__func_ptrs +wuffs_png__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_png__decoder__decode_frame), + (wuffs_base__status(*)(void*, + wuffs_base__frame_config*, + wuffs_base__io_buffer*))(&wuffs_png__decoder__decode_frame_config), + (wuffs_base__status(*)(void*, + wuffs_base__image_config*, + wuffs_base__io_buffer*))(&wuffs_png__decoder__decode_image_config), + (wuffs_base__rect_ie_u32(*)(const void*))(&wuffs_png__decoder__frame_dirty_rect), + (uint64_t(*)(const void*, + uint32_t))(&wuffs_png__decoder__get_quirk), + (uint32_t(*)(const void*))(&wuffs_png__decoder__num_animation_loops), + (uint64_t(*)(const void*))(&wuffs_png__decoder__num_decoded_frame_configs), + (uint64_t(*)(const void*))(&wuffs_png__decoder__num_decoded_frames), + (wuffs_base__status(*)(void*, + uint64_t, + uint64_t))(&wuffs_png__decoder__restart_frame), + (wuffs_base__status(*)(void*, + uint32_t, + uint64_t))(&wuffs_png__decoder__set_quirk), + (wuffs_base__empty_struct(*)(void*, + uint32_t, + bool))(&wuffs_png__decoder__set_report_metadata), + (wuffs_base__status(*)(void*, + wuffs_base__io_buffer*, + wuffs_base__more_information*, + wuffs_base__io_buffer*))(&wuffs_png__decoder__tell_me_more), + (wuffs_base__range_ii_u64(*)(const void*))(&wuffs_png__decoder__workbuf_len), +}; + +// ---------------- Initializer Implementations + +wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT +wuffs_png__decoder__initialize( + wuffs_png__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.choosy_filter_1 = &wuffs_png__decoder__filter_1__choosy_default; + self->private_impl.choosy_filter_3 = &wuffs_png__decoder__filter_3__choosy_default; + self->private_impl.choosy_filter_4 = &wuffs_png__decoder__filter_4__choosy_default; + self->private_impl.choosy_filter_and_swizzle = &wuffs_png__decoder__filter_and_swizzle__choosy_default; + + { + wuffs_base__status z = wuffs_crc32__ieee_hasher__initialize( + &self->private_data.f_crc32, sizeof(self->private_data.f_crc32), WUFFS_VERSION, options); + if (z.repr) { + return z; + } + } + { + wuffs_base__status z = wuffs_zlib__decoder__initialize( + &self->private_data.f_zlib, sizeof(self->private_data.f_zlib), WUFFS_VERSION, options); + if (z.repr) { + return z; + } + } + 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_png__decoder__func_ptrs_for__wuffs_base__image_decoder); + return wuffs_base__make_status(NULL); +} + +wuffs_png__decoder* +wuffs_png__decoder__alloc(void) { + wuffs_png__decoder* x = + (wuffs_png__decoder*)(calloc(1, sizeof(wuffs_png__decoder))); + if (!x) { + return NULL; + } + if (wuffs_png__decoder__initialize( + x, sizeof(wuffs_png__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) { + free(x); + return NULL; + } + return x; +} + +size_t +sizeof__wuffs_png__decoder(void) { + return sizeof(wuffs_png__decoder); +} + +// ---------------- Function Implementations + +// ‼ WUFFS MULTI-FILE SECTION +arm_neon +// -------- func png.decoder.filter_1_distance_4_arm_neon + +#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON) +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_png__decoder__filter_1_distance_4_arm_neon( + wuffs_png__decoder* self, + wuffs_base__slice_u8 a_curr) { + wuffs_base__slice_u8 v_curr = {0}; + uint8x8_t v_fa = {0}; + uint8x8_t v_fx = {0}; + + { + wuffs_base__slice_u8 i_slice_curr = a_curr; + v_curr.ptr = i_slice_curr.ptr; + v_curr.len = 4; + const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 8) * 8)); + while (v_curr.ptr < i_end0_curr) { + v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_fx = vadd_u8(v_fx, v_fa); + wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); + v_fa = v_fx; + v_curr.ptr += 4; + v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_fx = vadd_u8(v_fx, v_fa); + wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); + v_fa = v_fx; + v_curr.ptr += 4; + } + v_curr.len = 4; + const uint8_t* i_end1_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 4) * 4)); + while (v_curr.ptr < i_end1_curr) { + v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_fx = vadd_u8(v_fx, v_fa); + wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); + v_fa = v_fx; + v_curr.ptr += 4; + } + v_curr.len = 0; + } + return wuffs_base__make_empty_struct(); +} +#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON) +// ‼ WUFFS MULTI-FILE SECTION -arm_neon + +// ‼ WUFFS MULTI-FILE SECTION +arm_neon +// -------- func png.decoder.filter_3_distance_4_arm_neon +#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON) WUFFS_BASE__GENERATED_C_CODE static wuffs_base__empty_struct -wuffs_png__decoder__filter_3( +wuffs_png__decoder__filter_3_distance_4_arm_neon( wuffs_png__decoder* self, wuffs_base__slice_u8 a_curr, - wuffs_base__slice_u8 a_prev); + wuffs_base__slice_u8 a_prev) { + wuffs_base__slice_u8 v_curr = {0}; + wuffs_base__slice_u8 v_prev = {0}; + uint8x8_t v_fa = {0}; + uint8x8_t v_fb = {0}; + uint8x8_t v_fx = {0}; -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__filter_3__choosy_default( - wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr, - wuffs_base__slice_u8 a_prev); + if (((uint64_t)(a_prev.len)) == 0u) { + { + wuffs_base__slice_u8 i_slice_curr = a_curr; + v_curr.ptr = i_slice_curr.ptr; + v_curr.len = 4; + const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 8) * 8)); + while (v_curr.ptr < i_end0_curr) { + v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_fx = vadd_u8(v_fx, vhadd_u8(v_fa, v_fb)); + wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); + v_fa = v_fx; + v_curr.ptr += 4; + v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_fx = vadd_u8(v_fx, vhadd_u8(v_fa, v_fb)); + wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); + v_fa = v_fx; + v_curr.ptr += 4; + } + v_curr.len = 4; + const uint8_t* i_end1_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 4) * 4)); + while (v_curr.ptr < i_end1_curr) { + v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_fx = vadd_u8(v_fx, vhadd_u8(v_fa, v_fb)); + wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); + v_fa = v_fx; + v_curr.ptr += 4; + } + v_curr.len = 0; + } + } else { + { + wuffs_base__slice_u8 i_slice_curr = a_curr; + v_curr.ptr = i_slice_curr.ptr; + wuffs_base__slice_u8 i_slice_prev = a_prev; + v_prev.ptr = i_slice_prev.ptr; + i_slice_curr.len = ((size_t)(wuffs_base__u64__min(i_slice_curr.len, i_slice_prev.len))); + v_curr.len = 4; + v_prev.len = 4; + const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 8) * 8)); + while (v_curr.ptr < i_end0_curr) { + v_fb = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); + v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_fx = vadd_u8(v_fx, vhadd_u8(v_fa, v_fb)); + wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); + v_fa = v_fx; + v_curr.ptr += 4; + v_prev.ptr += 4; + v_fb = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); + v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_fx = vadd_u8(v_fx, vhadd_u8(v_fa, v_fb)); + wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); + v_fa = v_fx; + v_curr.ptr += 4; + v_prev.ptr += 4; + } + v_curr.len = 4; + v_prev.len = 4; + const uint8_t* i_end1_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 4) * 4)); + while (v_curr.ptr < i_end1_curr) { + v_fb = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); + v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_fx = vadd_u8(v_fx, vhadd_u8(v_fa, v_fb)); + wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); + v_fa = v_fx; + v_curr.ptr += 4; + v_prev.ptr += 4; + } + v_curr.len = 0; + v_prev.len = 0; + } + } + return wuffs_base__make_empty_struct(); +} +#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON) +// ‼ WUFFS MULTI-FILE SECTION -arm_neon -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__filter_3_distance_3_fallback( - wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr, - wuffs_base__slice_u8 a_prev); +// ‼ WUFFS MULTI-FILE SECTION +arm_neon +// -------- func png.decoder.filter_4_distance_3_arm_neon +#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON) WUFFS_BASE__GENERATED_C_CODE static wuffs_base__empty_struct -wuffs_png__decoder__filter_3_distance_4_fallback( +wuffs_png__decoder__filter_4_distance_3_arm_neon( wuffs_png__decoder* self, wuffs_base__slice_u8 a_curr, - wuffs_base__slice_u8 a_prev); + wuffs_base__slice_u8 a_prev) { + wuffs_base__slice_u8 v_curr = {0}; + wuffs_base__slice_u8 v_prev = {0}; + uint8x8_t v_fa = {0}; + uint8x8_t v_fb = {0}; + uint8x8_t v_fc = {0}; + uint8x8_t v_fx = {0}; + uint16x8_t v_fafb = {0}; + uint16x8_t v_fcfc = {0}; + uint16x8_t v_pa = {0}; + uint16x8_t v_pb = {0}; + uint16x8_t v_pc = {0}; + uint16x8_t v_cmpab = {0}; + uint16x8_t v_cmpac = {0}; + uint8x8_t v_picka = {0}; + uint8x8_t v_pickb = {0}; -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__filter_4( - wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr, - wuffs_base__slice_u8 a_prev); + { + wuffs_base__slice_u8 i_slice_curr = a_curr; + v_curr.ptr = i_slice_curr.ptr; + wuffs_base__slice_u8 i_slice_prev = a_prev; + v_prev.ptr = i_slice_prev.ptr; + i_slice_curr.len = ((size_t)(wuffs_base__u64__min(i_slice_curr.len, i_slice_prev.len))); + v_curr.len = 4; + v_prev.len = 4; + const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, wuffs_private_impl__iterate_total_advance((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)), 7, 6)); + while (v_curr.ptr < i_end0_curr) { + v_fb = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); + v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_fafb = vaddl_u8(v_fa, v_fb); + v_fcfc = vaddl_u8(v_fc, v_fc); + v_pa = vabdl_u8(v_fb, v_fc); + v_pb = vabdl_u8(v_fa, v_fc); + v_pc = vabdq_u16(v_fafb, v_fcfc); + v_cmpab = vcleq_u16(v_pa, v_pb); + v_cmpac = vcleq_u16(v_pa, v_pc); + v_picka = vmovn_u16(vandq_u16(v_cmpab, v_cmpac)); + v_pickb = vmovn_u16(vcleq_u16(v_pb, v_pc)); + v_fx = vadd_u8(v_fx, vbsl_u8(v_picka, v_fa, vbsl_u8(v_pickb, v_fb, v_fc))); + wuffs_base__poke_u24le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); + v_fc = v_fb; + v_fa = v_fx; + v_curr.ptr += 3; + v_prev.ptr += 3; + v_fb = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); + v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_fafb = vaddl_u8(v_fa, v_fb); + v_fcfc = vaddl_u8(v_fc, v_fc); + v_pa = vabdl_u8(v_fb, v_fc); + v_pb = vabdl_u8(v_fa, v_fc); + v_pc = vabdq_u16(v_fafb, v_fcfc); + v_cmpab = vcleq_u16(v_pa, v_pb); + v_cmpac = vcleq_u16(v_pa, v_pc); + v_picka = vmovn_u16(vandq_u16(v_cmpab, v_cmpac)); + v_pickb = vmovn_u16(vcleq_u16(v_pb, v_pc)); + v_fx = vadd_u8(v_fx, vbsl_u8(v_picka, v_fa, vbsl_u8(v_pickb, v_fb, v_fc))); + wuffs_base__poke_u24le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); + v_fc = v_fb; + v_fa = v_fx; + v_curr.ptr += 3; + v_prev.ptr += 3; + } + v_curr.len = 4; + v_prev.len = 4; + const uint8_t* i_end1_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, wuffs_private_impl__iterate_total_advance((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)), 4, 3)); + while (v_curr.ptr < i_end1_curr) { + v_fb = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); + v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_fafb = vaddl_u8(v_fa, v_fb); + v_fcfc = vaddl_u8(v_fc, v_fc); + v_pa = vabdl_u8(v_fb, v_fc); + v_pb = vabdl_u8(v_fa, v_fc); + v_pc = vabdq_u16(v_fafb, v_fcfc); + v_cmpab = vcleq_u16(v_pa, v_pb); + v_cmpac = vcleq_u16(v_pa, v_pc); + v_picka = vmovn_u16(vandq_u16(v_cmpab, v_cmpac)); + v_pickb = vmovn_u16(vcleq_u16(v_pb, v_pc)); + v_fx = vadd_u8(v_fx, vbsl_u8(v_picka, v_fa, vbsl_u8(v_pickb, v_fb, v_fc))); + wuffs_base__poke_u24le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); + v_fc = v_fb; + v_fa = v_fx; + v_curr.ptr += 3; + v_prev.ptr += 3; + } + v_curr.len = 3; + v_prev.len = 3; + const uint8_t* i_end2_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 3) * 3)); + while (v_curr.ptr < i_end2_curr) { + v_fb = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u24le__no_bounds_check(v_prev.ptr))); + v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u24le__no_bounds_check(v_curr.ptr))); + v_fafb = vaddl_u8(v_fa, v_fb); + v_fcfc = vaddl_u8(v_fc, v_fc); + v_pa = vabdl_u8(v_fb, v_fc); + v_pb = vabdl_u8(v_fa, v_fc); + v_pc = vabdq_u16(v_fafb, v_fcfc); + v_cmpab = vcleq_u16(v_pa, v_pb); + v_cmpac = vcleq_u16(v_pa, v_pc); + v_picka = vmovn_u16(vandq_u16(v_cmpab, v_cmpac)); + v_pickb = vmovn_u16(vcleq_u16(v_pb, v_pc)); + v_fx = vadd_u8(v_fx, vbsl_u8(v_picka, v_fa, vbsl_u8(v_pickb, v_fb, v_fc))); + wuffs_base__poke_u24le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); + v_curr.ptr += 3; + v_prev.ptr += 3; + } + v_curr.len = 0; + v_prev.len = 0; + } + return wuffs_base__make_empty_struct(); +} +#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON) +// ‼ WUFFS MULTI-FILE SECTION -arm_neon -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__filter_4__choosy_default( - wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr, - wuffs_base__slice_u8 a_prev); +// ‼ WUFFS MULTI-FILE SECTION +arm_neon +// -------- func png.decoder.filter_4_distance_4_arm_neon +#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON) WUFFS_BASE__GENERATED_C_CODE static wuffs_base__empty_struct -wuffs_png__decoder__filter_4_distance_3_fallback( +wuffs_png__decoder__filter_4_distance_4_arm_neon( wuffs_png__decoder* self, wuffs_base__slice_u8 a_curr, - wuffs_base__slice_u8 a_prev); + wuffs_base__slice_u8 a_prev) { + wuffs_base__slice_u8 v_curr = {0}; + wuffs_base__slice_u8 v_prev = {0}; + uint8x8_t v_fa = {0}; + uint8x8_t v_fb = {0}; + uint8x8_t v_fc = {0}; + uint8x8_t v_fx = {0}; + uint16x8_t v_fafb = {0}; + uint16x8_t v_fcfc = {0}; + uint16x8_t v_pa = {0}; + uint16x8_t v_pb = {0}; + uint16x8_t v_pc = {0}; + uint16x8_t v_cmpab = {0}; + uint16x8_t v_cmpac = {0}; + uint8x8_t v_picka = {0}; + uint8x8_t v_pickb = {0}; -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__filter_4_distance_4_fallback( - wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr, - wuffs_base__slice_u8 a_prev); + { + wuffs_base__slice_u8 i_slice_curr = a_curr; + v_curr.ptr = i_slice_curr.ptr; + wuffs_base__slice_u8 i_slice_prev = a_prev; + v_prev.ptr = i_slice_prev.ptr; + i_slice_curr.len = ((size_t)(wuffs_base__u64__min(i_slice_curr.len, i_slice_prev.len))); + v_curr.len = 4; + v_prev.len = 4; + const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 8) * 8)); + while (v_curr.ptr < i_end0_curr) { + v_fb = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); + v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_fafb = vaddl_u8(v_fa, v_fb); + v_fcfc = vaddl_u8(v_fc, v_fc); + v_pa = vabdl_u8(v_fb, v_fc); + v_pb = vabdl_u8(v_fa, v_fc); + v_pc = vabdq_u16(v_fafb, v_fcfc); + v_cmpab = vcleq_u16(v_pa, v_pb); + v_cmpac = vcleq_u16(v_pa, v_pc); + v_picka = vmovn_u16(vandq_u16(v_cmpab, v_cmpac)); + v_pickb = vmovn_u16(vcleq_u16(v_pb, v_pc)); + v_fx = vadd_u8(v_fx, vbsl_u8(v_picka, v_fa, vbsl_u8(v_pickb, v_fb, v_fc))); + wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); + v_fc = v_fb; + v_fa = v_fx; + v_curr.ptr += 4; + v_prev.ptr += 4; + v_fb = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); + v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_fafb = vaddl_u8(v_fa, v_fb); + v_fcfc = vaddl_u8(v_fc, v_fc); + v_pa = vabdl_u8(v_fb, v_fc); + v_pb = vabdl_u8(v_fa, v_fc); + v_pc = vabdq_u16(v_fafb, v_fcfc); + v_cmpab = vcleq_u16(v_pa, v_pb); + v_cmpac = vcleq_u16(v_pa, v_pc); + v_picka = vmovn_u16(vandq_u16(v_cmpab, v_cmpac)); + v_pickb = vmovn_u16(vcleq_u16(v_pb, v_pc)); + v_fx = vadd_u8(v_fx, vbsl_u8(v_picka, v_fa, vbsl_u8(v_pickb, v_fb, v_fc))); + wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); + v_fc = v_fb; + v_fa = v_fx; + v_curr.ptr += 4; + v_prev.ptr += 4; + } + v_curr.len = 4; + v_prev.len = 4; + const uint8_t* i_end1_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 4) * 4)); + while (v_curr.ptr < i_end1_curr) { + v_fb = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); + v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_fafb = vaddl_u8(v_fa, v_fb); + v_fcfc = vaddl_u8(v_fc, v_fc); + v_pa = vabdl_u8(v_fb, v_fc); + v_pb = vabdl_u8(v_fa, v_fc); + v_pc = vabdq_u16(v_fafb, v_fcfc); + v_cmpab = vcleq_u16(v_pa, v_pb); + v_cmpac = vcleq_u16(v_pa, v_pc); + v_picka = vmovn_u16(vandq_u16(v_cmpab, v_cmpac)); + v_pickb = vmovn_u16(vcleq_u16(v_pb, v_pc)); + v_fx = vadd_u8(v_fx, vbsl_u8(v_picka, v_fa, vbsl_u8(v_pickb, v_fb, v_fc))); + wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); + v_fc = v_fb; + v_fa = v_fx; + v_curr.ptr += 4; + v_prev.ptr += 4; + } + v_curr.len = 0; + v_prev.len = 0; + } + return wuffs_base__make_empty_struct(); +} +#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON) +// ‼ WUFFS MULTI-FILE SECTION -arm_neon -#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__filter_1_distance_4_x86_sse42( - wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr); -#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) +// -------- func png.decoder.filter_1 -#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) WUFFS_BASE__GENERATED_C_CODE static wuffs_base__empty_struct -wuffs_png__decoder__filter_3_distance_4_x86_sse42( +wuffs_png__decoder__filter_1( wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr, - wuffs_base__slice_u8 a_prev); -#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) + wuffs_base__slice_u8 a_curr) { + return (*self->private_impl.choosy_filter_1)(self, a_curr); +} -#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) WUFFS_BASE__GENERATED_C_CODE static wuffs_base__empty_struct -wuffs_png__decoder__filter_4_distance_3_x86_sse42( +wuffs_png__decoder__filter_1__choosy_default( wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr, - wuffs_base__slice_u8 a_prev); -#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) + wuffs_base__slice_u8 a_curr) { + uint64_t v_filter_distance = 0; + uint8_t v_fa = 0; + uint64_t v_i_start = 0; + uint64_t v_i = 0; -#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__filter_4_distance_4_x86_sse42( - wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr, - wuffs_base__slice_u8 a_prev); -#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) + v_filter_distance = ((uint64_t)(self->private_impl.f_filter_distance)); + v_i_start = 0u; + while (v_i_start < v_filter_distance) { + v_fa = 0u; + v_i = v_i_start; + while (v_i < ((uint64_t)(a_curr.len))) { + a_curr.ptr[v_i] = ((uint8_t)(a_curr.ptr[v_i] + v_fa)); + v_fa = a_curr.ptr[v_i]; + v_i += v_filter_distance; + } + v_i_start += 1u; + } + return wuffs_base__make_empty_struct(); +} -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__do_decode_image_config( - wuffs_png__decoder* self, - wuffs_base__image_config* a_dst, - wuffs_base__io_buffer* a_src); +// -------- func png.decoder.filter_1_distance_3_fallback WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__decode_ihdr( +static wuffs_base__empty_struct +wuffs_png__decoder__filter_1_distance_3_fallback( wuffs_png__decoder* self, - wuffs_base__io_buffer* a_src); + wuffs_base__slice_u8 a_curr) { + wuffs_base__slice_u8 v_curr = {0}; + uint8_t v_fa0 = 0; + uint8_t v_fa1 = 0; + uint8_t v_fa2 = 0; -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__assign_filter_distance( - wuffs_png__decoder* self); + { + wuffs_base__slice_u8 i_slice_curr = a_curr; + v_curr.ptr = i_slice_curr.ptr; + v_curr.len = 3; + const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 6) * 6)); + while (v_curr.ptr < i_end0_curr) { + v_fa0 = ((uint8_t)(v_fa0 + v_curr.ptr[0u])); + v_curr.ptr[0u] = v_fa0; + v_fa1 = ((uint8_t)(v_fa1 + v_curr.ptr[1u])); + v_curr.ptr[1u] = v_fa1; + v_fa2 = ((uint8_t)(v_fa2 + v_curr.ptr[2u])); + v_curr.ptr[2u] = v_fa2; + v_curr.ptr += 3; + v_fa0 = ((uint8_t)(v_fa0 + v_curr.ptr[0u])); + v_curr.ptr[0u] = v_fa0; + v_fa1 = ((uint8_t)(v_fa1 + v_curr.ptr[1u])); + v_curr.ptr[1u] = v_fa1; + v_fa2 = ((uint8_t)(v_fa2 + v_curr.ptr[2u])); + v_curr.ptr[2u] = v_fa2; + v_curr.ptr += 3; + } + v_curr.len = 3; + const uint8_t* i_end1_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 3) * 3)); + while (v_curr.ptr < i_end1_curr) { + v_fa0 = ((uint8_t)(v_fa0 + v_curr.ptr[0u])); + v_curr.ptr[0u] = v_fa0; + v_fa1 = ((uint8_t)(v_fa1 + v_curr.ptr[1u])); + v_curr.ptr[1u] = v_fa1; + v_fa2 = ((uint8_t)(v_fa2 + v_curr.ptr[2u])); + v_curr.ptr[2u] = v_fa2; + v_curr.ptr += 3; + } + v_curr.len = 0; + } + return wuffs_base__make_empty_struct(); +} -WUFFS_BASE__GENERATED_C_CODE -static uint64_t -wuffs_png__decoder__calculate_bytes_per_row( - const wuffs_png__decoder* self, - uint32_t a_width); +// -------- func png.decoder.filter_1_distance_4_fallback WUFFS_BASE__GENERATED_C_CODE static wuffs_base__empty_struct -wuffs_png__decoder__choose_filter_implementations( - wuffs_png__decoder* self); - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__decode_other_chunk( +wuffs_png__decoder__filter_1_distance_4_fallback( wuffs_png__decoder* self, - wuffs_base__io_buffer* a_src, - bool a_framy); + wuffs_base__slice_u8 a_curr) { + wuffs_base__slice_u8 v_curr = {0}; + uint8_t v_fa0 = 0; + uint8_t v_fa1 = 0; + uint8_t v_fa2 = 0; + uint8_t v_fa3 = 0; -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__decode_actl( - wuffs_png__decoder* self, - wuffs_base__io_buffer* a_src); + { + wuffs_base__slice_u8 i_slice_curr = a_curr; + v_curr.ptr = i_slice_curr.ptr; + v_curr.len = 4; + const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 4) * 4)); + while (v_curr.ptr < i_end0_curr) { + v_fa0 = ((uint8_t)(v_fa0 + v_curr.ptr[0u])); + v_curr.ptr[0u] = v_fa0; + v_fa1 = ((uint8_t)(v_fa1 + v_curr.ptr[1u])); + v_curr.ptr[1u] = v_fa1; + v_fa2 = ((uint8_t)(v_fa2 + v_curr.ptr[2u])); + v_curr.ptr[2u] = v_fa2; + v_fa3 = ((uint8_t)(v_fa3 + v_curr.ptr[3u])); + v_curr.ptr[3u] = v_fa3; + v_curr.ptr += 4; + } + v_curr.len = 0; + } + return wuffs_base__make_empty_struct(); +} -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__decode_chrm( - wuffs_png__decoder* self, - wuffs_base__io_buffer* a_src); +// -------- func png.decoder.filter_2 WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__decode_exif( +static wuffs_base__empty_struct +wuffs_png__decoder__filter_2( wuffs_png__decoder* self, - wuffs_base__io_buffer* a_src); + wuffs_base__slice_u8 a_curr, + wuffs_base__slice_u8 a_prev) { + uint64_t v_n = 0; + uint64_t v_i = 0; -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__decode_fctl( - wuffs_png__decoder* self, - wuffs_base__io_buffer* a_src); + v_n = wuffs_base__u64__min(((uint64_t)(a_curr.len)), ((uint64_t)(a_prev.len))); + v_i = 0u; + while (v_i < v_n) { + a_curr.ptr[v_i] = ((uint8_t)(a_curr.ptr[v_i] + a_prev.ptr[v_i])); + v_i += 1u; + } + return wuffs_base__make_empty_struct(); +} -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__decode_gama( - wuffs_png__decoder* self, - wuffs_base__io_buffer* a_src); +// -------- func png.decoder.filter_3 WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__decode_iccp( +static wuffs_base__empty_struct +wuffs_png__decoder__filter_3( wuffs_png__decoder* self, - wuffs_base__io_buffer* a_src); + wuffs_base__slice_u8 a_curr, + wuffs_base__slice_u8 a_prev) { + return (*self->private_impl.choosy_filter_3)(self, a_curr, a_prev); +} WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__decode_plte( +static wuffs_base__empty_struct +wuffs_png__decoder__filter_3__choosy_default( wuffs_png__decoder* self, - wuffs_base__io_buffer* a_src); + wuffs_base__slice_u8 a_curr, + wuffs_base__slice_u8 a_prev) { + uint64_t v_filter_distance = 0; + uint64_t v_n = 0; + uint64_t v_i = 0; -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__decode_srgb( - wuffs_png__decoder* self, - wuffs_base__io_buffer* a_src); + v_filter_distance = ((uint64_t)(self->private_impl.f_filter_distance)); + if (((uint64_t)(a_prev.len)) == 0u) { + v_i = v_filter_distance; + while (v_i < ((uint64_t)(a_curr.len))) { + a_curr.ptr[v_i] = ((uint8_t)(a_curr.ptr[v_i] + ((uint8_t)(a_curr.ptr[(v_i - v_filter_distance)] / 2u)))); + v_i += 1u; + } + } else { + v_n = wuffs_base__u64__min(((uint64_t)(a_curr.len)), ((uint64_t)(a_prev.len))); + v_i = 0u; + while ((v_i < v_n) && (v_i < v_filter_distance)) { + a_curr.ptr[v_i] = ((uint8_t)(a_curr.ptr[v_i] + ((uint8_t)(a_prev.ptr[v_i] / 2u)))); + v_i += 1u; + } + v_i = v_filter_distance; + while (v_i < v_n) { + a_curr.ptr[v_i] = ((uint8_t)(a_curr.ptr[v_i] + ((uint8_t)(((((uint32_t)(a_curr.ptr[(v_i - v_filter_distance)])) + ((uint32_t)(a_prev.ptr[v_i]))) / 2u))))); + v_i += 1u; + } + } + return wuffs_base__make_empty_struct(); +} -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__decode_trns( - wuffs_png__decoder* self, - wuffs_base__io_buffer* a_src); +// -------- func png.decoder.filter_3_distance_3_fallback WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__do_decode_frame_config( +static wuffs_base__empty_struct +wuffs_png__decoder__filter_3_distance_3_fallback( wuffs_png__decoder* self, - wuffs_base__frame_config* a_dst, - wuffs_base__io_buffer* a_src); + wuffs_base__slice_u8 a_curr, + wuffs_base__slice_u8 a_prev) { + wuffs_base__slice_u8 v_curr = {0}; + wuffs_base__slice_u8 v_prev = {0}; + uint8_t v_fa0 = 0; + uint8_t v_fa1 = 0; + uint8_t v_fa2 = 0; -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__skip_frame( - wuffs_png__decoder* self, - wuffs_base__io_buffer* a_src); + if (((uint64_t)(a_prev.len)) == 0u) { + { + wuffs_base__slice_u8 i_slice_curr = a_curr; + v_curr.ptr = i_slice_curr.ptr; + v_curr.len = 3; + const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 6) * 6)); + while (v_curr.ptr < i_end0_curr) { + v_fa0 = ((uint8_t)(((uint8_t)(v_fa0 / 2u)) + v_curr.ptr[0u])); + v_curr.ptr[0u] = v_fa0; + v_fa1 = ((uint8_t)(((uint8_t)(v_fa1 / 2u)) + v_curr.ptr[1u])); + v_curr.ptr[1u] = v_fa1; + v_fa2 = ((uint8_t)(((uint8_t)(v_fa2 / 2u)) + v_curr.ptr[2u])); + v_curr.ptr[2u] = v_fa2; + v_curr.ptr += 3; + v_fa0 = ((uint8_t)(((uint8_t)(v_fa0 / 2u)) + v_curr.ptr[0u])); + v_curr.ptr[0u] = v_fa0; + v_fa1 = ((uint8_t)(((uint8_t)(v_fa1 / 2u)) + v_curr.ptr[1u])); + v_curr.ptr[1u] = v_fa1; + v_fa2 = ((uint8_t)(((uint8_t)(v_fa2 / 2u)) + v_curr.ptr[2u])); + v_curr.ptr[2u] = v_fa2; + v_curr.ptr += 3; + } + v_curr.len = 3; + const uint8_t* i_end1_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 3) * 3)); + while (v_curr.ptr < i_end1_curr) { + v_fa0 = ((uint8_t)(((uint8_t)(v_fa0 / 2u)) + v_curr.ptr[0u])); + v_curr.ptr[0u] = v_fa0; + v_fa1 = ((uint8_t)(((uint8_t)(v_fa1 / 2u)) + v_curr.ptr[1u])); + v_curr.ptr[1u] = v_fa1; + v_fa2 = ((uint8_t)(((uint8_t)(v_fa2 / 2u)) + v_curr.ptr[2u])); + v_curr.ptr[2u] = v_fa2; + v_curr.ptr += 3; + } + v_curr.len = 0; + } + } else { + { + wuffs_base__slice_u8 i_slice_curr = a_curr; + v_curr.ptr = i_slice_curr.ptr; + wuffs_base__slice_u8 i_slice_prev = a_prev; + v_prev.ptr = i_slice_prev.ptr; + i_slice_curr.len = ((size_t)(wuffs_base__u64__min(i_slice_curr.len, i_slice_prev.len))); + v_curr.len = 3; + v_prev.len = 3; + const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 6) * 6)); + while (v_curr.ptr < i_end0_curr) { + v_fa0 = ((uint8_t)(((uint8_t)(((((uint32_t)(v_fa0)) + ((uint32_t)(v_prev.ptr[0u]))) / 2u))) + v_curr.ptr[0u])); + v_curr.ptr[0u] = v_fa0; + v_fa1 = ((uint8_t)(((uint8_t)(((((uint32_t)(v_fa1)) + ((uint32_t)(v_prev.ptr[1u]))) / 2u))) + v_curr.ptr[1u])); + v_curr.ptr[1u] = v_fa1; + v_fa2 = ((uint8_t)(((uint8_t)(((((uint32_t)(v_fa2)) + ((uint32_t)(v_prev.ptr[2u]))) / 2u))) + v_curr.ptr[2u])); + v_curr.ptr[2u] = v_fa2; + v_curr.ptr += 3; + v_prev.ptr += 3; + v_fa0 = ((uint8_t)(((uint8_t)(((((uint32_t)(v_fa0)) + ((uint32_t)(v_prev.ptr[0u]))) / 2u))) + v_curr.ptr[0u])); + v_curr.ptr[0u] = v_fa0; + v_fa1 = ((uint8_t)(((uint8_t)(((((uint32_t)(v_fa1)) + ((uint32_t)(v_prev.ptr[1u]))) / 2u))) + v_curr.ptr[1u])); + v_curr.ptr[1u] = v_fa1; + v_fa2 = ((uint8_t)(((uint8_t)(((((uint32_t)(v_fa2)) + ((uint32_t)(v_prev.ptr[2u]))) / 2u))) + v_curr.ptr[2u])); + v_curr.ptr[2u] = v_fa2; + v_curr.ptr += 3; + v_prev.ptr += 3; + } + v_curr.len = 3; + v_prev.len = 3; + const uint8_t* i_end1_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 3) * 3)); + while (v_curr.ptr < i_end1_curr) { + v_fa0 = ((uint8_t)(((uint8_t)(((((uint32_t)(v_fa0)) + ((uint32_t)(v_prev.ptr[0u]))) / 2u))) + v_curr.ptr[0u])); + v_curr.ptr[0u] = v_fa0; + v_fa1 = ((uint8_t)(((uint8_t)(((((uint32_t)(v_fa1)) + ((uint32_t)(v_prev.ptr[1u]))) / 2u))) + v_curr.ptr[1u])); + v_curr.ptr[1u] = v_fa1; + v_fa2 = ((uint8_t)(((uint8_t)(((((uint32_t)(v_fa2)) + ((uint32_t)(v_prev.ptr[2u]))) / 2u))) + v_curr.ptr[2u])); + v_curr.ptr[2u] = v_fa2; + v_curr.ptr += 3; + v_prev.ptr += 3; + } + v_curr.len = 0; + v_prev.len = 0; + } + } + return wuffs_base__make_empty_struct(); +} -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__do_decode_frame( - wuffs_png__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); +// -------- func png.decoder.filter_3_distance_4_fallback WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__decode_pass( +static wuffs_base__empty_struct +wuffs_png__decoder__filter_3_distance_4_fallback( wuffs_png__decoder* self, - wuffs_base__io_buffer* a_src, - wuffs_base__slice_u8 a_workbuf); + wuffs_base__slice_u8 a_curr, + wuffs_base__slice_u8 a_prev) { + wuffs_base__slice_u8 v_curr = {0}; + wuffs_base__slice_u8 v_prev = {0}; + uint8_t v_fa0 = 0; + uint8_t v_fa1 = 0; + uint8_t v_fa2 = 0; + uint8_t v_fa3 = 0; -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__do_tell_me_more( - wuffs_png__decoder* self, - wuffs_base__io_buffer* a_dst, - wuffs_base__more_information* a_minfo, - wuffs_base__io_buffer* a_src); + if (((uint64_t)(a_prev.len)) == 0u) { + { + wuffs_base__slice_u8 i_slice_curr = a_curr; + v_curr.ptr = i_slice_curr.ptr; + v_curr.len = 4; + const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 4) * 4)); + while (v_curr.ptr < i_end0_curr) { + v_fa0 = ((uint8_t)(((uint8_t)(v_fa0 / 2u)) + v_curr.ptr[0u])); + v_curr.ptr[0u] = v_fa0; + v_fa1 = ((uint8_t)(((uint8_t)(v_fa1 / 2u)) + v_curr.ptr[1u])); + v_curr.ptr[1u] = v_fa1; + v_fa2 = ((uint8_t)(((uint8_t)(v_fa2 / 2u)) + v_curr.ptr[2u])); + v_curr.ptr[2u] = v_fa2; + v_fa3 = ((uint8_t)(((uint8_t)(v_fa3 / 2u)) + v_curr.ptr[3u])); + v_curr.ptr[3u] = v_fa3; + v_curr.ptr += 4; + } + v_curr.len = 0; + } + } else { + { + wuffs_base__slice_u8 i_slice_curr = a_curr; + v_curr.ptr = i_slice_curr.ptr; + wuffs_base__slice_u8 i_slice_prev = a_prev; + v_prev.ptr = i_slice_prev.ptr; + i_slice_curr.len = ((size_t)(wuffs_base__u64__min(i_slice_curr.len, i_slice_prev.len))); + v_curr.len = 4; + v_prev.len = 4; + const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 4) * 4)); + while (v_curr.ptr < i_end0_curr) { + v_fa0 = ((uint8_t)(((uint8_t)(((((uint32_t)(v_fa0)) + ((uint32_t)(v_prev.ptr[0u]))) / 2u))) + v_curr.ptr[0u])); + v_curr.ptr[0u] = v_fa0; + v_fa1 = ((uint8_t)(((uint8_t)(((((uint32_t)(v_fa1)) + ((uint32_t)(v_prev.ptr[1u]))) / 2u))) + v_curr.ptr[1u])); + v_curr.ptr[1u] = v_fa1; + v_fa2 = ((uint8_t)(((uint8_t)(((((uint32_t)(v_fa2)) + ((uint32_t)(v_prev.ptr[2u]))) / 2u))) + v_curr.ptr[2u])); + v_curr.ptr[2u] = v_fa2; + v_fa3 = ((uint8_t)(((uint8_t)(((((uint32_t)(v_fa3)) + ((uint32_t)(v_prev.ptr[3u]))) / 2u))) + v_curr.ptr[3u])); + v_curr.ptr[3u] = v_fa3; + v_curr.ptr += 4; + v_prev.ptr += 4; + } + v_curr.len = 0; + v_prev.len = 0; + } + } + return wuffs_base__make_empty_struct(); +} -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__filter_and_swizzle( - wuffs_png__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__slice_u8 a_workbuf); +// -------- func png.decoder.filter_4 WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__filter_and_swizzle__choosy_default( +static wuffs_base__empty_struct +wuffs_png__decoder__filter_4( wuffs_png__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__slice_u8 a_workbuf); + wuffs_base__slice_u8 a_curr, + wuffs_base__slice_u8 a_prev) { + return (*self->private_impl.choosy_filter_4)(self, a_curr, a_prev); +} WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__filter_and_swizzle_tricky( +static wuffs_base__empty_struct +wuffs_png__decoder__filter_4__choosy_default( wuffs_png__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__slice_u8 a_workbuf); - -// ---------------- VTables + wuffs_base__slice_u8 a_curr, + wuffs_base__slice_u8 a_prev) { + uint64_t v_filter_distance = 0; + uint64_t v_n = 0; + uint64_t v_i = 0; + uint32_t v_fa = 0; + uint32_t v_fb = 0; + uint32_t v_fc = 0; + uint32_t v_pp = 0; + uint32_t v_pa = 0; + uint32_t v_pb = 0; + uint32_t v_pc = 0; -const wuffs_base__image_decoder__func_ptrs -wuffs_png__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_png__decoder__decode_frame), - (wuffs_base__status(*)(void*, - wuffs_base__frame_config*, - wuffs_base__io_buffer*))(&wuffs_png__decoder__decode_frame_config), - (wuffs_base__status(*)(void*, - wuffs_base__image_config*, - wuffs_base__io_buffer*))(&wuffs_png__decoder__decode_image_config), - (wuffs_base__rect_ie_u32(*)(const void*))(&wuffs_png__decoder__frame_dirty_rect), - (uint64_t(*)(const void*, - uint32_t))(&wuffs_png__decoder__get_quirk), - (uint32_t(*)(const void*))(&wuffs_png__decoder__num_animation_loops), - (uint64_t(*)(const void*))(&wuffs_png__decoder__num_decoded_frame_configs), - (uint64_t(*)(const void*))(&wuffs_png__decoder__num_decoded_frames), - (wuffs_base__status(*)(void*, - uint64_t, - uint64_t))(&wuffs_png__decoder__restart_frame), - (wuffs_base__status(*)(void*, - uint32_t, - uint64_t))(&wuffs_png__decoder__set_quirk), - (wuffs_base__empty_struct(*)(void*, - uint32_t, - bool))(&wuffs_png__decoder__set_report_metadata), - (wuffs_base__status(*)(void*, - wuffs_base__io_buffer*, - wuffs_base__more_information*, - wuffs_base__io_buffer*))(&wuffs_png__decoder__tell_me_more), - (wuffs_base__range_ii_u64(*)(const void*))(&wuffs_png__decoder__workbuf_len), -}; + v_filter_distance = ((uint64_t)(self->private_impl.f_filter_distance)); + v_n = wuffs_base__u64__min(((uint64_t)(a_curr.len)), ((uint64_t)(a_prev.len))); + v_i = 0u; + while ((v_i < v_n) && (v_i < v_filter_distance)) { + a_curr.ptr[v_i] = ((uint8_t)(a_curr.ptr[v_i] + a_prev.ptr[v_i])); + v_i += 1u; + } + v_i = v_filter_distance; + while (v_i < v_n) { + v_fa = ((uint32_t)(a_curr.ptr[(v_i - v_filter_distance)])); + v_fb = ((uint32_t)(a_prev.ptr[v_i])); + v_fc = ((uint32_t)(a_prev.ptr[(v_i - v_filter_distance)])); + v_pp = ((uint32_t)(((uint32_t)(v_fa + v_fb)) - v_fc)); + v_pa = ((uint32_t)(v_pp - v_fa)); + if (v_pa >= 2147483648u) { + v_pa = ((uint32_t)(0u - v_pa)); + } + v_pb = ((uint32_t)(v_pp - v_fb)); + if (v_pb >= 2147483648u) { + v_pb = ((uint32_t)(0u - v_pb)); + } + v_pc = ((uint32_t)(v_pp - v_fc)); + if (v_pc >= 2147483648u) { + v_pc = ((uint32_t)(0u - v_pc)); + } + if ((v_pa <= v_pb) && (v_pa <= v_pc)) { + } else if (v_pb <= v_pc) { + v_fa = v_fb; + } else { + v_fa = v_fc; + } + a_curr.ptr[v_i] = ((uint8_t)(a_curr.ptr[v_i] + ((uint8_t)(v_fa)))); + v_i += 1u; + } + return wuffs_base__make_empty_struct(); +} -// ---------------- Initializer Implementations +// -------- func png.decoder.filter_4_distance_3_fallback -wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT -wuffs_png__decoder__initialize( +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_png__decoder__filter_4_distance_3_fallback( wuffs_png__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); - } + wuffs_base__slice_u8 a_curr, + wuffs_base__slice_u8 a_prev) { + wuffs_base__slice_u8 v_curr = {0}; + wuffs_base__slice_u8 v_prev = {0}; + uint32_t v_fa0 = 0; + uint32_t v_fa1 = 0; + uint32_t v_fa2 = 0; + uint32_t v_fb0 = 0; + uint32_t v_fb1 = 0; + uint32_t v_fb2 = 0; + uint32_t v_fc0 = 0; + uint32_t v_fc1 = 0; + uint32_t v_fc2 = 0; + uint32_t v_pp0 = 0; + uint32_t v_pp1 = 0; + uint32_t v_pp2 = 0; + uint32_t v_pa0 = 0; + uint32_t v_pa1 = 0; + uint32_t v_pa2 = 0; + uint32_t v_pb0 = 0; + uint32_t v_pb1 = 0; + uint32_t v_pb2 = 0; + uint32_t v_pc0 = 0; + uint32_t v_pc1 = 0; + uint32_t v_pc2 = 0; - 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)); + { + wuffs_base__slice_u8 i_slice_curr = a_curr; + v_curr.ptr = i_slice_curr.ptr; + wuffs_base__slice_u8 i_slice_prev = a_prev; + v_prev.ptr = i_slice_prev.ptr; + i_slice_curr.len = ((size_t)(wuffs_base__u64__min(i_slice_curr.len, i_slice_prev.len))); + v_curr.len = 3; + v_prev.len = 3; + const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 3) * 3)); + while (v_curr.ptr < i_end0_curr) { + v_fb0 = ((uint32_t)(v_prev.ptr[0u])); + v_pp0 = ((uint32_t)(((uint32_t)(v_fa0 + v_fb0)) - v_fc0)); + v_pa0 = ((uint32_t)(v_pp0 - v_fa0)); + if (v_pa0 >= 2147483648u) { + v_pa0 = ((uint32_t)(0u - v_pa0)); + } + v_pb0 = ((uint32_t)(v_pp0 - v_fb0)); + if (v_pb0 >= 2147483648u) { + v_pb0 = ((uint32_t)(0u - v_pb0)); + } + v_pc0 = ((uint32_t)(v_pp0 - v_fc0)); + if (v_pc0 >= 2147483648u) { + v_pc0 = ((uint32_t)(0u - v_pc0)); + } + if ((v_pa0 <= v_pb0) && (v_pa0 <= v_pc0)) { + } else if (v_pb0 <= v_pc0) { + v_fa0 = v_fb0; + } else { + v_fa0 = v_fc0; + } + v_curr.ptr[0u] = ((uint8_t)(v_curr.ptr[0u] + ((uint8_t)(v_fa0)))); + v_fa0 = ((uint32_t)(v_curr.ptr[0u])); + v_fc0 = v_fb0; + v_fb1 = ((uint32_t)(v_prev.ptr[1u])); + v_pp1 = ((uint32_t)(((uint32_t)(v_fa1 + v_fb1)) - v_fc1)); + v_pa1 = ((uint32_t)(v_pp1 - v_fa1)); + if (v_pa1 >= 2147483648u) { + v_pa1 = ((uint32_t)(0u - v_pa1)); + } + v_pb1 = ((uint32_t)(v_pp1 - v_fb1)); + if (v_pb1 >= 2147483648u) { + v_pb1 = ((uint32_t)(0u - v_pb1)); + } + v_pc1 = ((uint32_t)(v_pp1 - v_fc1)); + if (v_pc1 >= 2147483648u) { + v_pc1 = ((uint32_t)(0u - v_pc1)); + } + if ((v_pa1 <= v_pb1) && (v_pa1 <= v_pc1)) { + } else if (v_pb1 <= v_pc1) { + v_fa1 = v_fb1; + } else { + v_fa1 = v_fc1; + } + v_curr.ptr[1u] = ((uint8_t)(v_curr.ptr[1u] + ((uint8_t)(v_fa1)))); + v_fa1 = ((uint32_t)(v_curr.ptr[1u])); + v_fc1 = v_fb1; + v_fb2 = ((uint32_t)(v_prev.ptr[2u])); + v_pp2 = ((uint32_t)(((uint32_t)(v_fa2 + v_fb2)) - v_fc2)); + v_pa2 = ((uint32_t)(v_pp2 - v_fa2)); + if (v_pa2 >= 2147483648u) { + v_pa2 = ((uint32_t)(0u - v_pa2)); + } + v_pb2 = ((uint32_t)(v_pp2 - v_fb2)); + if (v_pb2 >= 2147483648u) { + v_pb2 = ((uint32_t)(0u - v_pb2)); + } + v_pc2 = ((uint32_t)(v_pp2 - v_fc2)); + if (v_pc2 >= 2147483648u) { + v_pc2 = ((uint32_t)(0u - v_pc2)); + } + if ((v_pa2 <= v_pb2) && (v_pa2 <= v_pc2)) { + } else if (v_pb2 <= v_pc2) { + v_fa2 = v_fb2; + } else { + v_fa2 = v_fc2; + } + v_curr.ptr[2u] = ((uint8_t)(v_curr.ptr[2u] + ((uint8_t)(v_fa2)))); + v_fa2 = ((uint32_t)(v_curr.ptr[2u])); + v_fc2 = v_fb2; + v_curr.ptr += 3; + v_prev.ptr += 3; } + v_curr.len = 0; + v_prev.len = 0; } + return wuffs_base__make_empty_struct(); +} - self->private_impl.choosy_filter_1 = &wuffs_png__decoder__filter_1__choosy_default; - self->private_impl.choosy_filter_3 = &wuffs_png__decoder__filter_3__choosy_default; - self->private_impl.choosy_filter_4 = &wuffs_png__decoder__filter_4__choosy_default; - self->private_impl.choosy_filter_and_swizzle = &wuffs_png__decoder__filter_and_swizzle__choosy_default; +// -------- func png.decoder.filter_4_distance_4_fallback + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_png__decoder__filter_4_distance_4_fallback( + wuffs_png__decoder* self, + wuffs_base__slice_u8 a_curr, + wuffs_base__slice_u8 a_prev) { + wuffs_base__slice_u8 v_curr = {0}; + wuffs_base__slice_u8 v_prev = {0}; + uint32_t v_fa0 = 0; + uint32_t v_fa1 = 0; + uint32_t v_fa2 = 0; + uint32_t v_fa3 = 0; + uint32_t v_fb0 = 0; + uint32_t v_fb1 = 0; + uint32_t v_fb2 = 0; + uint32_t v_fb3 = 0; + uint32_t v_fc0 = 0; + uint32_t v_fc1 = 0; + uint32_t v_fc2 = 0; + uint32_t v_fc3 = 0; + uint32_t v_pp0 = 0; + uint32_t v_pp1 = 0; + uint32_t v_pp2 = 0; + uint32_t v_pp3 = 0; + uint32_t v_pa0 = 0; + uint32_t v_pa1 = 0; + uint32_t v_pa2 = 0; + uint32_t v_pa3 = 0; + uint32_t v_pb0 = 0; + uint32_t v_pb1 = 0; + uint32_t v_pb2 = 0; + uint32_t v_pb3 = 0; + uint32_t v_pc0 = 0; + uint32_t v_pc1 = 0; + uint32_t v_pc2 = 0; + uint32_t v_pc3 = 0; { - wuffs_base__status z = wuffs_crc32__ieee_hasher__initialize( - &self->private_data.f_crc32, sizeof(self->private_data.f_crc32), WUFFS_VERSION, options); - if (z.repr) { - return z; - } - } - { - wuffs_base__status z = wuffs_zlib__decoder__initialize( - &self->private_data.f_zlib, sizeof(self->private_data.f_zlib), WUFFS_VERSION, options); - if (z.repr) { - return z; + wuffs_base__slice_u8 i_slice_curr = a_curr; + v_curr.ptr = i_slice_curr.ptr; + wuffs_base__slice_u8 i_slice_prev = a_prev; + v_prev.ptr = i_slice_prev.ptr; + i_slice_curr.len = ((size_t)(wuffs_base__u64__min(i_slice_curr.len, i_slice_prev.len))); + v_curr.len = 4; + v_prev.len = 4; + const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 4) * 4)); + while (v_curr.ptr < i_end0_curr) { + v_fb0 = ((uint32_t)(v_prev.ptr[0u])); + v_pp0 = ((uint32_t)(((uint32_t)(v_fa0 + v_fb0)) - v_fc0)); + v_pa0 = ((uint32_t)(v_pp0 - v_fa0)); + if (v_pa0 >= 2147483648u) { + v_pa0 = ((uint32_t)(0u - v_pa0)); + } + v_pb0 = ((uint32_t)(v_pp0 - v_fb0)); + if (v_pb0 >= 2147483648u) { + v_pb0 = ((uint32_t)(0u - v_pb0)); + } + v_pc0 = ((uint32_t)(v_pp0 - v_fc0)); + if (v_pc0 >= 2147483648u) { + v_pc0 = ((uint32_t)(0u - v_pc0)); + } + if ((v_pa0 <= v_pb0) && (v_pa0 <= v_pc0)) { + } else if (v_pb0 <= v_pc0) { + v_fa0 = v_fb0; + } else { + v_fa0 = v_fc0; + } + v_curr.ptr[0u] = ((uint8_t)(v_curr.ptr[0u] + ((uint8_t)(v_fa0)))); + v_fa0 = ((uint32_t)(v_curr.ptr[0u])); + v_fc0 = v_fb0; + v_fb1 = ((uint32_t)(v_prev.ptr[1u])); + v_pp1 = ((uint32_t)(((uint32_t)(v_fa1 + v_fb1)) - v_fc1)); + v_pa1 = ((uint32_t)(v_pp1 - v_fa1)); + if (v_pa1 >= 2147483648u) { + v_pa1 = ((uint32_t)(0u - v_pa1)); + } + v_pb1 = ((uint32_t)(v_pp1 - v_fb1)); + if (v_pb1 >= 2147483648u) { + v_pb1 = ((uint32_t)(0u - v_pb1)); + } + v_pc1 = ((uint32_t)(v_pp1 - v_fc1)); + if (v_pc1 >= 2147483648u) { + v_pc1 = ((uint32_t)(0u - v_pc1)); + } + if ((v_pa1 <= v_pb1) && (v_pa1 <= v_pc1)) { + } else if (v_pb1 <= v_pc1) { + v_fa1 = v_fb1; + } else { + v_fa1 = v_fc1; + } + v_curr.ptr[1u] = ((uint8_t)(v_curr.ptr[1u] + ((uint8_t)(v_fa1)))); + v_fa1 = ((uint32_t)(v_curr.ptr[1u])); + v_fc1 = v_fb1; + v_fb2 = ((uint32_t)(v_prev.ptr[2u])); + v_pp2 = ((uint32_t)(((uint32_t)(v_fa2 + v_fb2)) - v_fc2)); + v_pa2 = ((uint32_t)(v_pp2 - v_fa2)); + if (v_pa2 >= 2147483648u) { + v_pa2 = ((uint32_t)(0u - v_pa2)); + } + v_pb2 = ((uint32_t)(v_pp2 - v_fb2)); + if (v_pb2 >= 2147483648u) { + v_pb2 = ((uint32_t)(0u - v_pb2)); + } + v_pc2 = ((uint32_t)(v_pp2 - v_fc2)); + if (v_pc2 >= 2147483648u) { + v_pc2 = ((uint32_t)(0u - v_pc2)); + } + if ((v_pa2 <= v_pb2) && (v_pa2 <= v_pc2)) { + } else if (v_pb2 <= v_pc2) { + v_fa2 = v_fb2; + } else { + v_fa2 = v_fc2; + } + v_curr.ptr[2u] = ((uint8_t)(v_curr.ptr[2u] + ((uint8_t)(v_fa2)))); + v_fa2 = ((uint32_t)(v_curr.ptr[2u])); + v_fc2 = v_fb2; + v_fb3 = ((uint32_t)(v_prev.ptr[3u])); + v_pp3 = ((uint32_t)(((uint32_t)(v_fa3 + v_fb3)) - v_fc3)); + v_pa3 = ((uint32_t)(v_pp3 - v_fa3)); + if (v_pa3 >= 2147483648u) { + v_pa3 = ((uint32_t)(0u - v_pa3)); + } + v_pb3 = ((uint32_t)(v_pp3 - v_fb3)); + if (v_pb3 >= 2147483648u) { + v_pb3 = ((uint32_t)(0u - v_pb3)); + } + v_pc3 = ((uint32_t)(v_pp3 - v_fc3)); + if (v_pc3 >= 2147483648u) { + v_pc3 = ((uint32_t)(0u - v_pc3)); + } + if ((v_pa3 <= v_pb3) && (v_pa3 <= v_pc3)) { + } else if (v_pb3 <= v_pc3) { + v_fa3 = v_fb3; + } else { + v_fa3 = v_fc3; + } + v_curr.ptr[3u] = ((uint8_t)(v_curr.ptr[3u] + ((uint8_t)(v_fa3)))); + v_fa3 = ((uint32_t)(v_curr.ptr[3u])); + v_fc3 = v_fb3; + v_curr.ptr += 4; + v_prev.ptr += 4; } + v_curr.len = 0; + v_prev.len = 0; } - 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_png__decoder__func_ptrs_for__wuffs_base__image_decoder); - return wuffs_base__make_status(NULL); -} - -wuffs_png__decoder* -wuffs_png__decoder__alloc(void) { - wuffs_png__decoder* x = - (wuffs_png__decoder*)(calloc(1, sizeof(wuffs_png__decoder))); - if (!x) { - return NULL; - } - if (wuffs_png__decoder__initialize( - x, sizeof(wuffs_png__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) { - free(x); - return NULL; - } - return x; -} - -size_t -sizeof__wuffs_png__decoder(void) { - return sizeof(wuffs_png__decoder); + return wuffs_base__make_empty_struct(); } -// ---------------- Function Implementations - -// ‼ WUFFS MULTI-FILE SECTION +arm_neon -// -------- func png.decoder.filter_1_distance_4_arm_neon +// ‼ WUFFS MULTI-FILE SECTION +x86_sse42 +// -------- func png.decoder.filter_1_distance_4_x86_sse42 -#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON) +#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) +WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2") WUFFS_BASE__GENERATED_C_CODE static wuffs_base__empty_struct -wuffs_png__decoder__filter_1_distance_4_arm_neon( +wuffs_png__decoder__filter_1_distance_4_x86_sse42( wuffs_png__decoder* self, wuffs_base__slice_u8 a_curr) { wuffs_base__slice_u8 v_curr = {0}; - uint8x8_t v_fa = {0}; - uint8x8_t v_fx = {0}; + __m128i v_x128 = {0}; + __m128i v_a128 = {0}; { wuffs_base__slice_u8 i_slice_curr = a_curr; @@ -61210,79 +65908,87 @@ wuffs_png__decoder__filter_1_distance_4_arm_neon( v_curr.len = 4; const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 8) * 8)); while (v_curr.ptr < i_end0_curr) { - v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_fx = vadd_u8(v_fx, v_fa); - wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); - v_fa = v_fx; + v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_x128 = _mm_add_epi8(v_x128, v_a128); + v_a128 = v_x128; + wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); v_curr.ptr += 4; - v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_fx = vadd_u8(v_fx, v_fa); - wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); - v_fa = v_fx; + v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_x128 = _mm_add_epi8(v_x128, v_a128); + v_a128 = v_x128; + wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); v_curr.ptr += 4; } v_curr.len = 4; const uint8_t* i_end1_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 4) * 4)); while (v_curr.ptr < i_end1_curr) { - v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_fx = vadd_u8(v_fx, v_fa); - wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); - v_fa = v_fx; + v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_x128 = _mm_add_epi8(v_x128, v_a128); + v_a128 = v_x128; + wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); v_curr.ptr += 4; } v_curr.len = 0; } return wuffs_base__make_empty_struct(); } -#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON) -// ‼ WUFFS MULTI-FILE SECTION -arm_neon +#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) +// ‼ WUFFS MULTI-FILE SECTION -x86_sse42 -// ‼ WUFFS MULTI-FILE SECTION +arm_neon -// -------- func png.decoder.filter_3_distance_4_arm_neon +// ‼ WUFFS MULTI-FILE SECTION +x86_sse42 +// -------- func png.decoder.filter_3_distance_4_x86_sse42 -#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON) +#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) +WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2") WUFFS_BASE__GENERATED_C_CODE static wuffs_base__empty_struct -wuffs_png__decoder__filter_3_distance_4_arm_neon( +wuffs_png__decoder__filter_3_distance_4_x86_sse42( wuffs_png__decoder* self, wuffs_base__slice_u8 a_curr, wuffs_base__slice_u8 a_prev) { wuffs_base__slice_u8 v_curr = {0}; wuffs_base__slice_u8 v_prev = {0}; - uint8x8_t v_fa = {0}; - uint8x8_t v_fb = {0}; - uint8x8_t v_fx = {0}; + __m128i v_x128 = {0}; + __m128i v_a128 = {0}; + __m128i v_b128 = {0}; + __m128i v_p128 = {0}; + __m128i v_k128 = {0}; if (((uint64_t)(a_prev.len)) == 0u) { + v_k128 = _mm_set1_epi8((int8_t)(254u)); { wuffs_base__slice_u8 i_slice_curr = a_curr; v_curr.ptr = i_slice_curr.ptr; v_curr.len = 4; const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 8) * 8)); while (v_curr.ptr < i_end0_curr) { - v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_fx = vadd_u8(v_fx, vhadd_u8(v_fa, v_fb)); - wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); - v_fa = v_fx; + v_p128 = _mm_avg_epu8(_mm_and_si128(v_a128, v_k128), v_b128); + v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_x128 = _mm_add_epi8(v_x128, v_p128); + v_a128 = v_x128; + wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); v_curr.ptr += 4; - v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_fx = vadd_u8(v_fx, vhadd_u8(v_fa, v_fb)); - wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); - v_fa = v_fx; + v_p128 = _mm_avg_epu8(_mm_and_si128(v_a128, v_k128), v_b128); + v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_x128 = _mm_add_epi8(v_x128, v_p128); + v_a128 = v_x128; + wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); v_curr.ptr += 4; } v_curr.len = 4; const uint8_t* i_end1_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 4) * 4)); while (v_curr.ptr < i_end1_curr) { - v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_fx = vadd_u8(v_fx, vhadd_u8(v_fa, v_fb)); - wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); - v_fa = v_fx; + v_p128 = _mm_avg_epu8(_mm_and_si128(v_a128, v_k128), v_b128); + v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_x128 = _mm_add_epi8(v_x128, v_p128); + v_a128 = v_x128; + wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); v_curr.ptr += 4; } v_curr.len = 0; } } else { + v_k128 = _mm_set1_epi8((int8_t)(1u)); { wuffs_base__slice_u8 i_slice_curr = a_curr; v_curr.ptr = i_slice_curr.ptr; @@ -61293,18 +65999,22 @@ wuffs_png__decoder__filter_3_distance_4_arm_neon( v_prev.len = 4; const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 8) * 8)); while (v_curr.ptr < i_end0_curr) { - v_fb = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); - v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_fx = vadd_u8(v_fx, vhadd_u8(v_fa, v_fb)); - wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); - v_fa = v_fx; + v_b128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); + v_p128 = _mm_avg_epu8(v_a128, v_b128); + v_p128 = _mm_sub_epi8(v_p128, _mm_and_si128(v_k128, _mm_xor_si128(v_a128, v_b128))); + v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_x128 = _mm_add_epi8(v_x128, v_p128); + v_a128 = v_x128; + wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); v_curr.ptr += 4; v_prev.ptr += 4; - v_fb = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); - v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_fx = vadd_u8(v_fx, vhadd_u8(v_fa, v_fb)); - wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); - v_fa = v_fx; + v_b128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); + v_p128 = _mm_avg_epu8(v_a128, v_b128); + v_p128 = _mm_sub_epi8(v_p128, _mm_and_si128(v_k128, _mm_xor_si128(v_a128, v_b128))); + v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_x128 = _mm_add_epi8(v_x128, v_p128); + v_a128 = v_x128; + wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); v_curr.ptr += 4; v_prev.ptr += 4; } @@ -61312,11 +66022,13 @@ wuffs_png__decoder__filter_3_distance_4_arm_neon( v_prev.len = 4; const uint8_t* i_end1_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 4) * 4)); while (v_curr.ptr < i_end1_curr) { - v_fb = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); - v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_fx = vadd_u8(v_fx, vhadd_u8(v_fa, v_fb)); - wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); - v_fa = v_fx; + v_b128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); + v_p128 = _mm_avg_epu8(v_a128, v_b128); + v_p128 = _mm_sub_epi8(v_p128, _mm_and_si128(v_k128, _mm_xor_si128(v_a128, v_b128))); + v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_x128 = _mm_add_epi8(v_x128, v_p128); + v_a128 = v_x128; + wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); v_curr.ptr += 4; v_prev.ptr += 4; } @@ -61326,34 +66038,32 @@ wuffs_png__decoder__filter_3_distance_4_arm_neon( } return wuffs_base__make_empty_struct(); } -#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON) -// ‼ WUFFS MULTI-FILE SECTION -arm_neon +#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) +// ‼ WUFFS MULTI-FILE SECTION -x86_sse42 -// ‼ WUFFS MULTI-FILE SECTION +arm_neon -// -------- func png.decoder.filter_4_distance_3_arm_neon +// ‼ WUFFS MULTI-FILE SECTION +x86_sse42 +// -------- func png.decoder.filter_4_distance_3_x86_sse42 -#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON) +#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) +WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2") WUFFS_BASE__GENERATED_C_CODE static wuffs_base__empty_struct -wuffs_png__decoder__filter_4_distance_3_arm_neon( +wuffs_png__decoder__filter_4_distance_3_x86_sse42( wuffs_png__decoder* self, wuffs_base__slice_u8 a_curr, wuffs_base__slice_u8 a_prev) { wuffs_base__slice_u8 v_curr = {0}; wuffs_base__slice_u8 v_prev = {0}; - uint8x8_t v_fa = {0}; - uint8x8_t v_fb = {0}; - uint8x8_t v_fc = {0}; - uint8x8_t v_fx = {0}; - uint16x8_t v_fafb = {0}; - uint16x8_t v_fcfc = {0}; - uint16x8_t v_pa = {0}; - uint16x8_t v_pb = {0}; - uint16x8_t v_pc = {0}; - uint16x8_t v_cmpab = {0}; - uint16x8_t v_cmpac = {0}; - uint8x8_t v_picka = {0}; - uint8x8_t v_pickb = {0}; + __m128i v_x128 = {0}; + __m128i v_a128 = {0}; + __m128i v_b128 = {0}; + __m128i v_c128 = {0}; + __m128i v_p128 = {0}; + __m128i v_pa128 = {0}; + __m128i v_pb128 = {0}; + __m128i v_pc128 = {0}; + __m128i v_smallest128 = {0}; + __m128i v_z128 = {0}; { wuffs_base__slice_u8 i_slice_curr = a_curr; @@ -61365,38 +66075,42 @@ wuffs_png__decoder__filter_4_distance_3_arm_neon( v_prev.len = 4; const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, wuffs_private_impl__iterate_total_advance((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)), 7, 6)); while (v_curr.ptr < i_end0_curr) { - v_fb = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); - v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_fafb = vaddl_u8(v_fa, v_fb); - v_fcfc = vaddl_u8(v_fc, v_fc); - v_pa = vabdl_u8(v_fb, v_fc); - v_pb = vabdl_u8(v_fa, v_fc); - v_pc = vabdq_u16(v_fafb, v_fcfc); - v_cmpab = vcleq_u16(v_pa, v_pb); - v_cmpac = vcleq_u16(v_pa, v_pc); - v_picka = vmovn_u16(vandq_u16(v_cmpab, v_cmpac)); - v_pickb = vmovn_u16(vcleq_u16(v_pb, v_pc)); - v_fx = vadd_u8(v_fx, vbsl_u8(v_picka, v_fa, vbsl_u8(v_pickb, v_fb, v_fc))); - wuffs_base__poke_u24le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); - v_fc = v_fb; - v_fa = v_fx; + v_b128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); + v_b128 = _mm_unpacklo_epi8(v_b128, v_z128); + v_pa128 = _mm_sub_epi16(v_b128, v_c128); + v_pb128 = _mm_sub_epi16(v_a128, v_c128); + v_pc128 = _mm_add_epi16(v_pa128, v_pb128); + v_pa128 = _mm_abs_epi16(v_pa128); + v_pb128 = _mm_abs_epi16(v_pb128); + v_pc128 = _mm_abs_epi16(v_pc128); + v_smallest128 = _mm_min_epi16(v_pc128, _mm_min_epi16(v_pb128, v_pa128)); + v_p128 = _mm_blendv_epi8(_mm_blendv_epi8(v_c128, v_b128, _mm_cmpeq_epi16(v_smallest128, v_pb128)), v_a128, _mm_cmpeq_epi16(v_smallest128, v_pa128)); + v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_x128 = _mm_unpacklo_epi8(v_x128, v_z128); + v_x128 = _mm_add_epi8(v_x128, v_p128); + v_a128 = v_x128; + v_c128 = v_b128; + v_x128 = _mm_packus_epi16(v_x128, v_x128); + wuffs_base__poke_u24le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); v_curr.ptr += 3; v_prev.ptr += 3; - v_fb = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); - v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_fafb = vaddl_u8(v_fa, v_fb); - v_fcfc = vaddl_u8(v_fc, v_fc); - v_pa = vabdl_u8(v_fb, v_fc); - v_pb = vabdl_u8(v_fa, v_fc); - v_pc = vabdq_u16(v_fafb, v_fcfc); - v_cmpab = vcleq_u16(v_pa, v_pb); - v_cmpac = vcleq_u16(v_pa, v_pc); - v_picka = vmovn_u16(vandq_u16(v_cmpab, v_cmpac)); - v_pickb = vmovn_u16(vcleq_u16(v_pb, v_pc)); - v_fx = vadd_u8(v_fx, vbsl_u8(v_picka, v_fa, vbsl_u8(v_pickb, v_fb, v_fc))); - wuffs_base__poke_u24le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); - v_fc = v_fb; - v_fa = v_fx; + v_b128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); + v_b128 = _mm_unpacklo_epi8(v_b128, v_z128); + v_pa128 = _mm_sub_epi16(v_b128, v_c128); + v_pb128 = _mm_sub_epi16(v_a128, v_c128); + v_pc128 = _mm_add_epi16(v_pa128, v_pb128); + v_pa128 = _mm_abs_epi16(v_pa128); + v_pb128 = _mm_abs_epi16(v_pb128); + v_pc128 = _mm_abs_epi16(v_pc128); + v_smallest128 = _mm_min_epi16(v_pc128, _mm_min_epi16(v_pb128, v_pa128)); + v_p128 = _mm_blendv_epi8(_mm_blendv_epi8(v_c128, v_b128, _mm_cmpeq_epi16(v_smallest128, v_pb128)), v_a128, _mm_cmpeq_epi16(v_smallest128, v_pa128)); + v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_x128 = _mm_unpacklo_epi8(v_x128, v_z128); + v_x128 = _mm_add_epi8(v_x128, v_p128); + v_a128 = v_x128; + v_c128 = v_b128; + v_x128 = _mm_packus_epi16(v_x128, v_x128); + wuffs_base__poke_u24le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); v_curr.ptr += 3; v_prev.ptr += 3; } @@ -61404,21 +66118,23 @@ wuffs_png__decoder__filter_4_distance_3_arm_neon( v_prev.len = 4; const uint8_t* i_end1_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, wuffs_private_impl__iterate_total_advance((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)), 4, 3)); while (v_curr.ptr < i_end1_curr) { - v_fb = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); - v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_fafb = vaddl_u8(v_fa, v_fb); - v_fcfc = vaddl_u8(v_fc, v_fc); - v_pa = vabdl_u8(v_fb, v_fc); - v_pb = vabdl_u8(v_fa, v_fc); - v_pc = vabdq_u16(v_fafb, v_fcfc); - v_cmpab = vcleq_u16(v_pa, v_pb); - v_cmpac = vcleq_u16(v_pa, v_pc); - v_picka = vmovn_u16(vandq_u16(v_cmpab, v_cmpac)); - v_pickb = vmovn_u16(vcleq_u16(v_pb, v_pc)); - v_fx = vadd_u8(v_fx, vbsl_u8(v_picka, v_fa, vbsl_u8(v_pickb, v_fb, v_fc))); - wuffs_base__poke_u24le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); - v_fc = v_fb; - v_fa = v_fx; + v_b128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); + v_b128 = _mm_unpacklo_epi8(v_b128, v_z128); + v_pa128 = _mm_sub_epi16(v_b128, v_c128); + v_pb128 = _mm_sub_epi16(v_a128, v_c128); + v_pc128 = _mm_add_epi16(v_pa128, v_pb128); + v_pa128 = _mm_abs_epi16(v_pa128); + v_pb128 = _mm_abs_epi16(v_pb128); + v_pc128 = _mm_abs_epi16(v_pc128); + v_smallest128 = _mm_min_epi16(v_pc128, _mm_min_epi16(v_pb128, v_pa128)); + v_p128 = _mm_blendv_epi8(_mm_blendv_epi8(v_c128, v_b128, _mm_cmpeq_epi16(v_smallest128, v_pb128)), v_a128, _mm_cmpeq_epi16(v_smallest128, v_pa128)); + v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_x128 = _mm_unpacklo_epi8(v_x128, v_z128); + v_x128 = _mm_add_epi8(v_x128, v_p128); + v_a128 = v_x128; + v_c128 = v_b128; + v_x128 = _mm_packus_epi16(v_x128, v_x128); + wuffs_base__poke_u24le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); v_curr.ptr += 3; v_prev.ptr += 3; } @@ -61426,19 +66142,21 @@ wuffs_png__decoder__filter_4_distance_3_arm_neon( v_prev.len = 3; const uint8_t* i_end2_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 3) * 3)); while (v_curr.ptr < i_end2_curr) { - v_fb = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u24le__no_bounds_check(v_prev.ptr))); - v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u24le__no_bounds_check(v_curr.ptr))); - v_fafb = vaddl_u8(v_fa, v_fb); - v_fcfc = vaddl_u8(v_fc, v_fc); - v_pa = vabdl_u8(v_fb, v_fc); - v_pb = vabdl_u8(v_fa, v_fc); - v_pc = vabdq_u16(v_fafb, v_fcfc); - v_cmpab = vcleq_u16(v_pa, v_pb); - v_cmpac = vcleq_u16(v_pa, v_pc); - v_picka = vmovn_u16(vandq_u16(v_cmpab, v_cmpac)); - v_pickb = vmovn_u16(vcleq_u16(v_pb, v_pc)); - v_fx = vadd_u8(v_fx, vbsl_u8(v_picka, v_fa, vbsl_u8(v_pickb, v_fb, v_fc))); - wuffs_base__poke_u24le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); + v_b128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u24le__no_bounds_check(v_prev.ptr))); + v_b128 = _mm_unpacklo_epi8(v_b128, v_z128); + v_pa128 = _mm_sub_epi16(v_b128, v_c128); + v_pb128 = _mm_sub_epi16(v_a128, v_c128); + v_pc128 = _mm_add_epi16(v_pa128, v_pb128); + v_pa128 = _mm_abs_epi16(v_pa128); + v_pb128 = _mm_abs_epi16(v_pb128); + v_pc128 = _mm_abs_epi16(v_pc128); + v_smallest128 = _mm_min_epi16(v_pc128, _mm_min_epi16(v_pb128, v_pa128)); + v_p128 = _mm_blendv_epi8(_mm_blendv_epi8(v_c128, v_b128, _mm_cmpeq_epi16(v_smallest128, v_pb128)), v_a128, _mm_cmpeq_epi16(v_smallest128, v_pa128)); + v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u24le__no_bounds_check(v_curr.ptr))); + v_x128 = _mm_unpacklo_epi8(v_x128, v_z128); + v_x128 = _mm_add_epi8(v_x128, v_p128); + v_x128 = _mm_packus_epi16(v_x128, v_x128); + wuffs_base__poke_u24le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); v_curr.ptr += 3; v_prev.ptr += 3; } @@ -61447,34 +66165,32 @@ wuffs_png__decoder__filter_4_distance_3_arm_neon( } return wuffs_base__make_empty_struct(); } -#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON) -// ‼ WUFFS MULTI-FILE SECTION -arm_neon +#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) +// ‼ WUFFS MULTI-FILE SECTION -x86_sse42 -// ‼ WUFFS MULTI-FILE SECTION +arm_neon -// -------- func png.decoder.filter_4_distance_4_arm_neon +// ‼ WUFFS MULTI-FILE SECTION +x86_sse42 +// -------- func png.decoder.filter_4_distance_4_x86_sse42 -#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON) +#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) +WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2") WUFFS_BASE__GENERATED_C_CODE static wuffs_base__empty_struct -wuffs_png__decoder__filter_4_distance_4_arm_neon( +wuffs_png__decoder__filter_4_distance_4_x86_sse42( wuffs_png__decoder* self, wuffs_base__slice_u8 a_curr, wuffs_base__slice_u8 a_prev) { wuffs_base__slice_u8 v_curr = {0}; wuffs_base__slice_u8 v_prev = {0}; - uint8x8_t v_fa = {0}; - uint8x8_t v_fb = {0}; - uint8x8_t v_fc = {0}; - uint8x8_t v_fx = {0}; - uint16x8_t v_fafb = {0}; - uint16x8_t v_fcfc = {0}; - uint16x8_t v_pa = {0}; - uint16x8_t v_pb = {0}; - uint16x8_t v_pc = {0}; - uint16x8_t v_cmpab = {0}; - uint16x8_t v_cmpac = {0}; - uint8x8_t v_picka = {0}; - uint8x8_t v_pickb = {0}; + __m128i v_x128 = {0}; + __m128i v_a128 = {0}; + __m128i v_b128 = {0}; + __m128i v_c128 = {0}; + __m128i v_p128 = {0}; + __m128i v_pa128 = {0}; + __m128i v_pb128 = {0}; + __m128i v_pc128 = {0}; + __m128i v_smallest128 = {0}; + __m128i v_z128 = {0}; { wuffs_base__slice_u8 i_slice_curr = a_curr; @@ -61486,38 +66202,42 @@ wuffs_png__decoder__filter_4_distance_4_arm_neon( v_prev.len = 4; const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 8) * 8)); while (v_curr.ptr < i_end0_curr) { - v_fb = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); - v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_fafb = vaddl_u8(v_fa, v_fb); - v_fcfc = vaddl_u8(v_fc, v_fc); - v_pa = vabdl_u8(v_fb, v_fc); - v_pb = vabdl_u8(v_fa, v_fc); - v_pc = vabdq_u16(v_fafb, v_fcfc); - v_cmpab = vcleq_u16(v_pa, v_pb); - v_cmpac = vcleq_u16(v_pa, v_pc); - v_picka = vmovn_u16(vandq_u16(v_cmpab, v_cmpac)); - v_pickb = vmovn_u16(vcleq_u16(v_pb, v_pc)); - v_fx = vadd_u8(v_fx, vbsl_u8(v_picka, v_fa, vbsl_u8(v_pickb, v_fb, v_fc))); - wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); - v_fc = v_fb; - v_fa = v_fx; + v_b128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); + v_b128 = _mm_unpacklo_epi8(v_b128, v_z128); + v_pa128 = _mm_sub_epi16(v_b128, v_c128); + v_pb128 = _mm_sub_epi16(v_a128, v_c128); + v_pc128 = _mm_add_epi16(v_pa128, v_pb128); + v_pa128 = _mm_abs_epi16(v_pa128); + v_pb128 = _mm_abs_epi16(v_pb128); + v_pc128 = _mm_abs_epi16(v_pc128); + v_smallest128 = _mm_min_epi16(v_pc128, _mm_min_epi16(v_pb128, v_pa128)); + v_p128 = _mm_blendv_epi8(_mm_blendv_epi8(v_c128, v_b128, _mm_cmpeq_epi16(v_smallest128, v_pb128)), v_a128, _mm_cmpeq_epi16(v_smallest128, v_pa128)); + v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_x128 = _mm_unpacklo_epi8(v_x128, v_z128); + v_x128 = _mm_add_epi8(v_x128, v_p128); + v_a128 = v_x128; + v_c128 = v_b128; + v_x128 = _mm_packus_epi16(v_x128, v_x128); + wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); v_curr.ptr += 4; v_prev.ptr += 4; - v_fb = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); - v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_fafb = vaddl_u8(v_fa, v_fb); - v_fcfc = vaddl_u8(v_fc, v_fc); - v_pa = vabdl_u8(v_fb, v_fc); - v_pb = vabdl_u8(v_fa, v_fc); - v_pc = vabdq_u16(v_fafb, v_fcfc); - v_cmpab = vcleq_u16(v_pa, v_pb); - v_cmpac = vcleq_u16(v_pa, v_pc); - v_picka = vmovn_u16(vandq_u16(v_cmpab, v_cmpac)); - v_pickb = vmovn_u16(vcleq_u16(v_pb, v_pc)); - v_fx = vadd_u8(v_fx, vbsl_u8(v_picka, v_fa, vbsl_u8(v_pickb, v_fb, v_fc))); - wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); - v_fc = v_fb; - v_fa = v_fx; + v_b128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); + v_b128 = _mm_unpacklo_epi8(v_b128, v_z128); + v_pa128 = _mm_sub_epi16(v_b128, v_c128); + v_pb128 = _mm_sub_epi16(v_a128, v_c128); + v_pc128 = _mm_add_epi16(v_pa128, v_pb128); + v_pa128 = _mm_abs_epi16(v_pa128); + v_pb128 = _mm_abs_epi16(v_pb128); + v_pc128 = _mm_abs_epi16(v_pc128); + v_smallest128 = _mm_min_epi16(v_pc128, _mm_min_epi16(v_pb128, v_pa128)); + v_p128 = _mm_blendv_epi8(_mm_blendv_epi8(v_c128, v_b128, _mm_cmpeq_epi16(v_smallest128, v_pb128)), v_a128, _mm_cmpeq_epi16(v_smallest128, v_pa128)); + v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_x128 = _mm_unpacklo_epi8(v_x128, v_z128); + v_x128 = _mm_add_epi8(v_x128, v_p128); + v_a128 = v_x128; + v_c128 = v_b128; + v_x128 = _mm_packus_epi16(v_x128, v_x128); + wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); v_curr.ptr += 4; v_prev.ptr += 4; } @@ -61525,21 +66245,23 @@ wuffs_png__decoder__filter_4_distance_4_arm_neon( v_prev.len = 4; const uint8_t* i_end1_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 4) * 4)); while (v_curr.ptr < i_end1_curr) { - v_fb = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); - v_fx = vreinterpret_u8_u32(vdup_n_u32(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_fafb = vaddl_u8(v_fa, v_fb); - v_fcfc = vaddl_u8(v_fc, v_fc); - v_pa = vabdl_u8(v_fb, v_fc); - v_pb = vabdl_u8(v_fa, v_fc); - v_pc = vabdq_u16(v_fafb, v_fcfc); - v_cmpab = vcleq_u16(v_pa, v_pb); - v_cmpac = vcleq_u16(v_pa, v_pc); - v_picka = vmovn_u16(vandq_u16(v_cmpab, v_cmpac)); - v_pickb = vmovn_u16(vcleq_u16(v_pb, v_pc)); - v_fx = vadd_u8(v_fx, vbsl_u8(v_picka, v_fa, vbsl_u8(v_pickb, v_fb, v_fc))); - wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, vget_lane_u32(vreinterpret_u32_u8(v_fx), 0u)); - v_fc = v_fb; - v_fa = v_fx; + v_b128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); + v_b128 = _mm_unpacklo_epi8(v_b128, v_z128); + v_pa128 = _mm_sub_epi16(v_b128, v_c128); + v_pb128 = _mm_sub_epi16(v_a128, v_c128); + v_pc128 = _mm_add_epi16(v_pa128, v_pb128); + v_pa128 = _mm_abs_epi16(v_pa128); + v_pb128 = _mm_abs_epi16(v_pb128); + v_pc128 = _mm_abs_epi16(v_pc128); + v_smallest128 = _mm_min_epi16(v_pc128, _mm_min_epi16(v_pb128, v_pa128)); + v_p128 = _mm_blendv_epi8(_mm_blendv_epi8(v_c128, v_b128, _mm_cmpeq_epi16(v_smallest128, v_pb128)), v_a128, _mm_cmpeq_epi16(v_smallest128, v_pa128)); + v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); + v_x128 = _mm_unpacklo_epi8(v_x128, v_z128); + v_x128 = _mm_add_epi8(v_x128, v_p128); + v_a128 = v_x128; + v_c128 = v_b128; + v_x128 = _mm_packus_epi16(v_x128, v_x128); + wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); v_curr.ptr += 4; v_prev.ptr += 4; } @@ -61548,1199 +66270,2170 @@ wuffs_png__decoder__filter_4_distance_4_arm_neon( } return wuffs_base__make_empty_struct(); } -#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON) -// ‼ WUFFS MULTI-FILE SECTION -arm_neon +#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) +// ‼ WUFFS MULTI-FILE SECTION -x86_sse42 -// -------- func png.decoder.filter_1 +// -------- func png.decoder.get_quirk WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__filter_1( +WUFFS_BASE__MAYBE_STATIC uint64_t +wuffs_png__decoder__get_quirk( + const wuffs_png__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; + } + + if ((a_key == 1u) && self->private_impl.f_ignore_checksum) { + return 1u; + } + return 0u; +} + +// -------- func png.decoder.set_quirk + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_png__decoder__set_quirk( wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr) { - return (*self->private_impl.choosy_filter_1)(self, a_curr); + 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); + } + + if (a_key == 1u) { + self->private_impl.f_ignore_checksum = (a_value > 0u); + wuffs_zlib__decoder__set_quirk(&self->private_data.f_zlib, a_key, a_value); + return wuffs_base__make_status(NULL); + } + return wuffs_base__make_status(wuffs_base__error__unsupported_option); } +// -------- func png.decoder.decode_image_config + WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__filter_1__choosy_default( +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_png__decoder__decode_image_config( wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr) { - uint64_t v_filter_distance = 0; - uint8_t v_fa = 0; - uint64_t v_i_start = 0; - uint64_t v_i = 0; + 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); - v_filter_distance = ((uint64_t)(self->private_impl.f_filter_distance)); - v_i_start = 0u; - while (v_i_start < v_filter_distance) { - v_fa = 0u; - v_i = v_i_start; - while (v_i < ((uint64_t)(a_curr.len))) { - a_curr.ptr[v_i] = ((uint8_t)(a_curr.ptr[v_i] + v_fa)); - v_fa = a_curr.ptr[v_i]; - v_i += v_filter_distance; + 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_png__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_png__error__truncated_input); + goto exit; + } + status = v_status; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1); } - v_i_start += 1u; + + ok: + self->private_impl.p_decode_image_config = 0; + goto exit; } - return wuffs_base__make_empty_struct(); + + 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 png.decoder.filter_1_distance_3_fallback +// -------- func png.decoder.do_decode_image_config WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__filter_1_distance_3_fallback( +static wuffs_base__status +wuffs_png__decoder__do_decode_image_config( wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr) { - wuffs_base__slice_u8 v_curr = {0}; - uint8_t v_fa0 = 0; - uint8_t v_fa1 = 0; - uint8_t v_fa2 = 0; + wuffs_base__image_config* a_dst, + wuffs_base__io_buffer* a_src) { + wuffs_base__status status = wuffs_base__make_status(NULL); - { - wuffs_base__slice_u8 i_slice_curr = a_curr; - v_curr.ptr = i_slice_curr.ptr; - v_curr.len = 3; - const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 6) * 6)); - while (v_curr.ptr < i_end0_curr) { - v_fa0 = ((uint8_t)(v_fa0 + v_curr.ptr[0u])); - v_curr.ptr[0u] = v_fa0; - v_fa1 = ((uint8_t)(v_fa1 + v_curr.ptr[1u])); - v_curr.ptr[1u] = v_fa1; - v_fa2 = ((uint8_t)(v_fa2 + v_curr.ptr[2u])); - v_curr.ptr[2u] = v_fa2; - v_curr.ptr += 3; - v_fa0 = ((uint8_t)(v_fa0 + v_curr.ptr[0u])); - v_curr.ptr[0u] = v_fa0; - v_fa1 = ((uint8_t)(v_fa1 + v_curr.ptr[1u])); - v_curr.ptr[1u] = v_fa1; - v_fa2 = ((uint8_t)(v_fa2 + v_curr.ptr[2u])); - v_curr.ptr[2u] = v_fa2; - v_curr.ptr += 3; + uint64_t v_magic = 0; + uint64_t v_mark = 0; + uint32_t v_checksum_have = 0; + uint32_t v_checksum_want = 0; + wuffs_base__status v_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_image_config; + if (coro_susp_point) { + v_checksum_have = self->private_data.s_do_decode_image_config.v_checksum_have; + } + 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; + } else if ( ! self->private_impl.f_seen_ihdr) { + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + uint64_t t_0; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 8)) { + t_0 = wuffs_base__peek_u64le__no_bounds_check(iop_a_src); + iop_a_src += 8; + } 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 == 56) { + t_0 = ((uint64_t)(*scratch)); + break; + } + num_bits_0 += 8u; + *scratch |= ((uint64_t)(num_bits_0)) << 56; + } + } + v_magic = t_0; + } + if (v_magic != 727905341920923785u) { + status = wuffs_base__make_status(wuffs_png__error__bad_header); + goto exit; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + uint64_t t_1; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 8)) { + t_1 = wuffs_base__peek_u64le__no_bounds_check(iop_a_src); + iop_a_src += 8; + } else { + self->private_data.s_do_decode_image_config.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + 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_1 = ((uint32_t)(*scratch >> 56)); + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_1; + if (num_bits_1 == 56) { + t_1 = ((uint64_t)(*scratch)); + break; + } + num_bits_1 += 8u; + *scratch |= ((uint64_t)(num_bits_1)) << 56; + } + } + v_magic = t_1; + } + if (v_magic != 5927942488114331648u) { + if (v_magic == 5278895250759221248u) { + status = wuffs_base__make_status(wuffs_png__error__unsupported_cgbi_extension); + goto exit; + } + status = wuffs_base__make_status(wuffs_png__error__bad_header); + goto exit; + } + self->private_impl.f_chunk_type_array[0u] = 73u; + self->private_impl.f_chunk_type_array[1u] = 72u; + self->private_impl.f_chunk_type_array[2u] = 68u; + self->private_impl.f_chunk_type_array[3u] = 82u; + wuffs_private_impl__ignore_status(wuffs_crc32__ieee_hasher__initialize(&self->private_data.f_crc32, + sizeof (wuffs_crc32__ieee_hasher), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED)); + wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__make_slice_u8(self->private_impl.f_chunk_type_array, 4)); + while (true) { + v_mark = ((uint64_t)(iop_a_src - io0_a_src)); + { + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + wuffs_base__status t_2 = wuffs_png__decoder__decode_ihdr(self, a_src); + v_status = t_2; + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + } + if ( ! self->private_impl.f_ignore_checksum) { + v_checksum_have = wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_private_impl__io__since(v_mark, ((uint64_t)(iop_a_src - io0_a_src)), io0_a_src)); + } + if (wuffs_base__status__is_ok(&v_status)) { + break; + } + status = v_status; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5); + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); + uint32_t t_3; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); + iop_a_src += 4; + } else { + self->private_data.s_do_decode_image_config.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); + 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_3 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3); + if (num_bits_3 == 24) { + t_3 = ((uint32_t)(*scratch >> 32)); + break; + } + num_bits_3 += 8u; + *scratch |= ((uint64_t)(num_bits_3)); + } + } + v_checksum_want = t_3; + } + if ( ! self->private_impl.f_ignore_checksum && (v_checksum_have != v_checksum_want)) { + status = wuffs_base__make_status(wuffs_png__error__bad_checksum); + goto exit; + } + self->private_impl.f_seen_ihdr = true; + } else if (self->private_impl.f_metadata_fourcc != 0u) { + self->private_impl.f_call_sequence = 16u; + status = wuffs_base__make_status(wuffs_base__note__metadata_reported); + goto ok; + } + while (true) { + if (((uint64_t)(io2_a_src - iop_a_src)) < 8u) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8); + continue; + } + self->private_impl.f_chunk_length = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); + self->private_impl.f_chunk_type = ((uint32_t)((wuffs_base__peek_u64le__no_bounds_check(iop_a_src) >> 32u))); + if (self->private_impl.f_chunk_type == 1413563465u) { + if ( ! self->private_impl.f_seen_actl || self->private_impl.f_seen_fctl) { + break; + } + self->private_impl.f_seen_idat = true; + } else if (self->private_impl.f_chunk_type == 1413571686u) { + if (self->private_impl.f_seen_idat && self->private_impl.f_seen_fctl) { + break; + } + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } + iop_a_src += 8u; + if ( ! self->private_impl.f_ignore_checksum && ((self->private_impl.f_chunk_type & 32u) == 0u)) { + self->private_impl.f_chunk_type_array[0u] = ((uint8_t)((self->private_impl.f_chunk_type >> 0u))); + self->private_impl.f_chunk_type_array[1u] = ((uint8_t)((self->private_impl.f_chunk_type >> 8u))); + self->private_impl.f_chunk_type_array[2u] = ((uint8_t)((self->private_impl.f_chunk_type >> 16u))); + self->private_impl.f_chunk_type_array[3u] = ((uint8_t)((self->private_impl.f_chunk_type >> 24u))); + wuffs_private_impl__ignore_status(wuffs_crc32__ieee_hasher__initialize(&self->private_data.f_crc32, + sizeof (wuffs_crc32__ieee_hasher), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED)); + wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__make_slice_u8(self->private_impl.f_chunk_type_array, 4)); + } + while (true) { + v_mark = ((uint64_t)(iop_a_src - io0_a_src)); + { + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + wuffs_base__status t_4 = wuffs_png__decoder__decode_other_chunk(self, a_src, false); + v_status = t_4; + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + } + if ( ! self->private_impl.f_ignore_checksum && ((self->private_impl.f_chunk_type & 32u) == 0u)) { + v_checksum_have = wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_private_impl__io__since(v_mark, ((uint64_t)(iop_a_src - io0_a_src)), io0_a_src)); + } + if (wuffs_base__status__is_ok(&v_status)) { + break; + } + status = v_status; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9); + } + if (self->private_impl.f_metadata_fourcc != 0u) { + self->private_impl.f_call_sequence = 16u; + status = wuffs_base__make_status(wuffs_base__note__metadata_reported); + goto ok; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10); + uint32_t t_5; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_5 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); + iop_a_src += 4; + } else { + self->private_data.s_do_decode_image_config.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11); + 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_5 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_5); + if (num_bits_5 == 24) { + t_5 = ((uint32_t)(*scratch >> 32)); + break; + } + num_bits_5 += 8u; + *scratch |= ((uint64_t)(num_bits_5)); + } + } + v_checksum_want = t_5; + } + if ( ! self->private_impl.f_ignore_checksum && ((self->private_impl.f_chunk_type & 32u) == 0u) && (v_checksum_have != v_checksum_want)) { + status = wuffs_base__make_status(wuffs_png__error__bad_checksum); + goto exit; + } } - v_curr.len = 3; - const uint8_t* i_end1_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 3) * 3)); - while (v_curr.ptr < i_end1_curr) { - v_fa0 = ((uint8_t)(v_fa0 + v_curr.ptr[0u])); - v_curr.ptr[0u] = v_fa0; - v_fa1 = ((uint8_t)(v_fa1 + v_curr.ptr[1u])); - v_curr.ptr[1u] = v_fa1; - v_fa2 = ((uint8_t)(v_fa2 + v_curr.ptr[2u])); - v_curr.ptr[2u] = v_fa2; - v_curr.ptr += 3; + if ((self->private_impl.f_color_type == 3u) && ! self->private_impl.f_seen_plte) { + status = wuffs_base__make_status(wuffs_png__error__missing_palette); + goto exit; } - v_curr.len = 0; - } - return wuffs_base__make_empty_struct(); -} + self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))); + self->private_impl.f_first_config_io_position = self->private_impl.f_frame_config_io_position; + if (a_dst != NULL) { + wuffs_base__image_config__set( + a_dst, + self->private_impl.f_dst_pixfmt, + 0u, + self->private_impl.f_width, + self->private_impl.f_height, + self->private_impl.f_first_config_io_position, + ((self->private_impl.f_color_type <= 3u) && ! self->private_impl.f_seen_trns)); + } + if ( ! self->private_impl.f_seen_actl) { + self->private_impl.f_num_animation_frames_value = 1u; + self->private_impl.f_first_rect_x0 = 0u; + self->private_impl.f_first_rect_y0 = 0u; + self->private_impl.f_first_rect_x1 = self->private_impl.f_width; + self->private_impl.f_first_rect_y1 = self->private_impl.f_height; + self->private_impl.f_first_duration = 0u; + self->private_impl.f_first_disposal = 0u; + self->private_impl.f_first_overwrite_instead_of_blend = false; + } + self->private_impl.f_call_sequence = 32u; -// -------- func png.decoder.filter_1_distance_4_fallback + ok: + self->private_impl.p_do_decode_image_config = 0; + goto exit; + } -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__filter_1_distance_4_fallback( - wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr) { - wuffs_base__slice_u8 v_curr = {0}; - uint8_t v_fa0 = 0; - uint8_t v_fa1 = 0; - uint8_t v_fa2 = 0; - uint8_t v_fa3 = 0; + goto suspend; + suspend: + self->private_impl.p_do_decode_image_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_data.s_do_decode_image_config.v_checksum_have = v_checksum_have; - { - wuffs_base__slice_u8 i_slice_curr = a_curr; - v_curr.ptr = i_slice_curr.ptr; - v_curr.len = 4; - const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 4) * 4)); - while (v_curr.ptr < i_end0_curr) { - v_fa0 = ((uint8_t)(v_fa0 + v_curr.ptr[0u])); - v_curr.ptr[0u] = v_fa0; - v_fa1 = ((uint8_t)(v_fa1 + v_curr.ptr[1u])); - v_curr.ptr[1u] = v_fa1; - v_fa2 = ((uint8_t)(v_fa2 + v_curr.ptr[2u])); - v_curr.ptr[2u] = v_fa2; - v_fa3 = ((uint8_t)(v_fa3 + v_curr.ptr[3u])); - v_curr.ptr[3u] = v_fa3; - v_curr.ptr += 4; - } - v_curr.len = 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 wuffs_base__make_empty_struct(); + + return status; } -// -------- func png.decoder.filter_2 +// -------- func png.decoder.decode_ihdr WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__filter_2( +static wuffs_base__status +wuffs_png__decoder__decode_ihdr( wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr, - wuffs_base__slice_u8 a_prev) { - uint64_t v_n = 0; - uint64_t v_i = 0; - - v_n = wuffs_base__u64__min(((uint64_t)(a_curr.len)), ((uint64_t)(a_prev.len))); - v_i = 0u; - while (v_i < v_n) { - a_curr.ptr[v_i] = ((uint8_t)(a_curr.ptr[v_i] + a_prev.ptr[v_i])); - v_i += 1u; - } - return wuffs_base__make_empty_struct(); -} + wuffs_base__io_buffer* a_src) { + wuffs_base__status status = wuffs_base__make_status(NULL); -// -------- func png.decoder.filter_3 + uint32_t v_a32 = 0; + uint8_t v_a8 = 0; -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__filter_3( - wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr, - wuffs_base__slice_u8 a_prev) { - return (*self->private_impl.choosy_filter_3)(self, a_curr, a_prev); -} + 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; + } -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__filter_3__choosy_default( - wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr, - wuffs_base__slice_u8 a_prev) { - uint64_t v_filter_distance = 0; - uint64_t v_n = 0; - uint64_t v_i = 0; + uint32_t coro_susp_point = self->private_impl.p_decode_ihdr; + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - v_filter_distance = ((uint64_t)(self->private_impl.f_filter_distance)); - if (((uint64_t)(a_prev.len)) == 0u) { - v_i = v_filter_distance; - while (v_i < ((uint64_t)(a_curr.len))) { - a_curr.ptr[v_i] = ((uint8_t)(a_curr.ptr[v_i] + ((uint8_t)(a_curr.ptr[(v_i - v_filter_distance)] / 2u)))); - v_i += 1u; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + uint32_t t_0; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_0 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); + iop_a_src += 4; + } else { + self->private_data.s_decode_ihdr.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_decode_ihdr.scratch; + uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0); + if (num_bits_0 == 24) { + t_0 = ((uint32_t)(*scratch >> 32)); + break; + } + num_bits_0 += 8u; + *scratch |= ((uint64_t)(num_bits_0)); + } + } + v_a32 = t_0; } - } else { - v_n = wuffs_base__u64__min(((uint64_t)(a_curr.len)), ((uint64_t)(a_prev.len))); - v_i = 0u; - while ((v_i < v_n) && (v_i < v_filter_distance)) { - a_curr.ptr[v_i] = ((uint8_t)(a_curr.ptr[v_i] + ((uint8_t)(a_prev.ptr[v_i] / 2u)))); - v_i += 1u; + if ((v_a32 == 0u) || (v_a32 > 2147483647u)) { + status = wuffs_base__make_status(wuffs_png__error__bad_header); + goto exit; + } else if (v_a32 > 16777215u) { + status = wuffs_base__make_status(wuffs_base__error__unsupported_image_dimension); + goto exit; } - v_i = v_filter_distance; - while (v_i < v_n) { - a_curr.ptr[v_i] = ((uint8_t)(a_curr.ptr[v_i] + ((uint8_t)(((((uint32_t)(a_curr.ptr[(v_i - v_filter_distance)])) + ((uint32_t)(a_prev.ptr[v_i]))) / 2u))))); - v_i += 1u; + self->private_impl.f_width = v_a32; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + uint32_t t_1; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_1 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); + iop_a_src += 4; + } else { + self->private_data.s_decode_ihdr.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + 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_decode_ihdr.scratch; + uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1); + if (num_bits_1 == 24) { + t_1 = ((uint32_t)(*scratch >> 32)); + break; + } + num_bits_1 += 8u; + *scratch |= ((uint64_t)(num_bits_1)); + } + } + v_a32 = t_1; } - } - return wuffs_base__make_empty_struct(); -} - -// -------- func png.decoder.filter_3_distance_3_fallback - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__filter_3_distance_3_fallback( - wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr, - wuffs_base__slice_u8 a_prev) { - wuffs_base__slice_u8 v_curr = {0}; - wuffs_base__slice_u8 v_prev = {0}; - uint8_t v_fa0 = 0; - uint8_t v_fa1 = 0; - uint8_t v_fa2 = 0; - - if (((uint64_t)(a_prev.len)) == 0u) { + if ((v_a32 == 0u) || (v_a32 > 2147483647u)) { + status = wuffs_base__make_status(wuffs_png__error__bad_header); + goto exit; + } else if (v_a32 > 16777215u) { + status = wuffs_base__make_status(wuffs_base__error__unsupported_image_dimension); + goto exit; + } + self->private_impl.f_height = v_a32; { - wuffs_base__slice_u8 i_slice_curr = a_curr; - v_curr.ptr = i_slice_curr.ptr; - v_curr.len = 3; - const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 6) * 6)); - while (v_curr.ptr < i_end0_curr) { - v_fa0 = ((uint8_t)(((uint8_t)(v_fa0 / 2u)) + v_curr.ptr[0u])); - v_curr.ptr[0u] = v_fa0; - v_fa1 = ((uint8_t)(((uint8_t)(v_fa1 / 2u)) + v_curr.ptr[1u])); - v_curr.ptr[1u] = v_fa1; - v_fa2 = ((uint8_t)(((uint8_t)(v_fa2 / 2u)) + v_curr.ptr[2u])); - v_curr.ptr[2u] = v_fa2; - v_curr.ptr += 3; - v_fa0 = ((uint8_t)(((uint8_t)(v_fa0 / 2u)) + v_curr.ptr[0u])); - v_curr.ptr[0u] = v_fa0; - v_fa1 = ((uint8_t)(((uint8_t)(v_fa1 / 2u)) + v_curr.ptr[1u])); - v_curr.ptr[1u] = v_fa1; - v_fa2 = ((uint8_t)(((uint8_t)(v_fa2 / 2u)) + v_curr.ptr[2u])); - v_curr.ptr[2u] = v_fa2; - v_curr.ptr += 3; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } - v_curr.len = 3; - const uint8_t* i_end1_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 3) * 3)); - while (v_curr.ptr < i_end1_curr) { - v_fa0 = ((uint8_t)(((uint8_t)(v_fa0 / 2u)) + v_curr.ptr[0u])); - v_curr.ptr[0u] = v_fa0; - v_fa1 = ((uint8_t)(((uint8_t)(v_fa1 / 2u)) + v_curr.ptr[1u])); - v_curr.ptr[1u] = v_fa1; - v_fa2 = ((uint8_t)(((uint8_t)(v_fa2 / 2u)) + v_curr.ptr[2u])); - v_curr.ptr[2u] = v_fa2; - v_curr.ptr += 3; + uint8_t t_2 = *iop_a_src++; + v_a8 = t_2; + } + if (v_a8 > 16u) { + status = wuffs_base__make_status(wuffs_png__error__bad_header); + goto exit; + } + self->private_impl.f_depth = v_a8; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } - v_curr.len = 0; + uint8_t t_3 = *iop_a_src++; + v_a8 = t_3; } - } else { + if ((v_a8 == 1u) || (v_a8 == 5u) || (v_a8 > 6u)) { + status = wuffs_base__make_status(wuffs_png__error__bad_header); + goto exit; + } + self->private_impl.f_color_type = v_a8; { - wuffs_base__slice_u8 i_slice_curr = a_curr; - v_curr.ptr = i_slice_curr.ptr; - wuffs_base__slice_u8 i_slice_prev = a_prev; - v_prev.ptr = i_slice_prev.ptr; - i_slice_curr.len = ((size_t)(wuffs_base__u64__min(i_slice_curr.len, i_slice_prev.len))); - v_curr.len = 3; - v_prev.len = 3; - const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 6) * 6)); - while (v_curr.ptr < i_end0_curr) { - v_fa0 = ((uint8_t)(((uint8_t)(((((uint32_t)(v_fa0)) + ((uint32_t)(v_prev.ptr[0u]))) / 2u))) + v_curr.ptr[0u])); - v_curr.ptr[0u] = v_fa0; - v_fa1 = ((uint8_t)(((uint8_t)(((((uint32_t)(v_fa1)) + ((uint32_t)(v_prev.ptr[1u]))) / 2u))) + v_curr.ptr[1u])); - v_curr.ptr[1u] = v_fa1; - v_fa2 = ((uint8_t)(((uint8_t)(((((uint32_t)(v_fa2)) + ((uint32_t)(v_prev.ptr[2u]))) / 2u))) + v_curr.ptr[2u])); - v_curr.ptr[2u] = v_fa2; - v_curr.ptr += 3; - v_prev.ptr += 3; - v_fa0 = ((uint8_t)(((uint8_t)(((((uint32_t)(v_fa0)) + ((uint32_t)(v_prev.ptr[0u]))) / 2u))) + v_curr.ptr[0u])); - v_curr.ptr[0u] = v_fa0; - v_fa1 = ((uint8_t)(((uint8_t)(((((uint32_t)(v_fa1)) + ((uint32_t)(v_prev.ptr[1u]))) / 2u))) + v_curr.ptr[1u])); - v_curr.ptr[1u] = v_fa1; - v_fa2 = ((uint8_t)(((uint8_t)(((((uint32_t)(v_fa2)) + ((uint32_t)(v_prev.ptr[2u]))) / 2u))) + v_curr.ptr[2u])); - v_curr.ptr[2u] = v_fa2; - v_curr.ptr += 3; - v_prev.ptr += 3; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } - v_curr.len = 3; - v_prev.len = 3; - const uint8_t* i_end1_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 3) * 3)); - while (v_curr.ptr < i_end1_curr) { - v_fa0 = ((uint8_t)(((uint8_t)(((((uint32_t)(v_fa0)) + ((uint32_t)(v_prev.ptr[0u]))) / 2u))) + v_curr.ptr[0u])); - v_curr.ptr[0u] = v_fa0; - v_fa1 = ((uint8_t)(((uint8_t)(((((uint32_t)(v_fa1)) + ((uint32_t)(v_prev.ptr[1u]))) / 2u))) + v_curr.ptr[1u])); - v_curr.ptr[1u] = v_fa1; - v_fa2 = ((uint8_t)(((uint8_t)(((((uint32_t)(v_fa2)) + ((uint32_t)(v_prev.ptr[2u]))) / 2u))) + v_curr.ptr[2u])); - v_curr.ptr[2u] = v_fa2; - v_curr.ptr += 3; - v_prev.ptr += 3; + uint8_t t_4 = *iop_a_src++; + v_a8 = t_4; + } + if (v_a8 != 0u) { + status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method); + goto exit; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } - v_curr.len = 0; - v_prev.len = 0; + uint8_t t_5 = *iop_a_src++; + v_a8 = t_5; + } + if (v_a8 != 0u) { + status = wuffs_base__make_status(wuffs_png__error__bad_header); + goto exit; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_6 = *iop_a_src++; + v_a8 = t_6; + } + if (v_a8 == 0u) { + self->private_impl.f_interlace_pass = 0u; + } else if (v_a8 == 1u) { + self->private_impl.f_interlace_pass = 1u; + self->private_impl.choosy_filter_and_swizzle = ( + &wuffs_png__decoder__filter_and_swizzle_tricky); + } else { + status = wuffs_base__make_status(wuffs_png__error__bad_header); + goto exit; + } + self->private_impl.f_filter_distance = 0u; + wuffs_png__decoder__assign_filter_distance(self); + if (self->private_impl.f_filter_distance == 0u) { + status = wuffs_base__make_status(wuffs_png__error__bad_header); + goto exit; } + self->private_impl.f_overall_workbuf_length = (((uint64_t)(self->private_impl.f_height)) * (1u + wuffs_png__decoder__calculate_bytes_per_row(self, self->private_impl.f_width))); + wuffs_png__decoder__choose_filter_implementations(self); + + goto ok; + ok: + self->private_impl.p_decode_ihdr = 0; + goto exit; } - return wuffs_base__make_empty_struct(); + + goto suspend; + suspend: + self->private_impl.p_decode_ihdr = 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 png.decoder.filter_3_distance_4_fallback +// -------- func png.decoder.assign_filter_distance WUFFS_BASE__GENERATED_C_CODE static wuffs_base__empty_struct -wuffs_png__decoder__filter_3_distance_4_fallback( - wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr, - wuffs_base__slice_u8 a_prev) { - wuffs_base__slice_u8 v_curr = {0}; - wuffs_base__slice_u8 v_prev = {0}; - uint8_t v_fa0 = 0; - uint8_t v_fa1 = 0; - uint8_t v_fa2 = 0; - uint8_t v_fa3 = 0; - - if (((uint64_t)(a_prev.len)) == 0u) { - { - wuffs_base__slice_u8 i_slice_curr = a_curr; - v_curr.ptr = i_slice_curr.ptr; - v_curr.len = 4; - const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 4) * 4)); - while (v_curr.ptr < i_end0_curr) { - v_fa0 = ((uint8_t)(((uint8_t)(v_fa0 / 2u)) + v_curr.ptr[0u])); - v_curr.ptr[0u] = v_fa0; - v_fa1 = ((uint8_t)(((uint8_t)(v_fa1 / 2u)) + v_curr.ptr[1u])); - v_curr.ptr[1u] = v_fa1; - v_fa2 = ((uint8_t)(((uint8_t)(v_fa2 / 2u)) + v_curr.ptr[2u])); - v_curr.ptr[2u] = v_fa2; - v_fa3 = ((uint8_t)(((uint8_t)(v_fa3 / 2u)) + v_curr.ptr[3u])); - v_curr.ptr[3u] = v_fa3; - v_curr.ptr += 4; - } - v_curr.len = 0; +wuffs_png__decoder__assign_filter_distance( + wuffs_png__decoder* self) { + if (self->private_impl.f_depth < 8u) { + if ((self->private_impl.f_depth != 1u) && (self->private_impl.f_depth != 2u) && (self->private_impl.f_depth != 4u)) { + return wuffs_base__make_empty_struct(); + } else if (self->private_impl.f_color_type == 0u) { + self->private_impl.f_dst_pixfmt = 536870920u; + self->private_impl.f_src_pixfmt = 536870920u; + } else if (self->private_impl.f_color_type == 3u) { + self->private_impl.f_dst_pixfmt = 2198077448u; + self->private_impl.f_src_pixfmt = 2198077448u; + } else { + return wuffs_base__make_empty_struct(); } - } else { - { - wuffs_base__slice_u8 i_slice_curr = a_curr; - v_curr.ptr = i_slice_curr.ptr; - wuffs_base__slice_u8 i_slice_prev = a_prev; - v_prev.ptr = i_slice_prev.ptr; - i_slice_curr.len = ((size_t)(wuffs_base__u64__min(i_slice_curr.len, i_slice_prev.len))); - v_curr.len = 4; - v_prev.len = 4; - const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 4) * 4)); - while (v_curr.ptr < i_end0_curr) { - v_fa0 = ((uint8_t)(((uint8_t)(((((uint32_t)(v_fa0)) + ((uint32_t)(v_prev.ptr[0u]))) / 2u))) + v_curr.ptr[0u])); - v_curr.ptr[0u] = v_fa0; - v_fa1 = ((uint8_t)(((uint8_t)(((((uint32_t)(v_fa1)) + ((uint32_t)(v_prev.ptr[1u]))) / 2u))) + v_curr.ptr[1u])); - v_curr.ptr[1u] = v_fa1; - v_fa2 = ((uint8_t)(((uint8_t)(((((uint32_t)(v_fa2)) + ((uint32_t)(v_prev.ptr[2u]))) / 2u))) + v_curr.ptr[2u])); - v_curr.ptr[2u] = v_fa2; - v_fa3 = ((uint8_t)(((uint8_t)(((((uint32_t)(v_fa3)) + ((uint32_t)(v_prev.ptr[3u]))) / 2u))) + v_curr.ptr[3u])); - v_curr.ptr[3u] = v_fa3; - v_curr.ptr += 4; - v_prev.ptr += 4; + self->private_impl.f_filter_distance = 1u; + self->private_impl.choosy_filter_and_swizzle = ( + &wuffs_png__decoder__filter_and_swizzle_tricky); + } else if (self->private_impl.f_color_type == 0u) { + if (self->private_impl.f_depth == 8u) { + self->private_impl.f_dst_pixfmt = 536870920u; + self->private_impl.f_src_pixfmt = 536870920u; + self->private_impl.f_filter_distance = 1u; + } else if (self->private_impl.f_depth == 16u) { + if (self->private_impl.f_interlace_pass == 0u) { + self->private_impl.f_dst_pixfmt = 536870923u; + self->private_impl.f_src_pixfmt = 537919499u; + } else { + self->private_impl.f_dst_pixfmt = 2164308923u; + self->private_impl.f_src_pixfmt = 2164308923u; } - v_curr.len = 0; - v_prev.len = 0; + self->private_impl.f_filter_distance = 2u; + } + } else if (self->private_impl.f_color_type == 2u) { + if (self->private_impl.f_depth == 8u) { + self->private_impl.f_dst_pixfmt = 2147485832u; + self->private_impl.f_src_pixfmt = 2684356744u; + self->private_impl.f_filter_distance = 3u; + } else if (self->private_impl.f_depth == 16u) { + self->private_impl.f_dst_pixfmt = 2164308923u; + self->private_impl.f_src_pixfmt = 2164308923u; + self->private_impl.f_filter_distance = 6u; + self->private_impl.choosy_filter_and_swizzle = ( + &wuffs_png__decoder__filter_and_swizzle_tricky); + } + } else if (self->private_impl.f_color_type == 3u) { + if (self->private_impl.f_depth == 8u) { + self->private_impl.f_dst_pixfmt = 2198077448u; + self->private_impl.f_src_pixfmt = 2198077448u; + self->private_impl.f_filter_distance = 1u; + } + } else if (self->private_impl.f_color_type == 4u) { + if (self->private_impl.f_depth == 8u) { + self->private_impl.f_dst_pixfmt = 553648264u; + self->private_impl.f_src_pixfmt = 553648264u; + self->private_impl.f_filter_distance = 2u; + } else if (self->private_impl.f_depth == 16u) { + self->private_impl.f_dst_pixfmt = 2164308923u; + self->private_impl.f_src_pixfmt = 2164308923u; + self->private_impl.f_filter_distance = 4u; + self->private_impl.choosy_filter_and_swizzle = ( + &wuffs_png__decoder__filter_and_swizzle_tricky); + } + } else if (self->private_impl.f_color_type == 6u) { + if (self->private_impl.f_depth == 8u) { + self->private_impl.f_dst_pixfmt = 2164295816u; + self->private_impl.f_src_pixfmt = 2701166728u; + self->private_impl.f_filter_distance = 4u; + } else if (self->private_impl.f_depth == 16u) { + self->private_impl.f_dst_pixfmt = 2164308923u; + self->private_impl.f_src_pixfmt = 2164308923u; + self->private_impl.f_filter_distance = 8u; + self->private_impl.choosy_filter_and_swizzle = ( + &wuffs_png__decoder__filter_and_swizzle_tricky); } } return wuffs_base__make_empty_struct(); } -// -------- func png.decoder.filter_4 +// -------- func png.decoder.calculate_bytes_per_row WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__filter_4( - wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr, - wuffs_base__slice_u8 a_prev) { - return (*self->private_impl.choosy_filter_4)(self, a_curr, a_prev); +static uint64_t +wuffs_png__decoder__calculate_bytes_per_row( + const wuffs_png__decoder* self, + uint32_t a_width) { + uint64_t v_bytes_per_channel = 0; + + if (self->private_impl.f_depth == 1u) { + return ((uint64_t)(((a_width + 7u) / 8u))); + } else if (self->private_impl.f_depth == 2u) { + return ((uint64_t)(((a_width + 3u) / 4u))); + } else if (self->private_impl.f_depth == 4u) { + return ((uint64_t)(((a_width + 1u) / 2u))); + } + v_bytes_per_channel = ((uint64_t)(((uint8_t)(self->private_impl.f_depth >> 3u)))); + return (((uint64_t)(a_width)) * v_bytes_per_channel * ((uint64_t)(WUFFS_PNG__NUM_CHANNELS[self->private_impl.f_color_type]))); } +// -------- func png.decoder.choose_filter_implementations + WUFFS_BASE__GENERATED_C_CODE static wuffs_base__empty_struct -wuffs_png__decoder__filter_4__choosy_default( - wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr, - wuffs_base__slice_u8 a_prev) { - uint64_t v_filter_distance = 0; - uint64_t v_n = 0; - uint64_t v_i = 0; - uint32_t v_fa = 0; - uint32_t v_fb = 0; - uint32_t v_fc = 0; - uint32_t v_pp = 0; - uint32_t v_pa = 0; - uint32_t v_pb = 0; - uint32_t v_pc = 0; - - v_filter_distance = ((uint64_t)(self->private_impl.f_filter_distance)); - v_n = wuffs_base__u64__min(((uint64_t)(a_curr.len)), ((uint64_t)(a_prev.len))); - v_i = 0u; - while ((v_i < v_n) && (v_i < v_filter_distance)) { - a_curr.ptr[v_i] = ((uint8_t)(a_curr.ptr[v_i] + a_prev.ptr[v_i])); - v_i += 1u; - } - v_i = v_filter_distance; - while (v_i < v_n) { - v_fa = ((uint32_t)(a_curr.ptr[(v_i - v_filter_distance)])); - v_fb = ((uint32_t)(a_prev.ptr[v_i])); - v_fc = ((uint32_t)(a_prev.ptr[(v_i - v_filter_distance)])); - v_pp = ((uint32_t)(((uint32_t)(v_fa + v_fb)) - v_fc)); - v_pa = ((uint32_t)(v_pp - v_fa)); - if (v_pa >= 2147483648u) { - v_pa = ((uint32_t)(0u - v_pa)); - } - v_pb = ((uint32_t)(v_pp - v_fb)); - if (v_pb >= 2147483648u) { - v_pb = ((uint32_t)(0u - v_pb)); - } - v_pc = ((uint32_t)(v_pp - v_fc)); - if (v_pc >= 2147483648u) { - v_pc = ((uint32_t)(0u - v_pc)); - } - if ((v_pa <= v_pb) && (v_pa <= v_pc)) { - } else if (v_pb <= v_pc) { - v_fa = v_fb; - } else { - v_fa = v_fc; - } - a_curr.ptr[v_i] = ((uint8_t)(a_curr.ptr[v_i] + ((uint8_t)(v_fa)))); - v_i += 1u; +wuffs_png__decoder__choose_filter_implementations( + wuffs_png__decoder* self) { + if (self->private_impl.f_filter_distance == 3u) { + self->private_impl.choosy_filter_1 = ( + &wuffs_png__decoder__filter_1_distance_3_fallback); + self->private_impl.choosy_filter_3 = ( + &wuffs_png__decoder__filter_3_distance_3_fallback); + self->private_impl.choosy_filter_4 = ( +#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON) + wuffs_base__cpu_arch__have_arm_neon() ? &wuffs_png__decoder__filter_4_distance_3_arm_neon : +#endif +#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) + wuffs_base__cpu_arch__have_x86_sse42() ? &wuffs_png__decoder__filter_4_distance_3_x86_sse42 : +#endif + &wuffs_png__decoder__filter_4_distance_3_fallback); + } else if (self->private_impl.f_filter_distance == 4u) { + self->private_impl.choosy_filter_1 = ( +#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON) + wuffs_base__cpu_arch__have_arm_neon() ? &wuffs_png__decoder__filter_1_distance_4_arm_neon : +#endif +#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) + wuffs_base__cpu_arch__have_x86_sse42() ? &wuffs_png__decoder__filter_1_distance_4_x86_sse42 : +#endif + &wuffs_png__decoder__filter_1_distance_4_fallback); + self->private_impl.choosy_filter_3 = ( +#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON) + wuffs_base__cpu_arch__have_arm_neon() ? &wuffs_png__decoder__filter_3_distance_4_arm_neon : +#endif +#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) + wuffs_base__cpu_arch__have_x86_sse42() ? &wuffs_png__decoder__filter_3_distance_4_x86_sse42 : +#endif + &wuffs_png__decoder__filter_3_distance_4_fallback); + self->private_impl.choosy_filter_4 = ( +#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON) + wuffs_base__cpu_arch__have_arm_neon() ? &wuffs_png__decoder__filter_4_distance_4_arm_neon : +#endif +#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) + wuffs_base__cpu_arch__have_x86_sse42() ? &wuffs_png__decoder__filter_4_distance_4_x86_sse42 : +#endif + &wuffs_png__decoder__filter_4_distance_4_fallback); } return wuffs_base__make_empty_struct(); } -// -------- func png.decoder.filter_4_distance_3_fallback +// -------- func png.decoder.decode_other_chunk WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__filter_4_distance_3_fallback( +static wuffs_base__status +wuffs_png__decoder__decode_other_chunk( wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr, - wuffs_base__slice_u8 a_prev) { - wuffs_base__slice_u8 v_curr = {0}; - wuffs_base__slice_u8 v_prev = {0}; - uint32_t v_fa0 = 0; - uint32_t v_fa1 = 0; - uint32_t v_fa2 = 0; - uint32_t v_fb0 = 0; - uint32_t v_fb1 = 0; - uint32_t v_fb2 = 0; - uint32_t v_fc0 = 0; - uint32_t v_fc1 = 0; - uint32_t v_fc2 = 0; - uint32_t v_pp0 = 0; - uint32_t v_pp1 = 0; - uint32_t v_pp2 = 0; - uint32_t v_pa0 = 0; - uint32_t v_pa1 = 0; - uint32_t v_pa2 = 0; - uint32_t v_pb0 = 0; - uint32_t v_pb1 = 0; - uint32_t v_pb2 = 0; - uint32_t v_pc0 = 0; - uint32_t v_pc1 = 0; - uint32_t v_pc2 = 0; + wuffs_base__io_buffer* a_src, + bool a_framy) { + wuffs_base__status status = wuffs_base__make_status(NULL); - { - wuffs_base__slice_u8 i_slice_curr = a_curr; - v_curr.ptr = i_slice_curr.ptr; - wuffs_base__slice_u8 i_slice_prev = a_prev; - v_prev.ptr = i_slice_prev.ptr; - i_slice_curr.len = ((size_t)(wuffs_base__u64__min(i_slice_curr.len, i_slice_prev.len))); - v_curr.len = 3; - v_prev.len = 3; - const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 3) * 3)); - while (v_curr.ptr < i_end0_curr) { - v_fb0 = ((uint32_t)(v_prev.ptr[0u])); - v_pp0 = ((uint32_t)(((uint32_t)(v_fa0 + v_fb0)) - v_fc0)); - v_pa0 = ((uint32_t)(v_pp0 - v_fa0)); - if (v_pa0 >= 2147483648u) { - v_pa0 = ((uint32_t)(0u - v_pa0)); - } - v_pb0 = ((uint32_t)(v_pp0 - v_fb0)); - if (v_pb0 >= 2147483648u) { - v_pb0 = ((uint32_t)(0u - v_pb0)); - } - v_pc0 = ((uint32_t)(v_pp0 - v_fc0)); - if (v_pc0 >= 2147483648u) { - v_pc0 = ((uint32_t)(0u - v_pc0)); - } - if ((v_pa0 <= v_pb0) && (v_pa0 <= v_pc0)) { - } else if (v_pb0 <= v_pc0) { - v_fa0 = v_fb0; + 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_decode_other_chunk; + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + + if ((self->private_impl.f_chunk_type == 1163152464u) && ! a_framy) { + if (self->private_impl.f_seen_plte) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } else if (self->private_impl.f_color_type == 3u) { + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + status = wuffs_png__decoder__decode_plte(self, 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_color_type == 2u) || (self->private_impl.f_color_type == 6u)) { } else { - v_fa0 = v_fc0; - } - v_curr.ptr[0u] = ((uint8_t)(v_curr.ptr[0u] + ((uint8_t)(v_fa0)))); - v_fa0 = ((uint32_t)(v_curr.ptr[0u])); - v_fc0 = v_fb0; - v_fb1 = ((uint32_t)(v_prev.ptr[1u])); - v_pp1 = ((uint32_t)(((uint32_t)(v_fa1 + v_fb1)) - v_fc1)); - v_pa1 = ((uint32_t)(v_pp1 - v_fa1)); - if (v_pa1 >= 2147483648u) { - v_pa1 = ((uint32_t)(0u - v_pa1)); + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; } - v_pb1 = ((uint32_t)(v_pp1 - v_fb1)); - if (v_pb1 >= 2147483648u) { - v_pb1 = ((uint32_t)(0u - v_pb1)); + self->private_impl.f_seen_plte = true; + } else if ((self->private_impl.f_chunk_type & 32u) == 0u) { + if (self->private_impl.f_chunk_type != 1413563465u) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; } - v_pc1 = ((uint32_t)(v_pp1 - v_fc1)); - if (v_pc1 >= 2147483648u) { - v_pc1 = ((uint32_t)(0u - v_pc1)); + } + if (self->private_impl.f_chunk_type == 1716082789u) { + if (self->private_impl.f_report_metadata_exif) { + if (self->private_impl.f_seen_exif) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); + status = wuffs_png__decoder__decode_exif(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } + self->private_impl.f_seen_exif = true; } - if ((v_pa1 <= v_pb1) && (v_pa1 <= v_pc1)) { - } else if (v_pb1 <= v_pc1) { - v_fa1 = v_fb1; - } else { - v_fa1 = v_fc1; + } else if ((self->private_impl.f_chunk_type == 1951945833u) || (self->private_impl.f_chunk_type == 1951942004u) || (self->private_impl.f_chunk_type == 1951945850u)) { + if (self->private_impl.f_report_metadata_kvp) { + self->private_impl.f_metadata_flavor = 4u; + self->private_impl.f_metadata_fourcc = 1263947851u; + self->private_impl.f_metadata_x = 0u; + self->private_impl.f_metadata_y = 0u; + self->private_impl.f_metadata_z = 0u; } - v_curr.ptr[1u] = ((uint8_t)(v_curr.ptr[1u] + ((uint8_t)(v_fa1)))); - v_fa1 = ((uint32_t)(v_curr.ptr[1u])); - v_fc1 = v_fb1; - v_fb2 = ((uint32_t)(v_prev.ptr[2u])); - v_pp2 = ((uint32_t)(((uint32_t)(v_fa2 + v_fb2)) - v_fc2)); - v_pa2 = ((uint32_t)(v_pp2 - v_fa2)); - if (v_pa2 >= 2147483648u) { - v_pa2 = ((uint32_t)(0u - v_pa2)); + } else if ( ! a_framy) { + if (self->private_impl.f_chunk_type == 1280598881u) { + if (self->private_impl.f_seen_actl) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + status = wuffs_png__decoder__decode_actl(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } + self->private_impl.f_seen_actl = true; + } else if (self->private_impl.f_chunk_type == 1297238115u) { + if (self->private_impl.f_report_metadata_chrm) { + if (self->private_impl.f_seen_chrm) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + status = wuffs_png__decoder__decode_chrm(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } + self->private_impl.f_seen_chrm = true; + } + } else if (self->private_impl.f_chunk_type == 1280598886u) { + if (self->private_impl.f_seen_fctl) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); + status = wuffs_png__decoder__decode_fctl(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } + self->private_impl.f_seen_fctl = true; + } else if (self->private_impl.f_chunk_type == 1095582055u) { + if (self->private_impl.f_report_metadata_gama) { + if (self->private_impl.f_seen_gama) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); + status = wuffs_png__decoder__decode_gama(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } + self->private_impl.f_seen_gama = true; + } + } else if (self->private_impl.f_chunk_type == 1346585449u) { + if (self->private_impl.f_report_metadata_iccp) { + if (self->private_impl.f_seen_iccp) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); + status = wuffs_png__decoder__decode_iccp(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } + self->private_impl.f_seen_iccp = true; + } + } else if (self->private_impl.f_chunk_type == 1111970419u) { + if (self->private_impl.f_report_metadata_srgb) { + if (self->private_impl.f_seen_srgb) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); + status = wuffs_png__decoder__decode_srgb(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } + self->private_impl.f_seen_srgb = true; + } + } else if (self->private_impl.f_chunk_type == 1397641844u) { + if (self->private_impl.f_seen_trns || ((self->private_impl.f_color_type == 3u) && ! self->private_impl.f_seen_plte)) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } else if (self->private_impl.f_color_type > 3u) { + } else { + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); + status = wuffs_png__decoder__decode_trns(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } + } + self->private_impl.f_seen_trns = true; } - v_pb2 = ((uint32_t)(v_pp2 - v_fb2)); - if (v_pb2 >= 2147483648u) { - v_pb2 = ((uint32_t)(0u - v_pb2)); + } + if (self->private_impl.f_metadata_fourcc == 0u) { + self->private_data.s_decode_other_chunk.scratch = self->private_impl.f_chunk_length; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10); + if (self->private_data.s_decode_other_chunk.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { + self->private_data.s_decode_other_chunk.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); + iop_a_src = io2_a_src; + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } - v_pc2 = ((uint32_t)(v_pp2 - v_fc2)); - if (v_pc2 >= 2147483648u) { - v_pc2 = ((uint32_t)(0u - v_pc2)); + iop_a_src += self->private_data.s_decode_other_chunk.scratch; + } + + goto ok; + ok: + self->private_impl.p_decode_other_chunk = 0; + goto exit; + } + + goto suspend; + suspend: + self->private_impl.p_decode_other_chunk = 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 png.decoder.decode_actl + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_png__decoder__decode_actl( + wuffs_png__decoder* self, + 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_decode_actl; + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + + if (self->private_impl.f_chunk_length != 8u) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } else if (self->private_impl.f_interlace_pass > 0u) { + status = wuffs_base__make_status(wuffs_png__error__unsupported_png_file); + goto exit; + } + self->private_impl.f_chunk_length = 0u; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + uint32_t t_0; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_0 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); + iop_a_src += 4; + } else { + self->private_data.s_decode_actl.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_decode_actl.scratch; + uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0); + if (num_bits_0 == 24) { + t_0 = ((uint32_t)(*scratch >> 32)); + break; + } + num_bits_0 += 8u; + *scratch |= ((uint64_t)(num_bits_0)); + } } - if ((v_pa2 <= v_pb2) && (v_pa2 <= v_pc2)) { - } else if (v_pb2 <= v_pc2) { - v_fa2 = v_fb2; + self->private_impl.f_num_animation_frames_value = t_0; + } + if (self->private_impl.f_num_animation_frames_value == 0u) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + uint32_t t_1; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_1 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); + iop_a_src += 4; } else { - v_fa2 = v_fc2; + self->private_data.s_decode_actl.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + 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_decode_actl.scratch; + uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1); + if (num_bits_1 == 24) { + t_1 = ((uint32_t)(*scratch >> 32)); + break; + } + num_bits_1 += 8u; + *scratch |= ((uint64_t)(num_bits_1)); + } } - v_curr.ptr[2u] = ((uint8_t)(v_curr.ptr[2u] + ((uint8_t)(v_fa2)))); - v_fa2 = ((uint32_t)(v_curr.ptr[2u])); - v_fc2 = v_fb2; - v_curr.ptr += 3; - v_prev.ptr += 3; + self->private_impl.f_num_animation_loops_value = t_1; } - v_curr.len = 0; - v_prev.len = 0; + + goto ok; + ok: + self->private_impl.p_decode_actl = 0; + goto exit; } - return wuffs_base__make_empty_struct(); + + goto suspend; + suspend: + self->private_impl.p_decode_actl = 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 png.decoder.filter_4_distance_4_fallback +// -------- func png.decoder.decode_chrm WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__filter_4_distance_4_fallback( +static wuffs_base__status +wuffs_png__decoder__decode_chrm( wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr, - wuffs_base__slice_u8 a_prev) { - wuffs_base__slice_u8 v_curr = {0}; - wuffs_base__slice_u8 v_prev = {0}; - uint32_t v_fa0 = 0; - uint32_t v_fa1 = 0; - uint32_t v_fa2 = 0; - uint32_t v_fa3 = 0; - uint32_t v_fb0 = 0; - uint32_t v_fb1 = 0; - uint32_t v_fb2 = 0; - uint32_t v_fb3 = 0; - uint32_t v_fc0 = 0; - uint32_t v_fc1 = 0; - uint32_t v_fc2 = 0; - uint32_t v_fc3 = 0; - uint32_t v_pp0 = 0; - uint32_t v_pp1 = 0; - uint32_t v_pp2 = 0; - uint32_t v_pp3 = 0; - uint32_t v_pa0 = 0; - uint32_t v_pa1 = 0; - uint32_t v_pa2 = 0; - uint32_t v_pa3 = 0; - uint32_t v_pb0 = 0; - uint32_t v_pb1 = 0; - uint32_t v_pb2 = 0; - uint32_t v_pb3 = 0; - uint32_t v_pc0 = 0; - uint32_t v_pc1 = 0; - uint32_t v_pc2 = 0; - uint32_t v_pc3 = 0; + wuffs_base__io_buffer* a_src) { + wuffs_base__status status = wuffs_base__make_status(NULL); - { - wuffs_base__slice_u8 i_slice_curr = a_curr; - v_curr.ptr = i_slice_curr.ptr; - wuffs_base__slice_u8 i_slice_prev = a_prev; - v_prev.ptr = i_slice_prev.ptr; - i_slice_curr.len = ((size_t)(wuffs_base__u64__min(i_slice_curr.len, i_slice_prev.len))); - v_curr.len = 4; - v_prev.len = 4; - const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 4) * 4)); - while (v_curr.ptr < i_end0_curr) { - v_fb0 = ((uint32_t)(v_prev.ptr[0u])); - v_pp0 = ((uint32_t)(((uint32_t)(v_fa0 + v_fb0)) - v_fc0)); - v_pa0 = ((uint32_t)(v_pp0 - v_fa0)); - if (v_pa0 >= 2147483648u) { - v_pa0 = ((uint32_t)(0u - v_pa0)); - } - v_pb0 = ((uint32_t)(v_pp0 - v_fb0)); - if (v_pb0 >= 2147483648u) { - v_pb0 = ((uint32_t)(0u - v_pb0)); - } - v_pc0 = ((uint32_t)(v_pp0 - v_fc0)); - if (v_pc0 >= 2147483648u) { - v_pc0 = ((uint32_t)(0u - v_pc0)); - } - if ((v_pa0 <= v_pb0) && (v_pa0 <= v_pc0)) { - } else if (v_pb0 <= v_pc0) { - v_fa0 = v_fb0; + uint64_t v_u = 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_decode_chrm; + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + + if (self->private_impl.f_chunk_length != 32u) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } + self->private_impl.f_chunk_length = 0u; + self->private_impl.f_metadata_flavor = 5u; + self->private_impl.f_metadata_fourcc = 1128813133u; + self->private_impl.f_metadata_x = 0u; + self->private_impl.f_metadata_y = 0u; + self->private_impl.f_metadata_z = 0u; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + uint64_t t_0; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_0 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src))); + iop_a_src += 4; } else { - v_fa0 = v_fc0; - } - v_curr.ptr[0u] = ((uint8_t)(v_curr.ptr[0u] + ((uint8_t)(v_fa0)))); - v_fa0 = ((uint32_t)(v_curr.ptr[0u])); - v_fc0 = v_fb0; - v_fb1 = ((uint32_t)(v_prev.ptr[1u])); - v_pp1 = ((uint32_t)(((uint32_t)(v_fa1 + v_fb1)) - v_fc1)); - v_pa1 = ((uint32_t)(v_pp1 - v_fa1)); - if (v_pa1 >= 2147483648u) { - v_pa1 = ((uint32_t)(0u - v_pa1)); - } - v_pb1 = ((uint32_t)(v_pp1 - v_fb1)); - if (v_pb1 >= 2147483648u) { - v_pb1 = ((uint32_t)(0u - v_pb1)); - } - v_pc1 = ((uint32_t)(v_pp1 - v_fc1)); - if (v_pc1 >= 2147483648u) { - v_pc1 = ((uint32_t)(0u - v_pc1)); + self->private_data.s_decode_chrm.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_decode_chrm.scratch; + uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0); + if (num_bits_0 == 24) { + t_0 = ((uint64_t)(*scratch >> 32)); + break; + } + num_bits_0 += 8u; + *scratch |= ((uint64_t)(num_bits_0)); + } } - if ((v_pa1 <= v_pb1) && (v_pa1 <= v_pc1)) { - } else if (v_pb1 <= v_pc1) { - v_fa1 = v_fb1; + v_u = t_0; + } + self->private_impl.f_metadata_x |= ((16777215u & v_u) << 0u); + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + uint64_t t_1; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_1 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src))); + iop_a_src += 4; } else { - v_fa1 = v_fc1; - } - v_curr.ptr[1u] = ((uint8_t)(v_curr.ptr[1u] + ((uint8_t)(v_fa1)))); - v_fa1 = ((uint32_t)(v_curr.ptr[1u])); - v_fc1 = v_fb1; - v_fb2 = ((uint32_t)(v_prev.ptr[2u])); - v_pp2 = ((uint32_t)(((uint32_t)(v_fa2 + v_fb2)) - v_fc2)); - v_pa2 = ((uint32_t)(v_pp2 - v_fa2)); - if (v_pa2 >= 2147483648u) { - v_pa2 = ((uint32_t)(0u - v_pa2)); - } - v_pb2 = ((uint32_t)(v_pp2 - v_fb2)); - if (v_pb2 >= 2147483648u) { - v_pb2 = ((uint32_t)(0u - v_pb2)); + self->private_data.s_decode_chrm.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + 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_decode_chrm.scratch; + uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1); + if (num_bits_1 == 24) { + t_1 = ((uint64_t)(*scratch >> 32)); + break; + } + num_bits_1 += 8u; + *scratch |= ((uint64_t)(num_bits_1)); + } } - v_pc2 = ((uint32_t)(v_pp2 - v_fc2)); - if (v_pc2 >= 2147483648u) { - v_pc2 = ((uint32_t)(0u - v_pc2)); + v_u = t_1; + } + self->private_impl.f_metadata_x |= ((16777215u & v_u) << 24u); + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); + uint64_t t_2; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_2 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src))); + iop_a_src += 4; + } else { + self->private_data.s_decode_chrm.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); + 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_decode_chrm.scratch; + uint32_t num_bits_2 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_2); + if (num_bits_2 == 24) { + t_2 = ((uint64_t)(*scratch >> 32)); + break; + } + num_bits_2 += 8u; + *scratch |= ((uint64_t)(num_bits_2)); + } } - if ((v_pa2 <= v_pb2) && (v_pa2 <= v_pc2)) { - } else if (v_pb2 <= v_pc2) { - v_fa2 = v_fb2; + v_u = t_2; + } + self->private_impl.f_metadata_x |= ((uint64_t)((16777215u & v_u) << 48u)); + self->private_impl.f_metadata_y |= ((16777215u & v_u) >> 16u); + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); + uint64_t t_3; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_3 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src))); + iop_a_src += 4; } else { - v_fa2 = v_fc2; + self->private_data.s_decode_chrm.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); + 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_decode_chrm.scratch; + uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3); + if (num_bits_3 == 24) { + t_3 = ((uint64_t)(*scratch >> 32)); + break; + } + num_bits_3 += 8u; + *scratch |= ((uint64_t)(num_bits_3)); + } } - v_curr.ptr[2u] = ((uint8_t)(v_curr.ptr[2u] + ((uint8_t)(v_fa2)))); - v_fa2 = ((uint32_t)(v_curr.ptr[2u])); - v_fc2 = v_fb2; - v_fb3 = ((uint32_t)(v_prev.ptr[3u])); - v_pp3 = ((uint32_t)(((uint32_t)(v_fa3 + v_fb3)) - v_fc3)); - v_pa3 = ((uint32_t)(v_pp3 - v_fa3)); - if (v_pa3 >= 2147483648u) { - v_pa3 = ((uint32_t)(0u - v_pa3)); + v_u = t_3; + } + self->private_impl.f_metadata_y |= ((16777215u & v_u) << 8u); + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); + uint64_t t_4; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_4 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src))); + iop_a_src += 4; + } else { + self->private_data.s_decode_chrm.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10); + 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_decode_chrm.scratch; + uint32_t num_bits_4 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_4); + if (num_bits_4 == 24) { + t_4 = ((uint64_t)(*scratch >> 32)); + break; + } + num_bits_4 += 8u; + *scratch |= ((uint64_t)(num_bits_4)); + } } - v_pb3 = ((uint32_t)(v_pp3 - v_fb3)); - if (v_pb3 >= 2147483648u) { - v_pb3 = ((uint32_t)(0u - v_pb3)); + v_u = t_4; + } + self->private_impl.f_metadata_y |= ((16777215u & v_u) << 32u); + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11); + uint64_t t_5; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_5 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src))); + iop_a_src += 4; + } else { + self->private_data.s_decode_chrm.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12); + 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_decode_chrm.scratch; + uint32_t num_bits_5 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_5); + if (num_bits_5 == 24) { + t_5 = ((uint64_t)(*scratch >> 32)); + break; + } + num_bits_5 += 8u; + *scratch |= ((uint64_t)(num_bits_5)); + } } - v_pc3 = ((uint32_t)(v_pp3 - v_fc3)); - if (v_pc3 >= 2147483648u) { - v_pc3 = ((uint32_t)(0u - v_pc3)); + v_u = t_5; + } + self->private_impl.f_metadata_y |= ((uint64_t)((16777215u & v_u) << 56u)); + self->private_impl.f_metadata_z |= ((16777215u & v_u) >> 8u); + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13); + uint64_t t_6; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_6 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src))); + iop_a_src += 4; + } else { + self->private_data.s_decode_chrm.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(14); + 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_decode_chrm.scratch; + uint32_t num_bits_6 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_6); + if (num_bits_6 == 24) { + t_6 = ((uint64_t)(*scratch >> 32)); + break; + } + num_bits_6 += 8u; + *scratch |= ((uint64_t)(num_bits_6)); + } } - if ((v_pa3 <= v_pb3) && (v_pa3 <= v_pc3)) { - } else if (v_pb3 <= v_pc3) { - v_fa3 = v_fb3; + v_u = t_6; + } + self->private_impl.f_metadata_z |= ((16777215u & v_u) << 16u); + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15); + uint64_t t_7; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_7 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src))); + iop_a_src += 4; } else { - v_fa3 = v_fc3; + self->private_data.s_decode_chrm.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16); + 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_decode_chrm.scratch; + uint32_t num_bits_7 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_7); + if (num_bits_7 == 24) { + t_7 = ((uint64_t)(*scratch >> 32)); + break; + } + num_bits_7 += 8u; + *scratch |= ((uint64_t)(num_bits_7)); + } } - v_curr.ptr[3u] = ((uint8_t)(v_curr.ptr[3u] + ((uint8_t)(v_fa3)))); - v_fa3 = ((uint32_t)(v_curr.ptr[3u])); - v_fc3 = v_fb3; - v_curr.ptr += 4; - v_prev.ptr += 4; + v_u = t_7; } - v_curr.len = 0; - v_prev.len = 0; + self->private_impl.f_metadata_z |= ((16777215u & v_u) << 40u); + + goto ok; + ok: + self->private_impl.p_decode_chrm = 0; + goto exit; } - return wuffs_base__make_empty_struct(); + + goto suspend; + suspend: + self->private_impl.p_decode_chrm = 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 png.decoder.decode_exif + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_png__decoder__decode_exif( + wuffs_png__decoder* self, + 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; + } + + if (self->private_impl.f_chunk_length < 4u) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } + self->private_impl.f_metadata_flavor = 3u; + self->private_impl.f_metadata_fourcc = 1163413830u; + self->private_impl.f_metadata_x = 0u; + self->private_impl.f_metadata_y = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))); + self->private_impl.f_metadata_z = wuffs_base__u64__sat_add(self->private_impl.f_metadata_y, ((uint64_t)(self->private_impl.f_chunk_length))); + self->private_impl.f_chunk_length = 0u; + + goto ok; + ok: + 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; } -// ‼ WUFFS MULTI-FILE SECTION +x86_sse42 -// -------- func png.decoder.filter_1_distance_4_x86_sse42 +// -------- func png.decoder.decode_fctl -#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) -WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2") WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__filter_1_distance_4_x86_sse42( +static wuffs_base__status +wuffs_png__decoder__decode_fctl( wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr) { - wuffs_base__slice_u8 v_curr = {0}; - __m128i v_x128 = {0}; - __m128i v_a128 = {0}; + wuffs_base__io_buffer* a_src) { + wuffs_base__status status = wuffs_base__make_status(NULL); - { - wuffs_base__slice_u8 i_slice_curr = a_curr; - v_curr.ptr = i_slice_curr.ptr; - v_curr.len = 4; - const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 8) * 8)); - while (v_curr.ptr < i_end0_curr) { - v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_x128 = _mm_add_epi8(v_x128, v_a128); - v_a128 = v_x128; - wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); - v_curr.ptr += 4; - v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_x128 = _mm_add_epi8(v_x128, v_a128); - v_a128 = v_x128; - wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); - v_curr.ptr += 4; - } - v_curr.len = 4; - const uint8_t* i_end1_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 4) * 4)); - while (v_curr.ptr < i_end1_curr) { - v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_x128 = _mm_add_epi8(v_x128, v_a128); - v_a128 = v_x128; - wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); - v_curr.ptr += 4; - } - v_curr.len = 0; - } - return wuffs_base__make_empty_struct(); -} -#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) -// ‼ WUFFS MULTI-FILE SECTION -x86_sse42 + uint32_t v_x0 = 0; + uint32_t v_y0 = 0; + uint32_t v_x1 = 0; + uint32_t v_y1 = 0; -// ‼ WUFFS MULTI-FILE SECTION +x86_sse42 -// -------- func png.decoder.filter_3_distance_4_x86_sse42 + 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; + } -#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) -WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2") -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__filter_3_distance_4_x86_sse42( - wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr, - wuffs_base__slice_u8 a_prev) { - wuffs_base__slice_u8 v_curr = {0}; - wuffs_base__slice_u8 v_prev = {0}; - __m128i v_x128 = {0}; - __m128i v_a128 = {0}; - __m128i v_b128 = {0}; - __m128i v_p128 = {0}; - __m128i v_k128 = {0}; + uint32_t coro_susp_point = self->private_impl.p_decode_fctl; + if (coro_susp_point) { + v_x0 = self->private_data.s_decode_fctl.v_x0; + v_x1 = self->private_data.s_decode_fctl.v_x1; + v_y1 = self->private_data.s_decode_fctl.v_y1; + } + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - if (((uint64_t)(a_prev.len)) == 0u) { - v_k128 = _mm_set1_epi8((int8_t)(254u)); + if (self->private_impl.f_chunk_length != 26u) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } + self->private_impl.f_chunk_length = 0u; { - wuffs_base__slice_u8 i_slice_curr = a_curr; - v_curr.ptr = i_slice_curr.ptr; - v_curr.len = 4; - const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 8) * 8)); - while (v_curr.ptr < i_end0_curr) { - v_p128 = _mm_avg_epu8(_mm_and_si128(v_a128, v_k128), v_b128); - v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_x128 = _mm_add_epi8(v_x128, v_p128); - v_a128 = v_x128; - wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); - v_curr.ptr += 4; - v_p128 = _mm_avg_epu8(_mm_and_si128(v_a128, v_k128), v_b128); - v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_x128 = _mm_add_epi8(v_x128, v_p128); - v_a128 = v_x128; - wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); - v_curr.ptr += 4; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + uint32_t t_0; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_0 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); + iop_a_src += 4; + } else { + self->private_data.s_decode_fctl.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_decode_fctl.scratch; + uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0); + if (num_bits_0 == 24) { + t_0 = ((uint32_t)(*scratch >> 32)); + break; + } + num_bits_0 += 8u; + *scratch |= ((uint64_t)(num_bits_0)); + } } - v_curr.len = 4; - const uint8_t* i_end1_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 4) * 4)); - while (v_curr.ptr < i_end1_curr) { - v_p128 = _mm_avg_epu8(_mm_and_si128(v_a128, v_k128), v_b128); - v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_x128 = _mm_add_epi8(v_x128, v_p128); - v_a128 = v_x128; - wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); - v_curr.ptr += 4; + v_x0 = t_0; + } + if (v_x0 != self->private_impl.f_next_animation_seq_num) { + status = wuffs_base__make_status(wuffs_png__error__bad_animation_sequence_number); + goto exit; + } else if (self->private_impl.f_next_animation_seq_num >= 4294967295u) { + status = wuffs_base__make_status(wuffs_png__error__unsupported_png_file); + goto exit; + } + self->private_impl.f_next_animation_seq_num += 1u; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + uint32_t t_1; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_1 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); + iop_a_src += 4; + } else { + self->private_data.s_decode_fctl.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + 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_decode_fctl.scratch; + uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1); + if (num_bits_1 == 24) { + t_1 = ((uint32_t)(*scratch >> 32)); + break; + } + num_bits_1 += 8u; + *scratch |= ((uint64_t)(num_bits_1)); + } } - v_curr.len = 0; + v_x1 = t_1; } - } else { - v_k128 = _mm_set1_epi8((int8_t)(1u)); { - wuffs_base__slice_u8 i_slice_curr = a_curr; - v_curr.ptr = i_slice_curr.ptr; - wuffs_base__slice_u8 i_slice_prev = a_prev; - v_prev.ptr = i_slice_prev.ptr; - i_slice_curr.len = ((size_t)(wuffs_base__u64__min(i_slice_curr.len, i_slice_prev.len))); - v_curr.len = 4; - v_prev.len = 4; - const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 8) * 8)); - while (v_curr.ptr < i_end0_curr) { - v_b128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); - v_p128 = _mm_avg_epu8(v_a128, v_b128); - v_p128 = _mm_sub_epi8(v_p128, _mm_and_si128(v_k128, _mm_xor_si128(v_a128, v_b128))); - v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_x128 = _mm_add_epi8(v_x128, v_p128); - v_a128 = v_x128; - wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); - v_curr.ptr += 4; - v_prev.ptr += 4; - v_b128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); - v_p128 = _mm_avg_epu8(v_a128, v_b128); - v_p128 = _mm_sub_epi8(v_p128, _mm_and_si128(v_k128, _mm_xor_si128(v_a128, v_b128))); - v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_x128 = _mm_add_epi8(v_x128, v_p128); - v_a128 = v_x128; - wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); - v_curr.ptr += 4; - v_prev.ptr += 4; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); + uint32_t t_2; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_2 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); + iop_a_src += 4; + } else { + self->private_data.s_decode_fctl.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); + 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_decode_fctl.scratch; + uint32_t num_bits_2 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_2); + if (num_bits_2 == 24) { + t_2 = ((uint32_t)(*scratch >> 32)); + break; + } + num_bits_2 += 8u; + *scratch |= ((uint64_t)(num_bits_2)); + } } - v_curr.len = 4; - v_prev.len = 4; - const uint8_t* i_end1_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 4) * 4)); - while (v_curr.ptr < i_end1_curr) { - v_b128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); - v_p128 = _mm_avg_epu8(v_a128, v_b128); - v_p128 = _mm_sub_epi8(v_p128, _mm_and_si128(v_k128, _mm_xor_si128(v_a128, v_b128))); - v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_x128 = _mm_add_epi8(v_x128, v_p128); - v_a128 = v_x128; - wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); - v_curr.ptr += 4; - v_prev.ptr += 4; + v_y1 = t_2; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); + uint32_t t_3; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); + iop_a_src += 4; + } else { + self->private_data.s_decode_fctl.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); + 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_decode_fctl.scratch; + uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3); + if (num_bits_3 == 24) { + t_3 = ((uint32_t)(*scratch >> 32)); + break; + } + num_bits_3 += 8u; + *scratch |= ((uint64_t)(num_bits_3)); + } } - v_curr.len = 0; - v_prev.len = 0; + v_x0 = t_3; } - } - return wuffs_base__make_empty_struct(); -} -#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) -// ‼ WUFFS MULTI-FILE SECTION -x86_sse42 - -// ‼ WUFFS MULTI-FILE SECTION +x86_sse42 -// -------- func png.decoder.filter_4_distance_3_x86_sse42 - -#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) -WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2") -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__filter_4_distance_3_x86_sse42( - wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr, - wuffs_base__slice_u8 a_prev) { - wuffs_base__slice_u8 v_curr = {0}; - wuffs_base__slice_u8 v_prev = {0}; - __m128i v_x128 = {0}; - __m128i v_a128 = {0}; - __m128i v_b128 = {0}; - __m128i v_c128 = {0}; - __m128i v_p128 = {0}; - __m128i v_pa128 = {0}; - __m128i v_pb128 = {0}; - __m128i v_pc128 = {0}; - __m128i v_smallest128 = {0}; - __m128i v_z128 = {0}; - - { - wuffs_base__slice_u8 i_slice_curr = a_curr; - v_curr.ptr = i_slice_curr.ptr; - wuffs_base__slice_u8 i_slice_prev = a_prev; - v_prev.ptr = i_slice_prev.ptr; - i_slice_curr.len = ((size_t)(wuffs_base__u64__min(i_slice_curr.len, i_slice_prev.len))); - v_curr.len = 4; - v_prev.len = 4; - const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, wuffs_private_impl__iterate_total_advance((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)), 7, 6)); - while (v_curr.ptr < i_end0_curr) { - v_b128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); - v_b128 = _mm_unpacklo_epi8(v_b128, v_z128); - v_pa128 = _mm_sub_epi16(v_b128, v_c128); - v_pb128 = _mm_sub_epi16(v_a128, v_c128); - v_pc128 = _mm_add_epi16(v_pa128, v_pb128); - v_pa128 = _mm_abs_epi16(v_pa128); - v_pb128 = _mm_abs_epi16(v_pb128); - v_pc128 = _mm_abs_epi16(v_pc128); - v_smallest128 = _mm_min_epi16(v_pc128, _mm_min_epi16(v_pb128, v_pa128)); - v_p128 = _mm_blendv_epi8(_mm_blendv_epi8(v_c128, v_b128, _mm_cmpeq_epi16(v_smallest128, v_pb128)), v_a128, _mm_cmpeq_epi16(v_smallest128, v_pa128)); - v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_x128 = _mm_unpacklo_epi8(v_x128, v_z128); - v_x128 = _mm_add_epi8(v_x128, v_p128); - v_a128 = v_x128; - v_c128 = v_b128; - v_x128 = _mm_packus_epi16(v_x128, v_x128); - wuffs_base__poke_u24le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); - v_curr.ptr += 3; - v_prev.ptr += 3; - v_b128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); - v_b128 = _mm_unpacklo_epi8(v_b128, v_z128); - v_pa128 = _mm_sub_epi16(v_b128, v_c128); - v_pb128 = _mm_sub_epi16(v_a128, v_c128); - v_pc128 = _mm_add_epi16(v_pa128, v_pb128); - v_pa128 = _mm_abs_epi16(v_pa128); - v_pb128 = _mm_abs_epi16(v_pb128); - v_pc128 = _mm_abs_epi16(v_pc128); - v_smallest128 = _mm_min_epi16(v_pc128, _mm_min_epi16(v_pb128, v_pa128)); - v_p128 = _mm_blendv_epi8(_mm_blendv_epi8(v_c128, v_b128, _mm_cmpeq_epi16(v_smallest128, v_pb128)), v_a128, _mm_cmpeq_epi16(v_smallest128, v_pa128)); - v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_x128 = _mm_unpacklo_epi8(v_x128, v_z128); - v_x128 = _mm_add_epi8(v_x128, v_p128); - v_a128 = v_x128; - v_c128 = v_b128; - v_x128 = _mm_packus_epi16(v_x128, v_x128); - wuffs_base__poke_u24le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); - v_curr.ptr += 3; - v_prev.ptr += 3; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); + uint32_t t_4; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_4 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); + iop_a_src += 4; + } else { + self->private_data.s_decode_fctl.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10); + 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_decode_fctl.scratch; + uint32_t num_bits_4 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_4); + if (num_bits_4 == 24) { + t_4 = ((uint32_t)(*scratch >> 32)); + break; + } + num_bits_4 += 8u; + *scratch |= ((uint64_t)(num_bits_4)); + } + } + v_y0 = t_4; } - v_curr.len = 4; - v_prev.len = 4; - const uint8_t* i_end1_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, wuffs_private_impl__iterate_total_advance((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)), 4, 3)); - while (v_curr.ptr < i_end1_curr) { - v_b128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); - v_b128 = _mm_unpacklo_epi8(v_b128, v_z128); - v_pa128 = _mm_sub_epi16(v_b128, v_c128); - v_pb128 = _mm_sub_epi16(v_a128, v_c128); - v_pc128 = _mm_add_epi16(v_pa128, v_pb128); - v_pa128 = _mm_abs_epi16(v_pa128); - v_pb128 = _mm_abs_epi16(v_pb128); - v_pc128 = _mm_abs_epi16(v_pc128); - v_smallest128 = _mm_min_epi16(v_pc128, _mm_min_epi16(v_pb128, v_pa128)); - v_p128 = _mm_blendv_epi8(_mm_blendv_epi8(v_c128, v_b128, _mm_cmpeq_epi16(v_smallest128, v_pb128)), v_a128, _mm_cmpeq_epi16(v_smallest128, v_pa128)); - v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_x128 = _mm_unpacklo_epi8(v_x128, v_z128); - v_x128 = _mm_add_epi8(v_x128, v_p128); - v_a128 = v_x128; - v_c128 = v_b128; - v_x128 = _mm_packus_epi16(v_x128, v_x128); - wuffs_base__poke_u24le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); - v_curr.ptr += 3; - v_prev.ptr += 3; + v_x1 += v_x0; + v_y1 += v_y0; + if ((v_x0 >= v_x1) || + (v_x0 > self->private_impl.f_width) || + (v_x1 > self->private_impl.f_width) || + (v_y0 >= v_y1) || + (v_y0 > self->private_impl.f_height) || + (v_y1 > self->private_impl.f_height)) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } + self->private_impl.f_frame_rect_x0 = v_x0; + self->private_impl.f_frame_rect_y0 = v_y0; + self->private_impl.f_frame_rect_x1 = v_x1; + self->private_impl.f_frame_rect_y1 = v_y1; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11); + uint32_t t_5; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { + t_5 = ((uint32_t)(wuffs_base__peek_u16be__no_bounds_check(iop_a_src))); + iop_a_src += 2; + } else { + self->private_data.s_decode_fctl.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12); + 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_decode_fctl.scratch; + uint32_t num_bits_5 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_5); + if (num_bits_5 == 8) { + t_5 = ((uint32_t)(*scratch >> 48)); + break; + } + num_bits_5 += 8u; + *scratch |= ((uint64_t)(num_bits_5)); + } + } + v_x0 = t_5; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13); + uint32_t t_6; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { + t_6 = ((uint32_t)(wuffs_base__peek_u16be__no_bounds_check(iop_a_src))); + iop_a_src += 2; + } else { + self->private_data.s_decode_fctl.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(14); + 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_decode_fctl.scratch; + uint32_t num_bits_6 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_6); + if (num_bits_6 == 8) { + t_6 = ((uint32_t)(*scratch >> 48)); + break; + } + num_bits_6 += 8u; + *scratch |= ((uint64_t)(num_bits_6)); + } + } + v_x1 = t_6; + } + if (v_x1 <= 0u) { + self->private_impl.f_frame_duration = (((uint64_t)(v_x0)) * 7056000u); + } else { + self->private_impl.f_frame_duration = ((((uint64_t)(v_x0)) * 705600000u) / ((uint64_t)(v_x1))); + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint32_t t_7 = *iop_a_src++; + v_x0 = t_7; + } + if (v_x0 == 0u) { + self->private_impl.f_frame_disposal = 0u; + } else if (v_x0 == 1u) { + self->private_impl.f_frame_disposal = 1u; + } else if (v_x0 == 2u) { + self->private_impl.f_frame_disposal = 2u; + } else { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint32_t t_8 = *iop_a_src++; + v_x0 = t_8; } - v_curr.len = 3; - v_prev.len = 3; - const uint8_t* i_end2_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 3) * 3)); - while (v_curr.ptr < i_end2_curr) { - v_b128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u24le__no_bounds_check(v_prev.ptr))); - v_b128 = _mm_unpacklo_epi8(v_b128, v_z128); - v_pa128 = _mm_sub_epi16(v_b128, v_c128); - v_pb128 = _mm_sub_epi16(v_a128, v_c128); - v_pc128 = _mm_add_epi16(v_pa128, v_pb128); - v_pa128 = _mm_abs_epi16(v_pa128); - v_pb128 = _mm_abs_epi16(v_pb128); - v_pc128 = _mm_abs_epi16(v_pc128); - v_smallest128 = _mm_min_epi16(v_pc128, _mm_min_epi16(v_pb128, v_pa128)); - v_p128 = _mm_blendv_epi8(_mm_blendv_epi8(v_c128, v_b128, _mm_cmpeq_epi16(v_smallest128, v_pb128)), v_a128, _mm_cmpeq_epi16(v_smallest128, v_pa128)); - v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u24le__no_bounds_check(v_curr.ptr))); - v_x128 = _mm_unpacklo_epi8(v_x128, v_z128); - v_x128 = _mm_add_epi8(v_x128, v_p128); - v_x128 = _mm_packus_epi16(v_x128, v_x128); - wuffs_base__poke_u24le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); - v_curr.ptr += 3; - v_prev.ptr += 3; + if (v_x0 == 0u) { + self->private_impl.f_frame_overwrite_instead_of_blend = true; + } else if (v_x0 == 1u) { + self->private_impl.f_frame_overwrite_instead_of_blend = false; + } else { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; } - v_curr.len = 0; - v_prev.len = 0; + if (self->private_impl.f_num_decoded_frame_configs_value == 0u) { + self->private_impl.f_first_rect_x0 = self->private_impl.f_frame_rect_x0; + self->private_impl.f_first_rect_y0 = self->private_impl.f_frame_rect_y0; + self->private_impl.f_first_rect_x1 = self->private_impl.f_frame_rect_x1; + self->private_impl.f_first_rect_y1 = self->private_impl.f_frame_rect_y1; + self->private_impl.f_first_duration = self->private_impl.f_frame_duration; + self->private_impl.f_first_disposal = self->private_impl.f_frame_disposal; + self->private_impl.f_first_overwrite_instead_of_blend = self->private_impl.f_frame_overwrite_instead_of_blend; + } + + goto ok; + ok: + self->private_impl.p_decode_fctl = 0; + goto exit; } - return wuffs_base__make_empty_struct(); + + goto suspend; + suspend: + self->private_impl.p_decode_fctl = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_data.s_decode_fctl.v_x0 = v_x0; + self->private_data.s_decode_fctl.v_x1 = v_x1; + self->private_data.s_decode_fctl.v_y1 = v_y1; + + 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; } -#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) -// ‼ WUFFS MULTI-FILE SECTION -x86_sse42 -// ‼ WUFFS MULTI-FILE SECTION +x86_sse42 -// -------- func png.decoder.filter_4_distance_4_x86_sse42 +// -------- func png.decoder.decode_gama -#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) -WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2") WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__filter_4_distance_4_x86_sse42( +static wuffs_base__status +wuffs_png__decoder__decode_gama( wuffs_png__decoder* self, - wuffs_base__slice_u8 a_curr, - wuffs_base__slice_u8 a_prev) { - wuffs_base__slice_u8 v_curr = {0}; - wuffs_base__slice_u8 v_prev = {0}; - __m128i v_x128 = {0}; - __m128i v_a128 = {0}; - __m128i v_b128 = {0}; - __m128i v_c128 = {0}; - __m128i v_p128 = {0}; - __m128i v_pa128 = {0}; - __m128i v_pb128 = {0}; - __m128i v_pc128 = {0}; - __m128i v_smallest128 = {0}; - __m128i v_z128 = {0}; + wuffs_base__io_buffer* a_src) { + wuffs_base__status status = wuffs_base__make_status(NULL); - { - wuffs_base__slice_u8 i_slice_curr = a_curr; - v_curr.ptr = i_slice_curr.ptr; - wuffs_base__slice_u8 i_slice_prev = a_prev; - v_prev.ptr = i_slice_prev.ptr; - i_slice_curr.len = ((size_t)(wuffs_base__u64__min(i_slice_curr.len, i_slice_prev.len))); - v_curr.len = 4; - v_prev.len = 4; - const uint8_t* i_end0_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 8) * 8)); - while (v_curr.ptr < i_end0_curr) { - v_b128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); - v_b128 = _mm_unpacklo_epi8(v_b128, v_z128); - v_pa128 = _mm_sub_epi16(v_b128, v_c128); - v_pb128 = _mm_sub_epi16(v_a128, v_c128); - v_pc128 = _mm_add_epi16(v_pa128, v_pb128); - v_pa128 = _mm_abs_epi16(v_pa128); - v_pb128 = _mm_abs_epi16(v_pb128); - v_pc128 = _mm_abs_epi16(v_pc128); - v_smallest128 = _mm_min_epi16(v_pc128, _mm_min_epi16(v_pb128, v_pa128)); - v_p128 = _mm_blendv_epi8(_mm_blendv_epi8(v_c128, v_b128, _mm_cmpeq_epi16(v_smallest128, v_pb128)), v_a128, _mm_cmpeq_epi16(v_smallest128, v_pa128)); - v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_x128 = _mm_unpacklo_epi8(v_x128, v_z128); - v_x128 = _mm_add_epi8(v_x128, v_p128); - v_a128 = v_x128; - v_c128 = v_b128; - v_x128 = _mm_packus_epi16(v_x128, v_x128); - wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); - v_curr.ptr += 4; - v_prev.ptr += 4; - v_b128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); - v_b128 = _mm_unpacklo_epi8(v_b128, v_z128); - v_pa128 = _mm_sub_epi16(v_b128, v_c128); - v_pb128 = _mm_sub_epi16(v_a128, v_c128); - v_pc128 = _mm_add_epi16(v_pa128, v_pb128); - v_pa128 = _mm_abs_epi16(v_pa128); - v_pb128 = _mm_abs_epi16(v_pb128); - v_pc128 = _mm_abs_epi16(v_pc128); - v_smallest128 = _mm_min_epi16(v_pc128, _mm_min_epi16(v_pb128, v_pa128)); - v_p128 = _mm_blendv_epi8(_mm_blendv_epi8(v_c128, v_b128, _mm_cmpeq_epi16(v_smallest128, v_pb128)), v_a128, _mm_cmpeq_epi16(v_smallest128, v_pa128)); - v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_x128 = _mm_unpacklo_epi8(v_x128, v_z128); - v_x128 = _mm_add_epi8(v_x128, v_p128); - v_a128 = v_x128; - v_c128 = v_b128; - v_x128 = _mm_packus_epi16(v_x128, v_x128); - wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); - v_curr.ptr += 4; - v_prev.ptr += 4; + 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_decode_gama; + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + + if (self->private_impl.f_chunk_length != 4u) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; } - v_curr.len = 4; - v_prev.len = 4; - const uint8_t* i_end1_curr = wuffs_private_impl__ptr_u8_plus_len(v_curr.ptr, (((i_slice_curr.len - (size_t)(v_curr.ptr - i_slice_curr.ptr)) / 4) * 4)); - while (v_curr.ptr < i_end1_curr) { - v_b128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_prev.ptr))); - v_b128 = _mm_unpacklo_epi8(v_b128, v_z128); - v_pa128 = _mm_sub_epi16(v_b128, v_c128); - v_pb128 = _mm_sub_epi16(v_a128, v_c128); - v_pc128 = _mm_add_epi16(v_pa128, v_pb128); - v_pa128 = _mm_abs_epi16(v_pa128); - v_pb128 = _mm_abs_epi16(v_pb128); - v_pc128 = _mm_abs_epi16(v_pc128); - v_smallest128 = _mm_min_epi16(v_pc128, _mm_min_epi16(v_pb128, v_pa128)); - v_p128 = _mm_blendv_epi8(_mm_blendv_epi8(v_c128, v_b128, _mm_cmpeq_epi16(v_smallest128, v_pb128)), v_a128, _mm_cmpeq_epi16(v_smallest128, v_pa128)); - v_x128 = _mm_cvtsi32_si128((int32_t)(wuffs_base__peek_u32le__no_bounds_check(v_curr.ptr))); - v_x128 = _mm_unpacklo_epi8(v_x128, v_z128); - v_x128 = _mm_add_epi8(v_x128, v_p128); - v_a128 = v_x128; - v_c128 = v_b128; - v_x128 = _mm_packus_epi16(v_x128, v_x128); - wuffs_base__poke_u32le__no_bounds_check(v_curr.ptr, ((uint32_t)(_mm_cvtsi128_si32(v_x128)))); - v_curr.ptr += 4; - v_prev.ptr += 4; + self->private_impl.f_chunk_length = 0u; + self->private_impl.f_metadata_flavor = 5u; + self->private_impl.f_metadata_fourcc = 1195461953u; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + uint64_t t_0; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_0 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src))); + iop_a_src += 4; + } else { + self->private_data.s_decode_gama.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_decode_gama.scratch; + uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0); + if (num_bits_0 == 24) { + t_0 = ((uint64_t)(*scratch >> 32)); + break; + } + num_bits_0 += 8u; + *scratch |= ((uint64_t)(num_bits_0)); + } + } + self->private_impl.f_metadata_x = t_0; } - v_curr.len = 0; - v_prev.len = 0; + self->private_impl.f_metadata_y = 0u; + self->private_impl.f_metadata_z = 0u; + + goto ok; + ok: + self->private_impl.p_decode_gama = 0; + goto exit; } - return wuffs_base__make_empty_struct(); -} -#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) -// ‼ WUFFS MULTI-FILE SECTION -x86_sse42 -// -------- func png.decoder.get_quirk + goto suspend; + suspend: + self->private_impl.p_decode_gama = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC uint64_t -wuffs_png__decoder__get_quirk( - const wuffs_png__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; + goto exit; + exit: + if (a_src && a_src->data.ptr) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); } - if ((a_key == 1u) && self->private_impl.f_ignore_checksum) { - return 1u; - } - return 0u; + return status; } -// -------- func png.decoder.set_quirk +// -------- func png.decoder.decode_iccp WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_png__decoder__set_quirk( +static wuffs_base__status +wuffs_png__decoder__decode_iccp( wuffs_png__decoder* self, - uint32_t a_key, - uint64_t a_value) { - if (!self) { - return wuffs_base__make_status(wuffs_base__error__bad_receiver); + wuffs_base__io_buffer* a_src) { + wuffs_base__status status = wuffs_base__make_status(NULL); + + uint8_t v_c8 = 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; } - 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); + + uint32_t coro_susp_point = self->private_impl.p_decode_iccp; + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + + while (true) { + if (self->private_impl.f_chunk_length <= 0u) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } + self->private_impl.f_chunk_length -= 1u; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_0 = *iop_a_src++; + v_c8 = t_0; + } + if (v_c8 == 0u) { + break; + } + } + if (self->private_impl.f_chunk_length <= 0u) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } + self->private_impl.f_chunk_length -= 1u; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_1 = *iop_a_src++; + v_c8 = t_1; + } + if (v_c8 != 0u) { + status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method); + goto exit; + } + self->private_impl.f_metadata_is_zlib_compressed = true; + self->private_impl.f_metadata_flavor = 4u; + self->private_impl.f_metadata_fourcc = 1229144912u; + self->private_impl.f_metadata_x = 0u; + self->private_impl.f_metadata_y = 0u; + self->private_impl.f_metadata_z = 0u; + + goto ok; + ok: + self->private_impl.p_decode_iccp = 0; + goto exit; } - if (a_key == 1u) { - self->private_impl.f_ignore_checksum = (a_value > 0u); - wuffs_zlib__decoder__set_quirk(&self->private_data.f_zlib, a_key, a_value); - return wuffs_base__make_status(NULL); + goto suspend; + suspend: + self->private_impl.p_decode_iccp = 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 wuffs_base__make_status(wuffs_base__error__unsupported_option); + + return status; } -// -------- func png.decoder.decode_image_config +// -------- func png.decoder.decode_plte WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_png__decoder__decode_image_config( +static wuffs_base__status +wuffs_png__decoder__decode_plte( wuffs_png__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); + wuffs_base__status status = wuffs_base__make_status(NULL); + + uint32_t v_num_entries = 0; + uint32_t v_i = 0; + uint32_t v_argb = 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; } - 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); + + uint32_t coro_susp_point = self->private_impl.p_decode_plte; + if (coro_susp_point) { + v_num_entries = self->private_data.s_decode_plte.v_num_entries; + v_i = self->private_data.s_decode_plte.v_i; } - if (!a_src) { - self->private_impl.magic = WUFFS_BASE__DISABLED; - return wuffs_base__make_status(wuffs_base__error__bad_argument); + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + + if ((self->private_impl.f_chunk_length > 768u) || ((self->private_impl.f_chunk_length % 3u) != 0u)) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } + v_num_entries = (((uint32_t)(self->private_impl.f_chunk_length)) / 3u); + self->private_impl.f_chunk_length = 0u; + while (v_i < v_num_entries) { + { + 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_u24be__no_bounds_check(iop_a_src))); + iop_a_src += 3; + } else { + self->private_data.s_decode_plte.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_decode_plte.scratch; + uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0); + if (num_bits_0 == 16) { + t_0 = ((uint32_t)(*scratch >> 40)); + break; + } + num_bits_0 += 8u; + *scratch |= ((uint64_t)(num_bits_0)); + } + } + v_argb = t_0; + } + v_argb |= 4278190080u; + self->private_data.f_src_palette[((4u * v_i) + 0u)] = ((uint8_t)((v_argb >> 0u))); + self->private_data.f_src_palette[((4u * v_i) + 1u)] = ((uint8_t)((v_argb >> 8u))); + self->private_data.f_src_palette[((4u * v_i) + 2u)] = ((uint8_t)((v_argb >> 16u))); + self->private_data.f_src_palette[((4u * v_i) + 3u)] = ((uint8_t)((v_argb >> 24u))); + v_i += 1u; + } + while (v_i < 256u) { + self->private_data.f_src_palette[((4u * v_i) + 0u)] = 0u; + self->private_data.f_src_palette[((4u * v_i) + 1u)] = 0u; + self->private_data.f_src_palette[((4u * v_i) + 2u)] = 0u; + self->private_data.f_src_palette[((4u * v_i) + 3u)] = 255u; + v_i += 1u; + } + + goto ok; + ok: + self->private_impl.p_decode_plte = 0; + goto exit; } - 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); + + goto suspend; + suspend: + self->private_impl.p_decode_plte = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_data.s_decode_plte.v_num_entries = v_num_entries; + self->private_data.s_decode_plte.v_i = v_i; + + goto exit; + exit: + if (a_src && a_src->data.ptr) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); } - self->private_impl.active_coroutine = 0; + + return status; +} + +// -------- func png.decoder.decode_srgb + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_png__decoder__decode_srgb( + wuffs_png__decoder* self, + wuffs_base__io_buffer* a_src) { wuffs_base__status status = wuffs_base__make_status(NULL); - wuffs_base__status v_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_decode_image_config; + uint32_t coro_susp_point = self->private_impl.p_decode_srgb; switch (coro_susp_point) { WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - while (true) { - { - wuffs_base__status t_0 = wuffs_png__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_png__error__truncated_input); - goto exit; + if (self->private_impl.f_chunk_length != 1u) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } + self->private_impl.f_chunk_length = 0u; + self->private_impl.f_metadata_flavor = 5u; + self->private_impl.f_metadata_fourcc = 1397901122u; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } - status = v_status; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1); + uint64_t t_0 = *iop_a_src++; + self->private_impl.f_metadata_x = t_0; } + self->private_impl.f_metadata_y = 0u; + self->private_impl.f_metadata_z = 0u; + goto ok; ok: - self->private_impl.p_decode_image_config = 0; + self->private_impl.p_decode_srgb = 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; + self->private_impl.p_decode_srgb = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; goto exit; exit: - if (wuffs_base__status__is_error(&status)) { - self->private_impl.magic = WUFFS_BASE__DISABLED; + if (a_src && a_src->data.ptr) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); } + return status; } -// -------- func png.decoder.do_decode_image_config +// -------- func png.decoder.decode_trns WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_png__decoder__do_decode_image_config( +wuffs_png__decoder__decode_trns( wuffs_png__decoder* self, - wuffs_base__image_config* a_dst, wuffs_base__io_buffer* a_src) { wuffs_base__status status = wuffs_base__make_status(NULL); - uint64_t v_magic = 0; - uint64_t v_mark = 0; - uint32_t v_checksum_have = 0; - uint32_t v_checksum_want = 0; - wuffs_base__status v_status = wuffs_base__make_status(NULL); + uint32_t v_i = 0; + uint32_t v_n = 0; + uint64_t v_u = 0; const uint8_t* iop_a_src = NULL; const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL; @@ -62753,483 +68446,158 @@ wuffs_png__decoder__do_decode_image_config( io2_a_src = io0_a_src + a_src->meta.wi; } - uint32_t coro_susp_point = self->private_impl.p_do_decode_image_config; + uint32_t coro_susp_point = self->private_impl.p_decode_trns; if (coro_susp_point) { - v_checksum_have = self->private_data.s_do_decode_image_config.v_checksum_have; + v_i = self->private_data.s_decode_trns.v_i; + v_n = self->private_data.s_decode_trns.v_n; } 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; - } else if ( ! self->private_impl.f_seen_ihdr) { + if (self->private_impl.f_color_type == 0u) { + self->private_impl.choosy_filter_and_swizzle = ( + &wuffs_png__decoder__filter_and_swizzle_tricky); + if (self->private_impl.f_depth <= 8u) { + self->private_impl.f_dst_pixfmt = 2164295816u; + self->private_impl.f_src_pixfmt = 2164295816u; + } else { + self->private_impl.f_dst_pixfmt = 2164308923u; + self->private_impl.f_src_pixfmt = 2164308923u; + } + if (self->private_impl.f_chunk_length != 2u) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } + self->private_impl.f_chunk_length = 0u; { WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); uint64_t t_0; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 8)) { - t_0 = wuffs_base__peek_u64le__no_bounds_check(iop_a_src); - iop_a_src += 8; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { + t_0 = ((uint64_t)(wuffs_base__peek_u16be__no_bounds_check(iop_a_src))); + iop_a_src += 2; } else { - self->private_data.s_do_decode_image_config.scratch = 0; + self->private_data.s_decode_trns.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; + uint64_t* scratch = &self->private_data.s_decode_trns.scratch; + uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu)); *scratch >>= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_0; - if (num_bits_0 == 56) { - t_0 = ((uint64_t)(*scratch)); + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0); + if (num_bits_0 == 8) { + t_0 = ((uint64_t)(*scratch >> 48)); break; } num_bits_0 += 8u; - *scratch |= ((uint64_t)(num_bits_0)) << 56; + *scratch |= ((uint64_t)(num_bits_0)); } } - v_magic = t_0; + v_u = t_0; } - if (v_magic != 727905341920923785u) { - status = wuffs_base__make_status(wuffs_png__error__bad_header); + if (self->private_impl.f_depth <= 1u) { + self->private_impl.f_remap_transparency = (((v_u & 1u) * 16777215u) | 4278190080u); + } else if (self->private_impl.f_depth <= 2u) { + self->private_impl.f_remap_transparency = (((v_u & 3u) * 5592405u) | 4278190080u); + } else if (self->private_impl.f_depth <= 4u) { + self->private_impl.f_remap_transparency = (((v_u & 15u) * 1118481u) | 4278190080u); + } else if (self->private_impl.f_depth <= 8u) { + self->private_impl.f_remap_transparency = (((v_u & 255u) * 65793u) | 4278190080u); + } else { + self->private_impl.f_remap_transparency = ((v_u * 4295032833u) | 18446462598732840960u); + } + } else if (self->private_impl.f_color_type == 2u) { + self->private_impl.choosy_filter_and_swizzle = ( + &wuffs_png__decoder__filter_and_swizzle_tricky); + if (self->private_impl.f_depth <= 8u) { + self->private_impl.f_dst_pixfmt = 2164295816u; + self->private_impl.f_src_pixfmt = 2164295816u; + } else { + self->private_impl.f_dst_pixfmt = 2164308923u; + self->private_impl.f_src_pixfmt = 2164308923u; + } + if (self->private_impl.f_chunk_length != 6u) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); goto exit; } + self->private_impl.f_chunk_length = 0u; { WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); uint64_t t_1; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 8)) { - t_1 = wuffs_base__peek_u64le__no_bounds_check(iop_a_src); - iop_a_src += 8; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 6)) { + t_1 = ((uint64_t)(wuffs_base__peek_u48be__no_bounds_check(iop_a_src))); + iop_a_src += 6; } else { - self->private_data.s_do_decode_image_config.scratch = 0; + self->private_data.s_decode_trns.scratch = 0; WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); 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_1 = ((uint32_t)(*scratch >> 56)); - *scratch <<= 8; - *scratch >>= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_1; - if (num_bits_1 == 56) { - t_1 = ((uint64_t)(*scratch)); - break; - } - num_bits_1 += 8u; - *scratch |= ((uint64_t)(num_bits_1)) << 56; - } - } - v_magic = t_1; - } - if (v_magic != 5927942488114331648u) { - if (v_magic == 5278895250759221248u) { - status = wuffs_base__make_status(wuffs_png__error__unsupported_cgbi_extension); - goto exit; - } - status = wuffs_base__make_status(wuffs_png__error__bad_header); - goto exit; - } - self->private_impl.f_chunk_type_array[0u] = 73u; - self->private_impl.f_chunk_type_array[1u] = 72u; - self->private_impl.f_chunk_type_array[2u] = 68u; - self->private_impl.f_chunk_type_array[3u] = 82u; - wuffs_private_impl__ignore_status(wuffs_crc32__ieee_hasher__initialize(&self->private_data.f_crc32, - sizeof (wuffs_crc32__ieee_hasher), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED)); - wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__make_slice_u8(self->private_impl.f_chunk_type_array, 4)); - while (true) { - v_mark = ((uint64_t)(iop_a_src - io0_a_src)); - { - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - wuffs_base__status t_2 = wuffs_png__decoder__decode_ihdr(self, a_src); - v_status = t_2; - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - } - if ( ! self->private_impl.f_ignore_checksum) { - v_checksum_have = wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_private_impl__io__since(v_mark, ((uint64_t)(iop_a_src - io0_a_src)), io0_a_src)); - } - if (wuffs_base__status__is_ok(&v_status)) { - break; - } - status = v_status; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5); - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); - uint32_t t_3; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_do_decode_image_config.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); - 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_3 = ((uint32_t)(*scratch & 0xFFu)); + uint64_t* scratch = &self->private_data.s_decode_trns.scratch; + uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFFu)); *scratch >>= 8; *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3); - if (num_bits_3 == 24) { - t_3 = ((uint32_t)(*scratch >> 32)); + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1); + if (num_bits_1 == 40) { + t_1 = ((uint64_t)(*scratch >> 16)); break; } - num_bits_3 += 8u; - *scratch |= ((uint64_t)(num_bits_3)); + num_bits_1 += 8u; + *scratch |= ((uint64_t)(num_bits_1)); } } - v_checksum_want = t_3; - } - if ( ! self->private_impl.f_ignore_checksum && (v_checksum_have != v_checksum_want)) { - status = wuffs_base__make_status(wuffs_png__error__bad_checksum); - goto exit; + v_u = t_1; } - self->private_impl.f_seen_ihdr = true; - } else if (self->private_impl.f_metadata_fourcc != 0u) { - self->private_impl.f_call_sequence = 16u; - status = wuffs_base__make_status(wuffs_base__note__metadata_reported); - goto ok; - } - while (true) { - if (((uint64_t)(io2_a_src - iop_a_src)) < 8u) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8); - continue; + if (self->private_impl.f_depth <= 8u) { + self->private_impl.f_remap_transparency = ((255u & (v_u >> 0u)) | + (65280u & (v_u >> 8u)) | + (16711680u & (v_u >> 16u)) | + 4278190080u); + } else { + self->private_impl.f_remap_transparency = (v_u | 18446462598732840960u); } - self->private_impl.f_chunk_length = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); - self->private_impl.f_chunk_type = ((uint32_t)((wuffs_base__peek_u64le__no_bounds_check(iop_a_src) >> 32u))); - if (self->private_impl.f_chunk_type == 1413563465u) { - if ( ! self->private_impl.f_seen_actl || self->private_impl.f_seen_fctl) { - break; - } - self->private_impl.f_seen_idat = true; - } else if (self->private_impl.f_chunk_type == 1413571686u) { - if (self->private_impl.f_seen_idat && self->private_impl.f_seen_fctl) { - break; - } + } else if (self->private_impl.f_color_type == 3u) { + self->private_impl.f_dst_pixfmt = 2164523016u; + self->private_impl.f_src_pixfmt = 2164523016u; + if (self->private_impl.f_chunk_length > 256u) { status = wuffs_base__make_status(wuffs_png__error__bad_chunk); goto exit; } - iop_a_src += 8u; - if ( ! self->private_impl.f_ignore_checksum && ((self->private_impl.f_chunk_type & 32u) == 0u)) { - self->private_impl.f_chunk_type_array[0u] = ((uint8_t)((self->private_impl.f_chunk_type >> 0u))); - self->private_impl.f_chunk_type_array[1u] = ((uint8_t)((self->private_impl.f_chunk_type >> 8u))); - self->private_impl.f_chunk_type_array[2u] = ((uint8_t)((self->private_impl.f_chunk_type >> 16u))); - self->private_impl.f_chunk_type_array[3u] = ((uint8_t)((self->private_impl.f_chunk_type >> 24u))); - wuffs_private_impl__ignore_status(wuffs_crc32__ieee_hasher__initialize(&self->private_data.f_crc32, - sizeof (wuffs_crc32__ieee_hasher), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED)); - wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__make_slice_u8(self->private_impl.f_chunk_type_array, 4)); - } - while (true) { - v_mark = ((uint64_t)(iop_a_src - io0_a_src)); + v_n = ((uint32_t)(self->private_impl.f_chunk_length)); + self->private_impl.f_chunk_length = 0u; + while (v_i < v_n) { { - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - wuffs_base__status t_4 = wuffs_png__decoder__decode_other_chunk(self, a_src, false); - v_status = t_4; - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - } - if ( ! self->private_impl.f_ignore_checksum && ((self->private_impl.f_chunk_type & 32u) == 0u)) { - v_checksum_have = wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_private_impl__io__since(v_mark, ((uint64_t)(iop_a_src - io0_a_src)), io0_a_src)); - } - if (wuffs_base__status__is_ok(&v_status)) { - break; - } - status = v_status; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9); - } - if (self->private_impl.f_metadata_fourcc != 0u) { - self->private_impl.f_call_sequence = 16u; - status = wuffs_base__make_status(wuffs_base__note__metadata_reported); - goto ok; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10); - uint32_t t_5; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_5 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_do_decode_image_config.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11); - 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_5 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_5); - if (num_bits_5 == 24) { - t_5 = ((uint32_t)(*scratch >> 32)); - break; - } - num_bits_5 += 8u; - *scratch |= ((uint64_t)(num_bits_5)); - } - } - v_checksum_want = t_5; - } - if ( ! self->private_impl.f_ignore_checksum && ((self->private_impl.f_chunk_type & 32u) == 0u) && (v_checksum_have != v_checksum_want)) { - status = wuffs_base__make_status(wuffs_png__error__bad_checksum); - goto exit; - } - } - if ((self->private_impl.f_color_type == 3u) && ! self->private_impl.f_seen_plte) { - status = wuffs_base__make_status(wuffs_png__error__missing_palette); - goto exit; - } - self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))); - self->private_impl.f_first_config_io_position = self->private_impl.f_frame_config_io_position; - if (a_dst != NULL) { - wuffs_base__image_config__set( - a_dst, - self->private_impl.f_dst_pixfmt, - 0u, - self->private_impl.f_width, - self->private_impl.f_height, - self->private_impl.f_first_config_io_position, - ((self->private_impl.f_color_type <= 3u) && ! self->private_impl.f_seen_trns)); - } - if ( ! self->private_impl.f_seen_actl) { - self->private_impl.f_num_animation_frames_value = 1u; - self->private_impl.f_first_rect_x0 = 0u; - self->private_impl.f_first_rect_y0 = 0u; - self->private_impl.f_first_rect_x1 = self->private_impl.f_width; - self->private_impl.f_first_rect_y1 = self->private_impl.f_height; - self->private_impl.f_first_duration = 0u; - self->private_impl.f_first_disposal = 0u; - self->private_impl.f_first_overwrite_instead_of_blend = false; - } - self->private_impl.f_call_sequence = 32u; - - 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; - self->private_data.s_do_decode_image_config.v_checksum_have = v_checksum_have; - - 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 png.decoder.decode_ihdr - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__decode_ihdr( - wuffs_png__decoder* self, - wuffs_base__io_buffer* a_src) { - wuffs_base__status status = wuffs_base__make_status(NULL); - - uint32_t v_a32 = 0; - uint8_t v_a8 = 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_decode_ihdr; - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - uint32_t t_0; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_0 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_decode_ihdr.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_decode_ihdr.scratch; - uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0); - if (num_bits_0 == 24) { - t_0 = ((uint32_t)(*scratch >> 32)); - break; - } - num_bits_0 += 8u; - *scratch |= ((uint64_t)(num_bits_0)); - } - } - v_a32 = t_0; - } - if ((v_a32 == 0u) || (v_a32 > 2147483647u)) { - status = wuffs_base__make_status(wuffs_png__error__bad_header); - goto exit; - } else if (v_a32 > 16777215u) { - status = wuffs_base__make_status(wuffs_base__error__unsupported_image_dimension); - goto exit; - } - self->private_impl.f_width = v_a32; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - uint32_t t_1; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_1 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_decode_ihdr.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); - while (true) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); 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_decode_ihdr.scratch; - uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1); - if (num_bits_1 == 24) { - t_1 = ((uint32_t)(*scratch >> 32)); - break; - } - num_bits_1 += 8u; - *scratch |= ((uint64_t)(num_bits_1)); + uint8_t t_2 = *iop_a_src++; + self->private_data.f_src_palette[((4u * v_i) + 3u)] = t_2; } + v_i += 1u; } - v_a32 = t_1; - } - if ((v_a32 == 0u) || (v_a32 > 2147483647u)) { - status = wuffs_base__make_status(wuffs_png__error__bad_header); - goto exit; - } else if (v_a32 > 16777215u) { - status = wuffs_base__make_status(wuffs_base__error__unsupported_image_dimension); - goto exit; - } - self->private_impl.f_height = v_a32; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_2 = *iop_a_src++; - v_a8 = t_2; - } - if (v_a8 > 16u) { - status = wuffs_base__make_status(wuffs_png__error__bad_header); - goto exit; - } - self->private_impl.f_depth = v_a8; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_3 = *iop_a_src++; - v_a8 = t_3; - } - if ((v_a8 == 1u) || (v_a8 == 5u) || (v_a8 > 6u)) { - status = wuffs_base__make_status(wuffs_png__error__bad_header); - goto exit; - } - self->private_impl.f_color_type = v_a8; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_4 = *iop_a_src++; - v_a8 = t_4; - } - if (v_a8 != 0u) { - status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method); - goto exit; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_5 = *iop_a_src++; - v_a8 = t_5; - } - if (v_a8 != 0u) { - status = wuffs_base__make_status(wuffs_png__error__bad_header); - goto exit; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_6 = *iop_a_src++; - v_a8 = t_6; - } - if (v_a8 == 0u) { - self->private_impl.f_interlace_pass = 0u; - } else if (v_a8 == 1u) { - self->private_impl.f_interlace_pass = 1u; - self->private_impl.choosy_filter_and_swizzle = ( - &wuffs_png__decoder__filter_and_swizzle_tricky); } else { - status = wuffs_base__make_status(wuffs_png__error__bad_header); - goto exit; - } - self->private_impl.f_filter_distance = 0u; - wuffs_png__decoder__assign_filter_distance(self); - if (self->private_impl.f_filter_distance == 0u) { - status = wuffs_base__make_status(wuffs_png__error__bad_header); + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); goto exit; } - self->private_impl.f_overall_workbuf_length = (((uint64_t)(self->private_impl.f_height)) * (1u + wuffs_png__decoder__calculate_bytes_per_row(self, self->private_impl.f_width))); - wuffs_png__decoder__choose_filter_implementations(self); goto ok; ok: - self->private_impl.p_decode_ihdr = 0; + self->private_impl.p_decode_trns = 0; goto exit; } goto suspend; suspend: - self->private_impl.p_decode_ihdr = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_impl.p_decode_trns = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_data.s_decode_trns.v_i = v_i; + self->private_data.s_decode_trns.v_n = v_n; goto exit; exit: @@ -63240,166 +68608,84 @@ wuffs_png__decoder__decode_ihdr( return status; } -// -------- func png.decoder.assign_filter_distance +// -------- func png.decoder.decode_frame_config WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__assign_filter_distance( - wuffs_png__decoder* self) { - if (self->private_impl.f_depth < 8u) { - if ((self->private_impl.f_depth != 1u) && (self->private_impl.f_depth != 2u) && (self->private_impl.f_depth != 4u)) { - return wuffs_base__make_empty_struct(); - } else if (self->private_impl.f_color_type == 0u) { - self->private_impl.f_dst_pixfmt = 536870920u; - self->private_impl.f_src_pixfmt = 536870920u; - } else if (self->private_impl.f_color_type == 3u) { - self->private_impl.f_dst_pixfmt = 2198077448u; - self->private_impl.f_src_pixfmt = 2198077448u; - } else { - return wuffs_base__make_empty_struct(); - } - self->private_impl.f_filter_distance = 1u; - self->private_impl.choosy_filter_and_swizzle = ( - &wuffs_png__decoder__filter_and_swizzle_tricky); - } else if (self->private_impl.f_color_type == 0u) { - if (self->private_impl.f_depth == 8u) { - self->private_impl.f_dst_pixfmt = 536870920u; - self->private_impl.f_src_pixfmt = 536870920u; - self->private_impl.f_filter_distance = 1u; - } else if (self->private_impl.f_depth == 16u) { - if (self->private_impl.f_interlace_pass == 0u) { - self->private_impl.f_dst_pixfmt = 536870923u; - self->private_impl.f_src_pixfmt = 537919499u; - } else { - self->private_impl.f_dst_pixfmt = 2164308923u; - self->private_impl.f_src_pixfmt = 2164308923u; - } - self->private_impl.f_filter_distance = 2u; - } - } else if (self->private_impl.f_color_type == 2u) { - if (self->private_impl.f_depth == 8u) { - self->private_impl.f_dst_pixfmt = 2147485832u; - self->private_impl.f_src_pixfmt = 2684356744u; - self->private_impl.f_filter_distance = 3u; - } else if (self->private_impl.f_depth == 16u) { - self->private_impl.f_dst_pixfmt = 2164308923u; - self->private_impl.f_src_pixfmt = 2164308923u; - self->private_impl.f_filter_distance = 6u; - self->private_impl.choosy_filter_and_swizzle = ( - &wuffs_png__decoder__filter_and_swizzle_tricky); - } - } else if (self->private_impl.f_color_type == 3u) { - if (self->private_impl.f_depth == 8u) { - self->private_impl.f_dst_pixfmt = 2198077448u; - self->private_impl.f_src_pixfmt = 2198077448u; - self->private_impl.f_filter_distance = 1u; - } - } else if (self->private_impl.f_color_type == 4u) { - if (self->private_impl.f_depth == 8u) { - self->private_impl.f_dst_pixfmt = 553648264u; - self->private_impl.f_src_pixfmt = 553648264u; - self->private_impl.f_filter_distance = 2u; - } else if (self->private_impl.f_depth == 16u) { - self->private_impl.f_dst_pixfmt = 2164308923u; - self->private_impl.f_src_pixfmt = 2164308923u; - self->private_impl.f_filter_distance = 4u; - self->private_impl.choosy_filter_and_swizzle = ( - &wuffs_png__decoder__filter_and_swizzle_tricky); - } - } else if (self->private_impl.f_color_type == 6u) { - if (self->private_impl.f_depth == 8u) { - self->private_impl.f_dst_pixfmt = 2164295816u; - self->private_impl.f_src_pixfmt = 2701166728u; - self->private_impl.f_filter_distance = 4u; - } else if (self->private_impl.f_depth == 16u) { - self->private_impl.f_dst_pixfmt = 2164308923u; - self->private_impl.f_src_pixfmt = 2164308923u; - self->private_impl.f_filter_distance = 8u; - self->private_impl.choosy_filter_and_swizzle = ( - &wuffs_png__decoder__filter_and_swizzle_tricky); - } +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_png__decoder__decode_frame_config( + wuffs_png__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); } - return wuffs_base__make_empty_struct(); -} + 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); -// -------- func png.decoder.calculate_bytes_per_row + wuffs_base__status v_status = wuffs_base__make_status(NULL); -WUFFS_BASE__GENERATED_C_CODE -static uint64_t -wuffs_png__decoder__calculate_bytes_per_row( - const wuffs_png__decoder* self, - uint32_t a_width) { - uint64_t v_bytes_per_channel = 0; + uint32_t coro_susp_point = self->private_impl.p_decode_frame_config; + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - if (self->private_impl.f_depth == 1u) { - return ((uint64_t)(((a_width + 7u) / 8u))); - } else if (self->private_impl.f_depth == 2u) { - return ((uint64_t)(((a_width + 3u) / 4u))); - } else if (self->private_impl.f_depth == 4u) { - return ((uint64_t)(((a_width + 1u) / 2u))); + while (true) { + { + wuffs_base__status t_0 = wuffs_png__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_png__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; } - v_bytes_per_channel = ((uint64_t)(((uint8_t)(self->private_impl.f_depth >> 3u)))); - return (((uint64_t)(a_width)) * v_bytes_per_channel * ((uint64_t)(WUFFS_PNG__NUM_CHANNELS[self->private_impl.f_color_type]))); -} -// -------- func png.decoder.choose_filter_implementations + 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; -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_png__decoder__choose_filter_implementations( - wuffs_png__decoder* self) { - if (self->private_impl.f_filter_distance == 3u) { - self->private_impl.choosy_filter_1 = ( - &wuffs_png__decoder__filter_1_distance_3_fallback); - self->private_impl.choosy_filter_3 = ( - &wuffs_png__decoder__filter_3_distance_3_fallback); - self->private_impl.choosy_filter_4 = ( -#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON) - wuffs_base__cpu_arch__have_arm_neon() ? &wuffs_png__decoder__filter_4_distance_3_arm_neon : -#endif -#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) - wuffs_base__cpu_arch__have_x86_sse42() ? &wuffs_png__decoder__filter_4_distance_3_x86_sse42 : -#endif - &wuffs_png__decoder__filter_4_distance_3_fallback); - } else if (self->private_impl.f_filter_distance == 4u) { - self->private_impl.choosy_filter_1 = ( -#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON) - wuffs_base__cpu_arch__have_arm_neon() ? &wuffs_png__decoder__filter_1_distance_4_arm_neon : -#endif -#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) - wuffs_base__cpu_arch__have_x86_sse42() ? &wuffs_png__decoder__filter_1_distance_4_x86_sse42 : -#endif - &wuffs_png__decoder__filter_1_distance_4_fallback); - self->private_impl.choosy_filter_3 = ( -#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON) - wuffs_base__cpu_arch__have_arm_neon() ? &wuffs_png__decoder__filter_3_distance_4_arm_neon : -#endif -#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) - wuffs_base__cpu_arch__have_x86_sse42() ? &wuffs_png__decoder__filter_3_distance_4_x86_sse42 : -#endif - &wuffs_png__decoder__filter_3_distance_4_fallback); - self->private_impl.choosy_filter_4 = ( -#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON) - wuffs_base__cpu_arch__have_arm_neon() ? &wuffs_png__decoder__filter_4_distance_4_arm_neon : -#endif -#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) - wuffs_base__cpu_arch__have_x86_sse42() ? &wuffs_png__decoder__filter_4_distance_4_x86_sse42 : -#endif - &wuffs_png__decoder__filter_4_distance_4_fallback); + goto exit; + exit: + if (wuffs_base__status__is_error(&status)) { + self->private_impl.magic = WUFFS_BASE__DISABLED; } - return wuffs_base__make_empty_struct(); + return status; } -// -------- func png.decoder.decode_other_chunk +// -------- func png.decoder.do_decode_frame_config WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_png__decoder__decode_other_chunk( +wuffs_png__decoder__do_decode_frame_config( wuffs_png__decoder* self, - wuffs_base__io_buffer* a_src, - bool a_framy) { + wuffs_base__frame_config* a_dst, + wuffs_base__io_buffer* a_src) { wuffs_base__status status = wuffs_base__make_status(NULL); + uint32_t v_checksum_have = 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; @@ -63411,218 +68697,392 @@ wuffs_png__decoder__decode_other_chunk( io2_a_src = io0_a_src + a_src->meta.wi; } - uint32_t coro_susp_point = self->private_impl.p_decode_other_chunk; + 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_chunk_type == 1163152464u) && ! a_framy) { - if (self->private_impl.f_seen_plte) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } else if (self->private_impl.f_color_type == 3u) { - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - status = wuffs_png__decoder__decode_plte(self, 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_color_type == 2u) || (self->private_impl.f_color_type == 6u)) { - } else { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; + if (((uint8_t)(self->private_impl.f_call_sequence & 16u)) != 0u) { + status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence); + goto exit; + } else 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)); } - self->private_impl.f_seen_plte = true; - } else if ((self->private_impl.f_chunk_type & 32u) == 0u) { - if (self->private_impl.f_chunk_type != 1413563465u) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + status = wuffs_png__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 (self->private_impl.f_frame_config_io_position != 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) { + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); + status = wuffs_png__decoder__skip_frame(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } + } else { + status = wuffs_base__make_status(wuffs_base__note__end_of_data); + goto ok; } - if (self->private_impl.f_chunk_type == 1716082789u) { - if (self->private_impl.f_report_metadata_exif) { - if (self->private_impl.f_seen_exif) { + if (self->private_impl.f_metadata_fourcc != 0u) { + self->private_impl.f_call_sequence = 48u; + status = wuffs_base__make_status(wuffs_base__note__metadata_reported); + goto ok; + } + if (self->private_impl.f_num_decoded_frame_configs_value == 0u) { + self->private_impl.f_frame_rect_x0 = self->private_impl.f_first_rect_x0; + self->private_impl.f_frame_rect_y0 = self->private_impl.f_first_rect_y0; + self->private_impl.f_frame_rect_x1 = self->private_impl.f_first_rect_x1; + self->private_impl.f_frame_rect_y1 = self->private_impl.f_first_rect_y1; + self->private_impl.f_frame_config_io_position = self->private_impl.f_first_config_io_position; + self->private_impl.f_frame_duration = self->private_impl.f_first_duration; + self->private_impl.f_frame_disposal = self->private_impl.f_first_disposal; + self->private_impl.f_frame_overwrite_instead_of_blend = self->private_impl.f_first_overwrite_instead_of_blend; + } else { + while (true) { + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + uint32_t t_0; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_0 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); + iop_a_src += 4; + } else { + self->private_data.s_do_decode_frame_config.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + 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_frame_config.scratch; + uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0); + if (num_bits_0 == 24) { + t_0 = ((uint32_t)(*scratch >> 32)); + break; + } + num_bits_0 += 8u; + *scratch |= ((uint64_t)(num_bits_0)); + } + } + self->private_impl.f_chunk_length = t_0; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); + uint32_t t_1; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_1 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src); + iop_a_src += 4; + } else { + self->private_data.s_do_decode_frame_config.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); + 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_frame_config.scratch; + uint32_t num_bits_1 = ((uint32_t)(*scratch >> 56)); + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_1; + if (num_bits_1 == 24) { + t_1 = ((uint32_t)(*scratch)); + break; + } + num_bits_1 += 8u; + *scratch |= ((uint64_t)(num_bits_1)) << 56; + } + } + self->private_impl.f_chunk_type = t_1; + } + if (self->private_impl.f_chunk_type == 1145980233u) { + if (self->private_impl.f_chunk_length != 0u) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); + uint32_t t_2; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_2 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src); + iop_a_src += 4; + } else { + self->private_data.s_do_decode_frame_config.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); + 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_frame_config.scratch; + uint32_t num_bits_2 = ((uint32_t)(*scratch >> 56)); + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_2; + if (num_bits_2 == 24) { + t_2 = ((uint32_t)(*scratch)); + break; + } + num_bits_2 += 8u; + *scratch |= ((uint64_t)(num_bits_2)) << 56; + } + } + v_checksum_have = t_2; + } + if ( ! self->private_impl.f_ignore_checksum && (v_checksum_have != 2187346606u)) { + status = wuffs_base__make_status(wuffs_png__error__bad_checksum); + goto exit; + } + self->private_impl.f_call_sequence = 96u; + status = wuffs_base__make_status(wuffs_base__note__end_of_data); + goto ok; + } else if (self->private_impl.f_chunk_type == 1413571686u) { status = wuffs_base__make_status(wuffs_png__error__bad_chunk); goto exit; + } else if (self->private_impl.f_chunk_type == 1280598886u) { + self->private_impl.f_frame_config_io_position = ((uint64_t)(wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))) - 8u)); + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); + status = wuffs_png__decoder__decode_fctl(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } + self->private_data.s_do_decode_frame_config.scratch = 4u; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10); + if (self->private_data.s_do_decode_frame_config.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { + self->private_data.s_do_decode_frame_config.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); + iop_a_src = io2_a_src; + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + iop_a_src += self->private_data.s_do_decode_frame_config.scratch; + break; } if (a_src) { a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); - status = wuffs_png__decoder__decode_exif(self, a_src); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11); + status = wuffs_png__decoder__decode_other_chunk(self, a_src, true); if (a_src) { iop_a_src = a_src->data.ptr + a_src->meta.ri; } if (status.repr) { goto suspend; } - self->private_impl.f_seen_exif = true; + if (self->private_impl.f_metadata_fourcc != 0u) { + self->private_impl.f_call_sequence = 48u; + status = wuffs_base__make_status(wuffs_base__note__metadata_reported); + goto ok; + } + self->private_data.s_do_decode_frame_config.scratch = 4u; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12); + if (self->private_data.s_do_decode_frame_config.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { + self->private_data.s_do_decode_frame_config.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); + iop_a_src = io2_a_src; + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + iop_a_src += self->private_data.s_do_decode_frame_config.scratch; + self->private_impl.f_chunk_length = 0u; } - } else if ((self->private_impl.f_chunk_type == 1951945833u) || (self->private_impl.f_chunk_type == 1951942004u) || (self->private_impl.f_chunk_type == 1951945850u)) { - if (self->private_impl.f_report_metadata_kvp) { - self->private_impl.f_metadata_flavor = 4u; - self->private_impl.f_metadata_fourcc = 1263947851u; - self->private_impl.f_metadata_x = 0u; - self->private_impl.f_metadata_y = 0u; - self->private_impl.f_metadata_z = 0u; + } + if (a_dst != NULL) { + wuffs_base__frame_config__set( + a_dst, + wuffs_base__utility__make_rect_ie_u32( + self->private_impl.f_frame_rect_x0, + self->private_impl.f_frame_rect_y0, + self->private_impl.f_frame_rect_x1, + self->private_impl.f_frame_rect_y1), + ((wuffs_base__flicks)(self->private_impl.f_frame_duration)), + ((uint64_t)(self->private_impl.f_num_decoded_frame_configs_value)), + self->private_impl.f_frame_config_io_position, + self->private_impl.f_frame_disposal, + ((self->private_impl.f_color_type <= 3u) && ! self->private_impl.f_seen_trns), + self->private_impl.f_frame_overwrite_instead_of_blend, + 0u); + } + wuffs_private_impl__u32__sat_add_indirect(&self->private_impl.f_num_decoded_frame_configs_value, 1u); + 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 png.decoder.skip_frame + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_png__decoder__skip_frame( + wuffs_png__decoder* self, + wuffs_base__io_buffer* a_src) { + wuffs_base__status status = wuffs_base__make_status(NULL); + + uint32_t v_seq_num = 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_skip_frame; + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + + self->private_impl.f_chunk_type_array[0u] = 0u; + self->private_impl.f_chunk_type_array[1u] = 0u; + self->private_impl.f_chunk_type_array[2u] = 0u; + self->private_impl.f_chunk_type_array[3u] = 0u; + while (true) { + if (((uint64_t)(io2_a_src - iop_a_src)) < 8u) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1); + continue; } - } else if ( ! a_framy) { - if (self->private_impl.f_chunk_type == 1280598881u) { - if (self->private_impl.f_seen_actl) { + self->private_impl.f_chunk_length = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); + self->private_impl.f_chunk_type = ((uint32_t)((wuffs_base__peek_u64le__no_bounds_check(iop_a_src) >> 32u))); + if (self->private_impl.f_chunk_type == 1413563465u) { + if (self->private_impl.f_chunk_type_array[0u] == 102u) { status = wuffs_base__make_status(wuffs_png__error__bad_chunk); goto exit; } - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - status = wuffs_png__decoder__decode_actl(self, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; - } - self->private_impl.f_seen_actl = true; - } else if (self->private_impl.f_chunk_type == 1297238115u) { - if (self->private_impl.f_report_metadata_chrm) { - if (self->private_impl.f_seen_chrm) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); - status = wuffs_png__decoder__decode_chrm(self, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; - } - self->private_impl.f_seen_chrm = true; - } - } else if (self->private_impl.f_chunk_type == 1280598886u) { - if (self->private_impl.f_seen_fctl) { + self->private_impl.f_chunk_type_array[0u] = 73u; + self->private_impl.f_chunk_type_array[1u] = 68u; + self->private_impl.f_chunk_type_array[2u] = 65u; + self->private_impl.f_chunk_type_array[3u] = 84u; + } else if (self->private_impl.f_chunk_type == 1413571686u) { + if (self->private_impl.f_chunk_type_array[0u] == 73u) { status = wuffs_base__make_status(wuffs_png__error__bad_chunk); goto exit; } - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); - status = wuffs_png__decoder__decode_fctl(self, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; - } - self->private_impl.f_seen_fctl = true; - } else if (self->private_impl.f_chunk_type == 1095582055u) { - if (self->private_impl.f_report_metadata_gama) { - if (self->private_impl.f_seen_gama) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); - status = wuffs_png__decoder__decode_gama(self, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; - } - self->private_impl.f_seen_gama = true; - } - } else if (self->private_impl.f_chunk_type == 1346585449u) { - if (self->private_impl.f_report_metadata_iccp) { - if (self->private_impl.f_seen_iccp) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); - status = wuffs_png__decoder__decode_iccp(self, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; - } - self->private_impl.f_seen_iccp = true; + self->private_impl.f_chunk_type_array[0u] = 102u; + self->private_impl.f_chunk_type_array[1u] = 100u; + self->private_impl.f_chunk_type_array[2u] = 65u; + self->private_impl.f_chunk_type_array[3u] = 84u; + if (self->private_impl.f_chunk_length < 4u) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; } - } else if (self->private_impl.f_chunk_type == 1111970419u) { - if (self->private_impl.f_report_metadata_srgb) { - if (self->private_impl.f_seen_srgb) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); - status = wuffs_png__decoder__decode_srgb(self, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; + self->private_impl.f_chunk_length -= 4u; + iop_a_src += 8u; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); + uint32_t t_0; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_0 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); + iop_a_src += 4; + } else { + self->private_data.s_skip_frame.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + 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_skip_frame.scratch; + uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0); + if (num_bits_0 == 24) { + t_0 = ((uint32_t)(*scratch >> 32)); + break; + } + num_bits_0 += 8u; + *scratch |= ((uint64_t)(num_bits_0)); + } } - self->private_impl.f_seen_srgb = true; + v_seq_num = t_0; } - } else if (self->private_impl.f_chunk_type == 1397641844u) { - if (self->private_impl.f_seen_trns || ((self->private_impl.f_color_type == 3u) && ! self->private_impl.f_seen_plte)) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + if (v_seq_num != self->private_impl.f_next_animation_seq_num) { + status = wuffs_base__make_status(wuffs_png__error__bad_animation_sequence_number); + goto exit; + } else if (self->private_impl.f_next_animation_seq_num >= 4294967295u) { + status = wuffs_base__make_status(wuffs_png__error__unsupported_png_file); goto exit; - } else if (self->private_impl.f_color_type > 3u) { - } else { - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); - status = wuffs_png__decoder__decode_trns(self, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; - } } - self->private_impl.f_seen_trns = true; + self->private_impl.f_next_animation_seq_num += 1u; + self->private_data.s_skip_frame.scratch = (((uint64_t)(self->private_impl.f_chunk_length)) + 4u); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + if (self->private_data.s_skip_frame.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { + self->private_data.s_skip_frame.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); + iop_a_src = io2_a_src; + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + iop_a_src += self->private_data.s_skip_frame.scratch; + self->private_impl.f_chunk_length = 0u; + continue; + } else if (self->private_impl.f_chunk_type_array[0u] != 0u) { + break; + } else if (self->private_impl.f_chunk_type == 1280598886u) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; } - } - if (self->private_impl.f_metadata_fourcc == 0u) { - self->private_data.s_decode_other_chunk.scratch = self->private_impl.f_chunk_length; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10); - if (self->private_data.s_decode_other_chunk.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { - self->private_data.s_decode_other_chunk.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); + self->private_data.s_skip_frame.scratch = (((uint64_t)(self->private_impl.f_chunk_length)) + 12u); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); + if (self->private_data.s_skip_frame.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { + self->private_data.s_skip_frame.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); iop_a_src = io2_a_src; status = wuffs_base__make_status(wuffs_base__suspension__short_read); goto suspend; } - iop_a_src += self->private_data.s_decode_other_chunk.scratch; + iop_a_src += self->private_data.s_skip_frame.scratch; + self->private_impl.f_chunk_length = 0u; } + wuffs_private_impl__u32__sat_add_indirect(&self->private_impl.f_num_decoded_frames_value, 1u); + self->private_impl.f_call_sequence = 32u; - goto ok; ok: - self->private_impl.p_decode_other_chunk = 0; + self->private_impl.p_skip_frame = 0; goto exit; } goto suspend; suspend: - self->private_impl.p_decode_other_chunk = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_impl.p_skip_frame = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; goto exit; exit: @@ -63633,15 +69093,98 @@ wuffs_png__decoder__decode_other_chunk( return status; } -// -------- func png.decoder.decode_actl +// -------- func png.decoder.decode_frame + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_png__decoder__decode_frame( + wuffs_png__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_png__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_png__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 png.decoder.do_decode_frame WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_png__decoder__decode_actl( +wuffs_png__decoder__do_decode_frame( wuffs_png__decoder* self, - wuffs_base__io_buffer* a_src) { + 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); + uint32_t v_seq_num = 0; + wuffs_base__status v_status = wuffs_base__make_status(NULL); + uint32_t v_pass_width = 0; + uint32_t v_pass_height = 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; @@ -63653,90 +69196,210 @@ wuffs_png__decoder__decode_actl( io2_a_src = io0_a_src + a_src->meta.wi; } - uint32_t coro_susp_point = self->private_impl.p_decode_actl; + 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_chunk_length != 8u) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } else if (self->private_impl.f_interlace_pass > 0u) { - status = wuffs_base__make_status(wuffs_png__error__unsupported_png_file); + if (((uint8_t)(self->private_impl.f_call_sequence & 16u)) != 0u) { + status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence); goto exit; - } - self->private_impl.f_chunk_length = 0u; - { + } else if (self->private_impl.f_call_sequence >= 96u) { + status = wuffs_base__make_status(wuffs_base__note__end_of_data); + goto ok; + } else if (self->private_impl.f_call_sequence != 64u) { + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - uint32_t t_0; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_0 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_decode_actl.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_decode_actl.scratch; - uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0); - if (num_bits_0 == 24) { - t_0 = ((uint32_t)(*scratch >> 32)); - break; + status = wuffs_png__decoder__do_decode_frame_config(self, NULL, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } + } + while (true) { + if (((uint64_t)(io2_a_src - iop_a_src)) < 8u) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2); + continue; + } + self->private_impl.f_chunk_length = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); + self->private_impl.f_chunk_type = ((uint32_t)((wuffs_base__peek_u64le__no_bounds_check(iop_a_src) >> 32u))); + if (self->private_impl.f_chunk_type == 1413563465u) { + self->private_impl.f_chunk_type_array[0u] = 73u; + self->private_impl.f_chunk_type_array[1u] = 68u; + self->private_impl.f_chunk_type_array[2u] = 65u; + self->private_impl.f_chunk_type_array[3u] = 84u; + iop_a_src += 8u; + if ( ! self->private_impl.f_ignore_checksum) { + wuffs_private_impl__ignore_status(wuffs_crc32__ieee_hasher__initialize(&self->private_data.f_crc32, + sizeof (wuffs_crc32__ieee_hasher), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED)); + wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__make_slice_u8(self->private_impl.f_chunk_type_array, 4)); + } + break; + } else if (self->private_impl.f_chunk_type == 1413571686u) { + self->private_impl.f_chunk_type_array[0u] = 102u; + self->private_impl.f_chunk_type_array[1u] = 100u; + self->private_impl.f_chunk_type_array[2u] = 65u; + self->private_impl.f_chunk_type_array[3u] = 84u; + if (self->private_impl.f_chunk_length < 4u) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } + self->private_impl.f_chunk_length -= 4u; + iop_a_src += 8u; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + uint32_t t_0; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_0 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); + iop_a_src += 4; + } else { + self->private_data.s_do_decode_frame.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + 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_frame.scratch; + uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0); + if (num_bits_0 == 24) { + t_0 = ((uint32_t)(*scratch >> 32)); + break; + } + num_bits_0 += 8u; + *scratch |= ((uint64_t)(num_bits_0)); + } } - num_bits_0 += 8u; - *scratch |= ((uint64_t)(num_bits_0)); + v_seq_num = t_0; + } + if (v_seq_num != self->private_impl.f_next_animation_seq_num) { + status = wuffs_base__make_status(wuffs_png__error__bad_animation_sequence_number); + goto exit; + } else if (self->private_impl.f_next_animation_seq_num >= 4294967295u) { + status = wuffs_base__make_status(wuffs_png__error__unsupported_png_file); + goto exit; } + self->private_impl.f_next_animation_seq_num += 1u; + break; + } else if (self->private_impl.f_chunk_type == 1280598886u) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; } - self->private_impl.f_num_animation_frames_value = t_0; + self->private_data.s_do_decode_frame.scratch = (((uint64_t)(self->private_impl.f_chunk_length)) + 12u); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); + if (self->private_data.s_do_decode_frame.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { + self->private_data.s_do_decode_frame.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); + iop_a_src = io2_a_src; + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + iop_a_src += self->private_data.s_do_decode_frame.scratch; + self->private_impl.f_chunk_length = 0u; } - if (self->private_impl.f_num_animation_frames_value == 0u) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; + if (self->private_impl.f_zlib_is_dirty) { + wuffs_private_impl__ignore_status(wuffs_zlib__decoder__initialize(&self->private_data.f_zlib, + sizeof (wuffs_zlib__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED)); + if (self->private_impl.f_ignore_checksum) { + wuffs_zlib__decoder__set_quirk(&self->private_data.f_zlib, 1u, 1u); + } } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - uint32_t t_1; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_1 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); - iop_a_src += 4; + self->private_impl.f_zlib_is_dirty = true; + 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_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024)), + wuffs_base__utility__make_pixel_format(self->private_impl.f_src_pixfmt), + wuffs_base__make_slice_u8(self->private_data.f_src_palette, 1024), + 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; + } + self->private_impl.f_workbuf_hist_pos_base = 0u; + while (true) { + if (self->private_impl.f_chunk_type_array[0u] == 73u) { + v_pass_width = (16777215u & ((((uint32_t)(WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][1u])) + self->private_impl.f_width) >> WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][0u])); + v_pass_height = (16777215u & ((((uint32_t)(WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][4u])) + self->private_impl.f_height) >> WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][3u])); } else { - self->private_data.s_decode_actl.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + v_pass_width = (16777215u & ((uint32_t)(self->private_impl.f_frame_rect_x1 - self->private_impl.f_frame_rect_x0))); + v_pass_height = (16777215u & ((uint32_t)(self->private_impl.f_frame_rect_y1 - self->private_impl.f_frame_rect_y0))); + } + if ((v_pass_width > 0u) && (v_pass_height > 0u)) { + self->private_impl.f_pass_bytes_per_row = wuffs_png__decoder__calculate_bytes_per_row(self, v_pass_width); + self->private_impl.f_pass_workbuf_length = (((uint64_t)(v_pass_height)) * (1u + self->private_impl.f_pass_bytes_per_row)); while (true) { - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; + { + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + wuffs_base__status t_1 = wuffs_png__decoder__decode_pass(self, a_src, a_workbuf); + v_status = t_1; + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } } - uint64_t* scratch = &self->private_data.s_decode_actl.scratch; - uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1); - if (num_bits_1 == 24) { - t_1 = ((uint32_t)(*scratch >> 32)); + if (wuffs_base__status__is_ok(&v_status)) { break; + } else if (wuffs_base__status__is_error(&v_status) || ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed))) { + if (self->private_impl.f_workbuf_wi <= ((uint64_t)(a_workbuf.len))) { + wuffs_png__decoder__filter_and_swizzle(self, a_dst, wuffs_base__slice_u8__subslice_j(a_workbuf, self->private_impl.f_workbuf_wi)); + } + if (v_status.repr == wuffs_base__suspension__short_read) { + status = wuffs_base__make_status(wuffs_png__error__truncated_input); + goto exit; + } } - num_bits_1 += 8u; - *scratch |= ((uint64_t)(num_bits_1)); + status = v_status; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6); + } + v_status = wuffs_png__decoder__filter_and_swizzle(self, a_dst, a_workbuf); + 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_workbuf_hist_pos_base += self->private_impl.f_pass_workbuf_length; } - self->private_impl.f_num_animation_loops_value = t_1; + if ((self->private_impl.f_interlace_pass == 0u) || (self->private_impl.f_interlace_pass >= 7u)) { + break; + } +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + self->private_impl.f_interlace_pass += 1u; +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif } + wuffs_private_impl__u32__sat_add_indirect(&self->private_impl.f_num_decoded_frames_value, 1u); + self->private_impl.f_call_sequence = 32u; - goto ok; ok: - self->private_impl.p_decode_actl = 0; + self->private_impl.p_do_decode_frame = 0; goto exit; } goto suspend; suspend: - self->private_impl.p_decode_actl = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_impl.p_do_decode_frame = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; goto exit; exit: @@ -63747,16 +69410,28 @@ wuffs_png__decoder__decode_actl( return status; } -// -------- func png.decoder.decode_chrm +// -------- func png.decoder.decode_pass WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_png__decoder__decode_chrm( +wuffs_png__decoder__decode_pass( wuffs_png__decoder* self, - wuffs_base__io_buffer* a_src) { + wuffs_base__io_buffer* a_src, + wuffs_base__slice_u8 a_workbuf) { wuffs_base__status status = wuffs_base__make_status(NULL); - uint64_t v_u = 0; + wuffs_base__io_buffer u_w = wuffs_base__empty_io_buffer(); + wuffs_base__io_buffer* v_w = &u_w; + uint8_t* iop_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + uint8_t* io0_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + uint8_t* io1_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + uint8_t* io2_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + uint64_t v_w_mark = 0; + uint64_t v_r_mark = 0; + wuffs_base__status v_zlib_status = wuffs_base__make_status(NULL); + uint32_t v_checksum_have = 0; + uint32_t v_checksum_want = 0; + uint32_t v_seq_num = 0; const uint8_t* iop_a_src = NULL; const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL; @@ -63769,272 +69444,304 @@ wuffs_png__decoder__decode_chrm( io2_a_src = io0_a_src + a_src->meta.wi; } - uint32_t coro_susp_point = self->private_impl.p_decode_chrm; + uint32_t coro_susp_point = self->private_impl.p_decode_pass; switch (coro_susp_point) { WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - if (self->private_impl.f_chunk_length != 32u) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } - self->private_impl.f_chunk_length = 0u; - self->private_impl.f_metadata_flavor = 5u; - self->private_impl.f_metadata_fourcc = 1128813133u; - self->private_impl.f_metadata_x = 0u; - self->private_impl.f_metadata_y = 0u; - self->private_impl.f_metadata_z = 0u; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - uint64_t t_0; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_0 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src))); - iop_a_src += 4; - } else { - self->private_data.s_decode_chrm.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_decode_chrm.scratch; - uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0); - if (num_bits_0 == 24) { - t_0 = ((uint64_t)(*scratch >> 32)); - break; - } - num_bits_0 += 8u; - *scratch |= ((uint64_t)(num_bits_0)); - } + self->private_impl.f_workbuf_wi = 0u; + while (true) { + if ((self->private_impl.f_workbuf_wi > self->private_impl.f_pass_workbuf_length) || (self->private_impl.f_pass_workbuf_length > ((uint64_t)(a_workbuf.len)))) { + status = wuffs_base__make_status(wuffs_base__error__bad_workbuf_length); + goto exit; } - v_u = t_0; - } - self->private_impl.f_metadata_x |= ((16777215u & v_u) << 0u); - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - uint64_t t_1; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_1 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src))); - iop_a_src += 4; - } else { - self->private_data.s_decode_chrm.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); - while (true) { - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; + { + wuffs_base__io_buffer* o_0_v_w = v_w; + uint8_t* o_0_iop_v_w = iop_v_w; + uint8_t* o_0_io0_v_w = io0_v_w; + uint8_t* o_0_io1_v_w = io1_v_w; + uint8_t* o_0_io2_v_w = io2_v_w; + v_w = wuffs_private_impl__io_writer__set( + &u_w, + &iop_v_w, + &io0_v_w, + &io1_v_w, + &io2_v_w, + wuffs_base__slice_u8__subslice_ij(a_workbuf, + self->private_impl.f_workbuf_wi, + self->private_impl.f_pass_workbuf_length), + ((uint64_t)(self->private_impl.f_workbuf_hist_pos_base + self->private_impl.f_workbuf_wi))); + { + const bool o_1_closed_a_src = a_src->meta.closed; + const uint8_t* o_1_io2_a_src = io2_a_src; + wuffs_private_impl__io_reader__limit(&io2_a_src, iop_a_src, + ((uint64_t)(self->private_impl.f_chunk_length))); + if (a_src) { + size_t n = ((size_t)(io2_a_src - a_src->data.ptr)); + a_src->meta.closed = a_src->meta.closed && (a_src->meta.wi <= n); + a_src->meta.wi = n; } - uint64_t* scratch = &self->private_data.s_decode_chrm.scratch; - uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1); - if (num_bits_1 == 24) { - t_1 = ((uint64_t)(*scratch >> 32)); - break; + v_w_mark = ((uint64_t)(iop_v_w - io0_v_w)); + v_r_mark = ((uint64_t)(iop_a_src - io0_a_src)); + { + u_w.meta.wi = ((size_t)(iop_v_w - u_w.data.ptr)); + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + wuffs_base__status t_0 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, v_w, a_src, wuffs_base__utility__empty_slice_u8()); + v_zlib_status = t_0; + iop_v_w = u_w.data.ptr + u_w.meta.wi; + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } } - num_bits_1 += 8u; - *scratch |= ((uint64_t)(num_bits_1)); - } - } - v_u = t_1; - } - self->private_impl.f_metadata_x |= ((16777215u & v_u) << 24u); - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); - uint64_t t_2; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_2 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src))); - iop_a_src += 4; - } else { - self->private_data.s_decode_chrm.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); - while (true) { - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; + if ( ! self->private_impl.f_ignore_checksum) { + wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_private_impl__io__since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src)), io0_a_src)); } - uint64_t* scratch = &self->private_data.s_decode_chrm.scratch; - uint32_t num_bits_2 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_2); - if (num_bits_2 == 24) { - t_2 = ((uint64_t)(*scratch >> 32)); - break; + wuffs_private_impl__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)(wuffs_private_impl__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src)))))); + wuffs_private_impl__u64__sat_add_indirect(&self->private_impl.f_workbuf_wi, wuffs_private_impl__io__count_since(v_w_mark, ((uint64_t)(iop_v_w - io0_v_w)))); + io2_a_src = o_1_io2_a_src; + if (a_src) { + a_src->meta.closed = o_1_closed_a_src; + a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr)); } - num_bits_2 += 8u; - *scratch |= ((uint64_t)(num_bits_2)); } + v_w = o_0_v_w; + iop_v_w = o_0_iop_v_w; + io0_v_w = o_0_io0_v_w; + io1_v_w = o_0_io1_v_w; + io2_v_w = o_0_io2_v_w; } - v_u = t_2; - } - self->private_impl.f_metadata_x |= ((uint64_t)((16777215u & v_u) << 48u)); - self->private_impl.f_metadata_y |= ((16777215u & v_u) >> 16u); - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); - uint64_t t_3; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_3 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src))); - iop_a_src += 4; - } else { - self->private_data.s_decode_chrm.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); - while (true) { - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; + if (wuffs_base__status__is_ok(&v_zlib_status)) { + if (self->private_impl.f_chunk_length > 0u) { + status = wuffs_base__make_status(wuffs_base__error__too_much_data); + goto exit; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + uint32_t t_1; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_1 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); + iop_a_src += 4; + } else { + self->private_data.s_decode_pass.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_decode_pass.scratch; + uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1); + if (num_bits_1 == 24) { + t_1 = ((uint32_t)(*scratch >> 32)); + break; + } + num_bits_1 += 8u; + *scratch |= ((uint64_t)(num_bits_1)); + } } - uint64_t* scratch = &self->private_data.s_decode_chrm.scratch; - uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3); - if (num_bits_3 == 24) { - t_3 = ((uint64_t)(*scratch >> 32)); - break; + v_checksum_want = t_1; + } + if ( ! self->private_impl.f_ignore_checksum && (self->private_impl.f_chunk_type_array[0u] == 73u)) { + v_checksum_have = wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__utility__empty_slice_u8()); + if (v_checksum_have != v_checksum_want) { + status = wuffs_base__make_status(wuffs_png__error__bad_checksum); + goto exit; } - num_bits_3 += 8u; - *scratch |= ((uint64_t)(num_bits_3)); } - } - v_u = t_3; - } - self->private_impl.f_metadata_y |= ((16777215u & v_u) << 8u); - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); - uint64_t t_4; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_4 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src))); - iop_a_src += 4; - } else { - self->private_data.s_decode_chrm.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10); - while (true) { - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; + break; + } else if (v_zlib_status.repr == wuffs_base__suspension__short_write) { + if ((1u <= self->private_impl.f_interlace_pass) && (self->private_impl.f_interlace_pass <= 6u)) { + break; + } + status = wuffs_base__make_status(wuffs_base__error__too_much_data); + goto exit; + } else if (v_zlib_status.repr != wuffs_base__suspension__short_read) { + status = v_zlib_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; + } else if (self->private_impl.f_chunk_length == 0u) { + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + uint32_t t_2; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_2 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); + iop_a_src += 4; + } else { + self->private_data.s_decode_pass.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + 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_decode_pass.scratch; + uint32_t num_bits_2 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_2); + if (num_bits_2 == 24) { + t_2 = ((uint32_t)(*scratch >> 32)); + break; + } + num_bits_2 += 8u; + *scratch |= ((uint64_t)(num_bits_2)); + } } - uint64_t* scratch = &self->private_data.s_decode_chrm.scratch; - uint32_t num_bits_4 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_4); - if (num_bits_4 == 24) { - t_4 = ((uint64_t)(*scratch >> 32)); - break; + v_checksum_want = t_2; + } + if ( ! self->private_impl.f_ignore_checksum && (self->private_impl.f_chunk_type_array[0u] == 73u)) { + v_checksum_have = wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__utility__empty_slice_u8()); + if (v_checksum_have != v_checksum_want) { + status = wuffs_base__make_status(wuffs_png__error__bad_checksum); + goto exit; } - num_bits_4 += 8u; - *scratch |= ((uint64_t)(num_bits_4)); } - } - v_u = t_4; - } - self->private_impl.f_metadata_y |= ((16777215u & v_u) << 32u); - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11); - uint64_t t_5; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_5 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src))); - iop_a_src += 4; - } else { - self->private_data.s_decode_chrm.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12); - while (true) { - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); + uint32_t t_3; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); + iop_a_src += 4; + } else { + self->private_data.s_decode_pass.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); + 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_decode_pass.scratch; + uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3); + if (num_bits_3 == 24) { + t_3 = ((uint32_t)(*scratch >> 32)); + break; + } + num_bits_3 += 8u; + *scratch |= ((uint64_t)(num_bits_3)); + } } - uint64_t* scratch = &self->private_data.s_decode_chrm.scratch; - uint32_t num_bits_5 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_5); - if (num_bits_5 == 24) { - t_5 = ((uint64_t)(*scratch >> 32)); - break; + self->private_impl.f_chunk_length = t_3; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); + uint32_t t_4; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_4 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src); + iop_a_src += 4; + } else { + self->private_data.s_decode_pass.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); + 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_decode_pass.scratch; + uint32_t num_bits_4 = ((uint32_t)(*scratch >> 56)); + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_4; + if (num_bits_4 == 24) { + t_4 = ((uint32_t)(*scratch)); + break; + } + num_bits_4 += 8u; + *scratch |= ((uint64_t)(num_bits_4)) << 56; + } } - num_bits_5 += 8u; - *scratch |= ((uint64_t)(num_bits_5)); + self->private_impl.f_chunk_type = t_4; } - } - v_u = t_5; - } - self->private_impl.f_metadata_y |= ((uint64_t)((16777215u & v_u) << 56u)); - self->private_impl.f_metadata_z |= ((16777215u & v_u) >> 8u); - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13); - uint64_t t_6; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_6 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src))); - iop_a_src += 4; - } else { - self->private_data.s_decode_chrm.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(14); - while (true) { - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; + if (self->private_impl.f_chunk_type_array[0u] == 73u) { + if (self->private_impl.f_chunk_type != 1413563465u) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; } - uint64_t* scratch = &self->private_data.s_decode_chrm.scratch; - uint32_t num_bits_6 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_6); - if (num_bits_6 == 24) { - t_6 = ((uint64_t)(*scratch >> 32)); - break; + if ( ! self->private_impl.f_ignore_checksum) { + wuffs_private_impl__ignore_status(wuffs_crc32__ieee_hasher__initialize(&self->private_data.f_crc32, + sizeof (wuffs_crc32__ieee_hasher), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED)); + wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__make_slice_u8(self->private_impl.f_chunk_type_array, 4)); } - num_bits_6 += 8u; - *scratch |= ((uint64_t)(num_bits_6)); - } - } - v_u = t_6; - } - self->private_impl.f_metadata_z |= ((16777215u & v_u) << 16u); - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15); - uint64_t t_7; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_7 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src))); - iop_a_src += 4; - } else { - self->private_data.s_decode_chrm.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16); - while (true) { - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; + } else { + if ((self->private_impl.f_chunk_type != 1413571686u) || (self->private_impl.f_chunk_length < 4u)) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; } - uint64_t* scratch = &self->private_data.s_decode_chrm.scratch; - uint32_t num_bits_7 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_7); - if (num_bits_7 == 24) { - t_7 = ((uint64_t)(*scratch >> 32)); - break; + self->private_impl.f_chunk_length -= 4u; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); + uint32_t t_5; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_5 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); + iop_a_src += 4; + } else { + self->private_data.s_decode_pass.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10); + 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_decode_pass.scratch; + uint32_t num_bits_5 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_5); + if (num_bits_5 == 24) { + t_5 = ((uint32_t)(*scratch >> 32)); + break; + } + num_bits_5 += 8u; + *scratch |= ((uint64_t)(num_bits_5)); + } + } + v_seq_num = t_5; + } + if (v_seq_num != self->private_impl.f_next_animation_seq_num) { + status = wuffs_base__make_status(wuffs_png__error__bad_animation_sequence_number); + goto exit; + } else if (self->private_impl.f_next_animation_seq_num >= 4294967295u) { + status = wuffs_base__make_status(wuffs_png__error__unsupported_png_file); + goto exit; } - num_bits_7 += 8u; - *scratch |= ((uint64_t)(num_bits_7)); + self->private_impl.f_next_animation_seq_num += 1u; } + continue; + } else if (((uint64_t)(io2_a_src - iop_a_src)) > 0u) { + status = wuffs_base__make_status(wuffs_png__error__internal_error_zlib_decoder_did_not_exhaust_its_input); + goto exit; + } + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11); + } + if (self->private_impl.f_workbuf_wi != self->private_impl.f_pass_workbuf_length) { + status = wuffs_base__make_status(wuffs_base__error__not_enough_data); + goto exit; + } else if (0u < ((uint64_t)(a_workbuf.len))) { + if (a_workbuf.ptr[0u] == 4u) { + a_workbuf.ptr[0u] = 1u; } - v_u = t_7; } - self->private_impl.f_metadata_z |= ((16777215u & v_u) << 40u); - goto ok; ok: - self->private_impl.p_decode_chrm = 0; + self->private_impl.p_decode_pass = 0; goto exit; } goto suspend; suspend: - self->private_impl.p_decode_chrm = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_impl.p_decode_pass = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; goto exit; exit: @@ -64045,395 +69752,246 @@ wuffs_png__decoder__decode_chrm( return status; } -// -------- func png.decoder.decode_exif +// -------- func png.decoder.frame_dirty_rect WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__decode_exif( - wuffs_png__decoder* self, - wuffs_base__io_buffer* a_src) { - wuffs_base__status status = wuffs_base__make_status(NULL); +WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32 +wuffs_png__decoder__frame_dirty_rect( + const wuffs_png__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(); + } - 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; + return wuffs_base__utility__make_rect_ie_u32( + self->private_impl.f_frame_rect_x0, + self->private_impl.f_frame_rect_y0, + self->private_impl.f_frame_rect_x1, + self->private_impl.f_frame_rect_y1); +} + +// -------- func png.decoder.num_animation_loops + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC uint32_t +wuffs_png__decoder__num_animation_loops( + const wuffs_png__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_chunk_length < 4u) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; + return self->private_impl.f_num_animation_loops_value; +} + +// -------- func png.decoder.num_decoded_frame_configs + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC uint64_t +wuffs_png__decoder__num_decoded_frame_configs( + const wuffs_png__decoder* self) { + if (!self) { + return 0; + } + if ((self->private_impl.magic != WUFFS_BASE__MAGIC) && + (self->private_impl.magic != WUFFS_BASE__DISABLED)) { + return 0; } - self->private_impl.f_metadata_flavor = 3u; - self->private_impl.f_metadata_fourcc = 1163413830u; - self->private_impl.f_metadata_x = 0u; - self->private_impl.f_metadata_y = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))); - self->private_impl.f_metadata_z = wuffs_base__u64__sat_add(self->private_impl.f_metadata_y, ((uint64_t)(self->private_impl.f_chunk_length))); - self->private_impl.f_chunk_length = 0u; - goto ok; - ok: - goto exit; - exit: - if (a_src && a_src->data.ptr) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + return ((uint64_t)(self->private_impl.f_num_decoded_frame_configs_value)); +} + +// -------- func png.decoder.num_decoded_frames + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC uint64_t +wuffs_png__decoder__num_decoded_frames( + const wuffs_png__decoder* self) { + if (!self) { + return 0; + } + if ((self->private_impl.magic != WUFFS_BASE__MAGIC) && + (self->private_impl.magic != WUFFS_BASE__DISABLED)) { + return 0; } - return status; + return ((uint64_t)(self->private_impl.f_num_decoded_frames_value)); } -// -------- func png.decoder.decode_fctl +// -------- func png.decoder.restart_frame WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__decode_fctl( +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_png__decoder__restart_frame( wuffs_png__decoder* self, - wuffs_base__io_buffer* a_src) { - wuffs_base__status status = wuffs_base__make_status(NULL); + 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); + } - uint32_t v_x0 = 0; - uint32_t v_y0 = 0; - uint32_t v_x1 = 0; - uint32_t v_y1 = 0; + if (self->private_impl.f_call_sequence < 32u) { + return wuffs_base__make_status(wuffs_base__error__bad_call_sequence); + } else if ((a_index >= ((uint64_t)(self->private_impl.f_num_animation_frames_value))) || ((a_index == 0u) && (a_io_position != self->private_impl.f_first_config_io_position))) { + return wuffs_base__make_status(wuffs_base__error__bad_argument); + } + self->private_impl.f_call_sequence = 40u; + if (self->private_impl.f_interlace_pass >= 1u) { + self->private_impl.f_interlace_pass = 1u; + } + self->private_impl.f_frame_config_io_position = a_io_position; + self->private_impl.f_num_decoded_frame_configs_value = ((uint32_t)(a_index)); + self->private_impl.f_num_decoded_frames_value = self->private_impl.f_num_decoded_frame_configs_value; + return 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; +// -------- func png.decoder.set_report_metadata + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct +wuffs_png__decoder__set_report_metadata( + wuffs_png__decoder* self, + uint32_t a_fourcc, + bool a_report) { + if (!self) { + return wuffs_base__make_empty_struct(); + } + if (self->private_impl.magic != WUFFS_BASE__MAGIC) { + return wuffs_base__make_empty_struct(); } - uint32_t coro_susp_point = self->private_impl.p_decode_fctl; - if (coro_susp_point) { - v_x0 = self->private_data.s_decode_fctl.v_x0; - v_x1 = self->private_data.s_decode_fctl.v_x1; - v_y1 = self->private_data.s_decode_fctl.v_y1; + if (a_fourcc == 1128813133u) { + self->private_impl.f_report_metadata_chrm = a_report; + } else if (a_fourcc == 1163413830u) { + self->private_impl.f_report_metadata_exif = a_report; + } else if (a_fourcc == 1195461953u) { + self->private_impl.f_report_metadata_gama = a_report; + } else if (a_fourcc == 1229144912u) { + self->private_impl.f_report_metadata_iccp = a_report; + } else if (a_fourcc == 1263947808u) { + self->private_impl.f_report_metadata_kvp = a_report; + } else if (a_fourcc == 1397901122u) { + self->private_impl.f_report_metadata_srgb = a_report; + } + return wuffs_base__make_empty_struct(); +} + +// -------- func png.decoder.tell_me_more + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_png__decoder__tell_me_more( + wuffs_png__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); + + wuffs_base__status v_status = wuffs_base__make_status(NULL); + + uint32_t coro_susp_point = self->private_impl.p_tell_me_more; switch (coro_susp_point) { WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - if (self->private_impl.f_chunk_length != 26u) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } - self->private_impl.f_chunk_length = 0u; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - uint32_t t_0; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_0 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_decode_fctl.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_decode_fctl.scratch; - uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0); - if (num_bits_0 == 24) { - t_0 = ((uint32_t)(*scratch >> 32)); - break; - } - num_bits_0 += 8u; - *scratch |= ((uint64_t)(num_bits_0)); - } - } - v_x0 = t_0; - } - if (v_x0 != self->private_impl.f_next_animation_seq_num) { - status = wuffs_base__make_status(wuffs_png__error__bad_animation_sequence_number); - goto exit; - } else if (self->private_impl.f_next_animation_seq_num >= 4294967295u) { - status = wuffs_base__make_status(wuffs_png__error__unsupported_png_file); - goto exit; - } - self->private_impl.f_next_animation_seq_num += 1u; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - uint32_t t_1; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_1 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_decode_fctl.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); - 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_decode_fctl.scratch; - uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1); - if (num_bits_1 == 24) { - t_1 = ((uint32_t)(*scratch >> 32)); - break; - } - num_bits_1 += 8u; - *scratch |= ((uint64_t)(num_bits_1)); - } - } - v_x1 = t_1; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); - uint32_t t_2; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_2 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_decode_fctl.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); - 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_decode_fctl.scratch; - uint32_t num_bits_2 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_2); - if (num_bits_2 == 24) { - t_2 = ((uint32_t)(*scratch >> 32)); - break; - } - num_bits_2 += 8u; - *scratch |= ((uint64_t)(num_bits_2)); - } - } - v_y1 = t_2; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); - uint32_t t_3; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_decode_fctl.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); - 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_decode_fctl.scratch; - uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3); - if (num_bits_3 == 24) { - t_3 = ((uint32_t)(*scratch >> 32)); - break; - } - num_bits_3 += 8u; - *scratch |= ((uint64_t)(num_bits_3)); - } - } - v_x0 = t_3; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); - uint32_t t_4; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_4 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_decode_fctl.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10); - 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_decode_fctl.scratch; - uint32_t num_bits_4 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_4); - if (num_bits_4 == 24) { - t_4 = ((uint32_t)(*scratch >> 32)); - break; - } - num_bits_4 += 8u; - *scratch |= ((uint64_t)(num_bits_4)); - } - } - v_y0 = t_4; - } - v_x1 += v_x0; - v_y1 += v_y0; - if ((v_x0 >= v_x1) || - (v_x0 > self->private_impl.f_width) || - (v_x1 > self->private_impl.f_width) || - (v_y0 >= v_y1) || - (v_y0 > self->private_impl.f_height) || - (v_y1 > self->private_impl.f_height)) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } - self->private_impl.f_frame_rect_x0 = v_x0; - self->private_impl.f_frame_rect_y0 = v_y0; - self->private_impl.f_frame_rect_x1 = v_x1; - self->private_impl.f_frame_rect_y1 = v_y1; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11); - uint32_t t_5; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { - t_5 = ((uint32_t)(wuffs_base__peek_u16be__no_bounds_check(iop_a_src))); - iop_a_src += 2; - } else { - self->private_data.s_decode_fctl.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12); - 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_decode_fctl.scratch; - uint32_t num_bits_5 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_5); - if (num_bits_5 == 8) { - t_5 = ((uint32_t)(*scratch >> 48)); - break; - } - num_bits_5 += 8u; - *scratch |= ((uint64_t)(num_bits_5)); - } - } - v_x0 = t_5; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13); - uint32_t t_6; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { - t_6 = ((uint32_t)(wuffs_base__peek_u16be__no_bounds_check(iop_a_src))); - iop_a_src += 2; - } else { - self->private_data.s_decode_fctl.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(14); - 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_decode_fctl.scratch; - uint32_t num_bits_6 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_6); - if (num_bits_6 == 8) { - t_6 = ((uint32_t)(*scratch >> 48)); - break; - } - num_bits_6 += 8u; - *scratch |= ((uint64_t)(num_bits_6)); - } - } - v_x1 = t_6; - } - if (v_x1 <= 0u) { - self->private_impl.f_frame_duration = (((uint64_t)(v_x0)) * 7056000u); - } else { - self->private_impl.f_frame_duration = ((((uint64_t)(v_x0)) * 705600000u) / ((uint64_t)(v_x1))); - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint32_t t_7 = *iop_a_src++; - v_x0 = t_7; - } - if (v_x0 == 0u) { - self->private_impl.f_frame_disposal = 0u; - } else if (v_x0 == 1u) { - self->private_impl.f_frame_disposal = 1u; - } else if (v_x0 == 2u) { - self->private_impl.f_frame_disposal = 2u; - } else { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint32_t t_8 = *iop_a_src++; - v_x0 = t_8; - } - if (v_x0 == 0u) { - self->private_impl.f_frame_overwrite_instead_of_blend = true; - } else if (v_x0 == 1u) { - self->private_impl.f_frame_overwrite_instead_of_blend = false; - } else { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } - if (self->private_impl.f_num_decoded_frame_configs_value == 0u) { - self->private_impl.f_first_rect_x0 = self->private_impl.f_frame_rect_x0; - self->private_impl.f_first_rect_y0 = self->private_impl.f_frame_rect_y0; - self->private_impl.f_first_rect_x1 = self->private_impl.f_frame_rect_x1; - self->private_impl.f_first_rect_y1 = self->private_impl.f_frame_rect_y1; - self->private_impl.f_first_duration = self->private_impl.f_frame_duration; - self->private_impl.f_first_disposal = self->private_impl.f_frame_disposal; - self->private_impl.f_first_overwrite_instead_of_blend = self->private_impl.f_frame_overwrite_instead_of_blend; + while (true) { + { + wuffs_base__status t_0 = wuffs_png__decoder__do_tell_me_more(self, a_dst, a_minfo, 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_png__error__truncated_input); + goto exit; + } + status = v_status; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1); } - goto ok; ok: - self->private_impl.p_decode_fctl = 0; + self->private_impl.p_tell_me_more = 0; goto exit; } goto suspend; suspend: - self->private_impl.p_decode_fctl = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; - self->private_data.s_decode_fctl.v_x0 = v_x0; - self->private_data.s_decode_fctl.v_x1 = v_x1; - self->private_data.s_decode_fctl.v_y1 = v_y1; + self->private_impl.p_tell_me_more = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 4 : 0; goto exit; exit: - if (a_src && a_src->data.ptr) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + if (wuffs_base__status__is_error(&status)) { + self->private_impl.magic = WUFFS_BASE__DISABLED; } - return status; } -// -------- func png.decoder.decode_gama +// -------- func png.decoder.do_tell_me_more WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_png__decoder__decode_gama( +wuffs_png__decoder__do_tell_me_more( wuffs_png__decoder* self, + wuffs_base__io_buffer* a_dst, + wuffs_base__more_information* a_minfo, wuffs_base__io_buffer* a_src) { wuffs_base__status status = wuffs_base__make_status(NULL); + uint8_t v_c8 = 0; + uint16_t v_c16 = 0; + wuffs_base__io_buffer u_w = wuffs_base__empty_io_buffer(); + wuffs_base__io_buffer* v_w = &u_w; + uint8_t* iop_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + uint8_t* io0_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + uint8_t* io1_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + uint8_t* io2_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + uint64_t v_num_written = 0; + uint64_t v_w_mark = 0; + uint64_t v_r_mark = 0; + wuffs_base__status v_zlib_status = wuffs_base__make_status(NULL); + + uint8_t* iop_a_dst = NULL; + uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + if (a_dst && a_dst->data.ptr) { + io0_a_dst = a_dst->data.ptr; + io1_a_dst = io0_a_dst + a_dst->meta.wi; + iop_a_dst = io1_a_dst; + io2_a_dst = io0_a_dst + a_dst->data.len; + if (a_dst->meta.closed) { + io2_a_dst = iop_a_dst; + } + } 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; @@ -64445,61 +70003,462 @@ wuffs_png__decoder__decode_gama( io2_a_src = io0_a_src + a_src->meta.wi; } - uint32_t coro_susp_point = self->private_impl.p_decode_gama; + uint32_t coro_susp_point = self->private_impl.p_do_tell_me_more; + if (coro_susp_point) { + v_zlib_status = self->private_data.s_do_tell_me_more.v_zlib_status; + } switch (coro_susp_point) { WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - if (self->private_impl.f_chunk_length != 4u) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + if (((uint8_t)(self->private_impl.f_call_sequence & 16u)) == 0u) { + status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence); goto exit; } - self->private_impl.f_chunk_length = 0u; - self->private_impl.f_metadata_flavor = 5u; - self->private_impl.f_metadata_fourcc = 1195461953u; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - uint64_t t_0; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_0 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src))); - iop_a_src += 4; - } else { - self->private_data.s_decode_gama.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); + if (self->private_impl.f_metadata_fourcc == 0u) { + status = wuffs_base__make_status(wuffs_base__error__no_more_information); + goto exit; + } + do { + if (self->private_impl.f_metadata_flavor == 3u) { while (true) { - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; + if (wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))) != self->private_impl.f_metadata_y) { + status = wuffs_base__make_status(wuffs_base__error__bad_i_o_position); + goto exit; + } else if (a_minfo != NULL) { + wuffs_base__more_information__set(a_minfo, + self->private_impl.f_metadata_flavor, + self->private_impl.f_metadata_fourcc, + self->private_impl.f_metadata_x, + self->private_impl.f_metadata_y, + self->private_impl.f_metadata_z); } - uint64_t* scratch = &self->private_data.s_decode_gama.scratch; - uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0); - if (num_bits_0 == 24) { - t_0 = ((uint64_t)(*scratch >> 32)); - break; + if (self->private_impl.f_metadata_y >= self->private_impl.f_metadata_z) { + goto label__goto_done__break; } - num_bits_0 += 8u; - *scratch |= ((uint64_t)(num_bits_0)); + self->private_impl.f_metadata_y = self->private_impl.f_metadata_z; + status = wuffs_base__make_status(wuffs_base__suspension__even_more_information); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1); } } - self->private_impl.f_metadata_x = t_0; + if (self->private_impl.f_metadata_is_zlib_compressed) { + if (self->private_impl.f_zlib_is_dirty) { + wuffs_private_impl__ignore_status(wuffs_zlib__decoder__initialize(&self->private_data.f_zlib, + sizeof (wuffs_zlib__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED)); + if (self->private_impl.f_ignore_checksum) { + wuffs_zlib__decoder__set_quirk(&self->private_data.f_zlib, 1u, 1u); + } + } + self->private_impl.f_zlib_is_dirty = true; + self->private_impl.f_ztxt_hist_pos = 0u; + } + label__loop__continue:; + while (true) { + if (a_minfo != NULL) { + wuffs_base__more_information__set(a_minfo, + self->private_impl.f_metadata_flavor, + self->private_impl.f_metadata_fourcc, + self->private_impl.f_metadata_x, + self->private_impl.f_metadata_y, + self->private_impl.f_metadata_z); + } + if (self->private_impl.f_metadata_flavor != 4u) { + break; + } + if (self->private_impl.f_metadata_is_zlib_compressed) { + if (self->private_impl.f_chunk_type == 1346585449u) { + { + const bool o_0_closed_a_src = a_src->meta.closed; + const uint8_t* o_0_io2_a_src = io2_a_src; + wuffs_private_impl__io_reader__limit(&io2_a_src, iop_a_src, + ((uint64_t)(self->private_impl.f_chunk_length))); + if (a_src) { + size_t n = ((size_t)(io2_a_src - a_src->data.ptr)); + a_src->meta.closed = a_src->meta.closed && (a_src->meta.wi <= n); + a_src->meta.wi = n; + } + v_r_mark = ((uint64_t)(iop_a_src - io0_a_src)); + { + if (a_dst) { + a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr)); + } + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + wuffs_base__status t_0 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, a_dst, a_src, wuffs_base__utility__empty_slice_u8()); + v_zlib_status = t_0; + if (a_dst) { + iop_a_dst = a_dst->data.ptr + a_dst->meta.wi; + } + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + } + wuffs_private_impl__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)(wuffs_private_impl__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src)))))); + io2_a_src = o_0_io2_a_src; + if (a_src) { + a_src->meta.closed = o_0_closed_a_src; + a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr)); + } + } + if (wuffs_base__status__is_ok(&v_zlib_status)) { + self->private_impl.f_metadata_is_zlib_compressed = false; + break; + } else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) { + status = v_zlib_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; + } + status = v_zlib_status; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2); + } else if (self->private_impl.f_chunk_type == 1951945833u) { + { + const bool o_1_closed_a_src = a_src->meta.closed; + const uint8_t* o_1_io2_a_src = io2_a_src; + wuffs_private_impl__io_reader__limit(&io2_a_src, iop_a_src, + ((uint64_t)(self->private_impl.f_chunk_length))); + if (a_src) { + size_t n = ((size_t)(io2_a_src - a_src->data.ptr)); + a_src->meta.closed = a_src->meta.closed && (a_src->meta.wi <= n); + a_src->meta.wi = n; + } + v_r_mark = ((uint64_t)(iop_a_src - io0_a_src)); + { + if (a_dst) { + a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr)); + } + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + wuffs_base__status t_1 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, a_dst, a_src, wuffs_base__utility__empty_slice_u8()); + v_zlib_status = t_1; + if (a_dst) { + iop_a_dst = a_dst->data.ptr + a_dst->meta.wi; + } + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + } + wuffs_private_impl__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)(wuffs_private_impl__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src)))))); + io2_a_src = o_1_io2_a_src; + if (a_src) { + a_src->meta.closed = o_1_closed_a_src; + a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr)); + } + } + if (wuffs_base__status__is_ok(&v_zlib_status)) { + self->private_impl.f_metadata_is_zlib_compressed = false; + break; + } else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) { + status = v_zlib_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; + } + status = v_zlib_status; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3); + } else if (self->private_impl.f_chunk_type == 1951945850u) { + if (self->private_impl.f_ztxt_ri == self->private_impl.f_ztxt_wi) { + { + wuffs_base__io_buffer* o_2_v_w = v_w; + uint8_t* o_2_iop_v_w = iop_v_w; + uint8_t* o_2_io0_v_w = io0_v_w; + uint8_t* o_2_io1_v_w = io1_v_w; + uint8_t* o_2_io2_v_w = io2_v_w; + v_w = wuffs_private_impl__io_writer__set( + &u_w, + &iop_v_w, + &io0_v_w, + &io1_v_w, + &io2_v_w, + wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024), + self->private_impl.f_ztxt_hist_pos); + { + const bool o_3_closed_a_src = a_src->meta.closed; + const uint8_t* o_3_io2_a_src = io2_a_src; + wuffs_private_impl__io_reader__limit(&io2_a_src, iop_a_src, + ((uint64_t)(self->private_impl.f_chunk_length))); + if (a_src) { + size_t n = ((size_t)(io2_a_src - a_src->data.ptr)); + a_src->meta.closed = a_src->meta.closed && (a_src->meta.wi <= n); + a_src->meta.wi = n; + } + v_w_mark = ((uint64_t)(iop_v_w - io0_v_w)); + v_r_mark = ((uint64_t)(iop_a_src - io0_a_src)); + { + u_w.meta.wi = ((size_t)(iop_v_w - u_w.data.ptr)); + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + wuffs_base__status t_2 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, v_w, a_src, wuffs_base__utility__empty_slice_u8()); + v_zlib_status = t_2; + iop_v_w = u_w.data.ptr + u_w.meta.wi; + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + } + wuffs_private_impl__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)(wuffs_private_impl__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src)))))); + v_num_written = wuffs_private_impl__io__count_since(v_w_mark, ((uint64_t)(iop_v_w - io0_v_w))); + io2_a_src = o_3_io2_a_src; + if (a_src) { + a_src->meta.closed = o_3_closed_a_src; + a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr)); + } + } + v_w = o_2_v_w; + iop_v_w = o_2_iop_v_w; + io0_v_w = o_2_io0_v_w; + io1_v_w = o_2_io1_v_w; + io2_v_w = o_2_io2_v_w; + } + if (v_num_written > 1024u) { + status = wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_i_o); + goto exit; + } + self->private_impl.f_ztxt_ri = 0u; + self->private_impl.f_ztxt_wi = ((uint32_t)(v_num_written)); + wuffs_private_impl__u64__sat_add_indirect(&self->private_impl.f_ztxt_hist_pos, v_num_written); + } + while (self->private_impl.f_ztxt_ri < self->private_impl.f_ztxt_wi) { + v_c16 = WUFFS_PNG__LATIN_1[self->private_data.f_dst_palette[self->private_impl.f_ztxt_ri]]; + if (v_c16 == 0u) { + status = wuffs_base__make_status(wuffs_png__error__bad_text_chunk_not_latin_1); + goto exit; + } else if (v_c16 <= 127u) { + if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0u) { + status = wuffs_base__make_status(wuffs_base__suspension__short_write); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4); + goto label__loop__continue; + } + self->private_impl.f_ztxt_ri += 1u; + (wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, ((uint8_t)(v_c16))), iop_a_dst += 1); + } else { + if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 1u) { + status = wuffs_base__make_status(wuffs_base__suspension__short_write); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5); + goto label__loop__continue; + } + self->private_impl.f_ztxt_ri += 1u; + (wuffs_base__poke_u16le__no_bounds_check(iop_a_dst, v_c16), iop_a_dst += 2); + } + } + if (wuffs_base__status__is_ok(&v_zlib_status)) { + self->private_impl.f_metadata_is_zlib_compressed = false; + break; + } else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) { + status = v_zlib_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; + } else if (v_zlib_status.repr != wuffs_base__suspension__short_write) { + status = v_zlib_status; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6); + } + } else { + status = wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_chunk_type); + goto exit; + } + } else if ((self->private_impl.f_chunk_type == 1951945833u) && (self->private_impl.f_metadata_fourcc == 1263947862u)) { + while (true) { + if (self->private_impl.f_chunk_length <= 0u) { + goto label__loop__break; + } else if (((uint64_t)(io2_a_src - iop_a_src)) <= 0u) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7); + goto label__loop__continue; + } else if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0u) { + status = wuffs_base__make_status(wuffs_base__suspension__short_write); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8); + goto label__loop__continue; + } + self->private_impl.f_chunk_length -= 1u; + v_c8 = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); + iop_a_src += 1u; + (wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, v_c8), iop_a_dst += 1); + } + } else { + while (true) { + if (self->private_impl.f_chunk_length <= 0u) { + if (self->private_impl.f_metadata_fourcc == 1263947851u) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } + goto label__loop__break; + } else if (((uint64_t)(io2_a_src - iop_a_src)) <= 0u) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9); + goto label__loop__continue; + } + v_c8 = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); + if (v_c8 == 0u) { + self->private_impl.f_chunk_length -= 1u; + iop_a_src += 1u; + goto label__loop__break; + } + v_c16 = WUFFS_PNG__LATIN_1[v_c8]; + if (v_c16 == 0u) { + status = wuffs_base__make_status(wuffs_png__error__bad_text_chunk_not_latin_1); + goto exit; + } else if (v_c16 <= 127u) { + if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0u) { + status = wuffs_base__make_status(wuffs_base__suspension__short_write); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10); + goto label__loop__continue; + } + self->private_impl.f_chunk_length -= 1u; + iop_a_src += 1u; + (wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, ((uint8_t)(v_c16))), iop_a_dst += 1); + } else { + if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 1u) { + status = wuffs_base__make_status(wuffs_base__suspension__short_write); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11); + goto label__loop__continue; + } + self->private_impl.f_chunk_length -= 1u; + iop_a_src += 1u; + (wuffs_base__poke_u16le__no_bounds_check(iop_a_dst, v_c16), iop_a_dst += 2); + } + } + } + } + label__loop__break:; + if (self->private_impl.f_metadata_fourcc == 1263947851u) { + self->private_impl.f_metadata_fourcc = 1263947862u; + if (self->private_impl.f_chunk_type == 1951945833u) { + if (self->private_impl.f_chunk_length <= 1u) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } + self->private_impl.f_chunk_length -= 2u; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_3 = *iop_a_src++; + v_c8 = t_3; + } + if (v_c8 == 0u) { + self->private_impl.f_metadata_is_zlib_compressed = false; + } else if (v_c8 == 1u) { + self->private_impl.f_metadata_is_zlib_compressed = true; + } else { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_4 = *iop_a_src++; + v_c8 = t_4; + } + if ((v_c8 != 0u) && self->private_impl.f_metadata_is_zlib_compressed) { + status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method); + goto exit; + } + self->private_impl.f_metadata_fourcc -= 2u; + while (self->private_impl.f_metadata_fourcc != 1263947862u) { + self->private_impl.f_metadata_fourcc += 1u; + while (true) { + if (self->private_impl.f_chunk_length <= 0u) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } + self->private_impl.f_chunk_length -= 1u; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(14); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_5 = *iop_a_src++; + v_c8 = t_5; + } + if (v_c8 == 0u) { + break; + } + } + } + } else if (self->private_impl.f_chunk_type == 1951945850u) { + if (self->private_impl.f_chunk_length <= 0u) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } + self->private_impl.f_chunk_length -= 1u; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_6 = *iop_a_src++; + v_c8 = t_6; + } + if (v_c8 != 0u) { + status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method); + goto exit; + } + self->private_impl.f_metadata_is_zlib_compressed = true; + } + self->private_impl.f_call_sequence &= 239u; + status = wuffs_base__make_status(NULL); + goto ok; + } + } while (0); + label__goto_done__break:; + if (self->private_impl.f_chunk_length != 0u) { + status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + goto exit; + } + self->private_data.s_do_tell_me_more.scratch = 4u; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16); + if (self->private_data.s_do_tell_me_more.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { + self->private_data.s_do_tell_me_more.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); + iop_a_src = io2_a_src; + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } + iop_a_src += self->private_data.s_do_tell_me_more.scratch; + self->private_impl.f_metadata_flavor = 0u; + self->private_impl.f_metadata_fourcc = 0u; + self->private_impl.f_metadata_x = 0u; self->private_impl.f_metadata_y = 0u; self->private_impl.f_metadata_z = 0u; - + self->private_impl.f_call_sequence &= 239u; + status = wuffs_base__make_status(NULL); goto ok; + ok: - self->private_impl.p_decode_gama = 0; + self->private_impl.p_do_tell_me_more = 0; goto exit; } goto suspend; suspend: - self->private_impl.p_decode_gama = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_impl.p_do_tell_me_more = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_data.s_do_tell_me_more.v_zlib_status = v_zlib_status; goto exit; exit: + if (a_dst && a_dst->data.ptr) { + a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr)); + } if (a_src && a_src->data.ptr) { a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); } @@ -64507,273 +70466,657 @@ wuffs_png__decoder__decode_gama( return status; } -// -------- func png.decoder.decode_iccp +// -------- func png.decoder.workbuf_len + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 +wuffs_png__decoder__workbuf_len( + const wuffs_png__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(self->private_impl.f_overall_workbuf_length, self->private_impl.f_overall_workbuf_length); +} + +// -------- func png.decoder.filter_and_swizzle WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_png__decoder__decode_iccp( +wuffs_png__decoder__filter_and_swizzle( wuffs_png__decoder* self, - wuffs_base__io_buffer* a_src) { - wuffs_base__status status = wuffs_base__make_status(NULL); + wuffs_base__pixel_buffer* a_dst, + wuffs_base__slice_u8 a_workbuf) { + return (*self->private_impl.choosy_filter_and_swizzle)(self, a_dst, a_workbuf); +} - uint8_t v_c8 = 0; +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_png__decoder__filter_and_swizzle__choosy_default( + wuffs_png__decoder* self, + wuffs_base__pixel_buffer* a_dst, + wuffs_base__slice_u8 a_workbuf) { + wuffs_base__pixel_format v_dst_pixfmt = {0}; + uint32_t v_dst_bits_per_pixel = 0; + uint64_t v_dst_bytes_per_pixel = 0; + uint64_t v_dst_bytes_per_row0 = 0; + uint64_t v_dst_bytes_per_row1 = 0; + wuffs_base__slice_u8 v_dst_palette = {0}; + wuffs_base__table_u8 v_tab = {0}; + uint32_t v_y = 0; + wuffs_base__slice_u8 v_dst = {0}; + uint8_t v_filter = 0; + wuffs_base__slice_u8 v_curr_row = {0}; + wuffs_base__slice_u8 v_prev_row = {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; + 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 = ((uint64_t)((v_dst_bits_per_pixel / 8u))); + v_dst_bytes_per_row0 = (((uint64_t)(self->private_impl.f_frame_rect_x0)) * v_dst_bytes_per_pixel); + v_dst_bytes_per_row1 = (((uint64_t)(self->private_impl.f_frame_rect_x1)) * v_dst_bytes_per_pixel); + v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024)); + v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0u); + if (v_dst_bytes_per_row1 < ((uint64_t)(v_tab.width))) { + v_tab = wuffs_base__table_u8__subtable_ij(v_tab, + 0u, + 0u, + v_dst_bytes_per_row1, + ((uint64_t)(v_tab.height))); + } + if (v_dst_bytes_per_row0 < ((uint64_t)(v_tab.width))) { + v_tab = wuffs_base__table_u8__subtable_ij(v_tab, + v_dst_bytes_per_row0, + 0u, + ((uint64_t)(v_tab.width)), + ((uint64_t)(v_tab.height))); + } else { + v_tab = wuffs_base__table_u8__subtable_ij(v_tab, + 0u, + 0u, + 0u, + 0u); + } + v_y = self->private_impl.f_frame_rect_y0; + while (v_y < self->private_impl.f_frame_rect_y1) { + v_dst = wuffs_private_impl__table_u8__row_u32(v_tab, v_y); + if (1u > ((uint64_t)(a_workbuf.len))) { + return wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_workbuf_length); + } + v_filter = a_workbuf.ptr[0u]; + a_workbuf = wuffs_base__slice_u8__subslice_i(a_workbuf, 1u); + if (self->private_impl.f_pass_bytes_per_row > ((uint64_t)(a_workbuf.len))) { + return wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_workbuf_length); + } + v_curr_row = wuffs_base__slice_u8__subslice_j(a_workbuf, self->private_impl.f_pass_bytes_per_row); + a_workbuf = wuffs_base__slice_u8__subslice_i(a_workbuf, self->private_impl.f_pass_bytes_per_row); + if (v_filter == 0u) { + } else if (v_filter == 1u) { + wuffs_png__decoder__filter_1(self, v_curr_row); + } else if (v_filter == 2u) { + wuffs_png__decoder__filter_2(self, v_curr_row, v_prev_row); + } else if (v_filter == 3u) { + wuffs_png__decoder__filter_3(self, v_curr_row, v_prev_row); + } else if (v_filter == 4u) { + wuffs_png__decoder__filter_4(self, v_curr_row, v_prev_row); + } else { + return wuffs_base__make_status(wuffs_png__error__bad_filter); + } + wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, v_curr_row); + v_prev_row = v_curr_row; + v_y += 1u; } + return wuffs_base__make_status(NULL); +} - uint32_t coro_susp_point = self->private_impl.p_decode_iccp; - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; +// -------- func png.decoder.filter_and_swizzle_tricky - while (true) { - if (self->private_impl.f_chunk_length <= 0u) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_png__decoder__filter_and_swizzle_tricky( + wuffs_png__decoder* self, + wuffs_base__pixel_buffer* a_dst, + wuffs_base__slice_u8 a_workbuf) { + wuffs_base__pixel_format v_dst_pixfmt = {0}; + uint32_t v_dst_bits_per_pixel = 0; + uint64_t v_dst_bytes_per_pixel = 0; + uint64_t v_dst_bytes_per_row1 = 0; + wuffs_base__slice_u8 v_dst_palette = {0}; + wuffs_base__table_u8 v_tab = {0}; + uint64_t v_src_bytes_per_pixel = 0; + uint32_t v_x = 0; + uint32_t v_y = 0; + uint64_t v_i = 0; + wuffs_base__slice_u8 v_dst = {0}; + uint8_t v_filter = 0; + wuffs_base__slice_u8 v_s = {0}; + wuffs_base__slice_u8 v_curr_row = {0}; + wuffs_base__slice_u8 v_prev_row = {0}; + uint8_t v_bits_unpacked[8] = {0}; + uint8_t v_bits_packed = 0; + uint8_t v_packs_remaining = 0; + uint8_t v_multiplier = 0; + uint8_t v_shift = 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 = ((uint64_t)((v_dst_bits_per_pixel / 8u))); + v_dst_bytes_per_row1 = (((uint64_t)(self->private_impl.f_frame_rect_x1)) * v_dst_bytes_per_pixel); + v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024)); + v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0u); + v_src_bytes_per_pixel = 1u; + if (self->private_impl.f_depth >= 8u) { + v_src_bytes_per_pixel = (((uint64_t)(WUFFS_PNG__NUM_CHANNELS[self->private_impl.f_color_type])) * ((uint64_t)(((uint8_t)(self->private_impl.f_depth >> 3u))))); + } + if (self->private_impl.f_chunk_type_array[0u] == 73u) { + v_y = ((uint32_t)(WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][5u])); + } else { + v_y = self->private_impl.f_frame_rect_y0; + } + while (v_y < self->private_impl.f_frame_rect_y1) { + v_dst = wuffs_private_impl__table_u8__row_u32(v_tab, v_y); + if (v_dst_bytes_per_row1 < ((uint64_t)(v_dst.len))) { + v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_dst_bytes_per_row1); + } + if (1u > ((uint64_t)(a_workbuf.len))) { + return wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_workbuf_length); + } + v_filter = a_workbuf.ptr[0u]; + a_workbuf = wuffs_base__slice_u8__subslice_i(a_workbuf, 1u); + if (self->private_impl.f_pass_bytes_per_row > ((uint64_t)(a_workbuf.len))) { + return wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_workbuf_length); + } + v_curr_row = wuffs_base__slice_u8__subslice_j(a_workbuf, self->private_impl.f_pass_bytes_per_row); + a_workbuf = wuffs_base__slice_u8__subslice_i(a_workbuf, self->private_impl.f_pass_bytes_per_row); + if (v_filter == 0u) { + } else if (v_filter == 1u) { + wuffs_png__decoder__filter_1(self, v_curr_row); + } else if (v_filter == 2u) { + wuffs_png__decoder__filter_2(self, v_curr_row, v_prev_row); + } else if (v_filter == 3u) { + wuffs_png__decoder__filter_3(self, v_curr_row, v_prev_row); + } else if (v_filter == 4u) { + wuffs_png__decoder__filter_4(self, v_curr_row, v_prev_row); + } else { + return wuffs_base__make_status(wuffs_png__error__bad_filter); + } + v_s = v_curr_row; + if (self->private_impl.f_chunk_type_array[0u] == 73u) { + v_x = ((uint32_t)(WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][2u])); + } else { + v_x = self->private_impl.f_frame_rect_x0; + } + if (self->private_impl.f_depth == 8u) { + while (v_x < self->private_impl.f_frame_rect_x1) { + v_i = (((uint64_t)(v_x)) * v_dst_bytes_per_pixel); + if (v_i <= ((uint64_t)(v_dst.len))) { + if (((uint32_t)(self->private_impl.f_remap_transparency)) != 0u) { + if (self->private_impl.f_color_type == 0u) { + if (1u <= ((uint64_t)(v_s.len))) { + v_bits_unpacked[0u] = v_s.ptr[0u]; + v_bits_unpacked[1u] = v_s.ptr[0u]; + v_bits_unpacked[2u] = v_s.ptr[0u]; + v_bits_unpacked[3u] = 255u; + v_s = wuffs_base__slice_u8__subslice_i(v_s, 1u); + if (((uint32_t)(self->private_impl.f_remap_transparency)) == ((((uint32_t)(v_bits_unpacked[0u])) << 0u) | + (((uint32_t)(v_bits_unpacked[1u])) << 8u) | + (((uint32_t)(v_bits_unpacked[2u])) << 16u) | + (((uint32_t)(v_bits_unpacked[3u])) << 24u))) { + v_bits_unpacked[0u] = 0u; + v_bits_unpacked[1u] = 0u; + v_bits_unpacked[2u] = 0u; + v_bits_unpacked[3u] = 0u; + } + wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__make_slice_u8(v_bits_unpacked, 4)); + } + } else { + if (3u <= ((uint64_t)(v_s.len))) { + v_bits_unpacked[0u] = v_s.ptr[2u]; + v_bits_unpacked[1u] = v_s.ptr[1u]; + v_bits_unpacked[2u] = v_s.ptr[0u]; + v_bits_unpacked[3u] = 255u; + v_s = wuffs_base__slice_u8__subslice_i(v_s, 3u); + if (((uint32_t)(self->private_impl.f_remap_transparency)) == ((((uint32_t)(v_bits_unpacked[0u])) << 0u) | + (((uint32_t)(v_bits_unpacked[1u])) << 8u) | + (((uint32_t)(v_bits_unpacked[2u])) << 16u) | + (((uint32_t)(v_bits_unpacked[3u])) << 24u))) { + v_bits_unpacked[0u] = 0u; + v_bits_unpacked[1u] = 0u; + v_bits_unpacked[2u] = 0u; + v_bits_unpacked[3u] = 0u; + } + wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__make_slice_u8(v_bits_unpacked, 4)); + } + } + } else if (v_src_bytes_per_pixel <= ((uint64_t)(v_s.len))) { + wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__slice_u8__subslice_j(v_s, v_src_bytes_per_pixel)); + v_s = wuffs_base__slice_u8__subslice_i(v_s, v_src_bytes_per_pixel); + } + } + v_x += (((uint32_t)(1u)) << WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][0u]); } - self->private_impl.f_chunk_length -= 1u; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; + } else if (self->private_impl.f_depth < 8u) { + v_multiplier = 1u; + if (self->private_impl.f_color_type == 0u) { + v_multiplier = WUFFS_PNG__LOW_BIT_DEPTH_MULTIPLIERS[self->private_impl.f_depth]; + } + v_shift = ((uint8_t)(((uint8_t)(8u - self->private_impl.f_depth)) & 7u)); + v_packs_remaining = 0u; + while (v_x < self->private_impl.f_frame_rect_x1) { + v_i = (((uint64_t)(v_x)) * v_dst_bytes_per_pixel); + if (v_i <= ((uint64_t)(v_dst.len))) { + if ((v_packs_remaining == 0u) && (1u <= ((uint64_t)(v_s.len)))) { + v_packs_remaining = WUFFS_PNG__LOW_BIT_DEPTH_NUM_PACKS[self->private_impl.f_depth]; + v_bits_packed = v_s.ptr[0u]; + v_s = wuffs_base__slice_u8__subslice_i(v_s, 1u); + } + v_bits_unpacked[0u] = ((uint8_t)(((uint8_t)(v_bits_packed >> v_shift)) * v_multiplier)); + v_bits_packed = ((uint8_t)(v_bits_packed << self->private_impl.f_depth)); + v_packs_remaining = ((uint8_t)(v_packs_remaining - 1u)); + if (((uint32_t)(self->private_impl.f_remap_transparency)) != 0u) { + v_bits_unpacked[1u] = v_bits_unpacked[0u]; + v_bits_unpacked[2u] = v_bits_unpacked[0u]; + v_bits_unpacked[3u] = 255u; + if (((uint32_t)(self->private_impl.f_remap_transparency)) == ((((uint32_t)(v_bits_unpacked[0u])) << 0u) | + (((uint32_t)(v_bits_unpacked[1u])) << 8u) | + (((uint32_t)(v_bits_unpacked[2u])) << 16u) | + (((uint32_t)(v_bits_unpacked[3u])) << 24u))) { + v_bits_unpacked[0u] = 0u; + v_bits_unpacked[1u] = 0u; + v_bits_unpacked[2u] = 0u; + v_bits_unpacked[3u] = 0u; + } + wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__make_slice_u8(v_bits_unpacked, 4)); + } else { + wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__make_slice_u8(v_bits_unpacked, 1)); + } } - uint8_t t_0 = *iop_a_src++; - v_c8 = t_0; + v_x += (((uint32_t)(1u)) << WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][0u]); } - if (v_c8 == 0u) { - break; + } else { + while (v_x < self->private_impl.f_frame_rect_x1) { + v_i = (((uint64_t)(v_x)) * v_dst_bytes_per_pixel); + if (v_i <= ((uint64_t)(v_dst.len))) { + if (self->private_impl.f_color_type == 0u) { + if (2u <= ((uint64_t)(v_s.len))) { + v_bits_unpacked[0u] = v_s.ptr[1u]; + v_bits_unpacked[1u] = v_s.ptr[0u]; + v_bits_unpacked[2u] = v_s.ptr[1u]; + v_bits_unpacked[3u] = v_s.ptr[0u]; + v_bits_unpacked[4u] = v_s.ptr[1u]; + v_bits_unpacked[5u] = v_s.ptr[0u]; + v_bits_unpacked[6u] = 255u; + v_bits_unpacked[7u] = 255u; + v_s = wuffs_base__slice_u8__subslice_i(v_s, 2u); + if (self->private_impl.f_remap_transparency == ((((uint64_t)(v_bits_unpacked[0u])) << 0u) | + (((uint64_t)(v_bits_unpacked[1u])) << 8u) | + (((uint64_t)(v_bits_unpacked[2u])) << 16u) | + (((uint64_t)(v_bits_unpacked[3u])) << 24u) | + (((uint64_t)(v_bits_unpacked[4u])) << 32u) | + (((uint64_t)(v_bits_unpacked[5u])) << 40u) | + (((uint64_t)(v_bits_unpacked[6u])) << 48u) | + (((uint64_t)(v_bits_unpacked[7u])) << 56u))) { + v_bits_unpacked[0u] = 0u; + v_bits_unpacked[1u] = 0u; + v_bits_unpacked[2u] = 0u; + v_bits_unpacked[3u] = 0u; + v_bits_unpacked[4u] = 0u; + v_bits_unpacked[5u] = 0u; + v_bits_unpacked[6u] = 0u; + v_bits_unpacked[7u] = 0u; + } + } + } else if (self->private_impl.f_color_type == 2u) { + if (6u <= ((uint64_t)(v_s.len))) { + v_bits_unpacked[0u] = v_s.ptr[5u]; + v_bits_unpacked[1u] = v_s.ptr[4u]; + v_bits_unpacked[2u] = v_s.ptr[3u]; + v_bits_unpacked[3u] = v_s.ptr[2u]; + v_bits_unpacked[4u] = v_s.ptr[1u]; + v_bits_unpacked[5u] = v_s.ptr[0u]; + v_bits_unpacked[6u] = 255u; + v_bits_unpacked[7u] = 255u; + v_s = wuffs_base__slice_u8__subslice_i(v_s, 6u); + if (self->private_impl.f_remap_transparency == ((((uint64_t)(v_bits_unpacked[0u])) << 0u) | + (((uint64_t)(v_bits_unpacked[1u])) << 8u) | + (((uint64_t)(v_bits_unpacked[2u])) << 16u) | + (((uint64_t)(v_bits_unpacked[3u])) << 24u) | + (((uint64_t)(v_bits_unpacked[4u])) << 32u) | + (((uint64_t)(v_bits_unpacked[5u])) << 40u) | + (((uint64_t)(v_bits_unpacked[6u])) << 48u) | + (((uint64_t)(v_bits_unpacked[7u])) << 56u))) { + v_bits_unpacked[0u] = 0u; + v_bits_unpacked[1u] = 0u; + v_bits_unpacked[2u] = 0u; + v_bits_unpacked[3u] = 0u; + v_bits_unpacked[4u] = 0u; + v_bits_unpacked[5u] = 0u; + v_bits_unpacked[6u] = 0u; + v_bits_unpacked[7u] = 0u; + } + } + } else if (self->private_impl.f_color_type == 4u) { + if (4u <= ((uint64_t)(v_s.len))) { + v_bits_unpacked[0u] = v_s.ptr[1u]; + v_bits_unpacked[1u] = v_s.ptr[0u]; + v_bits_unpacked[2u] = v_s.ptr[1u]; + v_bits_unpacked[3u] = v_s.ptr[0u]; + v_bits_unpacked[4u] = v_s.ptr[1u]; + v_bits_unpacked[5u] = v_s.ptr[0u]; + v_bits_unpacked[6u] = v_s.ptr[3u]; + v_bits_unpacked[7u] = v_s.ptr[2u]; + v_s = wuffs_base__slice_u8__subslice_i(v_s, 4u); + } + } else { + if (8u <= ((uint64_t)(v_s.len))) { + v_bits_unpacked[0u] = v_s.ptr[5u]; + v_bits_unpacked[1u] = v_s.ptr[4u]; + v_bits_unpacked[2u] = v_s.ptr[3u]; + v_bits_unpacked[3u] = v_s.ptr[2u]; + v_bits_unpacked[4u] = v_s.ptr[1u]; + v_bits_unpacked[5u] = v_s.ptr[0u]; + v_bits_unpacked[6u] = v_s.ptr[7u]; + v_bits_unpacked[7u] = v_s.ptr[6u]; + v_s = wuffs_base__slice_u8__subslice_i(v_s, 8u); + } + } + wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__make_slice_u8(v_bits_unpacked, 8)); + } + v_x += (((uint32_t)(1u)) << WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][0u]); } } - if (self->private_impl.f_chunk_length <= 0u) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } - self->private_impl.f_chunk_length -= 1u; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_1 = *iop_a_src++; - v_c8 = t_1; + v_prev_row = v_curr_row; + v_y += (((uint32_t)(1u)) << WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][3u]); + } + return wuffs_base__make_status(NULL); +} + +#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__PNG) + +#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__QOI) + +// ---------------- Status Codes Implementations + +const char wuffs_qoi__error__bad_footer[] = "#qoi: bad footer"; +const char wuffs_qoi__error__bad_header[] = "#qoi: bad header"; +const char wuffs_qoi__error__truncated_input[] = "#qoi: truncated input"; + +// ---------------- Private Consts + +// ---------------- Private Initializer Prototypes + +// ---------------- Private Function Prototypes + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_qoi__decoder__do_decode_image_config( + wuffs_qoi__decoder* self, + wuffs_base__image_config* a_dst, + wuffs_base__io_buffer* a_src); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_qoi__decoder__do_decode_frame_config( + wuffs_qoi__decoder* self, + wuffs_base__frame_config* a_dst, + wuffs_base__io_buffer* a_src); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_qoi__decoder__do_decode_frame( + wuffs_qoi__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_qoi__decoder__from_src_to_buffer( + wuffs_qoi__decoder* self, + wuffs_base__io_buffer* a_src); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_qoi__decoder__from_buffer_to_dst( + wuffs_qoi__decoder* self, + wuffs_base__pixel_buffer* a_dst); + +// ---------------- VTables + +const wuffs_base__image_decoder__func_ptrs +wuffs_qoi__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_qoi__decoder__decode_frame), + (wuffs_base__status(*)(void*, + wuffs_base__frame_config*, + wuffs_base__io_buffer*))(&wuffs_qoi__decoder__decode_frame_config), + (wuffs_base__status(*)(void*, + wuffs_base__image_config*, + wuffs_base__io_buffer*))(&wuffs_qoi__decoder__decode_image_config), + (wuffs_base__rect_ie_u32(*)(const void*))(&wuffs_qoi__decoder__frame_dirty_rect), + (uint64_t(*)(const void*, + uint32_t))(&wuffs_qoi__decoder__get_quirk), + (uint32_t(*)(const void*))(&wuffs_qoi__decoder__num_animation_loops), + (uint64_t(*)(const void*))(&wuffs_qoi__decoder__num_decoded_frame_configs), + (uint64_t(*)(const void*))(&wuffs_qoi__decoder__num_decoded_frames), + (wuffs_base__status(*)(void*, + uint64_t, + uint64_t))(&wuffs_qoi__decoder__restart_frame), + (wuffs_base__status(*)(void*, + uint32_t, + uint64_t))(&wuffs_qoi__decoder__set_quirk), + (wuffs_base__empty_struct(*)(void*, + uint32_t, + bool))(&wuffs_qoi__decoder__set_report_metadata), + (wuffs_base__status(*)(void*, + wuffs_base__io_buffer*, + wuffs_base__more_information*, + wuffs_base__io_buffer*))(&wuffs_qoi__decoder__tell_me_more), + (wuffs_base__range_ii_u64(*)(const void*))(&wuffs_qoi__decoder__workbuf_len), +}; + +// ---------------- Initializer Implementations + +wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT +wuffs_qoi__decoder__initialize( + wuffs_qoi__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 (v_c8 != 0u) { - status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method); - goto exit; +#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.f_metadata_is_zlib_compressed = true; - self->private_impl.f_metadata_flavor = 4u; - self->private_impl.f_metadata_fourcc = 1229144912u; - self->private_impl.f_metadata_x = 0u; - self->private_impl.f_metadata_y = 0u; - self->private_impl.f_metadata_z = 0u; - - goto ok; - ok: - self->private_impl.p_decode_iccp = 0; - goto exit; } - goto suspend; - suspend: - self->private_impl.p_decode_iccp = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + 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_qoi__decoder__func_ptrs_for__wuffs_base__image_decoder); + return wuffs_base__make_status(NULL); +} - goto exit; - exit: - if (a_src && a_src->data.ptr) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); +wuffs_qoi__decoder* +wuffs_qoi__decoder__alloc(void) { + wuffs_qoi__decoder* x = + (wuffs_qoi__decoder*)(calloc(1, sizeof(wuffs_qoi__decoder))); + if (!x) { + return NULL; } - - return status; + if (wuffs_qoi__decoder__initialize( + x, sizeof(wuffs_qoi__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) { + free(x); + return NULL; + } + return x; } -// -------- func png.decoder.decode_plte +size_t +sizeof__wuffs_qoi__decoder(void) { + return sizeof(wuffs_qoi__decoder); +} -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__decode_plte( - wuffs_png__decoder* self, - wuffs_base__io_buffer* a_src) { - wuffs_base__status status = wuffs_base__make_status(NULL); +// ---------------- Function Implementations - uint32_t v_num_entries = 0; - uint32_t v_i = 0; - uint32_t v_argb = 0; +// -------- func qoi.decoder.get_quirk - 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; +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC uint64_t +wuffs_qoi__decoder__get_quirk( + const wuffs_qoi__decoder* self, + uint32_t a_key) { + if (!self) { + return 0; } - - uint32_t coro_susp_point = self->private_impl.p_decode_plte; - if (coro_susp_point) { - v_num_entries = self->private_data.s_decode_plte.v_num_entries; - v_i = self->private_data.s_decode_plte.v_i; + if ((self->private_impl.magic != WUFFS_BASE__MAGIC) && + (self->private_impl.magic != WUFFS_BASE__DISABLED)) { + return 0; } - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - - if ((self->private_impl.f_chunk_length > 768u) || ((self->private_impl.f_chunk_length % 3u) != 0u)) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } - v_num_entries = (((uint32_t)(self->private_impl.f_chunk_length)) / 3u); - self->private_impl.f_chunk_length = 0u; - while (v_i < v_num_entries) { - { - 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_u24be__no_bounds_check(iop_a_src))); - iop_a_src += 3; - } else { - self->private_data.s_decode_plte.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_decode_plte.scratch; - uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0); - if (num_bits_0 == 16) { - t_0 = ((uint32_t)(*scratch >> 40)); - break; - } - num_bits_0 += 8u; - *scratch |= ((uint64_t)(num_bits_0)); - } - } - v_argb = t_0; - } - v_argb |= 4278190080u; - self->private_data.f_src_palette[((4u * v_i) + 0u)] = ((uint8_t)((v_argb >> 0u))); - self->private_data.f_src_palette[((4u * v_i) + 1u)] = ((uint8_t)((v_argb >> 8u))); - self->private_data.f_src_palette[((4u * v_i) + 2u)] = ((uint8_t)((v_argb >> 16u))); - self->private_data.f_src_palette[((4u * v_i) + 3u)] = ((uint8_t)((v_argb >> 24u))); - v_i += 1u; - } - while (v_i < 256u) { - self->private_data.f_src_palette[((4u * v_i) + 0u)] = 0u; - self->private_data.f_src_palette[((4u * v_i) + 1u)] = 0u; - self->private_data.f_src_palette[((4u * v_i) + 2u)] = 0u; - self->private_data.f_src_palette[((4u * v_i) + 3u)] = 255u; - v_i += 1u; - } - goto ok; - ok: - self->private_impl.p_decode_plte = 0; - goto exit; - } + return 0u; +} - goto suspend; - suspend: - self->private_impl.p_decode_plte = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; - self->private_data.s_decode_plte.v_num_entries = v_num_entries; - self->private_data.s_decode_plte.v_i = v_i; +// -------- func qoi.decoder.set_quirk - goto exit; - exit: - if (a_src && a_src->data.ptr) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_qoi__decoder__set_quirk( + wuffs_qoi__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 status; + return wuffs_base__make_status(wuffs_base__error__unsupported_option); } -// -------- func png.decoder.decode_srgb +// -------- func qoi.decoder.decode_image_config WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__decode_srgb( - wuffs_png__decoder* self, +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_qoi__decoder__decode_image_config( + wuffs_qoi__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); - 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; - } + wuffs_base__status v_status = wuffs_base__make_status(NULL); - uint32_t coro_susp_point = self->private_impl.p_decode_srgb; + uint32_t coro_susp_point = self->private_impl.p_decode_image_config; switch (coro_susp_point) { WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - if (self->private_impl.f_chunk_length != 1u) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } - self->private_impl.f_chunk_length = 0u; - self->private_impl.f_metadata_flavor = 5u; - self->private_impl.f_metadata_fourcc = 1397901122u; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; + while (true) { + { + wuffs_base__status t_0 = wuffs_qoi__decoder__do_decode_image_config(self, a_dst, a_src); + v_status = t_0; } - uint64_t t_0 = *iop_a_src++; - self->private_impl.f_metadata_x = t_0; + if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) { + status = wuffs_base__make_status(wuffs_qoi__error__truncated_input); + goto exit; + } + status = v_status; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1); } - self->private_impl.f_metadata_y = 0u; - self->private_impl.f_metadata_z = 0u; - goto ok; ok: - self->private_impl.p_decode_srgb = 0; + self->private_impl.p_decode_image_config = 0; goto exit; } goto suspend; suspend: - self->private_impl.p_decode_srgb = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + 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 (a_src && a_src->data.ptr) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + if (wuffs_base__status__is_error(&status)) { + self->private_impl.magic = WUFFS_BASE__DISABLED; } - return status; } -// -------- func png.decoder.decode_trns +// -------- func qoi.decoder.do_decode_image_config WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_png__decoder__decode_trns( - wuffs_png__decoder* self, +wuffs_qoi__decoder__do_decode_image_config( + wuffs_qoi__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_i = 0; - uint32_t v_n = 0; - uint64_t v_u = 0; + uint32_t v_a = 0; const uint8_t* iop_a_src = NULL; const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL; @@ -64786,158 +71129,159 @@ wuffs_png__decoder__decode_trns( io2_a_src = io0_a_src + a_src->meta.wi; } - uint32_t coro_susp_point = self->private_impl.p_decode_trns; - if (coro_susp_point) { - v_i = self->private_data.s_decode_trns.v_i; - v_n = self->private_data.s_decode_trns.v_n; - } + 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_color_type == 0u) { - self->private_impl.choosy_filter_and_swizzle = ( - &wuffs_png__decoder__filter_and_swizzle_tricky); - if (self->private_impl.f_depth <= 8u) { - self->private_impl.f_dst_pixfmt = 2164295816u; - self->private_impl.f_src_pixfmt = 2164295816u; + 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 >= 4)) { + t_0 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src); + iop_a_src += 4; } else { - self->private_impl.f_dst_pixfmt = 2164308923u; - self->private_impl.f_src_pixfmt = 2164308923u; - } - if (self->private_impl.f_chunk_length != 2u) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } - self->private_impl.f_chunk_length = 0u; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - uint64_t t_0; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { - t_0 = ((uint64_t)(wuffs_base__peek_u16be__no_bounds_check(iop_a_src))); - iop_a_src += 2; - } else { - self->private_data.s_decode_trns.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_decode_trns.scratch; - uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0); - if (num_bits_0 == 8) { - t_0 = ((uint64_t)(*scratch >> 48)); - break; - } - num_bits_0 += 8u; - *scratch |= ((uint64_t)(num_bits_0)); + 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 == 24) { + t_0 = ((uint32_t)(*scratch)); + break; } + num_bits_0 += 8u; + *scratch |= ((uint64_t)(num_bits_0)) << 56; } - v_u = t_0; - } - if (self->private_impl.f_depth <= 1u) { - self->private_impl.f_remap_transparency = (((v_u & 1u) * 16777215u) | 4278190080u); - } else if (self->private_impl.f_depth <= 2u) { - self->private_impl.f_remap_transparency = (((v_u & 3u) * 5592405u) | 4278190080u); - } else if (self->private_impl.f_depth <= 4u) { - self->private_impl.f_remap_transparency = (((v_u & 15u) * 1118481u) | 4278190080u); - } else if (self->private_impl.f_depth <= 8u) { - self->private_impl.f_remap_transparency = (((v_u & 255u) * 65793u) | 4278190080u); - } else { - self->private_impl.f_remap_transparency = ((v_u * 4295032833u) | 18446462598732840960u); } - } else if (self->private_impl.f_color_type == 2u) { - self->private_impl.choosy_filter_and_swizzle = ( - &wuffs_png__decoder__filter_and_swizzle_tricky); - if (self->private_impl.f_depth <= 8u) { - self->private_impl.f_dst_pixfmt = 2164295816u; - self->private_impl.f_src_pixfmt = 2164295816u; + v_a = t_0; + } + if (v_a != 1718185841u) { + status = wuffs_base__make_status(wuffs_qoi__error__bad_header); + goto exit; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + uint32_t t_1; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_1 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); + iop_a_src += 4; } else { - self->private_impl.f_dst_pixfmt = 2164308923u; - self->private_impl.f_src_pixfmt = 2164308923u; - } - if (self->private_impl.f_chunk_length != 6u) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } - self->private_impl.f_chunk_length = 0u; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - uint64_t t_1; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 6)) { - t_1 = ((uint64_t)(wuffs_base__peek_u48be__no_bounds_check(iop_a_src))); - iop_a_src += 6; - } else { - self->private_data.s_decode_trns.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); - 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_decode_trns.scratch; - uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1); - if (num_bits_1 == 40) { - t_1 = ((uint64_t)(*scratch >> 16)); - break; - } - num_bits_1 += 8u; - *scratch |= ((uint64_t)(num_bits_1)); + self->private_data.s_do_decode_image_config.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + 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_1 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1); + if (num_bits_1 == 24) { + t_1 = ((uint32_t)(*scratch >> 32)); + break; } + num_bits_1 += 8u; + *scratch |= ((uint64_t)(num_bits_1)); } - v_u = t_1; } - if (self->private_impl.f_depth <= 8u) { - self->private_impl.f_remap_transparency = ((255u & (v_u >> 0u)) | - (65280u & (v_u >> 8u)) | - (16711680u & (v_u >> 16u)) | - 4278190080u); + v_a = t_1; + } + if (v_a > 16777215u) { + status = wuffs_base__make_status(wuffs_base__error__unsupported_image_dimension); + goto exit; + } + self->private_impl.f_width = v_a; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); + uint32_t t_2; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_2 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); + iop_a_src += 4; } else { - self->private_impl.f_remap_transparency = (v_u | 18446462598732840960u); - } - } else if (self->private_impl.f_color_type == 3u) { - self->private_impl.f_dst_pixfmt = 2164523016u; - self->private_impl.f_src_pixfmt = 2164523016u; - if (self->private_impl.f_chunk_length > 256u) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } - v_n = ((uint32_t)(self->private_impl.f_chunk_length)); - self->private_impl.f_chunk_length = 0u; - while (v_i < v_n) { - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); + self->private_data.s_do_decode_image_config.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); + while (true) { if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { status = wuffs_base__make_status(wuffs_base__suspension__short_read); goto suspend; } - uint8_t t_2 = *iop_a_src++; - self->private_data.f_src_palette[((4u * v_i) + 3u)] = t_2; + uint64_t* scratch = &self->private_data.s_do_decode_image_config.scratch; + uint32_t num_bits_2 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_2); + if (num_bits_2 == 24) { + t_2 = ((uint32_t)(*scratch >> 32)); + break; + } + num_bits_2 += 8u; + *scratch |= ((uint64_t)(num_bits_2)); } - v_i += 1u; } + v_a = t_2; + } + if (v_a > 16777215u) { + status = wuffs_base__make_status(wuffs_base__error__unsupported_image_dimension); + goto exit; + } + self->private_impl.f_height = v_a; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint32_t t_3 = *iop_a_src++; + v_a = t_3; + } + if (v_a == 3u) { + self->private_impl.f_pixfmt = 2415954056u; + } else if (v_a == 4u) { + self->private_impl.f_pixfmt = 2164295816u; } else { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); + status = wuffs_base__make_status(wuffs_qoi__error__bad_header); goto exit; } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + iop_a_src++; + 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, + 14u, + (self->private_impl.f_pixfmt == 2415954056u)); + } + self->private_impl.f_call_sequence = 32u; goto ok; ok: - self->private_impl.p_decode_trns = 0; + self->private_impl.p_do_decode_image_config = 0; goto exit; } goto suspend; suspend: - self->private_impl.p_decode_trns = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; - self->private_data.s_decode_trns.v_i = v_i; - self->private_data.s_decode_trns.v_n = v_n; + self->private_impl.p_do_decode_image_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; goto exit; exit: @@ -64948,12 +71292,12 @@ wuffs_png__decoder__decode_trns( return status; } -// -------- func png.decoder.decode_frame_config +// -------- func qoi.decoder.decode_frame_config WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_png__decoder__decode_frame_config( - wuffs_png__decoder* self, +wuffs_qoi__decoder__decode_frame_config( + wuffs_qoi__decoder* self, wuffs_base__frame_config* a_dst, wuffs_base__io_buffer* a_src) { if (!self) { @@ -64985,11 +71329,11 @@ wuffs_png__decoder__decode_frame_config( while (true) { { - wuffs_base__status t_0 = wuffs_png__decoder__do_decode_frame_config(self, a_dst, a_src); + wuffs_base__status t_0 = wuffs_qoi__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_png__error__truncated_input); + status = wuffs_base__make_status(wuffs_qoi__error__truncated_input); goto exit; } status = v_status; @@ -65014,18 +71358,16 @@ wuffs_png__decoder__decode_frame_config( return status; } -// -------- func png.decoder.do_decode_frame_config +// -------- func qoi.decoder.do_decode_frame_config WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_png__decoder__do_decode_frame_config( - wuffs_png__decoder* self, +wuffs_qoi__decoder__do_decode_frame_config( + wuffs_qoi__decoder* self, wuffs_base__frame_config* a_dst, wuffs_base__io_buffer* a_src) { wuffs_base__status status = wuffs_base__make_status(NULL); - uint32_t v_checksum_have = 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; @@ -65041,16 +71383,13 @@ wuffs_png__decoder__do_decode_frame_config( switch (coro_susp_point) { WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - if (((uint8_t)(self->private_impl.f_call_sequence & 16u)) != 0u) { - status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence); - goto exit; - } else if (self->private_impl.f_call_sequence == 32u) { + 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_png__decoder__do_decode_image_config(self, NULL, a_src); + status = wuffs_qoi__decoder__do_decode_image_config(self, NULL, a_src); if (a_src) { iop_a_src = a_src->data.ptr + a_src->meta.ri; } @@ -65058,213 +71397,34 @@ wuffs_png__decoder__do_decode_frame_config( goto suspend; } } else if (self->private_impl.f_call_sequence == 40u) { - if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) { + if (14u != 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) { - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); - status = wuffs_png__decoder__skip_frame(self, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; - } - } else { + self->private_impl.f_call_sequence = 96u; status = wuffs_base__make_status(wuffs_base__note__end_of_data); goto ok; - } - if (self->private_impl.f_metadata_fourcc != 0u) { - self->private_impl.f_call_sequence = 48u; - status = wuffs_base__make_status(wuffs_base__note__metadata_reported); - goto ok; - } - if (self->private_impl.f_num_decoded_frame_configs_value == 0u) { - self->private_impl.f_frame_rect_x0 = self->private_impl.f_first_rect_x0; - self->private_impl.f_frame_rect_y0 = self->private_impl.f_first_rect_y0; - self->private_impl.f_frame_rect_x1 = self->private_impl.f_first_rect_x1; - self->private_impl.f_frame_rect_y1 = self->private_impl.f_first_rect_y1; - self->private_impl.f_frame_config_io_position = self->private_impl.f_first_config_io_position; - self->private_impl.f_frame_duration = self->private_impl.f_first_duration; - self->private_impl.f_frame_disposal = self->private_impl.f_first_disposal; - self->private_impl.f_frame_overwrite_instead_of_blend = self->private_impl.f_first_overwrite_instead_of_blend; } else { - while (true) { - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - uint32_t t_0; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_0 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_do_decode_frame_config.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); - 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_frame_config.scratch; - uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0); - if (num_bits_0 == 24) { - t_0 = ((uint32_t)(*scratch >> 32)); - break; - } - num_bits_0 += 8u; - *scratch |= ((uint64_t)(num_bits_0)); - } - } - self->private_impl.f_chunk_length = t_0; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); - uint32_t t_1; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_1 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_do_decode_frame_config.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); - 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_frame_config.scratch; - uint32_t num_bits_1 = ((uint32_t)(*scratch >> 56)); - *scratch <<= 8; - *scratch >>= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_1; - if (num_bits_1 == 24) { - t_1 = ((uint32_t)(*scratch)); - break; - } - num_bits_1 += 8u; - *scratch |= ((uint64_t)(num_bits_1)) << 56; - } - } - self->private_impl.f_chunk_type = t_1; - } - if (self->private_impl.f_chunk_type == 1145980233u) { - if (self->private_impl.f_chunk_length != 0u) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); - uint32_t t_2; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_2 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_do_decode_frame_config.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); - 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_frame_config.scratch; - uint32_t num_bits_2 = ((uint32_t)(*scratch >> 56)); - *scratch <<= 8; - *scratch >>= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_2; - if (num_bits_2 == 24) { - t_2 = ((uint32_t)(*scratch)); - break; - } - num_bits_2 += 8u; - *scratch |= ((uint64_t)(num_bits_2)) << 56; - } - } - v_checksum_have = t_2; - } - if ( ! self->private_impl.f_ignore_checksum && (v_checksum_have != 2187346606u)) { - status = wuffs_base__make_status(wuffs_png__error__bad_checksum); - goto exit; - } - self->private_impl.f_call_sequence = 96u; - status = wuffs_base__make_status(wuffs_base__note__end_of_data); - goto ok; - } else if (self->private_impl.f_chunk_type == 1413571686u) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } else if (self->private_impl.f_chunk_type == 1280598886u) { - self->private_impl.f_frame_config_io_position = ((uint64_t)(wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))) - 8u)); - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); - status = wuffs_png__decoder__decode_fctl(self, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; - } - self->private_data.s_do_decode_frame_config.scratch = 4u; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10); - if (self->private_data.s_do_decode_frame_config.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { - self->private_data.s_do_decode_frame_config.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); - iop_a_src = io2_a_src; - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - iop_a_src += self->private_data.s_do_decode_frame_config.scratch; - break; - } - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11); - status = wuffs_png__decoder__decode_other_chunk(self, a_src, true); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; - } - if (self->private_impl.f_metadata_fourcc != 0u) { - self->private_impl.f_call_sequence = 48u; - status = wuffs_base__make_status(wuffs_base__note__metadata_reported); - goto ok; - } - self->private_data.s_do_decode_frame_config.scratch = 4u; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12); - if (self->private_data.s_do_decode_frame_config.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { - self->private_data.s_do_decode_frame_config.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); - iop_a_src = io2_a_src; - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - iop_a_src += self->private_data.s_do_decode_frame_config.scratch; - self->private_impl.f_chunk_length = 0u; - } + 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( - self->private_impl.f_frame_rect_x0, - self->private_impl.f_frame_rect_y0, - self->private_impl.f_frame_rect_x1, - self->private_impl.f_frame_rect_y1), - ((wuffs_base__flicks)(self->private_impl.f_frame_duration)), - ((uint64_t)(self->private_impl.f_num_decoded_frame_configs_value)), - self->private_impl.f_frame_config_io_position, - self->private_impl.f_frame_disposal, - ((self->private_impl.f_color_type <= 3u) && ! self->private_impl.f_seen_trns), - self->private_impl.f_frame_overwrite_instead_of_blend, + 0u, + 0u, + self->private_impl.f_width, + self->private_impl.f_height), + ((wuffs_base__flicks)(0u)), + 0u, + 14u, + 0u, + (self->private_impl.f_pixfmt == 2415954056u), + false, 0u); } - wuffs_private_impl__u32__sat_add_indirect(&self->private_impl.f_num_decoded_frame_configs_value, 1u); self->private_impl.f_call_sequence = 64u; ok: @@ -65285,160 +71445,12 @@ wuffs_png__decoder__do_decode_frame_config( return status; } -// -------- func png.decoder.skip_frame - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__skip_frame( - wuffs_png__decoder* self, - wuffs_base__io_buffer* a_src) { - wuffs_base__status status = wuffs_base__make_status(NULL); - - uint32_t v_seq_num = 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_skip_frame; - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - - self->private_impl.f_chunk_type_array[0u] = 0u; - self->private_impl.f_chunk_type_array[1u] = 0u; - self->private_impl.f_chunk_type_array[2u] = 0u; - self->private_impl.f_chunk_type_array[3u] = 0u; - while (true) { - if (((uint64_t)(io2_a_src - iop_a_src)) < 8u) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1); - continue; - } - self->private_impl.f_chunk_length = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); - self->private_impl.f_chunk_type = ((uint32_t)((wuffs_base__peek_u64le__no_bounds_check(iop_a_src) >> 32u))); - if (self->private_impl.f_chunk_type == 1413563465u) { - if (self->private_impl.f_chunk_type_array[0u] == 102u) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } - self->private_impl.f_chunk_type_array[0u] = 73u; - self->private_impl.f_chunk_type_array[1u] = 68u; - self->private_impl.f_chunk_type_array[2u] = 65u; - self->private_impl.f_chunk_type_array[3u] = 84u; - } else if (self->private_impl.f_chunk_type == 1413571686u) { - if (self->private_impl.f_chunk_type_array[0u] == 73u) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } - self->private_impl.f_chunk_type_array[0u] = 102u; - self->private_impl.f_chunk_type_array[1u] = 100u; - self->private_impl.f_chunk_type_array[2u] = 65u; - self->private_impl.f_chunk_type_array[3u] = 84u; - if (self->private_impl.f_chunk_length < 4u) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } - self->private_impl.f_chunk_length -= 4u; - iop_a_src += 8u; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); - uint32_t t_0; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_0 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_skip_frame.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - 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_skip_frame.scratch; - uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0); - if (num_bits_0 == 24) { - t_0 = ((uint32_t)(*scratch >> 32)); - break; - } - num_bits_0 += 8u; - *scratch |= ((uint64_t)(num_bits_0)); - } - } - v_seq_num = t_0; - } - if (v_seq_num != self->private_impl.f_next_animation_seq_num) { - status = wuffs_base__make_status(wuffs_png__error__bad_animation_sequence_number); - goto exit; - } else if (self->private_impl.f_next_animation_seq_num >= 4294967295u) { - status = wuffs_base__make_status(wuffs_png__error__unsupported_png_file); - goto exit; - } - self->private_impl.f_next_animation_seq_num += 1u; - self->private_data.s_skip_frame.scratch = (((uint64_t)(self->private_impl.f_chunk_length)) + 4u); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); - if (self->private_data.s_skip_frame.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { - self->private_data.s_skip_frame.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); - iop_a_src = io2_a_src; - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - iop_a_src += self->private_data.s_skip_frame.scratch; - self->private_impl.f_chunk_length = 0u; - continue; - } else if (self->private_impl.f_chunk_type_array[0u] != 0u) { - break; - } else if (self->private_impl.f_chunk_type == 1280598886u) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } - self->private_data.s_skip_frame.scratch = (((uint64_t)(self->private_impl.f_chunk_length)) + 12u); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); - if (self->private_data.s_skip_frame.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { - self->private_data.s_skip_frame.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); - iop_a_src = io2_a_src; - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - iop_a_src += self->private_data.s_skip_frame.scratch; - self->private_impl.f_chunk_length = 0u; - } - wuffs_private_impl__u32__sat_add_indirect(&self->private_impl.f_num_decoded_frames_value, 1u); - self->private_impl.f_call_sequence = 32u; - - ok: - self->private_impl.p_skip_frame = 0; - goto exit; - } - - goto suspend; - suspend: - self->private_impl.p_skip_frame = 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 png.decoder.decode_frame +// -------- func qoi.decoder.decode_frame WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_png__decoder__decode_frame( - wuffs_png__decoder* self, +wuffs_qoi__decoder__decode_frame( + wuffs_qoi__decoder* self, wuffs_base__pixel_buffer* a_dst, wuffs_base__io_buffer* a_src, wuffs_base__pixel_blend a_blend, @@ -65473,7 +71485,7 @@ wuffs_png__decoder__decode_frame( while (true) { { - wuffs_base__status t_0 = wuffs_png__decoder__do_decode_frame(self, + wuffs_base__status t_0 = wuffs_qoi__decoder__do_decode_frame(self, a_dst, a_src, a_blend, @@ -65482,7 +71494,7 @@ wuffs_png__decoder__decode_frame( 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_png__error__truncated_input); + status = wuffs_base__make_status(wuffs_qoi__error__truncated_input); goto exit; } status = v_status; @@ -65507,12 +71519,12 @@ wuffs_png__decoder__decode_frame( return status; } -// -------- func png.decoder.do_decode_frame +// -------- func qoi.decoder.do_decode_frame WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_png__decoder__do_decode_frame( - wuffs_png__decoder* self, +wuffs_qoi__decoder__do_decode_frame( + wuffs_qoi__decoder* self, wuffs_base__pixel_buffer* a_dst, wuffs_base__io_buffer* a_src, wuffs_base__pixel_blend a_blend, @@ -65520,10 +71532,8 @@ wuffs_png__decoder__do_decode_frame( wuffs_base__decode_frame_options* a_opts) { wuffs_base__status status = wuffs_base__make_status(NULL); - uint32_t v_seq_num = 0; wuffs_base__status v_status = wuffs_base__make_status(NULL); - uint32_t v_pass_width = 0; - uint32_t v_pass_height = 0; + uint64_t v_c64 = 0; const uint8_t* iop_a_src = NULL; const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL; @@ -65539,123 +71549,29 @@ wuffs_png__decoder__do_decode_frame( uint32_t coro_susp_point = self->private_impl.p_do_decode_frame; switch (coro_susp_point) { WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - - if (((uint8_t)(self->private_impl.f_call_sequence & 16u)) != 0u) { - status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence); - goto exit; - } else if (self->private_impl.f_call_sequence >= 96u) { - status = wuffs_base__make_status(wuffs_base__note__end_of_data); - goto ok; - } else if (self->private_impl.f_call_sequence != 64u) { - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - status = wuffs_png__decoder__do_decode_frame_config(self, NULL, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; - } - } - while (true) { - if (((uint64_t)(io2_a_src - iop_a_src)) < 8u) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2); - continue; - } - self->private_impl.f_chunk_length = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); - self->private_impl.f_chunk_type = ((uint32_t)((wuffs_base__peek_u64le__no_bounds_check(iop_a_src) >> 32u))); - if (self->private_impl.f_chunk_type == 1413563465u) { - self->private_impl.f_chunk_type_array[0u] = 73u; - self->private_impl.f_chunk_type_array[1u] = 68u; - self->private_impl.f_chunk_type_array[2u] = 65u; - self->private_impl.f_chunk_type_array[3u] = 84u; - iop_a_src += 8u; - if ( ! self->private_impl.f_ignore_checksum) { - wuffs_private_impl__ignore_status(wuffs_crc32__ieee_hasher__initialize(&self->private_data.f_crc32, - sizeof (wuffs_crc32__ieee_hasher), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED)); - wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__make_slice_u8(self->private_impl.f_chunk_type_array, 4)); - } - break; - } else if (self->private_impl.f_chunk_type == 1413571686u) { - self->private_impl.f_chunk_type_array[0u] = 102u; - self->private_impl.f_chunk_type_array[1u] = 100u; - self->private_impl.f_chunk_type_array[2u] = 65u; - self->private_impl.f_chunk_type_array[3u] = 84u; - if (self->private_impl.f_chunk_length < 4u) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } - self->private_impl.f_chunk_length -= 4u; - iop_a_src += 8u; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - uint32_t t_0; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_0 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_do_decode_frame.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); - 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_frame.scratch; - uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0); - if (num_bits_0 == 24) { - t_0 = ((uint32_t)(*scratch >> 32)); - break; - } - num_bits_0 += 8u; - *scratch |= ((uint64_t)(num_bits_0)); - } - } - v_seq_num = t_0; - } - if (v_seq_num != self->private_impl.f_next_animation_seq_num) { - status = wuffs_base__make_status(wuffs_png__error__bad_animation_sequence_number); - goto exit; - } else if (self->private_impl.f_next_animation_seq_num >= 4294967295u) { - status = wuffs_base__make_status(wuffs_png__error__unsupported_png_file); - goto exit; - } - self->private_impl.f_next_animation_seq_num += 1u; - break; - } else if (self->private_impl.f_chunk_type == 1280598886u) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; + + if (self->private_impl.f_call_sequence == 64u) { + } else if (self->private_impl.f_call_sequence < 64u) { + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); } - self->private_data.s_do_decode_frame.scratch = (((uint64_t)(self->private_impl.f_chunk_length)) + 12u); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); - if (self->private_data.s_do_decode_frame.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { - self->private_data.s_do_decode_frame.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); - iop_a_src = io2_a_src; - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + status = wuffs_qoi__decoder__do_decode_frame_config(self, NULL, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; } - iop_a_src += self->private_data.s_do_decode_frame.scratch; - self->private_impl.f_chunk_length = 0u; - } - if (self->private_impl.f_zlib_is_dirty) { - wuffs_private_impl__ignore_status(wuffs_zlib__decoder__initialize(&self->private_data.f_zlib, - sizeof (wuffs_zlib__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED)); - if (self->private_impl.f_ignore_checksum) { - wuffs_zlib__decoder__set_quirk(&self->private_data.f_zlib, 1u, 1u); + if (status.repr) { + goto suspend; } + } else { + status = wuffs_base__make_status(wuffs_base__note__end_of_data); + goto ok; } - self->private_impl.f_zlib_is_dirty = true; 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_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024)), - wuffs_base__utility__make_pixel_format(self->private_impl.f_src_pixfmt), - wuffs_base__make_slice_u8(self->private_data.f_src_palette, 1024), + 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; @@ -65667,70 +71583,77 @@ wuffs_png__decoder__do_decode_frame( } goto ok; } - self->private_impl.f_workbuf_hist_pos_base = 0u; - while (true) { - if (self->private_impl.f_chunk_type_array[0u] == 73u) { - v_pass_width = (16777215u & ((((uint32_t)(WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][1u])) + self->private_impl.f_width) >> WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][0u])); - v_pass_height = (16777215u & ((((uint32_t)(WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][4u])) + self->private_impl.f_height) >> WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][3u])); - } else { - v_pass_width = (16777215u & ((uint32_t)(self->private_impl.f_frame_rect_x1 - self->private_impl.f_frame_rect_x0))); - v_pass_height = (16777215u & ((uint32_t)(self->private_impl.f_frame_rect_y1 - self->private_impl.f_frame_rect_y0))); + self->private_impl.f_dst_x = 0u; + self->private_impl.f_dst_y = 0u; + self->private_data.f_pixel[0u] = 0u; + self->private_data.f_pixel[1u] = 0u; + self->private_data.f_pixel[2u] = 0u; + self->private_data.f_pixel[3u] = 255u; + wuffs_private_impl__bulk_memset(&self->private_data.f_cache[0], 256u, 0u); + self->private_impl.f_remaining_pixels_times_4 = (((uint64_t)(self->private_impl.f_width)) * ((uint64_t)(self->private_impl.f_height)) * 4u); + while (self->private_impl.f_remaining_pixels_times_4 > 0u) { + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); } - if ((v_pass_width > 0u) && (v_pass_height > 0u)) { - self->private_impl.f_pass_bytes_per_row = wuffs_png__decoder__calculate_bytes_per_row(self, v_pass_width); - self->private_impl.f_pass_workbuf_length = (((uint64_t)(v_pass_height)) * (1u + self->private_impl.f_pass_bytes_per_row)); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); + status = wuffs_qoi__decoder__from_src_to_buffer(self, a_src); + if (a_src) { + iop_a_src = a_src->data.ptr + a_src->meta.ri; + } + if (status.repr) { + goto suspend; + } + if (self->private_impl.f_remaining_pixels_times_4 < ((uint64_t)(self->private_impl.f_buffer_index))) { + status = wuffs_base__make_status(wuffs_base__error__too_much_data); + goto exit; + } + self->private_impl.f_remaining_pixels_times_4 -= ((uint64_t)(self->private_impl.f_buffer_index)); + v_status = wuffs_qoi__decoder__from_buffer_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; + } + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + uint64_t t_0; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 8)) { + t_0 = wuffs_base__peek_u64be__no_bounds_check(iop_a_src); + iop_a_src += 8; + } else { + self->private_data.s_do_decode_frame.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); while (true) { - { - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - wuffs_base__status t_1 = wuffs_png__decoder__decode_pass(self, a_src, a_workbuf); - v_status = t_1; - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } - if (wuffs_base__status__is_ok(&v_status)) { + uint64_t* scratch = &self->private_data.s_do_decode_frame.scratch; + uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu)); + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0); + if (num_bits_0 == 56) { + t_0 = ((uint64_t)(*scratch >> 0)); break; - } else if (wuffs_base__status__is_error(&v_status) || ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed))) { - if (self->private_impl.f_workbuf_wi <= ((uint64_t)(a_workbuf.len))) { - wuffs_png__decoder__filter_and_swizzle(self, a_dst, wuffs_base__slice_u8__subslice_j(a_workbuf, self->private_impl.f_workbuf_wi)); - } - if (v_status.repr == wuffs_base__suspension__short_read) { - status = wuffs_base__make_status(wuffs_png__error__truncated_input); - goto exit; - } - } - status = v_status; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6); - } - v_status = wuffs_png__decoder__filter_and_swizzle(self, a_dst, a_workbuf); - 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; + num_bits_0 += 8u; + *scratch |= ((uint64_t)(num_bits_0)); } - self->private_impl.f_workbuf_hist_pos_base += self->private_impl.f_pass_workbuf_length; } - if ((self->private_impl.f_interlace_pass == 0u) || (self->private_impl.f_interlace_pass >= 7u)) { - break; - } -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - self->private_impl.f_interlace_pass += 1u; -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif + v_c64 = t_0; } - wuffs_private_impl__u32__sat_add_indirect(&self->private_impl.f_num_decoded_frames_value, 1u); - self->private_impl.f_call_sequence = 32u; + if (v_c64 != 1u) { + status = wuffs_base__make_status(wuffs_qoi__error__bad_footer); + goto exit; + } + self->private_impl.f_call_sequence = 96u; ok: self->private_impl.p_do_decode_frame = 0; @@ -65750,28 +71673,22 @@ wuffs_png__decoder__do_decode_frame( return status; } -// -------- func png.decoder.decode_pass +// -------- func qoi.decoder.from_src_to_buffer WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_png__decoder__decode_pass( - wuffs_png__decoder* self, - wuffs_base__io_buffer* a_src, - wuffs_base__slice_u8 a_workbuf) { +wuffs_qoi__decoder__from_src_to_buffer( + wuffs_qoi__decoder* self, + wuffs_base__io_buffer* a_src) { wuffs_base__status status = wuffs_base__make_status(NULL); - wuffs_base__io_buffer u_w = wuffs_base__empty_io_buffer(); - wuffs_base__io_buffer* v_w = &u_w; - uint8_t* iop_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - uint8_t* io0_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - uint8_t* io1_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - uint8_t* io2_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - uint64_t v_w_mark = 0; - uint64_t v_r_mark = 0; - wuffs_base__status v_zlib_status = wuffs_base__make_status(NULL); - uint32_t v_checksum_have = 0; - uint32_t v_checksum_want = 0; - uint32_t v_seq_num = 0; + uint8_t v_c8 = 0; + uint8_t v_dg = 0; + uint32_t v_bi = 0; + uint32_t v_bj = 0; + uint32_t v_bk = 0; + uint32_t v_ci = 0; + uint32_t v_hash4 = 0; const uint8_t* iop_a_src = NULL; const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL; @@ -65784,304 +71701,177 @@ wuffs_png__decoder__decode_pass( io2_a_src = io0_a_src + a_src->meta.wi; } - uint32_t coro_susp_point = self->private_impl.p_decode_pass; + uint32_t coro_susp_point = self->private_impl.p_from_src_to_buffer; + if (coro_susp_point) { + v_dg = self->private_data.s_from_src_to_buffer.v_dg; + v_bi = self->private_data.s_from_src_to_buffer.v_bi; + v_bk = self->private_data.s_from_src_to_buffer.v_bk; + } switch (coro_susp_point) { WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - self->private_impl.f_workbuf_wi = 0u; - while (true) { - if ((self->private_impl.f_workbuf_wi > self->private_impl.f_pass_workbuf_length) || (self->private_impl.f_pass_workbuf_length > ((uint64_t)(a_workbuf.len)))) { - status = wuffs_base__make_status(wuffs_base__error__bad_workbuf_length); - goto exit; - } + v_bk = 7936u; + if (self->private_impl.f_remaining_pixels_times_4 < 7936u) { + v_bk = ((uint32_t)(self->private_impl.f_remaining_pixels_times_4)); + } + while (v_bi < v_bk) { { - wuffs_base__io_buffer* o_0_v_w = v_w; - uint8_t* o_0_iop_v_w = iop_v_w; - uint8_t* o_0_io0_v_w = io0_v_w; - uint8_t* o_0_io1_v_w = io1_v_w; - uint8_t* o_0_io2_v_w = io2_v_w; - v_w = wuffs_private_impl__io_writer__set( - &u_w, - &iop_v_w, - &io0_v_w, - &io1_v_w, - &io2_v_w, - wuffs_base__slice_u8__subslice_ij(a_workbuf, - self->private_impl.f_workbuf_wi, - self->private_impl.f_pass_workbuf_length), - ((uint64_t)(self->private_impl.f_workbuf_hist_pos_base + self->private_impl.f_workbuf_wi))); - { - const bool o_1_closed_a_src = a_src->meta.closed; - const uint8_t* o_1_io2_a_src = io2_a_src; - wuffs_private_impl__io_reader__limit(&io2_a_src, iop_a_src, - ((uint64_t)(self->private_impl.f_chunk_length))); - if (a_src) { - size_t n = ((size_t)(io2_a_src - a_src->data.ptr)); - a_src->meta.closed = a_src->meta.closed && (a_src->meta.wi <= n); - a_src->meta.wi = n; - } - v_w_mark = ((uint64_t)(iop_v_w - io0_v_w)); - v_r_mark = ((uint64_t)(iop_a_src - io0_a_src)); - { - u_w.meta.wi = ((size_t)(iop_v_w - u_w.data.ptr)); - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - wuffs_base__status t_0 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, v_w, a_src, wuffs_base__utility__empty_slice_u8()); - v_zlib_status = t_0; - iop_v_w = u_w.data.ptr + u_w.meta.wi; - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - } - if ( ! self->private_impl.f_ignore_checksum) { - wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_private_impl__io__since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src)), io0_a_src)); - } - wuffs_private_impl__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)(wuffs_private_impl__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src)))))); - wuffs_private_impl__u64__sat_add_indirect(&self->private_impl.f_workbuf_wi, wuffs_private_impl__io__count_since(v_w_mark, ((uint64_t)(iop_v_w - io0_v_w)))); - io2_a_src = o_1_io2_a_src; - if (a_src) { - a_src->meta.closed = o_1_closed_a_src; - a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr)); - } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } - v_w = o_0_v_w; - iop_v_w = o_0_iop_v_w; - io0_v_w = o_0_io0_v_w; - io1_v_w = o_0_io1_v_w; - io2_v_w = o_0_io2_v_w; + uint8_t t_0 = *iop_a_src++; + v_c8 = t_0; } - if (wuffs_base__status__is_ok(&v_zlib_status)) { - if (self->private_impl.f_chunk_length > 0u) { - status = wuffs_base__make_status(wuffs_base__error__too_much_data); - goto exit; - } + if (v_c8 == 254u) { { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - uint32_t t_1; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_1 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_decode_pass.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_decode_pass.scratch; - uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1); - if (num_bits_1 == 24) { - t_1 = ((uint32_t)(*scratch >> 32)); - break; - } - num_bits_1 += 8u; - *scratch |= ((uint64_t)(num_bits_1)); - } - } - v_checksum_want = t_1; - } - if ( ! self->private_impl.f_ignore_checksum && (self->private_impl.f_chunk_type_array[0u] == 73u)) { - v_checksum_have = wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__utility__empty_slice_u8()); - if (v_checksum_have != v_checksum_want) { - status = wuffs_base__make_status(wuffs_png__error__bad_checksum); - goto exit; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } + uint8_t t_1 = *iop_a_src++; + self->private_data.f_pixel[2u] = t_1; } - break; - } else if (v_zlib_status.repr == wuffs_base__suspension__short_write) { - if ((1u <= self->private_impl.f_interlace_pass) && (self->private_impl.f_interlace_pass <= 6u)) { - break; - } - status = wuffs_base__make_status(wuffs_base__error__too_much_data); - goto exit; - } else if (v_zlib_status.repr != wuffs_base__suspension__short_read) { - status = v_zlib_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; - } else if (self->private_impl.f_chunk_length == 0u) { { WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - uint32_t t_2; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_2 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_decode_pass.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); - 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_decode_pass.scratch; - uint32_t num_bits_2 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_2); - if (num_bits_2 == 24) { - t_2 = ((uint32_t)(*scratch >> 32)); - break; - } - num_bits_2 += 8u; - *scratch |= ((uint64_t)(num_bits_2)); - } + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } - v_checksum_want = t_2; + uint8_t t_2 = *iop_a_src++; + self->private_data.f_pixel[1u] = t_2; } - if ( ! self->private_impl.f_ignore_checksum && (self->private_impl.f_chunk_type_array[0u] == 73u)) { - v_checksum_have = wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__utility__empty_slice_u8()); - if (v_checksum_have != v_checksum_want) { - status = wuffs_base__make_status(wuffs_png__error__bad_checksum); - goto exit; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } + uint8_t t_3 = *iop_a_src++; + self->private_data.f_pixel[0u] = t_3; } + } else if (v_c8 == 255u) { { WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); - uint32_t t_3; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_decode_pass.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); - 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_decode_pass.scratch; - uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3); - if (num_bits_3 == 24) { - t_3 = ((uint32_t)(*scratch >> 32)); - break; - } - num_bits_3 += 8u; - *scratch |= ((uint64_t)(num_bits_3)); - } + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } - self->private_impl.f_chunk_length = t_3; + uint8_t t_4 = *iop_a_src++; + self->private_data.f_pixel[2u] = t_4; } { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); - uint32_t t_4; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_4 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_decode_pass.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); - 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_decode_pass.scratch; - uint32_t num_bits_4 = ((uint32_t)(*scratch >> 56)); - *scratch <<= 8; - *scratch >>= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_4; - if (num_bits_4 == 24) { - t_4 = ((uint32_t)(*scratch)); - break; - } - num_bits_4 += 8u; - *scratch |= ((uint64_t)(num_bits_4)) << 56; - } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } - self->private_impl.f_chunk_type = t_4; + uint8_t t_5 = *iop_a_src++; + self->private_data.f_pixel[1u] = t_5; } - if (self->private_impl.f_chunk_type_array[0u] == 73u) { - if (self->private_impl.f_chunk_type != 1413563465u) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } - if ( ! self->private_impl.f_ignore_checksum) { - wuffs_private_impl__ignore_status(wuffs_crc32__ieee_hasher__initialize(&self->private_data.f_crc32, - sizeof (wuffs_crc32__ieee_hasher), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED)); - wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__make_slice_u8(self->private_impl.f_chunk_type_array, 4)); - } - } else { - if ((self->private_impl.f_chunk_type != 1413571686u) || (self->private_impl.f_chunk_length < 4u)) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } - self->private_impl.f_chunk_length -= 4u; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); - uint32_t t_5; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_5 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_decode_pass.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10); - 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_decode_pass.scratch; - uint32_t num_bits_5 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_5); - if (num_bits_5 == 24) { - t_5 = ((uint32_t)(*scratch >> 32)); - break; - } - num_bits_5 += 8u; - *scratch |= ((uint64_t)(num_bits_5)); - } - } - v_seq_num = t_5; + uint8_t t_6 = *iop_a_src++; + self->private_data.f_pixel[0u] = t_6; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } - if (v_seq_num != self->private_impl.f_next_animation_seq_num) { - status = wuffs_base__make_status(wuffs_png__error__bad_animation_sequence_number); - goto exit; - } else if (self->private_impl.f_next_animation_seq_num >= 4294967295u) { - status = wuffs_base__make_status(wuffs_png__error__unsupported_png_file); - goto exit; + uint8_t t_7 = *iop_a_src++; + self->private_data.f_pixel[3u] = t_7; + } + } else if (((uint8_t)(v_c8 >> 6u)) == 0u) { + v_ci = (4u * ((uint32_t)(((uint8_t)(v_c8 & 63u))))); + self->private_data.f_pixel[0u] = self->private_data.f_cache[(v_ci + 0u)]; + self->private_data.f_pixel[1u] = self->private_data.f_cache[(v_ci + 1u)]; + self->private_data.f_pixel[2u] = self->private_data.f_cache[(v_ci + 2u)]; + self->private_data.f_pixel[3u] = self->private_data.f_cache[(v_ci + 3u)]; + self->private_data.f_buffer[(v_bi + 0u)] = self->private_data.f_pixel[0u]; + self->private_data.f_buffer[(v_bi + 1u)] = self->private_data.f_pixel[1u]; + self->private_data.f_buffer[(v_bi + 2u)] = self->private_data.f_pixel[2u]; + self->private_data.f_buffer[(v_bi + 3u)] = self->private_data.f_pixel[3u]; + v_bi += 4u; + continue; + } else if (((uint8_t)(v_c8 >> 6u)) == 1u) { +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + self->private_data.f_pixel[2u] += ((uint8_t)(((uint8_t)(((uint8_t)(v_c8 >> 4u)) & 3u)) + 254u)); + self->private_data.f_pixel[1u] += ((uint8_t)(((uint8_t)(((uint8_t)(v_c8 >> 2u)) & 3u)) + 254u)); + self->private_data.f_pixel[0u] += ((uint8_t)(((uint8_t)(((uint8_t)(v_c8 >> 0u)) & 3u)) + 254u)); +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + } else if (((uint8_t)(v_c8 >> 6u)) == 2u) { + v_dg = ((uint8_t)(((uint8_t)(v_c8 & 63u)) + 224u)); + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } - self->private_impl.f_next_animation_seq_num += 1u; + uint8_t t_8 = *iop_a_src++; + v_c8 = t_8; + } +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + self->private_data.f_pixel[2u] += ((uint8_t)(((uint8_t)(v_dg + 248u)) + ((uint8_t)(15u & ((uint8_t)(v_c8 >> 4u)))))); + self->private_data.f_pixel[1u] += v_dg; + self->private_data.f_pixel[0u] += ((uint8_t)(((uint8_t)(v_dg + 248u)) + ((uint8_t)(15u & ((uint8_t)(v_c8 >> 0u)))))); +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + } else { + v_bj = (v_bi + (4u * (63u & (1u + ((uint32_t)(v_c8)))))); + while (v_bi < v_bj) { + self->private_data.f_buffer[(v_bi + 0u)] = self->private_data.f_pixel[0u]; + self->private_data.f_buffer[(v_bi + 1u)] = self->private_data.f_pixel[1u]; + self->private_data.f_buffer[(v_bi + 2u)] = self->private_data.f_pixel[2u]; + self->private_data.f_buffer[(v_bi + 3u)] = self->private_data.f_pixel[3u]; + v_bi += 4u; } continue; - } else if (((uint64_t)(io2_a_src - iop_a_src)) > 0u) { - status = wuffs_base__make_status(wuffs_png__error__internal_error_zlib_decoder_did_not_exhaust_its_input); - goto exit; - } - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11); - } - if (self->private_impl.f_workbuf_wi != self->private_impl.f_pass_workbuf_length) { - status = wuffs_base__make_status(wuffs_base__error__not_enough_data); - goto exit; - } else if (0u < ((uint64_t)(a_workbuf.len))) { - if (a_workbuf.ptr[0u] == 4u) { - a_workbuf.ptr[0u] = 1u; } + v_hash4 = (4u * (63u & ((((uint32_t)(self->private_data.f_pixel[2u])) * 3u) + + (((uint32_t)(self->private_data.f_pixel[1u])) * 5u) + + (((uint32_t)(self->private_data.f_pixel[0u])) * 7u) + + (((uint32_t)(self->private_data.f_pixel[3u])) * 11u)))); + self->private_data.f_cache[(v_hash4 + 0u)] = self->private_data.f_pixel[0u]; + self->private_data.f_cache[(v_hash4 + 1u)] = self->private_data.f_pixel[1u]; + self->private_data.f_cache[(v_hash4 + 2u)] = self->private_data.f_pixel[2u]; + self->private_data.f_cache[(v_hash4 + 3u)] = self->private_data.f_pixel[3u]; + self->private_data.f_buffer[(v_bi + 0u)] = self->private_data.f_pixel[0u]; + self->private_data.f_buffer[(v_bi + 1u)] = self->private_data.f_pixel[1u]; + self->private_data.f_buffer[(v_bi + 2u)] = self->private_data.f_pixel[2u]; + self->private_data.f_buffer[(v_bi + 3u)] = self->private_data.f_pixel[3u]; + v_bi += 4u; } + self->private_impl.f_buffer_index = v_bi; + goto ok; ok: - self->private_impl.p_decode_pass = 0; + self->private_impl.p_from_src_to_buffer = 0; goto exit; } goto suspend; suspend: - self->private_impl.p_decode_pass = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_impl.p_from_src_to_buffer = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_data.s_from_src_to_buffer.v_dg = v_dg; + self->private_data.s_from_src_to_buffer.v_bi = v_bi; + self->private_data.s_from_src_to_buffer.v_bk = v_bk; goto exit; exit: @@ -66092,12 +71882,69 @@ wuffs_png__decoder__decode_pass( return status; } -// -------- func png.decoder.frame_dirty_rect +// -------- func qoi.decoder.from_buffer_to_dst + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_qoi__decoder__from_buffer_to_dst( + wuffs_qoi__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_bi = 0; + uint32_t v_rem_x = 0; + wuffs_base__slice_u8 v_dst = {0}; + wuffs_base__slice_u8 v_src = {0}; + uint32_t v_src_length = 0; + uint64_t v_i = 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_bi < self->private_impl.f_buffer_index) { + if (self->private_impl.f_width <= self->private_impl.f_dst_x) { + self->private_impl.f_dst_x = 0u; + self->private_impl.f_dst_y += 1u; + if (self->private_impl.f_dst_y >= self->private_impl.f_height) { + break; + } + v_rem_x = self->private_impl.f_width; + } else { + v_rem_x = (self->private_impl.f_width - self->private_impl.f_dst_x); + } + v_src = wuffs_base__make_slice_u8_ij(self->private_data.f_buffer, v_bi, self->private_impl.f_buffer_index); + if (((uint64_t)((4u * v_rem_x))) < ((uint64_t)(v_src.len))) { + v_src = wuffs_base__slice_u8__subslice_j(v_src, ((uint64_t)((4u * v_rem_x)))); + } + v_src_length = ((uint32_t)(((uint64_t)(v_src.len)))); + v_bi += v_src_length; + v_dst = wuffs_private_impl__table_u8__row_u32(v_tab, self->private_impl.f_dst_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); + } + v_i = (((uint64_t)(self->private_impl.f_dst_x)) * ((uint64_t)(v_dst_bytes_per_pixel))); + self->private_impl.f_dst_x += (v_src_length / 4u); + if (v_i < ((uint64_t)(v_dst.len))) { + wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), wuffs_base__pixel_buffer__palette(a_dst), v_src); + } + } + return wuffs_base__make_status(NULL); +} + +// -------- func qoi.decoder.frame_dirty_rect WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32 -wuffs_png__decoder__frame_dirty_rect( - const wuffs_png__decoder* self) { +wuffs_qoi__decoder__frame_dirty_rect( + const wuffs_qoi__decoder* self) { if (!self) { return wuffs_base__utility__empty_rect_ie_u32(); } @@ -66107,18 +71954,18 @@ wuffs_png__decoder__frame_dirty_rect( } return wuffs_base__utility__make_rect_ie_u32( - self->private_impl.f_frame_rect_x0, - self->private_impl.f_frame_rect_y0, - self->private_impl.f_frame_rect_x1, - self->private_impl.f_frame_rect_y1); + 0u, + 0u, + self->private_impl.f_width, + self->private_impl.f_height); } -// -------- func png.decoder.num_animation_loops +// -------- func qoi.decoder.num_animation_loops WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC uint32_t -wuffs_png__decoder__num_animation_loops( - const wuffs_png__decoder* self) { +wuffs_qoi__decoder__num_animation_loops( + const wuffs_qoi__decoder* self) { if (!self) { return 0; } @@ -66127,15 +71974,15 @@ wuffs_png__decoder__num_animation_loops( return 0; } - return self->private_impl.f_num_animation_loops_value; + return 0u; } -// -------- func png.decoder.num_decoded_frame_configs +// -------- func qoi.decoder.num_decoded_frame_configs WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC uint64_t -wuffs_png__decoder__num_decoded_frame_configs( - const wuffs_png__decoder* self) { +wuffs_qoi__decoder__num_decoded_frame_configs( + const wuffs_qoi__decoder* self) { if (!self) { return 0; } @@ -66144,15 +71991,18 @@ wuffs_png__decoder__num_decoded_frame_configs( return 0; } - return ((uint64_t)(self->private_impl.f_num_decoded_frame_configs_value)); + if (self->private_impl.f_call_sequence > 32u) { + return 1u; + } + return 0u; } -// -------- func png.decoder.num_decoded_frames +// -------- func qoi.decoder.num_decoded_frames WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC uint64_t -wuffs_png__decoder__num_decoded_frames( - const wuffs_png__decoder* self) { +wuffs_qoi__decoder__num_decoded_frames( + const wuffs_qoi__decoder* self) { if (!self) { return 0; } @@ -66161,15 +72011,18 @@ wuffs_png__decoder__num_decoded_frames( return 0; } - return ((uint64_t)(self->private_impl.f_num_decoded_frames_value)); + if (self->private_impl.f_call_sequence > 64u) { + return 1u; + } + return 0u; } -// -------- func png.decoder.restart_frame +// -------- func qoi.decoder.restart_frame WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_png__decoder__restart_frame( - wuffs_png__decoder* self, +wuffs_qoi__decoder__restart_frame( + wuffs_qoi__decoder* self, uint64_t a_index, uint64_t a_io_position) { if (!self) { @@ -66184,56 +72037,31 @@ wuffs_png__decoder__restart_frame( if (self->private_impl.f_call_sequence < 32u) { return wuffs_base__make_status(wuffs_base__error__bad_call_sequence); - } else if ((a_index >= ((uint64_t)(self->private_impl.f_num_animation_frames_value))) || ((a_index == 0u) && (a_io_position != self->private_impl.f_first_config_io_position))) { + } + if ((a_index != 0u) || (a_io_position != 14u)) { return wuffs_base__make_status(wuffs_base__error__bad_argument); } self->private_impl.f_call_sequence = 40u; - if (self->private_impl.f_interlace_pass >= 1u) { - self->private_impl.f_interlace_pass = 1u; - } - self->private_impl.f_frame_config_io_position = a_io_position; - self->private_impl.f_num_decoded_frame_configs_value = ((uint32_t)(a_index)); - self->private_impl.f_num_decoded_frames_value = self->private_impl.f_num_decoded_frame_configs_value; return wuffs_base__make_status(NULL); } -// -------- func png.decoder.set_report_metadata +// -------- func qoi.decoder.set_report_metadata WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct -wuffs_png__decoder__set_report_metadata( - wuffs_png__decoder* self, +wuffs_qoi__decoder__set_report_metadata( + wuffs_qoi__decoder* self, uint32_t a_fourcc, bool a_report) { - if (!self) { - return wuffs_base__make_empty_struct(); - } - if (self->private_impl.magic != WUFFS_BASE__MAGIC) { - return wuffs_base__make_empty_struct(); - } - - if (a_fourcc == 1128813133u) { - self->private_impl.f_report_metadata_chrm = a_report; - } else if (a_fourcc == 1163413830u) { - self->private_impl.f_report_metadata_exif = a_report; - } else if (a_fourcc == 1195461953u) { - self->private_impl.f_report_metadata_gama = a_report; - } else if (a_fourcc == 1229144912u) { - self->private_impl.f_report_metadata_iccp = a_report; - } else if (a_fourcc == 1263947808u) { - self->private_impl.f_report_metadata_kvp = a_report; - } else if (a_fourcc == 1397901122u) { - self->private_impl.f_report_metadata_srgb = a_report; - } return wuffs_base__make_empty_struct(); } -// -------- func png.decoder.tell_me_more +// -------- func qoi.decoder.tell_me_more WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_png__decoder__tell_me_more( - wuffs_png__decoder* self, +wuffs_qoi__decoder__tell_me_more( + wuffs_qoi__decoder* self, wuffs_base__io_buffer* a_dst, wuffs_base__more_information* a_minfo, wuffs_base__io_buffer* a_src) { @@ -66258,937 +72086,651 @@ wuffs_png__decoder__tell_me_more( 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); + status = wuffs_base__make_status(wuffs_base__error__no_more_information); + goto exit; - uint32_t coro_susp_point = self->private_impl.p_tell_me_more; - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + goto ok; + ok: + goto exit; + exit: + if (wuffs_base__status__is_error(&status)) { + self->private_impl.magic = WUFFS_BASE__DISABLED; + } + return status; +} - while (true) { - { - wuffs_base__status t_0 = wuffs_png__decoder__do_tell_me_more(self, a_dst, a_minfo, 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_png__error__truncated_input); - goto exit; - } - status = v_status; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1); +// -------- func qoi.decoder.workbuf_len + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 +wuffs_qoi__decoder__workbuf_len( + const wuffs_qoi__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__QOI) + +#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__SHA256) + +// ---------------- Status Codes Implementations + +// ---------------- Private Consts + +static const uint32_t +WUFFS_SHA256__INITIAL_SHA256_H[8] WUFFS_BASE__POTENTIALLY_UNUSED = { + 1779033703u, 3144134277u, 1013904242u, 2773480762u, 1359893119u, 2600822924u, 528734635u, 1541459225u, +}; + +static const uint32_t +WUFFS_SHA256__K[64] WUFFS_BASE__POTENTIALLY_UNUSED = { + 1116352408u, 1899447441u, 3049323471u, 3921009573u, 961987163u, 1508970993u, 2453635748u, 2870763221u, + 3624381080u, 310598401u, 607225278u, 1426881987u, 1925078388u, 2162078206u, 2614888103u, 3248222580u, + 3835390401u, 4022224774u, 264347078u, 604807628u, 770255983u, 1249150122u, 1555081692u, 1996064986u, + 2554220882u, 2821834349u, 2952996808u, 3210313671u, 3336571891u, 3584528711u, 113926993u, 338241895u, + 666307205u, 773529912u, 1294757372u, 1396182291u, 1695183700u, 1986661051u, 2177026350u, 2456956037u, + 2730485921u, 2820302411u, 3259730800u, 3345764771u, 3516065817u, 3600352804u, 4094571909u, 275423344u, + 430227734u, 506948616u, 659060556u, 883997877u, 958139571u, 1322822218u, 1537002063u, 1747873779u, + 1955562222u, 2024104815u, 2227730452u, 2361852424u, 2428436474u, 2756734187u, 3204031479u, 3329325298u, +}; + +// ---------------- Private Initializer Prototypes + +// ---------------- Private Function Prototypes + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_sha256__hasher__up( + wuffs_sha256__hasher* self, + wuffs_base__slice_u8 a_x); + +// ---------------- VTables + +const wuffs_base__hasher_bitvec256__func_ptrs +wuffs_sha256__hasher__func_ptrs_for__wuffs_base__hasher_bitvec256 = { + (wuffs_base__bitvec256(*)(const void*))(&wuffs_sha256__hasher__checksum_bitvec256), + (uint64_t(*)(const void*, + uint32_t))(&wuffs_sha256__hasher__get_quirk), + (wuffs_base__status(*)(void*, + uint32_t, + uint64_t))(&wuffs_sha256__hasher__set_quirk), + (wuffs_base__empty_struct(*)(void*, + wuffs_base__slice_u8))(&wuffs_sha256__hasher__update), + (wuffs_base__bitvec256(*)(void*, + wuffs_base__slice_u8))(&wuffs_sha256__hasher__update_bitvec256), +}; + +// ---------------- Initializer Implementations + +wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT +wuffs_sha256__hasher__initialize( + wuffs_sha256__hasher* 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)); } + } - ok: - self->private_impl.p_tell_me_more = 0; - goto exit; + self->private_impl.magic = WUFFS_BASE__MAGIC; + self->private_impl.vtable_for__wuffs_base__hasher_bitvec256.vtable_name = + wuffs_base__hasher_bitvec256__vtable_name; + self->private_impl.vtable_for__wuffs_base__hasher_bitvec256.function_pointers = + (const void*)(&wuffs_sha256__hasher__func_ptrs_for__wuffs_base__hasher_bitvec256); + return wuffs_base__make_status(NULL); +} + +wuffs_sha256__hasher* +wuffs_sha256__hasher__alloc(void) { + wuffs_sha256__hasher* x = + (wuffs_sha256__hasher*)(calloc(1, sizeof(wuffs_sha256__hasher))); + if (!x) { + return NULL; + } + if (wuffs_sha256__hasher__initialize( + x, sizeof(wuffs_sha256__hasher), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) { + free(x); + return NULL; } + return x; +} - goto suspend; - suspend: - self->private_impl.p_tell_me_more = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; - self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 4 : 0; +size_t +sizeof__wuffs_sha256__hasher(void) { + return sizeof(wuffs_sha256__hasher); +} - goto exit; - exit: - if (wuffs_base__status__is_error(&status)) { - self->private_impl.magic = WUFFS_BASE__DISABLED; +// ---------------- Function Implementations + +// -------- func sha256.hasher.get_quirk + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC uint64_t +wuffs_sha256__hasher__get_quirk( + const wuffs_sha256__hasher* self, + uint32_t a_key) { + if (!self) { + return 0; } - return status; + if ((self->private_impl.magic != WUFFS_BASE__MAGIC) && + (self->private_impl.magic != WUFFS_BASE__DISABLED)) { + return 0; + } + + return 0u; } -// -------- func png.decoder.do_tell_me_more +// -------- func sha256.hasher.set_quirk WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__do_tell_me_more( - wuffs_png__decoder* self, - wuffs_base__io_buffer* a_dst, - wuffs_base__more_information* a_minfo, - wuffs_base__io_buffer* a_src) { - wuffs_base__status status = wuffs_base__make_status(NULL); +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_sha256__hasher__set_quirk( + wuffs_sha256__hasher* 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); + } - uint8_t v_c8 = 0; - uint16_t v_c16 = 0; - wuffs_base__io_buffer u_w = wuffs_base__empty_io_buffer(); - wuffs_base__io_buffer* v_w = &u_w; - uint8_t* iop_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - uint8_t* io0_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - uint8_t* io1_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - uint8_t* io2_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - uint64_t v_num_written = 0; - uint64_t v_w_mark = 0; - uint64_t v_r_mark = 0; - wuffs_base__status v_zlib_status = wuffs_base__make_status(NULL); + return wuffs_base__make_status(wuffs_base__error__unsupported_option); +} - uint8_t* iop_a_dst = NULL; - uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL; - if (a_dst && a_dst->data.ptr) { - io0_a_dst = a_dst->data.ptr; - io1_a_dst = io0_a_dst + a_dst->meta.wi; - iop_a_dst = io1_a_dst; - io2_a_dst = io0_a_dst + a_dst->data.len; - if (a_dst->meta.closed) { - io2_a_dst = iop_a_dst; +// -------- func sha256.hasher.update + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct +wuffs_sha256__hasher__update( + wuffs_sha256__hasher* self, + wuffs_base__slice_u8 a_x) { + if (!self) { + return wuffs_base__make_empty_struct(); + } + if (self->private_impl.magic != WUFFS_BASE__MAGIC) { + return wuffs_base__make_empty_struct(); + } + + uint64_t v_new_lmu = 0; + + if ((self->private_impl.f_length_modulo_u64 == 0u) && ! self->private_impl.f_length_overflows_u64) { + self->private_impl.f_h0 = WUFFS_SHA256__INITIAL_SHA256_H[0u]; + self->private_impl.f_h1 = WUFFS_SHA256__INITIAL_SHA256_H[1u]; + self->private_impl.f_h2 = WUFFS_SHA256__INITIAL_SHA256_H[2u]; + self->private_impl.f_h3 = WUFFS_SHA256__INITIAL_SHA256_H[3u]; + self->private_impl.f_h4 = WUFFS_SHA256__INITIAL_SHA256_H[4u]; + self->private_impl.f_h5 = WUFFS_SHA256__INITIAL_SHA256_H[5u]; + self->private_impl.f_h6 = WUFFS_SHA256__INITIAL_SHA256_H[6u]; + self->private_impl.f_h7 = WUFFS_SHA256__INITIAL_SHA256_H[7u]; + } + v_new_lmu = ((uint64_t)(self->private_impl.f_length_modulo_u64 + ((uint64_t)(a_x.len)))); + self->private_impl.f_length_overflows_u64 = ((v_new_lmu < self->private_impl.f_length_modulo_u64) || self->private_impl.f_length_overflows_u64); + self->private_impl.f_length_modulo_u64 = v_new_lmu; + if (self->private_impl.f_buf_len != 0u) { + while (self->private_impl.f_buf_len < 64u) { + if (((uint64_t)(a_x.len)) <= 0u) { + return wuffs_base__make_empty_struct(); + } + self->private_impl.f_buf_data[self->private_impl.f_buf_len] = a_x.ptr[0u]; + self->private_impl.f_buf_len += 1u; + a_x = wuffs_base__slice_u8__subslice_i(a_x, 1u); } + self->private_impl.f_buf_len = 0u; + wuffs_sha256__hasher__up(self, wuffs_base__make_slice_u8(self->private_impl.f_buf_data, 64)); } - 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; + wuffs_sha256__hasher__up(self, a_x); + return wuffs_base__make_empty_struct(); +} + +// -------- func sha256.hasher.update_bitvec256 + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__bitvec256 +wuffs_sha256__hasher__update_bitvec256( + wuffs_sha256__hasher* self, + wuffs_base__slice_u8 a_x) { + if (!self) { + return wuffs_base__utility__make_bitvec256(0u, 0u, 0u, 0u); } - - uint32_t coro_susp_point = self->private_impl.p_do_tell_me_more; - if (coro_susp_point) { - v_zlib_status = self->private_data.s_do_tell_me_more.v_zlib_status; + if (self->private_impl.magic != WUFFS_BASE__MAGIC) { + return wuffs_base__utility__make_bitvec256(0u, 0u, 0u, 0u); } - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - if (((uint8_t)(self->private_impl.f_call_sequence & 16u)) == 0u) { - status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence); - goto exit; - } - if (self->private_impl.f_metadata_fourcc == 0u) { - status = wuffs_base__make_status(wuffs_base__error__no_more_information); - goto exit; - } - do { - if (self->private_impl.f_metadata_flavor == 3u) { - while (true) { - if (wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))) != self->private_impl.f_metadata_y) { - status = wuffs_base__make_status(wuffs_base__error__bad_i_o_position); - goto exit; - } else if (a_minfo != NULL) { - wuffs_base__more_information__set(a_minfo, - self->private_impl.f_metadata_flavor, - self->private_impl.f_metadata_fourcc, - self->private_impl.f_metadata_x, - self->private_impl.f_metadata_y, - self->private_impl.f_metadata_z); - } - if (self->private_impl.f_metadata_y >= self->private_impl.f_metadata_z) { - goto label__goto_done__break; - } - self->private_impl.f_metadata_y = self->private_impl.f_metadata_z; - status = wuffs_base__make_status(wuffs_base__suspension__even_more_information); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1); - } - } - if (self->private_impl.f_metadata_is_zlib_compressed) { - if (self->private_impl.f_zlib_is_dirty) { - wuffs_private_impl__ignore_status(wuffs_zlib__decoder__initialize(&self->private_data.f_zlib, - sizeof (wuffs_zlib__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED)); - if (self->private_impl.f_ignore_checksum) { - wuffs_zlib__decoder__set_quirk(&self->private_data.f_zlib, 1u, 1u); - } - } - self->private_impl.f_zlib_is_dirty = true; - self->private_impl.f_ztxt_hist_pos = 0u; - } - label__loop__continue:; - while (true) { - if (a_minfo != NULL) { - wuffs_base__more_information__set(a_minfo, - self->private_impl.f_metadata_flavor, - self->private_impl.f_metadata_fourcc, - self->private_impl.f_metadata_x, - self->private_impl.f_metadata_y, - self->private_impl.f_metadata_z); - } - if (self->private_impl.f_metadata_flavor != 4u) { - break; - } - if (self->private_impl.f_metadata_is_zlib_compressed) { - if (self->private_impl.f_chunk_type == 1346585449u) { - { - const bool o_0_closed_a_src = a_src->meta.closed; - const uint8_t* o_0_io2_a_src = io2_a_src; - wuffs_private_impl__io_reader__limit(&io2_a_src, iop_a_src, - ((uint64_t)(self->private_impl.f_chunk_length))); - if (a_src) { - size_t n = ((size_t)(io2_a_src - a_src->data.ptr)); - a_src->meta.closed = a_src->meta.closed && (a_src->meta.wi <= n); - a_src->meta.wi = n; - } - v_r_mark = ((uint64_t)(iop_a_src - io0_a_src)); - { - if (a_dst) { - a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr)); - } - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - wuffs_base__status t_0 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, a_dst, a_src, wuffs_base__utility__empty_slice_u8()); - v_zlib_status = t_0; - if (a_dst) { - iop_a_dst = a_dst->data.ptr + a_dst->meta.wi; - } - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - } - wuffs_private_impl__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)(wuffs_private_impl__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src)))))); - io2_a_src = o_0_io2_a_src; - if (a_src) { - a_src->meta.closed = o_0_closed_a_src; - a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr)); - } - } - if (wuffs_base__status__is_ok(&v_zlib_status)) { - self->private_impl.f_metadata_is_zlib_compressed = false; - break; - } else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) { - status = v_zlib_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; - } - status = v_zlib_status; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2); - } else if (self->private_impl.f_chunk_type == 1951945833u) { - { - const bool o_1_closed_a_src = a_src->meta.closed; - const uint8_t* o_1_io2_a_src = io2_a_src; - wuffs_private_impl__io_reader__limit(&io2_a_src, iop_a_src, - ((uint64_t)(self->private_impl.f_chunk_length))); - if (a_src) { - size_t n = ((size_t)(io2_a_src - a_src->data.ptr)); - a_src->meta.closed = a_src->meta.closed && (a_src->meta.wi <= n); - a_src->meta.wi = n; - } - v_r_mark = ((uint64_t)(iop_a_src - io0_a_src)); - { - if (a_dst) { - a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr)); - } - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - wuffs_base__status t_1 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, a_dst, a_src, wuffs_base__utility__empty_slice_u8()); - v_zlib_status = t_1; - if (a_dst) { - iop_a_dst = a_dst->data.ptr + a_dst->meta.wi; - } - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - } - wuffs_private_impl__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)(wuffs_private_impl__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src)))))); - io2_a_src = o_1_io2_a_src; - if (a_src) { - a_src->meta.closed = o_1_closed_a_src; - a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr)); - } - } - if (wuffs_base__status__is_ok(&v_zlib_status)) { - self->private_impl.f_metadata_is_zlib_compressed = false; - break; - } else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) { - status = v_zlib_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; - } - status = v_zlib_status; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3); - } else if (self->private_impl.f_chunk_type == 1951945850u) { - if (self->private_impl.f_ztxt_ri == self->private_impl.f_ztxt_wi) { - { - wuffs_base__io_buffer* o_2_v_w = v_w; - uint8_t* o_2_iop_v_w = iop_v_w; - uint8_t* o_2_io0_v_w = io0_v_w; - uint8_t* o_2_io1_v_w = io1_v_w; - uint8_t* o_2_io2_v_w = io2_v_w; - v_w = wuffs_private_impl__io_writer__set( - &u_w, - &iop_v_w, - &io0_v_w, - &io1_v_w, - &io2_v_w, - wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024), - self->private_impl.f_ztxt_hist_pos); - { - const bool o_3_closed_a_src = a_src->meta.closed; - const uint8_t* o_3_io2_a_src = io2_a_src; - wuffs_private_impl__io_reader__limit(&io2_a_src, iop_a_src, - ((uint64_t)(self->private_impl.f_chunk_length))); - if (a_src) { - size_t n = ((size_t)(io2_a_src - a_src->data.ptr)); - a_src->meta.closed = a_src->meta.closed && (a_src->meta.wi <= n); - a_src->meta.wi = n; - } - v_w_mark = ((uint64_t)(iop_v_w - io0_v_w)); - v_r_mark = ((uint64_t)(iop_a_src - io0_a_src)); - { - u_w.meta.wi = ((size_t)(iop_v_w - u_w.data.ptr)); - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - wuffs_base__status t_2 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, v_w, a_src, wuffs_base__utility__empty_slice_u8()); - v_zlib_status = t_2; - iop_v_w = u_w.data.ptr + u_w.meta.wi; - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - } - wuffs_private_impl__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)(wuffs_private_impl__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src)))))); - v_num_written = wuffs_private_impl__io__count_since(v_w_mark, ((uint64_t)(iop_v_w - io0_v_w))); - io2_a_src = o_3_io2_a_src; - if (a_src) { - a_src->meta.closed = o_3_closed_a_src; - a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr)); - } - } - v_w = o_2_v_w; - iop_v_w = o_2_iop_v_w; - io0_v_w = o_2_io0_v_w; - io1_v_w = o_2_io1_v_w; - io2_v_w = o_2_io2_v_w; - } - if (v_num_written > 1024u) { - status = wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_i_o); - goto exit; - } - self->private_impl.f_ztxt_ri = 0u; - self->private_impl.f_ztxt_wi = ((uint32_t)(v_num_written)); - wuffs_private_impl__u64__sat_add_indirect(&self->private_impl.f_ztxt_hist_pos, v_num_written); - } - while (self->private_impl.f_ztxt_ri < self->private_impl.f_ztxt_wi) { - v_c16 = WUFFS_PNG__LATIN_1[self->private_data.f_dst_palette[self->private_impl.f_ztxt_ri]]; - if (v_c16 == 0u) { - status = wuffs_base__make_status(wuffs_png__error__bad_text_chunk_not_latin_1); - goto exit; - } else if (v_c16 <= 127u) { - if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0u) { - status = wuffs_base__make_status(wuffs_base__suspension__short_write); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4); - goto label__loop__continue; - } - self->private_impl.f_ztxt_ri += 1u; - (wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, ((uint8_t)(v_c16))), iop_a_dst += 1); - } else { - if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 1u) { - status = wuffs_base__make_status(wuffs_base__suspension__short_write); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5); - goto label__loop__continue; - } - self->private_impl.f_ztxt_ri += 1u; - (wuffs_base__poke_u16le__no_bounds_check(iop_a_dst, v_c16), iop_a_dst += 2); - } - } - if (wuffs_base__status__is_ok(&v_zlib_status)) { - self->private_impl.f_metadata_is_zlib_compressed = false; - break; - } else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) { - status = v_zlib_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; - } else if (v_zlib_status.repr != wuffs_base__suspension__short_write) { - status = v_zlib_status; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6); - } - } else { - status = wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_chunk_type); - goto exit; - } - } else if ((self->private_impl.f_chunk_type == 1951945833u) && (self->private_impl.f_metadata_fourcc == 1263947862u)) { - while (true) { - if (self->private_impl.f_chunk_length <= 0u) { - goto label__loop__break; - } else if (((uint64_t)(io2_a_src - iop_a_src)) <= 0u) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7); - goto label__loop__continue; - } else if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0u) { - status = wuffs_base__make_status(wuffs_base__suspension__short_write); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8); - goto label__loop__continue; - } - self->private_impl.f_chunk_length -= 1u; - v_c8 = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); - iop_a_src += 1u; - (wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, v_c8), iop_a_dst += 1); - } - } else { - while (true) { - if (self->private_impl.f_chunk_length <= 0u) { - if (self->private_impl.f_metadata_fourcc == 1263947851u) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } - goto label__loop__break; - } else if (((uint64_t)(io2_a_src - iop_a_src)) <= 0u) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9); - goto label__loop__continue; - } - v_c8 = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); - if (v_c8 == 0u) { - self->private_impl.f_chunk_length -= 1u; - iop_a_src += 1u; - goto label__loop__break; - } - v_c16 = WUFFS_PNG__LATIN_1[v_c8]; - if (v_c16 == 0u) { - status = wuffs_base__make_status(wuffs_png__error__bad_text_chunk_not_latin_1); - goto exit; - } else if (v_c16 <= 127u) { - if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0u) { - status = wuffs_base__make_status(wuffs_base__suspension__short_write); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10); - goto label__loop__continue; - } - self->private_impl.f_chunk_length -= 1u; - iop_a_src += 1u; - (wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, ((uint8_t)(v_c16))), iop_a_dst += 1); - } else { - if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 1u) { - status = wuffs_base__make_status(wuffs_base__suspension__short_write); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11); - goto label__loop__continue; - } - self->private_impl.f_chunk_length -= 1u; - iop_a_src += 1u; - (wuffs_base__poke_u16le__no_bounds_check(iop_a_dst, v_c16), iop_a_dst += 2); - } - } - } - } - label__loop__break:; - if (self->private_impl.f_metadata_fourcc == 1263947851u) { - self->private_impl.f_metadata_fourcc = 1263947862u; - if (self->private_impl.f_chunk_type == 1951945833u) { - if (self->private_impl.f_chunk_length <= 1u) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } - self->private_impl.f_chunk_length -= 2u; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_3 = *iop_a_src++; - v_c8 = t_3; - } - if (v_c8 == 0u) { - self->private_impl.f_metadata_is_zlib_compressed = false; - } else if (v_c8 == 1u) { - self->private_impl.f_metadata_is_zlib_compressed = true; - } else { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_4 = *iop_a_src++; - v_c8 = t_4; - } - if ((v_c8 != 0u) && self->private_impl.f_metadata_is_zlib_compressed) { - status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method); - goto exit; - } - self->private_impl.f_metadata_fourcc -= 2u; - while (self->private_impl.f_metadata_fourcc != 1263947862u) { - self->private_impl.f_metadata_fourcc += 1u; - while (true) { - if (self->private_impl.f_chunk_length <= 0u) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } - self->private_impl.f_chunk_length -= 1u; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(14); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_5 = *iop_a_src++; - v_c8 = t_5; - } - if (v_c8 == 0u) { - break; - } - } - } - } else if (self->private_impl.f_chunk_type == 1951945850u) { - if (self->private_impl.f_chunk_length <= 0u) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; - } - self->private_impl.f_chunk_length -= 1u; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_6 = *iop_a_src++; - v_c8 = t_6; - } - if (v_c8 != 0u) { - status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method); - goto exit; - } - self->private_impl.f_metadata_is_zlib_compressed = true; - } - self->private_impl.f_call_sequence &= 239u; - status = wuffs_base__make_status(NULL); - goto ok; + wuffs_sha256__hasher__update(self, a_x); + return wuffs_sha256__hasher__checksum_bitvec256(self); +} + +// -------- func sha256.hasher.up + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_sha256__hasher__up( + wuffs_sha256__hasher* self, + wuffs_base__slice_u8 a_x) { + wuffs_base__slice_u8 v_p = {0}; + uint32_t v_w[64] = {0}; + uint32_t v_w2 = 0; + uint32_t v_w15 = 0; + uint32_t v_s0 = 0; + uint32_t v_s1 = 0; + uint32_t v_t1 = 0; + uint32_t v_t2 = 0; + uint32_t v_a = 0; + uint32_t v_b = 0; + uint32_t v_c = 0; + uint32_t v_d = 0; + uint32_t v_e = 0; + uint32_t v_f = 0; + uint32_t v_g = 0; + uint32_t v_h = 0; + uint32_t v_i = 0; + uint32_t v_buf_len = 0; + + v_a = self->private_impl.f_h0; + v_b = self->private_impl.f_h1; + v_c = self->private_impl.f_h2; + v_d = self->private_impl.f_h3; + v_e = self->private_impl.f_h4; + v_f = self->private_impl.f_h5; + v_g = self->private_impl.f_h6; + v_h = self->private_impl.f_h7; + { + wuffs_base__slice_u8 i_slice_p = a_x; + v_p.ptr = i_slice_p.ptr; + v_p.len = 64; + const uint8_t* i_end0_p = wuffs_private_impl__ptr_u8_plus_len(v_p.ptr, (((i_slice_p.len - (size_t)(v_p.ptr - i_slice_p.ptr)) / 64) * 64)); + while (v_p.ptr < i_end0_p) { + v_w[0u] = ((((uint32_t)(v_p.ptr[0u])) << 24u) | + (((uint32_t)(v_p.ptr[1u])) << 16u) | + (((uint32_t)(v_p.ptr[2u])) << 8u) | + ((uint32_t)(v_p.ptr[3u]))); + v_w[1u] = ((((uint32_t)(v_p.ptr[4u])) << 24u) | + (((uint32_t)(v_p.ptr[5u])) << 16u) | + (((uint32_t)(v_p.ptr[6u])) << 8u) | + ((uint32_t)(v_p.ptr[7u]))); + v_w[2u] = ((((uint32_t)(v_p.ptr[8u])) << 24u) | + (((uint32_t)(v_p.ptr[9u])) << 16u) | + (((uint32_t)(v_p.ptr[10u])) << 8u) | + ((uint32_t)(v_p.ptr[11u]))); + v_w[3u] = ((((uint32_t)(v_p.ptr[12u])) << 24u) | + (((uint32_t)(v_p.ptr[13u])) << 16u) | + (((uint32_t)(v_p.ptr[14u])) << 8u) | + ((uint32_t)(v_p.ptr[15u]))); + v_w[4u] = ((((uint32_t)(v_p.ptr[16u])) << 24u) | + (((uint32_t)(v_p.ptr[17u])) << 16u) | + (((uint32_t)(v_p.ptr[18u])) << 8u) | + ((uint32_t)(v_p.ptr[19u]))); + v_w[5u] = ((((uint32_t)(v_p.ptr[20u])) << 24u) | + (((uint32_t)(v_p.ptr[21u])) << 16u) | + (((uint32_t)(v_p.ptr[22u])) << 8u) | + ((uint32_t)(v_p.ptr[23u]))); + v_w[6u] = ((((uint32_t)(v_p.ptr[24u])) << 24u) | + (((uint32_t)(v_p.ptr[25u])) << 16u) | + (((uint32_t)(v_p.ptr[26u])) << 8u) | + ((uint32_t)(v_p.ptr[27u]))); + v_w[7u] = ((((uint32_t)(v_p.ptr[28u])) << 24u) | + (((uint32_t)(v_p.ptr[29u])) << 16u) | + (((uint32_t)(v_p.ptr[30u])) << 8u) | + ((uint32_t)(v_p.ptr[31u]))); + v_w[8u] = ((((uint32_t)(v_p.ptr[32u])) << 24u) | + (((uint32_t)(v_p.ptr[33u])) << 16u) | + (((uint32_t)(v_p.ptr[34u])) << 8u) | + ((uint32_t)(v_p.ptr[35u]))); + v_w[9u] = ((((uint32_t)(v_p.ptr[36u])) << 24u) | + (((uint32_t)(v_p.ptr[37u])) << 16u) | + (((uint32_t)(v_p.ptr[38u])) << 8u) | + ((uint32_t)(v_p.ptr[39u]))); + v_w[10u] = ((((uint32_t)(v_p.ptr[40u])) << 24u) | + (((uint32_t)(v_p.ptr[41u])) << 16u) | + (((uint32_t)(v_p.ptr[42u])) << 8u) | + ((uint32_t)(v_p.ptr[43u]))); + v_w[11u] = ((((uint32_t)(v_p.ptr[44u])) << 24u) | + (((uint32_t)(v_p.ptr[45u])) << 16u) | + (((uint32_t)(v_p.ptr[46u])) << 8u) | + ((uint32_t)(v_p.ptr[47u]))); + v_w[12u] = ((((uint32_t)(v_p.ptr[48u])) << 24u) | + (((uint32_t)(v_p.ptr[49u])) << 16u) | + (((uint32_t)(v_p.ptr[50u])) << 8u) | + ((uint32_t)(v_p.ptr[51u]))); + v_w[13u] = ((((uint32_t)(v_p.ptr[52u])) << 24u) | + (((uint32_t)(v_p.ptr[53u])) << 16u) | + (((uint32_t)(v_p.ptr[54u])) << 8u) | + ((uint32_t)(v_p.ptr[55u]))); + v_w[14u] = ((((uint32_t)(v_p.ptr[56u])) << 24u) | + (((uint32_t)(v_p.ptr[57u])) << 16u) | + (((uint32_t)(v_p.ptr[58u])) << 8u) | + ((uint32_t)(v_p.ptr[59u]))); + v_w[15u] = ((((uint32_t)(v_p.ptr[60u])) << 24u) | + (((uint32_t)(v_p.ptr[61u])) << 16u) | + (((uint32_t)(v_p.ptr[62u])) << 8u) | + ((uint32_t)(v_p.ptr[63u]))); + v_i = 16u; + while (v_i < 64u) { + v_w2 = v_w[(v_i - 2u)]; + v_s1 = ((v_w2 >> 10u) ^ (((uint32_t)(v_w2 << 15u)) | (v_w2 >> 17u)) ^ (((uint32_t)(v_w2 << 13u)) | (v_w2 >> 19u))); + v_w15 = v_w[(v_i - 15u)]; + v_s0 = ((v_w15 >> 3u) ^ (((uint32_t)(v_w15 << 25u)) | (v_w15 >> 7u)) ^ (((uint32_t)(v_w15 << 14u)) | (v_w15 >> 18u))); + v_w[v_i] = ((uint32_t)(((uint32_t)(((uint32_t)(v_s1 + v_w[(v_i - 7u)])) + v_s0)) + v_w[(v_i - 16u)])); + v_i += 1u; } - } while (0); - label__goto_done__break:; - if (self->private_impl.f_chunk_length != 0u) { - status = wuffs_base__make_status(wuffs_png__error__bad_chunk); - goto exit; + v_i = 0u; + while (v_i < 64u) { + v_t1 = v_h; + v_t1 += ((((uint32_t)(v_e << 26u)) | (v_e >> 6u)) ^ (((uint32_t)(v_e << 21u)) | (v_e >> 11u)) ^ (((uint32_t)(v_e << 7u)) | (v_e >> 25u))); + v_t1 += ((v_e & v_f) ^ ((4294967295u ^ v_e) & v_g)); + v_t1 += WUFFS_SHA256__K[v_i]; + v_t1 += v_w[v_i]; + v_t2 = ((((uint32_t)(v_a << 30u)) | (v_a >> 2u)) ^ (((uint32_t)(v_a << 19u)) | (v_a >> 13u)) ^ (((uint32_t)(v_a << 10u)) | (v_a >> 22u))); + v_t2 += ((v_a & v_b) ^ (v_a & v_c) ^ (v_b & v_c)); + v_h = v_g; + v_g = v_f; + v_f = v_e; + v_e = ((uint32_t)(v_d + v_t1)); + v_d = v_c; + v_c = v_b; + v_b = v_a; + v_a = ((uint32_t)(v_t1 + v_t2)); + v_i += 1u; + } + v_a += self->private_impl.f_h0; + self->private_impl.f_h0 = v_a; + v_b += self->private_impl.f_h1; + self->private_impl.f_h1 = v_b; + v_c += self->private_impl.f_h2; + self->private_impl.f_h2 = v_c; + v_d += self->private_impl.f_h3; + self->private_impl.f_h3 = v_d; + v_e += self->private_impl.f_h4; + self->private_impl.f_h4 = v_e; + v_f += self->private_impl.f_h5; + self->private_impl.f_h5 = v_f; + v_g += self->private_impl.f_h6; + self->private_impl.f_h6 = v_g; + v_h += self->private_impl.f_h7; + self->private_impl.f_h7 = v_h; + v_p.ptr += 64; } - self->private_data.s_do_tell_me_more.scratch = 4u; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16); - if (self->private_data.s_do_tell_me_more.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { - self->private_data.s_do_tell_me_more.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); - iop_a_src = io2_a_src; - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; + v_p.len = 1; + const uint8_t* i_end1_p = wuffs_private_impl__ptr_u8_plus_len(i_slice_p.ptr, i_slice_p.len); + while (v_p.ptr < i_end1_p) { + self->private_impl.f_buf_data[v_buf_len] = v_p.ptr[0u]; + v_buf_len = ((v_buf_len + 1u) & 63u); + v_p.ptr += 1; } - iop_a_src += self->private_data.s_do_tell_me_more.scratch; - self->private_impl.f_metadata_flavor = 0u; - self->private_impl.f_metadata_fourcc = 0u; - self->private_impl.f_metadata_x = 0u; - self->private_impl.f_metadata_y = 0u; - self->private_impl.f_metadata_z = 0u; - self->private_impl.f_call_sequence &= 239u; - status = wuffs_base__make_status(NULL); - goto ok; - - ok: - self->private_impl.p_do_tell_me_more = 0; - goto exit; - } - - goto suspend; - suspend: - self->private_impl.p_do_tell_me_more = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; - self->private_data.s_do_tell_me_more.v_zlib_status = v_zlib_status; - - goto exit; - exit: - if (a_dst && a_dst->data.ptr) { - a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr)); - } - if (a_src && a_src->data.ptr) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + v_p.len = 0; } - - return status; + self->private_impl.f_buf_len = ((uint32_t)((((uint64_t)(a_x.len)) & 63u))); + return wuffs_base__make_empty_struct(); } -// -------- func png.decoder.workbuf_len +// -------- func sha256.hasher.checksum_bitvec256 WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 -wuffs_png__decoder__workbuf_len( - const wuffs_png__decoder* self) { +WUFFS_BASE__MAYBE_STATIC wuffs_base__bitvec256 +wuffs_sha256__hasher__checksum_bitvec256( + const wuffs_sha256__hasher* self) { if (!self) { - return wuffs_base__utility__empty_range_ii_u64(); + return wuffs_base__utility__make_bitvec256(0u, 0u, 0u, 0u); } 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_bitvec256(0u, 0u, 0u, 0u); } - return wuffs_base__utility__make_range_ii_u64(self->private_impl.f_overall_workbuf_length, self->private_impl.f_overall_workbuf_length); -} - -// -------- func png.decoder.filter_and_swizzle - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__filter_and_swizzle( - wuffs_png__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__slice_u8 a_workbuf) { - return (*self->private_impl.choosy_filter_and_swizzle)(self, a_dst, a_workbuf); -} - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__filter_and_swizzle__choosy_default( - wuffs_png__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__slice_u8 a_workbuf) { - wuffs_base__pixel_format v_dst_pixfmt = {0}; - uint32_t v_dst_bits_per_pixel = 0; - uint64_t v_dst_bytes_per_pixel = 0; - uint64_t v_dst_bytes_per_row0 = 0; - uint64_t v_dst_bytes_per_row1 = 0; - wuffs_base__slice_u8 v_dst_palette = {0}; - wuffs_base__table_u8 v_tab = {0}; - uint32_t v_y = 0; - wuffs_base__slice_u8 v_dst = {0}; - uint8_t v_filter = 0; - wuffs_base__slice_u8 v_curr_row = {0}; - wuffs_base__slice_u8 v_prev_row = {0}; + uint32_t v_buf_len = 0; + uint8_t v_buf_data[64] = {0}; + uint64_t v_length_in_bits = 0; + uint32_t v_w[64] = {0}; + uint32_t v_w2 = 0; + uint32_t v_w15 = 0; + uint32_t v_s0 = 0; + uint32_t v_s1 = 0; + uint32_t v_t1 = 0; + uint32_t v_t2 = 0; + uint32_t v_h0 = 0; + uint32_t v_h1 = 0; + uint32_t v_h2 = 0; + uint32_t v_h3 = 0; + uint32_t v_h4 = 0; + uint32_t v_h5 = 0; + uint32_t v_h6 = 0; + uint32_t v_h7 = 0; + uint32_t v_a = 0; + uint32_t v_b = 0; + uint32_t v_c = 0; + uint32_t v_d = 0; + uint32_t v_e = 0; + uint32_t v_f = 0; + uint32_t v_g = 0; + uint32_t v_h = 0; + uint32_t v_i = 0; + bool v_final_block = false; - 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 = ((uint64_t)((v_dst_bits_per_pixel / 8u))); - v_dst_bytes_per_row0 = (((uint64_t)(self->private_impl.f_frame_rect_x0)) * v_dst_bytes_per_pixel); - v_dst_bytes_per_row1 = (((uint64_t)(self->private_impl.f_frame_rect_x1)) * v_dst_bytes_per_pixel); - v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024)); - v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0u); - if (v_dst_bytes_per_row1 < ((uint64_t)(v_tab.width))) { - v_tab = wuffs_base__table_u8__subtable_ij(v_tab, - 0u, - 0u, - v_dst_bytes_per_row1, - ((uint64_t)(v_tab.height))); - } - if (v_dst_bytes_per_row0 < ((uint64_t)(v_tab.width))) { - v_tab = wuffs_base__table_u8__subtable_ij(v_tab, - v_dst_bytes_per_row0, - 0u, - ((uint64_t)(v_tab.width)), - ((uint64_t)(v_tab.height))); - } else { - v_tab = wuffs_base__table_u8__subtable_ij(v_tab, - 0u, - 0u, - 0u, - 0u); + v_i = 0u; + while (v_i < 64u) { + v_buf_data[v_i] = self->private_impl.f_buf_data[v_i]; + v_i += 1u; } - v_y = self->private_impl.f_frame_rect_y0; - while (v_y < self->private_impl.f_frame_rect_y1) { - v_dst = wuffs_private_impl__table_u8__row_u32(v_tab, v_y); - if (1u > ((uint64_t)(a_workbuf.len))) { - return wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_workbuf_length); - } - v_filter = a_workbuf.ptr[0u]; - a_workbuf = wuffs_base__slice_u8__subslice_i(a_workbuf, 1u); - if (self->private_impl.f_pass_bytes_per_row > ((uint64_t)(a_workbuf.len))) { - return wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_workbuf_length); - } - v_curr_row = wuffs_base__slice_u8__subslice_j(a_workbuf, self->private_impl.f_pass_bytes_per_row); - a_workbuf = wuffs_base__slice_u8__subslice_i(a_workbuf, self->private_impl.f_pass_bytes_per_row); - if (v_filter == 0u) { - } else if (v_filter == 1u) { - wuffs_png__decoder__filter_1(self, v_curr_row); - } else if (v_filter == 2u) { - wuffs_png__decoder__filter_2(self, v_curr_row, v_prev_row); - } else if (v_filter == 3u) { - wuffs_png__decoder__filter_3(self, v_curr_row, v_prev_row); - } else if (v_filter == 4u) { - wuffs_png__decoder__filter_4(self, v_curr_row, v_prev_row); - } else { - return wuffs_base__make_status(wuffs_png__error__bad_filter); + v_buf_len = (self->private_impl.f_buf_len & 63u); + if (v_buf_len < 56u) { + v_buf_data[v_buf_len] = 128u; + v_buf_len += 1u; + while (v_buf_len < 56u) { + v_buf_data[v_buf_len] = 0u; + v_buf_len += 1u; } - wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, v_curr_row); - v_prev_row = v_curr_row; - v_y += 1u; - } - return wuffs_base__make_status(NULL); -} - -// -------- func png.decoder.filter_and_swizzle_tricky - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_png__decoder__filter_and_swizzle_tricky( - wuffs_png__decoder* self, - wuffs_base__pixel_buffer* a_dst, - wuffs_base__slice_u8 a_workbuf) { - wuffs_base__pixel_format v_dst_pixfmt = {0}; - uint32_t v_dst_bits_per_pixel = 0; - uint64_t v_dst_bytes_per_pixel = 0; - uint64_t v_dst_bytes_per_row1 = 0; - wuffs_base__slice_u8 v_dst_palette = {0}; - wuffs_base__table_u8 v_tab = {0}; - uint64_t v_src_bytes_per_pixel = 0; - uint32_t v_x = 0; - uint32_t v_y = 0; - uint64_t v_i = 0; - wuffs_base__slice_u8 v_dst = {0}; - uint8_t v_filter = 0; - wuffs_base__slice_u8 v_s = {0}; - wuffs_base__slice_u8 v_curr_row = {0}; - wuffs_base__slice_u8 v_prev_row = {0}; - uint8_t v_bits_unpacked[8] = {0}; - uint8_t v_bits_packed = 0; - uint8_t v_packs_remaining = 0; - uint8_t v_multiplier = 0; - uint8_t v_shift = 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 = ((uint64_t)((v_dst_bits_per_pixel / 8u))); - v_dst_bytes_per_row1 = (((uint64_t)(self->private_impl.f_frame_rect_x1)) * v_dst_bytes_per_pixel); - v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024)); - v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0u); - v_src_bytes_per_pixel = 1u; - if (self->private_impl.f_depth >= 8u) { - v_src_bytes_per_pixel = (((uint64_t)(WUFFS_PNG__NUM_CHANNELS[self->private_impl.f_color_type])) * ((uint64_t)(((uint8_t)(self->private_impl.f_depth >> 3u))))); - } - if (self->private_impl.f_chunk_type_array[0u] == 73u) { - v_y = ((uint32_t)(WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][5u])); + v_final_block = true; } else { - v_y = self->private_impl.f_frame_rect_y0; - } - while (v_y < self->private_impl.f_frame_rect_y1) { - v_dst = wuffs_private_impl__table_u8__row_u32(v_tab, v_y); - if (v_dst_bytes_per_row1 < ((uint64_t)(v_dst.len))) { - v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_dst_bytes_per_row1); - } - if (1u > ((uint64_t)(a_workbuf.len))) { - return wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_workbuf_length); - } - v_filter = a_workbuf.ptr[0u]; - a_workbuf = wuffs_base__slice_u8__subslice_i(a_workbuf, 1u); - if (self->private_impl.f_pass_bytes_per_row > ((uint64_t)(a_workbuf.len))) { - return wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_workbuf_length); - } - v_curr_row = wuffs_base__slice_u8__subslice_j(a_workbuf, self->private_impl.f_pass_bytes_per_row); - a_workbuf = wuffs_base__slice_u8__subslice_i(a_workbuf, self->private_impl.f_pass_bytes_per_row); - if (v_filter == 0u) { - } else if (v_filter == 1u) { - wuffs_png__decoder__filter_1(self, v_curr_row); - } else if (v_filter == 2u) { - wuffs_png__decoder__filter_2(self, v_curr_row, v_prev_row); - } else if (v_filter == 3u) { - wuffs_png__decoder__filter_3(self, v_curr_row, v_prev_row); - } else if (v_filter == 4u) { - wuffs_png__decoder__filter_4(self, v_curr_row, v_prev_row); - } else { - return wuffs_base__make_status(wuffs_png__error__bad_filter); - } - v_s = v_curr_row; - if (self->private_impl.f_chunk_type_array[0u] == 73u) { - v_x = ((uint32_t)(WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][2u])); - } else { - v_x = self->private_impl.f_frame_rect_x0; - } - if (self->private_impl.f_depth == 8u) { - while (v_x < self->private_impl.f_frame_rect_x1) { - v_i = (((uint64_t)(v_x)) * v_dst_bytes_per_pixel); - if (v_i <= ((uint64_t)(v_dst.len))) { - if (((uint32_t)(self->private_impl.f_remap_transparency)) != 0u) { - if (self->private_impl.f_color_type == 0u) { - if (1u <= ((uint64_t)(v_s.len))) { - v_bits_unpacked[0u] = v_s.ptr[0u]; - v_bits_unpacked[1u] = v_s.ptr[0u]; - v_bits_unpacked[2u] = v_s.ptr[0u]; - v_bits_unpacked[3u] = 255u; - v_s = wuffs_base__slice_u8__subslice_i(v_s, 1u); - if (((uint32_t)(self->private_impl.f_remap_transparency)) == ((((uint32_t)(v_bits_unpacked[0u])) << 0u) | - (((uint32_t)(v_bits_unpacked[1u])) << 8u) | - (((uint32_t)(v_bits_unpacked[2u])) << 16u) | - (((uint32_t)(v_bits_unpacked[3u])) << 24u))) { - v_bits_unpacked[0u] = 0u; - v_bits_unpacked[1u] = 0u; - v_bits_unpacked[2u] = 0u; - v_bits_unpacked[3u] = 0u; - } - wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__make_slice_u8(v_bits_unpacked, 4)); - } - } else { - if (3u <= ((uint64_t)(v_s.len))) { - v_bits_unpacked[0u] = v_s.ptr[2u]; - v_bits_unpacked[1u] = v_s.ptr[1u]; - v_bits_unpacked[2u] = v_s.ptr[0u]; - v_bits_unpacked[3u] = 255u; - v_s = wuffs_base__slice_u8__subslice_i(v_s, 3u); - if (((uint32_t)(self->private_impl.f_remap_transparency)) == ((((uint32_t)(v_bits_unpacked[0u])) << 0u) | - (((uint32_t)(v_bits_unpacked[1u])) << 8u) | - (((uint32_t)(v_bits_unpacked[2u])) << 16u) | - (((uint32_t)(v_bits_unpacked[3u])) << 24u))) { - v_bits_unpacked[0u] = 0u; - v_bits_unpacked[1u] = 0u; - v_bits_unpacked[2u] = 0u; - v_bits_unpacked[3u] = 0u; - } - wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__make_slice_u8(v_bits_unpacked, 4)); - } - } - } else if (v_src_bytes_per_pixel <= ((uint64_t)(v_s.len))) { - wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__slice_u8__subslice_j(v_s, v_src_bytes_per_pixel)); - v_s = wuffs_base__slice_u8__subslice_i(v_s, v_src_bytes_per_pixel); - } - } - v_x += (((uint32_t)(1u)) << WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][0u]); - } - } else if (self->private_impl.f_depth < 8u) { - v_multiplier = 1u; - if (self->private_impl.f_color_type == 0u) { - v_multiplier = WUFFS_PNG__LOW_BIT_DEPTH_MULTIPLIERS[self->private_impl.f_depth]; - } - v_shift = ((uint8_t)(((uint8_t)(8u - self->private_impl.f_depth)) & 7u)); - v_packs_remaining = 0u; - while (v_x < self->private_impl.f_frame_rect_x1) { - v_i = (((uint64_t)(v_x)) * v_dst_bytes_per_pixel); - if (v_i <= ((uint64_t)(v_dst.len))) { - if ((v_packs_remaining == 0u) && (1u <= ((uint64_t)(v_s.len)))) { - v_packs_remaining = WUFFS_PNG__LOW_BIT_DEPTH_NUM_PACKS[self->private_impl.f_depth]; - v_bits_packed = v_s.ptr[0u]; - v_s = wuffs_base__slice_u8__subslice_i(v_s, 1u); - } - v_bits_unpacked[0u] = ((uint8_t)(((uint8_t)(v_bits_packed >> v_shift)) * v_multiplier)); - v_bits_packed = ((uint8_t)(v_bits_packed << self->private_impl.f_depth)); - v_packs_remaining = ((uint8_t)(v_packs_remaining - 1u)); - if (((uint32_t)(self->private_impl.f_remap_transparency)) != 0u) { - v_bits_unpacked[1u] = v_bits_unpacked[0u]; - v_bits_unpacked[2u] = v_bits_unpacked[0u]; - v_bits_unpacked[3u] = 255u; - if (((uint32_t)(self->private_impl.f_remap_transparency)) == ((((uint32_t)(v_bits_unpacked[0u])) << 0u) | - (((uint32_t)(v_bits_unpacked[1u])) << 8u) | - (((uint32_t)(v_bits_unpacked[2u])) << 16u) | - (((uint32_t)(v_bits_unpacked[3u])) << 24u))) { - v_bits_unpacked[0u] = 0u; - v_bits_unpacked[1u] = 0u; - v_bits_unpacked[2u] = 0u; - v_bits_unpacked[3u] = 0u; - } - wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__make_slice_u8(v_bits_unpacked, 4)); - } else { - wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__make_slice_u8(v_bits_unpacked, 1)); - } - } - v_x += (((uint32_t)(1u)) << WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][0u]); - } - } else { - while (v_x < self->private_impl.f_frame_rect_x1) { - v_i = (((uint64_t)(v_x)) * v_dst_bytes_per_pixel); - if (v_i <= ((uint64_t)(v_dst.len))) { - if (self->private_impl.f_color_type == 0u) { - if (2u <= ((uint64_t)(v_s.len))) { - v_bits_unpacked[0u] = v_s.ptr[1u]; - v_bits_unpacked[1u] = v_s.ptr[0u]; - v_bits_unpacked[2u] = v_s.ptr[1u]; - v_bits_unpacked[3u] = v_s.ptr[0u]; - v_bits_unpacked[4u] = v_s.ptr[1u]; - v_bits_unpacked[5u] = v_s.ptr[0u]; - v_bits_unpacked[6u] = 255u; - v_bits_unpacked[7u] = 255u; - v_s = wuffs_base__slice_u8__subslice_i(v_s, 2u); - if (self->private_impl.f_remap_transparency == ((((uint64_t)(v_bits_unpacked[0u])) << 0u) | - (((uint64_t)(v_bits_unpacked[1u])) << 8u) | - (((uint64_t)(v_bits_unpacked[2u])) << 16u) | - (((uint64_t)(v_bits_unpacked[3u])) << 24u) | - (((uint64_t)(v_bits_unpacked[4u])) << 32u) | - (((uint64_t)(v_bits_unpacked[5u])) << 40u) | - (((uint64_t)(v_bits_unpacked[6u])) << 48u) | - (((uint64_t)(v_bits_unpacked[7u])) << 56u))) { - v_bits_unpacked[0u] = 0u; - v_bits_unpacked[1u] = 0u; - v_bits_unpacked[2u] = 0u; - v_bits_unpacked[3u] = 0u; - v_bits_unpacked[4u] = 0u; - v_bits_unpacked[5u] = 0u; - v_bits_unpacked[6u] = 0u; - v_bits_unpacked[7u] = 0u; - } - } - } else if (self->private_impl.f_color_type == 2u) { - if (6u <= ((uint64_t)(v_s.len))) { - v_bits_unpacked[0u] = v_s.ptr[5u]; - v_bits_unpacked[1u] = v_s.ptr[4u]; - v_bits_unpacked[2u] = v_s.ptr[3u]; - v_bits_unpacked[3u] = v_s.ptr[2u]; - v_bits_unpacked[4u] = v_s.ptr[1u]; - v_bits_unpacked[5u] = v_s.ptr[0u]; - v_bits_unpacked[6u] = 255u; - v_bits_unpacked[7u] = 255u; - v_s = wuffs_base__slice_u8__subslice_i(v_s, 6u); - if (self->private_impl.f_remap_transparency == ((((uint64_t)(v_bits_unpacked[0u])) << 0u) | - (((uint64_t)(v_bits_unpacked[1u])) << 8u) | - (((uint64_t)(v_bits_unpacked[2u])) << 16u) | - (((uint64_t)(v_bits_unpacked[3u])) << 24u) | - (((uint64_t)(v_bits_unpacked[4u])) << 32u) | - (((uint64_t)(v_bits_unpacked[5u])) << 40u) | - (((uint64_t)(v_bits_unpacked[6u])) << 48u) | - (((uint64_t)(v_bits_unpacked[7u])) << 56u))) { - v_bits_unpacked[0u] = 0u; - v_bits_unpacked[1u] = 0u; - v_bits_unpacked[2u] = 0u; - v_bits_unpacked[3u] = 0u; - v_bits_unpacked[4u] = 0u; - v_bits_unpacked[5u] = 0u; - v_bits_unpacked[6u] = 0u; - v_bits_unpacked[7u] = 0u; - } - } - } else if (self->private_impl.f_color_type == 4u) { - if (4u <= ((uint64_t)(v_s.len))) { - v_bits_unpacked[0u] = v_s.ptr[1u]; - v_bits_unpacked[1u] = v_s.ptr[0u]; - v_bits_unpacked[2u] = v_s.ptr[1u]; - v_bits_unpacked[3u] = v_s.ptr[0u]; - v_bits_unpacked[4u] = v_s.ptr[1u]; - v_bits_unpacked[5u] = v_s.ptr[0u]; - v_bits_unpacked[6u] = v_s.ptr[3u]; - v_bits_unpacked[7u] = v_s.ptr[2u]; - v_s = wuffs_base__slice_u8__subslice_i(v_s, 4u); - } - } else { - if (8u <= ((uint64_t)(v_s.len))) { - v_bits_unpacked[0u] = v_s.ptr[5u]; - v_bits_unpacked[1u] = v_s.ptr[4u]; - v_bits_unpacked[2u] = v_s.ptr[3u]; - v_bits_unpacked[3u] = v_s.ptr[2u]; - v_bits_unpacked[4u] = v_s.ptr[1u]; - v_bits_unpacked[5u] = v_s.ptr[0u]; - v_bits_unpacked[6u] = v_s.ptr[7u]; - v_bits_unpacked[7u] = v_s.ptr[6u]; - v_s = wuffs_base__slice_u8__subslice_i(v_s, 8u); - } - } - wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__make_slice_u8(v_bits_unpacked, 8)); - } - v_x += (((uint32_t)(1u)) << WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][0u]); - } + v_buf_data[v_buf_len] = 128u; + v_buf_len += 1u; + while (v_buf_len < 64u) { + v_buf_data[v_buf_len] = 0u; + v_buf_len += 1u; } - v_prev_row = v_curr_row; - v_y += (((uint32_t)(1u)) << WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][3u]); } - return wuffs_base__make_status(NULL); + v_h0 = self->private_impl.f_h0; + v_a = v_h0; + v_h1 = self->private_impl.f_h1; + v_b = v_h1; + v_h2 = self->private_impl.f_h2; + v_c = v_h2; + v_h3 = self->private_impl.f_h3; + v_d = v_h3; + v_h4 = self->private_impl.f_h4; + v_e = v_h4; + v_h5 = self->private_impl.f_h5; + v_f = v_h5; + v_h6 = self->private_impl.f_h6; + v_g = v_h6; + v_h7 = self->private_impl.f_h7; + v_h = v_h7; + while (true) { + if (v_final_block) { + v_length_in_bits = ((uint64_t)(self->private_impl.f_length_modulo_u64 * 8u)); + v_buf_data[56u] = ((uint8_t)((v_length_in_bits >> 56u))); + v_buf_data[57u] = ((uint8_t)((v_length_in_bits >> 48u))); + v_buf_data[58u] = ((uint8_t)((v_length_in_bits >> 40u))); + v_buf_data[59u] = ((uint8_t)((v_length_in_bits >> 32u))); + v_buf_data[60u] = ((uint8_t)((v_length_in_bits >> 24u))); + v_buf_data[61u] = ((uint8_t)((v_length_in_bits >> 16u))); + v_buf_data[62u] = ((uint8_t)((v_length_in_bits >> 8u))); + v_buf_data[63u] = ((uint8_t)(v_length_in_bits)); + } + v_w[0u] = ((((uint32_t)(v_buf_data[0u])) << 24u) | + (((uint32_t)(v_buf_data[1u])) << 16u) | + (((uint32_t)(v_buf_data[2u])) << 8u) | + ((uint32_t)(v_buf_data[3u]))); + v_w[1u] = ((((uint32_t)(v_buf_data[4u])) << 24u) | + (((uint32_t)(v_buf_data[5u])) << 16u) | + (((uint32_t)(v_buf_data[6u])) << 8u) | + ((uint32_t)(v_buf_data[7u]))); + v_w[2u] = ((((uint32_t)(v_buf_data[8u])) << 24u) | + (((uint32_t)(v_buf_data[9u])) << 16u) | + (((uint32_t)(v_buf_data[10u])) << 8u) | + ((uint32_t)(v_buf_data[11u]))); + v_w[3u] = ((((uint32_t)(v_buf_data[12u])) << 24u) | + (((uint32_t)(v_buf_data[13u])) << 16u) | + (((uint32_t)(v_buf_data[14u])) << 8u) | + ((uint32_t)(v_buf_data[15u]))); + v_w[4u] = ((((uint32_t)(v_buf_data[16u])) << 24u) | + (((uint32_t)(v_buf_data[17u])) << 16u) | + (((uint32_t)(v_buf_data[18u])) << 8u) | + ((uint32_t)(v_buf_data[19u]))); + v_w[5u] = ((((uint32_t)(v_buf_data[20u])) << 24u) | + (((uint32_t)(v_buf_data[21u])) << 16u) | + (((uint32_t)(v_buf_data[22u])) << 8u) | + ((uint32_t)(v_buf_data[23u]))); + v_w[6u] = ((((uint32_t)(v_buf_data[24u])) << 24u) | + (((uint32_t)(v_buf_data[25u])) << 16u) | + (((uint32_t)(v_buf_data[26u])) << 8u) | + ((uint32_t)(v_buf_data[27u]))); + v_w[7u] = ((((uint32_t)(v_buf_data[28u])) << 24u) | + (((uint32_t)(v_buf_data[29u])) << 16u) | + (((uint32_t)(v_buf_data[30u])) << 8u) | + ((uint32_t)(v_buf_data[31u]))); + v_w[8u] = ((((uint32_t)(v_buf_data[32u])) << 24u) | + (((uint32_t)(v_buf_data[33u])) << 16u) | + (((uint32_t)(v_buf_data[34u])) << 8u) | + ((uint32_t)(v_buf_data[35u]))); + v_w[9u] = ((((uint32_t)(v_buf_data[36u])) << 24u) | + (((uint32_t)(v_buf_data[37u])) << 16u) | + (((uint32_t)(v_buf_data[38u])) << 8u) | + ((uint32_t)(v_buf_data[39u]))); + v_w[10u] = ((((uint32_t)(v_buf_data[40u])) << 24u) | + (((uint32_t)(v_buf_data[41u])) << 16u) | + (((uint32_t)(v_buf_data[42u])) << 8u) | + ((uint32_t)(v_buf_data[43u]))); + v_w[11u] = ((((uint32_t)(v_buf_data[44u])) << 24u) | + (((uint32_t)(v_buf_data[45u])) << 16u) | + (((uint32_t)(v_buf_data[46u])) << 8u) | + ((uint32_t)(v_buf_data[47u]))); + v_w[12u] = ((((uint32_t)(v_buf_data[48u])) << 24u) | + (((uint32_t)(v_buf_data[49u])) << 16u) | + (((uint32_t)(v_buf_data[50u])) << 8u) | + ((uint32_t)(v_buf_data[51u]))); + v_w[13u] = ((((uint32_t)(v_buf_data[52u])) << 24u) | + (((uint32_t)(v_buf_data[53u])) << 16u) | + (((uint32_t)(v_buf_data[54u])) << 8u) | + ((uint32_t)(v_buf_data[55u]))); + v_w[14u] = ((((uint32_t)(v_buf_data[56u])) << 24u) | + (((uint32_t)(v_buf_data[57u])) << 16u) | + (((uint32_t)(v_buf_data[58u])) << 8u) | + ((uint32_t)(v_buf_data[59u]))); + v_w[15u] = ((((uint32_t)(v_buf_data[60u])) << 24u) | + (((uint32_t)(v_buf_data[61u])) << 16u) | + (((uint32_t)(v_buf_data[62u])) << 8u) | + ((uint32_t)(v_buf_data[63u]))); + v_i = 16u; + while (v_i < 64u) { + v_w2 = v_w[(v_i - 2u)]; + v_s1 = ((v_w2 >> 10u) ^ (((uint32_t)(v_w2 << 15u)) | (v_w2 >> 17u)) ^ (((uint32_t)(v_w2 << 13u)) | (v_w2 >> 19u))); + v_w15 = v_w[(v_i - 15u)]; + v_s0 = ((v_w15 >> 3u) ^ (((uint32_t)(v_w15 << 25u)) | (v_w15 >> 7u)) ^ (((uint32_t)(v_w15 << 14u)) | (v_w15 >> 18u))); + v_w[v_i] = ((uint32_t)(((uint32_t)(((uint32_t)(v_s1 + v_w[(v_i - 7u)])) + v_s0)) + v_w[(v_i - 16u)])); + v_i += 1u; + } + v_i = 0u; + while (v_i < 64u) { + v_t1 = v_h; + v_t1 += ((((uint32_t)(v_e << 26u)) | (v_e >> 6u)) ^ (((uint32_t)(v_e << 21u)) | (v_e >> 11u)) ^ (((uint32_t)(v_e << 7u)) | (v_e >> 25u))); + v_t1 += ((v_e & v_f) ^ ((4294967295u ^ v_e) & v_g)); + v_t1 += WUFFS_SHA256__K[v_i]; + v_t1 += v_w[v_i]; + v_t2 = ((((uint32_t)(v_a << 30u)) | (v_a >> 2u)) ^ (((uint32_t)(v_a << 19u)) | (v_a >> 13u)) ^ (((uint32_t)(v_a << 10u)) | (v_a >> 22u))); + v_t2 += ((v_a & v_b) ^ (v_a & v_c) ^ (v_b & v_c)); + v_h = v_g; + v_g = v_f; + v_f = v_e; + v_e = ((uint32_t)(v_d + v_t1)); + v_d = v_c; + v_c = v_b; + v_b = v_a; + v_a = ((uint32_t)(v_t1 + v_t2)); + v_i += 1u; + } + v_a += v_h0; + v_b += v_h1; + v_c += v_h2; + v_d += v_h3; + v_e += v_h4; + v_f += v_h5; + v_g += v_h6; + v_h += v_h7; + if (v_final_block) { + break; + } + v_final_block = true; + v_h0 = v_a; + v_h1 = v_b; + v_h2 = v_c; + v_h3 = v_d; + v_h4 = v_e; + v_h5 = v_f; + v_h6 = v_g; + v_h7 = v_h; + v_buf_len = 0u; + while (v_buf_len < 56u) { + v_buf_data[v_buf_len] = 0u; + v_buf_len += 1u; + } + } + return wuffs_base__utility__make_bitvec256( + (((uint64_t)(v_h)) | (((uint64_t)(v_g)) << 32u)), + (((uint64_t)(v_f)) | (((uint64_t)(v_e)) << 32u)), + (((uint64_t)(v_d)) | (((uint64_t)(v_c)) << 32u)), + (((uint64_t)(v_b)) | (((uint64_t)(v_a)) << 32u))); } -#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__PNG) +#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__SHA256) -#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__QOI) +#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TARGA) // ---------------- Status Codes Implementations -const char wuffs_qoi__error__bad_footer[] = "#qoi: bad footer"; -const char wuffs_qoi__error__bad_header[] = "#qoi: bad header"; -const char wuffs_qoi__error__truncated_input[] = "#qoi: truncated input"; +const char wuffs_targa__error__bad_header[] = "#targa: bad header"; +const char wuffs_targa__error__bad_run_length_encoding[] = "#targa: bad run length encoding"; +const char wuffs_targa__error__truncated_input[] = "#targa: truncated input"; +const char wuffs_targa__error__unsupported_targa_file[] = "#targa: unsupported TARGA file"; // ---------------- Private Consts @@ -67198,83 +72740,71 @@ const char wuffs_qoi__error__truncated_input[] = "#qoi: truncated input"; WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_qoi__decoder__do_decode_image_config( - wuffs_qoi__decoder* self, +wuffs_targa__decoder__do_decode_image_config( + wuffs_targa__decoder* self, wuffs_base__image_config* a_dst, wuffs_base__io_buffer* a_src); WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_qoi__decoder__do_decode_frame_config( - wuffs_qoi__decoder* self, +wuffs_targa__decoder__do_decode_frame_config( + wuffs_targa__decoder* self, wuffs_base__frame_config* a_dst, wuffs_base__io_buffer* a_src); WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_qoi__decoder__do_decode_frame( - wuffs_qoi__decoder* self, +wuffs_targa__decoder__do_decode_frame( + wuffs_targa__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_qoi__decoder__from_src_to_buffer( - wuffs_qoi__decoder* self, - wuffs_base__io_buffer* a_src); - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_qoi__decoder__from_buffer_to_dst( - wuffs_qoi__decoder* self, - wuffs_base__pixel_buffer* a_dst); - // ---------------- VTables const wuffs_base__image_decoder__func_ptrs -wuffs_qoi__decoder__func_ptrs_for__wuffs_base__image_decoder = { +wuffs_targa__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_qoi__decoder__decode_frame), + wuffs_base__decode_frame_options*))(&wuffs_targa__decoder__decode_frame), (wuffs_base__status(*)(void*, wuffs_base__frame_config*, - wuffs_base__io_buffer*))(&wuffs_qoi__decoder__decode_frame_config), + wuffs_base__io_buffer*))(&wuffs_targa__decoder__decode_frame_config), (wuffs_base__status(*)(void*, wuffs_base__image_config*, - wuffs_base__io_buffer*))(&wuffs_qoi__decoder__decode_image_config), - (wuffs_base__rect_ie_u32(*)(const void*))(&wuffs_qoi__decoder__frame_dirty_rect), + wuffs_base__io_buffer*))(&wuffs_targa__decoder__decode_image_config), + (wuffs_base__rect_ie_u32(*)(const void*))(&wuffs_targa__decoder__frame_dirty_rect), (uint64_t(*)(const void*, - uint32_t))(&wuffs_qoi__decoder__get_quirk), - (uint32_t(*)(const void*))(&wuffs_qoi__decoder__num_animation_loops), - (uint64_t(*)(const void*))(&wuffs_qoi__decoder__num_decoded_frame_configs), - (uint64_t(*)(const void*))(&wuffs_qoi__decoder__num_decoded_frames), + uint32_t))(&wuffs_targa__decoder__get_quirk), + (uint32_t(*)(const void*))(&wuffs_targa__decoder__num_animation_loops), + (uint64_t(*)(const void*))(&wuffs_targa__decoder__num_decoded_frame_configs), + (uint64_t(*)(const void*))(&wuffs_targa__decoder__num_decoded_frames), (wuffs_base__status(*)(void*, uint64_t, - uint64_t))(&wuffs_qoi__decoder__restart_frame), + uint64_t))(&wuffs_targa__decoder__restart_frame), (wuffs_base__status(*)(void*, uint32_t, - uint64_t))(&wuffs_qoi__decoder__set_quirk), + uint64_t))(&wuffs_targa__decoder__set_quirk), (wuffs_base__empty_struct(*)(void*, uint32_t, - bool))(&wuffs_qoi__decoder__set_report_metadata), + bool))(&wuffs_targa__decoder__set_report_metadata), (wuffs_base__status(*)(void*, wuffs_base__io_buffer*, wuffs_base__more_information*, - wuffs_base__io_buffer*))(&wuffs_qoi__decoder__tell_me_more), - (wuffs_base__range_ii_u64(*)(const void*))(&wuffs_qoi__decoder__workbuf_len), + wuffs_base__io_buffer*))(&wuffs_targa__decoder__tell_me_more), + (wuffs_base__range_ii_u64(*)(const void*))(&wuffs_targa__decoder__workbuf_len), }; // ---------------- Initializer Implementations wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT -wuffs_qoi__decoder__initialize( - wuffs_qoi__decoder* self, +wuffs_targa__decoder__initialize( + wuffs_targa__decoder* self, size_t sizeof_star_self, uint64_t wuffs_version, uint32_t options){ @@ -67293,352 +72823,100 @@ wuffs_qoi__decoder__initialize( // 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_qoi__decoder__func_ptrs_for__wuffs_base__image_decoder); - return wuffs_base__make_status(NULL); -} - -wuffs_qoi__decoder* -wuffs_qoi__decoder__alloc(void) { - wuffs_qoi__decoder* x = - (wuffs_qoi__decoder*)(calloc(1, sizeof(wuffs_qoi__decoder))); - if (!x) { - return NULL; - } - if (wuffs_qoi__decoder__initialize( - x, sizeof(wuffs_qoi__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) { - free(x); - return NULL; - } - return x; -} - -size_t -sizeof__wuffs_qoi__decoder(void) { - return sizeof(wuffs_qoi__decoder); -} - -// ---------------- Function Implementations - -// -------- func qoi.decoder.get_quirk - -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC uint64_t -wuffs_qoi__decoder__get_quirk( - const wuffs_qoi__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 qoi.decoder.set_quirk - -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_qoi__decoder__set_quirk( - wuffs_qoi__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 qoi.decoder.decode_image_config - -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_qoi__decoder__decode_image_config( - wuffs_qoi__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_qoi__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_qoi__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 qoi.decoder.do_decode_image_config - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_qoi__decoder__do_decode_image_config( - wuffs_qoi__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_a = 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 >= 4)) { - t_0 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src); - iop_a_src += 4; - } 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 == 24) { - t_0 = ((uint32_t)(*scratch)); - break; - } - num_bits_0 += 8u; - *scratch |= ((uint64_t)(num_bits_0)) << 56; - } - } - v_a = t_0; - } - if (v_a != 1718185841u) { - status = wuffs_base__make_status(wuffs_qoi__error__bad_header); - goto exit; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - uint32_t t_1; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_1 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_do_decode_image_config.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); - 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_1 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1); - if (num_bits_1 == 24) { - t_1 = ((uint32_t)(*scratch >> 32)); - break; - } - num_bits_1 += 8u; - *scratch |= ((uint64_t)(num_bits_1)); - } - } - v_a = t_1; - } - if (v_a > 16777215u) { - status = wuffs_base__make_status(wuffs_base__error__unsupported_image_dimension); - goto exit; - } - self->private_impl.f_width = v_a; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); - uint32_t t_2; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_2 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_do_decode_image_config.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); - 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_2 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_2); - if (num_bits_2 == 24) { - t_2 = ((uint32_t)(*scratch >> 32)); - break; - } - num_bits_2 += 8u; - *scratch |= ((uint64_t)(num_bits_2)); - } - } - v_a = t_2; - } - if (v_a > 16777215u) { - status = wuffs_base__make_status(wuffs_base__error__unsupported_image_dimension); - goto exit; - } - self->private_impl.f_height = v_a; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint32_t t_3 = *iop_a_src++; - v_a = t_3; - } - if (v_a == 3u) { - self->private_impl.f_pixfmt = 2415954056u; - } else if (v_a == 4u) { - self->private_impl.f_pixfmt = 2164295816u; - } else { - status = wuffs_base__make_status(wuffs_qoi__error__bad_header); - goto exit; - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - iop_a_src++; - 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, - 14u, - (self->private_impl.f_pixfmt == 2415954056u)); +#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); } - self->private_impl.f_call_sequence = 32u; +#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)); + } + } - goto ok; - ok: - self->private_impl.p_do_decode_image_config = 0; - goto exit; + 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_targa__decoder__func_ptrs_for__wuffs_base__image_decoder); + return wuffs_base__make_status(NULL); +} + +wuffs_targa__decoder* +wuffs_targa__decoder__alloc(void) { + wuffs_targa__decoder* x = + (wuffs_targa__decoder*)(calloc(1, sizeof(wuffs_targa__decoder))); + if (!x) { + return NULL; + } + if (wuffs_targa__decoder__initialize( + x, sizeof(wuffs_targa__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) { + free(x); + return NULL; } + return x; +} - goto suspend; - suspend: - self->private_impl.p_do_decode_image_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; +size_t +sizeof__wuffs_targa__decoder(void) { + return sizeof(wuffs_targa__decoder); +} - goto exit; - exit: - if (a_src && a_src->data.ptr) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); +// ---------------- Function Implementations + +// -------- func targa.decoder.get_quirk + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC uint64_t +wuffs_targa__decoder__get_quirk( + const wuffs_targa__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 status; + return 0u; } -// -------- func qoi.decoder.decode_frame_config +// -------- func targa.decoder.set_quirk WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_qoi__decoder__decode_frame_config( - wuffs_qoi__decoder* self, - wuffs_base__frame_config* a_dst, +wuffs_targa__decoder__set_quirk( + wuffs_targa__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 targa.decoder.decode_image_config + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_targa__decoder__decode_image_config( + wuffs_targa__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); @@ -67654,7 +72932,7 @@ wuffs_qoi__decoder__decode_frame_config( 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.active_coroutine != 1)) { self->private_impl.magic = WUFFS_BASE__DISABLED; return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls); } @@ -67663,17 +72941,17 @@ wuffs_qoi__decoder__decode_frame_config( wuffs_base__status v_status = wuffs_base__make_status(NULL); - uint32_t coro_susp_point = self->private_impl.p_decode_frame_config; + 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_qoi__decoder__do_decode_frame_config(self, a_dst, a_src); + wuffs_base__status t_0 = wuffs_targa__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_qoi__error__truncated_input); + status = wuffs_base__make_status(wuffs_targa__error__truncated_input); goto exit; } status = v_status; @@ -67681,14 +72959,14 @@ wuffs_qoi__decoder__decode_frame_config( } ok: - self->private_impl.p_decode_frame_config = 0; + self->private_impl.p_decode_image_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; + 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: @@ -67698,16 +72976,20 @@ wuffs_qoi__decoder__decode_frame_config( return status; } -// -------- func qoi.decoder.do_decode_frame_config +// -------- func targa.decoder.do_decode_image_config WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_qoi__decoder__do_decode_frame_config( - wuffs_qoi__decoder* self, - wuffs_base__frame_config* a_dst, +wuffs_targa__decoder__do_decode_image_config( + wuffs_targa__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; + uint32_t v_c5 = 0; + uint32_t v_i = 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; @@ -67719,62 +73001,424 @@ wuffs_qoi__decoder__do_decode_frame_config( io2_a_src = io0_a_src + a_src->meta.wi; } - uint32_t coro_susp_point = self->private_impl.p_do_decode_frame_config; + uint32_t coro_susp_point = self->private_impl.p_do_decode_image_config; + if (coro_susp_point) { + v_i = self->private_data.s_do_decode_image_config.v_i; + } 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)); - } + 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); - status = wuffs_qoi__decoder__do_decode_image_config(self, NULL, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } - if (status.repr) { + uint8_t t_0 = *iop_a_src++; + self->private_impl.f_header_id_length = t_0; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); goto suspend; } - } else if (self->private_impl.f_call_sequence == 40u) { - if (16u != 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); + uint8_t t_1 = *iop_a_src++; + self->private_impl.f_header_color_map_type = t_1; + } + if (self->private_impl.f_header_color_map_type > 1u) { + status = wuffs_base__make_status(wuffs_targa__error__bad_header); + goto exit; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_2 = *iop_a_src++; + self->private_impl.f_header_image_type = t_2; + } + if ((self->private_impl.f_header_image_type == 1u) || + (self->private_impl.f_header_image_type == 2u) || + (self->private_impl.f_header_image_type == 3u) || + (self->private_impl.f_header_image_type == 9u) || + (self->private_impl.f_header_image_type == 10u) || + (self->private_impl.f_header_image_type == 11u)) { + } else { + status = wuffs_base__make_status(wuffs_targa__error__bad_header); + goto exit; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + uint16_t t_3; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { + t_3 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src); + iop_a_src += 2; + } else { + self->private_data.s_do_decode_image_config.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); + 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_3 = ((uint32_t)(*scratch >> 56)); + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_3; + if (num_bits_3 == 8) { + t_3 = ((uint16_t)(*scratch)); + break; + } + num_bits_3 += 8u; + *scratch |= ((uint64_t)(num_bits_3)) << 56; + } + } + self->private_impl.f_header_color_map_first_entry_index = t_3; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); + uint16_t t_4; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { + t_4 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src); + iop_a_src += 2; + } else { + self->private_data.s_do_decode_image_config.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); + 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_4 = ((uint32_t)(*scratch >> 56)); + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_4; + if (num_bits_4 == 8) { + t_4 = ((uint16_t)(*scratch)); + break; + } + num_bits_4 += 8u; + *scratch |= ((uint64_t)(num_bits_4)) << 56; + } + } + self->private_impl.f_header_color_map_length = t_4; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_5 = *iop_a_src++; + self->private_impl.f_header_color_map_entry_size = t_5; + } + if (self->private_impl.f_header_color_map_type != 0u) { + if ((self->private_impl.f_header_color_map_first_entry_index != 0u) || (self->private_impl.f_header_color_map_length > 256u)) { + status = wuffs_base__make_status(wuffs_targa__error__unsupported_targa_file); + goto exit; + } else if ((self->private_impl.f_header_color_map_entry_size != 15u) && + (self->private_impl.f_header_color_map_entry_size != 16u) && + (self->private_impl.f_header_color_map_entry_size != 24u) && + (self->private_impl.f_header_color_map_entry_size != 32u)) { + status = wuffs_base__make_status(wuffs_targa__error__bad_header); 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 ((self->private_impl.f_header_color_map_first_entry_index != 0u) || (self->private_impl.f_header_color_map_length != 0u) || (self->private_impl.f_header_color_map_entry_size != 0u)) { + status = wuffs_base__make_status(wuffs_targa__error__bad_header); + goto exit; + } + } + self->private_data.s_do_decode_image_config.scratch = 4u; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); + if (self->private_data.s_do_decode_image_config.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { + self->private_data.s_do_decode_image_config.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); + iop_a_src = io2_a_src; + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + iop_a_src += self->private_data.s_do_decode_image_config.scratch; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10); + uint32_t t_6; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { + t_6 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src))); + iop_a_src += 2; + } else { + self->private_data.s_do_decode_image_config.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11); + 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_6 = ((uint32_t)(*scratch >> 56)); + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_6; + if (num_bits_6 == 8) { + t_6 = ((uint32_t)(*scratch)); + break; + } + num_bits_6 += 8u; + *scratch |= ((uint64_t)(num_bits_6)) << 56; + } + } + self->private_impl.f_width = t_6; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12); + uint32_t t_7; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { + t_7 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src))); + iop_a_src += 2; + } else { + self->private_data.s_do_decode_image_config.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13); + 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_7 = ((uint32_t)(*scratch >> 56)); + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_7; + if (num_bits_7 == 8) { + t_7 = ((uint32_t)(*scratch)); + break; + } + num_bits_7 += 8u; + *scratch |= ((uint64_t)(num_bits_7)) << 56; + } + } + self->private_impl.f_height = t_7; + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(14); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_8 = *iop_a_src++; + self->private_impl.f_header_pixel_depth = t_8; + } + if ((self->private_impl.f_header_pixel_depth != 1u) && + (self->private_impl.f_header_pixel_depth != 8u) && + (self->private_impl.f_header_pixel_depth != 15u) && + (self->private_impl.f_header_pixel_depth != 16u) && + (self->private_impl.f_header_pixel_depth != 24u) && + (self->private_impl.f_header_pixel_depth != 32u)) { + status = wuffs_base__make_status(wuffs_targa__error__bad_header); + goto exit; + } + if (((uint8_t)(self->private_impl.f_header_image_type | 8u)) == 9u) { + self->private_impl.f_scratch_bytes_per_pixel = 1u; + self->private_impl.f_src_bytes_per_pixel = 1u; + self->private_impl.f_src_pixfmt = 2164523016u; + self->private_impl.f_opaque = ((self->private_impl.f_header_color_map_entry_size == 15u) || (self->private_impl.f_header_color_map_entry_size == 24u)); + } else if (((uint8_t)(self->private_impl.f_header_image_type | 8u)) == 10u) { + if ((self->private_impl.f_header_pixel_depth == 15u) || (self->private_impl.f_header_pixel_depth == 16u)) { + self->private_impl.f_scratch_bytes_per_pixel = 4u; + self->private_impl.f_src_bytes_per_pixel = 0u; + self->private_impl.f_src_pixfmt = 2164295816u; + } else if (self->private_impl.f_header_pixel_depth == 24u) { + self->private_impl.f_scratch_bytes_per_pixel = 3u; + self->private_impl.f_src_bytes_per_pixel = 3u; + self->private_impl.f_src_pixfmt = 2147485832u; + self->private_impl.f_opaque = true; + } else if (self->private_impl.f_header_pixel_depth == 32u) { + self->private_impl.f_scratch_bytes_per_pixel = 4u; + self->private_impl.f_src_bytes_per_pixel = 4u; + self->private_impl.f_src_pixfmt = 2164295816u; + } else { + status = wuffs_base__make_status(wuffs_targa__error__unsupported_targa_file); + goto exit; + } + } else { + if (self->private_impl.f_header_pixel_depth == 8u) { + self->private_impl.f_scratch_bytes_per_pixel = 1u; + self->private_impl.f_src_bytes_per_pixel = 1u; + self->private_impl.f_src_pixfmt = 536870920u; + self->private_impl.f_opaque = true; + } else { + status = wuffs_base__make_status(wuffs_targa__error__unsupported_targa_file); + goto exit; + } + } + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_9 = *iop_a_src++; + self->private_impl.f_header_image_descriptor = t_9; + } + if (((uint8_t)(self->private_impl.f_header_image_descriptor & 16u)) != 0u) { + status = wuffs_base__make_status(wuffs_targa__error__unsupported_targa_file); + goto exit; + } + self->private_data.s_do_decode_image_config.scratch = ((uint32_t)(self->private_impl.f_header_id_length)); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16); + if (self->private_data.s_do_decode_image_config.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { + self->private_data.s_do_decode_image_config.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); + iop_a_src = io2_a_src; + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + iop_a_src += self->private_data.s_do_decode_image_config.scratch; + if (self->private_impl.f_header_color_map_type != 0u) { + while (v_i < ((uint32_t)(self->private_impl.f_header_color_map_length))) { + if (self->private_impl.f_header_color_map_entry_size == 24u) { + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(17); + uint32_t t_10; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 3)) { + t_10 = ((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(18); + 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_10 = ((uint32_t)(*scratch >> 56)); + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_10; + if (num_bits_10 == 16) { + t_10 = ((uint32_t)(*scratch)); + break; + } + num_bits_10 += 8u; + *scratch |= ((uint64_t)(num_bits_10)) << 56; + } + } + v_c32 = t_10; + } + self->private_data.f_src_palette[(((v_i & 255u) * 4u) + 0u)] = ((uint8_t)((v_c32 >> 0u))); + self->private_data.f_src_palette[(((v_i & 255u) * 4u) + 1u)] = ((uint8_t)((v_c32 >> 8u))); + self->private_data.f_src_palette[(((v_i & 255u) * 4u) + 2u)] = ((uint8_t)((v_c32 >> 16u))); + self->private_data.f_src_palette[(((v_i & 255u) * 4u) + 3u)] = 255u; + } else if (self->private_impl.f_header_color_map_entry_size == 32u) { + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(19); + uint32_t t_11; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { + t_11 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src); + iop_a_src += 4; + } else { + self->private_data.s_do_decode_image_config.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(20); + 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_11 = ((uint32_t)(*scratch >> 56)); + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_11; + if (num_bits_11 == 24) { + t_11 = ((uint32_t)(*scratch)); + break; + } + num_bits_11 += 8u; + *scratch |= ((uint64_t)(num_bits_11)) << 56; + } + } + v_c32 = t_11; + } + self->private_data.f_src_palette[(((v_i & 255u) * 4u) + 0u)] = ((uint8_t)((v_c32 >> 0u))); + self->private_data.f_src_palette[(((v_i & 255u) * 4u) + 1u)] = ((uint8_t)((v_c32 >> 8u))); + self->private_data.f_src_palette[(((v_i & 255u) * 4u) + 2u)] = ((uint8_t)((v_c32 >> 16u))); + self->private_data.f_src_palette[(((v_i & 255u) * 4u) + 3u)] = ((uint8_t)((v_c32 >> 24u))); + } else { + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(21); + uint32_t t_12; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { + t_12 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src))); + iop_a_src += 2; + } else { + self->private_data.s_do_decode_image_config.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(22); + 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_12 = ((uint32_t)(*scratch >> 56)); + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_12; + if (num_bits_12 == 8) { + t_12 = ((uint32_t)(*scratch)); + break; + } + num_bits_12 += 8u; + *scratch |= ((uint64_t)(num_bits_12)) << 56; + } + } + v_c32 = t_12; + } + v_c5 = (31u & (v_c32 >> 0u)); + self->private_data.f_src_palette[(((v_i & 255u) * 4u) + 0u)] = ((uint8_t)(((v_c5 << 3u) | (v_c5 >> 2u)))); + v_c5 = (31u & (v_c32 >> 5u)); + self->private_data.f_src_palette[(((v_i & 255u) * 4u) + 1u)] = ((uint8_t)(((v_c5 << 3u) | (v_c5 >> 2u)))); + v_c5 = (31u & (v_c32 >> 10u)); + self->private_data.f_src_palette[(((v_i & 255u) * 4u) + 2u)] = ((uint8_t)(((v_c5 << 3u) | (v_c5 >> 2u)))); + self->private_data.f_src_palette[(((v_i & 255u) * 4u) + 3u)] = 255u; + } + v_i += 1u; + } + while (v_i < 256u) { + self->private_data.f_src_palette[((v_i * 4u) + 0u)] = 0u; + self->private_data.f_src_palette[((v_i * 4u) + 1u)] = 0u; + self->private_data.f_src_palette[((v_i * 4u) + 2u)] = 0u; + self->private_data.f_src_palette[((v_i * 4u) + 3u)] = 255u; + v_i += 1u; + } } + self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))); if (a_dst != NULL) { - wuffs_base__frame_config__set( + wuffs_base__image_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, - 14u, - 0u, - (self->private_impl.f_pixfmt == 2415954056u), - false, - 0u); + self->private_impl.f_src_pixfmt, + 0u, + self->private_impl.f_width, + self->private_impl.f_height, + self->private_impl.f_frame_config_io_position, + self->private_impl.f_opaque); } - self->private_impl.f_call_sequence = 64u; + self->private_impl.f_call_sequence = 32u; + goto ok; ok: - self->private_impl.p_do_decode_frame_config = 0; + self->private_impl.p_do_decode_image_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; + self->private_impl.p_do_decode_image_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_data.s_do_decode_image_config.v_i = v_i; goto exit; exit: @@ -67785,17 +73429,14 @@ wuffs_qoi__decoder__do_decode_frame_config( return status; } -// -------- func qoi.decoder.decode_frame +// -------- func targa.decoder.decode_frame_config WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_qoi__decoder__decode_frame( - wuffs_qoi__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_targa__decoder__decode_frame_config( + wuffs_targa__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); } @@ -67805,12 +73446,12 @@ wuffs_qoi__decoder__decode_frame( ? wuffs_base__error__disabled_by_previous_error : wuffs_base__error__initialize_not_called); } - if (!a_dst || !a_src) { + 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 != 3)) { + (self->private_impl.active_coroutine != 2)) { self->private_impl.magic = WUFFS_BASE__DISABLED; return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls); } @@ -67819,22 +73460,17 @@ wuffs_qoi__decoder__decode_frame( wuffs_base__status v_status = wuffs_base__make_status(NULL); - uint32_t coro_susp_point = self->private_impl.p_decode_frame; + 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_qoi__decoder__do_decode_frame(self, - a_dst, - a_src, - a_blend, - a_workbuf, - a_opts); + wuffs_base__status t_0 = wuffs_targa__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_qoi__error__truncated_input); + status = wuffs_base__make_status(wuffs_targa__error__truncated_input); goto exit; } status = v_status; @@ -67842,14 +73478,14 @@ wuffs_qoi__decoder__decode_frame( } ok: - self->private_impl.p_decode_frame = 0; + self->private_impl.p_decode_frame_config = 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; + 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: @@ -67859,22 +73495,16 @@ wuffs_qoi__decoder__decode_frame( return status; } -// -------- func qoi.decoder.do_decode_frame +// -------- func targa.decoder.do_decode_frame_config WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_qoi__decoder__do_decode_frame( - wuffs_qoi__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_targa__decoder__do_decode_frame_config( + wuffs_targa__decoder* self, + wuffs_base__frame_config* a_dst, + wuffs_base__io_buffer* a_src) { wuffs_base__status status = wuffs_base__make_status(NULL); - wuffs_base__status v_status = wuffs_base__make_status(NULL); - uint64_t v_c64 = 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; @@ -67886,525 +73516,83 @@ wuffs_qoi__decoder__do_decode_frame( io2_a_src = io0_a_src + a_src->meta.wi; } - uint32_t coro_susp_point = self->private_impl.p_do_decode_frame; + 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 == 64u) { - } else if (self->private_impl.f_call_sequence < 64u) { + 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_qoi__decoder__do_decode_frame_config(self, NULL, a_src); + status = wuffs_targa__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 { - 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); + } else if (self->private_impl.f_call_sequence == 40u) { + if (self->private_impl.f_frame_config_io_position != 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; - } - self->private_impl.f_dst_x = 0u; - self->private_impl.f_dst_y = 0u; - self->private_data.f_pixel[0u] = 0u; - self->private_data.f_pixel[1u] = 0u; - self->private_data.f_pixel[2u] = 0u; - self->private_data.f_pixel[3u] = 255u; - wuffs_private_impl__bulk_memset(&self->private_data.f_cache[0], 256u, 0u); - self->private_impl.f_remaining_pixels_times_4 = (((uint64_t)(self->private_impl.f_width)) * ((uint64_t)(self->private_impl.f_height)) * 4u); - while (self->private_impl.f_remaining_pixels_times_4 > 0u) { - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); - status = wuffs_qoi__decoder__from_src_to_buffer(self, a_src); - if (a_src) { - iop_a_src = a_src->data.ptr + a_src->meta.ri; - } - if (status.repr) { - goto suspend; - } - if (self->private_impl.f_remaining_pixels_times_4 < ((uint64_t)(self->private_impl.f_buffer_index))) { - status = wuffs_base__make_status(wuffs_base__error__too_much_data); - goto exit; - } - self->private_impl.f_remaining_pixels_times_4 -= ((uint64_t)(self->private_impl.f_buffer_index)); - v_status = wuffs_qoi__decoder__from_buffer_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; - } - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - uint64_t t_0; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 8)) { - t_0 = wuffs_base__peek_u64be__no_bounds_check(iop_a_src); - iop_a_src += 8; - } else { - self->private_data.s_do_decode_frame.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); - 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_frame.scratch; - uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu)); - *scratch >>= 8; - *scratch <<= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0); - if (num_bits_0 == 56) { - t_0 = ((uint64_t)(*scratch >> 0)); - break; - } - num_bits_0 += 8u; - *scratch |= ((uint64_t)(num_bits_0)); - } - } - v_c64 = t_0; - } - if (v_c64 != 1u) { - status = wuffs_base__make_status(wuffs_qoi__error__bad_footer); - goto exit; - } - 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: - if (a_src && a_src->data.ptr) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - - return status; -} - -// -------- func qoi.decoder.from_src_to_buffer - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_qoi__decoder__from_src_to_buffer( - wuffs_qoi__decoder* self, - wuffs_base__io_buffer* a_src) { - wuffs_base__status status = wuffs_base__make_status(NULL); - - uint8_t v_c8 = 0; - uint8_t v_dg = 0; - uint32_t v_bi = 0; - uint32_t v_bj = 0; - uint32_t v_bk = 0; - uint32_t v_ci = 0; - uint32_t v_hash4 = 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_from_src_to_buffer; - if (coro_susp_point) { - v_dg = self->private_data.s_from_src_to_buffer.v_dg; - v_bi = self->private_data.s_from_src_to_buffer.v_bi; - v_bk = self->private_data.s_from_src_to_buffer.v_bk; - } - switch (coro_susp_point) { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - - v_bk = 7936u; - if (self->private_impl.f_remaining_pixels_times_4 < 7936u) { - v_bk = ((uint32_t)(self->private_impl.f_remaining_pixels_times_4)); - } - while (v_bi < v_bk) { - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_0 = *iop_a_src++; - v_c8 = t_0; - } - if (v_c8 == 254u) { - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_1 = *iop_a_src++; - self->private_data.f_pixel[2u] = t_1; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_2 = *iop_a_src++; - self->private_data.f_pixel[1u] = t_2; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_3 = *iop_a_src++; - self->private_data.f_pixel[0u] = t_3; - } - } else if (v_c8 == 255u) { - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_4 = *iop_a_src++; - self->private_data.f_pixel[2u] = t_4; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_5 = *iop_a_src++; - self->private_data.f_pixel[1u] = t_5; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_6 = *iop_a_src++; - self->private_data.f_pixel[0u] = t_6; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_7 = *iop_a_src++; - self->private_data.f_pixel[3u] = t_7; - } - } else if (((uint8_t)(v_c8 >> 6u)) == 0u) { - v_ci = (4u * ((uint32_t)(((uint8_t)(v_c8 & 63u))))); - self->private_data.f_pixel[0u] = self->private_data.f_cache[(v_ci + 0u)]; - self->private_data.f_pixel[1u] = self->private_data.f_cache[(v_ci + 1u)]; - self->private_data.f_pixel[2u] = self->private_data.f_cache[(v_ci + 2u)]; - self->private_data.f_pixel[3u] = self->private_data.f_cache[(v_ci + 3u)]; - self->private_data.f_buffer[(v_bi + 0u)] = self->private_data.f_pixel[0u]; - self->private_data.f_buffer[(v_bi + 1u)] = self->private_data.f_pixel[1u]; - self->private_data.f_buffer[(v_bi + 2u)] = self->private_data.f_pixel[2u]; - self->private_data.f_buffer[(v_bi + 3u)] = self->private_data.f_pixel[3u]; - v_bi += 4u; - continue; - } else if (((uint8_t)(v_c8 >> 6u)) == 1u) { -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - self->private_data.f_pixel[2u] += ((uint8_t)(((uint8_t)(((uint8_t)(v_c8 >> 4u)) & 3u)) + 254u)); - self->private_data.f_pixel[1u] += ((uint8_t)(((uint8_t)(((uint8_t)(v_c8 >> 2u)) & 3u)) + 254u)); - self->private_data.f_pixel[0u] += ((uint8_t)(((uint8_t)(((uint8_t)(v_c8 >> 0u)) & 3u)) + 254u)); -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - } else if (((uint8_t)(v_c8 >> 6u)) == 2u) { - v_dg = ((uint8_t)(((uint8_t)(v_c8 & 63u)) + 224u)); - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_8 = *iop_a_src++; - v_c8 = t_8; - } -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - self->private_data.f_pixel[2u] += ((uint8_t)(((uint8_t)(v_dg + 248u)) + ((uint8_t)(15u & ((uint8_t)(v_c8 >> 4u)))))); - self->private_data.f_pixel[1u] += v_dg; - self->private_data.f_pixel[0u] += ((uint8_t)(((uint8_t)(v_dg + 248u)) + ((uint8_t)(15u & ((uint8_t)(v_c8 >> 0u)))))); -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - } else { - v_bj = (v_bi + (4u * (63u & (1u + ((uint32_t)(v_c8)))))); - while (v_bi < v_bj) { - self->private_data.f_buffer[(v_bi + 0u)] = self->private_data.f_pixel[0u]; - self->private_data.f_buffer[(v_bi + 1u)] = self->private_data.f_pixel[1u]; - self->private_data.f_buffer[(v_bi + 2u)] = self->private_data.f_pixel[2u]; - self->private_data.f_buffer[(v_bi + 3u)] = self->private_data.f_pixel[3u]; - v_bi += 4u; - } - continue; - } - v_hash4 = (4u * (63u & ((((uint32_t)(self->private_data.f_pixel[2u])) * 3u) + - (((uint32_t)(self->private_data.f_pixel[1u])) * 5u) + - (((uint32_t)(self->private_data.f_pixel[0u])) * 7u) + - (((uint32_t)(self->private_data.f_pixel[3u])) * 11u)))); - self->private_data.f_cache[(v_hash4 + 0u)] = self->private_data.f_pixel[0u]; - self->private_data.f_cache[(v_hash4 + 1u)] = self->private_data.f_pixel[1u]; - self->private_data.f_cache[(v_hash4 + 2u)] = self->private_data.f_pixel[2u]; - self->private_data.f_cache[(v_hash4 + 3u)] = self->private_data.f_pixel[3u]; - self->private_data.f_buffer[(v_bi + 0u)] = self->private_data.f_pixel[0u]; - self->private_data.f_buffer[(v_bi + 1u)] = self->private_data.f_pixel[1u]; - self->private_data.f_buffer[(v_bi + 2u)] = self->private_data.f_pixel[2u]; - self->private_data.f_buffer[(v_bi + 3u)] = self->private_data.f_pixel[3u]; - v_bi += 4u; - } - self->private_impl.f_buffer_index = v_bi; - - goto ok; - ok: - self->private_impl.p_from_src_to_buffer = 0; - goto exit; - } - - goto suspend; - suspend: - self->private_impl.p_from_src_to_buffer = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; - self->private_data.s_from_src_to_buffer.v_dg = v_dg; - self->private_data.s_from_src_to_buffer.v_bi = v_bi; - self->private_data.s_from_src_to_buffer.v_bk = v_bk; - - 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 qoi.decoder.from_buffer_to_dst - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_qoi__decoder__from_buffer_to_dst( - wuffs_qoi__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_bi = 0; - uint32_t v_rem_x = 0; - wuffs_base__slice_u8 v_dst = {0}; - wuffs_base__slice_u8 v_src = {0}; - uint32_t v_src_length = 0; - uint64_t v_i = 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_bi < self->private_impl.f_buffer_index) { - if (self->private_impl.f_width <= self->private_impl.f_dst_x) { - self->private_impl.f_dst_x = 0u; - self->private_impl.f_dst_y += 1u; - if (self->private_impl.f_dst_y >= self->private_impl.f_height) { - break; - } - v_rem_x = self->private_impl.f_width; } else { - v_rem_x = (self->private_impl.f_width - self->private_impl.f_dst_x); - } - v_src = wuffs_base__make_slice_u8_ij(self->private_data.f_buffer, v_bi, self->private_impl.f_buffer_index); - if (((uint64_t)((4u * v_rem_x))) < ((uint64_t)(v_src.len))) { - v_src = wuffs_base__slice_u8__subslice_j(v_src, ((uint64_t)((4u * v_rem_x)))); - } - v_src_length = ((uint32_t)(((uint64_t)(v_src.len)))); - v_bi += v_src_length; - v_dst = wuffs_private_impl__table_u8__row_u32(v_tab, self->private_impl.f_dst_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); - } - v_i = (((uint64_t)(self->private_impl.f_dst_x)) * ((uint64_t)(v_dst_bytes_per_pixel))); - self->private_impl.f_dst_x += (v_src_length / 4u); - if (v_i < ((uint64_t)(v_dst.len))) { - wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), wuffs_base__pixel_buffer__palette(a_dst), v_src); + status = wuffs_base__make_status(wuffs_base__note__end_of_data); + goto ok; } - } - return wuffs_base__make_status(NULL); -} - -// -------- func qoi.decoder.frame_dirty_rect - -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32 -wuffs_qoi__decoder__frame_dirty_rect( - const wuffs_qoi__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 qoi.decoder.num_animation_loops - -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC uint32_t -wuffs_qoi__decoder__num_animation_loops( - const wuffs_qoi__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 qoi.decoder.num_decoded_frame_configs - -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC uint64_t -wuffs_qoi__decoder__num_decoded_frame_configs( - const wuffs_qoi__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 qoi.decoder.num_decoded_frames - -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC uint64_t -wuffs_qoi__decoder__num_decoded_frames( - const wuffs_qoi__decoder* self) { - if (!self) { - return 0; - } - if ((self->private_impl.magic != WUFFS_BASE__MAGIC) && - (self->private_impl.magic != WUFFS_BASE__DISABLED)) { - return 0; - } + 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, + self->private_impl.f_frame_config_io_position, + 0u, + self->private_impl.f_opaque, + false, + 4278190080u); + } + self->private_impl.f_call_sequence = 64u; - if (self->private_impl.f_call_sequence > 64u) { - return 1u; + ok: + self->private_impl.p_do_decode_frame_config = 0; + goto exit; } - return 0u; -} -// -------- func qoi.decoder.restart_frame - -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_qoi__decoder__restart_frame( - wuffs_qoi__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); - } + goto suspend; + suspend: + self->private_impl.p_do_decode_frame_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; - 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 != 14u)) { - return wuffs_base__make_status(wuffs_base__error__bad_argument); + goto exit; + exit: + if (a_src && a_src->data.ptr) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); } - self->private_impl.f_call_sequence = 40u; - return wuffs_base__make_status(NULL); -} -// -------- func qoi.decoder.set_report_metadata - -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct -wuffs_qoi__decoder__set_report_metadata( - wuffs_qoi__decoder* self, - uint32_t a_fourcc, - bool a_report) { - return wuffs_base__make_empty_struct(); + return status; } -// -------- func qoi.decoder.tell_me_more +// -------- func targa.decoder.decode_frame WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_qoi__decoder__tell_me_more( - wuffs_qoi__decoder* self, - wuffs_base__io_buffer* a_dst, - wuffs_base__more_information* a_minfo, - wuffs_base__io_buffer* a_src) { +wuffs_targa__decoder__decode_frame( + wuffs_targa__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); } @@ -68419,18 +73607,47 @@ wuffs_qoi__decoder__tell_me_more( 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.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); - status = wuffs_base__make_status(wuffs_base__error__no_more_information); - goto exit; + 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_targa__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_targa__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 ok; - ok: goto exit; exit: if (wuffs_base__status__is_error(&status)) { @@ -68439,152 +73656,358 @@ wuffs_qoi__decoder__tell_me_more( return status; } -// -------- func qoi.decoder.workbuf_len - -WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 -wuffs_qoi__decoder__workbuf_len( - const wuffs_qoi__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__QOI) - -#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__SHA256) - -// ---------------- Status Codes Implementations - -// ---------------- Private Consts - -static const uint32_t -WUFFS_SHA256__INITIAL_SHA256_H[8] WUFFS_BASE__POTENTIALLY_UNUSED = { - 1779033703u, 3144134277u, 1013904242u, 2773480762u, 1359893119u, 2600822924u, 528734635u, 1541459225u, -}; - -static const uint32_t -WUFFS_SHA256__K[64] WUFFS_BASE__POTENTIALLY_UNUSED = { - 1116352408u, 1899447441u, 3049323471u, 3921009573u, 961987163u, 1508970993u, 2453635748u, 2870763221u, - 3624381080u, 310598401u, 607225278u, 1426881987u, 1925078388u, 2162078206u, 2614888103u, 3248222580u, - 3835390401u, 4022224774u, 264347078u, 604807628u, 770255983u, 1249150122u, 1555081692u, 1996064986u, - 2554220882u, 2821834349u, 2952996808u, 3210313671u, 3336571891u, 3584528711u, 113926993u, 338241895u, - 666307205u, 773529912u, 1294757372u, 1396182291u, 1695183700u, 1986661051u, 2177026350u, 2456956037u, - 2730485921u, 2820302411u, 3259730800u, 3345764771u, 3516065817u, 3600352804u, 4094571909u, 275423344u, - 430227734u, 506948616u, 659060556u, 883997877u, 958139571u, 1322822218u, 1537002063u, 1747873779u, - 1955562222u, 2024104815u, 2227730452u, 2361852424u, 2428436474u, 2756734187u, 3204031479u, 3329325298u, -}; - -// ---------------- Private Initializer Prototypes - -// ---------------- Private Function Prototypes +// -------- func targa.decoder.do_decode_frame WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_sha256__hasher__up( - wuffs_sha256__hasher* self, - wuffs_base__slice_u8 a_x); - -// ---------------- VTables - -const wuffs_base__hasher_bitvec256__func_ptrs -wuffs_sha256__hasher__func_ptrs_for__wuffs_base__hasher_bitvec256 = { - (wuffs_base__bitvec256(*)(const void*))(&wuffs_sha256__hasher__checksum_bitvec256), - (uint64_t(*)(const void*, - uint32_t))(&wuffs_sha256__hasher__get_quirk), - (wuffs_base__status(*)(void*, - uint32_t, - uint64_t))(&wuffs_sha256__hasher__set_quirk), - (wuffs_base__empty_struct(*)(void*, - wuffs_base__slice_u8))(&wuffs_sha256__hasher__update), - (wuffs_base__bitvec256(*)(void*, - wuffs_base__slice_u8))(&wuffs_sha256__hasher__update_bitvec256), -}; +static wuffs_base__status +wuffs_targa__decoder__do_decode_frame( + wuffs_targa__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); -// ---------------- Initializer Implementations + wuffs_base__status v_status = wuffs_base__make_status(NULL); + wuffs_base__pixel_format v_dst_pixfmt = {0}; + uint32_t v_dst_bits_per_pixel = 0; + uint64_t v_dst_bytes_per_pixel = 0; + uint32_t v_dst_x = 0; + uint32_t v_dst_y = 0; + wuffs_base__table_u8 v_tab = {0}; + wuffs_base__slice_u8 v_dst_palette = {0}; + wuffs_base__slice_u8 v_dst = {0}; + uint64_t v_dst_start = 0; + wuffs_base__slice_u8 v_src_palette = {0}; + uint64_t v_mark = 0; + uint64_t v_num_pixels64 = 0; + uint32_t v_num_pixels32 = 0; + uint32_t v_lit_length = 0; + uint32_t v_run_length = 0; + uint64_t v_num_dst_bytes = 0; + uint32_t v_num_src_bytes = 0; + uint32_t v_c32 = 0; + uint32_t v_c5 = 0; -wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT -wuffs_sha256__hasher__initialize( - wuffs_sha256__hasher* 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); + 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; } - 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); + + uint32_t coro_susp_point = self->private_impl.p_do_decode_frame; + if (coro_susp_point) { + v_dst_bytes_per_pixel = self->private_data.s_do_decode_frame.v_dst_bytes_per_pixel; + v_dst_x = self->private_data.s_do_decode_frame.v_dst_x; + v_dst_y = self->private_data.s_do_decode_frame.v_dst_y; + v_mark = self->private_data.s_do_decode_frame.v_mark; + v_num_pixels32 = self->private_data.s_do_decode_frame.v_num_pixels32; + v_lit_length = self->private_data.s_do_decode_frame.v_lit_length; + v_run_length = self->private_data.s_do_decode_frame.v_run_length; + v_num_dst_bytes = self->private_data.s_do_decode_frame.v_num_dst_bytes; } + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - 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; + if (self->private_impl.f_call_sequence == 64u) { + } else if (self->private_impl.f_call_sequence < 64u) { + if (a_src) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); + } + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + status = wuffs_targa__decoder__do_decode_frame_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 { - memset(&(self->private_impl), 0, sizeof(self->private_impl)); + status = wuffs_base__make_status(wuffs_base__note__end_of_data); + goto ok; + } + if (self->private_impl.f_header_color_map_type != 0u) { + v_src_palette = wuffs_base__make_slice_u8(self->private_data.f_src_palette, 1024); + } + 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_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024)), + wuffs_base__utility__make_pixel_format(self->private_impl.f_src_pixfmt), + v_src_palette, + 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; + } + 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) { + status = wuffs_base__make_status(wuffs_base__error__unsupported_option); + goto exit; + } + v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8u))); + if (((uint8_t)(self->private_impl.f_header_image_descriptor & 32u)) == 0u) { + v_dst_y = ((uint32_t)(self->private_impl.f_height - 1u)); + } + if (((uint8_t)(self->private_impl.f_header_image_type & 8u)) == 0u) { + v_lit_length = self->private_impl.f_width; + } + label__resume__continue:; + while (true) { + v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0u); + v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024)); + while (v_dst_y < self->private_impl.f_height) { + v_dst = wuffs_private_impl__table_u8__row_u32(v_tab, v_dst_y); + v_dst_start = (((uint64_t)(v_dst_x)) * v_dst_bytes_per_pixel); + if (v_dst_start <= ((uint64_t)(v_dst.len))) { + v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_dst_start); + } else { + v_dst = wuffs_base__utility__empty_slice_u8(); + } + while (v_dst_x < self->private_impl.f_width) { + if (self->private_impl.f_src_bytes_per_pixel > 0u) { + if (v_lit_length > 0u) { + v_mark = ((uint64_t)(iop_a_src - io0_a_src)); + v_num_pixels64 = (((uint64_t)(io2_a_src - iop_a_src)) / ((uint64_t)(self->private_impl.f_src_bytes_per_pixel))); + v_num_pixels32 = ((uint32_t)(wuffs_base__u64__min(v_num_pixels64, ((uint64_t)(v_lit_length))))); + v_num_dst_bytes = (((uint64_t)(v_num_pixels32)) * v_dst_bytes_per_pixel); + v_num_src_bytes = (v_num_pixels32 * self->private_impl.f_src_bytes_per_pixel); + self->private_data.s_do_decode_frame.scratch = v_num_src_bytes; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); + if (self->private_data.s_do_decode_frame.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { + self->private_data.s_do_decode_frame.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); + iop_a_src = io2_a_src; + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + iop_a_src += self->private_data.s_do_decode_frame.scratch; + wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_private_impl__io__since(v_mark, ((uint64_t)(iop_a_src - io0_a_src)), io0_a_src)); + if (v_num_dst_bytes <= ((uint64_t)(v_dst.len))) { + v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_num_dst_bytes); + } else { + v_dst = wuffs_base__utility__empty_slice_u8(); + } + v_dst_x += v_num_pixels32; + v_lit_length = (((uint32_t)(v_lit_length - v_num_pixels32)) & 65535u); + if (v_lit_length > 0u) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3); + goto label__resume__continue; + } + } else if (v_run_length > 0u) { + v_run_length -= 1u; + wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, self->private_impl.f_scratch_bytes_per_pixel)); + if (v_dst_bytes_per_pixel <= ((uint64_t)(v_dst.len))) { + v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_dst_bytes_per_pixel); + } + v_dst_x += 1u; + } else { + if (((uint64_t)(io2_a_src - iop_a_src)) <= 0u) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4); + goto label__resume__continue; + } + if (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) < 128u) { + v_lit_length = (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) + 1u); + iop_a_src += 1u; + if ((v_lit_length + v_dst_x) > self->private_impl.f_width) { + status = wuffs_base__make_status(wuffs_targa__error__bad_run_length_encoding); + goto exit; + } + } else { + if (self->private_impl.f_src_bytes_per_pixel == 1u) { + if (((uint64_t)(io2_a_src - iop_a_src)) < 2u) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5); + goto label__resume__continue; + } + v_run_length = ((((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) & 127u) + 1u); + iop_a_src += 1u; + self->private_data.f_scratch[0u] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); + iop_a_src += 1u; + } else if (self->private_impl.f_src_bytes_per_pixel == 3u) { + if (((uint64_t)(io2_a_src - iop_a_src)) < 4u) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6); + goto label__resume__continue; + } + v_run_length = ((((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) & 127u) + 1u); + iop_a_src += 1u; + self->private_data.f_scratch[0u] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); + iop_a_src += 1u; + self->private_data.f_scratch[1u] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); + iop_a_src += 1u; + self->private_data.f_scratch[2u] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); + iop_a_src += 1u; + } else { + if (((uint64_t)(io2_a_src - iop_a_src)) < 5u) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7); + goto label__resume__continue; + } + v_run_length = ((((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) & 127u) + 1u); + iop_a_src += 1u; + self->private_data.f_scratch[0u] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); + iop_a_src += 1u; + self->private_data.f_scratch[1u] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); + iop_a_src += 1u; + self->private_data.f_scratch[2u] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); + iop_a_src += 1u; + self->private_data.f_scratch[3u] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); + iop_a_src += 1u; + } + if ((v_run_length + v_dst_x) > self->private_impl.f_width) { + status = wuffs_base__make_status(wuffs_targa__error__bad_run_length_encoding); + goto exit; + } + } + } + } else { + if (v_lit_length > 0u) { + if (((uint64_t)(io2_a_src - iop_a_src)) < 2u) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8); + goto label__resume__continue; + } + v_c32 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src))); + iop_a_src += 2u; + v_c5 = (31u & (v_c32 >> 0u)); + self->private_data.f_scratch[0u] = ((uint8_t)(((v_c5 << 3u) | (v_c5 >> 2u)))); + v_c5 = (31u & (v_c32 >> 5u)); + self->private_data.f_scratch[1u] = ((uint8_t)(((v_c5 << 3u) | (v_c5 >> 2u)))); + v_c5 = (31u & (v_c32 >> 10u)); + self->private_data.f_scratch[2u] = ((uint8_t)(((v_c5 << 3u) | (v_c5 >> 2u)))); + self->private_data.f_scratch[3u] = 255u; + wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, 4)); + if (v_dst_bytes_per_pixel <= ((uint64_t)(v_dst.len))) { + v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_dst_bytes_per_pixel); + } + v_dst_x += 1u; + v_lit_length -= 1u; + } else if (v_run_length > 0u) { + v_run_length -= 1u; + wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, self->private_impl.f_scratch_bytes_per_pixel)); + if (v_dst_bytes_per_pixel <= ((uint64_t)(v_dst.len))) { + v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_dst_bytes_per_pixel); + } + v_dst_x += 1u; + } else { + if (((uint64_t)(io2_a_src - iop_a_src)) <= 0u) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9); + goto label__resume__continue; + } + if (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) < 128u) { + v_lit_length = (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) + 1u); + iop_a_src += 1u; + if ((v_lit_length + v_dst_x) > self->private_impl.f_width) { + status = wuffs_base__make_status(wuffs_targa__error__bad_run_length_encoding); + goto exit; + } + } else { + if (((uint64_t)(io2_a_src - iop_a_src)) < 3u) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10); + goto label__resume__continue; + } + v_run_length = ((((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) & 127u) + 1u); + iop_a_src += 1u; + v_c32 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src))); + iop_a_src += 2u; + v_c5 = (31u & (v_c32 >> 0u)); + self->private_data.f_scratch[0u] = ((uint8_t)(((v_c5 << 3u) | (v_c5 >> 2u)))); + v_c5 = (31u & (v_c32 >> 5u)); + self->private_data.f_scratch[1u] = ((uint8_t)(((v_c5 << 3u) | (v_c5 >> 2u)))); + v_c5 = (31u & (v_c32 >> 10u)); + self->private_data.f_scratch[2u] = ((uint8_t)(((v_c5 << 3u) | (v_c5 >> 2u)))); + self->private_data.f_scratch[3u] = 255u; + if ((v_run_length + v_dst_x) > self->private_impl.f_width) { + status = wuffs_base__make_status(wuffs_targa__error__bad_run_length_encoding); + goto exit; + } + } + } + } + } + v_dst_x = 0u; + if (((uint8_t)(self->private_impl.f_header_image_descriptor & 32u)) == 0u) { + v_dst_y -= 1u; + } else { + v_dst_y += 1u; + } + if (((uint8_t)(self->private_impl.f_header_image_type & 8u)) == 0u) { + v_lit_length = self->private_impl.f_width; + } + } + break; } + 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; + self->private_data.s_do_decode_frame.v_dst_bytes_per_pixel = v_dst_bytes_per_pixel; + self->private_data.s_do_decode_frame.v_dst_x = v_dst_x; + self->private_data.s_do_decode_frame.v_dst_y = v_dst_y; + self->private_data.s_do_decode_frame.v_mark = v_mark; + self->private_data.s_do_decode_frame.v_num_pixels32 = v_num_pixels32; + self->private_data.s_do_decode_frame.v_lit_length = v_lit_length; + self->private_data.s_do_decode_frame.v_run_length = v_run_length; + self->private_data.s_do_decode_frame.v_num_dst_bytes = v_num_dst_bytes; + + goto exit; + exit: + if (a_src && a_src->data.ptr) { + a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); } - self->private_impl.magic = WUFFS_BASE__MAGIC; - self->private_impl.vtable_for__wuffs_base__hasher_bitvec256.vtable_name = - wuffs_base__hasher_bitvec256__vtable_name; - self->private_impl.vtable_for__wuffs_base__hasher_bitvec256.function_pointers = - (const void*)(&wuffs_sha256__hasher__func_ptrs_for__wuffs_base__hasher_bitvec256); - return wuffs_base__make_status(NULL); + return status; } -wuffs_sha256__hasher* -wuffs_sha256__hasher__alloc(void) { - wuffs_sha256__hasher* x = - (wuffs_sha256__hasher*)(calloc(1, sizeof(wuffs_sha256__hasher))); - if (!x) { - return NULL; +// -------- func targa.decoder.frame_dirty_rect + +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32 +wuffs_targa__decoder__frame_dirty_rect( + const wuffs_targa__decoder* self) { + if (!self) { + return wuffs_base__utility__empty_rect_ie_u32(); } - if (wuffs_sha256__hasher__initialize( - x, sizeof(wuffs_sha256__hasher), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) { - free(x); - return NULL; + if ((self->private_impl.magic != WUFFS_BASE__MAGIC) && + (self->private_impl.magic != WUFFS_BASE__DISABLED)) { + return wuffs_base__utility__empty_rect_ie_u32(); } - return x; -} -size_t -sizeof__wuffs_sha256__hasher(void) { - return sizeof(wuffs_sha256__hasher); + return wuffs_base__utility__make_rect_ie_u32( + 0u, + 0u, + self->private_impl.f_width, + self->private_impl.f_height); } -// ---------------- Function Implementations - -// -------- func sha256.hasher.get_quirk +// -------- func targa.decoder.num_animation_loops WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC uint64_t -wuffs_sha256__hasher__get_quirk( - const wuffs_sha256__hasher* self, - uint32_t a_key) { +WUFFS_BASE__MAYBE_STATIC uint32_t +wuffs_targa__decoder__num_animation_loops( + const wuffs_targa__decoder* self) { if (!self) { return 0; } @@ -68596,555 +74019,620 @@ wuffs_sha256__hasher__get_quirk( return 0u; } -// -------- func sha256.hasher.set_quirk +// -------- func targa.decoder.num_decoded_frame_configs WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_sha256__hasher__set_quirk( - wuffs_sha256__hasher* self, - uint32_t a_key, - uint64_t a_value) { +WUFFS_BASE__MAYBE_STATIC uint64_t +wuffs_targa__decoder__num_decoded_frame_configs( + const wuffs_targa__decoder* self) { if (!self) { - return wuffs_base__make_status(wuffs_base__error__bad_receiver); + return 0; } - 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.magic != WUFFS_BASE__MAGIC) && + (self->private_impl.magic != WUFFS_BASE__DISABLED)) { + return 0; } - return wuffs_base__make_status(wuffs_base__error__unsupported_option); + if (self->private_impl.f_call_sequence > 32u) { + return 1u; + } + return 0u; } -// -------- func sha256.hasher.update +// -------- func targa.decoder.num_decoded_frames WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct -wuffs_sha256__hasher__update( - wuffs_sha256__hasher* self, - wuffs_base__slice_u8 a_x) { +WUFFS_BASE__MAYBE_STATIC uint64_t +wuffs_targa__decoder__num_decoded_frames( + const wuffs_targa__decoder* self) { if (!self) { - return wuffs_base__make_empty_struct(); + return 0; } - if (self->private_impl.magic != WUFFS_BASE__MAGIC) { - return wuffs_base__make_empty_struct(); + if ((self->private_impl.magic != WUFFS_BASE__MAGIC) && + (self->private_impl.magic != WUFFS_BASE__DISABLED)) { + return 0; } - uint64_t v_new_lmu = 0; - - if ((self->private_impl.f_length_modulo_u64 == 0u) && ! self->private_impl.f_length_overflows_u64) { - self->private_impl.f_h0 = WUFFS_SHA256__INITIAL_SHA256_H[0u]; - self->private_impl.f_h1 = WUFFS_SHA256__INITIAL_SHA256_H[1u]; - self->private_impl.f_h2 = WUFFS_SHA256__INITIAL_SHA256_H[2u]; - self->private_impl.f_h3 = WUFFS_SHA256__INITIAL_SHA256_H[3u]; - self->private_impl.f_h4 = WUFFS_SHA256__INITIAL_SHA256_H[4u]; - self->private_impl.f_h5 = WUFFS_SHA256__INITIAL_SHA256_H[5u]; - self->private_impl.f_h6 = WUFFS_SHA256__INITIAL_SHA256_H[6u]; - self->private_impl.f_h7 = WUFFS_SHA256__INITIAL_SHA256_H[7u]; - } - v_new_lmu = ((uint64_t)(self->private_impl.f_length_modulo_u64 + ((uint64_t)(a_x.len)))); - self->private_impl.f_length_overflows_u64 = ((v_new_lmu < self->private_impl.f_length_modulo_u64) || self->private_impl.f_length_overflows_u64); - self->private_impl.f_length_modulo_u64 = v_new_lmu; - if (self->private_impl.f_buf_len != 0u) { - while (self->private_impl.f_buf_len < 64u) { - if (((uint64_t)(a_x.len)) <= 0u) { - return wuffs_base__make_empty_struct(); - } - self->private_impl.f_buf_data[self->private_impl.f_buf_len] = a_x.ptr[0u]; - self->private_impl.f_buf_len += 1u; - a_x = wuffs_base__slice_u8__subslice_i(a_x, 1u); - } - self->private_impl.f_buf_len = 0u; - wuffs_sha256__hasher__up(self, wuffs_base__make_slice_u8(self->private_impl.f_buf_data, 64)); + if (self->private_impl.f_call_sequence > 64u) { + return 1u; } - wuffs_sha256__hasher__up(self, a_x); - return wuffs_base__make_empty_struct(); + return 0u; } -// -------- func sha256.hasher.update_bitvec256 +// -------- func targa.decoder.restart_frame WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__bitvec256 -wuffs_sha256__hasher__update_bitvec256( - wuffs_sha256__hasher* self, - wuffs_base__slice_u8 a_x) { +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_targa__decoder__restart_frame( + wuffs_targa__decoder* self, + uint64_t a_index, + uint64_t a_io_position) { if (!self) { - return wuffs_base__utility__make_bitvec256(0u, 0u, 0u, 0u); + return wuffs_base__make_status(wuffs_base__error__bad_receiver); } if (self->private_impl.magic != WUFFS_BASE__MAGIC) { - return wuffs_base__utility__make_bitvec256(0u, 0u, 0u, 0u); + 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); } - wuffs_sha256__hasher__update(self, a_x); - return wuffs_sha256__hasher__checksum_bitvec256(self); + if (self->private_impl.f_call_sequence < 32u) { + return wuffs_base__make_status(wuffs_base__error__bad_call_sequence); + } + if (a_index != 0u) { + return wuffs_base__make_status(wuffs_base__error__bad_argument); + } + self->private_impl.f_call_sequence = 40u; + self->private_impl.f_frame_config_io_position = a_io_position; + return wuffs_base__make_status(NULL); } -// -------- func sha256.hasher.up +// -------- func targa.decoder.set_report_metadata WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__empty_struct -wuffs_sha256__hasher__up( - wuffs_sha256__hasher* self, - wuffs_base__slice_u8 a_x) { - wuffs_base__slice_u8 v_p = {0}; - uint32_t v_w[64] = {0}; - uint32_t v_w2 = 0; - uint32_t v_w15 = 0; - uint32_t v_s0 = 0; - uint32_t v_s1 = 0; - uint32_t v_t1 = 0; - uint32_t v_t2 = 0; - uint32_t v_a = 0; - uint32_t v_b = 0; - uint32_t v_c = 0; - uint32_t v_d = 0; - uint32_t v_e = 0; - uint32_t v_f = 0; - uint32_t v_g = 0; - uint32_t v_h = 0; - uint32_t v_i = 0; - uint32_t v_buf_len = 0; - - v_a = self->private_impl.f_h0; - v_b = self->private_impl.f_h1; - v_c = self->private_impl.f_h2; - v_d = self->private_impl.f_h3; - v_e = self->private_impl.f_h4; - v_f = self->private_impl.f_h5; - v_g = self->private_impl.f_h6; - v_h = self->private_impl.f_h7; - { - wuffs_base__slice_u8 i_slice_p = a_x; - v_p.ptr = i_slice_p.ptr; - v_p.len = 64; - const uint8_t* i_end0_p = wuffs_private_impl__ptr_u8_plus_len(v_p.ptr, (((i_slice_p.len - (size_t)(v_p.ptr - i_slice_p.ptr)) / 64) * 64)); - while (v_p.ptr < i_end0_p) { - v_w[0u] = ((((uint32_t)(v_p.ptr[0u])) << 24u) | - (((uint32_t)(v_p.ptr[1u])) << 16u) | - (((uint32_t)(v_p.ptr[2u])) << 8u) | - ((uint32_t)(v_p.ptr[3u]))); - v_w[1u] = ((((uint32_t)(v_p.ptr[4u])) << 24u) | - (((uint32_t)(v_p.ptr[5u])) << 16u) | - (((uint32_t)(v_p.ptr[6u])) << 8u) | - ((uint32_t)(v_p.ptr[7u]))); - v_w[2u] = ((((uint32_t)(v_p.ptr[8u])) << 24u) | - (((uint32_t)(v_p.ptr[9u])) << 16u) | - (((uint32_t)(v_p.ptr[10u])) << 8u) | - ((uint32_t)(v_p.ptr[11u]))); - v_w[3u] = ((((uint32_t)(v_p.ptr[12u])) << 24u) | - (((uint32_t)(v_p.ptr[13u])) << 16u) | - (((uint32_t)(v_p.ptr[14u])) << 8u) | - ((uint32_t)(v_p.ptr[15u]))); - v_w[4u] = ((((uint32_t)(v_p.ptr[16u])) << 24u) | - (((uint32_t)(v_p.ptr[17u])) << 16u) | - (((uint32_t)(v_p.ptr[18u])) << 8u) | - ((uint32_t)(v_p.ptr[19u]))); - v_w[5u] = ((((uint32_t)(v_p.ptr[20u])) << 24u) | - (((uint32_t)(v_p.ptr[21u])) << 16u) | - (((uint32_t)(v_p.ptr[22u])) << 8u) | - ((uint32_t)(v_p.ptr[23u]))); - v_w[6u] = ((((uint32_t)(v_p.ptr[24u])) << 24u) | - (((uint32_t)(v_p.ptr[25u])) << 16u) | - (((uint32_t)(v_p.ptr[26u])) << 8u) | - ((uint32_t)(v_p.ptr[27u]))); - v_w[7u] = ((((uint32_t)(v_p.ptr[28u])) << 24u) | - (((uint32_t)(v_p.ptr[29u])) << 16u) | - (((uint32_t)(v_p.ptr[30u])) << 8u) | - ((uint32_t)(v_p.ptr[31u]))); - v_w[8u] = ((((uint32_t)(v_p.ptr[32u])) << 24u) | - (((uint32_t)(v_p.ptr[33u])) << 16u) | - (((uint32_t)(v_p.ptr[34u])) << 8u) | - ((uint32_t)(v_p.ptr[35u]))); - v_w[9u] = ((((uint32_t)(v_p.ptr[36u])) << 24u) | - (((uint32_t)(v_p.ptr[37u])) << 16u) | - (((uint32_t)(v_p.ptr[38u])) << 8u) | - ((uint32_t)(v_p.ptr[39u]))); - v_w[10u] = ((((uint32_t)(v_p.ptr[40u])) << 24u) | - (((uint32_t)(v_p.ptr[41u])) << 16u) | - (((uint32_t)(v_p.ptr[42u])) << 8u) | - ((uint32_t)(v_p.ptr[43u]))); - v_w[11u] = ((((uint32_t)(v_p.ptr[44u])) << 24u) | - (((uint32_t)(v_p.ptr[45u])) << 16u) | - (((uint32_t)(v_p.ptr[46u])) << 8u) | - ((uint32_t)(v_p.ptr[47u]))); - v_w[12u] = ((((uint32_t)(v_p.ptr[48u])) << 24u) | - (((uint32_t)(v_p.ptr[49u])) << 16u) | - (((uint32_t)(v_p.ptr[50u])) << 8u) | - ((uint32_t)(v_p.ptr[51u]))); - v_w[13u] = ((((uint32_t)(v_p.ptr[52u])) << 24u) | - (((uint32_t)(v_p.ptr[53u])) << 16u) | - (((uint32_t)(v_p.ptr[54u])) << 8u) | - ((uint32_t)(v_p.ptr[55u]))); - v_w[14u] = ((((uint32_t)(v_p.ptr[56u])) << 24u) | - (((uint32_t)(v_p.ptr[57u])) << 16u) | - (((uint32_t)(v_p.ptr[58u])) << 8u) | - ((uint32_t)(v_p.ptr[59u]))); - v_w[15u] = ((((uint32_t)(v_p.ptr[60u])) << 24u) | - (((uint32_t)(v_p.ptr[61u])) << 16u) | - (((uint32_t)(v_p.ptr[62u])) << 8u) | - ((uint32_t)(v_p.ptr[63u]))); - v_i = 16u; - while (v_i < 64u) { - v_w2 = v_w[(v_i - 2u)]; - v_s1 = ((v_w2 >> 10u) ^ (((uint32_t)(v_w2 << 15u)) | (v_w2 >> 17u)) ^ (((uint32_t)(v_w2 << 13u)) | (v_w2 >> 19u))); - v_w15 = v_w[(v_i - 15u)]; - v_s0 = ((v_w15 >> 3u) ^ (((uint32_t)(v_w15 << 25u)) | (v_w15 >> 7u)) ^ (((uint32_t)(v_w15 << 14u)) | (v_w15 >> 18u))); - v_w[v_i] = ((uint32_t)(((uint32_t)(((uint32_t)(v_s1 + v_w[(v_i - 7u)])) + v_s0)) + v_w[(v_i - 16u)])); - v_i += 1u; - } - v_i = 0u; - while (v_i < 64u) { - v_t1 = v_h; - v_t1 += ((((uint32_t)(v_e << 26u)) | (v_e >> 6u)) ^ (((uint32_t)(v_e << 21u)) | (v_e >> 11u)) ^ (((uint32_t)(v_e << 7u)) | (v_e >> 25u))); - v_t1 += ((v_e & v_f) ^ ((4294967295u ^ v_e) & v_g)); - v_t1 += WUFFS_SHA256__K[v_i]; - v_t1 += v_w[v_i]; - v_t2 = ((((uint32_t)(v_a << 30u)) | (v_a >> 2u)) ^ (((uint32_t)(v_a << 19u)) | (v_a >> 13u)) ^ (((uint32_t)(v_a << 10u)) | (v_a >> 22u))); - v_t2 += ((v_a & v_b) ^ (v_a & v_c) ^ (v_b & v_c)); - v_h = v_g; - v_g = v_f; - v_f = v_e; - v_e = ((uint32_t)(v_d + v_t1)); - v_d = v_c; - v_c = v_b; - v_b = v_a; - v_a = ((uint32_t)(v_t1 + v_t2)); - v_i += 1u; - } - v_a += self->private_impl.f_h0; - self->private_impl.f_h0 = v_a; - v_b += self->private_impl.f_h1; - self->private_impl.f_h1 = v_b; - v_c += self->private_impl.f_h2; - self->private_impl.f_h2 = v_c; - v_d += self->private_impl.f_h3; - self->private_impl.f_h3 = v_d; - v_e += self->private_impl.f_h4; - self->private_impl.f_h4 = v_e; - v_f += self->private_impl.f_h5; - self->private_impl.f_h5 = v_f; - v_g += self->private_impl.f_h6; - self->private_impl.f_h6 = v_g; - v_h += self->private_impl.f_h7; - self->private_impl.f_h7 = v_h; - v_p.ptr += 64; - } - v_p.len = 1; - const uint8_t* i_end1_p = wuffs_private_impl__ptr_u8_plus_len(i_slice_p.ptr, i_slice_p.len); - while (v_p.ptr < i_end1_p) { - self->private_impl.f_buf_data[v_buf_len] = v_p.ptr[0u]; - v_buf_len = ((v_buf_len + 1u) & 63u); - v_p.ptr += 1; - } - v_p.len = 0; - } - self->private_impl.f_buf_len = ((uint32_t)((((uint64_t)(a_x.len)) & 63u))); +WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct +wuffs_targa__decoder__set_report_metadata( + wuffs_targa__decoder* self, + uint32_t a_fourcc, + bool a_report) { return wuffs_base__make_empty_struct(); } -// -------- func sha256.hasher.checksum_bitvec256 +// -------- func targa.decoder.tell_me_more WUFFS_BASE__GENERATED_C_CODE -WUFFS_BASE__MAYBE_STATIC wuffs_base__bitvec256 -wuffs_sha256__hasher__checksum_bitvec256( - const wuffs_sha256__hasher* self) { +WUFFS_BASE__MAYBE_STATIC wuffs_base__status +wuffs_targa__decoder__tell_me_more( + wuffs_targa__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__utility__make_bitvec256(0u, 0u, 0u, 0u); - } - if ((self->private_impl.magic != WUFFS_BASE__MAGIC) && - (self->private_impl.magic != WUFFS_BASE__DISABLED)) { - return wuffs_base__utility__make_bitvec256(0u, 0u, 0u, 0u); - } - - uint32_t v_buf_len = 0; - uint8_t v_buf_data[64] = {0}; - uint64_t v_length_in_bits = 0; - uint32_t v_w[64] = {0}; - uint32_t v_w2 = 0; - uint32_t v_w15 = 0; - uint32_t v_s0 = 0; - uint32_t v_s1 = 0; - uint32_t v_t1 = 0; - uint32_t v_t2 = 0; - uint32_t v_h0 = 0; - uint32_t v_h1 = 0; - uint32_t v_h2 = 0; - uint32_t v_h3 = 0; - uint32_t v_h4 = 0; - uint32_t v_h5 = 0; - uint32_t v_h6 = 0; - uint32_t v_h7 = 0; - uint32_t v_a = 0; - uint32_t v_b = 0; - uint32_t v_c = 0; - uint32_t v_d = 0; - uint32_t v_e = 0; - uint32_t v_f = 0; - uint32_t v_g = 0; - uint32_t v_h = 0; - uint32_t v_i = 0; - bool v_final_block = false; - - v_i = 0u; - while (v_i < 64u) { - v_buf_data[v_i] = self->private_impl.f_buf_data[v_i]; - v_i += 1u; - } - v_buf_len = (self->private_impl.f_buf_len & 63u); - if (v_buf_len < 56u) { - v_buf_data[v_buf_len] = 128u; - v_buf_len += 1u; - while (v_buf_len < 56u) { - v_buf_data[v_buf_len] = 0u; - v_buf_len += 1u; - } - v_final_block = true; - } else { - v_buf_data[v_buf_len] = 128u; - v_buf_len += 1u; - while (v_buf_len < 64u) { - v_buf_data[v_buf_len] = 0u; - v_buf_len += 1u; - } + return wuffs_base__make_status(wuffs_base__error__bad_receiver); } - v_h0 = self->private_impl.f_h0; - v_a = v_h0; - v_h1 = self->private_impl.f_h1; - v_b = v_h1; - v_h2 = self->private_impl.f_h2; - v_c = v_h2; - v_h3 = self->private_impl.f_h3; - v_d = v_h3; - v_h4 = self->private_impl.f_h4; - v_e = v_h4; - v_h5 = self->private_impl.f_h5; - v_f = v_h5; - v_h6 = self->private_impl.f_h6; - v_g = v_h6; - v_h7 = self->private_impl.f_h7; - v_h = v_h7; - while (true) { - if (v_final_block) { - v_length_in_bits = ((uint64_t)(self->private_impl.f_length_modulo_u64 * 8u)); - v_buf_data[56u] = ((uint8_t)((v_length_in_bits >> 56u))); - v_buf_data[57u] = ((uint8_t)((v_length_in_bits >> 48u))); - v_buf_data[58u] = ((uint8_t)((v_length_in_bits >> 40u))); - v_buf_data[59u] = ((uint8_t)((v_length_in_bits >> 32u))); - v_buf_data[60u] = ((uint8_t)((v_length_in_bits >> 24u))); - v_buf_data[61u] = ((uint8_t)((v_length_in_bits >> 16u))); - v_buf_data[62u] = ((uint8_t)((v_length_in_bits >> 8u))); - v_buf_data[63u] = ((uint8_t)(v_length_in_bits)); - } - v_w[0u] = ((((uint32_t)(v_buf_data[0u])) << 24u) | - (((uint32_t)(v_buf_data[1u])) << 16u) | - (((uint32_t)(v_buf_data[2u])) << 8u) | - ((uint32_t)(v_buf_data[3u]))); - v_w[1u] = ((((uint32_t)(v_buf_data[4u])) << 24u) | - (((uint32_t)(v_buf_data[5u])) << 16u) | - (((uint32_t)(v_buf_data[6u])) << 8u) | - ((uint32_t)(v_buf_data[7u]))); - v_w[2u] = ((((uint32_t)(v_buf_data[8u])) << 24u) | - (((uint32_t)(v_buf_data[9u])) << 16u) | - (((uint32_t)(v_buf_data[10u])) << 8u) | - ((uint32_t)(v_buf_data[11u]))); - v_w[3u] = ((((uint32_t)(v_buf_data[12u])) << 24u) | - (((uint32_t)(v_buf_data[13u])) << 16u) | - (((uint32_t)(v_buf_data[14u])) << 8u) | - ((uint32_t)(v_buf_data[15u]))); - v_w[4u] = ((((uint32_t)(v_buf_data[16u])) << 24u) | - (((uint32_t)(v_buf_data[17u])) << 16u) | - (((uint32_t)(v_buf_data[18u])) << 8u) | - ((uint32_t)(v_buf_data[19u]))); - v_w[5u] = ((((uint32_t)(v_buf_data[20u])) << 24u) | - (((uint32_t)(v_buf_data[21u])) << 16u) | - (((uint32_t)(v_buf_data[22u])) << 8u) | - ((uint32_t)(v_buf_data[23u]))); - v_w[6u] = ((((uint32_t)(v_buf_data[24u])) << 24u) | - (((uint32_t)(v_buf_data[25u])) << 16u) | - (((uint32_t)(v_buf_data[26u])) << 8u) | - ((uint32_t)(v_buf_data[27u]))); - v_w[7u] = ((((uint32_t)(v_buf_data[28u])) << 24u) | - (((uint32_t)(v_buf_data[29u])) << 16u) | - (((uint32_t)(v_buf_data[30u])) << 8u) | - ((uint32_t)(v_buf_data[31u]))); - v_w[8u] = ((((uint32_t)(v_buf_data[32u])) << 24u) | - (((uint32_t)(v_buf_data[33u])) << 16u) | - (((uint32_t)(v_buf_data[34u])) << 8u) | - ((uint32_t)(v_buf_data[35u]))); - v_w[9u] = ((((uint32_t)(v_buf_data[36u])) << 24u) | - (((uint32_t)(v_buf_data[37u])) << 16u) | - (((uint32_t)(v_buf_data[38u])) << 8u) | - ((uint32_t)(v_buf_data[39u]))); - v_w[10u] = ((((uint32_t)(v_buf_data[40u])) << 24u) | - (((uint32_t)(v_buf_data[41u])) << 16u) | - (((uint32_t)(v_buf_data[42u])) << 8u) | - ((uint32_t)(v_buf_data[43u]))); - v_w[11u] = ((((uint32_t)(v_buf_data[44u])) << 24u) | - (((uint32_t)(v_buf_data[45u])) << 16u) | - (((uint32_t)(v_buf_data[46u])) << 8u) | - ((uint32_t)(v_buf_data[47u]))); - v_w[12u] = ((((uint32_t)(v_buf_data[48u])) << 24u) | - (((uint32_t)(v_buf_data[49u])) << 16u) | - (((uint32_t)(v_buf_data[50u])) << 8u) | - ((uint32_t)(v_buf_data[51u]))); - v_w[13u] = ((((uint32_t)(v_buf_data[52u])) << 24u) | - (((uint32_t)(v_buf_data[53u])) << 16u) | - (((uint32_t)(v_buf_data[54u])) << 8u) | - ((uint32_t)(v_buf_data[55u]))); - v_w[14u] = ((((uint32_t)(v_buf_data[56u])) << 24u) | - (((uint32_t)(v_buf_data[57u])) << 16u) | - (((uint32_t)(v_buf_data[58u])) << 8u) | - ((uint32_t)(v_buf_data[59u]))); - v_w[15u] = ((((uint32_t)(v_buf_data[60u])) << 24u) | - (((uint32_t)(v_buf_data[61u])) << 16u) | - (((uint32_t)(v_buf_data[62u])) << 8u) | - ((uint32_t)(v_buf_data[63u]))); - v_i = 16u; - while (v_i < 64u) { - v_w2 = v_w[(v_i - 2u)]; - v_s1 = ((v_w2 >> 10u) ^ (((uint32_t)(v_w2 << 15u)) | (v_w2 >> 17u)) ^ (((uint32_t)(v_w2 << 13u)) | (v_w2 >> 19u))); - v_w15 = v_w[(v_i - 15u)]; - v_s0 = ((v_w15 >> 3u) ^ (((uint32_t)(v_w15 << 25u)) | (v_w15 >> 7u)) ^ (((uint32_t)(v_w15 << 14u)) | (v_w15 >> 18u))); - v_w[v_i] = ((uint32_t)(((uint32_t)(((uint32_t)(v_s1 + v_w[(v_i - 7u)])) + v_s0)) + v_w[(v_i - 16u)])); - v_i += 1u; - } - v_i = 0u; - while (v_i < 64u) { - v_t1 = v_h; - v_t1 += ((((uint32_t)(v_e << 26u)) | (v_e >> 6u)) ^ (((uint32_t)(v_e << 21u)) | (v_e >> 11u)) ^ (((uint32_t)(v_e << 7u)) | (v_e >> 25u))); - v_t1 += ((v_e & v_f) ^ ((4294967295u ^ v_e) & v_g)); - v_t1 += WUFFS_SHA256__K[v_i]; - v_t1 += v_w[v_i]; - v_t2 = ((((uint32_t)(v_a << 30u)) | (v_a >> 2u)) ^ (((uint32_t)(v_a << 19u)) | (v_a >> 13u)) ^ (((uint32_t)(v_a << 10u)) | (v_a >> 22u))); - v_t2 += ((v_a & v_b) ^ (v_a & v_c) ^ (v_b & v_c)); - v_h = v_g; - v_g = v_f; - v_f = v_e; - v_e = ((uint32_t)(v_d + v_t1)); - v_d = v_c; - v_c = v_b; - v_b = v_a; - v_a = ((uint32_t)(v_t1 + v_t2)); - v_i += 1u; - } - v_a += v_h0; - v_b += v_h1; - v_c += v_h2; - v_d += v_h3; - v_e += v_h4; - v_f += v_h5; - v_g += v_h6; - v_h += v_h7; - if (v_final_block) { - break; - } - v_final_block = true; - v_h0 = v_a; - v_h1 = v_b; - v_h2 = v_c; - v_h3 = v_d; - v_h4 = v_e; - v_h5 = v_f; - v_h6 = v_g; - v_h7 = v_h; - v_buf_len = 0u; - while (v_buf_len < 56u) { - v_buf_data[v_buf_len] = 0u; - v_buf_len += 1u; - } + 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__utility__make_bitvec256( - (((uint64_t)(v_h)) | (((uint64_t)(v_g)) << 32u)), - (((uint64_t)(v_f)) | (((uint64_t)(v_e)) << 32u)), - (((uint64_t)(v_d)) | (((uint64_t)(v_c)) << 32u)), - (((uint64_t)(v_b)) | (((uint64_t)(v_a)) << 32u))); + 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; } -#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__SHA256) +// -------- func targa.decoder.workbuf_len -#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA) +WUFFS_BASE__GENERATED_C_CODE +WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 +wuffs_targa__decoder__workbuf_len( + const wuffs_targa__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__TARGA) + +#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__THUMBHASH) // ---------------- Status Codes Implementations -const char wuffs_tga__error__bad_header[] = "#tga: bad header"; -const char wuffs_tga__error__bad_run_length_encoding[] = "#tga: bad run length encoding"; -const char wuffs_tga__error__truncated_input[] = "#tga: truncated input"; -const char wuffs_tga__error__unsupported_tga_file[] = "#tga: unsupported TGA file"; +const char wuffs_thumbhash__error__bad_header[] = "#thumbhash: bad header"; +const char wuffs_thumbhash__error__truncated_input[] = "#thumbhash: truncated input"; // ---------------- Private Consts +#define WUFFS_THUMBHASH__QUIRKS_BASE 1712283648u + +static const uint8_t +WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[8] WUFFS_BASE__POTENTIALLY_UNUSED = { + 0u, 14u, 18u, 19u, 23u, 26u, 27u, 32u, +}; + +static const uint8_t +WUFFS_THUMBHASH__CUMULATIVE_DIMENSIONS[8] WUFFS_BASE__POTENTIALLY_UNUSED = { + 0u, 0u, 14u, 32u, 51u, 74u, 100u, 127u, +}; + +static const uint8_t +WUFFS_THUMBHASH__DIMENSION_CODES_FROM_HAS_ALPHA_AND_L_COUNT[2][8] WUFFS_BASE__POTENTIALLY_UNUSED = { + { + 23u, 23u, 23u, 23u, 39u, 71u, 103u, 119u, + }, { + 55u, 55u, 55u, 55u, 87u, 119u, 118u, 116u, + }, +}; + +static const uint16_t +WUFFS_THUMBHASH__FROM_4_BITS_TO_PLUS_MINUS_1_00[16] WUFFS_BASE__POTENTIALLY_UNUSED = { + 49152u, 51337u, 53521u, 55706u, 57890u, 60075u, 62259u, 64444u, + 1092u, 3277u, 5461u, 7646u, 9830u, 12015u, 14199u, 16384u, +}; + +static const uint16_t +WUFFS_THUMBHASH__FROM_4_BITS_TO_PLUS_MINUS_1_25[16] WUFFS_BASE__POTENTIALLY_UNUSED = { + 45056u, 47787u, 50517u, 53248u, 55979u, 58709u, 61440u, 64171u, + 1365u, 4096u, 6827u, 9557u, 12288u, 15019u, 17749u, 20480u, +}; + +static const uint16_t +WUFFS_THUMBHASH__COSINES[159][6] WUFFS_BASE__POTENTIALLY_UNUSED = { + { + 16281u, 15973u, 15465u, 14761u, 13873u, 12810u, + }, { + 15465u, 12810u, 8717u, 3646u, 63702u, 58427u, + }, { + 13873u, 7109u, 63702u, 55321u, 50071u, 49563u, + }, { + 11585u, 0u, 53951u, 49152u, 53951u, 0u, + }, { + 8717u, 58427u, 49255u, 55321u, 5411u, 15973u, + }, { + 5411u, 52726u, 51663u, 3646u, 16281u, 7109u, + }, { + 1834u, 49563u, 60125u, 14761u, 8717u, 52726u, + }, { + 63702u, 49563u, 5411u, 14761u, 56819u, 52726u, + }, + { + 60125u, 52726u, 13873u, 3646u, 49255u, 7109u, + }, { + 56819u, 58427u, 16281u, 55321u, 60125u, 15973u, + }, { + 53951u, 0u, 11585u, 49152u, 11585u, 0u, + }, { + 51663u, 7109u, 1834u, 55321u, 15465u, 49563u, + }, { + 50071u, 12810u, 56819u, 3646u, 1834u, 58427u, + }, { + 49255u, 15973u, 50071u, 14761u, 51663u, 12810u, + }, { + 16322u, 16135u, 15826u, 15396u, 14849u, 14189u, + }, { + 15826u, 14189u, 11585u, 8192u, 4240u, 0u, + }, + { + 14849u, 10531u, 4240u, 62691u, 56139u, 51347u, + }, { + 13421u, 5604u, 61296u, 52985u, 49214u, 51347u, + }, { + 11585u, 0u, 53951u, 49152u, 53951u, 0u, + }, { + 9397u, 59932u, 49710u, 52985u, 1428u, 14189u, + }, { + 6924u, 55005u, 49710u, 62691u, 13421u, 14189u, + }, { + 4240u, 51347u, 53951u, 8192u, 15826u, 0u, + }, { + 1428u, 49401u, 61296u, 15396u, 6924u, 51347u, + }, { + 64108u, 49401u, 4240u, 15396u, 58612u, 51347u, + }, + { + 61296u, 51347u, 11585u, 8192u, 49710u, 0u, + }, { + 58612u, 55005u, 15826u, 62691u, 52115u, 14189u, + }, { + 56139u, 59932u, 15826u, 52985u, 64108u, 14189u, + }, { + 53951u, 0u, 11585u, 49152u, 11585u, 0u, + }, { + 52115u, 5604u, 4240u, 52985u, 16322u, 51347u, + }, { + 50687u, 10531u, 61296u, 62691u, 9397u, 51347u, + }, { + 49710u, 14189u, 53951u, 8192u, 61296u, 0u, + }, { + 49214u, 16135u, 49710u, 15396u, 50687u, 14189u, + }, + { + 16328u, 16161u, 15883u, 15496u, 15004u, 14409u, + }, { + 15883u, 14409u, 12054u, 8961u, 5320u, 1353u, + }, { + 15004u, 11097u, 5320u, 64183u, 57738u, 52607u, + }, { + 13716u, 6581u, 62839u, 54439u, 49653u, 50040u, + }, { + 12054u, 1353u, 55473u, 49375u, 51820u, 61514u, + }, { + 10063u, 61514u, 50532u, 51127u, 62839u, 11097u, + }, { + 7798u, 56575u, 49208u, 58955u, 10063u, 16161u, + }, { + 5320u, 52607u, 51820u, 4022u, 16328u, 6581u, + }, + { + 2697u, 50040u, 57738u, 12929u, 12054u, 56575u, + }, { + 0u, 49152u, 0u, 16384u, 0u, 49152u, + }, { + 62839u, 50040u, 7798u, 12929u, 53482u, 56575u, + }, { + 60216u, 52607u, 13716u, 4022u, 49208u, 6581u, + }, { + 57738u, 56575u, 16328u, 58955u, 55473u, 16161u, + }, { + 55473u, 61514u, 15004u, 51127u, 2697u, 11097u, + }, { + 53482u, 1353u, 10063u, 49375u, 13716u, 61514u, + }, { + 51820u, 6581u, 2697u, 54439u, 15883u, 50040u, + }, + { + 50532u, 11097u, 60216u, 64183u, 7798u, 52607u, + }, { + 49653u, 14409u, 53482u, 8961u, 60216u, 1353u, + }, { + 49208u, 16161u, 49653u, 15496u, 50532u, 14409u, + }, { + 16346u, 16231u, 16041u, 15776u, 15438u, 15028u, + }, { + 16041u, 15028u, 13385u, 11183u, 8513u, 5487u, + }, { + 15438u, 12709u, 8513u, 3333u, 63305u, 57998u, + }, { + 14547u, 9448u, 2231u, 60049u, 53562u, 49760u, + }, { + 13385u, 5487u, 61116u, 52827u, 49190u, 51537u, + }, + { + 11974u, 1118u, 55196u, 49305u, 52151u, 62203u, + }, { + 10340u, 62203u, 50989u, 50508u, 61116u, 9448u, + }, { + 8513u, 57998u, 49190u, 56088u, 6527u, 16231u, + }, { + 6527u, 54353u, 50098u, 64418u, 14547u, 12709u, + }, { + 4420u, 51537u, 53562u, 7538u, 16041u, 1118u, + }, { + 2231u, 49760u, 59009u, 13999u, 10340u, 54353u, + }, { + 0u, 49152u, 0u, 16384u, 0u, 49152u, + }, { + 63305u, 49760u, 6527u, 13999u, 55196u, 54353u, + }, + { + 61116u, 51537u, 11974u, 7538u, 49495u, 1118u, + }, { + 59009u, 54353u, 15438u, 64418u, 50989u, 12709u, + }, { + 57023u, 57998u, 16346u, 56088u, 59009u, 16231u, + }, { + 55196u, 62203u, 14547u, 50508u, 4420u, 9448u, + }, { + 53562u, 1118u, 10340u, 49305u, 13385u, 62203u, + }, { + 52151u, 5487u, 4420u, 52827u, 16346u, 51537u, + }, { + 50989u, 9448u, 63305u, 60049u, 11974u, 49760u, + }, { + 50098u, 12709u, 57023u, 3333u, 2231u, 57998u, + }, + { + 49495u, 15028u, 52151u, 11183u, 57023u, 5487u, + }, { + 49190u, 16231u, 49495u, 15776u, 50098u, 15028u, + }, { + 16354u, 16265u, 16116u, 15908u, 15642u, 15319u, + }, { + 16116u, 15319u, 14021u, 12264u, 10104u, 7614u, + }, { + 15642u, 13484u, 10104u, 5810u, 989u, 61615u, + }, { + 14941u, 10865u, 4874u, 63561u, 57060u, 52052u, + }, { + 14021u, 7614u, 64547u, 56229u, 50595u, 49271u, + }, { + 12897u, 3921u, 58812u, 51029u, 49420u, 54671u, + }, + { + 11585u, 0u, 53951u, 49152u, 53951u, 0u, + }, { + 10104u, 61615u, 50595u, 51029u, 62583u, 10865u, + }, { + 8476u, 57922u, 49182u, 56229u, 6724u, 16265u, + }, { + 6724u, 54671u, 49894u, 63561u, 14021u, 13484u, + }, { + 4874u, 52052u, 52639u, 5810u, 16354u, 3921u, + }, { + 2953u, 50217u, 57060u, 12264u, 12897u, 57922u, + }, { + 989u, 49271u, 62583u, 15908u, 4874u, 50217u, + }, { + 64547u, 49271u, 2953u, 15908u, 60662u, 50217u, + }, + { + 62583u, 50217u, 8476u, 12264u, 52639u, 57922u, + }, { + 60662u, 52052u, 12897u, 5810u, 49182u, 3921u, + }, { + 58812u, 54671u, 15642u, 63561u, 51515u, 13484u, + }, { + 57060u, 57922u, 16354u, 56229u, 58812u, 16265u, + }, { + 55432u, 61615u, 14941u, 51029u, 2953u, 10865u, + }, { + 53951u, 0u, 11585u, 49152u, 11585u, 0u, + }, { + 52639u, 3921u, 6724u, 51029u, 16116u, 54671u, + }, { + 51515u, 7614u, 989u, 56229u, 14941u, 49271u, + }, + { + 50595u, 10865u, 60662u, 63561u, 8476u, 52052u, + }, { + 49894u, 13484u, 55432u, 5810u, 64547u, 61615u, + }, { + 49420u, 15319u, 51515u, 12264u, 55432u, 7614u, + }, { + 49182u, 16265u, 49420u, 15908u, 49894u, 15319u, + }, { + 16356u, 16273u, 16135u, 15942u, 15696u, 15396u, + }, { + 16135u, 15396u, 14189u, 12551u, 10531u, 8192u, + }, { + 15696u, 13689u, 10531u, 6489u, 1902u, 62691u, + }, { + 15044u, 11243u, 5604u, 64583u, 58183u, 52985u, + }, + { + 14189u, 8192u, 0u, 57344u, 51347u, 49152u, + }, { + 13142u, 4699u, 59932u, 51847u, 49180u, 52985u, + }, { + 11917u, 953u, 55005u, 49263u, 52394u, 62691u, + }, { + 10531u, 62691u, 51347u, 50140u, 59932u, 8192u, + }, { + 9003u, 59047u, 49401u, 54293u, 3778u, 15396u, + }, { + 7353u, 55752u, 49401u, 60837u, 11917u, 15396u, + }, { + 5604u, 52985u, 51347u, 2845u, 16135u, 8192u, + }, { + 3778u, 50895u, 55005u, 9784u, 15044u, 62691u, + }, + { + 1902u, 49594u, 59932u, 14641u, 9003u, 52985u, + }, { + 0u, 49152u, 0u, 16384u, 0u, 49152u, + }, { + 63634u, 49594u, 5604u, 14641u, 56533u, 52985u, + }, { + 61758u, 50895u, 10531u, 9784u, 50492u, 62691u, + }, { + 59932u, 52985u, 14189u, 2845u, 49401u, 8192u, + }, { + 58183u, 55752u, 16135u, 60837u, 53619u, 15396u, + }, { + 56533u, 59047u, 16135u, 54293u, 61758u, 15396u, + }, { + 55005u, 62691u, 14189u, 50140u, 5604u, 8192u, + }, + { + 53619u, 953u, 10531u, 49263u, 13142u, 62691u, + }, { + 52394u, 4699u, 5604u, 51847u, 16356u, 52985u, + }, { + 51347u, 8192u, 0u, 57344u, 14189u, 49152u, + }, { + 50492u, 11243u, 59932u, 64583u, 7353u, 52985u, + }, { + 49840u, 13689u, 55005u, 6489u, 63634u, 62691u, + }, { + 49401u, 15396u, 51347u, 12551u, 55005u, 8192u, + }, { + 49180u, 16273u, 49401u, 15942u, 49840u, 15396u, + }, { + 16364u, 16305u, 16207u, 16069u, 15893u, 15679u, + }, + { + 16207u, 15679u, 14811u, 13623u, 12140u, 10394u, + }, { + 15893u, 14449u, 12140u, 9102u, 5520u, 1606u, + }, { + 15426u, 12665u, 8423u, 3196u, 63132u, 57813u, + }, { + 14811u, 10394u, 3981u, 62340u, 55776u, 51087u, + }, { + 14053u, 7723u, 64732u, 56434u, 50725u, 49231u, + }, { + 13160u, 4756u, 60016u, 51913u, 49172u, 52871u, + }, { + 12140u, 1606u, 55776u, 49467u, 51483u, 60780u, + }, { + 11003u, 63930u, 52376u, 49467u, 57113u, 4756u, + }, + { + 9760u, 60780u, 50110u, 51913u, 64732u, 12665u, + }, { + 8423u, 57813u, 49172u, 56434u, 7005u, 16305u, + }, { + 7005u, 55142u, 49643u, 62340u, 13160u, 14449u, + }, { + 5520u, 52871u, 51483u, 3196u, 16207u, 7723u, + }, { + 3981u, 51087u, 54533u, 9102u, 15426u, 63930u, + }, { + 2404u, 49857u, 58531u, 13623u, 11003u, 55142u, + }, { + 804u, 49231u, 63132u, 16069u, 3981u, 49857u, + }, { + 64732u, 49231u, 2404u, 16069u, 61555u, 49857u, + }, + { + 63132u, 49857u, 7005u, 13623u, 54533u, 55142u, + }, { + 61555u, 51087u, 11003u, 9102u, 50110u, 63930u, + }, { + 60016u, 52871u, 14053u, 3196u, 49329u, 7723u, + }, { + 58531u, 55142u, 15893u, 62340u, 52376u, 14449u, + }, { + 57113u, 57813u, 16364u, 56434u, 58531u, 16305u, + }, { + 55776u, 60780u, 15426u, 51913u, 804u, 12665u, + }, { + 54533u, 63930u, 13160u, 49467u, 8423u, 4756u, + }, { + 53396u, 1606u, 9760u, 49467u, 14053u, 60780u, + }, + { + 52376u, 4756u, 5520u, 51913u, 16364u, 52871u, + }, { + 51483u, 7723u, 804u, 56434u, 14811u, 49231u, + }, { + 50725u, 10394u, 61555u, 62340u, 9760u, 51087u, + }, { + 50110u, 12665u, 57113u, 3196u, 2404u, 57813u, + }, { + 49643u, 14449u, 53396u, 9102u, 60016u, 1606u, + }, { + 49329u, 15679u, 50725u, 13623u, 53396u, 10394u, + }, { + 49172u, 16305u, 49329u, 16069u, 49643u, 15679u, + }, +}; + // ---------------- Private Initializer Prototypes // ---------------- Private Function Prototypes WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_tga__decoder__do_decode_image_config( - wuffs_tga__decoder* self, +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_tga__decoder__do_decode_frame_config( - wuffs_tga__decoder* self, +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_tga__decoder__do_decode_frame( - wuffs_tga__decoder* self, +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_coeffs( + wuffs_thumbhash__decoder* self, + wuffs_base__io_buffer* a_src); + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_thumbhash__decoder__from_coeffs_to_pixels( + wuffs_thumbhash__decoder* self); + +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_tga__decoder__func_ptrs_for__wuffs_base__image_decoder = { +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_tga__decoder__decode_frame), + wuffs_base__decode_frame_options*))(&wuffs_thumbhash__decoder__decode_frame), (wuffs_base__status(*)(void*, wuffs_base__frame_config*, - wuffs_base__io_buffer*))(&wuffs_tga__decoder__decode_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_tga__decoder__decode_image_config), - (wuffs_base__rect_ie_u32(*)(const void*))(&wuffs_tga__decoder__frame_dirty_rect), + 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_tga__decoder__get_quirk), - (uint32_t(*)(const void*))(&wuffs_tga__decoder__num_animation_loops), - (uint64_t(*)(const void*))(&wuffs_tga__decoder__num_decoded_frame_configs), - (uint64_t(*)(const void*))(&wuffs_tga__decoder__num_decoded_frames), + 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_tga__decoder__restart_frame), + uint64_t))(&wuffs_thumbhash__decoder__restart_frame), (wuffs_base__status(*)(void*, uint32_t, - uint64_t))(&wuffs_tga__decoder__set_quirk), + uint64_t))(&wuffs_thumbhash__decoder__set_quirk), (wuffs_base__empty_struct(*)(void*, uint32_t, - bool))(&wuffs_tga__decoder__set_report_metadata), + bool))(&wuffs_thumbhash__decoder__set_report_metadata), (wuffs_base__status(*)(void*, wuffs_base__io_buffer*, wuffs_base__more_information*, - wuffs_base__io_buffer*))(&wuffs_tga__decoder__tell_me_more), - (wuffs_base__range_ii_u64(*)(const void*))(&wuffs_tga__decoder__workbuf_len), + 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_tga__decoder__initialize( - wuffs_tga__decoder* self, +wuffs_thumbhash__decoder__initialize( + wuffs_thumbhash__decoder* self, size_t sizeof_star_self, uint64_t wuffs_version, uint32_t options){ @@ -69185,19 +74673,19 @@ wuffs_tga__decoder__initialize( 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_tga__decoder__func_ptrs_for__wuffs_base__image_decoder); + (const void*)(&wuffs_thumbhash__decoder__func_ptrs_for__wuffs_base__image_decoder); return wuffs_base__make_status(NULL); } -wuffs_tga__decoder* -wuffs_tga__decoder__alloc(void) { - wuffs_tga__decoder* x = - (wuffs_tga__decoder*)(calloc(1, sizeof(wuffs_tga__decoder))); +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_tga__decoder__initialize( - x, sizeof(wuffs_tga__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) { + if (wuffs_thumbhash__decoder__initialize( + x, sizeof(wuffs_thumbhash__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) { free(x); return NULL; } @@ -69205,18 +74693,18 @@ wuffs_tga__decoder__alloc(void) { } size_t -sizeof__wuffs_tga__decoder(void) { - return sizeof(wuffs_tga__decoder); +sizeof__wuffs_thumbhash__decoder(void) { + return sizeof(wuffs_thumbhash__decoder); } // ---------------- Function Implementations -// -------- func tga.decoder.get_quirk +// -------- func thumbhash.decoder.get_quirk WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC uint64_t -wuffs_tga__decoder__get_quirk( - const wuffs_tga__decoder* self, +wuffs_thumbhash__decoder__get_quirk( + const wuffs_thumbhash__decoder* self, uint32_t a_key) { if (!self) { return 0; @@ -69226,15 +74714,18 @@ wuffs_tga__decoder__get_quirk( return 0; } + if ((a_key == 1712283648u) && self->private_impl.f_quirk_just_raw_thumbhash) { + return 1u; + } return 0u; } -// -------- func tga.decoder.set_quirk +// -------- func thumbhash.decoder.set_quirk WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_tga__decoder__set_quirk( - wuffs_tga__decoder* self, +wuffs_thumbhash__decoder__set_quirk( + wuffs_thumbhash__decoder* self, uint32_t a_key, uint64_t a_value) { if (!self) { @@ -69247,15 +74738,19 @@ wuffs_tga__decoder__set_quirk( : wuffs_base__error__initialize_not_called); } + if (a_key == 1712283648u) { + self->private_impl.f_quirk_just_raw_thumbhash = (a_value > 0u); + return wuffs_base__make_status(NULL); + } return wuffs_base__make_status(wuffs_base__error__unsupported_option); } -// -------- func tga.decoder.decode_image_config +// -------- func thumbhash.decoder.decode_image_config WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_tga__decoder__decode_image_config( - wuffs_tga__decoder* self, +wuffs_thumbhash__decoder__decode_image_config( + wuffs_thumbhash__decoder* self, wuffs_base__image_config* a_dst, wuffs_base__io_buffer* a_src) { if (!self) { @@ -69287,11 +74782,11 @@ wuffs_tga__decoder__decode_image_config( while (true) { { - wuffs_base__status t_0 = wuffs_tga__decoder__do_decode_image_config(self, a_dst, a_src); + 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_tga__error__truncated_input); + status = wuffs_base__make_status(wuffs_thumbhash__error__truncated_input); goto exit; } status = v_status; @@ -69316,19 +74811,18 @@ wuffs_tga__decoder__decode_image_config( return status; } -// -------- func tga.decoder.do_decode_image_config +// -------- func thumbhash.decoder.do_decode_image_config WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_tga__decoder__do_decode_image_config( - wuffs_tga__decoder* self, +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; - uint32_t v_c5 = 0; - uint32_t v_i = 0; + uint8_t v_swap = 0; const uint8_t* iop_a_src = NULL; const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL; @@ -69342,9 +74836,6 @@ wuffs_tga__decoder__do_decode_image_config( } uint32_t coro_susp_point = self->private_impl.p_do_decode_image_config; - if (coro_susp_point) { - v_i = self->private_data.s_do_decode_image_config.v_i; - } switch (coro_susp_point) { WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; @@ -69352,400 +74843,160 @@ wuffs_tga__decoder__do_decode_image_config( status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence); goto exit; } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_0 = *iop_a_src++; - self->private_impl.f_header_id_length = t_0; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_1 = *iop_a_src++; - self->private_impl.f_header_color_map_type = t_1; - } - if (self->private_impl.f_header_color_map_type > 1u) { - status = wuffs_base__make_status(wuffs_tga__error__bad_header); - goto exit; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_2 = *iop_a_src++; - self->private_impl.f_header_image_type = t_2; - } - if ((self->private_impl.f_header_image_type == 1u) || - (self->private_impl.f_header_image_type == 2u) || - (self->private_impl.f_header_image_type == 3u) || - (self->private_impl.f_header_image_type == 9u) || - (self->private_impl.f_header_image_type == 10u) || - (self->private_impl.f_header_image_type == 11u)) { - } else { - status = wuffs_base__make_status(wuffs_tga__error__bad_header); - goto exit; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); - uint16_t t_3; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { - t_3 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src); - iop_a_src += 2; - } else { - self->private_data.s_do_decode_image_config.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); - 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_3 = ((uint32_t)(*scratch >> 56)); - *scratch <<= 8; - *scratch >>= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_3; - if (num_bits_3 == 8) { - t_3 = ((uint16_t)(*scratch)); - break; - } - num_bits_3 += 8u; - *scratch |= ((uint64_t)(num_bits_3)) << 56; - } - } - self->private_impl.f_header_color_map_first_entry_index = t_3; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); - uint16_t t_4; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { - t_4 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src); - iop_a_src += 2; - } else { - self->private_data.s_do_decode_image_config.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); - 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_4 = ((uint32_t)(*scratch >> 56)); - *scratch <<= 8; - *scratch >>= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_4; - if (num_bits_4 == 8) { - t_4 = ((uint16_t)(*scratch)); - break; + if ( ! self->private_impl.f_quirk_just_raw_thumbhash) { + { + 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; } - num_bits_4 += 8u; - *scratch |= ((uint64_t)(num_bits_4)) << 56; } + v_c32 = t_0; } - self->private_impl.f_header_color_map_length = t_4; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_5 = *iop_a_src++; - self->private_impl.f_header_color_map_entry_size = t_5; - } - if (self->private_impl.f_header_color_map_type != 0u) { - if ((self->private_impl.f_header_color_map_first_entry_index != 0u) || (self->private_impl.f_header_color_map_length > 256u)) { - status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file); - goto exit; - } else if ((self->private_impl.f_header_color_map_entry_size != 15u) && - (self->private_impl.f_header_color_map_entry_size != 16u) && - (self->private_impl.f_header_color_map_entry_size != 24u) && - (self->private_impl.f_header_color_map_entry_size != 32u)) { - status = wuffs_base__make_status(wuffs_tga__error__bad_header); - goto exit; - } - } else { - if ((self->private_impl.f_header_color_map_first_entry_index != 0u) || (self->private_impl.f_header_color_map_length != 0u) || (self->private_impl.f_header_color_map_entry_size != 0u)) { - status = wuffs_base__make_status(wuffs_tga__error__bad_header); + if (v_c32 != 16694979u) { + status = wuffs_base__make_status(wuffs_thumbhash__error__bad_header); goto exit; } } - self->private_data.s_do_decode_image_config.scratch = 4u; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); - if (self->private_data.s_do_decode_image_config.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { - self->private_data.s_do_decode_image_config.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); - iop_a_src = io2_a_src; - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - iop_a_src += self->private_data.s_do_decode_image_config.scratch; - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10); - uint32_t t_6; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { - t_6 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src))); - iop_a_src += 2; - } else { - self->private_data.s_do_decode_image_config.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11); - 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_6 = ((uint32_t)(*scratch >> 56)); - *scratch <<= 8; - *scratch >>= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_6; - if (num_bits_6 == 8) { - t_6 = ((uint32_t)(*scratch)); - break; - } - num_bits_6 += 8u; - *scratch |= ((uint64_t)(num_bits_6)) << 56; - } - } - self->private_impl.f_width = t_6; - } { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12); - uint32_t t_7; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { - t_7 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src))); - iop_a_src += 2; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + uint32_t t_1; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 3)) { + t_1 = ((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(13); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); 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_7 = ((uint32_t)(*scratch >> 56)); + uint32_t num_bits_1 = ((uint32_t)(*scratch >> 56)); *scratch <<= 8; *scratch >>= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_7; - if (num_bits_7 == 8) { - t_7 = ((uint32_t)(*scratch)); + *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_1; + if (num_bits_1 == 16) { + t_1 = ((uint32_t)(*scratch)); break; - } - num_bits_7 += 8u; - *scratch |= ((uint64_t)(num_bits_7)) << 56; - } - } - self->private_impl.f_height = t_7; - } - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(14); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - uint8_t t_8 = *iop_a_src++; - self->private_impl.f_header_pixel_depth = t_8; - } - if ((self->private_impl.f_header_pixel_depth != 1u) && - (self->private_impl.f_header_pixel_depth != 8u) && - (self->private_impl.f_header_pixel_depth != 15u) && - (self->private_impl.f_header_pixel_depth != 16u) && - (self->private_impl.f_header_pixel_depth != 24u) && - (self->private_impl.f_header_pixel_depth != 32u)) { - status = wuffs_base__make_status(wuffs_tga__error__bad_header); - goto exit; - } - if (((uint8_t)(self->private_impl.f_header_image_type | 8u)) == 9u) { - self->private_impl.f_scratch_bytes_per_pixel = 1u; - self->private_impl.f_src_bytes_per_pixel = 1u; - self->private_impl.f_src_pixfmt = 2164523016u; - self->private_impl.f_opaque = ((self->private_impl.f_header_color_map_entry_size == 15u) || (self->private_impl.f_header_color_map_entry_size == 24u)); - } else if (((uint8_t)(self->private_impl.f_header_image_type | 8u)) == 10u) { - if ((self->private_impl.f_header_pixel_depth == 15u) || (self->private_impl.f_header_pixel_depth == 16u)) { - self->private_impl.f_scratch_bytes_per_pixel = 4u; - self->private_impl.f_src_bytes_per_pixel = 0u; - self->private_impl.f_src_pixfmt = 2164295816u; - } else if (self->private_impl.f_header_pixel_depth == 24u) { - self->private_impl.f_scratch_bytes_per_pixel = 3u; - self->private_impl.f_src_bytes_per_pixel = 3u; - self->private_impl.f_src_pixfmt = 2147485832u; - self->private_impl.f_opaque = true; - } else if (self->private_impl.f_header_pixel_depth == 32u) { - self->private_impl.f_scratch_bytes_per_pixel = 4u; - self->private_impl.f_src_bytes_per_pixel = 4u; - self->private_impl.f_src_pixfmt = 2164295816u; - } else { - status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file); - goto exit; - } - } else { - if (self->private_impl.f_header_pixel_depth == 8u) { - self->private_impl.f_scratch_bytes_per_pixel = 1u; - self->private_impl.f_src_bytes_per_pixel = 1u; - self->private_impl.f_src_pixfmt = 536870920u; - self->private_impl.f_opaque = true; - } else { - status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file); - goto exit; + } + num_bits_1 += 8u; + *scratch |= ((uint64_t)(num_bits_1)) << 56; + } } + v_c32 = t_1; } + self->private_impl.f_l_dc = (((uint64_t)(((v_c32 >> 0u) & 63u))) * 136339441844224u); + self->private_impl.f_p_dc = ((uint64_t)((((uint64_t)(((v_c32 >> 6u) & 63u))) * 272678883688448u) - 8589384836186112u)); + self->private_impl.f_q_dc = ((uint64_t)((((uint64_t)(((v_c32 >> 12u) & 63u))) * 272678883688448u) - 8589384836186112u)); + self->private_impl.f_l_scale = ((uint8_t)(((v_c32 >> 18u) & 31u))); + self->private_impl.f_has_alpha = ((uint8_t)(((v_c32 >> 23u) & 1u))); { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15); - if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); + uint32_t t_2; + if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { + t_2 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src))); + iop_a_src += 2; + } else { + self->private_data.s_do_decode_image_config.scratch = 0; + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); + 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_2 = ((uint32_t)(*scratch >> 56)); + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_2; + if (num_bits_2 == 8) { + t_2 = ((uint32_t)(*scratch)); + break; + } + num_bits_2 += 8u; + *scratch |= ((uint64_t)(num_bits_2)) << 56; + } } - uint8_t t_9 = *iop_a_src++; - self->private_impl.f_header_image_descriptor = t_9; + v_c32 = t_2; } - if (((uint8_t)(self->private_impl.f_header_image_descriptor & 16u)) != 0u) { - status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file); - goto exit; + self->private_impl.f_l_count = ((uint8_t)(((v_c32 >> 0u) & 7u))); + self->private_impl.f_p_scale = ((uint8_t)(((v_c32 >> 3u) & 63u))); + self->private_impl.f_q_scale = ((uint8_t)(((v_c32 >> 9u) & 63u))); + self->private_impl.f_is_landscape = ((uint8_t)(((v_c32 >> 15u) & 1u))); + self->private_impl.f_w_dimension_code = ((uint8_t)(((uint8_t)(WUFFS_THUMBHASH__DIMENSION_CODES_FROM_HAS_ALPHA_AND_L_COUNT[self->private_impl.f_has_alpha][self->private_impl.f_l_count] >> 4u)) & 7u)); + self->private_impl.f_h_dimension_code = ((uint8_t)(((uint8_t)(WUFFS_THUMBHASH__DIMENSION_CODES_FROM_HAS_ALPHA_AND_L_COUNT[self->private_impl.f_has_alpha][self->private_impl.f_l_count] >> 0u)) & 7u)); + if (self->private_impl.f_is_landscape != 0u) { + v_swap = self->private_impl.f_w_dimension_code; + self->private_impl.f_w_dimension_code = self->private_impl.f_h_dimension_code; + self->private_impl.f_h_dimension_code = v_swap; } - self->private_data.s_do_decode_image_config.scratch = ((uint32_t)(self->private_impl.f_header_id_length)); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16); - if (self->private_data.s_do_decode_image_config.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { - self->private_data.s_do_decode_image_config.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); - iop_a_src = io2_a_src; - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; + if (self->private_impl.f_is_landscape != 0u) { + self->private_impl.f_lx = ((uint32_t)(((uint8_t)(7u - ((uint8_t)(2u * self->private_impl.f_has_alpha)))))); + self->private_impl.f_ly = ((uint32_t)(wuffs_base__u8__max(self->private_impl.f_l_count, 3u))); + } else { + self->private_impl.f_lx = ((uint32_t)(wuffs_base__u8__max(self->private_impl.f_l_count, 3u))); + self->private_impl.f_ly = ((uint32_t)(((uint8_t)(7u - ((uint8_t)(2u * self->private_impl.f_has_alpha)))))); } - iop_a_src += self->private_data.s_do_decode_image_config.scratch; - if (self->private_impl.f_header_color_map_type != 0u) { - while (v_i < ((uint32_t)(self->private_impl.f_header_color_map_length))) { - if (self->private_impl.f_header_color_map_entry_size == 24u) { - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(17); - uint32_t t_10; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 3)) { - t_10 = ((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(18); - 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_10 = ((uint32_t)(*scratch >> 56)); - *scratch <<= 8; - *scratch >>= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_10; - if (num_bits_10 == 16) { - t_10 = ((uint32_t)(*scratch)); - break; - } - num_bits_10 += 8u; - *scratch |= ((uint64_t)(num_bits_10)) << 56; - } - } - v_c32 = t_10; - } - self->private_data.f_src_palette[(((v_i & 255u) * 4u) + 0u)] = ((uint8_t)((v_c32 >> 0u))); - self->private_data.f_src_palette[(((v_i & 255u) * 4u) + 1u)] = ((uint8_t)((v_c32 >> 8u))); - self->private_data.f_src_palette[(((v_i & 255u) * 4u) + 2u)] = ((uint8_t)((v_c32 >> 16u))); - self->private_data.f_src_palette[(((v_i & 255u) * 4u) + 3u)] = 255u; - } else if (self->private_impl.f_header_color_map_entry_size == 32u) { - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(19); - uint32_t t_11; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_11 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src); - iop_a_src += 4; - } else { - self->private_data.s_do_decode_image_config.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(20); - 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_11 = ((uint32_t)(*scratch >> 56)); - *scratch <<= 8; - *scratch >>= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_11; - if (num_bits_11 == 24) { - t_11 = ((uint32_t)(*scratch)); - break; - } - num_bits_11 += 8u; - *scratch |= ((uint64_t)(num_bits_11)) << 56; - } - } - v_c32 = t_11; - } - self->private_data.f_src_palette[(((v_i & 255u) * 4u) + 0u)] = ((uint8_t)((v_c32 >> 0u))); - self->private_data.f_src_palette[(((v_i & 255u) * 4u) + 1u)] = ((uint8_t)((v_c32 >> 8u))); - self->private_data.f_src_palette[(((v_i & 255u) * 4u) + 2u)] = ((uint8_t)((v_c32 >> 16u))); - self->private_data.f_src_palette[(((v_i & 255u) * 4u) + 3u)] = ((uint8_t)((v_c32 >> 24u))); - } else { - { - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(21); - uint32_t t_12; - if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) { - t_12 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src))); - iop_a_src += 2; - } else { - self->private_data.s_do_decode_image_config.scratch = 0; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(22); - 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_12 = ((uint32_t)(*scratch >> 56)); - *scratch <<= 8; - *scratch >>= 8; - *scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_12; - if (num_bits_12 == 8) { - t_12 = ((uint32_t)(*scratch)); - break; - } - num_bits_12 += 8u; - *scratch |= ((uint64_t)(num_bits_12)) << 56; - } - } - v_c32 = t_12; - } - v_c5 = (31u & (v_c32 >> 0u)); - self->private_data.f_src_palette[(((v_i & 255u) * 4u) + 0u)] = ((uint8_t)(((v_c5 << 3u) | (v_c5 >> 2u)))); - v_c5 = (31u & (v_c32 >> 5u)); - self->private_data.f_src_palette[(((v_i & 255u) * 4u) + 1u)] = ((uint8_t)(((v_c5 << 3u) | (v_c5 >> 2u)))); - v_c5 = (31u & (v_c32 >> 10u)); - self->private_data.f_src_palette[(((v_i & 255u) * 4u) + 2u)] = ((uint8_t)(((v_c5 << 3u) | (v_c5 >> 2u)))); - self->private_data.f_src_palette[(((v_i & 255u) * 4u) + 3u)] = 255u; + self->private_impl.f_frame_config_io_position = 8u; + if (self->private_impl.f_has_alpha != 0u) { + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } - v_i += 1u; - } - while (v_i < 256u) { - self->private_data.f_src_palette[((v_i * 4u) + 0u)] = 0u; - self->private_data.f_src_palette[((v_i * 4u) + 1u)] = 0u; - self->private_data.f_src_palette[((v_i * 4u) + 2u)] = 0u; - self->private_data.f_src_palette[((v_i * 4u) + 3u)] = 255u; - v_i += 1u; + uint32_t t_3 = *iop_a_src++; + v_c32 = t_3; } + self->private_impl.f_a_dc = (((uint64_t)(((v_c32 >> 0u) & 15u))) << 42u); + self->private_impl.f_a_scale = ((uint8_t)(((v_c32 >> 4u) & 15u))); + self->private_impl.f_frame_config_io_position = 9u; + } + if (self->private_impl.f_quirk_just_raw_thumbhash) { +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + self->private_impl.f_frame_config_io_position -= 3u; +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + } + self->private_impl.f_pixfmt = 2415954056u; + if (self->private_impl.f_has_alpha != 0u) { + self->private_impl.f_pixfmt = 2164295816u; } - self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))); if (a_dst != NULL) { wuffs_base__image_config__set( a_dst, - self->private_impl.f_src_pixfmt, + self->private_impl.f_pixfmt, 0u, - self->private_impl.f_width, - self->private_impl.f_height, - self->private_impl.f_frame_config_io_position, - self->private_impl.f_opaque); + ((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_w_dimension_code])), + ((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_h_dimension_code])), + ((uint64_t)(self->private_impl.f_frame_config_io_position)), + (self->private_impl.f_has_alpha == 0u)); } self->private_impl.f_call_sequence = 32u; @@ -69758,7 +75009,6 @@ wuffs_tga__decoder__do_decode_image_config( goto suspend; suspend: self->private_impl.p_do_decode_image_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; - self->private_data.s_do_decode_image_config.v_i = v_i; goto exit; exit: @@ -69769,12 +75019,12 @@ wuffs_tga__decoder__do_decode_image_config( return status; } -// -------- func tga.decoder.decode_frame_config +// -------- func thumbhash.decoder.decode_frame_config WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_tga__decoder__decode_frame_config( - wuffs_tga__decoder* self, +wuffs_thumbhash__decoder__decode_frame_config( + wuffs_thumbhash__decoder* self, wuffs_base__frame_config* a_dst, wuffs_base__io_buffer* a_src) { if (!self) { @@ -69806,11 +75056,11 @@ wuffs_tga__decoder__decode_frame_config( while (true) { { - wuffs_base__status t_0 = wuffs_tga__decoder__do_decode_frame_config(self, a_dst, a_src); + 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_tga__error__truncated_input); + status = wuffs_base__make_status(wuffs_thumbhash__error__truncated_input); goto exit; } status = v_status; @@ -69835,12 +75085,12 @@ wuffs_tga__decoder__decode_frame_config( return status; } -// -------- func tga.decoder.do_decode_frame_config +// -------- func thumbhash.decoder.do_decode_frame_config WUFFS_BASE__GENERATED_C_CODE static wuffs_base__status -wuffs_tga__decoder__do_decode_frame_config( - wuffs_tga__decoder* self, +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); @@ -69866,7 +75116,7 @@ wuffs_tga__decoder__do_decode_frame_config( a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); } WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - status = wuffs_tga__decoder__do_decode_image_config(self, NULL, a_src); + 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; } @@ -69874,7 +75124,7 @@ wuffs_tga__decoder__do_decode_frame_config( goto suspend; } } else if (self->private_impl.f_call_sequence == 40u) { - if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) { + if (((uint64_t)(self->private_impl.f_frame_config_io_position)) != 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; } @@ -69892,15 +75142,15 @@ wuffs_tga__decoder__do_decode_frame_config( wuffs_base__utility__make_rect_ie_u32( 0u, 0u, - self->private_impl.f_width, - self->private_impl.f_height), + ((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_w_dimension_code])), + ((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_h_dimension_code]))), ((wuffs_base__flicks)(0u)), 0u, - self->private_impl.f_frame_config_io_position, + ((uint64_t)(self->private_impl.f_frame_config_io_position)), 0u, - self->private_impl.f_opaque, + (self->private_impl.f_has_alpha == 0u), false, - 4278190080u); + 0u); } self->private_impl.f_call_sequence = 64u; @@ -69922,12 +75172,12 @@ wuffs_tga__decoder__do_decode_frame_config( return status; } -// -------- func tga.decoder.decode_frame +// -------- func thumbhash.decoder.decode_frame WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_tga__decoder__decode_frame( - wuffs_tga__decoder* self, +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, @@ -69949,368 +75199,308 @@ wuffs_tga__decoder__decode_frame( 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_tga__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_tga__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 tga.decoder.do_decode_frame - -WUFFS_BASE__GENERATED_C_CODE -static wuffs_base__status -wuffs_tga__decoder__do_decode_frame( - wuffs_tga__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); - wuffs_base__pixel_format v_dst_pixfmt = {0}; - uint32_t v_dst_bits_per_pixel = 0; - uint64_t v_dst_bytes_per_pixel = 0; - uint32_t v_dst_x = 0; - uint32_t v_dst_y = 0; - wuffs_base__table_u8 v_tab = {0}; - wuffs_base__slice_u8 v_dst_palette = {0}; - wuffs_base__slice_u8 v_dst = {0}; - uint64_t v_dst_start = 0; - wuffs_base__slice_u8 v_src_palette = {0}; - uint64_t v_mark = 0; - uint64_t v_num_pixels64 = 0; - uint32_t v_num_pixels32 = 0; - uint32_t v_lit_length = 0; - uint32_t v_run_length = 0; - uint64_t v_num_dst_bytes = 0; - uint32_t v_num_src_bytes = 0; - uint32_t v_c32 = 0; - uint32_t v_c5 = 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_frame; - if (coro_susp_point) { - v_dst_bytes_per_pixel = self->private_data.s_do_decode_frame.v_dst_bytes_per_pixel; - v_dst_x = self->private_data.s_do_decode_frame.v_dst_x; - v_dst_y = self->private_data.s_do_decode_frame.v_dst_y; - v_mark = self->private_data.s_do_decode_frame.v_mark; - v_num_pixels32 = self->private_data.s_do_decode_frame.v_num_pixels32; - v_lit_length = self->private_data.s_do_decode_frame.v_lit_length; - v_run_length = self->private_data.s_do_decode_frame.v_run_length; - v_num_dst_bytes = self->private_data.s_do_decode_frame.v_num_dst_bytes; - } - 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) { - if (a_src) { - a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); - } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - status = wuffs_tga__decoder__do_decode_frame_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 { - status = wuffs_base__make_status(wuffs_base__note__end_of_data); - goto ok; - } - if (self->private_impl.f_header_color_map_type != 0u) { - v_src_palette = wuffs_base__make_slice_u8(self->private_data.f_src_palette, 1024); - } - 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_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024)), - wuffs_base__utility__make_pixel_format(self->private_impl.f_src_pixfmt), - v_src_palette, - 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; - } - 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) { - status = wuffs_base__make_status(wuffs_base__error__unsupported_option); - goto exit; - } - v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8u))); - if (((uint8_t)(self->private_impl.f_header_image_descriptor & 32u)) == 0u) { - v_dst_y = ((uint32_t)(self->private_impl.f_height - 1u)); - } - if (((uint8_t)(self->private_impl.f_header_image_type & 8u)) == 0u) { - v_lit_length = self->private_impl.f_width; - } - label__resume__continue:; - while (true) { - v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0u); - v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024)); - while (v_dst_y < self->private_impl.f_height) { - v_dst = wuffs_private_impl__table_u8__row_u32(v_tab, v_dst_y); - v_dst_start = (((uint64_t)(v_dst_x)) * v_dst_bytes_per_pixel); - if (v_dst_start <= ((uint64_t)(v_dst.len))) { - v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_dst_start); - } else { - v_dst = wuffs_base__utility__empty_slice_u8(); - } - while (v_dst_x < self->private_impl.f_width) { - if (self->private_impl.f_src_bytes_per_pixel > 0u) { - if (v_lit_length > 0u) { - v_mark = ((uint64_t)(iop_a_src - io0_a_src)); - v_num_pixels64 = (((uint64_t)(io2_a_src - iop_a_src)) / ((uint64_t)(self->private_impl.f_src_bytes_per_pixel))); - v_num_pixels32 = ((uint32_t)(wuffs_base__u64__min(v_num_pixels64, ((uint64_t)(v_lit_length))))); - v_num_dst_bytes = (((uint64_t)(v_num_pixels32)) * v_dst_bytes_per_pixel); - v_num_src_bytes = (v_num_pixels32 * self->private_impl.f_src_bytes_per_pixel); - self->private_data.s_do_decode_frame.scratch = v_num_src_bytes; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); - if (self->private_data.s_do_decode_frame.scratch > ((uint64_t)(io2_a_src - iop_a_src))) { - self->private_data.s_do_decode_frame.scratch -= ((uint64_t)(io2_a_src - iop_a_src)); - iop_a_src = io2_a_src; - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - goto suspend; - } - iop_a_src += self->private_data.s_do_decode_frame.scratch; - wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_private_impl__io__since(v_mark, ((uint64_t)(iop_a_src - io0_a_src)), io0_a_src)); - if (v_num_dst_bytes <= ((uint64_t)(v_dst.len))) { - v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_num_dst_bytes); - } else { - v_dst = wuffs_base__utility__empty_slice_u8(); - } - v_dst_x += v_num_pixels32; - v_lit_length = (((uint32_t)(v_lit_length - v_num_pixels32)) & 65535u); - if (v_lit_length > 0u) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3); - goto label__resume__continue; - } - } else if (v_run_length > 0u) { - v_run_length -= 1u; - wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, self->private_impl.f_scratch_bytes_per_pixel)); - if (v_dst_bytes_per_pixel <= ((uint64_t)(v_dst.len))) { - v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_dst_bytes_per_pixel); - } - v_dst_x += 1u; - } else { - if (((uint64_t)(io2_a_src - iop_a_src)) <= 0u) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4); - goto label__resume__continue; - } - if (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) < 128u) { - v_lit_length = (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) + 1u); - iop_a_src += 1u; - if ((v_lit_length + v_dst_x) > self->private_impl.f_width) { - status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding); - goto exit; - } - } else { - if (self->private_impl.f_src_bytes_per_pixel == 1u) { - if (((uint64_t)(io2_a_src - iop_a_src)) < 2u) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5); - goto label__resume__continue; - } - v_run_length = ((((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) & 127u) + 1u); - iop_a_src += 1u; - self->private_data.f_scratch[0u] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); - iop_a_src += 1u; - } else if (self->private_impl.f_src_bytes_per_pixel == 3u) { - if (((uint64_t)(io2_a_src - iop_a_src)) < 4u) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6); - goto label__resume__continue; - } - v_run_length = ((((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) & 127u) + 1u); - iop_a_src += 1u; - self->private_data.f_scratch[0u] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); - iop_a_src += 1u; - self->private_data.f_scratch[1u] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); - iop_a_src += 1u; - self->private_data.f_scratch[2u] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); - iop_a_src += 1u; - } else { - if (((uint64_t)(io2_a_src - iop_a_src)) < 5u) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7); - goto label__resume__continue; - } - v_run_length = ((((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) & 127u) + 1u); - iop_a_src += 1u; - self->private_data.f_scratch[0u] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); - iop_a_src += 1u; - self->private_data.f_scratch[1u] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); - iop_a_src += 1u; - self->private_data.f_scratch[2u] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); - iop_a_src += 1u; - self->private_data.f_scratch[3u] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src); - iop_a_src += 1u; - } - if ((v_run_length + v_dst_x) > self->private_impl.f_width) { - status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding); - goto exit; - } - } - } - } else { - if (v_lit_length > 0u) { - if (((uint64_t)(io2_a_src - iop_a_src)) < 2u) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8); - goto label__resume__continue; - } - v_c32 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src))); - iop_a_src += 2u; - v_c5 = (31u & (v_c32 >> 0u)); - self->private_data.f_scratch[0u] = ((uint8_t)(((v_c5 << 3u) | (v_c5 >> 2u)))); - v_c5 = (31u & (v_c32 >> 5u)); - self->private_data.f_scratch[1u] = ((uint8_t)(((v_c5 << 3u) | (v_c5 >> 2u)))); - v_c5 = (31u & (v_c32 >> 10u)); - self->private_data.f_scratch[2u] = ((uint8_t)(((v_c5 << 3u) | (v_c5 >> 2u)))); - self->private_data.f_scratch[3u] = 255u; - wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, 4)); - if (v_dst_bytes_per_pixel <= ((uint64_t)(v_dst.len))) { - v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_dst_bytes_per_pixel); - } - v_dst_x += 1u; - v_lit_length -= 1u; - } else if (v_run_length > 0u) { - v_run_length -= 1u; - wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, self->private_impl.f_scratch_bytes_per_pixel)); - if (v_dst_bytes_per_pixel <= ((uint64_t)(v_dst.len))) { - v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_dst_bytes_per_pixel); - } - v_dst_x += 1u; - } else { - if (((uint64_t)(io2_a_src - iop_a_src)) <= 0u) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9); - goto label__resume__continue; - } - if (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) < 128u) { - v_lit_length = (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) + 1u); - iop_a_src += 1u; - if ((v_lit_length + v_dst_x) > self->private_impl.f_width) { - status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding); - goto exit; - } - } else { - if (((uint64_t)(io2_a_src - iop_a_src)) < 3u) { - status = wuffs_base__make_status(wuffs_base__suspension__short_read); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10); - goto label__resume__continue; - } - v_run_length = ((((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) & 127u) + 1u); - iop_a_src += 1u; - v_c32 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src))); - iop_a_src += 2u; - v_c5 = (31u & (v_c32 >> 0u)); - self->private_data.f_scratch[0u] = ((uint8_t)(((v_c5 << 3u) | (v_c5 >> 2u)))); - v_c5 = (31u & (v_c32 >> 5u)); - self->private_data.f_scratch[1u] = ((uint8_t)(((v_c5 << 3u) | (v_c5 >> 2u)))); - v_c5 = (31u & (v_c32 >> 10u)); - self->private_data.f_scratch[2u] = ((uint8_t)(((v_c5 << 3u) | (v_c5 >> 2u)))); - self->private_data.f_scratch[3u] = 255u; - if ((v_run_length + v_dst_x) > self->private_impl.f_width) { - status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding); - goto exit; - } - } + 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_coeffs(self, a_src); + if (status.repr) { + goto suspend; + } + wuffs_thumbhash__decoder__from_coeffs_to_pixels(self); + 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_coeffs + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__status +wuffs_thumbhash__decoder__from_src_to_coeffs( + wuffs_thumbhash__decoder* self, + wuffs_base__io_buffer* a_src) { + wuffs_base__status status = wuffs_base__make_status(NULL); + + uint8_t v_c8 = 0; + uint32_t v_cy = 0; + uint32_t v_cx = 0; + uint32_t v_i = 0; + bool v_has_bits = false; + + 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_from_src_to_coeffs; + if (coro_susp_point) { + v_cy = self->private_data.s_from_src_to_coeffs.v_cy; + v_cx = self->private_data.s_from_src_to_coeffs.v_cx; + v_i = self->private_data.s_from_src_to_coeffs.v_i; + v_has_bits = self->private_data.s_from_src_to_coeffs.v_has_bits; + } + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + + v_i = 0u; + v_cy = 0u; + while (v_cy < self->private_impl.f_ly) { + v_cx = 0u; + if (v_cy == 0u) { + v_cx = 1u; + } + while (((uint32_t)(v_cx * self->private_impl.f_ly)) < ((uint32_t)(self->private_impl.f_lx * ((uint32_t)(self->private_impl.f_ly - v_cy))))) { + if (v_has_bits) { + v_has_bits = false; +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + v_c8 >>= 4u; +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + } else { + v_has_bits = true; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; } + uint8_t t_0 = *iop_a_src++; + v_c8 = t_0; } } - v_dst_x = 0u; - if (((uint8_t)(self->private_impl.f_header_image_descriptor & 32u)) == 0u) { - v_dst_y -= 1u; - } else { - v_dst_y += 1u; + self->private_data.f_lac[(v_i & 31u)] = ((uint32_t)(((uint32_t)(((uint32_t)(self->private_impl.f_l_scale)) * 126u)) * wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__FROM_4_BITS_TO_PLUS_MINUS_1_00[((uint8_t)(v_c8 & 15u))]))); + v_i += 1u; + v_cx += 1u; + } + v_cy += 1u; + } + v_i = 0u; + v_cx = 0u; + while (v_cx < 5u) { + if (v_has_bits) { + v_has_bits = false; +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + v_c8 >>= 4u; +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + } else { + v_has_bits = true; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_1 = *iop_a_src++; + v_c8 = t_1; } - if (((uint8_t)(self->private_impl.f_header_image_type & 8u)) == 0u) { - v_lit_length = self->private_impl.f_width; + } + self->private_data.f_pac[(v_i & 7u)] = ((uint32_t)(((uint32_t)(((uint32_t)(self->private_impl.f_p_scale)) * 62u)) * wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__FROM_4_BITS_TO_PLUS_MINUS_1_25[((uint8_t)(v_c8 & 15u))]))); + v_i += 1u; + v_cx += 1u; + } + v_i = 0u; + v_cx = 0u; + while (v_cx < 5u) { + if (v_has_bits) { + v_has_bits = false; +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + v_c8 >>= 4u; +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + } else { + v_has_bits = true; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_2 = *iop_a_src++; + v_c8 = t_2; } } - break; + self->private_data.f_qac[(v_i & 7u)] = ((uint32_t)(((uint32_t)(((uint32_t)(self->private_impl.f_q_scale)) * 62u)) * wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__FROM_4_BITS_TO_PLUS_MINUS_1_25[((uint8_t)(v_c8 & 15u))]))); + v_i += 1u; + v_cx += 1u; + } + if (self->private_impl.f_has_alpha == 0u) { + status = wuffs_base__make_status(NULL); + goto ok; + } + v_i = 0u; + v_cx = 0u; + while (v_cx < 14u) { + if (v_has_bits) { + v_has_bits = false; +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + v_c8 >>= 4u; +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + } else { + v_has_bits = true; + { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); + if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) { + status = wuffs_base__make_status(wuffs_base__suspension__short_read); + goto suspend; + } + uint8_t t_3 = *iop_a_src++; + v_c8 = t_3; + } + } + self->private_data.f_aac[(v_i & 15u)] = ((uint32_t)(((uint32_t)(((uint32_t)(self->private_impl.f_a_scale)) * 2u)) * wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__FROM_4_BITS_TO_PLUS_MINUS_1_00[((uint8_t)(v_c8 & 15u))]))); + v_i += 1u; + v_cx += 1u; } - self->private_impl.f_call_sequence = 96u; ok: - self->private_impl.p_do_decode_frame = 0; + self->private_impl.p_from_src_to_coeffs = 0; goto exit; } goto suspend; suspend: - self->private_impl.p_do_decode_frame = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; - self->private_data.s_do_decode_frame.v_dst_bytes_per_pixel = v_dst_bytes_per_pixel; - self->private_data.s_do_decode_frame.v_dst_x = v_dst_x; - self->private_data.s_do_decode_frame.v_dst_y = v_dst_y; - self->private_data.s_do_decode_frame.v_mark = v_mark; - self->private_data.s_do_decode_frame.v_num_pixels32 = v_num_pixels32; - self->private_data.s_do_decode_frame.v_lit_length = v_lit_length; - self->private_data.s_do_decode_frame.v_run_length = v_run_length; - self->private_data.s_do_decode_frame.v_num_dst_bytes = v_num_dst_bytes; + self->private_impl.p_from_src_to_coeffs = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_data.s_from_src_to_coeffs.v_cy = v_cy; + self->private_data.s_from_src_to_coeffs.v_cx = v_cx; + self->private_data.s_from_src_to_coeffs.v_i = v_i; + self->private_data.s_from_src_to_coeffs.v_has_bits = v_has_bits; goto exit; exit: @@ -70321,12 +75511,195 @@ wuffs_tga__decoder__do_decode_frame( return status; } -// -------- func tga.decoder.frame_dirty_rect +// -------- func thumbhash.decoder.from_coeffs_to_pixels + +WUFFS_BASE__GENERATED_C_CODE +static wuffs_base__empty_struct +wuffs_thumbhash__decoder__from_coeffs_to_pixels( + wuffs_thumbhash__decoder* self) { + uint32_t v_h = 0; + uint32_t v_w = 0; + uint32_t v_fy[8] = {0}; + uint32_t v_fx[8] = {0}; + uint32_t v_cosines_base_y = 0; + uint32_t v_cosines_base_x = 0; + uint32_t v_y = 0; + uint32_t v_x = 0; + uint32_t v_f = 0; + uint64_t v_l = 0; + uint64_t v_p = 0; + uint64_t v_q = 0; + uint64_t v_b = 0; + uint64_t v_g = 0; + uint64_t v_r = 0; + uint64_t v_a = 0; + uint32_t v_i = 0; + uint32_t v_cy = 0; + uint32_t v_cx = 0; + + v_h = ((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_h_dimension_code])); + v_w = ((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_w_dimension_code])); + v_fy[0u] = 16384u; + v_fx[0u] = 16384u; + v_a = 255u; + v_y = 0u; + while (v_y < v_h) { + v_cosines_base_y = ((uint32_t)(WUFFS_THUMBHASH__CUMULATIVE_DIMENSIONS[self->private_impl.f_h_dimension_code])); + v_fy[1u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_y + v_y)][0u]); + v_fy[2u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_y + v_y)][1u]); + v_fy[3u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_y + v_y)][2u]); + v_fy[4u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_y + v_y)][3u]); + v_fy[5u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_y + v_y)][4u]); + v_fy[6u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_y + v_y)][5u]); + v_x = 0u; + while (v_x < v_w) { + v_cosines_base_x = ((uint32_t)(WUFFS_THUMBHASH__CUMULATIVE_DIMENSIONS[self->private_impl.f_w_dimension_code])); + v_fx[1u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_x + v_x)][0u]); + v_fx[2u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_x + v_x)][1u]); + v_fx[3u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_x + v_x)][2u]); + v_fx[4u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_x + v_x)][3u]); + v_fx[5u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_x + v_x)][4u]); + v_fx[6u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_x + v_x)][5u]); + v_l = self->private_impl.f_l_dc; + v_i = 0u; + v_cy = 0u; + while (v_cy < self->private_impl.f_ly) { + v_cx = 0u; + if (v_cy == 0u) { + v_cx = 1u; + } + while (((uint32_t)(v_cx * self->private_impl.f_ly)) < ((uint32_t)(self->private_impl.f_lx * ((uint32_t)(self->private_impl.f_ly - v_cy))))) { + v_f = ((uint32_t)(v_fx[(v_cx & 7u)] * v_fy[(v_cy & 7u)])); + v_l += ((uint64_t)(wuffs_base__utility__sign_extend_convert_u32_u64(v_f) * wuffs_base__utility__sign_extend_convert_u32_u64(self->private_data.f_lac[(v_i & 31u)]))); + v_i += 1u; + v_cx += 1u; + } + v_cy += 1u; + } + v_p = self->private_impl.f_p_dc; + v_q = self->private_impl.f_q_dc; + v_i = 0u; + v_cy = 0u; + while (v_cy < 3u) { + v_cx = 0u; + if (v_cy == 0u) { + v_cx = 1u; + } + while (v_cx < (3u - v_cy)) { + v_f = ((uint32_t)(v_fx[v_cx] * v_fy[v_cy])); + v_p += ((uint64_t)(wuffs_base__utility__sign_extend_convert_u32_u64(v_f) * wuffs_base__utility__sign_extend_convert_u32_u64(self->private_data.f_pac[(v_i & 7u)]))); + v_q += ((uint64_t)(wuffs_base__utility__sign_extend_convert_u32_u64(v_f) * wuffs_base__utility__sign_extend_convert_u32_u64(self->private_data.f_qac[(v_i & 7u)]))); + v_i += 1u; + v_cx += 1u; + } + v_cy += 1u; + } + v_b = ((uint64_t)(v_l - wuffs_base__utility__i64_divide(((uint64_t)(2u * v_p)), 3u))); + v_r = wuffs_base__utility__sign_extend_rshift_u64(((uint64_t)(((uint64_t)(((uint64_t)(3u * v_l)) + v_q)) - v_b)), 1u); + v_g = ((uint64_t)(v_r - v_q)); + if ((v_b >> 63u) != 0u) { + v_b = 0u; + } else if (v_b >= 8589384836185950u) { + v_b = 255u; + } else { + v_b /= 33683862102690u; + } + if ((v_g >> 63u) != 0u) { + v_g = 0u; + } else if (v_g >= 8589384836185950u) { + v_g = 255u; + } else { + v_g /= 33683862102690u; + } + if ((v_r >> 63u) != 0u) { + v_r = 0u; + } else if (v_r >= 8589384836185950u) { + v_r = 255u; + } else { + v_r /= 33683862102690u; + } + if (self->private_impl.f_has_alpha != 0u) { + v_a = self->private_impl.f_a_dc; + v_i = 0u; + v_cy = 0u; + while (v_cy < 5u) { + v_cx = 0u; + if (v_cy == 0u) { + v_cx = 1u; + } + while (v_cx < (5u - v_cy)) { + v_f = ((uint32_t)(v_fx[v_cx] * v_fy[v_cy])); + v_a += ((uint64_t)(wuffs_base__utility__sign_extend_convert_u32_u64(v_f) * wuffs_base__utility__sign_extend_convert_u32_u64(self->private_data.f_aac[(v_i & 15u)]))); + v_i += 1u; + v_cx += 1u; + } + v_cy += 1u; + } + if ((v_a >> 63u) != 0u) { + v_a = 0u; + } else if (v_a >= 65970697666500u) { + v_a = 255u; + } else { + v_a /= 258708618300u; + } + } + self->private_data.f_pixels[v_y][((4u * v_x) + 0u)] = ((uint8_t)(v_b)); + self->private_data.f_pixels[v_y][((4u * v_x) + 1u)] = ((uint8_t)(v_g)); + self->private_data.f_pixels[v_y][((4u * v_x) + 2u)] = ((uint8_t)(v_r)); + self->private_data.f_pixels[v_y][((4u * v_x) + 3u)] = ((uint8_t)(v_a)); + v_x += 1u; + } + v_y += 1u; + } + return wuffs_base__make_empty_struct(); +} + +// -------- 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) { + uint32_t v_h = 0; + uint32_t v_w = 0; + 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_h = ((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_h_dimension_code])); + v_w = ((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_w_dimension_code])); + 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)((v_w * v_dst_bytes_per_pixel))); + v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0u); + while (v_y < v_h) { + v_src = wuffs_base__make_slice_u8(self->private_data.f_pixels[v_y], (v_w * 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_tga__decoder__frame_dirty_rect( - const wuffs_tga__decoder* self) { +wuffs_thumbhash__decoder__frame_dirty_rect( + const wuffs_thumbhash__decoder* self) { if (!self) { return wuffs_base__utility__empty_rect_ie_u32(); } @@ -70338,16 +75711,16 @@ wuffs_tga__decoder__frame_dirty_rect( return wuffs_base__utility__make_rect_ie_u32( 0u, 0u, - self->private_impl.f_width, - self->private_impl.f_height); + ((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_w_dimension_code])), + ((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_h_dimension_code]))); } -// -------- func tga.decoder.num_animation_loops +// -------- func thumbhash.decoder.num_animation_loops WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC uint32_t -wuffs_tga__decoder__num_animation_loops( - const wuffs_tga__decoder* self) { +wuffs_thumbhash__decoder__num_animation_loops( + const wuffs_thumbhash__decoder* self) { if (!self) { return 0; } @@ -70359,12 +75732,12 @@ wuffs_tga__decoder__num_animation_loops( return 0u; } -// -------- func tga.decoder.num_decoded_frame_configs +// -------- func thumbhash.decoder.num_decoded_frame_configs WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC uint64_t -wuffs_tga__decoder__num_decoded_frame_configs( - const wuffs_tga__decoder* self) { +wuffs_thumbhash__decoder__num_decoded_frame_configs( + const wuffs_thumbhash__decoder* self) { if (!self) { return 0; } @@ -70379,12 +75752,12 @@ wuffs_tga__decoder__num_decoded_frame_configs( return 0u; } -// -------- func tga.decoder.num_decoded_frames +// -------- func thumbhash.decoder.num_decoded_frames WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC uint64_t -wuffs_tga__decoder__num_decoded_frames( - const wuffs_tga__decoder* self) { +wuffs_thumbhash__decoder__num_decoded_frames( + const wuffs_thumbhash__decoder* self) { if (!self) { return 0; } @@ -70399,12 +75772,12 @@ wuffs_tga__decoder__num_decoded_frames( return 0u; } -// -------- func tga.decoder.restart_frame +// -------- func thumbhash.decoder.restart_frame WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_tga__decoder__restart_frame( - wuffs_tga__decoder* self, +wuffs_thumbhash__decoder__restart_frame( + wuffs_thumbhash__decoder* self, uint64_t a_index, uint64_t a_io_position) { if (!self) { @@ -70420,31 +75793,30 @@ wuffs_tga__decoder__restart_frame( if (self->private_impl.f_call_sequence < 32u) { return wuffs_base__make_status(wuffs_base__error__bad_call_sequence); } - if (a_index != 0u) { + if ((a_index != 0u) || (a_io_position != ((uint64_t)(self->private_impl.f_frame_config_io_position)))) { return wuffs_base__make_status(wuffs_base__error__bad_argument); } self->private_impl.f_call_sequence = 40u; - self->private_impl.f_frame_config_io_position = a_io_position; return wuffs_base__make_status(NULL); } -// -------- func tga.decoder.set_report_metadata +// -------- func thumbhash.decoder.set_report_metadata WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct -wuffs_tga__decoder__set_report_metadata( - wuffs_tga__decoder* self, +wuffs_thumbhash__decoder__set_report_metadata( + wuffs_thumbhash__decoder* self, uint32_t a_fourcc, bool a_report) { return wuffs_base__make_empty_struct(); } -// -------- func tga.decoder.tell_me_more +// -------- func thumbhash.decoder.tell_me_more WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__status -wuffs_tga__decoder__tell_me_more( - wuffs_tga__decoder* self, +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) { @@ -70482,12 +75854,12 @@ wuffs_tga__decoder__tell_me_more( return status; } -// -------- func tga.decoder.workbuf_len +// -------- func thumbhash.decoder.workbuf_len WUFFS_BASE__GENERATED_C_CODE WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 -wuffs_tga__decoder__workbuf_len( - const wuffs_tga__decoder* self) { +wuffs_thumbhash__decoder__workbuf_len( + const wuffs_thumbhash__decoder* self) { if (!self) { return wuffs_base__utility__empty_range_ii_u64(); } @@ -70499,7 +75871,7 @@ wuffs_tga__decoder__workbuf_len( return wuffs_base__utility__make_range_ii_u64(0u, 0u); } -#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA) +#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__THUMBHASH) #if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__VP8) @@ -76420,7 +81792,7 @@ WUFFS_XZ__FILTER_06_IA64_BRANCH_TABLE[32] WUFFS_BASE__POTENTIALLY_UNUSED = { 4u, 4u, 0u, 0u, 4u, 4u, 0u, 0u, }; -#define WUFFS_XZ__QUIRKS_BASE 2021322752u +#define WUFFS_XZ__QUIRKS_BASE 1963655168u static const uint8_t WUFFS_XZ__CHECKSUM_LENGTH[4] WUFFS_BASE__POTENTIALLY_UNUSED = { @@ -77164,7 +82536,7 @@ wuffs_xz__decoder__get_quirk( if (self->private_impl.f_ignore_checksum) { return 1u; } - } else if (a_key == 2021322752u) { + } else if (a_key == 1963655168u) { if (self->private_impl.f_standalone_format) { return 1u; } @@ -77193,7 +82565,7 @@ wuffs_xz__decoder__set_quirk( if (a_key == 1u) { self->private_impl.f_ignore_checksum = (a_value > 0u); return wuffs_base__make_status(NULL); - } else if (a_key == 2021322752u) { + } else if (a_key == 1963655168u) { self->private_impl.f_standalone_format = (a_value > 0u); return wuffs_base__make_status(NULL); } @@ -78517,7 +83889,7 @@ wuffs_xz__decoder__decode_block_header_sans_padding( uint8_t t_10 = *iop_a_src++; v_c8 = t_10; } - v_status = wuffs_lzma__decoder__set_quirk(&self->private_data.f_lzma, 1348001793u, (2u | (((uint64_t)(v_c8)) << 8u))); + v_status = wuffs_lzma__decoder__set_quirk(&self->private_data.f_lzma, 1290294273u, (2u | (((uint64_t)(v_c8)) << 8u))); if ( ! wuffs_base__status__is_ok(&v_status)) { status = wuffs_base__make_status(wuffs_xz__error__bad_filter); goto exit; @@ -79582,6 +84954,11 @@ DecodeImageCallbacks::SelectDecoder(uint32_t fourcc, return wuffs_bmp__decoder::alloc_as__wuffs_base__image_decoder(); #endif +#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ETC2) + case WUFFS_BASE__FOURCC__ETC2: + return wuffs_etc2__decoder::alloc_as__wuffs_base__image_decoder(); +#endif + #if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GIF) case WUFFS_BASE__FOURCC__GIF: return wuffs_gif__decoder::alloc_as__wuffs_base__image_decoder(); @@ -79616,9 +84993,14 @@ DecodeImageCallbacks::SelectDecoder(uint32_t fourcc, return wuffs_qoi__decoder::alloc_as__wuffs_base__image_decoder(); #endif -#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA) +#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TARGA) case WUFFS_BASE__FOURCC__TGA: - return wuffs_tga__decoder::alloc_as__wuffs_base__image_decoder(); + return wuffs_targa__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) @@ -79985,6 +85367,7 @@ DecodeImage0(wuffs_base__image_decoder::unique_ptr& image_decoder, wuffs_base__pixel_format pixel_format = callbacks.SelectPixfmt(image_config); if (pixel_format.repr != image_config.pixcfg.pixel_format().repr) { switch (pixel_format.repr) { + case WUFFS_BASE__PIXEL_FORMAT__Y: case WUFFS_BASE__PIXEL_FORMAT__BGR_565: case WUFFS_BASE__PIXEL_FORMAT__BGR: case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL: @@ -80738,6 +86121,537 @@ DecodeJson(DecodeJsonCallbacks& callbacks, #endif // defined(__cplusplus) && defined(WUFFS_BASE__HAVE_UNIQUE_PTR) + +// ---------------- Wuffs' reimplementation of the STB API. +// +// This is a drop-in replacement of that third-party library. +// +// Disabled by default, unless you #define the +// WUFFS_CONFIG__ENABLE_DROP_IN_REPLACEMENT__STB macro beforehand. +// +// For API docs, see https://github.com/nothings/stb + +#if defined(WUFFS_CONFIG__ENABLE_DROP_IN_REPLACEMENT__STB) + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// -------- + +#if defined(__GNUC__) +__thread const char* // + wuffs_drop_in__stb__g_failure_reason = NULL; +#elif defined(_MSC_VER) +__declspec(thread) const char* // + wuffs_drop_in__stb__g_failure_reason = NULL; +#else +const char* // + wuffs_drop_in__stb__g_failure_reason = NULL; +#endif + +// -------- + +static void // +wuffs_drop_in__stb__read( // + wuffs_base__io_buffer* srcbuf, // + stbi_io_callbacks const* clbk, // + void* user) { + uint8_t* ptr = wuffs_base__io_buffer__writer_pointer(srcbuf); + size_t len = wuffs_base__io_buffer__writer_length(srcbuf); + if (len > INT_MAX) { + len = INT_MAX; + } + int n = clbk->read(user, (char*)ptr, (int)len); + if (n > 0) { + srcbuf->meta.wi += (size_t)n; + } else { + srcbuf->meta.closed = clbk->eof(user); + } +} + +static wuffs_base__image_decoder* // +wuffs_drop_in__stb__make_decoder( // + wuffs_base__io_buffer* srcbuf, // + stbi_io_callbacks const* clbk, // + void* user) { + while (1) { + int32_t fourcc = wuffs_base__magic_number_guess_fourcc( + wuffs_base__io_buffer__reader_slice(srcbuf), srcbuf->meta.closed); + if (fourcc < 0) { + if (srcbuf->meta.closed || !clbk) { + break; + } + wuffs_drop_in__stb__read(srcbuf, clbk, user); + continue; + } + + switch (fourcc) { +#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BMP) + case WUFFS_BASE__FOURCC__BMP: + return wuffs_bmp__decoder__alloc_as__wuffs_base__image_decoder(); +#endif + +#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ETC2) + case WUFFS_BASE__FOURCC__ETC2: + return wuffs_etc2__decoder__alloc_as__wuffs_base__image_decoder(); +#endif + +#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GIF) + case WUFFS_BASE__FOURCC__GIF: + return wuffs_gif__decoder__alloc_as__wuffs_base__image_decoder(); +#endif + +#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__JPEG) + case WUFFS_BASE__FOURCC__JPEG: + return wuffs_jpeg__decoder__alloc_as__wuffs_base__image_decoder(); +#endif + +#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__NIE) + case WUFFS_BASE__FOURCC__NIE: + return wuffs_nie__decoder__alloc_as__wuffs_base__image_decoder(); +#endif + +#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__NETPBM) + case WUFFS_BASE__FOURCC__NPBM: + return wuffs_netpbm__decoder__alloc_as__wuffs_base__image_decoder(); +#endif + +#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__PNG) + case WUFFS_BASE__FOURCC__PNG: + return wuffs_png__decoder__alloc_as__wuffs_base__image_decoder(); +#endif + +#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__QOI) + case WUFFS_BASE__FOURCC__QOI: + return wuffs_qoi__decoder__alloc_as__wuffs_base__image_decoder(); +#endif + +#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TARGA) + case WUFFS_BASE__FOURCC__TGA: + return wuffs_targa__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(); +#endif + +#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WEBP) + case WUFFS_BASE__FOURCC__WEBP: + return wuffs_webp__decoder__alloc_as__wuffs_base__image_decoder(); +#endif + } + + wuffs_drop_in__stb__g_failure_reason = "unknown image type"; + break; + } + return NULL; +} + +// -------- + +static void* // +wuffs_drop_in__stb__load1( // + wuffs_base__io_buffer* srcbuf, // + stbi_io_callbacks const* clbk, // + void* user, // + wuffs_base__image_decoder* dec, // + wuffs_base__image_config* ic, // + uint32_t dst_pixfmt, // + int desired_channels, // + int info_only) { + // Favor faster decodes over rejecting invalid checksums. + wuffs_base__image_decoder__set_quirk(dec, WUFFS_BASE__QUIRK_IGNORE_CHECKSUM, + 1); + + while (1) { + wuffs_base__status status = + wuffs_base__image_decoder__decode_image_config(dec, ic, srcbuf); + if (status.repr == NULL) { + break; + } else if ((status.repr != wuffs_base__suspension__short_read) || !clbk) { + wuffs_drop_in__stb__g_failure_reason = status.repr; + return NULL; + } + + size_t wl = wuffs_base__io_buffer__writer_length(srcbuf); + wuffs_base__io_buffer__compact(srcbuf); + if (wl >= wuffs_base__io_buffer__writer_length(srcbuf)) { + wuffs_drop_in__stb__g_failure_reason = "I/O buffer is too small"; + return NULL; + } + wuffs_drop_in__stb__read(srcbuf, clbk, user); + } + + uint32_t w = wuffs_base__pixel_config__width(&ic->pixcfg); + uint32_t h = wuffs_base__pixel_config__height(&ic->pixcfg); + if ((w > 0xFFFFFF) || (h > 0xFFFFFF)) { + wuffs_drop_in__stb__g_failure_reason = "image is too large"; + return NULL; + } else if (info_only) { + return NULL; + } + + uint64_t pixbuf_len = (uint64_t)w * (uint64_t)h * (uint64_t)desired_channels; + uint64_t workbuf_len = wuffs_base__image_decoder__workbuf_len(dec).max_incl; +#if SIZE_MAX < 0xFFFFFFFFFFFFFFFFull + if ((pixbuf_len > ((uint64_t)SIZE_MAX)) || + (workbuf_len > ((uint64_t)SIZE_MAX))) { + wuffs_drop_in__stb__g_failure_reason = "image is too large"; + return NULL; + } +#endif + void* pixbuf_ptr = malloc((size_t)pixbuf_len); + if (!pixbuf_ptr) { + wuffs_drop_in__stb__g_failure_reason = "out of memory"; + return NULL; + } + void* workbuf_ptr = malloc((size_t)workbuf_len); + if (!workbuf_ptr) { + free(pixbuf_ptr); + wuffs_drop_in__stb__g_failure_reason = "out of memory"; + return NULL; + } + wuffs_base__slice_u8 workbuf = + wuffs_base__make_slice_u8(workbuf_ptr, (size_t)workbuf_len); + + wuffs_base__pixel_config pc = ((wuffs_base__pixel_config){}); + wuffs_base__pixel_config__set(&pc, dst_pixfmt, + WUFFS_BASE__PIXEL_SUBSAMPLING__NONE, w, h); + + wuffs_base__pixel_buffer pb = ((wuffs_base__pixel_buffer){}); + { + wuffs_base__status status = wuffs_base__pixel_buffer__set_from_slice( + &pb, &pc, wuffs_base__make_slice_u8(pixbuf_ptr, (size_t)pixbuf_len)); + if (status.repr) { + free(workbuf_ptr); + free(pixbuf_ptr); + wuffs_drop_in__stb__g_failure_reason = status.repr; + return NULL; + } + } + + while (1) { + wuffs_base__status status = wuffs_base__image_decoder__decode_frame( + dec, &pb, srcbuf, WUFFS_BASE__PIXEL_BLEND__SRC, workbuf, NULL); + if (status.repr == NULL) { + break; + } else if ((status.repr != wuffs_base__suspension__short_read) || !clbk) { + free(workbuf_ptr); + free(pixbuf_ptr); + wuffs_drop_in__stb__g_failure_reason = status.repr; + return NULL; + } + + size_t wl = wuffs_base__io_buffer__writer_length(srcbuf); + wuffs_base__io_buffer__compact(srcbuf); + if (wl >= wuffs_base__io_buffer__writer_length(srcbuf)) { + free(workbuf_ptr); + free(pixbuf_ptr); + wuffs_drop_in__stb__g_failure_reason = "I/O buffer is too small"; + return NULL; + } + wuffs_drop_in__stb__read(srcbuf, clbk, user); + } + + free(workbuf_ptr); + return pixbuf_ptr; +} + +static void* // +wuffs_drop_in__stb__load0( // + wuffs_base__io_buffer* srcbuf, // + stbi_io_callbacks const* clbk, // + void* user, // + int* x, // + int* y, // + int* channels_in_file, // + int desired_channels, // + int info_only) { + uint32_t dst_pixfmt = 0; + switch (desired_channels) { + case 1: + dst_pixfmt = WUFFS_BASE__PIXEL_FORMAT__Y; + break; + case 3: + dst_pixfmt = WUFFS_BASE__PIXEL_FORMAT__RGB; + break; + case 4: + dst_pixfmt = WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL; + break; + default: + wuffs_drop_in__stb__g_failure_reason = "unsupported format conversion"; + return NULL; + } + + wuffs_base__image_decoder* dec = + wuffs_drop_in__stb__make_decoder(srcbuf, clbk, user); + if (!dec) { + if (wuffs_drop_in__stb__g_failure_reason == NULL) { + wuffs_drop_in__stb__g_failure_reason = "couldn't allocate image decoder"; + } + return NULL; + } + + wuffs_base__image_config ic = ((wuffs_base__image_config){}); + stbi_uc* ret = wuffs_drop_in__stb__load1( + srcbuf, clbk, user, dec, &ic, dst_pixfmt, desired_channels, info_only); + free(dec); + + if (!info_only && !ret) { + return NULL; + } + + if (x) { + *x = (int)wuffs_base__pixel_config__width(&ic.pixcfg); + } + if (y) { + *y = (int)wuffs_base__pixel_config__height(&ic.pixcfg); + } + if (channels_in_file) { + wuffs_base__pixel_format src_pixfmt = + wuffs_base__pixel_config__pixel_format(&ic.pixcfg); + uint32_t n_color = wuffs_base__pixel_format__coloration(&src_pixfmt); + uint32_t n_alpha = wuffs_base__pixel_format__transparency(&src_pixfmt) != + WUFFS_BASE__PIXEL_ALPHA_TRANSPARENCY__OPAQUE; + *channels_in_file = (int)(n_color + n_alpha); + } + + return ret; +} + +// -------- + +WUFFS_DROP_IN__STB__MAYBE_STATIC int // +stbi_info_from_memory( // + stbi_uc const* buffer, // + int len, // + int* x, // + int* y, // + int* comp) { + wuffs_drop_in__stb__g_failure_reason = NULL; + if (len < 0) { + wuffs_drop_in__stb__g_failure_reason = "negative buffer length"; + return 0; + } else if (len == 0) { + wuffs_drop_in__stb__g_failure_reason = "empty buffer"; + return 0; + } + wuffs_base__io_buffer srcbuf = + wuffs_base__ptr_u8__reader((uint8_t*)(stbi_uc*)buffer, (size_t)len, true); + wuffs_drop_in__stb__load0(&srcbuf, NULL, NULL, x, y, comp, 1, 1); + return wuffs_drop_in__stb__g_failure_reason == NULL; +} + +WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* // +stbi_load_from_memory( // + stbi_uc const* buffer, // + int len, // + int* x, // + int* y, // + int* channels_in_file, // + int desired_channels) { + wuffs_drop_in__stb__g_failure_reason = NULL; + if (len < 0) { + wuffs_drop_in__stb__g_failure_reason = "negative buffer length"; + return NULL; + } else if (len == 0) { + wuffs_drop_in__stb__g_failure_reason = "empty buffer"; + return NULL; + } + wuffs_base__io_buffer srcbuf = + wuffs_base__ptr_u8__reader((uint8_t*)(stbi_uc*)buffer, (size_t)len, true); + return wuffs_drop_in__stb__load0(&srcbuf, NULL, NULL, x, y, channels_in_file, + desired_channels, 0); +} + +WUFFS_DROP_IN__STB__MAYBE_STATIC int // +stbi_info_from_callbacks( // + stbi_io_callbacks const* clbk, // + void* user, // + int* x, // + int* y, // + int* comp) { + wuffs_drop_in__stb__g_failure_reason = NULL; + void* iobuf_ptr = malloc(65536u); + if (!iobuf_ptr) { + wuffs_drop_in__stb__g_failure_reason = "out of memory"; + return 0; + } + wuffs_base__io_buffer srcbuf = + wuffs_base__ptr_u8__writer((uint8_t*)iobuf_ptr, 65536u); + wuffs_drop_in__stb__load0(&srcbuf, clbk, user, x, y, comp, 1, 1); + free(iobuf_ptr); + return wuffs_drop_in__stb__g_failure_reason == NULL; +} + +WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* // +stbi_load_from_callbacks( // + stbi_io_callbacks const* clbk, // + void* user, // + int* x, // + int* y, // + int* channels_in_file, // + int desired_channels) { + wuffs_drop_in__stb__g_failure_reason = NULL; + void* iobuf_ptr = malloc(65536u); + if (!iobuf_ptr) { + wuffs_drop_in__stb__g_failure_reason = "out of memory"; + return NULL; + } + wuffs_base__io_buffer srcbuf = + wuffs_base__ptr_u8__writer((uint8_t*)iobuf_ptr, 65536u); + stbi_uc* ret = wuffs_drop_in__stb__load0( + &srcbuf, clbk, user, x, y, channels_in_file, desired_channels, 0); + free(iobuf_ptr); + return ret; +} + +WUFFS_DROP_IN__STB__MAYBE_STATIC void // +stbi_image_free( // + void* retval_from_stbi_load) { + wuffs_drop_in__stb__g_failure_reason = NULL; + free(retval_from_stbi_load); +} + +WUFFS_DROP_IN__STB__MAYBE_STATIC const char* // +stbi_failure_reason(void) { + return wuffs_drop_in__stb__g_failure_reason + ? wuffs_drop_in__stb__g_failure_reason + : "ok"; +} + +// -------- + +#if !defined(STBI_NO_STDIO) + +#include + +// TODO: retry after EINTR? + +static int // +wuffs_drop_in__stb__file_callbacks__read( // + void* user, // + char* data, // + int size) { + return (int)fread(data, 1u, (size_t)size, (FILE*)user); +} + +static void // +wuffs_drop_in__stb__file_callbacks__skip( // + void* user, // + int n) { + fseek((FILE*)user, (long)n, SEEK_CUR); +} + +static int // +wuffs_drop_in__stb__file_callbacks__eof( // + void* user) { + return feof((FILE*)user); +} + +WUFFS_DROP_IN__STB__MAYBE_STATIC int // +stbi_info( // + char const* filename, // + int* x, // + int* y, // + int* comp) { + wuffs_drop_in__stb__g_failure_reason = NULL; + FILE* f = fopen(filename, "rb"); + if (!f) { + wuffs_drop_in__stb__g_failure_reason = "could not open file"; + return 0; + } + int ret = stbi_info_from_file(f, x, y, comp); + fclose(f); + return ret; +} + +WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* // +stbi_load( // + char const* filename, // + int* x, // + int* y, // + int* channels_in_file, // + int desired_channels) { + wuffs_drop_in__stb__g_failure_reason = NULL; + FILE* f = fopen(filename, "rb"); + if (!f) { + wuffs_drop_in__stb__g_failure_reason = "could not open file"; + return NULL; + } + stbi_uc* ret = + stbi_load_from_file(f, x, y, channels_in_file, desired_channels); + fclose(f); + return ret; +} + +WUFFS_DROP_IN__STB__MAYBE_STATIC int // +stbi_info_from_file( // + FILE* f, // + int* x, // + int* y, // + int* comp) { + wuffs_drop_in__stb__g_failure_reason = NULL; + void* iobuf_ptr = malloc(65536u); + if (!iobuf_ptr) { + wuffs_drop_in__stb__g_failure_reason = "out of memory"; + return 0; + } + wuffs_base__io_buffer srcbuf = + wuffs_base__ptr_u8__writer((uint8_t*)iobuf_ptr, 65536u); + stbi_io_callbacks clbk; + clbk.read = &wuffs_drop_in__stb__file_callbacks__read; + clbk.skip = &wuffs_drop_in__stb__file_callbacks__skip; + clbk.eof = &wuffs_drop_in__stb__file_callbacks__eof; + wuffs_drop_in__stb__load0(&srcbuf, &clbk, f, x, y, comp, 1, 1); + free(iobuf_ptr); + return wuffs_drop_in__stb__g_failure_reason == NULL; +} + +WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* // +stbi_load_from_file( // + FILE* f, // + int* x, // + int* y, // + int* channels_in_file, // + int desired_channels) { + wuffs_drop_in__stb__g_failure_reason = NULL; + void* iobuf_ptr = malloc(65536u); + if (!iobuf_ptr) { + wuffs_drop_in__stb__g_failure_reason = "out of memory"; + return NULL; + } + wuffs_base__io_buffer srcbuf = + wuffs_base__ptr_u8__writer((uint8_t*)iobuf_ptr, 65536u); + stbi_io_callbacks clbk; + clbk.read = &wuffs_drop_in__stb__file_callbacks__read; + clbk.skip = &wuffs_drop_in__stb__file_callbacks__skip; + clbk.eof = &wuffs_drop_in__stb__file_callbacks__eof; + stbi_uc* ret = wuffs_drop_in__stb__load0( + &srcbuf, &clbk, f, x, y, channels_in_file, desired_channels, 0); + free(iobuf_ptr); + return ret; +} + +#endif // !defined(STBI_NO_STDIO) + +// -------- + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // defined (WUFFS_CONFIG__ENABLE_DROP_IN_REPLACEMENT__STB) #endif // WUFFS_IMPLEMENTATION #if defined(__GNUC__)