jpeg 5.7 KB

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