mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
Compare commits
21
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b22c03837f | ||
|
|
64ef0df550 | ||
|
|
eadcb09109 | ||
|
|
3fce6225c9 | ||
|
|
46ac36bd7b | ||
|
|
0e985fe880 | ||
|
|
0fe290e0e4 | ||
|
|
09b8cbb82f | ||
|
|
ee923a973c | ||
|
|
67591a3570 | ||
|
|
b2a2486096 | ||
|
|
381e186f30 | ||
|
|
85a0283cfc | ||
|
|
e3b5a7d506 | ||
|
|
58968fab9f | ||
|
|
5bab861b51 | ||
|
|
d965fe5638 | ||
|
|
0e06bcc9bc | ||
|
|
79bf624c32 | ||
|
|
ad039b5d3a | ||
|
|
9c6d1dacad |
No files matched your search
@@ -203,6 +203,7 @@ func encode(w io.Writer, b64e *base64.Encoding, r io.Reader, color handsum.Color
|
||||
|
||||
if b64e != nil {
|
||||
enc := b64e.AppendEncode(nil, buf.Bytes())
|
||||
enc = append(enc, '\n')
|
||||
if _, err := w.Write(enc); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -70,6 +70,13 @@ code (instead of writing C/C++ code that _uses_ Wuffs' standard library).
|
||||
a tab).
|
||||
|
||||
|
||||
## 2026-07-11 version 0.3.5
|
||||
|
||||
- No significant changes to `wuffs-v0.3.c` per se.
|
||||
- Some test files were renamed, to work better with pkg.go.dev indexing.
|
||||
- Some test code had #include lines added, to fix some third party builds.
|
||||
|
||||
|
||||
## 2024-04-19 version 0.3.4
|
||||
|
||||
- Have `std/png` ignore tRNS chunks for color types 4 (YA) and 6 (RGBA).
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
// ----------------
|
||||
|
||||
/*
|
||||
convert-to-nia converts an image from stdin (e.g. in the BMP, GIF, JPEG or PNG
|
||||
format) to stdout (in the NIA/NIE format).
|
||||
convert-to-nia converts an image from stdin (e.g. in the BMP, GIF, JPEG, PNG,
|
||||
PPM, QOI, TARGA or WEBP format) to stdout (in the NIA/NIE format).
|
||||
|
||||
See the "const char* g_usage" string below for details.
|
||||
|
||||
@@ -135,8 +135,8 @@ static const char* g_usage =
|
||||
" -fail-if-unsandboxed\n"
|
||||
"\n"
|
||||
"convert-to-nia converts an image from stdin (e.g. in the BMP, GIF, JPEG\n"
|
||||
"or PNG format) to stdout (in the NIA format, or in the NIE, hash, PPM\n"
|
||||
"or PNG format if the -1, -d, -p or -u flag is given).\n"
|
||||
"PNG, PPM, QOI, TARGA or WEBP format) to stdout (in the NIA format, or\n"
|
||||
"in the NIE, hash, PPM or PNG format if given -1, -d, -p or -u flags).\n"
|
||||
"\n"
|
||||
"NIA/NIE is a trivial animated/still image file format, specified at\n"
|
||||
"https://github.com/google/wuffs/blob/main/doc/spec/nie-spec.md\n"
|
||||
|
||||
@@ -684,7 +684,7 @@ struct {
|
||||
static const char* g_usage =
|
||||
"Usage: stb-imagedumper *.{jpeg,png}\n"
|
||||
"\n"
|
||||
"If no filenames are given then it defaults to /dev/stdin\n"
|
||||
"The \"-\" filename is a special case, a short equivalent of /dev/stdin\n"
|
||||
"\n"
|
||||
"Flags:\n"
|
||||
" -a or -ascii-art (use ASCII art instead of ANSI color codes)\n"
|
||||
@@ -994,7 +994,11 @@ handle(const char* filename,
|
||||
&src_w, &src_h, &channels_in_file,
|
||||
bytes_per_pixel);
|
||||
} else {
|
||||
src_pixels = stbi_load(filename, //
|
||||
const char* fn = filename;
|
||||
if ((fn[0] == '-') && (fn[1] == '\x00')) {
|
||||
fn = "/dev/stdin";
|
||||
}
|
||||
src_pixels = stbi_load(fn, //
|
||||
&src_w, &src_h, &channels_in_file, bytes_per_pixel);
|
||||
}
|
||||
|
||||
@@ -1201,9 +1205,6 @@ main(int argc, char** argv) {
|
||||
handle(demos[c].filename, demos[c].src_len, demos[c].src_ptr,
|
||||
demos[c].src_len);
|
||||
}
|
||||
|
||||
} else if (g_flags.remaining_argc == 0) {
|
||||
handle("/dev/stdin", 0, NULL, 0);
|
||||
}
|
||||
|
||||
for (int c = 0; c < g_flags.remaining_argc; c++) {
|
||||
|
||||
@@ -237,11 +237,11 @@ fuzz_swizzle_ycck(wuffs_base__io_buffer* src, uint64_t hash) {
|
||||
uint32_t height_in_mcus = (3 & (hash >> 34)) + 1;
|
||||
|
||||
uint32_t allow_hv3 = 1 & (hash >> 36);
|
||||
bool is_rgb_or_cmyk = 1 & (hash >> 37);
|
||||
bool triangle_filter_for_2to1 = 1 & (hash >> 38);
|
||||
uint8_t ycc_model = (1 & (hash >> 37)) ? 0x80 : 0x00;
|
||||
uint8_t ycc_upsampling = 1 & (hash >> 38);
|
||||
bool use_4th_component = 1 & (hash >> 39);
|
||||
|
||||
if (triangle_filter_for_2to1) {
|
||||
if (ycc_upsampling) {
|
||||
x_min_incl = 0;
|
||||
y_min_incl = 0;
|
||||
} else {
|
||||
@@ -411,8 +411,8 @@ fuzz_swizzle_ycck(wuffs_base__io_buffer* src, uint64_t hash) {
|
||||
width0, width1, width2, width3, //
|
||||
h0, h1, h2, h3, //
|
||||
v0, v1, v2, v3, //
|
||||
is_rgb_or_cmyk, //
|
||||
triangle_filter_for_2to1, //
|
||||
ycc_model, //
|
||||
ycc_upsampling, //
|
||||
wuffs_base__make_slice_u8(scratch_buffer, sizeof(scratch_buffer)));
|
||||
if (status.repr) {
|
||||
return wuffs_base__status__message(&status);
|
||||
|
||||
@@ -68,7 +68,7 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
uint8_t v2,
|
||||
uint8_t v3,
|
||||
uint8_t ycc_model,
|
||||
bool triangle_filter_for_2to1,
|
||||
uint8_t ycc_upsampling,
|
||||
wuffs_base__slice_u8 scratch_buffer_2k);
|
||||
|
||||
// ---------------- Images (Utility)
|
||||
|
||||
@@ -445,10 +445,12 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2(
|
||||
size_t src_len,
|
||||
uint32_t h1v2_bias_ignored,
|
||||
bool first_column,
|
||||
bool last_column) {
|
||||
bool last_column,
|
||||
uint8_t odd_column_rounding) {
|
||||
uint8_t* dp = dst_ptr;
|
||||
const uint8_t* sp_major = src_ptr_major;
|
||||
const uint8_t* sp_minor = src_ptr_minor;
|
||||
const uint8_t oc = odd_column_rounding;
|
||||
|
||||
if (first_column) {
|
||||
src_len--;
|
||||
@@ -456,7 +458,7 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2(
|
||||
uint32_t sv = (12u * ((uint32_t)(*sp_major++))) + //
|
||||
(4u * ((uint32_t)(*sp_minor++)));
|
||||
*dp++ = (uint8_t)((sv + 8u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + 7u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + oc) >> 4u);
|
||||
return dst_ptr;
|
||||
}
|
||||
|
||||
@@ -468,7 +470,7 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2(
|
||||
uint32_t sv = (9u * ((uint32_t)(*sp_major++))) + //
|
||||
(3u * ((uint32_t)(*sp_minor++)));
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_m1) + (sv_minor_m1) + 8u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + 7u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + oc) >> 4u);
|
||||
if (src_len <= 0u) {
|
||||
return dst_ptr;
|
||||
}
|
||||
@@ -489,7 +491,7 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2(
|
||||
uint32_t sv = (9u * ((uint32_t)(*sp_major++))) + //
|
||||
(3u * ((uint32_t)(*sp_minor++)));
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_m1) + (sv_minor_m1) + 8u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + 7u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + oc) >> 4u);
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -562,8 +564,8 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2(
|
||||
// the u16 right value by 4. On the right (p1), shift right by 4 and then
|
||||
// shift left by 8 so that, when still in the u16x16 little-endian
|
||||
// interpretation, we have:
|
||||
// - m1_element = (etcetera + 8) >> 4
|
||||
// - p1_element = ((etcetera + 7) >> 4) << 8
|
||||
// - m1_element = (etcetera + 8) >> 4
|
||||
// - p1_element = ((etcetera + oc) >> 4) << 8
|
||||
//
|
||||
// step4_m1_lo = [0x00?? 0x00?? ... 0x00?? 0x00??]
|
||||
// step4_p1_lo = [0x??00 0x??00 ... 0x??00 0x??00]
|
||||
@@ -572,14 +574,14 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2(
|
||||
__m256i step4_m1_lo = _mm256_srli_epi16(
|
||||
_mm256_add_epi16(step3_m1_lo, _mm256_set1_epi16(8)), 4);
|
||||
__m256i step4_p1_lo = _mm256_slli_epi16(
|
||||
_mm256_srli_epi16(_mm256_add_epi16(step3_p1_lo, _mm256_set1_epi16(7)),
|
||||
4),
|
||||
_mm256_srli_epi16(
|
||||
_mm256_add_epi16(step3_p1_lo, _mm256_set1_epi16(oc)), 4),
|
||||
8);
|
||||
__m256i step4_m1_hi = _mm256_srli_epi16(
|
||||
_mm256_add_epi16(step3_m1_hi, _mm256_set1_epi16(8)), 4);
|
||||
__m256i step4_p1_hi = _mm256_slli_epi16(
|
||||
_mm256_srli_epi16(_mm256_add_epi16(step3_p1_hi, _mm256_set1_epi16(7)),
|
||||
4),
|
||||
_mm256_srli_epi16(
|
||||
_mm256_add_epi16(step3_p1_hi, _mm256_set1_epi16(oc)), 4),
|
||||
8);
|
||||
|
||||
// Bitwise-or two "0x00"-rich u16x16 vectors to get a u8x32 vector. Do
|
||||
@@ -630,7 +632,7 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2(
|
||||
uint32_t sv = (9u * ((uint32_t)(*sp_major++))) + //
|
||||
(3u * ((uint32_t)(*sp_minor++)));
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_m1) + (sv_minor_m1) + 8u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + 7u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + oc) >> 4u);
|
||||
}
|
||||
|
||||
return dst_ptr;
|
||||
|
||||
@@ -45,7 +45,36 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2(
|
||||
size_t src_len,
|
||||
uint32_t h1v2_bias_ignored,
|
||||
bool first_column,
|
||||
bool last_column);
|
||||
bool last_column,
|
||||
uint8_t odd_column_rounding);
|
||||
|
||||
static const uint8_t* //
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_libjpeg_x86_avx2(
|
||||
uint8_t* dst_ptr,
|
||||
const uint8_t* src_ptr_major,
|
||||
const uint8_t* src_ptr_minor,
|
||||
size_t src_len,
|
||||
uint32_t h1v2_bias_ignored,
|
||||
bool first_column,
|
||||
bool last_column) {
|
||||
return wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2(
|
||||
dst_ptr, src_ptr_major, src_ptr_minor, src_len, h1v2_bias_ignored,
|
||||
first_column, last_column, 7);
|
||||
}
|
||||
|
||||
static const uint8_t* //
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_libwebp_x86_avx2(
|
||||
uint8_t* dst_ptr,
|
||||
const uint8_t* src_ptr_major,
|
||||
const uint8_t* src_ptr_minor,
|
||||
size_t src_len,
|
||||
uint32_t h1v2_bias_ignored,
|
||||
bool first_column,
|
||||
bool last_column) {
|
||||
return wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2(
|
||||
dst_ptr, src_ptr_major, src_ptr_minor, src_len, h1v2_bias_ignored,
|
||||
first_column, last_column, 8);
|
||||
}
|
||||
#endif
|
||||
#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V3)
|
||||
|
||||
@@ -404,8 +433,8 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h1v2_triangle(
|
||||
const uint8_t* src_ptr_minor,
|
||||
size_t src_len,
|
||||
uint32_t h1v2_bias,
|
||||
bool first_column,
|
||||
bool last_column) {
|
||||
bool first_column_ignored,
|
||||
bool last_column_ignored) {
|
||||
uint8_t* dp = dst_ptr;
|
||||
const uint8_t* sp_major = src_ptr_major;
|
||||
const uint8_t* sp_minor = src_ptr_minor;
|
||||
@@ -477,10 +506,12 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle(
|
||||
size_t src_len,
|
||||
uint32_t h1v2_bias_ignored,
|
||||
bool first_column,
|
||||
bool last_column) {
|
||||
bool last_column,
|
||||
uint8_t odd_column_rounding) {
|
||||
uint8_t* dp = dst_ptr;
|
||||
const uint8_t* sp_major = src_ptr_major;
|
||||
const uint8_t* sp_minor = src_ptr_minor;
|
||||
const uint8_t oc = odd_column_rounding;
|
||||
|
||||
if (first_column) {
|
||||
src_len--;
|
||||
@@ -488,7 +519,7 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle(
|
||||
uint32_t sv = (12u * ((uint32_t)(*sp_major++))) + //
|
||||
(4u * ((uint32_t)(*sp_minor++)));
|
||||
*dp++ = (uint8_t)((sv + 8u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + 7u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + oc) >> 4u);
|
||||
return dst_ptr;
|
||||
}
|
||||
|
||||
@@ -500,7 +531,7 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle(
|
||||
uint32_t sv = (9u * ((uint32_t)(*sp_major++))) + //
|
||||
(3u * ((uint32_t)(*sp_minor++)));
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_m1) + (sv_minor_m1) + 8u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + 7u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + oc) >> 4u);
|
||||
if (src_len <= 0u) {
|
||||
return dst_ptr;
|
||||
}
|
||||
@@ -519,7 +550,7 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle(
|
||||
uint32_t sv = (9u * ((uint32_t)(*sp_major++))) + //
|
||||
(3u * ((uint32_t)(*sp_minor++)));
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_m1) + (sv_minor_m1) + 8u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + 7u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + oc) >> 4u);
|
||||
}
|
||||
|
||||
if (last_column) {
|
||||
@@ -531,12 +562,40 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle(
|
||||
uint32_t sv = (9u * ((uint32_t)(*sp_major++))) + //
|
||||
(3u * ((uint32_t)(*sp_minor++)));
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_m1) + (sv_minor_m1) + 8u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + 7u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + oc) >> 4u);
|
||||
}
|
||||
|
||||
return dst_ptr;
|
||||
}
|
||||
|
||||
static const uint8_t* //
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_libjpeg(
|
||||
uint8_t* dst_ptr,
|
||||
const uint8_t* src_ptr_major,
|
||||
const uint8_t* src_ptr_minor,
|
||||
size_t src_len,
|
||||
uint32_t h1v2_bias_ignored,
|
||||
bool first_column,
|
||||
bool last_column) {
|
||||
return wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle(
|
||||
dst_ptr, src_ptr_major, src_ptr_minor, src_len, h1v2_bias_ignored,
|
||||
first_column, last_column, 7);
|
||||
}
|
||||
|
||||
static const uint8_t* //
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_libwebp(
|
||||
uint8_t* dst_ptr,
|
||||
const uint8_t* src_ptr_major,
|
||||
const uint8_t* src_ptr_minor,
|
||||
size_t src_len,
|
||||
uint32_t h1v2_bias_ignored,
|
||||
bool first_column,
|
||||
bool last_column) {
|
||||
return wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle(
|
||||
dst_ptr, src_ptr_major, src_ptr_minor, src_len, h1v2_bias_ignored,
|
||||
first_column, last_column, 8);
|
||||
}
|
||||
|
||||
// wuffs_private_impl__swizzle_ycc__upsample_funcs is indexed by inv_h and then
|
||||
// inv_v.
|
||||
static const wuffs_private_impl__swizzle_ycc__upsample_func
|
||||
@@ -1288,7 +1347,7 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
uint8_t v2,
|
||||
uint8_t v3,
|
||||
uint8_t ycc_model,
|
||||
bool triangle_filter_for_2to1,
|
||||
uint8_t ycc_upsampling,
|
||||
wuffs_base__slice_u8 scratch_buffer_2k) {
|
||||
if (!p) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
@@ -1303,7 +1362,7 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
(4u <= ((unsigned int)v0 - 1u)) || //
|
||||
(4u <= ((unsigned int)v1 - 1u)) || //
|
||||
(4u <= ((unsigned int)v2 - 1u)) || //
|
||||
(triangle_filter_for_2to1 && ((x_min_incl | y_min_incl) > 0u)) ||
|
||||
((ycc_upsampling != 0) && ((x_min_incl | y_min_incl) > 0u)) ||
|
||||
(scratch_buffer_2k.len < 2048u)) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
@@ -1611,7 +1670,7 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
memcpy(&upfuncs, &wuffs_private_impl__swizzle_ycc__upsample_funcs,
|
||||
sizeof upfuncs);
|
||||
|
||||
if (triangle_filter_for_2to1 &&
|
||||
if ((ycc_upsampling != 0) &&
|
||||
(wuffs_private_impl__swizzle_has_triangle_upsampler(inv_h0, inv_v0) ||
|
||||
wuffs_private_impl__swizzle_has_triangle_upsampler(inv_h1, inv_v1) ||
|
||||
wuffs_private_impl__swizzle_has_triangle_upsampler(inv_h2, inv_v2) ||
|
||||
@@ -1621,7 +1680,10 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
|
||||
upfuncs[0][1] = wuffs_private_impl__swizzle_ycc__upsample_inv_h1v2_triangle;
|
||||
upfuncs[1][0] = wuffs_private_impl__swizzle_ycc__upsample_inv_h2v1_triangle;
|
||||
upfuncs[1][1] = wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle;
|
||||
upfuncs[1][1] =
|
||||
(ycc_upsampling == 1)
|
||||
? wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_libjpeg
|
||||
: wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_libwebp;
|
||||
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V3)
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
@@ -1639,7 +1701,9 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
#else
|
||||
if (wuffs_base__cpu_arch__have_x86_avx2()) {
|
||||
upfuncs[1][1] =
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2;
|
||||
(ycc_upsampling == 1)
|
||||
? wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_libjpeg_x86_avx2
|
||||
: wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_libwebp_x86_avx2;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -248,6 +248,12 @@ var Consts = [...]struct {
|
||||
{t.IDU32, "0x01", "YCC_MODEL__BT_601_STUDIO_RANGE"},
|
||||
{t.IDU32, "0x40", "YCC_MODEL__RGB"},
|
||||
{t.IDU32, "0x80", "YCC_MODEL__CMY"},
|
||||
|
||||
// ----
|
||||
|
||||
{t.IDU32, "0x00", "YCC_UPSAMPLING__BASIC"},
|
||||
{t.IDU32, "0x01", "YCC_UPSAMPLING__FANCY_LIKE_LIBJPEG"},
|
||||
{t.IDU32, "0x02", "YCC_UPSAMPLING__FANCY_LIKE_LIBWEBP"},
|
||||
}
|
||||
|
||||
var Statuses = [...]string{
|
||||
@@ -742,7 +748,7 @@ var funcsOther = [...]string{
|
||||
"v2: u8[..= 4]," +
|
||||
"v3: u8[..= 4]," +
|
||||
"ycc_model: u8," +
|
||||
"triangle_filter_for_2to1: bool," +
|
||||
"ycc_upsampling: u8," +
|
||||
"scratch_buffer_2k: slice u8) status",
|
||||
|
||||
// ---- arm_crc32_utility
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
// Copyright 2026 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
package handsum_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"image/png"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/google/wuffs/lib/handsum"
|
||||
)
|
||||
|
||||
func Example_decode() {
|
||||
srcBytes, err := base64.URLEncoding.DecodeString("" +
|
||||
"_tdrdX33KcrhdVU1hFi3h2mtY0qqd2dswzeX9jmJckmUxD15c1Vqk1iGdjmYoknlZDl5dmmZ" +
|
||||
"xEczhliahXRDpC3JFoiItjAtQ2vJpjBsUziLiXivgimZqDq6skhwhkxIsimmragKTLa-_Hmn" +
|
||||
"C5rf_acAvXR4zebYyq-Qc2SVtVnIA_mX9zVlEmn_Ul9pIzwHaFBb")
|
||||
if err != nil {
|
||||
log.Fatalf("base64.URLEncoding.DecodeString: %v", err)
|
||||
}
|
||||
|
||||
img, err := handsum.Decode(bytes.NewReader(srcBytes))
|
||||
if err != nil {
|
||||
log.Fatalf("handsum.Decode: %v", err)
|
||||
}
|
||||
fmt.Printf("%T %v\n", img, img.Bounds())
|
||||
|
||||
// Output:
|
||||
// *image.RGBA (0,0)-(16,12)
|
||||
}
|
||||
|
||||
func Example_encode() {
|
||||
f, err := os.Open("../../test/data/bricks-color.png")
|
||||
if err != nil {
|
||||
log.Fatalf("os.Open: %v", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
srcImage, err := png.Decode(f)
|
||||
if err != nil {
|
||||
log.Fatalf("png.Decode: %v", err)
|
||||
}
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
err = handsum.Encode(buf, srcImage, nil)
|
||||
if err != nil {
|
||||
log.Fatalf("handsum.Encode: %v", err)
|
||||
}
|
||||
|
||||
s := base64.URLEncoding.EncodeToString(buf.Bytes())
|
||||
for ; len(s) > 72; s = s[72:] {
|
||||
fmt.Println(s[:72])
|
||||
}
|
||||
fmt.Println(s)
|
||||
|
||||
// Output:
|
||||
// _tdrdX33KcrhdVU1hFi3h2mtY0qqd2dswzeX9jmJckmUxD15c1Vqk1iGdjmYoknlZDl5dmmZ
|
||||
// xEczhliahXRDpC3JFoiItjAtQ2vJpjBsUziLiXivgimZqDq6skhwhkxIsimmragKTLa-_Hmn
|
||||
// C5rf_acAvXR4zebYyq-Qc2SVtVnIA_mX9zVlEmn_Ul9pIzwHaFBb
|
||||
}
|
||||
+66
-67
@@ -47,9 +47,9 @@
|
||||
// 4.59375 bits per pixel for a 16×16 pixel image (a 1:1 aspect ratio), or
|
||||
// 6.125 bits per pixel for a 16×12 pixel image (a 4:3 aspect ratio).
|
||||
//
|
||||
// A Handsum file's starts with a 3 byte header: a 15-bit magic signature, a
|
||||
// 2-bit color (Gray, RGB or RGBA), a 2-bit quality and a 5-bit aspect ratio.
|
||||
// An image's longest dimension (width or height) is 16 pixels and the aspect
|
||||
// Handsum files start with a 3 byte header: a 15-bit magic signature, a 2-bit
|
||||
// color (Gray, RGB or RGBA), a 2-bit quality and a 5-bit aspect ratio. An
|
||||
// image's longest dimension (width or height) is 16 pixels and the aspect
|
||||
// ratio gives the shorter dimension.
|
||||
//
|
||||
// The color=RGB payload, after the header, holds a scaled 16×16 pixel YCbCr
|
||||
@@ -79,10 +79,11 @@
|
||||
//
|
||||
// All Handsum images use the sRGB color profile and non-premultiplied alpha.
|
||||
//
|
||||
// The "Handsum" name was inspired by the "Thumbhash" image file format, which
|
||||
// is also designed for very small thumbnails (or very compact representations
|
||||
// of image placeholders). Handsum files are bigger (but better quality) than
|
||||
// Thumbhash. "Handsum" also sounds like "handsome", meaning "good looking".
|
||||
// The "Handsum" name was inspired by the "Thumbhash" image file format (which
|
||||
// was in turn inspired by "Blurhash"), which is also designed for very small
|
||||
// thumbnails (or very compact representations of image placeholders). Handsum
|
||||
// files are bigger (but better quality) than Thumbhash (and Blurhash).
|
||||
// "Handsum" also sounds like "handsome", meaning "good looking".
|
||||
//
|
||||
// Other techniques and image formats, similar to Thumbhash, can be found by
|
||||
// search for "LQIP" or "Low Quality Image Placeholders".
|
||||
@@ -336,7 +337,7 @@ func Encode(w io.Writer, src image.Image, options *EncodeOptions) error {
|
||||
if c >= ColorRGBA {
|
||||
alphasBlock := lowleveljpeg.BlockU8{}
|
||||
alphasBlock.DownsampleFrom(&alphasQuadBlock)
|
||||
bitOffset = encodeBlockQ3(&buf, bitOffset, &alphasBlock, QualityBest.numberOfCoefficients())
|
||||
bitOffset = encodeBlockQ4(&buf, bitOffset, &alphasBlock, QualityBest.numberOfCoefficients())
|
||||
}
|
||||
|
||||
_, err := w.Write(buf[:bitOffset/8])
|
||||
@@ -374,13 +375,13 @@ func scaleSrc(src image.Image, alphasQuadBlock *lowleveljpeg.QuadBlockU8) image.
|
||||
type encodeBlockFunc func(buf *[fileSizeMax]byte, bitOffset int, src *lowleveljpeg.BlockU8, nCoeffs int) int
|
||||
|
||||
var encodeBlockFuncs = [4]encodeBlockFunc{
|
||||
encodeBlockQ0,
|
||||
encodeBlockQ1,
|
||||
encodeBlockQ1,
|
||||
encodeBlockQ3,
|
||||
encodeBlockQ2,
|
||||
encodeBlockQ2,
|
||||
encodeBlockQ4,
|
||||
}
|
||||
|
||||
func encodeBlockQ0(buf *[fileSizeMax]byte, bitOffset int, src *lowleveljpeg.BlockU8, nCoeffs int) int {
|
||||
func encodeBlockQ1(buf *[fileSizeMax]byte, bitOffset int, src *lowleveljpeg.BlockU8, nCoeffs int) int {
|
||||
f8 := src.ForwardDCT()
|
||||
|
||||
for _, z := range zigzag8 {
|
||||
@@ -397,7 +398,7 @@ func encodeBlockQ0(buf *[fileSizeMax]byte, bitOffset int, src *lowleveljpeg.Bloc
|
||||
return bitOffset
|
||||
}
|
||||
|
||||
func encodeBlockQ1(buf *[fileSizeMax]byte, bitOffset int, src *lowleveljpeg.BlockU8, nCoeffs int) int {
|
||||
func encodeBlockQ2(buf *[fileSizeMax]byte, bitOffset int, src *lowleveljpeg.BlockU8, nCoeffs int) int {
|
||||
for i := range 4 {
|
||||
x4 := (i & 1) << 2 // The sequence 0, 4, 0, 4.
|
||||
y4 := (i & 2) << 1 // The sequence 0, 0, 4, 4.
|
||||
@@ -421,7 +422,7 @@ func encodeBlockQ1(buf *[fileSizeMax]byte, bitOffset int, src *lowleveljpeg.Bloc
|
||||
return bitOffset
|
||||
}
|
||||
|
||||
func encodeBlockQ3(buf *[fileSizeMax]byte, bitOffset int, src *lowleveljpeg.BlockU8, nCoeffs int) int {
|
||||
func encodeBlockQ4(buf *[fileSizeMax]byte, bitOffset int, src *lowleveljpeg.BlockU8, nCoeffs int) int {
|
||||
// We could import the lowleveldct2x2 package and call its ForwardDCT
|
||||
// method (and InverseDCTFrom on decode), but it's easy to just inline it.
|
||||
|
||||
@@ -549,7 +550,7 @@ func Decode(r io.Reader) (image.Image, error) {
|
||||
|
||||
if c >= ColorRGBA {
|
||||
aaBlockU8 := lowleveljpeg.BlockU8{}
|
||||
bitOffset = decodeBlockQ3(aaBlockU8[:], 8, &buf, bitOffset, QualityBest.numberOfCoefficients())
|
||||
bitOffset = decodeBlockQ4(aaBlockU8[:], 8, &buf, bitOffset, QualityBest.numberOfCoefficients())
|
||||
aaQuadBlockU8.UpsampleFrom(&aaBlockU8)
|
||||
for i, v := range aaQuadBlockU8 {
|
||||
aaQuadBlockU8[i] = cubeRootLUT[v]
|
||||
@@ -576,13 +577,13 @@ func decodeWidthAndHeight(buf2 byte) (w int, h int, ok bool) {
|
||||
type decodeBlockFunc func(dst []byte, stride int, buf *[fileSizeMax]byte, bitOffset int, nCoeffs int) int
|
||||
|
||||
var decodeBlockFuncs = [4]decodeBlockFunc{
|
||||
decodeBlockQ0,
|
||||
decodeBlockQ1,
|
||||
decodeBlockQ1,
|
||||
decodeBlockQ3,
|
||||
decodeBlockQ2,
|
||||
decodeBlockQ2,
|
||||
decodeBlockQ4,
|
||||
}
|
||||
|
||||
func decodeBlockQ0(dst []byte, stride int, buf *[fileSizeMax]byte, bitOffset int, nCoeffs int) int {
|
||||
func decodeBlockQ1(dst []byte, stride int, buf *[fileSizeMax]byte, bitOffset int, nCoeffs int) int {
|
||||
a := lowleveljpeg.BlockI16{}
|
||||
|
||||
for _, z := range zigzag8 {
|
||||
@@ -607,7 +608,7 @@ func decodeBlockQ0(dst []byte, stride int, buf *[fileSizeMax]byte, bitOffset int
|
||||
return bitOffset
|
||||
}
|
||||
|
||||
func decodeBlockQ1(dst []byte, stride int, buf *[fileSizeMax]byte, bitOffset int, nCoeffs int) int {
|
||||
func decodeBlockQ2(dst []byte, stride int, buf *[fileSizeMax]byte, bitOffset int, nCoeffs int) int {
|
||||
tmp := lowleveljpeg.BlockU8{}
|
||||
|
||||
for i := range 4 {
|
||||
@@ -636,7 +637,7 @@ func decodeBlockQ1(dst []byte, stride int, buf *[fileSizeMax]byte, bitOffset int
|
||||
}
|
||||
}
|
||||
|
||||
smoothBlockSeams8x8Q1(&tmp)
|
||||
smoothBlockSeams8x8Q2(&tmp)
|
||||
|
||||
for i := range 8 {
|
||||
di := i * stride
|
||||
@@ -647,7 +648,7 @@ func decodeBlockQ1(dst []byte, stride int, buf *[fileSizeMax]byte, bitOffset int
|
||||
return bitOffset
|
||||
}
|
||||
|
||||
func decodeBlockQ3(dst []byte, stride int, buf *[fileSizeMax]byte, bitOffset int, nCoeffs int) int {
|
||||
func decodeBlockQ4(dst []byte, stride int, buf *[fileSizeMax]byte, bitOffset int, nCoeffs int) int {
|
||||
tmp := lowleveljpeg.BlockU8{}
|
||||
|
||||
for i := range 16 {
|
||||
@@ -673,7 +674,7 @@ func decodeBlockQ3(dst []byte, stride int, buf *[fileSizeMax]byte, bitOffset int
|
||||
tmp[o2+9] = biasAndClamp[((+dct0-dct1-dct2+1)>>1)&1023]
|
||||
}
|
||||
|
||||
smoothBlockSeams8x8Q3(&tmp)
|
||||
smoothBlockSeams8x8Q4(&tmp)
|
||||
|
||||
for i := range 8 {
|
||||
di := i * stride
|
||||
@@ -910,7 +911,7 @@ func smoothBlockSeams16x16(b *lowleveljpeg.QuadBlockU8) {
|
||||
b[0x87] = uint8(((9 * v87) + (3 * v77) + v78 + (3 * v88) + 8) / 16)
|
||||
}
|
||||
|
||||
func smoothBlockSeams8x8Q1(b *lowleveljpeg.BlockU8) {
|
||||
func smoothBlockSeams8x8Q2(b *lowleveljpeg.BlockU8) {
|
||||
for _, pair := range smoothingPairs8x8 {
|
||||
v0 := uint32(b[pair[0]])
|
||||
v1 := uint32(b[pair[1]])
|
||||
@@ -929,7 +930,7 @@ func smoothBlockSeams8x8Q1(b *lowleveljpeg.BlockU8) {
|
||||
b[0o43] = uint8(((9 * v43) + (3 * v33) + v34 + (3 * v44) + 8) / 16)
|
||||
}
|
||||
|
||||
func smoothBlockSeams8x8Q3(b *lowleveljpeg.BlockU8) {
|
||||
func smoothBlockSeams8x8Q4(b *lowleveljpeg.BlockU8) {
|
||||
for y := 1; y < 7; y += 2 {
|
||||
for x := 1; x < 7; x += 2 {
|
||||
o := (y * 8) + x
|
||||
@@ -1033,58 +1034,56 @@ var smoothingPairs8x8 = [12][2]uint8{
|
||||
{0o73, 0o74},
|
||||
}
|
||||
|
||||
// scaleAndBiasChromaUp is equivalent to this [256]uint8 look-up table.
|
||||
//
|
||||
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x04, 0x06,
|
||||
// 0x08, 0x0A, 0x0C, 0x0E, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x1E, 0x20, 0x22, 0x24, 0x26,
|
||||
// 0x28, 0x2A, 0x2C, 0x2E, 0x30, 0x32, 0x34, 0x36, 0x38, 0x3A, 0x3C, 0x3E, 0x40, 0x42, 0x44, 0x46,
|
||||
// 0x48, 0x4A, 0x4C, 0x4E, 0x50, 0x52, 0x54, 0x56, 0x58, 0x5A, 0x5C, 0x5E, 0x60, 0x62, 0x64, 0x66,
|
||||
// 0x68, 0x6A, 0x6C, 0x6E, 0x70, 0x72, 0x74, 0x76, 0x78, 0x7A, 0x7C, 0x7E, 0x80, 0x82, 0x84, 0x86,
|
||||
//
|
||||
// 0x88, 0x8A, 0x8C, 0x8E, 0x90, 0x92, 0x94, 0x96, 0x98, 0x9A, 0x9C, 0x9E, 0xA0, 0xA2, 0xA4, 0xA6,
|
||||
// 0xA8, 0xAA, 0xAC, 0xAE, 0xB0, 0xB2, 0xB4, 0xB6, 0xB8, 0xBA, 0xBC, 0xBE, 0xC0, 0xC2, 0xC4, 0xC6,
|
||||
// 0xC8, 0xCA, 0xCC, 0xCE, 0xD0, 0xD2, 0xD4, 0xD6, 0xD8, 0xDA, 0xDC, 0xDE, 0xE0, 0xE2, 0xE4, 0xE6,
|
||||
// 0xE8, 0xEA, 0xEC, 0xEE, 0xF0, 0xF2, 0xF4, 0xF6, 0xF8, 0xFA, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
// 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
// 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
// 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
// 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
func scaleAndBiasChromaUp(b *lowleveljpeg.BlockU8) {
|
||||
for i, v := range b {
|
||||
b[i] = scaleAndBiasChromaUpLUT[v]
|
||||
b[i] = uint8(max(0x00, min(0xFF, ((int(v)*2)-0x78))))
|
||||
}
|
||||
}
|
||||
|
||||
// scaleAndBiasChromaDown is equivalent to this [256]uint8 look-up table.
|
||||
//
|
||||
// 0x3C, 0x3C, 0x3D, 0x3D, 0x3E, 0x3E, 0x3F, 0x3F, 0x40, 0x40, 0x41, 0x41, 0x42, 0x42, 0x43, 0x43,
|
||||
// 0x44, 0x44, 0x45, 0x45, 0x46, 0x46, 0x47, 0x47, 0x48, 0x48, 0x49, 0x49, 0x4A, 0x4A, 0x4B, 0x4B,
|
||||
// 0x4C, 0x4C, 0x4D, 0x4D, 0x4E, 0x4E, 0x4F, 0x4F, 0x50, 0x50, 0x51, 0x51, 0x52, 0x52, 0x53, 0x53,
|
||||
// 0x54, 0x54, 0x55, 0x55, 0x56, 0x56, 0x57, 0x57, 0x58, 0x58, 0x59, 0x59, 0x5A, 0x5A, 0x5B, 0x5B,
|
||||
// 0x5C, 0x5C, 0x5D, 0x5D, 0x5E, 0x5E, 0x5F, 0x5F, 0x60, 0x60, 0x61, 0x61, 0x62, 0x62, 0x63, 0x63,
|
||||
// 0x64, 0x64, 0x65, 0x65, 0x66, 0x66, 0x67, 0x67, 0x68, 0x68, 0x69, 0x69, 0x6A, 0x6A, 0x6B, 0x6B,
|
||||
// 0x6C, 0x6C, 0x6D, 0x6D, 0x6E, 0x6E, 0x6F, 0x6F, 0x70, 0x70, 0x71, 0x71, 0x72, 0x72, 0x73, 0x73,
|
||||
// 0x74, 0x74, 0x75, 0x75, 0x76, 0x76, 0x77, 0x77, 0x78, 0x78, 0x79, 0x79, 0x7A, 0x7A, 0x7B, 0x7B,
|
||||
//
|
||||
// 0x7C, 0x7C, 0x7D, 0x7D, 0x7E, 0x7E, 0x7F, 0x7F, 0x80, 0x80, 0x81, 0x81, 0x82, 0x82, 0x83, 0x83,
|
||||
// 0x84, 0x84, 0x85, 0x85, 0x86, 0x86, 0x87, 0x87, 0x88, 0x88, 0x89, 0x89, 0x8A, 0x8A, 0x8B, 0x8B,
|
||||
// 0x8C, 0x8C, 0x8D, 0x8D, 0x8E, 0x8E, 0x8F, 0x8F, 0x90, 0x90, 0x91, 0x91, 0x92, 0x92, 0x93, 0x93,
|
||||
// 0x94, 0x94, 0x95, 0x95, 0x96, 0x96, 0x97, 0x97, 0x98, 0x98, 0x99, 0x99, 0x9A, 0x9A, 0x9B, 0x9B,
|
||||
// 0x9C, 0x9C, 0x9D, 0x9D, 0x9E, 0x9E, 0x9F, 0x9F, 0xA0, 0xA0, 0xA1, 0xA1, 0xA2, 0xA2, 0xA3, 0xA3,
|
||||
// 0xA4, 0xA4, 0xA5, 0xA5, 0xA6, 0xA6, 0xA7, 0xA7, 0xA8, 0xA8, 0xA9, 0xA9, 0xAA, 0xAA, 0xAB, 0xAB,
|
||||
// 0xAC, 0xAC, 0xAD, 0xAD, 0xAE, 0xAE, 0xAF, 0xAF, 0xB0, 0xB0, 0xB1, 0xB1, 0xB2, 0xB2, 0xB3, 0xB3,
|
||||
// 0xB4, 0xB4, 0xB5, 0xB5, 0xB6, 0xB6, 0xB7, 0xB7, 0xB8, 0xB8, 0xB9, 0xB9, 0xBA, 0xBA, 0xBB, 0xBB,
|
||||
func scaleAndBiasChromaDown(b *lowleveljpeg.BlockU8) {
|
||||
for i, v := range b {
|
||||
b[i] = scaleAndBiasChromaDownLUT[v]
|
||||
b[i] = (v >> 1) + 0x3C
|
||||
}
|
||||
}
|
||||
|
||||
var scaleAndBiasChromaUpLUT = [256]uint8{
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x04, 0x06,
|
||||
0x08, 0x0A, 0x0C, 0x0E, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x1E, 0x20, 0x22, 0x24, 0x26,
|
||||
0x28, 0x2A, 0x2C, 0x2E, 0x30, 0x32, 0x34, 0x36, 0x38, 0x3A, 0x3C, 0x3E, 0x40, 0x42, 0x44, 0x46,
|
||||
0x48, 0x4A, 0x4C, 0x4E, 0x50, 0x52, 0x54, 0x56, 0x58, 0x5A, 0x5C, 0x5E, 0x60, 0x62, 0x64, 0x66,
|
||||
0x68, 0x6A, 0x6C, 0x6E, 0x70, 0x72, 0x74, 0x76, 0x78, 0x7A, 0x7C, 0x7E, 0x80, 0x82, 0x84, 0x86,
|
||||
|
||||
0x88, 0x8A, 0x8C, 0x8E, 0x90, 0x92, 0x94, 0x96, 0x98, 0x9A, 0x9C, 0x9E, 0xA0, 0xA2, 0xA4, 0xA6,
|
||||
0xA8, 0xAA, 0xAC, 0xAE, 0xB0, 0xB2, 0xB4, 0xB6, 0xB8, 0xBA, 0xBC, 0xBE, 0xC0, 0xC2, 0xC4, 0xC6,
|
||||
0xC8, 0xCA, 0xCC, 0xCE, 0xD0, 0xD2, 0xD4, 0xD6, 0xD8, 0xDA, 0xDC, 0xDE, 0xE0, 0xE2, 0xE4, 0xE6,
|
||||
0xE8, 0xEA, 0xEC, 0xEE, 0xF0, 0xF2, 0xF4, 0xF6, 0xF8, 0xFA, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
}
|
||||
|
||||
var scaleAndBiasChromaDownLUT = [256]uint8{
|
||||
0x3C, 0x3C, 0x3D, 0x3D, 0x3E, 0x3E, 0x3F, 0x3F, 0x40, 0x40, 0x41, 0x41, 0x42, 0x42, 0x43, 0x43,
|
||||
0x44, 0x44, 0x45, 0x45, 0x46, 0x46, 0x47, 0x47, 0x48, 0x48, 0x49, 0x49, 0x4A, 0x4A, 0x4B, 0x4B,
|
||||
0x4C, 0x4C, 0x4D, 0x4D, 0x4E, 0x4E, 0x4F, 0x4F, 0x50, 0x50, 0x51, 0x51, 0x52, 0x52, 0x53, 0x53,
|
||||
0x54, 0x54, 0x55, 0x55, 0x56, 0x56, 0x57, 0x57, 0x58, 0x58, 0x59, 0x59, 0x5A, 0x5A, 0x5B, 0x5B,
|
||||
0x5C, 0x5C, 0x5D, 0x5D, 0x5E, 0x5E, 0x5F, 0x5F, 0x60, 0x60, 0x61, 0x61, 0x62, 0x62, 0x63, 0x63,
|
||||
0x64, 0x64, 0x65, 0x65, 0x66, 0x66, 0x67, 0x67, 0x68, 0x68, 0x69, 0x69, 0x6A, 0x6A, 0x6B, 0x6B,
|
||||
0x6C, 0x6C, 0x6D, 0x6D, 0x6E, 0x6E, 0x6F, 0x6F, 0x70, 0x70, 0x71, 0x71, 0x72, 0x72, 0x73, 0x73,
|
||||
0x74, 0x74, 0x75, 0x75, 0x76, 0x76, 0x77, 0x77, 0x78, 0x78, 0x79, 0x79, 0x7A, 0x7A, 0x7B, 0x7B,
|
||||
|
||||
0x7C, 0x7C, 0x7D, 0x7D, 0x7E, 0x7E, 0x7F, 0x7F, 0x80, 0x80, 0x81, 0x81, 0x82, 0x82, 0x83, 0x83,
|
||||
0x84, 0x84, 0x85, 0x85, 0x86, 0x86, 0x87, 0x87, 0x88, 0x88, 0x89, 0x89, 0x8A, 0x8A, 0x8B, 0x8B,
|
||||
0x8C, 0x8C, 0x8D, 0x8D, 0x8E, 0x8E, 0x8F, 0x8F, 0x90, 0x90, 0x91, 0x91, 0x92, 0x92, 0x93, 0x93,
|
||||
0x94, 0x94, 0x95, 0x95, 0x96, 0x96, 0x97, 0x97, 0x98, 0x98, 0x99, 0x99, 0x9A, 0x9A, 0x9B, 0x9B,
|
||||
0x9C, 0x9C, 0x9D, 0x9D, 0x9E, 0x9E, 0x9F, 0x9F, 0xA0, 0xA0, 0xA1, 0xA1, 0xA2, 0xA2, 0xA3, 0xA3,
|
||||
0xA4, 0xA4, 0xA5, 0xA5, 0xA6, 0xA6, 0xA7, 0xA7, 0xA8, 0xA8, 0xA9, 0xA9, 0xAA, 0xAA, 0xAB, 0xAB,
|
||||
0xAC, 0xAC, 0xAD, 0xAD, 0xAE, 0xAE, 0xAF, 0xAF, 0xB0, 0xB0, 0xB1, 0xB1, 0xB2, 0xB2, 0xB3, 0xB3,
|
||||
0xB4, 0xB4, 0xB5, 0xB5, 0xB6, 0xB6, 0xB7, 0xB7, 0xB8, 0xB8, 0xB9, 0xB9, 0xBA, 0xBA, 0xBB, 0xBB,
|
||||
}
|
||||
|
||||
// cubeRootLUT[x] is the cube root of x, when mapping the uint8 range [0x00,
|
||||
// 0xFF] to float64 range [-128/128, +127/128].
|
||||
var cubeRootLUT = [256]uint8{
|
||||
|
||||
@@ -19173,7 +19173,7 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
uint8_t v2,
|
||||
uint8_t v3,
|
||||
uint8_t ycc_model,
|
||||
bool triangle_filter_for_2to1,
|
||||
uint8_t ycc_upsampling,
|
||||
wuffs_base__slice_u8 scratch_buffer_2k);
|
||||
|
||||
// ---------------- Images (Utility)
|
||||
@@ -32370,7 +32370,36 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2(
|
||||
size_t src_len,
|
||||
uint32_t h1v2_bias_ignored,
|
||||
bool first_column,
|
||||
bool last_column);
|
||||
bool last_column,
|
||||
uint8_t odd_column_rounding);
|
||||
|
||||
static const uint8_t* //
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_libjpeg_x86_avx2(
|
||||
uint8_t* dst_ptr,
|
||||
const uint8_t* src_ptr_major,
|
||||
const uint8_t* src_ptr_minor,
|
||||
size_t src_len,
|
||||
uint32_t h1v2_bias_ignored,
|
||||
bool first_column,
|
||||
bool last_column) {
|
||||
return wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2(
|
||||
dst_ptr, src_ptr_major, src_ptr_minor, src_len, h1v2_bias_ignored,
|
||||
first_column, last_column, 7);
|
||||
}
|
||||
|
||||
static const uint8_t* //
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_libwebp_x86_avx2(
|
||||
uint8_t* dst_ptr,
|
||||
const uint8_t* src_ptr_major,
|
||||
const uint8_t* src_ptr_minor,
|
||||
size_t src_len,
|
||||
uint32_t h1v2_bias_ignored,
|
||||
bool first_column,
|
||||
bool last_column) {
|
||||
return wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2(
|
||||
dst_ptr, src_ptr_major, src_ptr_minor, src_len, h1v2_bias_ignored,
|
||||
first_column, last_column, 8);
|
||||
}
|
||||
#endif
|
||||
#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V3)
|
||||
|
||||
@@ -32729,8 +32758,8 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h1v2_triangle(
|
||||
const uint8_t* src_ptr_minor,
|
||||
size_t src_len,
|
||||
uint32_t h1v2_bias,
|
||||
bool first_column,
|
||||
bool last_column) {
|
||||
bool first_column_ignored,
|
||||
bool last_column_ignored) {
|
||||
uint8_t* dp = dst_ptr;
|
||||
const uint8_t* sp_major = src_ptr_major;
|
||||
const uint8_t* sp_minor = src_ptr_minor;
|
||||
@@ -32802,10 +32831,12 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle(
|
||||
size_t src_len,
|
||||
uint32_t h1v2_bias_ignored,
|
||||
bool first_column,
|
||||
bool last_column) {
|
||||
bool last_column,
|
||||
uint8_t odd_column_rounding) {
|
||||
uint8_t* dp = dst_ptr;
|
||||
const uint8_t* sp_major = src_ptr_major;
|
||||
const uint8_t* sp_minor = src_ptr_minor;
|
||||
const uint8_t oc = odd_column_rounding;
|
||||
|
||||
if (first_column) {
|
||||
src_len--;
|
||||
@@ -32813,7 +32844,7 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle(
|
||||
uint32_t sv = (12u * ((uint32_t)(*sp_major++))) + //
|
||||
(4u * ((uint32_t)(*sp_minor++)));
|
||||
*dp++ = (uint8_t)((sv + 8u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + 7u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + oc) >> 4u);
|
||||
return dst_ptr;
|
||||
}
|
||||
|
||||
@@ -32825,7 +32856,7 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle(
|
||||
uint32_t sv = (9u * ((uint32_t)(*sp_major++))) + //
|
||||
(3u * ((uint32_t)(*sp_minor++)));
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_m1) + (sv_minor_m1) + 8u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + 7u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + oc) >> 4u);
|
||||
if (src_len <= 0u) {
|
||||
return dst_ptr;
|
||||
}
|
||||
@@ -32844,7 +32875,7 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle(
|
||||
uint32_t sv = (9u * ((uint32_t)(*sp_major++))) + //
|
||||
(3u * ((uint32_t)(*sp_minor++)));
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_m1) + (sv_minor_m1) + 8u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + 7u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + oc) >> 4u);
|
||||
}
|
||||
|
||||
if (last_column) {
|
||||
@@ -32856,12 +32887,40 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle(
|
||||
uint32_t sv = (9u * ((uint32_t)(*sp_major++))) + //
|
||||
(3u * ((uint32_t)(*sp_minor++)));
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_m1) + (sv_minor_m1) + 8u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + 7u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + oc) >> 4u);
|
||||
}
|
||||
|
||||
return dst_ptr;
|
||||
}
|
||||
|
||||
static const uint8_t* //
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_libjpeg(
|
||||
uint8_t* dst_ptr,
|
||||
const uint8_t* src_ptr_major,
|
||||
const uint8_t* src_ptr_minor,
|
||||
size_t src_len,
|
||||
uint32_t h1v2_bias_ignored,
|
||||
bool first_column,
|
||||
bool last_column) {
|
||||
return wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle(
|
||||
dst_ptr, src_ptr_major, src_ptr_minor, src_len, h1v2_bias_ignored,
|
||||
first_column, last_column, 7);
|
||||
}
|
||||
|
||||
static const uint8_t* //
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_libwebp(
|
||||
uint8_t* dst_ptr,
|
||||
const uint8_t* src_ptr_major,
|
||||
const uint8_t* src_ptr_minor,
|
||||
size_t src_len,
|
||||
uint32_t h1v2_bias_ignored,
|
||||
bool first_column,
|
||||
bool last_column) {
|
||||
return wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle(
|
||||
dst_ptr, src_ptr_major, src_ptr_minor, src_len, h1v2_bias_ignored,
|
||||
first_column, last_column, 8);
|
||||
}
|
||||
|
||||
// wuffs_private_impl__swizzle_ycc__upsample_funcs is indexed by inv_h and then
|
||||
// inv_v.
|
||||
static const wuffs_private_impl__swizzle_ycc__upsample_func
|
||||
@@ -33613,7 +33672,7 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
uint8_t v2,
|
||||
uint8_t v3,
|
||||
uint8_t ycc_model,
|
||||
bool triangle_filter_for_2to1,
|
||||
uint8_t ycc_upsampling,
|
||||
wuffs_base__slice_u8 scratch_buffer_2k) {
|
||||
if (!p) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
@@ -33628,7 +33687,7 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
(4u <= ((unsigned int)v0 - 1u)) || //
|
||||
(4u <= ((unsigned int)v1 - 1u)) || //
|
||||
(4u <= ((unsigned int)v2 - 1u)) || //
|
||||
(triangle_filter_for_2to1 && ((x_min_incl | y_min_incl) > 0u)) ||
|
||||
((ycc_upsampling != 0) && ((x_min_incl | y_min_incl) > 0u)) ||
|
||||
(scratch_buffer_2k.len < 2048u)) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
@@ -33936,7 +33995,7 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
memcpy(&upfuncs, &wuffs_private_impl__swizzle_ycc__upsample_funcs,
|
||||
sizeof upfuncs);
|
||||
|
||||
if (triangle_filter_for_2to1 &&
|
||||
if ((ycc_upsampling != 0) &&
|
||||
(wuffs_private_impl__swizzle_has_triangle_upsampler(inv_h0, inv_v0) ||
|
||||
wuffs_private_impl__swizzle_has_triangle_upsampler(inv_h1, inv_v1) ||
|
||||
wuffs_private_impl__swizzle_has_triangle_upsampler(inv_h2, inv_v2) ||
|
||||
@@ -33946,7 +34005,10 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
|
||||
upfuncs[0][1] = wuffs_private_impl__swizzle_ycc__upsample_inv_h1v2_triangle;
|
||||
upfuncs[1][0] = wuffs_private_impl__swizzle_ycc__upsample_inv_h2v1_triangle;
|
||||
upfuncs[1][1] = wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle;
|
||||
upfuncs[1][1] =
|
||||
(ycc_upsampling == 1)
|
||||
? wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_libjpeg
|
||||
: wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_libwebp;
|
||||
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V3)
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
@@ -33964,7 +34026,9 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
#else
|
||||
if (wuffs_base__cpu_arch__have_x86_avx2()) {
|
||||
upfuncs[1][1] =
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2;
|
||||
(ycc_upsampling == 1)
|
||||
? wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_libjpeg_x86_avx2
|
||||
: wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_libwebp_x86_avx2;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -34439,10 +34503,12 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2(
|
||||
size_t src_len,
|
||||
uint32_t h1v2_bias_ignored,
|
||||
bool first_column,
|
||||
bool last_column) {
|
||||
bool last_column,
|
||||
uint8_t odd_column_rounding) {
|
||||
uint8_t* dp = dst_ptr;
|
||||
const uint8_t* sp_major = src_ptr_major;
|
||||
const uint8_t* sp_minor = src_ptr_minor;
|
||||
const uint8_t oc = odd_column_rounding;
|
||||
|
||||
if (first_column) {
|
||||
src_len--;
|
||||
@@ -34450,7 +34516,7 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2(
|
||||
uint32_t sv = (12u * ((uint32_t)(*sp_major++))) + //
|
||||
(4u * ((uint32_t)(*sp_minor++)));
|
||||
*dp++ = (uint8_t)((sv + 8u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + 7u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + oc) >> 4u);
|
||||
return dst_ptr;
|
||||
}
|
||||
|
||||
@@ -34462,7 +34528,7 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2(
|
||||
uint32_t sv = (9u * ((uint32_t)(*sp_major++))) + //
|
||||
(3u * ((uint32_t)(*sp_minor++)));
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_m1) + (sv_minor_m1) + 8u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + 7u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + oc) >> 4u);
|
||||
if (src_len <= 0u) {
|
||||
return dst_ptr;
|
||||
}
|
||||
@@ -34483,7 +34549,7 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2(
|
||||
uint32_t sv = (9u * ((uint32_t)(*sp_major++))) + //
|
||||
(3u * ((uint32_t)(*sp_minor++)));
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_m1) + (sv_minor_m1) + 8u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + 7u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + oc) >> 4u);
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -34556,8 +34622,8 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2(
|
||||
// the u16 right value by 4. On the right (p1), shift right by 4 and then
|
||||
// shift left by 8 so that, when still in the u16x16 little-endian
|
||||
// interpretation, we have:
|
||||
// - m1_element = (etcetera + 8) >> 4
|
||||
// - p1_element = ((etcetera + 7) >> 4) << 8
|
||||
// - m1_element = (etcetera + 8) >> 4
|
||||
// - p1_element = ((etcetera + oc) >> 4) << 8
|
||||
//
|
||||
// step4_m1_lo = [0x00?? 0x00?? ... 0x00?? 0x00??]
|
||||
// step4_p1_lo = [0x??00 0x??00 ... 0x??00 0x??00]
|
||||
@@ -34566,14 +34632,14 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2(
|
||||
__m256i step4_m1_lo = _mm256_srli_epi16(
|
||||
_mm256_add_epi16(step3_m1_lo, _mm256_set1_epi16(8)), 4);
|
||||
__m256i step4_p1_lo = _mm256_slli_epi16(
|
||||
_mm256_srli_epi16(_mm256_add_epi16(step3_p1_lo, _mm256_set1_epi16(7)),
|
||||
4),
|
||||
_mm256_srli_epi16(
|
||||
_mm256_add_epi16(step3_p1_lo, _mm256_set1_epi16(oc)), 4),
|
||||
8);
|
||||
__m256i step4_m1_hi = _mm256_srli_epi16(
|
||||
_mm256_add_epi16(step3_m1_hi, _mm256_set1_epi16(8)), 4);
|
||||
__m256i step4_p1_hi = _mm256_slli_epi16(
|
||||
_mm256_srli_epi16(_mm256_add_epi16(step3_p1_hi, _mm256_set1_epi16(7)),
|
||||
4),
|
||||
_mm256_srli_epi16(
|
||||
_mm256_add_epi16(step3_p1_hi, _mm256_set1_epi16(oc)), 4),
|
||||
8);
|
||||
|
||||
// Bitwise-or two "0x00"-rich u16x16 vectors to get a u8x32 vector. Do
|
||||
@@ -34624,7 +34690,7 @@ wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2(
|
||||
uint32_t sv = (9u * ((uint32_t)(*sp_major++))) + //
|
||||
(3u * ((uint32_t)(*sp_minor++)));
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_m1) + (sv_minor_m1) + 8u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + 7u) >> 4u);
|
||||
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + oc) >> 4u);
|
||||
}
|
||||
|
||||
return dst_ptr;
|
||||
@@ -50631,42 +50697,6 @@ WUFFS_HANDSUM__ZIGZAG[2][15] WUFFS_BASE__POTENTIALLY_UNUSED = {
|
||||
},
|
||||
};
|
||||
|
||||
static const uint8_t
|
||||
WUFFS_HANDSUM__SCALE_AND_BIAS_CHROMA_DOWN[256] WUFFS_BASE__POTENTIALLY_UNUSED = {
|
||||
60u, 60u, 61u, 61u, 62u, 62u, 63u, 63u,
|
||||
64u, 64u, 65u, 65u, 66u, 66u, 67u, 67u,
|
||||
68u, 68u, 69u, 69u, 70u, 70u, 71u, 71u,
|
||||
72u, 72u, 73u, 73u, 74u, 74u, 75u, 75u,
|
||||
76u, 76u, 77u, 77u, 78u, 78u, 79u, 79u,
|
||||
80u, 80u, 81u, 81u, 82u, 82u, 83u, 83u,
|
||||
84u, 84u, 85u, 85u, 86u, 86u, 87u, 87u,
|
||||
88u, 88u, 89u, 89u, 90u, 90u, 91u, 91u,
|
||||
92u, 92u, 93u, 93u, 94u, 94u, 95u, 95u,
|
||||
96u, 96u, 97u, 97u, 98u, 98u, 99u, 99u,
|
||||
100u, 100u, 101u, 101u, 102u, 102u, 103u, 103u,
|
||||
104u, 104u, 105u, 105u, 106u, 106u, 107u, 107u,
|
||||
108u, 108u, 109u, 109u, 110u, 110u, 111u, 111u,
|
||||
112u, 112u, 113u, 113u, 114u, 114u, 115u, 115u,
|
||||
116u, 116u, 117u, 117u, 118u, 118u, 119u, 119u,
|
||||
120u, 120u, 121u, 121u, 122u, 122u, 123u, 123u,
|
||||
124u, 124u, 125u, 125u, 126u, 126u, 127u, 127u,
|
||||
128u, 128u, 129u, 129u, 130u, 130u, 131u, 131u,
|
||||
132u, 132u, 133u, 133u, 134u, 134u, 135u, 135u,
|
||||
136u, 136u, 137u, 137u, 138u, 138u, 139u, 139u,
|
||||
140u, 140u, 141u, 141u, 142u, 142u, 143u, 143u,
|
||||
144u, 144u, 145u, 145u, 146u, 146u, 147u, 147u,
|
||||
148u, 148u, 149u, 149u, 150u, 150u, 151u, 151u,
|
||||
152u, 152u, 153u, 153u, 154u, 154u, 155u, 155u,
|
||||
156u, 156u, 157u, 157u, 158u, 158u, 159u, 159u,
|
||||
160u, 160u, 161u, 161u, 162u, 162u, 163u, 163u,
|
||||
164u, 164u, 165u, 165u, 166u, 166u, 167u, 167u,
|
||||
168u, 168u, 169u, 169u, 170u, 170u, 171u, 171u,
|
||||
172u, 172u, 173u, 173u, 174u, 174u, 175u, 175u,
|
||||
176u, 176u, 177u, 177u, 178u, 178u, 179u, 179u,
|
||||
180u, 180u, 181u, 181u, 182u, 182u, 183u, 183u,
|
||||
184u, 184u, 185u, 185u, 186u, 186u, 187u, 187u,
|
||||
};
|
||||
|
||||
static const uint8_t
|
||||
WUFFS_HANDSUM__CUBE_ROOT[256] WUFFS_BASE__POTENTIALLY_UNUSED = {
|
||||
0u, 0u, 1u, 1u, 1u, 2u, 2u, 2u,
|
||||
@@ -52175,8 +52205,8 @@ wuffs_handsum__decoder__scale_and_bias_chroma_down(
|
||||
while (v_y < 8u) {
|
||||
v_x = 0u;
|
||||
while (v_x < 8u) {
|
||||
self->private_data.f_buffers[1u][v_y][((4u * v_x) + 1u)] = WUFFS_HANDSUM__SCALE_AND_BIAS_CHROMA_DOWN[self->private_data.f_buffers[1u][v_y][((4u * v_x) + 1u)]];
|
||||
self->private_data.f_buffers[1u][v_y][((4u * v_x) + 2u)] = WUFFS_HANDSUM__SCALE_AND_BIAS_CHROMA_DOWN[self->private_data.f_buffers[1u][v_y][((4u * v_x) + 2u)]];
|
||||
self->private_data.f_buffers[1u][v_y][((4u * v_x) + 1u)] = ((uint8_t)(60u + ((uint8_t)(self->private_data.f_buffers[1u][v_y][((4u * v_x) + 1u)] >> 1u))));
|
||||
self->private_data.f_buffers[1u][v_y][((4u * v_x) + 2u)] = ((uint8_t)(60u + ((uint8_t)(self->private_data.f_buffers[1u][v_y][((4u * v_x) + 2u)] >> 1u))));
|
||||
v_x += 1u;
|
||||
}
|
||||
v_y += 1u;
|
||||
@@ -57760,6 +57790,7 @@ wuffs_jpeg__decoder__swizzle_colorful(
|
||||
uint32_t v_height1 = 0;
|
||||
uint32_t v_height2 = 0;
|
||||
uint32_t v_height3 = 0;
|
||||
uint8_t v_ycc_upsampling = 0;
|
||||
wuffs_base__status v_status = wuffs_base__make_status(NULL);
|
||||
|
||||
if (self->private_impl.f_swizzle_immediately) {
|
||||
@@ -57821,6 +57852,10 @@ wuffs_jpeg__decoder__swizzle_colorful(
|
||||
v_height3 = self->private_impl.f_components_workbuf_heights[3u];
|
||||
}
|
||||
}
|
||||
v_ycc_upsampling = ((uint8_t)(0u));
|
||||
if ( ! self->private_impl.f_use_lower_quality) {
|
||||
v_ycc_upsampling = ((uint8_t)(1u));
|
||||
}
|
||||
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)),
|
||||
@@ -57853,7 +57888,7 @@ wuffs_jpeg__decoder__swizzle_colorful(
|
||||
self->private_impl.f_components_v[2u],
|
||||
self->private_impl.f_components_v[3u],
|
||||
self->private_impl.f_ycc_model,
|
||||
! self->private_impl.f_use_lower_quality,
|
||||
v_ycc_upsampling,
|
||||
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);
|
||||
}
|
||||
@@ -81838,7 +81873,7 @@ wuffs_vp8__decoder__initialize_mb_coeffs(
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static uint32_t
|
||||
wuffs_vp8__decoder__decode_block_coefficients(
|
||||
wuffs_vp8__decoder__decode_subblock_coefficients(
|
||||
wuffs_vp8__decoder* self,
|
||||
wuffs_base__slice_u8 a_workbuf,
|
||||
uint32_t a_mby,
|
||||
@@ -82043,11 +82078,10 @@ wuffs_vp8__decoder__copy_from_yuv_cache(
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_vp8__decoder__swizzle_one_row_of_macroblocks(
|
||||
wuffs_vp8__decoder__swizzle(
|
||||
wuffs_vp8__decoder* self,
|
||||
wuffs_base__pixel_buffer* a_dst,
|
||||
wuffs_base__slice_u8 a_workbuf,
|
||||
uint32_t a_mby);
|
||||
wuffs_base__slice_u8 a_workbuf);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__empty_struct
|
||||
@@ -82342,7 +82376,7 @@ wuffs_vp8__decoder__decode_coefficients(
|
||||
self->private_data.f_mb_states_left &= 4286578687u;
|
||||
v_tnz = (1u & (self->private_data.f_mb_states_top[a_mbx] >> 23u));
|
||||
self->private_data.f_mb_states_top[a_mbx] &= 4286578687u;
|
||||
v_lnz = wuffs_vp8__decoder__decode_block_coefficients(self,
|
||||
v_lnz = wuffs_vp8__decoder__decode_subblock_coefficients(self,
|
||||
a_workbuf,
|
||||
a_mby,
|
||||
a_seg,
|
||||
@@ -82363,7 +82397,7 @@ wuffs_vp8__decoder__decode_coefficients(
|
||||
v_tnz = (1u & (self->private_data.f_mb_states_top[a_mbx] >> (24u + v_bx)));
|
||||
self->private_data.f_mb_states_top[a_mbx] &= (4294967295u ^ (((uint32_t)(1u)) << (24u + v_bx)));
|
||||
v_b = ((4u * v_by) + v_bx);
|
||||
v_lnz = wuffs_vp8__decoder__decode_block_coefficients(self,
|
||||
v_lnz = wuffs_vp8__decoder__decode_subblock_coefficients(self,
|
||||
a_workbuf,
|
||||
a_mby,
|
||||
a_seg,
|
||||
@@ -82396,7 +82430,7 @@ wuffs_vp8__decoder__decode_coefficients(
|
||||
(2u * v_by) +
|
||||
v_bx +
|
||||
16u);
|
||||
v_lnz = wuffs_vp8__decoder__decode_block_coefficients(self,
|
||||
v_lnz = wuffs_vp8__decoder__decode_subblock_coefficients(self,
|
||||
a_workbuf,
|
||||
a_mby,
|
||||
a_seg,
|
||||
@@ -82444,11 +82478,11 @@ wuffs_vp8__decoder__initialize_mb_coeffs(
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
// -------- func vp8.decoder.decode_block_coefficients
|
||||
// -------- func vp8.decoder.decode_subblock_coefficients
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static uint32_t
|
||||
wuffs_vp8__decoder__decode_block_coefficients(
|
||||
wuffs_vp8__decoder__decode_subblock_coefficients(
|
||||
wuffs_vp8__decoder* self,
|
||||
wuffs_base__slice_u8 a_workbuf,
|
||||
uint32_t a_mby,
|
||||
@@ -83920,22 +83954,17 @@ wuffs_vp8__decoder__decode_macroblocks(
|
||||
} else {
|
||||
wuffs_vp8__decoder__filter_normal(self, a_workbuf, (v_mby - 1u));
|
||||
}
|
||||
v_status = wuffs_vp8__decoder__swizzle_one_row_of_macroblocks(self, a_dst, a_workbuf, (v_mby - 1u));
|
||||
if ( ! wuffs_base__status__is_ok(&v_status)) {
|
||||
return wuffs_private_impl__status__ensure_not_a_suspension(v_status);
|
||||
}
|
||||
}
|
||||
v_mby += 1u;
|
||||
}
|
||||
if (self->private_impl.f_mbh > 0u) {
|
||||
v_mby = (self->private_impl.f_mbh - 1u);
|
||||
if (self->private_impl.f_filt_level <= 0u) {
|
||||
} else if (self->private_impl.f_filt_simple) {
|
||||
wuffs_vp8__decoder__filter_simple(self, a_workbuf, v_mby);
|
||||
wuffs_vp8__decoder__filter_simple(self, a_workbuf, (self->private_impl.f_mbh - 1u));
|
||||
} else {
|
||||
wuffs_vp8__decoder__filter_normal(self, a_workbuf, v_mby);
|
||||
wuffs_vp8__decoder__filter_normal(self, a_workbuf, (self->private_impl.f_mbh - 1u));
|
||||
}
|
||||
v_status = wuffs_vp8__decoder__swizzle_one_row_of_macroblocks(self, a_dst, a_workbuf, v_mby);
|
||||
v_status = wuffs_vp8__decoder__swizzle(self, a_dst, a_workbuf);
|
||||
if ( ! wuffs_base__status__is_ok(&v_status)) {
|
||||
return wuffs_private_impl__status__ensure_not_a_suspension(v_status);
|
||||
}
|
||||
@@ -84196,61 +84225,41 @@ wuffs_vp8__decoder__copy_from_yuv_cache(
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
// -------- func vp8.decoder.swizzle_one_row_of_macroblocks
|
||||
// -------- func vp8.decoder.swizzle
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_vp8__decoder__swizzle_one_row_of_macroblocks(
|
||||
wuffs_vp8__decoder__swizzle(
|
||||
wuffs_vp8__decoder* self,
|
||||
wuffs_base__pixel_buffer* a_dst,
|
||||
wuffs_base__slice_u8 a_workbuf,
|
||||
uint32_t a_mby) {
|
||||
uint32_t v_y_min_incl = 0;
|
||||
uint32_t v_y_max_excl = 0;
|
||||
uint64_t v_o = 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 a_workbuf) {
|
||||
wuffs_base__status v_status = wuffs_base__make_status(NULL);
|
||||
|
||||
if ((self->private_impl.f_workbuf_yuv_y_end > self->private_impl.f_workbuf_yuv_u_end) || (self->private_impl.f_workbuf_yuv_u_end > self->private_impl.f_workbuf_yuv_v_end) || (self->private_impl.f_workbuf_yuv_v_end > ((uint64_t)(a_workbuf.len)))) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_workbuf_length);
|
||||
}
|
||||
v_y_min_incl = wuffs_base__u32__sat_sub((a_mby * 16u), 6u);
|
||||
v_y_max_excl = ((a_mby * 16u) + 10u);
|
||||
if ((a_mby + 1u) >= self->private_impl.f_mbh) {
|
||||
v_y_max_excl = self->private_impl.f_height;
|
||||
}
|
||||
v_o = ((uint64_t)((v_y_min_incl * self->private_impl.f_workbuf_yuv_y_stride)));
|
||||
if (v_o < self->private_impl.f_workbuf_yuv_y_end) {
|
||||
v_src0 = wuffs_base__slice_u8__subslice_ij(a_workbuf, v_o, self->private_impl.f_workbuf_yuv_y_end);
|
||||
}
|
||||
v_o = (((uint64_t)(((v_y_min_incl / 2u) * self->private_impl.f_workbuf_yuv_uv_stride))) + self->private_impl.f_workbuf_yuv_y_end);
|
||||
if (v_o < self->private_impl.f_workbuf_yuv_u_end) {
|
||||
v_src1 = wuffs_base__slice_u8__subslice_ij(a_workbuf, v_o, self->private_impl.f_workbuf_yuv_u_end);
|
||||
}
|
||||
v_o = (((uint64_t)(((v_y_min_incl / 2u) * self->private_impl.f_workbuf_yuv_uv_stride))) + self->private_impl.f_workbuf_yuv_u_end);
|
||||
if (v_o < self->private_impl.f_workbuf_yuv_v_end) {
|
||||
v_src2 = wuffs_base__slice_u8__subslice_ij(a_workbuf, v_o, self->private_impl.f_workbuf_yuv_v_end);
|
||||
}
|
||||
v_status = wuffs_base__pixel_swizzler__swizzle_ycck(&self->private_impl.f_swizzler,
|
||||
a_dst,
|
||||
wuffs_base__pixel_buffer__palette(a_dst),
|
||||
0u,
|
||||
self->private_impl.f_width,
|
||||
v_y_min_incl,
|
||||
v_y_max_excl,
|
||||
v_src0,
|
||||
v_src1,
|
||||
v_src2,
|
||||
0u,
|
||||
self->private_impl.f_height,
|
||||
wuffs_base__slice_u8__subslice_j(a_workbuf, self->private_impl.f_workbuf_yuv_y_end),
|
||||
wuffs_base__slice_u8__subslice_ij(a_workbuf,
|
||||
self->private_impl.f_workbuf_yuv_y_end,
|
||||
self->private_impl.f_workbuf_yuv_u_end),
|
||||
wuffs_base__slice_u8__subslice_ij(a_workbuf,
|
||||
self->private_impl.f_workbuf_yuv_u_end,
|
||||
self->private_impl.f_workbuf_yuv_v_end),
|
||||
wuffs_base__utility__empty_slice_u8(),
|
||||
(self->private_impl.f_mbw * 16u),
|
||||
(self->private_impl.f_mbw * 8u),
|
||||
(self->private_impl.f_mbw * 8u),
|
||||
0u,
|
||||
wuffs_base__u32__sat_sub((self->private_impl.f_mbh * 16u), v_y_min_incl),
|
||||
wuffs_base__u32__sat_sub((self->private_impl.f_mbh * 8u), (v_y_min_incl / 2u)),
|
||||
wuffs_base__u32__sat_sub((self->private_impl.f_mbh * 8u), (v_y_min_incl / 2u)),
|
||||
(self->private_impl.f_mbh * 16u),
|
||||
(self->private_impl.f_mbh * 8u),
|
||||
(self->private_impl.f_mbh * 8u),
|
||||
0u,
|
||||
(self->private_impl.f_mbw * 16u),
|
||||
(self->private_impl.f_mbw * 8u),
|
||||
@@ -84265,7 +84274,7 @@ wuffs_vp8__decoder__swizzle_one_row_of_macroblocks(
|
||||
1u,
|
||||
0u,
|
||||
((uint8_t)(1u)),
|
||||
false,
|
||||
((uint8_t)(2u)),
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -85,15 +85,15 @@ extern "C" {
|
||||
// each major.minor branch, the commit count should increase monotonically.
|
||||
//
|
||||
// WUFFS_VERSION was overridden by "wuffs gen -version" based on revision
|
||||
// a138188d5742c0469de983878a430bdbe7e50e77 committed on 2024-04-19.
|
||||
#define WUFFS_VERSION 0x000030004
|
||||
// 40445d992b97be816cd09b0460c55e6a160389f6 committed on 2026-07-11.
|
||||
#define WUFFS_VERSION 0x000030005
|
||||
#define WUFFS_VERSION_MAJOR 0
|
||||
#define WUFFS_VERSION_MINOR 3
|
||||
#define WUFFS_VERSION_PATCH 4
|
||||
#define WUFFS_VERSION_PATCH 5
|
||||
#define WUFFS_VERSION_PRE_RELEASE_LABEL ""
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3401
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20240419
|
||||
#define WUFFS_VERSION_STRING "0.3.4+3401.20240419"
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3404
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20260711
|
||||
#define WUFFS_VERSION_STRING "0.3.5+3404.20260711"
|
||||
|
||||
// ---------------- Configuration
|
||||
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
// Copyright 2026 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// ----------------
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define BASIC_HANDSUM_DECODE_CONFIG__STATIC_FUNCTIONS
|
||||
#define BASIC_HANDSUM_DECODE_IMPLEMENTATION
|
||||
#include "../snippet/basic-handsum-decode.c"
|
||||
|
||||
// ----
|
||||
|
||||
// Hard-code a color=3, quality-4 Handsum image file, known in this repo as
|
||||
// test/data/mona-lisa.21x32.c3q4.handsum
|
||||
const uint8_t g_src_ptr__mona_lisa_21_32_c3q4_handsum[] = {
|
||||
0xfe, 0xd7, 0x7a, 0x87, 0x76, 0x68, 0x87, 0x75, 0x89, 0x77, 0x8c, 0xb7,
|
||||
0xc7, 0x9b, 0x78, 0x64, 0x5a, 0x98, 0xb4, 0x79, 0xe6, 0x75, 0x57, 0x8a,
|
||||
0x84, 0x88, 0x03, 0x86, 0x7a, 0x68, 0x87, 0x76, 0x68, 0xf4, 0x55, 0xe2,
|
||||
0x68, 0x9a, 0x89, 0xf4, 0x3b, 0x94, 0x75, 0x6a, 0xb8, 0xf8, 0x32, 0x68,
|
||||
0x55, 0x6a, 0x78, 0x55, 0x48, 0xac, 0x53, 0x6b, 0xf6, 0x93, 0x3b, 0x78,
|
||||
0x83, 0x25, 0x99, 0x92, 0x29, 0xb6, 0x66, 0x6a, 0x9a, 0x81, 0x19, 0x97,
|
||||
0x92, 0x2c, 0xb9, 0xd5, 0x3f, 0x88, 0x82, 0x48, 0xa6, 0x91, 0x19, 0x98,
|
||||
0x71, 0x38, 0x96, 0xa3, 0x26, 0x79, 0x81, 0x29, 0x97, 0x91, 0x1a, 0x98,
|
||||
0x81, 0x19, 0x97, 0x95, 0x58, 0xbb, 0x86, 0x57, 0x98, 0x96, 0x5a, 0x9e,
|
||||
0x26, 0x6c, 0x99, 0x87, 0x76, 0x4a, 0x78, 0x84, 0x6a, 0xa9, 0x67, 0x08,
|
||||
0x78, 0x94, 0x88, 0x88, 0x97, 0x45, 0xa8, 0x86, 0x78, 0x89, 0xa5, 0x85,
|
||||
0xba, 0x86, 0x58, 0x8a, 0x9a, 0xa8, 0x89, 0x9a, 0xa7, 0x79, 0xa9, 0xc8,
|
||||
0x99, 0x8b, 0x87,
|
||||
};
|
||||
const size_t g_src_len__mona_lisa_21_32_c3q4_handsum = 147;
|
||||
|
||||
// ----
|
||||
|
||||
int //
|
||||
main(int argc, char** argv) {
|
||||
basic_handsum_decode__pixel_buffer pixbuf;
|
||||
int result = basic_handsum_decode__decode(
|
||||
&pixbuf, g_src_ptr__mona_lisa_21_32_c3q4_handsum,
|
||||
g_src_len__mona_lisa_21_32_c3q4_handsum);
|
||||
|
||||
if (result != 0) {
|
||||
fprintf(stderr, "basic_handsum_decode__decode failed, result code: %d\n",
|
||||
result);
|
||||
return 1;
|
||||
|
||||
} else if ((pixbuf.width < 1) || (pixbuf.width > 16) || //
|
||||
(pixbuf.height < 1) || (pixbuf.height > 16)) {
|
||||
fprintf(stderr,
|
||||
"basic_handsum_decode__decode produced invalid dimensions\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Print pixbuf to stdout in the NIE image format (doc/spec/nie-spec.md).
|
||||
//
|
||||
// For test/data/mona-lisa.21x32.c3q4.handsum, the sha256sum of the output
|
||||
// should be 9749f54780a135710a50014fa827a04128e614903c48467fe8cf3e0b4ebeff62.
|
||||
//
|
||||
// This can be compared to Wuffs' full-featured (not just the c3q4 that
|
||||
// snippet/basic-handsum-decode.c supports) Handsum decoder implementation:
|
||||
//
|
||||
// clang-format off
|
||||
//
|
||||
// ./build-example.sh example/convert-to-nia
|
||||
// ./gen/bin/example-convert-to-nia -1 test/data/mona-lisa.21x32.c3q4.handsum | sha256sum
|
||||
//
|
||||
// clang-format on
|
||||
//
|
||||
// The example/imageviewer and example/stb-imagedumper programs can also view
|
||||
// NIE files directly.
|
||||
|
||||
uint8_t out[1040];
|
||||
out[0x0] = 0x6E;
|
||||
out[0x1] = 0xC3;
|
||||
out[0x2] = 0xAF;
|
||||
out[0x3] = 0x45;
|
||||
out[0x4] = 0xFF;
|
||||
out[0x5] = 0x62;
|
||||
out[0x6] = 0x6E;
|
||||
out[0x7] = 0x34;
|
||||
out[0x8] = pixbuf.width;
|
||||
out[0x9] = 0x00;
|
||||
out[0xA] = 0x00;
|
||||
out[0xB] = 0x00;
|
||||
out[0xC] = pixbuf.height;
|
||||
out[0xD] = 0x00;
|
||||
out[0xE] = 0x00;
|
||||
out[0xF] = 0x00;
|
||||
|
||||
size_t n = 4 * pixbuf.width * pixbuf.height;
|
||||
memcpy(&out[16], &pixbuf.bgra_pixels[0], n);
|
||||
if (write(1, out, 16 + n) < 0) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,283 @@
|
||||
// Copyright 2026 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
//go:build ignore
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
// replicate-libwebp-chroma-upsampling.go tests a Go port of libwebp's "fancy"
|
||||
// 4:2:0 chroma upsampling algorithm. This is a 9:3:3:1 triangle filter (the
|
||||
// 2-Dimensional analogue of the 1-Dimensional 3:1 triangle filter).
|
||||
//
|
||||
// libwebp's "fancy" upsampling is very similar to (but not exactly the same
|
||||
// as) libjpeg's "fancy" upsampling. Both are 9:3:3:1 and the weights sum to
|
||||
// 16, but they use a different integer arithmetic rounding algorithm:
|
||||
//
|
||||
// - libwebp uses truncate((weighted_average + 8) / 16), everywhere.
|
||||
// - libjpeg uses truncate((weighted_average + H) / 16), where H is 8
|
||||
// (rounding up) for even columns and 7 (rounding down) for odd columns.
|
||||
//
|
||||
// libwebp's plain C implementation is the src/dsp/upsampling.c UPSAMPLE_FUNC
|
||||
// macro. While it doesn't affect rounding, the macro also computes Cb and Cr
|
||||
// simultaneously using SWAR (SIMD Within A Register), packing u16x2 into a
|
||||
// u32, which this Go re-implementation does not replicate. libwebp also has
|
||||
// other SIMD-optimized implementations.
|
||||
//
|
||||
// libjpeg's plain C implementation is the jdsample.c h2v2_fancy_upsample
|
||||
// function. libjpeg also has other SIMD-optimized implementations.
|
||||
//
|
||||
// Usage: "go run replicate-libwebp-chroma-upsampling.go" should print nothing,
|
||||
// but it would print a diff if the hard-coded tests fail.
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := main1(); err != nil {
|
||||
os.Stderr.WriteString(err.Error() + "\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func main1() error {
|
||||
{
|
||||
dst := make([]byte, len(dstSamplesMona))
|
||||
upsampleImage(dst, 21, 32, srcSamplesMona[:], 16, 16)
|
||||
compare(dst, dstSamplesMona[:], 21, "test/data/mona-lisa.21x32.q90.lossy.webp")
|
||||
}
|
||||
|
||||
{
|
||||
dst := make([]byte, len(dstSamplesPeac))
|
||||
upsampleImage(dst, 24, 19, srcSamplesPeac[:], 16, 16)
|
||||
compare(dst, dstSamplesPeac[:], 24, "test/data/peacock.24x19.lossy.webp")
|
||||
}
|
||||
|
||||
if failed {
|
||||
return errors.New("Failed.")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func upsampleImage(dst []byte, dstw int, dsth int, src []byte, srcw int, srch int) {
|
||||
if (dstw <= 0) || (dsth <= 0) || (srcw <= 0) || (srch <= 0) {
|
||||
return
|
||||
}
|
||||
|
||||
// The dsty sequence is 0, 1, 3, 5, 7, 9, ...
|
||||
for dsty := 0; dsty < dsth; {
|
||||
dsty0 := dsty + 0
|
||||
dsty1 := dsty + 1
|
||||
srcy0 := dsty >> 1
|
||||
srcy1 := srcy0 + 1
|
||||
|
||||
if dsty == 0 { // First row.
|
||||
dsty1 = -1
|
||||
srcy1 = 0
|
||||
dsty = 1
|
||||
|
||||
} else if (dsty + 1) >= dsth { // Last row, when dsth is even.
|
||||
dsty1 = -1
|
||||
srcy1 = srcy0
|
||||
dsty += 1
|
||||
|
||||
} else { // All other rows.
|
||||
dsty += 2
|
||||
}
|
||||
|
||||
dst0 := dst[(dsty0+0)*dstw : (dsty0+1)*dstw]
|
||||
dst1 := []byte(nil)
|
||||
if dsty1 >= 0 {
|
||||
dst1 = dst[(dsty1+0)*dstw : (dsty1+1)*dstw]
|
||||
}
|
||||
src0 := src[(srcy0+0)*srcw : (srcy0+1)*srcw]
|
||||
src1 := src[(srcy1+0)*srcw : (srcy1+1)*srcw]
|
||||
upsampleStrip(dst0, dst1, src0, src1)
|
||||
}
|
||||
}
|
||||
|
||||
func upsampleStrip(dst0 []byte, dst1 []byte, src0 []byte, src1 []byte) {
|
||||
if (len(dst0) <= 0) ||
|
||||
((len(dst0) != len(dst1)) && (len(dst1) != 0)) ||
|
||||
((len(src0) != len(src1)) && (len(src1) != 0)) {
|
||||
return
|
||||
}
|
||||
|
||||
// t=top, l=left, c=current.
|
||||
tl := uint32(src0[0])
|
||||
cl := uint32(src1[0])
|
||||
|
||||
{
|
||||
dst0[0] = uint8(((3 * tl) + cl + 2) >> 2)
|
||||
}
|
||||
if len(dst1) > 0 {
|
||||
dst1[0] = uint8(((3 * cl) + tl + 2) >> 2)
|
||||
}
|
||||
|
||||
for x, lastPixelPair := 1, (len(dst0)-1)>>1; x <= lastPixelPair; x++ {
|
||||
tc := uint32(src0[x])
|
||||
cc := uint32(src1[x])
|
||||
|
||||
avg := tl + tc + cl + cc + 8
|
||||
diag12 := (avg + (2 * (tc + cl))) >> 3
|
||||
diag03 := (avg + (2 * (tl + cc))) >> 3
|
||||
|
||||
{
|
||||
dst0[(2*x)-1] = uint8((diag12 + tl) >> 1)
|
||||
dst0[(2*x)-0] = uint8((diag03 + tc) >> 1)
|
||||
}
|
||||
if len(dst1) > 0 {
|
||||
dst1[(2*x)-1] = uint8((diag03 + cl) >> 1)
|
||||
dst1[(2*x)-0] = uint8((diag12 + cc) >> 1)
|
||||
}
|
||||
|
||||
tl = tc
|
||||
cl = cc
|
||||
}
|
||||
|
||||
if (len(dst0) & 1) == 0 {
|
||||
n := len(dst0) - 1
|
||||
{
|
||||
dst0[n] = uint8(((3 * tl) + cl + 2) >> 2)
|
||||
}
|
||||
if len(dst1) > 0 {
|
||||
dst1[n] = uint8(((3 * cl) + tl + 2) >> 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func compare(have []byte, want []byte, width int, name string) {
|
||||
if len(have) != len(want) {
|
||||
panic("invalid compare")
|
||||
} else if bytes.Equal(have, want) {
|
||||
return
|
||||
}
|
||||
failed = true
|
||||
|
||||
fmt.Fprintf(os.Stderr, "Wrong output for %s\n", name)
|
||||
for i := range have {
|
||||
fmt.Fprintf(os.Stderr, " %02X", have[i]-want[i])
|
||||
if (i % width) == (width - 1) {
|
||||
fmt.Fprintln(os.Stderr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var failed = false
|
||||
|
||||
// srcSamplesMona are the Cb (Chroma blue) samples, 16x16 in four macroblocks,
|
||||
// from test/data/mona-lisa.21x32.q90.lossy.webp (whose dimensions are 21x32).
|
||||
var srcSamplesMona = [16 * 16]uint8{
|
||||
0x6E, 0x6E, 0x6E, 0x6E, 0x6E, 0x6D, 0x69, 0x6B, 0x70, 0x6D, 0x72, 0x6E, 0x73, 0x73, 0x73, 0x73,
|
||||
0x69, 0x69, 0x69, 0x69, 0x67, 0x6A, 0x70, 0x6D, 0x6C, 0x68, 0x6D, 0x6A, 0x6A, 0x6A, 0x6A, 0x6A,
|
||||
0x69, 0x69, 0x69, 0x69, 0x5F, 0x66, 0x7A, 0x70, 0x6B, 0x67, 0x6C, 0x69, 0x69, 0x69, 0x69, 0x69,
|
||||
0x6E, 0x6E, 0x6E, 0x6E, 0x58, 0x63, 0x81, 0x72, 0x6D, 0x6A, 0x6F, 0x6B, 0x70, 0x70, 0x70, 0x70,
|
||||
0x79, 0x73, 0x73, 0x79, 0x5C, 0x5B, 0x81, 0x77, 0x79, 0x72, 0x76, 0x76, 0x75, 0x75, 0x75, 0x75,
|
||||
0x7C, 0x77, 0x77, 0x7C, 0x66, 0x6A, 0x85, 0x75, 0x7D, 0x75, 0x7A, 0x79, 0x79, 0x79, 0x79, 0x79,
|
||||
0x79, 0x74, 0x74, 0x79, 0x69, 0x5E, 0x71, 0x7A, 0x6F, 0x6C, 0x75, 0x79, 0x77, 0x77, 0x77, 0x77,
|
||||
0x72, 0x6C, 0x6C, 0x72, 0x4F, 0x51, 0x65, 0x71, 0x76, 0x6C, 0x6E, 0x6C, 0x6C, 0x6C, 0x6C, 0x6C,
|
||||
|
||||
0x72, 0x6E, 0x7E, 0x6C, 0x57, 0x5C, 0x6F, 0x84, 0x87, 0x7A, 0x73, 0x77, 0x76, 0x76, 0x76, 0x76,
|
||||
0x74, 0x73, 0x84, 0x7E, 0x6E, 0x7C, 0x7F, 0x74, 0x87, 0x7D, 0x78, 0x7B, 0x7D, 0x7D, 0x7D, 0x7D,
|
||||
0x78, 0x77, 0x80, 0x85, 0x80, 0x81, 0x84, 0x89, 0x86, 0x83, 0x80, 0x7F, 0x7C, 0x7C, 0x7C, 0x7C,
|
||||
0x7D, 0x77, 0x75, 0x7E, 0x88, 0x85, 0x85, 0x87, 0x86, 0x86, 0x85, 0x83, 0x83, 0x83, 0x83, 0x83,
|
||||
0x89, 0x88, 0x75, 0x5A, 0x62, 0x7B, 0x85, 0x7A, 0x8A, 0x89, 0x87, 0x86, 0x86, 0x86, 0x86, 0x86,
|
||||
0x8A, 0x88, 0x79, 0x66, 0x63, 0x6B, 0x73, 0x76, 0x87, 0x85, 0x83, 0x82, 0x80, 0x80, 0x80, 0x80,
|
||||
0x8C, 0x88, 0x7F, 0x77, 0x81, 0x81, 0x86, 0x8C, 0x87, 0x85, 0x83, 0x82, 0x87, 0x87, 0x87, 0x87,
|
||||
0x8D, 0x88, 0x84, 0x83, 0x83, 0x88, 0x8A, 0x88, 0x8A, 0x89, 0x87, 0x86, 0x89, 0x89, 0x89, 0x89,
|
||||
}
|
||||
|
||||
var dstSamplesMona = [21 * 32]uint8{
|
||||
0x6E, 0x6E, 0x6E, 0x6E, 0x6E, 0x6E, 0x6E, 0x6E, 0x6E, 0x6E, 0x6D, 0x6C, 0x6A, 0x6A, 0x6B, 0x6C, 0x6F, 0x6F, 0x6E, 0x6E, 0x71,
|
||||
0x6D, 0x6D, 0x6D, 0x6D, 0x6D, 0x6D, 0x6D, 0x6D, 0x6C, 0x6C, 0x6C, 0x6C, 0x6B, 0x6B, 0x6B, 0x6C, 0x6E, 0x6E, 0x6D, 0x6D, 0x70,
|
||||
0x6A, 0x6A, 0x6A, 0x6A, 0x6A, 0x6A, 0x6A, 0x6A, 0x69, 0x69, 0x6A, 0x6C, 0x6D, 0x6E, 0x6D, 0x6D, 0x6D, 0x6C, 0x6A, 0x6B, 0x6D,
|
||||
0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x68, 0x66, 0x66, 0x68, 0x6B, 0x70, 0x71, 0x6F, 0x6D, 0x6C, 0x6B, 0x69, 0x69, 0x6C,
|
||||
0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x67, 0x63, 0x63, 0x66, 0x6B, 0x73, 0x75, 0x71, 0x6E, 0x6C, 0x6A, 0x68, 0x69, 0x6B,
|
||||
0x6A, 0x6A, 0x6A, 0x6A, 0x6A, 0x6A, 0x6A, 0x67, 0x61, 0x5F, 0x63, 0x6B, 0x76, 0x79, 0x73, 0x6F, 0x6D, 0x6B, 0x69, 0x69, 0x6C,
|
||||
0x6D, 0x6D, 0x6D, 0x6D, 0x6D, 0x6D, 0x6D, 0x68, 0x5F, 0x5C, 0x61, 0x6B, 0x78, 0x7C, 0x75, 0x70, 0x6E, 0x6C, 0x6A, 0x6B, 0x6D,
|
||||
0x71, 0x70, 0x70, 0x6F, 0x6F, 0x70, 0x70, 0x6B, 0x5F, 0x5B, 0x5F, 0x69, 0x79, 0x7E, 0x77, 0x72, 0x71, 0x6F, 0x6D, 0x6D, 0x70,
|
||||
|
||||
0x76, 0x75, 0x73, 0x72, 0x72, 0x73, 0x75, 0x6F, 0x62, 0x5C, 0x5D, 0x66, 0x78, 0x7E, 0x79, 0x76, 0x76, 0x75, 0x72, 0x71, 0x73,
|
||||
0x7A, 0x78, 0x75, 0x74, 0x74, 0x75, 0x78, 0x73, 0x65, 0x5F, 0x5F, 0x68, 0x79, 0x7F, 0x79, 0x77, 0x79, 0x78, 0x75, 0x74, 0x76,
|
||||
0x7B, 0x7A, 0x77, 0x76, 0x76, 0x77, 0x7A, 0x75, 0x69, 0x64, 0x66, 0x6E, 0x7D, 0x80, 0x79, 0x77, 0x7A, 0x7A, 0x76, 0x75, 0x78,
|
||||
0x7B, 0x7A, 0x78, 0x76, 0x76, 0x78, 0x7A, 0x76, 0x6C, 0x67, 0x67, 0x6D, 0x7A, 0x7E, 0x79, 0x77, 0x79, 0x78, 0x74, 0x74, 0x77,
|
||||
0x7A, 0x79, 0x76, 0x75, 0x75, 0x76, 0x79, 0x75, 0x6D, 0x66, 0x63, 0x66, 0x71, 0x77, 0x78, 0x77, 0x74, 0x71, 0x6F, 0x70, 0x74,
|
||||
0x77, 0x76, 0x73, 0x72, 0x72, 0x73, 0x76, 0x72, 0x68, 0x61, 0x5D, 0x60, 0x69, 0x70, 0x75, 0x76, 0x73, 0x70, 0x6D, 0x6E, 0x71,
|
||||
0x74, 0x72, 0x6F, 0x6E, 0x6E, 0x6F, 0x72, 0x6C, 0x5D, 0x55, 0x55, 0x59, 0x63, 0x6B, 0x70, 0x74, 0x74, 0x72, 0x6E, 0x6D, 0x6F,
|
||||
0x72, 0x71, 0x6E, 0x6E, 0x70, 0x71, 0x71, 0x69, 0x59, 0x52, 0x53, 0x59, 0x63, 0x6B, 0x72, 0x77, 0x79, 0x78, 0x72, 0x6F, 0x6F,
|
||||
|
||||
0x72, 0x71, 0x6F, 0x71, 0x77, 0x77, 0x71, 0x67, 0x5B, 0x56, 0x58, 0x5E, 0x68, 0x71, 0x7B, 0x80, 0x82, 0x80, 0x7A, 0x75, 0x73,
|
||||
0x73, 0x72, 0x70, 0x73, 0x7B, 0x7C, 0x74, 0x6C, 0x62, 0x5F, 0x62, 0x68, 0x6F, 0x76, 0x7D, 0x82, 0x85, 0x84, 0x7E, 0x79, 0x76,
|
||||
0x74, 0x73, 0x72, 0x76, 0x7E, 0x80, 0x7C, 0x75, 0x6D, 0x6B, 0x71, 0x76, 0x79, 0x7A, 0x79, 0x7C, 0x83, 0x84, 0x7F, 0x7B, 0x78,
|
||||
0x75, 0x75, 0x74, 0x78, 0x7F, 0x82, 0x81, 0x7C, 0x76, 0x75, 0x7B, 0x7E, 0x80, 0x7F, 0x7B, 0x7D, 0x83, 0x85, 0x81, 0x7D, 0x7B,
|
||||
0x77, 0x77, 0x76, 0x79, 0x7E, 0x82, 0x83, 0x81, 0x7D, 0x7D, 0x7F, 0x81, 0x82, 0x83, 0x84, 0x84, 0x86, 0x85, 0x83, 0x81, 0x7F,
|
||||
0x79, 0x79, 0x78, 0x79, 0x7C, 0x7F, 0x82, 0x83, 0x82, 0x82, 0x82, 0x83, 0x84, 0x85, 0x87, 0x88, 0x87, 0x85, 0x84, 0x83, 0x82,
|
||||
0x7C, 0x7B, 0x78, 0x77, 0x78, 0x7A, 0x7E, 0x81, 0x84, 0x86, 0x85, 0x84, 0x85, 0x85, 0x87, 0x87, 0x86, 0x86, 0x85, 0x85, 0x84,
|
||||
0x80, 0x7F, 0x7C, 0x7A, 0x77, 0x75, 0x75, 0x77, 0x7C, 0x80, 0x82, 0x83, 0x84, 0x85, 0x84, 0x85, 0x86, 0x87, 0x87, 0x86, 0x86,
|
||||
|
||||
0x86, 0x85, 0x84, 0x80, 0x79, 0x71, 0x68, 0x65, 0x69, 0x70, 0x79, 0x7F, 0x83, 0x83, 0x7F, 0x80, 0x86, 0x89, 0x88, 0x88, 0x87,
|
||||
0x89, 0x89, 0x88, 0x84, 0x7B, 0x70, 0x63, 0x5E, 0x61, 0x67, 0x72, 0x79, 0x7E, 0x7F, 0x7B, 0x7D, 0x85, 0x89, 0x88, 0x88, 0x87,
|
||||
0x8A, 0x89, 0x88, 0x84, 0x7C, 0x73, 0x68, 0x63, 0x63, 0x66, 0x6C, 0x71, 0x75, 0x77, 0x77, 0x7B, 0x84, 0x87, 0x86, 0x86, 0x85,
|
||||
0x8B, 0x8A, 0x89, 0x85, 0x7E, 0x76, 0x6E, 0x6A, 0x6A, 0x6C, 0x6F, 0x72, 0x76, 0x79, 0x7B, 0x7E, 0x84, 0x87, 0x86, 0x85, 0x84,
|
||||
0x8C, 0x8B, 0x89, 0x85, 0x80, 0x7B, 0x75, 0x74, 0x78, 0x7A, 0x7B, 0x7D, 0x80, 0x83, 0x85, 0x87, 0x87, 0x87, 0x86, 0x85, 0x84,
|
||||
0x8C, 0x8B, 0x89, 0x86, 0x82, 0x7F, 0x7C, 0x7C, 0x80, 0x82, 0x82, 0x84, 0x86, 0x88, 0x8A, 0x8A, 0x89, 0x87, 0x86, 0x86, 0x85,
|
||||
0x8D, 0x8C, 0x89, 0x87, 0x84, 0x82, 0x81, 0x81, 0x82, 0x83, 0x85, 0x87, 0x88, 0x89, 0x89, 0x89, 0x89, 0x89, 0x88, 0x88, 0x87,
|
||||
0x8D, 0x8C, 0x89, 0x87, 0x85, 0x84, 0x83, 0x83, 0x83, 0x84, 0x87, 0x89, 0x8A, 0x8A, 0x89, 0x89, 0x8A, 0x8A, 0x89, 0x89, 0x88,
|
||||
}
|
||||
|
||||
// srcSamplesPeac are the Cb (Chroma blue) samples, 16x16 in four macroblocks,
|
||||
// from test/data/peacock.24x19.lossy.webp (whose dimensions are 24x19).
|
||||
var srcSamplesPeac = [16 * 16]uint8{
|
||||
0x65, 0x65, 0x65, 0x63, 0x63, 0x6C, 0x72, 0x71, 0x66, 0x69, 0x73, 0x76, 0x6E, 0x6E, 0x6E, 0x6E,
|
||||
0x65, 0x65, 0x65, 0x65, 0x5F, 0x6B, 0x72, 0x6E, 0x69, 0x70, 0x6D, 0x73, 0x6E, 0x6E, 0x6E, 0x6E,
|
||||
0x67, 0x67, 0x67, 0x67, 0x6B, 0x96, 0x9C, 0x7B, 0x6D, 0x79, 0x63, 0x6F, 0x6E, 0x6E, 0x6E, 0x6E,
|
||||
0x68, 0x68, 0x68, 0x68, 0x80, 0x7E, 0x84, 0x8F, 0x72, 0x80, 0x5C, 0x6D, 0x6D, 0x6D, 0x6D, 0x6D,
|
||||
0x6A, 0x6A, 0x6A, 0x6A, 0x63, 0x6B, 0x7F, 0x95, 0x75, 0x74, 0x6F, 0x6A, 0x69, 0x69, 0x69, 0x69,
|
||||
0x6B, 0x6B, 0x6B, 0x6B, 0x6B, 0x6B, 0x99, 0x85, 0x74, 0x70, 0x6B, 0x67, 0x65, 0x65, 0x65, 0x65,
|
||||
0x6C, 0x6C, 0x6C, 0x6C, 0x6D, 0x81, 0xA8, 0x76, 0x6F, 0x6B, 0x66, 0x62, 0x60, 0x60, 0x60, 0x60,
|
||||
0x6C, 0x6C, 0x6C, 0x6C, 0x68, 0xA0, 0xA4, 0x72, 0x6B, 0x67, 0x62, 0x5F, 0x5C, 0x5C, 0x5C, 0x5C,
|
||||
|
||||
0x6B, 0x6B, 0x6B, 0x6B, 0x70, 0xA5, 0xA3, 0x89, 0x64, 0x68, 0x67, 0x60, 0x60, 0x60, 0x60, 0x60,
|
||||
0x6B, 0x6B, 0x6B, 0x6B, 0x7E, 0xAD, 0xAB, 0x97, 0x64, 0x68, 0x67, 0x60, 0x60, 0x60, 0x60, 0x60,
|
||||
0x6A, 0x6A, 0x6A, 0x6A, 0x87, 0xAD, 0xAB, 0xA0, 0x64, 0x68, 0x67, 0x60, 0x60, 0x60, 0x60, 0x60,
|
||||
0x69, 0x69, 0x69, 0x69, 0x85, 0xA5, 0xA3, 0x9E, 0x64, 0x68, 0x67, 0x60, 0x60, 0x60, 0x60, 0x60,
|
||||
0x69, 0x69, 0x69, 0x69, 0x7C, 0xAA, 0xAC, 0xA0, 0x64, 0x68, 0x67, 0x60, 0x60, 0x60, 0x60, 0x60,
|
||||
0x68, 0x68, 0x68, 0x68, 0x7C, 0xAA, 0xAC, 0xA0, 0x64, 0x68, 0x67, 0x60, 0x60, 0x60, 0x60, 0x60,
|
||||
0x68, 0x68, 0x68, 0x68, 0x7C, 0xAA, 0xAC, 0xA0, 0x64, 0x68, 0x67, 0x60, 0x60, 0x60, 0x60, 0x60,
|
||||
0x68, 0x68, 0x68, 0x68, 0x7C, 0xAA, 0xAC, 0xA0, 0x64, 0x68, 0x67, 0x60, 0x60, 0x60, 0x60, 0x60,
|
||||
}
|
||||
|
||||
var dstSamplesPeac = [24 * 19]uint8{
|
||||
0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x64, 0x63, 0x63, 0x65, 0x6A, 0x6E, 0x71, 0x72, 0x71, 0x6E, 0x69, 0x67, 0x68, 0x6C, 0x71, 0x74, 0x75, 0x76,
|
||||
0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x64, 0x63, 0x62, 0x64, 0x69, 0x6D, 0x70, 0x72, 0x71, 0x6E, 0x69, 0x68, 0x6A, 0x6C, 0x70, 0x72, 0x74, 0x75,
|
||||
0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x63, 0x61, 0x63, 0x68, 0x6D, 0x70, 0x71, 0x70, 0x6D, 0x6A, 0x6A, 0x6D, 0x6E, 0x6E, 0x70, 0x72, 0x74,
|
||||
0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x65, 0x63, 0x67, 0x71, 0x77, 0x7B, 0x7A, 0x74, 0x6F, 0x6C, 0x6C, 0x70, 0x70, 0x6C, 0x6C, 0x70, 0x72,
|
||||
0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x68, 0x71, 0x82, 0x8D, 0x90, 0x8B, 0x7E, 0x75, 0x6F, 0x6F, 0x74, 0x72, 0x6A, 0x68, 0x6D, 0x70,
|
||||
0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x6A, 0x6E, 0x78, 0x88, 0x92, 0x95, 0x91, 0x86, 0x7C, 0x73, 0x71, 0x78, 0x74, 0x68, 0x65, 0x6B, 0x6F,
|
||||
0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x6D, 0x76, 0x7D, 0x82, 0x86, 0x89, 0x8A, 0x8A, 0x84, 0x77, 0x74, 0x7B, 0x76, 0x66, 0x62, 0x6A, 0x6E,
|
||||
0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x6D, 0x75, 0x79, 0x79, 0x7C, 0x80, 0x86, 0x8D, 0x89, 0x7A, 0x75, 0x7A, 0x76, 0x68, 0x64, 0x69, 0x6C,
|
||||
|
||||
0x6A, 0x6A, 0x6A, 0x6A, 0x6A, 0x6A, 0x6A, 0x6A, 0x6A, 0x6C, 0x6E, 0x74, 0x7C, 0x85, 0x8F, 0x8C, 0x7C, 0x75, 0x76, 0x74, 0x6D, 0x6A, 0x6B, 0x6B,
|
||||
0x6A, 0x6A, 0x6A, 0x6A, 0x6A, 0x6A, 0x6A, 0x69, 0x66, 0x67, 0x6A, 0x72, 0x7F, 0x88, 0x8E, 0x8A, 0x7C, 0x74, 0x73, 0x72, 0x6F, 0x6D, 0x6A, 0x69,
|
||||
0x6B, 0x6B, 0x6B, 0x6B, 0x6B, 0x6B, 0x6B, 0x6A, 0x69, 0x6A, 0x6B, 0x75, 0x89, 0x90, 0x8B, 0x84, 0x79, 0x73, 0x72, 0x70, 0x6D, 0x6B, 0x69, 0x68,
|
||||
0x6B, 0x6B, 0x6B, 0x6B, 0x6B, 0x6B, 0x6B, 0x6B, 0x6B, 0x6D, 0x6F, 0x7C, 0x92, 0x96, 0x88, 0x7E, 0x76, 0x72, 0x70, 0x6E, 0x6B, 0x69, 0x67, 0x66,
|
||||
0x6C, 0x6C, 0x6C, 0x6C, 0x6C, 0x6C, 0x6C, 0x6C, 0x6C, 0x70, 0x78, 0x86, 0x9A, 0x9A, 0x84, 0x77, 0x73, 0x6F, 0x6D, 0x6B, 0x69, 0x66, 0x64, 0x63,
|
||||
0x6C, 0x6C, 0x6C, 0x6C, 0x6C, 0x6C, 0x6C, 0x6C, 0x6C, 0x73, 0x82, 0x90, 0x9F, 0x9B, 0x82, 0x73, 0x70, 0x6D, 0x6B, 0x69, 0x66, 0x64, 0x62, 0x61,
|
||||
0x6C, 0x6C, 0x6C, 0x6C, 0x6C, 0x6C, 0x6C, 0x6B, 0x6A, 0x75, 0x8D, 0x9B, 0xA2, 0x99, 0x80, 0x71, 0x6E, 0x6B, 0x69, 0x67, 0x64, 0x62, 0x61, 0x60,
|
||||
0x6C, 0x6C, 0x6C, 0x6C, 0x6C, 0x6C, 0x6C, 0x6B, 0x6A, 0x78, 0x93, 0xA2, 0xA3, 0x99, 0x83, 0x74, 0x6D, 0x69, 0x68, 0x66, 0x64, 0x62, 0x60, 0x5F,
|
||||
|
||||
0x6B, 0x6B, 0x6B, 0x6B, 0x6B, 0x6B, 0x6B, 0x6C, 0x6D, 0x7B, 0x96, 0xA4, 0xA3, 0x9B, 0x8B, 0x7C, 0x6D, 0x66, 0x67, 0x67, 0x66, 0x64, 0x61, 0x60,
|
||||
0x6B, 0x6B, 0x6B, 0x6B, 0x6B, 0x6B, 0x6B, 0x6D, 0x71, 0x80, 0x9A, 0xA7, 0xA6, 0x9F, 0x93, 0x82, 0x6E, 0x65, 0x67, 0x68, 0x67, 0x65, 0x62, 0x60,
|
||||
0x6B, 0x6B, 0x6B, 0x6B, 0x6B, 0x6B, 0x6B, 0x6F, 0x77, 0x87, 0x9F, 0xAB, 0xAA, 0xA4, 0x99, 0x88, 0x70, 0x65, 0x67, 0x68, 0x67, 0x65, 0x62, 0x60,
|
||||
}
|
||||
@@ -0,0 +1,486 @@
|
||||
// Copyright 2026 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// ----------------
|
||||
|
||||
// This is a small, self-contained, single-file C library to decode basic
|
||||
// Handsum image files. Basic means that it only supports Handsum's default
|
||||
// configuration, c3q4: color=3 (RGB, no Alpha) and quality=4 (best).
|
||||
//
|
||||
// It is a C port of some (decoding only and c3q4 only) of this Go library:
|
||||
// https://pkg.go.dev/github.com/google/wuffs/lib/handsum
|
||||
//
|
||||
// To decode other configurations, like c1q1 (Gray, worst quality) or c4q2
|
||||
// (RGBA, medium-low quality), use the github.com/google/wuffs Go or
|
||||
// C-transpiled-from-memory-safe-Wuffs implementations.
|
||||
//
|
||||
// To use this file as a "foo.c"-like implementation, instead of a "foo.h"-like
|
||||
// header, #define BASIC_HANDSUM_DECODE_IMPLEMENTATION before #include'ing or
|
||||
// compiling it.
|
||||
//
|
||||
// As an option, you may also #define
|
||||
// BASIC_HANDSUM_DECODE_CONFIG__STATIC_FUNCTIONS to make these functions have
|
||||
// static storage. This can help the compiler ignore or discard unused code,
|
||||
// which can produce faster compiles and smaller binaries.
|
||||
|
||||
#ifndef BASIC_HANDSUM_DECODE_INCLUDE_GUARD
|
||||
#define BASIC_HANDSUM_DECODE_INCLUDE_GUARD
|
||||
|
||||
#if defined(BASIC_HANDSUM_DECODE_CONFIG__STATIC_FUNCTIONS)
|
||||
#define BASIC_HANDSUM_DECODE__MAYBE_STATIC static
|
||||
#else
|
||||
#define BASIC_HANDSUM_DECODE__MAYBE_STATIC
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct basic_handsum_decode__pixel_buffer_type {
|
||||
uint32_t width; // Measured in pixels, not bytes.
|
||||
uint32_t height; // Measured in pixels, not bytes.
|
||||
uint8_t bgra_pixels[1024];
|
||||
} basic_handsum_decode__pixel_buffer;
|
||||
|
||||
// BASIC_HANDSUM_DECODE__RESULT__ETC can be returned by
|
||||
// basic_handsum_decode__decode. Zero means OK. Non-zero means an error.
|
||||
#define BASIC_HANDSUM_DECODE__RESULT__OK 0
|
||||
#define BASIC_HANDSUM_DECODE__RESULT__DST_IS_NULL 1
|
||||
#define BASIC_HANDSUM_DECODE__RESULT__SRC_IS_TOO_SHORT 2
|
||||
#define BASIC_HANDSUM_DECODE__RESULT__SRC_IS_NOT_HANDSUM_C3Q4 3
|
||||
|
||||
// Decodes the source bytes into the destination pixel buffer, producing 4
|
||||
// bytes per pixel (in B, G, R, A order). The bgra_pixels' row stride will be
|
||||
// (4 * width) bytes.
|
||||
//
|
||||
// It only supports c3q4 Handsum files: color=3 (so alpha is always 0xFF) and
|
||||
// quality=4 (best). Every valid c3q4 Handsum file is exactly 147 bytes long.
|
||||
//
|
||||
// On success, it returns zero and dst's width and height will range between 1
|
||||
// and 16, inclusive.
|
||||
//
|
||||
// On failure, it returns non-zero and, if dst is non-NULL, its width and
|
||||
// height will be set to zero.
|
||||
//
|
||||
// This function is thread-safe.
|
||||
BASIC_HANDSUM_DECODE__MAYBE_STATIC int //
|
||||
basic_handsum_decode__decode(basic_handsum_decode__pixel_buffer* dst,
|
||||
const uint8_t* src_ptr,
|
||||
const size_t src_len);
|
||||
|
||||
// --------
|
||||
|
||||
#ifdef BASIC_HANDSUM_DECODE_IMPLEMENTATION
|
||||
|
||||
#ifdef __wasm__
|
||||
static void //
|
||||
basic_handsum_decode__memcpy(uint8_t* restrict dst,
|
||||
const uint8_t* restrict src,
|
||||
size_t n) {
|
||||
while (n--) {
|
||||
*dst++ = *src++;
|
||||
}
|
||||
}
|
||||
#else
|
||||
#include <string.h>
|
||||
#define basic_handsum_decode__memcpy memcpy
|
||||
#endif
|
||||
|
||||
static void //
|
||||
basic_handsum_decode__smooth_block_seams_16x16(uint8_t* b) {
|
||||
static const uint8_t smoothing_pairs_16x16[28][2] = {
|
||||
{0x07, 0x08}, {0x17, 0x18}, {0x27, 0x28}, {0x37, 0x38},
|
||||
{0x47, 0x48}, {0x57, 0x58}, {0x67, 0x68},
|
||||
|
||||
{0x70, 0x80}, {0x71, 0x81}, {0x72, 0x82}, {0x73, 0x83},
|
||||
{0x74, 0x84}, {0x75, 0x85}, {0x76, 0x86},
|
||||
|
||||
{0x79, 0x89}, {0x7A, 0x8A}, {0x7B, 0x8B}, {0x7C, 0x8C},
|
||||
{0x7D, 0x8D}, {0x7E, 0x8E}, {0x7F, 0x8F},
|
||||
|
||||
{0x97, 0x98}, {0xA7, 0xA8}, {0xB7, 0xB8}, {0xC7, 0xC8},
|
||||
{0xD7, 0xD8}, {0xE7, 0xE8}, {0xF7, 0xF8},
|
||||
};
|
||||
|
||||
for (int i = 0; i < 28; i++) {
|
||||
uint8_t p0 = smoothing_pairs_16x16[i][0];
|
||||
uint8_t p1 = smoothing_pairs_16x16[i][1];
|
||||
uint32_t v0 = b[p0];
|
||||
uint32_t v1 = b[p1];
|
||||
b[p0] = ((3 * v0) + v1 + 2) / 4;
|
||||
b[p1] = ((3 * v1) + v0 + 2) / 4;
|
||||
}
|
||||
|
||||
uint32_t v77 = b[0x77];
|
||||
uint32_t v78 = b[0x78];
|
||||
uint32_t v88 = b[0x88];
|
||||
uint32_t v87 = b[0x87];
|
||||
|
||||
b[0x77] = ((9 * v77) + (3 * v78) + v88 + (3 * v87) + 8) / 16;
|
||||
b[0x78] = ((9 * v78) + (3 * v88) + v87 + (3 * v77) + 8) / 16;
|
||||
b[0x88] = ((9 * v88) + (3 * v87) + v77 + (3 * v78) + 8) / 16;
|
||||
b[0x87] = ((9 * v87) + (3 * v77) + v78 + (3 * v88) + 8) / 16;
|
||||
}
|
||||
|
||||
static void //
|
||||
basic_handsum_decode__smooth_block_seams_8x8_q4(uint8_t* b) {
|
||||
for (int y = 1; y < 7; y += 2) {
|
||||
for (int x = 1; x < 7; x += 2) {
|
||||
int o = (y * 8) + x;
|
||||
|
||||
uint32_t v0 = b[o + 0];
|
||||
uint32_t v1 = b[o + 1];
|
||||
uint32_t v9 = b[o + 9];
|
||||
uint32_t v8 = b[o + 8];
|
||||
|
||||
b[o + 0] = ((9 * v0) + (3 * v1) + v9 + (3 * v8) + 8) / 16;
|
||||
b[o + 1] = ((9 * v1) + (3 * v9) + v8 + (3 * v0) + 8) / 16;
|
||||
b[o + 9] = ((9 * v9) + (3 * v8) + v0 + (3 * v1) + 8) / 16;
|
||||
b[o + 8] = ((9 * v8) + (3 * v0) + v1 + (3 * v9) + 8) / 16;
|
||||
}
|
||||
|
||||
{
|
||||
uint32_t v0 = b[000 + y];
|
||||
uint32_t v1 = b[001 + y];
|
||||
b[000 + y] = ((3 * v0) + v1 + 2) / 4;
|
||||
b[001 + y] = ((3 * v1) + v0 + 2) / 4;
|
||||
}
|
||||
|
||||
{
|
||||
uint32_t v0 = b[070 + y];
|
||||
uint32_t v1 = b[071 + y];
|
||||
b[070 + y] = ((3 * v0) + v1 + 2) / 4;
|
||||
b[071 + y] = ((3 * v1) + v0 + 2) / 4;
|
||||
}
|
||||
|
||||
int y8 = y * 8;
|
||||
|
||||
{
|
||||
uint32_t v0 = b[000 + y8];
|
||||
uint32_t v1 = b[010 + y8];
|
||||
b[000 + y8] = ((3 * v0) + v1 + 2) / 4;
|
||||
b[010 + y8] = ((3 * v1) + v0 + 2) / 4;
|
||||
}
|
||||
|
||||
{
|
||||
uint32_t v0 = b[007 + y8];
|
||||
uint32_t v1 = b[017 + y8];
|
||||
b[007 + y8] = ((3 * v0) + v1 + 2) / 4;
|
||||
b[017 + y8] = ((3 * v1) + v0 + 2) / 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return (x + 0x80), if in range, otherwise clamped to 0x00 or 0xFF.
|
||||
static uint8_t //
|
||||
basic_handsum_decode__bias_and_clamp(int x) {
|
||||
x += 0x80;
|
||||
return ((x >> 8) == 0) ? x : ~(x >> 31);
|
||||
}
|
||||
|
||||
static int //
|
||||
basic_handsum_decode__decode_block_q4(uint8_t* dst_ptr,
|
||||
size_t dst_stride,
|
||||
const uint8_t* src_ptr,
|
||||
size_t bit_offset) {
|
||||
uint8_t tmp[64];
|
||||
for (int i = 0; i < 16; i++) {
|
||||
int nibble0 = (src_ptr[bit_offset >> 3] >> (bit_offset & 4)) & 15;
|
||||
int dct0 = (nibble0 * 0x22) - 256;
|
||||
bit_offset += 4;
|
||||
|
||||
int nibble1 = (src_ptr[bit_offset >> 3] >> (bit_offset & 4)) & 15;
|
||||
int dct1 = (nibble1 * 0x10) - 128;
|
||||
bit_offset += 4;
|
||||
|
||||
int nibble2 = (src_ptr[bit_offset >> 3] >> (bit_offset & 4)) & 15;
|
||||
int dct2 = (nibble2 * 0x10) - 128;
|
||||
bit_offset += 4;
|
||||
|
||||
int x2 = 2 * (i & 3);
|
||||
int y2 = 2 * (i >> 2);
|
||||
int o2 = (y2 * 8) + x2;
|
||||
|
||||
tmp[o2 + 0] =
|
||||
basic_handsum_decode__bias_and_clamp((+dct0 + dct1 + dct2 + 1) >> 1);
|
||||
tmp[o2 + 1] =
|
||||
basic_handsum_decode__bias_and_clamp((+dct0 - dct1 + dct2 + 1) >> 1);
|
||||
tmp[o2 + 8] =
|
||||
basic_handsum_decode__bias_and_clamp((+dct0 + dct1 - dct2 + 1) >> 1);
|
||||
tmp[o2 + 9] =
|
||||
basic_handsum_decode__bias_and_clamp((+dct0 - dct1 - dct2 + 1) >> 1);
|
||||
}
|
||||
|
||||
basic_handsum_decode__smooth_block_seams_8x8_q4(&tmp[0]);
|
||||
|
||||
for (size_t i = 0; i < 8; i++) {
|
||||
size_t di = i * dst_stride;
|
||||
size_t ti = i * 8;
|
||||
basic_handsum_decode__memcpy(&dst_ptr[di], &tmp[ti], 8);
|
||||
}
|
||||
|
||||
return bit_offset;
|
||||
}
|
||||
|
||||
static void //
|
||||
basic_handsum_decode__scale_and_bias_chroma_down(uint8_t* b) {
|
||||
for (int i = 0; i < 64; i++) {
|
||||
b[i] = (b[i] >> 1) + 0x3C;
|
||||
}
|
||||
}
|
||||
|
||||
static void //
|
||||
basic_handsum_decode__upsample_from(uint8_t* restrict dst,
|
||||
const uint8_t* restrict src) {
|
||||
// dst is 16x16, src is 8x8.
|
||||
for (int y = 0; y < 16; y++) {
|
||||
// sy is: 0, +8, -8, +8, -8, ..., +8, -8, 0.
|
||||
int sy = ((y == 0) || (y == 15)) ? 0 : ((y & 1) * 16) - 8;
|
||||
|
||||
for (int x = 0; x < 16; x++) {
|
||||
// sx is: 0, +1, -1, +1, -1, ..., +1, -1, 0.
|
||||
int sx = ((x == 0) || (x == 15)) ? 0 : ((x & 1) * 2) - 1;
|
||||
|
||||
int s0 = ((y >> 1) * 8) + (x >> 1);
|
||||
int v00 = src[s0];
|
||||
int v01 = src[s0 + sx];
|
||||
int v10 = src[s0 + sy];
|
||||
int v11 = src[s0 + sx + sy];
|
||||
|
||||
int d0 = (y * 16) + x;
|
||||
dst[d0] = ((9 * v00) + (3 * v01) + (3 * v10) + v11 + 8) / 16;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void //
|
||||
basic_handsum_decode__scale_horizontal(
|
||||
basic_handsum_decode__pixel_buffer* pixbuf) {
|
||||
uint8_t dst[1024];
|
||||
uint32_t w = pixbuf->width;
|
||||
const uint8_t* src = pixbuf->bgra_pixels;
|
||||
|
||||
for (int y = 0; y < 16; y++) {
|
||||
int dstx = 0;
|
||||
uint32_t acc0 = 0;
|
||||
uint32_t acc1 = 0;
|
||||
uint32_t acc2 = 0;
|
||||
uint32_t acc3 = 0;
|
||||
uint32_t remainder = 16;
|
||||
for (int srcx = 0; srcx < 16; srcx++) {
|
||||
int si = (64 * y) + (4 * srcx);
|
||||
uint32_t s0 = src[si + 0];
|
||||
uint32_t s1 = src[si + 1];
|
||||
uint32_t s2 = src[si + 2];
|
||||
uint32_t s3 = src[si + 3];
|
||||
|
||||
if (remainder > w) {
|
||||
remainder -= w;
|
||||
acc0 += w * s0;
|
||||
acc1 += w * s1;
|
||||
acc2 += w * s2;
|
||||
acc3 += w * s3;
|
||||
|
||||
} else {
|
||||
acc0 += remainder * s0;
|
||||
acc1 += remainder * s1;
|
||||
acc2 += remainder * s2;
|
||||
acc3 += remainder * s3;
|
||||
|
||||
int di = (4 * w * y) + (4 * dstx);
|
||||
dst[di + 0] = (acc0 + 8) / 16;
|
||||
dst[di + 1] = (acc1 + 8) / 16;
|
||||
dst[di + 2] = (acc2 + 8) / 16;
|
||||
dst[di + 3] = (acc3 + 8) / 16;
|
||||
dstx++;
|
||||
|
||||
uint32_t partial = w - remainder;
|
||||
|
||||
acc0 = partial * s0;
|
||||
acc1 = partial * s1;
|
||||
acc2 = partial * s2;
|
||||
acc3 = partial * s3;
|
||||
|
||||
remainder = 16 - partial;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int y = 0; y < 16; y++) {
|
||||
basic_handsum_decode__memcpy(&pixbuf->bgra_pixels[4 * w * y],
|
||||
&dst[4 * w * y], 4 * w);
|
||||
}
|
||||
}
|
||||
|
||||
static void //
|
||||
basic_handsum_decode__scale_vertical(
|
||||
basic_handsum_decode__pixel_buffer* pixbuf) {
|
||||
uint8_t dst[1024];
|
||||
uint32_t h = pixbuf->height;
|
||||
const uint8_t* src = pixbuf->bgra_pixels;
|
||||
|
||||
for (int x = 0; x < 16; x++) {
|
||||
int dsty = 0;
|
||||
uint32_t acc0 = 0;
|
||||
uint32_t acc1 = 0;
|
||||
uint32_t acc2 = 0;
|
||||
uint32_t acc3 = 0;
|
||||
uint32_t remainder = 16;
|
||||
for (int srcy = 0; srcy < 16; srcy++) {
|
||||
int si = (64 * srcy) + (4 * x);
|
||||
uint32_t s0 = src[si + 0];
|
||||
uint32_t s1 = src[si + 1];
|
||||
uint32_t s2 = src[si + 2];
|
||||
uint32_t s3 = src[si + 3];
|
||||
|
||||
if (remainder > h) {
|
||||
remainder -= h;
|
||||
acc0 += h * s0;
|
||||
acc1 += h * s1;
|
||||
acc2 += h * s2;
|
||||
acc3 += h * s3;
|
||||
|
||||
} else {
|
||||
acc0 += remainder * s0;
|
||||
acc1 += remainder * s1;
|
||||
acc2 += remainder * s2;
|
||||
acc3 += remainder * s3;
|
||||
|
||||
int di = (64 * dsty) + (4 * x);
|
||||
dst[di + 0] = (acc0 + 8) / 16;
|
||||
dst[di + 1] = (acc1 + 8) / 16;
|
||||
dst[di + 2] = (acc2 + 8) / 16;
|
||||
dst[di + 3] = (acc3 + 8) / 16;
|
||||
dsty++;
|
||||
|
||||
uint32_t partial = h - remainder;
|
||||
|
||||
acc0 = partial * s0;
|
||||
acc1 = partial * s1;
|
||||
acc2 = partial * s2;
|
||||
acc3 = partial * s3;
|
||||
|
||||
remainder = 16 - partial;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
basic_handsum_decode__memcpy(&pixbuf->bgra_pixels[0], &dst[0], 64 * h);
|
||||
}
|
||||
|
||||
static void //
|
||||
basic_handsum_decode__convert_ycbcr_bgra(
|
||||
basic_handsum_decode__pixel_buffer* dst,
|
||||
const uint8_t* restrict yy,
|
||||
const uint8_t* restrict cb,
|
||||
const uint8_t* restrict cr) {
|
||||
for (int i = 0; i < 256; i++) {
|
||||
int32_t yy1 = (int32_t)(yy[i]) * 0x10101;
|
||||
int32_t cb1 = (int32_t)(cb[i]) - 128;
|
||||
int32_t cr1 = (int32_t)(cr[i]) - 128;
|
||||
|
||||
int32_t r = yy1 + (91881 * cr1);
|
||||
if (((uint32_t)(r)&0xFF000000u) == 0) {
|
||||
r >>= 16;
|
||||
} else {
|
||||
r = -1 ^ (r >> 31);
|
||||
}
|
||||
|
||||
int32_t g = yy1 - (22554 * cb1) - (46802 * cr1);
|
||||
if (((uint32_t)(g)&0xFF000000u) == 0) {
|
||||
g >>= 16;
|
||||
} else {
|
||||
g = -1 ^ (g >> 31);
|
||||
}
|
||||
|
||||
int32_t b = yy1 + (116130 * cb1);
|
||||
if (((uint32_t)(b)&0xFF000000u) == 0) {
|
||||
b >>= 16;
|
||||
} else {
|
||||
b = -1 ^ (b >> 31);
|
||||
}
|
||||
|
||||
dst->bgra_pixels[(4 * i) + 0] = b;
|
||||
dst->bgra_pixels[(4 * i) + 1] = g;
|
||||
dst->bgra_pixels[(4 * i) + 2] = r;
|
||||
dst->bgra_pixels[(4 * i) + 3] = 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
BASIC_HANDSUM_DECODE__MAYBE_STATIC int //
|
||||
basic_handsum_decode__decode(basic_handsum_decode__pixel_buffer* dst,
|
||||
const uint8_t* src_ptr,
|
||||
const size_t src_len) {
|
||||
if (dst == NULL) {
|
||||
return BASIC_HANDSUM_DECODE__RESULT__DST_IS_NULL;
|
||||
}
|
||||
dst->width = 0;
|
||||
dst->height = 0;
|
||||
|
||||
if (src_len < 147) {
|
||||
return BASIC_HANDSUM_DECODE__RESULT__SRC_IS_TOO_SHORT;
|
||||
} else if ((src_ptr[0] != 0xFE) || //
|
||||
(src_ptr[1] != 0xD7) || //
|
||||
((src_ptr[2] & 0xE0) != 0x60) || //
|
||||
((src_ptr[2] & 0x1F) == 0x1F)) {
|
||||
return BASIC_HANDSUM_DECODE__RESULT__SRC_IS_NOT_HANDSUM_C3Q4;
|
||||
}
|
||||
|
||||
if ((src_ptr[2] & 0x10) == 0x00) { // Landscape.
|
||||
dst->width = 16;
|
||||
dst->height = 1 + (src_ptr[2] & 0x0F);
|
||||
} else { // Portrait.
|
||||
dst->width = 1 + (src_ptr[2] & 0x0F);
|
||||
dst->height = 16;
|
||||
}
|
||||
|
||||
uint8_t luma_quad_block[256];
|
||||
uint8_t tmp[64];
|
||||
uint8_t cb_quad_block[256];
|
||||
uint8_t cr_quad_block[256];
|
||||
size_t bit_offset = 24;
|
||||
|
||||
bit_offset = basic_handsum_decode__decode_block_q4( //
|
||||
&luma_quad_block[0x00], 16, src_ptr, bit_offset);
|
||||
bit_offset = basic_handsum_decode__decode_block_q4( //
|
||||
&luma_quad_block[0x08], 16, src_ptr, bit_offset);
|
||||
bit_offset = basic_handsum_decode__decode_block_q4( //
|
||||
&luma_quad_block[0x80], 16, src_ptr, bit_offset);
|
||||
bit_offset = basic_handsum_decode__decode_block_q4( //
|
||||
&luma_quad_block[0x88], 16, src_ptr, bit_offset);
|
||||
|
||||
basic_handsum_decode__smooth_block_seams_16x16(&luma_quad_block[0]);
|
||||
|
||||
bit_offset = basic_handsum_decode__decode_block_q4( //
|
||||
&tmp[0], 8, src_ptr, bit_offset);
|
||||
|
||||
basic_handsum_decode__scale_and_bias_chroma_down(&tmp[0]);
|
||||
basic_handsum_decode__upsample_from(&cb_quad_block[0], &tmp[0]);
|
||||
|
||||
bit_offset = basic_handsum_decode__decode_block_q4( //
|
||||
&tmp[0], 8, src_ptr, bit_offset);
|
||||
|
||||
basic_handsum_decode__scale_and_bias_chroma_down(&tmp[0]);
|
||||
basic_handsum_decode__upsample_from(&cr_quad_block[0], &tmp[0]);
|
||||
|
||||
basic_handsum_decode__convert_ycbcr_bgra(
|
||||
dst, &luma_quad_block[0], &cb_quad_block[0], &cr_quad_block[0]);
|
||||
|
||||
if (dst->width < 16) {
|
||||
basic_handsum_decode__scale_horizontal(dst);
|
||||
} else if (dst->height < 16) {
|
||||
basic_handsum_decode__scale_vertical(dst);
|
||||
}
|
||||
|
||||
return BASIC_HANDSUM_DECODE__RESULT__OK;
|
||||
}
|
||||
|
||||
#endif // BASIC_HANDSUM_DECODE_IMPLEMENTATION
|
||||
#endif // BASIC_HANDSUM_DECODE_INCLUDE_GUARD
|
||||
@@ -771,8 +771,8 @@ pri func decoder.smooth_seams_8x8!(which: base.u32[..= 1], y_offset: base.u32[..
|
||||
this.buffers[args.which][args.y_offset + 4][args.x_offset + 12] = w43 as base.u8
|
||||
}
|
||||
|
||||
// scale_and_bias_chroma_down applies a look-up table transform to the 8×8
|
||||
// Chroma samples in this.buffers[1].
|
||||
// scale_and_bias_chroma_down transforms the 8×8 Chroma samples in
|
||||
// this.buffers[1].
|
||||
pri func decoder.scale_and_bias_chroma_down!() {
|
||||
var y : base.u32
|
||||
var x : base.u32
|
||||
@@ -783,10 +783,8 @@ pri func decoder.scale_and_bias_chroma_down!() {
|
||||
while x < 8,
|
||||
inv y < 8,
|
||||
{
|
||||
this.buffers[1][y][(4 * x) + 1] = SCALE_AND_BIAS_CHROMA_DOWN[
|
||||
this.buffers[1][y][(4 * x) + 1]]
|
||||
this.buffers[1][y][(4 * x) + 2] = SCALE_AND_BIAS_CHROMA_DOWN[
|
||||
this.buffers[1][y][(4 * x) + 2]]
|
||||
this.buffers[1][y][(4 * x) + 1] = 0x3C + (this.buffers[1][y][(4 * x) + 1] >> 1)
|
||||
this.buffers[1][y][(4 * x) + 2] = 0x3C + (this.buffers[1][y][(4 * x) + 2] >> 1)
|
||||
|
||||
x += 1
|
||||
}
|
||||
@@ -1199,26 +1197,6 @@ pri const ZIGZAG : roarray[2] roarray[15] base.u8[..= 24] = [[
|
||||
0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 0, 0, 0, 0, 0,
|
||||
]]
|
||||
|
||||
pri const SCALE_AND_BIAS_CHROMA_DOWN : roarray[256] base.u8 = [
|
||||
0x3C, 0x3C, 0x3D, 0x3D, 0x3E, 0x3E, 0x3F, 0x3F, 0x40, 0x40, 0x41, 0x41, 0x42, 0x42, 0x43, 0x43,
|
||||
0x44, 0x44, 0x45, 0x45, 0x46, 0x46, 0x47, 0x47, 0x48, 0x48, 0x49, 0x49, 0x4A, 0x4A, 0x4B, 0x4B,
|
||||
0x4C, 0x4C, 0x4D, 0x4D, 0x4E, 0x4E, 0x4F, 0x4F, 0x50, 0x50, 0x51, 0x51, 0x52, 0x52, 0x53, 0x53,
|
||||
0x54, 0x54, 0x55, 0x55, 0x56, 0x56, 0x57, 0x57, 0x58, 0x58, 0x59, 0x59, 0x5A, 0x5A, 0x5B, 0x5B,
|
||||
0x5C, 0x5C, 0x5D, 0x5D, 0x5E, 0x5E, 0x5F, 0x5F, 0x60, 0x60, 0x61, 0x61, 0x62, 0x62, 0x63, 0x63,
|
||||
0x64, 0x64, 0x65, 0x65, 0x66, 0x66, 0x67, 0x67, 0x68, 0x68, 0x69, 0x69, 0x6A, 0x6A, 0x6B, 0x6B,
|
||||
0x6C, 0x6C, 0x6D, 0x6D, 0x6E, 0x6E, 0x6F, 0x6F, 0x70, 0x70, 0x71, 0x71, 0x72, 0x72, 0x73, 0x73,
|
||||
0x74, 0x74, 0x75, 0x75, 0x76, 0x76, 0x77, 0x77, 0x78, 0x78, 0x79, 0x79, 0x7A, 0x7A, 0x7B, 0x7B,
|
||||
|
||||
0x7C, 0x7C, 0x7D, 0x7D, 0x7E, 0x7E, 0x7F, 0x7F, 0x80, 0x80, 0x81, 0x81, 0x82, 0x82, 0x83, 0x83,
|
||||
0x84, 0x84, 0x85, 0x85, 0x86, 0x86, 0x87, 0x87, 0x88, 0x88, 0x89, 0x89, 0x8A, 0x8A, 0x8B, 0x8B,
|
||||
0x8C, 0x8C, 0x8D, 0x8D, 0x8E, 0x8E, 0x8F, 0x8F, 0x90, 0x90, 0x91, 0x91, 0x92, 0x92, 0x93, 0x93,
|
||||
0x94, 0x94, 0x95, 0x95, 0x96, 0x96, 0x97, 0x97, 0x98, 0x98, 0x99, 0x99, 0x9A, 0x9A, 0x9B, 0x9B,
|
||||
0x9C, 0x9C, 0x9D, 0x9D, 0x9E, 0x9E, 0x9F, 0x9F, 0xA0, 0xA0, 0xA1, 0xA1, 0xA2, 0xA2, 0xA3, 0xA3,
|
||||
0xA4, 0xA4, 0xA5, 0xA5, 0xA6, 0xA6, 0xA7, 0xA7, 0xA8, 0xA8, 0xA9, 0xA9, 0xAA, 0xAA, 0xAB, 0xAB,
|
||||
0xAC, 0xAC, 0xAD, 0xAD, 0xAE, 0xAE, 0xAF, 0xAF, 0xB0, 0xB0, 0xB1, 0xB1, 0xB2, 0xB2, 0xB3, 0xB3,
|
||||
0xB4, 0xB4, 0xB5, 0xB5, 0xB6, 0xB6, 0xB7, 0xB7, 0xB8, 0xB8, 0xB9, 0xB9, 0xBA, 0xBA, 0xBB, 0xBB,
|
||||
]
|
||||
|
||||
pri const CUBE_ROOT : roarray[256] base.u8 = [
|
||||
0x00, 0x00, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x05, 0x05,
|
||||
0x06, 0x06, 0x06, 0x07, 0x07, 0x07, 0x08, 0x08, 0x09, 0x09, 0x09, 0x0A, 0x0A, 0x0B, 0x0B, 0x0B,
|
||||
|
||||
@@ -7,3 +7,35 @@ compression format for opaque, still images.
|
||||
The ["Making Software - Image
|
||||
Compression"](https://www.makingsoftware.com/chapters/image-compression) book
|
||||
chapter also has a good overview of a number of image formats, including JPEG.
|
||||
|
||||
|
||||
# Further Reading
|
||||
|
||||
Web pages:
|
||||
|
||||
- [DCT and DFT for 1D and 2D Signals](https://ekrem-7-fidan.medium.com/dct-and-dft-for-1d-and-2d-signals-discrete-cosine-transform-and-discrete-fourier-transform-59feb837441d) by Ekrem Fidan.
|
||||
- [How JPEG works](https://cgjennings.ca/articles/jpeg-compression/) by Christopher G. Jennings.
|
||||
- [How JPG Works](https://www.freecodecamp.org/news/how-jpg-works-a4dbd2316f35/) by Colt McAnlis.
|
||||
- [JPEG compression](https://www.sophielwang.com/blog/jpeg) by Sophie Wang.
|
||||
- [JPEG Series, Part I: Visualizing the Inverse Discrete Cosine Transform](https://alexdowad.github.io/visualizing-the-idct/) by Alex Dowad.
|
||||
- [JPEG Series, Part II: Huffman Coding](https://alexdowad.github.io/huffman-coding/) by Alex Dowad.
|
||||
- [Not so fast, Mr. Fourier!](https://lcamtuf.substack.com/p/not-so-fast-mr-fourier) by Michał Zalewski.
|
||||
- [Understanding and Decoding a JPEG Image using Python](https://yasoob.me/posts/understanding-and-writing-jpeg-decoder-in-python/) by Yasoob Khalid.
|
||||
- [Unraveling the JPEG](https://parametric.press/issue-01/unraveling-the-jpeg/) by Omar Shehata.
|
||||
- [Wikipedia's JPEG Encoding page](https://en.wikipedia.org/wiki/JPEG#Encoding).
|
||||
|
||||
YouTube videos:
|
||||
|
||||
- [JPEG DCT, Discrete Cosine Transform (JPEG Pt2)- Computerphile](https://www.youtube.com/watch?v=Q2aEzeMDHMA).
|
||||
- [The Unreasonable Effectiveness of JPEG: A Signal Processing Approach](https://www.youtube.com/watch?v=0me3guauqOU).
|
||||
|
||||
Books:
|
||||
|
||||
You may be able to find these books at your local university's science library.
|
||||
|
||||
- [Compressed Image File Formats: JPEG, PNG, GIF, XBM, BMP](https://amazon.com/dp/0201604434), also known as the white book.
|
||||
- [JPEG: Still Image Data Compression Standard](https://amazon.com/dp/0442012721), also known as the pink book.
|
||||
|
||||
Link collections:
|
||||
|
||||
- [https://pinboard.in/u:thakis/t:jpeg/](https://pinboard.in/u:thakis/t:jpeg/)
|
||||
@@ -2072,7 +2072,9 @@ pri func decoder.swizzle_colorful!(dst: ptr base.pixel_buffer, workbuf: slice ba
|
||||
var height1 : base.u32[..= 0x1_0008]
|
||||
var height2 : base.u32[..= 0x1_0008]
|
||||
var height3 : base.u32[..= 0x1_0008]
|
||||
var status : base.status
|
||||
|
||||
var ycc_upsampling : base.u8
|
||||
var status : base.status
|
||||
|
||||
if this.swizzle_immediately {
|
||||
i = this.swizzle_immediately_c_offsets[0] as base.u64
|
||||
@@ -2137,6 +2139,11 @@ pri func decoder.swizzle_colorful!(dst: ptr base.pixel_buffer, workbuf: slice ba
|
||||
}
|
||||
}
|
||||
|
||||
ycc_upsampling = base.YCC_UPSAMPLING__BASIC as base.u8
|
||||
if not this.use_lower_quality {
|
||||
ycc_upsampling = base.YCC_UPSAMPLING__FANCY_LIKE_LIBJPEG as base.u8
|
||||
}
|
||||
|
||||
status = this.swizzler.swizzle_ycck!(
|
||||
dst: args.dst,
|
||||
dst_palette: args.dst.palette_or_else(fallback: this.dst_palette[..]),
|
||||
@@ -2169,7 +2176,7 @@ pri func decoder.swizzle_colorful!(dst: ptr base.pixel_buffer, workbuf: slice ba
|
||||
v2: this.components_v[2],
|
||||
v3: this.components_v[3],
|
||||
ycc_model: this.ycc_model,
|
||||
triangle_filter_for_2to1: not this.use_lower_quality,
|
||||
ycc_upsampling: ycc_upsampling,
|
||||
scratch_buffer_2k: this.swizzle_ycck_scratch_buffer_2k[..])
|
||||
return status
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
# VP8
|
||||
|
||||
VP8 is a compressed video data format, described in [RFC
|
||||
6386](https://www.ietf.org/rfc/rfc6386.txt).
|
||||
|
||||
The WebM movie (moving image) format consists of muliple VP8 frames, both key
|
||||
(I-Frames) and non-key (B-Frames, P-Frames, etc). Separate from WebM, the WebP
|
||||
still image format essentially wraps one VP8 key frame.
|
||||
@@ -8,6 +8,10 @@
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// --------
|
||||
|
||||
// RFC 6386 Section 7. Boolean Entropy Decoder.
|
||||
|
||||
pri func decoder.read_bit!(workbuf: roslice base.u8, part: base.u32[..= 8], prob: base.u32[..= 0xFF]) base.u32[..= 1] {
|
||||
var p : base.u32[..= 8]
|
||||
var c8 : base.u8
|
||||
|
||||
@@ -8,6 +8,14 @@
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// --------
|
||||
|
||||
// RFC 6386 Section 13. DCT Coefficient Decoding.
|
||||
//
|
||||
// and
|
||||
//
|
||||
// RFC 6386 Section 13.2. Coding of Individual Coefficient Values.
|
||||
|
||||
pri func decoder.decode_coefficients!(
|
||||
workbuf: slice base.u8,
|
||||
mbx: base.u32[..= 0x3FF],
|
||||
@@ -36,7 +44,7 @@ pri func decoder.decode_coefficients!(
|
||||
tnz = 1 & (this.mb_states_top[args.mbx] >> 23)
|
||||
this.mb_states_top[args.mbx] &= 0xFF7F_FFFF
|
||||
|
||||
lnz = this.decode_block_coefficients!(
|
||||
lnz = this.decode_subblock_coefficients!(
|
||||
workbuf: args.workbuf,
|
||||
mby: args.mby,
|
||||
seg: args.seg,
|
||||
@@ -67,7 +75,7 @@ pri func decoder.decode_coefficients!(
|
||||
|
||||
b = (4 * by) + bx
|
||||
|
||||
lnz = this.decode_block_coefficients!(
|
||||
lnz = this.decode_subblock_coefficients!(
|
||||
workbuf: args.workbuf,
|
||||
mby: args.mby,
|
||||
seg: args.seg,
|
||||
@@ -110,7 +118,7 @@ pri func decoder.decode_coefficients!(
|
||||
this.mb_states_top[args.mbx] &= 0xFFFF_FFFF ^ ((1 as base.u32) << (28 + bc + bx))
|
||||
|
||||
b = (2 * bc) + (2 * by) + bx + 16
|
||||
lnz = this.decode_block_coefficients!(
|
||||
lnz = this.decode_subblock_coefficients!(
|
||||
workbuf: args.workbuf,
|
||||
mby: args.mby,
|
||||
seg: args.seg,
|
||||
@@ -158,7 +166,7 @@ pri func decoder.initialize_mb_coeffs!() {
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_block_coefficients!(
|
||||
pri func decoder.decode_subblock_coefficients!(
|
||||
workbuf: slice base.u8,
|
||||
mby: base.u32[..= 0x3FF],
|
||||
seg: base.u32[..= 3],
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// --------
|
||||
|
||||
// A simplified and optimized version of decoder.inverse_dct_full when the AC
|
||||
// coefficients are all zero.
|
||||
pri func decoder.inverse_dct_dc_only!(
|
||||
cachex: base.u32[..= 28],
|
||||
cachey: base.u32[..= 22],
|
||||
@@ -25,6 +29,9 @@ pri func decoder.inverse_dct_dc_only!(
|
||||
}
|
||||
}
|
||||
|
||||
// RFC 6386 Section 14.4. Implementation of the DCT Inversion.
|
||||
//
|
||||
// It reads from mb_coeffs and yuv_cache and writes to yuv_cache.
|
||||
pri func decoder.inverse_dct_full!(
|
||||
cachex: base.u32[..= 28],
|
||||
cachey: base.u32[..= 22],
|
||||
@@ -119,8 +126,10 @@ pri func decoder.inverse_dct_full!(
|
||||
var q32 : base.u32
|
||||
var q33 : base.u32
|
||||
|
||||
// 85627 is approximately 65536 * cos(pi/8) * sqrt(2).
|
||||
// 35468 is approximately 65536 * sin(pi/8) * sqrt(2).
|
||||
//
|
||||
// 85627 is approximately 65536 * cos(pi/8) * sqrt(2). Compared to the RFC
|
||||
// implementation 85627 is also (20091 + 65536).
|
||||
|
||||
// --------
|
||||
|
||||
@@ -299,6 +308,9 @@ pri func decoder.inverse_dct_full!(
|
||||
this.yuv_cache[args.cachey + 3][args.cachex + 3] as base.u32) ~mod+ q33)]
|
||||
}
|
||||
|
||||
// RFC 6386 Section 14.3. Implementation of the WHT Inversion.
|
||||
//
|
||||
// It reads from and writes to mb_coeffs.
|
||||
pri func decoder.inverse_wht!() {
|
||||
var a00 : base.u32
|
||||
var a01 : base.u32
|
||||
|
||||
@@ -28,6 +28,8 @@ pri func decoder.decode_macroblocks!(dst: ptr base.pixel_buffer, workbuf: slice
|
||||
|
||||
this.mb_states_left = 0
|
||||
|
||||
// Decode this row, using this.mb_coeffs and this.yuv_cache before
|
||||
// ultimately writing to args.workbuf.
|
||||
mbx = 0
|
||||
while mbx < this.mbw,
|
||||
inv mby < 0x400,
|
||||
@@ -39,6 +41,7 @@ pri func decoder.decode_macroblocks!(dst: ptr base.pixel_buffer, workbuf: slice
|
||||
mbx += 1
|
||||
}
|
||||
|
||||
// Filter the previous row, already in args.workbuf.
|
||||
if mby > 0 {
|
||||
if this.filt_level <= 0 {
|
||||
// No-op.
|
||||
@@ -47,27 +50,22 @@ pri func decoder.decode_macroblocks!(dst: ptr base.pixel_buffer, workbuf: slice
|
||||
} else {
|
||||
this.filter_normal!(workbuf: args.workbuf, mby: mby - 1)
|
||||
}
|
||||
|
||||
status = this.swizzle_one_row_of_macroblocks!(dst: args.dst, workbuf: args.workbuf, mby: mby - 1)
|
||||
if not status.is_ok() {
|
||||
return status
|
||||
}
|
||||
}
|
||||
|
||||
mby += 1
|
||||
}
|
||||
|
||||
// Filter the final row, already in args.workbuf, and swizzle to args.dst.
|
||||
if this.mbh > 0 {
|
||||
mby = this.mbh - 1
|
||||
if this.filt_level <= 0 {
|
||||
// No-op.
|
||||
} else if this.filt_simple {
|
||||
this.filter_simple!(workbuf: args.workbuf, mby: mby)
|
||||
this.filter_simple!(workbuf: args.workbuf, mby: this.mbh - 1)
|
||||
} else {
|
||||
this.filter_normal!(workbuf: args.workbuf, mby: mby)
|
||||
this.filter_normal!(workbuf: args.workbuf, mby: this.mbh - 1)
|
||||
}
|
||||
|
||||
status = this.swizzle_one_row_of_macroblocks!(dst: args.dst, workbuf: args.workbuf, mby: mby)
|
||||
status = this.swizzle!(dst: args.dst, workbuf: args.workbuf)
|
||||
if not status.is_ok() {
|
||||
return status
|
||||
}
|
||||
@@ -85,6 +83,7 @@ pri func decoder.decode_one_macroblock!(workbuf: slice base.u8, mbx: base.u32[..
|
||||
var luma_mode : base.u32[..= 4]
|
||||
var chroma_mode : base.u32[..= 3]
|
||||
|
||||
// RFC 6386 Section 10. Segment-Based Feature Adjustments.
|
||||
seg = 0
|
||||
if this.seg_update_map {
|
||||
v1 = this.read_bit!(workbuf: args.workbuf, part: 0, prob: this.seg_probs[0] as base.u32)
|
||||
@@ -347,18 +346,9 @@ pri func decoder.copy_from_yuv_cache!(
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.swizzle_one_row_of_macroblocks!(
|
||||
pri func decoder.swizzle!(
|
||||
dst: ptr base.pixel_buffer,
|
||||
workbuf: slice base.u8,
|
||||
mby: base.u32[..= 0x3FF]) base.status {
|
||||
var y_min_incl : base.u32[..= 0x3FFF]
|
||||
var y_max_excl : base.u32[..= 0x3FFF]
|
||||
|
||||
var o : base.u64
|
||||
var src0 : slice base.u8
|
||||
var src1 : slice base.u8
|
||||
var src2 : slice base.u8
|
||||
|
||||
workbuf: slice base.u8) base.status {
|
||||
var status : base.status
|
||||
|
||||
if (this.workbuf_yuv_y_end > this.workbuf_yuv_u_end) or
|
||||
@@ -369,48 +359,24 @@ pri func decoder.swizzle_one_row_of_macroblocks!(
|
||||
assert this.workbuf_yuv_u_end <= args.workbuf.length() via "a <= b: a <= c; c <= b"(c: this.workbuf_yuv_v_end)
|
||||
assert this.workbuf_yuv_y_end <= args.workbuf.length() via "a <= b: a <= c; c <= b"(c: this.workbuf_yuv_u_end)
|
||||
|
||||
// There are 16 rows of pixels per macroblock. However, the bottom 6 rows
|
||||
// of pixels (the bottom 3 rows of samples, at 4:2:0 chroma subsampling)
|
||||
// can be modified by the the macroblock below's loop filtering (which
|
||||
// happens after decoder.swizzle_one_row_of_macroblocks returns), unless
|
||||
// we're swizzling the bottom-most row of macroblocks.
|
||||
y_min_incl = (args.mby * 16) ~sat- 6
|
||||
y_max_excl = (args.mby * 16) + 10
|
||||
if (args.mby + 1) >= this.mbh {
|
||||
y_max_excl = this.height
|
||||
}
|
||||
|
||||
o = (y_min_incl * this.workbuf_yuv_y_stride) as base.u64
|
||||
if o < this.workbuf_yuv_y_end {
|
||||
src0 = args.workbuf[o .. this.workbuf_yuv_y_end]
|
||||
}
|
||||
o = (((y_min_incl / 2) * this.workbuf_yuv_uv_stride) as base.u64) + this.workbuf_yuv_y_end
|
||||
if o < this.workbuf_yuv_u_end {
|
||||
src1 = args.workbuf[o .. this.workbuf_yuv_u_end]
|
||||
}
|
||||
o = (((y_min_incl / 2) * this.workbuf_yuv_uv_stride) as base.u64) + this.workbuf_yuv_u_end
|
||||
if o < this.workbuf_yuv_v_end {
|
||||
src2 = args.workbuf[o .. this.workbuf_yuv_v_end]
|
||||
}
|
||||
|
||||
status = this.swizzler.swizzle_ycck!(
|
||||
dst: args.dst,
|
||||
dst_palette: args.dst.palette(),
|
||||
x_min_incl: 0,
|
||||
x_max_excl: this.width,
|
||||
y_min_incl: y_min_incl,
|
||||
y_max_excl: y_max_excl,
|
||||
src0: src0,
|
||||
src1: src1,
|
||||
src2: src2,
|
||||
y_min_incl: 0,
|
||||
y_max_excl: this.height,
|
||||
src0: args.workbuf[.. this.workbuf_yuv_y_end],
|
||||
src1: args.workbuf[this.workbuf_yuv_y_end .. this.workbuf_yuv_u_end],
|
||||
src2: args.workbuf[this.workbuf_yuv_u_end .. this.workbuf_yuv_v_end],
|
||||
src3: this.util.empty_slice_u8(),
|
||||
width0: this.mbw * 16,
|
||||
width1: this.mbw * 8,
|
||||
width2: this.mbw * 8,
|
||||
width3: 0,
|
||||
height0: (this.mbh * 16) ~sat- y_min_incl,
|
||||
height1: (this.mbh * 8) ~sat- (y_min_incl / 2),
|
||||
height2: (this.mbh * 8) ~sat- (y_min_incl / 2),
|
||||
height0: this.mbh * 16,
|
||||
height1: this.mbh * 8,
|
||||
height2: this.mbh * 8,
|
||||
height3: 0,
|
||||
stride0: this.mbw * 16,
|
||||
stride1: this.mbw * 8,
|
||||
@@ -425,7 +391,7 @@ pri func decoder.swizzle_one_row_of_macroblocks!(
|
||||
v2: 1,
|
||||
v3: 0,
|
||||
ycc_model: base.YCC_MODEL__BT_601_STUDIO_RANGE as base.u8,
|
||||
triangle_filter_for_2to1: false,
|
||||
ycc_upsampling: base.YCC_UPSAMPLING__FANCY_LIKE_LIBWEBP as base.u8,
|
||||
scratch_buffer_2k: this.swizzle_ycck_scratch_buffer_2k[..])
|
||||
return status
|
||||
}
|
||||
@@ -10,7 +10,13 @@
|
||||
|
||||
// --------
|
||||
|
||||
// Predicts a 4×4 luma block, the Xs below, based on samples top and left.
|
||||
// RFC 6386 Section 12. Intraframe Prediction.
|
||||
//
|
||||
// These methods read from and write to yuv_cache.
|
||||
|
||||
// --------
|
||||
|
||||
// Predicts a 4×4 luma subblock, the Xs below, based on samples top and left.
|
||||
//
|
||||
// a b c d e f g h i
|
||||
// p X X X X
|
||||
|
||||
@@ -8,6 +8,66 @@
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// --------
|
||||
|
||||
// Reconstructing YUV samples involves adding predictions (based on previous
|
||||
// YUV samples, in macroblocks one column left or one column above) to
|
||||
// residuals (decoded from the bitstream, dequantized and IDCT'ed).
|
||||
//
|
||||
// There are 16×16 = 256 luma and 2×8×8 = 128 chroma samples per macroblock.
|
||||
// The decoder.yuv_cache field is a bit larger than that, being an array[26]
|
||||
// array[32] base.u8. Here's the layout.
|
||||
//
|
||||
// 0 1 2 3 4 5 6 7 8 9 A B C D E F 0 1 2 3 4 5 6 7 8 9 A B C D E F
|
||||
// . . . . . . . a b b b b b b b b b b b b b b b b c c c c . . . . 00
|
||||
// . . . . . . . d Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y . . . . . . . . 01
|
||||
// . . . . . . . d Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y . . . . . . . . 02
|
||||
// . . . . . . . d Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y . . . . . . . . 03
|
||||
// . . . . . . . d Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y c c c c . . . . 04
|
||||
// . . . . . . . d Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y . . . . . . . . 05
|
||||
// . . . . . . . d Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y . . . . . . . . 06
|
||||
// . . . . . . . d Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y . . . . . . . . 07
|
||||
// . . . . . . . d Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y c c c c . . . . 08
|
||||
// . . . . . . . d Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y . . . . . . . . 09
|
||||
// . . . . . . . d Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y . . . . . . . . 0A
|
||||
// . . . . . . . d Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y . . . . . . . . 0B
|
||||
// . . . . . . . d Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y c c c c . . . . 0C
|
||||
// . . . . . . . d Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y . . . . . . . . 0D
|
||||
// . . . . . . . d Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y . . . . . . . . 0E
|
||||
// . . . . . . . d Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y . . . . . . . . 0F
|
||||
// . . . . . . . d Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y . . . . . . . . 10
|
||||
// . . . . . . . e f f f f f f f f . . . . . . . g h h h h h h h h 11
|
||||
// . . . . . . . i U U U U U U U U . . . . . . . j V V V V V V V V 12
|
||||
// . . . . . . . i U U U U U U U U . . . . . . . j V V V V V V V V 13
|
||||
// . . . . . . . i U U U U U U U U . . . . . . . j V V V V V V V V 14
|
||||
// . . . . . . . i U U U U U U U U . . . . . . . j V V V V V V V V 15
|
||||
// . . . . . . . i U U U U U U U U . . . . . . . j V V V V V V V V 16
|
||||
// . . . . . . . i U U U U U U U U . . . . . . . j V V V V V V V V 17
|
||||
// . . . . . . . i U U U U U U U U . . . . . . . j V V V V V V V V 18
|
||||
// . . . . . . . i U U U U U U U U . . . . . . . j V V V V V V V V 19
|
||||
//
|
||||
// Y, U and V are this macroblock's luma and chroma values.
|
||||
//
|
||||
// The Y predictions (per 4×4 subblock) depend on the row above's Y values
|
||||
// (either abc or dYc) and the column left's Y values (ad or bY).
|
||||
//
|
||||
// The U predictions (per 8×8 block) depend on the row above's U values (ef)
|
||||
// and the column left's U values (i).
|
||||
//
|
||||
// The V predictions (per 8×8 block) depend on the row above's V values (gh)
|
||||
// and the column left's V values (j).
|
||||
//
|
||||
// For top-row (mby == 0) macroblocks, abcefgh is initialized to 0x7F. For
|
||||
// other macroblocks, these are copied from the bottom-most row of the
|
||||
// macroblock above (before filtering, for I-Frames), from the workbuf.
|
||||
//
|
||||
// The c values are then duplicated from row 0x00 to rows 0x04, 0x08 and 0x0C.
|
||||
//
|
||||
// For left-column (mbx == 0) macroblocks, adeigj are initialized to 0x81 (but
|
||||
// aeg is 0x7F if mby is also 0). For other macroblocks, these are copied from
|
||||
// the right-most column of the macroblock to the left (before filtering, for
|
||||
// I-Frames), from the yuv_cache to itself, shifted by 8 or 16 columns.
|
||||
|
||||
pri func decoder.reconstruct!(
|
||||
workbuf: slice base.u8,
|
||||
mbx: base.u32[..= 0x3FF],
|
||||
@@ -120,7 +180,10 @@ pri func decoder.prepare_yuv_cache!(
|
||||
var offset : base.u64[..= 0x17FE_FFF8]
|
||||
var o : base.u64
|
||||
|
||||
// For abcdefghij comments, see the layout at the top of this file.
|
||||
|
||||
if args.mbx <= 0 {
|
||||
// Initialize adeigj to 0x81.
|
||||
j = 0x00
|
||||
while j < 0x11 {
|
||||
this.yuv_cache[j][0x07] = 0x81
|
||||
@@ -133,6 +196,7 @@ pri func decoder.prepare_yuv_cache!(
|
||||
}
|
||||
|
||||
} else {
|
||||
// Copy from the previous (left) macroblock, in yuv_cache, to adeigj.
|
||||
j = 0x00
|
||||
while j < 0x11 {
|
||||
this.yuv_cache[j][0x07] = this.yuv_cache[j][0x17]
|
||||
@@ -146,6 +210,7 @@ pri func decoder.prepare_yuv_cache!(
|
||||
}
|
||||
|
||||
if args.mby <= 0 {
|
||||
// Initialize abcefgh to 0x7F.
|
||||
i = 0x00
|
||||
while i < 0x20 {
|
||||
this.yuv_cache[0x00][i] = 0x7F
|
||||
@@ -158,6 +223,8 @@ pri func decoder.prepare_yuv_cache!(
|
||||
}
|
||||
|
||||
} else {
|
||||
// Copy from the previous (above) macroblock, in args.workbuf, to bcfh.
|
||||
|
||||
offset = 0 +
|
||||
(((((args.mby * 16) - 1) * this.workbuf_yuv_y_stride) + (args.mbx * 16)) as base.u64)
|
||||
i = 0x00
|
||||
@@ -220,6 +287,7 @@ pri func decoder.prepare_yuv_cache!(
|
||||
}
|
||||
}
|
||||
|
||||
// Duplicate the c values.
|
||||
j = 0x04
|
||||
while j < 0x10 {
|
||||
this.yuv_cache[j][0x18] = this.yuv_cache[0][0x18]
|
||||
|
||||
@@ -33,6 +33,8 @@ pub struct decoder? implements base.image_decoder(
|
||||
|
||||
frame_config_io_position : base.u64,
|
||||
|
||||
// This uses the same representation as an wuffs_base__optional_u63:
|
||||
// ((value_as_u63 << 1) | has_value_as_u1).
|
||||
quirk_source_length : base.u64,
|
||||
|
||||
// Just under 144 MiB, for 9 partitions each up to 0xFF_FFFF bytes.
|
||||
@@ -119,6 +121,7 @@ pub struct decoder? implements base.image_decoder(
|
||||
// hold in the 0x100 bit) and prob_skip_false (in the low 8 bits).
|
||||
prob_skip : base.u32[..= 0x1FF],
|
||||
|
||||
// 4×4 luma subblock prediction modes.
|
||||
mb_subblock_modes : array[16] base.u8[..= 9],
|
||||
|
||||
// Two u32 values whose bits are packed like this:
|
||||
@@ -132,6 +135,13 @@ pub struct decoder? implements base.image_decoder(
|
||||
mb_dc_nz : base.u32,
|
||||
mb_ac_nz : base.u32,
|
||||
|
||||
// The workspace for the reconstruction-in-progress macroblock,
|
||||
// containing the predicted and then fully decoded (prediction plus
|
||||
// post-IDCT residuals) YUV samples to copy out to the workbuf. Its
|
||||
// edges also hold samples from previous (left and top) macroblocks
|
||||
// that are used in calculating this macroblock's predictions.
|
||||
//
|
||||
// See the comments near decoder.reconstruct for the layout.
|
||||
yuv_cache : array[26] array[32] base.u8,
|
||||
|
||||
swizzler : base.pixel_swizzler,
|
||||
@@ -142,6 +152,20 @@ pub struct decoder? implements base.image_decoder(
|
||||
// 1056 is (4 planes, 8 bands, 3 contexts, 11 tokens) flattened.
|
||||
coeff_probs : array[1056] base.u8,
|
||||
|
||||
// Macroblock coefficients. Per this.decode_one_macroblock:
|
||||
//
|
||||
// this.decode_coefficients decodes these macroblock coefficients from
|
||||
// the bitstream and dequantizes them, writing them to this.mb_coeffs.
|
||||
// At this point, these are pre-IDCT residuals.
|
||||
//
|
||||
// this.reconstruct calculates the predictions (writing them to
|
||||
// this.yuv_cache, not this.mb_coeffs) and then applies the inverse WHT
|
||||
// (if applicable) and the inverse DCT to the pre-IDCT residuals, by
|
||||
// calling this.inverse_dct_etc.
|
||||
//
|
||||
// this.inverse_dct_etc reads the pre-IDCT residuals from
|
||||
// this.mb_coeffs and writes fully decoded samples (predictions plus
|
||||
// post-IDCT residuals) to this.yuv_cache.
|
||||
mb_coeffs : array[25] array[16] base.u16,
|
||||
|
||||
// Macroblock states are a u32 whose bits are packed like this:
|
||||
|
||||
+4
-3
@@ -1,12 +1,13 @@
|
||||
# WebP
|
||||
|
||||
WebP is a still image format, described in [RFC
|
||||
6386](https://www.ietf.org/rfc/rfc6386.txt).
|
||||
WebP is a still image format, described in the [WebP Container
|
||||
Specification](https://developers.google.com/speed/webp/docs/riff_container).
|
||||
|
||||
The ["Making Software - Image
|
||||
Compression"](https://www.makingsoftware.com/chapters/image-compression) book
|
||||
chapter also has a good overview of a number of image formats, including WebP.
|
||||
|
||||
There are two WebP variants: lossy (based on VP8) and lossless. Wuffs' VP8
|
||||
There are two WebP variants: lossy (based on VP8) and lossless (based on what's
|
||||
essentially an unrelated design, other than "WebP" branding). Wuffs' VP8
|
||||
implementation is in a separate package, as the WebM moving image format also
|
||||
uses VP8. There's no Wuffs WebM package yet but there might be in the future.
|
||||
@@ -91,7 +91,7 @@ OK. f37cea44 test/3pdata/blinksuite/icc-v2-gbr-422-whole-mcus.jpg
|
||||
OK. 1de5a906 test/3pdata/blinksuite/icc-v2-gbr.jpg
|
||||
OK. 0da5f37e test/3pdata/blinksuite/jpeg-height-exif-orientation.jpg
|
||||
OK. 4409dca6 test/3pdata/blinksuite/large-gif-checkerboard.gif
|
||||
OK. 8f798e8b test/3pdata/blinksuite/large.webp
|
||||
OK. d67648b6 test/3pdata/blinksuite/large.webp
|
||||
BAD 2f310e57 test/3pdata/blinksuite/missing-eoi.jpg
|
||||
OK. 72bbe2b6 test/3pdata/blinksuite/motion-jpeg-single-frame.jpg
|
||||
OK. 0268284a test/3pdata/blinksuite/mu.png
|
||||
@@ -170,10 +170,10 @@ OK. 9a7e5ec7 test/3pdata/blinksuite/sprite_alternate_fragments_same.png
|
||||
OK. 1b1f5f96 test/3pdata/blinksuite/stripes-large.png
|
||||
OK. 6b85cdb9 test/3pdata/blinksuite/stripes-small.png
|
||||
OK. 16c2c0fe test/3pdata/blinksuite/test-load.jpg
|
||||
OK. 631f6a02 test/3pdata/blinksuite/test.webp
|
||||
OK. 6fbda804 test/3pdata/blinksuite/test.webp
|
||||
OK. 19d3a207 test/3pdata/blinksuite/test3.webp
|
||||
BAD 1dfa35c6 test/3pdata/blinksuite/truncated2.webp
|
||||
OK. 603ddc49 test/3pdata/blinksuite/webp-color-no-profile-lossy.webp
|
||||
OK. eb191e45 test/3pdata/blinksuite/webp-color-no-profile-lossy.webp
|
||||
BAD ed67a9a5 test/3pdata/blinksuite/wrong-block-length.gif
|
||||
OK. 577c5c4c test/3pdata/blinksuite/ycbcr-420-fast-int-progressive.jpg
|
||||
OK. bf4cd8e2 test/3pdata/blinksuite/ycbcr-420-float-progressive.jpg
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Generated by script/print-nia-checksums.sh
|
||||
OK. ca4c0038 test/3pdata/webpsuite/bad_palette_index.webp
|
||||
OK. 3557c3f5 test/3pdata/webpsuite/bryce.webp
|
||||
OK. a07d001c test/3pdata/webpsuite/bug3.webp
|
||||
OK. 3dd065ab test/3pdata/webpsuite/bryce.webp
|
||||
OK. 7794c8b2 test/3pdata/webpsuite/bug3.webp
|
||||
OK. 6fbda804 test/3pdata/webpsuite/color_cache_bits_11.webp
|
||||
BAD d338aed8 test/3pdata/webpsuite/dual_transform.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/grid.bmp
|
||||
@@ -49,77 +49,77 @@ OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_6.webp
|
||||
BAD 79781cfb test/3pdata/webpsuite/lossless_vec_2_7.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_8.webp
|
||||
BAD 79781cfb test/3pdata/webpsuite/lossless_vec_2_9.webp
|
||||
OK. 3a23e407 test/3pdata/webpsuite/lossy_extreme_probabilities.webp
|
||||
OK. f6f31bd1 test/3pdata/webpsuite/lossy_q0_f100.webp
|
||||
OK. ac62b1e6 test/3pdata/webpsuite/lossy_extreme_probabilities.webp
|
||||
OK. 84ff1fbf test/3pdata/webpsuite/lossy_q0_f100.webp
|
||||
OK. 6957defa test/3pdata/webpsuite/near_lossless_75.webp
|
||||
OK. 7c80a001 test/3pdata/webpsuite/one_color_no_palette.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/peak.bmp
|
||||
OK. 315bbd77 test/3pdata/webpsuite/peak.pgm
|
||||
OK. 6706e719 test/3pdata/webpsuite/peak.png
|
||||
OK. 6706e719 test/3pdata/webpsuite/peak.ppm
|
||||
OK. e58f2013 test/3pdata/webpsuite/segment01.webp
|
||||
OK. 931e5bb2 test/3pdata/webpsuite/segment02.webp
|
||||
OK. c42afa6d test/3pdata/webpsuite/segment03.webp
|
||||
OK. 6d2a2c1f test/3pdata/webpsuite/segment01.webp
|
||||
OK. b7705924 test/3pdata/webpsuite/segment02.webp
|
||||
OK. 98115d46 test/3pdata/webpsuite/segment03.webp
|
||||
OK. 9fba8052 test/3pdata/webpsuite/small_13x1.webp
|
||||
OK. f08db259 test/3pdata/webpsuite/small_1x1.webp
|
||||
OK. ae403f6e test/3pdata/webpsuite/small_1x13.webp
|
||||
OK. 70c37cb6 test/3pdata/webpsuite/small_31x13.webp
|
||||
OK. 80c1ff42 test/3pdata/webpsuite/test-nostrong.webp
|
||||
OK. 631f6a02 test/3pdata/webpsuite/test.webp
|
||||
OK. fc06d690 test/3pdata/webpsuite/small_31x13.webp
|
||||
OK. 706a6c13 test/3pdata/webpsuite/test-nostrong.webp
|
||||
OK. 6fbda804 test/3pdata/webpsuite/test.webp
|
||||
OK. b1e2e316 test/3pdata/webpsuite/very_short.webp
|
||||
OK. ff7d9585 test/3pdata/webpsuite/vp80-00-comprehensive-001.webp
|
||||
OK. 684b846a test/3pdata/webpsuite/vp80-00-comprehensive-002.webp
|
||||
OK. d3127a10 test/3pdata/webpsuite/vp80-00-comprehensive-003.webp
|
||||
OK. ff7d9585 test/3pdata/webpsuite/vp80-00-comprehensive-004.webp
|
||||
OK. c5600ecc test/3pdata/webpsuite/vp80-00-comprehensive-005.webp
|
||||
OK. 3836d469 test/3pdata/webpsuite/vp80-00-comprehensive-006.webp
|
||||
OK. 04f7f4c9 test/3pdata/webpsuite/vp80-00-comprehensive-007.webp
|
||||
OK. e06af858 test/3pdata/webpsuite/vp80-00-comprehensive-008.webp
|
||||
OK. 9458b100 test/3pdata/webpsuite/vp80-00-comprehensive-009.webp
|
||||
OK. 954647a5 test/3pdata/webpsuite/vp80-00-comprehensive-010.webp
|
||||
OK. ff7d9585 test/3pdata/webpsuite/vp80-00-comprehensive-011.webp
|
||||
OK. 6732c101 test/3pdata/webpsuite/vp80-00-comprehensive-012.webp
|
||||
OK. df21b5c8 test/3pdata/webpsuite/vp80-00-comprehensive-013.webp
|
||||
OK. de3154f1 test/3pdata/webpsuite/vp80-00-comprehensive-014.webp
|
||||
OK. 6291f264 test/3pdata/webpsuite/vp80-00-comprehensive-015.webp
|
||||
OK. 37bf6310 test/3pdata/webpsuite/vp80-00-comprehensive-001.webp
|
||||
OK. d87c0135 test/3pdata/webpsuite/vp80-00-comprehensive-002.webp
|
||||
OK. 53f2a4c8 test/3pdata/webpsuite/vp80-00-comprehensive-003.webp
|
||||
OK. 37bf6310 test/3pdata/webpsuite/vp80-00-comprehensive-004.webp
|
||||
OK. cc470087 test/3pdata/webpsuite/vp80-00-comprehensive-005.webp
|
||||
OK. 22f2bc85 test/3pdata/webpsuite/vp80-00-comprehensive-006.webp
|
||||
OK. 861d5c90 test/3pdata/webpsuite/vp80-00-comprehensive-007.webp
|
||||
OK. ec6e76ae test/3pdata/webpsuite/vp80-00-comprehensive-008.webp
|
||||
OK. 24899b34 test/3pdata/webpsuite/vp80-00-comprehensive-009.webp
|
||||
OK. b265598f test/3pdata/webpsuite/vp80-00-comprehensive-010.webp
|
||||
OK. 37bf6310 test/3pdata/webpsuite/vp80-00-comprehensive-011.webp
|
||||
OK. dafaf33d test/3pdata/webpsuite/vp80-00-comprehensive-012.webp
|
||||
OK. ca91f611 test/3pdata/webpsuite/vp80-00-comprehensive-013.webp
|
||||
OK. 11382a93 test/3pdata/webpsuite/vp80-00-comprehensive-014.webp
|
||||
OK. 85b7887a test/3pdata/webpsuite/vp80-00-comprehensive-015.webp
|
||||
OK. 3346ef2b test/3pdata/webpsuite/vp80-00-comprehensive-016.webp
|
||||
OK. 3346ef2b test/3pdata/webpsuite/vp80-00-comprehensive-017.webp
|
||||
OK. 34a0adbb test/3pdata/webpsuite/vp80-01-intra-1400.webp
|
||||
OK. 2cda6f62 test/3pdata/webpsuite/vp80-01-intra-1411.webp
|
||||
OK. a321721b test/3pdata/webpsuite/vp80-01-intra-1416.webp
|
||||
OK. 754a4ff8 test/3pdata/webpsuite/vp80-01-intra-1417.webp
|
||||
OK. 34a0adbb test/3pdata/webpsuite/vp80-02-inter-1402.webp
|
||||
OK. 2cda6f62 test/3pdata/webpsuite/vp80-02-inter-1412.webp
|
||||
OK. 0bb72bca test/3pdata/webpsuite/vp80-02-inter-1418.webp
|
||||
OK. 93739a20 test/3pdata/webpsuite/vp80-02-inter-1424.webp
|
||||
OK. 34a0adbb test/3pdata/webpsuite/vp80-03-segmentation-1401.webp
|
||||
OK. 34a0adbb test/3pdata/webpsuite/vp80-03-segmentation-1403.webp
|
||||
OK. aaea276b test/3pdata/webpsuite/vp80-03-segmentation-1407.webp
|
||||
OK. aaea276b test/3pdata/webpsuite/vp80-03-segmentation-1408.webp
|
||||
OK. aaea276b test/3pdata/webpsuite/vp80-03-segmentation-1409.webp
|
||||
OK. aaea276b test/3pdata/webpsuite/vp80-03-segmentation-1410.webp
|
||||
OK. 2cda6f62 test/3pdata/webpsuite/vp80-03-segmentation-1413.webp
|
||||
OK. 65fb3f68 test/3pdata/webpsuite/vp80-03-segmentation-1414.webp
|
||||
OK. 65fb3f68 test/3pdata/webpsuite/vp80-03-segmentation-1415.webp
|
||||
OK. 3819b4d7 test/3pdata/webpsuite/vp80-03-segmentation-1425.webp
|
||||
OK. 981e1d2e test/3pdata/webpsuite/vp80-03-segmentation-1426.webp
|
||||
OK. 57780055 test/3pdata/webpsuite/vp80-03-segmentation-1427.webp
|
||||
OK. caf44365 test/3pdata/webpsuite/vp80-03-segmentation-1432.webp
|
||||
OK. 17d6af96 test/3pdata/webpsuite/vp80-03-segmentation-1435.webp
|
||||
OK. 792cc4dc test/3pdata/webpsuite/vp80-03-segmentation-1436.webp
|
||||
OK. a0c109d5 test/3pdata/webpsuite/vp80-03-segmentation-1437.webp
|
||||
OK. 88f3ed22 test/3pdata/webpsuite/vp80-03-segmentation-1441.webp
|
||||
OK. ad7b1ced test/3pdata/webpsuite/vp80-03-segmentation-1442.webp
|
||||
OK. 34a0adbb test/3pdata/webpsuite/vp80-04-partitions-1404.webp
|
||||
OK. 34a0adbb test/3pdata/webpsuite/vp80-04-partitions-1405.webp
|
||||
OK. 34a0adbb test/3pdata/webpsuite/vp80-04-partitions-1406.webp
|
||||
OK. deb943fc test/3pdata/webpsuite/vp80-05-sharpness-1428.webp
|
||||
OK. eaffae2b test/3pdata/webpsuite/vp80-05-sharpness-1429.webp
|
||||
OK. 4442b90a test/3pdata/webpsuite/vp80-01-intra-1400.webp
|
||||
OK. 20ba1cc0 test/3pdata/webpsuite/vp80-01-intra-1411.webp
|
||||
OK. 6dafc49a test/3pdata/webpsuite/vp80-01-intra-1416.webp
|
||||
OK. bfd3e3e3 test/3pdata/webpsuite/vp80-01-intra-1417.webp
|
||||
OK. 4442b90a test/3pdata/webpsuite/vp80-02-inter-1402.webp
|
||||
OK. 20ba1cc0 test/3pdata/webpsuite/vp80-02-inter-1412.webp
|
||||
OK. 18734e4a test/3pdata/webpsuite/vp80-02-inter-1418.webp
|
||||
OK. de941f26 test/3pdata/webpsuite/vp80-02-inter-1424.webp
|
||||
OK. 4442b90a test/3pdata/webpsuite/vp80-03-segmentation-1401.webp
|
||||
OK. 4442b90a test/3pdata/webpsuite/vp80-03-segmentation-1403.webp
|
||||
OK. 29b4a1ef test/3pdata/webpsuite/vp80-03-segmentation-1407.webp
|
||||
OK. 29b4a1ef test/3pdata/webpsuite/vp80-03-segmentation-1408.webp
|
||||
OK. 29b4a1ef test/3pdata/webpsuite/vp80-03-segmentation-1409.webp
|
||||
OK. 29b4a1ef test/3pdata/webpsuite/vp80-03-segmentation-1410.webp
|
||||
OK. 20ba1cc0 test/3pdata/webpsuite/vp80-03-segmentation-1413.webp
|
||||
OK. 8463f4cd test/3pdata/webpsuite/vp80-03-segmentation-1414.webp
|
||||
OK. 8463f4cd test/3pdata/webpsuite/vp80-03-segmentation-1415.webp
|
||||
OK. 002fde0c test/3pdata/webpsuite/vp80-03-segmentation-1425.webp
|
||||
OK. 57573719 test/3pdata/webpsuite/vp80-03-segmentation-1426.webp
|
||||
OK. 13241231 test/3pdata/webpsuite/vp80-03-segmentation-1427.webp
|
||||
OK. dab26697 test/3pdata/webpsuite/vp80-03-segmentation-1432.webp
|
||||
OK. c3ef4215 test/3pdata/webpsuite/vp80-03-segmentation-1435.webp
|
||||
OK. c5120084 test/3pdata/webpsuite/vp80-03-segmentation-1436.webp
|
||||
OK. bcc51ad6 test/3pdata/webpsuite/vp80-03-segmentation-1437.webp
|
||||
OK. f1372752 test/3pdata/webpsuite/vp80-03-segmentation-1441.webp
|
||||
OK. cf14a320 test/3pdata/webpsuite/vp80-03-segmentation-1442.webp
|
||||
OK. 4442b90a test/3pdata/webpsuite/vp80-04-partitions-1404.webp
|
||||
OK. 4442b90a test/3pdata/webpsuite/vp80-04-partitions-1405.webp
|
||||
OK. 4442b90a test/3pdata/webpsuite/vp80-04-partitions-1406.webp
|
||||
OK. d6068a35 test/3pdata/webpsuite/vp80-05-sharpness-1428.webp
|
||||
OK. 84c592b7 test/3pdata/webpsuite/vp80-05-sharpness-1429.webp
|
||||
OK. 88ca32c7 test/3pdata/webpsuite/vp80-05-sharpness-1430.webp
|
||||
OK. 386ff4b2 test/3pdata/webpsuite/vp80-05-sharpness-1431.webp
|
||||
OK. 792cc4dc test/3pdata/webpsuite/vp80-05-sharpness-1433.webp
|
||||
OK. 8220ff9f test/3pdata/webpsuite/vp80-05-sharpness-1434.webp
|
||||
OK. 2b2a6b87 test/3pdata/webpsuite/vp80-05-sharpness-1438.webp
|
||||
OK. 7342903f test/3pdata/webpsuite/vp80-05-sharpness-1439.webp
|
||||
OK. 792cc4dc test/3pdata/webpsuite/vp80-05-sharpness-1440.webp
|
||||
OK. a5c713d9 test/3pdata/webpsuite/vp80-05-sharpness-1443.webp
|
||||
OK. bfa52a04 test/3pdata/webpsuite/vp80-05-sharpness-1431.webp
|
||||
OK. c5120084 test/3pdata/webpsuite/vp80-05-sharpness-1433.webp
|
||||
OK. 5941d626 test/3pdata/webpsuite/vp80-05-sharpness-1434.webp
|
||||
OK. 2e9ca716 test/3pdata/webpsuite/vp80-05-sharpness-1438.webp
|
||||
OK. 85784028 test/3pdata/webpsuite/vp80-05-sharpness-1439.webp
|
||||
OK. c5120084 test/3pdata/webpsuite/vp80-05-sharpness-1440.webp
|
||||
OK. 5e488473 test/3pdata/webpsuite/vp80-05-sharpness-1443.webp
|
||||
@@ -8,6 +8,9 @@
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "bzlib.h"
|
||||
|
||||
const char* //
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
// #define WUFFS_MIMICLIB_USE_LIBDEFLATE_INSTEAD_OF_ZLIB 1
|
||||
// #define WUFFS_MIMICLIB_USE_MINIZ_INSTEAD_OF_ZLIB 1
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// -------------------------------- WUFFS_MIMICLIB_USE_XXX_INSTEAD_OF_ZLIB
|
||||
#if defined(WUFFS_MIMICLIB_USE_LIBDEFLATE_INSTEAD_OF_ZLIB)
|
||||
#include "libdeflate.h"
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "gif_lib.h"
|
||||
|
||||
int //
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
//
|
||||
// #define WUFFS_MIMICLIB_USE_STB_IMAGE_INSTEAD_OF_LIBJPEG 1
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// -------------------------------- WUFFS_MIMICLIB_USE_XXX_INSTEAD_OF_LIBJPEG
|
||||
#if defined(WUFFS_MIMICLIB_USE_STB_IMAGE_INSTEAD_OF_LIBJPEG)
|
||||
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "lzma.h"
|
||||
|
||||
const char* //
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "openssl/evp.h"
|
||||
|
||||
const char* //
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
// #define WUFFS_MIMICLIB_USE_LODEPNG_INSTEAD_OF_LIBPNG 1
|
||||
// #define WUFFS_MIMICLIB_USE_STB_IMAGE_INSTEAD_OF_LIBPNG 1
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// -------------------------------- WUFFS_MIMICLIB_USE_XXX_INSTEAD_OF_LIBPNG
|
||||
#if defined(WUFFS_MIMICLIB_USE_LIBSPNG_INSTEAD_OF_LIBPNG)
|
||||
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// We #include a foo.cpp file, not a foo.h file, as stb_image is a "single file
|
||||
// C library".
|
||||
//
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "webp/decode.h"
|
||||
|
||||
static void //
|
||||
@@ -74,7 +77,6 @@ mimic_webp_decode(uint64_t* n_bytes_out,
|
||||
return "mimic_webp_decode: unsupported pixfmt";
|
||||
}
|
||||
|
||||
config.options.no_fancy_upsampling = 1; // TODO: remove for best mimicry.
|
||||
config.output.colorspace = MODE_BGRA;
|
||||
config.output.width = w;
|
||||
config.output.height = h;
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "xxhash.h"
|
||||
|
||||
uint32_t global_mimiclib_xxhash32_unused_u32;
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 310 B |
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
@@ -65,7 +65,7 @@ OK. 41e6110e test/data/bricks-color.etc1s.pkm
|
||||
OK. 5670f263 test/data/bricks-color.etc2.pkm
|
||||
OK. 72a1f9cc test/data/bricks-color.jpeg
|
||||
OK. 076cb375 test/data/bricks-color.lossless.webp
|
||||
OK. 3466b80b test/data/bricks-color.lossy.webp
|
||||
OK. 25a84d5d test/data/bricks-color.lossy.webp
|
||||
OK. 076cb375 test/data/bricks-color.png
|
||||
OK. 076cb375 test/data/bricks-color.qoi
|
||||
OK. 076cb375 test/data/bricks-color.tga
|
||||
@@ -102,26 +102,26 @@ OK. 030f5a48 test/data/harvesters.bmp
|
||||
OK. c18b3d5a test/data/harvesters.gif
|
||||
OK. f217df74 test/data/harvesters.jpeg
|
||||
OK. 030f5a48 test/data/harvesters.lossless.webp
|
||||
OK. 60bc9e08 test/data/harvesters.lossy.webp
|
||||
OK. 9fcd525c test/data/harvesters.lossy.webp
|
||||
OK. 030f5a48 test/data/harvesters.png
|
||||
OK. e776c90f test/data/hat.bmp
|
||||
OK. 6dcba6a4 test/data/hat.gif
|
||||
OK. 2298f3ca test/data/hat.jpeg
|
||||
OK. e776c90f test/data/hat.lossless.webp
|
||||
OK. be7f0169 test/data/hat.lossy.webp
|
||||
OK. 291ba102 test/data/hat.lossy.webp
|
||||
OK. e776c90f test/data/hat.png
|
||||
OK. d30bfe5d test/data/hat.wbmp
|
||||
OK. 33a44f22 test/data/hibiscus.primitive.bmp
|
||||
OK. 25e212b3 test/data/hibiscus.primitive.gif
|
||||
OK. 9624fa44 test/data/hibiscus.primitive.jpeg
|
||||
OK. 33a44f22 test/data/hibiscus.primitive.lossless.webp
|
||||
OK. 09bbaab0 test/data/hibiscus.primitive.lossy.webp
|
||||
OK. 05ebd4c2 test/data/hibiscus.primitive.lossy.webp
|
||||
OK. 33a44f22 test/data/hibiscus.primitive.png
|
||||
OK. 60040742 test/data/hibiscus.regular.bmp
|
||||
OK. b727da8b test/data/hibiscus.regular.gif
|
||||
OK. 41e39405 test/data/hibiscus.regular.jpeg
|
||||
OK. 60040742 test/data/hibiscus.regular.lossless.webp
|
||||
OK. 6bbe1ed2 test/data/hibiscus.regular.lossy.webp
|
||||
OK. 6f151b3e test/data/hibiscus.regular.lossy.webp
|
||||
OK. 60040742 test/data/hibiscus.regular.png
|
||||
OK. dcbb225a test/data/hippopotamus.bmp
|
||||
OK. ed4b78fc test/data/hippopotamus.interlaced.gif
|
||||
@@ -130,7 +130,7 @@ BAD c3c4bd65 test/data/hippopotamus.interlaced.truncated.gif
|
||||
BAD 3feec847 test/data/hippopotamus.interlaced.truncated.png
|
||||
OK. 96bdbbb3 test/data/hippopotamus.jpeg
|
||||
OK. dcbb225a test/data/hippopotamus.lossless.webp
|
||||
OK. 66ccbffa test/data/hippopotamus.lossy.webp
|
||||
OK. 56cf6ae1 test/data/hippopotamus.lossy.webp
|
||||
OK. 2535637e test/data/hippopotamus.masked-with-muybridge.etc2.bgra-binary.pkm
|
||||
OK. 720180ee test/data/hippopotamus.masked-with-muybridge.etc2.bgra-nonpremul.pkm
|
||||
OK. d3bbed27 test/data/hippopotamus.masked-with-muybridge.gif
|
||||
@@ -146,17 +146,19 @@ OK. 39d18fce test/data/mona-lisa.21x32.c3q4.handsum
|
||||
OK. f6bb81e2 test/data/mona-lisa.21x32.etc2.pkm
|
||||
OK. 012ce4cf test/data/mona-lisa.21x32.lossless.webp
|
||||
OK. 012ce4cf test/data/mona-lisa.21x32.png
|
||||
OK. 457ca659 test/data/mona-lisa.21x32.q0.lossy.webp
|
||||
OK. 4503912c test/data/mona-lisa.21x32.q25.lossy.webp
|
||||
OK. c2c97129 test/data/mona-lisa.21x32.q0.lossy.webp
|
||||
OK. c9d3bcd2 test/data/mona-lisa.21x32.q25.lossy.webp
|
||||
OK. 0a22e689 test/data/mona-lisa.21x32.q50.jpeg
|
||||
OK. 8ae1312b test/data/mona-lisa.21x32.q50.lossy.webp
|
||||
OK. 49f54fd4 test/data/mona-lisa.21x32.q50.lossy.webp
|
||||
OK. 059ecb80 test/data/mona-lisa.21x32.q90.jpeg
|
||||
OK. 567c8999 test/data/mona-lisa.21x32.q90.lossy.webp
|
||||
OK. 8396e4f6 test/data/mona-lisa.21x32.q90.lossy.webp
|
||||
OK. 012ce4cf test/data/mona-lisa.21x32.qoi
|
||||
OK. 12fc69a5 test/data/mona-lisa.21x32.th
|
||||
OK. 2dccfe56 test/data/muybridge-frame-000.wbmp
|
||||
OK. db2733f5 test/data/muybridge.apng
|
||||
OK. db2733f5 test/data/muybridge.gif
|
||||
OK. 773c8dda test/data/peacock.24x19.lossy.webp
|
||||
OK. ad130b74 test/data/peacock.24x19.png
|
||||
OK. d42a13cd test/data/peacock.default.jpeg
|
||||
OK. c8a50351 test/data/peacock.default.truncated.decoded-by-djpeg.png
|
||||
OK. 91b6bebb test/data/peacock.default.truncated.decoded-by-wuffs.png
|
||||
|
||||
Reference in new issue
Block a user