1 2#------------------------------------------------------------------------------ 3# $File: jpeg,v 1.25 2015/01/02 16:56:50 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 +2 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: 22>>11 byte x \b %d. 23>>12 byte x \b%02d 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 29>>16 beshort x \b%d 30>>4 beshort x \b, segment length %d 31# Next, show thumbnail info, if it exists: 32>>18 byte !0 \b, thumbnail %dx 33>>>19 byte x \b%d 34>6 string Exif \b, Exif standard: [ 35>>12 indirect/r x 36>>12 string x \b] 37 38# Jump to the first segment 39>(4.S+4) use jpeg_segment 40 41# This uses recursion... 420 name jpeg_segment 43>0 beshort 0xFFFE 44>>(2.S+2) use jpeg_segment 45>>2 pstring/HJ x \b, comment: "%s" 46 47>0 beshort 0xFFC0 48>>(2.S+2) use jpeg_segment 49>>4 byte x \b, baseline, precision %d 50>>7 beshort x \b, %dx 51>>5 beshort x \b%d 52>>9 byte x \b, frames %d 53 54>0 beshort 0xFFC1 55>>(2.S+2) use jpeg_segment 56>>4 byte x \b, extended sequential, precision %d 57>>7 beshort x \b, %dx 58>>5 beshort x \b%d 59>>9 byte x \b, frames %d 60 61>0 beshort 0xFFC2 62>>(2.S+2) use jpeg_segment 63>>4 byte x \b, progressive, precision %d 64>>7 beshort x \b, %dx 65>>5 beshort x \b%d 66>>9 byte x \b, frames %d 67 68# Define Huffman Tables 69>0 beshort 0xFFC4 70>>(2.S+2) use jpeg_segment 71 72>0 beshort 0xFFE1 73#>>(2.S+2) use jpeg_segment 74>>4 string Exif \b, Exif Standard: [ 75>>>10 indirect/r x 76>>>10 string x \b] 77 78# Application specific markers 79>0 beshort&0xFFE0 =0xFFE0 80>>(2.S+2) use jpeg_segment 81 82# DB: Define Quantization tables 83# DD: Define Restart interval [XXX: wrong here, it is 4 bytes] 84# D8: Start of image 85# D9: End of image 86# Dn: Restart 87>0 beshort&0xFFD0 =0xFFD0 88>>(2.S+2) use jpeg_segment 89 90#>0 beshort x unknown 0x%x 91#>>(2.S+2) use jpeg_segment 92 93# HSI is Handmade Software's proprietary JPEG encoding scheme 940 string hsi1 JPEG image data, HSI proprietary 95 96# From: David Santinoli <david@santinoli.com> 970 string \x00\x00\x00\x0C\x6A\x50\x20\x20\x0D\x0A\x87\x0A JPEG 2000 98# From: Johan van der Knijff <johan.vanderknijff@kb.nl> 99# Added sub-entries for JP2, JPX, JPM and MJ2 formats; added mimetypes 100# https://github.com/bitsgalore/jp2kMagic 101# 102# Now read value of 'Brand' field, which yields a few possibilities: 103>20 string \x6a\x70\x32\x20 Part 1 (JP2) 104!:mime image/jp2 105>20 string \x6a\x70\x78\x20 Part 2 (JPX) 106!:mime image/jpx 107>20 string \x6a\x70\x6d\x20 Part 6 (JPM) 108!:mime image/jpm 109>20 string \x6d\x6a\x70\x32 Part 3 (MJ2) 110!:mime video/mj2 111 112# Type: JPEG 2000 codesream 113# From: Mathieu Malaterre <mathieu.malaterre@gmail.com> 1140 belong 0xff4fff51 JPEG 2000 codestream 11545 beshort 0xff52 116