1ef01931fSBen Gras 2ef01931fSBen Gras#------------------------------------------------------------------------------ 3*0a6a1f1dSLionel Sambuc# $File: jpeg,v 1.26 2015/01/02 22:40:27 christos Exp $ 4ef01931fSBen Gras# JPEG images 5ef01931fSBen Gras# SunOS 5.5.1 had 6ef01931fSBen Gras# 7ef01931fSBen Gras# 0 string \377\330\377\340 JPEG file 8ef01931fSBen Gras# 0 string \377\330\377\356 JPG file 9ef01931fSBen Gras# 10ef01931fSBen Gras# both of which turn into "JPEG image data" here. 11ef01931fSBen Gras# 12ef01931fSBen Gras0 beshort 0xffd8 JPEG image data 13ef01931fSBen Gras!:mime image/jpeg 14ef01931fSBen Gras!:apple 8BIMJPEG 1584d9c625SLionel Sambuc!:strength +2 16ef01931fSBen Gras>6 string JFIF \b, JFIF standard 17ef01931fSBen Gras# The following added by Erik Rossen <rossen@freesurf.ch> 1999-09-06 18ef01931fSBen Gras# in a vain attempt to add image size reporting for JFIF. Note that these 19ef01931fSBen Gras# tests are not fool-proof since some perfectly valid JPEGs are currently 20ef01931fSBen Gras# impossible to specify in magic(4) format. 21ef01931fSBen Gras# First, a little JFIF version info: 22ef01931fSBen Gras>>11 byte x \b %d. 23ef01931fSBen Gras>>12 byte x \b%02d 24ef01931fSBen Gras# Next, the resolution or aspect ratio of the image: 25*0a6a1f1dSLionel Sambuc>>13 byte 0 \b, aspect ratio 26*0a6a1f1dSLionel Sambuc>>13 byte 1 \b, resolution (DPI) 27*0a6a1f1dSLionel Sambuc>>13 byte 2 \b, resolution (DPCM) 28*0a6a1f1dSLionel Sambuc>>14 beshort x \b, density %dx 29*0a6a1f1dSLionel Sambuc>>16 beshort x \b%d 30*0a6a1f1dSLionel Sambuc>>4 beshort x \b, segment length %d 31ef01931fSBen Gras# Next, show thumbnail info, if it exists: 32ef01931fSBen Gras>>18 byte !0 \b, thumbnail %dx 33ef01931fSBen Gras>>>19 byte x \b%d 34*0a6a1f1dSLionel Sambuc>6 string Exif \b, Exif standard: [ 35*0a6a1f1dSLionel Sambuc>>12 indirect/r x 36*0a6a1f1dSLionel Sambuc>>12 string x \b] 37ef01931fSBen Gras 38*0a6a1f1dSLionel Sambuc# Jump to the first segment 39*0a6a1f1dSLionel Sambuc>(4.S+4) use jpeg_segment 40*0a6a1f1dSLionel Sambuc 41*0a6a1f1dSLionel Sambuc# This uses recursion... 42*0a6a1f1dSLionel Sambuc0 name jpeg_segment 43*0a6a1f1dSLionel Sambuc>0 beshort 0xFFFE 44*0a6a1f1dSLionel Sambuc# Recursion handled by FFE0 45*0a6a1f1dSLionel Sambuc#>>(2.S+2) use jpeg_segment 46*0a6a1f1dSLionel Sambuc>>2 pstring/HJ x \b, comment: "%s" 47*0a6a1f1dSLionel Sambuc 48*0a6a1f1dSLionel Sambuc>0 beshort 0xFFC0 49*0a6a1f1dSLionel Sambuc>>(2.S+2) use jpeg_segment 50*0a6a1f1dSLionel Sambuc>>4 byte x \b, baseline, precision %d 51*0a6a1f1dSLionel Sambuc>>7 beshort x \b, %dx 52*0a6a1f1dSLionel Sambuc>>5 beshort x \b%d 53*0a6a1f1dSLionel Sambuc>>9 byte x \b, frames %d 54*0a6a1f1dSLionel Sambuc 55*0a6a1f1dSLionel Sambuc>0 beshort 0xFFC1 56*0a6a1f1dSLionel Sambuc>>(2.S+2) use jpeg_segment 57*0a6a1f1dSLionel Sambuc>>4 byte x \b, extended sequential, precision %d 58*0a6a1f1dSLionel Sambuc>>7 beshort x \b, %dx 59*0a6a1f1dSLionel Sambuc>>5 beshort x \b%d 60*0a6a1f1dSLionel Sambuc>>9 byte x \b, frames %d 61*0a6a1f1dSLionel Sambuc 62*0a6a1f1dSLionel Sambuc>0 beshort 0xFFC2 63*0a6a1f1dSLionel Sambuc>>(2.S+2) use jpeg_segment 64*0a6a1f1dSLionel Sambuc>>4 byte x \b, progressive, precision %d 65*0a6a1f1dSLionel Sambuc>>7 beshort x \b, %dx 66*0a6a1f1dSLionel Sambuc>>5 beshort x \b%d 67*0a6a1f1dSLionel Sambuc>>9 byte x \b, frames %d 68*0a6a1f1dSLionel Sambuc 69*0a6a1f1dSLionel Sambuc# Define Huffman Tables 70*0a6a1f1dSLionel Sambuc>0 beshort 0xFFC4 71*0a6a1f1dSLionel Sambuc>>(2.S+2) use jpeg_segment 72*0a6a1f1dSLionel Sambuc 73*0a6a1f1dSLionel Sambuc>0 beshort 0xFFE1 74*0a6a1f1dSLionel Sambuc# Recursion handled by FFE0 75*0a6a1f1dSLionel Sambuc#>>(2.S+2) use jpeg_segment 76*0a6a1f1dSLionel Sambuc>>4 string Exif \b, Exif Standard: [ 77*0a6a1f1dSLionel Sambuc>>>10 indirect/r x 78*0a6a1f1dSLionel Sambuc>>>10 string x \b] 79*0a6a1f1dSLionel Sambuc 80*0a6a1f1dSLionel Sambuc# Application specific markers 81*0a6a1f1dSLionel Sambuc>0 beshort&0xFFE0 =0xFFE0 82*0a6a1f1dSLionel Sambuc>>(2.S+2) use jpeg_segment 83*0a6a1f1dSLionel Sambuc 84*0a6a1f1dSLionel Sambuc# DB: Define Quantization tables 85*0a6a1f1dSLionel Sambuc# DD: Define Restart interval [XXX: wrong here, it is 4 bytes] 86*0a6a1f1dSLionel Sambuc# D8: Start of image 87*0a6a1f1dSLionel Sambuc# D9: End of image 88*0a6a1f1dSLionel Sambuc# Dn: Restart 89*0a6a1f1dSLionel Sambuc>0 beshort&0xFFD0 =0xFFD0 90*0a6a1f1dSLionel Sambuc>>0 beshort&0xFFE0 !0xFFE0 91*0a6a1f1dSLionel Sambuc>>>(2.S+2) use jpeg_segment 92*0a6a1f1dSLionel Sambuc 93*0a6a1f1dSLionel Sambuc#>0 beshort x unknown 0x%x 94*0a6a1f1dSLionel Sambuc#>>(2.S+2) use jpeg_segment 95ef01931fSBen Gras 96ef01931fSBen Gras# HSI is Handmade Software's proprietary JPEG encoding scheme 97ef01931fSBen Gras0 string hsi1 JPEG image data, HSI proprietary 98ef01931fSBen Gras 99ef01931fSBen Gras# From: David Santinoli <david@santinoli.com> 10084d9c625SLionel Sambuc0 string \x00\x00\x00\x0C\x6A\x50\x20\x20\x0D\x0A\x87\x0A JPEG 2000 10184d9c625SLionel Sambuc# From: Johan van der Knijff <johan.vanderknijff@kb.nl> 10284d9c625SLionel Sambuc# Added sub-entries for JP2, JPX, JPM and MJ2 formats; added mimetypes 10384d9c625SLionel Sambuc# https://github.com/bitsgalore/jp2kMagic 10484d9c625SLionel Sambuc# 10584d9c625SLionel Sambuc# Now read value of 'Brand' field, which yields a few possibilities: 10684d9c625SLionel Sambuc>20 string \x6a\x70\x32\x20 Part 1 (JP2) 10784d9c625SLionel Sambuc!:mime image/jp2 10884d9c625SLionel Sambuc>20 string \x6a\x70\x78\x20 Part 2 (JPX) 10984d9c625SLionel Sambuc!:mime image/jpx 11084d9c625SLionel Sambuc>20 string \x6a\x70\x6d\x20 Part 6 (JPM) 11184d9c625SLionel Sambuc!:mime image/jpm 11284d9c625SLionel Sambuc>20 string \x6d\x6a\x70\x32 Part 3 (MJ2) 11384d9c625SLionel Sambuc!:mime video/mj2 114ef01931fSBen Gras 115ef01931fSBen Gras# Type: JPEG 2000 codesream 116ef01931fSBen Gras# From: Mathieu Malaterre <mathieu.malaterre@gmail.com> 117ef01931fSBen Gras0 belong 0xff4fff51 JPEG 2000 codestream 118ef01931fSBen Gras45 beshort 0xff52 119