2 #------------------------------------------------------------------------------
3 # $File: jpeg,v 1.26 2015/01/02 22:40:27 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 >6 string JFIF \b, JFIF standard
17 # The following added by Erik Rossen <rossen@freesurf.ch> 1999-09-06
18 # in a vain attempt to add image size reporting for JFIF. Note that these
19 # tests are not fool-proof since some perfectly valid JPEGs are currently
20 # impossible to specify in magic(4) format.
21 # First, a little JFIF version info:
24 # Next, the resolution or aspect ratio of the image:
25 >>13 byte 0 \b, aspect ratio
26 >>13 byte 1 \b, resolution (DPI)
27 >>13 byte 2 \b, resolution (DPCM)
28 >>14 beshort x \b, density %dx
30 >>4 beshort x \b, segment length %d
31 # Next, show thumbnail info, if it exists:
32 >>18 byte !0 \b, thumbnail %dx
34 >6 string Exif \b, Exif standard: [
38 # Jump to the first segment
39 >(4.S+4) use jpeg_segment
41 # This uses recursion...
44 # Recursion handled by FFE0
45 #>>(2.S+2) use jpeg_segment
46 >>2 pstring/HJ x \b, comment: "%s"
49 >>(2.S+2) use jpeg_segment
50 >>4 byte x \b, baseline, precision %d
53 >>9 byte x \b, frames %d
56 >>(2.S+2) use jpeg_segment
57 >>4 byte x \b, extended sequential, precision %d
60 >>9 byte x \b, frames %d
63 >>(2.S+2) use jpeg_segment
64 >>4 byte x \b, progressive, precision %d
67 >>9 byte x \b, frames %d
69 # Define Huffman Tables
71 >>(2.S+2) use jpeg_segment
74 # Recursion handled by FFE0
75 #>>(2.S+2) use jpeg_segment
76 >>4 string Exif \b, Exif Standard: [
80 # Application specific markers
81 >0 beshort&0xFFE0 =0xFFE0
82 >>(2.S+2) use jpeg_segment
84 # DB: Define Quantization tables
85 # DD: Define Restart interval [XXX: wrong here, it is 4 bytes]
89 >0 beshort&0xFFD0 =0xFFD0
90 >>0 beshort&0xFFE0 !0xFFE0
91 >>>(2.S+2) use jpeg_segment
93 #>0 beshort x unknown 0x%x
94 #>>(2.S+2) use jpeg_segment
96 # HSI is Handmade Software's proprietary JPEG encoding scheme
97 0 string hsi1 JPEG image data, HSI proprietary
99 # From: David Santinoli <david@santinoli.com>
100 0 string \x00\x00\x00\x0C\x6A\x50\x20\x20\x0D\x0A\x87\x0A JPEG 2000
101 # From: Johan van der Knijff <johan.vanderknijff@kb.nl>
102 # Added sub-entries for JP2, JPX, JPM and MJ2 formats; added mimetypes
103 # https://github.com/bitsgalore/jp2kMagic
105 # Now read value of 'Brand' field, which yields a few possibilities:
106 >20 string \x6a\x70\x32\x20 Part 1 (JP2)
108 >20 string \x6a\x70\x78\x20 Part 2 (JPX)
110 >20 string \x6a\x70\x6d\x20 Part 6 (JPM)
112 >20 string \x6d\x6a\x70\x32 Part 3 (MJ2)
115 # Type: JPEG 2000 codesream
116 # From: Mathieu Malaterre <mathieu.malaterre@gmail.com>
117 0 belong 0xff4fff51 JPEG 2000 codestream