@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,345 @@
1
+ /*
2
+ * Block smoothing of progressive JPEGs whose low-frequency AC coefficients
3
+ * aren't fully known, e.g. because the file was cut off after a few scans.
4
+ * Estimates the missing coefficients from the DC values of the neighbouring
5
+ * blocks, so the image looks smooth instead of blocky.
6
+ *
7
+ * Based on jdcoefct.c (smoothing_ok and decompress_smooth_data) of the
8
+ * Independent JPEG Group's software, as found in libjpeg-turbo
9
+ * (https://github.com/libjpeg-turbo/libjpeg-turbo):
10
+ *
11
+ * Copyright (C) 1994-1997, Thomas G. Lane.
12
+ * libjpeg-turbo Modifications:
13
+ * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
14
+ * Copyright (C) 2010, 2015-2016, 2019-2020, 2022-2024, D. R. Commander.
15
+ * Copyright (C) 2015, 2020, Google, Inc.
16
+ * For conditions of distribution and use, see README.ijg.
17
+ *
18
+ * Modified by Jimp contributors (2026): translated from C to TypeScript for
19
+ * a whole image at once, instead of one iMCU row at a time.
20
+ */
21
+ import { idctBlock } from "./idct.js";
22
+ /** Coefficients 0..9 (in zig-zag order) take part in smoothing. */
23
+ const SAVED_COEFS = 10;
24
+ /** Natural-order positions of the coefficients that are estimated. */
25
+ const Q01 = 1;
26
+ const Q10 = 8;
27
+ const Q20 = 16;
28
+ const Q11 = 9;
29
+ const Q02 = 2;
30
+ const Q03 = 3;
31
+ const Q12 = 10;
32
+ const Q21 = 17;
33
+ const Q30 = 24;
34
+ /** Like libjpeg's smoothing_ok(): whether smoothing would change anything. */
35
+ export function smoothingUseful(components) {
36
+ let useful = false;
37
+ for (const { quantTable: q, coefBits } of components) {
38
+ if (!q[0] ||
39
+ !q[Q01] ||
40
+ !q[Q10] ||
41
+ !q[Q20] ||
42
+ !q[Q11] ||
43
+ !q[Q02] ||
44
+ !q[Q03] ||
45
+ !q[Q12] ||
46
+ !q[Q21] ||
47
+ !q[Q30]) {
48
+ return false;
49
+ }
50
+ if (coefBits[0] < 0) {
51
+ return false;
52
+ }
53
+ for (let i = 1; i < SAVED_COEFS; i++) {
54
+ if (coefBits[i] !== 0) {
55
+ useful = true;
56
+ }
57
+ }
58
+ }
59
+ return useful;
60
+ }
61
+ /** Rounded estimate of a coefficient, limited to what later scans could add. */
62
+ function estimate(num, quant, al) {
63
+ let pred = Math.trunc(((quant << 7) + Math.abs(num)) / (quant << 8));
64
+ if (al > 0 && pred >= 1 << al) {
65
+ pred = (1 << al) - 1;
66
+ }
67
+ return num >= 0 ? pred : -pred;
68
+ }
69
+ /**
70
+ * Smooths and inverse transforms a component, writing its samples into
71
+ * `plane`.
72
+ * @param scans the number of scans read
73
+ * @param lastGoodRow the last row of MCUs that had data in the last scan
74
+ * @param mcuRows the number of MCU rows of the frame
75
+ */
76
+ export function smoothAndTransform(idct, component, plane, scans, lastGoodRow, mcuRows) {
77
+ const { v, blocksPerLine, blocksPerColumn, blocksPerLineMcu, coefficients, quantTable: q, } = component;
78
+ const stride = blocksPerLine * 8;
79
+ const workspace = new Int16Array(64);
80
+ const lastColumn = blocksPerLine - 1;
81
+ const latch = Int8Array.from(component.coefBits.subarray(0, SAVED_COEFS));
82
+ const previousLatch = new Int8Array(SAVED_COEFS);
83
+ for (let i = 1; i < SAVED_COEFS; i++) {
84
+ previousLatch[i] = scans > 1 ? component.previousCoefBits[i] : -1;
85
+ }
86
+ const q00 = q[0];
87
+ const q01 = q[Q01];
88
+ const q10 = q[Q10];
89
+ const q20 = q[Q20];
90
+ const q11 = q[Q11];
91
+ const q02 = q[Q02];
92
+ const q03 = q[Q03];
93
+ const q12 = q[Q12];
94
+ const q21 = q[Q21];
95
+ const q30 = q[Q30];
96
+ /** DC coefficient of the block at a row and column. */
97
+ const dc = (row, col) => coefficients[(row * blocksPerLineMcu + col) * 64];
98
+ for (let mcuRow = 0; mcuRow < mcuRows; mcuRow++) {
99
+ // Block rows in this row of MCUs: all of them except in the last one
100
+ let blockRows = v;
101
+ if (mcuRow === mcuRows - 1) {
102
+ blockRows = blocksPerColumn % v || v;
103
+ }
104
+ // Rows past the last good one use what was known before the last scan
105
+ const coefBits = mcuRow > lastGoodRow ? previousLatch : latch;
106
+ // Only interpolate DC values when no AC data is available
107
+ let changeDC = true;
108
+ for (let i = 1; i < SAVED_COEFS; i++) {
109
+ if (coefBits[i] !== -1) {
110
+ changeDC = false;
111
+ }
112
+ }
113
+ // libjpeg's row bookkeeping, which decides where the edges are
114
+ const imageBlockRows = blockRows * mcuRows;
115
+ for (let blockRow = 0; blockRow < blockRows; blockRow++) {
116
+ const imageBlockRow = mcuRow * blockRows + blockRow;
117
+ const row = mcuRow * v + blockRow;
118
+ const prev = imageBlockRow > 0 ? row - 1 : row;
119
+ const prevPrev = imageBlockRow > 1 ? row - 2 : prev;
120
+ const next = imageBlockRow < imageBlockRows - 1 ? row + 1 : row;
121
+ const nextNext = imageBlockRow < imageBlockRows - 2 ? row + 2 : next;
122
+ // The 5x5 neighbourhood of DC values, as sliding registers
123
+ let dc01, dc02, dc03, dc04, dc05;
124
+ let dc06, dc07, dc08, dc09, dc10;
125
+ let dc11, dc12, dc13, dc14, dc15;
126
+ let dc16, dc17, dc18, dc19, dc20;
127
+ let dc21, dc22, dc23, dc24, dc25;
128
+ dc01 = dc02 = dc03 = dc04 = dc05 = dc(prevPrev, 0);
129
+ dc06 = dc07 = dc08 = dc09 = dc10 = dc(prev, 0);
130
+ dc11 = dc12 = dc13 = dc14 = dc15 = dc(row, 0);
131
+ dc16 = dc17 = dc18 = dc19 = dc20 = dc(next, 0);
132
+ dc21 = dc22 = dc23 = dc24 = dc25 = dc(nextNext, 0);
133
+ for (let col = 0; col <= lastColumn; col++) {
134
+ const offset = (row * blocksPerLineMcu + col) * 64;
135
+ workspace.set(coefficients.subarray(offset, offset + 64));
136
+ if (col === 0 && col < lastColumn) {
137
+ dc04 = dc05 = dc(prevPrev, 1);
138
+ dc09 = dc10 = dc(prev, 1);
139
+ dc14 = dc15 = dc(row, 1);
140
+ dc19 = dc20 = dc(next, 1);
141
+ dc24 = dc25 = dc(nextNext, 1);
142
+ }
143
+ if (col + 1 < lastColumn) {
144
+ dc05 = dc(prevPrev, col + 2);
145
+ dc10 = dc(prev, col + 2);
146
+ dc15 = dc(row, col + 2);
147
+ dc20 = dc(next, col + 2);
148
+ dc25 = dc(nextNext, col + 2);
149
+ }
150
+ let al;
151
+ // AC01
152
+ if ((al = coefBits[1]) !== 0 && workspace[1] === 0) {
153
+ const num = q00 *
154
+ (changeDC
155
+ ? -dc01 -
156
+ dc02 +
157
+ dc04 +
158
+ dc05 -
159
+ 3 * dc06 +
160
+ 13 * dc07 -
161
+ 13 * dc09 +
162
+ 3 * dc10 -
163
+ 3 * dc11 +
164
+ 38 * dc12 -
165
+ 38 * dc14 +
166
+ 3 * dc15 -
167
+ 3 * dc16 +
168
+ 13 * dc17 -
169
+ 13 * dc19 +
170
+ 3 * dc20 -
171
+ dc21 -
172
+ dc22 +
173
+ dc24 +
174
+ dc25
175
+ : -7 * dc11 + 50 * dc12 - 50 * dc14 + 7 * dc15);
176
+ workspace[1] = estimate(num, q01, al);
177
+ }
178
+ // AC10
179
+ if ((al = coefBits[2]) !== 0 && workspace[8] === 0) {
180
+ const num = q00 *
181
+ (changeDC
182
+ ? -dc01 -
183
+ 3 * dc02 -
184
+ 3 * dc03 -
185
+ 3 * dc04 -
186
+ dc05 -
187
+ dc06 +
188
+ 13 * dc07 +
189
+ 38 * dc08 +
190
+ 13 * dc09 -
191
+ dc10 +
192
+ dc16 -
193
+ 13 * dc17 -
194
+ 38 * dc18 -
195
+ 13 * dc19 +
196
+ dc20 +
197
+ dc21 +
198
+ 3 * dc22 +
199
+ 3 * dc23 +
200
+ 3 * dc24 +
201
+ dc25
202
+ : -7 * dc03 + 50 * dc08 - 50 * dc18 + 7 * dc23);
203
+ workspace[8] = estimate(num, q10, al);
204
+ }
205
+ // AC20
206
+ if ((al = coefBits[3]) !== 0 && workspace[16] === 0) {
207
+ const num = q00 *
208
+ (changeDC
209
+ ? dc03 +
210
+ 2 * dc07 +
211
+ 7 * dc08 +
212
+ 2 * dc09 -
213
+ 5 * dc12 -
214
+ 14 * dc13 -
215
+ 5 * dc14 +
216
+ 2 * dc17 +
217
+ 7 * dc18 +
218
+ 2 * dc19 +
219
+ dc23
220
+ : -dc03 + 13 * dc08 - 24 * dc13 + 13 * dc18 - dc23);
221
+ workspace[16] = estimate(num, q20, al);
222
+ }
223
+ // AC11
224
+ if ((al = coefBits[4]) !== 0 && workspace[9] === 0) {
225
+ const num = q00 *
226
+ (changeDC
227
+ ? -dc01 +
228
+ dc05 +
229
+ 9 * dc07 -
230
+ 9 * dc09 -
231
+ 9 * dc17 +
232
+ 9 * dc19 +
233
+ dc21 -
234
+ dc25
235
+ : dc10 +
236
+ dc16 -
237
+ 10 * dc17 +
238
+ 10 * dc19 -
239
+ dc02 -
240
+ dc20 +
241
+ dc22 -
242
+ dc24 +
243
+ dc04 -
244
+ dc06 +
245
+ 10 * dc07 -
246
+ 10 * dc09);
247
+ workspace[9] = estimate(num, q11, al);
248
+ }
249
+ // AC02
250
+ if ((al = coefBits[5]) !== 0 && workspace[2] === 0) {
251
+ const num = q00 *
252
+ (changeDC
253
+ ? 2 * dc07 -
254
+ 5 * dc08 +
255
+ 2 * dc09 +
256
+ dc11 +
257
+ 7 * dc12 -
258
+ 14 * dc13 +
259
+ 7 * dc14 +
260
+ dc15 +
261
+ 2 * dc17 -
262
+ 5 * dc18 +
263
+ 2 * dc19
264
+ : -dc11 + 13 * dc12 - 24 * dc13 + 13 * dc14 - dc15);
265
+ workspace[2] = estimate(num, q02, al);
266
+ }
267
+ if (changeDC) {
268
+ // AC03
269
+ if ((al = coefBits[6]) !== 0 && workspace[3] === 0) {
270
+ const num = q00 * (dc07 - dc09 + 2 * dc12 - 2 * dc14 + dc17 - dc19);
271
+ workspace[3] = estimate(num, q03, al);
272
+ }
273
+ // AC12
274
+ if ((al = coefBits[7]) !== 0 && workspace[10] === 0) {
275
+ const num = q00 * (dc07 - 3 * dc08 + dc09 - dc17 + 3 * dc18 - dc19);
276
+ workspace[10] = estimate(num, q12, al);
277
+ }
278
+ // AC21
279
+ if ((al = coefBits[8]) !== 0 && workspace[17] === 0) {
280
+ const num = q00 * (dc07 - dc09 - 3 * dc12 + 3 * dc14 + dc17 - dc19);
281
+ workspace[17] = estimate(num, q21, al);
282
+ }
283
+ // AC30
284
+ if ((al = coefBits[9]) !== 0 && workspace[24] === 0) {
285
+ const num = q00 * (dc07 + 2 * dc08 + dc09 - dc17 - 2 * dc18 - dc19);
286
+ workspace[24] = estimate(num, q30, al);
287
+ }
288
+ // DC
289
+ const num = q00 *
290
+ (-2 * dc01 -
291
+ 6 * dc02 -
292
+ 8 * dc03 -
293
+ 6 * dc04 -
294
+ 2 * dc05 -
295
+ 6 * dc06 +
296
+ 6 * dc07 +
297
+ 42 * dc08 +
298
+ 6 * dc09 -
299
+ 6 * dc10 -
300
+ 8 * dc11 +
301
+ 42 * dc12 +
302
+ 152 * dc13 +
303
+ 42 * dc14 -
304
+ 8 * dc15 -
305
+ 6 * dc16 +
306
+ 6 * dc17 +
307
+ 42 * dc18 +
308
+ 6 * dc19 -
309
+ 6 * dc20 -
310
+ 2 * dc21 -
311
+ 6 * dc22 -
312
+ 8 * dc23 -
313
+ 6 * dc24 -
314
+ 2 * dc25);
315
+ workspace[0] = estimate(num, q00, 0);
316
+ }
317
+ if (row < blocksPerColumn) {
318
+ idctBlock(idct, workspace, 0, q, plane, row * 8 * stride + col * 8, stride);
319
+ }
320
+ // Advance for the next column
321
+ dc01 = dc02;
322
+ dc02 = dc03;
323
+ dc03 = dc04;
324
+ dc04 = dc05;
325
+ dc06 = dc07;
326
+ dc07 = dc08;
327
+ dc08 = dc09;
328
+ dc09 = dc10;
329
+ dc11 = dc12;
330
+ dc12 = dc13;
331
+ dc13 = dc14;
332
+ dc14 = dc15;
333
+ dc16 = dc17;
334
+ dc17 = dc18;
335
+ dc18 = dc19;
336
+ dc19 = dc20;
337
+ dc21 = dc22;
338
+ dc22 = dc23;
339
+ dc23 = dc24;
340
+ dc24 = dc25;
341
+ }
342
+ }
343
+ }
344
+ }
345
+ //# sourceMappingURL=smoothing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smoothing.js","sourceRoot":"","sources":["../../../src/decoder/smoothing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,SAAS,EAAsC,MAAM,WAAW,CAAC;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,MAAM,UAAU,eAAe,CAAC,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;YACP,CAAC,CAAC,CAAC,GAAG,CAAC;YACP,CAAC,CAAC,CAAC,GAAG,CAAC;YACP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AAC;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,50 @@
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
+ function table(counts, symbols) {
7
+ return { counts: new Uint8Array(counts), symbols: new Uint8Array(symbols) };
8
+ }
9
+ const DC_SYMBOLS = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
10
+ export const LUMINANCE_DC = table([0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0], DC_SYMBOLS);
11
+ export const CHROMINANCE_DC = table([0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0], DC_SYMBOLS);
12
+ // prettier-ignore
13
+ export const LUMINANCE_AC = table([0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d], [
14
+ 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06,
15
+ 0x13, 0x51, 0x61, 0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
16
+ 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, 0x24, 0x33, 0x62, 0x72,
17
+ 0x82, 0x09, 0x0a, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
18
+ 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45,
19
+ 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
20
+ 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74, 0x75,
21
+ 0x76, 0x77, 0x78, 0x79, 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
22
+ 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3,
23
+ 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
24
+ 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9,
25
+ 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
26
+ 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf1, 0xf2, 0xf3, 0xf4,
27
+ 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa,
28
+ ]);
29
+ // prettier-ignore
30
+ export const CHROMINANCE_AC = table([0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77], [
31
+ 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41,
32
+ 0x51, 0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
33
+ 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, 0x15, 0x62, 0x72, 0xd1,
34
+ 0x0a, 0x16, 0x24, 0x34, 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
35
+ 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44,
36
+ 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
37
+ 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74,
38
+ 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
39
+ 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a,
40
+ 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
41
+ 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
42
+ 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
43
+ 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf2, 0xf3, 0xf4,
44
+ 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa,
45
+ ]);
46
+ export const STANDARD_TABLES = {
47
+ dc: [LUMINANCE_DC, CHROMINANCE_DC],
48
+ ac: [LUMINANCE_AC, CHROMINANCE_AC],
49
+ };
50
+ //# 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;AAE1D,MAAM,CAAC,MAAM,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,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAChD,UAAU,CACX,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,CACjC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,E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AE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;IACtE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;IACtE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;IACtE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;IACtE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;IACtE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;IACtE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;CACnC,CACF,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,EAAE,EAAE,CAAC,YAAY,EAAE,cAAc,CAAC;IAClC,EAAE,EAAE,CAAC,YAAY,EAAE,cAAc,CAAC;CACnC,CAAC","sourcesContent":["/**\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,57 @@
1
+ import { toBytes } from "./decode.js";
2
+ import { encodeImage } from "./encoder/encoder.js";
3
+ function channelCount(width, height, length) {
4
+ const pixels = width * height;
5
+ for (const channels of [4, 3, 1]) {
6
+ if (length === pixels * channels) {
7
+ return channels;
8
+ }
9
+ }
10
+ // Like jpeg-js, extra bytes after RGBA pixels are ignored
11
+ if (length > pixels * 4) {
12
+ return 4;
13
+ }
14
+ 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}`);
15
+ }
16
+ function checkDimension(name, value) {
17
+ if (typeof value !== "number" ||
18
+ !Number.isInteger(value) ||
19
+ value < 1 ||
20
+ value > 65535) {
21
+ throw new RangeError(`The ${name} of a JPEG must be an integer from 1 to 65535, got ${String(value)}`);
22
+ }
23
+ }
24
+ /**
25
+ * Encodes pixels as a JPEG. Throws a `TypeError` or `RangeError` for input
26
+ * that can't be encoded, instead of writing a broken JPEG.
27
+ */
28
+ export function encodeJpeg(image, options = {}) {
29
+ if (!image || typeof image !== "object") {
30
+ throw new TypeError("Expected an image with width, height and data");
31
+ }
32
+ const { width, height } = image;
33
+ checkDimension("width", width);
34
+ checkDimension("height", height);
35
+ const data = toBytes(image.data, "image data");
36
+ const quality = options.quality ?? 75;
37
+ if (typeof quality !== "number" || Number.isNaN(quality)) {
38
+ throw new TypeError(`Expected the quality to be a number, got ${String(quality)}`);
39
+ }
40
+ // Like jpeg-js, clamp to 1..100
41
+ const clamped = Math.min(Math.max(Math.round(quality), 1), 100);
42
+ const subsampling = options.chromaSubsampling ?? (clamped >= 90 ? "4:4:4" : "4:2:0");
43
+ if (!["4:4:4", "4:2:2", "4:2:0"].includes(subsampling)) {
44
+ throw new RangeError(`Expected chromaSubsampling to be "4:4:4", "4:2:2" or "4:2:0", got ${String(subsampling)}`);
45
+ }
46
+ return encodeImage({ width, height, data, channels: channelCount(width, height, data.length) }, {
47
+ quality: clamped,
48
+ subsampling,
49
+ optimizeHuffman: options.optimizeHuffman ?? true,
50
+ progressive: options.progressive ?? false,
51
+ comments: options.comments,
52
+ exif: options.exif === undefined
53
+ ? undefined
54
+ : toBytes(options.exif, "EXIF data"),
55
+ });
56
+ }
57
+ //# sourceMappingURL=encode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode.js","sourceRoot":"","sources":["../../src/encode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAiB,MAAM,aAAa,CAAC;AACrD,OAAO,EAA0B,WAAW,EAAE,MAAM,sBAAsB,CAAC;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,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CAAC,IAAY,EAAE,KAAc;IAClD,IACE,OAAO,KAAK,KAAK,QAAQ;QACzB,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC;QACxB,KAAK,GAAG,CAAC;QACT,KAAK,GAAG,KAAK,EACb,CAAC;QACD,MAAM,IAAI,UAAU,CAClB,OAAO,I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C,EAAE,CAC3F,CAAC;IACJ,CAAC;IAED,OAAO,WAAW,CAChB,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,OAAO,CAAC,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"]}