2
0

colorspace_spec.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2020 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. "use strict";
  23. var _primitives = require("../../core/primitives.js");
  24. var _stream = require("../../core/stream.js");
  25. var _colorspace = require("../../core/colorspace.js");
  26. var _image_utils = require("../../core/image_utils.js");
  27. var _function = require("../../core/function.js");
  28. var _test_utils = require("./test_utils.js");
  29. describe("colorspace", function () {
  30. describe("ColorSpace.isDefaultDecode", function () {
  31. it("should be true if decode is not an array", function () {
  32. expect(_colorspace.ColorSpace.isDefaultDecode("string", 0)).toBeTruthy();
  33. });
  34. it("should be true if length of decode array is not correct", function () {
  35. expect(_colorspace.ColorSpace.isDefaultDecode([0], 1)).toBeTruthy();
  36. expect(_colorspace.ColorSpace.isDefaultDecode([0, 1, 0], 1)).toBeTruthy();
  37. });
  38. it("should be true if decode map matches the default decode map", function () {
  39. expect(_colorspace.ColorSpace.isDefaultDecode([], 0)).toBeTruthy();
  40. expect(_colorspace.ColorSpace.isDefaultDecode([0, 0], 1)).toBeFalsy();
  41. expect(_colorspace.ColorSpace.isDefaultDecode([0, 1], 1)).toBeTruthy();
  42. expect(_colorspace.ColorSpace.isDefaultDecode([0, 1, 0, 1, 0, 1], 3)).toBeTruthy();
  43. expect(_colorspace.ColorSpace.isDefaultDecode([0, 1, 0, 1, 1, 1], 3)).toBeFalsy();
  44. expect(_colorspace.ColorSpace.isDefaultDecode([0, 1, 0, 1, 0, 1, 0, 1], 4)).toBeTruthy();
  45. expect(_colorspace.ColorSpace.isDefaultDecode([1, 0, 0, 1, 0, 1, 0, 1], 4)).toBeFalsy();
  46. });
  47. });
  48. describe("ColorSpace caching", function () {
  49. let localColorSpaceCache = null;
  50. beforeAll(function (done) {
  51. localColorSpaceCache = new _image_utils.LocalColorSpaceCache();
  52. done();
  53. });
  54. afterAll(function (done) {
  55. localColorSpaceCache = null;
  56. done();
  57. });
  58. it("caching by Name", function () {
  59. const xref = new _test_utils.XRefMock();
  60. const pdfFunctionFactory = new _function.PDFFunctionFactory({
  61. xref
  62. });
  63. const colorSpace1 = _colorspace.ColorSpace.parse({
  64. cs: _primitives.Name.get("Pattern"),
  65. xref,
  66. resources: null,
  67. pdfFunctionFactory,
  68. localColorSpaceCache
  69. });
  70. expect(colorSpace1.name).toEqual("Pattern");
  71. const colorSpace2 = _colorspace.ColorSpace.parse({
  72. cs: _primitives.Name.get("Pattern"),
  73. xref,
  74. resources: null,
  75. pdfFunctionFactory,
  76. localColorSpaceCache
  77. });
  78. expect(colorSpace2.name).toEqual("Pattern");
  79. const colorSpaceNonCached = _colorspace.ColorSpace.parse({
  80. cs: _primitives.Name.get("Pattern"),
  81. xref,
  82. resources: null,
  83. pdfFunctionFactory,
  84. localColorSpaceCache: new _image_utils.LocalColorSpaceCache()
  85. });
  86. expect(colorSpaceNonCached.name).toEqual("Pattern");
  87. const colorSpaceOther = _colorspace.ColorSpace.parse({
  88. cs: _primitives.Name.get("RGB"),
  89. xref,
  90. resources: null,
  91. pdfFunctionFactory,
  92. localColorSpaceCache
  93. });
  94. expect(colorSpaceOther.name).toEqual("DeviceRGB");
  95. expect(colorSpace1).toBe(colorSpace2);
  96. expect(colorSpace1).not.toBe(colorSpaceNonCached);
  97. expect(colorSpace1).not.toBe(colorSpaceOther);
  98. });
  99. it("caching by Ref", function () {
  100. const paramsCalGray = new _primitives.Dict();
  101. paramsCalGray.set("WhitePoint", [1, 1, 1]);
  102. paramsCalGray.set("BlackPoint", [0, 0, 0]);
  103. paramsCalGray.set("Gamma", 2.0);
  104. const paramsCalRGB = new _primitives.Dict();
  105. paramsCalRGB.set("WhitePoint", [1, 1, 1]);
  106. paramsCalRGB.set("BlackPoint", [0, 0, 0]);
  107. paramsCalRGB.set("Gamma", [1, 1, 1]);
  108. paramsCalRGB.set("Matrix", [1, 0, 0, 0, 1, 0, 0, 0, 1]);
  109. const xref = new _test_utils.XRefMock([{
  110. ref: _primitives.Ref.get(50, 0),
  111. data: [_primitives.Name.get("CalGray"), paramsCalGray]
  112. }, {
  113. ref: _primitives.Ref.get(100, 0),
  114. data: [_primitives.Name.get("CalRGB"), paramsCalRGB]
  115. }]);
  116. const pdfFunctionFactory = new _function.PDFFunctionFactory({
  117. xref
  118. });
  119. const colorSpace1 = _colorspace.ColorSpace.parse({
  120. cs: _primitives.Ref.get(50, 0),
  121. xref,
  122. resources: null,
  123. pdfFunctionFactory,
  124. localColorSpaceCache
  125. });
  126. expect(colorSpace1.name).toEqual("CalGray");
  127. const colorSpace2 = _colorspace.ColorSpace.parse({
  128. cs: _primitives.Ref.get(50, 0),
  129. xref,
  130. resources: null,
  131. pdfFunctionFactory,
  132. localColorSpaceCache
  133. });
  134. expect(colorSpace2.name).toEqual("CalGray");
  135. const colorSpaceNonCached = _colorspace.ColorSpace.parse({
  136. cs: _primitives.Ref.get(50, 0),
  137. xref,
  138. resources: null,
  139. pdfFunctionFactory,
  140. localColorSpaceCache: new _image_utils.LocalColorSpaceCache()
  141. });
  142. expect(colorSpaceNonCached.name).toEqual("CalGray");
  143. const colorSpaceOther = _colorspace.ColorSpace.parse({
  144. cs: _primitives.Ref.get(100, 0),
  145. xref,
  146. resources: null,
  147. pdfFunctionFactory,
  148. localColorSpaceCache
  149. });
  150. expect(colorSpaceOther.name).toEqual("CalRGB");
  151. expect(colorSpace1).toBe(colorSpace2);
  152. expect(colorSpace1).not.toBe(colorSpaceNonCached);
  153. expect(colorSpace1).not.toBe(colorSpaceOther);
  154. });
  155. });
  156. describe("DeviceGrayCS", function () {
  157. it("should handle the case when cs is a Name object", function () {
  158. const cs = _primitives.Name.get("DeviceGray");
  159. const xref = new _test_utils.XRefMock([{
  160. ref: _primitives.Ref.get(10, 0),
  161. data: new _primitives.Dict()
  162. }]);
  163. const resources = new _primitives.Dict();
  164. const pdfFunctionFactory = new _function.PDFFunctionFactory({
  165. xref
  166. });
  167. const colorSpace = _colorspace.ColorSpace.parse({
  168. cs,
  169. xref,
  170. resources,
  171. pdfFunctionFactory,
  172. localColorSpaceCache: new _image_utils.LocalColorSpaceCache()
  173. });
  174. const testSrc = new Uint8Array([27, 125, 250, 131]);
  175. const testDest = new Uint8ClampedArray(4 * 4 * 3);
  176. const expectedDest = new Uint8ClampedArray([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]);
  177. colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0);
  178. expect(colorSpace.getRgb(new Float32Array([0.1]), 0)).toEqual(new Uint8ClampedArray([26, 26, 26]));
  179. expect(colorSpace.getOutputLength(2, 0)).toEqual(6);
  180. expect(colorSpace.isPassthrough(8)).toBeFalsy();
  181. expect(testDest).toEqual(expectedDest);
  182. });
  183. it("should handle the case when cs is an indirect object", function () {
  184. const cs = _primitives.Ref.get(10, 0);
  185. const xref = new _test_utils.XRefMock([{
  186. ref: cs,
  187. data: _primitives.Name.get("DeviceGray")
  188. }]);
  189. const resources = new _primitives.Dict();
  190. const pdfFunctionFactory = new _function.PDFFunctionFactory({
  191. xref
  192. });
  193. const colorSpace = _colorspace.ColorSpace.parse({
  194. cs,
  195. xref,
  196. resources,
  197. pdfFunctionFactory,
  198. localColorSpaceCache: new _image_utils.LocalColorSpaceCache()
  199. });
  200. const testSrc = new Uint8Array([27, 125, 250, 131]);
  201. const testDest = new Uint8ClampedArray(3 * 3 * 3);
  202. const expectedDest = new Uint8ClampedArray([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]);
  203. colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
  204. expect(colorSpace.getRgb(new Float32Array([0.2]), 0)).toEqual(new Uint8ClampedArray([51, 51, 51]));
  205. expect(colorSpace.getOutputLength(3, 1)).toEqual(12);
  206. expect(colorSpace.isPassthrough(8)).toBeFalsy();
  207. expect(testDest).toEqual(expectedDest);
  208. });
  209. });
  210. describe("DeviceRgbCS", function () {
  211. it("should handle the case when cs is a Name object", function () {
  212. const cs = _primitives.Name.get("DeviceRGB");
  213. const xref = new _test_utils.XRefMock([{
  214. ref: _primitives.Ref.get(10, 0),
  215. data: new _primitives.Dict()
  216. }]);
  217. const resources = new _primitives.Dict();
  218. const pdfFunctionFactory = new _function.PDFFunctionFactory({
  219. xref
  220. });
  221. const colorSpace = _colorspace.ColorSpace.parse({
  222. cs,
  223. xref,
  224. resources,
  225. pdfFunctionFactory,
  226. localColorSpaceCache: new _image_utils.LocalColorSpaceCache()
  227. });
  228. const testSrc = new Uint8Array([27, 125, 250, 131, 139, 140, 111, 25, 198, 21, 147, 255]);
  229. const testDest = new Uint8ClampedArray(4 * 4 * 3);
  230. const expectedDest = new Uint8ClampedArray([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]);
  231. colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0);
  232. expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3]), 0)).toEqual(new Uint8ClampedArray([26, 51, 77]));
  233. expect(colorSpace.getOutputLength(4, 0)).toEqual(4);
  234. expect(colorSpace.isPassthrough(8)).toBeTruthy();
  235. expect(testDest).toEqual(expectedDest);
  236. });
  237. it("should handle the case when cs is an indirect object", function () {
  238. const cs = _primitives.Ref.get(10, 0);
  239. const xref = new _test_utils.XRefMock([{
  240. ref: cs,
  241. data: _primitives.Name.get("DeviceRGB")
  242. }]);
  243. const resources = new _primitives.Dict();
  244. const pdfFunctionFactory = new _function.PDFFunctionFactory({
  245. xref
  246. });
  247. const colorSpace = _colorspace.ColorSpace.parse({
  248. cs,
  249. xref,
  250. resources,
  251. pdfFunctionFactory,
  252. localColorSpaceCache: new _image_utils.LocalColorSpaceCache()
  253. });
  254. const testSrc = new Uint8Array([27, 125, 250, 131, 139, 140, 111, 25, 198, 21, 147, 255]);
  255. const testDest = new Uint8ClampedArray(3 * 3 * 3);
  256. const expectedDest = new Uint8ClampedArray([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]);
  257. colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
  258. expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3]), 0)).toEqual(new Uint8ClampedArray([26, 51, 77]));
  259. expect(colorSpace.getOutputLength(4, 1)).toEqual(5);
  260. expect(colorSpace.isPassthrough(8)).toBeTruthy();
  261. expect(testDest).toEqual(expectedDest);
  262. });
  263. });
  264. describe("DeviceCmykCS", function () {
  265. it("should handle the case when cs is a Name object", function () {
  266. const cs = _primitives.Name.get("DeviceCMYK");
  267. const xref = new _test_utils.XRefMock([{
  268. ref: _primitives.Ref.get(10, 0),
  269. data: new _primitives.Dict()
  270. }]);
  271. const resources = new _primitives.Dict();
  272. const pdfFunctionFactory = new _function.PDFFunctionFactory({
  273. xref
  274. });
  275. const colorSpace = _colorspace.ColorSpace.parse({
  276. cs,
  277. xref,
  278. resources,
  279. pdfFunctionFactory,
  280. localColorSpaceCache: new _image_utils.LocalColorSpaceCache()
  281. });
  282. const testSrc = new Uint8Array([27, 125, 250, 128, 131, 139, 140, 45, 111, 25, 198, 78, 21, 147, 255, 69]);
  283. const testDest = new Uint8ClampedArray(4 * 4 * 3);
  284. const expectedDest = new Uint8ClampedArray([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, 188, 98, 27, 188, 98, 27, 112, 144, 75, 112, 144, 75, 188, 98, 27, 188, 98, 27]);
  285. colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0);
  286. expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3, 1]), 0)).toEqual(new Uint8ClampedArray([32, 28, 21]));
  287. expect(colorSpace.getOutputLength(4, 0)).toEqual(3);
  288. expect(colorSpace.isPassthrough(8)).toBeFalsy();
  289. expect(testDest).toEqual(expectedDest);
  290. });
  291. it("should handle the case when cs is an indirect object", function () {
  292. const cs = _primitives.Ref.get(10, 0);
  293. const xref = new _test_utils.XRefMock([{
  294. ref: cs,
  295. data: _primitives.Name.get("DeviceCMYK")
  296. }]);
  297. const resources = new _primitives.Dict();
  298. const pdfFunctionFactory = new _function.PDFFunctionFactory({
  299. xref
  300. });
  301. const colorSpace = _colorspace.ColorSpace.parse({
  302. cs,
  303. xref,
  304. resources,
  305. pdfFunctionFactory,
  306. localColorSpaceCache: new _image_utils.LocalColorSpaceCache()
  307. });
  308. const testSrc = new Uint8Array([27, 125, 250, 128, 131, 139, 140, 45, 111, 25, 198, 78, 21, 147, 255, 69]);
  309. const testDest = new Uint8ClampedArray(3 * 3 * 3);
  310. const expectedDest = new Uint8ClampedArray([135, 81, 18, 135, 81, 18, 114, 102, 97, 135, 81, 18, 135, 81, 18, 114, 102, 97, 112, 144, 75, 112, 144, 75, 188, 98, 27]);
  311. colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
  312. expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3, 1]), 0)).toEqual(new Uint8ClampedArray([32, 28, 21]));
  313. expect(colorSpace.getOutputLength(4, 1)).toEqual(4);
  314. expect(colorSpace.isPassthrough(8)).toBeFalsy();
  315. expect(testDest).toEqual(expectedDest);
  316. });
  317. });
  318. describe("CalGrayCS", function () {
  319. it("should handle the case when cs is an array", function () {
  320. const params = new _primitives.Dict();
  321. params.set("WhitePoint", [1, 1, 1]);
  322. params.set("BlackPoint", [0, 0, 0]);
  323. params.set("Gamma", 2.0);
  324. const cs = [_primitives.Name.get("CalGray"), params];
  325. const xref = new _test_utils.XRefMock([{
  326. ref: _primitives.Ref.get(10, 0),
  327. data: new _primitives.Dict()
  328. }]);
  329. const resources = new _primitives.Dict();
  330. const pdfFunctionFactory = new _function.PDFFunctionFactory({
  331. xref
  332. });
  333. const colorSpace = _colorspace.ColorSpace.parse({
  334. cs,
  335. xref,
  336. resources,
  337. pdfFunctionFactory,
  338. localColorSpaceCache: new _image_utils.LocalColorSpaceCache()
  339. });
  340. const testSrc = new Uint8Array([27, 125, 250, 131]);
  341. const testDest = new Uint8ClampedArray(4 * 4 * 3);
  342. const expectedDest = new Uint8ClampedArray([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, 149, 149, 149, 149, 149, 149, 251, 251, 251, 251, 251, 251, 149, 149, 149, 149, 149, 149]);
  343. colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0);
  344. expect(colorSpace.getRgb(new Float32Array([1.0]), 0)).toEqual(new Uint8ClampedArray([255, 255, 255]));
  345. expect(colorSpace.getOutputLength(4, 0)).toEqual(12);
  346. expect(colorSpace.isPassthrough(8)).toBeFalsy();
  347. expect(testDest).toEqual(expectedDest);
  348. });
  349. });
  350. describe("CalRGBCS", function () {
  351. it("should handle the case when cs is an array", function () {
  352. const params = new _primitives.Dict();
  353. params.set("WhitePoint", [1, 1, 1]);
  354. params.set("BlackPoint", [0, 0, 0]);
  355. params.set("Gamma", [1, 1, 1]);
  356. params.set("Matrix", [1, 0, 0, 0, 1, 0, 0, 0, 1]);
  357. const cs = [_primitives.Name.get("CalRGB"), params];
  358. const xref = new _test_utils.XRefMock([{
  359. ref: _primitives.Ref.get(10, 0),
  360. data: new _primitives.Dict()
  361. }]);
  362. const resources = new _primitives.Dict();
  363. const pdfFunctionFactory = new _function.PDFFunctionFactory({
  364. xref
  365. });
  366. const colorSpace = _colorspace.ColorSpace.parse({
  367. cs,
  368. xref,
  369. resources,
  370. pdfFunctionFactory,
  371. localColorSpaceCache: new _image_utils.LocalColorSpaceCache()
  372. });
  373. const testSrc = new Uint8Array([27, 125, 250, 131, 139, 140, 111, 25, 198, 21, 147, 255]);
  374. const testDest = new Uint8ClampedArray(3 * 3 * 3);
  375. const expectedDest = new Uint8ClampedArray([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]);
  376. colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
  377. expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3]), 0)).toEqual(new Uint8ClampedArray([0, 147, 151]));
  378. expect(colorSpace.getOutputLength(4, 0)).toEqual(4);
  379. expect(colorSpace.isPassthrough(8)).toBeFalsy();
  380. expect(testDest).toEqual(expectedDest);
  381. });
  382. });
  383. describe("LabCS", function () {
  384. it("should handle the case when cs is an array", function () {
  385. const params = new _primitives.Dict();
  386. params.set("WhitePoint", [1, 1, 1]);
  387. params.set("BlackPoint", [0, 0, 0]);
  388. params.set("Range", [-100, 100, -100, 100]);
  389. const cs = [_primitives.Name.get("Lab"), params];
  390. const xref = new _test_utils.XRefMock([{
  391. ref: _primitives.Ref.get(10, 0),
  392. data: new _primitives.Dict()
  393. }]);
  394. const resources = new _primitives.Dict();
  395. const pdfFunctionFactory = new _function.PDFFunctionFactory({
  396. xref
  397. });
  398. const colorSpace = _colorspace.ColorSpace.parse({
  399. cs,
  400. xref,
  401. resources,
  402. pdfFunctionFactory,
  403. localColorSpaceCache: new _image_utils.LocalColorSpaceCache()
  404. });
  405. const testSrc = new Uint8Array([27, 25, 50, 31, 19, 40, 11, 25, 98, 21, 47, 55]);
  406. const testDest = new Uint8ClampedArray(3 * 3 * 3);
  407. const expectedDest = new Uint8ClampedArray([0, 49, 101, 0, 49, 101, 0, 53, 117, 0, 49, 101, 0, 49, 101, 0, 53, 117, 0, 41, 40, 0, 41, 40, 0, 43, 90]);
  408. colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
  409. expect(colorSpace.getRgb([55, 25, 35], 0)).toEqual(new Uint8ClampedArray([188, 100, 61]));
  410. expect(colorSpace.getOutputLength(4, 0)).toEqual(4);
  411. expect(colorSpace.isPassthrough(8)).toBeFalsy();
  412. expect(colorSpace.isDefaultDecode([0, 1])).toBeTruthy();
  413. expect(testDest).toEqual(expectedDest);
  414. });
  415. });
  416. describe("IndexedCS", function () {
  417. it("should handle the case when cs is an array", function () {
  418. const lookup = new _stream.Stream(new Uint8Array([23, 155, 35, 147, 69, 93, 255, 109, 70]));
  419. const cs = [_primitives.Name.get("Indexed"), _primitives.Name.get("DeviceRGB"), 2, lookup];
  420. const xref = new _test_utils.XRefMock([{
  421. ref: _primitives.Ref.get(10, 0),
  422. data: new _primitives.Dict()
  423. }]);
  424. const resources = new _primitives.Dict();
  425. const pdfFunctionFactory = new _function.PDFFunctionFactory({
  426. xref
  427. });
  428. const colorSpace = _colorspace.ColorSpace.parse({
  429. cs,
  430. xref,
  431. resources,
  432. pdfFunctionFactory,
  433. localColorSpaceCache: new _image_utils.LocalColorSpaceCache()
  434. });
  435. const testSrc = new Uint8Array([2, 2, 0, 1]);
  436. const testDest = new Uint8ClampedArray(3 * 3 * 3);
  437. const expectedDest = new Uint8ClampedArray([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]);
  438. colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
  439. expect(colorSpace.getRgb([2], 0)).toEqual(new Uint8ClampedArray([255, 109, 70]));
  440. expect(colorSpace.isPassthrough(8)).toBeFalsy();
  441. expect(colorSpace.isDefaultDecode([0, 1], 1)).toBeTruthy();
  442. expect(testDest).toEqual(expectedDest);
  443. });
  444. });
  445. describe("AlternateCS", function () {
  446. it("should handle the case when cs is an array", function () {
  447. const fnDict = new _primitives.Dict();
  448. fnDict.set("FunctionType", 4);
  449. fnDict.set("Domain", [0.0, 1.0]);
  450. fnDict.set("Range", [0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0]);
  451. fnDict.set("Length", 58);
  452. let fn = new _stream.StringStream("{ dup 0.84 mul " + "exch 0.00 exch " + "dup 0.44 mul " + "exch 0.21 mul }");
  453. fn = new _stream.Stream(fn.bytes, 0, 58, fnDict);
  454. const fnRef = _primitives.Ref.get(10, 0);
  455. const cs = [_primitives.Name.get("Separation"), _primitives.Name.get("LogoGreen"), _primitives.Name.get("DeviceCMYK"), fnRef];
  456. const xref = new _test_utils.XRefMock([{
  457. ref: fnRef,
  458. data: fn
  459. }]);
  460. const resources = new _primitives.Dict();
  461. const pdfFunctionFactory = new _function.PDFFunctionFactory({
  462. xref
  463. });
  464. const colorSpace = _colorspace.ColorSpace.parse({
  465. cs,
  466. xref,
  467. resources,
  468. pdfFunctionFactory,
  469. localColorSpaceCache: new _image_utils.LocalColorSpaceCache()
  470. });
  471. const testSrc = new Uint8Array([27, 25, 50, 31]);
  472. const testDest = new Uint8ClampedArray(3 * 3 * 3);
  473. const expectedDest = new Uint8ClampedArray([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]);
  474. colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
  475. expect(colorSpace.getRgb([0.1], 0)).toEqual(new Uint8ClampedArray([228, 243, 242]));
  476. expect(colorSpace.isPassthrough(8)).toBeFalsy();
  477. expect(colorSpace.isDefaultDecode([0, 1])).toBeTruthy();
  478. expect(testDest).toEqual(expectedDest);
  479. });
  480. });
  481. });