1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | 'use strict';
|
23 |
|
24 | var _primitives = require('../../core/primitives');
|
25 |
|
26 | var _stream = require('../../core/stream');
|
27 |
|
28 | var _colorspace = require('../../core/colorspace');
|
29 |
|
30 | var _function = require('../../core/function');
|
31 |
|
32 | var _test_utils = require('./test_utils');
|
33 |
|
34 | describe('colorspace', function () {
|
35 | describe('ColorSpace', function () {
|
36 | it('should be true if decode is not an array', function () {
|
37 | expect(_colorspace.ColorSpace.isDefaultDecode('string', 0)).toBeTruthy();
|
38 | });
|
39 | it('should be true if length of decode array is not correct', function () {
|
40 | expect(_colorspace.ColorSpace.isDefaultDecode([0], 1)).toBeTruthy();
|
41 | expect(_colorspace.ColorSpace.isDefaultDecode([0, 1, 0], 1)).toBeTruthy();
|
42 | });
|
43 | it('should be true if decode map matches the default decode map', function () {
|
44 | expect(_colorspace.ColorSpace.isDefaultDecode([], 0)).toBeTruthy();
|
45 | expect(_colorspace.ColorSpace.isDefaultDecode([0, 0], 1)).toBeFalsy();
|
46 | expect(_colorspace.ColorSpace.isDefaultDecode([0, 1], 1)).toBeTruthy();
|
47 | expect(_colorspace.ColorSpace.isDefaultDecode([0, 1, 0, 1, 0, 1], 3)).toBeTruthy();
|
48 | expect(_colorspace.ColorSpace.isDefaultDecode([0, 1, 0, 1, 1, 1], 3)).toBeFalsy();
|
49 | expect(_colorspace.ColorSpace.isDefaultDecode([0, 1, 0, 1, 0, 1, 0, 1], 4)).toBeTruthy();
|
50 | expect(_colorspace.ColorSpace.isDefaultDecode([1, 0, 0, 1, 0, 1, 0, 1], 4)).toBeFalsy();
|
51 | });
|
52 | });
|
53 | describe('DeviceGrayCS', function () {
|
54 | it('should handle the case when cs is a Name object', function () {
|
55 | var cs = _primitives.Name.get('DeviceGray');
|
56 | var xref = new _test_utils.XRefMock([{
|
57 | ref: new _primitives.Ref(10, 0),
|
58 | data: new _primitives.Dict()
|
59 | }]);
|
60 | var res = new _primitives.Dict();
|
61 | var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
|
62 | var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
|
63 | var testSrc = new Uint8Array([27, 125, 250, 131]);
|
64 | var testDest = new Uint8Array(4 * 4 * 3);
|
65 | var expectedDest = new Uint8Array([27, 27, 27, 27, 27, 27, 125, 125, 125, 125, 125, 125, 27, 27, 27, 27, 27, 27, 125, 125, 125, 125, 125, 125, 250, 250, 250, 250, 250, 250, 131, 131, 131, 131, 131, 131, 250, 250, 250, 250, 250, 250, 131, 131, 131, 131, 131, 131]);
|
66 | colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0);
|
67 | expect(colorSpace.getRgb(new Float32Array([0.1]), 0)).toEqual(new Uint8Array([25, 25, 25]));
|
68 | expect(colorSpace.getOutputLength(2, 0)).toEqual(6);
|
69 | expect(colorSpace.isPassthrough(8)).toBeFalsy();
|
70 | expect(testDest).toEqual(expectedDest);
|
71 | });
|
72 | it('should handle the case when cs is an indirect object', function () {
|
73 | var cs = new _primitives.Ref(10, 0);
|
74 | var xref = new _test_utils.XRefMock([{
|
75 | ref: cs,
|
76 | data: _primitives.Name.get('DeviceGray')
|
77 | }]);
|
78 | var res = new _primitives.Dict();
|
79 | var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
|
80 | var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
|
81 | var testSrc = new Uint8Array([27, 125, 250, 131]);
|
82 | var testDest = new Uint8Array(3 * 3 * 3);
|
83 | var expectedDest = new Uint8Array([27, 27, 27, 27, 27, 27, 125, 125, 125, 27, 27, 27, 27, 27, 27, 125, 125, 125, 250, 250, 250, 250, 250, 250, 131, 131, 131]);
|
84 | colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
|
85 | expect(colorSpace.getRgb(new Float32Array([0.2]), 0)).toEqual(new Uint8Array([51, 51, 51]));
|
86 | expect(colorSpace.getOutputLength(3, 1)).toEqual(12);
|
87 | expect(colorSpace.isPassthrough(8)).toBeFalsy();
|
88 | expect(testDest).toEqual(expectedDest);
|
89 | });
|
90 | });
|
91 | describe('DeviceRgbCS', function () {
|
92 | it('should handle the case when cs is a Name object', function () {
|
93 | var cs = _primitives.Name.get('DeviceRGB');
|
94 | var xref = new _test_utils.XRefMock([{
|
95 | ref: new _primitives.Ref(10, 0),
|
96 | data: new _primitives.Dict()
|
97 | }]);
|
98 | var res = new _primitives.Dict();
|
99 | var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
|
100 | var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
|
101 | var testSrc = new Uint8Array([27, 125, 250, 131, 139, 140, 111, 25, 198, 21, 147, 255]);
|
102 | var testDest = new Uint8Array(4 * 4 * 3);
|
103 | var expectedDest = new Uint8Array([27, 125, 250, 27, 125, 250, 131, 139, 140, 131, 139, 140, 27, 125, 250, 27, 125, 250, 131, 139, 140, 131, 139, 140, 111, 25, 198, 111, 25, 198, 21, 147, 255, 21, 147, 255, 111, 25, 198, 111, 25, 198, 21, 147, 255, 21, 147, 255]);
|
104 | colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0);
|
105 | expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3]), 0)).toEqual(new Uint8Array([25, 51, 76]));
|
106 | expect(colorSpace.getOutputLength(4, 0)).toEqual(4);
|
107 | expect(colorSpace.isPassthrough(8)).toBeTruthy();
|
108 | expect(testDest).toEqual(expectedDest);
|
109 | });
|
110 | it('should handle the case when cs is an indirect object', function () {
|
111 | var cs = new _primitives.Ref(10, 0);
|
112 | var xref = new _test_utils.XRefMock([{
|
113 | ref: cs,
|
114 | data: _primitives.Name.get('DeviceRGB')
|
115 | }]);
|
116 | var res = new _primitives.Dict();
|
117 | var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
|
118 | var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
|
119 | var testSrc = new Uint8Array([27, 125, 250, 131, 139, 140, 111, 25, 198, 21, 147, 255]);
|
120 | var testDest = new Uint8Array(3 * 3 * 3);
|
121 | var expectedDest = new Uint8Array([27, 125, 250, 27, 125, 250, 131, 139, 140, 27, 125, 250, 27, 125, 250, 131, 139, 140, 111, 25, 198, 111, 25, 198, 21, 147, 255]);
|
122 | colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
|
123 | expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3]), 0)).toEqual(new Uint8Array([25, 51, 76]));
|
124 | expect(colorSpace.getOutputLength(4, 1)).toEqual(5);
|
125 | expect(colorSpace.isPassthrough(8)).toBeTruthy();
|
126 | expect(testDest).toEqual(expectedDest);
|
127 | });
|
128 | });
|
129 | describe('DeviceCmykCS', function () {
|
130 | it('should handle the case when cs is a Name object', function () {
|
131 | var cs = _primitives.Name.get('DeviceCMYK');
|
132 | var xref = new _test_utils.XRefMock([{
|
133 | ref: new _primitives.Ref(10, 0),
|
134 | data: new _primitives.Dict()
|
135 | }]);
|
136 | var res = new _primitives.Dict();
|
137 | var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
|
138 | var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
|
139 | var testSrc = new Uint8Array([27, 125, 250, 128, 131, 139, 140, 45, 111, 25, 198, 78, 21, 147, 255, 69]);
|
140 | var testDest = new Uint8Array(4 * 4 * 3);
|
141 | var expectedDest = new Uint8Array([135, 80, 18, 135, 80, 18, 113, 102, 97, 113, 102, 97, 135, 80, 18, 135, 80, 18, 113, 102, 97, 113, 102, 97, 112, 143, 75, 112, 143, 75, 188, 98, 27, 188, 98, 27, 112, 143, 75, 112, 143, 75, 188, 98, 27, 188, 98, 27]);
|
142 | colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0);
|
143 | expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3, 1]), 0)).toEqual(new Uint8Array([31, 27, 20]));
|
144 | expect(colorSpace.getOutputLength(4, 0)).toEqual(3);
|
145 | expect(colorSpace.isPassthrough(8)).toBeFalsy();
|
146 | expect(testDest).toEqual(expectedDest);
|
147 | });
|
148 | it('should handle the case when cs is an indirect object', function () {
|
149 | var cs = new _primitives.Ref(10, 0);
|
150 | var xref = new _test_utils.XRefMock([{
|
151 | ref: cs,
|
152 | data: _primitives.Name.get('DeviceCMYK')
|
153 | }]);
|
154 | var res = new _primitives.Dict();
|
155 | var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
|
156 | var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
|
157 | var testSrc = new Uint8Array([27, 125, 250, 128, 131, 139, 140, 45, 111, 25, 198, 78, 21, 147, 255, 69]);
|
158 | var testDest = new Uint8Array(3 * 3 * 3);
|
159 | var expectedDest = new Uint8Array([135, 80, 18, 135, 80, 18, 113, 102, 97, 135, 80, 18, 135, 80, 18, 113, 102, 97, 112, 143, 75, 112, 143, 75, 188, 98, 27]);
|
160 | colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
|
161 | expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3, 1]), 0)).toEqual(new Uint8Array([31, 27, 20]));
|
162 | expect(colorSpace.getOutputLength(4, 1)).toEqual(4);
|
163 | expect(colorSpace.isPassthrough(8)).toBeFalsy();
|
164 | expect(testDest).toEqual(expectedDest);
|
165 | });
|
166 | });
|
167 | describe('CalGrayCS', function () {
|
168 | it('should handle the case when cs is an array', function () {
|
169 | var params = new _primitives.Dict();
|
170 | params.set('WhitePoint', [1, 1, 1]);
|
171 | params.set('BlackPoint', [0, 0, 0]);
|
172 | params.set('Gamma', 2.0);
|
173 | var cs = [_primitives.Name.get('CalGray'), params];
|
174 | var xref = new _test_utils.XRefMock([{
|
175 | ref: new _primitives.Ref(10, 0),
|
176 | data: new _primitives.Dict()
|
177 | }]);
|
178 | var res = new _primitives.Dict();
|
179 | var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
|
180 | var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
|
181 | var testSrc = new Uint8Array([27, 125, 250, 131]);
|
182 | var testDest = new Uint8Array(4 * 4 * 3);
|
183 | var expectedDest = new Uint8Array([25, 25, 25, 25, 25, 25, 143, 143, 143, 143, 143, 143, 25, 25, 25, 25, 25, 25, 143, 143, 143, 143, 143, 143, 251, 251, 251, 251, 251, 251, 148, 148, 148, 148, 148, 148, 251, 251, 251, 251, 251, 251, 148, 148, 148, 148, 148, 148]);
|
184 | colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0);
|
185 | expect(colorSpace.getRgb(new Float32Array([1.0]), 0)).toEqual(new Uint8Array([255, 255, 255]));
|
186 | expect(colorSpace.getOutputLength(4, 0)).toEqual(12);
|
187 | expect(colorSpace.isPassthrough(8)).toBeFalsy();
|
188 | expect(testDest).toEqual(expectedDest);
|
189 | });
|
190 | });
|
191 | describe('CalRGBCS', function () {
|
192 | it('should handle the case when cs is an array', function () {
|
193 | var params = new _primitives.Dict();
|
194 | params.set('WhitePoint', [1, 1, 1]);
|
195 | params.set('BlackPoint', [0, 0, 0]);
|
196 | params.set('Gamma', [1, 1, 1]);
|
197 | params.set('Matrix', [1, 0, 0, 0, 1, 0, 0, 0, 1]);
|
198 | var cs = [_primitives.Name.get('CalRGB'), params];
|
199 | var xref = new _test_utils.XRefMock([{
|
200 | ref: new _primitives.Ref(10, 0),
|
201 | data: new _primitives.Dict()
|
202 | }]);
|
203 | var res = new _primitives.Dict();
|
204 | var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
|
205 | var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
|
206 | var testSrc = new Uint8Array([27, 125, 250, 131, 139, 140, 111, 25, 198, 21, 147, 255]);
|
207 | var testDest = new Uint8Array(3 * 3 * 3);
|
208 | var expectedDest = new Uint8Array([0, 238, 255, 0, 238, 255, 185, 196, 195, 0, 238, 255, 0, 238, 255, 185, 196, 195, 235, 0, 243, 235, 0, 243, 0, 255, 255]);
|
209 | colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
|
210 | expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3]), 0)).toEqual(new Uint8Array([0, 147, 151]));
|
211 | expect(colorSpace.getOutputLength(4, 0)).toEqual(4);
|
212 | expect(colorSpace.isPassthrough(8)).toBeFalsy();
|
213 | expect(testDest).toEqual(expectedDest);
|
214 | });
|
215 | });
|
216 | describe('LabCS', function () {
|
217 | it('should handle the case when cs is an array', function () {
|
218 | var params = new _primitives.Dict();
|
219 | params.set('WhitePoint', [1, 1, 1]);
|
220 | params.set('BlackPoint', [0, 0, 0]);
|
221 | params.set('Range', [-100, 100, -100, 100]);
|
222 | var cs = [_primitives.Name.get('Lab'), params];
|
223 | var xref = new _test_utils.XRefMock([{
|
224 | ref: new _primitives.Ref(10, 0),
|
225 | data: new _primitives.Dict()
|
226 | }]);
|
227 | var res = new _primitives.Dict();
|
228 | var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
|
229 | var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
|
230 | var testSrc = new Uint8Array([27, 25, 50, 31, 19, 40, 11, 25, 98, 21, 47, 55]);
|
231 | var testDest = new Uint8Array(3 * 3 * 3);
|
232 | var expectedDest = new Uint8Array([0, 49, 101, 0, 49, 101, 0, 53, 116, 0, 49, 101, 0, 49, 101, 0, 53, 116, 0, 40, 39, 0, 40, 39, 0, 43, 90]);
|
233 | colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
|
234 | expect(colorSpace.getRgb([55, 25, 35], 0)).toEqual(new Uint8Array([188, 99, 61]));
|
235 | expect(colorSpace.getOutputLength(4, 0)).toEqual(4);
|
236 | expect(colorSpace.isPassthrough(8)).toBeFalsy();
|
237 | expect(colorSpace.isDefaultDecode([0, 1])).toBeTruthy();
|
238 | expect(testDest).toEqual(expectedDest);
|
239 | });
|
240 | });
|
241 | describe('IndexedCS', function () {
|
242 | it('should handle the case when cs is an array', function () {
|
243 | var lookup = new Uint8Array([23, 155, 35, 147, 69, 93, 255, 109, 70]);
|
244 | var cs = [_primitives.Name.get('Indexed'), _primitives.Name.get('DeviceRGB'), 2, lookup];
|
245 | var xref = new _test_utils.XRefMock([{
|
246 | ref: new _primitives.Ref(10, 0),
|
247 | data: new _primitives.Dict()
|
248 | }]);
|
249 | var res = new _primitives.Dict();
|
250 | var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
|
251 | var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
|
252 | var testSrc = new Uint8Array([2, 2, 0, 1]);
|
253 | var testDest = new Uint8Array(3 * 3 * 3);
|
254 | var expectedDest = new Uint8Array([255, 109, 70, 255, 109, 70, 255, 109, 70, 255, 109, 70, 255, 109, 70, 255, 109, 70, 23, 155, 35, 23, 155, 35, 147, 69, 93]);
|
255 | colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
|
256 | expect(colorSpace.getRgb([2], 0)).toEqual(new Uint8Array([255, 109, 70]));
|
257 | expect(colorSpace.isPassthrough(8)).toBeFalsy();
|
258 | expect(colorSpace.isDefaultDecode([0, 1])).toBeTruthy();
|
259 | expect(testDest).toEqual(expectedDest);
|
260 | });
|
261 | });
|
262 | describe('AlternateCS', function () {
|
263 | it('should handle the case when cs is an array', function () {
|
264 | var fnDict = new _primitives.Dict();
|
265 | fnDict.set('FunctionType', 4);
|
266 | fnDict.set('Domain', [0.0, 1.0]);
|
267 | fnDict.set('Range', [0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0]);
|
268 | fnDict.set('Length', 58);
|
269 | var fn = new _stream.StringStream('{ dup 0.84 mul ' + 'exch 0.00 exch ' + 'dup 0.44 mul ' + 'exch 0.21 mul }');
|
270 | fn = new _stream.Stream(fn.bytes, 0, 58, fnDict);
|
271 | var fnRef = new _primitives.Ref(10, 0);
|
272 | var cs = [_primitives.Name.get('Separation'), _primitives.Name.get('LogoGreen'), _primitives.Name.get('DeviceCMYK'), fnRef];
|
273 | var xref = new _test_utils.XRefMock([{
|
274 | ref: fnRef,
|
275 | data: fn
|
276 | }]);
|
277 | var res = new _primitives.Dict();
|
278 | var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
|
279 | var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
|
280 | var testSrc = new Uint8Array([27, 25, 50, 31]);
|
281 | var testDest = new Uint8Array(3 * 3 * 3);
|
282 | var expectedDest = new Uint8Array([227, 243, 242, 227, 243, 242, 228, 243, 242, 227, 243, 242, 227, 243, 242, 228, 243, 242, 203, 233, 229, 203, 233, 229, 222, 241, 239]);
|
283 | colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
|
284 | expect(colorSpace.getRgb([0.1], 0)).toEqual(new Uint8Array([228, 243, 241]));
|
285 | expect(colorSpace.isPassthrough(8)).toBeFalsy();
|
286 | expect(colorSpace.isDefaultDecode([0, 1])).toBeTruthy();
|
287 | expect(testDest).toEqual(expectedDest);
|
288 | });
|
289 | });
|
290 | }); |
\ | No newline at end of file |