2017-07-05 20:26:19 +09:00
|
|
|
/* Copyright 2017 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2020-01-02 20:00:16 +09:00
|
|
|
import { Dict, Name, Ref } from "../../src/core/primitives.js";
|
|
|
|
import { Stream, StringStream } from "../../src/core/stream.js";
|
|
|
|
import { ColorSpace } from "../../src/core/colorspace.js";
|
2020-06-18 01:45:11 +09:00
|
|
|
import { LocalColorSpaceCache } from "../../src/core/image_utils.js";
|
2020-01-02 20:00:16 +09:00
|
|
|
import { PDFFunctionFactory } from "../../src/core/function.js";
|
|
|
|
import { XRefMock } from "./test_utils.js";
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("colorspace", function () {
|
2020-06-18 01:45:11 +09:00
|
|
|
describe("ColorSpace.isDefaultDecode", function () {
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should be true if decode is not an array", function () {
|
2017-07-05 20:26:19 +09:00
|
|
|
expect(ColorSpace.isDefaultDecode("string", 0)).toBeTruthy();
|
|
|
|
});
|
2020-06-18 01:45:11 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should be true if length of decode array is not correct", function () {
|
2017-07-05 20:26:19 +09:00
|
|
|
expect(ColorSpace.isDefaultDecode([0], 1)).toBeTruthy();
|
|
|
|
expect(ColorSpace.isDefaultDecode([0, 1, 0], 1)).toBeTruthy();
|
|
|
|
});
|
2020-06-18 01:45:11 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should be true if decode map matches the default decode map", function () {
|
2017-07-05 20:26:19 +09:00
|
|
|
expect(ColorSpace.isDefaultDecode([], 0)).toBeTruthy();
|
|
|
|
|
|
|
|
expect(ColorSpace.isDefaultDecode([0, 0], 1)).toBeFalsy();
|
|
|
|
expect(ColorSpace.isDefaultDecode([0, 1], 1)).toBeTruthy();
|
|
|
|
|
|
|
|
expect(ColorSpace.isDefaultDecode([0, 1, 0, 1, 0, 1], 3)).toBeTruthy();
|
|
|
|
expect(ColorSpace.isDefaultDecode([0, 1, 0, 1, 1, 1], 3)).toBeFalsy();
|
|
|
|
|
|
|
|
expect(
|
|
|
|
ColorSpace.isDefaultDecode([0, 1, 0, 1, 0, 1, 0, 1], 4)
|
|
|
|
).toBeTruthy();
|
|
|
|
expect(
|
|
|
|
ColorSpace.isDefaultDecode([1, 0, 0, 1, 0, 1, 0, 1], 4)
|
|
|
|
).toBeFalsy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-06-18 01:45:11 +09:00
|
|
|
describe("ColorSpace caching", function () {
|
|
|
|
let localColorSpaceCache = null;
|
|
|
|
|
2021-04-11 03:21:31 +09:00
|
|
|
beforeAll(function () {
|
2020-06-18 01:45:11 +09:00
|
|
|
localColorSpaceCache = new LocalColorSpaceCache();
|
|
|
|
});
|
|
|
|
|
2021-04-11 03:21:31 +09:00
|
|
|
afterAll(function () {
|
2020-06-18 01:45:11 +09:00
|
|
|
localColorSpaceCache = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
it("caching by Name", function () {
|
|
|
|
const xref = new XRefMock();
|
|
|
|
const pdfFunctionFactory = new PDFFunctionFactory({
|
|
|
|
xref,
|
|
|
|
});
|
|
|
|
|
|
|
|
const colorSpace1 = ColorSpace.parse({
|
|
|
|
cs: Name.get("Pattern"),
|
|
|
|
xref,
|
|
|
|
resources: null,
|
|
|
|
pdfFunctionFactory,
|
|
|
|
localColorSpaceCache,
|
|
|
|
});
|
|
|
|
expect(colorSpace1.name).toEqual("Pattern");
|
|
|
|
|
|
|
|
const colorSpace2 = ColorSpace.parse({
|
|
|
|
cs: Name.get("Pattern"),
|
|
|
|
xref,
|
|
|
|
resources: null,
|
|
|
|
pdfFunctionFactory,
|
|
|
|
localColorSpaceCache,
|
|
|
|
});
|
|
|
|
expect(colorSpace2.name).toEqual("Pattern");
|
|
|
|
|
|
|
|
const colorSpaceNonCached = ColorSpace.parse({
|
|
|
|
cs: Name.get("Pattern"),
|
|
|
|
xref,
|
|
|
|
resources: null,
|
|
|
|
pdfFunctionFactory,
|
|
|
|
localColorSpaceCache: new LocalColorSpaceCache(),
|
|
|
|
});
|
|
|
|
expect(colorSpaceNonCached.name).toEqual("Pattern");
|
|
|
|
|
|
|
|
const colorSpaceOther = ColorSpace.parse({
|
|
|
|
cs: Name.get("RGB"),
|
|
|
|
xref,
|
|
|
|
resources: null,
|
|
|
|
pdfFunctionFactory,
|
|
|
|
localColorSpaceCache,
|
|
|
|
});
|
|
|
|
expect(colorSpaceOther.name).toEqual("DeviceRGB");
|
|
|
|
|
|
|
|
// These two must be *identical* if caching worked as intended.
|
|
|
|
expect(colorSpace1).toBe(colorSpace2);
|
|
|
|
|
|
|
|
expect(colorSpace1).not.toBe(colorSpaceNonCached);
|
|
|
|
expect(colorSpace1).not.toBe(colorSpaceOther);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("caching by Ref", function () {
|
|
|
|
const paramsCalGray = new Dict();
|
|
|
|
paramsCalGray.set("WhitePoint", [1, 1, 1]);
|
|
|
|
paramsCalGray.set("BlackPoint", [0, 0, 0]);
|
|
|
|
paramsCalGray.set("Gamma", 2.0);
|
|
|
|
|
|
|
|
const paramsCalRGB = new Dict();
|
|
|
|
paramsCalRGB.set("WhitePoint", [1, 1, 1]);
|
|
|
|
paramsCalRGB.set("BlackPoint", [0, 0, 0]);
|
|
|
|
paramsCalRGB.set("Gamma", [1, 1, 1]);
|
|
|
|
paramsCalRGB.set("Matrix", [1, 0, 0, 0, 1, 0, 0, 0, 1]);
|
|
|
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
{
|
|
|
|
ref: Ref.get(50, 0),
|
|
|
|
data: [Name.get("CalGray"), paramsCalGray],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ref: Ref.get(100, 0),
|
|
|
|
data: [Name.get("CalRGB"), paramsCalRGB],
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
const pdfFunctionFactory = new PDFFunctionFactory({
|
|
|
|
xref,
|
|
|
|
});
|
|
|
|
|
|
|
|
const colorSpace1 = ColorSpace.parse({
|
|
|
|
cs: Ref.get(50, 0),
|
|
|
|
xref,
|
|
|
|
resources: null,
|
|
|
|
pdfFunctionFactory,
|
|
|
|
localColorSpaceCache,
|
|
|
|
});
|
|
|
|
expect(colorSpace1.name).toEqual("CalGray");
|
|
|
|
|
|
|
|
const colorSpace2 = ColorSpace.parse({
|
|
|
|
cs: Ref.get(50, 0),
|
|
|
|
xref,
|
|
|
|
resources: null,
|
|
|
|
pdfFunctionFactory,
|
|
|
|
localColorSpaceCache,
|
|
|
|
});
|
|
|
|
expect(colorSpace2.name).toEqual("CalGray");
|
|
|
|
|
|
|
|
const colorSpaceNonCached = ColorSpace.parse({
|
|
|
|
cs: Ref.get(50, 0),
|
|
|
|
xref,
|
|
|
|
resources: null,
|
|
|
|
pdfFunctionFactory,
|
|
|
|
localColorSpaceCache: new LocalColorSpaceCache(),
|
|
|
|
});
|
|
|
|
expect(colorSpaceNonCached.name).toEqual("CalGray");
|
|
|
|
|
|
|
|
const colorSpaceOther = ColorSpace.parse({
|
|
|
|
cs: Ref.get(100, 0),
|
|
|
|
xref,
|
|
|
|
resources: null,
|
|
|
|
pdfFunctionFactory,
|
|
|
|
localColorSpaceCache,
|
|
|
|
});
|
|
|
|
expect(colorSpaceOther.name).toEqual("CalRGB");
|
|
|
|
|
|
|
|
// These two must be *identical* if caching worked as intended.
|
|
|
|
expect(colorSpace1).toBe(colorSpace2);
|
|
|
|
|
|
|
|
expect(colorSpace1).not.toBe(colorSpaceNonCached);
|
|
|
|
expect(colorSpace1).not.toBe(colorSpaceOther);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("DeviceGrayCS", function () {
|
|
|
|
it("should handle the case when cs is a Name object", function () {
|
2020-01-24 17:48:21 +09:00
|
|
|
const cs = Name.get("DeviceGray");
|
|
|
|
const xref = new XRefMock([
|
2017-07-05 20:26:19 +09:00
|
|
|
{
|
2019-05-26 00:40:14 +09:00
|
|
|
ref: Ref.get(10, 0),
|
2017-07-05 20:26:19 +09:00
|
|
|
data: new Dict(),
|
|
|
|
},
|
|
|
|
]);
|
2020-06-18 01:17:43 +09:00
|
|
|
const resources = new Dict();
|
2017-07-05 20:26:19 +09:00
|
|
|
|
2020-01-24 17:48:21 +09:00
|
|
|
const pdfFunctionFactory = new PDFFunctionFactory({
|
2017-09-19 20:49:30 +09:00
|
|
|
xref,
|
|
|
|
});
|
2020-06-18 01:17:43 +09:00
|
|
|
const colorSpace = ColorSpace.parse({
|
|
|
|
cs,
|
|
|
|
xref,
|
|
|
|
resources,
|
|
|
|
pdfFunctionFactory,
|
2020-06-18 01:45:11 +09:00
|
|
|
localColorSpaceCache: new LocalColorSpaceCache(),
|
2020-06-18 01:17:43 +09:00
|
|
|
});
|
2017-07-05 20:26:19 +09:00
|
|
|
|
2020-01-24 17:48:21 +09:00
|
|
|
const testSrc = new Uint8Array([27, 125, 250, 131]);
|
|
|
|
const testDest = new Uint8ClampedArray(4 * 4 * 3);
|
2019-12-25 23:54:34 +09:00
|
|
|
// prettier-ignore
|
2020-01-24 17:48:21 +09:00
|
|
|
const expectedDest = new Uint8ClampedArray([
|
2017-07-05 20:26:19 +09:00
|
|
|
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
|
|
|
|
]);
|
|
|
|
colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0);
|
|
|
|
|
|
|
|
expect(colorSpace.getRgb(new Float32Array([0.1]), 0)).toEqual(
|
2018-06-12 00:25:40 +09:00
|
|
|
new Uint8ClampedArray([26, 26, 26])
|
|
|
|
);
|
2017-07-05 20:26:19 +09:00
|
|
|
expect(colorSpace.getOutputLength(2, 0)).toEqual(6);
|
|
|
|
expect(colorSpace.isPassthrough(8)).toBeFalsy();
|
|
|
|
expect(testDest).toEqual(expectedDest);
|
|
|
|
});
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should handle the case when cs is an indirect object", function () {
|
2020-01-24 17:48:21 +09:00
|
|
|
const cs = Ref.get(10, 0);
|
|
|
|
const xref = new XRefMock([
|
2017-07-05 20:26:19 +09:00
|
|
|
{
|
|
|
|
ref: cs,
|
|
|
|
data: Name.get("DeviceGray"),
|
|
|
|
},
|
|
|
|
]);
|
2020-06-18 01:17:43 +09:00
|
|
|
const resources = new Dict();
|
2017-07-05 20:26:19 +09:00
|
|
|
|
2020-01-24 17:48:21 +09:00
|
|
|
const pdfFunctionFactory = new PDFFunctionFactory({
|
2017-09-19 20:49:30 +09:00
|
|
|
xref,
|
|
|
|
});
|
2020-06-18 01:17:43 +09:00
|
|
|
const colorSpace = ColorSpace.parse({
|
|
|
|
cs,
|
|
|
|
xref,
|
|
|
|
resources,
|
|
|
|
pdfFunctionFactory,
|
2020-06-18 01:45:11 +09:00
|
|
|
localColorSpaceCache: new LocalColorSpaceCache(),
|
2020-06-18 01:17:43 +09:00
|
|
|
});
|
2017-07-05 20:26:19 +09:00
|
|
|
|
2020-01-24 17:48:21 +09:00
|
|
|
const testSrc = new Uint8Array([27, 125, 250, 131]);
|
|
|
|
const testDest = new Uint8ClampedArray(3 * 3 * 3);
|
2019-12-25 23:54:34 +09:00
|
|
|
// prettier-ignore
|
2020-01-24 17:48:21 +09:00
|
|
|
const expectedDest = new Uint8ClampedArray([
|
2017-07-05 20:26:19 +09:00
|
|
|
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
|
|
|
|
]);
|
|
|
|
colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
|
|
|
|
|
|
|
|
expect(colorSpace.getRgb(new Float32Array([0.2]), 0)).toEqual(
|
2018-06-12 00:25:40 +09:00
|
|
|
new Uint8ClampedArray([51, 51, 51])
|
|
|
|
);
|
2017-07-05 20:26:19 +09:00
|
|
|
expect(colorSpace.getOutputLength(3, 1)).toEqual(12);
|
|
|
|
expect(colorSpace.isPassthrough(8)).toBeFalsy();
|
|
|
|
expect(testDest).toEqual(expectedDest);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("DeviceRgbCS", function () {
|
|
|
|
it("should handle the case when cs is a Name object", function () {
|
2020-01-24 17:48:21 +09:00
|
|
|
const cs = Name.get("DeviceRGB");
|
|
|
|
const xref = new XRefMock([
|
2017-07-05 20:26:19 +09:00
|
|
|
{
|
2019-05-26 00:40:14 +09:00
|
|
|
ref: Ref.get(10, 0),
|
2017-07-05 20:26:19 +09:00
|
|
|
data: new Dict(),
|
|
|
|
},
|
|
|
|
]);
|
2020-06-18 01:17:43 +09:00
|
|
|
const resources = new Dict();
|
2017-07-05 20:26:19 +09:00
|
|
|
|
2020-01-24 17:48:21 +09:00
|
|
|
const pdfFunctionFactory = new PDFFunctionFactory({
|
2017-09-19 20:49:30 +09:00
|
|
|
xref,
|
|
|
|
});
|
2020-06-18 01:17:43 +09:00
|
|
|
const colorSpace = ColorSpace.parse({
|
|
|
|
cs,
|
|
|
|
xref,
|
|
|
|
resources,
|
|
|
|
pdfFunctionFactory,
|
2020-06-18 01:45:11 +09:00
|
|
|
localColorSpaceCache: new LocalColorSpaceCache(),
|
2020-06-18 01:17:43 +09:00
|
|
|
});
|
2017-07-05 20:26:19 +09:00
|
|
|
|
2019-12-25 23:54:34 +09:00
|
|
|
// prettier-ignore
|
2020-01-24 17:48:21 +09:00
|
|
|
const testSrc = new Uint8Array([
|
2017-07-05 20:26:19 +09:00
|
|
|
27, 125, 250,
|
|
|
|
131, 139, 140,
|
|
|
|
111, 25, 198,
|
|
|
|
21, 147, 255
|
|
|
|
]);
|
2020-01-24 17:48:21 +09:00
|
|
|
const testDest = new Uint8ClampedArray(4 * 4 * 3);
|
2019-12-25 23:54:34 +09:00
|
|
|
// prettier-ignore
|
2020-01-24 17:48:21 +09:00
|
|
|
const expectedDest = new Uint8ClampedArray([
|
2017-07-05 20:26:19 +09:00
|
|
|
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
|
|
|
|
]);
|
|
|
|
colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0);
|
|
|
|
|
|
|
|
expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3]), 0)).toEqual(
|
2018-06-12 00:25:40 +09:00
|
|
|
new Uint8ClampedArray([26, 51, 77])
|
|
|
|
);
|
2017-07-05 20:26:19 +09:00
|
|
|
expect(colorSpace.getOutputLength(4, 0)).toEqual(4);
|
|
|
|
expect(colorSpace.isPassthrough(8)).toBeTruthy();
|
|
|
|
expect(testDest).toEqual(expectedDest);
|
|
|
|
});
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should handle the case when cs is an indirect object", function () {
|
2020-01-24 17:48:21 +09:00
|
|
|
const cs = Ref.get(10, 0);
|
|
|
|
const xref = new XRefMock([
|
2017-07-05 20:26:19 +09:00
|
|
|
{
|
|
|
|
ref: cs,
|
|
|
|
data: Name.get("DeviceRGB"),
|
|
|
|
},
|
|
|
|
]);
|
2020-06-18 01:17:43 +09:00
|
|
|
const resources = new Dict();
|
2017-07-05 20:26:19 +09:00
|
|
|
|
2020-01-24 17:48:21 +09:00
|
|
|
const pdfFunctionFactory = new PDFFunctionFactory({
|
2017-09-19 20:49:30 +09:00
|
|
|
xref,
|
|
|
|
});
|
2020-06-18 01:17:43 +09:00
|
|
|
const colorSpace = ColorSpace.parse({
|
|
|
|
cs,
|
|
|
|
xref,
|
|
|
|
resources,
|
|
|
|
pdfFunctionFactory,
|
2020-06-18 01:45:11 +09:00
|
|
|
localColorSpaceCache: new LocalColorSpaceCache(),
|
2020-06-18 01:17:43 +09:00
|
|
|
});
|
2017-07-05 20:26:19 +09:00
|
|
|
|
2019-12-25 23:54:34 +09:00
|
|
|
// prettier-ignore
|
2020-01-24 17:48:21 +09:00
|
|
|
const testSrc = new Uint8Array([
|
2017-07-05 20:26:19 +09:00
|
|
|
27, 125, 250,
|
|
|
|
131, 139, 140,
|
|
|
|
111, 25, 198,
|
|
|
|
21, 147, 255
|
|
|
|
]);
|
2020-01-24 17:48:21 +09:00
|
|
|
const testDest = new Uint8ClampedArray(3 * 3 * 3);
|
2019-12-25 23:54:34 +09:00
|
|
|
// prettier-ignore
|
2020-01-24 17:48:21 +09:00
|
|
|
const expectedDest = new Uint8ClampedArray([
|
2017-07-05 20:26:19 +09:00
|
|
|
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
|
|
|
|
]);
|
|
|
|
colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
|
|
|
|
|
|
|
|
expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3]), 0)).toEqual(
|
2018-06-12 00:25:40 +09:00
|
|
|
new Uint8ClampedArray([26, 51, 77])
|
|
|
|
);
|
2017-07-05 20:26:19 +09:00
|
|
|
expect(colorSpace.getOutputLength(4, 1)).toEqual(5);
|
|
|
|
expect(colorSpace.isPassthrough(8)).toBeTruthy();
|
|
|
|
expect(testDest).toEqual(expectedDest);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("DeviceCmykCS", function () {
|
|
|
|
it("should handle the case when cs is a Name object", function () {
|
2020-01-24 17:48:21 +09:00
|
|
|
const cs = Name.get("DeviceCMYK");
|
|
|
|
const xref = new XRefMock([
|
2017-07-05 20:26:19 +09:00
|
|
|
{
|
2019-05-26 00:40:14 +09:00
|
|
|
ref: Ref.get(10, 0),
|
2017-07-05 20:26:19 +09:00
|
|
|
data: new Dict(),
|
|
|
|
},
|
|
|
|
]);
|
2020-06-18 01:17:43 +09:00
|
|
|
const resources = new Dict();
|
2017-07-05 20:26:19 +09:00
|
|
|
|
2020-01-24 17:48:21 +09:00
|
|
|
const pdfFunctionFactory = new PDFFunctionFactory({
|
2017-09-19 20:49:30 +09:00
|
|
|
xref,
|
|
|
|
});
|
2020-06-18 01:17:43 +09:00
|
|
|
const colorSpace = ColorSpace.parse({
|
|
|
|
cs,
|
|
|
|
xref,
|
|
|
|
resources,
|
|
|
|
pdfFunctionFactory,
|
2020-06-18 01:45:11 +09:00
|
|
|
localColorSpaceCache: new LocalColorSpaceCache(),
|
2020-06-18 01:17:43 +09:00
|
|
|
});
|
2017-07-05 20:26:19 +09:00
|
|
|
|
2019-12-25 23:54:34 +09:00
|
|
|
// prettier-ignore
|
2020-01-24 17:48:21 +09:00
|
|
|
const testSrc = new Uint8Array([
|
2017-07-05 20:26:19 +09:00
|
|
|
27, 125, 250, 128,
|
|
|
|
131, 139, 140, 45,
|
|
|
|
111, 25, 198, 78,
|
|
|
|
21, 147, 255, 69
|
|
|
|
]);
|
2020-01-24 17:48:21 +09:00
|
|
|
const testDest = new Uint8ClampedArray(4 * 4 * 3);
|
2019-12-25 23:54:34 +09:00
|
|
|
// prettier-ignore
|
2020-01-24 17:48:21 +09:00
|
|
|
const expectedDest = new Uint8ClampedArray([
|
2018-06-12 00:25:40 +09:00
|
|
|
135, 81, 18,
|
|
|
|
135, 81, 18,
|
|
|
|
114, 102, 97,
|
|
|
|
114, 102, 97,
|
|
|
|
135, 81, 18,
|
|
|
|
135, 81, 18,
|
|
|
|
114, 102, 97,
|
|
|
|
114, 102, 97,
|
|
|
|
112, 144, 75,
|
|
|
|
112, 144, 75,
|
2017-07-05 20:26:19 +09:00
|
|
|
188, 98, 27,
|
|
|
|
188, 98, 27,
|
2018-06-12 00:25:40 +09:00
|
|
|
112, 144, 75,
|
|
|
|
112, 144, 75,
|
2017-07-05 20:26:19 +09:00
|
|
|
188, 98, 27,
|
|
|
|
188, 98, 27
|
|
|
|
]);
|
|
|
|
colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3, 1]), 0)
|
2018-06-12 00:25:40 +09:00
|
|
|
).toEqual(new Uint8ClampedArray([32, 28, 21]));
|
2017-07-05 20:26:19 +09:00
|
|
|
expect(colorSpace.getOutputLength(4, 0)).toEqual(3);
|
|
|
|
expect(colorSpace.isPassthrough(8)).toBeFalsy();
|
|
|
|
expect(testDest).toEqual(expectedDest);
|
|
|
|
});
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should handle the case when cs is an indirect object", function () {
|
2020-01-24 17:48:21 +09:00
|
|
|
const cs = Ref.get(10, 0);
|
|
|
|
const xref = new XRefMock([
|
2017-07-05 20:26:19 +09:00
|
|
|
{
|
|
|
|
ref: cs,
|
|
|
|
data: Name.get("DeviceCMYK"),
|
|
|
|
},
|
|
|
|
]);
|
2020-06-18 01:17:43 +09:00
|
|
|
const resources = new Dict();
|
2017-07-05 20:26:19 +09:00
|
|
|
|
2020-01-24 17:48:21 +09:00
|
|
|
const pdfFunctionFactory = new PDFFunctionFactory({
|
2017-09-19 20:49:30 +09:00
|
|
|
xref,
|
|
|
|
});
|
2020-06-18 01:17:43 +09:00
|
|
|
const colorSpace = ColorSpace.parse({
|
|
|
|
cs,
|
|
|
|
xref,
|
|
|
|
resources,
|
|
|
|
pdfFunctionFactory,
|
2020-06-18 01:45:11 +09:00
|
|
|
localColorSpaceCache: new LocalColorSpaceCache(),
|
2020-06-18 01:17:43 +09:00
|
|
|
});
|
2017-07-05 20:26:19 +09:00
|
|
|
|
2019-12-25 23:54:34 +09:00
|
|
|
// prettier-ignore
|
2020-01-24 17:48:21 +09:00
|
|
|
const testSrc = new Uint8Array([
|
2017-07-05 20:26:19 +09:00
|
|
|
27, 125, 250, 128,
|
|
|
|
131, 139, 140, 45,
|
|
|
|
111, 25, 198, 78,
|
|
|
|
21, 147, 255, 69
|
|
|
|
]);
|
2020-01-24 17:48:21 +09:00
|
|
|
const testDest = new Uint8ClampedArray(3 * 3 * 3);
|
2019-12-25 23:54:34 +09:00
|
|
|
// prettier-ignore
|
2020-01-24 17:48:21 +09:00
|
|
|
const expectedDest = new Uint8ClampedArray([
|
2018-06-12 00:25:40 +09:00
|
|
|
135, 81, 18,
|
|
|
|
135, 81, 18,
|
|
|
|
114, 102, 97,
|
|
|
|
135, 81, 18,
|
|
|
|
135, 81, 18,
|
|
|
|
114, 102, 97,
|
|
|
|
112, 144, 75,
|
|
|
|
112, 144, 75,
|
2017-07-05 20:26:19 +09:00
|
|
|
188, 98, 27
|
|
|
|
]);
|
|
|
|
colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3, 1]), 0)
|
2018-06-12 00:25:40 +09:00
|
|
|
).toEqual(new Uint8ClampedArray([32, 28, 21]));
|
2017-07-05 20:26:19 +09:00
|
|
|
expect(colorSpace.getOutputLength(4, 1)).toEqual(4);
|
|
|
|
expect(colorSpace.isPassthrough(8)).toBeFalsy();
|
|
|
|
expect(testDest).toEqual(expectedDest);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("CalGrayCS", function () {
|
|
|
|
it("should handle the case when cs is an array", function () {
|
2020-01-24 17:48:21 +09:00
|
|
|
const params = new Dict();
|
2017-07-05 20:26:19 +09:00
|
|
|
params.set("WhitePoint", [1, 1, 1]);
|
|
|
|
params.set("BlackPoint", [0, 0, 0]);
|
|
|
|
params.set("Gamma", 2.0);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
2020-01-24 17:48:21 +09:00
|
|
|
const cs = [Name.get("CalGray"), params];
|
|
|
|
const xref = new XRefMock([
|
2017-07-05 20:26:19 +09:00
|
|
|
{
|
2019-05-26 00:40:14 +09:00
|
|
|
ref: Ref.get(10, 0),
|
2017-07-05 20:26:19 +09:00
|
|
|
data: new Dict(),
|
|
|
|
},
|
|
|
|
]);
|
2020-06-18 01:17:43 +09:00
|
|
|
const resources = new Dict();
|
2017-07-05 20:26:19 +09:00
|
|
|
|
2020-01-24 17:48:21 +09:00
|
|
|
const pdfFunctionFactory = new PDFFunctionFactory({
|
2017-09-19 20:49:30 +09:00
|
|
|
xref,
|
|
|
|
});
|
2020-06-18 01:17:43 +09:00
|
|
|
const colorSpace = ColorSpace.parse({
|
|
|
|
cs,
|
|
|
|
xref,
|
|
|
|
resources,
|
|
|
|
pdfFunctionFactory,
|
2020-06-18 01:45:11 +09:00
|
|
|
localColorSpaceCache: new LocalColorSpaceCache(),
|
2020-06-18 01:17:43 +09:00
|
|
|
});
|
2017-07-05 20:26:19 +09:00
|
|
|
|
2020-01-24 17:48:21 +09:00
|
|
|
const testSrc = new Uint8Array([27, 125, 250, 131]);
|
|
|
|
const testDest = new Uint8ClampedArray(4 * 4 * 3);
|
2019-12-25 23:54:34 +09:00
|
|
|
// prettier-ignore
|
2020-01-24 17:48:21 +09:00
|
|
|
const expectedDest = new Uint8ClampedArray([
|
2017-07-05 20:26:19 +09:00
|
|
|
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,
|
2018-06-12 00:25:40 +09:00
|
|
|
149, 149, 149,
|
|
|
|
149, 149, 149,
|
2017-07-05 20:26:19 +09:00
|
|
|
251, 251, 251,
|
|
|
|
251, 251, 251,
|
2018-06-12 00:25:40 +09:00
|
|
|
149, 149, 149,
|
|
|
|
149, 149, 149
|
2017-07-05 20:26:19 +09:00
|
|
|
]);
|
|
|
|
colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0);
|
|
|
|
|
|
|
|
expect(colorSpace.getRgb(new Float32Array([1.0]), 0)).toEqual(
|
2018-06-12 00:25:40 +09:00
|
|
|
new Uint8ClampedArray([255, 255, 255])
|
|
|
|
);
|
2017-07-05 20:26:19 +09:00
|
|
|
expect(colorSpace.getOutputLength(4, 0)).toEqual(12);
|
|
|
|
expect(colorSpace.isPassthrough(8)).toBeFalsy();
|
|
|
|
expect(testDest).toEqual(expectedDest);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("CalRGBCS", function () {
|
|
|
|
it("should handle the case when cs is an array", function () {
|
2020-01-24 17:48:21 +09:00
|
|
|
const params = new Dict();
|
2017-07-05 20:26:19 +09:00
|
|
|
params.set("WhitePoint", [1, 1, 1]);
|
|
|
|
params.set("BlackPoint", [0, 0, 0]);
|
|
|
|
params.set("Gamma", [1, 1, 1]);
|
|
|
|
params.set("Matrix", [1, 0, 0, 0, 1, 0, 0, 0, 1]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
2020-01-24 17:48:21 +09:00
|
|
|
const cs = [Name.get("CalRGB"), params];
|
|
|
|
const xref = new XRefMock([
|
2017-07-05 20:26:19 +09:00
|
|
|
{
|
2019-05-26 00:40:14 +09:00
|
|
|
ref: Ref.get(10, 0),
|
2017-07-05 20:26:19 +09:00
|
|
|
data: new Dict(),
|
|
|
|
},
|
|
|
|
]);
|
2020-06-18 01:17:43 +09:00
|
|
|
const resources = new Dict();
|
2017-07-05 20:26:19 +09:00
|
|
|
|
2020-01-24 17:48:21 +09:00
|
|
|
const pdfFunctionFactory = new PDFFunctionFactory({
|
2017-09-19 20:49:30 +09:00
|
|
|
xref,
|
|
|
|
});
|
2020-06-18 01:17:43 +09:00
|
|
|
const colorSpace = ColorSpace.parse({
|
|
|
|
cs,
|
|
|
|
xref,
|
|
|
|
resources,
|
|
|
|
pdfFunctionFactory,
|
2020-06-18 01:45:11 +09:00
|
|
|
localColorSpaceCache: new LocalColorSpaceCache(),
|
2020-06-18 01:17:43 +09:00
|
|
|
});
|
2017-07-05 20:26:19 +09:00
|
|
|
|
2019-12-25 23:54:34 +09:00
|
|
|
// prettier-ignore
|
2020-01-24 17:48:21 +09:00
|
|
|
const testSrc = new Uint8Array([
|
2017-07-05 20:26:19 +09:00
|
|
|
27, 125, 250,
|
|
|
|
131, 139, 140,
|
|
|
|
111, 25, 198,
|
|
|
|
21, 147, 255
|
|
|
|
]);
|
2020-01-24 17:48:21 +09:00
|
|
|
const testDest = new Uint8ClampedArray(3 * 3 * 3);
|
2019-12-25 23:54:34 +09:00
|
|
|
// prettier-ignore
|
2020-01-24 17:48:21 +09:00
|
|
|
const expectedDest = new Uint8ClampedArray([
|
2017-07-05 20:26:19 +09:00
|
|
|
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
|
|
|
|
]);
|
|
|
|
colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
|
|
|
|
|
|
|
|
expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3]), 0)).toEqual(
|
2018-06-12 00:25:40 +09:00
|
|
|
new Uint8ClampedArray([0, 147, 151])
|
|
|
|
);
|
2017-07-05 20:26:19 +09:00
|
|
|
expect(colorSpace.getOutputLength(4, 0)).toEqual(4);
|
|
|
|
expect(colorSpace.isPassthrough(8)).toBeFalsy();
|
|
|
|
expect(testDest).toEqual(expectedDest);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("LabCS", function () {
|
|
|
|
it("should handle the case when cs is an array", function () {
|
2020-01-24 17:48:21 +09:00
|
|
|
const params = new Dict();
|
2017-07-05 20:26:19 +09:00
|
|
|
params.set("WhitePoint", [1, 1, 1]);
|
|
|
|
params.set("BlackPoint", [0, 0, 0]);
|
|
|
|
params.set("Range", [-100, 100, -100, 100]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
2020-01-24 17:48:21 +09:00
|
|
|
const cs = [Name.get("Lab"), params];
|
|
|
|
const xref = new XRefMock([
|
2017-07-05 20:26:19 +09:00
|
|
|
{
|
2019-05-26 00:40:14 +09:00
|
|
|
ref: Ref.get(10, 0),
|
2017-07-05 20:26:19 +09:00
|
|
|
data: new Dict(),
|
|
|
|
},
|
|
|
|
]);
|
2020-06-18 01:17:43 +09:00
|
|
|
const resources = new Dict();
|
2017-07-05 20:26:19 +09:00
|
|
|
|
2020-01-24 17:48:21 +09:00
|
|
|
const pdfFunctionFactory = new PDFFunctionFactory({
|
2017-09-19 20:49:30 +09:00
|
|
|
xref,
|
|
|
|
});
|
2020-06-18 01:17:43 +09:00
|
|
|
const colorSpace = ColorSpace.parse({
|
|
|
|
cs,
|
|
|
|
xref,
|
|
|
|
resources,
|
|
|
|
pdfFunctionFactory,
|
2020-06-18 01:45:11 +09:00
|
|
|
localColorSpaceCache: new LocalColorSpaceCache(),
|
2020-06-18 01:17:43 +09:00
|
|
|
});
|
2017-07-05 20:26:19 +09:00
|
|
|
|
2019-12-25 23:54:34 +09:00
|
|
|
// prettier-ignore
|
2020-01-24 17:48:21 +09:00
|
|
|
const testSrc = new Uint8Array([
|
2017-07-05 20:26:19 +09:00
|
|
|
27, 25, 50,
|
|
|
|
31, 19, 40,
|
|
|
|
11, 25, 98,
|
|
|
|
21, 47, 55
|
|
|
|
]);
|
2020-01-24 17:48:21 +09:00
|
|
|
const testDest = new Uint8ClampedArray(3 * 3 * 3);
|
2019-12-25 23:54:34 +09:00
|
|
|
// prettier-ignore
|
2020-01-24 17:48:21 +09:00
|
|
|
const expectedDest = new Uint8ClampedArray([
|
2017-07-05 20:26:19 +09:00
|
|
|
0, 49, 101,
|
|
|
|
0, 49, 101,
|
2018-06-12 00:25:40 +09:00
|
|
|
0, 53, 117,
|
2017-07-05 20:26:19 +09:00
|
|
|
0, 49, 101,
|
|
|
|
0, 49, 101,
|
2018-06-12 00:25:40 +09:00
|
|
|
0, 53, 117,
|
|
|
|
0, 41, 40,
|
|
|
|
0, 41, 40,
|
2017-07-05 20:26:19 +09:00
|
|
|
0, 43, 90
|
|
|
|
]);
|
|
|
|
colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
|
|
|
|
|
|
|
|
expect(colorSpace.getRgb([55, 25, 35], 0)).toEqual(
|
2018-06-12 00:25:40 +09:00
|
|
|
new Uint8ClampedArray([188, 100, 61])
|
|
|
|
);
|
2017-07-05 20:26:19 +09:00
|
|
|
expect(colorSpace.getOutputLength(4, 0)).toEqual(4);
|
|
|
|
expect(colorSpace.isPassthrough(8)).toBeFalsy();
|
|
|
|
expect(colorSpace.isDefaultDecode([0, 1])).toBeTruthy();
|
|
|
|
expect(testDest).toEqual(expectedDest);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("IndexedCS", function () {
|
|
|
|
it("should handle the case when cs is an array", function () {
|
2019-12-25 23:54:34 +09:00
|
|
|
// prettier-ignore
|
2020-07-10 23:12:20 +09:00
|
|
|
const lookup = new Stream(
|
|
|
|
new Uint8Array([
|
|
|
|
23, 155, 35,
|
|
|
|
147, 69, 93,
|
|
|
|
255, 109, 70
|
|
|
|
])
|
|
|
|
);
|
2020-01-24 17:48:21 +09:00
|
|
|
const cs = [Name.get("Indexed"), Name.get("DeviceRGB"), 2, lookup];
|
|
|
|
const xref = new XRefMock([
|
2017-07-05 20:26:19 +09:00
|
|
|
{
|
2019-05-26 00:40:14 +09:00
|
|
|
ref: Ref.get(10, 0),
|
2017-07-05 20:26:19 +09:00
|
|
|
data: new Dict(),
|
|
|
|
},
|
|
|
|
]);
|
2020-06-18 01:17:43 +09:00
|
|
|
const resources = new Dict();
|
2017-07-05 20:26:19 +09:00
|
|
|
|
2020-01-24 17:48:21 +09:00
|
|
|
const pdfFunctionFactory = new PDFFunctionFactory({
|
2017-09-19 20:49:30 +09:00
|
|
|
xref,
|
|
|
|
});
|
2020-06-18 01:17:43 +09:00
|
|
|
const colorSpace = ColorSpace.parse({
|
|
|
|
cs,
|
|
|
|
xref,
|
|
|
|
resources,
|
|
|
|
pdfFunctionFactory,
|
2020-06-18 01:45:11 +09:00
|
|
|
localColorSpaceCache: new LocalColorSpaceCache(),
|
2020-06-18 01:17:43 +09:00
|
|
|
});
|
2017-07-05 20:26:19 +09:00
|
|
|
|
2020-01-24 17:48:21 +09:00
|
|
|
const testSrc = new Uint8Array([2, 2, 0, 1]);
|
|
|
|
const testDest = new Uint8ClampedArray(3 * 3 * 3);
|
2019-12-25 23:54:34 +09:00
|
|
|
// prettier-ignore
|
2020-01-24 17:48:21 +09:00
|
|
|
const expectedDest = new Uint8ClampedArray([
|
2017-07-05 20:26:19 +09:00
|
|
|
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,
|
|
|
|
]);
|
|
|
|
colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
|
|
|
|
|
2018-06-12 00:25:40 +09:00
|
|
|
expect(colorSpace.getRgb([2], 0)).toEqual(
|
|
|
|
new Uint8ClampedArray([255, 109, 70])
|
|
|
|
);
|
2017-07-05 20:26:19 +09:00
|
|
|
expect(colorSpace.isPassthrough(8)).toBeFalsy();
|
2019-01-23 02:59:36 +09:00
|
|
|
expect(colorSpace.isDefaultDecode([0, 1], 1)).toBeTruthy();
|
2017-07-05 20:26:19 +09:00
|
|
|
expect(testDest).toEqual(expectedDest);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("AlternateCS", function () {
|
|
|
|
it("should handle the case when cs is an array", function () {
|
2020-01-24 17:48:21 +09:00
|
|
|
const fnDict = new Dict();
|
2017-07-05 20:26:19 +09:00
|
|
|
fnDict.set("FunctionType", 4);
|
|
|
|
fnDict.set("Domain", [0.0, 1.0]);
|
|
|
|
fnDict.set("Range", [0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0]);
|
|
|
|
fnDict.set("Length", 58);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
2017-07-05 20:26:19 +09:00
|
|
|
let fn = new StringStream(
|
|
|
|
"{ dup 0.84 mul " +
|
|
|
|
"exch 0.00 exch " +
|
|
|
|
"dup 0.44 mul " +
|
|
|
|
"exch 0.21 mul }"
|
|
|
|
);
|
|
|
|
fn = new Stream(fn.bytes, 0, 58, fnDict);
|
|
|
|
|
2020-01-24 17:48:21 +09:00
|
|
|
const fnRef = Ref.get(10, 0);
|
2017-07-05 20:26:19 +09:00
|
|
|
|
2020-01-24 17:48:21 +09:00
|
|
|
const cs = [
|
2017-07-05 20:26:19 +09:00
|
|
|
Name.get("Separation"),
|
|
|
|
Name.get("LogoGreen"),
|
|
|
|
Name.get("DeviceCMYK"),
|
|
|
|
fnRef,
|
|
|
|
];
|
2020-01-24 17:48:21 +09:00
|
|
|
const xref = new XRefMock([
|
2017-07-05 20:26:19 +09:00
|
|
|
{
|
|
|
|
ref: fnRef,
|
|
|
|
data: fn,
|
|
|
|
},
|
|
|
|
]);
|
2020-06-18 01:17:43 +09:00
|
|
|
const resources = new Dict();
|
2017-07-05 20:26:19 +09:00
|
|
|
|
2020-01-24 17:48:21 +09:00
|
|
|
const pdfFunctionFactory = new PDFFunctionFactory({
|
2017-09-19 20:49:30 +09:00
|
|
|
xref,
|
|
|
|
});
|
2020-06-18 01:17:43 +09:00
|
|
|
const colorSpace = ColorSpace.parse({
|
|
|
|
cs,
|
|
|
|
xref,
|
|
|
|
resources,
|
|
|
|
pdfFunctionFactory,
|
2020-06-18 01:45:11 +09:00
|
|
|
localColorSpaceCache: new LocalColorSpaceCache(),
|
2020-06-18 01:17:43 +09:00
|
|
|
});
|
2017-07-05 20:26:19 +09:00
|
|
|
|
2020-01-24 17:48:21 +09:00
|
|
|
const testSrc = new Uint8Array([27, 25, 50, 31]);
|
|
|
|
const testDest = new Uint8ClampedArray(3 * 3 * 3);
|
2019-12-25 23:54:34 +09:00
|
|
|
// prettier-ignore
|
2020-01-24 17:48:21 +09:00
|
|
|
const expectedDest = new Uint8ClampedArray([
|
2018-06-12 00:25:40 +09:00
|
|
|
226, 242, 241,
|
|
|
|
226, 242, 241,
|
|
|
|
229, 244, 242,
|
|
|
|
226, 242, 241,
|
|
|
|
226, 242, 241,
|
|
|
|
229, 244, 242,
|
|
|
|
203, 232, 229,
|
|
|
|
203, 232, 229,
|
|
|
|
222, 241, 238
|
2017-07-05 20:26:19 +09:00
|
|
|
]);
|
|
|
|
colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
|
|
|
|
|
|
|
|
expect(colorSpace.getRgb([0.1], 0)).toEqual(
|
2018-06-12 00:25:40 +09:00
|
|
|
new Uint8ClampedArray([228, 243, 242])
|
|
|
|
);
|
2017-07-05 20:26:19 +09:00
|
|
|
expect(colorSpace.isPassthrough(8)).toBeFalsy();
|
|
|
|
expect(colorSpace.isDefaultDecode([0, 1])).toBeTruthy();
|
|
|
|
expect(testDest).toEqual(expectedDest);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|