ag-psd 20.0.0 → 20.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## v20.1.0
4
+ - Improve performance of encoding and decoding large text fields.
5
+ - Added initial support for 32bit image data.
6
+ - Fixed handling compressed encoding mode by switching to better compression library.
7
+
3
8
  ## v20.0.0
4
9
  - Added support for reading 16bit image data, when reading PSD width default settings 16bit data will be converted to regular 8bit canvases, when `useImageData: true` is passed in read options the image data will be of type `Uint16Array` for 16bit images. Because of that type of `layer.imageData` and `psd.imageData` and `layer.mask.imageData` can be of different types depending on PSD file bitDepth.
5
10
  - Added support for reading image data compressed with zip with prediction mode.
package/README_PSD.md CHANGED
@@ -107,9 +107,21 @@ const psd: Psd = {
107
107
 
108
108
  ## Bitmaps and image data
109
109
 
110
- Image data can be accessed from `psd.canvas` or `layer.canvas` fields by default. These fields store regular HTMLCanvasElement (or node-canvas object when running in node.js). If `useImageData` option is set to true in read options then the image data will be available in `psd.imageData` and `layer.imageData` fields instead. Using image data option gives you direct access to pixel data without having to go through the canvas object, which bypasses alpha premultiplication and convertion from 16/32bit image data to 8bit canvas data.
110
+ Image data can be accessed from `psd.canvas` or `layer.canvas` fields by default. These fields store regular HTMLCanvasElement (or node-canvas object when running in node.js). For 16bit and 32 bit documents image data will be converted to regular 8bit canvas (this will result in a loss of data, use `useImageData` option if you want to preserve precission of color data).
111
111
 
112
- For 16/32bit documents `imageData` fields will contain pixel data as `Uint16Array` or `Uint32Array` respectfully.
112
+ If `useImageData` option is set to true in read options then the image data will be available in `psd.imageData` and `layer.imageData` fields instead. Using image data option gives you direct access to pixel data without having to go through the canvas object, which bypasses alpha premultiplication and convertion from 16/32bit image data to 8bit canvas data.
113
+
114
+ For 16bit documents `imageData` fields will contain pixel data as `Uint16Array`, the values ranging from 0 to 65535.
115
+
116
+ For 32bit documents `imageData` fields will contain pixel data as `Float32Array`, the values ranging from 0 to 1. 32bit values are in linear color space (as oposed to gamma corrected sRGB color). In order to convert the values to regular sRGB color space the values need to be gamma-corrected by using following conversion code (except alpha channel):
117
+
118
+ ```js
119
+ // convert 32bit linear to 8bit sRGB
120
+ destination[i] = Math.round(Math.pow(source[i], 1.0 / 2.2) * 255);
121
+
122
+ // convert 8bit sRGB to 32bit linear
123
+ destination[i] = Math.pow(source[i] / 255, 2.2);
124
+ ```
113
125
 
114
126
  ## Layers and Groups
115
127
 
@@ -241,7 +253,7 @@ Example layer structure:
241
253
 
242
254
  [](/files/blend-modes.png)
243
255
 
244
- - `canvas` (or `imageData`) see `canvas` property description in [Basic document structure](#basic-socument-structure)
256
+ - `canvas` (or `imageData`) see `canvas` property description in [Basic document structure](#basic-document-structure)
245
257
 
246
258
  Vector, text and smart object layers still have image data with pregenerated bitmap. You also need to provide that image data when writing PSD files.
247
259
 
@@ -726,7 +738,7 @@ if ('l' in color) {
726
738
  }
727
739
  ```
728
740
 
729
- If you expect the fields to be in one specific format you can just verity that it's correct and throw an error if it's a format that you didn't expect:
741
+ If you expect the fields to be in one specific format you can just verify that it's correct and throw an error if it's a format that you didn't expect:
730
742
 
731
743
  ```ts
732
744
  // handle only RGB colors
package/TODO CHANGED
@@ -1,5 +1,7 @@
1
+ writing 1, 16, 32 bit documents
1
2
  'pths'
2
3
  - cleanup errors from tests (make list of drawings that should ignore those errors)
4
+ - writing zip/zip with prediction
3
5
 
4
6
 
5
7
  - can we remove sectionDivider property ?
@@ -1904,6 +1904,10 @@ addHandler('Lr16', function () { return false; }, function (reader, _target, _le
1904
1904
  (0, psdReader_1.readLayerInfo)(reader, psd, options);
1905
1905
  }, function (_writer, _target) {
1906
1906
  });
1907
+ addHandler('Lr32', function () { return false; }, function (reader, _target, _left, psd, options) {
1908
+ (0, psdReader_1.readLayerInfo)(reader, psd, options);
1909
+ }, function (_writer, _target) {
1910
+ });
1907
1911
  addHandler('LMsk', hasKey('userMask'), function (reader, target) {
1908
1912
  target.userMask = {
1909
1913
  colorSpace: (0, psdReader_1.readColor)(reader),
@@ -2928,9 +2932,11 @@ addHandler('Txt2', hasKey('engineData'), function (reader, target, left) {
2928
2932
  var data = (0, psdReader_1.readBytes)(reader, left());
2929
2933
  target.engineData = (0, base64_js_1.fromByteArray)(data);
2930
2934
  // const engineData = parseEngineData(data);
2935
+ // const engineData2 = decodeEngineData2(engineData);
2931
2936
  // console.log(require('util').inspect(engineData, false, 99, true));
2932
- // require('fs').writeFileSync('resources/engineData2Simple.txt', require('util').inspect(engineData, false, 99, false), 'utf8');
2933
- // require('fs').writeFileSync('test_data.json', JSON.stringify(ed, null, 2), 'utf8');
2937
+ // require('fs').writeFileSync('test_data.bin', data);
2938
+ // require('fs').writeFileSync('test_data.txt', require('util').inspect(engineData, false, 99, false), 'utf8');
2939
+ // require('fs').writeFileSync('test_data.json', JSON.stringify(engineData2, null, 2), 'utf8');
2934
2940
  }, function (writer, target) {
2935
2941
  var buffer = (0, base64_js_1.toByteArray)(target.engineData);
2936
2942
  (0, psdWriter_1.writeBytes)(writer, buffer);