@jimp/jpeg-js 0.0.0-stage → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. package/LICENSE +129 -0
  2. package/LICENSE-APACHE-2.0 +202 -0
  3. package/NOTICE +27 -0
  4. package/README.ijg +260 -0
  5. package/README.md +261 -2
  6. package/dist/browser/compat.d.ts +44 -0
  7. package/dist/browser/compat.d.ts.map +1 -0
  8. package/dist/browser/compat.js +42 -0
  9. package/dist/browser/compat.js.map +1 -0
  10. package/dist/browser/decode.d.ts +73 -0
  11. package/dist/browser/decode.d.ts.map +1 -0
  12. package/dist/browser/decode.js +82 -0
  13. package/dist/browser/decode.js.map +1 -0
  14. package/dist/browser/decoder/arithmetic.d.ts +66 -0
  15. package/dist/browser/decoder/arithmetic.d.ts.map +1 -0
  16. package/dist/browser/decoder/arithmetic.js +374 -0
  17. package/dist/browser/decoder/arithmetic.js.map +1 -0
  18. package/dist/browser/decoder/decoder.d.ts +87 -0
  19. package/dist/browser/decoder/decoder.d.ts.map +1 -0
  20. package/dist/browser/decoder/decoder.js +869 -0
  21. package/dist/browser/decoder/decoder.js.map +1 -0
  22. package/dist/browser/decoder/huffman.d.ts +64 -0
  23. package/dist/browser/decoder/huffman.d.ts.map +1 -0
  24. package/dist/browser/decoder/huffman.js +260 -0
  25. package/dist/browser/decoder/huffman.js.map +1 -0
  26. package/dist/browser/decoder/idct.d.ts +20 -0
  27. package/dist/browser/decoder/idct.d.ts.map +1 -0
  28. package/dist/browser/decoder/idct.js +222 -0
  29. package/dist/browser/decoder/idct.js.map +1 -0
  30. package/dist/browser/decoder/output.d.ts +17 -0
  31. package/dist/browser/decoder/output.d.ts.map +1 -0
  32. package/dist/browser/decoder/output.js +351 -0
  33. package/dist/browser/decoder/output.js.map +1 -0
  34. package/dist/browser/decoder/scan-tables.d.ts +7 -0
  35. package/dist/browser/decoder/scan-tables.d.ts.map +1 -0
  36. package/dist/browser/decoder/scan-tables.js +13 -0
  37. package/dist/browser/decoder/scan-tables.js.map +1 -0
  38. package/dist/browser/decoder/scan.d.ts +57 -0
  39. package/dist/browser/decoder/scan.d.ts.map +1 -0
  40. package/dist/browser/decoder/scan.js +381 -0
  41. package/dist/browser/decoder/scan.js.map +1 -0
  42. package/dist/browser/decoder/smoothing.d.ts +28 -0
  43. package/dist/browser/decoder/smoothing.d.ts.map +1 -0
  44. package/dist/browser/decoder/smoothing.js +345 -0
  45. package/dist/browser/decoder/smoothing.js.map +1 -0
  46. package/dist/browser/decoder/standard-tables.d.ts +19 -0
  47. package/dist/browser/decoder/standard-tables.d.ts.map +1 -0
  48. package/dist/browser/decoder/standard-tables.js +50 -0
  49. package/dist/browser/decoder/standard-tables.js.map +1 -0
  50. package/dist/browser/encode.d.ts +57 -0
  51. package/dist/browser/encode.d.ts.map +1 -0
  52. package/dist/browser/encode.js +57 -0
  53. package/dist/browser/encode.js.map +1 -0
  54. package/dist/browser/encoder/encoder.d.ts +65 -0
  55. package/dist/browser/encoder/encoder.d.ts.map +1 -0
  56. package/dist/browser/encoder/encoder.js +713 -0
  57. package/dist/browser/encoder/encoder.js.map +1 -0
  58. package/dist/browser/encoder/huffman.d.ts +19 -0
  59. package/dist/browser/encoder/huffman.d.ts.map +1 -0
  60. package/dist/browser/encoder/huffman.js +135 -0
  61. package/dist/browser/encoder/huffman.js.map +1 -0
  62. package/dist/browser/encoder/progressive.d.ts +20 -0
  63. package/dist/browser/encoder/progressive.d.ts.map +1 -0
  64. package/dist/browser/encoder/progressive.js +315 -0
  65. package/dist/browser/encoder/progressive.js.map +1 -0
  66. package/dist/browser/encoder/writer.d.ts +18 -0
  67. package/dist/browser/encoder/writer.d.ts.map +1 -0
  68. package/dist/browser/encoder/writer.js +71 -0
  69. package/dist/browser/encoder/writer.js.map +1 -0
  70. package/dist/browser/errors.d.ts +27 -0
  71. package/dist/browser/errors.d.ts.map +1 -0
  72. package/dist/browser/errors.js +28 -0
  73. package/dist/browser/errors.js.map +1 -0
  74. package/dist/browser/index.d.ts +12 -0
  75. package/dist/browser/index.d.ts.map +1 -0
  76. package/dist/browser/index.js +8 -0
  77. package/dist/browser/index.js.map +1 -0
  78. package/dist/browser/package.json +3 -0
  79. package/dist/commonjs/compat.d.ts +44 -0
  80. package/dist/commonjs/compat.d.ts.map +1 -0
  81. package/dist/commonjs/compat.js +46 -0
  82. package/dist/commonjs/compat.js.map +1 -0
  83. package/dist/commonjs/decode.d.ts +73 -0
  84. package/dist/commonjs/decode.d.ts.map +1 -0
  85. package/dist/commonjs/decode.js +86 -0
  86. package/dist/commonjs/decode.js.map +1 -0
  87. package/dist/commonjs/decoder/arithmetic.d.ts +66 -0
  88. package/dist/commonjs/decoder/arithmetic.d.ts.map +1 -0
  89. package/dist/commonjs/decoder/arithmetic.js +380 -0
  90. package/dist/commonjs/decoder/arithmetic.js.map +1 -0
  91. package/dist/commonjs/decoder/decoder.d.ts +87 -0
  92. package/dist/commonjs/decoder/decoder.d.ts.map +1 -0
  93. package/dist/commonjs/decoder/decoder.js +873 -0
  94. package/dist/commonjs/decoder/decoder.js.map +1 -0
  95. package/dist/commonjs/decoder/huffman.d.ts +64 -0
  96. package/dist/commonjs/decoder/huffman.d.ts.map +1 -0
  97. package/dist/commonjs/decoder/huffman.js +265 -0
  98. package/dist/commonjs/decoder/huffman.js.map +1 -0
  99. package/dist/commonjs/decoder/idct.d.ts +20 -0
  100. package/dist/commonjs/decoder/idct.d.ts.map +1 -0
  101. package/dist/commonjs/decoder/idct.js +226 -0
  102. package/dist/commonjs/decoder/idct.js.map +1 -0
  103. package/dist/commonjs/decoder/output.d.ts +17 -0
  104. package/dist/commonjs/decoder/output.d.ts.map +1 -0
  105. package/dist/commonjs/decoder/output.js +354 -0
  106. package/dist/commonjs/decoder/output.js.map +1 -0
  107. package/dist/commonjs/decoder/scan-tables.d.ts +7 -0
  108. package/dist/commonjs/decoder/scan-tables.d.ts.map +1 -0
  109. package/dist/commonjs/decoder/scan-tables.js +16 -0
  110. package/dist/commonjs/decoder/scan-tables.js.map +1 -0
  111. package/dist/commonjs/decoder/scan.d.ts +57 -0
  112. package/dist/commonjs/decoder/scan.d.ts.map +1 -0
  113. package/dist/commonjs/decoder/scan.js +385 -0
  114. package/dist/commonjs/decoder/scan.js.map +1 -0
  115. package/dist/commonjs/decoder/smoothing.d.ts +28 -0
  116. package/dist/commonjs/decoder/smoothing.d.ts.map +1 -0
  117. package/dist/commonjs/decoder/smoothing.js +349 -0
  118. package/dist/commonjs/decoder/smoothing.js.map +1 -0
  119. package/dist/commonjs/decoder/standard-tables.d.ts +19 -0
  120. package/dist/commonjs/decoder/standard-tables.d.ts.map +1 -0
  121. package/dist/commonjs/decoder/standard-tables.js +53 -0
  122. package/dist/commonjs/decoder/standard-tables.js.map +1 -0
  123. package/dist/commonjs/encode.d.ts +57 -0
  124. package/dist/commonjs/encode.d.ts.map +1 -0
  125. package/dist/commonjs/encode.js +60 -0
  126. package/dist/commonjs/encode.js.map +1 -0
  127. package/dist/commonjs/encoder/encoder.d.ts +65 -0
  128. package/dist/commonjs/encoder/encoder.d.ts.map +1 -0
  129. package/dist/commonjs/encoder/encoder.js +720 -0
  130. package/dist/commonjs/encoder/encoder.js.map +1 -0
  131. package/dist/commonjs/encoder/huffman.d.ts +19 -0
  132. package/dist/commonjs/encoder/huffman.d.ts.map +1 -0
  133. package/dist/commonjs/encoder/huffman.js +139 -0
  134. package/dist/commonjs/encoder/huffman.js.map +1 -0
  135. package/dist/commonjs/encoder/progressive.d.ts +20 -0
  136. package/dist/commonjs/encoder/progressive.d.ts.map +1 -0
  137. package/dist/commonjs/encoder/progressive.js +318 -0
  138. package/dist/commonjs/encoder/progressive.js.map +1 -0
  139. package/dist/commonjs/encoder/writer.d.ts +18 -0
  140. package/dist/commonjs/encoder/writer.d.ts.map +1 -0
  141. package/dist/commonjs/encoder/writer.js +75 -0
  142. package/dist/commonjs/encoder/writer.js.map +1 -0
  143. package/dist/commonjs/errors.d.ts +27 -0
  144. package/dist/commonjs/errors.d.ts.map +1 -0
  145. package/dist/commonjs/errors.js +35 -0
  146. package/dist/commonjs/errors.js.map +1 -0
  147. package/dist/commonjs/index.d.ts +12 -0
  148. package/dist/commonjs/index.d.ts.map +1 -0
  149. package/dist/commonjs/index.js +19 -0
  150. package/dist/commonjs/index.js.map +1 -0
  151. package/dist/commonjs/package.json +3 -0
  152. package/dist/esm/compat.d.ts +44 -0
  153. package/dist/esm/compat.d.ts.map +1 -0
  154. package/dist/esm/compat.js +42 -0
  155. package/dist/esm/compat.js.map +1 -0
  156. package/dist/esm/decode.d.ts +73 -0
  157. package/dist/esm/decode.d.ts.map +1 -0
  158. package/dist/esm/decode.js +82 -0
  159. package/dist/esm/decode.js.map +1 -0
  160. package/dist/esm/decoder/arithmetic.d.ts +66 -0
  161. package/dist/esm/decoder/arithmetic.d.ts.map +1 -0
  162. package/dist/esm/decoder/arithmetic.js +374 -0
  163. package/dist/esm/decoder/arithmetic.js.map +1 -0
  164. package/dist/esm/decoder/decoder.d.ts +87 -0
  165. package/dist/esm/decoder/decoder.d.ts.map +1 -0
  166. package/dist/esm/decoder/decoder.js +869 -0
  167. package/dist/esm/decoder/decoder.js.map +1 -0
  168. package/dist/esm/decoder/huffman.d.ts +64 -0
  169. package/dist/esm/decoder/huffman.d.ts.map +1 -0
  170. package/dist/esm/decoder/huffman.js +260 -0
  171. package/dist/esm/decoder/huffman.js.map +1 -0
  172. package/dist/esm/decoder/idct.d.ts +20 -0
  173. package/dist/esm/decoder/idct.d.ts.map +1 -0
  174. package/dist/esm/decoder/idct.js +222 -0
  175. package/dist/esm/decoder/idct.js.map +1 -0
  176. package/dist/esm/decoder/output.d.ts +17 -0
  177. package/dist/esm/decoder/output.d.ts.map +1 -0
  178. package/dist/esm/decoder/output.js +351 -0
  179. package/dist/esm/decoder/output.js.map +1 -0
  180. package/dist/esm/decoder/scan-tables.d.ts +7 -0
  181. package/dist/esm/decoder/scan-tables.d.ts.map +1 -0
  182. package/dist/esm/decoder/scan-tables.js +13 -0
  183. package/dist/esm/decoder/scan-tables.js.map +1 -0
  184. package/dist/esm/decoder/scan.d.ts +57 -0
  185. package/dist/esm/decoder/scan.d.ts.map +1 -0
  186. package/dist/esm/decoder/scan.js +381 -0
  187. package/dist/esm/decoder/scan.js.map +1 -0
  188. package/dist/esm/decoder/smoothing.d.ts +28 -0
  189. package/dist/esm/decoder/smoothing.d.ts.map +1 -0
  190. package/dist/esm/decoder/smoothing.js +345 -0
  191. package/dist/esm/decoder/smoothing.js.map +1 -0
  192. package/dist/esm/decoder/standard-tables.d.ts +19 -0
  193. package/dist/esm/decoder/standard-tables.d.ts.map +1 -0
  194. package/dist/esm/decoder/standard-tables.js +50 -0
  195. package/dist/esm/decoder/standard-tables.js.map +1 -0
  196. package/dist/esm/encode.d.ts +57 -0
  197. package/dist/esm/encode.d.ts.map +1 -0
  198. package/dist/esm/encode.js +57 -0
  199. package/dist/esm/encode.js.map +1 -0
  200. package/dist/esm/encoder/encoder.d.ts +65 -0
  201. package/dist/esm/encoder/encoder.d.ts.map +1 -0
  202. package/dist/esm/encoder/encoder.js +713 -0
  203. package/dist/esm/encoder/encoder.js.map +1 -0
  204. package/dist/esm/encoder/huffman.d.ts +19 -0
  205. package/dist/esm/encoder/huffman.d.ts.map +1 -0
  206. package/dist/esm/encoder/huffman.js +135 -0
  207. package/dist/esm/encoder/huffman.js.map +1 -0
  208. package/dist/esm/encoder/progressive.d.ts +20 -0
  209. package/dist/esm/encoder/progressive.d.ts.map +1 -0
  210. package/dist/esm/encoder/progressive.js +315 -0
  211. package/dist/esm/encoder/progressive.js.map +1 -0
  212. package/dist/esm/encoder/writer.d.ts +18 -0
  213. package/dist/esm/encoder/writer.d.ts.map +1 -0
  214. package/dist/esm/encoder/writer.js +71 -0
  215. package/dist/esm/encoder/writer.js.map +1 -0
  216. package/dist/esm/errors.d.ts +27 -0
  217. package/dist/esm/errors.d.ts.map +1 -0
  218. package/dist/esm/errors.js +28 -0
  219. package/dist/esm/errors.js.map +1 -0
  220. package/dist/esm/index.d.ts +12 -0
  221. package/dist/esm/index.d.ts.map +1 -0
  222. package/dist/esm/index.js +8 -0
  223. package/dist/esm/index.js.map +1 -0
  224. package/dist/esm/package.json +3 -0
  225. package/package.json +99 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decoder.js","sourceRoot":"","sources":["../../../src/decoder/decoder.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;;;AAEH,4CAIsB;AACtB,mDAGyB;AACzB,6CAAoE;AACpE,uCAKmB;AACnB,2CAIqB;AACrB,uCAA0E;AAC1E,iDAAqE;AACrE,6DAAuD;AA0CvD,+EAA+E;AAC/E,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAC7B,oEAAoE;AACpE,MAAM,SAAS,GAAG,IAAI,CAAC;AAEvB,MAAM,SAAS,GAA2B;IACxC,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,wCAAwC;IAC9C,IAAI,EAAE,yCAAyC;IAC/C,IAAI,EAAE,sCAAsC;IAC5C,IAAI,EAAE,2BAA2B;IACjC,IAAI,EAAE,yDAAyD;IAC/D,IAAI,EAAE,0DAA0D;IAChE,IAAI,EAAE,uDAAuD;CAC9D,CAAC;AAEF,SAAS,GAAG,CAAC,KAAa;IACxB,OAAO,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AAC3D,CAAC;AAED,SAAS,YAAY,CAAC,IAAwB;IAC5C,OAAO,IAAI,KAAK,SAAS,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,CAAC;AAC5D,CAAC;AAED,mDAAmD;AACnD,SAAS,SAAS,CAAC,IAAY;IAC7B,OAAO,CAAC,CAAC,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,KAAK,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S,EACf,QAAQ,EACR,MAAM,CACP,CAAC;IACJ,CAAC;CACF","sourcesContent":["/*\n * JPEG decoder: marker parsing, frame setup and orchestration.\n *\n * Copyright 2011 notmasteryet\n * Copyright 2014 Mozilla Foundation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * This code was forked from https://github.com/notmasteryet/jpgjs, through\n * jpeg-js (https://github.com/jpeg-js/jpeg-js) and pdf.js\n * (https://github.com/mozilla/pdf.js, src/core/jpg.js and jpeg_utils.js).\n *\n * - The JPEG specification can be found in the ITU CCITT Recommendation T.81\n * (www.w3.org/Graphics/JPEG/itu-t81.pdf)\n * - The JFIF specification can be found in the JPEG File Interchange Format\n * (www.w3.org/Graphics/JPEG/jfif3.pdf)\n * - The Adobe Application-Specific JPEG markers in the\n * Supporting the DCT Filters in PostScript Level 2, Technical Note #5116\n * (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)\n *\n * Modified by Jimp contributors (2026):\n * - translated to TypeScript, with a JpegError subclass for every failure\n * instead of TypeErrors on malformed input;\n * - every segment is bounds-checked; SOS before SOF, unknown component IDs,\n * missing tables, bad sampling factors and bad progression parameters are\n * rejected;\n * - recovery from junk between segments, a lost 0xFF before a marker, segment\n * lengths that are off and a missing EOI, merged from jpeg-js and Jimp;\n * - DNL support only for frames whose SOF height is 0, found by scanning ahead\n * instead of re-parsing;\n * - entropy decoding, IDCT, upsampling and colour conversion are replaced by\n * ports of libjpeg-turbo's (scan.ts, idct.ts, output.ts), and arithmetic\n * coding is supported (arithmetic.ts);\n * - sequential images are decoded one MCU row at a time, straight into sample\n * planes, and colour conversion picks the colour space like libjpeg;\n * - resolution and memory limits from jpeg-js, plus external tables (JPEG\n * abbreviated format).\n */\n\nimport {\n JpegFormatError,\n JpegLimitError,\n JpegUnsupportedError,\n} from \"../errors.js\";\nimport {\n type ArithmeticConditioning,\n defaultConditioning,\n} from \"./arithmetic.js\";\nimport { buildHuffmanTable, type HuffmanTable } from \"./huffman.js\";\nimport {\n createIdctContext,\n idctBlock,\n type IdctContext,\n type SampleArray,\n} from \"./idct.js\";\nimport {\n type ColorSpace,\n convertToRgb,\n type OutputComponent,\n} from \"./output.js\";\nimport { decodeScan, NATURAL_ORDER, type ScanComponent } from \"./scan.js\";\nimport { smoothAndTransform, smoothingUseful } from \"./smoothing.js\";\nimport { STANDARD_TABLES } from \"./standard-tables.js\";\n\nexport interface DecoderOptions {\n colorTransform?: boolean;\n tolerantDecoding: boolean;\n allowTruncated: boolean;\n maxResolutionInMP: number;\n maxMemoryUsageInMB: number;\n /** An abbreviated JPEG with the DQT and DHT tables the image refers to. */\n tables?: Uint8Array;\n}\n\ninterface Component extends ScanComponent {\n id: number;\n quantId: number;\n /** Latched when the component's first scan starts, like libjpeg. */\n quantTable: Uint16Array | null;\n blocksPerColumnMcu: number;\n /** Size of the component's real samples. */\n width: number;\n height: number;\n plane: SampleArray | null;\n /** Some scan has covered this component. */\n scanned: boolean;\n /** Progression of each coefficient, see SmoothingComponent. */\n coefBits: Int8Array;\n previousCoefBits: Int8Array;\n}\n\ninterface Frame {\n progressive: boolean;\n arithmetic: boolean;\n precision: number;\n width: number;\n height: number;\n components: Component[];\n maxH: number;\n maxV: number;\n mcusPerLine: number;\n mcusPerColumn: number;\n}\n\n/** Maximum number of blocks in an MCU, as in libjpeg (D_MAX_BLOCKS_IN_MCU). */\nconst MAX_BLOCKS_IN_MCU = 10;\n/** Defends against files with an absurd number of (empty) scans. */\nconst MAX_SCANS = 1000;\n\nconst SOF_NAMES: Record<number, string> = {\n 0xc3: \"lossless\",\n 0xc5: \"differential sequential (hierarchical)\",\n 0xc6: \"differential progressive (hierarchical)\",\n 0xc7: \"differential lossless (hierarchical)\",\n 0xcb: \"arithmetic-coded lossless\",\n 0xcd: \"arithmetic-coded differential sequential (hierarchical)\",\n 0xce: \"arithmetic-coded differential progressive (hierarchical)\",\n 0xcf: \"arithmetic-coded differential lossless (hierarchical)\",\n};\n\nfunction hex(value: number) {\n return value.toString(16).toUpperCase().padStart(2, \"0\");\n}\n\nfunction isMarkerCode(code: number | undefined) {\n return code !== undefined && code >= 0xc0 && code <= 0xfe;\n}\n\n/** Markers that are followed by a length field. */\nfunction hasLength(code: number) {\n return !(code >= 0xd0 && code <= 0xd9) && code !== 0x01;\n}\n\nexport class JpegDecoder {\n width = 0;\n height = 0;\n jfif = false;\n adobe: { transformCode: number } | null = null;\n exif: Uint8Array | undefined;\n comments: string[] = [];\n\n private frame: Frame | null = null;\n private quantTables: (Uint16Array | undefined)[] = [];\n private dcTables: (HuffmanTable | undefined)[] = [];\n private acTables: (HuffmanTable | undefined)[] = [];\n private restartInterval = 0;\n private conditioning: ArithmeticConditioning = defaultConditioning();\n /** Sequential image whose single scan is decoded one MCU row at a time. */\n private streaming = false;\n private scans = 0;\n private idct: IdctContext | null = null;\n private memoryUsed = 0;\n /** See ScanResult.lastGoodRow. */\n private lastGoodRow = 0;\n\n constructor(private readonly options: DecoderOptions) {}\n\n private get tolerant() {\n return this.options.tolerantDecoding;\n }\n\n private corrupt(message: string) {\n if (!this.tolerant) {\n throw new JpegFormatError(message);\n }\n }\n\n /** Tracks memory use against maxMemoryUsageInMB, like jpeg-js. */\n requestMemory(bytes: number) {\n const max = this.options.maxMemoryUsageInMB * 1024 * 1024;\n\n this.memoryUsed += bytes;\n\n if (this.memoryUsed > max) {\n const exceeded = Math.ceil((this.memoryUsed - max) / 1024 / 1024);\n\n throw new JpegLimitError(\n `maxMemoryUsageInMB limit exceeded by at least ${exceeded}MB`,\n );\n }\n }\n\n parse(data: Uint8Array) {\n if (this.options.tables) {\n this.parseMarkers(this.options.tables, true);\n }\n\n this.parseMarkers(data, false);\n\n const frame = this.frame;\n\n if (!frame) {\n throw new JpegFormatError(\"JPEG data contains no image (no SOF marker)\");\n }\n\n if (this.scans === 0) {\n throw new JpegFormatError(\n \"JPEG data contains no image data (no SOS marker)\",\n );\n }\n\n if (!this.streaming) {\n this.finishCoefficients(frame);\n }\n }\n\n private parseMarkers(data: Uint8Array, tablesOnly: boolean) {\n const length = data.length;\n\n if (length < 2 || data[0] !== 0xff || data[1] !== 0xd8) {\n throw new JpegFormatError(\n tablesOnly\n ? \"JPEG tables don't start with an SOI marker\"\n : \"SOI not found: the data is not a JPEG\",\n );\n }\n\n let offset = 2;\n\n while (offset < length) {\n if (data[offset] !== 0xff || !isMarkerCode(data[offset + 1])) {\n // Fill bytes before a marker\n if (data[offset] === 0xff && data[offset + 1] === 0xff) {\n offset++;\n continue;\n }\n\n const next = this.recoverMarker(data, offset);\n\n if (next < 0) {\n break;\n }\n\n // Unless the marker only lost its 0xFF, parse from where it is\n if (next !== offset) {\n offset = next;\n continue;\n }\n }\n\n const code = data[offset + 1]!;\n let segmentEnd = offset + 2;\n\n if (hasLength(code)) {\n if (offset + 4 > length) {\n this.corrupt(\"JPEG data ends inside a marker segment\");\n break;\n }\n\n const segmentLength = (data[offset + 2]! << 8) | data[offset + 3]!;\n\n segmentEnd = offset + 2 + segmentLength;\n\n if (segmentLength < 2 || segmentEnd > length) {\n // Only metadata can be cut short and leave a usable image\n if (code >= 0xe0 || code === 0xfe) {\n this.corrupt(`Bad length of ${this.describe(code)}`);\n break;\n }\n\n throw new JpegFormatError(`Bad length of ${this.describe(code)}`);\n }\n }\n\n const start = offset + 4;\n\n if (code === 0xd9) {\n break;\n }\n\n if (\n tablesOnly &&\n code !== 0xdb &&\n code !== 0xc4 &&\n code !== 0xdd &&\n code !== 0xcc &&\n !(code >= 0xe0 && code <= 0xef) &&\n code !== 0xfe\n ) {\n throw new JpegFormatError(\n `JPEG tables can only contain DQT, DHT and DRI markers, not ${this.describe(code)}`,\n );\n }\n\n switch (code) {\n case 0xe0:\n case 0xe1:\n case 0xe2:\n case 0xe3:\n case 0xe4:\n case 0xe5:\n case 0xe6:\n case 0xe7:\n case 0xe8:\n case 0xe9:\n case 0xea:\n case 0xeb:\n case 0xec:\n case 0xed:\n case 0xee:\n case 0xef:\n case 0xfe:\n segmentEnd = this.fixSegmentEnd(data, start, segmentEnd);\n\n if (!tablesOnly) {\n this.readAppSegment(code, data.subarray(start, segmentEnd));\n }\n\n offset = segmentEnd;\n break;\n\n case 0xdb:\n this.readQuantTables(data, start, segmentEnd);\n offset = segmentEnd;\n break;\n\n case 0xc4:\n this.readHuffmanTables(data, start, segmentEnd);\n offset = segmentEnd;\n break;\n\n case 0xdd:\n if (segmentEnd - start < 2) {\n throw new JpegFormatError(\"Bad length of DRI marker\");\n }\n\n this.restartInterval = (data[start]! << 8) | data[start + 1]!;\n offset = segmentEnd;\n break;\n\n case 0xc0:\n case 0xc1:\n case 0xc2:\n case 0xc9:\n case 0xca:\n this.readFrame(code, data, start, segmentEnd);\n offset = segmentEnd;\n break;\n\n case 0xc3:\n case 0xc5:\n case 0xc6:\n case 0xc7:\n case 0xcb:\n case 0xcd:\n case 0xce:\n case 0xcf:\n throw new JpegUnsupportedError(\n `Unsupported JPEG process: ${SOF_NAMES[code]} (SOF${code - 0xc0}) JPEGs are not supported`,\n );\n\n case 0xda:\n offset = this.readScan(data, start, segmentEnd);\n break;\n\n case 0xd8: // SOI\n case 0xd0: // RSTn outside a scan, e.g. extra ones after it\n case 0xd1:\n case 0xd2:\n case 0xd3:\n case 0xd4:\n case 0xd5:\n case 0xd6:\n case 0xd7:\n offset += 2;\n break;\n\n case 0xcc:\n this.readConditioning(data, start, segmentEnd);\n offset = segmentEnd;\n break;\n\n case 0xdc: // DNL: read ahead in readFrame() when it's needed\n offset = segmentEnd;\n break;\n\n default:\n // JPGn, DHP, EXP, ... Skip them like APPn if their length is sane\n this.corrupt(`Unsupported JPEG marker ${this.describe(code)}`);\n offset = this.fixSegmentEnd(data, start, segmentEnd);\n break;\n }\n }\n }\n\n private describe(code: number) {\n return `marker 0xFF${hex(code)}`;\n }\n\n /**\n * Called when a marker was expected at `offset` but isn't there. Finds where\n * parsing should go on, or returns -1 to stop.\n */\n private recoverMarker(data: Uint8Array, offset: number) {\n const length = data.length;\n\n this.corrupt(\n `Corrupt JPEG data: expected a marker at offset ${offset}, found 0x${hex(data[offset]!)}`,\n );\n\n // The 0xFF of the marker was lost (seen from Pixel phones, jpeg-js #84):\n // parse it from here\n const code = data[offset + 1];\n\n if (\n isMarkerCode(code) &&\n hasLength(code!) &&\n offset + 4 <= length &&\n this.segmentEndsWell(\n data,\n offset + 2 + ((data[offset + 2]! << 8) | data[offset + 3]!),\n )\n ) {\n return offset;\n }\n\n // Otherwise skip to the next marker, like libjpeg does (and Jimp did\n // with skipJunkBeforeMarkers)\n for (let i = offset + 1; i + 1 < length; i++) {\n if (data[i] !== 0xff) {\n continue;\n }\n\n const next = data[i + 1]!;\n\n if (!isMarkerCode(next) || next === 0xff) {\n continue;\n }\n\n if (\n !hasLength(next) ||\n next === 0xda ||\n (i + 4 <= length &&\n this.segmentEndsWell(\n data,\n i + 2 + ((data[i + 2]! << 8) | data[i + 3]!),\n ))\n ) {\n return i;\n }\n }\n\n return -1;\n }\n\n /** Whether a segment ending at `end` is followed by a marker or the end. */\n private segmentEndsWell(data: Uint8Array, end: number) {\n return end === data.length || (end < data.length && data[end] === 0xff);\n }\n\n /**\n * Fixes the end of a segment whose length doesn't lead to a marker, by\n * searching for one in the data (pdf.js readDataBlock).\n */\n private fixSegmentEnd(data: Uint8Array, start: number, end: number) {\n if (this.segmentEndsWell(data, end)) {\n return end;\n }\n\n this.corrupt(\"Corrupt JPEG data: bad marker segment length\");\n\n for (let i = start; i + 1 < data.length; i++) {\n if (\n data[i] === 0xff &&\n isMarkerCode(data[i + 1]) &&\n data[i + 1] !== 0xff\n ) {\n return i;\n }\n }\n\n return data.length;\n }\n\n private readAppSegment(code: number, segment: Uint8Array) {\n const is = (...bytes: number[]) =>\n bytes.every((byte, index) => segment[index] === byte);\n\n if (code === 0xfe) {\n let comment = \"\";\n\n for (let i = 0; i < segment.length; i += 0x8000) {\n comment += String.fromCharCode(...segment.subarray(i, i + 0x8000));\n }\n\n this.comments.push(comment);\n } else if (code === 0xe0 && is(0x4a, 0x46, 0x49, 0x46, 0)) {\n // JFIF\\0\n this.jfif = true;\n } else if (code === 0xe1 && is(0x45, 0x78, 0x69, 0x66, 0)) {\n // Exif\\0. Like jpeg-js, everything after \"Exif\\0\", so starting with the\n // second padding byte\n this.exif = segment.slice(5);\n } else if (code === 0xee && is(0x41, 0x64, 0x6f, 0x62, 0x65)) {\n // Adobe\n this.adobe = { transformCode: segment[11] ?? 0 };\n }\n }\n\n private readQuantTables(data: Uint8Array, offset: number, end: number) {\n while (offset < end) {\n const spec = data[offset++]!;\n const precision = spec >> 4;\n\n if (precision > 1) {\n throw new JpegFormatError(\"Bogus DQT: invalid table precision\");\n }\n\n if (offset + 64 * (precision + 1) > end) {\n throw new JpegFormatError(\"Bad length of DQT marker\");\n }\n\n const table = new Uint16Array(64);\n\n for (let i = 0; i < 64; i++) {\n if (precision === 0) {\n table[NATURAL_ORDER[i]!] = data[offset++]!;\n } else {\n table[NATURAL_ORDER[i]!] = (data[offset]! << 8) | data[offset + 1]!;\n offset += 2;\n }\n }\n\n this.quantTables[spec & 15] = table;\n }\n }\n\n private readHuffmanTables(data: Uint8Array, offset: number, end: number) {\n while (offset < end) {\n const spec = data[offset++]!;\n const tableClass = spec >> 4;\n\n if (tableClass > 1 || offset + 16 > end) {\n throw new JpegFormatError(\"Bogus DHT: invalid table\");\n }\n\n const counts = data.subarray(offset, offset + 16);\n let count = 0;\n\n for (let i = 0; i < 16; i++) {\n count += counts[i]!;\n }\n\n offset += 16;\n\n if (count > 256 || offset + count > end) {\n throw new JpegFormatError(\"Bogus DHT: invalid table\");\n }\n\n const table = buildHuffmanTable(\n counts,\n data.subarray(offset, offset + count),\n tableClass === 0,\n );\n\n offset += count;\n (tableClass === 0 ? this.dcTables : this.acTables)[spec & 15] = table;\n }\n }\n\n /** DAC: arithmetic coding conditioning, like libjpeg's get_dac(). */\n private readConditioning(data: Uint8Array, offset: number, end: number) {\n if ((end - offset) % 2 !== 0) {\n throw new JpegFormatError(\"Bad length of DAC marker\");\n }\n\n for (; offset < end; offset += 2) {\n const index = data[offset]!;\n const value = data[offset + 1]!;\n const table = index & 15;\n\n if (index >= 32 || table > 3) {\n throw new JpegFormatError(`Bogus DAC index ${index}`);\n }\n\n if (index >= 16) {\n this.conditioning.acK[table] = value;\n } else {\n this.conditioning.dcLower[table] = value & 15;\n this.conditioning.dcUpper[table] = value >> 4;\n\n if ((value & 15) > value >> 4) {\n throw new JpegFormatError(`Bogus DAC value 0x${hex(value)}`);\n }\n }\n }\n }\n\n private readFrame(\n code: number,\n data: Uint8Array,\n offset: number,\n end: number,\n ) {\n if (this.frame) {\n throw new JpegFormatError(\n \"JPEG data has more than one frame (SOF marker)\",\n );\n }\n\n if (end - offset < 6) {\n throw new JpegFormatError(\"Bad length of SOF marker\");\n }\n\n const precision = data[offset]!;\n let height = (data[offset + 1]! << 8) | data[offset + 2]!;\n const width = (data[offset + 3]! << 8) | data[offset + 4]!;\n const count = data[offset + 5]!;\n\n if (precision !== 8 && precision !== 12) {\n throw new JpegUnsupportedError(\n `Unsupported JPEG data precision: ${precision} bits (only 8 and 12 are supported)`,\n );\n }\n\n if (count === 0 || end - offset < 6 + count * 3) {\n throw new JpegFormatError(\"Bad length of SOF marker\");\n }\n\n if (count !== 1 && count !== 3 && count !== 4) {\n throw new JpegUnsupportedError(\n `Unsupported JPEG colour format: ${count} components`,\n );\n }\n\n if (width === 0) {\n throw new JpegFormatError(\"Empty JPEG image (width is 0)\");\n }\n\n if (height === 0) {\n // The height is in a DNL marker after the first scan\n height = this.findDnlHeight(data, end);\n }\n\n const megapixels = (width * height) / 1e6;\n\n if (megapixels > this.options.maxResolutionInMP) {\n const exceeded = Math.ceil(megapixels - this.options.maxResolutionInMP);\n\n throw new JpegLimitError(\n `maxResolutionInMP limit exceeded by ${exceeded}MP`,\n );\n }\n\n const components: Component[] = [];\n let maxH = 1;\n let maxV = 1;\n\n for (let i = 0; i < count; i++) {\n const p = offset + 6 + i * 3;\n const id = data[p]!;\n const h = data[p + 1]! >> 4;\n const v = data[p + 1]! & 15;\n\n if (h < 1 || h > 4 || v < 1 || v > 4) {\n throw new JpegFormatError(\n \"Invalid sampling factor, expected values above 0 and up to 4\",\n );\n }\n\n maxH = Math.max(maxH, h);\n maxV = Math.max(maxV, v);\n components.push({\n id,\n h,\n v,\n quantId: data[p + 2]!,\n quantTable: null,\n blocksPerLine: 0,\n blocksPerColumn: 0,\n blocksPerLineMcu: 0,\n blocksPerColumnMcu: 0,\n width: 0,\n height: 0,\n coefficients: new Int16Array(0),\n plane: null,\n dcTable: null,\n acTable: null,\n pred: 0,\n dcArithmetic: 0,\n acArithmetic: 0,\n dcContext: 0,\n scanned: false,\n coefBits: new Int8Array(64).fill(-1),\n previousCoefBits: new Int8Array(64),\n });\n }\n\n const mcusPerLine = Math.ceil(width / (8 * maxH));\n const mcusPerColumn = Math.ceil(height / (8 * maxV));\n const sampleBytes = precision > 8 ? 2 : 1;\n let planeBytes = 0;\n let coefficientBytes = 0;\n\n for (const component of components) {\n component.width = Math.ceil((width * component.h) / maxH);\n component.height = Math.ceil((height * component.v) / maxV);\n component.blocksPerLine = Math.ceil(component.width / 8);\n component.blocksPerColumn = Math.ceil(component.height / 8);\n component.blocksPerLineMcu = mcusPerLine * component.h;\n component.blocksPerColumnMcu = mcusPerColumn * component.v;\n planeBytes +=\n component.blocksPerLine * component.blocksPerColumn * 64 * sampleBytes;\n coefficientBytes +=\n component.blocksPerLineMcu * component.blocksPerColumnMcu * 128;\n }\n\n this.width = width;\n this.height = height;\n const progressive = code === 0xc2 || code === 0xca;\n\n this.frame = {\n progressive,\n arithmetic: code === 0xc9 || code === 0xca,\n precision,\n width,\n height,\n components,\n maxH,\n maxV,\n mcusPerLine,\n mcusPerColumn,\n };\n\n // The planes and the output, plus the coefficients of a progressive JPEG\n this.requestMemory(planeBytes + width * height * 4);\n\n if (progressive) {\n this.requestMemory(coefficientBytes);\n }\n }\n\n /** Finds the DNL marker that gives the height of a frame. */\n private findDnlHeight(data: Uint8Array, offset: number) {\n for (let i = offset; i + 5 < data.length; i++) {\n if (data[i] === 0xff && data[i + 1] === 0xdc) {\n const height = (data[i + 4]! << 8) | data[i + 5]!;\n\n if (height > 0) {\n return height;\n }\n }\n }\n\n throw new JpegFormatError(\n \"Empty JPEG image (height is 0 and there is no DNL marker)\",\n );\n }\n\n private readScan(data: Uint8Array, offset: number, end: number) {\n const frame = this.frame;\n\n if (!frame) {\n throw new JpegFormatError(\n \"Corrupt JPEG data: SOS marker before SOF marker\",\n );\n }\n\n if (++this.scans > MAX_SCANS) {\n throw new JpegLimitError(`JPEG has more than ${MAX_SCANS} scans`);\n }\n\n const count = data[offset++]!;\n\n if (count < 1 || count > 4 || end - offset !== count * 2 + 3) {\n throw new JpegFormatError(\"Bad length of SOS marker\");\n }\n\n const components: Component[] = [];\n\n for (let i = 0; i < count; i++) {\n const id = data[offset++]!;\n const tables = data[offset++]!;\n const component = frame.components.find((c) => c.id === id);\n\n if (!component || components.includes(component)) {\n throw new JpegFormatError(`Invalid component ID ${id} in SOS marker`);\n }\n\n if (frame.arithmetic) {\n if (tables >> 4 > 3 || (tables & 15) > 3) {\n throw new JpegFormatError(\"Invalid arithmetic table in SOS marker\");\n }\n\n component.dcArithmetic = tables >> 4;\n component.acArithmetic = tables & 15;\n } else {\n component.dcTable = this.huffmanTable(\n this.dcTables,\n tables >> 4,\n true,\n frame.progressive,\n );\n component.acTable = this.huffmanTable(\n this.acTables,\n tables & 15,\n false,\n frame.progressive,\n );\n }\n\n components.push(component);\n }\n\n const spectralStart = data[offset++]!;\n const spectralEnd = data[offset++]!;\n const approxHigh = data[offset]! >> 4;\n const approxLow = data[offset]! & 15;\n\n if (frame.progressive) {\n const dc = spectralStart === 0;\n\n if (\n (dc\n ? spectralEnd !== 0\n : spectralStart > spectralEnd || spectralEnd > 63 || count !== 1) ||\n (approxHigh !== 0 && approxLow !== approxHigh - 1) ||\n approxLow > 13\n ) {\n throw new JpegFormatError(\n `Invalid progressive parameters Ss=${spectralStart} Se=${spectralEnd} Ah=${approxHigh} Al=${approxLow}`,\n );\n }\n }\n\n // Check the tables each kind of scan needs\n const needsDC =\n !frame.progressive || (spectralStart === 0 && approxHigh === 0);\n const needsAC = !frame.progressive || spectralStart > 0;\n\n for (const component of components) {\n if (frame.arithmetic) {\n break;\n }\n\n if ((needsDC && !component.dcTable) || (needsAC && !component.acTable)) {\n throw new JpegFormatError(\"Huffman table missing for SOS component\");\n }\n }\n\n if (count > 1) {\n let blocks = 0;\n\n for (const component of components) {\n blocks += component.h * component.v;\n }\n\n if (blocks > MAX_BLOCKS_IN_MCU) {\n throw new JpegFormatError(\n \"Sampling factors too large for interleaved scan\",\n );\n }\n }\n\n const scanStart = end;\n\n if (!frame.progressive && this.streaming) {\n // The image is complete, ignore further scans\n return this.skipScan(data, scanStart);\n }\n\n for (const component of components) {\n if (!component.quantTable) {\n component.quantTable = this.quantTables[component.quantId] ?? null;\n\n if (\n !component.quantTable &&\n !frame.progressive &&\n count === frame.components.length\n ) {\n throw new JpegFormatError(\n `Quantization table ${component.quantId} is missing`,\n );\n }\n }\n }\n\n this.checkEnoughData(\n frame,\n data,\n scanStart,\n components,\n needsDC ? (frame.progressive ? 1 : 2) : 0,\n );\n\n const firstScan = this.scans === 1;\n\n if (firstScan) {\n this.idct = createIdctContext(frame.precision);\n this.streaming = !frame.progressive && count === frame.components.length;\n }\n\n if (this.streaming) {\n return this.decodeStreamingScan(frame, data, scanStart, components);\n }\n\n if (frame.progressive) {\n // Track the progression for block smoothing, like jdphuff.c\n for (const { coefBits, previousCoefBits } of components) {\n const from = Math.min(spectralStart, 1);\n const to = Math.max(spectralEnd, 9);\n\n for (let i = from; i <= to; i++) {\n previousCoefBits[i] = this.scans > 1 ? coefBits[i]! : 0;\n }\n\n for (let i = spectralStart; i <= spectralEnd; i++) {\n coefBits[i] = approxLow;\n }\n }\n }\n\n for (const component of components) {\n if (component.coefficients.length === 0) {\n if (!frame.progressive) {\n this.requestMemory(\n component.blocksPerLineMcu * component.blocksPerColumnMcu * 128,\n );\n }\n\n component.coefficients = this.allocate(\n () =>\n new Int16Array(\n component.blocksPerLineMcu * component.blocksPerColumnMcu * 64,\n ),\n );\n }\n\n component.scanned = true;\n }\n\n const result = decodeScan(\n data,\n scanStart,\n {\n components,\n progressive: frame.progressive,\n spectralStart,\n spectralEnd,\n approxHigh,\n approxLow,\n mcusPerLine: frame.mcusPerLine,\n mcusPerColumn: frame.mcusPerColumn,\n restartInterval: this.restartInterval,\n arithmetic: frame.arithmetic ? this.conditioning : undefined,\n },\n this.scanOptions(),\n );\n\n this.lastGoodRow = result.lastGoodRow;\n\n return result.offset;\n }\n\n private scanOptions() {\n return {\n tolerant: this.tolerant,\n allowTruncated: this.options.allowTruncated,\n };\n }\n\n private huffmanTable(\n tables: (HuffmanTable | undefined)[],\n id: number,\n isDC: boolean,\n progressive: boolean,\n ) {\n let table = tables[id];\n\n // Like libjpeg-turbo, fall back on the tables of the JPEG standard\n // (Annex K) in sequential JPEGs: Motion JPEG frames leave them out\n if (!table && !progressive && id < 2) {\n const standard = STANDARD_TABLES[isDC ? \"dc\" : \"ac\"][id]!;\n\n table = buildHuffmanTable(standard.counts, standard.symbols, isDC);\n tables[id] = table;\n }\n\n return table ?? null;\n }\n\n /**\n * Rejects a frame that is too big for the data left before decoding it, so\n * a small file can't make the decoder allocate and decode a huge image.\n * Every block needs at least one bit per scan for its DC coefficient, two\n * for a sequential scan (with the end-of-block code).\n */\n private checkEnoughData(\n frame: Frame,\n data: Uint8Array,\n offset: number,\n components: Component[],\n bitsPerBlock: number,\n ) {\n // Arithmetic coding can take less than a bit per block\n if (this.options.allowTruncated || bitsPerBlock === 0 || frame.arithmetic) {\n return;\n }\n\n let blocks = 0;\n\n for (const component of components) {\n blocks +=\n components.length === 1\n ? component.blocksPerLine * component.blocksPerColumn\n : frame.mcusPerLine * frame.mcusPerColumn * component.h * component.v;\n }\n\n // Leave a row of MCUs, which may be missing (see checkTruncated())\n const rowBlocks =\n frame.mcusPerLine * frame.maxH * frame.maxV * components.length;\n\n if (((blocks - rowBlocks) * bitsPerBlock) / 8 > data.length - offset) {\n throw new JpegFormatError(\n \"JPEG data is truncated: the image data ends before the image is complete\",\n );\n }\n }\n\n private allocate<T>(create: () => T): T {\n try {\n return create();\n } catch (error) {\n if (error instanceof RangeError) {\n throw new JpegLimitError(\n \"Could not allocate enough memory for the image\",\n );\n }\n\n throw error;\n }\n }\n\n private createPlane(frame: Frame, component: Component) {\n const size = component.blocksPerLine * component.blocksPerColumn * 64;\n\n component.plane = this.allocate(() =>\n frame.precision > 8 ? new Uint16Array(size) : new Uint8Array(size),\n );\n }\n\n private decodeStreamingScan(\n frame: Frame,\n data: Uint8Array,\n offset: number,\n components: Component[],\n ) {\n const single = components.length === 1;\n const idct = this.idct!;\n\n for (const component of components) {\n const rows = single ? 1 : component.v;\n\n component.coefficients = new Int16Array(\n component.blocksPerLineMcu * rows * 64,\n );\n this.createPlane(frame, component);\n component.scanned = true;\n }\n\n const onRow = (mcuRow: number) => {\n for (const component of components) {\n const rows = single ? 1 : component.v;\n const {\n blocksPerLine,\n blocksPerColumn,\n blocksPerLineMcu,\n coefficients,\n } = component;\n const plane = component.plane!;\n const stride = blocksPerLine * 8;\n const quantTable = component.quantTable!;\n\n for (let j = 0; j < rows; j++) {\n const blockRow = mcuRow * rows + j;\n\n if (blockRow >= blocksPerColumn) {\n break;\n }\n\n for (let col = 0; col < blocksPerLine; col++) {\n idctBlock(\n idct,\n coefficients,\n (j * blocksPerLineMcu + col) * 64,\n quantTable,\n plane,\n blockRow * 8 * stride + col * 8,\n stride,\n );\n }\n }\n\n coefficients.fill(0);\n }\n };\n\n return decodeScan(\n data,\n offset,\n {\n components,\n progressive: false,\n spectralStart: 0,\n spectralEnd: 63,\n approxHigh: 0,\n approxLow: 0,\n mcusPerLine: frame.mcusPerLine,\n mcusPerColumn: frame.mcusPerColumn,\n restartInterval: this.restartInterval,\n arithmetic: frame.arithmetic ? this.conditioning : undefined,\n onRow,\n },\n this.scanOptions(),\n ).offset;\n }\n\n /** Skips the data of a scan that isn't decoded. */\n private skipScan(data: Uint8Array, offset: number) {\n for (let i = offset; i + 1 < data.length; i++) {\n const next = data[i + 1]!;\n\n if (\n data[i] === 0xff &&\n next !== 0 &&\n next !== 0xff &&\n !(next >= 0xd0 && next <= 0xd7)\n ) {\n return i;\n }\n }\n\n return data.length;\n }\n\n /** IDCT of the stored coefficients of a progressive or multi-scan JPEG. */\n private finishCoefficients(frame: Frame) {\n const idct = this.idct!;\n const latched = frame.components.every((c) => c.quantTable);\n const smoothing =\n frame.progressive &&\n latched &&\n smoothingUseful(\n frame.components.map((c) => ({ ...c, quantTable: c.quantTable! })),\n );\n\n for (const component of frame.components) {\n if (!component.scanned) {\n this.corrupt(\"JPEG data is missing a colour component\");\n }\n\n const quantTable =\n component.quantTable ?? this.quantTables[component.quantId];\n\n if (!quantTable) {\n throw new JpegFormatError(\n `Quantization table ${component.quantId} is missing`,\n );\n }\n\n this.createPlane(frame, component);\n\n if (!component.scanned) {\n continue;\n }\n\n if (smoothing) {\n smoothAndTransform(\n idct,\n { ...component, quantTable },\n component.plane!,\n this.scans,\n this.lastGoodRow,\n frame.mcusPerColumn,\n );\n component.coefficients = new Int16Array(0);\n continue;\n }\n\n const { blocksPerLine, blocksPerColumn, blocksPerLineMcu, coefficients } =\n component;\n const plane = component.plane!;\n const stride = blocksPerLine * 8;\n\n for (let row = 0; row < blocksPerColumn; row++) {\n for (let col = 0; col < blocksPerLine; col++) {\n idctBlock(\n idct,\n coefficients,\n (row * blocksPerLineMcu + col) * 64,\n quantTable,\n plane,\n row * 8 * stride + col * 8,\n stride,\n );\n }\n }\n\n // Free the coefficients before the output is allocated\n component.coefficients = new Int16Array(0);\n }\n }\n\n /**\n * The colour space of the data, picked like libjpeg does unless\n * `colorTransform` says whether to transform from YCbCr (or YCCK).\n */\n get colorSpace(): ColorSpace {\n const frame = this.frame!;\n const count = frame.components.length;\n const transform = this.options.colorTransform;\n\n if (count === 1) {\n return \"grayscale\";\n }\n\n if (count === 3) {\n if (transform !== undefined) {\n return transform ? \"ycbcr\" : \"rgb\";\n }\n\n if (this.jfif) {\n return \"ycbcr\";\n }\n\n if (this.adobe) {\n return this.adobe.transformCode === 0 ? \"rgb\" : \"ycbcr\";\n }\n\n const [a, b, c] = frame.components as [Component, Component, Component];\n\n // ASCII 'R', 'G', 'B'\n return a.id === 0x52 && b.id === 0x47 && c.id === 0x42 ? \"rgb\" : \"ycbcr\";\n }\n\n if (transform !== undefined) {\n return transform ? \"ycck\" : \"cmyk\";\n }\n\n return this.adobe && this.adobe.transformCode !== 0 ? \"ycck\" : \"cmyk\";\n }\n\n /** Converts the decoded image to RGBA (`channels` 4) or RGB. */\n getPixels(output: Uint8Array, channels: 3 | 4) {\n const frame = this.frame!;\n const components: OutputComponent[] = frame.components.map((c) => ({\n plane: c.plane!,\n stride: c.blocksPerLine * 8,\n width: c.width,\n height: c.height,\n h: c.h,\n v: c.v,\n }));\n\n convertToRgb(\n components,\n this.colorSpace,\n frame.width,\n frame.height,\n frame.precision,\n channels,\n output,\n );\n }\n}\n"]}
@@ -0,0 +1,64 @@
1
+ /** Codes up to this many bits are decoded with a single table lookup. */
2
+ export declare const LOOKAHEAD_BITS = 9;
3
+ export interface HuffmanTable {
4
+ /**
5
+ * Indexed by the next LOOKAHEAD_BITS bits: `(length << 8) | symbol`, or 0
6
+ * when the code is longer than LOOKAHEAD_BITS.
7
+ */
8
+ lookup: Uint16Array;
9
+ /** Largest code of each length, -1 if there is none. Index 17 is a sentinel. */
10
+ maxcode: Int32Array;
11
+ /** Index into `values` of the first code of each length, minus that code. */
12
+ valoffset: Int32Array;
13
+ values: Uint8Array;
14
+ }
15
+ /**
16
+ * Builds the decoding tables of a DHT table.
17
+ * @param counts the number of codes of each length 1..16
18
+ * @param symbols the symbols, in order of increasing code length
19
+ */
20
+ export declare function buildHuffmanTable(counts: Uint8Array, symbols: Uint8Array, isDC: boolean): HuffmanTable;
21
+ /** The end of the data was reached, as if an EOI marker was there. */
22
+ export declare const END_OF_DATA = 256;
23
+ /**
24
+ * Reads the bits of entropy-coded data. Stuffed zero bytes after 0xFF are
25
+ * removed. On reaching a marker or the end of the data it stops there and
26
+ * supplies zero bits, counting them in `padBits`, so decoding never reads out
27
+ * of bounds and the caller can tell afterwards that the data ran out.
28
+ */
29
+ export declare class BitReader {
30
+ readonly data: Uint8Array;
31
+ offset: number;
32
+ /** Bit buffer; only the low `bits` bits are valid. */
33
+ buf: number;
34
+ bits: number;
35
+ /** How many of the most recent bits in the buffer are zero padding. */
36
+ padBits: number;
37
+ /** The marker code the reader stopped at, END_OF_DATA, or NO_MARKER. */
38
+ marker: number;
39
+ /** Offset of the 0xFF of `marker`. */
40
+ markerOffset: number;
41
+ constructor(data: Uint8Array, offset: number);
42
+ /** Fills the buffer to at least 25 bits. */
43
+ fill(): void;
44
+ /** True once more bits were consumed than the data had. */
45
+ get overrun(): boolean;
46
+ getBits(n: number): number;
47
+ getBit(): number;
48
+ /**
49
+ * Decodes one Huffman-coded symbol. Returns -1 for a code that isn't in the
50
+ * table, which only happens with corrupt data.
51
+ */
52
+ decode(table: HuffmanTable): number;
53
+ /** Drops the bits left in the buffer, e.g. before a restart marker. */
54
+ discardBits(): void;
55
+ /**
56
+ * Finds the next marker if the reader hasn't stopped at one, skipping any
57
+ * other bytes, as libjpeg's next_marker() does.
58
+ */
59
+ findMarker(): void;
60
+ /** Steps past the marker the reader stopped at, so reading resumes after it. */
61
+ skipMarker(): void;
62
+ get atMarker(): boolean;
63
+ }
64
+ //# sourceMappingURL=huffman.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"huffman.d.ts","sourceRoot":"","sources":["../../../src/decoder/huffman.ts"],"names":[],"mappings":"AAkBA,yEAAyE;AACzE,eAAO,MAAM,cAAc,IAAI,CAAC;AAEhC,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,MAAM,EAAE,WAAW,CAAC;IACpB,gFAAgF;IAChF,OAAO,EAAE,UAAU,CAAC;IACpB,6EAA6E;IAC7E,SAAS,EAAE,UAAU,CAAC;IACtB,MAAM,EAAE,UAAU,CAAC;CACpB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE,OAAO,GACZ,YAAY,CAqFd;AAID,sEAAsE;AACtE,eAAO,MAAM,WAAW,MAAQ,CAAC;AAEjC;;;;;GAKG;AACH,qBAAa,SAAS;IAYlB,QAAQ,CAAC,IAAI,EAAE,UAAU;IAClB,MAAM,EAAE,MAAM;IAZvB,sDAAsD;IACtD,GAAG,SAAK;IACR,IAAI,SAAK;IACT,uEAAuE;IACvE,OAAO,SAAK;IACZ,wEAAwE;IACxE,MAAM,SAAa;IACnB,sCAAsC;IACtC,YAAY,SAAK;IAEjB,YACW,IAAI,EAAE,UAAU,EAClB,MAAM,EAAE,MAAM,EACnB;IAEJ,4CAA4C;IAC5C,IAAI,SA8CH;IAED,2DAA2D;IAC3D,IAAI,OAAO,YAEV;IAED,OAAO,CAAC,CAAC,EAAE,MAAM,UAQhB;IAED,MAAM,WAQL;IAED;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,YAAY,UAqCzB;IAED,uEAAuE;IACvE,WAAW,SAGV;IAED;;;OAGG;IACH,UAAU,SAqCT;IAED,gFAAgF;IAChF,UAAU,SAKT;IAED,IAAI,QAAQ,YAEX;CACF"}
@@ -0,0 +1,265 @@
1
+ "use strict";
2
+ /*
3
+ * Huffman decoding tables and the entropy-coded data bit reader.
4
+ *
5
+ * Based on jdhuff.c of the Independent JPEG Group's software, as found in
6
+ * libjpeg-turbo (https://github.com/libjpeg-turbo/libjpeg-turbo):
7
+ *
8
+ * Copyright (C) 1991-1997, Thomas G. Lane.
9
+ * libjpeg-turbo Modifications:
10
+ * Copyright (C) 2009-2011, 2016, 2018-2019, 2022, D. R. Commander.
11
+ * For conditions of distribution and use, see README.ijg.
12
+ *
13
+ * Modified by Jimp contributors (2026): translated from C to TypeScript, with
14
+ * a 32-bit bit buffer that pads with zeros past a marker and counts the
15
+ * padding instead of suspending.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.BitReader = exports.END_OF_DATA = exports.LOOKAHEAD_BITS = void 0;
19
+ exports.buildHuffmanTable = buildHuffmanTable;
20
+ const errors_js_1 = require("../errors.js");
21
+ /** Codes up to this many bits are decoded with a single table lookup. */
22
+ exports.LOOKAHEAD_BITS = 9;
23
+ /**
24
+ * Builds the decoding tables of a DHT table.
25
+ * @param counts the number of codes of each length 1..16
26
+ * @param symbols the symbols, in order of increasing code length
27
+ */
28
+ function buildHuffmanTable(counts, symbols, isDC) {
29
+ const sizes = new Uint8Array(257);
30
+ const codes = new Int32Array(257);
31
+ let p = 0;
32
+ for (let l = 1; l <= 16; l++) {
33
+ const count = counts[l - 1];
34
+ if (p + count > 256) {
35
+ throw new errors_js_1.JpegFormatError("Bogus Huffman table definition");
36
+ }
37
+ for (let i = 0; i < count; i++) {
38
+ sizes[p++] = l;
39
+ }
40
+ }
41
+ const symbolCount = p;
42
+ let code = 0;
43
+ let size = sizes[0];
44
+ p = 0;
45
+ while (sizes[p]) {
46
+ while (sizes[p] === size) {
47
+ codes[p++] = code++;
48
+ }
49
+ // Codes of this length must fit in this many bits
50
+ if (code >= 1 << size) {
51
+ throw new errors_js_1.JpegFormatError("Bogus Huffman table definition");
52
+ }
53
+ code <<= 1;
54
+ size++;
55
+ }
56
+ const maxcode = new Int32Array(18);
57
+ const valoffset = new Int32Array(18);
58
+ p = 0;
59
+ for (let l = 1; l <= 16; l++) {
60
+ const count = counts[l - 1];
61
+ if (count) {
62
+ valoffset[l] = p - codes[p];
63
+ p += count;
64
+ maxcode[l] = codes[p - 1];
65
+ }
66
+ else {
67
+ maxcode[l] = -1;
68
+ }
69
+ }
70
+ maxcode[17] = 0xfffff;
71
+ const lookup = new Uint16Array(1 << exports.LOOKAHEAD_BITS);
72
+ p = 0;
73
+ for (let l = 1; l <= exports.LOOKAHEAD_BITS; l++) {
74
+ for (let i = 0; i < counts[l - 1]; i++, p++) {
75
+ // Every LOOKAHEAD_BITS-bit sequence that starts with this code
76
+ let index = codes[p] << (exports.LOOKAHEAD_BITS - l);
77
+ for (let n = 1 << (exports.LOOKAHEAD_BITS - l); n > 0; n--) {
78
+ lookup[index++] = (l << 8) | symbols[p];
79
+ }
80
+ }
81
+ }
82
+ const values = new Uint8Array(256);
83
+ values.set(symbols.subarray(0, symbolCount));
84
+ // DC differences of more than 15 bits can't occur with 8- or 12-bit samples
85
+ if (isDC) {
86
+ for (let i = 0; i < symbolCount; i++) {
87
+ if (values[i] > 15) {
88
+ throw new errors_js_1.JpegFormatError("Bogus Huffman table definition");
89
+ }
90
+ }
91
+ }
92
+ return { lookup, maxcode, valoffset, values };
93
+ }
94
+ /** No marker has been reached. */
95
+ const NO_MARKER = -1;
96
+ /** The end of the data was reached, as if an EOI marker was there. */
97
+ exports.END_OF_DATA = 0x100;
98
+ /**
99
+ * Reads the bits of entropy-coded data. Stuffed zero bytes after 0xFF are
100
+ * removed. On reaching a marker or the end of the data it stops there and
101
+ * supplies zero bits, counting them in `padBits`, so decoding never reads out
102
+ * of bounds and the caller can tell afterwards that the data ran out.
103
+ */
104
+ class BitReader {
105
+ data;
106
+ offset;
107
+ /** Bit buffer; only the low `bits` bits are valid. */
108
+ buf = 0;
109
+ bits = 0;
110
+ /** How many of the most recent bits in the buffer are zero padding. */
111
+ padBits = 0;
112
+ /** The marker code the reader stopped at, END_OF_DATA, or NO_MARKER. */
113
+ marker = NO_MARKER;
114
+ /** Offset of the 0xFF of `marker`. */
115
+ markerOffset = 0;
116
+ constructor(data, offset) {
117
+ this.data = data;
118
+ this.offset = offset;
119
+ }
120
+ /** Fills the buffer to at least 25 bits. */
121
+ fill() {
122
+ const data = this.data;
123
+ const end = data.length;
124
+ while (this.bits <= 24) {
125
+ let byte = 0;
126
+ if (this.marker !== NO_MARKER) {
127
+ this.padBits += 8;
128
+ }
129
+ else if (this.offset >= end) {
130
+ this.marker = exports.END_OF_DATA;
131
+ this.markerOffset = end;
132
+ this.padBits += 8;
133
+ }
134
+ else {
135
+ byte = data[this.offset];
136
+ if (byte === 0xff) {
137
+ // Any number of fill bytes may precede a marker
138
+ let next = this.offset + 1;
139
+ while (next < end && data[next] === 0xff) {
140
+ next++;
141
+ }
142
+ if (next >= end) {
143
+ this.marker = exports.END_OF_DATA;
144
+ this.markerOffset = end;
145
+ this.padBits += 8;
146
+ byte = 0;
147
+ }
148
+ else if (data[next] === 0) {
149
+ // Stuffed zero byte: the data byte is 0xFF
150
+ this.offset = next + 1;
151
+ }
152
+ else {
153
+ this.marker = data[next];
154
+ this.markerOffset = next - 1;
155
+ this.padBits += 8;
156
+ byte = 0;
157
+ }
158
+ }
159
+ else {
160
+ this.offset++;
161
+ }
162
+ }
163
+ this.buf = (this.buf << 8) | byte;
164
+ this.bits += 8;
165
+ }
166
+ }
167
+ /** True once more bits were consumed than the data had. */
168
+ get overrun() {
169
+ return this.bits < this.padBits;
170
+ }
171
+ getBits(n) {
172
+ if (this.bits < n) {
173
+ this.fill();
174
+ }
175
+ this.bits -= n;
176
+ return (this.buf >>> this.bits) & ((1 << n) - 1);
177
+ }
178
+ getBit() {
179
+ if (this.bits < 1) {
180
+ this.fill();
181
+ }
182
+ this.bits--;
183
+ return (this.buf >>> this.bits) & 1;
184
+ }
185
+ /**
186
+ * Decodes one Huffman-coded symbol. Returns -1 for a code that isn't in the
187
+ * table, which only happens with corrupt data.
188
+ */
189
+ decode(table) {
190
+ // Enough for the longest code plus the 17th bit that flags a bad one
191
+ if (this.bits < 17) {
192
+ this.fill();
193
+ }
194
+ const entry = table.lookup[(this.buf >>> (this.bits - exports.LOOKAHEAD_BITS)) &
195
+ ((1 << exports.LOOKAHEAD_BITS) - 1)];
196
+ if (entry !== 0) {
197
+ this.bits -= entry >> 8;
198
+ return entry & 0xff;
199
+ }
200
+ // Longer code: compare it with the largest code of each length
201
+ const maxcode = table.maxcode;
202
+ let length = exports.LOOKAHEAD_BITS + 1;
203
+ let code = (this.buf >>> (this.bits - length)) & ((1 << length) - 1);
204
+ while (code > maxcode[length]) {
205
+ length++;
206
+ code = (this.buf >>> (this.bits - length)) & ((1 << length) - 1);
207
+ }
208
+ if (length > 16) {
209
+ this.bits -= 16;
210
+ return -1;
211
+ }
212
+ this.bits -= length;
213
+ return table.values[(table.valoffset[length] + code) & 0xff];
214
+ }
215
+ /** Drops the bits left in the buffer, e.g. before a restart marker. */
216
+ discardBits() {
217
+ this.bits = 0;
218
+ this.padBits = 0;
219
+ }
220
+ /**
221
+ * Finds the next marker if the reader hasn't stopped at one, skipping any
222
+ * other bytes, as libjpeg's next_marker() does.
223
+ */
224
+ findMarker() {
225
+ if (this.marker !== NO_MARKER) {
226
+ return;
227
+ }
228
+ const data = this.data;
229
+ const end = data.length;
230
+ let offset = this.offset;
231
+ while (offset < end) {
232
+ if (data[offset] !== 0xff) {
233
+ offset++;
234
+ continue;
235
+ }
236
+ let next = offset + 1;
237
+ while (next < end && data[next] === 0xff) {
238
+ next++;
239
+ }
240
+ if (next >= end) {
241
+ break;
242
+ }
243
+ if (data[next] !== 0) {
244
+ this.marker = data[next];
245
+ this.markerOffset = next - 1;
246
+ return;
247
+ }
248
+ offset = next + 1;
249
+ }
250
+ this.marker = exports.END_OF_DATA;
251
+ this.markerOffset = end;
252
+ }
253
+ /** Steps past the marker the reader stopped at, so reading resumes after it. */
254
+ skipMarker() {
255
+ if (this.marker !== exports.END_OF_DATA) {
256
+ this.offset = this.markerOffset + 2;
257
+ this.marker = NO_MARKER;
258
+ }
259
+ }
260
+ get atMarker() {
261
+ return this.marker !== NO_MARKER;
262
+ }
263
+ }
264
+ exports.BitReader = BitReader;
265
+ //# sourceMappingURL=huffman.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"huffman.js","sourceRoot":"","sources":["../../../src/decoder/huffman.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;AAEH,4CAA+C;AAE/C,yEAAyE;AAC5D,QAAA,cAAc,GAAG,CAAC,CAAC;AAehC;;;;GAIG;AACH,2BACE,MAAkB,EAClB,OAAmB,EACnB,IAAa;IAEb,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;IAClC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEV,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7B,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAE,CAAC;QAE7B,IAAI,CAAC,GAAG,KAAK,GAAG,GAAG,EAAE,CAAC;YACpB,MAAM,IAAI,2BAAe,CAAC,gCAAgC,CAAC,CAAC;QAC9D,CAAC;QAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;YAC/B,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;QACjB,CAAC;IACH,CAAC;IAED,MAAM,WAAW,GAAG,CAAC,CAAC;IACtB,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,IAAI,IAAI,GAAG,KAAK,CAAC,CAAC,CAAE,CAAC;IAErB,CAAC,GAAG,CAAC,CAAC;IAEN,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QAChB,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YACzB,KAAK,CAAC,CAAC,EAAE,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F;IAChF,UAAU;QACR,IAAI,IAAI,CAAC,MAAM,KAAK,QAAA,WAAW,EAAE,CAAC;YAChC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC;YACpC,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC;IACnC,CAAC;CACF","sourcesContent":["/*\n * Huffman decoding tables and the entropy-coded data bit reader.\n *\n * Based on jdhuff.c of the Independent JPEG Group's software, as found in\n * libjpeg-turbo (https://github.com/libjpeg-turbo/libjpeg-turbo):\n *\n * Copyright (C) 1991-1997, Thomas G. Lane.\n * libjpeg-turbo Modifications:\n * Copyright (C) 2009-2011, 2016, 2018-2019, 2022, D. R. Commander.\n * For conditions of distribution and use, see README.ijg.\n *\n * Modified by Jimp contributors (2026): translated from C to TypeScript, with\n * a 32-bit bit buffer that pads with zeros past a marker and counts the\n * padding instead of suspending.\n */\n\nimport { JpegFormatError } from \"../errors.js\";\n\n/** Codes up to this many bits are decoded with a single table lookup. */\nexport const LOOKAHEAD_BITS = 9;\n\nexport interface HuffmanTable {\n /**\n * Indexed by the next LOOKAHEAD_BITS bits: `(length << 8) | symbol`, or 0\n * when the code is longer than LOOKAHEAD_BITS.\n */\n lookup: Uint16Array;\n /** Largest code of each length, -1 if there is none. Index 17 is a sentinel. */\n maxcode: Int32Array;\n /** Index into `values` of the first code of each length, minus that code. */\n valoffset: Int32Array;\n values: Uint8Array;\n}\n\n/**\n * Builds the decoding tables of a DHT table.\n * @param counts the number of codes of each length 1..16\n * @param symbols the symbols, in order of increasing code length\n */\nexport function buildHuffmanTable(\n counts: Uint8Array,\n symbols: Uint8Array,\n isDC: boolean,\n): HuffmanTable {\n const sizes = new Uint8Array(257);\n const codes = new Int32Array(257);\n let p = 0;\n\n for (let l = 1; l <= 16; l++) {\n const count = counts[l - 1]!;\n\n if (p + count > 256) {\n throw new JpegFormatError(\"Bogus Huffman table definition\");\n }\n\n for (let i = 0; i < count; i++) {\n sizes[p++] = l;\n }\n }\n\n const symbolCount = p;\n let code = 0;\n let size = sizes[0]!;\n\n p = 0;\n\n while (sizes[p]) {\n while (sizes[p] === size) {\n codes[p++] = code++;\n }\n\n // Codes of this length must fit in this many bits\n if (code >= 1 << size) {\n throw new JpegFormatError(\"Bogus Huffman table definition\");\n }\n\n code <<= 1;\n size++;\n }\n\n const maxcode = new Int32Array(18);\n const valoffset = new Int32Array(18);\n\n p = 0;\n\n for (let l = 1; l <= 16; l++) {\n const count = counts[l - 1]!;\n\n if (count) {\n valoffset[l] = p - codes[p]!;\n p += count;\n maxcode[l] = codes[p - 1]!;\n } else {\n maxcode[l] = -1;\n }\n }\n\n maxcode[17] = 0xfffff;\n\n const lookup = new Uint16Array(1 << LOOKAHEAD_BITS);\n\n p = 0;\n\n for (let l = 1; l <= LOOKAHEAD_BITS; l++) {\n for (let i = 0; i < counts[l - 1]!; i++, p++) {\n // Every LOOKAHEAD_BITS-bit sequence that starts with this code\n let index = codes[p]! << (LOOKAHEAD_BITS - l);\n\n for (let n = 1 << (LOOKAHEAD_BITS - l); n > 0; n--) {\n lookup[index++] = (l << 8) | symbols[p]!;\n }\n }\n }\n\n const values = new Uint8Array(256);\n\n values.set(symbols.subarray(0, symbolCount));\n\n // DC differences of more than 15 bits can't occur with 8- or 12-bit samples\n if (isDC) {\n for (let i = 0; i < symbolCount; i++) {\n if (values[i]! > 15) {\n throw new JpegFormatError(\"Bogus Huffman table definition\");\n }\n }\n }\n\n return { lookup, maxcode, valoffset, values };\n}\n\n/** No marker has been reached. */\nconst NO_MARKER = -1;\n/** The end of the data was reached, as if an EOI marker was there. */\nexport const END_OF_DATA = 0x100;\n\n/**\n * Reads the bits of entropy-coded data. Stuffed zero bytes after 0xFF are\n * removed. On reaching a marker or the end of the data it stops there and\n * supplies zero bits, counting them in `padBits`, so decoding never reads out\n * of bounds and the caller can tell afterwards that the data ran out.\n */\nexport class BitReader {\n /** Bit buffer; only the low `bits` bits are valid. */\n buf = 0;\n bits = 0;\n /** How many of the most recent bits in the buffer are zero padding. */\n padBits = 0;\n /** The marker code the reader stopped at, END_OF_DATA, or NO_MARKER. */\n marker = NO_MARKER;\n /** Offset of the 0xFF of `marker`. */\n markerOffset = 0;\n\n constructor(\n readonly data: Uint8Array,\n public offset: number,\n ) {}\n\n /** Fills the buffer to at least 25 bits. */\n fill() {\n const data = this.data;\n const end = data.length;\n\n while (this.bits <= 24) {\n let byte = 0;\n\n if (this.marker !== NO_MARKER) {\n this.padBits += 8;\n } else if (this.offset >= end) {\n this.marker = END_OF_DATA;\n this.markerOffset = end;\n this.padBits += 8;\n } else {\n byte = data[this.offset]!;\n\n if (byte === 0xff) {\n // Any number of fill bytes may precede a marker\n let next = this.offset + 1;\n\n while (next < end && data[next] === 0xff) {\n next++;\n }\n\n if (next >= end) {\n this.marker = END_OF_DATA;\n this.markerOffset = end;\n this.padBits += 8;\n byte = 0;\n } else if (data[next] === 0) {\n // Stuffed zero byte: the data byte is 0xFF\n this.offset = next + 1;\n } else {\n this.marker = data[next]!;\n this.markerOffset = next - 1;\n this.padBits += 8;\n byte = 0;\n }\n } else {\n this.offset++;\n }\n }\n\n this.buf = (this.buf << 8) | byte;\n this.bits += 8;\n }\n }\n\n /** True once more bits were consumed than the data had. */\n get overrun() {\n return this.bits < this.padBits;\n }\n\n getBits(n: number) {\n if (this.bits < n) {\n this.fill();\n }\n\n this.bits -= n;\n\n return (this.buf >>> this.bits) & ((1 << n) - 1);\n }\n\n getBit() {\n if (this.bits < 1) {\n this.fill();\n }\n\n this.bits--;\n\n return (this.buf >>> this.bits) & 1;\n }\n\n /**\n * Decodes one Huffman-coded symbol. Returns -1 for a code that isn't in the\n * table, which only happens with corrupt data.\n */\n decode(table: HuffmanTable) {\n // Enough for the longest code plus the 17th bit that flags a bad one\n if (this.bits < 17) {\n this.fill();\n }\n\n const entry =\n table.lookup[\n (this.buf >>> (this.bits - LOOKAHEAD_BITS)) &\n ((1 << LOOKAHEAD_BITS) - 1)\n ]!;\n\n if (entry !== 0) {\n this.bits -= entry >> 8;\n\n return entry & 0xff;\n }\n\n // Longer code: compare it with the largest code of each length\n const maxcode = table.maxcode;\n let length = LOOKAHEAD_BITS + 1;\n let code = (this.buf >>> (this.bits - length)) & ((1 << length) - 1);\n\n while (code > maxcode[length]!) {\n length++;\n code = (this.buf >>> (this.bits - length)) & ((1 << length) - 1);\n }\n\n if (length > 16) {\n this.bits -= 16;\n\n return -1;\n }\n\n this.bits -= length;\n\n return table.values[(table.valoffset[length]! + code) & 0xff]!;\n }\n\n /** Drops the bits left in the buffer, e.g. before a restart marker. */\n discardBits() {\n this.bits = 0;\n this.padBits = 0;\n }\n\n /**\n * Finds the next marker if the reader hasn't stopped at one, skipping any\n * other bytes, as libjpeg's next_marker() does.\n */\n findMarker() {\n if (this.marker !== NO_MARKER) {\n return;\n }\n\n const data = this.data;\n const end = data.length;\n let offset = this.offset;\n\n while (offset < end) {\n if (data[offset] !== 0xff) {\n offset++;\n continue;\n }\n\n let next = offset + 1;\n\n while (next < end && data[next] === 0xff) {\n next++;\n }\n\n if (next >= end) {\n break;\n }\n\n if (data[next] !== 0) {\n this.marker = data[next]!;\n this.markerOffset = next - 1;\n\n return;\n }\n\n offset = next + 1;\n }\n\n this.marker = END_OF_DATA;\n this.markerOffset = end;\n }\n\n /** Steps past the marker the reader stopped at, so reading resumes after it. */\n skipMarker() {\n if (this.marker !== END_OF_DATA) {\n this.offset = this.markerOffset + 2;\n this.marker = NO_MARKER;\n }\n }\n\n get atMarker() {\n return this.marker !== NO_MARKER;\n }\n}\n"]}
@@ -0,0 +1,20 @@
1
+ export type SampleArray = Uint8Array | Uint16Array;
2
+ export interface IdctContext {
3
+ /** Precision of the first pass: 2 for 8-bit samples, 1 for 12-bit. */
4
+ pass1Bits: number;
5
+ /**
6
+ * Maps a descaled IDCT output (masked with `rangeMask`) to a sample, with
7
+ * the +CENTER level shift and clamping (libjpeg's IDCT_range_limit).
8
+ */
9
+ rangeLimit: SampleArray;
10
+ rangeMask: number;
11
+ workspace: Int32Array;
12
+ }
13
+ export declare function createIdctContext(precision: number): IdctContext;
14
+ /**
15
+ * Dequantizes and inverse transforms the block of coefficients at
16
+ * `coefficients[offset]` (in natural order) into 8x8 samples at
17
+ * `output[outOffset]`, `outStride` samples apart per row.
18
+ */
19
+ export declare function idctBlock(ctx: IdctContext, coefficients: Int16Array, offset: number, quantTable: Uint16Array, output: SampleArray, outOffset: number, outStride: number): void;
20
+ //# sourceMappingURL=idct.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idct.d.ts","sourceRoot":"","sources":["../../../src/decoder/idct.ts"],"names":[],"mappings":"AAoCA,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,WAAW,CAAC;AAEnD,MAAM,WAAW,WAAW;IAC1B,sEAAsE;IACtE,SAAS,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,UAAU,EAAE,WAAW,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,UAAU,CAAC;CACvB;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,WAAW,CA4BhE;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CACvB,GAAG,EAAE,WAAW,EAChB,YAAY,EAAE,UAAU,EACxB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,WAAW,EACvB,MAAM,EAAE,WAAW,EACnB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,QAyLlB"}