xref: /freebsd/contrib/file/magic/Magdir/jpeg (revision ae316d1d1cffd71ab7751f94e10118777a88e027)
1b6cee71dSXin LI
2b6cee71dSXin LI#------------------------------------------------------------------------------
3*ae316d1dSXin LI# $File: jpeg,v 1.40 2024/11/10 00:26:35 christos Exp $
4b6cee71dSXin LI# JPEG images
5b6cee71dSXin LI# SunOS 5.5.1 had
6b6cee71dSXin LI#
7b6cee71dSXin LI#	0	string		\377\330\377\340	JPEG file
8b6cee71dSXin LI#	0	string		\377\330\377\356	JPG file
9b6cee71dSXin LI#
10b6cee71dSXin LI# both of which turn into "JPEG image data" here.
11b6cee71dSXin LI#
1243a5ec4eSXin LI0	belong			0xffd8fff7	JPEG-LS image data
1343a5ec4eSXin LI!:mime	image/jls
1443a5ec4eSXin LI!:ext jls
1543a5ec4eSXin LI>0	use			jpeg
1643a5ec4eSXin LI
1743a5ec4eSXin LI0	belong&0xffffff00	0xffd8ff00	JPEG image data
18b6cee71dSXin LI!:mime	image/jpeg
19b6cee71dSXin LI!:apple	8BIMJPEG
205f0216bdSXin LI!:strength *3
215f0216bdSXin LI!:ext jpeg/jpg/jpe/jfif
2243a5ec4eSXin LI>0	use			jpeg
2343a5ec4eSXin LI
2443a5ec4eSXin LI0	name		jpeg
25b6cee71dSXin LI>6	string		JFIF		\b, JFIF standard
26b6cee71dSXin LI# The following added by Erik Rossen <rossen@freesurf.ch> 1999-09-06
27b6cee71dSXin LI# in a vain attempt to add image size reporting for JFIF.  Note that these
28b6cee71dSXin LI# tests are not fool-proof since some perfectly valid JPEGs are currently
29b6cee71dSXin LI# impossible to specify in magic(4) format.
30b6cee71dSXin LI# First, a little JFIF version info:
31b6cee71dSXin LI>>11	byte		x		\b %d.
32b6cee71dSXin LI>>12	byte		x		\b%02d
33b6cee71dSXin LI# Next, the resolution or aspect ratio of the image:
34c2931133SXin LI>>13	byte		0		\b, aspect ratio
35c2931133SXin LI>>13	byte		1		\b, resolution (DPI)
36c2931133SXin LI>>13	byte		2		\b, resolution (DPCM)
37*ae316d1dSXin LI>>14	ubeshort	x		\b, density %ux
38*ae316d1dSXin LI>>16	ubeshort	x		\b%u
39*ae316d1dSXin LI>>4	ubeshort	x		\b, segment length %u
40b6cee71dSXin LI# Next, show thumbnail info, if it exists:
41*ae316d1dSXin LI>>18	byte		!0		\b, thumbnail %ux
42*ae316d1dSXin LI>>>19	byte		x		\b%u
434460e5b0SXin LI>6	string		Exif		\b, Exif standard: [
444460e5b0SXin LI>>12	indirect/r	x
454460e5b0SXin LI>>12	string		x		\b]
46c2931133SXin LI
47c2931133SXin LI# Jump to the first segment
48c2931133SXin LI>(4.S+4)	use		jpeg_segment
49c2931133SXin LI
50c2931133SXin LI# This uses recursion...
51c2931133SXin LI0		name		jpeg_segment
52c2931133SXin LI>0	beshort		0xFFFE
535f0216bdSXin LI# Recursion handled by FFE0
545f0216bdSXin LI#>>(2.S+2)	use			jpeg_segment
55c2931133SXin LI>>2	pstring/HJ	x		\b, comment: "%s"
56c2931133SXin LI
57c2931133SXin LI>0	beshort		0xFFC0
58c2931133SXin LI>>(2.S+2)	use			jpeg_segment
59c2931133SXin LI>>4	byte		x		\b, baseline, precision %d
60*ae316d1dSXin LI>>7	ubeshort	x		\b, %ux
61*ae316d1dSXin LI>>5	ubeshort	x		\b%u
6248c779cdSXin LI>>9	byte		x		\b, components %d
63c2931133SXin LI
64c2931133SXin LI>0	beshort		0xFFC1
65c2931133SXin LI>>(2.S+2)	use			jpeg_segment
66c2931133SXin LI>>4	byte		x		\b, extended sequential, precision %d
67*ae316d1dSXin LI>>7	ubeshort	x		\b, %ux
68*ae316d1dSXin LI>>5	ubeshort	x		\b%u
6948c779cdSXin LI>>9	byte		x		\b, components %d
70c2931133SXin LI
71c2931133SXin LI>0	beshort		0xFFC2
72c2931133SXin LI>>(2.S+2)	use			jpeg_segment
73c2931133SXin LI>>4	byte		x		\b, progressive, precision %d
74*ae316d1dSXin LI>>7	ubeshort	x		\b, %ux
75*ae316d1dSXin LI>>5	ubeshort	x		\b%u
7648c779cdSXin LI>>9	byte		x		\b, components %d
77c2931133SXin LI
78c2931133SXin LI# Define Huffman Tables
79c2931133SXin LI>0	beshort		0xFFC4
80c2931133SXin LI>>(2.S+2)	use			jpeg_segment
81c2931133SXin LI
824460e5b0SXin LI>0	beshort		0xFFE1
835f0216bdSXin LI# Recursion handled by FFE0
844460e5b0SXin LI#>>(2.S+2)	use			jpeg_segment
854460e5b0SXin LI>>4	string		Exif		\b, Exif Standard: [
864460e5b0SXin LI>>>10	indirect/r	x
874460e5b0SXin LI>>>10	string		x		\b]
884460e5b0SXin LI
89c2931133SXin LI# Application specific markers
90c2931133SXin LI>0	beshort&0xFFE0	=0xFFE0
91c2931133SXin LI>>(2.S+2)	use			jpeg_segment
92c2931133SXin LI
93c2931133SXin LI# DB: Define Quantization tables
94c2931133SXin LI# DD: Define Restart interval [XXX: wrong here, it is 4 bytes]
95c2931133SXin LI# D8: Start of image
96c2931133SXin LI# D9: End of image
97c2931133SXin LI# Dn: Restart
98c2931133SXin LI>0	beshort&0xFFD0	=0xFFD0
995f0216bdSXin LI>>0	beshort&0xFFE0	!0xFFE0
1005f0216bdSXin LI>>>(2.S+2)	use			jpeg_segment
101b6cee71dSXin LI
10243a5ec4eSXin LI#>0	beshort		x		unknown %#x
1034460e5b0SXin LI#>>(2.S+2)	use			jpeg_segment
1044460e5b0SXin LI
105b6cee71dSXin LI# HSI is Handmade Software's proprietary JPEG encoding scheme
106a2dfb722SXin LI# Update:	Joerg Jenderek
107a2dfb722SXin LI# URL:		http://fileformats.archiveteam.org/wiki/HSI_JPEG
108a2dfb722SXin LI# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-hsi1.trid.xml
109a2dfb722SXin LI# Note:         called by TrID "HSI JPEG bitmap"
110b6cee71dSXin LI0	string		hsi1		JPEG image data, HSI proprietary
111a2dfb722SXin LI#!:mime	application/octet-stream
112a2dfb722SXin LI!:mime	image/x-hsi
113a2dfb722SXin LI!:ext	hsi/jpg
114b6cee71dSXin LI
115b6cee71dSXin LI# From: David Santinoli <david@santinoli.com>
116b6cee71dSXin LI0	string		\x00\x00\x00\x0C\x6A\x50\x20\x20\x0D\x0A\x87\x0A	JPEG 2000
117a2dfb722SXin LI# delete from ./animation (version 1.87) with jP (=6A50h) magic at offset 4
118b6cee71dSXin LI# From: Johan van der Knijff <johan.vanderknijff@kb.nl>
119b6cee71dSXin LI# Added sub-entries for JP2, JPX, JPM and MJ2 formats; added mimetypes
120b6cee71dSXin LI# https://github.com/bitsgalore/jp2kMagic
121b6cee71dSXin LI#
122b6cee71dSXin LI# Now read value of 'Brand' field, which yields a few possibilities:
123a2dfb722SXin LI# Update:	Joerg Jenderek
124a2dfb722SXin LI# URL:		http://fileformats.archiveteam.org/wiki/JP2
125a2dfb722SXin LI# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-jpeg2k.trid.xml
126a2dfb722SXin LI# Note:         called by TrID "JPEG 2000 bitmap"
127b6cee71dSXin LI>20	string		\x6a\x70\x32\x20	Part 1 (JP2)
128a2dfb722SXin LI# aliases	image/jpeg2000, image/jpeg2000-image, image/x-jpeg2000-image
129b6cee71dSXin LI!:mime	image/jp2
130a2dfb722SXin LI!:ext	jp2
131a2dfb722SXin LI# URL:		http://fileformats.archiveteam.org/wiki/JPX
132a2dfb722SXin LI# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-jpx.trid.xml
133a2dfb722SXin LI# Note:         called by TrID "JPEG 2000 eXtended bitmap"
134b6cee71dSXin LI>20	string		\x6a\x70\x78\x20	Part 2 (JPX)
135b6cee71dSXin LI!:mime	image/jpx
136a2dfb722SXin LI!:ext	jpf/jpx
137a2dfb722SXin LI# URL:		http://fileformats.archiveteam.org/wiki/JPM
138a2dfb722SXin LI# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-jpm.trid.xml
139a2dfb722SXin LI# Note:         called by TrID "JPEG 2000 eXtended bitmap"
140b6cee71dSXin LI>20	string		\x6a\x70\x6d\x20	Part 6 (JPM)
141b6cee71dSXin LI!:mime	image/jpm
142a2dfb722SXin LI!:ext	jpm
143a2dfb722SXin LI# URL:		http://fileformats.archiveteam.org/wiki/MJ2
144a2dfb722SXin LI# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/v/video-mj2.trid.xml
145a2dfb722SXin LI# Note:         called by TrID "Motion JPEG 2000 video"
146b6cee71dSXin LI>20	string		\x6d\x6a\x70\x32	Part 3 (MJ2)
147b6cee71dSXin LI!:mime	video/mj2
148a2dfb722SXin LI!:ext	mj2/mjp2
149b6cee71dSXin LI
150b6cee71dSXin LI# Type: JPEG 2000 codesream
151b6cee71dSXin LI# From: Mathieu Malaterre <mathieu.malaterre@gmail.com>
152a2dfb722SXin LI# Update:	Joerg Jenderek
153a2dfb722SXin LI# URL:		http://fileformats.archiveteam.org/wiki/JPEG_2000_codestream
154a2dfb722SXin LI# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-jpc.trid.xml
155a2dfb722SXin LI# Note:         called by TrID "JPEG-2000 Code Stream bitmap"
156b6cee71dSXin LI0	belong		0xff4fff51						JPEG 2000 codestream
157a2dfb722SXin LI# value like: 0701h FF50h
158a2dfb722SXin LI#>45	ubeshort	x	\b, at 45 %#4.4x
159a2dfb722SXin LI#!:mime	application/octet-stream
160a2dfb722SXin LI# https://reposcope.com/mimetype/image/x-jp2-codestream
161a2dfb722SXin LI!:mime	image/x-jp2-codestream
162a2dfb722SXin LI!:ext	jpc/j2c/j2k
163a2dfb722SXin LI# MAYBE also JHC like in byte_causal.jhc ?
164a2dfb722SXin LI# WHAT IS THAT? DEAD ENTRY?
165a2dfb722SXin LI#45	beshort		0xff52
166a5d223e6SXin LI
167a5d223e6SXin LI# JPEG extended range
168*ae316d1dSXin LI# Update:	Joerg Jenderek 2023
169a2dfb722SXin LI# URL:		http://fileformats.archiveteam.org/wiki/JPEG_XR
170a2dfb722SXin LI# Reference:	https://www.itu.int/rec/T-REC-T.832
171a2dfb722SXin LI#		http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-wmp.trid.xml
172*ae316d1dSXin LI#		http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-jxr.trid.xml
173*ae316d1dSXin LI# Note:         called by TrID "JPEG XR bitmap" and "JPEG XR bitmap (WMPHOTO)"
174*ae316d1dSXin LI#		verified as "JPEG XR" by XnView `nconvert -fullinfo *.jxr *.wdp`
175*ae316d1dSXin LI#		partly by ImageMagick command `identify -verbose *.wdp`
176*ae316d1dSXin LI#		and libjxr-tools `JxrDecApp -v -i example.wdp -o example.tif`
177a5d223e6SXin LI0	string		\x49\x49\xbc
178*ae316d1dSXin LI# FILE_VERSION_ID; shall be equal to 1; other values are reserved for future use and are unlike to appear
179a5d223e6SXin LI>3	byte		1
180a2dfb722SXin LI# FIRST_IFD_OFFSET; shall be an integer multiple of 2; so skip DROID fmt-590-signature-id-931.wdp
181*ae316d1dSXin LI>>4	lelong%2	0	JPEG-XR Image
182a2dfb722SXin LI#!:mime	image/vnd.ms-photo
183a5d223e6SXin LI!:mime	image/jxr
184a2dfb722SXin LI# NO example for HDP !
185a2dfb722SXin LI!:ext	jxr/wdp/hdp
186a2dfb722SXin LI# MAYBE also WMP ?
187a2dfb722SXin LI#!:ext	jxr/wdp/hdp/wmp
188*ae316d1dSXin LI# moved from ./images (version 1.243 ) and merged
189*ae316d1dSXin LI# example:
190a2dfb722SXin LI# http://shikino.co.jp/solution/upfile/FLOWER.wdp.zip
191*ae316d1dSXin LI# often GDI_SIGNATURE "WMPHOTO\0" at offset 90 like: FLOWER.wdp abydos.jxr SMALLTOMATO.wdp
192*ae316d1dSXin LI>90	bequad		0x574D50484F544F00
193*ae316d1dSXin LI>>0	use	jxr-info
194*ae316d1dSXin LI# seldom no GDI_SIGNATURE WMPHOTO\0 at offset 90 like: example.wdp MARKET-3361-ipm-bg-DE-treat[1].wdp
195*ae316d1dSXin LI>90	bequad		!0x574D50484F544F00
196*ae316d1dSXin LI# look for GDI_SIGNATURE WMPHOTO\0 at other offset
197*ae316d1dSXin LI>>4	search/3267/sb	WMPHOTO\0
198*ae316d1dSXin LI>>>&-90	use	jxr-info
199*ae316d1dSXin LI#
200*ae316d1dSXin LI0	name	jxr-info
201*ae316d1dSXin LI# check for GDI_SIGNATURE that corresponds to "WMPHOTO\0"
202a2dfb722SXin LI>90	bequad		0x574D50484F544F00
203a2dfb722SXin LI>>98	byte&0x08	=0x08			\b, hard tiling
204a2dfb722SXin LI>>99	byte&0x80	=0x80			\b, tiling present
205a2dfb722SXin LI>>99	byte&0x40	=0x40			\b, codestream present
206a2dfb722SXin LI>>99	byte&0x38	x			\b, spatial xform=
207a2dfb722SXin LI>>99	byte&0x38	0x00			\bTL
208a2dfb722SXin LI>>99	byte&0x38	0x08			\bBL
209a2dfb722SXin LI>>99	byte&0x38	0x10			\bTR
210a2dfb722SXin LI>>99	byte&0x38	0x18			\bBR
211a2dfb722SXin LI>>99	byte&0x38	0x20			\bBT
212a2dfb722SXin LI>>99	byte&0x38	0x28			\bRB
213a2dfb722SXin LI>>99	byte&0x38	0x30			\bLT
214a2dfb722SXin LI>>99	byte&0x38	0x38			\bLB
215a2dfb722SXin LI>>100	byte&0x80	=0x80			\b, short header
216*ae316d1dSXin LI>>>102	beshort+1	x			\b, %u
217*ae316d1dSXin LI>>>104	beshort+1	x			\bx%u
218a2dfb722SXin LI>>100	byte&0x80	=0x00			\b, long header
219a2dfb722SXin LI>>>102	belong+1	x			\b, %x
220a2dfb722SXin LI>>>106	belong+1	x			\bx%x
221a2dfb722SXin LI>>101	beshort&0xf	x			\b, bitdepth=
222a2dfb722SXin LI>>>101	beshort&0xf	0x0			\b1-WHITE=1
223a2dfb722SXin LI>>>101	beshort&0xf	0x1			\b8
224a2dfb722SXin LI>>>101	beshort&0xf	0x2			\b16
225a2dfb722SXin LI>>>101	beshort&0xf	0x3			\b16-SIGNED
226a2dfb722SXin LI>>>101	beshort&0xf	0x4			\b16-FLOAT
227a2dfb722SXin LI>>>101	beshort&0xf	0x5			\b(reserved 5)
228a2dfb722SXin LI>>>101	beshort&0xf	0x6			\b32-SIGNED
229a2dfb722SXin LI>>>101	beshort&0xf	0x7			\b32-FLOAT
230a2dfb722SXin LI>>>101	beshort&0xf	0x8			\b5
231a2dfb722SXin LI>>>101	beshort&0xf	0x9			\b10
232a2dfb722SXin LI>>>101	beshort&0xf	0xa			\b5-6-5
233a2dfb722SXin LI>>>101	beshort&0xf	0xb			\b(reserved %d)
234a2dfb722SXin LI>>>101	beshort&0xf	0xc			\b(reserved %d)
235a2dfb722SXin LI>>>101	beshort&0xf	0xd			\b(reserved %d)
236a2dfb722SXin LI>>>101	beshort&0xf	0xe			\b(reserved %d)
237a2dfb722SXin LI>>>101	beshort&0xf	0xf			\b1-BLACK=1
238a2dfb722SXin LI>>101	beshort&0xf0	x			\b, colorfmt=
239a2dfb722SXin LI>>>101	beshort&0xf0	0x00			\bYONLY
240a2dfb722SXin LI>>>101	beshort&0xf0	0x10			\bYUV240
241a2dfb722SXin LI>>>101	beshort&0xf0	0x20			\bYWV422
242a2dfb722SXin LI>>>101	beshort&0xf0	0x30			\bYWV444
243a2dfb722SXin LI>>>101	beshort&0xf0	0x40			\bCMYK
244a2dfb722SXin LI>>>101	beshort&0xf0	0x50			\bCMYKDIRECT
245a2dfb722SXin LI>>>101	beshort&0xf0	0x60			\bNCOMPONENT
246a2dfb722SXin LI>>>101	beshort&0xf0	0x70			\bRGB
247a2dfb722SXin LI>>>101	beshort&0xf0	0x80			\bRGBE
248a2dfb722SXin LI>>>101	beshort&0xf0	>0x80			\b(reserved %#x)
24943a5ec4eSXin LI
25043a5ec4eSXin LI# JPEG XL
25143a5ec4eSXin LI# From: Ian Tester
252a2dfb722SXin LI# Update:	Joerg Jenderek
253a2dfb722SXin LI# URL:		http://fileformats.archiveteam.org/wiki/JPEG_XL
254a2dfb722SXin LI# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-jxl.trid.xml
255a2dfb722SXin LI# Note:         called by TrID "JPEG XL bitmap"
25643a5ec4eSXin LI0	string	\xff\x0a				JPEG XL codestream
257898496eeSXin LI!:mime	image/jxl
25843a5ec4eSXin LI!:ext jxl
25943a5ec4eSXin LI
26043a5ec4eSXin LI# JPEG XL (transcoded JPEG file)
261a2dfb722SXin LI# Update:	Joerg Jenderek
262a2dfb722SXin LI# URL:		http://fileformats.archiveteam.org/wiki/JPEG_XL
263a2dfb722SXin LI# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-jxl-iso.trid.xml
264a2dfb722SXin LI# Note:         called by TrID "JPEG XL bitmap (ISOBMFF)"
26543a5ec4eSXin LI0	string	\x00\x00\x00\x0cJXL\x20\x0d\x0a\x87\x0a	JPEG XL container
266898496eeSXin LI!:mime	image/jxl
26743a5ec4eSXin LI!:ext jxl
268