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