mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-26 17:01:35 +01:00
std/handsum: tweak magic identifier bytes
This commit is contained in:
1 parent
acbf9d2ecf
commit
38a5e853c9
17 files changed
+153
-78
No files matched your search
+7
-5
@@ -40,8 +40,8 @@ var (
|
|||||||
roundtripFlag = flag.Bool("roundtrip", false, "whether to encode-and-decode the input")
|
roundtripFlag = flag.Bool("roundtrip", false, "whether to encode-and-decode the input")
|
||||||
|
|
||||||
bFlag = flag.String("b", "gray", "encoding background color: e.g. red, white, 9c27b0 or #ff8")
|
bFlag = flag.String("b", "gray", "encoding background color: e.g. red, white, 9c27b0 or #ff8")
|
||||||
cFlag = flag.String("c", "rgb", "encoding color: gray or rgb [default]")
|
cFlag = flag.String("c", "rgb", "encoding color: gray (1), rgb (3, default) or rgba (4)")
|
||||||
qFlag = flag.Int("q", 3, "encoding quality: 0, 1, 2 or 3 [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.
|
const usageStr = `handsum decodes and encodes the Handsum lossy image file format.
|
||||||
@@ -75,8 +75,8 @@ Flags:
|
|||||||
-roundtrip
|
-roundtrip
|
||||||
|
|
||||||
-b encoding background color: e.g. red, white, 9c27b0 or #ff8
|
-b encoding background color: e.g. red, white, 9c27b0 or #ff8
|
||||||
-c encoding color: gray or rgb [default]
|
-c encoding color: gray (1), rgb (3, default) or rgba (4)
|
||||||
-q encoding quality: 0, 1, 2 or 3 [default]
|
-q encoding quality: 0, 1, 2 or 3 (default)
|
||||||
`
|
`
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -92,8 +92,10 @@ func main1() error {
|
|||||||
|
|
||||||
color := handsum.ColorRGB
|
color := handsum.ColorRGB
|
||||||
switch *cFlag {
|
switch *cFlag {
|
||||||
case "0", "GRAY", "Gray", "gray":
|
case "1", "GRAY", "Gray", "gray":
|
||||||
color = handsum.ColorGray
|
color = handsum.ColorGray
|
||||||
|
case "4", "RGBA", "Rgba", "rgba":
|
||||||
|
color = handsum.ColorRGBA
|
||||||
}
|
}
|
||||||
quality := handsum.Quality(max(0, min(3, *qFlag)))
|
quality := handsum.Quality(max(0, min(3, *qFlag)))
|
||||||
|
|
||||||
|
|||||||
@@ -175,6 +175,7 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
|
|||||||
{+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG
|
{+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG
|
||||||
{+0x54482020, "\x02\xC3\xBE\xFE"}, // TH
|
{+0x54482020, "\x02\xC3\xBE\xFE"}, // TH
|
||||||
{+0x585A2020, "\x04\xFD\x37\x7A\x58\x5A"}, // XZ
|
{+0x585A2020, "\x04\xFD\x37\x7A\x58\x5A"}, // XZ
|
||||||
|
{+0x484E534D, "\x01\xFE\xD6"}, // HANDSUM
|
||||||
{+0x484E534D, "\x01\xFE\xD7"}, // HANDSUM
|
{+0x484E534D, "\x01\xFE\xD7"}, // HANDSUM
|
||||||
{+0x4A504547, "\x01\xFF\xD8"}, // JPEG
|
{+0x4A504547, "\x01\xFF\xD8"}, // JPEG
|
||||||
};
|
};
|
||||||
|
|||||||
+77
-27
@@ -15,9 +15,9 @@
|
|||||||
// This is a very lossy format for very small thumbnails. Very small in terms
|
// This is a very lossy format for very small thumbnails. Very small in terms
|
||||||
// of image dimensions, up to 16×16 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 two color settings (Gray and RGB) and four quality
|
// The file format has three color settings (Gray, RGB and RGBA) and four
|
||||||
// settings. For any given color-and-quality combination, every Handsum image
|
// quality settings. For any given color-and-quality combination, every Handsum
|
||||||
// file with those settings is a fixed number of bytes. For color=Gray:
|
// image file with those settings is a fixed number of bytes. For color=Gray:
|
||||||
//
|
//
|
||||||
// - A quality=0 file is 33 bytes long.
|
// - A quality=0 file is 33 bytes long.
|
||||||
// - A quality=1 file is 51 bytes long.
|
// - A quality=1 file is 51 bytes long.
|
||||||
@@ -31,6 +31,13 @@
|
|||||||
// - A quality=2 file is 123 bytes long.
|
// - A quality=2 file is 123 bytes long.
|
||||||
// - A quality=3 file is 147 bytes long.
|
// - A quality=3 file is 147 bytes long.
|
||||||
//
|
//
|
||||||
|
// For color=RGBA:
|
||||||
|
//
|
||||||
|
// - A quality=0 file is 72 bytes long.
|
||||||
|
// - A quality=1 file is 99 bytes long.
|
||||||
|
// - A quality=2 file is 147 bytes long.
|
||||||
|
// - A quality=3 file is 171 bytes long.
|
||||||
|
//
|
||||||
// Every Gray/q0 image file is exactly 48 bytes (384 bits) long. For a 16×16
|
// 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.
|
// pixel image, this uses 1.5 bits (0.1875 bytes) per pixel.
|
||||||
//
|
//
|
||||||
@@ -38,10 +45,10 @@
|
|||||||
// 4.59375 bits per pixel for a 16×16 pixel image (a 1:1 aspect ratio), or
|
// 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).
|
// 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
|
// A Handsum file's starts with a 3 byte header: a 15-bit magic signature, a
|
||||||
// 1-bit color, a 2-bit quality and a 5-bit aspect ratio. An image's longest
|
// 2-bit color (Gray, RGB or RGBA), a 2-bit quality and a 5-bit aspect ratio.
|
||||||
// dimension (width or height) is 16 pixels and the aspect ratio gives the
|
// An image's longest dimension (width or height) is 16 pixels and the aspect
|
||||||
// shorter dimension.
|
// ratio gives the shorter dimension.
|
||||||
//
|
//
|
||||||
// The color=RGB 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
|
// 4:2:0 JPEG MCU (Minimum Coded Unit), 4 Luma and 2 Chroma blocks. Each block
|
||||||
@@ -136,13 +143,19 @@ import (
|
|||||||
// that is no greater than 16.
|
// that is no greater than 16.
|
||||||
const MaxDimension = 16
|
const MaxDimension = 16
|
||||||
|
|
||||||
// Magic is the byte string prefix of every Handsum image file.
|
// MagicEtc is the byte string prefix of every Handsum image file. A Gray image
|
||||||
|
// starts with Magic0. An RGB or RGBA image starts with Magic1. The two 16-bit
|
||||||
|
// strings only differ in their final bit.
|
||||||
//
|
//
|
||||||
// It's like how every JPEG image file starts with "\xFF\xD8".
|
// It's like how every JPEG image file starts with "\xFF\xD8".
|
||||||
const Magic = "\xFE\xD7"
|
const (
|
||||||
|
Magic0 = "\xFE\xD6"
|
||||||
|
Magic1 = "\xFE\xD7"
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
image.RegisterFormat("handsum", Magic, Decode, DecodeConfig)
|
image.RegisterFormat("handsum", Magic0, Decode, DecodeConfig)
|
||||||
|
image.RegisterFormat("handsum", Magic1, Decode, DecodeConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -156,20 +169,32 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func fileSize(c Color, q Quality) int {
|
func fileSize(c Color, q Quality) int {
|
||||||
// 33, 51, 83, 99. 48, 75, 123, 147.
|
// 33, 51, 83, 99.
|
||||||
return int("\x21\x33\x53\x63\x30\x4B\x7B\x93"[(int(c&1)<<2)|int(q&3)])
|
// 0, 0, 0, 0.
|
||||||
|
// 48, 75, 123, 147.
|
||||||
|
// 72, 99, 147, 171.
|
||||||
|
return int(("" +
|
||||||
|
"\x21\x33\x53\x63" +
|
||||||
|
"\x00\x00\x00\x00" +
|
||||||
|
"\x30\x4B\x7B\x93" +
|
||||||
|
"\x48\x63\x93\xAB")[(int((c-1)&3)<<2)|int(q&3)])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Color is a Handsum image's color setting, either 0 (Gray) or 1 (RGB).
|
// Color is a Handsum image's color setting, either 1 (Gray), 3 (RGB) or 4
|
||||||
|
// (RGBA).
|
||||||
type Color uint8
|
type Color uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ColorGray = Color(0)
|
ColorGray = Color(1)
|
||||||
ColorRGB = Color(1)
|
ColorRGB = Color(3)
|
||||||
|
ColorRGBA = Color(4)
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c Color) numberOfBlocks() int {
|
func (c Color) numberOfBlocks() int {
|
||||||
return int("\x04\x06"[c&1])
|
if c == ColorGray {
|
||||||
|
return 4
|
||||||
|
}
|
||||||
|
return 6
|
||||||
}
|
}
|
||||||
|
|
||||||
// OptionColor is an option type, what Rust would call an Option<Color>.
|
// OptionColor is an option type, what Rust would call an Option<Color>.
|
||||||
@@ -180,8 +205,11 @@ type OptionColor struct {
|
|||||||
// MakeOptionColor returns an option value that is Some(c), instead of the
|
// MakeOptionColor returns an option value that is Some(c), instead of the
|
||||||
// OptionColor zero-value, which is None.
|
// OptionColor zero-value, which is None.
|
||||||
func MakeOptionColor(c Color) OptionColor {
|
func MakeOptionColor(c Color) OptionColor {
|
||||||
|
if (c == ColorGray) || (c == ColorRGB) || (c == ColorRGBA) {
|
||||||
return OptionColor{representation: 0x80 | uint8(c)}
|
return OptionColor{representation: 0x80 | uint8(c)}
|
||||||
}
|
}
|
||||||
|
return OptionColor{}
|
||||||
|
}
|
||||||
|
|
||||||
// Quality is a Handsum image's quality setting, from 0 (worst) to 3 (best).
|
// Quality is a Handsum image's quality setting, from 0 (worst) to 3 (best).
|
||||||
type Quality uint8
|
type Quality uint8
|
||||||
@@ -206,8 +234,11 @@ type OptionQuality struct {
|
|||||||
// MakeOptionQuality returns an option value that is Some(q), instead of the
|
// MakeOptionQuality returns an option value that is Some(q), instead of the
|
||||||
// OptionQuality zero-value, which is None.
|
// OptionQuality zero-value, which is None.
|
||||||
func MakeOptionQuality(q Quality) OptionQuality {
|
func MakeOptionQuality(q Quality) OptionQuality {
|
||||||
|
if (0 <= q) && (q <= 3) {
|
||||||
return OptionQuality{representation: 0x80 | uint8(q)}
|
return OptionQuality{representation: 0x80 | uint8(q)}
|
||||||
}
|
}
|
||||||
|
return OptionQuality{}
|
||||||
|
}
|
||||||
|
|
||||||
// EncodeOptions are optional arguments to Encode. The zero value is valid and
|
// EncodeOptions are optional arguments to Encode. The zero value is valid and
|
||||||
// means to use the default configuration, encoding to 147 bytes.
|
// means to use the default configuration, encoding to 147 bytes.
|
||||||
@@ -223,14 +254,14 @@ type EncodeOptions struct {
|
|||||||
|
|
||||||
func (o *EncodeOptions) color() Color {
|
func (o *EncodeOptions) color() Color {
|
||||||
if (o != nil) && ((o.Color.representation & 0x80) != 0) {
|
if (o != nil) && ((o.Color.representation & 0x80) != 0) {
|
||||||
return Color(o.Color.representation & 0x01)
|
return Color(o.Color.representation & 0x7F)
|
||||||
}
|
}
|
||||||
return ColorRGB
|
return ColorRGB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *EncodeOptions) quality() Quality {
|
func (o *EncodeOptions) quality() Quality {
|
||||||
if (o != nil) && ((o.Quality.representation & 0x80) != 0) {
|
if (o != nil) && ((o.Quality.representation & 0x80) != 0) {
|
||||||
return Quality(o.Quality.representation & 0x03)
|
return Quality(o.Quality.representation & 0x7F)
|
||||||
}
|
}
|
||||||
return QualityBest
|
return QualityBest
|
||||||
}
|
}
|
||||||
@@ -278,9 +309,9 @@ func Encode(w io.Writer, src image.Image, options *EncodeOptions) error {
|
|||||||
c := options.color()
|
c := options.color()
|
||||||
q := options.quality()
|
q := options.quality()
|
||||||
buf := [fileSizeMax]byte{}
|
buf := [fileSizeMax]byte{}
|
||||||
buf[0] = Magic[0]
|
buf[0] = Magic0[0]
|
||||||
buf[1] = Magic[1]
|
buf[1] = Magic0[1] | uint8((c-1)>>1)
|
||||||
buf[2] = ((uint8(c)) << 7) | ((uint8(q)) << 5) | aspectRatio
|
buf[2] = ((uint8(c - 1)) << 7) | ((uint8(q)) << 5) | aspectRatio
|
||||||
|
|
||||||
bitOffset := 3 * 8
|
bitOffset := 3 * 8
|
||||||
encodeBlock := encodeBlockFuncs[q]
|
encodeBlock := encodeBlockFuncs[q]
|
||||||
@@ -381,12 +412,16 @@ func DecodeConfig(r io.Reader) (image.Config, error) {
|
|||||||
buf := [fileSizeHeader]byte{}
|
buf := [fileSizeHeader]byte{}
|
||||||
if _, err := io.ReadFull(r, buf[:]); err != nil {
|
if _, err := io.ReadFull(r, buf[:]); err != nil {
|
||||||
return image.Config{}, err
|
return image.Config{}, err
|
||||||
} else if (buf[0] != Magic[0]) || (buf[1] != Magic[1]) {
|
} else if (buf[0] != Magic0[0]) || ((0xFE & buf[1]) != Magic0[1]) {
|
||||||
|
return image.Config{}, ErrNotAHandsumFile
|
||||||
|
}
|
||||||
|
c, ok := decodeColorSetting(buf[1], buf[2])
|
||||||
|
if !ok {
|
||||||
return image.Config{}, ErrNotAHandsumFile
|
return image.Config{}, ErrNotAHandsumFile
|
||||||
}
|
}
|
||||||
|
|
||||||
cm := color.GrayModel
|
cm := color.GrayModel
|
||||||
if (buf[2] & 0x80) != 0 {
|
if c > ColorGray {
|
||||||
cm = color.RGBAModel
|
cm = color.RGBAModel
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -398,15 +433,30 @@ func DecodeConfig(r io.Reader) (image.Config, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func decodeColorSetting(buf1 byte, buf2 byte) (Color, bool) {
|
||||||
|
switch ((buf1 & 1) << 1) | (buf2 >> 7) {
|
||||||
|
case 0:
|
||||||
|
return ColorGray, true
|
||||||
|
case 2:
|
||||||
|
return ColorRGB, true
|
||||||
|
case 3:
|
||||||
|
// TODO: return ColorRGBA, true
|
||||||
|
}
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
|
||||||
// Decode reads a Handsum image from r.
|
// Decode reads a Handsum image from r.
|
||||||
func Decode(r io.Reader) (image.Image, error) {
|
func Decode(r io.Reader) (image.Image, error) {
|
||||||
buf := [fileSizeMax]byte{}
|
buf := [fileSizeMax]byte{}
|
||||||
if _, err := io.ReadFull(r, buf[:fileSizeHeader]); err != nil {
|
if _, err := io.ReadFull(r, buf[:fileSizeHeader]); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if (buf[0] != Magic[0]) || (buf[1] != Magic[1]) {
|
} else if (buf[0] != Magic0[0]) || ((0xFE & buf[1]) != Magic0[1]) {
|
||||||
|
return nil, ErrNotAHandsumFile
|
||||||
|
}
|
||||||
|
c, ok := decodeColorSetting(buf[1], buf[2])
|
||||||
|
if !ok {
|
||||||
return nil, ErrNotAHandsumFile
|
return nil, ErrNotAHandsumFile
|
||||||
}
|
}
|
||||||
c := Color(buf[2] >> 7)
|
|
||||||
q := Quality((buf[2] >> 5) & 0x03)
|
q := Quality((buf[2] >> 5) & 0x03)
|
||||||
if _, err := io.ReadFull(r, buf[fileSizeHeader:fileSize(c, q)]); err != nil {
|
if _, err := io.ReadFull(r, buf[fileSizeHeader:fileSize(c, q)]); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -424,7 +474,7 @@ func Decode(r io.Reader) (image.Image, error) {
|
|||||||
cbQuadBlockU8 := lowleveljpeg.QuadBlockU8{}
|
cbQuadBlockU8 := lowleveljpeg.QuadBlockU8{}
|
||||||
crQuadBlockU8 := lowleveljpeg.QuadBlockU8{}
|
crQuadBlockU8 := lowleveljpeg.QuadBlockU8{}
|
||||||
|
|
||||||
if c != 0 {
|
if c > ColorGray {
|
||||||
cbBlockU8 := lowleveljpeg.BlockU8{}
|
cbBlockU8 := lowleveljpeg.BlockU8{}
|
||||||
crBlockU8 := lowleveljpeg.BlockU8{}
|
crBlockU8 := lowleveljpeg.BlockU8{}
|
||||||
|
|
||||||
@@ -438,7 +488,7 @@ func Decode(r io.Reader) (image.Image, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dstW, dstH := decodeWidthAndHeight(buf[2])
|
dstW, dstH := decodeWidthAndHeight(buf[2])
|
||||||
return finishDecode(dstW, dstH, c == 0, &lumaQuadBlockU8, &cbQuadBlockU8, &crQuadBlockU8), nil
|
return finishDecode(dstW, dstH, c == ColorGray, &lumaQuadBlockU8, &cbQuadBlockU8, &crQuadBlockU8), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeWidthAndHeight(buf2 byte) (w int, h int) {
|
func decodeWidthAndHeight(buf2 byte) (w int, h int) {
|
||||||
|
|||||||
@@ -25,7 +25,13 @@ func makePlainColorImage(grayValue uint8) image.Image {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testRoundTrip(tt *testing.T, src image.Image, pixelValue uint8, justCheckThatItsGray bool) {
|
func testRoundTrip(tt *testing.T, src image.Image, pixelValue uint8, justCheckThatItsGray bool) {
|
||||||
for c := Color(0); c < 2; c++ {
|
colors := []Color{
|
||||||
|
ColorGray,
|
||||||
|
ColorRGB,
|
||||||
|
// TODO: ColorRGBA,
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range colors {
|
||||||
for q := Quality(0); q < 4; q++ {
|
for q := Quality(0); q < 4; q++ {
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
err := Encode(buf, src, &EncodeOptions{
|
err := Encode(buf, src, &EncodeOptions{
|
||||||
|
|||||||
@@ -23989,6 +23989,7 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
|
|||||||
{+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG
|
{+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG
|
||||||
{+0x54482020, "\x02\xC3\xBE\xFE"}, // TH
|
{+0x54482020, "\x02\xC3\xBE\xFE"}, // TH
|
||||||
{+0x585A2020, "\x04\xFD\x37\x7A\x58\x5A"}, // XZ
|
{+0x585A2020, "\x04\xFD\x37\x7A\x58\x5A"}, // XZ
|
||||||
|
{+0x484E534D, "\x01\xFE\xD6"}, // HANDSUM
|
||||||
{+0x484E534D, "\x01\xFE\xD7"}, // HANDSUM
|
{+0x484E534D, "\x01\xFE\xD7"}, // HANDSUM
|
||||||
{+0x4A504547, "\x01\xFF\xD8"}, // JPEG
|
{+0x4A504547, "\x01\xFF\xD8"}, // JPEG
|
||||||
};
|
};
|
||||||
@@ -50319,12 +50320,16 @@ const char wuffs_handsum__error__truncated_input[] = "#handsum: truncated input"
|
|||||||
|
|
||||||
// ---------------- Private Consts
|
// ---------------- Private Consts
|
||||||
|
|
||||||
static const uint32_t
|
static const uint8_t
|
||||||
WUFFS_HANDSUM__PAYLOAD_SIZES[2][4] WUFFS_BASE__POTENTIALLY_UNUSED = {
|
WUFFS_HANDSUM__PAYLOAD_SIZES[4][4] WUFFS_BASE__POTENTIALLY_UNUSED = {
|
||||||
{
|
{
|
||||||
30u, 48u, 80u, 96u,
|
30u, 48u, 80u, 96u,
|
||||||
|
}, {
|
||||||
|
0u, 0u, 0u, 0u,
|
||||||
}, {
|
}, {
|
||||||
45u, 72u, 120u, 144u,
|
45u, 72u, 120u, 144u,
|
||||||
|
}, {
|
||||||
|
76u, 99u, 147u, 171u,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -50917,9 +50922,9 @@ wuffs_handsum__decoder__do_decode_image_config(
|
|||||||
{
|
{
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||||
uint32_t t_0;
|
uint32_t t_0;
|
||||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
|
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 3)) {
|
||||||
t_0 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
|
t_0 = ((uint32_t)(wuffs_base__peek_u24be__no_bounds_check(iop_a_src)));
|
||||||
iop_a_src += 2;
|
iop_a_src += 3;
|
||||||
} else {
|
} else {
|
||||||
self->private_data.s_do_decode_image_config.scratch = 0;
|
self->private_data.s_do_decode_image_config.scratch = 0;
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||||
@@ -50929,34 +50934,29 @@ wuffs_handsum__decoder__do_decode_image_config(
|
|||||||
goto suspend;
|
goto suspend;
|
||||||
}
|
}
|
||||||
uint64_t* scratch = &self->private_data.s_do_decode_image_config.scratch;
|
uint64_t* scratch = &self->private_data.s_do_decode_image_config.scratch;
|
||||||
uint32_t num_bits_0 = ((uint32_t)(*scratch >> 56));
|
uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu));
|
||||||
*scratch <<= 8;
|
|
||||||
*scratch >>= 8;
|
*scratch >>= 8;
|
||||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_0;
|
*scratch <<= 8;
|
||||||
if (num_bits_0 == 8) {
|
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0);
|
||||||
t_0 = ((uint32_t)(*scratch));
|
if (num_bits_0 == 16) {
|
||||||
|
t_0 = ((uint32_t)(*scratch >> 40));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
num_bits_0 += 8u;
|
num_bits_0 += 8u;
|
||||||
*scratch |= ((uint64_t)(num_bits_0)) << 56;
|
*scratch |= ((uint64_t)(num_bits_0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
v_c32 = t_0;
|
v_c32 = t_0;
|
||||||
}
|
}
|
||||||
if (v_c32 != 55294u) {
|
if ((v_c32 >> 9u) != 32619u) {
|
||||||
status = wuffs_base__make_status(wuffs_handsum__error__bad_header);
|
status = wuffs_base__make_status(wuffs_handsum__error__bad_header);
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
{
|
self->private_impl.f_color = ((v_c32 >> 7u) & 3u);
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
if ((self->private_impl.f_color & 1u) == 1u) {
|
||||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
status = wuffs_base__make_status(wuffs_handsum__error__bad_header);
|
||||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
goto exit;
|
||||||
goto suspend;
|
|
||||||
}
|
}
|
||||||
uint32_t t_1 = *iop_a_src++;
|
|
||||||
v_c32 = t_1;
|
|
||||||
}
|
|
||||||
self->private_impl.f_color = (v_c32 >> 7u);
|
|
||||||
self->private_impl.f_quality = ((v_c32 >> 5u) & 3u);
|
self->private_impl.f_quality = ((v_c32 >> 5u) & 3u);
|
||||||
if ((v_c32 & 16u) == 0u) {
|
if ((v_c32 & 16u) == 0u) {
|
||||||
self->private_impl.f_width = 16u;
|
self->private_impl.f_width = 16u;
|
||||||
@@ -51243,6 +51243,7 @@ wuffs_handsum__decoder__do_decode_frame(
|
|||||||
uint32_t v_pixfmt = 0;
|
uint32_t v_pixfmt = 0;
|
||||||
wuffs_base__status v_status = wuffs_base__make_status(NULL);
|
wuffs_base__status v_status = wuffs_base__make_status(NULL);
|
||||||
uint32_t v_num_read = 0;
|
uint32_t v_num_read = 0;
|
||||||
|
uint32_t v_payload_size = 0;
|
||||||
uint32_t v_which = 0;
|
uint32_t v_which = 0;
|
||||||
|
|
||||||
const uint8_t* iop_a_src = NULL;
|
const uint8_t* iop_a_src = NULL;
|
||||||
@@ -51300,10 +51301,14 @@ wuffs_handsum__decoder__do_decode_frame(
|
|||||||
}
|
}
|
||||||
goto ok;
|
goto ok;
|
||||||
}
|
}
|
||||||
while (v_num_read < WUFFS_HANDSUM__PAYLOAD_SIZES[self->private_impl.f_color][self->private_impl.f_quality]) {
|
while (true) {
|
||||||
|
v_payload_size = ((uint32_t)(WUFFS_HANDSUM__PAYLOAD_SIZES[self->private_impl.f_color][self->private_impl.f_quality]));
|
||||||
|
if (v_num_read >= v_payload_size) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
v_num_read += wuffs_private_impl__io_reader__limited_copy_u32_to_slice(
|
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_color][self->private_impl.f_quality] - v_num_read), wuffs_base__make_slice_u8_ij(self->private_data.f_bits, v_num_read, 256));
|
&iop_a_src, io2_a_src,(v_payload_size - 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]) {
|
if (v_num_read < v_payload_size) {
|
||||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
|||||||
pub struct decoder? implements base.image_decoder(
|
pub struct decoder? implements base.image_decoder(
|
||||||
width : base.u32[..= 16],
|
width : base.u32[..= 16],
|
||||||
height : base.u32[..= 16],
|
height : base.u32[..= 16],
|
||||||
color : base.u32[..= 1],
|
color : base.u32[..= 3], // 0=gray, 2=rgb, 3=rgba.
|
||||||
quality : base.u32[..= 3],
|
quality : base.u32[..= 3],
|
||||||
|
|
||||||
// The call sequence state machine is discussed in
|
// The call sequence state machine is discussed in
|
||||||
@@ -68,12 +68,14 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
|||||||
return base."#bad call sequence"
|
return base."#bad call sequence"
|
||||||
}
|
}
|
||||||
|
|
||||||
c32 = args.src.read_u16le_as_u32?()
|
c32 = args.src.read_u24be_as_u32?()
|
||||||
if c32 <> '\xFE\xD7'le {
|
if (c32 >> 9) <> 0x7F6B {
|
||||||
|
return "#bad header"
|
||||||
|
}
|
||||||
|
this.color = (c32 >> 7) & 3
|
||||||
|
if (this.color & 1) == 1 {
|
||||||
return "#bad header"
|
return "#bad header"
|
||||||
}
|
}
|
||||||
c32 = args.src.read_u8_as_u32?()
|
|
||||||
this.color = c32 >> 7
|
|
||||||
this.quality = (c32 >> 5) & 3
|
this.quality = (c32 >> 5) & 3
|
||||||
|
|
||||||
if (c32 & 0x10) == 0x00 { // Landscape.
|
if (c32 & 0x10) == 0x00 { // Landscape.
|
||||||
@@ -164,6 +166,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
|||||||
var pixfmt : base.u32
|
var pixfmt : base.u32
|
||||||
var status : base.status
|
var status : base.status
|
||||||
var num_read : base.u32
|
var num_read : base.u32
|
||||||
|
var payload_size : base.u32[..= 171]
|
||||||
var which : base.u32[..= 1]
|
var which : base.u32[..= 1]
|
||||||
|
|
||||||
if this.call_sequence == 0x40 {
|
if this.call_sequence == 0x40 {
|
||||||
@@ -189,13 +192,17 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
|||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
|
|
||||||
while num_read < PAYLOAD_SIZES[this.color][this.quality] {
|
while true {
|
||||||
assert num_read < 256 via "a < b: a < c; c <= b"(c: PAYLOAD_SIZES[this.color][this.quality])
|
payload_size = PAYLOAD_SIZES[this.color][this.quality] as base.u32
|
||||||
assert PAYLOAD_SIZES[this.color][this.quality] > num_read via "a > b: b < a"()
|
if num_read >= payload_size {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
assert num_read < 256 via "a < b: a < c; c <= b"(c: payload_size)
|
||||||
|
assert payload_size > num_read via "a > b: b < a"()
|
||||||
num_read ~mod+= args.src.limited_copy_u32_to_slice!(
|
num_read ~mod+= args.src.limited_copy_u32_to_slice!(
|
||||||
up_to: PAYLOAD_SIZES[this.color][this.quality] - num_read,
|
up_to: payload_size - num_read,
|
||||||
s: this.bits[num_read ..])
|
s: this.bits[num_read ..])
|
||||||
if num_read < PAYLOAD_SIZES[this.color][this.quality] {
|
if num_read < payload_size {
|
||||||
yield? base."$short read"
|
yield? base."$short read"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1084,10 +1091,14 @@ pub func decoder.workbuf_len() base.range_ii_u64 {
|
|||||||
return this.util.make_range_ii_u64(min_incl: 0, max_incl: 0)
|
return this.util.make_range_ii_u64(min_incl: 0, max_incl: 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pri const PAYLOAD_SIZES : roarray[2] roarray[4] base.u32[..= 144] = [[
|
pri const PAYLOAD_SIZES : roarray[4] roarray[4] base.u8[..= 171] = [[
|
||||||
30, 48, 80, 96,
|
30, 48, 80, 96,
|
||||||
|
],[
|
||||||
|
0, 0, 0, 0,
|
||||||
],[
|
],[
|
||||||
45, 72, 120, 144,
|
45, 72, 120, 144,
|
||||||
|
],[
|
||||||
|
69, 96, 144, 168,
|
||||||
]]
|
]]
|
||||||
|
|
||||||
pri const NUM_COEFFS : roarray[4] base.u32[..= 15] = [
|
pri const NUM_COEFFS : roarray[4] base.u32[..= 15] = [
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
þ׋†¼“‡§ŠˆHˆ—˜›‰¨˜uxºh{ixHކ{xwv‰»§†¬˜†©Y—§SV´§v
|
þ׆¼“‡§ŠˆHˆ—˜›‰¨˜uxºh{ixHކ{xwv‰»§†¬˜†©Y—§SV´§v
|
||||||
@@ -1 +1 @@
|
|||||||
ţ׫UÚ‡7ź…¦�h�š†Ô{ĽC—‡Dy§´›z¦Šwe“şÔŐ‡&mYćRi�‰h噋Sz¶úk¦»{śTÚęIÍpoŐ¨ăSË6…đb
|
ţ×+UÚ‡7ź…¦�h�š†Ô{ĽC—‡Dy§´›z¦Šwe“şÔŐ‡&mYćRi�‰h噋Sz¶úk¦»{śTÚęIÍpoŐ¨ăSË6…đb
|
||||||
@@ -1 +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
|
ţ×KUÚ‡��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 +1 @@
|
|||||||
�ラsャ迫ヲzx(汚剱汚冱wケx及x(合休ww�
|
�ヨsャ迫ヲzx(汚剱汚冱wケx及x(合休ww�
|
||||||
@@ -1 +1 @@
|
|||||||
ўз+cк�%����x���в{Ыa��RyЈВ�zЃ�wR�ЊТХw4lhдSh��xг�{ayЇ
|
ўж+cк�%����x���в{Ыa��RyЈВ�zЃ�wR�ЊТХw4lhдSh��xг�{ayЇ
|
||||||
@@ -1 +1 @@
|
|||||||
ţ×KcÚ‡�‡%ꔆh“�x‰�‚š‡x�Ň{ËŞ‡a—�™�Ry¨‰š˛‹z‡xىw��R“Ş—yÂĹw�‰4lhx�ÔSh����xx�Ó™{‡–ay§�y
|
ţÖKcÚ‡�‡%ꔆh“�x‰�‚š‡x�Ň{ËŞ‡a—�™�Ry¨‰š˛‹z‡xىw��R“Ş—yÂĹw�‰4lhx�ÔSh����xx�Ó™{‡–ay§�y
|
||||||
@@ -1 +1 @@
|
|||||||
þ×krMø©ðr45‚8¶ƒ9«b)ªs8{¡—ôˆ€(…‰�&{‘(vt˜¡(Öq‰ƒ)™¡(Tƒ(šrDD’©hˆ¤!MQKÉ”[qІH®€ˆ¥«�(bt,I�—
|
þÖkrMø©ðr45‚8¶ƒ9«b)ªs8{¡—ôˆ€(…‰�&{‘(vt˜¡(Öq‰ƒ)™¡(Tƒ(šrDD’©hˆ¤!MQKÉ”[qІH®€ˆ¥«�(bt,I�—
|
||||||
@@ -1 +1 @@
|
|||||||
þ×ërMø©ðr45‚8¶ƒ9«b)ªs8{¡—ôˆ€(…‰�&{‘(vt˜¡(Öq‰ƒ)™¡(Tƒ(šrDD’©hˆ¤!MQKÉ”[qІH®€ˆ¥«�(bt,I�—ˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆ
|
þ×krMø©ðr45‚8¶ƒ9«b)ªs8{¡—ôˆ€(…‰�&{‘(vt˜¡(Öq‰ƒ)™¡(Tƒ(šrDD’©hˆ¤!MQKÉ”[qІH®€ˆ¥«�(bt,I�—ˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆ
|
||||||
@@ -1 +1 @@
|
|||||||
þךv‹švXˆ™h¶yª¦†™—c{‰˜¹Yy(¸ˆŠ‰Š™˜w”˜yˆˆˆ—y‡wˆˆˆ˜
|
þ×v‹švXˆ™h¶yª¦†™—c{‰˜¹Yy(¸ˆŠ‰Š™˜w”˜yˆˆˆ—y‡wˆˆˆ˜
|
||||||
@@ -1 +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©Č™‹‡
|
ţ×z‡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©Č™‹‡
|
||||||
Reference in new issue
Block a user