std/handsum: redo Handsum image file format

This commit is contained in:
Nigel Tao committed 2026-04-28 21:12:28 +10:00
1 parent 32b741db7f
commit f8c6b35ff5
25 files changed
+1795 -901

No files matched your search

+23 -28
View File
@@ -17,11 +17,9 @@ import (
"bytes"
"errors"
"flag"
"fmt"
"image"
"image/png"
"os"
"strings"
"github.com/google/wuffs/lib/handsum"
@@ -37,7 +35,9 @@ var (
decodeFlag = flag.Bool("decode", false, "whether to decode the input")
encodeFlag = flag.Bool("encode", false, "whether to encode the input")
roundtripFlag = flag.Bool("roundtrip", false, "whether to encode-and-decode the input")
variantFlag = flag.String("variant", "hvpc", "which variant to encode to: hvpc, hvpg, hvxc, hvxg")
cFlag = flag.String("c", "rgb", "encoding color: gray or rgb [default]")
qFlag = flag.Int("q", 3, "encoding quality: 0, 1, 2 or 3 [default]")
)
const usageStr = `handsum decodes and encodes the Handsum lossy image file format.
@@ -56,14 +56,10 @@ Decode inputs Handsum and outputs PNG.
Encode inputs BMP, GIF, JPEG, PNG, TIFF or WEBP and outputs Handsum.
Roundtrip is equivalent to encode (to an ephemeral file) and then decode.
For encode or roundtrip, you can also choose a quality and color variant
For encode or roundtrip, the default color and quality is -c=rgb -q=3 (best
quality; 147 bytes per file) but you can choose a lower setting. For example:
-variant=hvpc to use Handsum Variant Potato Color (the default)
-variant=hvpg to use Handsum Variant Potato Gray
-variant=hvxc to use Handsum Variant ExtremelyPotato Color
-variant=hvxg to use Handsum Variant ExtremelyPotato Gray
For example: handsum -encode -variant=hvpg foo.png > foo.hvpg.handsum
handsum -encode -c=gray -q=2 foo.png > foo.handsum
`
func main() {
@@ -77,19 +73,12 @@ func main1() error {
flag.Usage = func() { os.Stderr.WriteString(usageStr) }
flag.Parse()
variant := handsum.Variant(0)
switch strings.ToLower(*variantFlag) {
case "hvpc":
variant = handsum.VariantPotatoColor
case "hvpg":
variant = handsum.VariantPotatoGray
case "hvxc":
variant = handsum.VariantExtremelyPotatoColor
case "hvxg":
variant = handsum.VariantExtremelyPotatoGray
default:
return fmt.Errorf("bad -variant flag value %q", *variantFlag)
color := handsum.ColorRGB
switch *cFlag {
case "0", "GRAY", "Gray", "gray":
color = handsum.ColorGray
}
quality := handsum.Quality(max(0, min(3, *qFlag)))
inFile := os.Stdin
switch flag.NArg() {
@@ -110,10 +99,10 @@ func main1() error {
return decode(inFile)
}
if !*decodeFlag && *encodeFlag && !*roundtripFlag {
return encode(inFile, variant)
return encode(inFile, color, quality)
}
if !*decodeFlag && !*encodeFlag && *roundtripFlag {
return roundtrip(inFile, variant)
return roundtrip(inFile, color, quality)
}
return errors.New("must specify exactly one of -decode, -encode, -roundtrip or -help")
}
@@ -126,21 +115,27 @@ func decode(inFile *os.File) error {
return png.Encode(os.Stdout, src)
}
func encode(inFile *os.File, variant handsum.Variant) error {
func encode(inFile *os.File, color handsum.Color, quality handsum.Quality) error {
src, _, err := image.Decode(inFile)
if err != nil {
return err
}
return handsum.Encode(os.Stdout, src, &handsum.EncodeOptions{Variant: variant})
return handsum.Encode(os.Stdout, src, &handsum.EncodeOptions{
Color: handsum.MakeOptionColor(color),
Quality: handsum.MakeOptionQuality(quality),
})
}
func roundtrip(inFile *os.File, variant handsum.Variant) error {
func roundtrip(inFile *os.File, color handsum.Color, quality handsum.Quality) error {
src, _, err := image.Decode(inFile)
if err != nil {
return err
}
buf := &bytes.Buffer{}
err = handsum.Encode(buf, src, &handsum.EncodeOptions{Variant: variant})
err = handsum.Encode(buf, src, &handsum.EncodeOptions{
Color: handsum.MakeOptionColor(color),
Quality: handsum.MakeOptionQuality(quality),
})
if err != nil {
return err
}
+28 -28
View File
@@ -39,7 +39,7 @@ See example/convert-to-nia and example/imageviewer in the Wuffs repository for
examples of using its C and C++ APIs.
Coming back to this program, pass the -demo flag to decode six versions of the
same image of the Mona Lisa, in Thumbhash, Handsum (HVXC), Handsum (HVPC),
same image of the Mona Lisa, in Thumbhash, Handsum (q=0), Handsum (q=3),
PKM/ETC2, JPEG and PNG formats. Only the last one is lossless.
As of April 2026, the actual STB Image implementation only decodes two out of
@@ -230,30 +230,30 @@ const uint8_t g_src_ptr__mona_lisa_21_32_th[] = {
};
const size_t g_src_len__mona_lisa_21_32_th = 24;
const uint8_t g_src_ptr__mona_lisa_21_32_hvxc_handsum[] = {
0xfe, 0xd7, 0x74, 0x17, 0x6f, 0xef, 0x00, 0x08, 0xa9, 0xfb, 0x6a, 0xf0,
0x1d, 0xff, 0xf0, 0xa0, 0xcb, 0xe2, 0x04, 0x4f, 0xad, 0xfa, 0xfb, 0x0c,
0x2e, 0x26, 0xf9, 0x8a, 0x6f, 0xac, 0x9f, 0xbf, 0xc8, 0x67, 0x90, 0xc9,
0x7b, 0x89, 0x77, 0x88, 0x96, 0x6a, 0x75, 0x75, 0x87, 0x87, 0x88, 0xa9,
const uint8_t g_src_ptr__mona_lisa_21_32_r0_handsum[] = {
0xfe, 0xd7, 0x9a, 0x76, 0x8b, 0x9a, 0x76, 0x58, 0x88, 0x99, 0x68, 0xb6,
0x79, 0xaa, 0xa6, 0x86, 0x99, 0x97, 0x63, 0x7b, 0x89, 0x98, 0xb9, 0x59,
0x79, 0x28, 0xb8, 0x88, 0x8a, 0x89, 0x8a, 0x99, 0x98, 0x77, 0x94, 0x98,
0x79, 0x88, 0x88, 0x88, 0x97, 0x79, 0x87, 0x77, 0x88, 0x88, 0x88, 0x98,
};
const size_t g_src_len__mona_lisa_21_32_hvxc_handsum = 48;
const size_t g_src_len__mona_lisa_21_32_r0_handsum = 48;
const uint8_t g_src_ptr__mona_lisa_21_32_hvpc_handsum[] = {
0xfe, 0xd7, 0xf4, 0x87, 0x7a, 0xa8, 0x87, 0x7b, 0x87, 0xa7, 0x84, 0x59,
0x47, 0x95, 0x98, 0xa4, 0x56, 0x78, 0x54, 0x77, 0x2a, 0x94, 0x59, 0x87,
0x93, 0x88, 0xfd, 0x96, 0x76, 0xa8, 0x97, 0x7b, 0xb8, 0x14, 0x5b, 0x2f,
0xb8, 0x97, 0x87, 0x14, 0x25, 0x7c, 0xa5, 0x66, 0x58, 0x18, 0x3e, 0xb8,
0xc4, 0x66, 0xa8, 0xb5, 0x48, 0x64, 0xb3, 0x66, 0x0a, 0x73, 0x36, 0x98,
0x83, 0x2b, 0x87, 0x71, 0x27, 0x6a, 0xa6, 0x66, 0x76, 0x81, 0x18, 0x79,
0x82, 0x14, 0x58, 0x34, 0x30, 0x88, 0x92, 0x48, 0x6b, 0x81, 0x17, 0x78,
0x91, 0x38, 0x7a, 0x63, 0x2a, 0x97, 0x81, 0x27, 0x8a, 0x71, 0x07, 0x78,
0x90, 0x18, 0x79, 0x87, 0x68, 0x77, 0x87, 0x79, 0x88, 0x87, 0x77, 0x85,
0xb7, 0x76, 0x78, 0x87, 0x79, 0xa7, 0x98, 0x8a, 0x97, 0x78, 0x79, 0xc8,
0x98, 0x9a, 0x88, 0x88, 0x99, 0xaa, 0x78, 0x89, 0x98, 0x88, 0x99, 0x8a,
0x69, 0x89, 0x98, 0x89, 0x97, 0x78, 0x88, 0x97, 0x79, 0x98, 0x98, 0x68,
0x89, 0x87, 0x89,
const uint8_t g_src_ptr__mona_lisa_21_32_r3_handsum[] = {
0xfe, 0xd7, 0xfa, 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_hvpc_handsum = 147;
const size_t g_src_len__mona_lisa_21_32_r3_handsum = 147;
const uint8_t g_src_ptr__mona_lisa_21_32_etc2_pkm[] = {
0x50, 0x4b, 0x4d, 0x20, 0x32, 0x30, 0x00, 0x01, 0x00, 0x18, 0x00, 0x20,
@@ -1110,14 +1110,14 @@ main(int argc, char** argv) {
g_src_len__mona_lisa_21_32_th,
},
{
"«demo»/mona-lisa.21x32.hvxc.handsum",
g_src_ptr__mona_lisa_21_32_hvxc_handsum,
g_src_len__mona_lisa_21_32_hvxc_handsum,
"«demo»/mona-lisa.21x32.r0.handsum",
g_src_ptr__mona_lisa_21_32_r0_handsum,
g_src_len__mona_lisa_21_32_r0_handsum,
},
{
"«demo»/mona-lisa.21x32.hvpc.handsum",
g_src_ptr__mona_lisa_21_32_hvpc_handsum,
g_src_len__mona_lisa_21_32_hvpc_handsum,
"«demo»/mona-lisa.21x32.r3.handsum",
g_src_ptr__mona_lisa_21_32_r3_handsum,
g_src_len__mona_lisa_21_32_r3_handsum,
},
{
"«demo»/mona-lisa.21x32.etc2.pkm",
+619 -282
View File
@@ -13,49 +13,57 @@
// Package handsum implements the Handsum image file format.
//
// This is a very lossy format for very small thumbnails. Very small in terms
// of image dimensions, up to 32×32 pixels, but also in terms of file size.
// of image dimensions, up to 16×16 pixels, but also in terms of file size.
//
// The file format has four variants, combining two quality settings (P is
// Potato, X is Extremely Potato) and two color settings (C is Color, G is
// Gray). Each Handsum Variant (named HV??) is a fixed number of bytes:
// The file format has two color settings (Gray and RGB) and four quality
// settings. For any given color-and-quality combination, every Handsum image
// file with those settings is a fixed number of bytes. For color=Gray:
//
// - The HVPC variant is 147 bytes long.
// - The HVPG variant is 99 bytes long.
// - The HVXC variant is 48 bytes long.
// - The HVXG variant is 33 bytes long.
// - A quality=0 file is 33 bytes long.
// - A quality=1 file is 51 bytes long.
// - A quality=2 file is 83 bytes long.
// - A quality=3 file is 99 bytes long.
//
// For example, every HVXC image file is exactly 48 bytes (384 bits) long. For
// a 32×32 pixel image, this uses 0.375 bits (0.046875 bytes) per pixel.
// For color=RGB:
//
// HVPC (P for Potato, not X for Extremely Potato), always 147 bytes, uses
// 1.1484375 bits per pixel for a 32×32 pixel image (a 1:1 aspect ratio), or
// 1.53125 bits per pixel for a 32×24 pixel image (a 4:3 aspect ratio).
// - A quality=0 file is 48 bytes long.
// - A quality=1 file is 75 bytes long.
// - A quality=2 file is 123 bytes long.
// - A quality=3 file is 147 bytes long.
//
// Every Gray/q0 image file is exactly 48 bytes (384 bits) long. For a 16×16
// pixel image, this uses 1.5 bits (0.1875 bytes) per pixel.
//
// Every RGB/q3 image file is exactly 147 bytes (1176 bits) long. This uses
// 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 16-bit magic signature, a
// 2-bit variant and a 6-bit aspect ratio. An image's longest dimension (width
// or height) is 32 pixels and the aspect ratio gives the shorter dimension.
// 1-bit color, 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 C (Color) payload, after the header, holds a scaled 16×16 pixel YCbCr
// The color=RGB payload, after the header, holds a scaled 16×16 pixel YCbCr
// 4:2:0 JPEG MCU (Minimum Coded Unit), 4 Luma and 2 Chroma blocks. Each block
// is 8×8 pixels.
//
// The G (Gray) payload is just the C payload with the 4 Luma blocks but
// without the 2 Chroma blocks. This drops the final 48 (for P, Potato) or 15
// (for X, Extremely Potato) bytes from the C variant's encoding.
// The color=RGB payload ends with 2 Chroma blocks in 15, 24, 40 or 48 bytes
// (depending on the quality setting). For a grayscale image, the encoded
// Chroma blocks' bytes are all 0x88, and the color=Gray payload is just the 4
// Luma blocks without explicitly recording the 2 Chroma blocks.
//
// P (Potato) splits the MCU into 8×8 pixel blocks and further splits each
// block into 2×2 pixel mini-blocks. DCT (Discrete Cosine Transform) is applied
// to each mini-block, producing 4 DCT coefficients. Only the 3 lowest
// frequency DCT coefficients are kept.
// Each 8×8 block is sub-divided into 8×8 (for q0), 4×4 (for q1 and q2) or 2×2
// (for q3) tiles. DCT (Discrete Cosine Transform) is applied to each tile,
// producing 64, 16, 16 or 4 DCT coefficients (depending on the quality). Only
// the 15 (out of 64), 6 (out of 16), 10 (out of 16) or 3 (out of 4) lowest
// frequency DCT coefficients are kept for each tile. Lowest frequency means
// the top-left corner in the usual visualization of JPEG's zig-zag ordering.
//
// X (Extremely Potato) splits the MCU into 8×8 pixel blocks. DCT is applied to
// each block, producing 64 DCT coefficients, just like JPEG. Only the 15
// lowest frequency DCT coefficients are kept. Lowest frequency means the
// top-left corner in the usual visualization of JPEG's zig-zag ordering.
// In percentage terms, the quality setting keeps 23%, 38%, 63% or 75% of the
// 64 DCT coefficients in each 8×8 block.
//
// Either way, P or X, each DCT coefficient is encoded as one nibble (4 bits;
// half a byte) with fixed bias and quantization factors. Each 8×8 pixel block
// encodes in 48 (P) or 15 (X) nibbles.
// Each DCT coefficient is encoded as one nibble (4 bits) with fixed bias and
// quantization factors.
//
// All Handsum images use the sRGB color profile.
//
@@ -65,66 +73,68 @@
// Thumbhash. "Handsum" also sounds like "handsome", meaning "good looking".
package handsum
// When decoding, each nibble produces a DCT coefficient according to a simple
// linear formula, with different parameters (the linear slope and intercept)
// depending on DC vs AC coefficients and on the quality setting (whether the
// tiles are 8×8, 4×4 or 2×2):
//
// ====== ======== DC ======== ======== AC ========
// Bucket q0 q1,q2 q3 q0 q1,q2 q3
//
// 0x0 -1024 -512 -256 -512 -256 -128
// 0x1 -888 -444 -222 -448 -224 -112
// 0x2 -752 -376 -188 -384 -192 -96
// 0x3 -616 -308 -154 -320 -160 -80
// ... ... ... ... ... ... ...
// 0x7 -72 -36 -18 -64 -32 -16
// 0x8 +64 +32 +16 0 0 0
// 0x9 +200 +100 +50 +64 +32 +16
// ... ... ... ... ... ... ...
// 0xE +880 +440 +220 +384 +192 +96
// 0xF +1016 +508 +254 +448 +224 +112
//
// Width 0x88 0x44 0x22 0x40 0x20 0x10
// TileSize 8 4 2 8 4 2
// ====== ======== DC ======== ======== AC ========
//
// DC bucket widths are multiples of 0x11, not 0x10 with bucket=0x8 mapping to
// zero, so that an input tile that is pure black (luma=0x00) or pure white
// (luma=0xFF) can round-trip losslessly (as bucket 0x0 or bucket 0xF). AC maps
// bucket=0x8 to zero, so that a uniformly-valued tile (all-0x00, all-0x11,
// all-0x22, ..., all-0xFF) can again round-trip losslessly.
//
// This encoder uses smaller bucket widths for the AC coefficients, compared to
// those used when decoding (42, 18, 8 instead of 64, 32, 16). This adjustment
// is arbitrary but the results seem a little more vibrant. It also compensates
// somewhat for the mean-reversion (gray-reversion) from the decoder's seam
// smoothing, a localized blur that mitigates artifacts at tile boundaries.
//
// Luma values can span the full range [0x00, 0xFF] but decoded Chroma values
// are restricted to a narrower range [0x3C, 0xBB], as extreme Chroma values
// are rare in practice. The latter range has a slight bias (not centred on the
// neutral 0x80) so that the Chroma DC components of a neutral gray image can
// round-trip losslessly (in the 0x8 bucket). Chroma is narrowed (after Inverse
// DCT) on decode and so is widened (before Forward DCT) on encode. Luma and
// wide-Chroma then use the same DCT buckets.
import (
"errors"
"image"
"image/color"
"io"
"github.com/google/wuffs/lib/lowleveldct4x4"
"github.com/google/wuffs/lib/lowleveljpeg"
"golang.org/x/image/draw"
)
// Variant represents one of the Handsum file format's four variants.
//
// The zero value means unknown (before decoding) or to use the default option
// (when encoding).
type Variant uint8
const (
VariantExtremelyPotatoGray = Variant(1)
VariantExtremelyPotatoColor = Variant(2)
VariantPotatoGray = Variant(3)
VariantPotatoColor = Variant(4)
)
func (v Variant) isExtremelyPotato() bool { return v <= VariantExtremelyPotatoColor }
func (v Variant) isGray() bool { return (v & 1) != 0 }
func (v Variant) numberOfBlocks() int { return 6 - (2 * int(v&1)) }
func (v Variant) fileSize() int {
switch v {
case VariantExtremelyPotatoGray:
return FileSizeHVXG
case VariantExtremelyPotatoColor:
return FileSizeHVXC
case VariantPotatoGray:
return FileSizeHVPG
}
return FileSizeHVPC
}
const (
// FileSizeHVXG is the size (in bytes) of every HVXG Handsum image file.
FileSizeHVXG = 33
// FileSizeHVXC is the size (in bytes) of every HVXC Handsum image file.
FileSizeHVXC = 48
// FileSizeHVPG is the size (in bytes) of every HVPG Handsum image file.
FileSizeHVPG = 99
// FileSizeHVPC is the size (in bytes) of every HVPC Handsum image file.
FileSizeHVPC = 147
fileSizeHeader = 3
fileSizeMax = 147
)
// MaxDimension is the maximum (inclusive) width or height of every Handsum
// image file.
//
// Every image is either (W × 32) or (32 × H) or both, for some positive W or H
// that is no greater than 32.
const MaxDimension = 32
// Every image is either (W × 16) or (16 × H) or both, for some positive W or H
// that is no greater than 16.
const MaxDimension = 16
// Magic is the byte string prefix of every Handsum image file.
//
@@ -140,19 +150,89 @@ var (
ErrNotAHandsumFile = errors.New("handsum: not a handsum file")
)
// EncodeOptions are optional arguments to Encode. The zero value is valid and
// means to use the default configuration.
type EncodeOptions struct {
// Variant is which of the four Handsum Variants to use. If zero, the
// default is HVPC (Handsum Variant Potato Color).
Variant Variant
const (
fileSizeHeader = 3
fileSizeMax = 147
)
func fileSize(c Color, q Quality) int {
// 33, 51, 83, 99. 48, 75, 123, 147.
return int("\x21\x33\x53\x63\x30\x4B\x7B\x93"[(int(c&1)<<2)|int(q&3)])
}
func (o *EncodeOptions) variant() Variant {
if (o != nil) && (1 <= o.Variant) && (o.Variant <= 4) {
return o.Variant
// Color is a Handsum image's color setting, either 0 (Gray) or 1 (RGB).
type Color uint8
const (
ColorGray = Color(0)
ColorRGB = Color(1)
)
func (c Color) numberOfBlocks() int {
return int("\x04\x06"[c&1])
}
// OptionColor is an option type, what Rust would call an Option<Color>.
type OptionColor struct {
representation uint8
}
// MakeOptionColor returns an option value that is Some(c), instead of the
// OptionColor zero-value, which is None.
func MakeOptionColor(c Color) OptionColor {
return OptionColor{representation: 0x80 | uint8(c)}
}
// Quality is a Handsum image's quality setting, from 0 (worst) to 3 (best).
type Quality uint8
const (
QualityWorst = Quality(0)
QualityMediumLow = Quality(1)
QualityMediumHigh = Quality(2)
QualityBest = Quality(3)
)
func (q Quality) numberOfCoefficients() int {
// 15 (out of 64), 6 (out of 16), 10 (out of 16), 3 (out of 4).
return int("\x0F\x06\x0A\x03"[q&3])
}
// OptionQuality is an option type, what Rust would call an Option<Quality>.
type OptionQuality struct {
representation uint8
}
// MakeOptionQuality returns an option value that is Some(q), instead of the
// OptionQuality zero-value, which is None.
func MakeOptionQuality(q Quality) OptionQuality {
return OptionQuality{representation: 0x80 | uint8(q)}
}
// EncodeOptions are optional arguments to Encode. The zero value is valid and
// means to use the default configuration, encoding to 147 bytes.
type EncodeOptions struct {
// Color is the color setting. The None option (the zero OptionColor value)
// means to use the default, ColorRGB.
Color OptionColor
// Quality is the quality-versus-file-size setting. The None option (the
// zero OptionQuality value) means to use the default, QualityBest.
Quality OptionQuality
}
func (o *EncodeOptions) color() Color {
if (o != nil) && ((o.Color.representation & 0x80) != 0) {
return Color(o.Color.representation & 0x01)
}
return VariantPotatoColor
return ColorRGB
}
func (o *EncodeOptions) quality() Quality {
if (o != nil) && ((o.Quality.representation & 0x80) != 0) {
return Quality(o.Quality.representation & 0x03)
}
return QualityBest
}
// Encode writes src to w in the Handsum format.
@@ -168,19 +248,19 @@ func Encode(w io.Writer, src image.Image, options *EncodeOptions) error {
return ErrBadArgument
}
aspectRatio := byte(0x1F)
aspectRatio := byte(0x0F)
if srcW > srcH { // Landscape.
a := ((int64(srcH) * 64) + int64(srcW)) / (2 * int64(srcW))
a := ((int64(srcH) * 32) + int64(srcW)) / (2 * int64(srcW))
if a <= 0 {
a = 1
}
aspectRatio = byte(a-1) | 0x00
} else if srcW < srcH { // Portrait.
a := ((int64(srcW) * 64) + int64(srcH)) / (2 * int64(srcH))
a := ((int64(srcW) * 32) + int64(srcH)) / (2 * int64(srcH))
if a <= 0 {
a = 1
}
aspectRatio = byte(a-1) | 0x20
aspectRatio = byte(a-1) | 0x10
}
dst := image.NewRGBA(image.Rectangle{Max: image.Point{X: 16, Y: 16}})
@@ -189,145 +269,113 @@ func Encode(w io.Writer, src image.Image, options *EncodeOptions) error {
dstU8s := lowleveljpeg.Array6BlockU8{}
dstU8s.ExtractFrom(dst, 0, 0)
v := options.variant()
// Biasing the Chroma blocks by +8 shifts the neutral (gray) Chroma values
// from 0x80 to 0x88. DC coefficient bias-and-quantization can losslessly
// encode a block whose elements are a uniform multiple of 0x11.
scaleAndBiasChromaUp(&dstU8s[4])
scaleAndBiasChromaUp(&dstU8s[5])
c := options.color()
q := options.quality()
buf := [fileSizeMax]byte{}
buf[0] = Magic[0]
buf[1] = Magic[1]
buf[2] = aspectRatio | ((uint8(v) - 1) << 6)
buf[2] = ((uint8(c)) << 7) | ((uint8(q)) << 5) | aspectRatio
bitOffset := 3 * 8
if v.isExtremelyPotato() {
dstI16s := lowleveljpeg.Array6BlockI16{}
dstI16s.ForwardDCTFrom(&dstU8s)
for i := range v.numberOfBlocks() {
bitOffset = encodeXBlock(&buf, bitOffset, &dstI16s[i])
}
} else {
// Biasing the Chroma blocks by +8 shifts the neutral (gray) Chroma
// values from 0x80 to 0x88. encodePBlock's DC coefficient quantization
// can encode multiples of 0x11 losslessly.
biasUp(&dstU8s[4])
biasUp(&dstU8s[5])
for i := range v.numberOfBlocks() {
bitOffset = encodePBlock(&buf, bitOffset, &dstU8s[i])
}
encodeBlock := encodeBlockFuncs[q]
for i := range c.numberOfBlocks() {
bitOffset = encodeBlock(&buf, bitOffset, &dstU8s[i], q.numberOfCoefficients())
}
_, err := w.Write(buf[:bitOffset/8])
return err
}
func encodePBlock(buf *[fileSizeMax]byte, bitOffset int, b *lowleveljpeg.BlockU8) int {
type encodeBlockFunc func(buf *[fileSizeMax]byte, bitOffset int, src *lowleveljpeg.BlockU8, nCoeffs int) int
var encodeBlockFuncs = [4]encodeBlockFunc{
encodeBlockQ0,
encodeBlockQ1,
encodeBlockQ1,
encodeBlockQ3,
}
func encodeBlockQ0(buf *[fileSizeMax]byte, bitOffset int, src *lowleveljpeg.BlockU8, nCoeffs int) int {
f8 := src.ForwardDCT()
for _, z := range zigzag8 {
v := int32(f8[z])
if z == 0 {
v = (v + 1024 + 0x44) / 0x88
} else {
v = (v + (8.5 * 42)) / 42
}
buf[bitOffset>>3] |= nibblify(v) << (bitOffset & 4)
bitOffset += 4
}
return bitOffset
}
func encodeBlockQ1(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.
o4 := (8 * y4) + x4 // The sequence 0, 4, 32, 36.
b4 := extract4x4Tile(src, o4)
f4 := b4.ForwardDCT()
for _, z := range zigzag4[:nCoeffs] {
v := int32(f4[z])
if z == 0 {
v = (v + 512 + 0x22) / 0x44
} else {
v = (v + (8.5 * 18)) / 18
}
buf[bitOffset>>3] |= nibblify(v) << (bitOffset & 4)
bitOffset += 4
}
}
return bitOffset
}
func encodeBlockQ3(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.
for i := range 16 {
x := 2 * (i & 3)
y := 2 * (i >> 2)
j := (8 * y) + x
b00 := int(b[j+0o00])
b01 := int(b[j+0o01])
b10 := int(b[j+0o10])
b11 := int(b[j+0o11])
s0 := int32(src[j+0]) - 0x80
s1 := int32(src[j+1]) - 0x80
s2 := int32(src[j+8]) - 0x80
s3 := int32(src[j+9]) - 0x80
// Compute the quantized DC coefficient.
//
// "(p + q + r + s + 2) >> 2" takes the average of four numbers,
// rounding properly. Shifting by (2 + 4) instead of by 2 quantizes the
// range [0x00, 0xFF] to [0x0, 0xF].
avgw := (+b00 + b01 + b10 + b11 + 2) >> 6
dct0 := (+s0 + s1 + s2 + s3 + 1) >> 1
dct1 := (+s0 - s1 + s2 - s3 + 1) >> 1
dct2 := (+s0 + s1 - s2 - s3 + 1) >> 1
// Compute the quantized AC coefficients: one horizontal and one
// vertical. These two lines are equivalent to:
//
// avgx := (((-b00 + b01 - b10 + b11 + 2) >> 2) + 2) >> 2
// avgy := (((-b00 - b01 + b10 + b11 + 2) >> 2) + 2) >> 2
//
// The inner "(foo + 2) >> 2" calculation is like taking an average.
//
// In theory, the outer calculation should be "(foo + 4) >> 3" instead
// of "(foo + 2) >> 2", since on the decode side, we multiply by 8.
// Scaling by 2 is an arbitrary adjustment that's not mirrored on the
// decode side, but the results seem a little more vibrant.
avgx := (-b00 + b01 - b10 + b11 + 10) >> 4
avgy := (-b00 - b01 + b10 + b11 + 10) >> 4
// Clip DC to [0, 15] and AC to [-8, +7]. Pack it in a nibble.
ew := max(0, min(15, avgw+0))
ex := max(0, min(15, avgx+8))
ey := max(0, min(15, avgy+8))
buf[bitOffset>>3] |= uint8(ew) << (bitOffset & 4)
v0 := (dct0 + 256 + 0x11) / 0x22
buf[bitOffset>>3] |= nibblify(v0) << (bitOffset & 4)
bitOffset += 4
buf[bitOffset>>3] |= uint8(ex) << (bitOffset & 4)
bitOffset += 4
buf[bitOffset>>3] |= uint8(ey) << (bitOffset & 4)
bitOffset += 4
}
return bitOffset
}
func encodeXBlock(buf *[fileSizeMax]byte, bitOffset int, b *lowleveljpeg.BlockI16) int {
for i := range nCoeffs {
e := uint8(0)
if i == 0 {
e = encodeXDC(b[0])
} else {
e = encodeXAC(b[zigzag[i]])
}
buf[bitOffset>>3] |= e << (bitOffset & 4)
v1 := (dct1 + (8.5 * 8)) / 8
buf[bitOffset>>3] |= nibblify(v1) << (bitOffset & 4)
bitOffset += 4
v2 := (dct2 + (8.5 * 8)) / 8
buf[bitOffset>>3] |= nibblify(v2) << (bitOffset & 4)
bitOffset += 4
}
return bitOffset
}
func encodeXDC(value int16) uint8 {
const w = dcBucketWidth
v := int32(value) + ((w * 8) + (w / 2))
v /= w
if v < 0x0 {
return 0x0
} else if v > 0xF {
return 0xF
}
return uint8(v)
}
func encodeXAC(value int16) uint8 {
// Scaling by 2 is an arbitrary adjustment that's not mirrored on the
// decode side, but the results seem a little more vibrant.
const w = acBucketWidth / 2
v := int32(value) + ((w * 8) + (w / 2))
v /= w
if v < 0x0 {
return 0x0
} else if v > 0xF {
return 0xF
}
return uint8(v)
}
// For X (Extremely Potato), both DC and AC coefficients are quantized into 16
// buckets (4 bits), but they use different bucket widths:
//
// Bucket DC AC
// 0x0 -1024 -128
// 0x1 -896 -112
// 0x2 -768 -96
// 0x3 -640 -80
// ... ... ...
// 0x7 -128 -16
// 0x8 0 0
// 0x9 +128 +16
// ... ... ...
// 0xE +768 +96
// 0xF +896 +112
const (
dcBucketWidth = 128
acBucketWidth = 16
)
// DecodeConfig reads a Handsum image configuration from r.
func DecodeConfig(r io.Reader) (image.Config, error) {
buf := [fileSizeHeader]byte{}
@@ -336,9 +384,10 @@ func DecodeConfig(r io.Reader) (image.Config, error) {
} else if (buf[0] != Magic[0]) || (buf[1] != Magic[1]) {
return image.Config{}, ErrNotAHandsumFile
}
cm := color.RGBAModel
if v := Variant(buf[2]>>6) + 1; v.isGray() {
cm = color.GrayModel
cm := color.GrayModel
if (buf[2] & 0x80) != 0 {
cm = color.RGBAModel
}
w, h := decodeWidthAndHeight(buf[2])
@@ -357,25 +406,23 @@ func Decode(r io.Reader) (image.Image, error) {
} else if (buf[0] != Magic[0]) || (buf[1] != Magic[1]) {
return nil, ErrNotAHandsumFile
}
v := Variant(buf[2]>>6) + 1
if _, err := io.ReadFull(r, buf[fileSizeHeader:v.fileSize()]); err != nil {
c := Color(buf[2] >> 7)
q := Quality((buf[2] >> 5) & 0x03)
if _, err := io.ReadFull(r, buf[fileSizeHeader:fileSize(c, q)]); err != nil {
return nil, err
}
bitOffset := 3 * 8
decodeBlock := decodePBlock
if v.isExtremelyPotato() {
decodeBlock = decodeXBlock
}
decodeBlock := decodeBlockFuncs[q]
lumaQuadBlockU8 := lowleveljpeg.QuadBlockU8{}
bitOffset = decodeBlock(lumaQuadBlockU8[0x00:], 16, &buf, bitOffset)
bitOffset = decodeBlock(lumaQuadBlockU8[0x08:], 16, &buf, bitOffset)
bitOffset = decodeBlock(lumaQuadBlockU8[0x80:], 16, &buf, bitOffset)
bitOffset = decodeBlock(lumaQuadBlockU8[0x88:], 16, &buf, bitOffset)
smoothLumaBlockSeams(&lumaQuadBlockU8)
bitOffset = decodeBlock(lumaQuadBlockU8[0x00:], 16, &buf, bitOffset, q.numberOfCoefficients())
bitOffset = decodeBlock(lumaQuadBlockU8[0x08:], 16, &buf, bitOffset, q.numberOfCoefficients())
bitOffset = decodeBlock(lumaQuadBlockU8[0x80:], 16, &buf, bitOffset, q.numberOfCoefficients())
bitOffset = decodeBlock(lumaQuadBlockU8[0x88:], 16, &buf, bitOffset, q.numberOfCoefficients())
smoothBlockSeams16x16(&lumaQuadBlockU8)
src := image.Image(nil)
if v.isGray() {
if c == 0 {
src = &image.Gray{
Pix: lumaQuadBlockU8[:],
Stride: 16,
@@ -386,12 +433,10 @@ func Decode(r io.Reader) (image.Image, error) {
cbBlockU8 := lowleveljpeg.BlockU8{}
crBlockU8 := lowleveljpeg.BlockU8{}
bitOffset = decodeBlock(cbBlockU8[:], 8, &buf, bitOffset)
bitOffset = decodeBlock(crBlockU8[:], 8, &buf, bitOffset)
if v == VariantPotatoColor {
biasDown(&cbBlockU8)
biasDown(&crBlockU8)
}
bitOffset = decodeBlock(cbBlockU8[:], 8, &buf, bitOffset, q.numberOfCoefficients())
bitOffset = decodeBlock(crBlockU8[:], 8, &buf, bitOffset, q.numberOfCoefficients())
scaleAndBiasChromaDown(&cbBlockU8)
scaleAndBiasChromaDown(&crBlockU8)
cbQuadBlockU8 := lowleveljpeg.QuadBlockU8{}
cbQuadBlockU8.UpsampleFrom(&cbBlockU8)
@@ -416,55 +461,35 @@ func Decode(r io.Reader) (image.Image, error) {
}
func decodeWidthAndHeight(buf2 byte) (w int, h int) {
if (buf2 & 0x20) == 0 { // Landscape.
w = 32
h = 1 + int(buf2&0x1F)
if (buf2 & 0x10) == 0 { // Landscape.
w = 16
h = 1 + int(buf2&0x0F)
} else { // Portrait.
w = 1 + int(buf2&0x1F)
h = 32
w = 1 + int(buf2&0x0F)
h = 16
}
return w, h
}
func decodePBlock(dst []byte, stride int, src *[fileSizeMax]byte, bitOffset int) int {
for i := range 16 {
// Decode the quantized-by-0x11 DC coefficient, covering [0x00, 0xFF].
ew := int((src[bitOffset>>3] >> (bitOffset & 4)) & 15)
bitOffset += 4
type decodeBlockFunc func(dst []byte, stride int, buf *[fileSizeMax]byte, bitOffset int, nCoeffs int) int
// Decode the quantized-by-8 AC coefficients, covering [-64, +56]. The
// -8 here, which applies to both Luma and Chroma blocks, is not the
// Chroma-only bias handled by biasUp and biasDown.
ex := int((src[bitOffset>>3]>>(bitOffset&4))&15) - 8
bitOffset += 4
ey := int((src[bitOffset>>3]>>(bitOffset&4))&15) - 8
bitOffset += 4
x := 2 * (i & 3)
y := 2 * (i >> 2)
j0 := ((y + 0) * stride) + x
j1 := ((y + 1) * stride) + x
dst[j0+0] = uint8(max(0x00, min(0xFF, (ew*0x11)+((-ey-ex)*8))))
dst[j0+1] = uint8(max(0x00, min(0xFF, (ew*0x11)+((-ey+ex)*8))))
dst[j1+0] = uint8(max(0x00, min(0xFF, (ew*0x11)+((+ey-ex)*8))))
dst[j1+1] = uint8(max(0x00, min(0xFF, (ew*0x11)+((+ey+ex)*8))))
}
return bitOffset
var decodeBlockFuncs = [4]decodeBlockFunc{
decodeBlockQ0,
decodeBlockQ1,
decodeBlockQ1,
decodeBlockQ3,
}
func decodeXBlock(dst []byte, stride int, src *[fileSizeMax]byte, bitOffset int) int {
func decodeBlockQ0(dst []byte, stride int, buf *[fileSizeMax]byte, bitOffset int, nCoeffs int) int {
a := lowleveljpeg.BlockI16{}
{
nibble := (src[bitOffset>>3] >> (bitOffset & 4)) & 15
a[0] = (int16(nibble) - 8) * dcBucketWidth
bitOffset += 4
}
for i := 1; i < nCoeffs; i++ {
nibble := (src[bitOffset>>3] >> (bitOffset & 4)) & 15
a[zigzag[i]] = (int16(nibble) - 8) * acBucketWidth
for _, z := range zigzag8 {
nibble := (buf[bitOffset>>3] >> (bitOffset & 4)) & 15
if z == 0 {
a[z] = int16((int32(nibble) * 0x88) - 1024)
} else {
a[z] = int16((int32(nibble) * 0x40) - 512)
}
bitOffset += 4
}
@@ -480,32 +505,129 @@ func decodeXBlock(dst []byte, stride int, src *[fileSizeMax]byte, bitOffset int)
return bitOffset
}
const nCoeffs = 15
func decodeBlockQ1(dst []byte, stride int, buf *[fileSizeMax]byte, bitOffset int, nCoeffs int) int {
tmp := lowleveljpeg.BlockU8{}
// zigzag represents JPEG's zig-zag order for visiting DCT coefficients. X
// (Extremely Potato) only uses the first (1 + 2 + 3 + 4 + 5) = 15 of JPEG's 64
// DCT coefficients.
for i := range 4 {
a := lowleveldct4x4.BlockI16{}
for _, z := range zigzag4[:nCoeffs] {
nibble := (buf[bitOffset>>3] >> (bitOffset & 4)) & 15
if z == 0 {
a[z] = int16((int32(nibble) * 0x44) - 512)
} else {
a[z] = int16((int32(nibble) * 0x20) - 256)
}
bitOffset += 4
}
b := lowleveldct4x4.BlockU8{}
b.InverseDCTFrom(&a)
x4 := (i & 1) << 2 // The sequence 0, 4, 0, 4.
y4 := (i & 2) << 1 // The sequence 0, 0, 4, 4.
for i := range 4 {
ti := ((i + y4) * 8) + x4
bi := i * 4
copy(tmp[ti:ti+4], b[bi:bi+4])
}
}
smoothBlockSeams8x8Q1(&tmp)
for i := range 8 {
di := i * stride
ti := i * 8
copy(dst[di:di+8], tmp[ti:ti+8])
}
return bitOffset
}
func decodeBlockQ3(dst []byte, stride int, buf *[fileSizeMax]byte, bitOffset int, nCoeffs int) int {
tmp := lowleveljpeg.BlockU8{}
for i := range 16 {
nibble0 := (buf[bitOffset>>3] >> (bitOffset & 4)) & 15
dct0 := (int32(nibble0) * 0x22) - 256
bitOffset += 4
nibble1 := (buf[bitOffset>>3] >> (bitOffset & 4)) & 15
dct1 := (int32(nibble1) * 0x10) - 128
bitOffset += 4
nibble2 := (buf[bitOffset>>3] >> (bitOffset & 4)) & 15
dct2 := (int32(nibble2) * 0x10) - 128
bitOffset += 4
x2 := 2 * (i & 3) // The sequence 0, 2, 4, 6, 0, 2, 4, ..., 6.
y2 := 2 * (i >> 2) // The sequence 0, 0, 0, 0, 2, 2, 2, ..., 6.
o2 := (y2 * 8) + x2 // The sequence 0, 2, 4, 6, 16, 18, 20, ..., 54.
tmp[o2+0] = biasAndClamp[((+dct0+dct1+dct2+1)>>1)&1023]
tmp[o2+1] = biasAndClamp[((+dct0-dct1+dct2+1)>>1)&1023]
tmp[o2+8] = biasAndClamp[((+dct0+dct1-dct2+1)>>1)&1023]
tmp[o2+9] = biasAndClamp[((+dct0-dct1-dct2+1)>>1)&1023]
}
smoothBlockSeams8x8Q3(&tmp)
for i := range 8 {
di := i * stride
ti := i * 8
copy(dst[di:di+8], tmp[ti:ti+8])
}
return bitOffset
}
// zigzag8 represents JPEG's zig-zag order for visiting DCT coefficients.
// QualityWorst only uses the first (1 + 2 + 3 + 4 + 5) = 15 of JPEG's 64 DCT
// coefficients.
//
// https://en.wikipedia.org/wiki/File:JPEG_ZigZag.svg
var zigzag = [nCoeffs]uint8{
var zigzag8 = [15]uint8{
0o00, 0o01, 0o10, 0o20, 0o11, 0o02, 0o03, 0o12, // 0, 1, 8, 16, 9, 2, 3, 10,
0o21, 0o30, 0o40, 0o31, 0o22, 0o13, 0o04, // 17, 24, 32, 25, 18, 11, 4,
}
func biasUp(b *lowleveljpeg.BlockU8) {
for i, v := range b {
b[i] = uint8(min(0xFF, int(v)+8))
// zigzag4 is like zigzag8 but using the first (1 + 2 + 3) = 6 or (1 + 2 + 3 +
// 4) = 10 (instead of 15) DCT coefficients of a 4×4 (instead of 8×8) block.
var zigzag4 = [10]uint8{
0o00, 0o01, 0o04, 0o10, 0o05, 0o02, 0o03, 0o06, // 0, 1, 4, 8, 5, 2, 3, 6,
0o11, 0o14, // 9, 12,
}
// nibblify clamps v to the range [0x0, 0xF].
func nibblify(v int32) uint8 {
return uint8(max(0x0, min(0xF, v)))
}
// extract4x4Tile extracts a 4×4 tile out of an 8×8 block.
func extract4x4Tile(b8 *lowleveljpeg.BlockU8, offset int) lowleveldct4x4.BlockU8 {
return lowleveldct4x4.BlockU8{
b8[offset+0x00],
b8[offset+0x01],
b8[offset+0x02],
b8[offset+0x03],
b8[offset+0x08],
b8[offset+0x09],
b8[offset+0x0A],
b8[offset+0x0B],
b8[offset+0x10],
b8[offset+0x11],
b8[offset+0x12],
b8[offset+0x13],
b8[offset+0x18],
b8[offset+0x19],
b8[offset+0x1A],
b8[offset+0x1B],
}
}
func biasDown(b *lowleveljpeg.BlockU8) {
for i, v := range b {
b[i] = uint8(max(0x00, int(v)-8))
}
}
func smoothLumaBlockSeams(b *lowleveljpeg.QuadBlockU8) {
for _, pair := range smoothingPairs {
func smoothBlockSeams16x16(b *lowleveljpeg.QuadBlockU8) {
for _, pair := range smoothingPairs16x16 {
v0 := uint32(b[pair[0]])
v1 := uint32(b[pair[1]])
b[pair[0]] = uint8(((3 * v0) + v1 + 2) / 4)
@@ -523,9 +645,76 @@ func smoothLumaBlockSeams(b *lowleveljpeg.QuadBlockU8) {
b[0x87] = uint8(((9 * v87) + (3 * v77) + v78 + (3 * v88) + 8) / 16)
}
// smoothingPairs are the seams of the four 8×8 Luma blocks in a 16×16 MCU. The
// central 4 pixels are handled separately.
var smoothingPairs = [28][2]uint8{
func smoothBlockSeams8x8Q1(b *lowleveljpeg.BlockU8) {
for _, pair := range smoothingPairs8x8 {
v0 := uint32(b[pair[0]])
v1 := uint32(b[pair[1]])
b[pair[0]] = uint8(((3 * v0) + v1 + 2) / 4)
b[pair[1]] = uint8(((3 * v1) + v0 + 2) / 4)
}
v33 := uint32(b[0o33])
v34 := uint32(b[0o34])
v44 := uint32(b[0o44])
v43 := uint32(b[0o43])
b[0o33] = uint8(((9 * v33) + (3 * v34) + v44 + (3 * v43) + 8) / 16)
b[0o34] = uint8(((9 * v34) + (3 * v44) + v43 + (3 * v33) + 8) / 16)
b[0o44] = uint8(((9 * v44) + (3 * v43) + v33 + (3 * v34) + 8) / 16)
b[0o43] = uint8(((9 * v43) + (3 * v33) + v34 + (3 * v44) + 8) / 16)
}
func smoothBlockSeams8x8Q3(b *lowleveljpeg.BlockU8) {
for y := 1; y < 7; y += 2 {
for x := 1; x < 7; x += 2 {
o := (y * 8) + x
v0 := uint32(b[o+0])
v1 := uint32(b[o+1])
v9 := uint32(b[o+9])
v8 := uint32(b[o+8])
b[o+0] = uint8(((9 * v0) + (3 * v1) + v9 + (3 * v8) + 8) / 16)
b[o+1] = uint8(((9 * v1) + (3 * v9) + v8 + (3 * v0) + 8) / 16)
b[o+9] = uint8(((9 * v9) + (3 * v8) + v0 + (3 * v1) + 8) / 16)
b[o+8] = uint8(((9 * v8) + (3 * v0) + v1 + (3 * v9) + 8) / 16)
}
{
v0 := uint32(b[0o00+y])
v1 := uint32(b[0o01+y])
b[0o00+y] = uint8(((3 * v0) + v1 + 2) / 4)
b[0o01+y] = uint8(((3 * v1) + v0 + 2) / 4)
}
{
v0 := uint32(b[0o70+y])
v1 := uint32(b[0o71+y])
b[0o70+y] = uint8(((3 * v0) + v1 + 2) / 4)
b[0o71+y] = uint8(((3 * v1) + v0 + 2) / 4)
}
y8 := y * 8
{
v0 := uint32(b[0o00+y8])
v1 := uint32(b[0o10+y8])
b[0o00+y8] = uint8(((3 * v0) + v1 + 2) / 4)
b[0o10+y8] = uint8(((3 * v1) + v0 + 2) / 4)
}
{
v0 := uint32(b[0o07+y8])
v1 := uint32(b[0o17+y8])
b[0o07+y8] = uint8(((3 * v0) + v1 + 2) / 4)
b[0o17+y8] = uint8(((3 * v1) + v0 + 2) / 4)
}
}
}
// smoothingPairs16x16 are the seams of the four 8×8 Luma blocks in a 16×16
// MCU. The central 4 pixels are handled separately.
var smoothingPairs16x16 = [28][2]uint8{
{0x07, 0x08},
{0x17, 0x18},
{0x27, 0x28},
@@ -558,3 +747,151 @@ var smoothingPairs = [28][2]uint8{
{0xE7, 0xE8},
{0xF7, 0xF8},
}
// smoothingPairs8x8 is like smoothingPairs16x16 but for the seams of the four
// 4×4 quadrants of an 8×8.
var smoothingPairs8x8 = [12][2]uint8{
{0o03, 0o04},
{0o13, 0o14},
{0o23, 0o24},
{0o30, 0o40},
{0o31, 0o41},
{0o32, 0o42},
{0o35, 0o45},
{0o36, 0o46},
{0o37, 0o47},
{0o53, 0o54},
{0o63, 0o64},
{0o73, 0o74},
}
func scaleAndBiasChromaUp(b *lowleveljpeg.BlockU8) {
for i, v := range b {
b[i] = scaleAndBiasChromaUpLUT[v]
}
}
func scaleAndBiasChromaDown(b *lowleveljpeg.BlockU8) {
for i, v := range b {
b[i] = scaleAndBiasChromaDownLUT[v]
}
}
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,
}
// biasAndClamp[x & 1023] is (x + 0x80), clamped to the range [0x00, 0xFF], for
// a signed integer x in the range [-512, +511].
var biasAndClamp = [1024]uint8{
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 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, 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, 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, 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, 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, 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,
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, 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, 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, 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, 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, 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, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
}
+85
View File
@@ -0,0 +1,85 @@
// 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
import (
"bytes"
"image"
"testing"
)
func makePlainColorImage(grayValue uint8) image.Image {
m := image.NewGray(image.Rect(0, 0, 5, 5))
for i := range m.Pix {
m.Pix[i] = grayValue
}
return m
}
func testRoundTrip(tt *testing.T, src image.Image, pixelValue uint8, justCheckThatItsGray bool) {
for c := Color(0); c < 2; c++ {
for q := Quality(0); q < 4; q++ {
buf := &bytes.Buffer{}
err := Encode(buf, src, &EncodeOptions{
Color: MakeOptionColor(c),
Quality: MakeOptionQuality(q),
})
if err != nil {
tt.Fatalf("c=%d: q=%d: Encode: %v", c, q, err)
}
dst, err := Decode(buf)
if err != nil {
tt.Fatalf("c=%d: q=%d: Decode: %v", c, q, err)
}
pix, stride := []byte(nil), 0
switch dst := dst.(type) {
case *image.Gray:
pix, stride = dst.Pix, 1
case *image.RGBA:
pix, stride = dst.Pix, 4
}
if !justCheckThatItsGray {
for i := 0; i < len(pix); i += stride {
if pix[i] != pixelValue {
tt.Fatalf("c=%d: q=%d: i=%d: pix: got [% 02X], want %02X",
c, q, i, pix, pixelValue)
}
}
} else if stride == 4 {
for i := 0; i < len(pix); i += 4 {
if (pix[i] != pix[i+1]) || (pix[i] != pix[i+2]) {
tt.Fatalf("c=%d: q=%d: i=%d: pix: got [% 02X], want gray",
c, q, i, pix)
}
}
}
}
}
}
func TestRoundTripPureBlack(tt *testing.T) {
testRoundTrip(tt, makePlainColorImage(0x00), 0x00, false)
}
func TestRoundTripPureWhite(tt *testing.T) {
testRoundTrip(tt, makePlainColorImage(0xFF), 0xFF, false)
}
func TestRoundTripGray(tt *testing.T) {
src := image.NewGray(image.Rect(0, 0, 16, 16))
for i := range src.Pix {
src.Pix[i] = uint8(37 * i)
}
testRoundTrip(tt, src, 0, true)
}
+487 -261
View File
@@ -10675,7 +10675,8 @@ struct wuffs_handsum__decoder__struct {
uint32_t f_width;
uint32_t f_height;
uint32_t f_variant;
uint32_t f_color;
uint32_t f_quality;
uint8_t f_call_sequence;
uint16_t f_bit_offset;
uint16_t f_coeffs[40];
@@ -10691,7 +10692,7 @@ struct wuffs_handsum__decoder__struct {
struct {
uint8_t f_bits[256];
uint8_t f_buffers[2][32][128];
uint8_t f_buffers[2][16][64];
struct {
uint64_t scratch;
@@ -50319,8 +50320,17 @@ const char wuffs_handsum__error__truncated_input[] = "#handsum: truncated input"
// ---------------- Private Consts
static const uint32_t
WUFFS_HANDSUM__PAYLOAD_SIZES[4] WUFFS_BASE__POTENTIALLY_UNUSED = {
30u, 45u, 96u, 144u,
WUFFS_HANDSUM__PAYLOAD_SIZES[2][4] WUFFS_BASE__POTENTIALLY_UNUSED = {
{
30u, 48u, 80u, 96u,
}, {
45u, 72u, 120u, 144u,
},
};
static const uint32_t
WUFFS_HANDSUM__NUM_COEFFS[4] WUFFS_BASE__POTENTIALLY_UNUSED = {
15u, 6u, 10u, 3u,
};
static const uint8_t
@@ -50332,25 +50342,54 @@ WUFFS_HANDSUM__CLAMP_7[32] WUFFS_BASE__POTENTIALLY_UNUSED = {
};
static const uint8_t
WUFFS_HANDSUM__CLAMP_15[64] WUFFS_BASE__POTENTIALLY_UNUSED = {
0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u,
8u, 9u, 10u, 11u, 12u, 13u, 14u, 15u,
15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u,
15u, 15u, 15u, 15u, 15u, 15u, 15u, 15u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
WUFFS_HANDSUM__ZIGZAG[2][15] WUFFS_BASE__POTENTIALLY_UNUSED = {
{
0u, 1u, 8u, 16u, 9u, 2u, 3u, 10u,
17u, 24u, 32u, 25u, 18u, 11u, 4u,
}, {
0u, 1u, 4u, 8u, 5u, 2u, 3u, 6u,
9u, 12u, 0u, 0u, 0u, 0u, 0u,
},
};
static const uint8_t
WUFFS_HANDSUM__ZIGZAG[15] WUFFS_BASE__POTENTIALLY_UNUSED = {
0u, 1u, 8u, 16u, 9u, 2u, 3u, 10u,
17u, 24u, 32u, 25u, 18u, 11u, 4u,
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__SMOOTHING_PAIRS[56] WUFFS_BASE__POTENTIALLY_UNUSED = {
WUFFS_HANDSUM__SMOOTHING_PAIRS_16X16[56] WUFFS_BASE__POTENTIALLY_UNUSED = {
7u, 8u, 23u, 24u, 39u, 40u, 55u, 56u,
71u, 72u, 87u, 88u, 103u, 104u, 112u, 128u,
113u, 129u, 114u, 130u, 115u, 131u, 116u, 132u,
@@ -50360,16 +50399,25 @@ WUFFS_HANDSUM__SMOOTHING_PAIRS[56] WUFFS_BASE__POTENTIALLY_UNUSED = {
199u, 200u, 215u, 216u, 231u, 232u, 247u, 248u,
};
static const uint8_t
WUFFS_HANDSUM__SMOOTHING_PAIRS_8X8[24] WUFFS_BASE__POTENTIALLY_UNUSED = {
3u, 4u, 11u, 12u, 19u, 20u, 24u, 32u,
25u, 33u, 26u, 34u, 29u, 37u, 30u, 38u,
31u, 39u, 43u, 44u, 51u, 52u, 59u, 60u,
};
#define WUFFS_HANDSUM__FIXED_POINT_INV_SQRT_2 46341u
#define WUFFS_HANDSUM__FIXED_POINT_HALF 32768u
#define WUFFS_HANDSUM__FIXED_POINT_INV_2_SQRT_2 23170u
static const uint32_t
WUFFS_HANDSUM__COSINES[32] WUFFS_BASE__POTENTIALLY_UNUSED = {
65536u, 64276u, 60547u, 54491u, 46340u, 36409u, 25079u, 12785u,
0u, 4294954511u, 4294942217u, 4294930887u, 4294920956u, 4294912805u, 4294906749u, 4294903020u,
4294901760u, 4294903020u, 4294906749u, 4294912805u, 4294920956u, 4294930887u, 4294942217u, 4294954511u,
0u, 12785u, 25079u, 36409u, 46340u, 54491u, 60547u, 64276u,
65536u, 64277u, 60547u, 54491u, 46341u, 36410u, 25080u, 12785u,
0u, 4294954511u, 4294942216u, 4294930886u, 4294920955u, 4294912805u, 4294906749u, 4294903019u,
4294901760u, 4294903019u, 4294906749u, 4294912805u, 4294920955u, 4294930886u, 4294942216u, 4294954511u,
0u, 12785u, 25080u, 36410u, 46341u, 54491u, 60547u, 64277u,
};
static const uint8_t
@@ -50534,7 +50582,12 @@ wuffs_handsum__decoder__do_decode_frame(
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__decode_pblock(
wuffs_handsum__decoder__decode_zigzag_coeffs(
wuffs_handsum__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__decode_block_q0(
wuffs_handsum__decoder* self,
uint32_t a_which,
uint32_t a_y_offset,
@@ -50542,7 +50595,7 @@ wuffs_handsum__decoder__decode_pblock(
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__decode_xblock(
wuffs_handsum__decoder__decode_block_q1(
wuffs_handsum__decoder* self,
uint32_t a_which,
uint32_t a_y_offset,
@@ -50550,48 +50603,62 @@ wuffs_handsum__decoder__decode_xblock(
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__decode_xcoeffs(
wuffs_handsum__decoder__decode_tile_q1(
wuffs_handsum__decoder* self,
uint32_t a_which,
uint32_t a_y_offset,
uint32_t a_x_offset);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__decode_block_q3(
wuffs_handsum__decoder* self,
uint32_t a_which,
uint32_t a_y_offset,
uint32_t a_x_offset);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__smooth_seams_16x16(
wuffs_handsum__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__smooth_luma_block_seams(
wuffs_handsum__decoder__smooth_seams_8x8(
wuffs_handsum__decoder* self,
uint32_t a_which,
uint32_t a_y_offset,
uint32_t a_x_offset);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__scale_and_bias_chroma_down(
wuffs_handsum__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__upsample_8_to_16_chroma(
wuffs_handsum__decoder__upsample_chroma(
wuffs_handsum__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__upsample_16_to_32_bgr(
wuffs_handsum__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__convert_32_bgr_to_y(
wuffs_handsum__decoder__convert_yxxx_to_y(
wuffs_handsum__decoder* self,
uint32_t a_which);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__convert_16_y_to_bgr(
wuffs_handsum__decoder__convert_yccx_to_bgrx(
wuffs_handsum__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__convert_16_ycc_to_bgr(
wuffs_handsum__decoder__scale_horizontal(
wuffs_handsum__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__scale_32_horizontal(
wuffs_handsum__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__scale_32_vertical(
wuffs_handsum__decoder__scale_vertical(
wuffs_handsum__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
@@ -50889,17 +50956,18 @@ wuffs_handsum__decoder__do_decode_image_config(
uint32_t t_1 = *iop_a_src++;
v_c32 = t_1;
}
self->private_impl.f_variant = (v_c32 >> 6u);
if ((v_c32 & 32u) == 0u) {
self->private_impl.f_width = 32u;
self->private_impl.f_height = ((v_c32 & 31u) + 1u);
self->private_impl.f_color = (v_c32 >> 7u);
self->private_impl.f_quality = ((v_c32 >> 5u) & 3u);
if ((v_c32 & 16u) == 0u) {
self->private_impl.f_width = 16u;
self->private_impl.f_height = ((v_c32 & 15u) + 1u);
} else {
self->private_impl.f_width = ((v_c32 & 31u) + 1u);
self->private_impl.f_height = 32u;
self->private_impl.f_width = ((v_c32 & 15u) + 1u);
self->private_impl.f_height = 16u;
}
if (a_dst != NULL) {
v_pixfmt = 536870920u;
if ((self->private_impl.f_variant & 1u) != 0u) {
if (self->private_impl.f_color != 0u) {
v_pixfmt = 2415954056u;
}
wuffs_base__image_config__set(
@@ -51213,7 +51281,7 @@ wuffs_handsum__decoder__do_decode_frame(
goto ok;
}
v_pixfmt = 536870920u;
if ((self->private_impl.f_variant & 1u) != 0u) {
if (self->private_impl.f_color != 0u) {
v_pixfmt = 2415954056u;
}
v_status = wuffs_base__pixel_swizzler__prepare(&self->private_impl.f_swizzler,
@@ -51232,52 +51300,59 @@ wuffs_handsum__decoder__do_decode_frame(
}
goto ok;
}
while (v_num_read < WUFFS_HANDSUM__PAYLOAD_SIZES[self->private_impl.f_variant]) {
while (v_num_read < WUFFS_HANDSUM__PAYLOAD_SIZES[self->private_impl.f_color][self->private_impl.f_quality]) {
v_num_read += wuffs_private_impl__io_reader__limited_copy_u32_to_slice(
&iop_a_src, io2_a_src,(WUFFS_HANDSUM__PAYLOAD_SIZES[self->private_impl.f_variant] - v_num_read), wuffs_base__make_slice_u8_ij(self->private_data.f_bits, v_num_read, 256));
if (v_num_read < WUFFS_HANDSUM__PAYLOAD_SIZES[self->private_impl.f_variant]) {
&iop_a_src, io2_a_src,(WUFFS_HANDSUM__PAYLOAD_SIZES[self->private_impl.f_color][self->private_impl.f_quality] - v_num_read), wuffs_base__make_slice_u8_ij(self->private_data.f_bits, v_num_read, 256));
if (v_num_read < WUFFS_HANDSUM__PAYLOAD_SIZES[self->private_impl.f_color][self->private_impl.f_quality]) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
}
}
self->private_impl.f_bit_offset = 0u;
if (self->private_impl.f_variant < 2u) {
wuffs_handsum__decoder__decode_xblock(self, 0u, 0u, 0u);
wuffs_handsum__decoder__decode_xblock(self, 0u, 0u, 32u);
wuffs_handsum__decoder__decode_xblock(self, 0u, 8u, 0u);
wuffs_handsum__decoder__decode_xblock(self, 0u, 8u, 32u);
if (self->private_impl.f_variant == 1u) {
wuffs_handsum__decoder__decode_xblock(self, 1u, 0u, 1u);
wuffs_handsum__decoder__decode_xblock(self, 1u, 0u, 2u);
if (self->private_impl.f_quality == 0u) {
wuffs_handsum__decoder__decode_block_q0(self, 0u, 0u, 0u);
wuffs_handsum__decoder__decode_block_q0(self, 0u, 0u, 32u);
wuffs_handsum__decoder__decode_block_q0(self, 0u, 8u, 0u);
wuffs_handsum__decoder__decode_block_q0(self, 0u, 8u, 32u);
if (self->private_impl.f_color != 0u) {
wuffs_handsum__decoder__decode_block_q0(self, 1u, 0u, 1u);
wuffs_handsum__decoder__decode_block_q0(self, 1u, 0u, 2u);
}
} else if (self->private_impl.f_quality < 3u) {
wuffs_handsum__decoder__decode_block_q1(self, 0u, 0u, 0u);
wuffs_handsum__decoder__decode_block_q1(self, 0u, 0u, 32u);
wuffs_handsum__decoder__decode_block_q1(self, 0u, 8u, 0u);
wuffs_handsum__decoder__decode_block_q1(self, 0u, 8u, 32u);
if (self->private_impl.f_color != 0u) {
wuffs_handsum__decoder__decode_block_q1(self, 1u, 0u, 1u);
wuffs_handsum__decoder__decode_block_q1(self, 1u, 0u, 2u);
}
} else {
wuffs_handsum__decoder__decode_pblock(self, 0u, 0u, 0u);
wuffs_handsum__decoder__decode_pblock(self, 0u, 0u, 32u);
wuffs_handsum__decoder__decode_pblock(self, 0u, 8u, 0u);
wuffs_handsum__decoder__decode_pblock(self, 0u, 8u, 32u);
if (self->private_impl.f_variant == 3u) {
wuffs_handsum__decoder__decode_pblock(self, 1u, 0u, 1u);
wuffs_handsum__decoder__decode_pblock(self, 1u, 0u, 2u);
wuffs_handsum__decoder__decode_block_q3(self, 0u, 0u, 0u);
wuffs_handsum__decoder__decode_block_q3(self, 0u, 0u, 32u);
wuffs_handsum__decoder__decode_block_q3(self, 0u, 8u, 0u);
wuffs_handsum__decoder__decode_block_q3(self, 0u, 8u, 32u);
if (self->private_impl.f_color != 0u) {
wuffs_handsum__decoder__decode_block_q3(self, 1u, 0u, 1u);
wuffs_handsum__decoder__decode_block_q3(self, 1u, 0u, 2u);
}
}
wuffs_handsum__decoder__smooth_luma_block_seams(self);
if ((self->private_impl.f_variant & 1u) == 0u) {
wuffs_handsum__decoder__convert_16_y_to_bgr(self);
} else {
wuffs_handsum__decoder__upsample_8_to_16_chroma(self);
wuffs_handsum__decoder__convert_16_ycc_to_bgr(self);
wuffs_handsum__decoder__smooth_seams_16x16(self);
if (self->private_impl.f_color != 0u) {
wuffs_handsum__decoder__scale_and_bias_chroma_down(self);
wuffs_handsum__decoder__upsample_chroma(self);
wuffs_handsum__decoder__convert_yccx_to_bgrx(self);
}
wuffs_handsum__decoder__upsample_16_to_32_bgr(self);
v_which = 1u;
if (self->private_impl.f_width < 32u) {
v_which = 0u;
wuffs_handsum__decoder__scale_32_horizontal(self);
} else if (self->private_impl.f_height < 32u) {
v_which = 0u;
wuffs_handsum__decoder__scale_32_vertical(self);
v_which = 0u;
if (self->private_impl.f_width < 16u) {
v_which = 1u;
wuffs_handsum__decoder__scale_horizontal(self);
} else if (self->private_impl.f_height < 16u) {
v_which = 1u;
wuffs_handsum__decoder__scale_vertical(self);
}
if ((self->private_impl.f_variant & 1u) == 0u) {
wuffs_handsum__decoder__convert_32_bgr_to_y(self, v_which);
if (self->private_impl.f_color == 0u) {
wuffs_handsum__decoder__convert_yxxx_to_y(self, v_which);
}
v_status = wuffs_handsum__decoder__from_pixels_to_dst(self, a_dst, v_which);
if ( ! wuffs_base__status__is_ok(&v_status)) {
@@ -51311,64 +51386,55 @@ wuffs_handsum__decoder__do_decode_frame(
return status;
}
// -------- func handsum.decoder.decode_pblock
// -------- func handsum.decoder.decode_zigzag_coeffs
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__decode_pblock(
wuffs_handsum__decoder* self,
uint32_t a_which,
uint32_t a_y_offset,
uint32_t a_x_offset) {
wuffs_handsum__decoder__decode_zigzag_coeffs(
wuffs_handsum__decoder* self) {
uint16_t v_dcm = 0;
uint16_t v_dcn = 0;
uint16_t v_acm = 0;
uint16_t v_acn = 0;
uint32_t v_z = 0;
uint32_t v_num_coeffs = 0;
uint32_t v_bo = 0;
uint32_t v_y = 0;
uint32_t v_x = 0;
uint32_t v_sw = 0;
uint32_t v_sx = 0;
uint32_t v_sy = 0;
uint8_t v_v00 = 0;
uint8_t v_v01 = 0;
uint8_t v_v10 = 0;
uint8_t v_v11 = 0;
uint8_t v_nibble = 0;
uint32_t v_i = 0;
v_dcm = 136u;
v_dcn = 1024u;
v_acm = 64u;
v_acn = 512u;
v_z = 0u;
if (self->private_impl.f_quality != 0u) {
v_dcm = 68u;
v_dcn = 512u;
v_acm = 32u;
v_acn = 256u;
v_z = 1u;
}
v_num_coeffs = WUFFS_HANDSUM__NUM_COEFFS[self->private_impl.f_quality];
v_bo = ((uint32_t)(self->private_impl.f_bit_offset));
v_y = 0u;
while (v_y < 8u) {
v_x = 0u;
while (v_x < 8u) {
v_sw = ((uint32_t)(((uint32_t)(((uint32_t)(((uint8_t)(((uint8_t)(self->private_data.f_bits[((v_bo >> 3u) & 255u)] >> (v_bo & 4u))) & 15u)))) * 17u)) - 128u));
v_bo += 4u;
v_sx = ((uint32_t)(((uint32_t)(((uint32_t)(((uint8_t)(((uint8_t)(self->private_data.f_bits[((v_bo >> 3u) & 255u)] >> (v_bo & 4u))) & 15u)))) * 8u)) - 64u));
v_bo += 4u;
v_sy = ((uint32_t)(((uint32_t)(((uint32_t)(((uint8_t)(((uint8_t)(self->private_data.f_bits[((v_bo >> 3u) & 255u)] >> (v_bo & 4u))) & 15u)))) * 8u)) - 64u));
v_bo += 4u;
v_v00 = WUFFS_HANDSUM__BIAS_AND_CLAMP[(((uint32_t)(((uint32_t)(v_sw - v_sy)) - v_sx)) & 1023u)];
v_v01 = WUFFS_HANDSUM__BIAS_AND_CLAMP[(((uint32_t)(((uint32_t)(v_sw - v_sy)) + v_sx)) & 1023u)];
v_v10 = WUFFS_HANDSUM__BIAS_AND_CLAMP[(((uint32_t)(((uint32_t)(v_sw + v_sy)) - v_sx)) & 1023u)];
v_v11 = WUFFS_HANDSUM__BIAS_AND_CLAMP[(((uint32_t)(((uint32_t)(v_sw + v_sy)) + v_sx)) & 1023u)];
if (a_which != 0u) {
v_v00 = WUFFS_HANDSUM__BIAS_AND_CLAMP[(((uint32_t)(((uint32_t)(v_v00)) - 136u)) & 1023u)];
v_v01 = WUFFS_HANDSUM__BIAS_AND_CLAMP[(((uint32_t)(((uint32_t)(v_v01)) - 136u)) & 1023u)];
v_v10 = WUFFS_HANDSUM__BIAS_AND_CLAMP[(((uint32_t)(((uint32_t)(v_v10)) - 136u)) & 1023u)];
v_v11 = WUFFS_HANDSUM__BIAS_AND_CLAMP[(((uint32_t)(((uint32_t)(v_v11)) - 136u)) & 1023u)];
}
self->private_data.f_buffers[a_which][(a_y_offset + v_y + 0u)][(a_x_offset + (4u * v_x) + 0u)] = v_v00;
self->private_data.f_buffers[a_which][(a_y_offset + v_y + 0u)][(a_x_offset + (4u * v_x) + 4u)] = v_v01;
self->private_data.f_buffers[a_which][(a_y_offset + v_y + 1u)][(a_x_offset + (4u * v_x) + 0u)] = v_v10;
self->private_data.f_buffers[a_which][(a_y_offset + v_y + 1u)][(a_x_offset + (4u * v_x) + 4u)] = v_v11;
v_x += 2u;
}
v_y += 2u;
v_nibble = ((uint8_t)(((uint8_t)(self->private_data.f_bits[((v_bo >> 3u) & 255u)] >> (v_bo & 4u))) & 15u));
self->private_impl.f_coeffs[0u] = ((uint16_t)(((uint16_t)(((uint16_t)(v_nibble)) * v_dcm)) - v_dcn));
v_bo += 4u;
v_i = 1u;
while (v_i < v_num_coeffs) {
v_nibble = ((uint8_t)(((uint8_t)(self->private_data.f_bits[((v_bo >> 3u) & 255u)] >> (v_bo & 4u))) & 15u));
self->private_impl.f_coeffs[WUFFS_HANDSUM__ZIGZAG[v_z][v_i]] = ((uint16_t)(((uint16_t)(((uint16_t)(v_nibble)) * v_acm)) - v_acn));
v_bo += 4u;
v_i += 1u;
}
self->private_impl.f_bit_offset = ((uint16_t)(v_bo));
return wuffs_base__make_empty_struct();
}
// -------- func handsum.decoder.decode_xblock
// -------- func handsum.decoder.decode_block_q0
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__decode_xblock(
wuffs_handsum__decoder__decode_block_q0(
wuffs_handsum__decoder* self,
uint32_t a_which,
uint32_t a_y_offset,
@@ -51385,7 +51451,7 @@ wuffs_handsum__decoder__decode_xblock(
uint64_t v_c_16 = 0;
uint64_t v_result_0 = 0;
wuffs_handsum__decoder__decode_xcoeffs(self);
wuffs_handsum__decoder__decode_zigzag_coeffs(self);
v_y = 0u;
while (v_y < 8u) {
v_x = 0u;
@@ -51420,36 +51486,170 @@ wuffs_handsum__decoder__decode_xblock(
return wuffs_base__make_empty_struct();
}
// -------- func handsum.decoder.decode_xcoeffs
// -------- func handsum.decoder.decode_block_q1
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__decode_xcoeffs(
wuffs_handsum__decoder* self) {
uint32_t v_bo = 0;
uint8_t v_nibble = 0;
wuffs_handsum__decoder__decode_block_q1(
wuffs_handsum__decoder* self,
uint32_t a_which,
uint32_t a_y_offset,
uint32_t a_x_offset) {
uint32_t v_i = 0;
v_bo = ((uint32_t)(self->private_impl.f_bit_offset));
v_nibble = ((uint8_t)(((uint8_t)(self->private_data.f_bits[((v_bo >> 3u) & 255u)] >> (v_bo & 4u))) & 15u));
self->private_impl.f_coeffs[0u] = ((uint16_t)(((uint16_t)(((uint16_t)(v_nibble)) - 8u)) * 128u));
v_bo += 4u;
v_i = 1u;
while (v_i < 15u) {
v_nibble = ((uint8_t)(((uint8_t)(self->private_data.f_bits[((v_bo >> 3u) & 255u)] >> (v_bo & 4u))) & 15u));
self->private_impl.f_coeffs[WUFFS_HANDSUM__ZIGZAG[v_i]] = ((uint16_t)(((uint16_t)(((uint16_t)(v_nibble)) - 8u)) * 16u));
v_bo += 4u;
v_i = 0u;
while (v_i < 4u) {
wuffs_handsum__decoder__decode_zigzag_coeffs(self);
wuffs_handsum__decoder__decode_tile_q1(self, a_which, (a_y_offset + ((v_i & 2u) << 1u)), (a_x_offset + ((v_i & 1u) << 4u)));
v_i += 1u;
}
self->private_impl.f_bit_offset = ((uint16_t)(v_bo));
wuffs_handsum__decoder__smooth_seams_8x8(self, a_which, a_y_offset, a_x_offset);
return wuffs_base__make_empty_struct();
}
// -------- func handsum.decoder.smooth_luma_block_seams
// -------- func handsum.decoder.decode_tile_q1
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__smooth_luma_block_seams(
wuffs_handsum__decoder__decode_tile_q1(
wuffs_handsum__decoder* self,
uint32_t a_which,
uint32_t a_y_offset,
uint32_t a_x_offset) {
uint32_t v_y = 0;
uint32_t v_x = 0;
uint32_t v_v = 0;
uint32_t v_u = 0;
uint64_t v_alphas_sum_32 = 0;
uint64_t v_half_alpha_v_16 = 0;
uint64_t v_half_alpha_u_16 = 0;
uint64_t v_alphas_16 = 0;
uint64_t v_c_32 = 0;
uint64_t v_c_16 = 0;
uint64_t v_result_0 = 0;
v_y = 0u;
while (v_y < 4u) {
v_x = 0u;
while (v_x < 4u) {
v_alphas_sum_32 = 0u;
v_v = 0u;
while (v_v < 4u) {
v_half_alpha_v_16 = ((uint64_t)(32768u));
if (v_v != 0u) {
v_half_alpha_v_16 = ((uint64_t)(46341u));
}
v_u = 0u;
while (v_u < 4u) {
v_half_alpha_u_16 = ((uint64_t)(32768u));
if (v_u != 0u) {
v_half_alpha_u_16 = ((uint64_t)(46341u));
}
v_alphas_16 = wuffs_base__utility__sign_extend_rshift_u64(((uint64_t)(((uint64_t)(v_half_alpha_v_16 * v_half_alpha_u_16)) + 32768u)), 16u);
v_c_32 = ((uint64_t)(wuffs_base__utility__sign_extend_convert_u32_u64(WUFFS_HANDSUM__COSINES[((((4u * v_x) + 2u) * v_u) & 31u)]) * wuffs_base__utility__sign_extend_convert_u32_u64(WUFFS_HANDSUM__COSINES[((((4u * v_y) + 2u) * v_v) & 31u)])));
v_c_16 = wuffs_base__utility__sign_extend_rshift_u64(((uint64_t)(v_c_32 + 32768u)), 16u);
v_alphas_sum_32 += ((uint64_t)(((uint64_t)(v_alphas_16 * v_c_16)) * wuffs_base__utility__sign_extend_convert_u16_u64(self->private_impl.f_coeffs[((4u * v_v) + v_u)])));
v_u += 1u;
}
v_v += 1u;
}
v_result_0 = wuffs_base__utility__sign_extend_rshift_u64(((uint64_t)(v_alphas_sum_32 + 2147483648u)), 32u);
self->private_data.f_buffers[a_which][(a_y_offset + v_y)][(a_x_offset + (4u * v_x))] = WUFFS_HANDSUM__BIAS_AND_CLAMP[(v_result_0 & 1023u)];
v_x += 1u;
}
v_y += 1u;
}
return wuffs_base__make_empty_struct();
}
// -------- func handsum.decoder.decode_block_q3
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__decode_block_q3(
wuffs_handsum__decoder* self,
uint32_t a_which,
uint32_t a_y_offset,
uint32_t a_x_offset) {
uint32_t v_bo = 0;
uint32_t v_y = 0;
uint32_t v_x = 0;
uint32_t v_dct0 = 0;
uint32_t v_dct1 = 0;
uint32_t v_dct2 = 0;
uint8_t v_v00 = 0;
uint8_t v_v01 = 0;
uint8_t v_v10 = 0;
uint8_t v_v11 = 0;
uint32_t v_v0 = 0;
uint32_t v_v1 = 0;
uint32_t v_v8 = 0;
uint32_t v_v9 = 0;
v_bo = ((uint32_t)(self->private_impl.f_bit_offset));
v_y = 0u;
while (v_y < 7u) {
v_x = 0u;
while (v_x < 7u) {
v_dct0 = ((uint32_t)(((uint32_t)(((uint32_t)(((uint8_t)(((uint8_t)(self->private_data.f_bits[((v_bo >> 3u) & 255u)] >> (v_bo & 4u))) & 15u)))) * 34u)) - 256u));
v_bo += 4u;
v_dct1 = ((uint32_t)(((uint32_t)(((uint32_t)(((uint8_t)(((uint8_t)(self->private_data.f_bits[((v_bo >> 3u) & 255u)] >> (v_bo & 4u))) & 15u)))) * 16u)) - 128u));
v_bo += 4u;
v_dct2 = ((uint32_t)(((uint32_t)(((uint32_t)(((uint8_t)(((uint8_t)(self->private_data.f_bits[((v_bo >> 3u) & 255u)] >> (v_bo & 4u))) & 15u)))) * 16u)) - 128u));
v_bo += 4u;
v_v00 = WUFFS_HANDSUM__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(((uint32_t)(v_dct0 + v_dct1)) + v_dct2)) + 1u)) >> 1u) & 1023u)];
v_v01 = WUFFS_HANDSUM__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(((uint32_t)(v_dct0 - v_dct1)) + v_dct2)) + 1u)) >> 1u) & 1023u)];
v_v10 = WUFFS_HANDSUM__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(((uint32_t)(v_dct0 + v_dct1)) - v_dct2)) + 1u)) >> 1u) & 1023u)];
v_v11 = WUFFS_HANDSUM__BIAS_AND_CLAMP[((((uint32_t)(((uint32_t)(((uint32_t)(v_dct0 - v_dct1)) - v_dct2)) + 1u)) >> 1u) & 1023u)];
self->private_data.f_buffers[a_which][(a_y_offset + v_y + 0u)][(a_x_offset + (4u * v_x) + 0u)] = v_v00;
self->private_data.f_buffers[a_which][(a_y_offset + v_y + 0u)][(a_x_offset + (4u * v_x) + 4u)] = v_v01;
self->private_data.f_buffers[a_which][(a_y_offset + v_y + 1u)][(a_x_offset + (4u * v_x) + 0u)] = v_v10;
self->private_data.f_buffers[a_which][(a_y_offset + v_y + 1u)][(a_x_offset + (4u * v_x) + 4u)] = v_v11;
v_x += 2u;
}
v_y += 2u;
}
self->private_impl.f_bit_offset = ((uint16_t)(v_bo));
v_y = 1u;
while (v_y < 7u) {
v_x = 1u;
while (v_x < 7u) {
v_v0 = ((uint32_t)(self->private_data.f_buffers[a_which][(a_y_offset + v_y + 0u)][(a_x_offset + (4u * v_x) + 0u)]));
v_v1 = ((uint32_t)(self->private_data.f_buffers[a_which][(a_y_offset + v_y + 0u)][(a_x_offset + (4u * v_x) + 4u)]));
v_v9 = ((uint32_t)(self->private_data.f_buffers[a_which][(a_y_offset + v_y + 1u)][(a_x_offset + (4u * v_x) + 4u)]));
v_v8 = ((uint32_t)(self->private_data.f_buffers[a_which][(a_y_offset + v_y + 1u)][(a_x_offset + (4u * v_x) + 0u)]));
self->private_data.f_buffers[a_which][(a_y_offset + v_y + 0u)][(a_x_offset + (4u * v_x) + 0u)] = ((uint8_t)((((uint32_t)(((uint32_t)(((uint32_t)(((uint32_t)(((uint32_t)(9u * v_v0)) + ((uint32_t)(3u * v_v1)))) + v_v9)) + ((uint32_t)(3u * v_v8)))) + 8u)) / 16u)));
self->private_data.f_buffers[a_which][(a_y_offset + v_y + 0u)][(a_x_offset + (4u * v_x) + 4u)] = ((uint8_t)((((uint32_t)(((uint32_t)(((uint32_t)(((uint32_t)(((uint32_t)(9u * v_v1)) + ((uint32_t)(3u * v_v9)))) + v_v8)) + ((uint32_t)(3u * v_v0)))) + 8u)) / 16u)));
self->private_data.f_buffers[a_which][(a_y_offset + v_y + 1u)][(a_x_offset + (4u * v_x) + 4u)] = ((uint8_t)((((uint32_t)(((uint32_t)(((uint32_t)(((uint32_t)(((uint32_t)(9u * v_v9)) + ((uint32_t)(3u * v_v8)))) + v_v0)) + ((uint32_t)(3u * v_v1)))) + 8u)) / 16u)));
self->private_data.f_buffers[a_which][(a_y_offset + v_y + 1u)][(a_x_offset + (4u * v_x) + 0u)] = ((uint8_t)((((uint32_t)(((uint32_t)(((uint32_t)(((uint32_t)(((uint32_t)(9u * v_v8)) + ((uint32_t)(3u * v_v0)))) + v_v1)) + ((uint32_t)(3u * v_v9)))) + 8u)) / 16u)));
v_x += 2u;
}
v_v0 = ((uint32_t)(self->private_data.f_buffers[a_which][(a_y_offset + 0u + 0u)][(a_x_offset + (4u * v_y) + 0u)]));
v_v1 = ((uint32_t)(self->private_data.f_buffers[a_which][(a_y_offset + 0u + 0u)][(a_x_offset + (4u * v_y) + 4u)]));
self->private_data.f_buffers[a_which][(a_y_offset + 0u + 0u)][(a_x_offset + (4u * v_y) + 0u)] = ((uint8_t)((((uint32_t)(((uint32_t)(((uint32_t)(3u * v_v0)) + v_v1)) + 2u)) / 4u)));
self->private_data.f_buffers[a_which][(a_y_offset + 0u + 0u)][(a_x_offset + (4u * v_y) + 4u)] = ((uint8_t)((((uint32_t)(((uint32_t)(((uint32_t)(3u * v_v1)) + v_v0)) + 2u)) / 4u)));
v_v0 = ((uint32_t)(self->private_data.f_buffers[a_which][(a_y_offset + 7u + 0u)][(a_x_offset + (4u * v_y) + 0u)]));
v_v1 = ((uint32_t)(self->private_data.f_buffers[a_which][(a_y_offset + 7u + 0u)][(a_x_offset + (4u * v_y) + 4u)]));
self->private_data.f_buffers[a_which][(a_y_offset + 7u + 0u)][(a_x_offset + (4u * v_y) + 0u)] = ((uint8_t)((((uint32_t)(((uint32_t)(((uint32_t)(3u * v_v0)) + v_v1)) + 2u)) / 4u)));
self->private_data.f_buffers[a_which][(a_y_offset + 7u + 0u)][(a_x_offset + (4u * v_y) + 4u)] = ((uint8_t)((((uint32_t)(((uint32_t)(((uint32_t)(3u * v_v1)) + v_v0)) + 2u)) / 4u)));
v_v0 = ((uint32_t)(self->private_data.f_buffers[a_which][(a_y_offset + v_y + 0u)][(a_x_offset + 0u + 0u)]));
v_v1 = ((uint32_t)(self->private_data.f_buffers[a_which][(a_y_offset + v_y + 1u)][(a_x_offset + 0u + 0u)]));
self->private_data.f_buffers[a_which][(a_y_offset + v_y + 0u)][(a_x_offset + 0u + 0u)] = ((uint8_t)((((uint32_t)(((uint32_t)(((uint32_t)(3u * v_v0)) + v_v1)) + 2u)) / 4u)));
self->private_data.f_buffers[a_which][(a_y_offset + v_y + 1u)][(a_x_offset + 0u + 0u)] = ((uint8_t)((((uint32_t)(((uint32_t)(((uint32_t)(3u * v_v1)) + v_v0)) + 2u)) / 4u)));
v_v0 = ((uint32_t)(self->private_data.f_buffers[a_which][(a_y_offset + v_y + 0u)][(a_x_offset + 28u + 0u)]));
v_v1 = ((uint32_t)(self->private_data.f_buffers[a_which][(a_y_offset + v_y + 1u)][(a_x_offset + 28u + 0u)]));
self->private_data.f_buffers[a_which][(a_y_offset + v_y + 0u)][(a_x_offset + 28u + 0u)] = ((uint8_t)((((uint32_t)(((uint32_t)(((uint32_t)(3u * v_v0)) + v_v1)) + 2u)) / 4u)));
self->private_data.f_buffers[a_which][(a_y_offset + v_y + 1u)][(a_x_offset + 28u + 0u)] = ((uint8_t)((((uint32_t)(((uint32_t)(((uint32_t)(3u * v_v1)) + v_v0)) + 2u)) / 4u)));
v_y += 2u;
}
return wuffs_base__make_empty_struct();
}
// -------- func handsum.decoder.smooth_seams_16x16
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__smooth_seams_16x16(
wuffs_handsum__decoder* self) {
uint32_t v_i = 0;
uint8_t v_p0 = 0;
@@ -51473,18 +51673,18 @@ wuffs_handsum__decoder__smooth_luma_block_seams(
v_i = 0u;
while (v_i <= 54u) {
v_p0 = WUFFS_HANDSUM__SMOOTHING_PAIRS[(v_i + 0u)];
v_p1 = WUFFS_HANDSUM__SMOOTHING_PAIRS[(v_i + 1u)];
v_p0 = WUFFS_HANDSUM__SMOOTHING_PAIRS_16X16[(v_i + 0u)];
v_p1 = WUFFS_HANDSUM__SMOOTHING_PAIRS_16X16[(v_i + 1u)];
v_y0 = ((uint32_t)(((uint8_t)(v_p0 >> 4u))));
v_y1 = ((uint32_t)(((uint8_t)(v_p1 >> 4u))));
v_x0 = ((uint32_t)(((uint8_t)(v_p0 & 15u))));
v_x1 = ((uint32_t)(((uint8_t)(v_p1 & 15u))));
v_v0 = ((uint32_t)(self->private_data.f_buffers[0u][v_y0][(v_x0 * 4u)]));
v_v1 = ((uint32_t)(self->private_data.f_buffers[0u][v_y1][(v_x1 * 4u)]));
v_x0 = (((uint32_t)(((uint8_t)(v_p0 & 15u)))) << 2u);
v_x1 = (((uint32_t)(((uint8_t)(v_p1 & 15u)))) << 2u);
v_v0 = ((uint32_t)(self->private_data.f_buffers[0u][v_y0][v_x0]));
v_v1 = ((uint32_t)(self->private_data.f_buffers[0u][v_y1][v_x1]));
v_w0 = (((3u * v_v0) + v_v1 + 2u) / 4u);
v_w1 = (((3u * v_v1) + v_v0 + 2u) / 4u);
self->private_data.f_buffers[0u][v_y0][(v_x0 * 4u)] = ((uint8_t)(v_w0));
self->private_data.f_buffers[0u][v_y1][(v_x1 * 4u)] = ((uint8_t)(v_w1));
self->private_data.f_buffers[0u][v_y0][v_x0] = ((uint8_t)(v_w0));
self->private_data.f_buffers[0u][v_y1][v_x1] = ((uint8_t)(v_w1));
v_i += 2u;
}
v_v77 = ((uint32_t)(self->private_data.f_buffers[0u][7u][28u]));
@@ -51518,11 +51718,109 @@ wuffs_handsum__decoder__smooth_luma_block_seams(
return wuffs_base__make_empty_struct();
}
// -------- func handsum.decoder.upsample_8_to_16_chroma
// -------- func handsum.decoder.smooth_seams_8x8
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__upsample_8_to_16_chroma(
wuffs_handsum__decoder__smooth_seams_8x8(
wuffs_handsum__decoder* self,
uint32_t a_which,
uint32_t a_y_offset,
uint32_t a_x_offset) {
uint32_t v_i = 0;
uint8_t v_p0 = 0;
uint8_t v_p1 = 0;
uint32_t v_y0 = 0;
uint32_t v_y1 = 0;
uint32_t v_x0 = 0;
uint32_t v_x1 = 0;
uint32_t v_v0 = 0;
uint32_t v_v1 = 0;
uint32_t v_w0 = 0;
uint32_t v_w1 = 0;
uint32_t v_v33 = 0;
uint32_t v_v34 = 0;
uint32_t v_v44 = 0;
uint32_t v_v43 = 0;
uint32_t v_w33 = 0;
uint32_t v_w34 = 0;
uint32_t v_w44 = 0;
uint32_t v_w43 = 0;
v_i = 0u;
while (v_i <= 22u) {
v_p0 = WUFFS_HANDSUM__SMOOTHING_PAIRS_8X8[(v_i + 0u)];
v_p1 = WUFFS_HANDSUM__SMOOTHING_PAIRS_8X8[(v_i + 1u)];
v_y0 = (a_y_offset + ((uint32_t)(((uint8_t)(v_p0 >> 3u)))));
v_y1 = (a_y_offset + ((uint32_t)(((uint8_t)(v_p1 >> 3u)))));
v_x0 = (a_x_offset + (((uint32_t)(((uint8_t)(v_p0 & 7u)))) << 2u));
v_x1 = (a_x_offset + (((uint32_t)(((uint8_t)(v_p1 & 7u)))) << 2u));
v_v0 = ((uint32_t)(self->private_data.f_buffers[a_which][v_y0][v_x0]));
v_v1 = ((uint32_t)(self->private_data.f_buffers[a_which][v_y1][v_x1]));
v_w0 = (((3u * v_v0) + v_v1 + 2u) / 4u);
v_w1 = (((3u * v_v1) + v_v0 + 2u) / 4u);
self->private_data.f_buffers[a_which][v_y0][v_x0] = ((uint8_t)(v_w0));
self->private_data.f_buffers[a_which][v_y1][v_x1] = ((uint8_t)(v_w1));
v_i += 2u;
}
v_v33 = ((uint32_t)(self->private_data.f_buffers[a_which][(a_y_offset + 3u)][(a_x_offset + 12u)]));
v_v34 = ((uint32_t)(self->private_data.f_buffers[a_which][(a_y_offset + 3u)][(a_x_offset + 16u)]));
v_v44 = ((uint32_t)(self->private_data.f_buffers[a_which][(a_y_offset + 4u)][(a_x_offset + 16u)]));
v_v43 = ((uint32_t)(self->private_data.f_buffers[a_which][(a_y_offset + 4u)][(a_x_offset + 12u)]));
v_w33 = (((9u * v_v33) +
(3u * v_v34) +
v_v44 +
(3u * v_v43) +
8u) / 16u);
v_w34 = (((9u * v_v34) +
(3u * v_v44) +
v_v43 +
(3u * v_v33) +
8u) / 16u);
v_w44 = (((9u * v_v44) +
(3u * v_v43) +
v_v33 +
(3u * v_v34) +
8u) / 16u);
v_w43 = (((9u * v_v43) +
(3u * v_v33) +
v_v34 +
(3u * v_v44) +
8u) / 16u);
self->private_data.f_buffers[a_which][(a_y_offset + 3u)][(a_x_offset + 12u)] = ((uint8_t)(v_w33));
self->private_data.f_buffers[a_which][(a_y_offset + 3u)][(a_x_offset + 16u)] = ((uint8_t)(v_w34));
self->private_data.f_buffers[a_which][(a_y_offset + 4u)][(a_x_offset + 16u)] = ((uint8_t)(v_w44));
self->private_data.f_buffers[a_which][(a_y_offset + 4u)][(a_x_offset + 12u)] = ((uint8_t)(v_w43));
return wuffs_base__make_empty_struct();
}
// -------- func handsum.decoder.scale_and_bias_chroma_down
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__scale_and_bias_chroma_down(
wuffs_handsum__decoder* self) {
uint32_t v_y = 0;
uint32_t v_x = 0;
v_y = 0u;
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)]];
v_x += 1u;
}
v_y += 1u;
}
return wuffs_base__make_empty_struct();
}
// -------- func handsum.decoder.upsample_chroma
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__upsample_chroma(
wuffs_handsum__decoder* self) {
uint32_t v_y = 0;
uint32_t v_dy = 0;
@@ -51560,68 +51858,20 @@ wuffs_handsum__decoder__upsample_8_to_16_chroma(
return wuffs_base__make_empty_struct();
}
// -------- func handsum.decoder.upsample_16_to_32_bgr
// -------- func handsum.decoder.convert_yxxx_to_y
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__upsample_16_to_32_bgr(
wuffs_handsum__decoder* self) {
uint32_t v_y = 0;
uint32_t v_dy = 0;
uint32_t v_y0 = 0;
uint32_t v_y1 = 0;
uint32_t v_x = 0;
uint32_t v_dx = 0;
uint32_t v_x0 = 0;
uint32_t v_x1 = 0;
v_y = 0u;
while (v_y < 32u) {
v_dy = ((uint32_t)(((v_y & 1u) * 2u) - 1u));
v_y0 = (v_y >> 1u);
v_y1 = ((uint32_t)(WUFFS_HANDSUM__CLAMP_15[(((uint32_t)(v_y0 + v_dy)) & 63u)]));
v_x = 0u;
while (v_x < 32u) {
v_dx = ((uint32_t)(((v_x & 1u) * 2u) - 1u));
v_x0 = (v_x >> 1u);
v_x1 = ((uint32_t)(WUFFS_HANDSUM__CLAMP_15[(((uint32_t)(v_x0 + v_dx)) & 63u)]));
self->private_data.f_buffers[1u][v_y][((4u * v_x) + 0u)] = ((uint8_t)((((((uint32_t)(self->private_data.f_buffers[0u][v_y0][((4u * v_x0) + 0u)])) * 9u) +
(((uint32_t)(self->private_data.f_buffers[0u][v_y0][((4u * v_x1) + 0u)])) * 3u) +
(((uint32_t)(self->private_data.f_buffers[0u][v_y1][((4u * v_x0) + 0u)])) * 3u) +
((uint32_t)(self->private_data.f_buffers[0u][v_y1][((4u * v_x1) + 0u)])) +
8u) / 16u)));
self->private_data.f_buffers[1u][v_y][((4u * v_x) + 1u)] = ((uint8_t)((((((uint32_t)(self->private_data.f_buffers[0u][v_y0][((4u * v_x0) + 1u)])) * 9u) +
(((uint32_t)(self->private_data.f_buffers[0u][v_y0][((4u * v_x1) + 1u)])) * 3u) +
(((uint32_t)(self->private_data.f_buffers[0u][v_y1][((4u * v_x0) + 1u)])) * 3u) +
((uint32_t)(self->private_data.f_buffers[0u][v_y1][((4u * v_x1) + 1u)])) +
8u) / 16u)));
self->private_data.f_buffers[1u][v_y][((4u * v_x) + 2u)] = ((uint8_t)((((((uint32_t)(self->private_data.f_buffers[0u][v_y0][((4u * v_x0) + 2u)])) * 9u) +
(((uint32_t)(self->private_data.f_buffers[0u][v_y0][((4u * v_x1) + 2u)])) * 3u) +
(((uint32_t)(self->private_data.f_buffers[0u][v_y1][((4u * v_x0) + 2u)])) * 3u) +
((uint32_t)(self->private_data.f_buffers[0u][v_y1][((4u * v_x1) + 2u)])) +
8u) / 16u)));
self->private_data.f_buffers[1u][v_y][((4u * v_x) + 3u)] = 255u;
v_x += 1u;
}
v_y += 1u;
}
return wuffs_base__make_empty_struct();
}
// -------- func handsum.decoder.convert_32_bgr_to_y
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__convert_32_bgr_to_y(
wuffs_handsum__decoder__convert_yxxx_to_y(
wuffs_handsum__decoder* self,
uint32_t a_which) {
uint32_t v_y = 0;
uint32_t v_x = 0;
v_y = 0u;
while (v_y < 32u) {
while (v_y < 16u) {
v_x = 1u;
while (v_x < 32u) {
while (v_x < 16u) {
self->private_data.f_buffers[a_which][v_y][v_x] = self->private_data.f_buffers[a_which][v_y][(4u * v_x)];
v_x += 1u;
}
@@ -51630,35 +51880,11 @@ wuffs_handsum__decoder__convert_32_bgr_to_y(
return wuffs_base__make_empty_struct();
}
// -------- func handsum.decoder.convert_16_y_to_bgr
// -------- func handsum.decoder.convert_yccx_to_bgrx
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__convert_16_y_to_bgr(
wuffs_handsum__decoder* self) {
uint32_t v_y = 0;
uint32_t v_x = 0;
uint8_t v_gray = 0;
v_y = 0u;
while (v_y < 16u) {
v_x = 0u;
while (v_x < 16u) {
v_gray = self->private_data.f_buffers[0u][v_y][((4u * v_x) + 0u)];
self->private_data.f_buffers[0u][v_y][((4u * v_x) + 1u)] = v_gray;
self->private_data.f_buffers[0u][v_y][((4u * v_x) + 2u)] = v_gray;
v_x += 1u;
}
v_y += 1u;
}
return wuffs_base__make_empty_struct();
}
// -------- func handsum.decoder.convert_16_ycc_to_bgr
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__convert_16_ycc_to_bgr(
wuffs_handsum__decoder__convert_yccx_to_bgrx(
wuffs_handsum__decoder* self) {
uint32_t v_y = 0;
uint32_t v_x = 0;
@@ -51704,11 +51930,11 @@ wuffs_handsum__decoder__convert_16_ycc_to_bgr(
return wuffs_base__make_empty_struct();
}
// -------- func handsum.decoder.scale_32_horizontal
// -------- func handsum.decoder.scale_horizontal
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__scale_32_horizontal(
wuffs_handsum__decoder__scale_horizontal(
wuffs_handsum__decoder* self) {
uint32_t v_y = 0;
uint32_t v_dstx = 0;
@@ -51723,17 +51949,17 @@ wuffs_handsum__decoder__scale_32_horizontal(
uint32_t v_partial = 0;
v_y = 0u;
while (v_y < 32u) {
while (v_y < 16u) {
v_dstx = 0u;
v_srcx = 0u;
v_acc0 = 0u;
v_acc1 = 0u;
v_acc2 = 0u;
v_remainder = 32u;
while (v_srcx < 32u) {
v_s0 = ((uint32_t)(self->private_data.f_buffers[1u][v_y][((4u * v_srcx) + 0u)]));
v_s1 = ((uint32_t)(self->private_data.f_buffers[1u][v_y][((4u * v_srcx) + 1u)]));
v_s2 = ((uint32_t)(self->private_data.f_buffers[1u][v_y][((4u * v_srcx) + 2u)]));
v_remainder = 16u;
while (v_srcx < 16u) {
v_s0 = ((uint32_t)(self->private_data.f_buffers[0u][v_y][((4u * v_srcx) + 0u)]));
v_s1 = ((uint32_t)(self->private_data.f_buffers[0u][v_y][((4u * v_srcx) + 1u)]));
v_s2 = ((uint32_t)(self->private_data.f_buffers[0u][v_y][((4u * v_srcx) + 2u)]));
if (v_remainder > self->private_impl.f_width) {
v_remainder -= self->private_impl.f_width;
v_acc0 += (self->private_impl.f_width * v_s0);
@@ -51743,16 +51969,16 @@ wuffs_handsum__decoder__scale_32_horizontal(
v_acc0 += (v_remainder * v_s0);
v_acc1 += (v_remainder * v_s1);
v_acc2 += (v_remainder * v_s2);
self->private_data.f_buffers[0u][v_y][((4u * v_dstx) + 0u)] = ((uint8_t)((((uint32_t)(v_acc0 + 16u)) / 32u)));
self->private_data.f_buffers[0u][v_y][((4u * v_dstx) + 1u)] = ((uint8_t)((((uint32_t)(v_acc1 + 16u)) / 32u)));
self->private_data.f_buffers[0u][v_y][((4u * v_dstx) + 2u)] = ((uint8_t)((((uint32_t)(v_acc2 + 16u)) / 32u)));
self->private_data.f_buffers[0u][v_y][((4u * v_dstx) + 3u)] = 255u;
v_dstx = ((v_dstx + 1u) & 31u);
self->private_data.f_buffers[1u][v_y][((4u * v_dstx) + 0u)] = ((uint8_t)((((uint32_t)(v_acc0 + 8u)) / 16u)));
self->private_data.f_buffers[1u][v_y][((4u * v_dstx) + 1u)] = ((uint8_t)((((uint32_t)(v_acc1 + 8u)) / 16u)));
self->private_data.f_buffers[1u][v_y][((4u * v_dstx) + 2u)] = ((uint8_t)((((uint32_t)(v_acc2 + 8u)) / 16u)));
self->private_data.f_buffers[1u][v_y][((4u * v_dstx) + 3u)] = 255u;
v_dstx = ((v_dstx + 1u) & 15u);
v_partial = (self->private_impl.f_width - v_remainder);
v_acc0 = (v_partial * v_s0);
v_acc1 = (v_partial * v_s1);
v_acc2 = (v_partial * v_s2);
v_remainder = (32u - v_partial);
v_remainder = (16u - v_partial);
}
v_srcx += 1u;
}
@@ -51761,11 +51987,11 @@ wuffs_handsum__decoder__scale_32_horizontal(
return wuffs_base__make_empty_struct();
}
// -------- func handsum.decoder.scale_32_vertical
// -------- func handsum.decoder.scale_vertical
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_handsum__decoder__scale_32_vertical(
wuffs_handsum__decoder__scale_vertical(
wuffs_handsum__decoder* self) {
uint32_t v_x = 0;
uint32_t v_dsty = 0;
@@ -51780,17 +52006,17 @@ wuffs_handsum__decoder__scale_32_vertical(
uint32_t v_partial = 0;
v_x = 0u;
while (v_x < 32u) {
while (v_x < 16u) {
v_dsty = 0u;
v_srcy = 0u;
v_acc0 = 0u;
v_acc1 = 0u;
v_acc2 = 0u;
v_remainder = 32u;
while (v_srcy < 32u) {
v_s0 = ((uint32_t)(self->private_data.f_buffers[1u][v_srcy][((4u * v_x) + 0u)]));
v_s1 = ((uint32_t)(self->private_data.f_buffers[1u][v_srcy][((4u * v_x) + 1u)]));
v_s2 = ((uint32_t)(self->private_data.f_buffers[1u][v_srcy][((4u * v_x) + 2u)]));
v_remainder = 16u;
while (v_srcy < 16u) {
v_s0 = ((uint32_t)(self->private_data.f_buffers[0u][v_srcy][((4u * v_x) + 0u)]));
v_s1 = ((uint32_t)(self->private_data.f_buffers[0u][v_srcy][((4u * v_x) + 1u)]));
v_s2 = ((uint32_t)(self->private_data.f_buffers[0u][v_srcy][((4u * v_x) + 2u)]));
if (v_remainder > self->private_impl.f_height) {
v_remainder -= self->private_impl.f_height;
v_acc0 += (self->private_impl.f_height * v_s0);
@@ -51800,16 +52026,16 @@ wuffs_handsum__decoder__scale_32_vertical(
v_acc0 += (v_remainder * v_s0);
v_acc1 += (v_remainder * v_s1);
v_acc2 += (v_remainder * v_s2);
self->private_data.f_buffers[0u][v_dsty][((4u * v_x) + 0u)] = ((uint8_t)((((uint32_t)(v_acc0 + 16u)) / 32u)));
self->private_data.f_buffers[0u][v_dsty][((4u * v_x) + 1u)] = ((uint8_t)((((uint32_t)(v_acc1 + 16u)) / 32u)));
self->private_data.f_buffers[0u][v_dsty][((4u * v_x) + 2u)] = ((uint8_t)((((uint32_t)(v_acc2 + 16u)) / 32u)));
self->private_data.f_buffers[0u][v_dsty][((4u * v_x) + 3u)] = 255u;
v_dsty = ((v_dsty + 1u) & 31u);
self->private_data.f_buffers[1u][v_dsty][((4u * v_x) + 0u)] = ((uint8_t)((((uint32_t)(v_acc0 + 8u)) / 16u)));
self->private_data.f_buffers[1u][v_dsty][((4u * v_x) + 1u)] = ((uint8_t)((((uint32_t)(v_acc1 + 8u)) / 16u)));
self->private_data.f_buffers[1u][v_dsty][((4u * v_x) + 2u)] = ((uint8_t)((((uint32_t)(v_acc2 + 8u)) / 16u)));
self->private_data.f_buffers[1u][v_dsty][((4u * v_x) + 3u)] = 255u;
v_dsty = ((v_dsty + 1u) & 15u);
v_partial = (self->private_impl.f_height - v_remainder);
v_acc0 = (v_partial * v_s0);
v_acc1 = (v_partial * v_s1);
v_acc2 = (v_partial * v_s2);
v_remainder = (32u - v_partial);
v_remainder = (16u - v_partial);
}
v_srcy += 1u;
}
@@ -51845,7 +52071,7 @@ wuffs_handsum__decoder__from_pixels_to_dst(
v_dst_bytes_per_row = ((uint64_t)((self->private_impl.f_width * v_dst_bytes_per_pixel)));
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0u);
v_src_bytes_per_pixel = 1u;
if ((self->private_impl.f_variant & 1u) != 0u) {
if (self->private_impl.f_color != 0u) {
v_src_bytes_per_pixel = 4u;
}
while (v_y < self->private_impl.f_height) {
+518 -277
View File
@@ -20,9 +20,10 @@ pub status "#truncated input"
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
pub struct decoder? implements base.image_decoder(
width : base.u32[..= 32],
height : base.u32[..= 32],
variant : base.u32[..= 3],
width : base.u32[..= 16],
height : base.u32[..= 16],
color : base.u32[..= 1],
quality : base.u32[..= 3],
// The call sequence state machine is discussed in
// (/doc/std/image-decoders-call-sequence.md).
@@ -36,7 +37,7 @@ pub struct decoder? implements base.image_decoder(
util : base.utility,
) + (
bits : array[256] base.u8,
buffers : array[2] array[32] array[128] base.u8,
buffers : array[2] array[16] array[64] base.u8,
)
pub func decoder.get_quirk(key: base.u32) base.u64 {
@@ -72,19 +73,20 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
return "#bad header"
}
c32 = args.src.read_u8_as_u32?()
this.variant = c32 >> 6
this.color = c32 >> 7
this.quality = (c32 >> 5) & 3
if (c32 & 0x20) == 0x00 { // Landscape.
this.width = 32
this.height = (c32 & 0x1F) + 1
if (c32 & 0x10) == 0x00 { // Landscape.
this.width = 16
this.height = (c32 & 0x0F) + 1
} else { // Portrait.
this.width = (c32 & 0x1F) + 1
this.height = 32
this.width = (c32 & 0x0F) + 1
this.height = 16
}
if args.dst <> nullptr {
pixfmt = base.PIXEL_FORMAT__Y
if (this.variant & 1) <> 0 {
if this.color <> 0 {
pixfmt = base.PIXEL_FORMAT__BGRX
}
@@ -173,7 +175,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
}
pixfmt = base.PIXEL_FORMAT__Y
if (this.variant & 1) <> 0 {
if this.color <> 0 {
pixfmt = base.PIXEL_FORMAT__BGRX
}
@@ -187,60 +189,68 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
return status
}
while num_read < PAYLOAD_SIZES[this.variant] {
assert num_read < 256 via "a < b: a < c; c <= b"(c: PAYLOAD_SIZES[this.variant])
assert PAYLOAD_SIZES[this.variant] > num_read via "a > b: b < a"()
while num_read < PAYLOAD_SIZES[this.color][this.quality] {
assert num_read < 256 via "a < b: a < c; c <= b"(c: PAYLOAD_SIZES[this.color][this.quality])
assert PAYLOAD_SIZES[this.color][this.quality] > num_read via "a > b: b < a"()
num_read ~mod+= args.src.limited_copy_u32_to_slice!(
up_to: PAYLOAD_SIZES[this.variant] - num_read,
up_to: PAYLOAD_SIZES[this.color][this.quality] - num_read,
s: this.bits[num_read ..])
if num_read < PAYLOAD_SIZES[this.variant] {
if num_read < PAYLOAD_SIZES[this.color][this.quality] {
yield? base."$short read"
}
}
this.bit_offset = 0
if this.variant < 2 {
this.decode_xblock!(which: 0, y_offset: 0, x_offset: 4 * 0)
this.decode_xblock!(which: 0, y_offset: 0, x_offset: 4 * 8)
this.decode_xblock!(which: 0, y_offset: 8, x_offset: 4 * 0)
this.decode_xblock!(which: 0, y_offset: 8, x_offset: 4 * 8)
if this.variant == 1 {
this.decode_xblock!(which: 1, y_offset: 0, x_offset: 1)
this.decode_xblock!(which: 1, y_offset: 0, x_offset: 2)
if this.quality == 0 {
this.decode_block_q0!(which: 0, y_offset: 0, x_offset: 4 * 0)
this.decode_block_q0!(which: 0, y_offset: 0, x_offset: 4 * 8)
this.decode_block_q0!(which: 0, y_offset: 8, x_offset: 4 * 0)
this.decode_block_q0!(which: 0, y_offset: 8, x_offset: 4 * 8)
if this.color <> 0 {
this.decode_block_q0!(which: 1, y_offset: 0, x_offset: 1)
this.decode_block_q0!(which: 1, y_offset: 0, x_offset: 2)
}
} else if this.quality < 3 {
this.decode_block_q1!(which: 0, y_offset: 0, x_offset: 4 * 0)
this.decode_block_q1!(which: 0, y_offset: 0, x_offset: 4 * 8)
this.decode_block_q1!(which: 0, y_offset: 8, x_offset: 4 * 0)
this.decode_block_q1!(which: 0, y_offset: 8, x_offset: 4 * 8)
if this.color <> 0 {
this.decode_block_q1!(which: 1, y_offset: 0, x_offset: 1)
this.decode_block_q1!(which: 1, y_offset: 0, x_offset: 2)
}
} else {
this.decode_pblock!(which: 0, y_offset: 0, x_offset: 4 * 0)
this.decode_pblock!(which: 0, y_offset: 0, x_offset: 4 * 8)
this.decode_pblock!(which: 0, y_offset: 8, x_offset: 4 * 0)
this.decode_pblock!(which: 0, y_offset: 8, x_offset: 4 * 8)
if this.variant == 3 {
this.decode_pblock!(which: 1, y_offset: 0, x_offset: 1)
this.decode_pblock!(which: 1, y_offset: 0, x_offset: 2)
this.decode_block_q3!(which: 0, y_offset: 0, x_offset: 4 * 0)
this.decode_block_q3!(which: 0, y_offset: 0, x_offset: 4 * 8)
this.decode_block_q3!(which: 0, y_offset: 8, x_offset: 4 * 0)
this.decode_block_q3!(which: 0, y_offset: 8, x_offset: 4 * 8)
if this.color <> 0 {
this.decode_block_q3!(which: 1, y_offset: 0, x_offset: 1)
this.decode_block_q3!(which: 1, y_offset: 0, x_offset: 2)
}
}
this.smooth_luma_block_seams!()
this.smooth_seams_16x16!()
if (this.variant & 1) == 0 {
this.convert_16_y_to_bgr!()
} else {
this.upsample_8_to_16_chroma!()
this.convert_16_ycc_to_bgr!()
if this.color <> 0 {
this.scale_and_bias_chroma_down!()
this.upsample_chroma!()
this.convert_yccx_to_bgrx!()
}
this.upsample_16_to_32_bgr!()
which = 1
if this.width < 32 {
which = 0
this.scale_32_horizontal!()
} else if this.height < 32 {
which = 0
this.scale_32_vertical!()
which = 0
if this.width < 16 {
which = 1
this.scale_horizontal!()
} else if this.height < 16 {
which = 1
this.scale_vertical!()
}
if (this.variant & 1) == 0 {
this.convert_32_bgr_to_y!(which: which)
if this.color == 0 {
this.convert_yxxx_to_y!(which: which)
}
status = this.from_pixels_to_dst!(dst: args.dst, which: which)
@@ -251,71 +261,54 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
this.call_sequence = 0x60
}
pri func decoder.decode_pblock!(which: base.u32[..= 1], y_offset: base.u32[..= 8], x_offset: base.u32[..= 32]) {
var bo : base.u32
pri func decoder.decode_zigzag_coeffs!() {
var dcm : base.u16
var dcn : base.u16
var acm : base.u16
var acn : base.u16
var z : base.u32[..= 1]
var y : base.u32
var x : base.u32
var num_coeffs : base.u32[..= 15]
var sw : base.u32
var sx : base.u32
var sy : base.u32
var bo : base.u32
var nibble : base.u8[..= 15]
var i : base.u32
var v00 : base.u8
var v01 : base.u8
var v10 : base.u8
var v11 : base.u8
dcm = 0x88
dcn = 1024
acm = 64
acn = 512
z = 0
if this.quality <> 0 {
dcm = 0x44
dcn = 512
acm = 32
acn = 256
z = 1
}
num_coeffs = NUM_COEFFS[this.quality]
bo = this.bit_offset as base.u32
y = 0
while y < 8 {
x = 0
while x < 8,
inv y < 8,
{
// sw, sx and sy are scaled-and-biased versions of lib/handsum's
// ew, ex and ey.
//
// sw's "~mod- 0x80" is because BIAS_AND_CLAMP[0] is 0x80.
sw = ((((this.bits[(bo >> 3) & 255] >> (bo & 4)) & 15) as base.u32) ~mod* 0x11) ~mod- 0x80
bo ~mod+= 4
sx = ((((this.bits[(bo >> 3) & 255] >> (bo & 4)) & 15) as base.u32) ~mod* 0x08) ~mod- 0x40
bo ~mod+= 4
sy = ((((this.bits[(bo >> 3) & 255] >> (bo & 4)) & 15) as base.u32) ~mod* 0x08) ~mod- 0x40
bo ~mod+= 4
nibble = (this.bits[(bo >> 3) & 255] >> (bo & 4)) & 15
this.coeffs[0] = ((nibble as base.u16) ~mod* dcm) ~mod- dcn
bo ~mod+= 4
v00 = BIAS_AND_CLAMP[((sw ~mod- sy) ~mod- sx) & 1023]
v01 = BIAS_AND_CLAMP[((sw ~mod- sy) ~mod+ sx) & 1023]
v10 = BIAS_AND_CLAMP[((sw ~mod+ sy) ~mod- sx) & 1023]
v11 = BIAS_AND_CLAMP[((sw ~mod+ sy) ~mod+ sx) & 1023]
i = 1
while i < num_coeffs {
assert i < 15 via "a < b: a < c; c <= b"(c: num_coeffs)
nibble = (this.bits[(bo >> 3) & 255] >> (bo & 4)) & 15
this.coeffs[ZIGZAG[z][i]] = ((nibble as base.u16) ~mod* acm) ~mod- acn
bo ~mod+= 4
if args.which <> 0 {
// This does what lib/handsum calls biasDown.
v00 = BIAS_AND_CLAMP[((v00 as base.u32) ~mod- 0x88) & 1023]
v01 = BIAS_AND_CLAMP[((v01 as base.u32) ~mod- 0x88) & 1023]
v10 = BIAS_AND_CLAMP[((v10 as base.u32) ~mod- 0x88) & 1023]
v11 = BIAS_AND_CLAMP[((v11 as base.u32) ~mod- 0x88) & 1023]
}
this.buffers[args.which][args.y_offset + y + 0][args.x_offset + (4 * x) + 0] = v00
this.buffers[args.which][args.y_offset + y + 0][args.x_offset + (4 * x) + 4] = v01
this.buffers[args.which][args.y_offset + y + 1][args.x_offset + (4 * x) + 0] = v10
this.buffers[args.which][args.y_offset + y + 1][args.x_offset + (4 * x) + 4] = v11
x += 2
}
y += 2
i += 1
}
this.bit_offset = (bo & 0xFFFF) as base.u16
}
// decode_xblock calls decode_xcoeffs and then performs an Inverse Discrete
// Cosine Transform. The IDCT algorithm is equivalent to the lowleveljpeg Go
// package's BlockU8.InverseDCTFrom code, although Handsum only needs to go up
// to (5, 5) in DCT space, instead of (8, 8).
pri func decoder.decode_xblock!(which: base.u32[..= 1], y_offset: base.u32[..= 8], x_offset: base.u32[..= 32]) {
pri func decoder.decode_block_q0!(which: base.u32[..= 1], y_offset: base.u32[..= 8], x_offset: base.u32[..= 32]) {
var y : base.u32
var x : base.u32
var v : base.u32
@@ -329,7 +322,11 @@ pri func decoder.decode_xblock!(which: base.u32[..= 1], y_offset: base.u32[..= 8
var c_16 : base.u64
var result_0 : base.u64
this.decode_xcoeffs!()
this.decode_zigzag_coeffs!()
// This IDCT (Inverse Discrete Cosine Transform) algorithm is equivalent to
// the lowleveljpeg Go package's BlockU8.InverseDCTFrom code, although
// Handsum only needs to go up to (5, 5) in DCT space, instead of (8, 8).
y = 0
while y < 8 {
@@ -393,37 +390,224 @@ pri func decoder.decode_xblock!(which: base.u32[..= 1], y_offset: base.u32[..= 8
}
}
pri func decoder.decode_xcoeffs!() {
var bo : base.u32
var nibble : base.u8[..= 15]
var i : base.u32
pri func decoder.decode_block_q1!(which: base.u32[..= 1], y_offset: base.u32[..= 8], x_offset: base.u32[..= 32]) {
var i : base.u32
bo = this.bit_offset as base.u32
nibble = (this.bits[(bo >> 3) & 255] >> (bo & 4)) & 15
this.coeffs[0] = ((nibble as base.u16) ~mod- 8) ~mod* 128
bo ~mod+= 4
i = 1
while i < 15 {
nibble = (this.bits[(bo >> 3) & 255] >> (bo & 4)) & 15
this.coeffs[ZIGZAG[i]] = ((nibble as base.u16) ~mod- 8) ~mod* 16
bo ~mod+= 4
i = 0
while i < 4 {
this.decode_zigzag_coeffs!()
this.decode_tile_q1!(
which: args.which,
y_offset: args.y_offset + ((i & 2) << 1),
x_offset: args.x_offset + ((i & 1) << 4))
i += 1
}
this.bit_offset = (bo & 0xFFFF) as base.u16
this.smooth_seams_8x8!(
which: args.which,
y_offset: args.y_offset,
x_offset: args.x_offset)
}
pri func decoder.smooth_luma_block_seams!() {
pri func decoder.decode_tile_q1!(which: base.u32[..= 1], y_offset: base.u32[..= 12], x_offset: base.u32[..= 48]) {
var y : base.u32
var x : base.u32
var v : base.u32
var u : base.u32
var alphas_sum_32 : base.u64
var half_alpha_v_16 : base.u64
var half_alpha_u_16 : base.u64
var alphas_16 : base.u64
var c_32 : base.u64
var c_16 : base.u64
var result_0 : base.u64
// IDCT but for 4×4 tiles instead of 8×8.
y = 0
while y < 4 {
x = 0
while x < 4,
inv y < 4,
{
alphas_sum_32 = 0
v = 0
while v < 4,
inv y < 4,
inv x < 4,
{
half_alpha_v_16 = FIXED_POINT_HALF as base.u64
if v <> 0 {
half_alpha_v_16 = FIXED_POINT_INV_SQRT_2 as base.u64
}
u = 0
while u < 4,
inv y < 4,
inv x < 4,
inv v < 4,
{
half_alpha_u_16 = FIXED_POINT_HALF as base.u64
if u <> 0 {
half_alpha_u_16 = FIXED_POINT_INV_SQRT_2 as base.u64
}
alphas_16 = this.util.sign_extend_rshift_u64(
a: (half_alpha_v_16 ~mod* half_alpha_u_16) ~mod+ (1 << 15),
n: 16)
c_32 = this.util.sign_extend_convert_u32_u64(a: COSINES[(((4 * x) + 2) * u) & 31]) ~mod*
this.util.sign_extend_convert_u32_u64(a: COSINES[(((4 * y) + 2) * v) & 31])
c_16 = this.util.sign_extend_rshift_u64(
a: c_32 ~mod+ (1 << 15),
n: 16)
alphas_sum_32 ~mod+= (alphas_16 ~mod* c_16) ~mod*
this.util.sign_extend_convert_u16_u64(
a: this.coeffs[(4 * v) + u])
u += 1
}
v += 1
}
result_0 = this.util.sign_extend_rshift_u64(
a: alphas_sum_32 ~mod+ (1 << 31),
n: 32)
this.buffers[args.which][args.y_offset + y][args.x_offset + (4 * x)] =
BIAS_AND_CLAMP[result_0 & 1023]
x += 1
}
y += 1
}
}
pri func decoder.decode_block_q3!(which: base.u32[..= 1], y_offset: base.u32[..= 8], x_offset: base.u32[..= 32]) {
var bo : base.u32
var y : base.u32
var x : base.u32
var dct0 : base.u32
var dct1 : base.u32
var dct2 : base.u32
var v00 : base.u8
var v01 : base.u8
var v10 : base.u8
var v11 : base.u8
var v0 : base.u32
var v1 : base.u32
var v8 : base.u32
var v9 : base.u32
bo = this.bit_offset as base.u32
y = 0
while y < 7 {
x = 0
while x < 7,
inv y < 7,
{
dct0 = ((((this.bits[(bo >> 3) & 255] >> (bo & 4)) & 15) as base.u32) ~mod* 0x22) ~mod- 0x100
bo ~mod+= 4
dct1 = ((((this.bits[(bo >> 3) & 255] >> (bo & 4)) & 15) as base.u32) ~mod* 0x10) ~mod- 0x080
bo ~mod+= 4
dct2 = ((((this.bits[(bo >> 3) & 255] >> (bo & 4)) & 15) as base.u32) ~mod* 0x10) ~mod- 0x080
bo ~mod+= 4
// IDCT but for 2×2 tiles instead of 8×8.
v00 = BIAS_AND_CLAMP[((((dct0 ~mod+ dct1) ~mod+ dct2) ~mod+ 1) >> 1) & 1023]
v01 = BIAS_AND_CLAMP[((((dct0 ~mod- dct1) ~mod+ dct2) ~mod+ 1) >> 1) & 1023]
v10 = BIAS_AND_CLAMP[((((dct0 ~mod+ dct1) ~mod- dct2) ~mod+ 1) >> 1) & 1023]
v11 = BIAS_AND_CLAMP[((((dct0 ~mod- dct1) ~mod- dct2) ~mod+ 1) >> 1) & 1023]
this.buffers[args.which][args.y_offset + y + 0][args.x_offset + (4 * x) + 0] = v00
this.buffers[args.which][args.y_offset + y + 0][args.x_offset + (4 * x) + 4] = v01
this.buffers[args.which][args.y_offset + y + 1][args.x_offset + (4 * x) + 0] = v10
this.buffers[args.which][args.y_offset + y + 1][args.x_offset + (4 * x) + 4] = v11
x += 2
}
y += 2
}
this.bit_offset = (bo & 0xFFFF) as base.u16
// Smooth the seams between adjacent 2×2 tiles.
y = 1
while y < 7 {
x = 1
while x < 7,
inv y < 7,
{
v0 = this.buffers[args.which][args.y_offset + y + 0][args.x_offset + (4 * x) + 0] as base.u32
v1 = this.buffers[args.which][args.y_offset + y + 0][args.x_offset + (4 * x) + 4] as base.u32
v9 = this.buffers[args.which][args.y_offset + y + 1][args.x_offset + (4 * x) + 4] as base.u32
v8 = this.buffers[args.which][args.y_offset + y + 1][args.x_offset + (4 * x) + 0] as base.u32
this.buffers[args.which][args.y_offset + y + 0][args.x_offset + (4 * x) + 0] =
(((((((9 ~mod* v0) ~mod+ (3 ~mod* v1)) ~mod+ v9) ~mod+ (3 ~mod* v8)) ~mod+ 8) / 16) & 0xFF) as base.u8
this.buffers[args.which][args.y_offset + y + 0][args.x_offset + (4 * x) + 4] =
(((((((9 ~mod* v1) ~mod+ (3 ~mod* v9)) ~mod+ v8) ~mod+ (3 ~mod* v0)) ~mod+ 8) / 16) & 0xFF) as base.u8
this.buffers[args.which][args.y_offset + y + 1][args.x_offset + (4 * x) + 4] =
(((((((9 ~mod* v9) ~mod+ (3 ~mod* v8)) ~mod+ v0) ~mod+ (3 ~mod* v1)) ~mod+ 8) / 16) & 0xFF) as base.u8
this.buffers[args.which][args.y_offset + y + 1][args.x_offset + (4 * x) + 0] =
(((((((9 ~mod* v8) ~mod+ (3 ~mod* v0)) ~mod+ v1) ~mod+ (3 ~mod* v9)) ~mod+ 8) / 16) & 0xFF) as base.u8
x += 2
}
v0 = this.buffers[args.which][args.y_offset + 0 + 0][args.x_offset + (4 * y) + 0] as base.u32
v1 = this.buffers[args.which][args.y_offset + 0 + 0][args.x_offset + (4 * y) + 4] as base.u32
this.buffers[args.which][args.y_offset + 0 + 0][args.x_offset + (4 * y) + 0] =
(((((3 ~mod* v0) ~mod+ v1) ~mod+ 2) / 4) & 0xFF) as base.u8
this.buffers[args.which][args.y_offset + 0 + 0][args.x_offset + (4 * y) + 4] =
(((((3 ~mod* v1) ~mod+ v0) ~mod+ 2) / 4) & 0xFF) as base.u8
v0 = this.buffers[args.which][args.y_offset + 7 + 0][args.x_offset + (4 * y) + 0] as base.u32
v1 = this.buffers[args.which][args.y_offset + 7 + 0][args.x_offset + (4 * y) + 4] as base.u32
this.buffers[args.which][args.y_offset + 7 + 0][args.x_offset + (4 * y) + 0] =
(((((3 ~mod* v0) ~mod+ v1) ~mod+ 2) / 4) & 0xFF) as base.u8
this.buffers[args.which][args.y_offset + 7 + 0][args.x_offset + (4 * y) + 4] =
(((((3 ~mod* v1) ~mod+ v0) ~mod+ 2) / 4) & 0xFF) as base.u8
v0 = this.buffers[args.which][args.y_offset + y + 0][args.x_offset + (4 * 0) + 0] as base.u32
v1 = this.buffers[args.which][args.y_offset + y + 1][args.x_offset + (4 * 0) + 0] as base.u32
this.buffers[args.which][args.y_offset + y + 0][args.x_offset + (4 * 0) + 0] =
(((((3 ~mod* v0) ~mod+ v1) ~mod+ 2) / 4) & 0xFF) as base.u8
this.buffers[args.which][args.y_offset + y + 1][args.x_offset + (4 * 0) + 0] =
(((((3 ~mod* v1) ~mod+ v0) ~mod+ 2) / 4) & 0xFF) as base.u8
v0 = this.buffers[args.which][args.y_offset + y + 0][args.x_offset + (4 * 7) + 0] as base.u32
v1 = this.buffers[args.which][args.y_offset + y + 1][args.x_offset + (4 * 7) + 0] as base.u32
this.buffers[args.which][args.y_offset + y + 0][args.x_offset + (4 * 7) + 0] =
(((((3 ~mod* v0) ~mod+ v1) ~mod+ 2) / 4) & 0xFF) as base.u8
this.buffers[args.which][args.y_offset + y + 1][args.x_offset + (4 * 7) + 0] =
(((((3 ~mod* v1) ~mod+ v0) ~mod+ 2) / 4) & 0xFF) as base.u8
y += 2
}
}
pri func decoder.smooth_seams_16x16!() {
var i : base.u32
var p0 : base.u8
var p1 : base.u8
var y0 : base.u32[..= 15]
var y1 : base.u32[..= 15]
var x0 : base.u32[..= 15]
var x1 : base.u32[..= 15]
var x0 : base.u32[..= 60]
var x1 : base.u32[..= 60]
var v0 : base.u32[..= 255]
var v1 : base.u32[..= 255]
@@ -443,42 +627,130 @@ pri func decoder.smooth_luma_block_seams!() {
i = 0
while i <= 54 {
p0 = SMOOTHING_PAIRS[i + 0]
p1 = SMOOTHING_PAIRS[i + 1]
p0 = SMOOTHING_PAIRS_16X16[i + 0]
p1 = SMOOTHING_PAIRS_16X16[i + 1]
y0 = (p0 >> 4) as base.u32
y1 = (p1 >> 4) as base.u32
x0 = (p0 & 15) as base.u32
x1 = (p1 & 15) as base.u32
x0 = ((p0 & 15) as base.u32) << 2
x1 = ((p1 & 15) as base.u32) << 2
v0 = this.buffers[0][y0][x0 * 4] as base.u32
v1 = this.buffers[0][y1][x1 * 4] as base.u32
v0 = this.buffers[0][y0][x0] as base.u32
v1 = this.buffers[0][y1][x1] as base.u32
w0 = ((3 * v0) + v1 + 2) / 4
w1 = ((3 * v1) + v0 + 2) / 4
this.buffers[0][y0][x0 * 4] = w0 as base.u8
this.buffers[0][y1][x1 * 4] = w1 as base.u8
this.buffers[0][y0][x0] = w0 as base.u8
this.buffers[0][y1][x1] = w1 as base.u8
i += 2
}
v77 = this.buffers[0][7][7 * 4] as base.u32
v78 = this.buffers[0][7][8 * 4] as base.u32
v88 = this.buffers[0][8][8 * 4] as base.u32
v87 = this.buffers[0][8][7 * 4] as base.u32
v77 = this.buffers[0][7][28] as base.u32
v78 = this.buffers[0][7][32] as base.u32
v88 = this.buffers[0][8][32] as base.u32
v87 = this.buffers[0][8][28] as base.u32
w77 = ((9 * v77) + (3 * v78) + v88 + (3 * v87) + 8) / 16
w78 = ((9 * v78) + (3 * v88) + v87 + (3 * v77) + 8) / 16
w88 = ((9 * v88) + (3 * v87) + v77 + (3 * v78) + 8) / 16
w87 = ((9 * v87) + (3 * v77) + v78 + (3 * v88) + 8) / 16
this.buffers[0][7][7 * 4] = w77 as base.u8
this.buffers[0][7][8 * 4] = w78 as base.u8
this.buffers[0][8][8 * 4] = w88 as base.u8
this.buffers[0][8][7 * 4] = w87 as base.u8
this.buffers[0][7][28] = w77 as base.u8
this.buffers[0][7][32] = w78 as base.u8
this.buffers[0][8][32] = w88 as base.u8
this.buffers[0][8][28] = w87 as base.u8
}
pri func decoder.upsample_8_to_16_chroma!() {
pri func decoder.smooth_seams_8x8!(which: base.u32[..= 1], y_offset: base.u32[..= 8], x_offset: base.u32[..= 32]) {
var i : base.u32
var p0 : base.u8
var p1 : base.u8
var y0 : base.u32[..= 15]
var y1 : base.u32[..= 15]
var x0 : base.u32[..= 60]
var x1 : base.u32[..= 60]
var v0 : base.u32[..= 255]
var v1 : base.u32[..= 255]
var w0 : base.u32[..= 255]
var w1 : base.u32[..= 255]
var v33 : base.u32[..= 255]
var v34 : base.u32[..= 255]
var v44 : base.u32[..= 255]
var v43 : base.u32[..= 255]
var w33 : base.u32[..= 255]
var w34 : base.u32[..= 255]
var w44 : base.u32[..= 255]
var w43 : base.u32[..= 255]
i = 0
while i <= 22 {
p0 = SMOOTHING_PAIRS_8X8[i + 0]
p1 = SMOOTHING_PAIRS_8X8[i + 1]
y0 = args.y_offset + ((p0 >> 3) as base.u32)
y1 = args.y_offset + ((p1 >> 3) as base.u32)
x0 = args.x_offset + (((p0 & 7) as base.u32) << 2)
x1 = args.x_offset + (((p1 & 7) as base.u32) << 2)
v0 = this.buffers[args.which][y0][x0] as base.u32
v1 = this.buffers[args.which][y1][x1] as base.u32
w0 = ((3 * v0) + v1 + 2) / 4
w1 = ((3 * v1) + v0 + 2) / 4
this.buffers[args.which][y0][x0] = w0 as base.u8
this.buffers[args.which][y1][x1] = w1 as base.u8
i += 2
}
v33 = this.buffers[args.which][args.y_offset + 3][args.x_offset + 12] as base.u32
v34 = this.buffers[args.which][args.y_offset + 3][args.x_offset + 16] as base.u32
v44 = this.buffers[args.which][args.y_offset + 4][args.x_offset + 16] as base.u32
v43 = this.buffers[args.which][args.y_offset + 4][args.x_offset + 12] as base.u32
w33 = ((9 * v33) + (3 * v34) + v44 + (3 * v43) + 8) / 16
w34 = ((9 * v34) + (3 * v44) + v43 + (3 * v33) + 8) / 16
w44 = ((9 * v44) + (3 * v43) + v33 + (3 * v34) + 8) / 16
w43 = ((9 * v43) + (3 * v33) + v34 + (3 * v44) + 8) / 16
this.buffers[args.which][args.y_offset + 3][args.x_offset + 12] = w33 as base.u8
this.buffers[args.which][args.y_offset + 3][args.x_offset + 16] = w34 as base.u8
this.buffers[args.which][args.y_offset + 4][args.x_offset + 16] = w44 as base.u8
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].
pri func decoder.scale_and_bias_chroma_down!() {
var y : base.u32
var x : base.u32
y = 0
while y < 8 {
x = 0
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]]
x += 1
}
y += 1
}
}
// upsample_chroma converts the 8×8 Chroma samples in this.buffers[1] to 16×16
// Chroma samples in this.buffers[0], adjacent to the existing 16×16 Luma
// samples in this.buffers[0].
pri func decoder.upsample_chroma!() {
var y : base.u32
var dy : base.u32
var y0 : base.u32[..= 7]
@@ -520,65 +792,15 @@ pri func decoder.upsample_8_to_16_chroma!() {
}
}
pri func decoder.upsample_16_to_32_bgr!() {
var y : base.u32
var dy : base.u32
var y0 : base.u32[..= 15]
var y1 : base.u32[..= 15]
var x : base.u32
var dx : base.u32
var x0 : base.u32[..= 15]
var x1 : base.u32[..= 15]
y = 0
while y < 32 {
dy = (((y & 1) * 2) ~mod- 1)
y0 = y >> 1
y1 = CLAMP_15[(y0 ~mod+ dy) & 63] as base.u32
x = 0
while x < 32,
inv y < 32,
{
dx = (((x & 1) * 2) ~mod- 1)
x0 = x >> 1
x1 = CLAMP_15[(x0 ~mod+ dx) & 63] as base.u32
this.buffers[1][y][(4 * x) + 0] = ((
((this.buffers[0][y0][(4 * x0) + 0] as base.u32) * 9) +
((this.buffers[0][y0][(4 * x1) + 0] as base.u32) * 3) +
((this.buffers[0][y1][(4 * x0) + 0] as base.u32) * 3) +
(this.buffers[0][y1][(4 * x1) + 0] as base.u32) + 8) / 16) as base.u8
this.buffers[1][y][(4 * x) + 1] = ((
((this.buffers[0][y0][(4 * x0) + 1] as base.u32) * 9) +
((this.buffers[0][y0][(4 * x1) + 1] as base.u32) * 3) +
((this.buffers[0][y1][(4 * x0) + 1] as base.u32) * 3) +
(this.buffers[0][y1][(4 * x1) + 1] as base.u32) + 8) / 16) as base.u8
this.buffers[1][y][(4 * x) + 2] = ((
((this.buffers[0][y0][(4 * x0) + 2] as base.u32) * 9) +
((this.buffers[0][y0][(4 * x1) + 2] as base.u32) * 3) +
((this.buffers[0][y1][(4 * x0) + 2] as base.u32) * 3) +
(this.buffers[0][y1][(4 * x1) + 2] as base.u32) + 8) / 16) as base.u8
this.buffers[1][y][(4 * x) + 3] = 0xFF
x += 1
}
y += 1
}
}
pri func decoder.convert_32_bgr_to_y!(which: base.u32[..= 1]) {
pri func decoder.convert_yxxx_to_y!(which: base.u32[..= 1]) {
var y : base.u32
var x : base.u32
y = 0
while y < 32 {
while y < 16 {
x = 1
while x < 32,
inv y < 32,
while x < 16,
inv y < 16,
{
this.buffers[args.which][y][x] = this.buffers[args.which][y][4 * x]
@@ -588,28 +810,7 @@ pri func decoder.convert_32_bgr_to_y!(which: base.u32[..= 1]) {
}
}
pri func decoder.convert_16_y_to_bgr!() {
var y : base.u32
var x : base.u32
var gray : base.u8
y = 0
while y < 16 {
x = 0
while x < 16,
inv y < 16,
{
gray = this.buffers[0][y][(4 * x) + 0]
this.buffers[0][y][(4 * x) + 1] = gray
this.buffers[0][y][(4 * x) + 2] = gray
x += 1
}
y += 1
}
}
pri func decoder.convert_16_ycc_to_bgr!() {
pri func decoder.convert_yccx_to_bgrx!() {
var y : base.u32
var x : base.u32
var yy1 : base.u32
@@ -663,9 +864,9 @@ pri func decoder.convert_16_ycc_to_bgr!() {
}
}
pri func decoder.scale_32_horizontal!() {
pri func decoder.scale_horizontal!() {
var y : base.u32
var dstx : base.u32[..= 31]
var dstx : base.u32[..= 15]
var srcx : base.u32
var acc0 : base.u32
var acc1 : base.u32
@@ -673,23 +874,23 @@ pri func decoder.scale_32_horizontal!() {
var s0 : base.u32[..= 0xFF]
var s1 : base.u32[..= 0xFF]
var s2 : base.u32[..= 0xFF]
var remainder : base.u32[..= 32]
var partial : base.u32[..= 32]
var remainder : base.u32[..= 16]
var partial : base.u32[..= 16]
y = 0
while y < 32 {
while y < 16 {
dstx = 0
srcx = 0
acc0 = 0
acc1 = 0
acc2 = 0
remainder = 32
while srcx < 32,
inv y < 32,
remainder = 16
while srcx < 16,
inv y < 16,
{
s0 = this.buffers[1][y][(4 * srcx) + 0] as base.u32
s1 = this.buffers[1][y][(4 * srcx) + 1] as base.u32
s2 = this.buffers[1][y][(4 * srcx) + 2] as base.u32
s0 = this.buffers[0][y][(4 * srcx) + 0] as base.u32
s1 = this.buffers[0][y][(4 * srcx) + 1] as base.u32
s2 = this.buffers[0][y][(4 * srcx) + 2] as base.u32
if remainder > this.width {
remainder -= this.width
@@ -704,11 +905,11 @@ pri func decoder.scale_32_horizontal!() {
acc1 ~mod+= remainder * s1
acc2 ~mod+= remainder * s2
this.buffers[0][y][(4 * dstx) + 0] = (((acc0 ~mod+ 16) / 32) & 0xFF) as base.u8
this.buffers[0][y][(4 * dstx) + 1] = (((acc1 ~mod+ 16) / 32) & 0xFF) as base.u8
this.buffers[0][y][(4 * dstx) + 2] = (((acc2 ~mod+ 16) / 32) & 0xFF) as base.u8
this.buffers[0][y][(4 * dstx) + 3] = 0xFF
dstx = (dstx + 1) & 31
this.buffers[1][y][(4 * dstx) + 0] = (((acc0 ~mod+ 8) / 16) & 0xFF) as base.u8
this.buffers[1][y][(4 * dstx) + 1] = (((acc1 ~mod+ 8) / 16) & 0xFF) as base.u8
this.buffers[1][y][(4 * dstx) + 2] = (((acc2 ~mod+ 8) / 16) & 0xFF) as base.u8
this.buffers[1][y][(4 * dstx) + 3] = 0xFF
dstx = (dstx + 1) & 15
partial = this.width - remainder
@@ -716,7 +917,7 @@ pri func decoder.scale_32_horizontal!() {
acc1 = partial * s1
acc2 = partial * s2
remainder = 32 - partial
remainder = 16 - partial
}
srcx += 1
@@ -725,9 +926,9 @@ pri func decoder.scale_32_horizontal!() {
}
}
pri func decoder.scale_32_vertical!() {
pri func decoder.scale_vertical!() {
var x : base.u32
var dsty : base.u32[..= 31]
var dsty : base.u32[..= 15]
var srcy : base.u32
var acc0 : base.u32
var acc1 : base.u32
@@ -735,23 +936,23 @@ pri func decoder.scale_32_vertical!() {
var s0 : base.u32[..= 0xFF]
var s1 : base.u32[..= 0xFF]
var s2 : base.u32[..= 0xFF]
var remainder : base.u32[..= 32]
var partial : base.u32[..= 32]
var remainder : base.u32[..= 16]
var partial : base.u32[..= 16]
x = 0
while x < 32 {
while x < 16 {
dsty = 0
srcy = 0
acc0 = 0
acc1 = 0
acc2 = 0
remainder = 32
while srcy < 32,
inv x < 32,
remainder = 16
while srcy < 16,
inv x < 16,
{
s0 = this.buffers[1][srcy][(4 * x) + 0] as base.u32
s1 = this.buffers[1][srcy][(4 * x) + 1] as base.u32
s2 = this.buffers[1][srcy][(4 * x) + 2] as base.u32
s0 = this.buffers[0][srcy][(4 * x) + 0] as base.u32
s1 = this.buffers[0][srcy][(4 * x) + 1] as base.u32
s2 = this.buffers[0][srcy][(4 * x) + 2] as base.u32
if remainder > this.height {
remainder -= this.height
@@ -766,11 +967,11 @@ pri func decoder.scale_32_vertical!() {
acc1 ~mod+= remainder * s1
acc2 ~mod+= remainder * s2
this.buffers[0][dsty][(4 * x) + 0] = (((acc0 ~mod+ 16) / 32) & 0xFF) as base.u8
this.buffers[0][dsty][(4 * x) + 1] = (((acc1 ~mod+ 16) / 32) & 0xFF) as base.u8
this.buffers[0][dsty][(4 * x) + 2] = (((acc2 ~mod+ 16) / 32) & 0xFF) as base.u8
this.buffers[0][dsty][(4 * x) + 3] = 0xFF
dsty = (dsty + 1) & 31
this.buffers[1][dsty][(4 * x) + 0] = (((acc0 ~mod+ 8) / 16) & 0xFF) as base.u8
this.buffers[1][dsty][(4 * x) + 1] = (((acc1 ~mod+ 8) / 16) & 0xFF) as base.u8
this.buffers[1][dsty][(4 * x) + 2] = (((acc2 ~mod+ 8) / 16) & 0xFF) as base.u8
this.buffers[1][dsty][(4 * x) + 3] = 0xFF
dsty = (dsty + 1) & 15
partial = this.height - remainder
@@ -778,7 +979,7 @@ pri func decoder.scale_32_vertical!() {
acc1 = partial * s1
acc2 = partial * s2
remainder = 32 - partial
remainder = 16 - partial
}
srcy += 1
@@ -810,12 +1011,12 @@ pri func decoder.from_pixels_to_dst!(dst: ptr base.pixel_buffer, which: base.u32
tab = args.dst.plane(p: 0)
src_bytes_per_pixel = 1
if (this.variant & 1) <> 0 {
if this.color <> 0 {
src_bytes_per_pixel = 4
}
while y < this.height {
assert y < 32 via "a < b: a < c; c <= b"(c: this.height)
assert y < 16 via "a < b: a < c; c <= b"(c: this.height)
src = this.buffers[args.which][y][.. this.width * src_bytes_per_pixel]
dst = tab.row_u32(y: y)
@@ -883,8 +1084,14 @@ pub func decoder.workbuf_len() base.range_ii_u64 {
return this.util.make_range_ii_u64(min_incl: 0, max_incl: 0)
}
pri const PAYLOAD_SIZES : roarray[4] base.u32[..= 144] = [
30, 45, 96, 144,
pri const PAYLOAD_SIZES : roarray[2] roarray[4] base.u32[..= 144] = [[
30, 48, 80, 96,
],[
45, 72, 120, 144,
]]
pri const NUM_COEFFS : roarray[4] base.u32[..= 15] = [
15, 6, 10, 3,
]
pri const CLAMP_7 : roarray[32] base.u8[..= 7] = [
@@ -894,21 +1101,36 @@ pri const CLAMP_7 : roarray[32] base.u8[..= 7] = [
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
]
pri const CLAMP_15 : roarray[64] base.u8[..= 15] = [
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
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,
]
// For commentary on these constants below, see the lib/handsum and
// lib/lowleveljpeg Go packages.
pri const ZIGZAG : roarray[15] base.u8[..= 39] = [
pri const ZIGZAG : roarray[2] roarray[15] base.u8[..= 39] = [[
0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4,
],[
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 SMOOTHING_PAIRS : roarray[56] base.u8 = [
pri const SMOOTHING_PAIRS_16X16 : roarray[56] base.u8 = [
0x07, 0x08,
0x17, 0x18,
0x27, 0x28,
@@ -942,42 +1164,61 @@ pri const SMOOTHING_PAIRS : roarray[56] base.u8 = [
0xF7, 0xF8,
]
pri const SMOOTHING_PAIRS_8X8 : roarray[24] base.u8[..= 0x3F] = [
0x03, 0x04,
0x0B, 0x0C,
0x13, 0x14,
0x18, 0x20,
0x19, 0x21,
0x1A, 0x22,
0x1D, 0x25,
0x1E, 0x26,
0x1F, 0x27,
0x2B, 0x2C,
0x33, 0x34,
0x3B, 0x3C,
]
pri const FIXED_POINT_INV_SQRT_2 : base.u16 = 0xB505
pri const FIXED_POINT_HALF : base.u16 = 0x8000
pri const FIXED_POINT_INV_2_SQRT_2 : base.u16 = 0x5A82
pri const COSINES : roarray[32] base.u32 = [
0x0001_0000,
0x0000_FB14,
0x0000_FB15,
0x0000_EC83,
0x0000_D4DB,
0x0000_B504,
0x0000_8E39,
0x0000_61F7,
0x0000_B505,
0x0000_8E3A,
0x0000_61F8,
0x0000_31F1,
0x0000_0000,
0xFFFF_CE0F,
0xFFFF_9E09,
0xFFFF_71C7,
0xFFFF_4AFC,
0xFFFF_9E08,
0xFFFF_71C6,
0xFFFF_4AFB,
0xFFFF_2B25,
0xFFFF_137D,
0xFFFF_04EC,
0xFFFF_04EB,
0xFFFF_0000,
0xFFFF_04EC,
0xFFFF_04EB,
0xFFFF_137D,
0xFFFF_2B25,
0xFFFF_4AFC,
0xFFFF_71C7,
0xFFFF_9E09,
0xFFFF_4AFB,
0xFFFF_71C6,
0xFFFF_9E08,
0xFFFF_CE0F,
0x0000_0000,
0x0000_31F1,
0x0000_61F7,
0x0000_8E39,
0x0000_B504,
0x0000_61F8,
0x0000_8E3A,
0x0000_B505,
0x0000_D4DB,
0x0000_EC83,
0x0000_FB14,
0x0000_FB15,
]
pri const BIAS_AND_CLAMP : roarray[1024] base.u8 = [
+14 -14
View File
@@ -66,7 +66,7 @@ the first "./a.out" with "./a.out -bench". Combine these changes with the
// ---------------- Handsum Tests
const char* //
test_wuffs_handsum_decode_interface_hvpc() {
test_wuffs_handsum_decode_interface_g0() {
CHECK_FOCUS(__func__);
wuffs_handsum__decoder dec;
CHECK_STATUS("initialize",
@@ -75,11 +75,11 @@ test_wuffs_handsum_decode_interface_hvpc() {
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
return do_test__wuffs_base__image_decoder(
wuffs_handsum__decoder__upcast_as__wuffs_base__image_decoder(&dec),
"test/data/bricks-color.hvpc.handsum", 0, SIZE_MAX, 32, 24, 0xFF052A90);
"test/data/bricks-gray.g0.handsum", 0, SIZE_MAX, 16, 12, 0xFF040404);
}
const char* //
test_wuffs_handsum_decode_interface_hvpg() {
test_wuffs_handsum_decode_interface_r1() {
CHECK_FOCUS(__func__);
wuffs_handsum__decoder dec;
CHECK_STATUS("initialize",
@@ -88,11 +88,11 @@ test_wuffs_handsum_decode_interface_hvpg() {
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
return do_test__wuffs_base__image_decoder(
wuffs_handsum__decoder__upcast_as__wuffs_base__image_decoder(&dec),
"test/data/bricks-gray.hvpg.handsum", 0, SIZE_MAX, 32, 24, 0xFF010101);
"test/data/bricks-color.r1.handsum", 0, SIZE_MAX, 16, 12, 0xFF313D58);
}
const char* //
test_wuffs_handsum_decode_interface_hvxc() {
test_wuffs_handsum_decode_interface_g2() {
CHECK_FOCUS(__func__);
wuffs_handsum__decoder dec;
CHECK_STATUS("initialize",
@@ -101,11 +101,11 @@ test_wuffs_handsum_decode_interface_hvxc() {
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
return do_test__wuffs_base__image_decoder(
wuffs_handsum__decoder__upcast_as__wuffs_base__image_decoder(&dec),
"test/data/bricks-color.hvxc.handsum", 0, SIZE_MAX, 32, 24, 0xFF571218);
"test/data/bricks-gray.g2.handsum", 0, SIZE_MAX, 16, 12, 0xFF101010);
}
const char* //
test_wuffs_handsum_decode_interface_hvxg() {
test_wuffs_handsum_decode_interface_r3() {
CHECK_FOCUS(__func__);
wuffs_handsum__decoder dec;
CHECK_STATUS("initialize",
@@ -114,7 +114,7 @@ test_wuffs_handsum_decode_interface_hvxg() {
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
return do_test__wuffs_base__image_decoder(
wuffs_handsum__decoder__upcast_as__wuffs_base__image_decoder(&dec),
"test/data/bricks-gray.hvxg.handsum", 0, SIZE_MAX, 32, 24, 0xFF0D0D0D);
"test/data/bricks-color.r3.handsum", 0, SIZE_MAX, 16, 12, 0xFF0B337D);
}
const char* //
@@ -158,13 +158,13 @@ test_wuffs_handsum_decode_frame_config() {
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
.data = g_src_slice_u8,
});
CHECK_STRING(read_file(&src, "test/data/mona-lisa.21x32.hvxc.handsum"));
CHECK_STRING(read_file(&src, "test/data/mona-lisa.21x32.r3.handsum"));
CHECK_STATUS("decode_frame_config #0",
wuffs_handsum__decoder__decode_frame_config(&dec, &fc, &src));
uint32_t have = wuffs_base__frame_config__width(&fc);
uint32_t want = 21;
uint32_t want = 11;
if (have != want) {
RETURN_FAIL("width: have %u, want %u", have, want);
}
@@ -203,10 +203,10 @@ test_wuffs_handsum_decode_frame_config() {
proc g_tests[] = {
test_wuffs_handsum_decode_frame_config,
test_wuffs_handsum_decode_interface_hvpc,
test_wuffs_handsum_decode_interface_hvpg,
test_wuffs_handsum_decode_interface_hvxc,
test_wuffs_handsum_decode_interface_hvxg,
test_wuffs_handsum_decode_interface_g0,
test_wuffs_handsum_decode_interface_r1,
test_wuffs_handsum_decode_interface_g2,
test_wuffs_handsum_decode_interface_r3,
test_wuffs_handsum_decode_truncated_input,
#ifdef WUFFS_MIMIC
-1
View File
@@ -1 +0,0 @@
ţ×וséĆ/Ą\ë„XY—WcŁFf—iĄS)z8‡’H|C#—’K¦rXš–7xbH;Ł(—–gxC9í†Hv•|Íd#Hö��f?ăĂeGv?´˛9…‰xa’'�x7fbHź–DČQ'z{�ÇŞ©uZxyę—cZ™Ţ{Š�kąhi“Ť•zŠvhhćČzZšĹx"µd�µVč�o§
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
þ׋†¼“‡§ŠˆHˆ—˜›‰¨˜uxºh{ixHކ{xwv‰»§†¬˜†©Y—§SV´§v
+1
View File
@@ -0,0 +1 @@
ţ׫UÚ‡7ź…¦�h�š†Ô{ĽC—‡Dy§´›z¦Šwe“şÔŐ‡&mYćRi�‰h噋Sz¶úk¦»{śTÚęIÍpoŐ¨ăSË6…đb
+1
View File
@@ -0,0 +1 @@
ţ×ËUÚ‡��7ź…‡h¦�h‰‡�š†i‰Ô{ĽŞ‡C—‡™�Dy§‰š´›z†x¦Šw��e“ş—yÔŐ‡�‰&mYx�ćRi™‡�‰hx�噋†–Sz¶�yúk¦gZ»{§—śTÚÇ‹ęIÍe•poş·Ő¨ăK�SË6Y“…đb‡o
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
�ラ sャ迫ヲzx(汚剱汚冱wケx及x(合休ww�
+1
View File
@@ -0,0 +1 @@
ўз+cк�%����x���в{Ыa��RyЈВ�zЃ�wR�ЊТХw4lhдSh��xг�{ayЇ
+1
View File
@@ -0,0 +1 @@
ţ×KcÚ‡�‡%ꔆh“�x‰�‚š‡x�Ň{ËŞ‡a—�™�Ry¨‰š˛‹z‡xىw��R“Ş—yÂĹw�‰4lhx�ÔSh����xx�Ó™{‡–ay§�y
+1
View File
@@ -0,0 +1 @@
þ×krMø©ðr45‚8¶ƒ9«b)ªs8{¡—ôˆ€(…‰�&{‘(vt˜¡(Öq‰ƒ)™¡(Tƒ(šrDD’©hˆ¤!MQKÉ”[qІH®€ˆ¥«�(bt,I�—
-1
View File
@@ -1 +0,0 @@
þ×—’Dö¨’,Û�8j“7u¡'g“9–qyˆ€‹A˜�*•q(š”ˆp(;‘˜“(‡ã†¢LÍrgóiˆtıFGtµ�‡†Hb€ˆufp(®”$Èpy
-1
View File
@@ -1 +0,0 @@
ţ×#˙ŕÁđ_Z(›Öëď~ůŰ#4ţ'oG&źˇ_8T1z
+1
View File
@@ -0,0 +1 @@
þ×ërMø©ðr45‚8¶ƒ9«b)ªs8{¡—ôˆ€(…‰�&{‘(vt˜¡(Öq‰ƒ)™¡(Tƒ(šrDD’©hˆ¤!MQKÉ”[qІH®€ˆ¥«�(bt,I�—ˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆ
-2
View File
@@ -1,2 +0,0 @@
þ×ô‡z¨‡{‡§„YG•˜¤VxTw*”Y‡“ˆý–v¨—{¸[/¸—‡%|¥fX>¸Äf¨µHd³f
s6˜ƒ+‡q'j¦fv�y‚X40ˆ’Hk�x‘8zc*—�'Šqx�y‡hw‡yˆ‡w…·vx‡y§˜Š—xyÈ˜šˆˆ™ªx‰˜ˆ™Ši‰˜‰—xˆ—y˜˜h‰‡‰
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
þךv‹švXˆ™h¶yª¦†™—c{‰˜¹Yy(¸ˆŠ‰Š™˜w”˜yˆˆˆ—y‡wˆˆˆ˜
+1
View File
@@ -0,0 +1 @@
ţ×ú‡vh‡u‰wŚ·Ç›xdZ�´yćuWŠ„�†zh‡vhôUâhš‰ô;”uj¸ř2hUjxUH¬Skö“;x�%™’)¶fjš�—’,ąŐ?�‚H¦‘�q8–Ł&y�)—‘��—•X»†W�–Zž&l™‡vJx„j©gx”��—E¨†x‰Ą…ş†XŠš¨‰š§y©Č™‹‡
+11 -6
View File
@@ -55,13 +55,15 @@ OK. 076cb375 test/data/bricks-color.bmp
OK. bdbbfadb test/data/bricks-color.etc1.pkm
OK. 41e6110e test/data/bricks-color.etc1s.pkm
OK. 5670f263 test/data/bricks-color.etc2.pkm
OK. 0fffe1d3 test/data/bricks-color.hvpc.handsum
OK. 1fef6814 test/data/bricks-color.hvxc.handsum
OK. 72a1f9cc test/data/bricks-color.jpeg
OK. 076cb375 test/data/bricks-color.lossless.webp
OK. 9d451b1c test/data/bricks-color.lossy.webp
OK. 076cb375 test/data/bricks-color.png
OK. 076cb375 test/data/bricks-color.qoi
OK. 1bb2c55a test/data/bricks-color.r0.handsum
OK. 74bb07e1 test/data/bricks-color.r1.handsum
OK. 43dd4660 test/data/bricks-color.r2.handsum
OK. 79b8bd57 test/data/bricks-color.r3.handsum
OK. 076cb375 test/data/bricks-color.tga
OK. f36c2e80 test/data/bricks-dither.bmp
OK. f36c2e80 test/data/bricks-dither.gif
@@ -69,14 +71,17 @@ OK. f36c2e80 test/data/bricks-dither.lossless.webp
OK. f36c2e80 test/data/bricks-dither.no-ancillary.png
OK. f36c2e80 test/data/bricks-dither.png
OK. c2bce675 test/data/bricks-gray.bmp
OK. 00db551d test/data/bricks-gray.g0.handsum
OK. 5c979d98 test/data/bricks-gray.g1.handsum
OK. 23430f55 test/data/bricks-gray.g2.handsum
OK. 6065d955 test/data/bricks-gray.g3.handsum
OK. c2bce675 test/data/bricks-gray.gif
OK. 46a6768e test/data/bricks-gray.hvpg.handsum
OK. cd16ce62 test/data/bricks-gray.hvxg.handsum
OK. 3a2478ad test/data/bricks-gray.jpeg
OK. c2bce675 test/data/bricks-gray.lossless.webp
OK. 9d451b1c test/data/bricks-gray.lossy.webp
OK. c2bce675 test/data/bricks-gray.no-ancillary.png
OK. c2bce675 test/data/bricks-gray.png
OK. 6065d955 test/data/bricks-gray.r3.handsum
OK. c2bce675 test/data/bricks-gray.tga
OK. 7aebfe6c test/data/bricks-nodither.bmp
OK. 7aebfe6c test/data/bricks-nodither.gif
@@ -133,8 +138,6 @@ OK. ed4b78fc test/data/hippopotamus.regular.gif
OK. dcbb225a test/data/hippopotamus.regular.png
BAD e4c5926b test/data/hippopotamus.regular.truncated.png
OK. f6bb81e2 test/data/mona-lisa.21x32.etc2.pkm
OK. 7f351b34 test/data/mona-lisa.21x32.hvpc.handsum
OK. b507f884 test/data/mona-lisa.21x32.hvxc.handsum
OK. 012ce4cf test/data/mona-lisa.21x32.lossless.webp
OK. 012ce4cf test/data/mona-lisa.21x32.png
OK. e8aeb873 test/data/mona-lisa.21x32.q0.lossy.webp
@@ -144,6 +147,8 @@ OK. e8aeb873 test/data/mona-lisa.21x32.q50.lossy.webp
OK. 059ecb80 test/data/mona-lisa.21x32.q90.jpeg
OK. e8aeb873 test/data/mona-lisa.21x32.q90.lossy.webp
OK. 012ce4cf test/data/mona-lisa.21x32.qoi
OK. 57441dc9 test/data/mona-lisa.21x32.r0.handsum
OK. 39d18fce test/data/mona-lisa.21x32.r3.handsum
OK. 12fc69a5 test/data/mona-lisa.21x32.th
OK. 2dccfe56 test/data/muybridge-frame-000.wbmp
OK. db2733f5 test/data/muybridge.apng