mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 08:32:11 +01:00
1 parent
4c09c77bb9
commit
5aa7a9339f
5 files changed
+512
-48
No files matched your search
@@ -9640,6 +9640,9 @@ struct wuffs_png__decoder__struct {
|
||||
|
||||
// ---------------- Status Codes
|
||||
|
||||
extern const char wuffs_tga__error__bad_header[];
|
||||
extern const char wuffs_tga__error__unsupported_tga_file[];
|
||||
|
||||
// ---------------- Public Consts
|
||||
|
||||
#define WUFFS_TGA__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0
|
||||
@@ -9792,15 +9795,31 @@ struct wuffs_tga__decoder__struct {
|
||||
uint32_t f_width;
|
||||
uint32_t f_height;
|
||||
uint8_t f_call_sequence;
|
||||
uint8_t f_header_id_length;
|
||||
uint8_t f_header_color_map_type;
|
||||
uint8_t f_header_image_type;
|
||||
uint16_t f_header_color_map_first_entry_index;
|
||||
uint16_t f_header_color_map_length;
|
||||
uint8_t f_header_color_map_entry_size;
|
||||
uint16_t f_header_x_origin;
|
||||
uint16_t f_header_y_origin;
|
||||
uint8_t f_header_pixel_depth;
|
||||
uint8_t f_header_image_descriptor;
|
||||
uint64_t f_frame_config_io_position;
|
||||
wuffs_base__pixel_swizzler f_swizzler;
|
||||
|
||||
uint32_t p_decode_image_config[1];
|
||||
uint32_t p_decode_frame_config[1];
|
||||
uint32_t p_decode_frame[1];
|
||||
} private_impl;
|
||||
|
||||
struct {
|
||||
struct {
|
||||
uint64_t scratch;
|
||||
} s_decode_image_config[1];
|
||||
struct {
|
||||
uint32_t v_dst_x;
|
||||
uint32_t v_dst_y;
|
||||
uint8_t v_src[4];
|
||||
} s_decode_frame[1];
|
||||
} private_data;
|
||||
@@ -41949,6 +41968,9 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
|
||||
|
||||
// ---------------- Status Codes Implementations
|
||||
|
||||
const char wuffs_tga__error__bad_header[] = "#tga: bad header";
|
||||
const char wuffs_tga__error__unsupported_tga_file[] = "#tga: unsupported TGA file";
|
||||
|
||||
// ---------------- Private Consts
|
||||
|
||||
// ---------------- Private Initializer Prototypes
|
||||
@@ -42111,27 +42133,323 @@ wuffs_tga__decoder__decode_image_config(
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence != 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence != 0) {
|
||||
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 > 1) {
|
||||
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 == 1) || (self->private_impl.f_header_image_type == 2) || (self->private_impl.f_header_image_type == 3)) {
|
||||
} else if ((self->private_impl.f_header_image_type == 9) || (self->private_impl.f_header_image_type == 10) || (self->private_impl.f_header_image_type == 11)) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
|
||||
goto exit;
|
||||
} 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_decode_image_config[0].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_image_config[0].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 += 8;
|
||||
*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_decode_image_config[0].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_image_config[0].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 += 8;
|
||||
*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 != 0) {
|
||||
if ((self->private_impl.f_header_color_map_first_entry_index != 0) || (self->private_impl.f_header_color_map_length > 256)) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
|
||||
goto exit;
|
||||
} else if ((self->private_impl.f_header_color_map_entry_size != 15) &&
|
||||
(self->private_impl.f_header_color_map_entry_size != 16) &&
|
||||
(self->private_impl.f_header_color_map_entry_size != 24) &&
|
||||
(self->private_impl.f_header_color_map_entry_size != 32)) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
} else {
|
||||
if ((self->private_impl.f_header_color_map_first_entry_index != 0) || (self->private_impl.f_header_color_map_length != 0) || (self->private_impl.f_header_color_map_entry_size != 0)) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
uint16_t t_6;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
|
||||
t_6 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 2;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].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_image_config[0].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 = ((uint16_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_6 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_6)) << 56;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_header_x_origin = t_6;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
|
||||
uint16_t t_7;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
|
||||
t_7 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 2;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].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_image_config[0].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 = ((uint16_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_7 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_7)) << 56;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_header_y_origin = t_7;
|
||||
}
|
||||
if ((self->private_impl.f_header_x_origin != 0) || (self->private_impl.f_header_y_origin != 0)) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13);
|
||||
uint32_t t_8;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
|
||||
t_8 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
|
||||
iop_a_src += 2;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].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_image_config[0].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 == 8) {
|
||||
t_8 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_8 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_8)) << 56;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_width = t_8;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15);
|
||||
uint32_t t_9;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
|
||||
t_9 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
|
||||
iop_a_src += 2;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].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_image_config[0].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 == 8) {
|
||||
t_9 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_9 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_9)) << 56;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_height = t_9;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(17);
|
||||
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_10 = *iop_a_src++;
|
||||
self->private_impl.f_header_pixel_depth = t_10;
|
||||
}
|
||||
if ((self->private_impl.f_header_pixel_depth != 1) &&
|
||||
(self->private_impl.f_header_pixel_depth != 8) &&
|
||||
(self->private_impl.f_header_pixel_depth != 15) &&
|
||||
(self->private_impl.f_header_pixel_depth != 16) &&
|
||||
(self->private_impl.f_header_pixel_depth != 24) &&
|
||||
(self->private_impl.f_header_pixel_depth != 32)) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(18);
|
||||
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_11 = *iop_a_src++;
|
||||
self->private_impl.f_header_image_descriptor = t_11;
|
||||
}
|
||||
if ((self->private_impl.f_header_image_descriptor & 16) != 0) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
|
||||
goto exit;
|
||||
}
|
||||
self->private_data.s_decode_image_config[0].scratch = ((uint32_t)(self->private_impl.f_header_id_length));
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(19);
|
||||
if (self->private_data.s_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_decode_image_config[0].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_image_config[0].scratch;
|
||||
if (self->private_impl.f_header_color_map_type != 0) {
|
||||
}
|
||||
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,
|
||||
2164295816,
|
||||
0,
|
||||
self->private_impl.f_width,
|
||||
self->private_impl.f_height,
|
||||
self->private_impl.f_frame_config_io_position,
|
||||
false);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_image_config[0] = 0;
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_width = 1;
|
||||
self->private_impl.f_height = 1;
|
||||
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,
|
||||
2164295816,
|
||||
0,
|
||||
self->private_impl.f_width,
|
||||
self->private_impl.f_height,
|
||||
self->private_impl.f_frame_config_io_position,
|
||||
false);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_decode_image_config[0] = 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) {
|
||||
@@ -42286,12 +42604,17 @@ wuffs_tga__decoder__decode_frame(
|
||||
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 = {0};
|
||||
uint8_t v_src[4] = {0};
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
|
||||
if (coro_susp_point) {
|
||||
v_dst_x = self->private_data.s_decode_frame[0].v_dst_x;
|
||||
v_dst_y = self->private_data.s_decode_frame[0].v_dst_y;
|
||||
memcpy(v_src, self->private_data.s_decode_frame[0].v_src, sizeof(v_src));
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
@@ -42330,13 +42653,35 @@ wuffs_tga__decoder__decode_frame(
|
||||
status = wuffs_base__make_status(wuffs_base__error__unsupported_option);
|
||||
goto exit;
|
||||
}
|
||||
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
|
||||
v_dst = wuffs_base__table_u8__row_u32(v_tab, 0);
|
||||
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
|
||||
v_src[0] = 127;
|
||||
v_src[1] = 0;
|
||||
v_src[2] = 255;
|
||||
v_src[3] = 255;
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, wuffs_base__pixel_buffer__palette(a_dst), wuffs_base__make_slice_u8(v_src, 4));
|
||||
if ((self->private_impl.f_header_image_descriptor & 32) == 0) {
|
||||
v_dst_y = ((uint32_t)(self->private_impl.f_height - 1));
|
||||
}
|
||||
while (true) {
|
||||
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
|
||||
while (v_dst_y < self->private_impl.f_height) {
|
||||
v_dst = wuffs_base__table_u8__row_u32(v_tab, v_dst_y);
|
||||
while (v_dst_x < self->private_impl.f_width) {
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, wuffs_base__pixel_buffer__palette(a_dst), wuffs_base__make_slice_u8(v_src, 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 += 1;
|
||||
}
|
||||
v_dst_x = 0;
|
||||
if ((self->private_impl.f_header_image_descriptor & 32) == 0) {
|
||||
v_dst_y -= 1;
|
||||
} else {
|
||||
v_dst_y += 1;
|
||||
}
|
||||
}
|
||||
goto label__resume__break;
|
||||
}
|
||||
label__resume__break:;
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
|
||||
ok:
|
||||
@@ -42348,6 +42693,8 @@ wuffs_tga__decoder__decode_frame(
|
||||
suspend:
|
||||
self->private_impl.p_decode_frame[0] = 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_data.s_decode_frame[0].v_dst_x = v_dst_x;
|
||||
self->private_data.s_decode_frame[0].v_dst_y = v_dst_y;
|
||||
memcpy(self->private_data.s_decode_frame[0].v_src, v_src, sizeof(v_src));
|
||||
|
||||
goto exit;
|
||||
|
||||
+135
-12
@@ -12,6 +12,9 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
pub status "#bad header"
|
||||
pub status "#unsupported TGA file"
|
||||
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
|
||||
pub struct decoder? implements base.image_decoder(
|
||||
@@ -45,6 +48,17 @@ pub struct decoder? implements base.image_decoder(
|
||||
// - RF is restart_frame
|
||||
call_sequence : base.u8,
|
||||
|
||||
header_id_length : base.u8,
|
||||
header_color_map_type : base.u8,
|
||||
header_image_type : base.u8,
|
||||
header_color_map_first_entry_index : base.u16,
|
||||
header_color_map_length : base.u16,
|
||||
header_color_map_entry_size : base.u8,
|
||||
header_x_origin : base.u16,
|
||||
header_y_origin : base.u16,
|
||||
header_pixel_depth : base.u8,
|
||||
header_image_descriptor : base.u8,
|
||||
|
||||
frame_config_io_position : base.u64,
|
||||
|
||||
swizzler : base.pixel_swizzler,
|
||||
@@ -59,8 +73,82 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
return base."#bad call sequence"
|
||||
}
|
||||
|
||||
this.width = 1
|
||||
this.height = 1
|
||||
this.header_id_length = args.src.read_u8?()
|
||||
this.header_color_map_type = args.src.read_u8?()
|
||||
if this.header_color_map_type > 1 {
|
||||
return "#bad header"
|
||||
}
|
||||
|
||||
this.header_image_type = args.src.read_u8?()
|
||||
if (this.header_image_type == 0x01) or
|
||||
(this.header_image_type == 0x02) or
|
||||
(this.header_image_type == 0x03) {
|
||||
// No-op.
|
||||
} else if (this.header_image_type == 0x09) or
|
||||
(this.header_image_type == 0x0A) or
|
||||
(this.header_image_type == 0x0B) {
|
||||
// TODO: support run-length encoding.
|
||||
return "#unsupported TGA file"
|
||||
} else {
|
||||
// TODO: 0x20 and 0x21 are invalid, according to the spec, but are
|
||||
// apparently unofficial extensions.
|
||||
return "#bad header"
|
||||
}
|
||||
|
||||
this.header_color_map_first_entry_index = args.src.read_u16le?()
|
||||
this.header_color_map_length = args.src.read_u16le?()
|
||||
this.header_color_map_entry_size = args.src.read_u8?()
|
||||
if this.header_color_map_type <> 0 {
|
||||
// We have a color-mapped image (in Wuffs, an indexed pixel format).
|
||||
if (this.header_color_map_first_entry_index <> 0) or
|
||||
(this.header_color_map_length > 0x100) {
|
||||
return "#unsupported TGA file"
|
||||
} else if (this.header_color_map_entry_size <> 0x0F) and
|
||||
(this.header_color_map_entry_size <> 0x10) and
|
||||
(this.header_color_map_entry_size <> 0x18) and
|
||||
(this.header_color_map_entry_size <> 0x20) {
|
||||
return "#bad header"
|
||||
}
|
||||
} else {
|
||||
// The color-map fields must be zero.
|
||||
if (this.header_color_map_first_entry_index <> 0) or
|
||||
(this.header_color_map_length <> 0) or
|
||||
(this.header_color_map_entry_size <> 0) {
|
||||
return "#bad header"
|
||||
}
|
||||
}
|
||||
|
||||
this.header_x_origin = args.src.read_u16le?()
|
||||
this.header_y_origin = args.src.read_u16le?()
|
||||
if (this.header_x_origin <> 0) or (this.header_y_origin <> 0) {
|
||||
return "#unsupported TGA file"
|
||||
}
|
||||
|
||||
this.width = args.src.read_u16le_as_u32?()
|
||||
this.height = args.src.read_u16le_as_u32?()
|
||||
|
||||
this.header_pixel_depth = args.src.read_u8?()
|
||||
if (this.header_pixel_depth <> 0x01) and
|
||||
(this.header_pixel_depth <> 0x08) and
|
||||
(this.header_pixel_depth <> 0x0F) and
|
||||
(this.header_pixel_depth <> 0x10) and
|
||||
(this.header_pixel_depth <> 0x18) and
|
||||
(this.header_pixel_depth <> 0x20) {
|
||||
return "#bad header"
|
||||
}
|
||||
|
||||
this.header_image_descriptor = args.src.read_u8?()
|
||||
if (this.header_image_descriptor & 0x10) <> 0 {
|
||||
// We don't support right-to-left, only left-to-right pixel order.
|
||||
return "#unsupported TGA file"
|
||||
}
|
||||
|
||||
// Skip the Image ID.
|
||||
args.src.skip_u32?(n: this.header_id_length as base.u32)
|
||||
|
||||
if this.header_color_map_type <> 0 {
|
||||
// TODO: read the color map.
|
||||
}
|
||||
|
||||
this.frame_config_io_position = args.src.position()
|
||||
|
||||
@@ -110,12 +198,15 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
}
|
||||
|
||||
pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
||||
var status : base.status
|
||||
var dst_pixfmt : base.pixel_format
|
||||
var dst_bits_per_pixel : base.u32[..= 256]
|
||||
var tab : table base.u8
|
||||
var dst : slice base.u8
|
||||
var src : array[4] base.u8
|
||||
var status : base.status
|
||||
var dst_pixfmt : base.pixel_format
|
||||
var dst_bits_per_pixel : base.u32[..= 256]
|
||||
var dst_bytes_per_pixel : base.u64[..= 32]
|
||||
var dst_x : base.u32
|
||||
var dst_y : base.u32
|
||||
var tab : table base.u8
|
||||
var dst : slice base.u8
|
||||
var src : array[4] base.u8
|
||||
|
||||
if this.call_sequence < 4 {
|
||||
this.decode_frame_config?(dst: nullptr, src: args.src)
|
||||
@@ -142,15 +233,47 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
if (dst_bits_per_pixel & 7) <> 0 {
|
||||
return base."#unsupported option"
|
||||
}
|
||||
dst_bytes_per_pixel = (dst_bits_per_pixel / 8) as base.u64
|
||||
|
||||
tab = args.dst.plane(p: 0)
|
||||
dst = tab.row_u32(y: 0)
|
||||
// TODO: don't hard-code reddish purple.
|
||||
src[0] = 0x7F
|
||||
src[1] = 0x00
|
||||
src[2] = 0xFF
|
||||
src[3] = 0xFF
|
||||
this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst, dst_palette: args.dst.palette(), src: src[..])
|
||||
|
||||
if (this.header_image_descriptor & 0x20) == 0 { // Bottom-to-top.
|
||||
dst_y = this.height ~mod- 1
|
||||
}
|
||||
|
||||
// TODO: add "continue.resume" lines after short reads.
|
||||
while.resume true {
|
||||
tab = args.dst.plane(p: 0)
|
||||
while dst_y < this.height {
|
||||
dst = tab.row_u32(y: dst_y)
|
||||
|
||||
while dst_x < this.width {
|
||||
assert dst_x < 0xFFFF_FFFF via "a < b: a < c; c <= b"(c: this.width)
|
||||
|
||||
// TODO: be more efficient than swizzling one pixel at a time.
|
||||
this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst, dst_palette: args.dst.palette(), src: src[..])
|
||||
|
||||
if dst_bytes_per_pixel <= dst.length() {
|
||||
dst = dst[dst_bytes_per_pixel ..]
|
||||
}
|
||||
|
||||
dst_x += 1
|
||||
} endwhile
|
||||
dst_x = 0
|
||||
|
||||
if (this.header_image_descriptor & 0x20) == 0 { // Bottom-to-top.
|
||||
dst_y ~mod-= 1
|
||||
} else { // Top-to-bottom.
|
||||
dst_y ~mod+= 1
|
||||
}
|
||||
} endwhile
|
||||
break.resume
|
||||
} endwhile.resume
|
||||
|
||||
this.call_sequence = 0xFF
|
||||
}
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
# Generated by script/print-nia-checksums.sh
|
||||
1f87b217 test/3pdata/tgasuite/bad-color-map.tga
|
||||
1f87b217 test/3pdata/tgasuite/cbw8.tga
|
||||
1f87b217 test/3pdata/tgasuite/ccm8.tga
|
||||
1f87b217 test/3pdata/tgasuite/ctc24.tga
|
||||
1f87b217 test/3pdata/tgasuite/sixteen-bit-gray-colormap2.tga
|
||||
1f87b217 test/3pdata/tgasuite/ubw8.tga
|
||||
1f87b217 test/3pdata/tgasuite/ucm8.tga
|
||||
1f87b217 test/3pdata/tgasuite/utc16.tga
|
||||
1f87b217 test/3pdata/tgasuite/utc24.tga
|
||||
1f87b217 test/3pdata/tgasuite/utc32.tga
|
||||
3da6493d test/3pdata/tgasuite/ubw8.tga
|
||||
3da6493d test/3pdata/tgasuite/ucm8.tga
|
||||
3da6493d test/3pdata/tgasuite/utc16.tga
|
||||
3da6493d test/3pdata/tgasuite/utc24.tga
|
||||
3da6493d test/3pdata/tgasuite/utc32.tga
|
||||
+1
-1
@@ -79,7 +79,7 @@ test_wuffs_tga_decode_interface() {
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
return do_test__wuffs_base__image_decoder(
|
||||
wuffs_tga__decoder__upcast_as__wuffs_base__image_decoder(&dec),
|
||||
"test/data/bricks-color.tga", 0, SIZE_MAX, 1, 1, 0xFFFF007F);
|
||||
"test/data/bricks-color.tga", 0, SIZE_MAX, 160, 120, 0xFFFF007F);
|
||||
}
|
||||
|
||||
// ---------------- Mimic Tests
|
||||
|
||||
@@ -26,7 +26,7 @@ e08a7cc8 test/data/artificial-png/exif.png
|
||||
e08a7cc8 test/data/artificial-png/key-value-pairs.png
|
||||
076cb375 test/data/bricks-color.bmp
|
||||
076cb375 test/data/bricks-color.png
|
||||
1f87b217 test/data/bricks-color.tga
|
||||
0a9502ff test/data/bricks-color.tga
|
||||
f36c2e80 test/data/bricks-dither.bmp
|
||||
f36c2e80 test/data/bricks-dither.gif
|
||||
f36c2e80 test/data/bricks-dither.no-ancillary.png
|
||||
@@ -35,13 +35,12 @@ c2bce675 test/data/bricks-gray.bmp
|
||||
c2bce675 test/data/bricks-gray.gif
|
||||
c2bce675 test/data/bricks-gray.no-ancillary.png
|
||||
c2bce675 test/data/bricks-gray.png
|
||||
1f87b217 test/data/bricks-gray.tga
|
||||
0a9502ff test/data/bricks-gray.tga
|
||||
7aebfe6c test/data/bricks-nodither.bmp
|
||||
7aebfe6c test/data/bricks-nodither.gif
|
||||
7aebfe6c test/data/bricks-nodither.png
|
||||
1f87b217 test/data/bricks-nodither.tga
|
||||
0a9502ff test/data/bricks-nodither.tga
|
||||
ae2e547d test/data/bricks-nodither.wbmp
|
||||
1f87b217 test/data/cbor-rfc-7049-examples.cbor
|
||||
b47730a2 test/data/checkerboard.gamma1dot0.png
|
||||
b47730a2 test/data/checkerboard.gamma2dot2.png
|
||||
aa3e6c7c test/data/crude-flag.nie
|
||||
|
||||
Reference in new issue
Block a user