From a494e33776995c3617d07cb8ab7536f3bbbfd280 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 8 Feb 2016 13:49:30 +0100 Subject: [PATCH] Update `JpegImage.getData` to support `forceRGBoutput` for images with `numComponents === 1` (issue 6066) *A more robust solution for issue 6066.* As a temporary work-around for (the upstream) [bug 1164199](https://bugzilla.mozilla.org/show_bug.cgi?id=1164199), we parsed *all* images in the Firefox addon during a short time. Doing so uncovered an issue with our image handling (see 6066), for JPEG images with a `DeviceGray` ColorSpace *and* `bpc !== 1` (bits per component). As long as we let the browser handle image decoding in this case, this isn't going to be an issue, but I do think that we should proactively fix this to avoid future issues if we change where the images are decoded (in `jpg.js` vs in browser). Also, we currently don't seem to have a test-case for that kind of image data. --- src/core/jpg.js | 13 ++++++++++++- test/pdfs/issue6066.pdf.link | 1 + test/test_manifest.json | 9 +++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 test/pdfs/issue6066.pdf.link diff --git a/src/core/jpg.js b/src/core/jpg.js index 984005228..be6840479 100644 --- a/src/core/jpg.js +++ b/src/core/jpg.js @@ -1019,7 +1019,18 @@ var JpegImage = (function jpegImage() { // type of data: Uint8Array(width * height * numComponents) var data = this._getLinearizedBlockData(width, height); - if (this.numComponents === 3) { + if (this.numComponents === 1 && forceRGBoutput) { + var dataLength = data.length; + var rgbData = new Uint8Array(dataLength * 3); + var offset = 0; + for (var i = 0; i < dataLength; i++) { + var grayColor = data[i]; + rgbData[offset++] = grayColor; + rgbData[offset++] = grayColor; + rgbData[offset++] = grayColor; + } + return rgbData; + } else if (this.numComponents === 3) { return this._convertYccToRgb(data); } else if (this.numComponents === 4) { if (this._isColorConversionNeeded()) { diff --git a/test/pdfs/issue6066.pdf.link b/test/pdfs/issue6066.pdf.link new file mode 100644 index 000000000..0aa55bd83 --- /dev/null +++ b/test/pdfs/issue6066.pdf.link @@ -0,0 +1 @@ +http://web.archive.org/web/20160213124006/http://www.leon.pl/userfiles/file/Zapytanie%20ofertowe%201-2014.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index 589f96ba0..1bbc7f005 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -980,6 +980,15 @@ "lastPage": 3, "type": "eq" }, + { "id": "issue6066", + "file": "pdfs/issue6066.pdf", + "md5": "b26eb08fc5ab2518ba8fde603bdfc46b", + "rounds": 1, + "link": true, + "firstPage": 2, + "lastPage": 2, + "type": "eq" + }, { "id": "issue1905", "file": "pdfs/issue1905.pdf", "md5": "b1bbd72ca6522ae1502aa26320f81994",