image.js 20 KB

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