image.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * JavaScript code in this page
  4. *
  5. * Copyright 2022 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. Object.defineProperty(exports, "__esModule", {
  24. value: true
  25. });
  26. exports.PDFImage = void 0;
  27. var _util = require("../shared/util.js");
  28. var _image_utils = require("../shared/image_utils.js");
  29. var _base_stream = require("./base_stream.js");
  30. var _colorspace = require("./colorspace.js");
  31. var _decode_stream = require("./decode_stream.js");
  32. var _jpeg_stream = require("./jpeg_stream.js");
  33. var _jpx = require("./jpx.js");
  34. var _primitives = require("./primitives.js");
  35. function decodeAndClamp(value, addend, coefficient, max) {
  36. value = addend + value * coefficient;
  37. if (value < 0) {
  38. value = 0;
  39. } else if (value > max) {
  40. value = max;
  41. }
  42. return value;
  43. }
  44. function resizeImageMask(src, bpc, w1, h1, w2, h2) {
  45. const length = w2 * h2;
  46. let dest;
  47. if (bpc <= 8) {
  48. dest = new Uint8Array(length);
  49. } else if (bpc <= 16) {
  50. dest = new Uint16Array(length);
  51. } else {
  52. dest = new Uint32Array(length);
  53. }
  54. const xRatio = w1 / w2;
  55. const yRatio = h1 / h2;
  56. let i,
  57. j,
  58. py,
  59. newIndex = 0,
  60. oldIndex;
  61. const xScaled = new Uint16Array(w2);
  62. const w1Scanline = w1;
  63. for (i = 0; i < w2; i++) {
  64. xScaled[i] = Math.floor(i * xRatio);
  65. }
  66. for (i = 0; i < h2; i++) {
  67. py = Math.floor(i * yRatio) * w1Scanline;
  68. for (j = 0; j < w2; j++) {
  69. oldIndex = py + xScaled[j];
  70. dest[newIndex++] = src[oldIndex];
  71. }
  72. }
  73. return dest;
  74. }
  75. class PDFImage {
  76. constructor({
  77. xref,
  78. res,
  79. image,
  80. isInline = false,
  81. smask = null,
  82. mask = null,
  83. isMask = false,
  84. pdfFunctionFactory,
  85. localColorSpaceCache
  86. }) {
  87. this.image = image;
  88. const dict = image.dict;
  89. const filter = dict.get("F", "Filter");
  90. let filterName;
  91. if (filter instanceof _primitives.Name) {
  92. filterName = filter.name;
  93. } else if (Array.isArray(filter)) {
  94. const filterZero = xref.fetchIfRef(filter[0]);
  95. if (filterZero instanceof _primitives.Name) {
  96. filterName = filterZero.name;
  97. }
  98. }
  99. switch (filterName) {
  100. case "JPXDecode":
  101. const jpxImage = new _jpx.JpxImage();
  102. jpxImage.parseImageProperties(image.stream);
  103. image.stream.reset();
  104. image.width = jpxImage.width;
  105. image.height = jpxImage.height;
  106. image.bitsPerComponent = jpxImage.bitsPerComponent;
  107. image.numComps = jpxImage.componentsCount;
  108. break;
  109. case "JBIG2Decode":
  110. image.bitsPerComponent = 1;
  111. image.numComps = 1;
  112. break;
  113. }
  114. let width = dict.get("W", "Width");
  115. let height = dict.get("H", "Height");
  116. if (Number.isInteger(image.width) && image.width > 0 && Number.isInteger(image.height) && image.height > 0 && (image.width !== width || image.height !== height)) {
  117. (0, _util.warn)("PDFImage - using the Width/Height of the image data, " + "rather than the image dictionary.");
  118. width = image.width;
  119. height = image.height;
  120. }
  121. if (width < 1 || height < 1) {
  122. throw new _util.FormatError(`Invalid image width: ${width} or height: ${height}`);
  123. }
  124. this.width = width;
  125. this.height = height;
  126. this.interpolate = dict.get("I", "Interpolate");
  127. this.imageMask = dict.get("IM", "ImageMask") || false;
  128. this.matte = dict.get("Matte") || false;
  129. let bitsPerComponent = image.bitsPerComponent;
  130. if (!bitsPerComponent) {
  131. bitsPerComponent = dict.get("BPC", "BitsPerComponent");
  132. if (!bitsPerComponent) {
  133. if (this.imageMask) {
  134. bitsPerComponent = 1;
  135. } else {
  136. throw new _util.FormatError(`Bits per component missing in image: ${this.imageMask}`);
  137. }
  138. }
  139. }
  140. this.bpc = bitsPerComponent;
  141. if (!this.imageMask) {
  142. let colorSpace = dict.getRaw("CS") || dict.getRaw("ColorSpace");
  143. if (!colorSpace) {
  144. (0, _util.info)("JPX images (which do not require color spaces)");
  145. switch (image.numComps) {
  146. case 1:
  147. colorSpace = _primitives.Name.get("DeviceGray");
  148. break;
  149. case 3:
  150. colorSpace = _primitives.Name.get("DeviceRGB");
  151. break;
  152. case 4:
  153. colorSpace = _primitives.Name.get("DeviceCMYK");
  154. break;
  155. default:
  156. throw new Error(`JPX images with ${image.numComps} color components not supported.`);
  157. }
  158. }
  159. this.colorSpace = _colorspace.ColorSpace.parse({
  160. cs: colorSpace,
  161. xref,
  162. resources: isInline ? res : null,
  163. pdfFunctionFactory,
  164. localColorSpaceCache
  165. });
  166. this.numComps = this.colorSpace.numComps;
  167. }
  168. this.decode = dict.getArray("D", "Decode");
  169. this.needsDecode = false;
  170. if (this.decode && (this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode, bitsPerComponent) || isMask && !_colorspace.ColorSpace.isDefaultDecode(this.decode, 1))) {
  171. this.needsDecode = true;
  172. const max = (1 << bitsPerComponent) - 1;
  173. this.decodeCoefficients = [];
  174. this.decodeAddends = [];
  175. const isIndexed = this.colorSpace && this.colorSpace.name === "Indexed";
  176. for (let i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  177. const dmin = this.decode[i];
  178. const dmax = this.decode[i + 1];
  179. this.decodeCoefficients[j] = isIndexed ? (dmax - dmin) / max : dmax - dmin;
  180. this.decodeAddends[j] = isIndexed ? dmin : max * dmin;
  181. }
  182. }
  183. if (smask) {
  184. this.smask = new PDFImage({
  185. xref,
  186. res,
  187. image: smask,
  188. isInline,
  189. pdfFunctionFactory,
  190. localColorSpaceCache
  191. });
  192. } else if (mask) {
  193. if (mask instanceof _base_stream.BaseStream) {
  194. const maskDict = mask.dict,
  195. imageMask = maskDict.get("IM", "ImageMask");
  196. if (!imageMask) {
  197. (0, _util.warn)("Ignoring /Mask in image without /ImageMask.");
  198. } else {
  199. this.mask = new PDFImage({
  200. xref,
  201. res,
  202. image: mask,
  203. isInline,
  204. isMask: true,
  205. pdfFunctionFactory,
  206. localColorSpaceCache
  207. });
  208. }
  209. } else {
  210. this.mask = mask;
  211. }
  212. }
  213. }
  214. static async buildImage({
  215. xref,
  216. res,
  217. image,
  218. isInline = false,
  219. pdfFunctionFactory,
  220. localColorSpaceCache
  221. }) {
  222. const imageData = image;
  223. let smaskData = null;
  224. let maskData = null;
  225. const smask = image.dict.get("SMask");
  226. const mask = image.dict.get("Mask");
  227. if (smask) {
  228. if (smask instanceof _base_stream.BaseStream) {
  229. smaskData = smask;
  230. } else {
  231. (0, _util.warn)("Unsupported /SMask format.");
  232. }
  233. } else if (mask) {
  234. if (mask instanceof _base_stream.BaseStream || Array.isArray(mask)) {
  235. maskData = mask;
  236. } else {
  237. (0, _util.warn)("Unsupported /Mask format.");
  238. }
  239. }
  240. return new PDFImage({
  241. xref,
  242. res,
  243. image: imageData,
  244. isInline,
  245. smask: smaskData,
  246. mask: maskData,
  247. pdfFunctionFactory,
  248. localColorSpaceCache
  249. });
  250. }
  251. static createRawMask({
  252. imgArray,
  253. width,
  254. height,
  255. imageIsFromDecodeStream,
  256. inverseDecode,
  257. interpolate
  258. }) {
  259. const computedLength = (width + 7 >> 3) * height;
  260. const actualLength = imgArray.byteLength;
  261. const haveFullData = computedLength === actualLength;
  262. let data, i;
  263. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  264. data = imgArray;
  265. } else if (!inverseDecode) {
  266. data = new Uint8Array(imgArray);
  267. } else {
  268. data = new Uint8Array(computedLength);
  269. data.set(imgArray);
  270. data.fill(0xff, actualLength);
  271. }
  272. if (inverseDecode) {
  273. for (i = 0; i < actualLength; i++) {
  274. data[i] ^= 0xff;
  275. }
  276. }
  277. return {
  278. data,
  279. width,
  280. height,
  281. interpolate
  282. };
  283. }
  284. static createMask({
  285. imgArray,
  286. width,
  287. height,
  288. imageIsFromDecodeStream,
  289. inverseDecode,
  290. interpolate,
  291. isOffscreenCanvasSupported = true
  292. }) {
  293. const isSingleOpaquePixel = width === 1 && height === 1 && inverseDecode === (imgArray.length === 0 || !!(imgArray[0] & 128));
  294. if (isSingleOpaquePixel) {
  295. return {
  296. isSingleOpaquePixel
  297. };
  298. }
  299. if (isOffscreenCanvasSupported && _util.FeatureTest.isOffscreenCanvasSupported) {
  300. const canvas = new OffscreenCanvas(width, height);
  301. const ctx = canvas.getContext("2d");
  302. const imgData = ctx.createImageData(width, height);
  303. (0, _image_utils.applyMaskImageData)({
  304. src: imgArray,
  305. dest: imgData.data,
  306. width,
  307. height,
  308. inverseDecode
  309. });
  310. ctx.putImageData(imgData, 0, 0);
  311. const bitmap = canvas.transferToImageBitmap();
  312. return {
  313. data: null,
  314. width,
  315. height,
  316. interpolate,
  317. bitmap
  318. };
  319. }
  320. return this.createRawMask({
  321. imgArray,
  322. width,
  323. height,
  324. inverseDecode,
  325. imageIsFromDecodeStream,
  326. interpolate
  327. });
  328. }
  329. get drawWidth() {
  330. return Math.max(this.width, this.smask && this.smask.width || 0, this.mask && this.mask.width || 0);
  331. }
  332. get drawHeight() {
  333. return Math.max(this.height, this.smask && this.smask.height || 0, this.mask && this.mask.height || 0);
  334. }
  335. decodeBuffer(buffer) {
  336. const bpc = this.bpc;
  337. const numComps = this.numComps;
  338. const decodeAddends = this.decodeAddends;
  339. const decodeCoefficients = this.decodeCoefficients;
  340. const max = (1 << bpc) - 1;
  341. let i, ii;
  342. if (bpc === 1) {
  343. for (i = 0, ii = buffer.length; i < ii; i++) {
  344. buffer[i] = +!buffer[i];
  345. }
  346. return;
  347. }
  348. let index = 0;
  349. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  350. for (let j = 0; j < numComps; j++) {
  351. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j], decodeCoefficients[j], max);
  352. index++;
  353. }
  354. }
  355. }
  356. getComponents(buffer) {
  357. const bpc = this.bpc;
  358. if (bpc === 8) {
  359. return buffer;
  360. }
  361. const width = this.width;
  362. const height = this.height;
  363. const numComps = this.numComps;
  364. const length = width * height * numComps;
  365. let bufferPos = 0;
  366. let output;
  367. if (bpc <= 8) {
  368. output = new Uint8Array(length);
  369. } else if (bpc <= 16) {
  370. output = new Uint16Array(length);
  371. } else {
  372. output = new Uint32Array(length);
  373. }
  374. const rowComps = width * numComps;
  375. const max = (1 << bpc) - 1;
  376. let i = 0,
  377. ii,
  378. buf;
  379. if (bpc === 1) {
  380. let mask, loop1End, loop2End;
  381. for (let j = 0; j < height; j++) {
  382. loop1End = i + (rowComps & ~7);
  383. loop2End = i + rowComps;
  384. while (i < loop1End) {
  385. buf = buffer[bufferPos++];
  386. output[i] = buf >> 7 & 1;
  387. output[i + 1] = buf >> 6 & 1;
  388. output[i + 2] = buf >> 5 & 1;
  389. output[i + 3] = buf >> 4 & 1;
  390. output[i + 4] = buf >> 3 & 1;
  391. output[i + 5] = buf >> 2 & 1;
  392. output[i + 6] = buf >> 1 & 1;
  393. output[i + 7] = buf & 1;
  394. i += 8;
  395. }
  396. if (i < loop2End) {
  397. buf = buffer[bufferPos++];
  398. mask = 128;
  399. while (i < loop2End) {
  400. output[i++] = +!!(buf & mask);
  401. mask >>= 1;
  402. }
  403. }
  404. }
  405. } else {
  406. let bits = 0;
  407. buf = 0;
  408. for (i = 0, ii = length; i < ii; ++i) {
  409. if (i % rowComps === 0) {
  410. buf = 0;
  411. bits = 0;
  412. }
  413. while (bits < bpc) {
  414. buf = buf << 8 | buffer[bufferPos++];
  415. bits += 8;
  416. }
  417. const remainingBits = bits - bpc;
  418. let value = buf >> remainingBits;
  419. if (value < 0) {
  420. value = 0;
  421. } else if (value > max) {
  422. value = max;
  423. }
  424. output[i] = value;
  425. buf &= (1 << remainingBits) - 1;
  426. bits = remainingBits;
  427. }
  428. }
  429. return output;
  430. }
  431. fillOpacity(rgbaBuf, width, height, actualHeight, image) {
  432. const smask = this.smask;
  433. const mask = this.mask;
  434. let alphaBuf, sw, sh, i, ii, j;
  435. if (smask) {
  436. sw = smask.width;
  437. sh = smask.height;
  438. alphaBuf = new Uint8ClampedArray(sw * sh);
  439. smask.fillGrayBuffer(alphaBuf);
  440. if (sw !== width || sh !== height) {
  441. alphaBuf = resizeImageMask(alphaBuf, smask.bpc, sw, sh, width, height);
  442. }
  443. } else if (mask) {
  444. if (mask instanceof PDFImage) {
  445. sw = mask.width;
  446. sh = mask.height;
  447. alphaBuf = new Uint8ClampedArray(sw * sh);
  448. mask.numComps = 1;
  449. mask.fillGrayBuffer(alphaBuf);
  450. for (i = 0, ii = sw * sh; i < ii; ++i) {
  451. alphaBuf[i] = 255 - alphaBuf[i];
  452. }
  453. if (sw !== width || sh !== height) {
  454. alphaBuf = resizeImageMask(alphaBuf, mask.bpc, sw, sh, width, height);
  455. }
  456. } else if (Array.isArray(mask)) {
  457. alphaBuf = new Uint8ClampedArray(width * height);
  458. const numComps = this.numComps;
  459. for (i = 0, ii = width * height; i < ii; ++i) {
  460. let opacity = 0;
  461. const imageOffset = i * numComps;
  462. for (j = 0; j < numComps; ++j) {
  463. const color = image[imageOffset + j];
  464. const maskOffset = j * 2;
  465. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  466. opacity = 255;
  467. break;
  468. }
  469. }
  470. alphaBuf[i] = opacity;
  471. }
  472. } else {
  473. throw new _util.FormatError("Unknown mask format.");
  474. }
  475. }
  476. if (alphaBuf) {
  477. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  478. rgbaBuf[j] = alphaBuf[i];
  479. }
  480. } else {
  481. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  482. rgbaBuf[j] = 255;
  483. }
  484. }
  485. }
  486. undoPreblend(buffer, width, height) {
  487. const matte = this.smask && this.smask.matte;
  488. if (!matte) {
  489. return;
  490. }
  491. const matteRgb = this.colorSpace.getRgb(matte, 0);
  492. const matteR = matteRgb[0];
  493. const matteG = matteRgb[1];
  494. const matteB = matteRgb[2];
  495. const length = width * height * 4;
  496. for (let i = 0; i < length; i += 4) {
  497. const alpha = buffer[i + 3];
  498. if (alpha === 0) {
  499. buffer[i] = 255;
  500. buffer[i + 1] = 255;
  501. buffer[i + 2] = 255;
  502. continue;
  503. }
  504. const k = 255 / alpha;
  505. buffer[i] = (buffer[i] - matteR) * k + matteR;
  506. buffer[i + 1] = (buffer[i + 1] - matteG) * k + matteG;
  507. buffer[i + 2] = (buffer[i + 2] - matteB) * k + matteB;
  508. }
  509. }
  510. createImageData(forceRGBA = false) {
  511. const drawWidth = this.drawWidth;
  512. const drawHeight = this.drawHeight;
  513. const imgData = {
  514. width: drawWidth,
  515. height: drawHeight,
  516. interpolate: this.interpolate,
  517. kind: 0,
  518. data: null
  519. };
  520. const numComps = this.numComps;
  521. const originalWidth = this.width;
  522. const originalHeight = this.height;
  523. const bpc = this.bpc;
  524. const rowBytes = originalWidth * numComps * bpc + 7 >> 3;
  525. if (!forceRGBA) {
  526. let kind;
  527. if (this.colorSpace.name === "DeviceGray" && bpc === 1) {
  528. kind = _util.ImageKind.GRAYSCALE_1BPP;
  529. } else if (this.colorSpace.name === "DeviceRGB" && bpc === 8 && !this.needsDecode) {
  530. kind = _util.ImageKind.RGB_24BPP;
  531. }
  532. if (kind && !this.smask && !this.mask && drawWidth === originalWidth && drawHeight === originalHeight) {
  533. imgData.kind = kind;
  534. imgData.data = this.getImageBytes(originalHeight * rowBytes, {});
  535. if (this.needsDecode) {
  536. (0, _util.assert)(kind === _util.ImageKind.GRAYSCALE_1BPP, "PDFImage.createImageData: The image must be grayscale.");
  537. const buffer = imgData.data;
  538. for (let i = 0, ii = buffer.length; i < ii; i++) {
  539. buffer[i] ^= 0xff;
  540. }
  541. }
  542. return imgData;
  543. }
  544. if (this.image instanceof _jpeg_stream.JpegStream && !this.smask && !this.mask) {
  545. let imageLength = originalHeight * rowBytes;
  546. switch (this.colorSpace.name) {
  547. case "DeviceGray":
  548. imageLength *= 3;
  549. case "DeviceRGB":
  550. case "DeviceCMYK":
  551. imgData.kind = _util.ImageKind.RGB_24BPP;
  552. imgData.data = this.getImageBytes(imageLength, {
  553. drawWidth,
  554. drawHeight,
  555. forceRGB: true
  556. });
  557. return imgData;
  558. }
  559. }
  560. }
  561. const imgArray = this.getImageBytes(originalHeight * rowBytes, {
  562. internal: true
  563. });
  564. const actualHeight = 0 | imgArray.length / rowBytes * drawHeight / originalHeight;
  565. const comps = this.getComponents(imgArray);
  566. let alpha01, maybeUndoPreblend;
  567. if (!forceRGBA && !this.smask && !this.mask) {
  568. imgData.kind = _util.ImageKind.RGB_24BPP;
  569. imgData.data = new Uint8ClampedArray(drawWidth * drawHeight * 3);
  570. alpha01 = 0;
  571. maybeUndoPreblend = false;
  572. } else {
  573. imgData.kind = _util.ImageKind.RGBA_32BPP;
  574. imgData.data = new Uint8ClampedArray(drawWidth * drawHeight * 4);
  575. alpha01 = 1;
  576. maybeUndoPreblend = true;
  577. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight, comps);
  578. }
  579. if (this.needsDecode) {
  580. this.decodeBuffer(comps);
  581. }
  582. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight, drawWidth, drawHeight, actualHeight, bpc, comps, alpha01);
  583. if (maybeUndoPreblend) {
  584. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  585. }
  586. return imgData;
  587. }
  588. fillGrayBuffer(buffer) {
  589. const numComps = this.numComps;
  590. if (numComps !== 1) {
  591. throw new _util.FormatError(`Reading gray scale from a color image: ${numComps}`);
  592. }
  593. const width = this.width;
  594. const height = this.height;
  595. const bpc = this.bpc;
  596. const rowBytes = width * numComps * bpc + 7 >> 3;
  597. const imgArray = this.getImageBytes(height * rowBytes, {
  598. internal: true
  599. });
  600. const comps = this.getComponents(imgArray);
  601. let i, length;
  602. if (bpc === 1) {
  603. length = width * height;
  604. if (this.needsDecode) {
  605. for (i = 0; i < length; ++i) {
  606. buffer[i] = comps[i] - 1 & 255;
  607. }
  608. } else {
  609. for (i = 0; i < length; ++i) {
  610. buffer[i] = -comps[i] & 255;
  611. }
  612. }
  613. return;
  614. }
  615. if (this.needsDecode) {
  616. this.decodeBuffer(comps);
  617. }
  618. length = width * height;
  619. const scale = 255 / ((1 << bpc) - 1);
  620. for (i = 0; i < length; ++i) {
  621. buffer[i] = scale * comps[i];
  622. }
  623. }
  624. getImageBytes(length, {
  625. drawWidth,
  626. drawHeight,
  627. forceRGB = false,
  628. internal = false
  629. }) {
  630. this.image.reset();
  631. this.image.drawWidth = drawWidth || this.width;
  632. this.image.drawHeight = drawHeight || this.height;
  633. this.image.forceRGB = !!forceRGB;
  634. const imageBytes = this.image.getBytes(length);
  635. if (internal || this.image instanceof _decode_stream.DecodeStream) {
  636. return imageBytes;
  637. }
  638. (0, _util.assert)(imageBytes instanceof Uint8Array, 'PDFImage.getImageBytes: Unsupported "imageBytes" type.');
  639. return new Uint8Array(imageBytes);
  640. }
  641. }
  642. exports.PDFImage = PDFImage;