2 #------------------------------------------------------------------------------
3 # $File: jpeg,v 1.31 2017/03/17 21:35:28 christos Exp $
7 # 0 string \377\330\377\340 JPEG file
8 # 0 string \377\330\377\356 JPG file
10 # both of which turn into "JPEG image data" here.
12 0 beshort 0xffd8 JPEG image data
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:
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
31 >>4 beshort x \b, segment length %d
32 # Next, show thumbnail info, if it exists:
33 >>18 byte !0 \b, thumbnail %dx
35 >6 string Exif \b, Exif standard: [
39 # Jump to the first segment
40 >(4.S+4) use jpeg_segment
42 # This uses recursion...
45 # Recursion handled by FFE0
46 #>>(2.S+2) use jpeg_segment
47 >>2 pstring/HJ x \b, comment: "%s"
50 >>(2.S+2) use jpeg_segment
51 >>4 byte x \b, baseline, precision %d
54 >>9 byte x \b, frames %d
57 >>(2.S+2) use jpeg_segment
58 >>4 byte x \b, extended sequential, precision %d
61 >>9 byte x \b, frames %d
64 >>(2.S+2) use jpeg_segment
65 >>4 byte x \b, progressive, precision %d
68 >>9 byte x \b, frames %d
70 # Define Huffman Tables
72 >>(2.S+2) use jpeg_segment
75 # Recursion handled by FFE0
76 #>>(2.S+2) use jpeg_segment
77 >>4 string Exif \b, Exif Standard: [
81 # Application specific markers
82 >0 beshort&0xFFE0 =0xFFE0
83 >>(2.S+2) use jpeg_segment
85 # DB: Define Quantization tables
86 # DD: Define Restart interval [XXX: wrong here, it is 4 bytes]
90 >0 beshort&0xFFD0 =0xFFD0
91 >>0 beshort&0xFFE0 !0xFFE0
92 >>>(2.S+2) use jpeg_segment
94 #>0 beshort x unknown 0x%x
95 #>>(2.S+2) use jpeg_segment
97 # HSI is Handmade Software's proprietary JPEG encoding scheme
98 0 string hsi1 JPEG image data, HSI proprietary
100 # From: David Santinoli <david@santinoli.com>
101 0 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
106 # Now read value of 'Brand' field, which yields a few possibilities:
107 >20 string \x6a\x70\x32\x20 Part 1 (JP2)
109 >20 string \x6a\x70\x78\x20 Part 2 (JPX)
111 >20 string \x6a\x70\x6d\x20 Part 6 (JPM)
113 >20 string \x6d\x6a\x70\x32 Part 3 (MJ2)
116 # Type: JPEG 2000 codesream
117 # From: Mathieu Malaterre <mathieu.malaterre@gmail.com>
118 0 belong 0xff4fff51 JPEG 2000 codestream
121 # JPEG extended range
122 0 string \x49\x49\xbc
124 >>4 lelong%2 0 JPEG-XR