From 58b214eab360dbf1599fc9290d895a0dcdde36e7 Mon Sep 17 00:00:00 2001 From: Jani Pehkonen Date: Tue, 28 Nov 2017 21:24:27 +0200 Subject: [PATCH] Fix inverted 1-bit images in SVG backend --- src/display/svg.js | 12 ++++++------ test/pdfs/.gitignore | 1 + test/pdfs/images_1bit_grayscale.pdf | Bin 0 -> 4573 bytes test/test_manifest.json | 6 ++++++ 4 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 test/pdfs/images_1bit_grayscale.pdf diff --git a/src/display/svg.js b/src/display/svg.js index 25353ebbb..16f3bc228 100644 --- a/src/display/svg.js +++ b/src/display/svg.js @@ -182,7 +182,7 @@ var convertImgDataToPng = (function convertImgDataToPngClosure() { return idat; } - function encode(imgData, kind, forceDataSchema) { + function encode(imgData, kind, forceDataSchema, isMask) { var width = imgData.width; var height = imgData.height; var bitDepth, colorType, lineSize; @@ -220,8 +220,8 @@ var convertImgDataToPng = (function convertImgDataToPngClosure() { offsetLiterals += lineSize; } - if (kind === ImageKind.GRAYSCALE_1BPP) { - // inverting for B/W + if (kind === ImageKind.GRAYSCALE_1BPP && isMask) { + // inverting for image masks offsetLiterals = 0; for (y = 0; y < height; y++) { offsetLiterals++; // skipping predictor @@ -265,10 +265,10 @@ var convertImgDataToPng = (function convertImgDataToPngClosure() { return createObjectURL(data, 'image/png', forceDataSchema); } - return function convertImgDataToPng(imgData, forceDataSchema) { + return function convertImgDataToPng(imgData, forceDataSchema, isMask) { var kind = (imgData.kind === undefined ? ImageKind.GRAYSCALE_1BPP : imgData.kind); - return encode(imgData, kind, forceDataSchema); + return encode(imgData, kind, forceDataSchema, isMask); }; })(); @@ -1161,7 +1161,7 @@ SVGGraphics = (function SVGGraphicsClosure() { var width = imgData.width; var height = imgData.height; - var imgSrc = convertImgDataToPng(imgData, this.forceDataSchema); + var imgSrc = convertImgDataToPng(imgData, this.forceDataSchema, !!mask); var cliprect = this.svgFactory.createElement('svg:rect'); cliprect.setAttributeNS(null, 'x', '0'); cliprect.setAttributeNS(null, 'y', '0'); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index bed1b9c37..95bcc0f9a 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -119,6 +119,7 @@ !issue5084.pdf !issue8960_reduced.pdf !issue5202.pdf +!images_1bit_grayscale.pdf !issue5280.pdf !issue5677.pdf !issue5954.pdf diff --git a/test/pdfs/images_1bit_grayscale.pdf b/test/pdfs/images_1bit_grayscale.pdf new file mode 100644 index 0000000000000000000000000000000000000000..4cf15c794663f8743ba99f445d7bcaa2511357c8 GIT binary patch literal 4573 zcmcgwdsq`!77q{t1{4r2Ak+*X0wUxML6CqT4~r7O)>3>02oDVelAs`BKqz3gJgoHz z%fpt|)@=*Rw^CXyNDy?5gw{T=SO`P{Y(;t05+KRl84Mc4uJvoby?@Ni@7{CI%suy< z-#K?27y*Hp{ghxPWx;6@|gosCc>I^R)eFk7J*lj#{sjs+(zdHActxkVU0d*Y;wdUg>9F~<5r};4W39%bZ z%YJj~*~;YYhxpudcwxU|PxqIyr^bY2@}Dr_EWj51Pi#g$c5*VospyHqM4(!;`y zt|EPEiP}C7gBo3uAX;ojs+Jiwjz{%?UFA8Br|laq_XZ;v1d=-g<;OG9CqqeltIH~k zmj5^2*0gaRUA%Tb;g%+ zE{Afig}Nd0=t(bqnv3PpsD5k#CUEbm!lT6eew%+(KU@~yq!YfZXmI2_gE%xL$ZQv^ z#bAv;`el3ke>j;jV||kV0OLp@xDlpUpP4c^o_DIWioOBRC)(>T$-p+?()n-kAMfP?d=80!cn=6ddGCA{DXUrI?c_JgjMuX#gDsFKS}G{Iy?2qLxQK(Nkg+m z0|$m;xh9P_z_@gFcE@Lv4YQY{k1gGV^UlvXMO?v}+4XwrqkxHz&+12*T8Xmv6}=MB zeK>`!JK01$C)t?2a*J?FB(p|(|2`)EOSDsWx6^Qz%kU~){Yl;y-lWj4-D%ih@U(?q zad=%rUcrxTB4LhHG7zKjH5Pso+5e_c4a?c}4;S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