2 #------------------------------------------------------------------------------
3 # $File: jpeg,v 1.21 2014/09/12 20:47:00 christos Exp $
7 # 0 string \377\330\377\340 JPEG file
8 # 0 string \377\330\377\356 JPG file
10 # both of which turn into "JPEG image data" here.
12 0 beshort 0xffd8 JPEG image data
16 >6 string JFIF \b, JFIF standard
17 # The following added by Erik Rossen <rossen@freesurf.ch> 1999-09-06
18 # in a vain attempt to add image size reporting for JFIF. Note that these
19 # tests are not fool-proof since some perfectly valid JPEGs are currently
20 # impossible to specify in magic(4) format.
21 # First, a little JFIF version info:
24 # Next, the resolution or aspect ratio of the image:
25 >>13 byte 0 \b, aspect ratio
26 >>13 byte 1 \b, resolution (DPI)
27 >>13 byte 2 \b, resolution (DPCM)
28 >>14 beshort x \b, density %dx
30 >>4 beshort x \b, segment length %d
31 # Next, show thumbnail info, if it exists:
32 >>18 byte !0 \b, thumbnail %dx
35 # EXIF moved down here to avoid reporting a bogus version number,
36 # and EXIF version number printing added.
37 # - Patrik R=E5dman <patrik+file-magic@iki.fi>
38 >6 string Exif \b, EXIF standard
39 # Look for EXIF IFD offset in IFD 0, and then look for EXIF version tag in EXIF IFD.
40 # All possible combinations of entries have to be enumerated, since no looping
41 # is possible. And both endians are possible...
42 # The combinations included below are from real-world JPEGs.
48 >>>>(78.l+14) leshort 0x9000
49 >>>>>(78.l+23) byte x %c
50 >>>>>(78.l+24) byte x \b.%c
51 >>>>>(78.l+25) byte !0x30 \b%c
55 >>>>(126.l+38) leshort 0x9000
56 >>>>>(126.l+47) byte x %c
57 >>>>>(126.l+48) byte x \b.%c
58 >>>>>(126.l+49) byte !0x30 \b%c
62 >>>>(138.l+38) leshort 0x9000
63 >>>>>(138.l+47) byte x %c
64 >>>>>(138.l+48) byte x \b.%c
65 >>>>>(138.l+49) byte !0x30 \b%c
67 >>>>(138.l+50) leshort 0x9000
68 >>>>>(138.l+59) byte x %c
69 >>>>>(138.l+60) byte x \b.%c
70 >>>>>(138.l+61) byte !0x30 \b%c
72 >>>>(138.l+62) leshort 0x9000
73 >>>>>(138.l+71) byte x %c
74 >>>>>(138.l+72) byte x \b.%c
75 >>>>>(138.l+73) byte !0x30 \b%c
79 >>>>(150.l+38) leshort 0x9000
80 >>>>>(150.l+47) byte x %c
81 >>>>>(150.l+48) byte x \b.%c
82 >>>>>(150.l+49) byte !0x30 \b%c
84 >>>>(150.l+50) leshort 0x9000
85 >>>>>(150.l+59) byte x %c
86 >>>>>(150.l+60) byte x \b.%c
87 >>>>>(150.l+61) byte !0x30 \b%c
89 >>>>(150.l+62) leshort 0x9000
90 >>>>>(150.l+71) byte x %c
91 >>>>>(150.l+72) byte x \b.%c
92 >>>>>(150.l+73) byte !0x30 \b%c
98 >>>>(126.L+14) beshort 0x9000
99 >>>>>(126.L+23) byte x %c
100 >>>>>(126.L+24) byte x \b.%c
101 >>>>>(126.L+25) byte !0x30 \b%c
103 >>>>(126.L+38) beshort 0x9000
104 >>>>>(126.L+47) byte x %c
105 >>>>>(126.L+48) byte x \b.%c
106 >>>>>(126.L+49) byte !0x30 \b%c
108 >>>130 beshort 0x8769
110 >>>>(138.L+38) beshort 0x9000
111 >>>>>(138.L+47) byte x %c
112 >>>>>(138.L+48) byte x \b.%c
113 >>>>>(138.L+49) byte !0x30 \b%c
115 >>>>(138.L+62) beshort 0x9000
116 >>>>>(138.L+71) byte x %c
117 >>>>>(138.L+72) byte x \b.%c
118 >>>>>(138.L+73) byte !0x30 \b%c
120 >>>142 beshort 0x8769
122 >>>>(150.L+50) beshort 0x9000
123 >>>>>(150.L+59) byte x %c
124 >>>>>(150.L+60) byte x \b.%c
125 >>>>>(150.L+61) byte !0x30 \b%c
127 # Jump to the first segment
128 >(4.S+4) use jpeg_segment
130 # This uses recursion...
133 >>(2.S+2) use jpeg_segment
134 >>2 pstring/HJ x \b, comment: "%s"
137 >>(2.S+2) use jpeg_segment
138 >>4 byte x \b, baseline, precision %d
139 >>7 beshort x \b, %dx
141 >>9 byte x \b, frames %d
144 >>(2.S+2) use jpeg_segment
145 >>4 byte x \b, extended sequential, precision %d
146 >>7 beshort x \b, %dx
148 >>9 byte x \b, frames %d
151 >>(2.S+2) use jpeg_segment
152 >>4 byte x \b, progressive, precision %d
153 >>7 beshort x \b, %dx
155 >>9 byte x \b, frames %d
157 # Define Huffman Tables
159 >>(2.S+2) use jpeg_segment
161 # Application specific markers
162 >0 beshort&0xFFE0 =0xFFE0
163 >>(2.S+2) use jpeg_segment
165 # DB: Define Quantization tables
166 # DD: Define Restart interval [XXX: wrong here, it is 4 bytes]
170 >0 beshort&0xFFD0 =0xFFD0
171 >>(2.S+2) use jpeg_segment
173 # HSI is Handmade Software's proprietary JPEG encoding scheme
174 0 string hsi1 JPEG image data, HSI proprietary
176 # From: David Santinoli <david@santinoli.com>
177 0 string \x00\x00\x00\x0C\x6A\x50\x20\x20\x0D\x0A\x87\x0A JPEG 2000
178 # From: Johan van der Knijff <johan.vanderknijff@kb.nl>
179 # Added sub-entries for JP2, JPX, JPM and MJ2 formats; added mimetypes
180 # https://github.com/bitsgalore/jp2kMagic
182 # Now read value of 'Brand' field, which yields a few possibilities:
183 >20 string \x6a\x70\x32\x20 Part 1 (JP2)
185 >20 string \x6a\x70\x78\x20 Part 2 (JPX)
187 >20 string \x6a\x70\x6d\x20 Part 6 (JPM)
189 >20 string \x6d\x6a\x70\x32 Part 3 (MJ2)
192 # Type: JPEG 2000 codesream
193 # From: Mathieu Malaterre <mathieu.malaterre@gmail.com>
194 0 belong 0xff4fff51 JPEG 2000 codestream