1
1
mirror of https://github.com/wader/fq.git synced 2024-10-26 20:06:29 +03:00

Merge pull request #857 from wader/webp-lossless

webp: Decode width, height and flags for lossless webp
This commit is contained in:
Mattias Wadman 2024-01-20 17:37:24 +01:00 committed by GitHub
commit a13808d2ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 38 additions and 0 deletions

BIN
format/riff/testdata/4x4.lossless.webp vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 B

View File

@ -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| |..| |

View File

@ -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")