Repository: commons-imaging Updated Branches: refs/heads/master 40ab2ccf4 -> c5ca63fe3
IMAGING-123: remove duplicated lines found via CPD reports. Thanks to Jens Kapitza Project: http://git-wip-us.apache.org/repos/asf/commons-imaging/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-imaging/commit/c5ca63fe Tree: http://git-wip-us.apache.org/repos/asf/commons-imaging/tree/c5ca63fe Diff: http://git-wip-us.apache.org/repos/asf/commons-imaging/diff/c5ca63fe Branch: refs/heads/master Commit: c5ca63fe3864a0fd7673641d08049741e94a0287 Parents: 40ab2cc Author: Bruno P. Kinoshita <[email protected]> Authored: Fri Dec 29 00:58:55 2017 +1300 Committer: Bruno P. Kinoshita <[email protected]> Committed: Fri Dec 29 00:58:55 2017 +1300 ---------------------------------------------------------------------- src/changes/changes.xml | 3 + .../common/itu_t4/T4AndT6Compression.java | 94 ++++++++------------ 2 files changed, 40 insertions(+), 57 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-imaging/blob/c5ca63fe/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 1b6cb8b..80260c7 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -46,6 +46,9 @@ The <action> type attribute can be add,update,fix,remove. <body> <release version="1.0" date="TBA" description="First major release"> + <action issue="IMAGING-123" dev="kinow" type="update" due-to=" Jens Kapitza"> + remove duplicated lines in T4AndT6Compression + </action> <action issue="IMAGING-209" dev="kinow" type="fix" due-to="Isak Wertwein"> PnmImageParser throws ImageWriteException when writing if PnmImageParser.PARAM_KEY_PNM_RAWBITS is provided </action> http://git-wip-us.apache.org/repos/asf/commons-imaging/blob/c5ca63fe/src/main/java/org/apache/commons/imaging/common/itu_t4/T4AndT6Compression.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/imaging/common/itu_t4/T4AndT6Compression.java b/src/main/java/org/apache/commons/imaging/common/itu_t4/T4AndT6Compression.java index 5a090a7..c27bb5d 100644 --- a/src/main/java/org/apache/commons/imaging/common/itu_t4/T4AndT6Compression.java +++ b/src/main/java/org/apache/commons/imaging/common/itu_t4/T4AndT6Compression.java @@ -241,7 +241,39 @@ public final class T4AndT6Compression { return ret; } } - + + private static int compressT(final int a0, final int a1, final int b1, final BitArrayOutputStream outputStream,final int codingA0Color, final int[] codingLine ){ + final int a1b1 = a1 - b1; + if (-3 <= a1b1 && a1b1 <= 3) { + T4_T6_Tables.Entry entry; + if (a1b1 == -3) { + entry = T4_T6_Tables.VL3; + } else if (a1b1 == -2) { + entry = T4_T6_Tables.VL2; + } else if (a1b1 == -1) { + entry = T4_T6_Tables.VL1; + } else if (a1b1 == 0) { + entry = T4_T6_Tables.V0; + } else if (a1b1 == 1) { + entry = T4_T6_Tables.VR1; + } else if (a1b1 == 2) { + entry = T4_T6_Tables.VR2; + } else { + entry = T4_T6_Tables.VR3; + } + entry.writeBits(outputStream); + return a1; + + } else { + final int a2 = nextChangingElement(codingLine, 1 - codingA0Color, a1 + 1); + final int a0a1 = a1 - a0; + final int a1a2 = a2 - a1; + T4_T6_Tables.H.writeBits(outputStream); + writeRunLength(outputStream, a0a1, codingA0Color); + writeRunLength(outputStream, a1a2, 1 - codingA0Color); + return a2; + } + } public static byte[] compressT4_2D(final byte[] uncompressed, final int width, final int height, final boolean hasFill, final int parameterK) throws ImageWriteException { @@ -277,35 +309,9 @@ public final class T4AndT6Compression { T4_T6_Tables.P.writeBits(outputStream); a0 = b2; } else { - final int a1b1 = a1 - b1; - if (-3 <= a1b1 && a1b1 <= 3) { - T4_T6_Tables.Entry entry; - if (a1b1 == -3) { - entry = T4_T6_Tables.VL3; - } else if (a1b1 == -2) { - entry = T4_T6_Tables.VL2; - } else if (a1b1 == -1) { - entry = T4_T6_Tables.VL1; - } else if (a1b1 == 0) { - entry = T4_T6_Tables.V0; - } else if (a1b1 == 1) { - entry = T4_T6_Tables.VR1; - } else if (a1b1 == 2) { - entry = T4_T6_Tables.VR2; - } else { - entry = T4_T6_Tables.VR3; - } - entry.writeBits(outputStream); + a0 = compressT(a0, a1, b1, outputStream, codingA0Color, codingLine); + if (a0 == a1) { codingA0Color = 1 - codingA0Color; - a0 = a1; - } else { - final int a2 = nextChangingElement(codingLine, 1 - codingA0Color, a1 + 1); - final int a0a1 = a1 - a0; - final int a1a2 = a2 - a1; - T4_T6_Tables.H.writeBits(outputStream); - writeRunLength(outputStream, a0a1, codingA0Color); - writeRunLength(outputStream, a1a2, 1 - codingA0Color); - a0 = a2; } } referenceA0Color = changingElementAt(referenceLine, a0); @@ -480,35 +486,9 @@ public final class T4AndT6Compression { T4_T6_Tables.P.writeBits(outputStream); a0 = b2; } else { - final int a1b1 = a1 - b1; - if (-3 <= a1b1 && a1b1 <= 3) { - T4_T6_Tables.Entry entry; - if (a1b1 == -3) { - entry = T4_T6_Tables.VL3; - } else if (a1b1 == -2) { - entry = T4_T6_Tables.VL2; - } else if (a1b1 == -1) { - entry = T4_T6_Tables.VL1; - } else if (a1b1 == 0) { - entry = T4_T6_Tables.V0; - } else if (a1b1 == 1) { - entry = T4_T6_Tables.VR1; - } else if (a1b1 == 2) { - entry = T4_T6_Tables.VR2; - } else { - entry = T4_T6_Tables.VR3; - } - entry.writeBits(outputStream); + a0 = compressT(a0, a1, b1, outputStream, codingA0Color, codingLine); + if (a0 == a1) { codingA0Color = 1 - codingA0Color; - a0 = a1; - } else { - final int a2 = nextChangingElement(codingLine, 1 - codingA0Color, a1 + 1); - final int a0a1 = a1 - a0; - final int a1a2 = a2 - a1; - T4_T6_Tables.H.writeBits(outputStream); - writeRunLength(outputStream, a0a1, codingA0Color); - writeRunLength(outputStream, a1a2, 1 - codingA0Color); - a0 = a2; } } referenceA0Color = changingElementAt(referenceLine, a0);
