@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,349 @@
1
+ "use strict";
2
+ /*
3
+ * Block smoothing of progressive JPEGs whose low-frequency AC coefficients
4
+ * aren't fully known, e.g. because the file was cut off after a few scans.
5
+ * Estimates the missing coefficients from the DC values of the neighbouring
6
+ * blocks, so the image looks smooth instead of blocky.
7
+ *
8
+ * Based on jdcoefct.c (smoothing_ok and decompress_smooth_data) of the
9
+ * Independent JPEG Group's software, as found in libjpeg-turbo
10
+ * (https://github.com/libjpeg-turbo/libjpeg-turbo):
11
+ *
12
+ * Copyright (C) 1994-1997, Thomas G. Lane.
13
+ * libjpeg-turbo Modifications:
14
+ * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
15
+ * Copyright (C) 2010, 2015-2016, 2019-2020, 2022-2024, D. R. Commander.
16
+ * Copyright (C) 2015, 2020, Google, Inc.
17
+ * For conditions of distribution and use, see README.ijg.
18
+ *
19
+ * Modified by Jimp contributors (2026): translated from C to TypeScript for
20
+ * a whole image at once, instead of one iMCU row at a time.
21
+ */
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.smoothingUseful = smoothingUseful;
24
+ exports.smoothAndTransform = smoothAndTransform;
25
+ const idct_js_1 = require("./idct.js");
26
+ /** Coefficients 0..9 (in zig-zag order) take part in smoothing. */
27
+ const SAVED_COEFS = 10;
28
+ /** Natural-order positions of the coefficients that are estimated. */
29
+ const Q01 = 1;
30
+ const Q10 = 8;
31
+ const Q20 = 16;
32
+ const Q11 = 9;
33
+ const Q02 = 2;
34
+ const Q03 = 3;
35
+ const Q12 = 10;
36
+ const Q21 = 17;
37
+ const Q30 = 24;
38
+ /** Like libjpeg's smoothing_ok(): whether smoothing would change anything. */
39
+ function smoothingUseful(components) {
40
+ let useful = false;
41
+ for (const { quantTable: q, coefBits } of components) {
42
+ if (!q[0] ||
43
+ !q[Q01] ||
44
+ !q[Q10] ||
45
+ !q[Q20] ||
46
+ !q[Q11] ||
47
+ !q[Q02] ||
48
+ !q[Q03] ||
49
+ !q[Q12] ||
50
+ !q[Q21] ||
51
+ !q[Q30]) {
52
+ return false;
53
+ }
54
+ if (coefBits[0] < 0) {
55
+ return false;
56
+ }
57
+ for (let i = 1; i < SAVED_COEFS; i++) {
58
+ if (coefBits[i] !== 0) {
59
+ useful = true;
60
+ }
61
+ }
62
+ }
63
+ return useful;
64
+ }
65
+ /** Rounded estimate of a coefficient, limited to what later scans could add. */
66
+ function estimate(num, quant, al) {
67
+ let pred = Math.trunc(((quant << 7) + Math.abs(num)) / (quant << 8));
68
+ if (al > 0 && pred >= 1 << al) {
69
+ pred = (1 << al) - 1;
70
+ }
71
+ return num >= 0 ? pred : -pred;
72
+ }
73
+ /**
74
+ * Smooths and inverse transforms a component, writing its samples into
75
+ * `plane`.
76
+ * @param scans the number of scans read
77
+ * @param lastGoodRow the last row of MCUs that had data in the last scan
78
+ * @param mcuRows the number of MCU rows of the frame
79
+ */
80
+ function smoothAndTransform(idct, component, plane, scans, lastGoodRow, mcuRows) {
81
+ const { v, blocksPerLine, blocksPerColumn, blocksPerLineMcu, coefficients, quantTable: q, } = component;
82
+ const stride = blocksPerLine * 8;
83
+ const workspace = new Int16Array(64);
84
+ const lastColumn = blocksPerLine - 1;
85
+ const latch = Int8Array.from(component.coefBits.subarray(0, SAVED_COEFS));
86
+ const previousLatch = new Int8Array(SAVED_COEFS);
87
+ for (let i = 1; i < SAVED_COEFS; i++) {
88
+ previousLatch[i] = scans > 1 ? component.previousCoefBits[i] : -1;
89
+ }
90
+ const q00 = q[0];
91
+ const q01 = q[Q01];
92
+ const q10 = q[Q10];
93
+ const q20 = q[Q20];
94
+ const q11 = q[Q11];
95
+ const q02 = q[Q02];
96
+ const q03 = q[Q03];
97
+ const q12 = q[Q12];
98
+ const q21 = q[Q21];
99
+ const q30 = q[Q30];
100
+ /** DC coefficient of the block at a row and column. */
101
+ const dc = (row, col) => coefficients[(row * blocksPerLineMcu + col) * 64];
102
+ for (let mcuRow = 0; mcuRow < mcuRows; mcuRow++) {
103
+ // Block rows in this row of MCUs: all of them except in the last one
104
+ let blockRows = v;
105
+ if (mcuRow === mcuRows - 1) {
106
+ blockRows = blocksPerColumn % v || v;
107
+ }
108
+ // Rows past the last good one use what was known before the last scan
109
+ const coefBits = mcuRow > lastGoodRow ? previousLatch : latch;
110
+ // Only interpolate DC values when no AC data is available
111
+ let changeDC = true;
112
+ for (let i = 1; i < SAVED_COEFS; i++) {
113
+ if (coefBits[i] !== -1) {
114
+ changeDC = false;
115
+ }
116
+ }
117
+ // libjpeg's row bookkeeping, which decides where the edges are
118
+ const imageBlockRows = blockRows * mcuRows;
119
+ for (let blockRow = 0; blockRow < blockRows; blockRow++) {
120
+ const imageBlockRow = mcuRow * blockRows + blockRow;
121
+ const row = mcuRow * v + blockRow;
122
+ const prev = imageBlockRow > 0 ? row - 1 : row;
123
+ const prevPrev = imageBlockRow > 1 ? row - 2 : prev;
124
+ const next = imageBlockRow < imageBlockRows - 1 ? row + 1 : row;
125
+ const nextNext = imageBlockRow < imageBlockRows - 2 ? row + 2 : next;
126
+ // The 5x5 neighbourhood of DC values, as sliding registers
127
+ let dc01, dc02, dc03, dc04, dc05;
128
+ let dc06, dc07, dc08, dc09, dc10;
129
+ let dc11, dc12, dc13, dc14, dc15;
130
+ let dc16, dc17, dc18, dc19, dc20;
131
+ let dc21, dc22, dc23, dc24, dc25;
132
+ dc01 = dc02 = dc03 = dc04 = dc05 = dc(prevPrev, 0);
133
+ dc06 = dc07 = dc08 = dc09 = dc10 = dc(prev, 0);
134
+ dc11 = dc12 = dc13 = dc14 = dc15 = dc(row, 0);
135
+ dc16 = dc17 = dc18 = dc19 = dc20 = dc(next, 0);
136
+ dc21 = dc22 = dc23 = dc24 = dc25 = dc(nextNext, 0);
137
+ for (let col = 0; col <= lastColumn; col++) {
138
+ const offset = (row * blocksPerLineMcu + col) * 64;
139
+ workspace.set(coefficients.subarray(offset, offset + 64));
140
+ if (col === 0 && col < lastColumn) {
141
+ dc04 = dc05 = dc(prevPrev, 1);
142
+ dc09 = dc10 = dc(prev, 1);
143
+ dc14 = dc15 = dc(row, 1);
144
+ dc19 = dc20 = dc(next, 1);
145
+ dc24 = dc25 = dc(nextNext, 1);
146
+ }
147
+ if (col + 1 < lastColumn) {
148
+ dc05 = dc(prevPrev, col + 2);
149
+ dc10 = dc(prev, col + 2);
150
+ dc15 = dc(row, col + 2);
151
+ dc20 = dc(next, col + 2);
152
+ dc25 = dc(nextNext, col + 2);
153
+ }
154
+ let al;
155
+ // AC01
156
+ if ((al = coefBits[1]) !== 0 && workspace[1] === 0) {
157
+ const num = q00 *
158
+ (changeDC
159
+ ? -dc01 -
160
+ dc02 +
161
+ dc04 +
162
+ dc05 -
163
+ 3 * dc06 +
164
+ 13 * dc07 -
165
+ 13 * dc09 +
166
+ 3 * dc10 -
167
+ 3 * dc11 +
168
+ 38 * dc12 -
169
+ 38 * dc14 +
170
+ 3 * dc15 -
171
+ 3 * dc16 +
172
+ 13 * dc17 -
173
+ 13 * dc19 +
174
+ 3 * dc20 -
175
+ dc21 -
176
+ dc22 +
177
+ dc24 +
178
+ dc25
179
+ : -7 * dc11 + 50 * dc12 - 50 * dc14 + 7 * dc15);
180
+ workspace[1] = estimate(num, q01, al);
181
+ }
182
+ // AC10
183
+ if ((al = coefBits[2]) !== 0 && workspace[8] === 0) {
184
+ const num = q00 *
185
+ (changeDC
186
+ ? -dc01 -
187
+ 3 * dc02 -
188
+ 3 * dc03 -
189
+ 3 * dc04 -
190
+ dc05 -
191
+ dc06 +
192
+ 13 * dc07 +
193
+ 38 * dc08 +
194
+ 13 * dc09 -
195
+ dc10 +
196
+ dc16 -
197
+ 13 * dc17 -
198
+ 38 * dc18 -
199
+ 13 * dc19 +
200
+ dc20 +
201
+ dc21 +
202
+ 3 * dc22 +
203
+ 3 * dc23 +
204
+ 3 * dc24 +
205
+ dc25
206
+ : -7 * dc03 + 50 * dc08 - 50 * dc18 + 7 * dc23);
207
+ workspace[8] = estimate(num, q10, al);
208
+ }
209
+ // AC20
210
+ if ((al = coefBits[3]) !== 0 && workspace[16] === 0) {
211
+ const num = q00 *
212
+ (changeDC
213
+ ? dc03 +
214
+ 2 * dc07 +
215
+ 7 * dc08 +
216
+ 2 * dc09 -
217
+ 5 * dc12 -
218
+ 14 * dc13 -
219
+ 5 * dc14 +
220
+ 2 * dc17 +
221
+ 7 * dc18 +
222
+ 2 * dc19 +
223
+ dc23
224
+ : -dc03 + 13 * dc08 - 24 * dc13 + 13 * dc18 - dc23);
225
+ workspace[16] = estimate(num, q20, al);
226
+ }
227
+ // AC11
228
+ if ((al = coefBits[4]) !== 0 && workspace[9] === 0) {
229
+ const num = q00 *
230
+ (changeDC
231
+ ? -dc01 +
232
+ dc05 +
233
+ 9 * dc07 -
234
+ 9 * dc09 -
235
+ 9 * dc17 +
236
+ 9 * dc19 +
237
+ dc21 -
238
+ dc25
239
+ : dc10 +
240
+ dc16 -
241
+ 10 * dc17 +
242
+ 10 * dc19 -
243
+ dc02 -
244
+ dc20 +
245
+ dc22 -
246
+ dc24 +
247
+ dc04 -
248
+ dc06 +
249
+ 10 * dc07 -
250
+ 10 * dc09);
251
+ workspace[9] = estimate(num, q11, al);
252
+ }
253
+ // AC02
254
+ if ((al = coefBits[5]) !== 0 && workspace[2] === 0) {
255
+ const num = q00 *
256
+ (changeDC
257
+ ? 2 * dc07 -
258
+ 5 * dc08 +
259
+ 2 * dc09 +
260
+ dc11 +
261
+ 7 * dc12 -
262
+ 14 * dc13 +
263
+ 7 * dc14 +
264
+ dc15 +
265
+ 2 * dc17 -
266
+ 5 * dc18 +
267
+ 2 * dc19
268
+ : -dc11 + 13 * dc12 - 24 * dc13 + 13 * dc14 - dc15);
269
+ workspace[2] = estimate(num, q02, al);
270
+ }
271
+ if (changeDC) {
272
+ // AC03
273
+ if ((al = coefBits[6]) !== 0 && workspace[3] === 0) {
274
+ const num = q00 * (dc07 - dc09 + 2 * dc12 - 2 * dc14 + dc17 - dc19);
275
+ workspace[3] = estimate(num, q03, al);
276
+ }
277
+ // AC12
278
+ if ((al = coefBits[7]) !== 0 && workspace[10] === 0) {
279
+ const num = q00 * (dc07 - 3 * dc08 + dc09 - dc17 + 3 * dc18 - dc19);
280
+ workspace[10] = estimate(num, q12, al);
281
+ }
282
+ // AC21
283
+ if ((al = coefBits[8]) !== 0 && workspace[17] === 0) {
284
+ const num = q00 * (dc07 - dc09 - 3 * dc12 + 3 * dc14 + dc17 - dc19);
285
+ workspace[17] = estimate(num, q21, al);
286
+ }
287
+ // AC30
288
+ if ((al = coefBits[9]) !== 0 && workspace[24] === 0) {
289
+ const num = q00 * (dc07 + 2 * dc08 + dc09 - dc17 - 2 * dc18 - dc19);
290
+ workspace[24] = estimate(num, q30, al);
291
+ }
292
+ // DC
293
+ const num = q00 *
294
+ (-2 * dc01 -
295
+ 6 * dc02 -
296
+ 8 * dc03 -
297
+ 6 * dc04 -
298
+ 2 * dc05 -
299
+ 6 * dc06 +
300
+ 6 * dc07 +
301
+ 42 * dc08 +
302
+ 6 * dc09 -
303
+ 6 * dc10 -
304
+ 8 * dc11 +
305
+ 42 * dc12 +
306
+ 152 * dc13 +
307
+ 42 * dc14 -
308
+ 8 * dc15 -
309
+ 6 * dc16 +
310
+ 6 * dc17 +
311
+ 42 * dc18 +
312
+ 6 * dc19 -
313
+ 6 * dc20 -
314
+ 2 * dc21 -
315
+ 6 * dc22 -
316
+ 8 * dc23 -
317
+ 6 * dc24 -
318
+ 2 * dc25);
319
+ workspace[0] = estimate(num, q00, 0);
320
+ }
321
+ if (row < blocksPerColumn) {
322
+ (0, idct_js_1.idctBlock)(idct, workspace, 0, q, plane, row * 8 * stride + col * 8, stride);
323
+ }
324
+ // Advance for the next column
325
+ dc01 = dc02;
326
+ dc02 = dc03;
327
+ dc03 = dc04;
328
+ dc04 = dc05;
329
+ dc06 = dc07;
330
+ dc07 = dc08;
331
+ dc08 = dc09;
332
+ dc09 = dc10;
333
+ dc11 = dc12;
334
+ dc12 = dc13;
335
+ dc13 = dc14;
336
+ dc14 = dc15;
337
+ dc16 = dc17;
338
+ dc17 = dc18;
339
+ dc18 = dc19;
340
+ dc19 = dc20;
341
+ dc21 = dc22;
342
+ dc22 = dc23;
343
+ dc23 = dc24;
344
+ dc24 = dc25;
345
+ }
346
+ }
347
+ }
348
+ }
349
+ //# sourceMappingURL=smoothing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smoothing.js","sourceRoot":"","sources":["../../../src/decoder/smoothing.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;;AAEH,uCAA0E;AAE1E,mEAAmE;AACnE,MAAM,WAAW,GAAG,EAAE,CAAC;AAEvB,sEAAsE;AACtE,MAAM,GAAG,GAAG,CAAC,CAAC;AACd,MAAM,GAAG,GAAG,CAAC,CAAC;AACd,MAAM,GAAG,GAAG,EAAE,CAAC;AACf,MAAM,GAAG,GAAG,CAAC,CAAC;AACd,MAAM,GAAG,GAAG,CAAC,CAAC;AACd,MAAM,GAAG,GAAG,CAAC,CAAC;AACd,MAAM,GAAG,GAAG,EAAE,CAAC;AACf,MAAM,GAAG,GAAG,EAAE,CAAC;AACf,MAAM,GAAG,GAAG,EAAE,CAAC;AAmBf,8EAA8E;AAC9E,yBAAgC,UAAgC;IAC9D,IAAI,MAAM,GAAG,KAAK,CAAC;IAEnB,KAAK,MAAM,EAAE,UAAU,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,UAAU,EAAE,CAAC;QACrD,IACE,CAAC,CAAC,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC,GAAG,CAAC;YACP,CAAC,CAAC,CAAC,GAAG,CAAC;YACP,CAAC,CAAC,CAAC,GAAG,CAAC;YACP,CAAC,CAAC,CAAC,GAAG,CAAC;YAC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,GAAG,GAAG,GAAG,CAAC,EAC1B,MAAM,CACP,CAAC;gBACJ,CAAC;gBAED,8BAA8B;gBAC9B,IAAI,GAAG,IAAI,CAAC;gBACZ,IAAI,GAAG,IAAI,CAAC;gBACZ,IAAI,GAAG,IAAI,CAAC;gBACZ,IAAI,GAAG,IAAI,CAAC;gBACZ,IAAI,GAAG,IAAI,CAAC;gBACZ,IAAI,GAAG,IAAI,CAAC;gBACZ,IAAI,GAAG,IAAI,CAAC;gBACZ,IAAI,GAAG,IAAI,CAAC;gBACZ,IAAI,GAAG,IAAI,CAAC;gBACZ,IAAI,GAAG,IAAI,CAAC;gBACZ,IAAI,GAAG,IAAI,CAAC;gBACZ,IAAI,GAAG,IAAI,CAAC;gBACZ,IAAI,GAAG,IAAI,CAAC;gBACZ,IAAI,GAAG,IAAI,CAAC;gBACZ,IAAI,GAAG,IAAI,CAAC;gBACZ,IAAI,GAAG,IAAI,CAAC;gBACZ,IAAI,GAAG,IAAI,CAAC;gBACZ,IAAI,GAAG,IAAI,CAAC;gBACZ,IAAI,GAAG,IAAI,CAAC;gBACZ,IAAI,GAAG,IAAI,CAAC;YACd,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["/*\n * Block smoothing of progressive JPEGs whose low-frequency AC coefficients\n * aren't fully known, e.g. because the file was cut off after a few scans.\n * Estimates the missing coefficients from the DC values of the neighbouring\n * blocks, so the image looks smooth instead of blocky.\n *\n * Based on jdcoefct.c (smoothing_ok and decompress_smooth_data) of the\n * Independent JPEG Group's software, as found in libjpeg-turbo\n * (https://github.com/libjpeg-turbo/libjpeg-turbo):\n *\n * Copyright (C) 1994-1997, Thomas G. Lane.\n * libjpeg-turbo Modifications:\n * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB\n * Copyright (C) 2010, 2015-2016, 2019-2020, 2022-2024, D. R. Commander.\n * Copyright (C) 2015, 2020, Google, Inc.\n * For conditions of distribution and use, see README.ijg.\n *\n * Modified by Jimp contributors (2026): translated from C to TypeScript for\n * a whole image at once, instead of one iMCU row at a time.\n */\n\nimport { idctBlock, type IdctContext, type SampleArray } from \"./idct.js\";\n\n/** Coefficients 0..9 (in zig-zag order) take part in smoothing. */\nconst SAVED_COEFS = 10;\n\n/** Natural-order positions of the coefficients that are estimated. */\nconst Q01 = 1;\nconst Q10 = 8;\nconst Q20 = 16;\nconst Q11 = 9;\nconst Q02 = 2;\nconst Q03 = 3;\nconst Q12 = 10;\nconst Q21 = 17;\nconst Q30 = 24;\n\nexport interface SmoothingComponent {\n v: number;\n blocksPerLine: number;\n blocksPerColumn: number;\n blocksPerLineMcu: number;\n coefficients: Int16Array;\n quantTable: Uint16Array;\n /**\n * For each coefficient (zig-zag order), the successive approximation bit\n * position of the last scan that covered it, or -1 if none did. 0 means\n * fully known.\n */\n coefBits: Int8Array;\n /** `coefBits` before the component's last scan. */\n previousCoefBits: Int8Array;\n}\n\n/** Like libjpeg's smoothing_ok(): whether smoothing would change anything. */\nexport function smoothingUseful(components: SmoothingComponent[]) {\n let useful = false;\n\n for (const { quantTable: q, coefBits } of components) {\n if (\n !q[0] ||\n !q[Q01] ||\n !q[Q10] ||\n !q[Q20] ||\n !q[Q11] ||\n !q[Q02] ||\n !q[Q03] ||\n !q[Q12] ||\n !q[Q21] ||\n !q[Q30]\n ) {\n return false;\n }\n\n if (coefBits[0]! < 0) {\n return false;\n }\n\n for (let i = 1; i < SAVED_COEFS; i++) {\n if (coefBits[i] !== 0) {\n useful = true;\n }\n }\n }\n\n return useful;\n}\n\n/** Rounded estimate of a coefficient, limited to what later scans could add. */\nfunction estimate(num: number, quant: number, al: number) {\n let pred = Math.trunc(((quant << 7) + Math.abs(num)) / (quant << 8));\n\n if (al > 0 && pred >= 1 << al) {\n pred = (1 << al) - 1;\n }\n\n return num >= 0 ? pred : -pred;\n}\n\n/**\n * Smooths and inverse transforms a component, writing its samples into\n * `plane`.\n * @param scans the number of scans read\n * @param lastGoodRow the last row of MCUs that had data in the last scan\n * @param mcuRows the number of MCU rows of the frame\n */\nexport function smoothAndTransform(\n idct: IdctContext,\n component: SmoothingComponent,\n plane: SampleArray,\n scans: number,\n lastGoodRow: number,\n mcuRows: number,\n) {\n const {\n v,\n blocksPerLine,\n blocksPerColumn,\n blocksPerLineMcu,\n coefficients,\n quantTable: q,\n } = component;\n const stride = blocksPerLine * 8;\n const workspace = new Int16Array(64);\n const lastColumn = blocksPerLine - 1;\n\n const latch = Int8Array.from(component.coefBits.subarray(0, SAVED_COEFS));\n const previousLatch = new Int8Array(SAVED_COEFS);\n\n for (let i = 1; i < SAVED_COEFS; i++) {\n previousLatch[i] = scans > 1 ? component.previousCoefBits[i]! : -1;\n }\n\n const q00 = q[0]!;\n const q01 = q[Q01]!;\n const q10 = q[Q10]!;\n const q20 = q[Q20]!;\n const q11 = q[Q11]!;\n const q02 = q[Q02]!;\n const q03 = q[Q03]!;\n const q12 = q[Q12]!;\n const q21 = q[Q21]!;\n const q30 = q[Q30]!;\n\n /** DC coefficient of the block at a row and column. */\n const dc = (row: number, col: number) =>\n coefficients[(row * blocksPerLineMcu + col) * 64]!;\n\n for (let mcuRow = 0; mcuRow < mcuRows; mcuRow++) {\n // Block rows in this row of MCUs: all of them except in the last one\n let blockRows = v;\n\n if (mcuRow === mcuRows - 1) {\n blockRows = blocksPerColumn % v || v;\n }\n\n // Rows past the last good one use what was known before the last scan\n const coefBits = mcuRow > lastGoodRow ? previousLatch : latch;\n // Only interpolate DC values when no AC data is available\n let changeDC = true;\n\n for (let i = 1; i < SAVED_COEFS; i++) {\n if (coefBits[i] !== -1) {\n changeDC = false;\n }\n }\n\n // libjpeg's row bookkeeping, which decides where the edges are\n const imageBlockRows = blockRows * mcuRows;\n\n for (let blockRow = 0; blockRow < blockRows; blockRow++) {\n const imageBlockRow = mcuRow * blockRows + blockRow;\n const row = mcuRow * v + blockRow;\n const prev = imageBlockRow > 0 ? row - 1 : row;\n const prevPrev = imageBlockRow > 1 ? row - 2 : prev;\n const next = imageBlockRow < imageBlockRows - 1 ? row + 1 : row;\n const nextNext = imageBlockRow < imageBlockRows - 2 ? row + 2 : next;\n\n // The 5x5 neighbourhood of DC values, as sliding registers\n let dc01, dc02, dc03, dc04, dc05;\n let dc06, dc07, dc08, dc09, dc10;\n let dc11, dc12, dc13, dc14, dc15;\n let dc16, dc17, dc18, dc19, dc20;\n let dc21, dc22, dc23, dc24, dc25;\n\n dc01 = dc02 = dc03 = dc04 = dc05 = dc(prevPrev, 0);\n dc06 = dc07 = dc08 = dc09 = dc10 = dc(prev, 0);\n dc11 = dc12 = dc13 = dc14 = dc15 = dc(row, 0);\n dc16 = dc17 = dc18 = dc19 = dc20 = dc(next, 0);\n dc21 = dc22 = dc23 = dc24 = dc25 = dc(nextNext, 0);\n\n for (let col = 0; col <= lastColumn; col++) {\n const offset = (row * blocksPerLineMcu + col) * 64;\n\n workspace.set(coefficients.subarray(offset, offset + 64));\n\n if (col === 0 && col < lastColumn) {\n dc04 = dc05 = dc(prevPrev, 1);\n dc09 = dc10 = dc(prev, 1);\n dc14 = dc15 = dc(row, 1);\n dc19 = dc20 = dc(next, 1);\n dc24 = dc25 = dc(nextNext, 1);\n }\n\n if (col + 1 < lastColumn) {\n dc05 = dc(prevPrev, col + 2);\n dc10 = dc(prev, col + 2);\n dc15 = dc(row, col + 2);\n dc20 = dc(next, col + 2);\n dc25 = dc(nextNext, col + 2);\n }\n\n let al: number;\n\n // AC01\n if ((al = coefBits[1]!) !== 0 && workspace[1] === 0) {\n const num =\n q00 *\n (changeDC\n ? -dc01 -\n dc02 +\n dc04 +\n dc05 -\n 3 * dc06 +\n 13 * dc07 -\n 13 * dc09 +\n 3 * dc10 -\n 3 * dc11 +\n 38 * dc12 -\n 38 * dc14 +\n 3 * dc15 -\n 3 * dc16 +\n 13 * dc17 -\n 13 * dc19 +\n 3 * dc20 -\n dc21 -\n dc22 +\n dc24 +\n dc25\n : -7 * dc11 + 50 * dc12 - 50 * dc14 + 7 * dc15);\n\n workspace[1] = estimate(num, q01, al);\n }\n\n // AC10\n if ((al = coefBits[2]!) !== 0 && workspace[8] === 0) {\n const num =\n q00 *\n (changeDC\n ? -dc01 -\n 3 * dc02 -\n 3 * dc03 -\n 3 * dc04 -\n dc05 -\n dc06 +\n 13 * dc07 +\n 38 * dc08 +\n 13 * dc09 -\n dc10 +\n dc16 -\n 13 * dc17 -\n 38 * dc18 -\n 13 * dc19 +\n dc20 +\n dc21 +\n 3 * dc22 +\n 3 * dc23 +\n 3 * dc24 +\n dc25\n : -7 * dc03 + 50 * dc08 - 50 * dc18 + 7 * dc23);\n\n workspace[8] = estimate(num, q10, al);\n }\n\n // AC20\n if ((al = coefBits[3]!) !== 0 && workspace[16] === 0) {\n const num =\n q00 *\n (changeDC\n ? dc03 +\n 2 * dc07 +\n 7 * dc08 +\n 2 * dc09 -\n 5 * dc12 -\n 14 * dc13 -\n 5 * dc14 +\n 2 * dc17 +\n 7 * dc18 +\n 2 * dc19 +\n dc23\n : -dc03 + 13 * dc08 - 24 * dc13 + 13 * dc18 - dc23);\n\n workspace[16] = estimate(num, q20, al);\n }\n\n // AC11\n if ((al = coefBits[4]!) !== 0 && workspace[9] === 0) {\n const num =\n q00 *\n (changeDC\n ? -dc01 +\n dc05 +\n 9 * dc07 -\n 9 * dc09 -\n 9 * dc17 +\n 9 * dc19 +\n dc21 -\n dc25\n : dc10 +\n dc16 -\n 10 * dc17 +\n 10 * dc19 -\n dc02 -\n dc20 +\n dc22 -\n dc24 +\n dc04 -\n dc06 +\n 10 * dc07 -\n 10 * dc09);\n\n workspace[9] = estimate(num, q11, al);\n }\n\n // AC02\n if ((al = coefBits[5]!) !== 0 && workspace[2] === 0) {\n const num =\n q00 *\n (changeDC\n ? 2 * dc07 -\n 5 * dc08 +\n 2 * dc09 +\n dc11 +\n 7 * dc12 -\n 14 * dc13 +\n 7 * dc14 +\n dc15 +\n 2 * dc17 -\n 5 * dc18 +\n 2 * dc19\n : -dc11 + 13 * dc12 - 24 * dc13 + 13 * dc14 - dc15);\n\n workspace[2] = estimate(num, q02, al);\n }\n\n if (changeDC) {\n // AC03\n if ((al = coefBits[6]!) !== 0 && workspace[3] === 0) {\n const num = q00 * (dc07 - dc09 + 2 * dc12 - 2 * dc14 + dc17 - dc19);\n\n workspace[3] = estimate(num, q03, al);\n }\n\n // AC12\n if ((al = coefBits[7]!) !== 0 && workspace[10] === 0) {\n const num = q00 * (dc07 - 3 * dc08 + dc09 - dc17 + 3 * dc18 - dc19);\n\n workspace[10] = estimate(num, q12, al);\n }\n\n // AC21\n if ((al = coefBits[8]!) !== 0 && workspace[17] === 0) {\n const num = q00 * (dc07 - dc09 - 3 * dc12 + 3 * dc14 + dc17 - dc19);\n\n workspace[17] = estimate(num, q21, al);\n }\n\n // AC30\n if ((al = coefBits[9]!) !== 0 && workspace[24] === 0) {\n const num = q00 * (dc07 + 2 * dc08 + dc09 - dc17 - 2 * dc18 - dc19);\n\n workspace[24] = estimate(num, q30, al);\n }\n\n // DC\n const num =\n q00 *\n (-2 * dc01 -\n 6 * dc02 -\n 8 * dc03 -\n 6 * dc04 -\n 2 * dc05 -\n 6 * dc06 +\n 6 * dc07 +\n 42 * dc08 +\n 6 * dc09 -\n 6 * dc10 -\n 8 * dc11 +\n 42 * dc12 +\n 152 * dc13 +\n 42 * dc14 -\n 8 * dc15 -\n 6 * dc16 +\n 6 * dc17 +\n 42 * dc18 +\n 6 * dc19 -\n 6 * dc20 -\n 2 * dc21 -\n 6 * dc22 -\n 8 * dc23 -\n 6 * dc24 -\n 2 * dc25);\n\n workspace[0] = estimate(num, q00, 0);\n }\n\n if (row < blocksPerColumn) {\n idctBlock(\n idct,\n workspace,\n 0,\n q,\n plane,\n row * 8 * stride + col * 8,\n stride,\n );\n }\n\n // Advance for the next column\n dc01 = dc02;\n dc02 = dc03;\n dc03 = dc04;\n dc04 = dc05;\n dc06 = dc07;\n dc07 = dc08;\n dc08 = dc09;\n dc09 = dc10;\n dc11 = dc12;\n dc12 = dc13;\n dc13 = dc14;\n dc14 = dc15;\n dc16 = dc17;\n dc17 = dc18;\n dc18 = dc19;\n dc19 = dc20;\n dc21 = dc22;\n dc22 = dc23;\n dc23 = dc24;\n dc24 = dc25;\n }\n }\n }\n}\n"]}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The example Huffman tables of the JPEG standard (ITU T.81 Annex K.3), as
3
+ * counts of codes of each length 1..16 followed by the symbols. Most encoders
4
+ * use them, and Motion JPEG frames leave them out.
5
+ */
6
+ interface StandardTable {
7
+ counts: Uint8Array;
8
+ symbols: Uint8Array;
9
+ }
10
+ export declare const LUMINANCE_DC: StandardTable;
11
+ export declare const CHROMINANCE_DC: StandardTable;
12
+ export declare const LUMINANCE_AC: StandardTable;
13
+ export declare const CHROMINANCE_AC: StandardTable;
14
+ export declare const STANDARD_TABLES: {
15
+ dc: StandardTable[];
16
+ ac: StandardTable[];
17
+ };
18
+ export {};
19
+ //# sourceMappingURL=standard-tables.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard-tables.d.ts","sourceRoot":"","sources":["../../../src/decoder/standard-tables.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,UAAU,aAAa;IACrB,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,UAAU,CAAC;CACrB;AAQD,eAAO,MAAM,YAAY,eAGxB,CAAC;AAEF,eAAO,MAAM,cAAc,eAG1B,CAAC;AAGF,eAAO,MAAM,YAAY,eAkBxB,CAAC;AAGF,eAAO,MAAM,cAAc,eAkB1B,CAAC;AAEF,eAAO,MAAM,eAAe;IAC1B,EAAE;IACF,EAAE;CACH,CAAC"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ /**
3
+ * The example Huffman tables of the JPEG standard (ITU T.81 Annex K.3), as
4
+ * counts of codes of each length 1..16 followed by the symbols. Most encoders
5
+ * use them, and Motion JPEG frames leave them out.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.STANDARD_TABLES = exports.CHROMINANCE_AC = exports.LUMINANCE_AC = exports.CHROMINANCE_DC = exports.LUMINANCE_DC = void 0;
9
+ function table(counts, symbols) {
10
+ return { counts: new Uint8Array(counts), symbols: new Uint8Array(symbols) };
11
+ }
12
+ const DC_SYMBOLS = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
13
+ exports.LUMINANCE_DC = table([0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0], DC_SYMBOLS);
14
+ exports.CHROMINANCE_DC = table([0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0], DC_SYMBOLS);
15
+ // prettier-ignore
16
+ exports.LUMINANCE_AC = table([0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d], [
17
+ 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06,
18
+ 0x13, 0x51, 0x61, 0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
19
+ 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, 0x24, 0x33, 0x62, 0x72,
20
+ 0x82, 0x09, 0x0a, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
21
+ 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45,
22
+ 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
23
+ 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74, 0x75,
24
+ 0x76, 0x77, 0x78, 0x79, 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
25
+ 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3,
26
+ 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
27
+ 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9,
28
+ 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
29
+ 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf1, 0xf2, 0xf3, 0xf4,
30
+ 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa,
31
+ ]);
32
+ // prettier-ignore
33
+ exports.CHROMINANCE_AC = table([0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77], [
34
+ 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41,
35
+ 0x51, 0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
36
+ 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, 0x15, 0x62, 0x72, 0xd1,
37
+ 0x0a, 0x16, 0x24, 0x34, 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
38
+ 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44,
39
+ 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
40
+ 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74,
41
+ 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
42
+ 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a,
43
+ 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
44
+ 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
45
+ 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
46
+ 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf2, 0xf3, 0xf4,
47
+ 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa,
48
+ ]);
49
+ exports.STANDARD_TABLES = {
50
+ dc: [exports.LUMINANCE_DC, exports.CHROMINANCE_DC],
51
+ ac: [exports.LUMINANCE_AC, exports.CHROMINANCE_AC],
52
+ };
53
+ //# sourceMappingURL=standard-tables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard-tables.js","sourceRoot":"","sources":["../../../src/decoder/standard-tables.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAOH,SAAS,KAAK,CAAC,MAAgB,EAAE,OAAiB;IAChD,OAAO,EAAE,MAAM,EAAE,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,IAAI,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;AAC9E,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AAE7C,QAAA,YAAY,GAAG,KAAK,CAC/B,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC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["/**\n * The example Huffman tables of the JPEG standard (ITU T.81 Annex K.3), as\n * counts of codes of each length 1..16 followed by the symbols. Most encoders\n * use them, and Motion JPEG frames leave them out.\n */\n\ninterface StandardTable {\n counts: Uint8Array;\n symbols: Uint8Array;\n}\n\nfunction table(counts: number[], symbols: number[]): StandardTable {\n return { counts: new Uint8Array(counts), symbols: new Uint8Array(symbols) };\n}\n\nconst DC_SYMBOLS = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];\n\nexport const LUMINANCE_DC = table(\n [0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0],\n DC_SYMBOLS,\n);\n\nexport const CHROMINANCE_DC = table(\n [0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0],\n DC_SYMBOLS,\n);\n\n// prettier-ignore\nexport const LUMINANCE_AC = table(\n [0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d],\n [\n 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06,\n 0x13, 0x51, 0x61, 0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,\n 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, 0x24, 0x33, 0x62, 0x72,\n 0x82, 0x09, 0x0a, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,\n 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45,\n 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,\n 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74, 0x75,\n 0x76, 0x77, 0x78, 0x79, 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,\n 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3,\n 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,\n 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9,\n 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,\n 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf1, 0xf2, 0xf3, 0xf4,\n 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa,\n ],\n);\n\n// prettier-ignore\nexport const CHROMINANCE_AC = table(\n [0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77],\n [\n 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41,\n 0x51, 0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,\n 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, 0x15, 0x62, 0x72, 0xd1,\n 0x0a, 0x16, 0x24, 0x34, 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,\n 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44,\n 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,\n 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74,\n 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,\n 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a,\n 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,\n 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,\n 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,\n 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf2, 0xf3, 0xf4,\n 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa,\n ],\n);\n\nexport const STANDARD_TABLES = {\n dc: [LUMINANCE_DC, CHROMINANCE_DC],\n ac: [LUMINANCE_AC, CHROMINANCE_AC],\n};\n"]}
@@ -0,0 +1,57 @@
1
+ import { type JpegData } from "./decode.js";
2
+ import { type ChromaSubsampling } from "./encoder/encoder.js";
3
+ export type { ChromaSubsampling };
4
+ export interface RawImageData<T = JpegData> {
5
+ width: number;
6
+ height: number;
7
+ /**
8
+ * Pixels row by row: RGBA (4 bytes per pixel, alpha is ignored), RGB (3) or
9
+ * greyscale (1). The layout is told apart by the length.
10
+ */
11
+ data: T;
12
+ }
13
+ export interface EncodeJpegOptions {
14
+ /**
15
+ * 1 (smallest, worst) to 100 (largest, best), scaling the quantization
16
+ * tables of the JPEG standard like libjpeg does.
17
+ * @default 75
18
+ */
19
+ quality?: number;
20
+ /**
21
+ * How much to reduce the resolution of the colour (chroma) channels, which
22
+ * the eye is less sensitive to: not at all (4:4:4), by half horizontally
23
+ * (4:2:2) or by half both ways (4:2:0). By default 4:2:0 below quality 90
24
+ * and 4:4:4 from 90, like sharp. Greyscale images have no chroma.
25
+ */
26
+ chromaSubsampling?: ChromaSubsampling;
27
+ /**
28
+ * Build Huffman tables for the image instead of using the example tables
29
+ * of the JPEG standard, like libjpeg's `optimize_coding`. The file is
30
+ * usually 5-15% smaller with the same pixels, but the image is transformed
31
+ * before it's written, which takes more memory.
32
+ * @default true
33
+ */
34
+ optimizeHuffman?: boolean;
35
+ /**
36
+ * Write a progressive JPEG, which browsers show at a low quality first and
37
+ * refine as it downloads, with libjpeg's default scans. It's usually a few
38
+ * percent smaller too, but takes more memory and time to encode and
39
+ * decode. Its Huffman tables are always optimized.
40
+ * @default false
41
+ */
42
+ progressive?: boolean;
43
+ /** Text to write in COM segments, one per string. */
44
+ comments?: string[];
45
+ /**
46
+ * EXIF data to write in an APP1 segment. If it doesn't start with "Exif",
47
+ * "Exif\0" is written first, so the `exifBuffer` of a decoded JPEG can be
48
+ * passed back in.
49
+ */
50
+ exif?: JpegData;
51
+ }
52
+ /**
53
+ * Encodes pixels as a JPEG. Throws a `TypeError` or `RangeError` for input
54
+ * that can't be encoded, instead of writing a broken JPEG.
55
+ */
56
+ export declare function encodeJpeg(image: RawImageData, options?: EncodeJpegOptions): Uint8Array;
57
+ //# sourceMappingURL=encode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/encode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,KAAK,iBAAiB,EAAe,MAAM,sBAAsB,CAAC;AAE3E,YAAY,EAAE,iBAAiB,EAAE,CAAC;AAElC,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,QAAQ;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,IAAI,EAAE,CAAC,CAAC;CACT;AAED,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,qDAAqD;IACrD,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB;;;;OAIG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAC;CACjB;AAkCD;;;GAGG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,YAAY,EACnB,OAAO,GAAE,iBAAsB,GAC9B,UAAU,CA4CZ"}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.encodeJpeg = encodeJpeg;
4
+ const decode_js_1 = require("./decode.js");
5
+ const encoder_js_1 = require("./encoder/encoder.js");
6
+ function channelCount(width, height, length) {
7
+ const pixels = width * height;
8
+ for (const channels of [4, 3, 1]) {
9
+ if (length === pixels * channels) {
10
+ return channels;
11
+ }
12
+ }
13
+ // Like jpeg-js, extra bytes after RGBA pixels are ignored
14
+ if (length > pixels * 4) {
15
+ return 4;
16
+ }
17
+ throw new RangeError(`Expected ${pixels * 4} (RGBA), ${pixels * 3} (RGB) or ${pixels} (greyscale) bytes of pixel data for a ${width}x${height} image, got ${length}`);
18
+ }
19
+ function checkDimension(name, value) {
20
+ if (typeof value !== "number" ||
21
+ !Number.isInteger(value) ||
22
+ value < 1 ||
23
+ value > 65535) {
24
+ throw new RangeError(`The ${name} of a JPEG must be an integer from 1 to 65535, got ${String(value)}`);
25
+ }
26
+ }
27
+ /**
28
+ * Encodes pixels as a JPEG. Throws a `TypeError` or `RangeError` for input
29
+ * that can't be encoded, instead of writing a broken JPEG.
30
+ */
31
+ function encodeJpeg(image, options = {}) {
32
+ if (!image || typeof image !== "object") {
33
+ throw new TypeError("Expected an image with width, height and data");
34
+ }
35
+ const { width, height } = image;
36
+ checkDimension("width", width);
37
+ checkDimension("height", height);
38
+ const data = (0, decode_js_1.toBytes)(image.data, "image data");
39
+ const quality = options.quality ?? 75;
40
+ if (typeof quality !== "number" || Number.isNaN(quality)) {
41
+ throw new TypeError(`Expected the quality to be a number, got ${String(quality)}`);
42
+ }
43
+ // Like jpeg-js, clamp to 1..100
44
+ const clamped = Math.min(Math.max(Math.round(quality), 1), 100);
45
+ const subsampling = options.chromaSubsampling ?? (clamped >= 90 ? "4:4:4" : "4:2:0");
46
+ if (!["4:4:4", "4:2:2", "4:2:0"].includes(subsampling)) {
47
+ throw new RangeError(`Expected chromaSubsampling to be "4:4:4", "4:2:2" or "4:2:0", got ${String(subsampling)}`);
48
+ }
49
+ return (0, encoder_js_1.encodeImage)({ width, height, data, channels: channelCount(width, height, data.length) }, {
50
+ quality: clamped,
51
+ subsampling,
52
+ optimizeHuffman: options.optimizeHuffman ?? true,
53
+ progressive: options.progressive ?? false,
54
+ comments: options.comments,
55
+ exif: options.exif === undefined
56
+ ? undefined
57
+ : (0, decode_js_1.toBytes)(options.exif, "EXIF data"),
58
+ });
59
+ }
60
+ //# sourceMappingURL=encode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode.js","sourceRoot":"","sources":["../../src/encode.ts"],"names":[],"mappings":";;;AAAA,2CAAqD;AACrD,qDAA2E;AAsD3E,SAAS,YAAY,CAAC,KAAa,EAAE,MAAc,EAAE,MAAc;IACjE,MAAM,MAAM,GAAG,KAAK,GAAG,MAAM,CAAC;IAE9B,KAAK,MAAM,QAAQ,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAU,EAAE,CAAC;QAC1C,IAAI,MAAM,KAAK,MAAM,GAAG,QAAQ,EAAE,CAAC;YACjC,OAAO,QAAQ,CAAC;QAClB,CAAC;IACH,CAAC;IAED,0DAA0D;IAC1D,IAAI,MAAM,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,OAAO,CAAC,CAAC;IACX,CAAC;IAED,MAAM,IAAI,UAAU,CAClB,YAAY,MAAM,GAAG,CAAC,YAAY,MAAM,GAAG,CAAC,aAAa,MAAM,0CAA0C,KAAK,IAAI,MAAM,eAAe,MAAM,EAAE,CAChJ,CA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AAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAEnE,IAAI,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;QACvD,MAAM,IAAI,UAAU,CAClB,qEAAqE,MAAM,CAAC,WAAW,CAAC,EAAE,CAC3F,CAAC;IACJ,CAAC;IAED,OAAO,IAAA,wBAAW,EAChB,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,EAC3E;QACE,OAAO,EAAE,OAAO;QAChB,WAAW;QACX,eAAe,EAAE,OAAO,CAAC,eAAe,IAAI,IAAI;QAChD,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,KAAK;QACzC,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,IAAI,EACF,OAAO,CAAC,IAAI,KAAK,SAAS;YACxB,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,IAAA,mBAAO,EAAC,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC;KACzC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { toBytes, type JpegData } from \"./decode.js\";\nimport { type ChromaSubsampling, encodeImage } from \"./encoder/encoder.js\";\n\nexport type { ChromaSubsampling };\n\nexport interface RawImageData<T = JpegData> {\n width: number;\n height: number;\n /**\n * Pixels row by row: RGBA (4 bytes per pixel, alpha is ignored), RGB (3) or\n * greyscale (1). The layout is told apart by the length.\n */\n data: T;\n}\n\nexport interface EncodeJpegOptions {\n /**\n * 1 (smallest, worst) to 100 (largest, best), scaling the quantization\n * tables of the JPEG standard like libjpeg does.\n * @default 75\n */\n quality?: number;\n /**\n * How much to reduce the resolution of the colour (chroma) channels, which\n * the eye is less sensitive to: not at all (4:4:4), by half horizontally\n * (4:2:2) or by half both ways (4:2:0). By default 4:2:0 below quality 90\n * and 4:4:4 from 90, like sharp. Greyscale images have no chroma.\n */\n chromaSubsampling?: ChromaSubsampling;\n /**\n * Build Huffman tables for the image instead of using the example tables\n * of the JPEG standard, like libjpeg's `optimize_coding`. The file is\n * usually 5-15% smaller with the same pixels, but the image is transformed\n * before it's written, which takes more memory.\n * @default true\n */\n optimizeHuffman?: boolean;\n /**\n * Write a progressive JPEG, which browsers show at a low quality first and\n * refine as it downloads, with libjpeg's default scans. It's usually a few\n * percent smaller too, but takes more memory and time to encode and\n * decode. Its Huffman tables are always optimized.\n * @default false\n */\n progressive?: boolean;\n /** Text to write in COM segments, one per string. */\n comments?: string[];\n /**\n * EXIF data to write in an APP1 segment. If it doesn't start with \"Exif\",\n * \"Exif\\0\" is written first, so the `exifBuffer` of a decoded JPEG can be\n * passed back in.\n */\n exif?: JpegData;\n}\n\nfunction channelCount(width: number, height: number, length: number) {\n const pixels = width * height;\n\n for (const channels of [4, 3, 1] as const) {\n if (length === pixels * channels) {\n return channels;\n }\n }\n\n // Like jpeg-js, extra bytes after RGBA pixels are ignored\n if (length > pixels * 4) {\n return 4;\n }\n\n throw new RangeError(\n `Expected ${pixels * 4} (RGBA), ${pixels * 3} (RGB) or ${pixels} (greyscale) bytes of pixel data for a ${width}x${height} image, got ${length}`,\n );\n}\n\nfunction checkDimension(name: string, value: unknown) {\n if (\n typeof value !== \"number\" ||\n !Number.isInteger(value) ||\n value < 1 ||\n value > 65535\n ) {\n throw new RangeError(\n `The ${name} of a JPEG must be an integer from 1 to 65535, got ${String(value)}`,\n );\n }\n}\n\n/**\n * Encodes pixels as a JPEG. Throws a `TypeError` or `RangeError` for input\n * that can't be encoded, instead of writing a broken JPEG.\n */\nexport function encodeJpeg(\n image: RawImageData,\n options: EncodeJpegOptions = {},\n): Uint8Array {\n if (!image || typeof image !== \"object\") {\n throw new TypeError(\"Expected an image with width, height and data\");\n }\n\n const { width, height } = image;\n\n checkDimension(\"width\", width);\n checkDimension(\"height\", height);\n\n const data = toBytes(image.data, \"image data\");\n const quality = options.quality ?? 75;\n\n if (typeof quality !== \"number\" || Number.isNaN(quality)) {\n throw new TypeError(\n `Expected the quality to be a number, got ${String(quality)}`,\n );\n }\n\n // Like jpeg-js, clamp to 1..100\n const clamped = Math.min(Math.max(Math.round(quality), 1), 100);\n const subsampling =\n options.chromaSubsampling ?? (clamped >= 90 ? \"4:4:4\" : \"4:2:0\");\n\n if (![\"4:4:4\", \"4:2:2\", \"4:2:0\"].includes(subsampling)) {\n throw new RangeError(\n `Expected chromaSubsampling to be \"4:4:4\", \"4:2:2\" or \"4:2:0\", got ${String(subsampling)}`,\n );\n }\n\n return encodeImage(\n { width, height, data, channels: channelCount(width, height, data.length) },\n {\n quality: clamped,\n subsampling,\n optimizeHuffman: options.optimizeHuffman ?? true,\n progressive: options.progressive ?? false,\n comments: options.comments,\n exif:\n options.exif === undefined\n ? undefined\n : toBytes(options.exif, \"EXIF data\"),\n },\n );\n}\n"]}