ag-psd 30.2.0 → 31.0.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 (252) hide show
  1. package/.v8-cache/v24.13.1-x64-cf738c9d/01e5e61b +0 -0
  2. package/.v8-cache/v24.13.1-x64-cf738c9d/05135617 +0 -0
  3. package/.v8-cache/v24.13.1-x64-cf738c9d/06423db9 +0 -0
  4. package/.v8-cache/v24.13.1-x64-cf738c9d/06e765df +0 -0
  5. package/.v8-cache/v24.13.1-x64-cf738c9d/0930679d +0 -0
  6. package/.v8-cache/v24.13.1-x64-cf738c9d/09519a62 +0 -0
  7. package/.v8-cache/v24.13.1-x64-cf738c9d/0a6607b0 +0 -0
  8. package/.v8-cache/v24.13.1-x64-cf738c9d/0ad8fa6e +0 -0
  9. package/.v8-cache/v24.13.1-x64-cf738c9d/0d390e10 +0 -0
  10. package/.v8-cache/v24.13.1-x64-cf738c9d/0dfa7b16 +0 -0
  11. package/.v8-cache/v24.13.1-x64-cf738c9d/0e9e09db +0 -0
  12. package/.v8-cache/v24.13.1-x64-cf738c9d/1130885f +0 -0
  13. package/.v8-cache/v24.13.1-x64-cf738c9d/1222cb8c +0 -0
  14. package/.v8-cache/v24.13.1-x64-cf738c9d/15e2c039 +0 -0
  15. package/.v8-cache/v24.13.1-x64-cf738c9d/1a2d469d +0 -0
  16. package/.v8-cache/v24.13.1-x64-cf738c9d/1b300c82 +0 -0
  17. package/.v8-cache/v24.13.1-x64-cf738c9d/1bc3d370 +0 -0
  18. package/.v8-cache/v24.13.1-x64-cf738c9d/1e44e5af +0 -0
  19. package/.v8-cache/v24.13.1-x64-cf738c9d/1efa10a1 +0 -0
  20. package/.v8-cache/v24.13.1-x64-cf738c9d/1f6c8743 +0 -0
  21. package/.v8-cache/v24.13.1-x64-cf738c9d/20b27e40 +0 -0
  22. package/.v8-cache/v24.13.1-x64-cf738c9d/257c62ba +0 -0
  23. package/.v8-cache/v24.13.1-x64-cf738c9d/25d60154 +0 -0
  24. package/.v8-cache/v24.13.1-x64-cf738c9d/26f822f3 +0 -0
  25. package/.v8-cache/v24.13.1-x64-cf738c9d/2a1e2a8d +0 -0
  26. package/.v8-cache/v24.13.1-x64-cf738c9d/2b02fded +0 -0
  27. package/.v8-cache/v24.13.1-x64-cf738c9d/2c76dc0d +0 -0
  28. package/.v8-cache/v24.13.1-x64-cf738c9d/2deb286a +0 -0
  29. package/.v8-cache/v24.13.1-x64-cf738c9d/32018e44 +0 -0
  30. package/.v8-cache/v24.13.1-x64-cf738c9d/341402c3 +0 -0
  31. package/.v8-cache/v24.13.1-x64-cf738c9d/34e0fa2e +0 -0
  32. package/.v8-cache/v24.13.1-x64-cf738c9d/3bbf643e +0 -0
  33. package/.v8-cache/v24.13.1-x64-cf738c9d/3ceff89e +0 -0
  34. package/.v8-cache/v24.13.1-x64-cf738c9d/404f5cdc +0 -0
  35. package/.v8-cache/v24.13.1-x64-cf738c9d/4087aa2b +0 -0
  36. package/.v8-cache/v24.13.1-x64-cf738c9d/4376c1f9 +0 -0
  37. package/.v8-cache/v24.13.1-x64-cf738c9d/44903df4 +0 -0
  38. package/.v8-cache/v24.13.1-x64-cf738c9d/44d58dc8 +0 -0
  39. package/.v8-cache/v24.13.1-x64-cf738c9d/4511bacf +0 -0
  40. package/.v8-cache/v24.13.1-x64-cf738c9d/47da0ce8 +0 -0
  41. package/.v8-cache/v24.13.1-x64-cf738c9d/48cd54a9 +0 -0
  42. package/.v8-cache/v24.13.1-x64-cf738c9d/4d938476 +0 -0
  43. package/.v8-cache/v24.13.1-x64-cf738c9d/4ec6d390 +0 -0
  44. package/.v8-cache/v24.13.1-x64-cf738c9d/4f5702bd +0 -0
  45. package/.v8-cache/v24.13.1-x64-cf738c9d/514cc428 +0 -0
  46. package/.v8-cache/v24.13.1-x64-cf738c9d/557d3b42 +0 -0
  47. package/.v8-cache/v24.13.1-x64-cf738c9d/56abbff7 +0 -0
  48. package/.v8-cache/v24.13.1-x64-cf738c9d/57b540ee +0 -0
  49. package/.v8-cache/v24.13.1-x64-cf738c9d/5e20c081 +0 -0
  50. package/.v8-cache/v24.13.1-x64-cf738c9d/651c4ada +0 -0
  51. package/.v8-cache/v24.13.1-x64-cf738c9d/652a0d59 +0 -0
  52. package/.v8-cache/v24.13.1-x64-cf738c9d/6a0e89ee +0 -0
  53. package/.v8-cache/v24.13.1-x64-cf738c9d/6af33b91 +0 -0
  54. package/.v8-cache/v24.13.1-x64-cf738c9d/6c2562d2 +0 -0
  55. package/.v8-cache/v24.13.1-x64-cf738c9d/6dae0cfa +0 -0
  56. package/.v8-cache/v24.13.1-x64-cf738c9d/6e2529ce +0 -0
  57. package/.v8-cache/v24.13.1-x64-cf738c9d/71df9cb3 +0 -0
  58. package/.v8-cache/v24.13.1-x64-cf738c9d/72e1d543 +0 -0
  59. package/.v8-cache/v24.13.1-x64-cf738c9d/75519c80 +0 -0
  60. package/.v8-cache/v24.13.1-x64-cf738c9d/79bf115c +0 -0
  61. package/.v8-cache/v24.13.1-x64-cf738c9d/7a39347c +0 -0
  62. package/.v8-cache/v24.13.1-x64-cf738c9d/7b83e3d3 +0 -0
  63. package/.v8-cache/v24.13.1-x64-cf738c9d/7cd71bc5 +0 -0
  64. package/.v8-cache/v24.13.1-x64-cf738c9d/7da78512 +0 -0
  65. package/.v8-cache/v24.13.1-x64-cf738c9d/7ea06cea +0 -0
  66. package/.v8-cache/v24.13.1-x64-cf738c9d/82c3b573 +0 -0
  67. package/.v8-cache/v24.13.1-x64-cf738c9d/84c186e4 +0 -0
  68. package/.v8-cache/v24.13.1-x64-cf738c9d/8607bd36 +0 -0
  69. package/.v8-cache/v24.13.1-x64-cf738c9d/87372817 +0 -0
  70. package/.v8-cache/v24.13.1-x64-cf738c9d/87cf2209 +0 -0
  71. package/.v8-cache/v24.13.1-x64-cf738c9d/882aaa05 +0 -0
  72. package/.v8-cache/v24.13.1-x64-cf738c9d/8a4d3de8 +0 -0
  73. package/.v8-cache/v24.13.1-x64-cf738c9d/8e223473 +0 -0
  74. package/.v8-cache/v24.13.1-x64-cf738c9d/92b7aefd +0 -0
  75. package/.v8-cache/v24.13.1-x64-cf738c9d/932f0770 +0 -0
  76. package/.v8-cache/v24.13.1-x64-cf738c9d/937c03a1 +0 -0
  77. package/.v8-cache/v24.13.1-x64-cf738c9d/991e4758 +0 -0
  78. package/.v8-cache/v24.13.1-x64-cf738c9d/9af658fb +0 -0
  79. package/.v8-cache/v24.13.1-x64-cf738c9d/9ed80ba5 +0 -0
  80. package/.v8-cache/v24.13.1-x64-cf738c9d/9f0dc993 +0 -0
  81. package/.v8-cache/v24.13.1-x64-cf738c9d/a19c0c4f +0 -0
  82. package/.v8-cache/v24.13.1-x64-cf738c9d/a6409d95 +0 -0
  83. package/.v8-cache/v24.13.1-x64-cf738c9d/a7e80865 +0 -0
  84. package/.v8-cache/v24.13.1-x64-cf738c9d/ac9802c6 +0 -0
  85. package/.v8-cache/v24.13.1-x64-cf738c9d/acc36e66 +0 -0
  86. package/.v8-cache/v24.13.1-x64-cf738c9d/ad11e2dc +0 -0
  87. package/.v8-cache/v24.13.1-x64-cf738c9d/b0c8fcd8 +0 -0
  88. package/.v8-cache/v24.13.1-x64-cf738c9d/b1762958 +0 -0
  89. package/.v8-cache/v24.13.1-x64-cf738c9d/b3c2fab7 +0 -0
  90. package/.v8-cache/v24.13.1-x64-cf738c9d/b5b3329b +0 -0
  91. package/.v8-cache/v24.13.1-x64-cf738c9d/b806679e +0 -0
  92. package/.v8-cache/v24.13.1-x64-cf738c9d/bc1cdd48 +0 -0
  93. package/.v8-cache/v24.13.1-x64-cf738c9d/bc7ebd1d +0 -0
  94. package/.v8-cache/v24.13.1-x64-cf738c9d/c0b789d2 +0 -0
  95. package/.v8-cache/v24.13.1-x64-cf738c9d/c314aece +0 -0
  96. package/.v8-cache/v24.13.1-x64-cf738c9d/c399a5dc +0 -0
  97. package/.v8-cache/v24.13.1-x64-cf738c9d/c681cbc8 +0 -0
  98. package/.v8-cache/v24.13.1-x64-cf738c9d/c6834ffc +0 -0
  99. package/.v8-cache/v24.13.1-x64-cf738c9d/c6f12ed5 +0 -0
  100. package/.v8-cache/v24.13.1-x64-cf738c9d/cb0f0a3d +0 -0
  101. package/.v8-cache/v24.13.1-x64-cf738c9d/cbcb7c95 +0 -0
  102. package/.v8-cache/v24.13.1-x64-cf738c9d/cdd9107c +0 -0
  103. package/.v8-cache/v24.13.1-x64-cf738c9d/cdf2c4a3 +0 -0
  104. package/.v8-cache/v24.13.1-x64-cf738c9d/cfc49f4f +0 -0
  105. package/.v8-cache/v24.13.1-x64-cf738c9d/cff9434a +0 -0
  106. package/.v8-cache/v24.13.1-x64-cf738c9d/d02dd6f7 +0 -0
  107. package/.v8-cache/v24.13.1-x64-cf738c9d/d0507bf3 +0 -0
  108. package/.v8-cache/v24.13.1-x64-cf738c9d/d60fce19 +0 -0
  109. package/.v8-cache/v24.13.1-x64-cf738c9d/d733d619 +0 -0
  110. package/.v8-cache/v24.13.1-x64-cf738c9d/d75b7803 +0 -0
  111. package/.v8-cache/v24.13.1-x64-cf738c9d/dc86f000 +0 -0
  112. package/.v8-cache/v24.13.1-x64-cf738c9d/defa4f7f +0 -0
  113. package/.v8-cache/v24.13.1-x64-cf738c9d/e03e2acd +0 -0
  114. package/.v8-cache/v24.13.1-x64-cf738c9d/e0e3f52c +0 -0
  115. package/.v8-cache/v24.13.1-x64-cf738c9d/e158d332 +0 -0
  116. package/.v8-cache/v24.13.1-x64-cf738c9d/e6735171 +0 -0
  117. package/.v8-cache/v24.13.1-x64-cf738c9d/e6745c2b +0 -0
  118. package/.v8-cache/v24.13.1-x64-cf738c9d/e6b99945 +0 -0
  119. package/.v8-cache/v24.13.1-x64-cf738c9d/e6d8ceb8 +0 -0
  120. package/.v8-cache/v24.13.1-x64-cf738c9d/e7ffec37 +0 -0
  121. package/.v8-cache/v24.13.1-x64-cf738c9d/ea33b6de +0 -0
  122. package/.v8-cache/v24.13.1-x64-cf738c9d/eaafa3c4 +0 -0
  123. package/.v8-cache/v24.13.1-x64-cf738c9d/ebb50fca +0 -0
  124. package/.v8-cache/v24.13.1-x64-cf738c9d/ec805f2e +0 -0
  125. package/.v8-cache/v24.13.1-x64-cf738c9d/edaef8f1 +0 -0
  126. package/.v8-cache/v24.13.1-x64-cf738c9d/ee4401c8 +0 -0
  127. package/.v8-cache/v24.13.1-x64-cf738c9d/eeeebdfe +0 -0
  128. package/.v8-cache/v24.13.1-x64-cf738c9d/f3d51676 +0 -0
  129. package/.v8-cache/v24.13.1-x64-cf738c9d/f7b50a75 +0 -0
  130. package/.v8-cache/v24.13.1-x64-cf738c9d/fa58ca72 +0 -0
  131. package/.v8-cache/v24.13.1-x64-cf738c9d/fc97d72d +0 -0
  132. package/.v8-cache/v24.13.1-x64-cf738c9d/fd0a2987 +0 -0
  133. package/CHANGELOG.md +6 -0
  134. package/README.md +64 -0
  135. package/TODO.md +2 -0
  136. package/dist/abr.d.ts +196 -196
  137. package/dist/abr.js +364 -365
  138. package/dist/abr.js.map +1 -1
  139. package/dist/additionalInfo.d.ts +26 -26
  140. package/dist/additionalInfo.js +3478 -3478
  141. package/dist/additionalInfo.js.map +1 -1
  142. package/dist/ase.d.ts +32 -32
  143. package/dist/ase.js +81 -82
  144. package/dist/ase.js.map +1 -1
  145. package/dist/bundle.js +12380 -12259
  146. package/dist/csh.d.ts +10 -10
  147. package/dist/csh.js +35 -36
  148. package/dist/csh.js.map +1 -1
  149. package/dist/descriptor.d.ts +601 -601
  150. package/dist/descriptor.js +2003 -2003
  151. package/dist/descriptor.js.map +1 -1
  152. package/dist/effectsHelpers.d.ts +5 -5
  153. package/dist/effectsHelpers.js +286 -287
  154. package/dist/effectsHelpers.js.map +1 -1
  155. package/dist/engineData.d.ts +2 -2
  156. package/dist/engineData.js +334 -335
  157. package/dist/engineData.js.map +1 -1
  158. package/dist/engineData2.d.ts +2 -2
  159. package/dist/engineData2.js +409 -410
  160. package/dist/engineData2.js.map +1 -1
  161. package/dist/helpers.d.ts +74 -74
  162. package/dist/helpers.js +353 -342
  163. package/dist/helpers.js.map +1 -1
  164. package/dist/imageResources.d.ts +17 -17
  165. package/dist/imageResources.js +1040 -1040
  166. package/dist/imageResources.js.map +1 -1
  167. package/dist/index.d.ts +20 -22
  168. package/dist/index.js +61 -56
  169. package/dist/index.js.map +1 -1
  170. package/dist/initializeCanvas.d.ts +1 -1
  171. package/dist/initializeCanvas.js +9 -10
  172. package/dist/initializeCanvas.js.map +1 -1
  173. package/dist/jpeg.d.ts +1 -1
  174. package/dist/jpeg.js +1020 -1021
  175. package/dist/jpeg.js.map +1 -1
  176. package/dist/psd.d.ts +1877 -1873
  177. package/dist/psd.js +45 -45
  178. package/dist/psd.js.map +1 -1
  179. package/dist/psdReader.d.ts +52 -45
  180. package/dist/psdReader.js +1385 -1282
  181. package/dist/psdReader.js.map +1 -1
  182. package/dist/psdWriter.d.ts +34 -34
  183. package/dist/psdWriter.js +834 -824
  184. package/dist/psdWriter.js.map +1 -1
  185. package/dist/text.d.ts +179 -179
  186. package/dist/text.js +552 -553
  187. package/dist/text.js.map +1 -1
  188. package/dist/utf8.d.ts +4 -6
  189. package/dist/utf8.js +156 -157
  190. package/dist/utf8.js.map +1 -1
  191. package/dist-es/abr.d.ts +196 -196
  192. package/dist-es/abr.js +364 -361
  193. package/dist-es/abr.js.map +1 -1
  194. package/dist-es/additionalInfo.d.ts +26 -26
  195. package/dist-es/additionalInfo.js +3478 -3472
  196. package/dist-es/additionalInfo.js.map +1 -1
  197. package/dist-es/ase.d.ts +32 -32
  198. package/dist-es/ase.js +81 -78
  199. package/dist-es/ase.js.map +1 -1
  200. package/dist-es/csh.d.ts +10 -10
  201. package/dist-es/csh.js +35 -32
  202. package/dist-es/csh.js.map +1 -1
  203. package/dist-es/descriptor.d.ts +601 -601
  204. package/dist-es/descriptor.js +2003 -1970
  205. package/dist-es/descriptor.js.map +1 -1
  206. package/dist-es/effectsHelpers.d.ts +5 -5
  207. package/dist-es/effectsHelpers.js +286 -282
  208. package/dist-es/effectsHelpers.js.map +1 -1
  209. package/dist-es/engineData.d.ts +2 -2
  210. package/dist-es/engineData.js +334 -330
  211. package/dist-es/engineData.js.map +1 -1
  212. package/dist-es/engineData2.d.ts +2 -2
  213. package/dist-es/engineData2.js +409 -406
  214. package/dist-es/engineData2.js.map +1 -1
  215. package/dist-es/helpers.d.ts +74 -74
  216. package/dist-es/helpers.js +353 -324
  217. package/dist-es/helpers.js.map +1 -1
  218. package/dist-es/imageResources.d.ts +17 -17
  219. package/dist-es/imageResources.js +1040 -1037
  220. package/dist-es/imageResources.js.map +1 -1
  221. package/dist-es/index.d.ts +20 -22
  222. package/dist-es/index.js +61 -33
  223. package/dist-es/index.js.map +1 -1
  224. package/dist-es/initializeCanvas.d.ts +1 -1
  225. package/dist-es/initializeCanvas.js +9 -6
  226. package/dist-es/initializeCanvas.js.map +1 -1
  227. package/dist-es/jpeg.d.ts +1 -1
  228. package/dist-es/jpeg.js +1020 -1017
  229. package/dist-es/jpeg.js.map +1 -1
  230. package/dist-es/psd.d.ts +1877 -1873
  231. package/dist-es/psd.js +45 -42
  232. package/dist-es/psd.js.map +1 -1
  233. package/dist-es/psdReader.d.ts +52 -45
  234. package/dist-es/psdReader.js +1385 -1244
  235. package/dist-es/psdReader.js.map +1 -1
  236. package/dist-es/psdWriter.d.ts +34 -34
  237. package/dist-es/psdWriter.js +834 -794
  238. package/dist-es/psdWriter.js.map +1 -1
  239. package/dist-es/text.d.ts +179 -179
  240. package/dist-es/text.js +552 -548
  241. package/dist-es/text.js.map +1 -1
  242. package/dist-es/utf8.d.ts +4 -6
  243. package/dist-es/utf8.js +156 -150
  244. package/dist-es/utf8.js.map +1 -1
  245. package/package.json +4 -3
  246. package/src/helpers.ts +13 -3
  247. package/src/index.ts +4 -6
  248. package/src/psd.ts +4 -0
  249. package/src/psdReader.ts +136 -43
  250. package/src/psdWriter.ts +42 -23
  251. package/tsconfig-es6.json +2 -1
  252. package/tsconfig.json +1 -0
package/dist-es/abr.js CHANGED
@@ -1,362 +1,365 @@
1
- import { BlnM, parseAngle, parsePercent, parseUnitsToNumber, readVersionAndDescriptor } from './descriptor';
2
- import { checkSignature, createReader, readBytes, readDataRLE, readInt16, readInt32, readPascalString, readPattern, readSignature, readUint16, readUint32, readUint8, skipBytes } from './psdReader';
3
- const dynamicsControl = ['off', 'fade', 'pen pressure', 'pen tilt', 'stylus wheel', 'initial direction', 'direction', 'initial rotation', 'rotation'];
4
- const dynamicBrushShapeShapes = ['round point', 'round blunt', 'round curve', 'round angle', 'round fan', 'flat point', 'flat blunt', 'flat curve', 'flat angle', 'flat fan'];
5
- const tipsBrushShapeShapes = ['erodible point', 'erodible flat', 'erodible round', 'erodible square', 'erodible triangle', 'custom'];
6
- const toBrushType = {
7
- _: 'brush',
8
- MixB: 'mixer brush',
9
- SmTl: 'smudge brush',
10
- // PbTl
11
- // ErTl
12
- };
13
- function parseDynamics(desc) {
14
- return {
15
- control: dynamicsControl[desc.bVTy],
16
- steps: desc.fStp,
17
- jitter: parsePercent(desc.jitter),
18
- minimum: parsePercent(desc['Mnm ']),
19
- };
20
- }
21
- function parseBrushShape(desc) {
22
- switch (desc._classID) {
23
- case 'computedBrush': {
24
- return {
25
- type: 'computed',
26
- size: parseUnitsToNumber(desc.Dmtr, 'Pixels'),
27
- angle: parseAngle(desc.Angl),
28
- roundness: parsePercent(desc.Rndn),
29
- spacingOn: desc.Intr,
30
- spacing: parsePercent(desc.Spcn),
31
- flipX: desc.flipX,
32
- flipY: desc.flipY,
33
- hardness: parsePercent(desc.Hrdn),
34
- };
35
- }
36
- case 'sampledBrush': {
37
- return {
38
- type: 'sampled',
39
- size: parseUnitsToNumber(desc.Dmtr, 'Pixels'),
40
- angle: parseAngle(desc.Angl),
41
- roundness: parsePercent(desc.Rndn),
42
- spacingOn: desc.Intr,
43
- spacing: parsePercent(desc.Spcn),
44
- flipX: desc.flipX,
45
- flipY: desc.flipY,
46
- name: desc['Nm '],
47
- sampledData: desc.sampledData,
48
- };
49
- }
50
- case 'dBrush':
51
- return {
52
- type: 'dynamic',
53
- shape: dynamicBrushShapeShapes[desc['Shp ']],
54
- angle: parseAngle(desc.Angl),
55
- size: parseUnitsToNumber(desc.Dmtr, 'Pixels'),
56
- density: parsePercent(desc.Dnst),
57
- length: parsePercent(desc.Lngt),
58
- clumping: parsePercent(desc.clumping),
59
- thickness: parsePercent(desc.thickness),
60
- stiffness: parsePercent(desc.stiffness),
61
- physics: desc.physics,
62
- spacing: parsePercent(desc.Spcn),
63
- spacingOn: desc.Intr,
64
- flipX: desc.flipX,
65
- flipY: desc.flipY,
66
- };
67
- case 'dTips': {
68
- return Object.assign(Object.assign({ type: 'tips', angle: parseAngle(desc.Angl), size: parseUnitsToNumber(desc.Dmtr, 'Pixels'), shape: dynamicBrushShapeShapes[desc['Shp ']], physics: desc.physics, spacing: parsePercent(desc.Spcn), spacingOn: desc.Intr, flipX: desc.flipX, flipY: desc.flipY,
69
- // tips:
70
- tipsType: tipsBrushShapeShapes[desc.dtipsType], tipsLengthRatio: parsePercent(desc.dtipsLengthRatio), tipsHardness: parsePercent(desc.dtipsHardness) }, (desc.dtipsGridSize && desc.dtipsErodibleTipHeightMap ? {
71
- tipsGridSize: desc.dtipsGridSize,
72
- tipsErodibleTipHeightMap: parseHeightmap(desc.dtipsErodibleTipHeightMap),
73
- } : {})), {
74
- // airbrush
75
- tipsAirbrushCutoffAngle: desc.dtipsAirbrushCutoffAngle, tipsAirbrushGranularity: parsePercent(desc.dtipsAirbrushGranularity), tipsAirbrushStreakiness: parsePercent(desc.dtipsAirbrushStreakiness), tipsAirbrushSplatSize: parsePercent(desc.dtipsAirbrushSplatSize), tipsAirbrushSplatCount: desc.dtipsAirbrushSplatCount });
76
- }
77
- default:
78
- console.log(require('util').inspect(desc, false, 99, true));
79
- throw new Error(`Unknown brush classId: ${desc._classID}`);
80
- }
81
- }
82
- function parseHeightmap(array) {
83
- const result = [];
84
- for (let i = 0; i < array.byteLength; i++) {
85
- result.push(array[i]);
86
- }
87
- return result;
88
- // const view = new DataView(array.buffer, array.byteOffset, array.byteLength);
89
- // const result: number[] = [];
90
- // for (let i = 0, len = (array.byteLength / 4) | 0; i < len; i++) {
91
- // result.push(view.getInt32(i * 4)); ????
92
- // }
93
- // return result;
94
- }
95
- export function readAbr(buffer, options = {}) {
96
- var _a, _b, _c, _d;
97
- const reader = createReader(buffer.buffer, buffer.byteOffset, buffer.byteLength);
98
- const version = readInt16(reader);
99
- const samples = [];
100
- const brushes = [];
101
- const patterns = [];
102
- if (version === 1 || version === 2) {
103
- throw new Error(`Unsupported ABR version (${version})`); // TODO: ...
104
- }
105
- else if (version === 6 || version === 7 || version === 9 || version === 10) {
106
- const minorVersion = readInt16(reader);
107
- if (minorVersion !== 1 && minorVersion !== 2)
108
- throw new Error('Unsupported ABR minor version');
109
- while (reader.offset < reader.view.byteLength) {
110
- checkSignature(reader, '8BIM');
111
- const type = readSignature(reader);
112
- let size = readUint32(reader);
113
- const end = reader.offset + size;
114
- switch (type) {
115
- case 'samp': {
116
- while (reader.offset < end) {
117
- let brushLength = readUint32(reader);
118
- while (brushLength & 0b11)
119
- brushLength++; // pad to 4 byte alignment
120
- const brushEnd = reader.offset + brushLength;
121
- const id = readPascalString(reader, 1);
122
- // v1 - Skip the Int16 bounds rectangle and the unknown Int16.
123
- // v2 - Skip the unknown bytes.
124
- skipBytes(reader, minorVersion === 1 ? 10 : 264);
125
- const y = readInt32(reader);
126
- const x = readInt32(reader);
127
- const h = readInt32(reader) - y;
128
- const w = readInt32(reader) - x;
129
- if (w <= 0 || h <= 0)
130
- throw new Error('Invalid bounds');
131
- const bithDepth = readInt16(reader);
132
- const compression = readUint8(reader); // 0 - raw, 1 - RLE
133
- const alpha = new Uint8Array(w * h);
134
- if (bithDepth === 8) {
135
- if (compression === 0) {
136
- alpha.set(readBytes(reader, alpha.byteLength));
137
- }
138
- else if (compression === 1) {
139
- readDataRLE(reader, { width: w, height: h, data: alpha }, w, h, bithDepth, 1, [0], false);
140
- }
141
- else {
142
- throw new Error('Invalid compression');
143
- }
144
- }
145
- else if (bithDepth === 16) {
146
- if (compression === 0) {
147
- for (let i = 0; i < alpha.byteLength; i++) {
148
- alpha[i] = readUint16(reader) >> 8; // convert to 8bit values
149
- }
150
- }
151
- else if (compression === 1) {
152
- throw new Error('not implemented (16bit RLE)'); // TODO: ...
153
- }
154
- else {
155
- throw new Error('Invalid compression');
156
- }
157
- }
158
- else {
159
- throw new Error('Invalid depth');
160
- }
161
- samples.push({ id, bounds: { x, y, w, h }, alpha });
162
- reader.offset = brushEnd;
163
- }
164
- break;
165
- }
166
- case 'desc': {
167
- const desc = readVersionAndDescriptor(reader, true);
168
- // console.log(require('util').inspect(desc, false, 99, true));
169
- // require('fs').writeFileSync('test.log', require('util').inspect(desc, false, 99, false), 'utf8');
170
- for (const brush of desc.Brsh) {
171
- const b = {
172
- name: brush['Nm '],
173
- shape: parseBrushShape(brush.Brsh),
174
- spacing: parsePercent(brush.Spcn),
175
- // TODO: brushGroup ???
176
- wetEdges: brush.Wtdg,
177
- noise: brush.Nose,
178
- // TODO: TxtC ??? smoothing / build-up ?
179
- // TODO: 'Rpt ' ???
180
- useBrushSize: brush.useBrushSize, // ???
181
- };
182
- if (brush.interpretation != null)
183
- b.interpretation = brush.interpretation;
184
- if (brush.protectTexture != null)
185
- b.protectTexture = brush.protectTexture;
186
- if (brush.useTipDynamics) {
187
- b.shapeDynamics = {
188
- tiltScale: parsePercent(brush.tiltScale),
189
- sizeDynamics: parseDynamics(brush.szVr),
190
- angleDynamics: parseDynamics(brush.angleDynamics),
191
- roundnessDynamics: parseDynamics(brush.roundnessDynamics),
192
- flipX: brush.flipX,
193
- flipY: brush.flipY,
194
- brushProjection: brush.brushProjection,
195
- minimumDiameter: parsePercent(brush.minimumDiameter),
196
- minimumRoundness: parsePercent(brush.minimumRoundness),
197
- };
198
- }
199
- if (brush.useScatter) {
200
- b.scatter = {
201
- count: brush['Cnt '],
202
- bothAxes: brush.bothAxes,
203
- countDynamics: parseDynamics(brush.countDynamics),
204
- scatterDynamics: parseDynamics(brush.scatterDynamics),
205
- };
206
- }
207
- if (brush.useTexture && brush.Txtr) {
208
- b.texture = {
209
- id: brush.Txtr.Idnt,
210
- name: brush.Txtr['Nm '],
211
- blendMode: BlnM.decode(brush.textureBlendMode),
212
- depth: parsePercent(brush.textureDepth),
213
- depthMinimum: parsePercent(brush.minimumDepth),
214
- depthDynamics: parseDynamics(brush.textureDepthDynamics),
215
- scale: parsePercent(brush.textureScale),
216
- invert: brush.InvT,
217
- brightness: brush.textureBrightness,
218
- contrast: brush.textureContrast,
219
- textureEachTip: !!brush.TxtC,
220
- };
221
- }
222
- const db = brush.dualBrush;
223
- if (db && db.useDualBrush) {
224
- b.dualBrush = {
225
- flip: db.Flip,
226
- shape: parseBrushShape(db.Brsh),
227
- blendMode: BlnM.decode(db.BlnM),
228
- useScatter: db.useScatter,
229
- spacing: parsePercent(db.Spcn),
230
- count: db['Cnt '],
231
- bothAxes: db.bothAxes,
232
- countDynamics: parseDynamics(db.countDynamics),
233
- scatterDynamics: parseDynamics(db.scatterDynamics),
234
- };
235
- }
236
- if (brush.useColorDynamics) {
237
- b.colorDynamics = {
238
- foregroundBackground: parseDynamics(brush.clVr),
239
- hue: parsePercent(brush['H ']),
240
- saturation: parsePercent(brush.Strt),
241
- brightness: parsePercent(brush.Brgh),
242
- purity: parsePercent(brush.purity),
243
- perTip: brush.colorDynamicsPerTip,
244
- };
245
- }
246
- if (brush.usePaintDynamics) {
247
- b.transfer = {
248
- flowDynamics: parseDynamics(brush.prVr),
249
- opacityDynamics: parseDynamics(brush.opVr),
250
- wetnessDynamics: parseDynamics(brush.wtVr),
251
- mixDynamics: parseDynamics(brush.mxVr),
252
- };
253
- }
254
- if (brush.useBrushPose) {
255
- b.brushPose = {
256
- overrideAngle: brush.overridePoseAngle,
257
- overrideTiltX: brush.overridePoseTiltX,
258
- overrideTiltY: brush.overridePoseTiltY,
259
- overridePressure: brush.overridePosePressure,
260
- pressure: parsePercent(brush.brushPosePressure),
261
- tiltX: brush.brushPoseTiltX,
262
- tiltY: brush.brushPoseTiltY,
263
- angle: brush.brushPoseAngle,
264
- };
265
- }
266
- const to = brush.toolOptions;
267
- if (to) {
268
- b.toolOptions = {
269
- type: toBrushType[to._classID] || 'brush',
270
- brushPreset: to.brushPreset,
271
- flow: (_a = to.flow) !== null && _a !== void 0 ? _a : 100,
272
- smooth: (_b = to.Smoo) !== null && _b !== void 0 ? _b : 0,
273
- mode: BlnM.decode(to['Md '] || 'BlnM.Nrml'),
274
- opacity: (_c = to.Opct) !== null && _c !== void 0 ? _c : 100,
275
- smoothing: !!to.smoothing,
276
- smoothingValue: to.smoothingValue || 0,
277
- smoothingRadiusMode: !!to.smoothingRadiusMode,
278
- smoothingCatchup: !!to.smoothingCatchup,
279
- smoothingCatchupAtEnd: !!to.smoothingCatchupAtEnd,
280
- smoothingZoomCompensation: !!to.smoothingZoomCompensation,
281
- pressureSmoothing: !!to.pressureSmoothing,
282
- usePressureOverridesSize: !!to.usePressureOverridesSize,
283
- usePressureOverridesOpacity: !!to.usePressureOverridesOpacity,
284
- useLegacy: !!to.useLegacy,
285
- };
286
- if (to.prVr)
287
- b.toolOptions.flowDynamics = parseDynamics(to.prVr);
288
- if (to.opVr)
289
- b.toolOptions.opacityDynamics = parseDynamics(to.opVr);
290
- if (to.szVr)
291
- b.toolOptions.sizeDynamics = parseDynamics(to.szVr);
292
- if ('wetness' in to)
293
- b.toolOptions.wetness = to.wetness;
294
- if ('dryness' in to)
295
- b.toolOptions.dryness = to.dryness;
296
- if ('mix' in to)
297
- b.toolOptions.mix = to.mix;
298
- if ('autoFill' in to)
299
- b.toolOptions.autoFill = to.autoFill;
300
- if ('autoClean' in to)
301
- b.toolOptions.autoClean = to.autoClean;
302
- if ('loadSolidColorOnly' in to)
303
- b.toolOptions.loadSolidColorOnly = to.loadSolidColorOnly;
304
- if ('sampleAllLayers' in to)
305
- b.toolOptions.sampleAllLayers = to.sampleAllLayers;
306
- if ('SmdF' in to)
307
- b.toolOptions.smudgeFingerPainting = to.SmdF;
308
- if ('SmdS' in to)
309
- b.toolOptions.smudgeSampleAllLayers = to.SmdS;
310
- if ('Prs ' in to)
311
- b.toolOptions.strength = to['Prs '];
312
- if ('SmdF' in to)
313
- b.toolOptions.smudgeFingerPainting = to.SmdF;
314
- if ('SmdS' in to)
315
- b.toolOptions.smudgeSampleAllLayers = to.SmdS;
316
- }
317
- brushes.push(b);
318
- }
319
- break;
320
- }
321
- case 'patt': {
322
- while (reader.offset < end) {
323
- patterns.push(readPattern(reader));
324
- }
325
- reader.offset = end;
326
- break;
327
- }
328
- case 'phry': {
329
- // TODO: what is this ?
330
- const desc = readVersionAndDescriptor(reader);
331
- // example:
332
- // hierarchy: [
333
- // {
334
- // 'Nm ': 'PRE_EXPORT ',
335
- // zuid: '965209f2-6f35-9a40-aa43-485684382172'
336
- // },
337
- // {},
338
- // ...
339
- // ]
340
- if (options.logMissingFeatures) {
341
- if ((_d = desc.hierarchy) === null || _d === void 0 ? void 0 : _d.length) {
342
- // console.log('unhandled phry section', desc);
343
- }
344
- }
345
- break;
346
- }
347
- default:
348
- throw new Error(`Invalid brush type: ${type}`);
349
- }
350
- // align to 4 bytes
351
- while (size % 4) {
352
- reader.offset++;
353
- size++;
354
- }
355
- }
356
- }
357
- else {
358
- throw new Error(`Unsupported ABR version (${version})`);
359
- }
360
- return { samples, patterns, brushes };
361
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readAbr = readAbr;
4
+ const descriptor_1 = require("./descriptor");
5
+ const psdReader_1 = require("./psdReader");
6
+ const dynamicsControl = ['off', 'fade', 'pen pressure', 'pen tilt', 'stylus wheel', 'initial direction', 'direction', 'initial rotation', 'rotation'];
7
+ const dynamicBrushShapeShapes = ['round point', 'round blunt', 'round curve', 'round angle', 'round fan', 'flat point', 'flat blunt', 'flat curve', 'flat angle', 'flat fan'];
8
+ const tipsBrushShapeShapes = ['erodible point', 'erodible flat', 'erodible round', 'erodible square', 'erodible triangle', 'custom'];
9
+ const toBrushType = {
10
+ _: 'brush',
11
+ MixB: 'mixer brush',
12
+ SmTl: 'smudge brush',
13
+ // PbTl
14
+ // ErTl
15
+ };
16
+ function parseDynamics(desc) {
17
+ return {
18
+ control: dynamicsControl[desc.bVTy],
19
+ steps: desc.fStp,
20
+ jitter: (0, descriptor_1.parsePercent)(desc.jitter),
21
+ minimum: (0, descriptor_1.parsePercent)(desc['Mnm ']),
22
+ };
23
+ }
24
+ function parseBrushShape(desc) {
25
+ switch (desc._classID) {
26
+ case 'computedBrush': {
27
+ return {
28
+ type: 'computed',
29
+ size: (0, descriptor_1.parseUnitsToNumber)(desc.Dmtr, 'Pixels'),
30
+ angle: (0, descriptor_1.parseAngle)(desc.Angl),
31
+ roundness: (0, descriptor_1.parsePercent)(desc.Rndn),
32
+ spacingOn: desc.Intr,
33
+ spacing: (0, descriptor_1.parsePercent)(desc.Spcn),
34
+ flipX: desc.flipX,
35
+ flipY: desc.flipY,
36
+ hardness: (0, descriptor_1.parsePercent)(desc.Hrdn),
37
+ };
38
+ }
39
+ case 'sampledBrush': {
40
+ return {
41
+ type: 'sampled',
42
+ size: (0, descriptor_1.parseUnitsToNumber)(desc.Dmtr, 'Pixels'),
43
+ angle: (0, descriptor_1.parseAngle)(desc.Angl),
44
+ roundness: (0, descriptor_1.parsePercent)(desc.Rndn),
45
+ spacingOn: desc.Intr,
46
+ spacing: (0, descriptor_1.parsePercent)(desc.Spcn),
47
+ flipX: desc.flipX,
48
+ flipY: desc.flipY,
49
+ name: desc['Nm '],
50
+ sampledData: desc.sampledData,
51
+ };
52
+ }
53
+ case 'dBrush':
54
+ return {
55
+ type: 'dynamic',
56
+ shape: dynamicBrushShapeShapes[desc['Shp ']],
57
+ angle: (0, descriptor_1.parseAngle)(desc.Angl),
58
+ size: (0, descriptor_1.parseUnitsToNumber)(desc.Dmtr, 'Pixels'),
59
+ density: (0, descriptor_1.parsePercent)(desc.Dnst),
60
+ length: (0, descriptor_1.parsePercent)(desc.Lngt),
61
+ clumping: (0, descriptor_1.parsePercent)(desc.clumping),
62
+ thickness: (0, descriptor_1.parsePercent)(desc.thickness),
63
+ stiffness: (0, descriptor_1.parsePercent)(desc.stiffness),
64
+ physics: desc.physics,
65
+ spacing: (0, descriptor_1.parsePercent)(desc.Spcn),
66
+ spacingOn: desc.Intr,
67
+ flipX: desc.flipX,
68
+ flipY: desc.flipY,
69
+ };
70
+ case 'dTips': {
71
+ return Object.assign(Object.assign({ type: 'tips', angle: (0, descriptor_1.parseAngle)(desc.Angl), size: (0, descriptor_1.parseUnitsToNumber)(desc.Dmtr, 'Pixels'), shape: dynamicBrushShapeShapes[desc['Shp ']], physics: desc.physics, spacing: (0, descriptor_1.parsePercent)(desc.Spcn), spacingOn: desc.Intr, flipX: desc.flipX, flipY: desc.flipY,
72
+ // tips:
73
+ tipsType: tipsBrushShapeShapes[desc.dtipsType], tipsLengthRatio: (0, descriptor_1.parsePercent)(desc.dtipsLengthRatio), tipsHardness: (0, descriptor_1.parsePercent)(desc.dtipsHardness) }, (desc.dtipsGridSize && desc.dtipsErodibleTipHeightMap ? {
74
+ tipsGridSize: desc.dtipsGridSize,
75
+ tipsErodibleTipHeightMap: parseHeightmap(desc.dtipsErodibleTipHeightMap),
76
+ } : {})), {
77
+ // airbrush
78
+ tipsAirbrushCutoffAngle: desc.dtipsAirbrushCutoffAngle, tipsAirbrushGranularity: (0, descriptor_1.parsePercent)(desc.dtipsAirbrushGranularity), tipsAirbrushStreakiness: (0, descriptor_1.parsePercent)(desc.dtipsAirbrushStreakiness), tipsAirbrushSplatSize: (0, descriptor_1.parsePercent)(desc.dtipsAirbrushSplatSize), tipsAirbrushSplatCount: desc.dtipsAirbrushSplatCount });
79
+ }
80
+ default:
81
+ console.log(require('util').inspect(desc, false, 99, true));
82
+ throw new Error(`Unknown brush classId: ${desc._classID}`);
83
+ }
84
+ }
85
+ function parseHeightmap(array) {
86
+ const result = [];
87
+ for (let i = 0; i < array.byteLength; i++) {
88
+ result.push(array[i]);
89
+ }
90
+ return result;
91
+ // const view = new DataView(array.buffer, array.byteOffset, array.byteLength);
92
+ // const result: number[] = [];
93
+ // for (let i = 0, len = (array.byteLength / 4) | 0; i < len; i++) {
94
+ // result.push(view.getInt32(i * 4)); ????
95
+ // }
96
+ // return result;
97
+ }
98
+ function readAbr(buffer, options = {}) {
99
+ var _a, _b, _c, _d;
100
+ const reader = (0, psdReader_1.createReader)(buffer.buffer, buffer.byteOffset, buffer.byteLength);
101
+ const version = (0, psdReader_1.readInt16)(reader);
102
+ const samples = [];
103
+ const brushes = [];
104
+ const patterns = [];
105
+ if (version === 1 || version === 2) {
106
+ throw new Error(`Unsupported ABR version (${version})`); // TODO: ...
107
+ }
108
+ else if (version === 6 || version === 7 || version === 9 || version === 10) {
109
+ const minorVersion = (0, psdReader_1.readInt16)(reader);
110
+ if (minorVersion !== 1 && minorVersion !== 2)
111
+ throw new Error('Unsupported ABR minor version');
112
+ while (reader.offset < reader.view.byteLength) {
113
+ (0, psdReader_1.checkSignature)(reader, '8BIM');
114
+ const type = (0, psdReader_1.readSignature)(reader);
115
+ let size = (0, psdReader_1.readUint32)(reader);
116
+ const end = reader.offset + size;
117
+ switch (type) {
118
+ case 'samp': {
119
+ while (reader.offset < end) {
120
+ let brushLength = (0, psdReader_1.readUint32)(reader);
121
+ while (brushLength & 0b11)
122
+ brushLength++; // pad to 4 byte alignment
123
+ const brushEnd = reader.offset + brushLength;
124
+ const id = (0, psdReader_1.readPascalString)(reader, 1);
125
+ // v1 - Skip the Int16 bounds rectangle and the unknown Int16.
126
+ // v2 - Skip the unknown bytes.
127
+ (0, psdReader_1.skipBytes)(reader, minorVersion === 1 ? 10 : 264);
128
+ const y = (0, psdReader_1.readInt32)(reader);
129
+ const x = (0, psdReader_1.readInt32)(reader);
130
+ const h = (0, psdReader_1.readInt32)(reader) - y;
131
+ const w = (0, psdReader_1.readInt32)(reader) - x;
132
+ if (w <= 0 || h <= 0)
133
+ throw new Error('Invalid bounds');
134
+ const bithDepth = (0, psdReader_1.readInt16)(reader);
135
+ const compression = (0, psdReader_1.readUint8)(reader); // 0 - raw, 1 - RLE
136
+ const alpha = new Uint8Array(w * h);
137
+ if (bithDepth === 8) {
138
+ if (compression === 0) {
139
+ alpha.set((0, psdReader_1.readBytes)(reader, alpha.byteLength));
140
+ }
141
+ else if (compression === 1) {
142
+ (0, psdReader_1.readDataRLE)(reader, { width: w, height: h, data: alpha }, w, h, bithDepth, 1, [0], false);
143
+ }
144
+ else {
145
+ throw new Error('Invalid compression');
146
+ }
147
+ }
148
+ else if (bithDepth === 16) {
149
+ if (compression === 0) {
150
+ for (let i = 0; i < alpha.byteLength; i++) {
151
+ alpha[i] = (0, psdReader_1.readUint16)(reader) >> 8; // convert to 8bit values
152
+ }
153
+ }
154
+ else if (compression === 1) {
155
+ throw new Error('not implemented (16bit RLE)'); // TODO: ...
156
+ }
157
+ else {
158
+ throw new Error('Invalid compression');
159
+ }
160
+ }
161
+ else {
162
+ throw new Error('Invalid depth');
163
+ }
164
+ samples.push({ id, bounds: { x, y, w, h }, alpha });
165
+ reader.offset = brushEnd;
166
+ }
167
+ break;
168
+ }
169
+ case 'desc': {
170
+ const desc = (0, descriptor_1.readVersionAndDescriptor)(reader, true);
171
+ // console.log(require('util').inspect(desc, false, 99, true));
172
+ // require('fs').writeFileSync('test.log', require('util').inspect(desc, false, 99, false), 'utf8');
173
+ for (const brush of desc.Brsh) {
174
+ const b = {
175
+ name: brush['Nm '],
176
+ shape: parseBrushShape(brush.Brsh),
177
+ spacing: (0, descriptor_1.parsePercent)(brush.Spcn),
178
+ // TODO: brushGroup ???
179
+ wetEdges: brush.Wtdg,
180
+ noise: brush.Nose,
181
+ // TODO: TxtC ??? smoothing / build-up ?
182
+ // TODO: 'Rpt ' ???
183
+ useBrushSize: brush.useBrushSize, // ???
184
+ };
185
+ if (brush.interpretation != null)
186
+ b.interpretation = brush.interpretation;
187
+ if (brush.protectTexture != null)
188
+ b.protectTexture = brush.protectTexture;
189
+ if (brush.useTipDynamics) {
190
+ b.shapeDynamics = {
191
+ tiltScale: (0, descriptor_1.parsePercent)(brush.tiltScale),
192
+ sizeDynamics: parseDynamics(brush.szVr),
193
+ angleDynamics: parseDynamics(brush.angleDynamics),
194
+ roundnessDynamics: parseDynamics(brush.roundnessDynamics),
195
+ flipX: brush.flipX,
196
+ flipY: brush.flipY,
197
+ brushProjection: brush.brushProjection,
198
+ minimumDiameter: (0, descriptor_1.parsePercent)(brush.minimumDiameter),
199
+ minimumRoundness: (0, descriptor_1.parsePercent)(brush.minimumRoundness),
200
+ };
201
+ }
202
+ if (brush.useScatter) {
203
+ b.scatter = {
204
+ count: brush['Cnt '],
205
+ bothAxes: brush.bothAxes,
206
+ countDynamics: parseDynamics(brush.countDynamics),
207
+ scatterDynamics: parseDynamics(brush.scatterDynamics),
208
+ };
209
+ }
210
+ if (brush.useTexture && brush.Txtr) {
211
+ b.texture = {
212
+ id: brush.Txtr.Idnt,
213
+ name: brush.Txtr['Nm '],
214
+ blendMode: descriptor_1.BlnM.decode(brush.textureBlendMode),
215
+ depth: (0, descriptor_1.parsePercent)(brush.textureDepth),
216
+ depthMinimum: (0, descriptor_1.parsePercent)(brush.minimumDepth),
217
+ depthDynamics: parseDynamics(brush.textureDepthDynamics),
218
+ scale: (0, descriptor_1.parsePercent)(brush.textureScale),
219
+ invert: brush.InvT,
220
+ brightness: brush.textureBrightness,
221
+ contrast: brush.textureContrast,
222
+ textureEachTip: !!brush.TxtC,
223
+ };
224
+ }
225
+ const db = brush.dualBrush;
226
+ if (db && db.useDualBrush) {
227
+ b.dualBrush = {
228
+ flip: db.Flip,
229
+ shape: parseBrushShape(db.Brsh),
230
+ blendMode: descriptor_1.BlnM.decode(db.BlnM),
231
+ useScatter: db.useScatter,
232
+ spacing: (0, descriptor_1.parsePercent)(db.Spcn),
233
+ count: db['Cnt '],
234
+ bothAxes: db.bothAxes,
235
+ countDynamics: parseDynamics(db.countDynamics),
236
+ scatterDynamics: parseDynamics(db.scatterDynamics),
237
+ };
238
+ }
239
+ if (brush.useColorDynamics) {
240
+ b.colorDynamics = {
241
+ foregroundBackground: parseDynamics(brush.clVr),
242
+ hue: (0, descriptor_1.parsePercent)(brush['H ']),
243
+ saturation: (0, descriptor_1.parsePercent)(brush.Strt),
244
+ brightness: (0, descriptor_1.parsePercent)(brush.Brgh),
245
+ purity: (0, descriptor_1.parsePercent)(brush.purity),
246
+ perTip: brush.colorDynamicsPerTip,
247
+ };
248
+ }
249
+ if (brush.usePaintDynamics) {
250
+ b.transfer = {
251
+ flowDynamics: parseDynamics(brush.prVr),
252
+ opacityDynamics: parseDynamics(brush.opVr),
253
+ wetnessDynamics: parseDynamics(brush.wtVr),
254
+ mixDynamics: parseDynamics(brush.mxVr),
255
+ };
256
+ }
257
+ if (brush.useBrushPose) {
258
+ b.brushPose = {
259
+ overrideAngle: brush.overridePoseAngle,
260
+ overrideTiltX: brush.overridePoseTiltX,
261
+ overrideTiltY: brush.overridePoseTiltY,
262
+ overridePressure: brush.overridePosePressure,
263
+ pressure: (0, descriptor_1.parsePercent)(brush.brushPosePressure),
264
+ tiltX: brush.brushPoseTiltX,
265
+ tiltY: brush.brushPoseTiltY,
266
+ angle: brush.brushPoseAngle,
267
+ };
268
+ }
269
+ const to = brush.toolOptions;
270
+ if (to) {
271
+ b.toolOptions = {
272
+ type: toBrushType[to._classID] || 'brush',
273
+ brushPreset: to.brushPreset,
274
+ flow: (_a = to.flow) !== null && _a !== void 0 ? _a : 100,
275
+ smooth: (_b = to.Smoo) !== null && _b !== void 0 ? _b : 0,
276
+ mode: descriptor_1.BlnM.decode(to['Md '] || 'BlnM.Nrml'), // sometimes mode is missing
277
+ opacity: (_c = to.Opct) !== null && _c !== void 0 ? _c : 100,
278
+ smoothing: !!to.smoothing,
279
+ smoothingValue: to.smoothingValue || 0,
280
+ smoothingRadiusMode: !!to.smoothingRadiusMode,
281
+ smoothingCatchup: !!to.smoothingCatchup,
282
+ smoothingCatchupAtEnd: !!to.smoothingCatchupAtEnd,
283
+ smoothingZoomCompensation: !!to.smoothingZoomCompensation,
284
+ pressureSmoothing: !!to.pressureSmoothing,
285
+ usePressureOverridesSize: !!to.usePressureOverridesSize,
286
+ usePressureOverridesOpacity: !!to.usePressureOverridesOpacity,
287
+ useLegacy: !!to.useLegacy,
288
+ };
289
+ if (to.prVr)
290
+ b.toolOptions.flowDynamics = parseDynamics(to.prVr);
291
+ if (to.opVr)
292
+ b.toolOptions.opacityDynamics = parseDynamics(to.opVr);
293
+ if (to.szVr)
294
+ b.toolOptions.sizeDynamics = parseDynamics(to.szVr);
295
+ if ('wetness' in to)
296
+ b.toolOptions.wetness = to.wetness;
297
+ if ('dryness' in to)
298
+ b.toolOptions.dryness = to.dryness;
299
+ if ('mix' in to)
300
+ b.toolOptions.mix = to.mix;
301
+ if ('autoFill' in to)
302
+ b.toolOptions.autoFill = to.autoFill;
303
+ if ('autoClean' in to)
304
+ b.toolOptions.autoClean = to.autoClean;
305
+ if ('loadSolidColorOnly' in to)
306
+ b.toolOptions.loadSolidColorOnly = to.loadSolidColorOnly;
307
+ if ('sampleAllLayers' in to)
308
+ b.toolOptions.sampleAllLayers = to.sampleAllLayers;
309
+ if ('SmdF' in to)
310
+ b.toolOptions.smudgeFingerPainting = to.SmdF;
311
+ if ('SmdS' in to)
312
+ b.toolOptions.smudgeSampleAllLayers = to.SmdS;
313
+ if ('Prs ' in to)
314
+ b.toolOptions.strength = to['Prs '];
315
+ if ('SmdF' in to)
316
+ b.toolOptions.smudgeFingerPainting = to.SmdF;
317
+ if ('SmdS' in to)
318
+ b.toolOptions.smudgeSampleAllLayers = to.SmdS;
319
+ }
320
+ brushes.push(b);
321
+ }
322
+ break;
323
+ }
324
+ case 'patt': {
325
+ while (reader.offset < end) {
326
+ patterns.push((0, psdReader_1.readPattern)(reader));
327
+ }
328
+ reader.offset = end;
329
+ break;
330
+ }
331
+ case 'phry': {
332
+ // TODO: what is this ?
333
+ const desc = (0, descriptor_1.readVersionAndDescriptor)(reader);
334
+ // example:
335
+ // hierarchy: [
336
+ // {
337
+ // 'Nm ': 'PRE_EXPORT ',
338
+ // zuid: '965209f2-6f35-9a40-aa43-485684382172'
339
+ // },
340
+ // {},
341
+ // ...
342
+ // ]
343
+ if (options.logMissingFeatures) {
344
+ if ((_d = desc.hierarchy) === null || _d === void 0 ? void 0 : _d.length) {
345
+ // console.log('unhandled phry section', desc);
346
+ }
347
+ }
348
+ break;
349
+ }
350
+ default:
351
+ throw new Error(`Invalid brush type: ${type}`);
352
+ }
353
+ // align to 4 bytes
354
+ while (size % 4) {
355
+ reader.offset++;
356
+ size++;
357
+ }
358
+ }
359
+ }
360
+ else {
361
+ throw new Error(`Unsupported ABR version (${version})`);
362
+ }
363
+ return { samples, patterns, brushes };
364
+ }
362
365
  //# sourceMappingURL=abr.js.map