xref: /freebsd/contrib/file/magic/Magdir/jpeg (revision e92ffd9b626833ebdbf2742c8ffddc6cd94b963e)
1
2#------------------------------------------------------------------------------
3# $File: jpeg,v 1.36 2021/08/28 12:30:52 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	beshort		x		\b, density %dx
38>>16	beshort		x		\b%d
39>>4	beshort		x		\b, segment length %d
40# Next, show thumbnail info, if it exists:
41>>18	byte		!0		\b, thumbnail %dx
42>>>19	byte		x		\b%d
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	beshort		x		\b, %dx
61>>5	beshort		x		\b%d
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	beshort		x		\b, %dx
68>>5	beshort		x		\b%d
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	beshort		x		\b, %dx
75>>5	beshort		x		\b%d
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
1060	string		hsi1		JPEG image data, HSI proprietary
107
108# From: David Santinoli <david@santinoli.com>
1090	string		\x00\x00\x00\x0C\x6A\x50\x20\x20\x0D\x0A\x87\x0A	JPEG 2000
110# From: Johan van der Knijff <johan.vanderknijff@kb.nl>
111# Added sub-entries for JP2, JPX, JPM and MJ2 formats; added mimetypes
112# https://github.com/bitsgalore/jp2kMagic
113#
114# Now read value of 'Brand' field, which yields a few possibilities:
115>20	string		\x6a\x70\x32\x20	Part 1 (JP2)
116!:mime	image/jp2
117>20	string		\x6a\x70\x78\x20	Part 2 (JPX)
118!:mime	image/jpx
119>20	string		\x6a\x70\x6d\x20	Part 6 (JPM)
120!:mime	image/jpm
121>20	string		\x6d\x6a\x70\x32	Part 3 (MJ2)
122!:mime	video/mj2
123
124# Type: JPEG 2000 codesream
125# From: Mathieu Malaterre <mathieu.malaterre@gmail.com>
1260	belong		0xff4fff51						JPEG 2000 codestream
12745	beshort		0xff52
128
129# JPEG extended range
1300	string		\x49\x49\xbc
131>3	byte		1
132>>4	lelong%2	0	JPEG-XR
133!:mime	image/jxr
134!:ext	jxr
135
136# JPEG XL
137# From: Ian Tester
1380	string	\xff\x0a				JPEG XL codestream
139!:mime  image/jxl
140!:ext jxl
141
142# JPEG XL (transcoded JPEG file)
1430	string	\x00\x00\x00\x0cJXL\x20\x0d\x0a\x87\x0a	JPEG XL container
144!:mime  image/jxl
145!:ext jxl
146