pdfjs-dist 2.2.228 → 2.6.347

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.

Potentially problematic release.


This version of pdfjs-dist might be problematic. Click here for more details.

Files changed (229) hide show
  1. package/README.md +4 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +8816 -19300
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +22 -1
  6. package/build/pdf.worker.entry.js +5 -3
  7. package/build/pdf.worker.js +27185 -35746
  8. package/build/pdf.worker.js.map +1 -1
  9. package/build/pdf.worker.min.js +22 -1
  10. package/es5/build/pdf.js +26665 -0
  11. package/es5/build/pdf.js.map +1 -0
  12. package/es5/build/pdf.min.js +22 -0
  13. package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
  14. package/es5/build/pdf.worker.js +61231 -0
  15. package/es5/build/pdf.worker.js.map +1 -0
  16. package/es5/build/pdf.worker.min.js +22 -0
  17. package/es5/image_decoders/pdf.image_decoders.js +12529 -0
  18. package/es5/image_decoders/pdf.image_decoders.js.map +1 -0
  19. package/es5/image_decoders/pdf.image_decoders.min.js +22 -0
  20. package/es5/web/images/annotation-check.svg +11 -0
  21. package/es5/web/images/annotation-comment.svg +16 -0
  22. package/es5/web/images/annotation-help.svg +26 -0
  23. package/es5/web/images/annotation-insert.svg +10 -0
  24. package/es5/web/images/annotation-key.svg +11 -0
  25. package/es5/web/images/annotation-newparagraph.svg +11 -0
  26. package/es5/web/images/annotation-noicon.svg +7 -0
  27. package/es5/web/images/annotation-note.svg +42 -0
  28. package/es5/web/images/annotation-paragraph.svg +16 -0
  29. package/es5/web/images/loading-icon.gif +0 -0
  30. package/es5/web/images/shadow.png +0 -0
  31. package/es5/web/pdf_viewer.css +406 -0
  32. package/es5/web/pdf_viewer.js +7886 -0
  33. package/es5/web/pdf_viewer.js.map +1 -0
  34. package/image_decoders/pdf.image_decoders.js +1498 -4832
  35. package/image_decoders/pdf.image_decoders.js.map +1 -1
  36. package/image_decoders/pdf.image_decoders.min.js +22 -1
  37. package/lib/README.md +7 -0
  38. package/lib/core/annotation.js +1144 -927
  39. package/lib/core/arithmetic_decoder.js +81 -97
  40. package/lib/core/bidi.js +54 -46
  41. package/lib/core/ccitt.js +88 -81
  42. package/lib/core/ccitt_stream.js +15 -14
  43. package/lib/core/cff_parser.js +747 -716
  44. package/lib/core/charsets.js +4 -4
  45. package/lib/core/chunked_stream.js +462 -553
  46. package/lib/core/cmap.js +231 -277
  47. package/lib/core/colorspace.js +715 -857
  48. package/lib/core/core_utils.js +57 -52
  49. package/lib/core/crypto.js +416 -437
  50. package/lib/core/document.js +629 -670
  51. package/lib/core/encodings.js +15 -15
  52. package/lib/core/evaluator.js +3229 -2800
  53. package/lib/core/font_renderer.js +135 -178
  54. package/lib/core/fonts.js +602 -534
  55. package/lib/core/function.js +355 -279
  56. package/lib/core/glyphlist.js +4527 -4526
  57. package/lib/core/image.js +442 -439
  58. package/lib/core/image_utils.js +221 -61
  59. package/lib/core/jbig2.js +325 -316
  60. package/lib/core/jbig2_stream.js +18 -17
  61. package/lib/core/jpeg_stream.js +21 -26
  62. package/lib/core/jpg.js +289 -233
  63. package/lib/core/jpx.js +161 -143
  64. package/lib/core/jpx_stream.js +28 -28
  65. package/lib/core/metrics.js +2928 -2928
  66. package/lib/core/murmurhash3.js +87 -102
  67. package/lib/core/obj.js +1343 -1300
  68. package/lib/core/operator_list.js +90 -67
  69. package/lib/core/parser.js +990 -987
  70. package/lib/core/pattern.js +105 -77
  71. package/lib/core/pdf_manager.js +149 -316
  72. package/lib/core/primitives.js +156 -104
  73. package/lib/core/ps_parser.js +175 -214
  74. package/lib/core/standard_fonts.js +237 -236
  75. package/lib/core/stream.js +94 -74
  76. package/lib/core/type1_parser.js +89 -69
  77. package/lib/core/unicode.js +1654 -1654
  78. package/lib/core/worker.js +275 -290
  79. package/lib/core/worker_stream.js +101 -210
  80. package/lib/core/writer.js +242 -0
  81. package/lib/display/annotation_layer.js +772 -1041
  82. package/lib/display/annotation_storage.js +89 -0
  83. package/lib/display/api.js +1575 -1868
  84. package/lib/display/api_compatibility.js +12 -17
  85. package/lib/display/canvas.js +370 -222
  86. package/lib/display/content_disposition.js +40 -59
  87. package/lib/display/display_utils.js +341 -536
  88. package/lib/display/fetch_stream.js +188 -304
  89. package/lib/display/font_loader.js +282 -414
  90. package/lib/display/metadata.js +81 -99
  91. package/lib/display/network.js +362 -511
  92. package/lib/display/network_utils.js +25 -18
  93. package/lib/display/node_stream.js +283 -465
  94. package/lib/display/node_utils.js +87 -0
  95. package/lib/display/optional_content_config.js +184 -0
  96. package/lib/display/pattern_helper.js +93 -44
  97. package/lib/display/svg.js +1163 -1401
  98. package/lib/display/text_layer.js +154 -137
  99. package/lib/display/transport_stream.js +237 -375
  100. package/lib/display/webgl.js +70 -83
  101. package/lib/display/worker_options.js +3 -3
  102. package/lib/display/xml_parser.js +303 -392
  103. package/lib/examples/node/domstubs.js +37 -37
  104. package/lib/pdf.js +220 -58
  105. package/lib/pdf.worker.js +14 -6
  106. package/lib/shared/compatibility.js +3 -246
  107. package/lib/shared/is_node.js +7 -6
  108. package/lib/shared/message_handler.js +327 -332
  109. package/lib/shared/util.js +271 -306
  110. package/lib/test/unit/annotation_spec.js +1902 -763
  111. package/lib/test/unit/annotation_storage_spec.js +83 -0
  112. package/lib/test/unit/api_spec.js +790 -592
  113. package/lib/test/unit/bidi_spec.js +7 -7
  114. package/lib/test/unit/cff_parser_spec.js +73 -72
  115. package/lib/test/unit/clitests_helper.js +7 -9
  116. package/lib/test/unit/cmap_spec.js +86 -88
  117. package/lib/test/unit/colorspace_spec.js +346 -154
  118. package/lib/test/unit/core_utils_spec.js +125 -105
  119. package/lib/test/unit/crypto_spec.js +232 -185
  120. package/lib/test/unit/custom_spec.js +150 -24
  121. package/lib/test/unit/display_svg_spec.js +34 -39
  122. package/lib/test/unit/display_utils_spec.js +139 -149
  123. package/lib/test/unit/document_spec.js +128 -17
  124. package/lib/test/unit/encodings_spec.js +12 -34
  125. package/lib/test/unit/evaluator_spec.js +112 -91
  126. package/lib/test/unit/fetch_stream_spec.js +31 -29
  127. package/lib/test/unit/function_spec.js +206 -204
  128. package/lib/test/unit/jasmine-boot.js +48 -32
  129. package/lib/test/unit/message_handler_spec.js +173 -159
  130. package/lib/test/unit/metadata_spec.js +71 -71
  131. package/lib/test/unit/murmurhash3_spec.js +12 -12
  132. package/lib/test/unit/network_spec.js +13 -11
  133. package/lib/test/unit/network_utils_spec.js +158 -144
  134. package/lib/test/unit/node_stream_spec.js +76 -90
  135. package/lib/test/unit/parser_spec.js +108 -114
  136. package/lib/test/unit/pdf_find_controller_spec.js +55 -86
  137. package/lib/test/unit/pdf_find_utils_spec.js +32 -32
  138. package/lib/test/unit/pdf_history_spec.js +32 -32
  139. package/lib/test/unit/primitives_spec.js +337 -156
  140. package/lib/test/unit/stream_spec.js +16 -14
  141. package/lib/test/unit/test_utils.js +91 -304
  142. package/lib/test/unit/testreporter.js +33 -22
  143. package/lib/test/unit/type1_parser_spec.js +42 -42
  144. package/lib/test/unit/ui_utils_spec.js +299 -461
  145. package/lib/test/unit/unicode_spec.js +42 -42
  146. package/lib/test/unit/util_spec.js +129 -149
  147. package/lib/test/unit/writer_spec.js +84 -0
  148. package/lib/web/annotation_layer_builder.js +78 -111
  149. package/lib/web/app.js +1542 -1267
  150. package/lib/web/app_options.js +76 -91
  151. package/lib/web/base_tree_viewer.js +100 -0
  152. package/lib/web/base_viewer.js +869 -834
  153. package/lib/web/chromecom.js +165 -252
  154. package/lib/web/debugger.js +149 -205
  155. package/lib/web/download_manager.js +34 -58
  156. package/lib/web/firefox_print_service.js +62 -34
  157. package/lib/web/firefoxcom.js +206 -374
  158. package/lib/web/genericcom.js +26 -108
  159. package/lib/web/genericl10n.js +24 -153
  160. package/lib/web/grab_to_pan.js +30 -30
  161. package/lib/web/interfaces.js +80 -254
  162. package/lib/web/overlay_manager.js +70 -246
  163. package/lib/web/password_prompt.js +38 -64
  164. package/lib/web/pdf_attachment_viewer.js +150 -126
  165. package/lib/web/pdf_cursor_tools.js +75 -102
  166. package/lib/web/pdf_document_properties.js +229 -383
  167. package/lib/web/pdf_find_bar.js +136 -170
  168. package/lib/web/pdf_find_controller.js +492 -548
  169. package/lib/web/pdf_find_utils.js +13 -13
  170. package/lib/web/pdf_history.js +397 -406
  171. package/lib/web/pdf_layer_viewer.js +208 -0
  172. package/lib/web/pdf_link_service.js +304 -348
  173. package/lib/web/pdf_outline_viewer.js +119 -212
  174. package/lib/web/pdf_page_view.js +474 -513
  175. package/lib/web/pdf_presentation_mode.js +308 -357
  176. package/lib/web/pdf_print_service.js +96 -110
  177. package/lib/web/pdf_rendering_queue.js +87 -108
  178. package/lib/web/pdf_sidebar.js +286 -302
  179. package/lib/web/pdf_sidebar_resizer.js +92 -119
  180. package/lib/web/pdf_single_page_viewer.js +77 -126
  181. package/lib/web/pdf_thumbnail_view.js +289 -297
  182. package/lib/web/pdf_thumbnail_viewer.js +202 -206
  183. package/lib/web/pdf_viewer.component.js +20 -21
  184. package/lib/web/pdf_viewer.js +55 -115
  185. package/lib/web/preferences.js +69 -273
  186. package/lib/web/secondary_toolbar.js +164 -196
  187. package/lib/web/text_layer_builder.js +284 -319
  188. package/lib/web/toolbar.js +217 -210
  189. package/lib/web/ui_utils.js +274 -421
  190. package/lib/web/view_history.js +52 -226
  191. package/lib/web/viewer_compatibility.js +21 -6
  192. package/package.json +4 -9
  193. package/types/display/annotation_layer.d.ts +61 -0
  194. package/types/display/annotation_storage.d.ts +36 -0
  195. package/types/display/api.d.ts +1107 -0
  196. package/types/display/api_compatibility.d.ts +1 -0
  197. package/types/display/canvas.d.ts +4 -0
  198. package/types/display/content_disposition.d.ts +7 -0
  199. package/types/display/display_utils.d.ts +243 -0
  200. package/types/display/fetch_stream.d.ts +67 -0
  201. package/types/display/font_loader.d.ts +19 -0
  202. package/types/display/metadata.d.ts +9 -0
  203. package/types/display/network.d.ts +80 -0
  204. package/types/display/network_utils.d.ts +14 -0
  205. package/types/display/node_stream.d.ts +72 -0
  206. package/types/display/node_utils.d.ts +6 -0
  207. package/types/display/optional_content_config.d.ts +12 -0
  208. package/types/display/pattern_helper.d.ts +5 -0
  209. package/types/display/svg.d.ts +2 -0
  210. package/types/display/text_layer.d.ts +83 -0
  211. package/types/display/transport_stream.d.ts +57 -0
  212. package/types/display/webgl.d.ts +20 -0
  213. package/types/display/worker_options.d.ts +27 -0
  214. package/types/display/xml_parser.d.ts +35 -0
  215. package/types/pdf.d.ts +33 -0
  216. package/types/shared/compatibility.d.ts +1 -0
  217. package/types/shared/is_node.d.ts +1 -0
  218. package/types/shared/message_handler.d.ts +62 -0
  219. package/types/shared/util.d.ts +421 -0
  220. package/web/images/shadow.png +0 -0
  221. package/web/pdf_viewer.css +29 -27
  222. package/web/pdf_viewer.js +3524 -4746
  223. package/web/pdf_viewer.js.map +1 -1
  224. package/webpack.js +6 -5
  225. package/external/streams/streams-lib.js +0 -3962
  226. package/external/url/url-lib.js +0 -627
  227. package/lib/shared/streams_polyfill.js +0 -43
  228. package/lib/shared/url_polyfill.js +0 -56
  229. package/web/images/texture.png +0 -0
package/lib/core/image.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * @licstart The following is the entire license notice for the
3
3
  * Javascript code in this page
4
4
  *
5
- * Copyright 2019 Mozilla Foundation
5
+ * Copyright 2020 Mozilla Foundation
6
6
  *
7
7
  * Licensed under the Apache License, Version 2.0 (the "License");
8
8
  * you may not use this file except in compliance with the License.
@@ -26,92 +26,87 @@ Object.defineProperty(exports, "__esModule", {
26
26
  });
27
27
  exports.PDFImage = void 0;
28
28
 
29
- var _util = require("../shared/util");
29
+ var _util = require("../shared/util.js");
30
30
 
31
- var _primitives = require("./primitives");
31
+ var _primitives = require("./primitives.js");
32
32
 
33
- var _colorspace = require("./colorspace");
33
+ var _colorspace = require("./colorspace.js");
34
34
 
35
- var _stream = require("./stream");
35
+ var _stream = require("./stream.js");
36
36
 
37
- var _jpeg_stream = require("./jpeg_stream");
37
+ var _jpeg_stream = require("./jpeg_stream.js");
38
38
 
39
- var _jpx = require("./jpx");
39
+ var _jpx = require("./jpx.js");
40
40
 
41
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
41
+ function decodeAndClamp(value, addend, coefficient, max) {
42
+ value = addend + value * coefficient;
42
43
 
43
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
44
-
45
- function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
44
+ if (value < 0) {
45
+ value = 0;
46
+ } else if (value > max) {
47
+ value = max;
48
+ }
46
49
 
47
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
50
+ return value;
51
+ }
48
52
 
49
- var PDFImage = function PDFImageClosure() {
50
- function handleImageData(image, nativeDecoder) {
51
- if (nativeDecoder && nativeDecoder.canDecode(image)) {
52
- return nativeDecoder.decode(image)["catch"](function (reason) {
53
- (0, _util.warn)('Native image decoding failed -- trying to recover: ' + (reason && reason.message));
54
- return image;
55
- });
56
- }
53
+ function resizeImageMask(src, bpc, w1, h1, w2, h2) {
54
+ var length = w2 * h2;
55
+ let dest;
57
56
 
58
- return Promise.resolve(image);
57
+ if (bpc <= 8) {
58
+ dest = new Uint8Array(length);
59
+ } else if (bpc <= 16) {
60
+ dest = new Uint16Array(length);
61
+ } else {
62
+ dest = new Uint32Array(length);
59
63
  }
60
64
 
61
- function decodeAndClamp(value, addend, coefficient, max) {
62
- value = addend + value * coefficient;
63
- return value < 0 ? 0 : value > max ? max : value;
65
+ var xRatio = w1 / w2;
66
+ var yRatio = h1 / h2;
67
+ var i,
68
+ j,
69
+ py,
70
+ newIndex = 0,
71
+ oldIndex;
72
+ var xScaled = new Uint16Array(w2);
73
+ var w1Scanline = w1;
74
+
75
+ for (i = 0; i < w2; i++) {
76
+ xScaled[i] = Math.floor(i * xRatio);
64
77
  }
65
78
 
66
- function resizeImageMask(src, bpc, w1, h1, w2, h2) {
67
- var length = w2 * h2;
68
- var dest = bpc <= 8 ? new Uint8Array(length) : bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length);
69
- var xRatio = w1 / w2;
70
- var yRatio = h1 / h2;
71
- var i,
72
- j,
73
- py,
74
- newIndex = 0,
75
- oldIndex;
76
- var xScaled = new Uint16Array(w2);
77
- var w1Scanline = w1;
78
-
79
- for (i = 0; i < w2; i++) {
80
- xScaled[i] = Math.floor(i * xRatio);
81
- }
82
-
83
- for (i = 0; i < h2; i++) {
84
- py = Math.floor(i * yRatio) * w1Scanline;
79
+ for (i = 0; i < h2; i++) {
80
+ py = Math.floor(i * yRatio) * w1Scanline;
85
81
 
86
- for (j = 0; j < w2; j++) {
87
- oldIndex = py + xScaled[j];
88
- dest[newIndex++] = src[oldIndex];
89
- }
82
+ for (j = 0; j < w2; j++) {
83
+ oldIndex = py + xScaled[j];
84
+ dest[newIndex++] = src[oldIndex];
90
85
  }
91
-
92
- return dest;
93
86
  }
94
87
 
95
- function PDFImage(_ref) {
96
- var xref = _ref.xref,
97
- res = _ref.res,
98
- image = _ref.image,
99
- _ref$isInline = _ref.isInline,
100
- isInline = _ref$isInline === void 0 ? false : _ref$isInline,
101
- _ref$smask = _ref.smask,
102
- smask = _ref$smask === void 0 ? null : _ref$smask,
103
- _ref$mask = _ref.mask,
104
- mask = _ref$mask === void 0 ? null : _ref$mask,
105
- _ref$isMask = _ref.isMask,
106
- isMask = _ref$isMask === void 0 ? false : _ref$isMask,
107
- pdfFunctionFactory = _ref.pdfFunctionFactory;
88
+ return dest;
89
+ }
90
+
91
+ class PDFImage {
92
+ constructor({
93
+ xref,
94
+ res,
95
+ image,
96
+ isInline = false,
97
+ smask = null,
98
+ mask = null,
99
+ isMask = false,
100
+ pdfFunctionFactory,
101
+ localColorSpaceCache
102
+ }) {
108
103
  this.image = image;
109
104
  var dict = image.dict;
110
- var filter = dict.get('Filter');
105
+ const filter = dict.get("Filter");
111
106
 
112
107
  if ((0, _primitives.isName)(filter)) {
113
108
  switch (filter.name) {
114
- case 'JPXDecode':
109
+ case "JPXDecode":
115
110
  var jpxImage = new _jpx.JpxImage();
116
111
  jpxImage.parseImageProperties(image.stream);
117
112
  image.stream.reset();
@@ -121,41 +116,41 @@ var PDFImage = function PDFImageClosure() {
121
116
  image.numComps = jpxImage.componentsCount;
122
117
  break;
123
118
 
124
- case 'JBIG2Decode':
119
+ case "JBIG2Decode":
125
120
  image.bitsPerComponent = 1;
126
121
  image.numComps = 1;
127
122
  break;
128
123
  }
129
124
  }
130
125
 
131
- var width = dict.get('Width', 'W');
132
- var height = dict.get('Height', 'H');
126
+ let width = dict.get("Width", "W");
127
+ let height = dict.get("Height", "H");
133
128
 
134
129
  if (Number.isInteger(image.width) && image.width > 0 && Number.isInteger(image.height) && image.height > 0 && (image.width !== width || image.height !== height)) {
135
- (0, _util.warn)('PDFImage - using the Width/Height of the image data, ' + 'rather than the image dictionary.');
130
+ (0, _util.warn)("PDFImage - using the Width/Height of the image data, " + "rather than the image dictionary.");
136
131
  width = image.width;
137
132
  height = image.height;
138
133
  }
139
134
 
140
135
  if (width < 1 || height < 1) {
141
- throw new _util.FormatError("Invalid image width: ".concat(width, " or ") + "height: ".concat(height));
136
+ throw new _util.FormatError(`Invalid image width: ${width} or height: ${height}`);
142
137
  }
143
138
 
144
139
  this.width = width;
145
140
  this.height = height;
146
- this.interpolate = dict.get('Interpolate', 'I') || false;
147
- this.imageMask = dict.get('ImageMask', 'IM') || false;
148
- this.matte = dict.get('Matte') || false;
141
+ this.interpolate = dict.get("Interpolate", "I") || false;
142
+ this.imageMask = dict.get("ImageMask", "IM") || false;
143
+ this.matte = dict.get("Matte") || false;
149
144
  var bitsPerComponent = image.bitsPerComponent;
150
145
 
151
146
  if (!bitsPerComponent) {
152
- bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
147
+ bitsPerComponent = dict.get("BitsPerComponent", "BPC");
153
148
 
154
149
  if (!bitsPerComponent) {
155
150
  if (this.imageMask) {
156
151
  bitsPerComponent = 1;
157
152
  } else {
158
- throw new _util.FormatError("Bits per component missing in image: ".concat(this.imageMask));
153
+ throw new _util.FormatError(`Bits per component missing in image: ${this.imageMask}`);
159
154
  }
160
155
  }
161
156
  }
@@ -163,35 +158,40 @@ var PDFImage = function PDFImageClosure() {
163
158
  this.bpc = bitsPerComponent;
164
159
 
165
160
  if (!this.imageMask) {
166
- var colorSpace = dict.get('ColorSpace', 'CS');
161
+ let colorSpace = dict.getRaw("ColorSpace") || dict.getRaw("CS");
167
162
 
168
163
  if (!colorSpace) {
169
- (0, _util.info)('JPX images (which do not require color spaces)');
164
+ (0, _util.info)("JPX images (which do not require color spaces)");
170
165
 
171
166
  switch (image.numComps) {
172
167
  case 1:
173
- colorSpace = _primitives.Name.get('DeviceGray');
168
+ colorSpace = _primitives.Name.get("DeviceGray");
174
169
  break;
175
170
 
176
171
  case 3:
177
- colorSpace = _primitives.Name.get('DeviceRGB');
172
+ colorSpace = _primitives.Name.get("DeviceRGB");
178
173
  break;
179
174
 
180
175
  case 4:
181
- colorSpace = _primitives.Name.get('DeviceCMYK');
176
+ colorSpace = _primitives.Name.get("DeviceCMYK");
182
177
  break;
183
178
 
184
179
  default:
185
- throw new Error("JPX images with ".concat(image.numComps, " ") + 'color components not supported.');
180
+ throw new Error(`JPX images with ${image.numComps} ` + "color components not supported.");
186
181
  }
187
182
  }
188
183
 
189
- var resources = isInline ? res : null;
190
- this.colorSpace = _colorspace.ColorSpace.parse(colorSpace, xref, resources, pdfFunctionFactory);
184
+ this.colorSpace = _colorspace.ColorSpace.parse({
185
+ cs: colorSpace,
186
+ xref,
187
+ resources: isInline ? res : null,
188
+ pdfFunctionFactory,
189
+ localColorSpaceCache
190
+ });
191
191
  this.numComps = this.colorSpace.numComps;
192
192
  }
193
193
 
194
- this.decode = dict.getArray('Decode', 'D');
194
+ this.decode = dict.getArray("Decode", "D");
195
195
  this.needsDecode = false;
196
196
 
197
197
  if (this.decode && (this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode, bitsPerComponent) || isMask && !_colorspace.ColorSpace.isDefaultDecode(this.decode, 1))) {
@@ -199,7 +199,7 @@ var PDFImage = function PDFImageClosure() {
199
199
  var max = (1 << bitsPerComponent) - 1;
200
200
  this.decodeCoefficients = [];
201
201
  this.decodeAddends = [];
202
- var isIndexed = this.colorSpace && this.colorSpace.name === 'Indexed';
202
+ const isIndexed = this.colorSpace && this.colorSpace.name === "Indexed";
203
203
 
204
204
  for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
205
205
  var dmin = this.decode[i];
@@ -211,27 +211,29 @@ var PDFImage = function PDFImageClosure() {
211
211
 
212
212
  if (smask) {
213
213
  this.smask = new PDFImage({
214
- xref: xref,
215
- res: res,
214
+ xref,
215
+ res,
216
216
  image: smask,
217
- isInline: isInline,
218
- pdfFunctionFactory: pdfFunctionFactory
217
+ isInline,
218
+ pdfFunctionFactory,
219
+ localColorSpaceCache
219
220
  });
220
221
  } else if (mask) {
221
222
  if ((0, _primitives.isStream)(mask)) {
222
223
  var maskDict = mask.dict,
223
- imageMask = maskDict.get('ImageMask', 'IM');
224
+ imageMask = maskDict.get("ImageMask", "IM");
224
225
 
225
226
  if (!imageMask) {
226
- (0, _util.warn)('Ignoring /Mask in image without /ImageMask.');
227
+ (0, _util.warn)("Ignoring /Mask in image without /ImageMask.");
227
228
  } else {
228
229
  this.mask = new PDFImage({
229
- xref: xref,
230
- res: res,
230
+ xref,
231
+ res,
231
232
  image: mask,
232
- isInline: isInline,
233
+ isInline,
233
234
  isMask: true,
234
- pdfFunctionFactory: pdfFunctionFactory
235
+ pdfFunctionFactory,
236
+ localColorSpaceCache
235
237
  });
236
238
  }
237
239
  } else {
@@ -240,66 +242,49 @@ var PDFImage = function PDFImageClosure() {
240
242
  }
241
243
  }
242
244
 
243
- PDFImage.buildImage = function (_ref2) {
244
- var handler = _ref2.handler,
245
- xref = _ref2.xref,
246
- res = _ref2.res,
247
- image = _ref2.image,
248
- _ref2$isInline = _ref2.isInline,
249
- isInline = _ref2$isInline === void 0 ? false : _ref2$isInline,
250
- _ref2$nativeDecoder = _ref2.nativeDecoder,
251
- nativeDecoder = _ref2$nativeDecoder === void 0 ? null : _ref2$nativeDecoder,
252
- pdfFunctionFactory = _ref2.pdfFunctionFactory;
253
- var imagePromise = handleImageData(image, nativeDecoder);
254
- var smaskPromise;
255
- var maskPromise;
256
- var smask = image.dict.get('SMask');
257
- var mask = image.dict.get('Mask');
245
+ static async buildImage({
246
+ xref,
247
+ res,
248
+ image,
249
+ isInline = false,
250
+ pdfFunctionFactory,
251
+ localColorSpaceCache
252
+ }) {
253
+ const imageData = image;
254
+ let smaskData = null;
255
+ let maskData = null;
256
+ const smask = image.dict.get("SMask");
257
+ const mask = image.dict.get("Mask");
258
258
 
259
259
  if (smask) {
260
- smaskPromise = handleImageData(smask, nativeDecoder);
261
- maskPromise = Promise.resolve(null);
262
- } else {
263
- smaskPromise = Promise.resolve(null);
264
-
265
- if (mask) {
266
- if ((0, _primitives.isStream)(mask)) {
267
- maskPromise = handleImageData(mask, nativeDecoder);
268
- } else if (Array.isArray(mask)) {
269
- maskPromise = Promise.resolve(mask);
270
- } else {
271
- (0, _util.warn)('Unsupported mask format.');
272
- maskPromise = Promise.resolve(null);
273
- }
260
+ smaskData = smask;
261
+ } else if (mask) {
262
+ if ((0, _primitives.isStream)(mask) || Array.isArray(mask)) {
263
+ maskData = mask;
274
264
  } else {
275
- maskPromise = Promise.resolve(null);
265
+ (0, _util.warn)("Unsupported mask format.");
276
266
  }
277
267
  }
278
268
 
279
- return Promise.all([imagePromise, smaskPromise, maskPromise]).then(function (_ref3) {
280
- var _ref4 = _slicedToArray(_ref3, 3),
281
- imageData = _ref4[0],
282
- smaskData = _ref4[1],
283
- maskData = _ref4[2];
284
-
285
- return new PDFImage({
286
- xref: xref,
287
- res: res,
288
- image: imageData,
289
- isInline: isInline,
290
- smask: smaskData,
291
- mask: maskData,
292
- pdfFunctionFactory: pdfFunctionFactory
293
- });
269
+ return new PDFImage({
270
+ xref,
271
+ res,
272
+ image: imageData,
273
+ isInline,
274
+ smask: smaskData,
275
+ mask: maskData,
276
+ pdfFunctionFactory,
277
+ localColorSpaceCache
294
278
  });
295
- };
296
-
297
- PDFImage.createMask = function (_ref5) {
298
- var imgArray = _ref5.imgArray,
299
- width = _ref5.width,
300
- height = _ref5.height,
301
- imageIsFromDecodeStream = _ref5.imageIsFromDecodeStream,
302
- inverseDecode = _ref5.inverseDecode;
279
+ }
280
+
281
+ static createMask({
282
+ imgArray,
283
+ width,
284
+ height,
285
+ imageIsFromDecodeStream,
286
+ inverseDecode
287
+ }) {
303
288
  var computedLength = (width + 7 >> 3) * height;
304
289
  var actualLength = imgArray.byteLength;
305
290
  var haveFullData = computedLength === actualLength;
@@ -321,366 +306,384 @@ var PDFImage = function PDFImageClosure() {
321
306
 
322
307
  if (inverseDecode) {
323
308
  for (i = 0; i < actualLength; i++) {
324
- data[i] ^= 0xFF;
309
+ data[i] ^= 0xff;
325
310
  }
326
311
  }
327
312
 
328
313
  return {
329
- data: data,
330
- width: width,
331
- height: height
314
+ data,
315
+ width,
316
+ height
332
317
  };
333
- };
334
-
335
- PDFImage.prototype = {
336
- get drawWidth() {
337
- return Math.max(this.width, this.smask && this.smask.width || 0, this.mask && this.mask.width || 0);
338
- },
339
-
340
- get drawHeight() {
341
- return Math.max(this.height, this.smask && this.smask.height || 0, this.mask && this.mask.height || 0);
342
- },
343
-
344
- decodeBuffer: function decodeBuffer(buffer) {
345
- var bpc = this.bpc;
346
- var numComps = this.numComps;
347
- var decodeAddends = this.decodeAddends;
348
- var decodeCoefficients = this.decodeCoefficients;
349
- var max = (1 << bpc) - 1;
350
- var i, ii;
351
-
352
- if (bpc === 1) {
353
- for (i = 0, ii = buffer.length; i < ii; i++) {
354
- buffer[i] = +!buffer[i];
355
- }
318
+ }
356
319
 
357
- return;
358
- }
320
+ get drawWidth() {
321
+ return Math.max(this.width, this.smask && this.smask.width || 0, this.mask && this.mask.width || 0);
322
+ }
359
323
 
360
- var index = 0;
324
+ get drawHeight() {
325
+ return Math.max(this.height, this.smask && this.smask.height || 0, this.mask && this.mask.height || 0);
326
+ }
361
327
 
362
- for (i = 0, ii = this.width * this.height; i < ii; i++) {
363
- for (var j = 0; j < numComps; j++) {
364
- buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j], decodeCoefficients[j], max);
365
- index++;
366
- }
328
+ decodeBuffer(buffer) {
329
+ var bpc = this.bpc;
330
+ var numComps = this.numComps;
331
+ var decodeAddends = this.decodeAddends;
332
+ var decodeCoefficients = this.decodeCoefficients;
333
+ var max = (1 << bpc) - 1;
334
+ var i, ii;
335
+
336
+ if (bpc === 1) {
337
+ for (i = 0, ii = buffer.length; i < ii; i++) {
338
+ buffer[i] = +!buffer[i];
367
339
  }
368
- },
369
- getComponents: function getComponents(buffer) {
370
- var bpc = this.bpc;
371
340
 
372
- if (bpc === 8) {
373
- return buffer;
341
+ return;
342
+ }
343
+
344
+ var index = 0;
345
+
346
+ for (i = 0, ii = this.width * this.height; i < ii; i++) {
347
+ for (var j = 0; j < numComps; j++) {
348
+ buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j], decodeCoefficients[j], max);
349
+ index++;
374
350
  }
351
+ }
352
+ }
375
353
 
376
- var width = this.width;
377
- var height = this.height;
378
- var numComps = this.numComps;
379
- var length = width * height * numComps;
380
- var bufferPos = 0;
381
- var output = bpc <= 8 ? new Uint8Array(length) : bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length);
382
- var rowComps = width * numComps;
383
- var max = (1 << bpc) - 1;
384
- var i = 0,
385
- ii,
386
- buf;
387
-
388
- if (bpc === 1) {
389
- var mask, loop1End, loop2End;
390
-
391
- for (var j = 0; j < height; j++) {
392
- loop1End = i + (rowComps & ~7);
393
- loop2End = i + rowComps;
394
-
395
- while (i < loop1End) {
396
- buf = buffer[bufferPos++];
397
- output[i] = buf >> 7 & 1;
398
- output[i + 1] = buf >> 6 & 1;
399
- output[i + 2] = buf >> 5 & 1;
400
- output[i + 3] = buf >> 4 & 1;
401
- output[i + 4] = buf >> 3 & 1;
402
- output[i + 5] = buf >> 2 & 1;
403
- output[i + 6] = buf >> 1 & 1;
404
- output[i + 7] = buf & 1;
405
- i += 8;
406
- }
354
+ getComponents(buffer) {
355
+ var bpc = this.bpc;
356
+
357
+ if (bpc === 8) {
358
+ return buffer;
359
+ }
407
360
 
408
- if (i < loop2End) {
409
- buf = buffer[bufferPos++];
410
- mask = 128;
361
+ var width = this.width;
362
+ var height = this.height;
363
+ var numComps = this.numComps;
364
+ var length = width * height * numComps;
365
+ var bufferPos = 0;
366
+ let output;
367
+
368
+ if (bpc <= 8) {
369
+ output = new Uint8Array(length);
370
+ } else if (bpc <= 16) {
371
+ output = new Uint16Array(length);
372
+ } else {
373
+ output = new Uint32Array(length);
374
+ }
411
375
 
412
- while (i < loop2End) {
413
- output[i++] = +!!(buf & mask);
414
- mask >>= 1;
415
- }
416
- }
376
+ var rowComps = width * numComps;
377
+ var max = (1 << bpc) - 1;
378
+ var i = 0,
379
+ ii,
380
+ buf;
381
+
382
+ if (bpc === 1) {
383
+ var mask, loop1End, loop2End;
384
+
385
+ for (var j = 0; j < height; j++) {
386
+ loop1End = i + (rowComps & ~7);
387
+ loop2End = i + rowComps;
388
+
389
+ while (i < loop1End) {
390
+ buf = buffer[bufferPos++];
391
+ output[i] = buf >> 7 & 1;
392
+ output[i + 1] = buf >> 6 & 1;
393
+ output[i + 2] = buf >> 5 & 1;
394
+ output[i + 3] = buf >> 4 & 1;
395
+ output[i + 4] = buf >> 3 & 1;
396
+ output[i + 5] = buf >> 2 & 1;
397
+ output[i + 6] = buf >> 1 & 1;
398
+ output[i + 7] = buf & 1;
399
+ i += 8;
417
400
  }
418
- } else {
419
- var bits = 0;
420
- buf = 0;
421
401
 
422
- for (i = 0, ii = length; i < ii; ++i) {
423
- if (i % rowComps === 0) {
424
- buf = 0;
425
- bits = 0;
426
- }
402
+ if (i < loop2End) {
403
+ buf = buffer[bufferPos++];
404
+ mask = 128;
427
405
 
428
- while (bits < bpc) {
429
- buf = buf << 8 | buffer[bufferPos++];
430
- bits += 8;
406
+ while (i < loop2End) {
407
+ output[i++] = +!!(buf & mask);
408
+ mask >>= 1;
431
409
  }
410
+ }
411
+ }
412
+ } else {
413
+ var bits = 0;
414
+ buf = 0;
415
+
416
+ for (i = 0, ii = length; i < ii; ++i) {
417
+ if (i % rowComps === 0) {
418
+ buf = 0;
419
+ bits = 0;
420
+ }
421
+
422
+ while (bits < bpc) {
423
+ buf = buf << 8 | buffer[bufferPos++];
424
+ bits += 8;
425
+ }
426
+
427
+ var remainingBits = bits - bpc;
428
+ let value = buf >> remainingBits;
432
429
 
433
- var remainingBits = bits - bpc;
434
- var value = buf >> remainingBits;
435
- output[i] = value < 0 ? 0 : value > max ? max : value;
436
- buf = buf & (1 << remainingBits) - 1;
437
- bits = remainingBits;
430
+ if (value < 0) {
431
+ value = 0;
432
+ } else if (value > max) {
433
+ value = max;
438
434
  }
435
+
436
+ output[i] = value;
437
+ buf = buf & (1 << remainingBits) - 1;
438
+ bits = remainingBits;
439
439
  }
440
+ }
441
+
442
+ return output;
443
+ }
440
444
 
441
- return output;
442
- },
443
- fillOpacity: function fillOpacity(rgbaBuf, width, height, actualHeight, image) {
444
- var smask = this.smask;
445
- var mask = this.mask;
446
- var alphaBuf, sw, sh, i, ii, j;
445
+ fillOpacity(rgbaBuf, width, height, actualHeight, image) {
446
+ var smask = this.smask;
447
+ var mask = this.mask;
448
+ var alphaBuf, sw, sh, i, ii, j;
447
449
 
448
- if (smask) {
449
- sw = smask.width;
450
- sh = smask.height;
450
+ if (smask) {
451
+ sw = smask.width;
452
+ sh = smask.height;
453
+ alphaBuf = new Uint8ClampedArray(sw * sh);
454
+ smask.fillGrayBuffer(alphaBuf);
455
+
456
+ if (sw !== width || sh !== height) {
457
+ alphaBuf = resizeImageMask(alphaBuf, smask.bpc, sw, sh, width, height);
458
+ }
459
+ } else if (mask) {
460
+ if (mask instanceof PDFImage) {
461
+ sw = mask.width;
462
+ sh = mask.height;
451
463
  alphaBuf = new Uint8ClampedArray(sw * sh);
452
- smask.fillGrayBuffer(alphaBuf);
464
+ mask.numComps = 1;
465
+ mask.fillGrayBuffer(alphaBuf);
466
+
467
+ for (i = 0, ii = sw * sh; i < ii; ++i) {
468
+ alphaBuf[i] = 255 - alphaBuf[i];
469
+ }
453
470
 
454
471
  if (sw !== width || sh !== height) {
455
- alphaBuf = resizeImageMask(alphaBuf, smask.bpc, sw, sh, width, height);
472
+ alphaBuf = resizeImageMask(alphaBuf, mask.bpc, sw, sh, width, height);
456
473
  }
457
- } else if (mask) {
458
- if (mask instanceof PDFImage) {
459
- sw = mask.width;
460
- sh = mask.height;
461
- alphaBuf = new Uint8ClampedArray(sw * sh);
462
- mask.numComps = 1;
463
- mask.fillGrayBuffer(alphaBuf);
464
-
465
- for (i = 0, ii = sw * sh; i < ii; ++i) {
466
- alphaBuf[i] = 255 - alphaBuf[i];
467
- }
474
+ } else if (Array.isArray(mask)) {
475
+ alphaBuf = new Uint8ClampedArray(width * height);
476
+ var numComps = this.numComps;
468
477
 
469
- if (sw !== width || sh !== height) {
470
- alphaBuf = resizeImageMask(alphaBuf, mask.bpc, sw, sh, width, height);
471
- }
472
- } else if (Array.isArray(mask)) {
473
- alphaBuf = new Uint8ClampedArray(width * height);
474
- var numComps = this.numComps;
475
-
476
- for (i = 0, ii = width * height; i < ii; ++i) {
477
- var opacity = 0;
478
- var imageOffset = i * numComps;
479
-
480
- for (j = 0; j < numComps; ++j) {
481
- var color = image[imageOffset + j];
482
- var maskOffset = j * 2;
483
-
484
- if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
485
- opacity = 255;
486
- break;
487
- }
488
- }
478
+ for (i = 0, ii = width * height; i < ii; ++i) {
479
+ var opacity = 0;
480
+ var imageOffset = i * numComps;
481
+
482
+ for (j = 0; j < numComps; ++j) {
483
+ var color = image[imageOffset + j];
484
+ var maskOffset = j * 2;
489
485
 
490
- alphaBuf[i] = opacity;
486
+ if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
487
+ opacity = 255;
488
+ break;
489
+ }
491
490
  }
492
- } else {
493
- throw new _util.FormatError('Unknown mask format.');
494
- }
495
- }
496
491
 
497
- if (alphaBuf) {
498
- for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
499
- rgbaBuf[j] = alphaBuf[i];
492
+ alphaBuf[i] = opacity;
500
493
  }
501
494
  } else {
502
- for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
503
- rgbaBuf[j] = 255;
504
- }
495
+ throw new _util.FormatError("Unknown mask format.");
505
496
  }
506
- },
507
- undoPreblend: function undoPreblend(buffer, width, height) {
508
- var matte = this.smask && this.smask.matte;
497
+ }
509
498
 
510
- if (!matte) {
511
- return;
499
+ if (alphaBuf) {
500
+ for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
501
+ rgbaBuf[j] = alphaBuf[i];
502
+ }
503
+ } else {
504
+ for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
505
+ rgbaBuf[j] = 255;
512
506
  }
507
+ }
508
+ }
513
509
 
514
- var matteRgb = this.colorSpace.getRgb(matte, 0);
515
- var matteR = matteRgb[0];
516
- var matteG = matteRgb[1];
517
- var matteB = matteRgb[2];
518
- var length = width * height * 4;
510
+ undoPreblend(buffer, width, height) {
511
+ var matte = this.smask && this.smask.matte;
519
512
 
520
- for (var i = 0; i < length; i += 4) {
521
- var alpha = buffer[i + 3];
513
+ if (!matte) {
514
+ return;
515
+ }
522
516
 
523
- if (alpha === 0) {
524
- buffer[i] = 255;
525
- buffer[i + 1] = 255;
526
- buffer[i + 2] = 255;
527
- continue;
528
- }
517
+ var matteRgb = this.colorSpace.getRgb(matte, 0);
518
+ var matteR = matteRgb[0];
519
+ var matteG = matteRgb[1];
520
+ var matteB = matteRgb[2];
521
+ var length = width * height * 4;
529
522
 
530
- var k = 255 / alpha;
531
- buffer[i] = (buffer[i] - matteR) * k + matteR;
532
- buffer[i + 1] = (buffer[i + 1] - matteG) * k + matteG;
533
- buffer[i + 2] = (buffer[i + 2] - matteB) * k + matteB;
534
- }
535
- },
536
- createImageData: function createImageData() {
537
- var forceRGBA = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
538
- var drawWidth = this.drawWidth;
539
- var drawHeight = this.drawHeight;
540
- var imgData = {
541
- width: drawWidth,
542
- height: drawHeight,
543
- kind: 0,
544
- data: null
545
- };
546
- var numComps = this.numComps;
547
- var originalWidth = this.width;
548
- var originalHeight = this.height;
549
- var bpc = this.bpc;
550
- var rowBytes = originalWidth * numComps * bpc + 7 >> 3;
551
- var imgArray;
552
-
553
- if (!forceRGBA) {
554
- var kind;
555
-
556
- if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
557
- kind = _util.ImageKind.GRAYSCALE_1BPP;
558
- } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 && !this.needsDecode) {
559
- kind = _util.ImageKind.RGB_24BPP;
560
- }
523
+ for (var i = 0; i < length; i += 4) {
524
+ var alpha = buffer[i + 3];
561
525
 
562
- if (kind && !this.smask && !this.mask && drawWidth === originalWidth && drawHeight === originalHeight) {
563
- imgData.kind = kind;
564
- imgArray = this.getImageBytes(originalHeight * rowBytes);
526
+ if (alpha === 0) {
527
+ buffer[i] = 255;
528
+ buffer[i + 1] = 255;
529
+ buffer[i + 2] = 255;
530
+ continue;
531
+ }
565
532
 
566
- if (this.image instanceof _stream.DecodeStream) {
567
- imgData.data = imgArray;
568
- } else {
569
- var newArray = new Uint8ClampedArray(imgArray.length);
570
- newArray.set(imgArray);
571
- imgData.data = newArray;
572
- }
533
+ var k = 255 / alpha;
534
+ buffer[i] = (buffer[i] - matteR) * k + matteR;
535
+ buffer[i + 1] = (buffer[i + 1] - matteG) * k + matteG;
536
+ buffer[i + 2] = (buffer[i + 2] - matteB) * k + matteB;
537
+ }
538
+ }
573
539
 
574
- if (this.needsDecode) {
575
- (0, _util.assert)(kind === _util.ImageKind.GRAYSCALE_1BPP, 'PDFImage.createImageData: The image must be grayscale.');
576
- var buffer = imgData.data;
540
+ createImageData(forceRGBA = false) {
541
+ var drawWidth = this.drawWidth;
542
+ var drawHeight = this.drawHeight;
543
+ var imgData = {
544
+ width: drawWidth,
545
+ height: drawHeight,
546
+ kind: 0,
547
+ data: null
548
+ };
549
+ var numComps = this.numComps;
550
+ var originalWidth = this.width;
551
+ var originalHeight = this.height;
552
+ var bpc = this.bpc;
553
+ var rowBytes = originalWidth * numComps * bpc + 7 >> 3;
554
+ var imgArray;
555
+
556
+ if (!forceRGBA) {
557
+ var kind;
558
+
559
+ if (this.colorSpace.name === "DeviceGray" && bpc === 1) {
560
+ kind = _util.ImageKind.GRAYSCALE_1BPP;
561
+ } else if (this.colorSpace.name === "DeviceRGB" && bpc === 8 && !this.needsDecode) {
562
+ kind = _util.ImageKind.RGB_24BPP;
563
+ }
577
564
 
578
- for (var i = 0, ii = buffer.length; i < ii; i++) {
579
- buffer[i] ^= 0xff;
580
- }
581
- }
565
+ if (kind && !this.smask && !this.mask && drawWidth === originalWidth && drawHeight === originalHeight) {
566
+ imgData.kind = kind;
567
+ imgArray = this.getImageBytes(originalHeight * rowBytes);
582
568
 
583
- return imgData;
569
+ if (this.image instanceof _stream.DecodeStream) {
570
+ imgData.data = imgArray;
571
+ } else {
572
+ var newArray = new Uint8ClampedArray(imgArray.length);
573
+ newArray.set(imgArray);
574
+ imgData.data = newArray;
584
575
  }
585
576
 
586
- if (this.image instanceof _jpeg_stream.JpegStream && !this.smask && !this.mask) {
587
- var imageLength = originalHeight * rowBytes;
588
-
589
- switch (this.colorSpace.name) {
590
- case 'DeviceGray':
591
- imageLength *= 3;
577
+ if (this.needsDecode) {
578
+ (0, _util.assert)(kind === _util.ImageKind.GRAYSCALE_1BPP, "PDFImage.createImageData: The image must be grayscale.");
579
+ var buffer = imgData.data;
592
580
 
593
- case 'DeviceRGB':
594
- case 'DeviceCMYK':
595
- imgData.kind = _util.ImageKind.RGB_24BPP;
596
- imgData.data = this.getImageBytes(imageLength, drawWidth, drawHeight, true);
597
- return imgData;
581
+ for (var i = 0, ii = buffer.length; i < ii; i++) {
582
+ buffer[i] ^= 0xff;
598
583
  }
599
584
  }
585
+
586
+ return imgData;
600
587
  }
601
588
 
602
- imgArray = this.getImageBytes(originalHeight * rowBytes);
603
- var actualHeight = 0 | imgArray.length / rowBytes * drawHeight / originalHeight;
604
- var comps = this.getComponents(imgArray);
605
- var alpha01, maybeUndoPreblend;
589
+ if (this.image instanceof _jpeg_stream.JpegStream && !this.smask && !this.mask) {
590
+ let imageLength = originalHeight * rowBytes;
606
591
 
607
- if (!forceRGBA && !this.smask && !this.mask) {
608
- imgData.kind = _util.ImageKind.RGB_24BPP;
609
- imgData.data = new Uint8ClampedArray(drawWidth * drawHeight * 3);
610
- alpha01 = 0;
611
- maybeUndoPreblend = false;
612
- } else {
613
- imgData.kind = _util.ImageKind.RGBA_32BPP;
614
- imgData.data = new Uint8ClampedArray(drawWidth * drawHeight * 4);
615
- alpha01 = 1;
616
- maybeUndoPreblend = true;
617
- this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight, comps);
618
- }
592
+ switch (this.colorSpace.name) {
593
+ case "DeviceGray":
594
+ imageLength *= 3;
619
595
 
620
- if (this.needsDecode) {
621
- this.decodeBuffer(comps);
596
+ case "DeviceRGB":
597
+ case "DeviceCMYK":
598
+ imgData.kind = _util.ImageKind.RGB_24BPP;
599
+ imgData.data = this.getImageBytes(imageLength, drawWidth, drawHeight, true);
600
+ return imgData;
601
+ }
622
602
  }
603
+ }
623
604
 
624
- this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight, drawWidth, drawHeight, actualHeight, bpc, comps, alpha01);
605
+ imgArray = this.getImageBytes(originalHeight * rowBytes);
606
+ var actualHeight = 0 | imgArray.length / rowBytes * drawHeight / originalHeight;
607
+ var comps = this.getComponents(imgArray);
608
+ var alpha01, maybeUndoPreblend;
625
609
 
626
- if (maybeUndoPreblend) {
627
- this.undoPreblend(imgData.data, drawWidth, actualHeight);
628
- }
610
+ if (!forceRGBA && !this.smask && !this.mask) {
611
+ imgData.kind = _util.ImageKind.RGB_24BPP;
612
+ imgData.data = new Uint8ClampedArray(drawWidth * drawHeight * 3);
613
+ alpha01 = 0;
614
+ maybeUndoPreblend = false;
615
+ } else {
616
+ imgData.kind = _util.ImageKind.RGBA_32BPP;
617
+ imgData.data = new Uint8ClampedArray(drawWidth * drawHeight * 4);
618
+ alpha01 = 1;
619
+ maybeUndoPreblend = true;
620
+ this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight, comps);
621
+ }
629
622
 
630
- return imgData;
631
- },
632
- fillGrayBuffer: function fillGrayBuffer(buffer) {
633
- var numComps = this.numComps;
623
+ if (this.needsDecode) {
624
+ this.decodeBuffer(comps);
625
+ }
634
626
 
635
- if (numComps !== 1) {
636
- throw new _util.FormatError("Reading gray scale from a color image: ".concat(numComps));
637
- }
627
+ this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight, drawWidth, drawHeight, actualHeight, bpc, comps, alpha01);
638
628
 
639
- var width = this.width;
640
- var height = this.height;
641
- var bpc = this.bpc;
642
- var rowBytes = width * numComps * bpc + 7 >> 3;
643
- var imgArray = this.getImageBytes(height * rowBytes);
644
- var comps = this.getComponents(imgArray);
645
- var i, length;
629
+ if (maybeUndoPreblend) {
630
+ this.undoPreblend(imgData.data, drawWidth, actualHeight);
631
+ }
646
632
 
647
- if (bpc === 1) {
648
- length = width * height;
633
+ return imgData;
634
+ }
649
635
 
650
- if (this.needsDecode) {
651
- for (i = 0; i < length; ++i) {
652
- buffer[i] = comps[i] - 1 & 255;
653
- }
654
- } else {
655
- for (i = 0; i < length; ++i) {
656
- buffer[i] = -comps[i] & 255;
657
- }
658
- }
636
+ fillGrayBuffer(buffer) {
637
+ var numComps = this.numComps;
659
638
 
660
- return;
661
- }
639
+ if (numComps !== 1) {
640
+ throw new _util.FormatError(`Reading gray scale from a color image: ${numComps}`);
641
+ }
662
642
 
663
- if (this.needsDecode) {
664
- this.decodeBuffer(comps);
665
- }
643
+ var width = this.width;
644
+ var height = this.height;
645
+ var bpc = this.bpc;
646
+ var rowBytes = width * numComps * bpc + 7 >> 3;
647
+ var imgArray = this.getImageBytes(height * rowBytes);
648
+ var comps = this.getComponents(imgArray);
649
+ var i, length;
666
650
 
651
+ if (bpc === 1) {
667
652
  length = width * height;
668
- var scale = 255 / ((1 << bpc) - 1);
669
653
 
670
- for (i = 0; i < length; ++i) {
671
- buffer[i] = scale * comps[i];
654
+ if (this.needsDecode) {
655
+ for (i = 0; i < length; ++i) {
656
+ buffer[i] = comps[i] - 1 & 255;
657
+ }
658
+ } else {
659
+ for (i = 0; i < length; ++i) {
660
+ buffer[i] = -comps[i] & 255;
661
+ }
672
662
  }
673
- },
674
- getImageBytes: function getImageBytes(length, drawWidth, drawHeight) {
675
- var forceRGB = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
676
- this.image.reset();
677
- this.image.drawWidth = drawWidth || this.width;
678
- this.image.drawHeight = drawHeight || this.height;
679
- this.image.forceRGB = !!forceRGB;
680
- return this.image.getBytes(length, true);
663
+
664
+ return;
665
+ }
666
+
667
+ if (this.needsDecode) {
668
+ this.decodeBuffer(comps);
681
669
  }
682
- };
683
- return PDFImage;
684
- }();
670
+
671
+ length = width * height;
672
+ var scale = 255 / ((1 << bpc) - 1);
673
+
674
+ for (i = 0; i < length; ++i) {
675
+ buffer[i] = scale * comps[i];
676
+ }
677
+ }
678
+
679
+ getImageBytes(length, drawWidth, drawHeight, forceRGB = false) {
680
+ this.image.reset();
681
+ this.image.drawWidth = drawWidth || this.width;
682
+ this.image.drawHeight = drawHeight || this.height;
683
+ this.image.forceRGB = !!forceRGB;
684
+ return this.image.getBytes(length, true);
685
+ }
686
+
687
+ }
685
688
 
686
689
  exports.PDFImage = PDFImage;