pdfjs-dist 2.0.943 → 2.4.456
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 +8286 -14230
- 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 +25500 -26628
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25473 -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 +57878 -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 +407 -0
- package/es5/web/pdf_viewer.js +7757 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +2887 -4094
- 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 +855 -778
- package/lib/core/arithmetic_decoder.js +325 -311
- package/lib/core/bidi.js +117 -50
- package/lib/core/ccitt.js +251 -89
- package/lib/core/ccitt_stream.js +26 -16
- package/lib/core/cff_parser.js +525 -197
- package/lib/core/charsets.js +6 -5
- package/lib/core/chunked_stream.js +541 -406
- package/lib/core/cmap.js +368 -253
- package/lib/core/colorspace.js +781 -800
- package/lib/core/core_utils.js +152 -0
- package/lib/core/crypto.js +609 -422
- package/lib/core/document.js +649 -481
- package/lib/core/encodings.js +33 -24
- package/lib/core/evaluator.js +1471 -736
- package/lib/core/font_renderer.js +289 -149
- package/lib/core/fonts.js +1067 -413
- package/lib/core/function.js +517 -287
- package/lib/core/glyphlist.js +4529 -4527
- package/lib/core/image.js +232 -114
- package/lib/core/image_utils.js +94 -0
- package/lib/core/jbig2.js +711 -342
- package/lib/core/jbig2_stream.js +31 -19
- package/lib/core/jpeg_stream.js +151 -26
- package/lib/core/jpg.js +433 -181
- package/lib/core/jpx.js +551 -143
- package/lib/core/jpx_stream.js +40 -28
- package/lib/core/metrics.js +2931 -2931
- package/lib/core/murmurhash3.js +104 -97
- package/lib/core/obj.js +1561 -1053
- package/lib/core/operator_list.js +192 -64
- package/lib/core/parser.js +1162 -864
- package/lib/core/pattern.js +224 -75
- package/lib/core/pdf_manager.js +154 -285
- package/lib/core/primitives.js +145 -69
- package/lib/core/ps_parser.js +212 -162
- package/lib/core/standard_fonts.js +245 -244
- package/lib/core/stream.js +353 -81
- package/lib/core/type1_parser.js +218 -68
- package/lib/core/unicode.js +1682 -1655
- package/lib/core/worker.js +233 -302
- package/lib/core/worker_stream.js +168 -0
- package/lib/display/annotation_layer.js +808 -862
- package/lib/display/api.js +1778 -1462
- package/lib/display/api_compatibility.js +14 -9
- package/lib/display/canvas.js +463 -140
- package/lib/display/content_disposition.js +86 -58
- package/lib/display/display_utils.js +524 -0
- package/lib/display/fetch_stream.js +202 -274
- package/lib/display/font_loader.js +311 -333
- package/lib/display/metadata.js +98 -88
- package/lib/display/network.js +343 -347
- package/lib/display/network_utils.js +46 -26
- package/lib/display/node_stream.js +326 -404
- package/lib/display/pattern_helper.js +168 -69
- package/lib/display/svg.js +1296 -885
- package/lib/display/text_layer.js +229 -103
- package/lib/display/transport_stream.js +290 -250
- package/lib/display/webgl.js +116 -83
- package/lib/display/worker_options.js +6 -5
- package/lib/display/xml_parser.js +358 -337
- package/lib/examples/node/domstubs.js +95 -39
- package/lib/pdf.js +49 -31
- package/lib/pdf.worker.js +7 -5
- package/lib/shared/compatibility.js +3 -145
- package/lib/shared/is_node.js +8 -7
- package/lib/shared/message_handler.js +367 -314
- package/lib/shared/util.js +421 -415
- package/lib/test/unit/annotation_spec.js +1570 -690
- package/lib/test/unit/api_spec.js +855 -493
- package/lib/test/unit/bidi_spec.js +12 -12
- package/lib/test/unit/cff_parser_spec.js +88 -61
- package/lib/test/unit/clitests_helper.js +9 -12
- package/lib/test/unit/cmap_spec.js +140 -88
- package/lib/test/unit/colorspace_spec.js +204 -152
- package/lib/test/unit/core_utils_spec.js +211 -0
- package/lib/test/unit/crypto_spec.js +194 -182
- package/lib/test/unit/custom_spec.js +50 -64
- package/lib/test/unit/display_svg_spec.js +53 -38
- package/lib/test/unit/display_utils_spec.js +263 -0
- package/lib/test/unit/document_spec.js +17 -22
- package/lib/test/unit/encodings_spec.js +15 -57
- package/lib/test/unit/evaluator_spec.js +90 -83
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +219 -205
- package/lib/test/unit/jasmine-boot.js +68 -39
- package/lib/test/unit/message_handler_spec.js +187 -160
- package/lib/test/unit/metadata_spec.js +87 -34
- package/lib/test/unit/murmurhash3_spec.js +13 -13
- package/lib/test/unit/network_spec.js +26 -59
- package/lib/test/unit/network_utils_spec.js +187 -121
- package/lib/test/unit/node_stream_spec.js +98 -90
- package/lib/test/unit/parser_spec.js +173 -131
- package/lib/test/unit/pdf_find_controller_spec.js +148 -67
- package/lib/test/unit/pdf_find_utils_spec.js +35 -34
- package/lib/test/unit/pdf_history_spec.js +45 -33
- package/lib/test/unit/primitives_spec.js +161 -126
- package/lib/test/unit/stream_spec.js +22 -15
- package/lib/test/unit/test_utils.js +149 -98
- package/lib/test/unit/testreporter.js +36 -18
- package/lib/test/unit/type1_parser_spec.js +46 -44
- package/lib/test/unit/ui_utils_spec.js +388 -372
- package/lib/test/unit/unicode_spec.js +49 -46
- package/lib/test/unit/util_spec.js +144 -248
- package/lib/web/annotation_layer_builder.js +75 -95
- package/lib/web/app.js +1538 -1147
- package/lib/web/app_options.js +116 -104
- package/lib/web/base_viewer.js +950 -775
- package/lib/web/chromecom.js +217 -225
- package/lib/web/debugger.js +236 -148
- package/lib/web/download_manager.js +50 -50
- package/lib/web/firefox_print_service.js +51 -33
- package/lib/web/firefoxcom.js +225 -352
- package/lib/web/genericcom.js +30 -93
- package/lib/web/genericl10n.js +26 -143
- package/lib/web/grab_to_pan.js +57 -33
- package/lib/web/interfaces.js +105 -232
- package/lib/web/overlay_manager.js +73 -227
- package/lib/web/password_prompt.js +44 -62
- package/lib/web/pdf_attachment_viewer.js +118 -123
- package/lib/web/pdf_cursor_tools.js +89 -93
- package/lib/web/pdf_document_properties.js +242 -281
- package/lib/web/pdf_find_bar.js +157 -163
- package/lib/web/pdf_find_controller.js +598 -454
- package/lib/web/pdf_find_utils.js +32 -16
- package/lib/web/pdf_history.js +481 -355
- package/lib/web/pdf_link_service.js +355 -323
- package/lib/web/pdf_outline_viewer.js +167 -152
- package/lib/web/pdf_page_view.js +511 -457
- package/lib/web/pdf_presentation_mode.js +347 -335
- package/lib/web/pdf_print_service.js +133 -103
- package/lib/web/pdf_rendering_queue.js +98 -100
- package/lib/web/pdf_sidebar.js +323 -299
- package/lib/web/pdf_sidebar_resizer.js +107 -108
- package/lib/web/pdf_single_page_viewer.js +94 -146
- package/lib/web/pdf_thumbnail_view.js +319 -269
- package/lib/web/pdf_thumbnail_viewer.js +219 -199
- package/lib/web/pdf_viewer.component.js +111 -32
- package/lib/web/pdf_viewer.js +61 -101
- package/lib/web/preferences.js +87 -272
- package/lib/web/secondary_toolbar.js +207 -220
- package/lib/web/text_layer_builder.js +322 -322
- package/lib/web/toolbar.js +227 -180
- package/lib/web/ui_utils.js +476 -421
- package/lib/web/view_history.js +59 -208
- package/lib/web/viewer_compatibility.js +9 -6
- package/package.json +2 -9
- package/web/pdf_viewer.css +36 -22
- package/web/pdf_viewer.js +4407 -4516
- 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 -441
- package/lib/shared/streams_polyfill.js +0 -39
- package/lib/shared/url_polyfill.js +0 -50
- package/lib/test/unit/dom_utils_spec.js +0 -89
- package/lib/web/dom_events.js +0 -140
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.
|
@@ -19,40 +19,35 @@
|
|
19
19
|
* @licend The above is the entire license notice for the
|
20
20
|
* Javascript code in this page
|
21
21
|
*/
|
22
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
24
|
Object.defineProperty(exports, "__esModule", {
|
25
25
|
value: true
|
26
26
|
});
|
27
|
-
exports.ColorSpace =
|
27
|
+
exports.ColorSpace = void 0;
|
28
28
|
|
29
|
-
var
|
29
|
+
var _util = require("../shared/util.js");
|
30
30
|
|
31
|
-
var
|
32
|
-
|
33
|
-
var _primitives = require('./primitives');
|
34
|
-
|
35
|
-
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
36
|
-
|
37
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
38
|
-
|
39
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
31
|
+
var _primitives = require("./primitives.js");
|
40
32
|
|
41
33
|
function resizeRgbImage(src, dest, w1, h1, w2, h2, alpha01) {
|
42
|
-
|
34
|
+
const COMPONENTS = 3;
|
43
35
|
alpha01 = alpha01 !== 1 ? 0 : alpha01;
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
oldIndex
|
48
|
-
|
49
|
-
|
50
|
-
|
36
|
+
const xRatio = w1 / w2;
|
37
|
+
const yRatio = h1 / h2;
|
38
|
+
let newIndex = 0,
|
39
|
+
oldIndex;
|
40
|
+
const xScaled = new Uint16Array(w2);
|
41
|
+
const w1Scanline = w1 * COMPONENTS;
|
42
|
+
|
43
|
+
for (let i = 0; i < w2; i++) {
|
51
44
|
xScaled[i] = Math.floor(i * xRatio) * COMPONENTS;
|
52
45
|
}
|
53
|
-
|
54
|
-
|
55
|
-
|
46
|
+
|
47
|
+
for (let i = 0; i < h2; i++) {
|
48
|
+
const py = Math.floor(i * yRatio) * w1Scanline;
|
49
|
+
|
50
|
+
for (let j = 0; j < w2; j++) {
|
56
51
|
oldIndex = py + xScaled[j];
|
57
52
|
dest[newIndex++] = src[oldIndex++];
|
58
53
|
dest[newIndex++] = src[oldIndex++];
|
@@ -62,746 +57,730 @@ function resizeRgbImage(src, dest, w1, h1, w2, h2, alpha01) {
|
|
62
57
|
}
|
63
58
|
}
|
64
59
|
|
65
|
-
|
66
|
-
|
67
|
-
_classCallCheck(this, ColorSpace);
|
68
|
-
|
60
|
+
class ColorSpace {
|
61
|
+
constructor(name, numComps) {
|
69
62
|
if (this.constructor === ColorSpace) {
|
70
|
-
(0, _util.unreachable)(
|
63
|
+
(0, _util.unreachable)("Cannot initialize ColorSpace.");
|
71
64
|
}
|
65
|
+
|
72
66
|
this.name = name;
|
73
67
|
this.numComps = numComps;
|
74
68
|
}
|
75
69
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
}
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
rgbBuf = new Uint8Array(count * 3);
|
130
|
-
var rgbPos = 0;
|
131
|
-
for (var _i3 = 0; _i3 < count; ++_i3) {
|
132
|
-
var _key = comps[_i3] * 3;
|
133
|
-
rgbBuf[rgbPos++] = colorMap[_key];
|
134
|
-
rgbBuf[rgbPos++] = colorMap[_key + 1];
|
135
|
-
rgbBuf[rgbPos++] = colorMap[_key + 2];
|
136
|
-
}
|
70
|
+
getRgb(src, srcOffset) {
|
71
|
+
const rgb = new Uint8ClampedArray(3);
|
72
|
+
this.getRgbItem(src, srcOffset, rgb, 0);
|
73
|
+
return rgb;
|
74
|
+
}
|
75
|
+
|
76
|
+
getRgbItem(src, srcOffset, dest, destOffset) {
|
77
|
+
(0, _util.unreachable)("Should not call ColorSpace.getRgbItem");
|
78
|
+
}
|
79
|
+
|
80
|
+
getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
|
81
|
+
(0, _util.unreachable)("Should not call ColorSpace.getRgbBuffer");
|
82
|
+
}
|
83
|
+
|
84
|
+
getOutputLength(inputLength, alpha01) {
|
85
|
+
(0, _util.unreachable)("Should not call ColorSpace.getOutputLength");
|
86
|
+
}
|
87
|
+
|
88
|
+
isPassthrough(bits) {
|
89
|
+
return false;
|
90
|
+
}
|
91
|
+
|
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;
|
137
123
|
}
|
138
124
|
} else {
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
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];
|
144
133
|
}
|
145
134
|
}
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
for (var _i4 = 0, ii = width * actualHeight; _i4 < ii; _i4++) {
|
153
|
-
dest[_destPos++] = rgbBuf[_rgbPos++];
|
154
|
-
dest[_destPos++] = rgbBuf[_rgbPos++];
|
155
|
-
dest[_destPos++] = rgbBuf[_rgbPos++];
|
156
|
-
_destPos += alpha01;
|
157
|
-
}
|
158
|
-
}
|
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);
|
159
141
|
}
|
160
142
|
}
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
143
|
+
|
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;
|
156
|
+
}
|
157
|
+
}
|
165
158
|
}
|
166
|
-
}
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
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}`);
|
171
226
|
}
|
172
|
-
}
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
case
|
181
|
-
return
|
182
|
-
|
183
|
-
|
184
|
-
case
|
185
|
-
return
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
case
|
192
|
-
|
193
|
-
|
194
|
-
gamma = IR[3];
|
195
|
-
var matrix = IR[4];
|
196
|
-
return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
|
197
|
-
case 'PatternCS':
|
198
|
-
var basePatternCS = IR[1];
|
199
|
-
if (basePatternCS) {
|
200
|
-
basePatternCS = this.fromIR(basePatternCS);
|
201
|
-
}
|
202
|
-
return new PatternCS(basePatternCS);
|
203
|
-
case 'IndexedCS':
|
204
|
-
var baseIndexedCS = IR[1];
|
205
|
-
var hiVal = IR[2];
|
206
|
-
var lookup = IR[3];
|
207
|
-
return new IndexedCS(this.fromIR(baseIndexedCS), hiVal, lookup);
|
208
|
-
case 'AlternateCS':
|
209
|
-
var numComps = IR[1];
|
210
|
-
var alt = IR[2];
|
211
|
-
var tintFn = IR[3];
|
212
|
-
return new AlternateCS(numComps, this.fromIR(alt), tintFn);
|
213
|
-
case 'LabCS':
|
214
|
-
whitePoint = IR[1];
|
215
|
-
blackPoint = IR[2];
|
216
|
-
var range = IR[3];
|
217
|
-
return new LabCS(whitePoint, blackPoint, range);
|
227
|
+
}
|
228
|
+
|
229
|
+
static parseToIR(cs, xref, res = null, pdfFunctionFactory) {
|
230
|
+
cs = xref.fetchIfRef(cs);
|
231
|
+
|
232
|
+
if ((0, _primitives.isName)(cs)) {
|
233
|
+
switch (cs.name) {
|
234
|
+
case "DeviceGray":
|
235
|
+
case "G":
|
236
|
+
return "DeviceGrayCS";
|
237
|
+
|
238
|
+
case "DeviceRGB":
|
239
|
+
case "RGB":
|
240
|
+
return "DeviceRgbCS";
|
241
|
+
|
242
|
+
case "DeviceCMYK":
|
243
|
+
case "CMYK":
|
244
|
+
return "DeviceCmykCS";
|
245
|
+
|
246
|
+
case "Pattern":
|
247
|
+
return ["PatternCS", null];
|
248
|
+
|
218
249
|
default:
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
cs = xref.fetchIfRef(cs);
|
229
|
-
if ((0, _primitives.isName)(cs)) {
|
230
|
-
switch (cs.name) {
|
231
|
-
case 'DeviceGray':
|
232
|
-
case 'G':
|
233
|
-
return 'DeviceGrayCS';
|
234
|
-
case 'DeviceRGB':
|
235
|
-
case 'RGB':
|
236
|
-
return 'DeviceRgbCS';
|
237
|
-
case 'DeviceCMYK':
|
238
|
-
case 'CMYK':
|
239
|
-
return 'DeviceCmykCS';
|
240
|
-
case 'Pattern':
|
241
|
-
return ['PatternCS', null];
|
242
|
-
default:
|
243
|
-
if ((0, _primitives.isDict)(res)) {
|
244
|
-
var colorSpaces = res.get('ColorSpace');
|
245
|
-
if ((0, _primitives.isDict)(colorSpaces)) {
|
246
|
-
var resCS = colorSpaces.get(cs.name);
|
247
|
-
if (resCS) {
|
248
|
-
if ((0, _primitives.isName)(resCS)) {
|
249
|
-
return this.parseToIR(resCS, xref, res, pdfFunctionFactory);
|
250
|
-
}
|
251
|
-
cs = resCS;
|
252
|
-
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);
|
253
259
|
}
|
260
|
+
|
261
|
+
cs = resCS;
|
262
|
+
break;
|
254
263
|
}
|
255
264
|
}
|
256
|
-
|
257
|
-
|
265
|
+
}
|
266
|
+
|
267
|
+
throw new _util.FormatError(`unrecognized colorspace ${cs.name}`);
|
258
268
|
}
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
if (numComps ===
|
304
|
-
return
|
305
|
-
} else if (numComps === 3) {
|
306
|
-
return 'DeviceRgbCS';
|
307
|
-
} else if (numComps === 4) {
|
308
|
-
return 'DeviceCmykCS';
|
309
|
-
}
|
310
|
-
break;
|
311
|
-
case 'Pattern':
|
312
|
-
var basePatternCS = cs[1] || null;
|
313
|
-
if (basePatternCS) {
|
314
|
-
basePatternCS = this.parseToIR(basePatternCS, xref, res, pdfFunctionFactory);
|
315
|
-
}
|
316
|
-
return ['PatternCS', basePatternCS];
|
317
|
-
case 'Indexed':
|
318
|
-
case 'I':
|
319
|
-
var baseIndexedCS = this.parseToIR(cs[1], xref, res, pdfFunctionFactory);
|
320
|
-
var hiVal = xref.fetchIfRef(cs[2]) + 1;
|
321
|
-
var lookup = xref.fetchIfRef(cs[3]);
|
322
|
-
if ((0, _primitives.isStream)(lookup)) {
|
323
|
-
lookup = lookup.getBytes();
|
269
|
+
}
|
270
|
+
|
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;
|
324
315
|
}
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
return
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
316
|
+
|
317
|
+
(0, _util.warn)("ICCBased color space: Ignoring incorrect /Alternate entry.");
|
318
|
+
}
|
319
|
+
|
320
|
+
if (numComps === 1) {
|
321
|
+
return "DeviceGrayCS";
|
322
|
+
} else if (numComps === 3) {
|
323
|
+
return "DeviceRgbCS";
|
324
|
+
} else if (numComps === 4) {
|
325
|
+
return "DeviceCmykCS";
|
326
|
+
}
|
327
|
+
|
328
|
+
break;
|
329
|
+
|
330
|
+
case "Pattern":
|
331
|
+
let basePatternCS = cs[1] || null;
|
332
|
+
|
333
|
+
if (basePatternCS) {
|
334
|
+
basePatternCS = this.parseToIR(basePatternCS, xref, res, pdfFunctionFactory);
|
335
|
+
}
|
336
|
+
|
337
|
+
return ["PatternCS", basePatternCS];
|
338
|
+
|
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]);
|
344
|
+
|
345
|
+
if ((0, _primitives.isStream)(lookup)) {
|
346
|
+
lookup = lookup.getBytes();
|
347
|
+
}
|
348
|
+
|
349
|
+
return ["IndexedCS", baseIndexedCS, hiVal, lookup];
|
350
|
+
|
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];
|
358
|
+
|
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}"`);
|
342
368
|
}
|
343
|
-
throw new _util.FormatError('unrecognized color space object: "' + cs + '"');
|
344
369
|
}
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
if (n * 2 !== decode.length) {
|
352
|
-
(0, _util.warn)('The decode map is not the correct length');
|
353
|
-
return true;
|
354
|
-
}
|
355
|
-
for (var i = 0, ii = decode.length; i < ii; i += 2) {
|
356
|
-
if (decode[i] !== 0 || decode[i + 1] !== 1) {
|
357
|
-
return false;
|
358
|
-
}
|
359
|
-
}
|
370
|
+
|
371
|
+
throw new _util.FormatError(`unrecognized color space object: "${cs}"`);
|
372
|
+
}
|
373
|
+
|
374
|
+
static isDefaultDecode(decode, numComps) {
|
375
|
+
if (!Array.isArray(decode)) {
|
360
376
|
return true;
|
361
377
|
}
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
return
|
366
|
-
get gray() {
|
367
|
-
return (0, _util.shadow)(this, 'gray', new DeviceGrayCS());
|
368
|
-
},
|
369
|
-
get rgb() {
|
370
|
-
return (0, _util.shadow)(this, 'rgb', new DeviceRgbCS());
|
371
|
-
},
|
372
|
-
get cmyk() {
|
373
|
-
return (0, _util.shadow)(this, 'cmyk', new DeviceCmykCS());
|
374
|
-
}
|
375
|
-
});
|
378
|
+
|
379
|
+
if (numComps * 2 !== decode.length) {
|
380
|
+
(0, _util.warn)("The decode map is not the correct length");
|
381
|
+
return true;
|
376
382
|
}
|
377
|
-
}]);
|
378
383
|
|
379
|
-
|
380
|
-
|
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
|
+
}
|
389
|
+
|
390
|
+
return true;
|
391
|
+
}
|
381
392
|
|
382
|
-
|
383
|
-
|
393
|
+
static get singletons() {
|
394
|
+
return (0, _util.shadow)(this, "singletons", {
|
395
|
+
get gray() {
|
396
|
+
return (0, _util.shadow)(this, "gray", new DeviceGrayCS());
|
397
|
+
},
|
384
398
|
|
385
|
-
|
386
|
-
|
399
|
+
get rgb() {
|
400
|
+
return (0, _util.shadow)(this, "rgb", new DeviceRgbCS());
|
401
|
+
},
|
387
402
|
|
388
|
-
|
403
|
+
get cmyk() {
|
404
|
+
return (0, _util.shadow)(this, "cmyk", new DeviceCmykCS());
|
405
|
+
}
|
389
406
|
|
390
|
-
|
391
|
-
_this.tintFn = tintFn;
|
392
|
-
_this.tmpBuf = new Float32Array(base.numComps);
|
393
|
-
return _this;
|
407
|
+
});
|
394
408
|
}
|
395
409
|
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
}
|
410
|
+
}
|
411
|
+
|
412
|
+
exports.ColorSpace = ColorSpace;
|
413
|
+
|
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
|
+
}
|
421
|
+
|
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
|
+
}
|
427
|
+
|
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;
|
432
445
|
}
|
433
|
-
|
434
|
-
|
446
|
+
|
447
|
+
tintFn(scaled, 0, tinted, 0);
|
448
|
+
|
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;
|
435
456
|
}
|
436
457
|
}
|
437
|
-
}, {
|
438
|
-
key: 'getOutputLength',
|
439
|
-
value: function getOutputLength(inputLength, alpha01) {
|
440
|
-
return this.base.getOutputLength(inputLength * this.base.numComps / this.numComps, alpha01);
|
441
|
-
}
|
442
|
-
}, {
|
443
|
-
key: 'isDefaultDecode',
|
444
|
-
value: function isDefaultDecode(decodeMap) {
|
445
|
-
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
446
|
-
}
|
447
|
-
}]);
|
448
|
-
|
449
|
-
return AlternateCS;
|
450
|
-
}(ColorSpace);
|
451
458
|
|
452
|
-
|
453
|
-
|
459
|
+
if (!isPassthrough) {
|
460
|
+
base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
|
461
|
+
}
|
462
|
+
}
|
454
463
|
|
455
|
-
|
456
|
-
|
464
|
+
getOutputLength(inputLength, alpha01) {
|
465
|
+
return this.base.getOutputLength(inputLength * this.base.numComps / this.numComps, alpha01);
|
466
|
+
}
|
457
467
|
|
458
|
-
|
468
|
+
}
|
459
469
|
|
460
|
-
|
461
|
-
|
470
|
+
class PatternCS extends ColorSpace {
|
471
|
+
constructor(baseCS) {
|
472
|
+
super("Pattern", null);
|
473
|
+
this.base = baseCS;
|
462
474
|
}
|
463
475
|
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
var IndexedCS = function (_ColorSpace3) {
|
468
|
-
_inherits(IndexedCS, _ColorSpace3);
|
476
|
+
isDefaultDecode(decodeMap, bpc) {
|
477
|
+
(0, _util.unreachable)("Should not call PatternCS.isDefaultDecode");
|
478
|
+
}
|
469
479
|
|
470
|
-
|
471
|
-
_classCallCheck(this, IndexedCS);
|
480
|
+
}
|
472
481
|
|
473
|
-
|
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;
|
474
489
|
|
475
|
-
_this3.base = base;
|
476
|
-
_this3.highVal = highVal;
|
477
|
-
var baseNumComps = base.numComps;
|
478
|
-
var length = baseNumComps * highVal;
|
479
490
|
if ((0, _primitives.isStream)(lookup)) {
|
480
|
-
|
481
|
-
|
482
|
-
|
491
|
+
this.lookup = new Uint8Array(length);
|
492
|
+
const bytes = lookup.getBytes(length);
|
493
|
+
this.lookup.set(bytes);
|
483
494
|
} else if ((0, _util.isString)(lookup)) {
|
484
|
-
|
485
|
-
|
486
|
-
|
495
|
+
this.lookup = new Uint8Array(length);
|
496
|
+
|
497
|
+
for (let i = 0; i < length; ++i) {
|
498
|
+
this.lookup[i] = lookup.charCodeAt(i);
|
487
499
|
}
|
488
500
|
} else if (lookup instanceof Uint8Array) {
|
489
|
-
|
501
|
+
this.lookup = lookup;
|
490
502
|
} else {
|
491
|
-
throw new _util.FormatError(
|
503
|
+
throw new _util.FormatError(`Unrecognized lookup table: ${lookup}`);
|
492
504
|
}
|
493
|
-
return _this3;
|
494
505
|
}
|
495
506
|
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
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);
|
511
|
+
}
|
512
|
+
|
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;
|
502
523
|
}
|
503
|
-
}
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
|
513
|
-
destOffset += outputDelta;
|
514
|
-
}
|
524
|
+
}
|
525
|
+
|
526
|
+
getOutputLength(inputLength, alpha01) {
|
527
|
+
return this.base.getOutputLength(inputLength * this.base.numComps, alpha01);
|
528
|
+
}
|
529
|
+
|
530
|
+
isDefaultDecode(decodeMap, bpc) {
|
531
|
+
if (!Array.isArray(decodeMap)) {
|
532
|
+
return true;
|
515
533
|
}
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
return
|
534
|
+
|
535
|
+
if (decodeMap.length !== 2) {
|
536
|
+
(0, _util.warn)("Decode map length is not correct");
|
537
|
+
return true;
|
520
538
|
}
|
521
|
-
|
522
|
-
|
523
|
-
|
539
|
+
|
540
|
+
if (!Number.isInteger(bpc) || bpc < 1) {
|
541
|
+
(0, _util.warn)("Bits per component is not correct");
|
524
542
|
return true;
|
525
543
|
}
|
526
|
-
}]);
|
527
544
|
|
528
|
-
|
529
|
-
}
|
545
|
+
return decodeMap[0] === 0 && decodeMap[1] === (1 << bpc) - 1;
|
546
|
+
}
|
530
547
|
|
531
|
-
|
532
|
-
_inherits(DeviceGrayCS, _ColorSpace4);
|
548
|
+
}
|
533
549
|
|
534
|
-
|
535
|
-
|
550
|
+
class DeviceGrayCS extends ColorSpace {
|
551
|
+
constructor() {
|
552
|
+
super("DeviceGray", 1);
|
553
|
+
}
|
536
554
|
|
537
|
-
|
555
|
+
getRgbItem(src, srcOffset, dest, destOffset) {
|
556
|
+
const c = src[srcOffset] * 255;
|
557
|
+
dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
|
538
558
|
}
|
539
559
|
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
q = destOffset;
|
552
|
-
for (var i = 0; i < count; ++i) {
|
553
|
-
var c = scale * src[j++];
|
554
|
-
dest[q++] = c;
|
555
|
-
dest[q++] = c;
|
556
|
-
dest[q++] = c;
|
557
|
-
q += alpha01;
|
558
|
-
}
|
559
|
-
}
|
560
|
-
}, {
|
561
|
-
key: 'getOutputLength',
|
562
|
-
value: function getOutputLength(inputLength, alpha01) {
|
563
|
-
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;
|
564
571
|
}
|
565
|
-
}
|
566
|
-
key: 'isDefaultDecode',
|
567
|
-
value: function isDefaultDecode(decodeMap) {
|
568
|
-
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
569
|
-
}
|
570
|
-
}]);
|
572
|
+
}
|
571
573
|
|
572
|
-
|
573
|
-
|
574
|
+
getOutputLength(inputLength, alpha01) {
|
575
|
+
return inputLength * (3 + alpha01);
|
576
|
+
}
|
574
577
|
|
575
|
-
|
576
|
-
_inherits(DeviceRgbCS, _ColorSpace5);
|
578
|
+
}
|
577
579
|
|
578
|
-
|
579
|
-
|
580
|
+
class DeviceRgbCS extends ColorSpace {
|
581
|
+
constructor() {
|
582
|
+
super("DeviceRGB", 3);
|
583
|
+
}
|
580
584
|
|
581
|
-
|
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;
|
582
589
|
}
|
583
590
|
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
dest[destOffset + 1] = src[srcOffset + 1] * 255;
|
589
|
-
dest[destOffset + 2] = src[srcOffset + 2] * 255;
|
590
|
-
}
|
591
|
-
}, {
|
592
|
-
key: 'getRgbBuffer',
|
593
|
-
value: function getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
|
594
|
-
if (bits === 8 && alpha01 === 0) {
|
595
|
-
dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
|
596
|
-
return;
|
597
|
-
}
|
598
|
-
var scale = 255 / ((1 << bits) - 1);
|
599
|
-
var j = srcOffset,
|
600
|
-
q = destOffset;
|
601
|
-
for (var 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;
|
606
|
-
}
|
607
|
-
}
|
608
|
-
}, {
|
609
|
-
key: 'getOutputLength',
|
610
|
-
value: function getOutputLength(inputLength, alpha01) {
|
611
|
-
return inputLength * (3 + alpha01) / 3 | 0;
|
612
|
-
}
|
613
|
-
}, {
|
614
|
-
key: 'isPassthrough',
|
615
|
-
value: function isPassthrough(bits) {
|
616
|
-
return bits === 8;
|
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;
|
617
595
|
}
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
596
|
+
|
597
|
+
const scale = 255 / ((1 << bits) - 1);
|
598
|
+
let j = srcOffset,
|
599
|
+
q = destOffset;
|
600
|
+
|
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;
|
622
606
|
}
|
623
|
-
}
|
607
|
+
}
|
624
608
|
|
625
|
-
|
626
|
-
|
609
|
+
getOutputLength(inputLength, alpha01) {
|
610
|
+
return inputLength * (3 + alpha01) / 3 | 0;
|
611
|
+
}
|
612
|
+
|
613
|
+
isPassthrough(bits) {
|
614
|
+
return bits === 8;
|
615
|
+
}
|
616
|
+
|
617
|
+
}
|
627
618
|
|
628
|
-
|
619
|
+
const DeviceCmykCS = function DeviceCmykCSClosure() {
|
629
620
|
function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
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;
|
634
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);
|
635
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);
|
636
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);
|
637
628
|
}
|
638
629
|
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
_classCallCheck(this, DeviceCmykCS);
|
630
|
+
class DeviceCmykCS extends ColorSpace {
|
631
|
+
constructor() {
|
632
|
+
super("DeviceCMYK", 4);
|
633
|
+
}
|
644
634
|
|
645
|
-
|
635
|
+
getRgbItem(src, srcOffset, dest, destOffset) {
|
636
|
+
convertToRgb(src, srcOffset, 1, dest, destOffset);
|
646
637
|
}
|
647
638
|
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
value: function getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
|
656
|
-
var scale = 1 / ((1 << bits) - 1);
|
657
|
-
for (var i = 0; i < count; i++) {
|
658
|
-
convertToRgb(src, srcOffset, scale, dest, destOffset);
|
659
|
-
srcOffset += 4;
|
660
|
-
destOffset += 3 + alpha01;
|
661
|
-
}
|
662
|
-
}
|
663
|
-
}, {
|
664
|
-
key: 'getOutputLength',
|
665
|
-
value: function getOutputLength(inputLength, alpha01) {
|
666
|
-
return inputLength / 4 * (3 + alpha01) | 0;
|
667
|
-
}
|
668
|
-
}, {
|
669
|
-
key: 'isDefaultDecode',
|
670
|
-
value: function isDefaultDecode(decodeMap) {
|
671
|
-
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
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;
|
672
646
|
}
|
673
|
-
}
|
647
|
+
}
|
674
648
|
|
675
|
-
|
676
|
-
|
649
|
+
getOutputLength(inputLength, alpha01) {
|
650
|
+
return inputLength / 4 * (3 + alpha01) | 0;
|
651
|
+
}
|
652
|
+
|
653
|
+
}
|
677
654
|
|
678
655
|
return DeviceCmykCS;
|
679
656
|
}();
|
680
|
-
|
657
|
+
|
658
|
+
const CalGrayCS = function CalGrayCSClosure() {
|
681
659
|
function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
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);
|
686
664
|
dest[destOffset] = val;
|
687
665
|
dest[destOffset + 1] = val;
|
688
666
|
dest[destOffset + 2] = val;
|
689
667
|
}
|
690
668
|
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
function CalGrayCS(whitePoint, blackPoint, gamma) {
|
695
|
-
_classCallCheck(this, CalGrayCS);
|
696
|
-
|
697
|
-
var _this7 = _possibleConstructorReturn(this, (CalGrayCS.__proto__ || Object.getPrototypeOf(CalGrayCS)).call(this, 'CalGray', 1));
|
669
|
+
class CalGrayCS extends ColorSpace {
|
670
|
+
constructor(whitePoint, blackPoint, gamma) {
|
671
|
+
super("CalGray", 1);
|
698
672
|
|
699
673
|
if (!whitePoint) {
|
700
|
-
throw new _util.FormatError(
|
674
|
+
throw new _util.FormatError("WhitePoint missing - required for color space CalGray");
|
701
675
|
}
|
676
|
+
|
702
677
|
blackPoint = blackPoint || [0, 0, 0];
|
703
678
|
gamma = gamma || 1;
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
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");
|
713
689
|
}
|
714
|
-
|
715
|
-
|
716
|
-
|
690
|
+
|
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;
|
717
694
|
}
|
718
|
-
|
719
|
-
|
695
|
+
|
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.`);
|
720
698
|
}
|
721
|
-
|
722
|
-
|
723
|
-
|
699
|
+
|
700
|
+
if (this.G < 1) {
|
701
|
+
(0, _util.info)(`Invalid Gamma: ${this.G} for ${this.name}, ` + "falling back to default.");
|
702
|
+
this.G = 1;
|
724
703
|
}
|
725
|
-
return _this7;
|
726
704
|
}
|
727
705
|
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
srcOffset += 1;
|
740
|
-
destOffset += 3 + alpha01;
|
741
|
-
}
|
742
|
-
}
|
743
|
-
}, {
|
744
|
-
key: 'getOutputLength',
|
745
|
-
value: function getOutputLength(inputLength, alpha01) {
|
746
|
-
return inputLength * (3 + alpha01);
|
747
|
-
}
|
748
|
-
}, {
|
749
|
-
key: 'isDefaultDecode',
|
750
|
-
value: function isDefaultDecode(decodeMap) {
|
751
|
-
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
706
|
+
getRgbItem(src, srcOffset, dest, destOffset) {
|
707
|
+
convertToRgb(this, src, srcOffset, dest, destOffset, 1);
|
708
|
+
}
|
709
|
+
|
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;
|
752
717
|
}
|
753
|
-
}
|
718
|
+
}
|
754
719
|
|
755
|
-
|
756
|
-
|
720
|
+
getOutputLength(inputLength, alpha01) {
|
721
|
+
return inputLength * (3 + alpha01);
|
722
|
+
}
|
723
|
+
|
724
|
+
}
|
757
725
|
|
758
726
|
return CalGrayCS;
|
759
727
|
}();
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
728
|
+
|
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;
|
738
|
+
|
769
739
|
function matrixProduct(a, b, result) {
|
770
740
|
result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
771
741
|
result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
|
772
742
|
result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
|
773
743
|
}
|
744
|
+
|
774
745
|
function convertToFlat(sourceWhitePoint, LMS, result) {
|
775
746
|
result[0] = LMS[0] * 1 / sourceWhitePoint[0];
|
776
747
|
result[1] = LMS[1] * 1 / sourceWhitePoint[1];
|
777
748
|
result[2] = LMS[2] * 1 / sourceWhitePoint[2];
|
778
749
|
}
|
750
|
+
|
779
751
|
function convertToD65(sourceWhitePoint, LMS, result) {
|
780
|
-
|
781
|
-
|
782
|
-
|
752
|
+
const D65X = 0.95047;
|
753
|
+
const D65Y = 1;
|
754
|
+
const D65Z = 1.08883;
|
783
755
|
result[0] = LMS[0] * D65X / sourceWhitePoint[0];
|
784
756
|
result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
|
785
757
|
result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
|
786
758
|
}
|
759
|
+
|
787
760
|
function sRGBTransferFunction(color) {
|
788
761
|
if (color <= 0.0031308) {
|
789
762
|
return adjustToRange(0, 1, 12.92 * color);
|
790
763
|
}
|
791
|
-
|
764
|
+
|
765
|
+
return adjustToRange(0, 1, (1 + 0.055) * color ** (1 / 2.4) - 0.055);
|
792
766
|
}
|
767
|
+
|
793
768
|
function adjustToRange(min, max, value) {
|
794
769
|
return Math.max(min, Math.min(max, value));
|
795
770
|
}
|
771
|
+
|
796
772
|
function decodeL(L) {
|
797
773
|
if (L < 0) {
|
798
774
|
return -decodeL(-L);
|
799
775
|
}
|
776
|
+
|
800
777
|
if (L > 8.0) {
|
801
|
-
return
|
778
|
+
return ((L + 16) / 116) ** 3;
|
802
779
|
}
|
780
|
+
|
803
781
|
return L * DECODE_L_CONSTANT;
|
804
782
|
}
|
783
|
+
|
805
784
|
function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
|
806
785
|
if (sourceBlackPoint[0] === 0 && sourceBlackPoint[1] === 0 && sourceBlackPoint[2] === 0) {
|
807
786
|
result[0] = XYZ_Flat[0];
|
@@ -809,23 +788,25 @@ var CalRGBCS = function CalRGBCSClosure() {
|
|
809
788
|
result[2] = XYZ_Flat[2];
|
810
789
|
return;
|
811
790
|
}
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
791
|
+
|
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;
|
825
805
|
result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
|
826
806
|
result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
|
827
807
|
result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
|
828
808
|
}
|
809
|
+
|
829
810
|
function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
|
830
811
|
if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
|
831
812
|
result[0] = XYZ_In[0];
|
@@ -833,248 +814,248 @@ var CalRGBCS = function CalRGBCSClosure() {
|
|
833
814
|
result[2] = XYZ_In[2];
|
834
815
|
return;
|
835
816
|
}
|
836
|
-
|
817
|
+
|
818
|
+
const LMS = result;
|
837
819
|
matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
|
838
|
-
|
820
|
+
const LMS_Flat = tempNormalizeMatrix;
|
839
821
|
convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
|
840
822
|
matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
|
841
823
|
}
|
824
|
+
|
842
825
|
function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
|
843
|
-
|
826
|
+
const LMS = result;
|
844
827
|
matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
|
845
|
-
|
828
|
+
const LMS_D65 = tempNormalizeMatrix;
|
846
829
|
convertToD65(sourceWhitePoint, LMS, LMS_D65);
|
847
830
|
matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
|
848
831
|
}
|
832
|
+
|
849
833
|
function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
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;
|
860
844
|
XYZ[0] = X;
|
861
845
|
XYZ[1] = Y;
|
862
846
|
XYZ[2] = Z;
|
863
|
-
|
847
|
+
const XYZ_Flat = tempConvertMatrix2;
|
864
848
|
normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
|
865
|
-
|
849
|
+
const XYZ_Black = tempConvertMatrix1;
|
866
850
|
compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
|
867
|
-
|
851
|
+
const XYZ_D65 = tempConvertMatrix2;
|
868
852
|
normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
|
869
|
-
|
853
|
+
const SRGB = tempConvertMatrix1;
|
870
854
|
matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
|
871
855
|
dest[destOffset] = sRGBTransferFunction(SRGB[0]) * 255;
|
872
856
|
dest[destOffset + 1] = sRGBTransferFunction(SRGB[1]) * 255;
|
873
857
|
dest[destOffset + 2] = sRGBTransferFunction(SRGB[2]) * 255;
|
874
858
|
}
|
875
859
|
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
|
880
|
-
_classCallCheck(this, CalRGBCS);
|
881
|
-
|
882
|
-
var _this8 = _possibleConstructorReturn(this, (CalRGBCS.__proto__ || Object.getPrototypeOf(CalRGBCS)).call(this, 'CalRGB', 3));
|
860
|
+
class CalRGBCS extends ColorSpace {
|
861
|
+
constructor(whitePoint, blackPoint, gamma, matrix) {
|
862
|
+
super("CalRGB", 3);
|
883
863
|
|
884
864
|
if (!whitePoint) {
|
885
|
-
throw new _util.FormatError(
|
865
|
+
throw new _util.FormatError("WhitePoint missing - required for color space CalRGB");
|
886
866
|
}
|
867
|
+
|
887
868
|
blackPoint = blackPoint || new Float32Array(3);
|
888
869
|
gamma = gamma || new Float32Array([1, 1, 1]);
|
889
870
|
matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
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];
|
891
|
+
|
910
892
|
if (XW < 0 || ZW < 0 || YW !== 1) {
|
911
|
-
throw new _util.FormatError(
|
893
|
+
throw new _util.FormatError(`Invalid WhitePoint components for ${this.name}` + ", no fallback available");
|
912
894
|
}
|
895
|
+
|
913
896
|
if (XB < 0 || YB < 0 || ZB < 0) {
|
914
|
-
(0, _util.info)(
|
915
|
-
|
897
|
+
(0, _util.info)(`Invalid BlackPoint for ${this.name} [${XB}, ${YB}, ${ZB}], ` + "falling back to default.");
|
898
|
+
this.blackPoint = new Float32Array(3);
|
916
899
|
}
|
917
|
-
|
918
|
-
|
919
|
-
|
900
|
+
|
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;
|
920
904
|
}
|
921
|
-
return _this8;
|
922
905
|
}
|
923
906
|
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
srcOffset += 3;
|
936
|
-
destOffset += 3 + alpha01;
|
937
|
-
}
|
938
|
-
}
|
939
|
-
}, {
|
940
|
-
key: 'getOutputLength',
|
941
|
-
value: function getOutputLength(inputLength, alpha01) {
|
942
|
-
return inputLength * (3 + alpha01) / 3 | 0;
|
943
|
-
}
|
944
|
-
}, {
|
945
|
-
key: 'isDefaultDecode',
|
946
|
-
value: function isDefaultDecode(decodeMap) {
|
947
|
-
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
907
|
+
getRgbItem(src, srcOffset, dest, destOffset) {
|
908
|
+
convertToRgb(this, src, srcOffset, dest, destOffset, 1);
|
909
|
+
}
|
910
|
+
|
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;
|
948
918
|
}
|
949
|
-
}
|
919
|
+
}
|
950
920
|
|
951
|
-
|
952
|
-
|
921
|
+
getOutputLength(inputLength, alpha01) {
|
922
|
+
return inputLength * (3 + alpha01) / 3 | 0;
|
923
|
+
}
|
924
|
+
|
925
|
+
}
|
953
926
|
|
954
927
|
return CalRGBCS;
|
955
928
|
}();
|
956
|
-
|
929
|
+
|
930
|
+
const LabCS = function LabCSClosure() {
|
957
931
|
function fn_g(x) {
|
958
|
-
|
932
|
+
let result;
|
933
|
+
|
959
934
|
if (x >= 6 / 29) {
|
960
935
|
result = x * x * x;
|
961
936
|
} else {
|
962
937
|
result = 108 / 841 * (x - 4 / 29);
|
963
938
|
}
|
939
|
+
|
964
940
|
return result;
|
965
941
|
}
|
942
|
+
|
966
943
|
function decode(value, high1, low2, high2) {
|
967
944
|
return low2 + value * (high2 - low2) / high1;
|
968
945
|
}
|
946
|
+
|
969
947
|
function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
|
970
|
-
|
971
|
-
|
972
|
-
|
948
|
+
let Ls = src[srcOffset];
|
949
|
+
let as = src[srcOffset + 1];
|
950
|
+
let bs = src[srcOffset + 2];
|
951
|
+
|
973
952
|
if (maxVal !== false) {
|
974
953
|
Ls = decode(Ls, maxVal, 0, 100);
|
975
954
|
as = decode(as, maxVal, cs.amin, cs.amax);
|
976
955
|
bs = decode(bs, maxVal, cs.bmin, cs.bmax);
|
977
956
|
}
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
957
|
+
|
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;
|
977
|
+
|
989
978
|
if (cs.ZW < 1) {
|
990
|
-
r = X * 3.1339 + Y * -1.
|
991
|
-
g = X * -0.9785 + Y * 1.
|
992
|
-
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;
|
993
982
|
} else {
|
994
983
|
r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
|
995
984
|
g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
|
996
|
-
b = X * 0.0557 + Y * -0.
|
985
|
+
b = X * 0.0557 + Y * -0.204 + Z * 1.057;
|
997
986
|
}
|
987
|
+
|
998
988
|
dest[destOffset] = Math.sqrt(r) * 255;
|
999
989
|
dest[destOffset + 1] = Math.sqrt(g) * 255;
|
1000
990
|
dest[destOffset + 2] = Math.sqrt(b) * 255;
|
1001
991
|
}
|
1002
992
|
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
function LabCS(whitePoint, blackPoint, range) {
|
1007
|
-
_classCallCheck(this, LabCS);
|
1008
|
-
|
1009
|
-
var _this9 = _possibleConstructorReturn(this, (LabCS.__proto__ || Object.getPrototypeOf(LabCS)).call(this, 'Lab', 3));
|
993
|
+
class LabCS extends ColorSpace {
|
994
|
+
constructor(whitePoint, blackPoint, range) {
|
995
|
+
super("Lab", 3);
|
1010
996
|
|
1011
997
|
if (!whitePoint) {
|
1012
|
-
throw new _util.FormatError(
|
998
|
+
throw new _util.FormatError("WhitePoint missing - required for color space Lab");
|
1013
999
|
}
|
1000
|
+
|
1014
1001
|
blackPoint = blackPoint || [0, 0, 0];
|
1015
1002
|
range = range || [-100, 100, -100, 100];
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
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");
|
1028
1016
|
}
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1017
|
+
|
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;
|
1032
1021
|
}
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1022
|
+
|
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;
|
1039
1029
|
}
|
1040
|
-
return _this9;
|
1041
1030
|
}
|
1042
1031
|
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
srcOffset += 3;
|
1055
|
-
destOffset += 3 + alpha01;
|
1056
|
-
}
|
1057
|
-
}
|
1058
|
-
}, {
|
1059
|
-
key: 'getOutputLength',
|
1060
|
-
value: function getOutputLength(inputLength, alpha01) {
|
1061
|
-
return inputLength * (3 + alpha01) / 3 | 0;
|
1062
|
-
}
|
1063
|
-
}, {
|
1064
|
-
key: 'isDefaultDecode',
|
1065
|
-
value: function isDefaultDecode(decodeMap) {
|
1066
|
-
return true;
|
1067
|
-
}
|
1068
|
-
}, {
|
1069
|
-
key: 'usesZeroToOneRange',
|
1070
|
-
get: function get() {
|
1071
|
-
return (0, _util.shadow)(this, 'usesZeroToOneRange', false);
|
1032
|
+
getRgbItem(src, srcOffset, dest, destOffset) {
|
1033
|
+
convertToRgb(this, src, srcOffset, false, dest, destOffset);
|
1034
|
+
}
|
1035
|
+
|
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;
|
1072
1043
|
}
|
1073
|
-
}
|
1044
|
+
}
|
1074
1045
|
|
1075
|
-
|
1076
|
-
|
1046
|
+
getOutputLength(inputLength, alpha01) {
|
1047
|
+
return inputLength * (3 + alpha01) / 3 | 0;
|
1048
|
+
}
|
1049
|
+
|
1050
|
+
isDefaultDecode(decodeMap, bpc) {
|
1051
|
+
return true;
|
1052
|
+
}
|
1053
|
+
|
1054
|
+
get usesZeroToOneRange() {
|
1055
|
+
return (0, _util.shadow)(this, "usesZeroToOneRange", false);
|
1056
|
+
}
|
1057
|
+
|
1058
|
+
}
|
1077
1059
|
|
1078
1060
|
return LabCS;
|
1079
|
-
}();
|
1080
|
-
exports.ColorSpace = ColorSpace;
|
1061
|
+
}();
|