jpeg 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #------------------------------------------------------------------------------
  2. # $File: jpeg,v 1.36 2021/08/28 12:30:52 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 belong 0xffd8fff7 JPEG-LS image data
  12. !:mime image/jls
  13. !:ext jls
  14. >0 use jpeg
  15. 0 belong&0xffffff00 0xffd8ff00 JPEG image data
  16. !:mime image/jpeg
  17. !:apple 8BIMJPEG
  18. !:strength *3
  19. !:ext jpeg/jpg/jpe/jfif
  20. >0 use jpeg
  21. 0 name jpeg
  22. >6 string JFIF \b, JFIF standard
  23. # The following added by Erik Rossen <rossen@freesurf.ch> 1999-09-06
  24. # in a vain attempt to add image size reporting for JFIF. Note that these
  25. # tests are not fool-proof since some perfectly valid JPEGs are currently
  26. # impossible to specify in magic(4) format.
  27. # First, a little JFIF version info:
  28. >>11 byte x \b %d.
  29. >>12 byte x \b%02d
  30. # Next, the resolution or aspect ratio of the image:
  31. >>13 byte 0 \b, aspect ratio
  32. >>13 byte 1 \b, resolution (DPI)
  33. >>13 byte 2 \b, resolution (DPCM)
  34. >>14 beshort x \b, density %dx
  35. >>16 beshort x \b%d
  36. >>4 beshort x \b, segment length %d
  37. # Next, show thumbnail info, if it exists:
  38. >>18 byte !0 \b, thumbnail %dx
  39. >>>19 byte x \b%d
  40. >6 string Exif \b, Exif standard: [
  41. >>12 indirect/r x
  42. >>12 string x \b]
  43. # Jump to the first segment
  44. >(4.S+4) use jpeg_segment
  45. # This uses recursion...
  46. 0 name jpeg_segment
  47. >0 beshort 0xFFFE
  48. # Recursion handled by FFE0
  49. #>>(2.S+2) use jpeg_segment
  50. >>2 pstring/HJ x \b, comment: "%s"
  51. >0 beshort 0xFFC0
  52. >>(2.S+2) use jpeg_segment
  53. >>4 byte x \b, baseline, precision %d
  54. >>7 beshort x \b, %dx
  55. >>5 beshort x \b%d
  56. >>9 byte x \b, components %d
  57. >0 beshort 0xFFC1
  58. >>(2.S+2) use jpeg_segment
  59. >>4 byte x \b, extended sequential, precision %d
  60. >>7 beshort x \b, %dx
  61. >>5 beshort x \b%d
  62. >>9 byte x \b, components %d
  63. >0 beshort 0xFFC2
  64. >>(2.S+2) use jpeg_segment
  65. >>4 byte x \b, progressive, precision %d
  66. >>7 beshort x \b, %dx
  67. >>5 beshort x \b%d
  68. >>9 byte x \b, components %d
  69. # Define Huffman Tables
  70. >0 beshort 0xFFC4
  71. >>(2.S+2) use jpeg_segment
  72. >0 beshort 0xFFE1
  73. # Recursion handled by FFE0
  74. #>>(2.S+2) use jpeg_segment
  75. >>4 string Exif \b, Exif Standard: [
  76. >>>10 indirect/r x
  77. >>>10 string x \b]
  78. # Application specific markers
  79. >0 beshort&0xFFE0 =0xFFE0
  80. >>(2.S+2) use jpeg_segment
  81. # DB: Define Quantization tables
  82. # DD: Define Restart interval [XXX: wrong here, it is 4 bytes]
  83. # D8: Start of image
  84. # D9: End of image
  85. # Dn: Restart
  86. >0 beshort&0xFFD0 =0xFFD0
  87. >>0 beshort&0xFFE0 !0xFFE0
  88. >>>(2.S+2) use jpeg_segment
  89. #>0 beshort x unknown %#x
  90. #>>(2.S+2) use jpeg_segment
  91. # HSI is Handmade Software's proprietary JPEG encoding scheme
  92. 0 string hsi1 JPEG image data, HSI proprietary
  93. # From: David Santinoli <david@santinoli.com>
  94. 0 string \x00\x00\x00\x0C\x6A\x50\x20\x20\x0D\x0A\x87\x0A JPEG 2000
  95. # From: Johan van der Knijff <johan.vanderknijff@kb.nl>
  96. # Added sub-entries for JP2, JPX, JPM and MJ2 formats; added mimetypes
  97. # https://github.com/bitsgalore/jp2kMagic
  98. #
  99. # Now read value of 'Brand' field, which yields a few possibilities:
  100. >20 string \x6a\x70\x32\x20 Part 1 (JP2)
  101. !:mime image/jp2
  102. >20 string \x6a\x70\x78\x20 Part 2 (JPX)
  103. !:mime image/jpx
  104. >20 string \x6a\x70\x6d\x20 Part 6 (JPM)
  105. !:mime image/jpm
  106. >20 string \x6d\x6a\x70\x32 Part 3 (MJ2)
  107. !:mime video/mj2
  108. # Type: JPEG 2000 codesream
  109. # From: Mathieu Malaterre <mathieu.malaterre@gmail.com>
  110. 0 belong 0xff4fff51 JPEG 2000 codestream
  111. 45 beshort 0xff52
  112. # JPEG extended range
  113. 0 string \x49\x49\xbc
  114. >3 byte 1
  115. >>4 lelong%2 0 JPEG-XR
  116. !:mime image/jxr
  117. !:ext jxr
  118. # JPEG XL
  119. # From: Ian Tester
  120. 0 string \xff\x0a JPEG XL codestream
  121. !:mime image/jxl
  122. !:ext jxl
  123. # JPEG XL (transcoded JPEG file)
  124. 0 string \x00\x00\x00\x0cJXL\x20\x0d\x0a\x87\x0a JPEG XL container
  125. !:mime image/jxl
  126. !:ext jxl