From b0421dfc3184f060e6a46e2b8ffed8baa4572845 Mon Sep 17 00:00:00 2001 From: Mattias Wadman Date: Sat, 20 Jan 2024 16:17:27 +0100 Subject: [PATCH] webp: Decode width, height and flags for lossless webp --- format/riff/testdata/4x4.lossless.webp | Bin 0 -> 34 bytes format/riff/testdata/4x4.lossless.webp.fqtest | 18 ++++++++++++++++ .../testdata/{4x4.fqtest => 4x4.webp.fqtest} | 0 format/riff/webp.go | 20 ++++++++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 format/riff/testdata/4x4.lossless.webp create mode 100644 format/riff/testdata/4x4.lossless.webp.fqtest rename format/riff/testdata/{4x4.fqtest => 4x4.webp.fqtest} (100%) diff --git a/format/riff/testdata/4x4.lossless.webp b/format/riff/testdata/4x4.lossless.webp new file mode 100644 index 0000000000000000000000000000000000000000..c6b70b2d6fe070a7624f09c3ed430393e8486436 GIT binary patch literal 34 ocmWIYbaRtpU|#`Farw^-0Ck}USO5S3 literal 0 HcmV?d00001 diff --git a/format/riff/testdata/4x4.lossless.webp.fqtest b/format/riff/testdata/4x4.lossless.webp.fqtest new file mode 100644 index 000000000..3f5bbb3e2 --- /dev/null +++ b/format/riff/testdata/4x4.lossless.webp.fqtest @@ -0,0 +1,18 @@ +# convert -size 4x4 "xc:#000" -define webp:lossless=true 4x4.lossless.webp +$ fq -d webp dv 4x4.lossless.webp + |00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: 4x4.lossless.webp (webp) 0x0-0x22 (34) +0x00|52 49 46 46 |RIFF | id: "RIFF" 0x0-0x4 (4) +0x00| 1a 00 00 00 | .... | size: 26 0x4-0x8 (4) +0x00| 57 45 42 50 | WEBP | format: "WEBP" (valid) 0x8-0xc (4) + | | | chunks[0:1]: 0xc-0x22 (22) + | | | [0]{}: chunk 0xc-0x22 (22) +0x00| 56 50 38 4c| VP8L| id: "VP8L" 0xc-0x10 (4) +0x10|0e 00 00 00 |.... | size: 14 0x10-0x14 (4) +0x10| 2f | / | signature: 0x2f (valid) 0x14-0x15 (1) +0x10| 03 c0 00 00 | .... | width_height_flags: 49155 0x15-0x19 (4) + | | | width: 4 + | | | height: 4 + | | | alpha_is_used: false + | | | version_number: 0 +0x10| 07 10 11 fd 0f 44 44| .....DD| data: raw bits 0x19-0x22 (9) +0x20|ff 03| |..| | diff --git a/format/riff/testdata/4x4.fqtest b/format/riff/testdata/4x4.webp.fqtest similarity index 100% rename from format/riff/testdata/4x4.fqtest rename to format/riff/testdata/4x4.webp.fqtest diff --git a/format/riff/webp.go b/format/riff/webp.go index 2d27d59fa..ebc0bbc59 100644 --- a/format/riff/webp.go +++ b/format/riff/webp.go @@ -52,6 +52,26 @@ func webpDecode(d *decode.D) any { case "VP8": d.Format(&vp8FrameGroup, nil) return false, nil + case "VP8L": + d.FieldU8("signature", d.UintAssert(0x2f), scalar.UintHex) + n := d.FieldU32("width_height_flags") + // TODO: replace with "bit endian" decoding + b0 := (n >> 24) & 0xff + b1 := (n >> 16) & 0xff + b2 := (n >> 8) & 0xff + b3 := (n >> 0) & 0xf + width := b3 | (b2&0b0011_111)<<8 + width += 1 + height := (b2&0b1100_0000)>>6 | b1<<8 | (b0&0b0000_1111)<<16 + height += 1 + alphaIsUsed := b3&0b0001_0000 != 0 + versionNumber := (b3 & 0b1110_0000) >> 5 + d.FieldValueUint("width", width) + d.FieldValueUint("height", height) + d.FieldValueBool("alpha_is_used", alphaIsUsed) + d.FieldValueUint("version_number", versionNumber) + d.FieldRawLen("data", d.BitsLeft()) + return false, nil case "VP8X": d.FieldU2("reserved0") d.FieldBool("icc_profile")