1
1
mirror of https://github.com/wader/fq.git synced 2024-09-11 20:07:11 +03:00

Merge pull request #925 from wader/jp2c-probe

jp2c: Support probe
This commit is contained in:
Mattias Wadman 2024-04-10 21:57:27 +02:00 committed by GitHub
commit f6609ccb0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 72 additions and 2 deletions

View File

@ -132,12 +132,12 @@
|[`xml`](#xml) |Extensible&nbsp;Markup&nbsp;Language |<sub></sub>|
|`yaml` |YAML&nbsp;Ain't&nbsp;Markup&nbsp;Language |<sub></sub>|
|[`zip`](#zip) |ZIP&nbsp;archive |<sub>`probe`</sub>|
|`image` |Group |<sub>`gif` `jpeg` `mp4` `png` `tiff` `webp`</sub>|
|`image` |Group |<sub>`gif` `jp2c` `jpeg` `mp4` `png` `tiff` `webp`</sub>|
|`inet_packet` |Group |<sub>`ipv4_packet` `ipv6_packet`</sub>|
|`ip_packet` |Group |<sub>`icmp` `icmpv6` `tcp_segment` `udp_datagram`</sub>|
|`link_frame` |Group |<sub>`bsd_loopback_frame` `ether8023_frame` `ipv4_packet` `ipv6_packet` `sll2_packet` `sll_packet`</sub>|
|`mp3_frame_tags` |Group |<sub>`mp3_frame_vbri` `mp3_frame_xing`</sub>|
|`probe` |Group |<sub>`adts` `aiff` `apple_bookmark` `ar` `avi` `avro_ocf` `bitcoin_blkdat` `bplist` `bzip2` `caff` `elf` `fit` `flac` `gif` `gzip` `html` `jpeg` `json` `jsonl` `leveldb_table` `luajit` `macho` `macho_fat` `matroska` `moc3` `mp3` `mp4` `mpeg_ts` `nes` `ogg` `opentimestamps` `pcap` `pcapng` `png` `tar` `tiff` `toml` `tzif` `wasm` `wav` `webp` `xml` `yaml` `zip`</sub>|
|`probe` |Group |<sub>`adts` `aiff` `apple_bookmark` `ar` `avi` `avro_ocf` `bitcoin_blkdat` `bplist` `bzip2` `caff` `elf` `fit` `flac` `gif` `gzip` `html` `jp2c` `jpeg` `json` `jsonl` `leveldb_table` `luajit` `macho` `macho_fat` `matroska` `moc3` `mp3` `mp4` `mpeg_ts` `nes` `ogg` `opentimestamps` `pcap` `pcapng` `png` `tar` `tiff` `toml` `tzif` `wasm` `wav` `webp` `xml` `yaml` `zip`</sub>|
|`tcp_stream` |Group |<sub>`dns_tcp` `rtmp` `tls`</sub>|
|`udp_payload` |Group |<sub>`dns`</sub>|

View File

@ -14,6 +14,7 @@ $ fq -n _registry.groups.probe
"flac",
"gif",
"gzip",
"jp2c",
"jpeg",
"leveldb_table",
"luajit",

View File

@ -12,6 +12,7 @@ func init() {
format.JP2C,
&decode.Format{
Description: "JPEG 2000 codestream",
Groups: []*decode.Group{format.Probe, format.Image},
DecodeFn: jp2cDecode,
RootName: "segments",
RootArray: true,
@ -70,13 +71,17 @@ var jp2Markers = scalar.UintMap{
}
func jp2cDecode(d *decode.D) any {
seenSOC := false
seenSIZ := false
seenEOC := false
for !seenEOC && !d.End() {
d.FieldStruct("segment", func(d *decode.D) {
marker := d.FieldU16("marker", jp2Markers, scalar.UintHex)
switch marker {
case JP2_SOC:
// zero length
seenSOC = true
return
case JP2_SOD:
l, _ := d.PeekFind(16, 8, d.BitsLeft(), func(v uint64) bool {
@ -90,6 +95,7 @@ func jp2cDecode(d *decode.D) any {
d.FieldU8("tp_sot")
d.FieldU8("tn_sot")
case JP2_SIZ:
seenSIZ = true
d.FieldU16("l_siz")
d.FieldU16("r_siz")
d.FieldU32("x_siz")
@ -126,5 +132,9 @@ func jp2cDecode(d *decode.D) any {
})
}
if !(seenSOC && seenSIZ && seenEOC) {
d.Fatalf("SOC, SIZ or EOC marker not found")
}
return nil
}

BIN
format/jpeg/testdata/test.j2c vendored Normal file

Binary file not shown.

59
format/jpeg/testdata/test.j2c.fqtest vendored Normal file
View File

@ -0,0 +1,59 @@
# test probe
$ fq dv test.j2c
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.[0:9]: test.j2c (jp2c) 0x0-0xa4 (164)
| | | [0]{}: segment 0x0-0x2 (2)
0x00|ff 4f |.O | marker: "soc" (0xff4f) (Start of codestream) 0x0-0x2 (2)
| | | [1]{}: segment 0x2-0x2d (43)
0x00| ff 51 | .Q | marker: "siz" (0xff51) (Image and tile size) 0x2-0x4 (2)
0x00| 00 29 | .) | l_siz: 41 0x4-0x6 (2)
0x00| 00 00 | .. | r_siz: 0 0x6-0x8 (2)
0x00| 00 00 00 01 | .... | x_siz: 1 0x8-0xc (4)
0x00| 00 00 00 01| ....| y_siz: 1 0xc-0x10 (4)
0x10|00 00 00 00 |.... | xo_siz: 0 0x10-0x14 (4)
0x10| 00 00 00 00 | .... | yo_siz: 0 0x14-0x18 (4)
0x10| 00 00 00 01 | .... | xt_siz: 1 0x18-0x1c (4)
0x10| 00 00 00 01| ....| yt_siz: 1 0x1c-0x20 (4)
0x20|00 00 00 00 |.... | xto_siz: 0 0x20-0x24 (4)
0x20| 00 00 00 00 | .... | yto_siz: 0 0x24-0x28 (4)
0x20| 00 01 | .. | c_siz: 1 0x28-0x2a (2)
| | | components[0:1]: 0x2a-0x2d (3)
| | | [0]{}: component 0x2a-0x2d (3)
0x20| 0f | . | s_sizi: 15 0x2a-0x2b (1)
0x20| 01 | . | xr_sizi: 1 0x2b-0x2c (1)
0x20| 01 | . | yr_sizi: 1 0x2c-0x2d (1)
| | | [2]{}: segment 0x2d-0x51 (36)
0x20| ff 64 | .d | marker: "com" (0xff64) (Comment) 0x2d-0x2f (2)
0x20| 00| .| length: 34 0x2f-0x31 (2)
0x30|22 |" |
0x30| 00 01 | .. | r_cme: 1 0x31-0x33 (2)
0x30| 43 72 65 61 74 6f 72 3a 20 4a 61 73 50| Creator: JasP| data: "Creator: JasPer Version 2.0.33" 0x33-0x51 (30)
0x40|65 72 20 56 65 72 73 69 6f 6e 20 32 2e 30 2e 33|er Version 2.0.3|
0x50|33 |3 |
| | | [3]{}: segment 0x51-0x5f (14)
0x50| ff 52 | .R | marker: "cod" (0xff52) (Coding style default) 0x51-0x53 (2)
0x50| 00 0c | .. | length: 12 0x53-0x55 (2)
0x50| 00 00 00 01 00 05 04 04 00 01 | .......... | data: raw bits 0x55-0x5f (10)
| | | [4]{}: segment 0x5f-0x74 (21)
0x50| ff| .| marker: "qcd" (0xff5c) (Quantization default) 0x5f-0x61 (2)
0x60|5c |\ |
0x60| 00 13 | .. | length: 19 0x61-0x63 (2)
0x60| 40 80 88 88 90 88 88 90 88 88 90 88 88| @............| data: raw bits 0x63-0x74 (17)
0x70|90 88 88 90 |.... |
| | | [5]{}: segment 0x74-0x80 (12)
0x70| ff 90 | .. | marker: "sot" (0xff90) (Start of tile) 0x74-0x76 (2)
0x70| 00 0a | .. | l_sot: 10 0x76-0x78 (2)
0x70| 00 00 | .. | i_sot: 0 0x78-0x7a (2)
0x70| 00 00 00 2e | .... | p_sot: 46 0x7a-0x7e (4)
0x70| 00 | . | tp_sot: 0 0x7e-0x7f (1)
0x70| 01| .| tn_sot: 1 0x7f-0x80 (1)
| | | [6]{}: segment 0x80-0x96 (22)
0x80|ff 5d |.] | marker: "qcc" (0xff5d) (Quantization component) 0x80-0x82 (2)
0x80| 00 14 | .. | length: 20 0x82-0x84 (2)
0x80| 00 40 80 00 00 00 00 00 00 00 00 00| .@..........| data: raw bits 0x84-0x96 (18)
0x90|00 00 00 00 00 00 |...... |
| | | [7]{}: segment 0x96-0xa2 (12)
0x90| ff 93 | .. | marker: "sod" (0xff93) (Start of data) 0x96-0x98 (2)
0x90| df f8 90 08 07 80 80 80| ........| data: raw bits 0x98-0xa2 (10)
0xa0|80 80 |.. |
| | | [8]{}: segment 0xa2-0xa4 (2)
0xa0| ff d9| | ..| | marker: "eoc" (0xffd9) (End of codestream) 0xa2-0xa4 (2)