168349Sobrien
268349Sobrien#------------------------------------------------------------------------------
3284193Sdelphij# $File: jpeg,v 1.25 2015/01/02 16:56:50 christos Exp $
468349Sobrien# JPEG images
568349Sobrien# SunOS 5.5.1 had
668349Sobrien#
768349Sobrien#	0	string		\377\330\377\340	JPEG file
868349Sobrien#	0	string		\377\330\377\356	JPG file
968349Sobrien#
1068349Sobrien# both of which turn into "JPEG image data" here.
1168349Sobrien#
1268349Sobrien0	beshort		0xffd8		JPEG image data
13186690Sobrien!:mime	image/jpeg
14191736Sobrien!:apple	8BIMJPEG
15267843Sdelphij!:strength +2
1668349Sobrien>6	string		JFIF		\b, JFIF standard
1768349Sobrien# The following added by Erik Rossen <rossen@freesurf.ch> 1999-09-06
1868349Sobrien# in a vain attempt to add image size reporting for JFIF.  Note that these
1968349Sobrien# tests are not fool-proof since some perfectly valid JPEGs are currently
2068349Sobrien# impossible to specify in magic(4) format.
2168349Sobrien# First, a little JFIF version info:
22133359Sobrien>>11	byte		x		\b %d.
23133359Sobrien>>12	byte		x		\b%02d
2468349Sobrien# Next, the resolution or aspect ratio of the image:
25284193Sdelphij>>13	byte		0		\b, aspect ratio
26284193Sdelphij>>13	byte		1		\b, resolution (DPI)
27284193Sdelphij>>13	byte		2		\b, resolution (DPCM)
28284193Sdelphij>>14	beshort		x		\b, density %dx
29284193Sdelphij>>16	beshort		x		\b%d
30284193Sdelphij>>4	beshort		x		\b, segment length %d
3168349Sobrien# Next, show thumbnail info, if it exists:
32133359Sobrien>>18	byte		!0		\b, thumbnail %dx
33133359Sobrien>>>19	byte		x		\b%d
34284193Sdelphij>6	string		Exif		\b, Exif standard: [
35284193Sdelphij>>12	indirect/r	x
36284193Sdelphij>>12	string		x		\b]
37133359Sobrien
38284193Sdelphij# Jump to the first segment
39284193Sdelphij>(4.S+4)	use		jpeg_segment
4068349Sobrien
41284193Sdelphij# This uses recursion...
42284193Sdelphij0		name		jpeg_segment
43284193Sdelphij>0	beshort		0xFFFE
44284193Sdelphij>>(2.S+2)	use			jpeg_segment
45284193Sdelphij>>2	pstring/HJ	x		\b, comment: "%s"
46284193Sdelphij
47284193Sdelphij>0	beshort		0xFFC0
48284193Sdelphij>>(2.S+2)	use			jpeg_segment
49284193Sdelphij>>4	byte		x		\b, baseline, precision %d
50284193Sdelphij>>7	beshort		x		\b, %dx
51284193Sdelphij>>5	beshort		x		\b%d
52284193Sdelphij>>9	byte		x		\b, frames %d
53284193Sdelphij
54284193Sdelphij>0	beshort		0xFFC1		
55284193Sdelphij>>(2.S+2)	use			jpeg_segment
56284193Sdelphij>>4	byte		x		\b, extended sequential, precision %d
57284193Sdelphij>>7	beshort		x		\b, %dx
58284193Sdelphij>>5	beshort		x		\b%d
59284193Sdelphij>>9	byte		x		\b, frames %d
60284193Sdelphij
61284193Sdelphij>0	beshort		0xFFC2		
62284193Sdelphij>>(2.S+2)	use			jpeg_segment
63284193Sdelphij>>4	byte		x		\b, progressive, precision %d
64284193Sdelphij>>7	beshort		x		\b, %dx
65284193Sdelphij>>5	beshort		x		\b%d
66284193Sdelphij>>9	byte		x		\b, frames %d
67284193Sdelphij
68284193Sdelphij# Define Huffman Tables
69284193Sdelphij>0	beshort		0xFFC4
70284193Sdelphij>>(2.S+2)	use			jpeg_segment
71284193Sdelphij
72284193Sdelphij>0	beshort		0xFFE1		
73284193Sdelphij#>>(2.S+2)	use			jpeg_segment
74284193Sdelphij>>4	string		Exif		\b, Exif Standard: [
75284193Sdelphij>>>10	indirect/r	x		
76284193Sdelphij>>>10	string		x		\b]
77284193Sdelphij
78284193Sdelphij# Application specific markers
79284193Sdelphij>0	beshort&0xFFE0	=0xFFE0
80284193Sdelphij>>(2.S+2)	use			jpeg_segment
81284193Sdelphij
82284193Sdelphij# DB: Define Quantization tables
83284193Sdelphij# DD: Define Restart interval [XXX: wrong here, it is 4 bytes]
84284193Sdelphij# D8: Start of image
85284193Sdelphij# D9: End of image
86284193Sdelphij# Dn: Restart
87284193Sdelphij>0	beshort&0xFFD0	=0xFFD0
88284193Sdelphij>>(2.S+2)	use			jpeg_segment
89284193Sdelphij
90284193Sdelphij#>0	beshort		x		unknown 0x%x
91284193Sdelphij#>>(2.S+2)	use			jpeg_segment
92284193Sdelphij
9368349Sobrien# HSI is Handmade Software's proprietary JPEG encoding scheme
9468349Sobrien0	string		hsi1		JPEG image data, HSI proprietary
95111658Sobrien
96111658Sobrien# From: David Santinoli <david@santinoli.com>
97267843Sdelphij0	string		\x00\x00\x00\x0C\x6A\x50\x20\x20\x0D\x0A\x87\x0A	JPEG 2000
98267843Sdelphij# From: Johan van der Knijff <johan.vanderknijff@kb.nl>
99267843Sdelphij# Added sub-entries for JP2, JPX, JPM and MJ2 formats; added mimetypes
100267843Sdelphij# https://github.com/bitsgalore/jp2kMagic
101267843Sdelphij#
102267843Sdelphij# Now read value of 'Brand' field, which yields a few possibilities:
103267843Sdelphij>20	string		\x6a\x70\x32\x20	Part 1 (JP2)
104267843Sdelphij!:mime	image/jp2
105267843Sdelphij>20	string		\x6a\x70\x78\x20	Part 2 (JPX)
106267843Sdelphij!:mime	image/jpx
107267843Sdelphij>20	string		\x6a\x70\x6d\x20	Part 6 (JPM)
108267843Sdelphij!:mime	image/jpm
109267843Sdelphij>20	string		\x6d\x6a\x70\x32	Part 3 (MJ2)
110267843Sdelphij!:mime	video/mj2
111186690Sobrien
112186690Sobrien# Type: JPEG 2000 codesream
113186690Sobrien# From: Mathieu Malaterre <mathieu.malaterre@gmail.com>
114186690Sobrien0	belong		0xff4fff51						JPEG 2000 codestream
115186690Sobrien45	beshort		0xff52
116