Deleted Added
full compact
jpeg (267897) jpeg (275698)
1
2#------------------------------------------------------------------------------
1
2#------------------------------------------------------------------------------
3# $File: jpeg,v 1.19 2013/02/04 15:50:03 christos Exp $
3# $File: jpeg,v 1.21 2014/09/12 20:47:00 christos Exp $
4# JPEG images
5# SunOS 5.5.1 had
6#
7# 0 string \377\330\377\340 JPEG file
8# 0 string \377\330\377\356 JPG file
9#
10# both of which turn into "JPEG image data" here.
11#
120 beshort 0xffd8 JPEG image data
13!:mime image/jpeg
14!:apple 8BIMJPEG
15!:strength +2
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:
22>>11 byte x \b %d.
23>>12 byte x \b%02d
24# Next, the resolution or aspect ratio of the image:
4# JPEG images
5# SunOS 5.5.1 had
6#
7# 0 string \377\330\377\340 JPEG file
8# 0 string \377\330\377\356 JPG file
9#
10# both of which turn into "JPEG image data" here.
11#
120 beshort 0xffd8 JPEG image data
13!:mime image/jpeg
14!:apple 8BIMJPEG
15!:strength +2
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:
22>>11 byte x \b %d.
23>>12 byte x \b%02d
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#>>4 beshort x \b, segment length %d
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
29>>16 beshort x \b%d
30>>4 beshort x \b, segment length %d
29# Next, show thumbnail info, if it exists:
30>>18 byte !0 \b, thumbnail %dx
31>>>19 byte x \b%d
32
33# EXIF moved down here to avoid reporting a bogus version number,
34# and EXIF version number printing added.
35# - Patrik R=E5dman <patrik+file-magic@iki.fi>
36>6 string Exif \b, EXIF standard
37# Look for EXIF IFD offset in IFD 0, and then look for EXIF version tag in EXIF IFD.
38# All possible combinations of entries have to be enumerated, since no looping
39# is possible. And both endians are possible...
40# The combinations included below are from real-world JPEGs.
41# Little-endian
42>>12 string II
43# IFD 0 Entry #5:
44>>>70 leshort 0x8769
45# EXIF IFD Entry #1:
46>>>>(78.l+14) leshort 0x9000
47>>>>>(78.l+23) byte x %c
48>>>>>(78.l+24) byte x \b.%c
49>>>>>(78.l+25) byte !0x30 \b%c
50# IFD 0 Entry #9:
51>>>118 leshort 0x8769
52# EXIF IFD Entry #3:
53>>>>(126.l+38) leshort 0x9000
54>>>>>(126.l+47) byte x %c
55>>>>>(126.l+48) byte x \b.%c
56>>>>>(126.l+49) byte !0x30 \b%c
57# IFD 0 Entry #10
58>>>130 leshort 0x8769
59# EXIF IFD Entry #3:
60>>>>(138.l+38) leshort 0x9000
61>>>>>(138.l+47) byte x %c
62>>>>>(138.l+48) byte x \b.%c
63>>>>>(138.l+49) byte !0x30 \b%c
64# EXIF IFD Entry #4:
65>>>>(138.l+50) leshort 0x9000
66>>>>>(138.l+59) byte x %c
67>>>>>(138.l+60) byte x \b.%c
68>>>>>(138.l+61) byte !0x30 \b%c
69# EXIF IFD Entry #5:
70>>>>(138.l+62) leshort 0x9000
71>>>>>(138.l+71) byte x %c
72>>>>>(138.l+72) byte x \b.%c
73>>>>>(138.l+73) byte !0x30 \b%c
74# IFD 0 Entry #11
75>>>142 leshort 0x8769
76# EXIF IFD Entry #3:
77>>>>(150.l+38) leshort 0x9000
78>>>>>(150.l+47) byte x %c
79>>>>>(150.l+48) byte x \b.%c
80>>>>>(150.l+49) byte !0x30 \b%c
81# EXIF IFD Entry #4:
82>>>>(150.l+50) leshort 0x9000
83>>>>>(150.l+59) byte x %c
84>>>>>(150.l+60) byte x \b.%c
85>>>>>(150.l+61) byte !0x30 \b%c
86# EXIF IFD Entry #5:
87>>>>(150.l+62) leshort 0x9000
88>>>>>(150.l+71) byte x %c
89>>>>>(150.l+72) byte x \b.%c
90>>>>>(150.l+73) byte !0x30 \b%c
91# Big-endian
92>>12 string MM
93# IFD 0 Entry #9:
94>>>118 beshort 0x8769
95# EXIF IFD Entry #1:
96>>>>(126.L+14) beshort 0x9000
97>>>>>(126.L+23) byte x %c
98>>>>>(126.L+24) byte x \b.%c
99>>>>>(126.L+25) byte !0x30 \b%c
100# EXIF IFD Entry #3:
101>>>>(126.L+38) beshort 0x9000
102>>>>>(126.L+47) byte x %c
103>>>>>(126.L+48) byte x \b.%c
104>>>>>(126.L+49) byte !0x30 \b%c
105# IFD 0 Entry #10
106>>>130 beshort 0x8769
107# EXIF IFD Entry #3:
108>>>>(138.L+38) beshort 0x9000
109>>>>>(138.L+47) byte x %c
110>>>>>(138.L+48) byte x \b.%c
111>>>>>(138.L+49) byte !0x30 \b%c
112# EXIF IFD Entry #5:
113>>>>(138.L+62) beshort 0x9000
114>>>>>(138.L+71) byte x %c
115>>>>>(138.L+72) byte x \b.%c
116>>>>>(138.L+73) byte !0x30 \b%c
117# IFD 0 Entry #11
118>>>142 beshort 0x8769
119# EXIF IFD Entry #4:
120>>>>(150.L+50) beshort 0x9000
121>>>>>(150.L+59) byte x %c
122>>>>>(150.L+60) byte x \b.%c
123>>>>>(150.L+61) byte !0x30 \b%c
31# Next, show thumbnail info, if it exists:
32>>18 byte !0 \b, thumbnail %dx
33>>>19 byte x \b%d
34
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.
43# Little-endian
44>>12 string II
45# IFD 0 Entry #5:
46>>>70 leshort 0x8769
47# EXIF IFD Entry #1:
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
52# IFD 0 Entry #9:
53>>>118 leshort 0x8769
54# EXIF IFD Entry #3:
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
59# IFD 0 Entry #10
60>>>130 leshort 0x8769
61# EXIF IFD Entry #3:
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
66# EXIF IFD Entry #4:
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
71# EXIF IFD Entry #5:
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
76# IFD 0 Entry #11
77>>>142 leshort 0x8769
78# EXIF IFD Entry #3:
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
83# EXIF IFD Entry #4:
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
88# EXIF IFD Entry #5:
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
93# Big-endian
94>>12 string MM
95# IFD 0 Entry #9:
96>>>118 beshort 0x8769
97# EXIF IFD Entry #1:
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
102# EXIF IFD Entry #3:
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
107# IFD 0 Entry #10
108>>>130 beshort 0x8769
109# EXIF IFD Entry #3:
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
114# EXIF IFD Entry #5:
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
119# IFD 0 Entry #11
120>>>142 beshort 0x8769
121# EXIF IFD Entry #4:
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
124# Here things get sticky. We can do ONE MORE marker segment with
125# indirect addressing, and that's all. It would be great if we could
126# do pointer arithemetic like in an assembler language. Christos?
127# And if there was some sort of looping construct to do searches, plus a few
128# named accumulators, it would be even more effective...
129# At least we can show a comment if no other segments got inserted before:
130>(4.S+5) byte 0xFE \b, comment:
131>>(4.S+6) pstring/HJ x "%s"
132# Or, we can show the encoding type (I've included only the three most common)
133# and image dimensions if we are lucky and the SOFn (image segment) is here:
134>(4.S+5) byte 0xC0 \b, baseline
135>>(4.S+6) byte x \b, precision %d
136>>(4.S+7) beshort x \b, %dx
137>>(4.S+9) beshort x \b%d
138>(4.S+5) byte 0xC1 \b, extended sequential
139>>(4.S+6) byte x \b, precision %d
140>>(4.S+7) beshort x \b, %dx
141>>(4.S+9) beshort x \b%d
142>(4.S+5) byte 0xC2 \b, progressive
143>>(4.S+6) byte x \b, precision %d
144>>(4.S+7) beshort x \b, %dx
145>>(4.S+9) beshort x \b%d
146# I've commented-out quantisation table reporting. I doubt anyone cares yet.
147#>(4.S+5) byte 0xDB \b, quantisation table
148#>>(4.S+6) beshort x \b length=%d
149#>14 beshort x \b, %d x
150#>16 beshort x \b %d
151
126
127# Jump to the first segment
128>(4.S+4) use jpeg_segment
129
130# This uses recursion...
1310 name jpeg_segment
132>0 beshort 0xFFFE
133>>(2.S+2) use jpeg_segment
134>>2 pstring/HJ x \b, comment: "%s"
135
136>0 beshort 0xFFC0
137>>(2.S+2) use jpeg_segment
138>>4 byte x \b, baseline, precision %d
139>>7 beshort x \b, %dx
140>>5 beshort x \b%d
141>>9 byte x \b, frames %d
142
143>0 beshort 0xFFC1
144>>(2.S+2) use jpeg_segment
145>>4 byte x \b, extended sequential, precision %d
146>>7 beshort x \b, %dx
147>>5 beshort x \b%d
148>>9 byte x \b, frames %d
149
150>0 beshort 0xFFC2
151>>(2.S+2) use jpeg_segment
152>>4 byte x \b, progressive, precision %d
153>>7 beshort x \b, %dx
154>>5 beshort x \b%d
155>>9 byte x \b, frames %d
156
157# Define Huffman Tables
158>0 beshort 0xFFC4
159>>(2.S+2) use jpeg_segment
160
161# Application specific markers
162>0 beshort&0xFFE0 =0xFFE0
163>>(2.S+2) use jpeg_segment
164
165# DB: Define Quantization tables
166# DD: Define Restart interval [XXX: wrong here, it is 4 bytes]
167# D8: Start of image
168# D9: End of image
169# Dn: Restart
170>0 beshort&0xFFD0 =0xFFD0
171>>(2.S+2) use jpeg_segment
172
152# HSI is Handmade Software's proprietary JPEG encoding scheme
1530 string hsi1 JPEG image data, HSI proprietary
154
155# From: David Santinoli <david@santinoli.com>
1560 string \x00\x00\x00\x0C\x6A\x50\x20\x20\x0D\x0A\x87\x0A JPEG 2000
157# From: Johan van der Knijff <johan.vanderknijff@kb.nl>
158# Added sub-entries for JP2, JPX, JPM and MJ2 formats; added mimetypes
159# https://github.com/bitsgalore/jp2kMagic
160#
161# Now read value of 'Brand' field, which yields a few possibilities:
162>20 string \x6a\x70\x32\x20 Part 1 (JP2)
163!:mime image/jp2
164>20 string \x6a\x70\x78\x20 Part 2 (JPX)
165!:mime image/jpx
166>20 string \x6a\x70\x6d\x20 Part 6 (JPM)
167!:mime image/jpm
168>20 string \x6d\x6a\x70\x32 Part 3 (MJ2)
169!:mime video/mj2
170
171# Type: JPEG 2000 codesream
172# From: Mathieu Malaterre <mathieu.malaterre@gmail.com>
1730 belong 0xff4fff51 JPEG 2000 codestream
17445 beshort 0xff52
173# HSI is Handmade Software's proprietary JPEG encoding scheme
1740 string hsi1 JPEG image data, HSI proprietary
175
176# From: David Santinoli <david@santinoli.com>
1770 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
181#
182# Now read value of 'Brand' field, which yields a few possibilities:
183>20 string \x6a\x70\x32\x20 Part 1 (JP2)
184!:mime image/jp2
185>20 string \x6a\x70\x78\x20 Part 2 (JPX)
186!:mime image/jpx
187>20 string \x6a\x70\x6d\x20 Part 6 (JPM)
188!:mime image/jpm
189>20 string \x6d\x6a\x70\x32 Part 3 (MJ2)
190!:mime video/mj2
191
192# Type: JPEG 2000 codesream
193# From: Mathieu Malaterre <mathieu.malaterre@gmail.com>
1940 belong 0xff4fff51 JPEG 2000 codestream
19545 beshort 0xff52