Repository: commons-imaging Updated Branches: refs/heads/master 6228007aa -> 8cf2b1280
Allow writing PCX files with 1 plane and a bitdepth of 2. Patch by: me Project: http://git-wip-us.apache.org/repos/asf/commons-imaging/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-imaging/commit/8cf2b128 Tree: http://git-wip-us.apache.org/repos/asf/commons-imaging/tree/8cf2b128 Diff: http://git-wip-us.apache.org/repos/asf/commons-imaging/diff/8cf2b128 Branch: refs/heads/master Commit: 8cf2b128010edabf2e6afb2cf1063a2137f69385 Parents: 6228007 Author: Damjan Jovanovic <damjan....@gmail.com> Authored: Mon Feb 19 06:51:28 2018 +0200 Committer: Damjan Jovanovic <damjan....@gmail.com> Committed: Mon Feb 19 06:51:28 2018 +0200 ---------------------------------------------------------------------- .../commons/imaging/formats/pcx/PcxWriter.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-imaging/blob/8cf2b128/src/main/java/org/apache/commons/imaging/formats/pcx/PcxWriter.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/imaging/formats/pcx/PcxWriter.java b/src/main/java/org/apache/commons/imaging/formats/pcx/PcxWriter.java index a75ea87..f782fe7 100644 --- a/src/main/java/org/apache/commons/imaging/formats/pcx/PcxWriter.java +++ b/src/main/java/org/apache/commons/imaging/formats/pcx/PcxWriter.java @@ -142,8 +142,13 @@ class PcxWriter { bitDepth = 1; planes = 3; } else if (palette.length() > 2 || bitDepthWanted == 2) { - bitDepth = 1; - planes = 2; + if (planesWanted == 2) { + bitDepth = 1; + planes = 2; + } else { + bitDepth = 2; + planes = 1; + } } else { boolean onlyBlackAndWhite = true; if (palette.length() >= 1) { @@ -277,6 +282,12 @@ class PcxWriter { plane2[x >>> 3] |= ((index & 4) >> 2) << (7 - (x & 7)); plane3[x >>> 3] |= ((index & 8) >> 3) << (7 - (x & 7)); } + } else if (bitDepth == 2 && planes == 1) { + for (int x = 0; x < src.getWidth(); x++) { + final int argb = src.getRGB(x, y); + final int index = palette.getPaletteIndex(0xffffff & argb); + plane0[x >>> 2] |= (index << 2 * (3 - (x & 3))); + } } else if (bitDepth == 4 && planes == 1) { for (int x = 0; x < src.getWidth(); x++) { final int argb = src.getRGB(x, y);