From d18cf474191fca913c1abaee7ce9fef7987055b3 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 10 Jul 2020 16:12:20 +0200 Subject: [PATCH] Remove the special handling, used when creating Indexed ColorSpaces, for the case where the `lookup`-data is a `Stream` This special-case was added in PR 1992, however it became unnecessary with the changes in PR 4824 since all of the ColorSpace parsing is now done on the worker-thread (with only RGB-data being sent to the main-thread). --- src/core/colorspace.js | 20 ++++++-------------- test/unit/colorspace_spec.js | 12 +++++++----- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/core/colorspace.js b/src/core/colorspace.js index ff07c2547..219584ddd 100644 --- a/src/core/colorspace.js +++ b/src/core/colorspace.js @@ -17,7 +17,6 @@ import { assert, FormatError, info, - isString, shadow, unreachable, warn, @@ -472,10 +471,7 @@ class ColorSpace { case "I": baseCS = this._parse(cs[1], xref, resources, pdfFunctionFactory); const hiVal = xref.fetchIfRef(cs[2]) + 1; - let lookup = xref.fetchIfRef(cs[3]); - if (isStream(lookup)) { - lookup = lookup.getBytes(); - } + const lookup = xref.fetchIfRef(cs[3]); return new IndexedCS(baseCS, hiVal, lookup); case "Separation": case "DeviceN": @@ -643,22 +639,18 @@ class IndexedCS extends ColorSpace { this.base = base; this.highVal = highVal; - const baseNumComps = base.numComps; - const length = baseNumComps * highVal; + const length = base.numComps * highVal; + this.lookup = new Uint8Array(length); if (isStream(lookup)) { - this.lookup = new Uint8Array(length); const bytes = lookup.getBytes(length); this.lookup.set(bytes); - } else if (isString(lookup)) { - this.lookup = new Uint8Array(length); + } else if (typeof lookup === "string") { for (let i = 0; i < length; ++i) { - this.lookup[i] = lookup.charCodeAt(i); + this.lookup[i] = lookup.charCodeAt(i) & 0xff; } - } else if (lookup instanceof Uint8Array) { - this.lookup = lookup; } else { - throw new FormatError(`Unrecognized lookup table: ${lookup}`); + throw new FormatError(`IndexedCS - unrecognized lookup table: ${lookup}`); } } diff --git a/test/unit/colorspace_spec.js b/test/unit/colorspace_spec.js index eeb381e33..ca56de381 100644 --- a/test/unit/colorspace_spec.js +++ b/test/unit/colorspace_spec.js @@ -679,11 +679,13 @@ describe("colorspace", function () { describe("IndexedCS", function () { it("should handle the case when cs is an array", function () { // prettier-ignore - const lookup = new Uint8Array([ - 23, 155, 35, - 147, 69, 93, - 255, 109, 70 - ]); + const lookup = new Stream( + new Uint8Array([ + 23, 155, 35, + 147, 69, 93, + 255, 109, 70 + ]) + ); const cs = [Name.get("Indexed"), Name.get("DeviceRGB"), 2, lookup]; const xref = new XRefMock([ {