1 2#------------------------------------------------------------------------------ 3# $File: jpeg,v 1.19 2013/02/04 15:50:03 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#>>4 beshort x \b, segment length %d 29# Next, show thumbnail info, if it exists: 30>>18 byte !0 \b, thumbnail %dx 31>>>19 byte x \b%d 32 33# EXIF moved down here to avoid reporting a bogus version number, 34# and EXIF version number printing added. 35# - Patrik R=E5dman <patrik+file-magic@iki.fi> 36>6 string Exif \b, EXIF standard 37# Look for EXIF IFD offset in IFD 0, and then look for EXIF version tag in EXIF IFD. 38# All possible combinations of entries have to be enumerated, since no looping 39# is possible. And both endians are possible... 40# The combinations included below are from real-world JPEGs. 41# Little-endian 42>>12 string II 43# IFD 0 Entry #5: 44>>>70 leshort 0x8769 45# EXIF IFD Entry #1: 46>>>>(78.l+14) leshort 0x9000 47>>>>>(78.l+23) byte x %c 48>>>>>(78.l+24) byte x \b.%c 49>>>>>(78.l+25) byte !0x30 \b%c 50# IFD 0 Entry #9: 51>>>118 leshort 0x8769 52# EXIF IFD Entry #3: 53>>>>(126.l+38) leshort 0x9000 54>>>>>(126.l+47) byte x %c 55>>>>>(126.l+48) byte x \b.%c 56>>>>>(126.l+49) byte !0x30 \b%c 57# IFD 0 Entry #10 58>>>130 leshort 0x8769 59# EXIF IFD Entry #3: 60>>>>(138.l+38) leshort 0x9000 61>>>>>(138.l+47) byte x %c 62>>>>>(138.l+48) byte x \b.%c 63>>>>>(138.l+49) byte !0x30 \b%c 64# EXIF IFD Entry #4: 65>>>>(138.l+50) leshort 0x9000 66>>>>>(138.l+59) byte x %c 67>>>>>(138.l+60) byte x \b.%c 68>>>>>(138.l+61) byte !0x30 \b%c 69# EXIF IFD Entry #5: 70>>>>(138.l+62) leshort 0x9000 71>>>>>(138.l+71) byte x %c 72>>>>>(138.l+72) byte x \b.%c 73>>>>>(138.l+73) byte !0x30 \b%c 74# IFD 0 Entry #11 75>>>142 leshort 0x8769 76# EXIF IFD Entry #3: 77>>>>(150.l+38) leshort 0x9000 78>>>>>(150.l+47) byte x %c 79>>>>>(150.l+48) byte x \b.%c 80>>>>>(150.l+49) byte !0x30 \b%c 81# EXIF IFD Entry #4: 82>>>>(150.l+50) leshort 0x9000 83>>>>>(150.l+59) byte x %c 84>>>>>(150.l+60) byte x \b.%c 85>>>>>(150.l+61) byte !0x30 \b%c 86# EXIF IFD Entry #5: 87>>>>(150.l+62) leshort 0x9000 88>>>>>(150.l+71) byte x %c 89>>>>>(150.l+72) byte x \b.%c 90>>>>>(150.l+73) byte !0x30 \b%c 91# Big-endian 92>>12 string MM 93# IFD 0 Entry #9: 94>>>118 beshort 0x8769 95# EXIF IFD Entry #1: 96>>>>(126.L+14) beshort 0x9000 97>>>>>(126.L+23) byte x %c 98>>>>>(126.L+24) byte x \b.%c 99>>>>>(126.L+25) byte !0x30 \b%c 100# EXIF IFD Entry #3: 101>>>>(126.L+38) beshort 0x9000 102>>>>>(126.L+47) byte x %c 103>>>>>(126.L+48) byte x \b.%c 104>>>>>(126.L+49) byte !0x30 \b%c 105# IFD 0 Entry #10 106>>>130 beshort 0x8769 107# EXIF IFD Entry #3: 108>>>>(138.L+38) beshort 0x9000 109>>>>>(138.L+47) byte x %c 110>>>>>(138.L+48) byte x \b.%c 111>>>>>(138.L+49) byte !0x30 \b%c 112# EXIF IFD Entry #5: 113>>>>(138.L+62) beshort 0x9000 114>>>>>(138.L+71) byte x %c 115>>>>>(138.L+72) byte x \b.%c 116>>>>>(138.L+73) byte !0x30 \b%c 117# IFD 0 Entry #11 118>>>142 beshort 0x8769 119# EXIF IFD Entry #4: 120>>>>(150.L+50) beshort 0x9000 121>>>>>(150.L+59) byte x %c 122>>>>>(150.L+60) byte x \b.%c 123>>>>>(150.L+61) byte !0x30 \b%c 124# Here things get sticky. We can do ONE MORE marker segment with 125# indirect addressing, and that's all. It would be great if we could 126# do pointer arithemetic like in an assembler language. Christos? 127# And if there was some sort of looping construct to do searches, plus a few 128# named accumulators, it would be even more effective... 129# At least we can show a comment if no other segments got inserted before: 130>(4.S+5) byte 0xFE \b, comment: 131>>(4.S+6) pstring/HJ x "%s" 132# Or, we can show the encoding type (I've included only the three most common) 133# and image dimensions if we are lucky and the SOFn (image segment) is here: 134>(4.S+5) byte 0xC0 \b, baseline 135>>(4.S+6) byte x \b, precision %d 136>>(4.S+7) beshort x \b, %dx 137>>(4.S+9) beshort x \b%d 138>(4.S+5) byte 0xC1 \b, extended sequential 139>>(4.S+6) byte x \b, precision %d 140>>(4.S+7) beshort x \b, %dx 141>>(4.S+9) beshort x \b%d 142>(4.S+5) byte 0xC2 \b, progressive 143>>(4.S+6) byte x \b, precision %d 144>>(4.S+7) beshort x \b, %dx 145>>(4.S+9) beshort x \b%d 146# I've commented-out quantisation table reporting. I doubt anyone cares yet. 147#>(4.S+5) byte 0xDB \b, quantisation table 148#>>(4.S+6) beshort x \b length=%d 149#>14 beshort x \b, %d x 150#>16 beshort x \b %d 151 152# HSI is Handmade Software's proprietary JPEG encoding scheme 1530 string hsi1 JPEG image data, HSI proprietary 154 155# From: David Santinoli <david@santinoli.com> 1560 string \x00\x00\x00\x0C\x6A\x50\x20\x20\x0D\x0A\x87\x0A JPEG 2000 157# From: Johan van der Knijff <johan.vanderknijff@kb.nl> 158# Added sub-entries for JP2, JPX, JPM and MJ2 formats; added mimetypes 159# https://github.com/bitsgalore/jp2kMagic 160# 161# Now read value of 'Brand' field, which yields a few possibilities: 162>20 string \x6a\x70\x32\x20 Part 1 (JP2) 163!:mime image/jp2 164>20 string \x6a\x70\x78\x20 Part 2 (JPX) 165!:mime image/jpx 166>20 string \x6a\x70\x6d\x20 Part 6 (JPM) 167!:mime image/jpm 168>20 string \x6d\x6a\x70\x32 Part 3 (MJ2) 169!:mime video/mj2 170 171# Type: JPEG 2000 codesream 172# From: Mathieu Malaterre <mathieu.malaterre@gmail.com> 1730 belong 0xff4fff51 JPEG 2000 codestream 17445 beshort 0xff52 175