ag-psd 20.0.0 → 20.1.1

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.
package/dist/bundle.js CHANGED
@@ -2205,6 +2205,10 @@ addHandler('Lr16', function () { return false; }, function (reader, _target, _le
2205
2205
  (0, psdReader_1.readLayerInfo)(reader, psd, options);
2206
2206
  }, function (_writer, _target) {
2207
2207
  });
2208
+ addHandler('Lr32', function () { return false; }, function (reader, _target, _left, psd, options) {
2209
+ (0, psdReader_1.readLayerInfo)(reader, psd, options);
2210
+ }, function (_writer, _target) {
2211
+ });
2208
2212
  addHandler('LMsk', hasKey('userMask'), function (reader, target) {
2209
2213
  target.userMask = {
2210
2214
  colorSpace: (0, psdReader_1.readColor)(reader),
@@ -3229,9 +3233,11 @@ addHandler('Txt2', hasKey('engineData'), function (reader, target, left) {
3229
3233
  var data = (0, psdReader_1.readBytes)(reader, left());
3230
3234
  target.engineData = (0, base64_js_1.fromByteArray)(data);
3231
3235
  // const engineData = parseEngineData(data);
3236
+ // const engineData2 = decodeEngineData2(engineData);
3232
3237
  // console.log(require('util').inspect(engineData, false, 99, true));
3233
- // require('fs').writeFileSync('resources/engineData2Simple.txt', require('util').inspect(engineData, false, 99, false), 'utf8');
3234
- // require('fs').writeFileSync('test_data.json', JSON.stringify(ed, null, 2), 'utf8');
3238
+ // require('fs').writeFileSync('test_data.bin', data);
3239
+ // require('fs').writeFileSync('test_data.txt', require('util').inspect(engineData, false, 99, false), 'utf8');
3240
+ // require('fs').writeFileSync('test_data.json', JSON.stringify(engineData2, null, 2), 'utf8');
3235
3241
  }, function (writer, target) {
3236
3242
  var buffer = (0, base64_js_1.toByteArray)(target.engineData);
3237
3243
  (0, psdWriter_1.writeBytes)(writer, buffer);
@@ -6292,7 +6298,7 @@ function hasAlpha(data) {
6292
6298
  exports.hasAlpha = hasAlpha;
6293
6299
  function resetImageData(_a) {
6294
6300
  var data = _a.data;
6295
- var alpha = (data instanceof Uint32Array) ? (0xffffffff >>> 0) : ((data instanceof Uint16Array) ? 0xffff : 0xff);
6301
+ var alpha = (data instanceof Float32Array) ? 1.0 : ((data instanceof Uint16Array) ? 0xffff : 0xff);
6296
6302
  for (var p = 0, size = data.length | 0; p < size; p = (p + 4) | 0) {
6297
6303
  data[p + 0] = 0;
6298
6304
  data[p + 1] = 0;
@@ -6311,9 +6317,19 @@ function imageDataToCanvas(pixelData) {
6311
6317
  imageData = (0, exports.createImageData)(pixelData.width, pixelData.height);
6312
6318
  var src = pixelData.data;
6313
6319
  var dst = imageData.data;
6314
- var shift = (src instanceof Uint32Array) ? 24 : ((src instanceof Uint16Array) ? 8 : 0);
6315
- for (var i = 0, size = src.length; i < size; i++) {
6316
- dst[i] = src[i] >>> shift;
6320
+ if (src instanceof Float32Array) {
6321
+ for (var i = 0, size = src.length; i < size; i += 4) {
6322
+ dst[i + 0] = Math.round(Math.pow(src[i + 0], 1.0 / 2.2) * 255);
6323
+ dst[i + 1] = Math.round(Math.pow(src[i + 1], 1.0 / 2.2) * 255);
6324
+ dst[i + 2] = Math.round(Math.pow(src[i + 2], 1.0 / 2.2) * 255);
6325
+ dst[i + 3] = Math.round(src[i + 3] * 255);
6326
+ }
6327
+ }
6328
+ else {
6329
+ var shift = (src instanceof Uint16Array) ? 8 : 0;
6330
+ for (var i = 0, size = src.length; i < size; i++) {
6331
+ dst[i] = src[i] >>> shift;
6332
+ }
6317
6333
  }
6318
6334
  }
6319
6335
  canvas.getContext('2d').putImageData(imageData, 0, 0);
@@ -6321,7 +6337,7 @@ function imageDataToCanvas(pixelData) {
6321
6337
  }
6322
6338
  exports.imageDataToCanvas = imageDataToCanvas;
6323
6339
  function decodeBitmap(input, output, width, height) {
6324
- if (input instanceof Uint32Array || input instanceof Uint16Array)
6340
+ if (!(input instanceof Uint8Array || input instanceof Uint8ClampedArray))
6325
6341
  throw new Error('Invalid bit depth');
6326
6342
  for (var y = 0, p = 0, o = 0; y < height; y++) {
6327
6343
  for (var x = 0; x < width;) {
@@ -6577,7 +6593,11 @@ addHandler(1061, function (target) { return target.captionDigest !== undefined;
6577
6593
  (0, psdWriter_1.writeUint8)(writer, byteAt(target.captionDigest, i * 2));
6578
6594
  }
6579
6595
  });
6580
- addHandler(1060, function (target) { return target.xmpMetadata !== undefined; }, function (reader, target, left) { return target.xmpMetadata = readUtf8String(reader, left()); }, function (writer, target) { return writeUtf8String(writer, target.xmpMetadata); });
6596
+ addHandler(1060, function (target) { return target.xmpMetadata !== undefined; }, function (reader, target, left) {
6597
+ target.xmpMetadata = readUtf8String(reader, left());
6598
+ }, function (writer, target) {
6599
+ writeUtf8String(writer, target.xmpMetadata);
6600
+ });
6581
6601
  var Inte = (0, helpers_1.createEnum)('Inte', 'perceptual', {
6582
6602
  'perceptual': 'Img ',
6583
6603
  'saturation': 'Grp ',
@@ -7859,8 +7879,15 @@ function readPsd(reader, readOptions) {
7859
7879
  var fixOffsets = [0, 1, -1, 2, -2, 3, -3, 4, -4];
7860
7880
  // color mode data
7861
7881
  readSection(reader, 1, function (left) {
7862
- if (options.throwForMissingFeatures)
7863
- throw new Error('Color mode data not supported');
7882
+ if (!left())
7883
+ return;
7884
+ // const numbers: number[] = [];
7885
+ // console.log('color mode', left());
7886
+ // while (left()) {
7887
+ // numbers.push(readUint32(reader));
7888
+ // }
7889
+ // console.log('color mode', numbers);
7890
+ // if (options.throwForMissingFeatures) throw new Error('Color mode data not supported');
7864
7891
  skipBytes(reader, left());
7865
7892
  });
7866
7893
  // image resources
@@ -8262,7 +8289,7 @@ function createImageDataBitDepth(width, height, bitDepth) {
8262
8289
  return { width: width, height: height, data: new Uint16Array(width * height * 4) };
8263
8290
  }
8264
8291
  else if (bitDepth === 32) {
8265
- return { width: width, height: height, data: new Uint32Array(width * height * 4) };
8292
+ return { width: width, height: height, data: new Float32Array(width * height * 4) };
8266
8293
  }
8267
8294
  else {
8268
8295
  throw new Error("Invalid bitDepth (".concat(bitDepth, ")"));
@@ -8280,13 +8307,15 @@ function readImageData(reader, psd, options) {
8280
8307
  (0, helpers_1.resetImageData)(imageData);
8281
8308
  switch (psd.colorMode) {
8282
8309
  case 0 /* ColorMode.Bitmap */: {
8310
+ if (bitsPerChannel !== 1)
8311
+ throw new Error('Invalid bitsPerChannel for bitmap color mode');
8283
8312
  var bytes = void 0;
8284
8313
  if (compression === 0 /* Compression.RawData */) {
8285
8314
  bytes = readBytes(reader, Math.ceil(psd.width / 8) * psd.height);
8286
8315
  }
8287
8316
  else if (compression === 1 /* Compression.RleCompressed */) {
8288
8317
  bytes = new Uint8Array(psd.width * psd.height);
8289
- readDataRLE(reader, { data: bytes, width: psd.width, height: psd.height }, psd.width, psd.height, bitsPerChannel, 1, [0], options.large);
8318
+ readDataRLE(reader, { data: bytes, width: psd.width, height: psd.height }, psd.width, psd.height, 8, 1, [0], options.large);
8290
8319
  }
8291
8320
  else {
8292
8321
  throw new Error("Bitmap compression not supported: ".concat(compression));
@@ -8424,12 +8453,12 @@ function bytesToArray(bytes, bitDepth) {
8424
8453
  }
8425
8454
  else if (bitDepth === 32) {
8426
8455
  if (bytes.byteOffset % 4) {
8427
- var result = new Uint32Array(bytes.byteLength / 4);
8456
+ var result = new Float32Array(bytes.byteLength / 4);
8428
8457
  new Uint8Array(result.buffer, result.byteOffset, result.byteLength).set(bytes);
8429
8458
  return result;
8430
8459
  }
8431
8460
  else {
8432
- return new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4);
8461
+ return new Float32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4);
8433
8462
  }
8434
8463
  }
8435
8464
  else {
@@ -8446,6 +8475,18 @@ function copyChannelToPixelData(pixelData, channel, offset, step) {
8446
8475
  }
8447
8476
  function readDataRaw(reader, pixelData, width, height, bitDepth, step, offset) {
8448
8477
  var buffer = readBytes(reader, width * height * Math.floor(bitDepth / 8));
8478
+ if (bitDepth == 32) {
8479
+ for (var i = 0; i < buffer.byteLength; i += 4) {
8480
+ var a = buffer[i + 0];
8481
+ var b = buffer[i + 1];
8482
+ var c = buffer[i + 2];
8483
+ var d = buffer[i + 3];
8484
+ buffer[i + 0] = d;
8485
+ buffer[i + 1] = c;
8486
+ buffer[i + 2] = b;
8487
+ buffer[i + 3] = a;
8488
+ }
8489
+ }
8449
8490
  var array = bytesToArray(buffer, bitDepth);
8450
8491
  if (pixelData && offset < step) {
8451
8492
  copyChannelToPixelData(pixelData, array, offset, step);
@@ -8476,8 +8517,18 @@ function readDataZip(reader, length, pixelData, width, height, bitDepth, step, o
8476
8517
  }
8477
8518
  else if (bitDepth === 32) {
8478
8519
  if (prediction)
8479
- decodePredicted(decompressed, width, height, 0x100);
8480
- copyChannelToPixelData(pixelData, array, offset, step);
8520
+ decodePredicted(decompressed, width * 4, height, 0x100);
8521
+ var di = offset;
8522
+ var dst = new Uint32Array(pixelData.data.buffer, pixelData.data.byteOffset, pixelData.data.length);
8523
+ for (var y = 0; y < height; y++) {
8524
+ var a = width * 4 * y;
8525
+ for (var x = 0; x < width; x++, a++, di += step) {
8526
+ var b = a + width;
8527
+ var c = b + width;
8528
+ var d = c + width;
8529
+ dst[di] = ((decompressed[a] << 24) | (decompressed[b] << 16) | (decompressed[c] << 8) | decompressed[d]) >>> 0;
8530
+ }
8531
+ }
8481
8532
  }
8482
8533
  else {
8483
8534
  throw new Error('Invalid bitDepth');
@@ -10138,6 +10189,9 @@ function encodeStringTo(buffer, offset, value) {
10138
10189
  }
10139
10190
  exports.encodeStringTo = encodeStringTo;
10140
10191
  function encodeString(value) {
10192
+ if (value.length > 1000 && typeof TextEncoder !== 'undefined') {
10193
+ return (new TextEncoder()).encode(value);
10194
+ }
10141
10195
  var buffer = new Uint8Array(stringLengthInBytes(value));
10142
10196
  encodeStringTo(buffer, 0, value);
10143
10197
  return buffer;
@@ -10156,7 +10210,10 @@ function continuationByte(buffer, index) {
10156
10210
  }
10157
10211
  }
10158
10212
  function decodeString(value) {
10159
- var result = '';
10213
+ if (value.byteLength > 1000 && typeof TextDecoder !== 'undefined') {
10214
+ return (new TextDecoder()).decode(value);
10215
+ }
10216
+ var result = [];
10160
10217
  for (var i = 0; i < value.length;) {
10161
10218
  var byte1 = value[i++];
10162
10219
  var code = void 0;
@@ -10195,12 +10252,12 @@ function decodeString(value) {
10195
10252
  }
10196
10253
  if (code > 0xffff) {
10197
10254
  code -= 0x10000;
10198
- result += String.fromCharCode(code >>> 10 & 0x3ff | 0xd800);
10255
+ result.push(String.fromCharCode(code >>> 10 & 0x3ff | 0xd800));
10199
10256
  code = 0xdc00 | code & 0x3ff;
10200
10257
  }
10201
- result += String.fromCharCode(code);
10258
+ result.push(String.fromCharCode(code));
10202
10259
  }
10203
- return result;
10260
+ return result.join('');
10204
10261
  }
10205
10262
  exports.decodeString = decodeString;
10206
10263
 
@@ -0,0 +1 @@
1
+ export declare function decodeEngineData2(data: any): any;
@@ -0,0 +1,349 @@
1
+ "use strict";
2
+ /// Engine data 2 experiments
3
+ // /test/engineData2.json:1109 is character codes
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.decodeEngineData2 = void 0;
6
+ var keysColor = {
7
+ '0': {
8
+ uproot: true,
9
+ children: {
10
+ '0': { name: 'Type' },
11
+ '1': { name: 'Values' },
12
+ },
13
+ },
14
+ };
15
+ var keysStyleSheet = {
16
+ '0': { name: 'Font' },
17
+ '1': { name: 'FontSize' },
18
+ '2': { name: 'FauxBold' },
19
+ '3': { name: 'FauxItalic' },
20
+ '4': { name: 'AutoLeading' },
21
+ '5': { name: 'Leading' },
22
+ '6': { name: 'HorizontalScale' },
23
+ '7': { name: 'VerticalScale' },
24
+ '8': { name: 'Tracking' },
25
+ '9': { name: 'BaselineShift' },
26
+ // '10': ???
27
+ '11': { name: 'Kerning?' },
28
+ '12': { name: 'FontCaps' },
29
+ '13': { name: 'FontBaseline' },
30
+ '15': { name: 'Strikethrough?' },
31
+ '16': { name: 'Underline?' },
32
+ '18': { name: 'Ligatures' },
33
+ '19': { name: 'DLigatures' },
34
+ // '20': ???
35
+ // '21': ???
36
+ // '22': ???
37
+ '23': { name: 'Fractions' },
38
+ '24': { name: 'Ordinals' },
39
+ // '25': ???
40
+ // '26': ???
41
+ // '27': ???
42
+ '28': { name: 'StylisticAlternates' },
43
+ // '29': ???
44
+ '30': { name: 'OldStyle?' },
45
+ '35': { name: 'BaselineDirection' },
46
+ '38': { name: 'Language' },
47
+ '52': { name: 'NoBreak' },
48
+ '53': { name: 'FillColor', children: keysColor },
49
+ '54': { name: 'StrokeColor?', children: keysColor },
50
+ '55': { children: { '99': { uproot: true } } },
51
+ // '68': ???
52
+ // '70': ???
53
+ // '71': ???
54
+ // '72': ???
55
+ // '73': ???
56
+ '79': { children: keysColor },
57
+ // '85': ???
58
+ // '87': ???
59
+ // '88': ???
60
+ };
61
+ var keysParagraph = {
62
+ '0': { name: 'Justification' },
63
+ '1': { name: 'FirstLineIndent' },
64
+ '2': { name: 'StartIndent' },
65
+ '3': { name: 'EndIndent' },
66
+ '4': { name: 'SpaceBefore' },
67
+ '5': { name: 'SpaceAfter' },
68
+ '7': { name: 'AutoLeading' },
69
+ '9': { name: 'AutoHyphenate' },
70
+ '10': { name: 'HyphenatedWordSize' },
71
+ '11': { name: 'PreHyphen' },
72
+ '12': { name: 'PostHyphen' },
73
+ '13': { name: 'ConsecutiveHyphens?' },
74
+ '14': { name: 'Zone' },
75
+ '15': { name: 'HypenateCapitalizedWords' },
76
+ '17': { name: 'WordSpacing' },
77
+ '18': { name: 'LetterSpacing' },
78
+ '19': { name: 'GlyphSpacing' },
79
+ '32': { name: 'StyleSheet', children: keysStyleSheet },
80
+ };
81
+ var keysStyleSheetData = {
82
+ name: 'StyleSheetData',
83
+ children: keysStyleSheet,
84
+ };
85
+ var keysRoot = {
86
+ '0': {
87
+ name: 'ResourceDict',
88
+ children: {
89
+ '1': {
90
+ name: 'FontSet',
91
+ children: {
92
+ '0': {
93
+ uproot: true,
94
+ children: {
95
+ '0': {
96
+ uproot: true,
97
+ children: {
98
+ '0': {
99
+ uproot: true,
100
+ children: {
101
+ '0': { name: 'Name' },
102
+ '2': { name: 'FontType' },
103
+ },
104
+ },
105
+ },
106
+ }
107
+ },
108
+ },
109
+ },
110
+ },
111
+ '2': {
112
+ name: '2',
113
+ children: {},
114
+ },
115
+ '3': {
116
+ name: 'MojiKumiSet',
117
+ children: {
118
+ '0': {
119
+ uproot: true,
120
+ children: {
121
+ '0': {
122
+ uproot: true,
123
+ children: {
124
+ '0': { name: 'InternalName' },
125
+ },
126
+ },
127
+ },
128
+ },
129
+ },
130
+ },
131
+ '4': {
132
+ name: 'KinsokuSet',
133
+ children: {
134
+ '0': {
135
+ uproot: true,
136
+ children: {
137
+ '0': {
138
+ uproot: true,
139
+ children: {
140
+ '0': { name: 'Name' },
141
+ '5': {
142
+ uproot: true,
143
+ children: {
144
+ '0': { name: 'NoStart' },
145
+ '1': { name: 'NoEnd' },
146
+ '2': { name: 'Keep' },
147
+ '3': { name: 'Hanging' },
148
+ '4': { name: 'Name' },
149
+ },
150
+ },
151
+ },
152
+ },
153
+ },
154
+ },
155
+ },
156
+ },
157
+ '5': {
158
+ name: 'StyleSheetSet',
159
+ children: {
160
+ '0': {
161
+ uproot: true,
162
+ children: {
163
+ '0': {
164
+ uproot: true,
165
+ children: {
166
+ '0': { name: 'Name' },
167
+ '6': keysStyleSheetData,
168
+ },
169
+ },
170
+ },
171
+ },
172
+ },
173
+ },
174
+ '6': {
175
+ name: 'ParagraphSheetSet',
176
+ children: {
177
+ '0': {
178
+ uproot: true,
179
+ children: {
180
+ '0': {
181
+ uproot: true,
182
+ children: {
183
+ '0': { name: 'Name' },
184
+ '5': {
185
+ name: 'Properties',
186
+ children: keysParagraph,
187
+ },
188
+ '6': { name: 'DefaultStyleSheet' },
189
+ },
190
+ },
191
+ },
192
+ },
193
+ },
194
+ },
195
+ '8': {
196
+ name: '8',
197
+ children: {},
198
+ },
199
+ '9': {
200
+ name: 'Predefined',
201
+ children: {
202
+ '0': {
203
+ children: { '0': { uproot: true } },
204
+ },
205
+ '1': {
206
+ children: { '0': { uproot: true } },
207
+ },
208
+ },
209
+ },
210
+ },
211
+ },
212
+ '1': {
213
+ name: 'EngineDict',
214
+ children: {
215
+ '0': {
216
+ name: '0',
217
+ children: {
218
+ // 0: ???
219
+ // 1: ???
220
+ // 2: ???
221
+ '3': { name: 'SuperscriptSize' },
222
+ '4': { name: 'SuperscriptPosition' },
223
+ '5': { name: 'SubscriptSize' },
224
+ '6': { name: 'SubscriptPosition' },
225
+ '7': { name: 'SmallCapSize' },
226
+ '8': { name: 'UseFractionalGlyphWidths' },
227
+ '15': { children: { '0': { uproot: true } } },
228
+ // 16: ???
229
+ // 17: ???
230
+ },
231
+ },
232
+ '1': {
233
+ name: 'Editors?',
234
+ children: {
235
+ '0': {
236
+ name: 'Editor',
237
+ children: {
238
+ '0': { name: 'Text' },
239
+ '5': {
240
+ name: 'ParagraphRun',
241
+ children: {
242
+ '0': {
243
+ name: 'RunArray',
244
+ children: {
245
+ '0': {
246
+ name: 'ParagraphSheet',
247
+ children: {
248
+ '0': {
249
+ uproot: true,
250
+ children: {
251
+ '0': { name: '0' },
252
+ '5': {
253
+ name: '5',
254
+ children: keysParagraph,
255
+ },
256
+ '6': { name: '6' },
257
+ },
258
+ },
259
+ },
260
+ },
261
+ '1': { name: 'RunLength' },
262
+ },
263
+ },
264
+ },
265
+ },
266
+ '6': {
267
+ name: 'StyleRun',
268
+ children: {
269
+ '0': {
270
+ name: 'RunArray',
271
+ children: {
272
+ '0': {
273
+ name: 'StyleSheet',
274
+ children: {
275
+ '0': {
276
+ uproot: true,
277
+ children: {
278
+ '6': keysStyleSheetData,
279
+ },
280
+ },
281
+ },
282
+ },
283
+ '1': { name: 'RunLength' },
284
+ },
285
+ },
286
+ },
287
+ },
288
+ },
289
+ },
290
+ '1': {
291
+ name: 'FontVectorData ???',
292
+ // children: {
293
+ // '0': {},
294
+ // '2': {
295
+ // // '5'
296
+ // // '6'
297
+ // },
298
+ // }
299
+ },
300
+ },
301
+ },
302
+ '2': {
303
+ name: 'StyleSheet',
304
+ children: keysStyleSheet,
305
+ },
306
+ '3': {
307
+ name: 'ParagraphSheet',
308
+ children: keysParagraph,
309
+ },
310
+ },
311
+ },
312
+ };
313
+ function decodeObj(obj, keys) {
314
+ var _a, _b;
315
+ if (obj === null)
316
+ return obj;
317
+ if (Array.isArray(obj))
318
+ return obj.map(function (x) { return decodeObj(x, keys); });
319
+ if (typeof obj !== 'object')
320
+ return obj;
321
+ var result = {};
322
+ for (var _i = 0, _c = Object.keys(obj); _i < _c.length; _i++) {
323
+ var key = _c[_i];
324
+ if (keys[key]) {
325
+ if (keys[key].uproot) {
326
+ if (key !== '99')
327
+ result = decodeObj(obj[key], (_a = keys[key].children) !== null && _a !== void 0 ? _a : {});
328
+ if (obj['99'])
329
+ result._type = obj['99'];
330
+ break;
331
+ }
332
+ else {
333
+ result[keys[key].name || key] = decodeObj(obj[key], (_b = keys[key].children) !== null && _b !== void 0 ? _b : {});
334
+ }
335
+ }
336
+ else if (key === '99') {
337
+ result._type = obj[key];
338
+ }
339
+ else {
340
+ result[key] = decodeObj(obj[key], {});
341
+ }
342
+ }
343
+ return result;
344
+ }
345
+ function decodeEngineData2(data) {
346
+ return decodeObj(data, keysRoot);
347
+ }
348
+ exports.decodeEngineData2 = decodeEngineData2;
349
+ //# sourceMappingURL=engineData2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engineData2.js","sourceRoot":"../src/","sources":["engineData2.ts"],"names":[],"mappings":";AAAA,6BAA6B;AAC7B,iDAAiD;;;AAUjD,IAAM,SAAS,GAAa;IAC3B,GAAG,EAAE;QACJ,MAAM,EAAE,IAAI;QACZ,QAAQ,EAAE;YACT,GAAG,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;YACrB,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;SACvB;KACD;CACD,CAAC;AAEF,IAAM,cAAc,GAAa;IAChC,GAAG,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;IACrB,GAAG,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FD,8CAEC"}
package/dist/helpers.js CHANGED
@@ -135,7 +135,7 @@ function hasAlpha(data) {
135
135
  exports.hasAlpha = hasAlpha;
136
136
  function resetImageData(_a) {
137
137
  var data = _a.data;
138
- var alpha = (data instanceof Uint32Array) ? (0xffffffff >>> 0) : ((data instanceof Uint16Array) ? 0xffff : 0xff);
138
+ var alpha = (data instanceof Float32Array) ? 1.0 : ((data instanceof Uint16Array) ? 0xffff : 0xff);
139
139
  for (var p = 0, size = data.length | 0; p < size; p = (p + 4) | 0) {
140
140
  data[p + 0] = 0;
141
141
  data[p + 1] = 0;
@@ -154,9 +154,19 @@ function imageDataToCanvas(pixelData) {
154
154
  imageData = (0, exports.createImageData)(pixelData.width, pixelData.height);
155
155
  var src = pixelData.data;
156
156
  var dst = imageData.data;
157
- var shift = (src instanceof Uint32Array) ? 24 : ((src instanceof Uint16Array) ? 8 : 0);
158
- for (var i = 0, size = src.length; i < size; i++) {
159
- dst[i] = src[i] >>> shift;
157
+ if (src instanceof Float32Array) {
158
+ for (var i = 0, size = src.length; i < size; i += 4) {
159
+ dst[i + 0] = Math.round(Math.pow(src[i + 0], 1.0 / 2.2) * 255);
160
+ dst[i + 1] = Math.round(Math.pow(src[i + 1], 1.0 / 2.2) * 255);
161
+ dst[i + 2] = Math.round(Math.pow(src[i + 2], 1.0 / 2.2) * 255);
162
+ dst[i + 3] = Math.round(src[i + 3] * 255);
163
+ }
164
+ }
165
+ else {
166
+ var shift = (src instanceof Uint16Array) ? 8 : 0;
167
+ for (var i = 0, size = src.length; i < size; i++) {
168
+ dst[i] = src[i] >>> shift;
169
+ }
160
170
  }
161
171
  }
162
172
  canvas.getContext('2d').putImageData(imageData, 0, 0);
@@ -164,7 +174,7 @@ function imageDataToCanvas(pixelData) {
164
174
  }
165
175
  exports.imageDataToCanvas = imageDataToCanvas;
166
176
  function decodeBitmap(input, output, width, height) {
167
- if (input instanceof Uint32Array || input instanceof Uint16Array)
177
+ if (!(input instanceof Uint8Array || input instanceof Uint8ClampedArray))
168
178
  throw new Error('Invalid bit depth');
169
179
  for (var y = 0, p = 0, o = 0; y < height; y++) {
170
180
  for (var x = 0; x < width;) {