xref: /freebsd/contrib/file/magic/Magdir/jpeg (revision 62cfcf62f627e5093fb37026a6d8c98e4d2ef04c)
1
2#------------------------------------------------------------------------------
3# $File: jpeg,v 1.32 2018/10/01 18:58:29 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 *3
16!:ext jpeg/jpg/jpe/jfif
17>6	string		JFIF		\b, JFIF standard
18# The following added by Erik Rossen <rossen@freesurf.ch> 1999-09-06
19# in a vain attempt to add image size reporting for JFIF.  Note that these
20# tests are not fool-proof since some perfectly valid JPEGs are currently
21# impossible to specify in magic(4) format.
22# First, a little JFIF version info:
23>>11	byte		x		\b %d.
24>>12	byte		x		\b%02d
25# Next, the resolution or aspect ratio of the image:
26>>13	byte		0		\b, aspect ratio
27>>13	byte		1		\b, resolution (DPI)
28>>13	byte		2		\b, resolution (DPCM)
29>>14	beshort		x		\b, density %dx
30>>16	beshort		x		\b%d
31>>4	beshort		x		\b, segment length %d
32# Next, show thumbnail info, if it exists:
33>>18	byte		!0		\b, thumbnail %dx
34>>>19	byte		x		\b%d
35>6	string		Exif		\b, Exif standard: [
36>>12	indirect/r	x
37>>12	string		x		\b]
38
39# Jump to the first segment
40>(4.S+4)	use		jpeg_segment
41
42# This uses recursion...
430		name		jpeg_segment
44>0	beshort		0xFFFE
45# Recursion handled by FFE0
46#>>(2.S+2)	use			jpeg_segment
47>>2	pstring/HJ	x		\b, comment: "%s"
48
49>0	beshort		0xFFC0
50>>(2.S+2)	use			jpeg_segment
51>>4	byte		x		\b, baseline, precision %d
52>>7	beshort		x		\b, %dx
53>>5	beshort		x		\b%d
54>>9	byte		x		\b, components %d
55
56>0	beshort		0xFFC1
57>>(2.S+2)	use			jpeg_segment
58>>4	byte		x		\b, extended sequential, precision %d
59>>7	beshort		x		\b, %dx
60>>5	beshort		x		\b%d
61>>9	byte		x		\b, components %d
62
63>0	beshort		0xFFC2
64>>(2.S+2)	use			jpeg_segment
65>>4	byte		x		\b, progressive, precision %d
66>>7	beshort		x		\b, %dx
67>>5	beshort		x		\b%d
68>>9	byte		x		\b, components %d
69
70# Define Huffman Tables
71>0	beshort		0xFFC4
72>>(2.S+2)	use			jpeg_segment
73
74>0	beshort		0xFFE1
75# Recursion handled by FFE0
76#>>(2.S+2)	use			jpeg_segment
77>>4	string		Exif		\b, Exif Standard: [
78>>>10	indirect/r	x
79>>>10	string		x		\b]
80
81# Application specific markers
82>0	beshort&0xFFE0	=0xFFE0
83>>(2.S+2)	use			jpeg_segment
84
85# DB: Define Quantization tables
86# DD: Define Restart interval [XXX: wrong here, it is 4 bytes]
87# D8: Start of image
88# D9: End of image
89# Dn: Restart
90>0	beshort&0xFFD0	=0xFFD0
91>>0	beshort&0xFFE0	!0xFFE0
92>>>(2.S+2)	use			jpeg_segment
93
94#>0	beshort		x		unknown 0x%x
95#>>(2.S+2)	use			jpeg_segment
96
97# HSI is Handmade Software's proprietary JPEG encoding scheme
980	string		hsi1		JPEG image data, HSI proprietary
99
100# From: David Santinoli <david@santinoli.com>
1010	string		\x00\x00\x00\x0C\x6A\x50\x20\x20\x0D\x0A\x87\x0A	JPEG 2000
102# From: Johan van der Knijff <johan.vanderknijff@kb.nl>
103# Added sub-entries for JP2, JPX, JPM and MJ2 formats; added mimetypes
104# https://github.com/bitsgalore/jp2kMagic
105#
106# Now read value of 'Brand' field, which yields a few possibilities:
107>20	string		\x6a\x70\x32\x20	Part 1 (JP2)
108!:mime	image/jp2
109>20	string		\x6a\x70\x78\x20	Part 2 (JPX)
110!:mime	image/jpx
111>20	string		\x6a\x70\x6d\x20	Part 6 (JPM)
112!:mime	image/jpm
113>20	string		\x6d\x6a\x70\x32	Part 3 (MJ2)
114!:mime	video/mj2
115
116# Type: JPEG 2000 codesream
117# From: Mathieu Malaterre <mathieu.malaterre@gmail.com>
1180	belong		0xff4fff51						JPEG 2000 codestream
11945	beshort		0xff52
120
121# JPEG extended range
1220	string		\x49\x49\xbc
123>3	byte		1
124>>4	lelong%2	0	JPEG-XR
125!:mime	image/jxr
126!:ext	jxr
127