jpeg 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #------------------------------------------------------------------------------
  2. # $File: jpeg,v 1.20 2014/08/05 07:32:31 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 +2
  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. >>14 beshort x \b, density %dx
  28. >>16 beshort x \b%d
  29. >>4 beshort x \b, segment length %d
  30. # Next, show thumbnail info, if it exists:
  31. >>18 byte !0 \b, thumbnail %dx
  32. >>>19 byte x \b%d
  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. # Jump to the first segment
  125. >(4.S+4) use jpeg_segment
  126. # This uses recursion...
  127. 0 name jpeg_segment
  128. >0 beshort 0xFFFE
  129. >>(2.S+2) use jpeg_segment
  130. >>2 pstring/HJ x \b, comment: "%s"
  131. >0 beshort 0xFFC0
  132. >>(2.S+2) use jpeg_segment
  133. >>4 byte x \b, baseline, precision %d
  134. >>7 beshort x \b, %dx
  135. >>5 beshort x \b%d
  136. >>9 byte x \b, frames %d
  137. >0 beshort 0xFFC1
  138. >>(2.S+2) use jpeg_segment
  139. >>4 byte x \b, extended sequential, precision %d
  140. >>7 beshort x \b, %dx
  141. >>5 beshort x \b%d
  142. >>9 byte x \b, frames %d
  143. >0 beshort 0xFFC2
  144. >>(2.S+2) use jpeg_segment
  145. >>4 byte x \b, progressive, precision %d
  146. >>7 beshort x \b, %dx
  147. >>5 beshort x \b%d
  148. >>9 byte x \b, frames %d
  149. # Define Huffman Tables
  150. >0 beshort 0xFFC4
  151. >>(2.S+2) use jpeg_segment
  152. # Application specific markers
  153. >0 beshort&0xFFE0 =0xFFE0
  154. >>(2.S+2) use jpeg_segment
  155. # DB: Define Quantization tables
  156. # DD: Define Restart interval [XXX: wrong here, it is 4 bytes]
  157. # D8: Start of image
  158. # D9: End of image
  159. # Dn: Restart
  160. >0 beshort&0xFFD0 =0xFFD0
  161. >>(2.S+2) use jpeg_segment
  162. # HSI is Handmade Software's proprietary JPEG encoding scheme
  163. 0 string hsi1 JPEG image data, HSI proprietary
  164. # From: David Santinoli <david@santinoli.com>
  165. 0 string \x00\x00\x00\x0C\x6A\x50\x20\x20\x0D\x0A\x87\x0A JPEG 2000
  166. # From: Johan van der Knijff <johan.vanderknijff@kb.nl>
  167. # Added sub-entries for JP2, JPX, JPM and MJ2 formats; added mimetypes
  168. # https://github.com/bitsgalore/jp2kMagic
  169. #
  170. # Now read value of 'Brand' field, which yields a few possibilities:
  171. >20 string \x6a\x70\x32\x20 Part 1 (JP2)
  172. !:mime image/jp2
  173. >20 string \x6a\x70\x78\x20 Part 2 (JPX)
  174. !:mime image/jpx
  175. >20 string \x6a\x70\x6d\x20 Part 6 (JPM)
  176. !:mime image/jpm
  177. >20 string \x6d\x6a\x70\x32 Part 3 (MJ2)
  178. !:mime video/mj2
  179. # Type: JPEG 2000 codesream
  180. # From: Mathieu Malaterre <mathieu.malaterre@gmail.com>
  181. 0 belong 0xff4fff51 JPEG 2000 codestream
  182. 45 beshort 0xff52