jpeg revision 276415
1
2#------------------------------------------------------------------------------
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:
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
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
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
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
196