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

Merge pull request #912 from wader/icc-profile-nicer-strings

icc_profile: Strip whitespace in header and tag strings
This commit is contained in:
Mattias Wadman 2024-04-03 10:17:53 +02:00 committed by GitHub
commit 93eb6e83ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 25 deletions

View File

@ -8,6 +8,7 @@ import (
"github.com/wader/fq/internal/mathx"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
func init() {
@ -70,7 +71,7 @@ func multiLocalizedUnicodeType(tagStart int64, d *decode.D) {
}
var typeToDecode = map[string]func(tagStart int64, d *decode.D){
"XYZ ": xyzType,
"XYZ": xyzType,
"text": textType,
"para": paraType,
"desc": descType,
@ -111,13 +112,13 @@ func iccProfileDecode(d *decode.D) any {
d.FramedFn(int64(size)*8, func(d *decode.D) {
d.FieldStruct("header", func(d *decode.D) {
d.FieldU32("size")
d.FieldUTF8NullFixedLen("cmm_type_signature", 4)
d.FieldUTF8NullFixedLen("cmm_type_signature", 4, scalar.ActualTrimSpace)
d.FieldUintFn("version_major", decodeBCDU8)
d.FieldUintFn("version_minor", decodeBCDU8)
d.FieldU16("version_reserved")
d.FieldUTF8NullFixedLen("device_class_signature", 4)
d.FieldUTF8NullFixedLen("color_space", 4)
d.FieldUTF8NullFixedLen("connection_space", 4)
d.FieldUTF8NullFixedLen("device_class_signature", 4, scalar.ActualTrimSpace)
d.FieldUTF8NullFixedLen("color_space", 4, scalar.ActualTrimSpace)
d.FieldUTF8NullFixedLen("connection_space", 4, scalar.ActualTrimSpace)
d.FieldStruct("timestamp", func(d *decode.D) {
d.FieldU16("year")
d.FieldU16("month")
@ -127,16 +128,16 @@ func iccProfileDecode(d *decode.D) any {
d.FieldU16("seconds")
})
d.FieldUTF8NullFixedLen("file_signature", 4)
d.FieldUTF8NullFixedLen("primary_platform", 4)
d.FieldUTF8NullFixedLen("file_signature", 4, scalar.ActualTrimSpace)
d.FieldUTF8NullFixedLen("primary_platform", 4, scalar.ActualTrimSpace)
d.FieldU32("flags")
d.FieldUTF8NullFixedLen("device_manufacturer", 4)
d.FieldUTF8NullFixedLen("device_model", 4)
d.FieldUTF8NullFixedLen("device_attribute", 8)
d.FieldUTF8NullFixedLen("render_intent", 4)
d.FieldUTF8NullFixedLen("xyz_illuminant", 12)
d.FieldUTF8NullFixedLen("profile_creator_signature", 4)
d.FieldUTF8NullFixedLen("profile_id", 16)
d.FieldUTF8NullFixedLen("device_manufacturer", 4, scalar.ActualTrimSpace)
d.FieldUTF8NullFixedLen("device_model", 4, scalar.ActualTrimSpace)
d.FieldUTF8NullFixedLen("device_attribute", 8, scalar.ActualTrimSpace)
d.FieldUTF8NullFixedLen("render_intent", 4, scalar.ActualTrimSpace)
d.FieldUTF8NullFixedLen("xyz_illuminant", 12, scalar.ActualTrimSpace)
d.FieldUTF8NullFixedLen("profile_creator_signature", 4, scalar.ActualTrimSpace)
d.FieldUTF8NullFixedLen("profile_id", 16, scalar.ActualTrimSpace)
d.FieldRawLen("reserved", 28*8, d.BitBufIsZero())
})
@ -145,13 +146,13 @@ func iccProfileDecode(d *decode.D) any {
d.FieldArray("table", func(d *decode.D) {
for i := uint64(0); i < tagCount; i++ {
d.FieldStruct("element", func(d *decode.D) {
d.FieldUTF8NullFixedLen("signature", 4)
d.FieldUTF8NullFixedLen("signature", 4, scalar.ActualTrimSpace)
offset := d.FieldU32("offset")
size := d.FieldU32("size")
d.RangeFn(int64(offset)*8, int64(size)*8, func(d *decode.D) {
tagStart := d.Pos()
typ := d.FieldUTF8NullFixedLen("type", 4)
typ := d.FieldUTF8NullFixedLen("type", 4, scalar.ActualTrimSpace)
d.FieldU32("reserved")
if fn, ok := typeToDecode[typ]; ok {

View File

@ -8,8 +8,8 @@ $ fq -d icc_profile dv sRGB2014.icc
0x000| 00 | . | version_minor: 0 0x9-0xa (1)
0x000| 00 00 | .. | version_reserved: 0 0xa-0xc (2)
0x000| 6d 6e 74 72| mntr| device_class_signature: "mntr" 0xc-0x10 (4)
0x010|52 47 42 20 |RGB | color_space: "RGB " 0x10-0x14 (4)
0x010| 58 59 5a 20 | XYZ | connection_space: "XYZ " 0x14-0x18 (4)
0x010|52 47 42 20 |RGB | color_space: "RGB" 0x10-0x14 (4)
0x010| 58 59 5a 20 | XYZ | connection_space: "XYZ" 0x14-0x18 (4)
| | | timestamp{}: 0x18-0x24 (12)
0x010| 07 df | .. | year: 2015 0x18-0x1a (2)
0x010| 00 02 | .. | month: 2 0x1a-0x1c (2)
@ -55,7 +55,7 @@ $ fq -d icc_profile dv sRGB2014.icc
0x090|62 58 59 5a |bXYZ | signature: "bXYZ" 0x90-0x94 (4)
0x090| 00 00 01 a8 | .... | offset: 424 0x94-0x98 (4)
0x090| 00 00 00 14 | .... | size: 20 0x98-0x9c (4)
0x1a0| 58 59 5a 20 | XYZ | type: "XYZ " 0x1a8-0x1ac (4)
0x1a0| 58 59 5a 20 | XYZ | type: "XYZ" 0x1a8-0x1ac (4)
0x1a0| 00 00 00 00| ....| reserved: 0 0x1ac-0x1b0 (4)
0x1b0|00 00 24 a0 |..$. | x: 0.14306640625 0x1b0-0x1b4 (4)
0x1b0| 00 00 0f 84 | .... | y: 0.06060791015625 0x1b4-0x1b8 (4)
@ -109,7 +109,7 @@ $ fq -d icc_profile dv sRGB2014.icc
0x0c0| 67 58 59 5a| gXYZ| signature: "gXYZ" 0xcc-0xd0 (4)
0x0d0|00 00 0a 50 |...P | offset: 2640 0xd0-0xd4 (4)
0x0d0| 00 00 00 14 | .... | size: 20 0xd4-0xd8 (4)
0xa50|58 59 5a 20 |XYZ | type: "XYZ " 0xa50-0xa54 (4)
0xa50|58 59 5a 20 |XYZ | type: "XYZ" 0xa50-0xa54 (4)
0xa50| 00 00 00 00 | .... | reserved: 0 0xa54-0xa58 (4)
0xa50| 00 00 62 99 | ..b. | x: 0.3851470947265625 0xa58-0xa5c (4)
0xa50| 00 00 b7 85| ....| y: 0.7168731689453125 0xa5c-0xa60 (4)
@ -118,7 +118,7 @@ $ fq -d icc_profile dv sRGB2014.icc
0x0d0| 6c 75 6d 69 | lumi | signature: "lumi" 0xd8-0xdc (4)
0x0d0| 00 00 0a 64| ...d| offset: 2660 0xdc-0xe0 (4)
0x0e0|00 00 00 14 |.... | size: 20 0xe0-0xe4 (4)
0xa60| 58 59 5a 20 | XYZ | type: "XYZ " 0xa64-0xa68 (4)
0xa60| 58 59 5a 20 | XYZ | type: "XYZ" 0xa64-0xa68 (4)
0xa60| 00 00 00 00 | .... | reserved: 0 0xa68-0xa6c (4)
0xa60| 00 00 00 00| ....| x: 0 0xa6c-0xa70 (4)
0xa70|00 50 00 00 |.P.. | y: 80 0xa70-0xa74 (4)
@ -135,7 +135,7 @@ $ fq -d icc_profile dv sRGB2014.icc
0x0f0|62 6b 70 74 |bkpt | signature: "bkpt" 0xf0-0xf4 (4)
0x0f0| 00 00 0a 9c | .... | offset: 2716 0xf4-0xf8 (4)
0x0f0| 00 00 00 14 | .... | size: 20 0xf8-0xfc (4)
0xa90| 58 59 5a 20| XYZ | type: "XYZ " 0xa9c-0xaa0 (4)
0xa90| 58 59 5a 20| XYZ | type: "XYZ" 0xa9c-0xaa0 (4)
0xaa0|00 00 00 00 |.... | reserved: 0 0xaa0-0xaa4 (4)
0xaa0| 00 00 00 9e | .... | x: 0.002410888671875 0xaa4-0xaa8 (4)
0xaa0| 00 00 00 a4 | .... | y: 0.00250244140625 0xaa8-0xaac (4)
@ -144,7 +144,7 @@ $ fq -d icc_profile dv sRGB2014.icc
0x0f0| 72 58 59 5a| rXYZ| signature: "rXYZ" 0xfc-0x100 (4)
0x100|00 00 0a b0 |.... | offset: 2736 0x100-0x104 (4)
0x100| 00 00 00 14 | .... | size: 20 0x104-0x108 (4)
0xab0|58 59 5a 20 |XYZ | type: "XYZ " 0xab0-0xab4 (4)
0xab0|58 59 5a 20 |XYZ | type: "XYZ" 0xab0-0xab4 (4)
0xab0| 00 00 00 00 | .... | reserved: 0 0xab4-0xab8 (4)
0xab0| 00 00 6f a2 | ..o. | x: 0.436065673828125 0xab8-0xabc (4)
0xab0| 00 00 38 f5| ..8.| y: 0.2224884033203125 0xabc-0xac0 (4)
@ -153,7 +153,7 @@ $ fq -d icc_profile dv sRGB2014.icc
0x100| 74 65 63 68 | tech | signature: "tech" 0x108-0x10c (4)
0x100| 00 00 0a c4| ....| offset: 2756 0x10c-0x110 (4)
0x110|00 00 00 0c |.... | size: 12 0x110-0x114 (4)
0xac0| 73 69 67 20 | sig | type: "sig " 0xac4-0xac8 (4)
0xac0| 73 69 67 20 | sig | type: "sig" 0xac4-0xac8 (4)
0xac0| 00 00 00 00 | .... | reserved: 0 0xac8-0xacc (4)
0xac0| 43 52 54 20| CRT | data: raw bits 0xacc-0xad0 (4)
| | | [12]{}: element 0x114-0xb58 (2628)
@ -180,7 +180,7 @@ $ fq -d icc_profile dv sRGB2014.icc
0x120|77 74 70 74 |wtpt | signature: "wtpt" 0x120-0x124 (4)
0x120| 00 00 0b 58 | ...X | offset: 2904 0x124-0x128 (4)
0x120| 00 00 00 14 | .... | size: 20 0x128-0x12c (4)
0xb50| 58 59 5a 20 | XYZ | type: "XYZ " 0xb58-0xb5c (4)
0xb50| 58 59 5a 20 | XYZ | type: "XYZ" 0xb58-0xb5c (4)
0xb50| 00 00 00 00| ....| reserved: 0 0xb5c-0xb60 (4)
0xb60|00 00 f6 d6 |.... | x: 0.964202880859375 0xb60-0xb64 (4)
0xb60| 00 01 00 00 | .... | y: 1 0xb64-0xb68 (4)