pdfjs-dist 2.1.266 → 2.5.207
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.
- package/CODE_OF_CONDUCT.md +15 -0
- package/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8382 -18492
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +22 -1
- package/build/pdf.worker.entry.js +5 -3
- package/build/pdf.worker.js +20417 -29816
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25688 -0
- package/es5/build/pdf.js.map +1 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +58239 -0
- package/es5/build/pdf.worker.js.map +1 -0
- package/es5/web/images/annotation-check.svg +11 -0
- package/es5/web/images/annotation-comment.svg +16 -0
- package/es5/web/images/annotation-help.svg +26 -0
- package/es5/web/images/annotation-insert.svg +10 -0
- package/es5/web/images/annotation-key.svg +11 -0
- package/es5/web/images/annotation-newparagraph.svg +11 -0
- package/es5/web/images/annotation-noicon.svg +7 -0
- package/es5/web/images/annotation-note.svg +42 -0
- package/es5/web/images/annotation-paragraph.svg +16 -0
- package/es5/web/images/loading-icon.gif +0 -0
- package/es5/web/images/shadow.png +0 -0
- package/es5/web/images/texture.png +0 -0
- package/es5/web/pdf_viewer.css +403 -0
- package/es5/web/pdf_viewer.js +7742 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +1475 -4897
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +22 -1
- package/lib/README.md +7 -0
- package/lib/core/annotation.js +750 -899
- package/lib/core/arithmetic_decoder.js +81 -97
- package/lib/core/bidi.js +54 -46
- package/lib/core/ccitt.js +88 -81
- package/lib/core/ccitt_stream.js +15 -14
- package/lib/core/cff_parser.js +235 -183
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +447 -542
- package/lib/core/cmap.js +222 -264
- package/lib/core/colorspace.js +699 -863
- package/lib/core/core_utils.js +152 -0
- package/lib/core/crypto.js +379 -437
- package/lib/core/document.js +573 -660
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +1103 -868
- package/lib/core/font_renderer.js +135 -178
- package/lib/core/fonts.js +570 -491
- package/lib/core/function.js +291 -288
- package/lib/core/glyphlist.js +4527 -4526
- package/lib/core/image.js +145 -149
- package/lib/core/image_utils.js +170 -0
- package/lib/core/jbig2.js +325 -316
- package/lib/core/jbig2_stream.js +18 -17
- package/lib/core/jpeg_stream.js +21 -26
- package/lib/core/jpg.js +284 -232
- package/lib/core/jpx.js +161 -143
- package/lib/core/jpx_stream.js +28 -28
- package/lib/core/metrics.js +2929 -2929
- package/lib/core/murmurhash3.js +90 -101
- package/lib/core/obj.js +1183 -1157
- package/lib/core/operator_list.js +99 -67
- package/lib/core/parser.js +972 -911
- package/lib/core/pattern.js +87 -70
- package/lib/core/pdf_manager.js +150 -315
- package/lib/core/primitives.js +83 -56
- package/lib/core/ps_parser.js +175 -214
- package/lib/core/standard_fonts.js +237 -236
- package/lib/core/stream.js +94 -74
- package/lib/core/type1_parser.js +87 -69
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +193 -390
- package/lib/core/worker_stream.js +168 -0
- package/lib/display/annotation_layer.js +741 -972
- package/lib/display/api.js +1500 -1791
- package/lib/display/api_compatibility.js +12 -17
- package/lib/display/canvas.js +165 -165
- package/lib/display/content_disposition.js +40 -59
- package/lib/display/display_utils.js +515 -0
- package/lib/display/fetch_stream.js +183 -298
- package/lib/display/font_loader.js +273 -413
- package/lib/display/metadata.js +86 -98
- package/lib/display/network.js +266 -359
- package/lib/display/network_utils.js +25 -18
- package/lib/display/node_stream.js +285 -458
- package/lib/display/pattern_helper.js +113 -65
- package/lib/display/svg.js +1166 -901
- package/lib/display/text_layer.js +156 -132
- package/lib/display/transport_stream.js +262 -278
- package/lib/display/webgl.js +70 -83
- package/lib/display/worker_options.js +3 -3
- package/lib/display/xml_parser.js +303 -392
- package/lib/examples/node/domstubs.js +40 -37
- package/lib/pdf.js +226 -59
- package/lib/pdf.worker.js +14 -6
- package/lib/shared/compatibility.js +3 -246
- package/lib/shared/is_node.js +7 -6
- package/lib/shared/message_handler.js +327 -332
- package/lib/shared/util.js +266 -416
- package/lib/test/unit/annotation_spec.js +1555 -701
- package/lib/test/unit/api_spec.js +802 -604
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +84 -69
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +74 -76
- package/lib/test/unit/colorspace_spec.js +166 -161
- package/lib/test/unit/core_utils_spec.js +211 -0
- package/lib/test/unit/crypto_spec.js +181 -181
- package/lib/test/unit/custom_spec.js +20 -22
- package/lib/test/unit/display_svg_spec.js +34 -39
- package/lib/test/unit/display_utils_spec.js +263 -0
- package/lib/test/unit/document_spec.js +16 -21
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +83 -83
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +206 -204
- package/lib/test/unit/jasmine-boot.js +46 -30
- package/lib/test/unit/message_handler_spec.js +173 -159
- package/lib/test/unit/metadata_spec.js +69 -69
- package/lib/test/unit/murmurhash3_spec.js +12 -12
- package/lib/test/unit/network_spec.js +13 -61
- package/lib/test/unit/network_utils_spec.js +183 -119
- package/lib/test/unit/node_stream_spec.js +78 -92
- package/lib/test/unit/parser_spec.js +172 -114
- package/lib/test/unit/pdf_find_controller_spec.js +55 -86
- package/lib/test/unit/pdf_find_utils_spec.js +32 -32
- package/lib/test/unit/pdf_history_spec.js +32 -32
- package/lib/test/unit/primitives_spec.js +140 -125
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +131 -143
- package/lib/test/unit/testreporter.js +19 -19
- package/lib/test/unit/type1_parser_spec.js +42 -42
- package/lib/test/unit/ui_utils_spec.js +297 -459
- package/lib/test/unit/unicode_spec.js +38 -38
- package/lib/test/unit/util_spec.js +121 -305
- package/lib/web/annotation_layer_builder.js +66 -103
- package/lib/web/app.js +1328 -1214
- package/lib/web/app_options.js +105 -107
- package/lib/web/base_viewer.js +824 -838
- package/lib/web/chromecom.js +165 -252
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +39 -55
- package/lib/web/firefox_print_service.js +37 -27
- package/lib/web/firefoxcom.js +212 -363
- package/lib/web/genericcom.js +26 -108
- package/lib/web/genericl10n.js +24 -153
- package/lib/web/grab_to_pan.js +32 -30
- package/lib/web/interfaces.js +80 -254
- package/lib/web/overlay_manager.js +70 -246
- package/lib/web/password_prompt.js +38 -64
- package/lib/web/pdf_attachment_viewer.js +113 -131
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +221 -306
- package/lib/web/pdf_find_bar.js +136 -170
- package/lib/web/pdf_find_controller.js +491 -548
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +397 -406
- package/lib/web/pdf_link_service.js +304 -348
- package/lib/web/pdf_outline_viewer.js +140 -175
- package/lib/web/pdf_page_view.js +452 -523
- package/lib/web/pdf_presentation_mode.js +308 -357
- package/lib/web/pdf_print_service.js +90 -104
- package/lib/web/pdf_rendering_queue.js +84 -108
- package/lib/web/pdf_sidebar.js +276 -306
- package/lib/web/pdf_sidebar_resizer.js +92 -119
- package/lib/web/pdf_single_page_viewer.js +77 -126
- package/lib/web/pdf_thumbnail_view.js +276 -297
- package/lib/web/pdf_thumbnail_viewer.js +186 -206
- package/lib/web/pdf_viewer.component.js +20 -21
- package/lib/web/pdf_viewer.js +55 -115
- package/lib/web/preferences.js +82 -286
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +282 -339
- package/lib/web/toolbar.js +217 -210
- package/lib/web/ui_utils.js +267 -420
- package/lib/web/view_history.js +52 -226
- package/lib/web/viewer_compatibility.js +21 -6
- package/package.json +2 -9
- package/web/pdf_viewer.css +35 -25
- package/web/pdf_viewer.js +3489 -4855
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +14 -5
- package/external/streams/streams-lib.js +0 -3962
- package/external/url/url-lib.js +0 -627
- package/lib/display/dom_utils.js +0 -494
- package/lib/shared/streams_polyfill.js +0 -43
- package/lib/shared/url_polyfill.js +0 -56
- package/lib/test/unit/dom_utils_spec.js +0 -89
package/lib/core/colorspace.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
|
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,46 +26,28 @@ Object.defineProperty(exports, "__esModule", {
|
|
26
26
|
});
|
27
27
|
exports.ColorSpace = void 0;
|
28
28
|
|
29
|
-
var _util = require("../shared/util");
|
29
|
+
var _util = require("../shared/util.js");
|
30
30
|
|
31
|
-
var _primitives = require("./primitives");
|
32
|
-
|
33
|
-
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
34
|
-
|
35
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
36
|
-
|
37
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
38
|
-
|
39
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
40
|
-
|
41
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
42
|
-
|
43
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
44
|
-
|
45
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
46
|
-
|
47
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
48
|
-
|
49
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
31
|
+
var _primitives = require("./primitives.js");
|
50
32
|
|
51
33
|
function resizeRgbImage(src, dest, w1, h1, w2, h2, alpha01) {
|
52
|
-
|
34
|
+
const COMPONENTS = 3;
|
53
35
|
alpha01 = alpha01 !== 1 ? 0 : alpha01;
|
54
|
-
|
55
|
-
|
56
|
-
|
36
|
+
const xRatio = w1 / w2;
|
37
|
+
const yRatio = h1 / h2;
|
38
|
+
let newIndex = 0,
|
57
39
|
oldIndex;
|
58
|
-
|
59
|
-
|
40
|
+
const xScaled = new Uint16Array(w2);
|
41
|
+
const w1Scanline = w1 * COMPONENTS;
|
60
42
|
|
61
|
-
for (
|
43
|
+
for (let i = 0; i < w2; i++) {
|
62
44
|
xScaled[i] = Math.floor(i * xRatio) * COMPONENTS;
|
63
45
|
}
|
64
46
|
|
65
|
-
for (
|
66
|
-
|
47
|
+
for (let i = 0; i < h2; i++) {
|
48
|
+
const py = Math.floor(i * yRatio) * w1Scanline;
|
67
49
|
|
68
|
-
for (
|
50
|
+
for (let j = 0; j < w2; j++) {
|
69
51
|
oldIndex = py + xScaled[j];
|
70
52
|
dest[newIndex++] = src[oldIndex++];
|
71
53
|
dest[newIndex++] = src[oldIndex++];
|
@@ -75,806 +57,684 @@ function resizeRgbImage(src, dest, w1, h1, w2, h2, alpha01) {
|
|
75
57
|
}
|
76
58
|
}
|
77
59
|
|
78
|
-
|
79
|
-
|
80
|
-
function () {
|
81
|
-
function ColorSpace(name, numComps) {
|
82
|
-
_classCallCheck(this, ColorSpace);
|
83
|
-
|
60
|
+
class ColorSpace {
|
61
|
+
constructor(name, numComps) {
|
84
62
|
if (this.constructor === ColorSpace) {
|
85
|
-
(0, _util.unreachable)(
|
63
|
+
(0, _util.unreachable)("Cannot initialize ColorSpace.");
|
86
64
|
}
|
87
65
|
|
88
66
|
this.name = name;
|
89
67
|
this.numComps = numComps;
|
90
68
|
}
|
91
69
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
return rgb;
|
98
|
-
}
|
99
|
-
}, {
|
100
|
-
key: "getRgbItem",
|
101
|
-
value: function getRgbItem(src, srcOffset, dest, destOffset) {
|
102
|
-
(0, _util.unreachable)('Should not call ColorSpace.getRgbItem');
|
103
|
-
}
|
104
|
-
}, {
|
105
|
-
key: "getRgbBuffer",
|
106
|
-
value: function getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
|
107
|
-
(0, _util.unreachable)('Should not call ColorSpace.getRgbBuffer');
|
108
|
-
}
|
109
|
-
}, {
|
110
|
-
key: "getOutputLength",
|
111
|
-
value: function getOutputLength(inputLength, alpha01) {
|
112
|
-
(0, _util.unreachable)('Should not call ColorSpace.getOutputLength');
|
113
|
-
}
|
114
|
-
}, {
|
115
|
-
key: "isPassthrough",
|
116
|
-
value: function isPassthrough(bits) {
|
117
|
-
return false;
|
118
|
-
}
|
119
|
-
}, {
|
120
|
-
key: "isDefaultDecode",
|
121
|
-
value: function isDefaultDecode(decodeMap, bpc) {
|
122
|
-
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
123
|
-
}
|
124
|
-
}, {
|
125
|
-
key: "fillRgb",
|
126
|
-
value: function fillRgb(dest, originalWidth, originalHeight, width, height, actualHeight, bpc, comps, alpha01) {
|
127
|
-
var count = originalWidth * originalHeight;
|
128
|
-
var rgbBuf = null;
|
129
|
-
var numComponentColors = 1 << bpc;
|
130
|
-
var needsResizing = originalHeight !== height || originalWidth !== width;
|
131
|
-
|
132
|
-
if (this.isPassthrough(bpc)) {
|
133
|
-
rgbBuf = comps;
|
134
|
-
} else if (this.numComps === 1 && count > numComponentColors && this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
|
135
|
-
var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) : new Uint16Array(numComponentColors);
|
136
|
-
|
137
|
-
for (var i = 0; i < numComponentColors; i++) {
|
138
|
-
allColors[i] = i;
|
139
|
-
}
|
70
|
+
getRgb(src, srcOffset) {
|
71
|
+
const rgb = new Uint8ClampedArray(3);
|
72
|
+
this.getRgbItem(src, srcOffset, rgb, 0);
|
73
|
+
return rgb;
|
74
|
+
}
|
140
75
|
|
141
|
-
|
142
|
-
|
76
|
+
getRgbItem(src, srcOffset, dest, destOffset) {
|
77
|
+
(0, _util.unreachable)("Should not call ColorSpace.getRgbItem");
|
78
|
+
}
|
143
79
|
|
144
|
-
|
145
|
-
|
80
|
+
getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
|
81
|
+
(0, _util.unreachable)("Should not call ColorSpace.getRgbBuffer");
|
82
|
+
}
|
146
83
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
dest[destPos++] = colorMap[key + 1];
|
151
|
-
dest[destPos++] = colorMap[key + 2];
|
152
|
-
destPos += alpha01;
|
153
|
-
}
|
154
|
-
} else {
|
155
|
-
rgbBuf = new Uint8Array(count * 3);
|
156
|
-
var rgbPos = 0;
|
84
|
+
getOutputLength(inputLength, alpha01) {
|
85
|
+
(0, _util.unreachable)("Should not call ColorSpace.getOutputLength");
|
86
|
+
}
|
157
87
|
|
158
|
-
|
159
|
-
|
88
|
+
isPassthrough(bits) {
|
89
|
+
return false;
|
90
|
+
}
|
160
91
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
92
|
+
isDefaultDecode(decodeMap, bpc) {
|
93
|
+
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
94
|
+
}
|
95
|
+
|
96
|
+
fillRgb(dest, originalWidth, originalHeight, width, height, actualHeight, bpc, comps, alpha01) {
|
97
|
+
const count = originalWidth * originalHeight;
|
98
|
+
let rgbBuf = null;
|
99
|
+
const numComponentColors = 1 << bpc;
|
100
|
+
const needsResizing = originalHeight !== height || originalWidth !== width;
|
101
|
+
|
102
|
+
if (this.isPassthrough(bpc)) {
|
103
|
+
rgbBuf = comps;
|
104
|
+
} else if (this.numComps === 1 && count > numComponentColors && this.name !== "DeviceGray" && this.name !== "DeviceRGB") {
|
105
|
+
const allColors = bpc <= 8 ? new Uint8Array(numComponentColors) : new Uint16Array(numComponentColors);
|
106
|
+
|
107
|
+
for (let i = 0; i < numComponentColors; i++) {
|
108
|
+
allColors[i] = i;
|
109
|
+
}
|
110
|
+
|
111
|
+
const colorMap = new Uint8ClampedArray(numComponentColors * 3);
|
112
|
+
this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc, 0);
|
113
|
+
|
114
|
+
if (!needsResizing) {
|
115
|
+
let destPos = 0;
|
116
|
+
|
117
|
+
for (let i = 0; i < count; ++i) {
|
118
|
+
const key = comps[i] * 3;
|
119
|
+
dest[destPos++] = colorMap[key];
|
120
|
+
dest[destPos++] = colorMap[key + 1];
|
121
|
+
dest[destPos++] = colorMap[key + 2];
|
122
|
+
destPos += alpha01;
|
165
123
|
}
|
166
124
|
} else {
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
125
|
+
rgbBuf = new Uint8Array(count * 3);
|
126
|
+
let rgbPos = 0;
|
127
|
+
|
128
|
+
for (let i = 0; i < count; ++i) {
|
129
|
+
const key = comps[i] * 3;
|
130
|
+
rgbBuf[rgbPos++] = colorMap[key];
|
131
|
+
rgbBuf[rgbPos++] = colorMap[key + 1];
|
132
|
+
rgbBuf[rgbPos++] = colorMap[key + 2];
|
172
133
|
}
|
173
134
|
}
|
135
|
+
} else {
|
136
|
+
if (!needsResizing) {
|
137
|
+
this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc, alpha01);
|
138
|
+
} else {
|
139
|
+
rgbBuf = new Uint8ClampedArray(count * 3);
|
140
|
+
this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc, 0);
|
141
|
+
}
|
142
|
+
}
|
174
143
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
}
|
144
|
+
if (rgbBuf) {
|
145
|
+
if (needsResizing) {
|
146
|
+
resizeRgbImage(rgbBuf, dest, originalWidth, originalHeight, width, height, alpha01);
|
147
|
+
} else {
|
148
|
+
let destPos = 0,
|
149
|
+
rgbPos = 0;
|
150
|
+
|
151
|
+
for (let i = 0, ii = width * actualHeight; i < ii; i++) {
|
152
|
+
dest[destPos++] = rgbBuf[rgbPos++];
|
153
|
+
dest[destPos++] = rgbBuf[rgbPos++];
|
154
|
+
dest[destPos++] = rgbBuf[rgbPos++];
|
155
|
+
destPos += alpha01;
|
188
156
|
}
|
189
157
|
}
|
190
158
|
}
|
191
|
-
}
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
159
|
+
}
|
160
|
+
|
161
|
+
get usesZeroToOneRange() {
|
162
|
+
return (0, _util.shadow)(this, "usesZeroToOneRange", true);
|
163
|
+
}
|
164
|
+
|
165
|
+
static parse(cs, xref, res, pdfFunctionFactory) {
|
166
|
+
const IR = this.parseToIR(cs, xref, res, pdfFunctionFactory);
|
167
|
+
return this.fromIR(IR);
|
168
|
+
}
|
169
|
+
|
170
|
+
static fromIR(IR) {
|
171
|
+
const name = Array.isArray(IR) ? IR[0] : IR;
|
172
|
+
let whitePoint, blackPoint, gamma;
|
173
|
+
|
174
|
+
switch (name) {
|
175
|
+
case "DeviceGrayCS":
|
176
|
+
return this.singletons.gray;
|
177
|
+
|
178
|
+
case "DeviceRgbCS":
|
179
|
+
return this.singletons.rgb;
|
180
|
+
|
181
|
+
case "DeviceCmykCS":
|
182
|
+
return this.singletons.cmyk;
|
183
|
+
|
184
|
+
case "CalGrayCS":
|
185
|
+
whitePoint = IR[1];
|
186
|
+
blackPoint = IR[2];
|
187
|
+
gamma = IR[3];
|
188
|
+
return new CalGrayCS(whitePoint, blackPoint, gamma);
|
189
|
+
|
190
|
+
case "CalRGBCS":
|
191
|
+
whitePoint = IR[1];
|
192
|
+
blackPoint = IR[2];
|
193
|
+
gamma = IR[3];
|
194
|
+
const matrix = IR[4];
|
195
|
+
return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
|
196
|
+
|
197
|
+
case "PatternCS":
|
198
|
+
let basePatternCS = IR[1];
|
199
|
+
|
200
|
+
if (basePatternCS) {
|
201
|
+
basePatternCS = this.fromIR(basePatternCS);
|
202
|
+
}
|
203
|
+
|
204
|
+
return new PatternCS(basePatternCS);
|
205
|
+
|
206
|
+
case "IndexedCS":
|
207
|
+
const baseIndexedCS = IR[1];
|
208
|
+
const hiVal = IR[2];
|
209
|
+
const lookup = IR[3];
|
210
|
+
return new IndexedCS(this.fromIR(baseIndexedCS), hiVal, lookup);
|
211
|
+
|
212
|
+
case "AlternateCS":
|
213
|
+
const numComps = IR[1];
|
214
|
+
const alt = IR[2];
|
215
|
+
const tintFn = IR[3];
|
216
|
+
return new AlternateCS(numComps, this.fromIR(alt), tintFn);
|
217
|
+
|
218
|
+
case "LabCS":
|
219
|
+
whitePoint = IR[1];
|
220
|
+
blackPoint = IR[2];
|
221
|
+
const range = IR[3];
|
222
|
+
return new LabCS(whitePoint, blackPoint, range);
|
223
|
+
|
224
|
+
default:
|
225
|
+
throw new _util.FormatError(`Unknown colorspace name: ${name}`);
|
201
226
|
}
|
202
|
-
}
|
203
|
-
key: "fromIR",
|
204
|
-
value: function fromIR(IR) {
|
205
|
-
var name = Array.isArray(IR) ? IR[0] : IR;
|
206
|
-
var whitePoint, blackPoint, gamma;
|
207
|
-
|
208
|
-
switch (name) {
|
209
|
-
case 'DeviceGrayCS':
|
210
|
-
return this.singletons.gray;
|
211
|
-
|
212
|
-
case 'DeviceRgbCS':
|
213
|
-
return this.singletons.rgb;
|
214
|
-
|
215
|
-
case 'DeviceCmykCS':
|
216
|
-
return this.singletons.cmyk;
|
217
|
-
|
218
|
-
case 'CalGrayCS':
|
219
|
-
whitePoint = IR[1];
|
220
|
-
blackPoint = IR[2];
|
221
|
-
gamma = IR[3];
|
222
|
-
return new CalGrayCS(whitePoint, blackPoint, gamma);
|
223
|
-
|
224
|
-
case 'CalRGBCS':
|
225
|
-
whitePoint = IR[1];
|
226
|
-
blackPoint = IR[2];
|
227
|
-
gamma = IR[3];
|
228
|
-
var matrix = IR[4];
|
229
|
-
return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
|
230
|
-
|
231
|
-
case 'PatternCS':
|
232
|
-
var basePatternCS = IR[1];
|
227
|
+
}
|
233
228
|
|
234
|
-
|
235
|
-
|
236
|
-
}
|
229
|
+
static parseToIR(cs, xref, res = null, pdfFunctionFactory) {
|
230
|
+
cs = xref.fetchIfRef(cs);
|
237
231
|
|
238
|
-
|
232
|
+
if ((0, _primitives.isName)(cs)) {
|
233
|
+
switch (cs.name) {
|
234
|
+
case "DeviceGray":
|
235
|
+
case "G":
|
236
|
+
return "DeviceGrayCS";
|
239
237
|
|
240
|
-
case
|
241
|
-
|
242
|
-
|
243
|
-
var lookup = IR[3];
|
244
|
-
return new IndexedCS(this.fromIR(baseIndexedCS), hiVal, lookup);
|
238
|
+
case "DeviceRGB":
|
239
|
+
case "RGB":
|
240
|
+
return "DeviceRgbCS";
|
245
241
|
|
246
|
-
case
|
247
|
-
|
248
|
-
|
249
|
-
var tintFn = IR[3];
|
250
|
-
return new AlternateCS(numComps, this.fromIR(alt), tintFn);
|
242
|
+
case "DeviceCMYK":
|
243
|
+
case "CMYK":
|
244
|
+
return "DeviceCmykCS";
|
251
245
|
|
252
|
-
case
|
253
|
-
|
254
|
-
blackPoint = IR[2];
|
255
|
-
var range = IR[3];
|
256
|
-
return new LabCS(whitePoint, blackPoint, range);
|
246
|
+
case "Pattern":
|
247
|
+
return ["PatternCS", null];
|
257
248
|
|
258
249
|
default:
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
if ((0, _primitives.isName)(cs)) {
|
270
|
-
switch (cs.name) {
|
271
|
-
case 'DeviceGray':
|
272
|
-
case 'G':
|
273
|
-
return 'DeviceGrayCS';
|
274
|
-
|
275
|
-
case 'DeviceRGB':
|
276
|
-
case 'RGB':
|
277
|
-
return 'DeviceRgbCS';
|
278
|
-
|
279
|
-
case 'DeviceCMYK':
|
280
|
-
case 'CMYK':
|
281
|
-
return 'DeviceCmykCS';
|
282
|
-
|
283
|
-
case 'Pattern':
|
284
|
-
return ['PatternCS', null];
|
285
|
-
|
286
|
-
default:
|
287
|
-
if ((0, _primitives.isDict)(res)) {
|
288
|
-
var colorSpaces = res.get('ColorSpace');
|
289
|
-
|
290
|
-
if ((0, _primitives.isDict)(colorSpaces)) {
|
291
|
-
var resCS = colorSpaces.get(cs.name);
|
292
|
-
|
293
|
-
if (resCS) {
|
294
|
-
if ((0, _primitives.isName)(resCS)) {
|
295
|
-
return this.parseToIR(resCS, xref, res, pdfFunctionFactory);
|
296
|
-
}
|
297
|
-
|
298
|
-
cs = resCS;
|
299
|
-
break;
|
250
|
+
if ((0, _primitives.isDict)(res)) {
|
251
|
+
const colorSpaces = res.get("ColorSpace");
|
252
|
+
|
253
|
+
if ((0, _primitives.isDict)(colorSpaces)) {
|
254
|
+
const resCS = colorSpaces.get(cs.name);
|
255
|
+
|
256
|
+
if (resCS) {
|
257
|
+
if ((0, _primitives.isName)(resCS)) {
|
258
|
+
return this.parseToIR(resCS, xref, res, pdfFunctionFactory);
|
300
259
|
}
|
260
|
+
|
261
|
+
cs = resCS;
|
262
|
+
break;
|
301
263
|
}
|
302
264
|
}
|
265
|
+
}
|
303
266
|
|
304
|
-
|
305
|
-
}
|
267
|
+
throw new _util.FormatError(`unrecognized colorspace ${cs.name}`);
|
306
268
|
}
|
269
|
+
}
|
307
270
|
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
}
|
353
|
-
|
354
|
-
(0, _util.warn)('ICCBased color space: Ignoring incorrect /Alternate entry.');
|
271
|
+
if (Array.isArray(cs)) {
|
272
|
+
const mode = xref.fetchIfRef(cs[0]).name;
|
273
|
+
let numComps, params, alt, whitePoint, blackPoint, gamma;
|
274
|
+
|
275
|
+
switch (mode) {
|
276
|
+
case "DeviceGray":
|
277
|
+
case "G":
|
278
|
+
return "DeviceGrayCS";
|
279
|
+
|
280
|
+
case "DeviceRGB":
|
281
|
+
case "RGB":
|
282
|
+
return "DeviceRgbCS";
|
283
|
+
|
284
|
+
case "DeviceCMYK":
|
285
|
+
case "CMYK":
|
286
|
+
return "DeviceCmykCS";
|
287
|
+
|
288
|
+
case "CalGray":
|
289
|
+
params = xref.fetchIfRef(cs[1]);
|
290
|
+
whitePoint = params.getArray("WhitePoint");
|
291
|
+
blackPoint = params.getArray("BlackPoint");
|
292
|
+
gamma = params.get("Gamma");
|
293
|
+
return ["CalGrayCS", whitePoint, blackPoint, gamma];
|
294
|
+
|
295
|
+
case "CalRGB":
|
296
|
+
params = xref.fetchIfRef(cs[1]);
|
297
|
+
whitePoint = params.getArray("WhitePoint");
|
298
|
+
blackPoint = params.getArray("BlackPoint");
|
299
|
+
gamma = params.getArray("Gamma");
|
300
|
+
const matrix = params.getArray("Matrix");
|
301
|
+
return ["CalRGBCS", whitePoint, blackPoint, gamma, matrix];
|
302
|
+
|
303
|
+
case "ICCBased":
|
304
|
+
const stream = xref.fetchIfRef(cs[1]);
|
305
|
+
const dict = stream.dict;
|
306
|
+
numComps = dict.get("N");
|
307
|
+
alt = dict.get("Alternate");
|
308
|
+
|
309
|
+
if (alt) {
|
310
|
+
const altIR = this.parseToIR(alt, xref, res, pdfFunctionFactory);
|
311
|
+
const altCS = this.fromIR(altIR, pdfFunctionFactory);
|
312
|
+
|
313
|
+
if (altCS.numComps === numComps) {
|
314
|
+
return altIR;
|
355
315
|
}
|
356
316
|
|
357
|
-
|
358
|
-
|
359
|
-
} else if (numComps === 3) {
|
360
|
-
return 'DeviceRgbCS';
|
361
|
-
} else if (numComps === 4) {
|
362
|
-
return 'DeviceCmykCS';
|
363
|
-
}
|
317
|
+
(0, _util.warn)("ICCBased color space: Ignoring incorrect /Alternate entry.");
|
318
|
+
}
|
364
319
|
|
365
|
-
|
320
|
+
if (numComps === 1) {
|
321
|
+
return "DeviceGrayCS";
|
322
|
+
} else if (numComps === 3) {
|
323
|
+
return "DeviceRgbCS";
|
324
|
+
} else if (numComps === 4) {
|
325
|
+
return "DeviceCmykCS";
|
326
|
+
}
|
366
327
|
|
367
|
-
|
368
|
-
var basePatternCS = cs[1] || null;
|
328
|
+
break;
|
369
329
|
|
370
|
-
|
371
|
-
|
372
|
-
}
|
330
|
+
case "Pattern":
|
331
|
+
let basePatternCS = cs[1] || null;
|
373
332
|
|
374
|
-
|
333
|
+
if (basePatternCS) {
|
334
|
+
basePatternCS = this.parseToIR(basePatternCS, xref, res, pdfFunctionFactory);
|
335
|
+
}
|
375
336
|
|
376
|
-
|
377
|
-
case 'I':
|
378
|
-
var baseIndexedCS = this.parseToIR(cs[1], xref, res, pdfFunctionFactory);
|
379
|
-
var hiVal = xref.fetchIfRef(cs[2]) + 1;
|
380
|
-
var lookup = xref.fetchIfRef(cs[3]);
|
337
|
+
return ["PatternCS", basePatternCS];
|
381
338
|
|
382
|
-
|
383
|
-
|
384
|
-
|
339
|
+
case "Indexed":
|
340
|
+
case "I":
|
341
|
+
const baseIndexedCS = this.parseToIR(cs[1], xref, res, pdfFunctionFactory);
|
342
|
+
const hiVal = xref.fetchIfRef(cs[2]) + 1;
|
343
|
+
let lookup = xref.fetchIfRef(cs[3]);
|
385
344
|
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
case 'DeviceN':
|
390
|
-
var name = xref.fetchIfRef(cs[1]);
|
391
|
-
numComps = Array.isArray(name) ? name.length : 1;
|
392
|
-
alt = this.parseToIR(cs[2], xref, res, pdfFunctionFactory);
|
393
|
-
var tintFn = pdfFunctionFactory.create(xref.fetchIfRef(cs[3]));
|
394
|
-
return ['AlternateCS', numComps, alt, tintFn];
|
395
|
-
|
396
|
-
case 'Lab':
|
397
|
-
params = xref.fetchIfRef(cs[1]);
|
398
|
-
whitePoint = params.getArray('WhitePoint');
|
399
|
-
blackPoint = params.getArray('BlackPoint');
|
400
|
-
var range = params.getArray('Range');
|
401
|
-
return ['LabCS', whitePoint, blackPoint, range];
|
402
|
-
|
403
|
-
default:
|
404
|
-
throw new _util.FormatError("unimplemented color space object \"".concat(mode, "\""));
|
405
|
-
}
|
406
|
-
}
|
345
|
+
if ((0, _primitives.isStream)(lookup)) {
|
346
|
+
lookup = lookup.getBytes();
|
347
|
+
}
|
407
348
|
|
408
|
-
|
409
|
-
}
|
410
|
-
}, {
|
411
|
-
key: "isDefaultDecode",
|
412
|
-
value: function isDefaultDecode(decode, numComps) {
|
413
|
-
if (!Array.isArray(decode)) {
|
414
|
-
return true;
|
415
|
-
}
|
349
|
+
return ["IndexedCS", baseIndexedCS, hiVal, lookup];
|
416
350
|
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
351
|
+
case "Separation":
|
352
|
+
case "DeviceN":
|
353
|
+
const name = xref.fetchIfRef(cs[1]);
|
354
|
+
numComps = Array.isArray(name) ? name.length : 1;
|
355
|
+
alt = this.parseToIR(cs[2], xref, res, pdfFunctionFactory);
|
356
|
+
const tintFn = pdfFunctionFactory.create(xref.fetchIfRef(cs[3]));
|
357
|
+
return ["AlternateCS", numComps, alt, tintFn];
|
421
358
|
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
359
|
+
case "Lab":
|
360
|
+
params = xref.fetchIfRef(cs[1]);
|
361
|
+
whitePoint = params.getArray("WhitePoint");
|
362
|
+
blackPoint = params.getArray("BlackPoint");
|
363
|
+
const range = params.getArray("Range");
|
364
|
+
return ["LabCS", whitePoint, blackPoint, range];
|
365
|
+
|
366
|
+
default:
|
367
|
+
throw new _util.FormatError(`unimplemented color space object "${mode}"`);
|
426
368
|
}
|
369
|
+
}
|
427
370
|
|
371
|
+
throw new _util.FormatError(`unrecognized color space object: "${cs}"`);
|
372
|
+
}
|
373
|
+
|
374
|
+
static isDefaultDecode(decode, numComps) {
|
375
|
+
if (!Array.isArray(decode)) {
|
428
376
|
return true;
|
429
377
|
}
|
430
|
-
}, {
|
431
|
-
key: "singletons",
|
432
|
-
get: function get() {
|
433
|
-
return (0, _util.shadow)(this, 'singletons', {
|
434
|
-
get gray() {
|
435
|
-
return (0, _util.shadow)(this, 'gray', new DeviceGrayCS());
|
436
|
-
},
|
437
|
-
|
438
|
-
get rgb() {
|
439
|
-
return (0, _util.shadow)(this, 'rgb', new DeviceRgbCS());
|
440
|
-
},
|
441
|
-
|
442
|
-
get cmyk() {
|
443
|
-
return (0, _util.shadow)(this, 'cmyk', new DeviceCmykCS());
|
444
|
-
}
|
445
378
|
|
446
|
-
|
379
|
+
if (numComps * 2 !== decode.length) {
|
380
|
+
(0, _util.warn)("The decode map is not the correct length");
|
381
|
+
return true;
|
447
382
|
}
|
448
|
-
}]);
|
449
383
|
|
450
|
-
|
451
|
-
|
384
|
+
for (let i = 0, ii = decode.length; i < ii; i += 2) {
|
385
|
+
if (decode[i] !== 0 || decode[i + 1] !== 1) {
|
386
|
+
return false;
|
387
|
+
}
|
388
|
+
}
|
452
389
|
|
453
|
-
|
390
|
+
return true;
|
391
|
+
}
|
454
392
|
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
393
|
+
static get singletons() {
|
394
|
+
return (0, _util.shadow)(this, "singletons", {
|
395
|
+
get gray() {
|
396
|
+
return (0, _util.shadow)(this, "gray", new DeviceGrayCS());
|
397
|
+
},
|
459
398
|
|
460
|
-
|
461
|
-
|
399
|
+
get rgb() {
|
400
|
+
return (0, _util.shadow)(this, "rgb", new DeviceRgbCS());
|
401
|
+
},
|
462
402
|
|
463
|
-
|
403
|
+
get cmyk() {
|
404
|
+
return (0, _util.shadow)(this, "cmyk", new DeviceCmykCS());
|
405
|
+
}
|
464
406
|
|
465
|
-
|
466
|
-
_this.base = base;
|
467
|
-
_this.tintFn = tintFn;
|
468
|
-
_this.tmpBuf = new Float32Array(base.numComps);
|
469
|
-
return _this;
|
407
|
+
});
|
470
408
|
}
|
471
409
|
|
472
|
-
|
473
|
-
key: "getRgbItem",
|
474
|
-
value: function getRgbItem(src, srcOffset, dest, destOffset) {
|
475
|
-
var tmpBuf = this.tmpBuf;
|
476
|
-
this.tintFn(src, srcOffset, tmpBuf, 0);
|
477
|
-
this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
|
478
|
-
}
|
479
|
-
}, {
|
480
|
-
key: "getRgbBuffer",
|
481
|
-
value: function getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
|
482
|
-
var tintFn = this.tintFn;
|
483
|
-
var base = this.base;
|
484
|
-
var scale = 1 / ((1 << bits) - 1);
|
485
|
-
var baseNumComps = base.numComps;
|
486
|
-
var usesZeroToOneRange = base.usesZeroToOneRange;
|
487
|
-
var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) && alpha01 === 0;
|
488
|
-
var pos = isPassthrough ? destOffset : 0;
|
489
|
-
var baseBuf = isPassthrough ? dest : new Uint8ClampedArray(baseNumComps * count);
|
490
|
-
var numComps = this.numComps;
|
491
|
-
var scaled = new Float32Array(numComps);
|
492
|
-
var tinted = new Float32Array(baseNumComps);
|
493
|
-
var i, j;
|
494
|
-
|
495
|
-
for (i = 0; i < count; i++) {
|
496
|
-
for (j = 0; j < numComps; j++) {
|
497
|
-
scaled[j] = src[srcOffset++] * scale;
|
498
|
-
}
|
499
|
-
|
500
|
-
tintFn(scaled, 0, tinted, 0);
|
410
|
+
}
|
501
411
|
|
502
|
-
|
503
|
-
for (j = 0; j < baseNumComps; j++) {
|
504
|
-
baseBuf[pos++] = tinted[j] * 255;
|
505
|
-
}
|
506
|
-
} else {
|
507
|
-
base.getRgbItem(tinted, 0, baseBuf, pos);
|
508
|
-
pos += baseNumComps;
|
509
|
-
}
|
510
|
-
}
|
412
|
+
exports.ColorSpace = ColorSpace;
|
511
413
|
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
return this.base.getOutputLength(inputLength * this.base.numComps / this.numComps, alpha01);
|
520
|
-
}
|
521
|
-
}]);
|
414
|
+
class AlternateCS extends ColorSpace {
|
415
|
+
constructor(numComps, base, tintFn) {
|
416
|
+
super("Alternate", numComps);
|
417
|
+
this.base = base;
|
418
|
+
this.tintFn = tintFn;
|
419
|
+
this.tmpBuf = new Float32Array(base.numComps);
|
420
|
+
}
|
522
421
|
|
523
|
-
|
524
|
-
|
422
|
+
getRgbItem(src, srcOffset, dest, destOffset) {
|
423
|
+
const tmpBuf = this.tmpBuf;
|
424
|
+
this.tintFn(src, srcOffset, tmpBuf, 0);
|
425
|
+
this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
|
426
|
+
}
|
525
427
|
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
428
|
+
getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
|
429
|
+
const tintFn = this.tintFn;
|
430
|
+
const base = this.base;
|
431
|
+
const scale = 1 / ((1 << bits) - 1);
|
432
|
+
const baseNumComps = base.numComps;
|
433
|
+
const usesZeroToOneRange = base.usesZeroToOneRange;
|
434
|
+
const isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) && alpha01 === 0;
|
435
|
+
let pos = isPassthrough ? destOffset : 0;
|
436
|
+
const baseBuf = isPassthrough ? dest : new Uint8ClampedArray(baseNumComps * count);
|
437
|
+
const numComps = this.numComps;
|
438
|
+
const scaled = new Float32Array(numComps);
|
439
|
+
const tinted = new Float32Array(baseNumComps);
|
440
|
+
let i, j;
|
441
|
+
|
442
|
+
for (i = 0; i < count; i++) {
|
443
|
+
for (j = 0; j < numComps; j++) {
|
444
|
+
scaled[j] = src[srcOffset++] * scale;
|
445
|
+
}
|
530
446
|
|
531
|
-
|
532
|
-
var _this2;
|
447
|
+
tintFn(scaled, 0, tinted, 0);
|
533
448
|
|
534
|
-
|
449
|
+
if (usesZeroToOneRange) {
|
450
|
+
for (j = 0; j < baseNumComps; j++) {
|
451
|
+
baseBuf[pos++] = tinted[j] * 255;
|
452
|
+
}
|
453
|
+
} else {
|
454
|
+
base.getRgbItem(tinted, 0, baseBuf, pos);
|
455
|
+
pos += baseNumComps;
|
456
|
+
}
|
457
|
+
}
|
535
458
|
|
536
|
-
|
537
|
-
|
538
|
-
|
459
|
+
if (!isPassthrough) {
|
460
|
+
base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
|
461
|
+
}
|
539
462
|
}
|
540
463
|
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
(0, _util.unreachable)('Should not call PatternCS.isDefaultDecode');
|
545
|
-
}
|
546
|
-
}]);
|
464
|
+
getOutputLength(inputLength, alpha01) {
|
465
|
+
return this.base.getOutputLength(inputLength * this.base.numComps / this.numComps, alpha01);
|
466
|
+
}
|
547
467
|
|
548
|
-
|
549
|
-
}(ColorSpace);
|
468
|
+
}
|
550
469
|
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
470
|
+
class PatternCS extends ColorSpace {
|
471
|
+
constructor(baseCS) {
|
472
|
+
super("Pattern", null);
|
473
|
+
this.base = baseCS;
|
474
|
+
}
|
555
475
|
|
556
|
-
|
557
|
-
|
476
|
+
isDefaultDecode(decodeMap, bpc) {
|
477
|
+
(0, _util.unreachable)("Should not call PatternCS.isDefaultDecode");
|
478
|
+
}
|
558
479
|
|
559
|
-
|
480
|
+
}
|
560
481
|
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
482
|
+
class IndexedCS extends ColorSpace {
|
483
|
+
constructor(base, highVal, lookup) {
|
484
|
+
super("Indexed", 1);
|
485
|
+
this.base = base;
|
486
|
+
this.highVal = highVal;
|
487
|
+
const baseNumComps = base.numComps;
|
488
|
+
const length = baseNumComps * highVal;
|
566
489
|
|
567
490
|
if ((0, _primitives.isStream)(lookup)) {
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
_this3.lookup.set(bytes);
|
491
|
+
this.lookup = new Uint8Array(length);
|
492
|
+
const bytes = lookup.getBytes(length);
|
493
|
+
this.lookup.set(bytes);
|
572
494
|
} else if ((0, _util.isString)(lookup)) {
|
573
|
-
|
495
|
+
this.lookup = new Uint8Array(length);
|
574
496
|
|
575
|
-
for (
|
576
|
-
|
497
|
+
for (let i = 0; i < length; ++i) {
|
498
|
+
this.lookup[i] = lookup.charCodeAt(i);
|
577
499
|
}
|
578
500
|
} else if (lookup instanceof Uint8Array) {
|
579
|
-
|
501
|
+
this.lookup = lookup;
|
580
502
|
} else {
|
581
|
-
throw new _util.FormatError(
|
503
|
+
throw new _util.FormatError(`Unrecognized lookup table: ${lookup}`);
|
582
504
|
}
|
505
|
+
}
|
583
506
|
|
584
|
-
|
507
|
+
getRgbItem(src, srcOffset, dest, destOffset) {
|
508
|
+
const numComps = this.base.numComps;
|
509
|
+
const start = src[srcOffset] * numComps;
|
510
|
+
this.base.getRgbBuffer(this.lookup, start, 1, dest, destOffset, 8, 0);
|
585
511
|
}
|
586
512
|
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
var base = this.base;
|
598
|
-
var numComps = base.numComps;
|
599
|
-
var outputDelta = base.getOutputLength(numComps, alpha01);
|
600
|
-
var lookup = this.lookup;
|
601
|
-
|
602
|
-
for (var i = 0; i < count; ++i) {
|
603
|
-
var lookupPos = src[srcOffset++] * numComps;
|
604
|
-
base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
|
605
|
-
destOffset += outputDelta;
|
606
|
-
}
|
607
|
-
}
|
608
|
-
}, {
|
609
|
-
key: "getOutputLength",
|
610
|
-
value: function getOutputLength(inputLength, alpha01) {
|
611
|
-
return this.base.getOutputLength(inputLength * this.base.numComps, alpha01);
|
513
|
+
getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
|
514
|
+
const base = this.base;
|
515
|
+
const numComps = base.numComps;
|
516
|
+
const outputDelta = base.getOutputLength(numComps, alpha01);
|
517
|
+
const lookup = this.lookup;
|
518
|
+
|
519
|
+
for (let i = 0; i < count; ++i) {
|
520
|
+
const lookupPos = src[srcOffset++] * numComps;
|
521
|
+
base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
|
522
|
+
destOffset += outputDelta;
|
612
523
|
}
|
613
|
-
}
|
614
|
-
key: "isDefaultDecode",
|
615
|
-
value: function isDefaultDecode(decodeMap, bpc) {
|
616
|
-
if (!Array.isArray(decodeMap)) {
|
617
|
-
return true;
|
618
|
-
}
|
524
|
+
}
|
619
525
|
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
}
|
526
|
+
getOutputLength(inputLength, alpha01) {
|
527
|
+
return this.base.getOutputLength(inputLength * this.base.numComps, alpha01);
|
528
|
+
}
|
624
529
|
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
530
|
+
isDefaultDecode(decodeMap, bpc) {
|
531
|
+
if (!Array.isArray(decodeMap)) {
|
532
|
+
return true;
|
533
|
+
}
|
629
534
|
|
630
|
-
|
535
|
+
if (decodeMap.length !== 2) {
|
536
|
+
(0, _util.warn)("Decode map length is not correct");
|
537
|
+
return true;
|
538
|
+
}
|
539
|
+
|
540
|
+
if (!Number.isInteger(bpc) || bpc < 1) {
|
541
|
+
(0, _util.warn)("Bits per component is not correct");
|
542
|
+
return true;
|
631
543
|
}
|
632
|
-
}]);
|
633
544
|
|
634
|
-
|
635
|
-
}
|
545
|
+
return decodeMap[0] === 0 && decodeMap[1] === (1 << bpc) - 1;
|
546
|
+
}
|
636
547
|
|
637
|
-
|
638
|
-
/*#__PURE__*/
|
639
|
-
function (_ColorSpace4) {
|
640
|
-
_inherits(DeviceGrayCS, _ColorSpace4);
|
548
|
+
}
|
641
549
|
|
642
|
-
|
643
|
-
|
550
|
+
class DeviceGrayCS extends ColorSpace {
|
551
|
+
constructor() {
|
552
|
+
super("DeviceGray", 1);
|
553
|
+
}
|
644
554
|
|
645
|
-
|
555
|
+
getRgbItem(src, srcOffset, dest, destOffset) {
|
556
|
+
const c = src[srcOffset] * 255;
|
557
|
+
dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
|
646
558
|
}
|
647
559
|
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
q = destOffset;
|
660
|
-
|
661
|
-
for (var i = 0; i < count; ++i) {
|
662
|
-
var c = scale * src[j++];
|
663
|
-
dest[q++] = c;
|
664
|
-
dest[q++] = c;
|
665
|
-
dest[q++] = c;
|
666
|
-
q += alpha01;
|
667
|
-
}
|
668
|
-
}
|
669
|
-
}, {
|
670
|
-
key: "getOutputLength",
|
671
|
-
value: function getOutputLength(inputLength, alpha01) {
|
672
|
-
return inputLength * (3 + alpha01);
|
560
|
+
getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
|
561
|
+
const scale = 255 / ((1 << bits) - 1);
|
562
|
+
let j = srcOffset,
|
563
|
+
q = destOffset;
|
564
|
+
|
565
|
+
for (let i = 0; i < count; ++i) {
|
566
|
+
const c = scale * src[j++];
|
567
|
+
dest[q++] = c;
|
568
|
+
dest[q++] = c;
|
569
|
+
dest[q++] = c;
|
570
|
+
q += alpha01;
|
673
571
|
}
|
674
|
-
}
|
572
|
+
}
|
675
573
|
|
676
|
-
|
677
|
-
|
574
|
+
getOutputLength(inputLength, alpha01) {
|
575
|
+
return inputLength * (3 + alpha01);
|
576
|
+
}
|
678
577
|
|
679
|
-
|
680
|
-
/*#__PURE__*/
|
681
|
-
function (_ColorSpace5) {
|
682
|
-
_inherits(DeviceRgbCS, _ColorSpace5);
|
578
|
+
}
|
683
579
|
|
684
|
-
|
685
|
-
|
580
|
+
class DeviceRgbCS extends ColorSpace {
|
581
|
+
constructor() {
|
582
|
+
super("DeviceRGB", 3);
|
583
|
+
}
|
686
584
|
|
687
|
-
|
585
|
+
getRgbItem(src, srcOffset, dest, destOffset) {
|
586
|
+
dest[destOffset] = src[srcOffset] * 255;
|
587
|
+
dest[destOffset + 1] = src[srcOffset + 1] * 255;
|
588
|
+
dest[destOffset + 2] = src[srcOffset + 2] * 255;
|
688
589
|
}
|
689
590
|
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
dest[destOffset + 1] = src[srcOffset + 1] * 255;
|
695
|
-
dest[destOffset + 2] = src[srcOffset + 2] * 255;
|
591
|
+
getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
|
592
|
+
if (bits === 8 && alpha01 === 0) {
|
593
|
+
dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
|
594
|
+
return;
|
696
595
|
}
|
697
|
-
}, {
|
698
|
-
key: "getRgbBuffer",
|
699
|
-
value: function getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
|
700
|
-
if (bits === 8 && alpha01 === 0) {
|
701
|
-
dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
|
702
|
-
return;
|
703
|
-
}
|
704
596
|
|
705
|
-
|
706
|
-
|
707
|
-
|
597
|
+
const scale = 255 / ((1 << bits) - 1);
|
598
|
+
let j = srcOffset,
|
599
|
+
q = destOffset;
|
708
600
|
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
}
|
601
|
+
for (let i = 0; i < count; ++i) {
|
602
|
+
dest[q++] = scale * src[j++];
|
603
|
+
dest[q++] = scale * src[j++];
|
604
|
+
dest[q++] = scale * src[j++];
|
605
|
+
q += alpha01;
|
715
606
|
}
|
716
|
-
}
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
}
|
726
|
-
}]);
|
607
|
+
}
|
608
|
+
|
609
|
+
getOutputLength(inputLength, alpha01) {
|
610
|
+
return inputLength * (3 + alpha01) / 3 | 0;
|
611
|
+
}
|
612
|
+
|
613
|
+
isPassthrough(bits) {
|
614
|
+
return bits === 8;
|
615
|
+
}
|
727
616
|
|
728
|
-
|
729
|
-
}(ColorSpace);
|
617
|
+
}
|
730
618
|
|
731
|
-
|
619
|
+
const DeviceCmykCS = function DeviceCmykCSClosure() {
|
732
620
|
function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
621
|
+
const c = src[srcOffset] * srcScale;
|
622
|
+
const m = src[srcOffset + 1] * srcScale;
|
623
|
+
const y = src[srcOffset + 2] * srcScale;
|
624
|
+
const k = src[srcOffset + 3] * srcScale;
|
737
625
|
dest[destOffset] = 255 + c * (-4.387332384609988 * c + 54.48615194189176 * m + 18.82290502165302 * y + 212.25662451639585 * k + -285.2331026137004) + m * (1.7149763477362134 * m - 5.6096736904047315 * y + -17.873870861415444 * k - 5.497006427196366) + y * (-2.5217340131683033 * y - 21.248923337353073 * k + 17.5119270841813) + k * (-21.86122147463605 * k - 189.48180835922747);
|
738
626
|
dest[destOffset + 1] = 255 + c * (8.841041422036149 * c + 60.118027045597366 * m + 6.871425592049007 * y + 31.159100130055922 * k + -79.2970844816548) + m * (-15.310361306967817 * m + 17.575251261109482 * y + 131.35250912493976 * k - 190.9453302588951) + y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) + k * (-20.737325471181034 * k - 187.80453709719578);
|
739
627
|
dest[destOffset + 2] = 255 + c * (0.8842522430003296 * c + 8.078677503112928 * m + 30.89978309703729 * y - 0.23883238689178934 * k + -14.183576799673286) + m * (10.49593273432072 * m + 63.02378494754052 * y + 50.606957656360734 * k - 112.23884253719248) + y * (0.03296041114873217 * y + 115.60384449646641 * k + -193.58209356861505) + k * (-22.33816807309886 * k - 180.12613974708367);
|
740
628
|
}
|
741
629
|
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
function DeviceCmykCS() {
|
748
|
-
_classCallCheck(this, DeviceCmykCS);
|
630
|
+
class DeviceCmykCS extends ColorSpace {
|
631
|
+
constructor() {
|
632
|
+
super("DeviceCMYK", 4);
|
633
|
+
}
|
749
634
|
|
750
|
-
|
635
|
+
getRgbItem(src, srcOffset, dest, destOffset) {
|
636
|
+
convertToRgb(src, srcOffset, 1, dest, destOffset);
|
751
637
|
}
|
752
638
|
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
value: function getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
|
761
|
-
var scale = 1 / ((1 << bits) - 1);
|
762
|
-
|
763
|
-
for (var i = 0; i < count; i++) {
|
764
|
-
convertToRgb(src, srcOffset, scale, dest, destOffset);
|
765
|
-
srcOffset += 4;
|
766
|
-
destOffset += 3 + alpha01;
|
767
|
-
}
|
768
|
-
}
|
769
|
-
}, {
|
770
|
-
key: "getOutputLength",
|
771
|
-
value: function getOutputLength(inputLength, alpha01) {
|
772
|
-
return inputLength / 4 * (3 + alpha01) | 0;
|
639
|
+
getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
|
640
|
+
const scale = 1 / ((1 << bits) - 1);
|
641
|
+
|
642
|
+
for (let i = 0; i < count; i++) {
|
643
|
+
convertToRgb(src, srcOffset, scale, dest, destOffset);
|
644
|
+
srcOffset += 4;
|
645
|
+
destOffset += 3 + alpha01;
|
773
646
|
}
|
774
|
-
}
|
647
|
+
}
|
775
648
|
|
776
|
-
|
777
|
-
|
649
|
+
getOutputLength(inputLength, alpha01) {
|
650
|
+
return inputLength / 4 * (3 + alpha01) | 0;
|
651
|
+
}
|
652
|
+
|
653
|
+
}
|
778
654
|
|
779
655
|
return DeviceCmykCS;
|
780
656
|
}();
|
781
657
|
|
782
|
-
|
658
|
+
const CalGrayCS = function CalGrayCSClosure() {
|
783
659
|
function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
660
|
+
const A = src[srcOffset] * scale;
|
661
|
+
const AG = A ** cs.G;
|
662
|
+
const L = cs.YW * AG;
|
663
|
+
const val = Math.max(295.8 * L ** 0.333333333333333333 - 40.8, 0);
|
788
664
|
dest[destOffset] = val;
|
789
665
|
dest[destOffset + 1] = val;
|
790
666
|
dest[destOffset + 2] = val;
|
791
667
|
}
|
792
668
|
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
_inherits(CalGrayCS, _ColorSpace7);
|
797
|
-
|
798
|
-
function CalGrayCS(whitePoint, blackPoint, gamma) {
|
799
|
-
var _this4;
|
800
|
-
|
801
|
-
_classCallCheck(this, CalGrayCS);
|
802
|
-
|
803
|
-
_this4 = _possibleConstructorReturn(this, _getPrototypeOf(CalGrayCS).call(this, 'CalGray', 1));
|
669
|
+
class CalGrayCS extends ColorSpace {
|
670
|
+
constructor(whitePoint, blackPoint, gamma) {
|
671
|
+
super("CalGray", 1);
|
804
672
|
|
805
673
|
if (!whitePoint) {
|
806
|
-
throw new _util.FormatError(
|
674
|
+
throw new _util.FormatError("WhitePoint missing - required for color space CalGray");
|
807
675
|
}
|
808
676
|
|
809
677
|
blackPoint = blackPoint || [0, 0, 0];
|
810
678
|
gamma = gamma || 1;
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
if (
|
820
|
-
throw new _util.FormatError(
|
679
|
+
this.XW = whitePoint[0];
|
680
|
+
this.YW = whitePoint[1];
|
681
|
+
this.ZW = whitePoint[2];
|
682
|
+
this.XB = blackPoint[0];
|
683
|
+
this.YB = blackPoint[1];
|
684
|
+
this.ZB = blackPoint[2];
|
685
|
+
this.G = gamma;
|
686
|
+
|
687
|
+
if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
|
688
|
+
throw new _util.FormatError(`Invalid WhitePoint components for ${this.name}` + ", no fallback available");
|
821
689
|
}
|
822
690
|
|
823
|
-
if (
|
824
|
-
(0, _util.info)(
|
825
|
-
|
691
|
+
if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
|
692
|
+
(0, _util.info)(`Invalid BlackPoint for ${this.name}, falling back to default.`);
|
693
|
+
this.XB = this.YB = this.ZB = 0;
|
826
694
|
}
|
827
695
|
|
828
|
-
if (
|
829
|
-
(0, _util.warn)(
|
696
|
+
if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
|
697
|
+
(0, _util.warn)(`${this.name}, BlackPoint: XB: ${this.XB}, YB: ${this.YB}, ` + `ZB: ${this.ZB}, only default values are supported.`);
|
830
698
|
}
|
831
699
|
|
832
|
-
if (
|
833
|
-
(0, _util.info)(
|
834
|
-
|
700
|
+
if (this.G < 1) {
|
701
|
+
(0, _util.info)(`Invalid Gamma: ${this.G} for ${this.name}, ` + "falling back to default.");
|
702
|
+
this.G = 1;
|
835
703
|
}
|
704
|
+
}
|
836
705
|
|
837
|
-
|
706
|
+
getRgbItem(src, srcOffset, dest, destOffset) {
|
707
|
+
convertToRgb(this, src, srcOffset, dest, destOffset, 1);
|
838
708
|
}
|
839
709
|
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
value: function getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
|
848
|
-
var scale = 1 / ((1 << bits) - 1);
|
849
|
-
|
850
|
-
for (var i = 0; i < count; ++i) {
|
851
|
-
convertToRgb(this, src, srcOffset, dest, destOffset, scale);
|
852
|
-
srcOffset += 1;
|
853
|
-
destOffset += 3 + alpha01;
|
854
|
-
}
|
855
|
-
}
|
856
|
-
}, {
|
857
|
-
key: "getOutputLength",
|
858
|
-
value: function getOutputLength(inputLength, alpha01) {
|
859
|
-
return inputLength * (3 + alpha01);
|
710
|
+
getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
|
711
|
+
const scale = 1 / ((1 << bits) - 1);
|
712
|
+
|
713
|
+
for (let i = 0; i < count; ++i) {
|
714
|
+
convertToRgb(this, src, srcOffset, dest, destOffset, scale);
|
715
|
+
srcOffset += 1;
|
716
|
+
destOffset += 3 + alpha01;
|
860
717
|
}
|
861
|
-
}
|
718
|
+
}
|
862
719
|
|
863
|
-
|
864
|
-
|
720
|
+
getOutputLength(inputLength, alpha01) {
|
721
|
+
return inputLength * (3 + alpha01);
|
722
|
+
}
|
723
|
+
|
724
|
+
}
|
865
725
|
|
866
726
|
return CalGrayCS;
|
867
727
|
}();
|
868
728
|
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
729
|
+
const CalRGBCS = function CalRGBCSClosure() {
|
730
|
+
const BRADFORD_SCALE_MATRIX = new Float32Array([0.8951, 0.2664, -0.1614, -0.7502, 1.7135, 0.0367, 0.0389, -0.0685, 1.0296]);
|
731
|
+
const BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([0.9869929, -0.1470543, 0.1599627, 0.4323053, 0.5183603, 0.0492912, -0.0085287, 0.0400428, 0.9684867]);
|
732
|
+
const SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([3.2404542, -1.5371385, -0.4985314, -0.9692660, 1.8760108, 0.0415560, 0.0556434, -0.2040259, 1.0572252]);
|
733
|
+
const FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
|
734
|
+
const tempNormalizeMatrix = new Float32Array(3);
|
735
|
+
const tempConvertMatrix1 = new Float32Array(3);
|
736
|
+
const tempConvertMatrix2 = new Float32Array(3);
|
737
|
+
const DECODE_L_CONSTANT = ((8 + 16) / 116) ** 3 / 8.0;
|
878
738
|
|
879
739
|
function matrixProduct(a, b, result) {
|
880
740
|
result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
@@ -889,9 +749,9 @@ var CalRGBCS = function CalRGBCSClosure() {
|
|
889
749
|
}
|
890
750
|
|
891
751
|
function convertToD65(sourceWhitePoint, LMS, result) {
|
892
|
-
|
893
|
-
|
894
|
-
|
752
|
+
const D65X = 0.95047;
|
753
|
+
const D65Y = 1;
|
754
|
+
const D65Z = 1.08883;
|
895
755
|
result[0] = LMS[0] * D65X / sourceWhitePoint[0];
|
896
756
|
result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
|
897
757
|
result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
|
@@ -902,7 +762,7 @@ var CalRGBCS = function CalRGBCSClosure() {
|
|
902
762
|
return adjustToRange(0, 1, 12.92 * color);
|
903
763
|
}
|
904
764
|
|
905
|
-
return adjustToRange(0, 1, (1 + 0.055) *
|
765
|
+
return adjustToRange(0, 1, (1 + 0.055) * color ** (1 / 2.4) - 0.055);
|
906
766
|
}
|
907
767
|
|
908
768
|
function adjustToRange(min, max, value) {
|
@@ -915,7 +775,7 @@ var CalRGBCS = function CalRGBCSClosure() {
|
|
915
775
|
}
|
916
776
|
|
917
777
|
if (L > 8.0) {
|
918
|
-
return
|
778
|
+
return ((L + 16) / 116) ** 3;
|
919
779
|
}
|
920
780
|
|
921
781
|
return L * DECODE_L_CONSTANT;
|
@@ -929,19 +789,19 @@ var CalRGBCS = function CalRGBCSClosure() {
|
|
929
789
|
return;
|
930
790
|
}
|
931
791
|
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
792
|
+
const zeroDecodeL = decodeL(0);
|
793
|
+
const X_DST = zeroDecodeL;
|
794
|
+
const X_SRC = decodeL(sourceBlackPoint[0]);
|
795
|
+
const Y_DST = zeroDecodeL;
|
796
|
+
const Y_SRC = decodeL(sourceBlackPoint[1]);
|
797
|
+
const Z_DST = zeroDecodeL;
|
798
|
+
const Z_SRC = decodeL(sourceBlackPoint[2]);
|
799
|
+
const X_Scale = (1 - X_DST) / (1 - X_SRC);
|
800
|
+
const X_Offset = 1 - X_Scale;
|
801
|
+
const Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
|
802
|
+
const Y_Offset = 1 - Y_Scale;
|
803
|
+
const Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
|
804
|
+
const Z_Offset = 1 - Z_Scale;
|
945
805
|
result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
|
946
806
|
result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
|
947
807
|
result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
|
@@ -955,137 +815,121 @@ var CalRGBCS = function CalRGBCSClosure() {
|
|
955
815
|
return;
|
956
816
|
}
|
957
817
|
|
958
|
-
|
818
|
+
const LMS = result;
|
959
819
|
matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
|
960
|
-
|
820
|
+
const LMS_Flat = tempNormalizeMatrix;
|
961
821
|
convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
|
962
822
|
matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
|
963
823
|
}
|
964
824
|
|
965
825
|
function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
|
966
|
-
|
826
|
+
const LMS = result;
|
967
827
|
matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
|
968
|
-
|
828
|
+
const LMS_D65 = tempNormalizeMatrix;
|
969
829
|
convertToD65(sourceWhitePoint, LMS, LMS_D65);
|
970
830
|
matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
|
971
831
|
}
|
972
832
|
|
973
833
|
function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
834
|
+
const A = adjustToRange(0, 1, src[srcOffset] * scale);
|
835
|
+
const B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
|
836
|
+
const C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
|
837
|
+
const AGR = A ** cs.GR;
|
838
|
+
const BGG = B ** cs.GG;
|
839
|
+
const CGB = C ** cs.GB;
|
840
|
+
const X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
|
841
|
+
const Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
|
842
|
+
const Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
|
843
|
+
const XYZ = tempConvertMatrix1;
|
984
844
|
XYZ[0] = X;
|
985
845
|
XYZ[1] = Y;
|
986
846
|
XYZ[2] = Z;
|
987
|
-
|
847
|
+
const XYZ_Flat = tempConvertMatrix2;
|
988
848
|
normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
|
989
|
-
|
849
|
+
const XYZ_Black = tempConvertMatrix1;
|
990
850
|
compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
|
991
|
-
|
851
|
+
const XYZ_D65 = tempConvertMatrix2;
|
992
852
|
normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
|
993
|
-
|
853
|
+
const SRGB = tempConvertMatrix1;
|
994
854
|
matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
|
995
855
|
dest[destOffset] = sRGBTransferFunction(SRGB[0]) * 255;
|
996
856
|
dest[destOffset + 1] = sRGBTransferFunction(SRGB[1]) * 255;
|
997
857
|
dest[destOffset + 2] = sRGBTransferFunction(SRGB[2]) * 255;
|
998
858
|
}
|
999
859
|
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
_inherits(CalRGBCS, _ColorSpace8);
|
1004
|
-
|
1005
|
-
function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
|
1006
|
-
var _this5;
|
1007
|
-
|
1008
|
-
_classCallCheck(this, CalRGBCS);
|
1009
|
-
|
1010
|
-
_this5 = _possibleConstructorReturn(this, _getPrototypeOf(CalRGBCS).call(this, 'CalRGB', 3));
|
860
|
+
class CalRGBCS extends ColorSpace {
|
861
|
+
constructor(whitePoint, blackPoint, gamma, matrix) {
|
862
|
+
super("CalRGB", 3);
|
1011
863
|
|
1012
864
|
if (!whitePoint) {
|
1013
|
-
throw new _util.FormatError(
|
865
|
+
throw new _util.FormatError("WhitePoint missing - required for color space CalRGB");
|
1014
866
|
}
|
1015
867
|
|
1016
868
|
blackPoint = blackPoint || new Float32Array(3);
|
1017
869
|
gamma = gamma || new Float32Array([1, 1, 1]);
|
1018
870
|
matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
871
|
+
const XW = whitePoint[0];
|
872
|
+
const YW = whitePoint[1];
|
873
|
+
const ZW = whitePoint[2];
|
874
|
+
this.whitePoint = whitePoint;
|
875
|
+
const XB = blackPoint[0];
|
876
|
+
const YB = blackPoint[1];
|
877
|
+
const ZB = blackPoint[2];
|
878
|
+
this.blackPoint = blackPoint;
|
879
|
+
this.GR = gamma[0];
|
880
|
+
this.GG = gamma[1];
|
881
|
+
this.GB = gamma[2];
|
882
|
+
this.MXA = matrix[0];
|
883
|
+
this.MYA = matrix[1];
|
884
|
+
this.MZA = matrix[2];
|
885
|
+
this.MXB = matrix[3];
|
886
|
+
this.MYB = matrix[4];
|
887
|
+
this.MZB = matrix[5];
|
888
|
+
this.MXC = matrix[6];
|
889
|
+
this.MYC = matrix[7];
|
890
|
+
this.MZC = matrix[8];
|
1039
891
|
|
1040
892
|
if (XW < 0 || ZW < 0 || YW !== 1) {
|
1041
|
-
throw new _util.FormatError(
|
893
|
+
throw new _util.FormatError(`Invalid WhitePoint components for ${this.name}` + ", no fallback available");
|
1042
894
|
}
|
1043
895
|
|
1044
896
|
if (XB < 0 || YB < 0 || ZB < 0) {
|
1045
|
-
(0, _util.info)(
|
1046
|
-
|
897
|
+
(0, _util.info)(`Invalid BlackPoint for ${this.name} [${XB}, ${YB}, ${ZB}], ` + "falling back to default.");
|
898
|
+
this.blackPoint = new Float32Array(3);
|
1047
899
|
}
|
1048
900
|
|
1049
|
-
if (
|
1050
|
-
(0, _util.info)(
|
1051
|
-
|
901
|
+
if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
|
902
|
+
(0, _util.info)(`Invalid Gamma [${this.GR}, ${this.GG}, ${this.GB}] for ` + `${this.name}, falling back to default.`);
|
903
|
+
this.GR = this.GG = this.GB = 1;
|
1052
904
|
}
|
905
|
+
}
|
1053
906
|
|
1054
|
-
|
907
|
+
getRgbItem(src, srcOffset, dest, destOffset) {
|
908
|
+
convertToRgb(this, src, srcOffset, dest, destOffset, 1);
|
1055
909
|
}
|
1056
910
|
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
value: function getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
|
1065
|
-
var scale = 1 / ((1 << bits) - 1);
|
1066
|
-
|
1067
|
-
for (var i = 0; i < count; ++i) {
|
1068
|
-
convertToRgb(this, src, srcOffset, dest, destOffset, scale);
|
1069
|
-
srcOffset += 3;
|
1070
|
-
destOffset += 3 + alpha01;
|
1071
|
-
}
|
1072
|
-
}
|
1073
|
-
}, {
|
1074
|
-
key: "getOutputLength",
|
1075
|
-
value: function getOutputLength(inputLength, alpha01) {
|
1076
|
-
return inputLength * (3 + alpha01) / 3 | 0;
|
911
|
+
getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
|
912
|
+
const scale = 1 / ((1 << bits) - 1);
|
913
|
+
|
914
|
+
for (let i = 0; i < count; ++i) {
|
915
|
+
convertToRgb(this, src, srcOffset, dest, destOffset, scale);
|
916
|
+
srcOffset += 3;
|
917
|
+
destOffset += 3 + alpha01;
|
1077
918
|
}
|
1078
|
-
}
|
919
|
+
}
|
1079
920
|
|
1080
|
-
|
1081
|
-
|
921
|
+
getOutputLength(inputLength, alpha01) {
|
922
|
+
return inputLength * (3 + alpha01) / 3 | 0;
|
923
|
+
}
|
924
|
+
|
925
|
+
}
|
1082
926
|
|
1083
927
|
return CalRGBCS;
|
1084
928
|
}();
|
1085
929
|
|
1086
|
-
|
930
|
+
const LabCS = function LabCSClosure() {
|
1087
931
|
function fn_g(x) {
|
1088
|
-
|
932
|
+
let result;
|
1089
933
|
|
1090
934
|
if (x >= 6 / 29) {
|
1091
935
|
result = x * x * x;
|
@@ -1101,9 +945,9 @@ var LabCS = function LabCSClosure() {
|
|
1101
945
|
}
|
1102
946
|
|
1103
947
|
function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
948
|
+
let Ls = src[srcOffset];
|
949
|
+
let as = src[srcOffset + 1];
|
950
|
+
let bs = src[srcOffset + 2];
|
1107
951
|
|
1108
952
|
if (maxVal !== false) {
|
1109
953
|
Ls = decode(Ls, maxVal, 0, 100);
|
@@ -1111,24 +955,34 @@ var LabCS = function LabCSClosure() {
|
|
1111
955
|
bs = decode(bs, maxVal, cs.bmin, cs.bmax);
|
1112
956
|
}
|
1113
957
|
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
958
|
+
if (as > cs.amax) {
|
959
|
+
as = cs.amax;
|
960
|
+
} else if (as < cs.amin) {
|
961
|
+
as = cs.amin;
|
962
|
+
}
|
963
|
+
|
964
|
+
if (bs > cs.bmax) {
|
965
|
+
bs = cs.bmax;
|
966
|
+
} else if (bs < cs.bmin) {
|
967
|
+
bs = cs.bmin;
|
968
|
+
}
|
969
|
+
|
970
|
+
const M = (Ls + 16) / 116;
|
971
|
+
const L = M + as / 500;
|
972
|
+
const N = M - bs / 200;
|
973
|
+
const X = cs.XW * fn_g(L);
|
974
|
+
const Y = cs.YW * fn_g(M);
|
975
|
+
const Z = cs.ZW * fn_g(N);
|
976
|
+
let r, g, b;
|
1123
977
|
|
1124
978
|
if (cs.ZW < 1) {
|
1125
|
-
r = X * 3.1339 + Y * -1.
|
1126
|
-
g = X * -0.9785 + Y * 1.
|
1127
|
-
b = X * 0.
|
979
|
+
r = X * 3.1339 + Y * -1.617 + Z * -0.4906;
|
980
|
+
g = X * -0.9785 + Y * 1.916 + Z * 0.0333;
|
981
|
+
b = X * 0.072 + Y * -0.229 + Z * 1.4057;
|
1128
982
|
} else {
|
1129
983
|
r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
|
1130
984
|
g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
|
1131
|
-
b = X * 0.0557 + Y * -0.
|
985
|
+
b = X * 0.0557 + Y * -0.204 + Z * 1.057;
|
1132
986
|
}
|
1133
987
|
|
1134
988
|
dest[destOffset] = Math.sqrt(r) * 255;
|
@@ -1136,90 +990,72 @@ var LabCS = function LabCSClosure() {
|
|
1136
990
|
dest[destOffset + 2] = Math.sqrt(b) * 255;
|
1137
991
|
}
|
1138
992
|
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
_inherits(LabCS, _ColorSpace9);
|
1143
|
-
|
1144
|
-
function LabCS(whitePoint, blackPoint, range) {
|
1145
|
-
var _this6;
|
1146
|
-
|
1147
|
-
_classCallCheck(this, LabCS);
|
1148
|
-
|
1149
|
-
_this6 = _possibleConstructorReturn(this, _getPrototypeOf(LabCS).call(this, 'Lab', 3));
|
993
|
+
class LabCS extends ColorSpace {
|
994
|
+
constructor(whitePoint, blackPoint, range) {
|
995
|
+
super("Lab", 3);
|
1150
996
|
|
1151
997
|
if (!whitePoint) {
|
1152
|
-
throw new _util.FormatError(
|
998
|
+
throw new _util.FormatError("WhitePoint missing - required for color space Lab");
|
1153
999
|
}
|
1154
1000
|
|
1155
1001
|
blackPoint = blackPoint || [0, 0, 0];
|
1156
1002
|
range = range || [-100, 100, -100, 100];
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
if (
|
1169
|
-
throw new _util.FormatError(
|
1003
|
+
this.XW = whitePoint[0];
|
1004
|
+
this.YW = whitePoint[1];
|
1005
|
+
this.ZW = whitePoint[2];
|
1006
|
+
this.amin = range[0];
|
1007
|
+
this.amax = range[1];
|
1008
|
+
this.bmin = range[2];
|
1009
|
+
this.bmax = range[3];
|
1010
|
+
this.XB = blackPoint[0];
|
1011
|
+
this.YB = blackPoint[1];
|
1012
|
+
this.ZB = blackPoint[2];
|
1013
|
+
|
1014
|
+
if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
|
1015
|
+
throw new _util.FormatError("Invalid WhitePoint components, no fallback available");
|
1170
1016
|
}
|
1171
1017
|
|
1172
|
-
if (
|
1173
|
-
(0, _util.info)(
|
1174
|
-
|
1018
|
+
if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
|
1019
|
+
(0, _util.info)("Invalid BlackPoint, falling back to default");
|
1020
|
+
this.XB = this.YB = this.ZB = 0;
|
1175
1021
|
}
|
1176
1022
|
|
1177
|
-
if (
|
1178
|
-
(0, _util.info)(
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1023
|
+
if (this.amin > this.amax || this.bmin > this.bmax) {
|
1024
|
+
(0, _util.info)("Invalid Range, falling back to defaults");
|
1025
|
+
this.amin = -100;
|
1026
|
+
this.amax = 100;
|
1027
|
+
this.bmin = -100;
|
1028
|
+
this.bmax = 100;
|
1183
1029
|
}
|
1030
|
+
}
|
1184
1031
|
|
1185
|
-
|
1032
|
+
getRgbItem(src, srcOffset, dest, destOffset) {
|
1033
|
+
convertToRgb(this, src, srcOffset, false, dest, destOffset);
|
1186
1034
|
}
|
1187
1035
|
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
value: function getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
|
1196
|
-
var maxVal = (1 << bits) - 1;
|
1197
|
-
|
1198
|
-
for (var i = 0; i < count; i++) {
|
1199
|
-
convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
|
1200
|
-
srcOffset += 3;
|
1201
|
-
destOffset += 3 + alpha01;
|
1202
|
-
}
|
1203
|
-
}
|
1204
|
-
}, {
|
1205
|
-
key: "getOutputLength",
|
1206
|
-
value: function getOutputLength(inputLength, alpha01) {
|
1207
|
-
return inputLength * (3 + alpha01) / 3 | 0;
|
1208
|
-
}
|
1209
|
-
}, {
|
1210
|
-
key: "isDefaultDecode",
|
1211
|
-
value: function isDefaultDecode(decodeMap, bpc) {
|
1212
|
-
return true;
|
1213
|
-
}
|
1214
|
-
}, {
|
1215
|
-
key: "usesZeroToOneRange",
|
1216
|
-
get: function get() {
|
1217
|
-
return (0, _util.shadow)(this, 'usesZeroToOneRange', false);
|
1036
|
+
getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
|
1037
|
+
const maxVal = (1 << bits) - 1;
|
1038
|
+
|
1039
|
+
for (let i = 0; i < count; i++) {
|
1040
|
+
convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
|
1041
|
+
srcOffset += 3;
|
1042
|
+
destOffset += 3 + alpha01;
|
1218
1043
|
}
|
1219
|
-
}
|
1044
|
+
}
|
1045
|
+
|
1046
|
+
getOutputLength(inputLength, alpha01) {
|
1047
|
+
return inputLength * (3 + alpha01) / 3 | 0;
|
1048
|
+
}
|
1220
1049
|
|
1221
|
-
|
1222
|
-
|
1050
|
+
isDefaultDecode(decodeMap, bpc) {
|
1051
|
+
return true;
|
1052
|
+
}
|
1053
|
+
|
1054
|
+
get usesZeroToOneRange() {
|
1055
|
+
return (0, _util.shadow)(this, "usesZeroToOneRange", false);
|
1056
|
+
}
|
1057
|
+
|
1058
|
+
}
|
1223
1059
|
|
1224
1060
|
return LabCS;
|
1225
1061
|
}();
|