diff --git a/.github/workflows/push-trigger.yml b/.github/workflows/push-trigger.yml new file mode 100644 index 0000000..fec2e44 --- /dev/null +++ b/.github/workflows/push-trigger.yml @@ -0,0 +1,65 @@ +name: Maven Package upon a push + +on: + release: + types: [published] + pull_request: + types: [opened, reopened, synchronize] + workflow_dispatch: + inputs: + message: + description: 'Message for manually triggering' + required: false + default: 'Triggered for Updates' + type: string + push: + branches: + - '!release-branch' + - 'MOSIP*' + - 'develop*' + - 'master' + - '1.*' + - 'release*' + +jobs: + build-maven-imagedecoder: + uses: mosip/kattu/.github/workflows/maven-build.yml@master-java21 + with: + SERVICE_LOCATION: imagedecoder + BUILD_ARTIFACT: imagedecoder + secrets: + OSSRH_USER: ${{ secrets.OSSRH_USER }} + OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }} + OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }} + GPG_SECRET: ${{ secrets.GPG_SECRET }} + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + + publish_to_nexus: + if: "${{ !contains(github.ref, 'master') && github.event_name != 'pull_request' && github.event_name != 'release' && github.event_name != 'prerelease' && github.event_name != 'publish' }}" + needs: build-maven-imagedecoder + uses: mosip/kattu/.github/workflows/maven-publish-to-nexus.yml@master-java21 + with: + SERVICE_LOCATION: imagedecoder + secrets: + OSSRH_USER: ${{ secrets.OSSRH_USER }} + OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }} + OSSRH_URL: ${{ secrets.RELEASE_URL }} + OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }} + GPG_SECRET: ${{ secrets.GPG_SECRET }} + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + + sonar_analysis: + needs: build-maven-imagedecoder + if: "${{ github.event_name != 'pull_request' }}" + uses: mosip/kattu/.github/workflows/maven-sonar-analysis.yml@master-java21 + with: + SERVICE_LOCATION: imagedecoder + PROJECT_KEY: 'mosip_imagedecoder' + secrets: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + ORG_KEY: ${{ secrets.ORG_KEY }} + OSSRH_USER: ${{ secrets.OSSRH_USER }} + OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }} + OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }} + GPG_SECRET: ${{ secrets.GPG_SECRET }} + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} diff --git a/.github/workflows/push_trigger.yml b/.github/workflows/push_trigger.yml deleted file mode 100644 index 0b498d0..0000000 --- a/.github/workflows/push_trigger.yml +++ /dev/null @@ -1,189 +0,0 @@ -name: Maven Package upon a push - -on: - push: - branches: - - master - - 1.* - - develop - - release-1* - -jobs: - - build_imagedecoder: - - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - ref: ${{ github.ref }} - java-version: 11 - server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file - - - name: Setup branch and env - run: | - # Strip git ref prefix from version - echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV - echo "GPG_TTY=$(tty)" >> $GITHUB_ENV - - - name: Setup branch and GPG public key - run: | - # Strip git ref prefix from version - echo ${{ env.BRANCH_NAME }} - echo ${{ env.GPG_TTY }} - sudo apt-get --yes install gnupg2 - gpg2 --import ./.github/keys/mosipgpgkey_pub.gpg - gpg2 --quiet --batch --passphrase=${{secrets.gpg_secret}} --allow-secret-key-import --import ./.github/keys/mosipgpgkey_sec.gpg - - - uses: actions/cache@v1 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven-${{ env.BRANCH_NAME }} - - - name: Install xmllint - run: | - sudo apt-get update - sudo apt-get install libxml2-utils - - - name: Setup the settings file for ossrh server - run: echo " ossrh ${{secrets.ossrh_user}} ${{secrets.ossrh_secret}} ossrh true gpg2 ${{secrets.gpg_secret}} allow-snapshots true snapshots-repo https://oss.sonatype.org/content/repositories/snapshots false true releases-repo https://oss.sonatype.org/service/local/staging/deploy/maven2 true false sonar . https://sonarcloud.io false " > $GITHUB_WORKSPACE/settings.xml - - - name: Build with Maven Image Decoder - run: | - cd imagedecoder - mvn -B package -s $GITHUB_WORKSPACE/settings.xml --file pom.xml - - - name: Ready the springboot artifacts - run: find -name '*.jar' -type f -exec zip release.zip {} + - - - name: Upload the springboot jars - uses: actions/upload-artifact@v1 - with: - name: release - path: ./release.zip - - - uses: 8398a7/action-slack@v3 - with: - status: ${{ job.status }} - fields: repo,message,commit,author,action,eventName,ref,workflow,job,took # selectable (default: repo,message) - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} # required - if: failure() # Pick up events even if the job fails or is canceled. - - publish_to_nexus_imagedecoder: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - ref: ${{ github.ref }} - java-version: 11 - server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file - - - name: Setup branch and env - run: | - # Strip git ref prefix from version - echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV - echo "GPG_TTY=$(tty)" >> $GITHUB_ENV - - - name: Setup branch and GPG public key - run: | - # Strip git ref prefix from version - echo ${{ env.BRANCH_NAME }} - echo ${{ env.GPG_TTY }} - sudo apt-get --yes install gnupg2 - gpg2 --import ./.github/keys/mosipgpgkey_pub.gpg - gpg2 --quiet --batch --passphrase=${{secrets.gpg_secret}} --allow-secret-key-import --import ./.github/keys/mosipgpgkey_sec.gpg - - - uses: actions/cache@v1 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven-${{ env.BRANCH_NAME }} - - - name: Install xmllint - run: | - sudo apt-get update - sudo apt-get install libxml2-utils - - - name: Setup the settings file for ossrh server - run: echo " ossrh ${{secrets.ossrh_user}} ${{secrets.ossrh_secret}} ossrh true gpg2 ${{secrets.gpg_secret}} allow-snapshots true snapshots-repo https://oss.sonatype.org/content/repositories/snapshots false true releases-repo https://oss.sonatype.org/service/local/staging/deploy/maven2 true false sonar . https://sonarcloud.io false " > $GITHUB_WORKSPACE/settings.xml - - - name: Publish the maven package - run: | - cd imagedecoder && mvn deploy -DskipTests -DaltDeploymentRepository=ossrh::default::${{ secrets.RELEASE_URL }} -s $GITHUB_WORKSPACE/settings.xml -f pom.xml - env: - GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} - GPG_TTY: $(tty) - - - uses: 8398a7/action-slack@v3 - with: - status: ${{ job.status }} - fields: repo,message,commit,author,action,eventName,ref,workflow,job,took # selectable (default: repo,message) - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} # required - if: failure() # Pick up events even if the job fails or is canceled. - - sonar_analysis_imagedecoder: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - ref: ${{ github.ref }} - java-version: 11 - server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file - - - name: Setup branch and env - run: | - # Strip git ref prefix from version - echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV - echo "GPG_TTY=$(tty)" >> $GITHUB_ENV - - - name: Setup branch and GPG public key - run: | - # Strip git ref prefix from version - echo ${{ env.BRANCH_NAME }} - echo ${{ env.GPG_TTY }} - sudo apt-get --yes install gnupg2 - gpg2 --import ./.github/keys/mosipgpgkey_pub.gpg - gpg2 --quiet --batch --passphrase=${{secrets.gpg_secret}} --allow-secret-key-import --import ./.github/keys/mosipgpgkey_sec.gpg - - - uses: actions/cache@v1 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven-${{ env.BRANCH_NAME }} - - - name: Install xmllint - run: | - sudo apt-get update - sudo apt-get install libxml2-utils - - - name: Setup the settings file for ossrh server - run: echo " ossrh ${{secrets.ossrh_user}} ${{secrets.ossrh_secret}} ossrh true gpg2 ${{secrets.gpg_secret}} allow-snapshots true snapshots-repo https://oss.sonatype.org/content/repositories/snapshots false true releases-repo https://oss.sonatype.org/service/local/staging/deploy/maven2 true false sonar . https://sonarcloud.io false " > $GITHUB_WORKSPACE/settings.xml - - - name: Build with Maven - run: | - cd imagedecoder - mvn -B package -s $GITHUB_WORKSPACE/settings.xml --file pom.xml - - - name: Analyze with SonarCloud - run: | - cd imagedecoder - mvn -B -Dgpg.skip verify sonar:sonar -Dsonar.projectKey=mosip_imagedecoder -Dsonar.organization=${{ secrets.ORG_KEY }} -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} - - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a899532 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/.metadata/ +.sonarlint/ +*/.classpath +*/.gitignore +*/.project +*/.settings/ \ No newline at end of file diff --git a/README.md b/README.md index 57886c5..fd7c02c 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -# decoder \ No newline at end of file +# decoder + diff --git a/imagedecoder/pom.xml b/imagedecoder/pom.xml index 67eb7ab..faf82bf 100644 --- a/imagedecoder/pom.xml +++ b/imagedecoder/pom.xml @@ -1,44 +1,75 @@ - - 4.0.0 + + 4.0.0 - io.mosip.imagedecoder - imagedecoder - 0.0.1-SNAPSHOT + io.mosip.imagedecoder + imagedecoder + 0.0.1-SNAPSHOT - Image Decoder Project (from https://github.com/mosip/imagedecoder) + Imagedecoder + http://github.com/mosip/imagedecoder + Image decoder for MOSIP + + UTF-8 + 21 - - UTF-8 - 1.8 - 1.8 - 1.7.25 - 1.2.0.1-SNAPSHOT - 2.11.1 - 2.11.1 - + + ${java.version} + ${java.version} + 3.11.0 + 3.0.2 + 3.1.0 + 3.2.0 + 2.3 + 0.8.11 + 3.1.1 + 3.3.1 + 3.2.0 + 3.2.3 + 3.0.2 + 3.1.0 + 3.1.1 + 2.22.0 + 1.6.7 + 3.2.5 + 3.7.0.1746 - - - org.slf4j - jul-to-slf4j - ${org.slf4j.version} - - - org.slf4j - jcl-over-slf4j - ${org.slf4j.version} - + + 3.0.1 + + + 1.2.1-SNAPSHOT + 1.2.1-SNAPSHOT + 1.2.1-SNAPSHOT + + + + + + io.mosip.kernel + kernel-bom + ${kernel.bom.version} + pom + import + + + + + - org.projectlombok - lombok - 1.18.24 - compile - + org.slf4j + jul-to-slf4j + + + org.slf4j + jcl-over-slf4j + io.mosip.kernel kernel-core - ${kernel.version} + ${kernel.core.version} org.springframework.boot @@ -48,17 +79,25 @@ - - com.fasterxml.jackson.core - jackson-databind - ${jackson-databind.version} - - com.fasterxml.jackson.core - jackson-core - ${jackson-core.version} + io.mosip.kernel + kernel-logger-logback + ${kernel.logger.logback.version} + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.core + jackson-core + + + org.junit.vintage + junit-vintage-engine - + + ossrh @@ -69,11 +108,23 @@ https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven.compiler.version} + + ${java.version} + + --enable-preview + + + maven-deploy-plugin - 2.8.1 + ${maven.deploy.plugin.version} default-deploy @@ -85,28 +136,28 @@ - org.apache.maven.plugins - maven-assembly-plugin - 3.1.1 - - - jar-with-dependencies - - - - - make-assembly - package - - single - - - - + org.apache.maven.plugins + maven-assembly-plugin + ${maven.assembly.plugin.version} + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + org.sonatype.plugins nexus-staging-maven-plugin - 1.6.7 + ${nexus.staging.maven.plugin.version} true @@ -128,7 +179,7 @@ org.apache.maven.plugins maven-source-plugin true - 2.2.1 + ${maven.source.plugin.version} attach-sources @@ -142,7 +193,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.2.0 + ${maven.javadoc.plugin.version} attach-javadocs @@ -158,8 +209,7 @@ org.apache.maven.plugins maven-gpg-plugin - 1.5 - + ${maven.gpg.plugin.version} sign-artifacts @@ -176,10 +226,52 @@ + + org.apache.maven.plugins + maven-surefire-plugin + ${maven.surefire.plugin.version} + + ${skipTests} + false + + ${argLine} + --add-modules=ALL-SYSTEM + --add-opens java.xml/jdk.xml.internal=ALL-UNNAMED + --add-opens java.base/java.lang.reflect=ALL-UNNAMED + --add-opens java.base/java.lang.stream=ALL-UNNAMED + --add-opens java.base/java.time=ALL-UNNAMED + --add-opens java.base/java.time.LocalDate=ALL-UNNAMED + --add-opens + java.base/java.time.LocalDateTime=ALL-UNNAMED + --add-opens + java.base/java.time.LocalDateTime.date=ALL-UNNAMED + --enable-preview + + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.maven.plugin.version} + + + + prepare-agent + + + + report + prepare-package + + report + + + + pl.project13.maven git-commit-id-plugin - 3.0.1 + ${git.commit.id.plugin.version} get-the-git-infos @@ -191,18 +283,51 @@ true - ${project.build.outputDirectory}/git.properties + + ${project.build.outputDirectory}/git.properties ^git.build.(time|version)$ ^git.commit.id.(abbrev|full)$ full ${project.basedir}/.git - + + + + sonar + + . + src/main/java/**,src/main/resources/** + ${sonar.coverage.exclusions} + https://sonarcloud.io + + + false + + + + + org.sonarsource.scanner.maven + sonar-maven-plugin + ${maven.sonar.plugin.version} + + + verify + + sonar + + + + + + + + + scm:git:git://github.com/mosip/imagedecoder.git scm:git:ssh://github.com:mosip/imagedecoder.git @@ -223,4 +348,4 @@ https://github.com/mosip/imagedecoder.git - + \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/constant/DecoderConstant.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/constant/DecoderConstant.java index 63cc554..7239d6d 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/constant/DecoderConstant.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/constant/DecoderConstant.java @@ -1,13 +1,21 @@ package io.mosip.imagedecoder.constant; -public class DecoderConstant { +public class DecoderConstant { + public DecoderConstant() { + throw new IllegalStateException("DecoderConstant class"); + } + + public static final String LOGGER_SESSIONID = "DECODER"; + public static final String LOGGER_IDTYPE = "DECODER"; + public static final String LOGGER_EMPTY = ""; + public static final int REQUEST_IMAGE_HEADER = 1; public static final int REQUEST_IMAGE_HEADER_AND_DATA = 2; public static final String IMAGE_WIDTH = "WIDTH"; - public static final String IMAGE_HEIGHT = "HEIGHT"; + public static final String IMAGE_HEIGHT = "HEIGHT"; public static final String IMAGE_LOSSLESS = "LOSSLESS"; - public static final String IMAGE_DEPTH = "DEPTH"; + public static final String IMAGE_DEPTH = "DEPTH"; public static final String IMAGE_DPI_HORIZONTAL = "DPI_HORIZONTAL"; public static final String IMAGE_DPI_VERTICAL = "DPI_VERTICAL"; public static final String IMAGE_BIT_RATE = "BIT_RATE"; @@ -15,14 +23,13 @@ public class DecoderConstant { public static final String IMAGE_SIZE = "SIZE"; public static final String IMAGE_TYPE = "TYPE"; public static final String IMAGE_COLOR_SPACE = "COLOR_SPACE"; - public static final String IMAGE_ASPECT_RATIO = "ASPECT_RATIO"; - public static final String IMAGE_COMPRESSION_RATIO = "COMPRESSION_RATIO"; + public static final String IMAGE_ASPECT_RATIO = "ASPECT_RATIO"; + public static final String IMAGE_COMPRESSION_RATIO = "COMPRESSION_RATIO"; public static final int WHENCE_SEEK_END = 1; public static final int WHENCE_SEEK_CUR = 2; public static final int WHENCE_SEEK_SET = 3; - - + public static final String IMAGE_TYPE_JP2000 = "JP2000"; public static final String IMAGE_TYPE_WSQ = "WSQ"; } diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/constant/openjpeg/OpenJpegConstant.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/constant/openjpeg/OpenJpegConstant.java index 3bf96f5..edcc9e4 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/constant/openjpeg/OpenJpegConstant.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/constant/openjpeg/OpenJpegConstant.java @@ -4,12 +4,9 @@ import io.mosip.imagedecoder.model.openjpeg.J2KProgressionOrder; import io.mosip.imagedecoder.model.openjpeg.ProgressionOrder; import lombok.Data; -import lombok.Getter; -import lombok.Setter; -@Getter -@Setter @Data +@SuppressWarnings({ "java:S2386"}) public class OpenJpegConstant extends DecoderConstant { public static final String OPENJPEG_VERSION = "1.3.0"; @@ -156,9 +153,10 @@ public class OpenJpegConstant extends DecoderConstant { public static final double DBL_MIN = 2.2250738585072014e-308; // min positive value public static final int DBL_MIN_10_EXP = (-307); // min decimal exponent public static final int DBL_MIN_EXP = (-1021); // min binary exponent + + @SuppressWarnings({ "java:S115" }) public static final int _DBL_RADIX = 2; // exponent radix public static final double DBL_TRUE_MIN = 4.9406564584124654e-324; // min positive value - public static final int[] LUT_CONTEXTNO_ZC = { 0, 1, 1, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, @@ -264,7 +262,7 @@ public class OpenJpegConstant extends DecoderConstant { /* */ /* This table contains the norms of the 5-3 wavelets for different bands. */ /* */ - public static final double DWT_NORMS [][] = { + public static final double [][] DWT_NORMS = { {1.000, 1.500, 2.750, 5.375, 10.68, 21.34, 42.67, 85.33, 170.7, 341.3}, {1.038, 1.592, 2.919, 5.703, 11.33, 22.64, 45.25, 90.48, 180.9}, {1.038, 1.592, 2.919, 5.703, 11.33, 22.64, 45.25, 90.48, 180.9}, @@ -274,7 +272,7 @@ public class OpenJpegConstant extends DecoderConstant { /* */ /* This table contains the norms of the 9-7 wavelets for different bands. */ /* */ - public static final double DWT_NORMS_REAL[][] = { + public static final double[][] DWT_NORMS_REAL = { {1.000, 1.965, 4.177, 8.403, 16.90, 33.84, 67.69, 135.3, 270.6, 540.9}, {2.022, 3.989, 8.355, 17.04, 34.27, 68.63, 137.3, 274.6, 549.0}, {2.022, 3.989, 8.355, 17.04, 34.27, 68.63, 137.3, 274.6, 549.0}, @@ -287,7 +285,6 @@ public class OpenJpegConstant extends DecoderConstant { public static final float DWT_DELTA = -0.443506852f; // -3633 public static final float K = 1.230174105f; // 10078 - /* FIXME: What is this constant? */ public static final float C13318 = 1.625732422f; /* */ @@ -303,7 +300,6 @@ public class OpenJpegConstant extends DecoderConstant { public static final double[] MCT_NORMS_REAL = { 1.732, 1.805, 1.573 }; /** @defgroup JP2 JP2 - JPEG-2000 file format reader/writer */ - /*@{*/ public static final int JPIP_JPIP = 0x6a706970; @@ -330,7 +326,7 @@ public class OpenJpegConstant extends DecoderConstant { new J2KProgressionOrder(ProgressionOrder.RPCL, "RPCL".toCharArray()), new J2KProgressionOrder(ProgressionOrder.PROG_UNKNOWN, "".toCharArray()) }; - public static final int T1_MOD[] = { OpenJpegConstant.T1_SIG_S, OpenJpegConstant.T1_SIG_S | OpenJpegConstant.T1_SGN_S, OpenJpegConstant.T1_SIG_E, + public static final int[] T1_MOD = { OpenJpegConstant.T1_SIG_S, OpenJpegConstant.T1_SIG_S | OpenJpegConstant.T1_SGN_S, OpenJpegConstant.T1_SIG_E, OpenJpegConstant.T1_SIG_E | OpenJpegConstant.T1_SGN_E, OpenJpegConstant.T1_SIG_W, OpenJpegConstant.T1_SIG_W | OpenJpegConstant.T1_SGN_W, OpenJpegConstant.T1_SIG_N, OpenJpegConstant.T1_SIG_N | OpenJpegConstant.T1_SGN_N }; diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/constant/wsq/WsqConstant.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/constant/wsq/WsqConstant.java index ce31761..a983b4b 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/constant/wsq/WsqConstant.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/constant/wsq/WsqConstant.java @@ -85,5 +85,5 @@ public class WsqConstant extends DecoderConstant { public static final String NCM_SD_ID = "SD_ID"; /* 4,9,10,14,18 */ /// < Invalid data found when processing input - public static final int AVERROR_INVALIDDATA = ByteStreamUtil.getInstance().FFERRTAG('I', 'N', 'D', 'A'); + public static final int AVERROR_INVALIDDATA = ByteStreamUtil.getInstance().ffErrorTag('I', 'N', 'D', 'A'); } diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/constant/wsq/WsqErrorCode.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/constant/wsq/WsqErrorCode.java index b352d0a..87207e9 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/constant/wsq/WsqErrorCode.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/constant/wsq/WsqErrorCode.java @@ -7,7 +7,8 @@ * @since 1.0.0 */ public enum WsqErrorCode { - NON_COMPLIANT_WITH_WSQ_SPECS(-1, "MOS-EXT-1", "A code in the hufftable contains an : all 1's code. This image may still be decodable. It is not compliant with the WSQ specification."), + NON_COMPLIANT_WITH_WSQ_SPECS(-1, "MOS-EXT-1", + "A code in the hufftable contains an : all 1's code. This image may still be decodable. It is not compliant with the WSQ specification."), EMPTY_STRING_FOUND(-2, "MOS-EXT-2", "Empty name string found."), NO_DATA_TO_READ(-3, "MOS-EXT-3", "No huffman table bytes remaining."), TABLE_ID_ALREADY_DEFINED(-4, "MOS-EXT-4", "Huffman table Id already defined."), @@ -19,8 +20,9 @@ public enum WsqErrorCode { NO_MARKER_FOUND(-13, "MOS-EXT-13", "No marker found."), NOT_VALID_MARKER_FOUND(-14, "MOS-EXT-14", "Not a valid marker found."), INVALID_MARKER_FOUND(-15, "MOS-EXT-15", "Invalid marker found."), - - ENCODED_DATA_WRONG(-31, "MOS-EXT-31", "Decoded data extends past image buffer. Encoded data appears corrupt or non-standard."), + + ENCODED_DATA_WRONG(-31, "MOS-EXT-31", + "Decoded data extends past image buffer. Encoded data appears corrupt or non-standard."), INVALID_CODE_INHUFFMAN_DATA(-32, "MOS-EXT-32", "Invalid code in HuffmanData."), NO_STUFFED_ZEROS(-33, "MOS-DEC-33", "getWsqNextBits : No stuffed zeros."), QUANTIZATION_TABLE_PARAMS_NOT_DEFINED(-34, "MOS-DEC-34", "Quantization table parameters not defined."), @@ -29,7 +31,7 @@ public enum WsqErrorCode { INVALID_QUANTIZATION_PIXEL_VALUE(-37, "MOS-DEC-37", "Invalid quantization pixel value."), IMAGE_DATA_OVERFLOW_WILL_READING(-38, "MOS-DEC-38", "Image Data overflow while reading."), INVALID_TABLE_DEFINED(-39, "MOS-DEC-39", "Invalid Table defined."), - + TECHNICAL_ERROR_EXCEPTION(-500, "MOS-EXT-500", "Technical Error"); private final int errorId; @@ -53,13 +55,13 @@ public String getErrorCode() { public String getErrorMessage() { return errorMessage; } - + public static WsqErrorCode fromErrorCode(String errorCode) { - for (WsqErrorCode paramCode : WsqErrorCode.values()) { - if (paramCode.getErrorCode().equalsIgnoreCase(errorCode)) { - return paramCode; - } - } + for (WsqErrorCode paramCode : WsqErrorCode.values()) { + if (paramCode.getErrorCode().equalsIgnoreCase(errorCode)) { + return paramCode; + } + } return TECHNICAL_ERROR_EXCEPTION; } -} +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/logger/ImageDecoderLogger.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/logger/ImageDecoderLogger.java new file mode 100644 index 0000000..6e6790a --- /dev/null +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/logger/ImageDecoderLogger.java @@ -0,0 +1,23 @@ +package io.mosip.imagedecoder.logger; + +import io.mosip.kernel.core.logger.spi.Logger; +import io.mosip.kernel.logger.logback.factory.Logfactory; + +public final class ImageDecoderLogger { + /** + * Instantiates a new ImageDecoder logger. + */ + private ImageDecoderLogger() { + throw new IllegalStateException("ImageDecoderLogger class"); + } + + /** + * Method to get the rolling file logger for the class provided. + * + * @param clazz the clazz + * @return the logger + */ + public static Logger getLogger(Class clazz) { + return Logfactory.getSlf4jLogger(clazz); + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/ByteBufferContext.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/ByteBufferContext.java index 16ced8a..9ee13ac 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/ByteBufferContext.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/ByteBufferContext.java @@ -1,14 +1,30 @@ package io.mosip.imagedecoder.model; import java.nio.ByteBuffer; +import java.util.Objects; import lombok.Data; -import lombok.Getter; -import lombok.Setter; -@Getter -@Setter @Data public class ByteBufferContext { private ByteBuffer buffer; + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (!(o instanceof ByteBufferContext)) + return false; + ByteBufferContext that = (ByteBufferContext) o; + return Objects.equals(buffer, that.buffer); + } + + @Override + public int hashCode() { + return Objects.hash(buffer); + } + + public boolean canEqual(Object other) { + return other instanceof ByteBufferContext; + } } \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/DecoderRequestInfo.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/DecoderRequestInfo.java index 8bbd8f0..b9b1274 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/DecoderRequestInfo.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/DecoderRequestInfo.java @@ -1,18 +1,40 @@ package io.mosip.imagedecoder.model; +import java.util.Arrays; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; /** * The DecoderRequestInfo * * @author Janardhan B S */ -@Getter -@Setter @Data -public class DecoderRequestInfo { +public class DecoderRequestInfo { private byte[] imageData; private boolean isBufferedImage; + private boolean isAllInfo = true; + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (!(o instanceof DecoderRequestInfo)) + return false; + DecoderRequestInfo that = (DecoderRequestInfo) o; + return isBufferedImage == that.isBufferedImage && isAllInfo == that.isAllInfo + && Arrays.equals(imageData, that.imageData); // Arrays.equals for array comparison + } + + @Override + public int hashCode() { + int result = Objects.hash(isBufferedImage, isAllInfo); + result = 31 * result + Arrays.hashCode(imageData); // Arrays.hashCode for array + return result; + } + + public boolean canEqual(Object other) { + return other instanceof DecoderRequestInfo; + } } \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/DecoderResponseInfo.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/DecoderResponseInfo.java index aa10d9e..9ed87ed 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/DecoderResponseInfo.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/DecoderResponseInfo.java @@ -1,20 +1,17 @@ package io.mosip.imagedecoder.model; import java.awt.image.BufferedImage; +import java.util.Objects; import lombok.Data; -import lombok.Getter; -import lombok.Setter; /** * The DecoderRequestInfo * * @author Janardhan B S */ -@Getter -@Setter @Data -public class DecoderResponseInfo { +public class DecoderResponseInfo { // JPEG2000 or WSQ private String imageType; private String imageWidth; @@ -27,12 +24,43 @@ public class DecoderResponseInfo { private String imageDpiVertical; private String imageBitRate; private String imageSize; - //base 64 urlencoded image data + // base 64 urlencoded image data private String imageData; private BufferedImage bufferedImage; - //GRAY or RGB + // GRAY or RGB private String imageColorSpace; private String imageAspectRatio; - //Lossy should be 15 : 1, for lossless should be 1 : 1 + // Lossy should be 15 : 1, for lossless should be 1 : 1 private String imageCompressionRatio; + private boolean isAllInfo = true; + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (!(o instanceof DecoderResponseInfo)) + return false; + DecoderResponseInfo that = (DecoderResponseInfo) o; + return isAllInfo == that.isAllInfo && Objects.equals(imageType, that.imageType) + && Objects.equals(imageWidth, that.imageWidth) && Objects.equals(imageHeight, that.imageHeight) + && Objects.equals(imageLossless, that.imageLossless) && Objects.equals(imageDepth, that.imageDepth) + && Objects.equals(imageDpiHorizontal, that.imageDpiHorizontal) + && Objects.equals(imageDpiVertical, that.imageDpiVertical) + && Objects.equals(imageBitRate, that.imageBitRate) && Objects.equals(imageSize, that.imageSize) + && Objects.equals(imageData, that.imageData) && Objects.equals(bufferedImage, that.bufferedImage) + && Objects.equals(imageColorSpace, that.imageColorSpace) + && Objects.equals(imageAspectRatio, that.imageAspectRatio) + && Objects.equals(imageCompressionRatio, that.imageCompressionRatio); + } + + @Override + public int hashCode() { + return Objects.hash(imageType, imageWidth, imageHeight, imageLossless, imageDepth, imageDpiHorizontal, + imageDpiVertical, imageBitRate, imageSize, imageData, bufferedImage, imageColorSpace, imageAspectRatio, + imageCompressionRatio, isAllInfo); + } + + public boolean canEqual(Object other) { + return other instanceof DecoderResponseInfo; + } } \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/Response.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/Response.java index 1796790..6d27105 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/Response.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/Response.java @@ -1,5 +1,7 @@ package io.mosip.imagedecoder.model; +import java.util.Objects; + import lombok.Data; /** @@ -10,13 +12,34 @@ */ @Data public class Response { - + /** The status code. */ private Integer statusCode; - + /** The status message. */ private String statusMessage; - + /** The response. */ + @SuppressWarnings({ "java:S1700" }) private T response; + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (!(o instanceof Response)) + return false; + Response that = (Response) o; + return Objects.equals(statusCode, that.statusCode) && Objects.equals(statusMessage, that.statusMessage) + && Objects.equals(response, that.response); + } + + @Override + public int hashCode() { + return Objects.hash(statusCode, statusMessage, response); + } + + public boolean canEqual(Object other) { + return other instanceof Response; + } } \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Bio.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Bio.java index 636faef..e37a818 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Bio.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Bio.java @@ -1,15 +1,16 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Arrays; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** -Individual bit input-output stream (BIO) -*/ + * Individual bit input-output stream (BIO) + */ +@Data +@ToString public class Bio { /** pointer to the start of the buffer */ private int start; @@ -22,4 +23,26 @@ public class Bio { private long buf; /** coder : number of bits free to write. decoder : number of bits read */ private int ct; -} + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof Bio)) + return false; + Bio that = (Bio) obj; + return start == that.start && end == that.end && bpIndex == that.bpIndex && buf == that.buf && ct == that.ct + && Arrays.equals(bp, that.bp); + } + + @Override + public int hashCode() { + int result = Objects.hash(start, end, bpIndex, buf, ct); + result = 31 * result + Arrays.hashCode(bp); + return result; + } + + public boolean canEqual(Object other) { + return other instanceof Bio; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Cio.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Cio.java index 06cfc7a..681e265 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Cio.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Cio.java @@ -1,15 +1,16 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Arrays; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** * Byte input-output stream (CIO) */ +@Data +@ToString public class Cio { /** codec context */ private CodecContextInfo codecContextInfo; @@ -27,4 +28,27 @@ public class Cio { private int end; /** pointer to the current position */ private int bpIndex = -1; -} + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof Cio)) + return false; + Cio that = (Cio) obj; + return openMode == that.openMode && length == that.length && start == that.start && end == that.end + && bpIndex == that.bpIndex && Objects.equals(codecContextInfo, that.codecContextInfo) + && Arrays.equals(buffer, that.buffer); + } + + @Override + public int hashCode() { + int result = Objects.hash(codecContextInfo, openMode, length, start, end, bpIndex); + result = 31 * result + Arrays.hashCode(buffer); + return result; + } + + public boolean canEqual(Object other) { + return other instanceof Cio; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/CodeStreamInfo.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/CodeStreamInfo.java index 0bbbb4d..1da65db 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/CodeStreamInfo.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/CodeStreamInfo.java @@ -1,15 +1,16 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Arrays; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** - * CodeStreaminfo + * CodeStreaminfo */ +@Data +@ToString public class CodeStreamInfo { /** maximum distortion reduction on the whole image */ private double distortionMax; @@ -57,4 +58,37 @@ public class CodeStreamInfo { private int codeStreamSize; /** information regarding tiles inside image */ private TileInfo[] tileInfo; -} + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof CodeStreamInfo)) + return false; + CodeStreamInfo that = (CodeStreamInfo) obj; + return Double.compare(that.distortionMax, distortionMax) == 0 && packetNo == that.packetNo + && indexWrite == that.indexWrite && imageWidth == that.imageWidth && imageHeight == that.imageHeight + && tileX == that.tileX && tileY == that.tileY && tileOX == that.tileOX && tileOY == that.tileOY + && tileWidth == that.tileWidth && tileHeight == that.tileHeight && noOfComps == that.noOfComps + && noOfLayers == that.noOfLayers && markerNo == that.markerNo && maxMarkerNo == that.maxMarkerNo + && mainHeadStart == that.mainHeadStart && mainHeadEnd == that.mainHeadEnd + && codeStreamSize == that.codeStreamSize + && Arrays.equals(noOfDecompositionComps, that.noOfDecompositionComps) + && Arrays.equals(markers, that.markers) && Arrays.equals(tileInfo, that.tileInfo); + } + + @Override + public int hashCode() { + int result = Objects.hash(distortionMax, packetNo, indexWrite, imageWidth, imageHeight, tileX, tileY, tileOX, + tileOY, tileWidth, tileHeight, noOfComps, noOfLayers, markerNo, maxMarkerNo, mainHeadStart, mainHeadEnd, + codeStreamSize); + result = 31 * result + Arrays.hashCode(noOfDecompositionComps); + result = 31 * result + Arrays.hashCode(markers); + result = 31 * result + Arrays.hashCode(tileInfo); + return result; + } + + public boolean canEqual(Object other) { + return other instanceof CodeStreamInfo; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/CodecContextInfo.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/CodecContextInfo.java index e2a0b03..5f67e63 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/CodecContextInfo.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/CodecContextInfo.java @@ -1,21 +1,41 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /* * Routines that are to be used by both halves of the library are declared to * receive a pointer to this structure. There are no actual instances of * CommonStructure, only of CompressionContextInfo and DecompressionContextInfo. */ +@Data +@ToString public class CodecContextInfo { private ContextInfo contextInfo = new ContextInfo(); /* Fields common to both master struct types */ /* - * Additional fields follow in an actual CompressionContextInfo or DecompressionContextInfo. All three - * structs must agree on these initial fields! + * Additional fields follow in an actual CompressionContextInfo or + * DecompressionContextInfo. All three structs must agree on these initial + * fields! */ + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof CodecContextInfo)) + return false; + CodecContextInfo that = (CodecContextInfo) obj; + return Objects.equals(contextInfo, that.contextInfo); + } + + @Override + public int hashCode() { + return Objects.hash(contextInfo); + } + + public boolean canEqual(Object other) { + return other instanceof CodecContextInfo; + } } \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/CodingParameters.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/CodingParameters.java index 87884d0..3a7317f 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/CodingParameters.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/CodingParameters.java @@ -1,16 +1,17 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Arrays; +import java.util.Objects; + import io.mosip.imagedecoder.constant.openjpeg.OpenJpegConstant; import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** * Coding parameters */ +@Data +@ToString public class CodingParameters { /** Digital cinema profile */ private JP2CinemeaMode cinemaMode; @@ -130,4 +131,57 @@ public class CodingParameters { /** maximum number of tiles at the decoder */ private int maxTiles; // USE_JPWL END + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof CodingParameters)) + return false; + CodingParameters that = (CodingParameters) obj; + return maxCompSize == that.maxCompSize && imageSize == that.imageSize && tilePartOn == that.tilePartOn + && tilePartFlag == that.tilePartFlag && tilePartPosition == that.tilePartPosition + && distortionAllocation == that.distortionAllocation && fixedAllocation == that.fixedAllocation + && fixedQuality == that.fixedQuality && reduce == that.reduce && layer == that.layer + && tileX0 == that.tileX0 && tileY0 == that.tileY0 && tileDX == that.tileDX && tileDY == that.tileDY + && tileWidth == that.tileWidth && tileHeight == that.tileHeight && tileNoSize == that.tileNoSize + && ppmDataIndex == that.ppmDataIndex && ppm == that.ppm && ppmStore == that.ppmStore + && ppmPrevious == that.ppmPrevious && ppmLength == that.ppmLength && epcOn == that.epcOn + && epbOn == that.epbOn && esdOn == that.esdOn && infoOn == that.infoOn && redOn == that.redOn + && hprotMH == that.hprotMH && sensSize == that.sensSize && sensAddr == that.sensAddr + && sensRange == that.sensRange && sensMH == that.sensMH && correct == that.correct + && expComps == that.expComps && maxTiles == that.maxTiles && Arrays.equals(comment, that.comment) + && Arrays.equals(tileNo, that.tileNo) && Arrays.equals(ppmData, that.ppmData) + && Arrays.equals(ppmDataFirst, that.ppmDataFirst) && Arrays.equals(tcps, that.tcps) + && Arrays.equals(matrice, that.matrice) && Arrays.equals(hprotTPHTileNo, that.hprotTPHTileNo) + && Arrays.equals(hprotTPH, that.hprotTPH) && Arrays.equals(pprotTileNo, that.pprotTileNo) + && Arrays.equals(pprotPacketNo, that.pprotPacketNo) && Arrays.equals(pprot, that.pprot) + && Arrays.equals(sensTPHTileNo, that.sensTPHTileNo) && Arrays.equals(sensTPH, that.sensTPH); + } + + @Override + public int hashCode() { + int result = Objects.hash(maxCompSize, imageSize, tilePartOn, tilePartFlag, tilePartPosition, + distortionAllocation, fixedAllocation, fixedQuality, reduce, layer, tileX0, tileY0, tileDX, tileDY, + tileWidth, tileHeight, tileNoSize, ppmDataIndex, ppm, ppmStore, ppmPrevious, ppmLength, epcOn, epbOn, + esdOn, infoOn, redOn, hprotMH, sensSize, sensAddr, sensRange, sensMH, correct, expComps, maxTiles); + result = 31 * result + Arrays.hashCode(comment); + result = 31 * result + Arrays.hashCode(tileNo); + result = 31 * result + Arrays.hashCode(ppmData); + result = 31 * result + Arrays.hashCode(ppmDataFirst); + result = 31 * result + Arrays.hashCode(tcps); + result = 31 * result + Arrays.hashCode(matrice); + result = 31 * result + Arrays.hashCode(hprotTPHTileNo); + result = 31 * result + Arrays.hashCode(hprotTPH); + result = 31 * result + Arrays.hashCode(pprotTileNo); + result = 31 * result + Arrays.hashCode(pprotPacketNo); + result = 31 * result + Arrays.hashCode(pprot); + result = 31 * result + Arrays.hashCode(sensTPHTileNo); + result = 31 * result + Arrays.hashCode(sensTPH); + return result; + } + + public boolean canEqual(Object other) { + return other instanceof CodingParameters; + } } \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/CompressionParameters.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/CompressionParameters.java index 7349405..84e9313 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/CompressionParameters.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/CompressionParameters.java @@ -1,16 +1,17 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Arrays; +import java.util.Objects; + import io.mosip.imagedecoder.constant.openjpeg.OpenJpegConstant; import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** * Compression parameters */ +@Data +@ToString public class CompressionParameters { /** * size of tile: tile_size_on = false (not in argument) or = true (in argument) @@ -98,7 +99,6 @@ public class CompressionParameters { /* UniPG>> */ /** @name JPWL encoding parameters */ - /* @{ */ /** enables writing of EPC in MH, thus activating JPWL */ private int jpwlEpcOn; /** error protection method for MH (0,1,16,32,37-128) */ @@ -142,4 +142,72 @@ public class CompressionParameters { private int tpFlag; /** MCT (multiple component transform) */ private int tcpMct; + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (!(o instanceof CompressionParameters)) + return false; + CompressionParameters that = (CompressionParameters) o; + return tileSizeOn == that.tileSizeOn && cpTileX0 == that.cpTileX0 && cpTileY0 == that.cpTileY0 + && cpTileDX == that.cpTileDX && cpTileDY == that.cpTileDY + && cpDistortionAllocation == that.cpDistortionAllocation && cpFixedAllocation == that.cpFixedAllocation + && cpFixedQuality == that.cpFixedQuality && codingStyle == that.codingStyle && noOfPocs == that.noOfPocs + && tcpNoOfLayers == that.tcpNoOfLayers && noOfResolution == that.noOfResolution + && codeBlockWidthInit == that.codeBlockWidthInit && codeBlockHeightInit == that.codeBlockHeightInit + && mode == that.mode && irreversible == that.irreversible && roiCompNo == that.roiCompNo + && roiShift == that.roiShift && resSpec == that.resSpec && indexOn == that.indexOn + && imageOffsetX0 == that.imageOffsetX0 && imageOffsetY0 == that.imageOffsetY0 + && subSamplingDX == that.subSamplingDX && subSamplingDY == that.subSamplingDY + && decodeFormat == that.decodeFormat && codecFormat == that.codecFormat && jpwlEpcOn == that.jpwlEpcOn + && jpwlHprotMH == that.jpwlHprotMH && jpwlSensSize == that.jpwlSensSize + && jpwlSensAddr == that.jpwlSensAddr && jpwlSensRange == that.jpwlSensRange + && jpwlSensMH == that.jpwlSensMH && maxCompSize == that.maxCompSize && tpOn == that.tpOn + && tpFlag == that.tpFlag && tcpMct == that.tcpMct && Arrays.equals(cpMatrice, that.cpMatrice) + && Arrays.equals(cpComment, that.cpComment) && Arrays.equals(tcpRates, that.tcpRates) + && Arrays.equals(tcpDistortionRatio, that.tcpDistortionRatio) + && Arrays.equals(precinctWidthInit, that.precinctWidthInit) + && Arrays.equals(precinctHeightInit, that.precinctHeightInit) && Arrays.equals(infile, that.infile) + && Arrays.equals(outfile, that.outfile) && Arrays.equals(index, that.index) + && Arrays.equals(jpwlHprotTPHTileNo, that.jpwlHprotTPHTileNo) + && Arrays.equals(jpwlHprotTPH, that.jpwlHprotTPH) + && Arrays.equals(jpwlPprotTileNo, that.jpwlPprotTileNo) + && Arrays.equals(jpwlPprotPacketNo, that.jpwlPprotPacketNo) && Arrays.equals(jpwlPprot, that.jpwlPprot) + && Arrays.equals(jpwlSensTPHTileNo, that.jpwlSensTPHTileNo) + && Arrays.equals(jpwlSensTPH, that.jpwlSensTPH) && cpCinemaMode == that.cpCinemaMode + && cpRsizCap == that.cpRsizCap && Arrays.equals(pocs, that.pocs); + } + + @Override + public int hashCode() { + int result = Objects.hash(tileSizeOn, cpTileX0, cpTileY0, cpTileDX, cpTileDY, cpDistortionAllocation, + cpFixedAllocation, cpFixedQuality, codingStyle, noOfPocs, tcpNoOfLayers, noOfResolution, + codeBlockWidthInit, codeBlockHeightInit, mode, irreversible, roiCompNo, roiShift, resSpec, indexOn, + imageOffsetX0, imageOffsetY0, subSamplingDX, subSamplingDY, decodeFormat, codecFormat, jpwlEpcOn, + jpwlHprotMH, jpwlSensSize, jpwlSensAddr, jpwlSensRange, jpwlSensMH, maxCompSize, tpOn, tpFlag, tcpMct, + cpCinemaMode, cpRsizCap); + result = 31 * result + Arrays.hashCode(cpMatrice); + result = 31 * result + Arrays.hashCode(cpComment); + result = 31 * result + Arrays.hashCode(tcpRates); + result = 31 * result + Arrays.hashCode(tcpDistortionRatio); + result = 31 * result + Arrays.hashCode(precinctWidthInit); + result = 31 * result + Arrays.hashCode(precinctHeightInit); + result = 31 * result + Arrays.hashCode(infile); + result = 31 * result + Arrays.hashCode(outfile); + result = 31 * result + Arrays.hashCode(index); + result = 31 * result + Arrays.hashCode(jpwlHprotTPHTileNo); + result = 31 * result + Arrays.hashCode(jpwlHprotTPH); + result = 31 * result + Arrays.hashCode(jpwlPprotTileNo); + result = 31 * result + Arrays.hashCode(jpwlPprotPacketNo); + result = 31 * result + Arrays.hashCode(jpwlPprot); + result = 31 * result + Arrays.hashCode(jpwlSensTPHTileNo); + result = 31 * result + Arrays.hashCode(jpwlSensTPH); + result = 31 * result + Arrays.hashCode(pocs); + return result; + } + + public boolean canEqual(Object other) { + return other instanceof CompressionParameters; + } } \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/ContextInfo.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/ContextInfo.java index 431f793..b498ef2 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/ContextInfo.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/ContextInfo.java @@ -1,15 +1,13 @@ package io.mosip.imagedecoder.model.openjpeg; import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** * Common fields between JPEG-2000 compression and decompression master structs. */ +@Data +@ToString public class ContextInfo { private Object clientData; /** < Available for use by application */ @@ -21,5 +19,37 @@ public class ContextInfo { /** < pointer to the J2K codec */ private Object jp2Handle; /** < pointer to the JP2 codec */ - private Object mj2Handle; /** < pointer to the MJ2 codec */ + private Object mj2Handle; + + /** < pointer to the MJ2 codec */ + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof ContextInfo)) + return false; + ContextInfo that = (ContextInfo) obj; + return isDecompressor == that.isDecompressor && canEqual(that) + && (clientData != null ? clientData.equals(that.clientData) : that.clientData == null) + && (codecFormat != null ? codecFormat.equals(that.codecFormat) : that.codecFormat == null) + && (j2kHandle != null ? j2kHandle.equals(that.j2kHandle) : that.j2kHandle == null) + && (jp2Handle != null ? jp2Handle.equals(that.jp2Handle) : that.jp2Handle == null) + && (mj2Handle != null ? mj2Handle.equals(that.mj2Handle) : that.mj2Handle == null); + } + + @Override + public int hashCode() { + int result = clientData != null ? clientData.hashCode() : 0; + result = 31 * result + isDecompressor; + result = 31 * result + (codecFormat != null ? codecFormat.hashCode() : 0); + result = 31 * result + (j2kHandle != null ? j2kHandle.hashCode() : 0); + result = 31 * result + (jp2Handle != null ? jp2Handle.hashCode() : 0); + result = 31 * result + (mj2Handle != null ? mj2Handle.hashCode() : 0); + return result; + } + + public boolean canEqual(Object obj) { + return obj instanceof ContextInfo; + } } \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/DecoderFunctionInfo.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/DecoderFunctionInfo.java index 3938bdc..4fa6376 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/DecoderFunctionInfo.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/DecoderFunctionInfo.java @@ -1,13 +1,10 @@ package io.mosip.imagedecoder.model.openjpeg; import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter @Data - +@ToString public class DecoderFunctionInfo { /** marker value */ private int id; @@ -15,10 +12,35 @@ public class DecoderFunctionInfo { private int states; /** action linked to the marker */ private String j2kFunctionName; + public DecoderFunctionInfo(int id, int states, String j2kFunctionName) { super(); this.id = id; this.states = states; this.j2kFunctionName = j2kFunctionName; - } -} + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof DecoderFunctionInfo)) + return false; + DecoderFunctionInfo that = (DecoderFunctionInfo) obj; + return id == that.id && states == that.states && canEqual(that) + && (j2kFunctionName != null ? j2kFunctionName.equals(that.j2kFunctionName) + : that.j2kFunctionName == null); + } + + @Override + public int hashCode() { + int result = id; + result = 31 * result + states; + result = 31 * result + (j2kFunctionName != null ? j2kFunctionName.hashCode() : 0); + return result; + } + + public boolean canEqual(Object obj) { + return obj instanceof DecoderFunctionInfo; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/DecompressionParameters.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/DecompressionParameters.java index ccc7f61..70e096f 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/DecompressionParameters.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/DecompressionParameters.java @@ -2,15 +2,13 @@ import io.mosip.imagedecoder.constant.openjpeg.OpenJpegConstant; import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** * Decompression parameters */ +@Data +@ToString public class DecompressionParameters { /** * Set the number of highest resolution levels to be discarded. The image @@ -29,7 +27,6 @@ public class DecompressionParameters { private int cpLayer; /** @name command line encoder parameters (not used inside the library) */ - /* @{ */ /** input file name */ private char[] infile = new char[OpenJpegConstant.MAX_PATH_LEN]; /** output file name */ @@ -38,19 +35,14 @@ public class DecompressionParameters { private int decodeFormat; /** output file format 0: PGX, 1: PxM, 2: BMP */ private int codecFormat; - /* @} */ - /* UniPG>> */ /** @name JPWL decoding parameters */ - /* @{ */ /** activates the JPWL correction capabilities */ private int jpwlCorrect; /** expected number of components */ private int jpwlExpComps; /** maximum number of tiles */ private int jpwlMaxTiles; - /* @} */ - /* <0x8000, 1.5->0xffff) */ private long qeval; @@ -21,6 +21,7 @@ public class MQCoderState { /** next state if the next encoded symbol is the LPS */ private int nlpsIndex; private MQCoderState nlps; + public MQCoderState(long qeval, int mps, int nmpsIndex, int nlpsIndex) { super(); this.qeval = qeval; @@ -28,4 +29,24 @@ public MQCoderState(long qeval, int mps, int nmpsIndex, int nlpsIndex) { this.nmpsIndex = nmpsIndex; this.nlpsIndex = nlpsIndex; } -} + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof MQCoderState)) + return false; + MQCoderState that = (MQCoderState) obj; + return canEqual(that) && qeval == that.qeval && mps == that.mps && nmpsIndex == that.nmpsIndex + && nlpsIndex == that.nlpsIndex && Objects.equals(nmps, that.nmps) && Objects.equals(nlps, that.nlps); + } + + @Override + public int hashCode() { + return Objects.hash(qeval, mps, nmpsIndex, nlpsIndex, nmps, nlps); + } + + public boolean canEqual(Object obj) { + return obj instanceof MQCoderState; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/MarkerInfo.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/MarkerInfo.java index 06c4044..189393c 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/MarkerInfo.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/MarkerInfo.java @@ -1,15 +1,15 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** * Marker structure */ +@Data +@ToString public class MarkerInfo { /** marker type */ private int type; @@ -17,4 +17,23 @@ public class MarkerInfo { private int position; /** length, marker val included */ private int length; -} + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof MarkerInfo)) + return false; + MarkerInfo that = (MarkerInfo) obj; + return canEqual(that) && type == that.type && position == that.position && length == that.length; + } + + @Override + public int hashCode() { + return Objects.hash(type, position, length); + } + + public boolean canEqual(Object obj) { + return obj instanceof MarkerInfo; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/OpenJpegImage.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/OpenJpegImage.java index 755c1cb..0761c97 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/OpenJpegImage.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/OpenJpegImage.java @@ -1,15 +1,16 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Arrays; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** * Defines image data and characteristics */ +@Data +@ToString public class OpenJpegImage { /** * XOsiz: horizontal offset from the origin of the reference grid to the left @@ -34,4 +35,25 @@ public class OpenJpegImage { /** image components */ private OpenJpegImageComponent[] comps; private JP2ResolutionBox resolutionBox = null; -} + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof OpenJpegImage)) + return false; + OpenJpegImage that = (OpenJpegImage) obj; + return canEqual(that) && x0 == that.x0 && y0 == that.y0 && x1 == that.x1 && y1 == that.y1 + && noOfComps == that.noOfComps && qmfbid == that.qmfbid && Objects.equals(colorSpace, that.colorSpace) + && Arrays.equals(comps, that.comps) && Objects.equals(resolutionBox, that.resolutionBox); + } + + @Override + public int hashCode() { + return Objects.hash(x0, y0, x1, y1, noOfComps, qmfbid, colorSpace, resolutionBox) + Arrays.hashCode(comps); + } + + public boolean canEqual(Object obj) { + return obj instanceof OpenJpegImage; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/OpenJpegImageComponent.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/OpenJpegImageComponent.java index 5617230..62ad565 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/OpenJpegImageComponent.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/OpenJpegImageComponent.java @@ -1,15 +1,16 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Arrays; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** * Defines a single image component */ +@Data +@ToString public class OpenJpegImageComponent { /** * XRsiz: horizontal separation of a sample of ith component with respect to the @@ -44,4 +45,26 @@ public class OpenJpegImageComponent { private int factor; /** image component data */ private int[] data; -} + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof OpenJpegImageComponent)) + return false; + OpenJpegImageComponent that = (OpenJpegImageComponent) obj; + return canEqual(that) && dX == that.dX && dY == that.dY && width == that.width && height == that.height + && x0 == that.x0 && y0 == that.y0 && prec == that.prec && bpp == that.bpp && sgnd == that.sgnd + && resNoDecoded == that.resNoDecoded && factor == that.factor && Arrays.equals(data, that.data); + } + + @Override + public int hashCode() { + return Objects.hash(dX, dY, width, height, x0, y0, prec, bpp, sgnd, resNoDecoded, factor) + + Arrays.hashCode(data); + } + + public boolean canEqual(Object obj) { + return obj instanceof OpenJpegImageComponent; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/OpenJpegImageComponentParameters.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/OpenJpegImageComponentParameters.java index 070d4de..f7b25cf 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/OpenJpegImageComponentParameters.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/OpenJpegImageComponentParameters.java @@ -1,15 +1,15 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** * Component parameters structure used by the imageCreate function */ +@Data +@ToString public class OpenJpegImageComponentParameters { /** * XRsiz: horizontal separation of a sample of ith component with respect to the @@ -35,4 +35,24 @@ public class OpenJpegImageComponentParameters { private int bpp; /** signed (1) / unsigned (0) */ private int sgnd; -} + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof OpenJpegImageComponentParameters)) + return false; + OpenJpegImageComponentParameters that = (OpenJpegImageComponentParameters) obj; + return canEqual(that) && dx == that.dx && dy == that.dy && width == that.width && height == that.height + && x0 == that.x0 && y0 == that.y0 && prec == that.prec && bpp == that.bpp && sgnd == that.sgnd; + } + + @Override + public int hashCode() { + return Objects.hash(dx, dy, width, height, x0, y0, prec, bpp, sgnd); + } + + public boolean canEqual(Object obj) { + return obj instanceof OpenJpegImageComponentParameters; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/PacketInfo.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/PacketInfo.java index 2c484f0..02dfd71 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/PacketInfo.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/PacketInfo.java @@ -1,15 +1,15 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** * Index structure : Information concerning a packet inside tile */ +@Data +@ToString public class PacketInfo { /** packet start position (including SOP marker if it exists) */ private int startPosition; @@ -17,6 +17,26 @@ public class PacketInfo { private int endPHPosition; /** packet end position */ private int endPosition; - /** packet distortion*/ + /** packet distortion */ private double distortion; -} + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof PacketInfo)) + return false; + PacketInfo that = (PacketInfo) obj; + return canEqual(that) && startPosition == that.startPosition && endPHPosition == that.endPHPosition + && endPosition == that.endPosition && Double.compare(that.distortion, distortion) == 0; + } + + @Override + public int hashCode() { + return Objects.hash(startPosition, endPHPosition, endPosition, distortion); + } + + public boolean canEqual(Object obj) { + return obj instanceof PacketInfo; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/PiComponent.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/PiComponent.java index 036bfb4..bbb88a0 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/PiComponent.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/PiComponent.java @@ -1,18 +1,42 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Arrays; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** * pi Component */ +@Data +@ToString public class PiComponent { - private int dX, dY; - /** number of resolution levels */ + private int dX; + private int dY; + /** number of resolution levels */ private int noOfResolutions; private PiResolution[] resolutions; -} + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof PiComponent)) + return false; + PiComponent that = (PiComponent) obj; + return canEqual(that) && dX == that.dX && dY == that.dY && noOfResolutions == that.noOfResolutions + && Arrays.equals(resolutions, that.resolutions); + } + + @Override + public int hashCode() { + int result = Objects.hash(dX, dY, noOfResolutions); + result = 31 * result + Arrays.hashCode(resolutions); + return result; + } + + public boolean canEqual(Object obj) { + return obj instanceof PiComponent; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/PiIterator.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/PiIterator.java index d1c3291..feeee55 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/PiIterator.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/PiIterator.java @@ -1,28 +1,32 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Arrays; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** * pi iterator */ +@Data +@ToString public class PiIterator { - /** Enabling Tile part generation*/ + /** Enabling Tile part generation */ private int tilePartOn; - /** precise if the packet has been already used (usefull for progression order change) */ + /** + * precise if the packet has been already used (usefull for progression order + * change) + */ private int[] include; /** layer step used to localize the packet in the include vector */ private int stepL; /** resolution step used to localize the packet in the include vector */ - private int stepR; + private int stepR; /** component step used to localize the packet in the include vector */ - private int stepC; + private int stepC; /** precinct step used to localize the packet in the include vector */ - private int stepP; + private int stepP; /** component that identify the packet */ private int compNo; /** resolution that identify the packet */ @@ -30,15 +34,49 @@ public class PiIterator { /** precinct that identify the packet */ private int precNo; /** layer that identify the packet */ - private int layNo; + private int layNo; /** 0 if the first packet */ private int first; /** progression order change information */ private Poc poc; /** number of components in the image */ private int noOfComps; - /** Components*/ + /** Components */ private PiComponent[] comps; - private int tX0, tY0, tX1, tY1; - private int x, y, dX, dY; -} + private int tX0; + private int tY0; + private int tX1; + private int tY1; + private int x; + private int y; + private int dX; + private int dY; + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof PiIterator)) + return false; + PiIterator that = (PiIterator) obj; + return canEqual(that) && tilePartOn == that.tilePartOn && stepL == that.stepL && stepR == that.stepR + && stepC == that.stepC && stepP == that.stepP && compNo == that.compNo && resNo == that.resNo + && precNo == that.precNo && layNo == that.layNo && first == that.first && noOfComps == that.noOfComps + && tX0 == that.tX0 && tY0 == that.tY0 && tX1 == that.tX1 && tY1 == that.tY1 && x == that.x + && y == that.y && dX == that.dX && dY == that.dY && Arrays.equals(include, that.include) + && Objects.equals(poc, that.poc) && Arrays.equals(comps, that.comps); + } + + @Override + public int hashCode() { + int result = Objects.hash(tilePartOn, stepL, stepR, stepC, stepP, compNo, resNo, precNo, layNo, first, poc, + noOfComps, tX0, tY0, tX1, tY1, x, y, dX, dY); + result = 31 * result + Arrays.hashCode(include); + result = 31 * result + Arrays.hashCode(comps); + return result; + } + + public boolean canEqual(Object obj) { + return obj instanceof PiIterator; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/PiResolution.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/PiResolution.java index b885e38..e17d7ea 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/PiResolution.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/PiResolution.java @@ -1,16 +1,37 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** * pi resolution */ +@Data +@ToString public class PiResolution { - private int pDX, pDY; - private int pWidth, pHeight; -} + private int pDX; + private int pDY; + private int pWidth; + private int pHeight; + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof PiResolution)) + return false; + PiResolution that = (PiResolution) obj; + return canEqual(that) && pDX == that.pDX && pDY == that.pDY && pWidth == that.pWidth && pHeight == that.pHeight; + } + + @Override + public int hashCode() { + return Objects.hash(pDX, pDY, pWidth, pHeight); + } + + public boolean canEqual(Object obj) { + return obj instanceof PiResolution; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Poc.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Poc.java index f9f7ade..7b693f4 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Poc.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Poc.java @@ -1,40 +1,97 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Arrays; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** * Progression order changes */ +@Data +@ToString public class Poc { /** Resolution num start, Component num start, given by POC */ - private int resNo0, compNo0; + private int resNo0; + private int compNo0; /** Layer num end,Resolution num end, Component num end, given by POC */ - private int layNo1, resNo1, compNo1; + private int layNo1; + private int resNo1; + private int compNo1; /** Layer num start,Precinct num start, Precinct num end */ - private int layNo0, precNo0, precNo1; + private int layNo0; + private int precNo0; + private int precNo1; /** Progression order enum */ - private ProgressionOrder progressionOrder, progressionOrder1; + private ProgressionOrder progressionOrder; + private ProgressionOrder progressionOrder1; /** Progression order string */ private char[] progressionName = new char[5]; /** Tile number */ private int tile; /** Start and end values for Tile width and height */ - private int tX0, tX1, tY0, tY1; + private int tX0; + private int tX1; + private int tY0; + private int tY1; /** Start value, initialised in piInitEncode */ - private int layS, resS, compS, prcS; + private int layS; + private int resS; + private int compS; + private int prcS; /** End value, initialised in piInitEncode */ - private int layE, resE, compE, prcE; + private int layE; + private int resE; + private int compE; + private int prcE; /** - * Start and end values of Tile width and height, initialised in - * piInitEncode + * Start and end values of Tile width and height, initialised in piInitEncode */ - private int tXS, tXE, tYS, tYE, dX, dY; + private int tXS; + private int tXE; + private int tYS; + private int tYE; + private int dX; + private int dY; /** Temporary values for Tile parts, initialised in piCreateEncode */ - private int layTmp, resTmp, compTmp, prcTmp, tx0Tmp, ty0Tmp; -} + private int layTmp; + private int resTmp; + private int compTmp; + private int prcTmp; + private int tx0Tmp; + private int ty0Tmp; + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof Poc)) + return false; + Poc that = (Poc) obj; + return canEqual(that) && resNo0 == that.resNo0 && compNo0 == that.compNo0 && layNo1 == that.layNo1 + && resNo1 == that.resNo1 && compNo1 == that.compNo1 && layNo0 == that.layNo0 && precNo0 == that.precNo0 + && precNo1 == that.precNo1 && tile == that.tile && tX0 == that.tX0 && tX1 == that.tX1 && tY0 == that.tY0 + && tY1 == that.tY1 && layS == that.layS && resS == that.resS && compS == that.compS && prcS == that.prcS + && layE == that.layE && resE == that.resE && compE == that.compE && prcE == that.prcE && tXS == that.tXS + && tXE == that.tXE && tYS == that.tYS && tYE == that.tYE && dX == that.dX && dY == that.dY + && layTmp == that.layTmp && resTmp == that.resTmp && compTmp == that.compTmp && prcTmp == that.prcTmp + && tx0Tmp == that.tx0Tmp && ty0Tmp == that.ty0Tmp + && Objects.equals(progressionOrder, that.progressionOrder) + && Objects.equals(progressionOrder1, that.progressionOrder1) + && Arrays.equals(progressionName, that.progressionName); + } + + @Override + public int hashCode() { + int result = Objects.hash(resNo0, compNo0, layNo1, resNo1, compNo1, layNo0, precNo0, precNo1, progressionOrder, + progressionOrder1, tile, tX0, tX1, tY0, tY1, layS, resS, compS, prcS, layE, resE, compE, prcE, tXS, tXE, + tYS, tYE, dX, dY, layTmp, resTmp, compTmp, prcTmp, tx0Tmp, ty0Tmp); + result = 31 * result + Arrays.hashCode(progressionName); + return result; + } + public boolean canEqual(Object obj) { + return obj instanceof Poc; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/ProgressionOrder.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/ProgressionOrder.java index 7a3b53c..b26903a 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/ProgressionOrder.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/ProgressionOrder.java @@ -25,6 +25,7 @@ public enum ProgressionOrder { this.value = value; } + @SuppressWarnings({ "java:S1144" }) ProgressionOrder(ProgressionOrder value) { this.value = value.value(); } @@ -39,7 +40,7 @@ public static ProgressionOrder fromValue(int value) { return c; } } - throw new IllegalArgumentException(value + ""); + throw new IllegalArgumentException("No enum constant for value: " + value); } @Override diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Raw.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Raw.java index 5282dc6..8b2947b 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Raw.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Raw.java @@ -1,15 +1,16 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Arrays; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** -RAW encoding operations -*/ + * RAW encoding operations + */ +@Data +@ToString public class Raw { /** temporary buffer where bits are coded or decoded */ private int c; @@ -27,4 +28,26 @@ public class Raw { private int start; /** pointer to the end of the buffer */ private int end; -} + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof Raw)) + return false; + Raw that = (Raw) obj; + return canEqual(that) && c == that.c && ct == that.ct && lengthMax == that.lengthMax && length == that.length + && bpIndex == that.bpIndex && start == that.start && end == that.end && Arrays.equals(bp, that.bp); + } + + @Override + public int hashCode() { + int result = Objects.hash(c, ct, lengthMax, length, bpIndex, start, end); + result = 31 * result + Arrays.hashCode(bp); + return result; + } + + public boolean canEqual(Object obj) { + return obj instanceof Raw; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/RsizCapabilities.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/RsizCapabilities.java index 6aaf8b0..22d3c15 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/RsizCapabilities.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/RsizCapabilities.java @@ -19,6 +19,7 @@ public enum RsizCapabilities { this.value = value; } + @SuppressWarnings({ "java:S1144" }) RsizCapabilities(RsizCapabilities value) { this.value = value.value(); } @@ -33,7 +34,7 @@ public static RsizCapabilities fromValue(int value) { return c; } } - throw new IllegalArgumentException(value + ""); + throw new IllegalArgumentException("No enum constant for value: " + value); } @Override diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/StepSize.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/StepSize.java index 73e76cf..8b41da5 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/StepSize.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/StepSize.java @@ -1,18 +1,37 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** -Quantization stepsize -*/ + * Quantization stepsize + */ +@Data +@ToString public class StepSize { /** exponent */ private int expn; /** mantissa */ private int mant; + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof StepSize)) + return false; + StepSize that = (StepSize) obj; + return canEqual(that) && expn == that.expn && mant == that.mant; + } + + @Override + public int hashCode() { + return Objects.hash(expn, mant); + } + + public boolean canEqual(Object obj) { + return obj instanceof StepSize; + } } \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Tcd.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Tcd.java index d43150e..ecdaf79 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Tcd.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Tcd.java @@ -1,23 +1,23 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** -Tile coder/decoder -*/ + * Tile coder/decoder + */ +@Data +@ToString public class Tcd { - /** Position of the tilepart flag in Progression order*/ + /** Position of the tilepart flag in Progression order */ private int tilePartPosition; - /** Tile part number*/ + /** Tile part number */ private int tilePartNo; - /** Current tile part number*/ + /** Current tile part number */ private int curTilePartNo; - /** Total number of tileparts of the current tile*/ + /** Total number of tileparts of the current tile */ private int curTotalNoOfTileParts; /** Current Packet iterator number */ private int curPiNo; @@ -35,7 +35,33 @@ public class Tcd { /** coding/decoding parameters common to all tiles */ private Tcp tcp; /** current encoded/decoded tile */ - int tcdTileNo; - /** Time taken to encode a tile*/ - double encodingTime; + private int tcdTileNo; + /** Time taken to encode a tile */ + private double encodingTime; + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Tcd tcd = (Tcd) o; + return tilePartPosition == tcd.tilePartPosition && tilePartNo == tcd.tilePartNo + && curTilePartNo == tcd.curTilePartNo && curTotalNoOfTileParts == tcd.curTotalNoOfTileParts + && curPiNo == tcd.curPiNo && tcdTileNo == tcd.tcdTileNo + && Double.compare(tcd.encodingTime, encodingTime) == 0 + && Objects.equals(codecContextInfo, tcd.codecContextInfo) && Objects.equals(tcdImage, tcd.tcdImage) + && Objects.equals(image, tcd.image) && Objects.equals(codingParameters, tcd.codingParameters) + && Objects.equals(tcdTile, tcd.tcdTile) && Objects.equals(tcp, tcd.tcp); + } + + @Override + public int hashCode() { + return Objects.hash(tilePartPosition, tilePartNo, curTilePartNo, curTotalNoOfTileParts, curPiNo, + codecContextInfo, tcdImage, image, codingParameters, tcdTile, tcp, tcdTileNo, encodingTime); + } + + public boolean canEqual(Object other) { + return other instanceof Tcd; + } } \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdBand.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdBand.java index a0f91bc..771fda5 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdBand.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdBand.java @@ -1,19 +1,58 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Arrays; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** -Tile band -*/ + * Tile band + */ +@Data +@ToString public class TcdBand { - private int x0, y0, x1, y1; /* dimension of the subband : left upper corner (x0, y0) right low corner (x1,y1) */ + private int x0; /* + * dimension of the subband : left upper corner (x0, y0) right low corner + * (x1,y1) + */ + private int y0; /* + * dimension of the subband : left upper corner (x0, y0) right low corner + * (x1,y1) + */ + private int x1; /* + * dimension of the subband : left upper corner (x0, y0) right low corner + * (x1,y1) + */ + private int y1; /* + * dimension of the subband : left upper corner (x0, y0) right low corner + * (x1,y1) + */ private int bandNo; - private TcdPrecinct[] precincts; /* precinct information */ + private TcdPrecinct[] precincts; /* precinct information */ private int noOfBps; private float stepSize; + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + TcdBand tcdBand = (TcdBand) o; + return x0 == tcdBand.x0 && y0 == tcdBand.y0 && x1 == tcdBand.x1 && y1 == tcdBand.y1 && bandNo == tcdBand.bandNo + && noOfBps == tcdBand.noOfBps && Float.compare(tcdBand.stepSize, stepSize) == 0 + && Arrays.equals(precincts, tcdBand.precincts); + } + + @Override + public int hashCode() { + int result = Objects.hash(x0, y0, x1, y1, bandNo, noOfBps, stepSize); + result = 31 * result + Arrays.hashCode(precincts); + return result; + } + + public boolean canEqual(Object other) { + return other instanceof TcdBand; + } } \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdCodeBlockDecoder.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdCodeBlockDecoder.java index 7506a8e..9efcf12 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdCodeBlockDecoder.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdCodeBlockDecoder.java @@ -1,22 +1,53 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Arrays; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** -Tile block decode -*/ + * Tile block decode + */ +@Data +@ToString public class TcdCodeBlockDecoder { - private byte[] data; /* Data */ - private TcdSegment[] segs; /* segments informations */ - private int x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */ + private byte[] data; /* Data */ + private TcdSegment[] segs; /* segments informations */ + private int x0; + private int y0; + private int x1; + private int y1; /* + * dimension of the code-blocks : left upper corner (x0, y0) right low corner + * (x1,y1) + */ private int noOfBps; private int noOfLengthBits; - private int length; /* length */ - private int noOfNewPasses; /* number of pass added to the code-blocks */ - private int noOfSegs; /* number of segments */ + private int length; /* length */ + private int noOfNewPasses; /* number of pass added to the code-blocks */ + private int noOfSegs; /* number of segments */ + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + TcdCodeBlockDecoder that = (TcdCodeBlockDecoder) o; + return x0 == that.x0 && y0 == that.y0 && x1 == that.x1 && y1 == that.y1 && noOfBps == that.noOfBps + && noOfLengthBits == that.noOfLengthBits && length == that.length && noOfNewPasses == that.noOfNewPasses + && noOfSegs == that.noOfSegs && Arrays.equals(data, that.data) && Arrays.equals(segs, that.segs); + } + + @Override + public int hashCode() { + int result = Objects.hash(x0, y0, x1, y1, noOfBps, noOfLengthBits, length, noOfNewPasses, noOfSegs); + result = 31 * result + Arrays.hashCode(data); + result = 31 * result + Arrays.hashCode(segs); + return result; + } + + public boolean canEqual(Object other) { + return other instanceof TcdCodeBlockDecoder; + } } \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdCodeBlockEncoder.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdCodeBlockEncoder.java index 5025a6f..5c0f59e 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdCodeBlockEncoder.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdCodeBlockEncoder.java @@ -1,24 +1,59 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Arrays; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** -Tile block encode -*/ + * Tile block encode + */ +@Data +@ToString public class TcdCodeBlockEncoder { - private int dataIndex; /* Data Index*/ - private byte [] data; /* Data */ - private TcdLayer[] layers; /* layer information */ - private TcdPass[] passes; /* information about the passes */ - private int x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */ + private int dataIndex; /* Data Index */ + private byte[] data; /* Data */ + private TcdLayer[] layers; /* layer information */ + private TcdPass[] passes; /* information about the passes */ + private int x0; + private int y0; + private int x1; + private int y1; /* + * dimension of the code-blocks : left upper corner (x0, y0) right low corner + * (x1,y1) + */ private int noOfBps; private int noOfLengthBits; - private int noOfPasses; /* number of pass already done for the code-blocks */ - private int noOfPassesInLayers; /* number of passes in the layer */ - private int totalPasses; /* total number of passes */ + private int noOfPasses; /* number of pass already done for the code-blocks */ + private int noOfPassesInLayers; /* number of passes in the layer */ + private int totalPasses; /* total number of passes */ + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + TcdCodeBlockEncoder that = (TcdCodeBlockEncoder) o; + return dataIndex == that.dataIndex && x0 == that.x0 && y0 == that.y0 && x1 == that.x1 && y1 == that.y1 + && noOfBps == that.noOfBps && noOfLengthBits == that.noOfLengthBits && noOfPasses == that.noOfPasses + && noOfPassesInLayers == that.noOfPassesInLayers && totalPasses == that.totalPasses + && Arrays.equals(data, that.data) && Arrays.equals(layers, that.layers) + && Arrays.equals(passes, that.passes); + } + + @Override + public int hashCode() { + int result = Objects.hash(dataIndex, x0, y0, x1, y1, noOfBps, noOfLengthBits, noOfPasses, noOfPassesInLayers, + totalPasses); + result = 31 * result + Arrays.hashCode(data); + result = 31 * result + Arrays.hashCode(layers); + result = 31 * result + Arrays.hashCode(passes); + return result; + } + + public boolean canEqual(Object other) { + return other instanceof TcdCodeBlockEncoder; + } } \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdImage.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdImage.java index 866b746..becc2c1 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdImage.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdImage.java @@ -1,16 +1,40 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Arrays; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** -Tile Image -*/ + * Tile Image + */ +@Data +@ToString public class TcdImage { - private int tileWidth, tileHeight; /* number of tiles in width and heigth */ - private TcdTile[] tiles; /* Tiles information */ + private int tileWidth; /* number of tiles in width */ + private int tileHeight; /* number of tiles in heigth */ + private TcdTile[] tiles; /* Tiles information */ + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + TcdImage tcdImage = (TcdImage) o; + return tileWidth == tcdImage.tileWidth && tileHeight == tcdImage.tileHeight + && Arrays.equals(tiles, tcdImage.tiles); + } + + @Override + public int hashCode() { + int result = Objects.hash(tileWidth, tileHeight); + result = 31 * result + Arrays.hashCode(tiles); + return result; + } + + public boolean canEqual(Object other) { + return other instanceof TcdImage; + } } \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdLayer.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdLayer.java index f8a0b26..767ac4f 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdLayer.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdLayer.java @@ -1,18 +1,41 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Arrays; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** -Tile layers -*/ + * Tile layers + */ +@Data +@ToString public class TcdLayer { - private int noOfPasses; /* Number of passes in the layer */ - private int length; /* len of information */ - private double distortion; /* add for index */ - private byte[] data; /* data */ + private int noOfPasses; /* Number of passes in the layer */ + private int length; /* len of information */ + private double distortion; /* add for index */ + private byte[] data; /* data */ + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + TcdLayer tcdLayer = (TcdLayer) o; + return noOfPasses == tcdLayer.noOfPasses && length == tcdLayer.length + && Double.compare(tcdLayer.distortion, distortion) == 0 && Arrays.equals(data, tcdLayer.data); + } + + @Override + public int hashCode() { + int result = Objects.hash(noOfPasses, length, distortion); + result = 31 * result + Arrays.hashCode(data); + return result; + } + + public boolean canEqual(Object other) { + return other instanceof TcdLayer; + } } \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdPass.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdPass.java index 0a0ae25..38abccd 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdPass.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdPass.java @@ -1,17 +1,38 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** -pass -*/ + * pass + */ +@Data +@ToString public class TcdPass { private int rate; private double distortionDec; - private int term, length; + private int term; + private int length; + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + TcdPass tcdPass = (TcdPass) o; + return rate == tcdPass.rate && term == tcdPass.term && length == tcdPass.length + && Double.compare(tcdPass.distortionDec, distortionDec) == 0; + } + + @Override + public int hashCode() { + return Objects.hash(rate, distortionDec, term, length); + } + + public boolean canEqual(Object other) { + return other instanceof TcdPass; + } } \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdPrecinct.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdPrecinct.java index b6290e5..9e90517 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdPrecinct.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdPrecinct.java @@ -1,21 +1,54 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Arrays; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** -Tile precinct -*/ + * Tile precinct + */ +@Data +@ToString public class TcdPrecinct { - private int x0, y0, x1, y1; /* dimension of the precinct : left upper corner (x0, y0) right low corner (x1,y1) */ - private int cWidth, cHeight; /* number of precinct in width and heigth */ + private int x0; + private int y0; + private int x1; + private int y1; /* + * dimension of the precinct : left upper corner (x0, y0) right low corner + * (x1,y1) + */ + private int cWidth; /* number of precinct in width */ + private int cHeight; /* number of precinct in heigth */ /* code-blocks informations */ private TcdCodeBlockEncoder[] tcdCodeBlockEncoder; private TcdCodeBlockDecoder[] tcdCodeBlockDecoder; - private TgtTree inclTree; /* inclusion tree */ - private TgtTree imsbTree; /* IMSB tree */ + private TgtTree inclTree; /* inclusion tree */ + private TgtTree imsbTree; /* IMSB tree */ + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + TcdPrecinct that = (TcdPrecinct) o; + return x0 == that.x0 && y0 == that.y0 && x1 == that.x1 && cWidth == that.cWidth && cHeight == that.cHeight + && Arrays.equals(tcdCodeBlockEncoder, that.tcdCodeBlockEncoder) + && Arrays.equals(tcdCodeBlockDecoder, that.tcdCodeBlockDecoder) + && Objects.equals(inclTree, that.inclTree) && Objects.equals(imsbTree, that.imsbTree); + } + + @Override + public int hashCode() { + int result = Objects.hash(x0, y0, x1, cWidth, cHeight, inclTree, imsbTree); + result = 31 * result + Arrays.hashCode(tcdCodeBlockEncoder); + result = 31 * result + Arrays.hashCode(tcdCodeBlockDecoder); + return result; + } + + public boolean canEqual(Object other) { + return other instanceof TcdPrecinct; + } } \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdResolution.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdResolution.java index e754952..b274320 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdResolution.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdResolution.java @@ -1,18 +1,48 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Arrays; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** -Tile resolution -*/ + * Tile resolution + */ +@Data +@ToString public class TcdResolution { - private int x0, y0, x1, y1; /* dimension of the resolution level : left upper corner (x0, y0) right low corner (x1,y1) */ - private int pWidth, pHeight; - private int noOfBands; /* number sub-band for the resolution level */ - private TcdBand[] bands = new TcdBand[3]; /* subband information */ + private int x0; + private int y0; + private int x1; + private int y1; /* + * dimension of the resolution level : left upper corner (x0, y0) right low + * corner (x1,y1) + */ + private int pWidth; + private int pHeight; + private int noOfBands; /* number sub-band for the resolution level */ + private TcdBand[] bands = new TcdBand[3]; /* subband information */ + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + TcdResolution that = (TcdResolution) o; + return x0 == that.x0 && y0 == that.y0 && x1 == that.x1 && y1 == that.y1 && pWidth == that.pWidth + && pHeight == that.pHeight && noOfBands == that.noOfBands && Arrays.equals(bands, that.bands); + } + + @Override + public int hashCode() { + int result = Objects.hash(x0, y0, x1, y1, pWidth, pHeight, noOfBands); + result = 31 * result + Arrays.hashCode(bands); + return result; + } + + public boolean canEqual(Object other) { + return other instanceof TcdResolution; + } } \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdSegment.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdSegment.java index c788c62..325f60b 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdSegment.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdSegment.java @@ -1,15 +1,16 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Arrays; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** -Segment -*/ + * Segment + */ +@Data +@ToString public class TcdSegment { private byte[] data; private int dataIndex; @@ -18,4 +19,27 @@ public class TcdSegment { private int maxPasses; private int noOfNewPasses; private int newLength; + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + TcdSegment that = (TcdSegment) o; + return dataIndex == that.dataIndex && noOfPasses == that.noOfPasses && length == that.length + && maxPasses == that.maxPasses && noOfNewPasses == that.noOfNewPasses && newLength == that.newLength + && Arrays.equals(data, that.data); + } + + @Override + public int hashCode() { + int result = Objects.hash(dataIndex, noOfPasses, length, maxPasses, noOfNewPasses, newLength); + result = 31 * result + Arrays.hashCode(data); + return result; + } + + public boolean canEqual(Object other) { + return other instanceof TcdSegment; + } } \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdTile.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdTile.java index de83a71..0cdac5e 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdTile.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdTile.java @@ -1,22 +1,53 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Arrays; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** -Tile -*/ + * Tile + */ +@Data +@ToString public class TcdTile { - private int x0, y0, x1, y1; /* dimension of the tile : left upper corner (x0, y0) right low corner (x1,y1) */ - private int noOfComps; /* number of components in tile */ - private TcdTileComponent[] comps; /* Components information */ - private int noOfPixels; /* add fixed_quality */ - private double distortionTile; /* add fixed_quality */ - private double[] distortionLayer = new double[100]; /* add fixed_quality */ + private int x0; + private int y0; + private int x1; + private int y1; /* + * dimension of the tile : left upper corner (x0, y0) right low corner (x1,y1) + */ + private int noOfComps; /* number of components in tile */ + private TcdTileComponent[] comps; /* Components information */ + private int noOfPixels; /* add fixed_quality */ + private double distortionTile; /* add fixed_quality */ + private double[] distortionLayer = new double[100]; /* add fixed_quality */ /** packet number */ private int packetNo; + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + TcdTile tcdTile = (TcdTile) o; + return x0 == tcdTile.x0 && y0 == tcdTile.y0 && x1 == tcdTile.x1 && y1 == tcdTile.y1 + && noOfComps == tcdTile.noOfComps && noOfPixels == tcdTile.noOfPixels + && Double.compare(tcdTile.distortionTile, distortionTile) == 0 && packetNo == tcdTile.packetNo + && Arrays.equals(comps, tcdTile.comps) && Arrays.equals(distortionLayer, tcdTile.distortionLayer); + } + + @Override + public int hashCode() { + int result = Objects.hash(x0, y0, x1, y1, noOfComps, noOfPixels, distortionTile, packetNo); + result = 31 * result + Arrays.hashCode(comps); + result = 31 * result + Arrays.hashCode(distortionLayer); + return result; + } + + public boolean canEqual(Object other) { + return other instanceof TcdTile; + } } \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdTileComponent.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdTileComponent.java index 1a478e1..53b1560 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdTileComponent.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TcdTileComponent.java @@ -1,20 +1,52 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Arrays; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** -Tile comp -*/ + * Tile comp + */ +@Data +@ToString public class TcdTileComponent { - private int x0, y0, x1, y1; /* dimension of component : left upper corner (x0, y0) right low corner (x1,y1) */ - private int noOfResolutions; /* number of resolutions level */ - private TcdResolution[] resolutions; /* resolutions information */ - private int[] iData; /* data of the component */ - private double[] fData; /* data of the component */ - private int noOfPixels; /* add fixed_quality */ + private int x0; + private int y0; + private int x1; + private int y1; /* + * dimension of component : left upper corner (x0, y0) right low corner (x1,y1) + */ + private int noOfResolutions; /* number of resolutions level */ + private TcdResolution[] resolutions; /* resolutions information */ + private int[] iData; /* data of the component */ + private double[] fData; /* data of the component */ + private int noOfPixels; /* add fixed_quality */ + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + TcdTileComponent that = (TcdTileComponent) o; + return x0 == that.x0 && y0 == that.y0 && x1 == that.x1 && y1 == that.y1 + && noOfResolutions == that.noOfResolutions && noOfPixels == that.noOfPixels + && Arrays.equals(resolutions, that.resolutions) && Arrays.equals(iData, that.iData) + && Arrays.equals(fData, that.fData); + } + + @Override + public int hashCode() { + int result = Objects.hash(x0, y0, x1, y1, noOfResolutions, noOfPixels); + result = 31 * result + Arrays.hashCode(resolutions); + result = 31 * result + Arrays.hashCode(iData); + result = 31 * result + Arrays.hashCode(fData); + return result; + } + + public boolean canEqual(Object other) { + return other instanceof TcdTileComponent; + } } \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Tcp.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Tcp.java index 315b995..dce5b5e 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Tcp.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Tcp.java @@ -1,17 +1,17 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Arrays; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** -Tile coding parameters : -this structure is used to store coding/decoding parameters common to all -tiles (information like COD, COC in main header) -*/ + * Tile coding parameters : this structure is used to store coding/decoding + * parameters common to all tiles (information like COD, COC in main header) + */ +@Data +@ToString public class Tcp { /** 1 : first part-tile of a tile */ private int first; @@ -46,4 +46,36 @@ public class Tcp { private float[] distortionRatio = new float[100]; /** tile-component coding parameters */ private TileComponentCodingParameters[] tccps; + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Tcp tcp = (Tcp) o; + return first == tcp.first && codingStyle == tcp.codingStyle && noOfLayers == tcp.noOfLayers && mct == tcp.mct + && noOfPocs == tcp.noOfPocs && isPoc == tcp.isPoc && pptDataIndex == tcp.pptDataIndex && ppt == tcp.ppt + && pptStore == tcp.pptStore && pptLength == tcp.pptLength && Arrays.equals(rates, tcp.rates) + && Arrays.equals(pocs, tcp.pocs) && Arrays.equals(pptData, tcp.pptData) + && Arrays.equals(pptDataFirst, tcp.pptDataFirst) && Arrays.equals(distortionRatio, tcp.distortionRatio) + && Arrays.equals(tccps, tcp.tccps) && Objects.equals(progressionOrder, tcp.progressionOrder); + } + + @Override + public int hashCode() { + int result = Objects.hash(first, codingStyle, progressionOrder, noOfLayers, mct, noOfPocs, isPoc, pptDataIndex, + ppt, pptStore, pptLength); + result = 31 * result + Arrays.hashCode(rates); + result = 31 * result + Arrays.hashCode(pocs); + result = 31 * result + Arrays.hashCode(pptData); + result = 31 * result + Arrays.hashCode(pptDataFirst); + result = 31 * result + Arrays.hashCode(distortionRatio); + result = 31 * result + Arrays.hashCode(tccps); + return result; + } + + public boolean canEqual(Object other) { + return other instanceof Tcp; + } } \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TgtNode.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TgtNode.java index d33fece..49cb79a 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TgtNode.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TgtNode.java @@ -1,18 +1,37 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** -Tag node -*/ + * Tag node + */ +@Data +@ToString public class TgtNode { private int parent; private int value; private int low; private int known; + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + TgtNode tgtNode = (TgtNode) o; + return parent == tgtNode.parent && value == tgtNode.value && low == tgtNode.low && known == tgtNode.known; + } + + @Override + public int hashCode() { + return Objects.hash(parent, value, low, known); + } + + public boolean canEqual(Object other) { + return other instanceof TgtNode; + } } \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TgtTree.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TgtTree.java index a42d79c..2ffcb05 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TgtTree.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TgtTree.java @@ -1,18 +1,41 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Arrays; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** -Tag tree -*/ + * Tag tree + */ +@Data +@ToString public class TgtTree { private int noOfLeafSH; private int noOfLeafSV; private int noOfNodes; private TgtNode[] nodes; + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + TgtTree tgtTree = (TgtTree) o; + return noOfLeafSH == tgtTree.noOfLeafSH && noOfLeafSV == tgtTree.noOfLeafSV && noOfNodes == tgtTree.noOfNodes + && Arrays.equals(nodes, tgtTree.nodes); + } + + @Override + public int hashCode() { + int result = Objects.hash(noOfLeafSH, noOfLeafSV, noOfNodes); + result = 31 * result + Arrays.hashCode(nodes); + return result; + } + + public boolean canEqual(Object other) { + return other instanceof TgtTree; + } } \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Tier1.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Tier1.java index b9957ea..fc421b3 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Tier1.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Tier1.java @@ -1,15 +1,16 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Arrays; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** -Tier-1 coding (coding of code-block coefficients) -*/ + * Tier-1 coding (coding of code-block coefficients) + */ +@Data +@ToString public class Tier1 { /** codec context */ private CodecContextInfo codecContextInfo; @@ -26,4 +27,30 @@ public class Tier1 { private int dataSize; private int flagsSize; private int flagsStride; + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Tier1 tier1 = (Tier1) o; + return width == tier1.width && height == tier1.height && dataSize == tier1.dataSize + && flagsSize == tier1.flagsSize && flagsStride == tier1.flagsStride + && Objects.equals(codecContextInfo, tier1.codecContextInfo) && Objects.equals(mqc, tier1.mqc) + && Objects.equals(raw, tier1.raw) && Arrays.equals(data, tier1.data) + && Arrays.equals(flags, tier1.flags); + } + + @Override + public int hashCode() { + int result = Objects.hash(codecContextInfo, mqc, raw, width, height, dataSize, flagsSize, flagsStride); + result = 31 * result + Arrays.hashCode(data); + result = 31 * result + Arrays.hashCode(flags); + return result; + } + + public boolean canEqual(Object other) { + return other instanceof Tier1; + } } diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Tier2.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Tier2.java index 4eb0bcb..021023b 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Tier2.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/Tier2.java @@ -1,15 +1,15 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** -Tier-2 coding (coding of code-block coefficients) -*/ + * Tier-2 coding (coding of code-block coefficients) + */ +@Data +@ToString public class Tier2 { /** codec context */ private CodecContextInfo codecContextInfo; @@ -18,4 +18,24 @@ public class Tier2 { private OpenJpegImage image; /** pointer to the image coding parameters */ private CodingParameters codingParameters; -} + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Tier2 tier2 = (Tier2) o; + return Objects.equals(codecContextInfo, tier2.codecContextInfo) && Objects.equals(image, tier2.image) + && Objects.equals(codingParameters, tier2.codingParameters); + } + + @Override + public int hashCode() { + return Objects.hash(codecContextInfo, image, codingParameters); + } + + public boolean canEqual(Object other) { + return other instanceof Tier2; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TileComponentCodingParameters.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TileComponentCodingParameters.java index 1dca928..c138e5f 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TileComponentCodingParameters.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TileComponentCodingParameters.java @@ -1,16 +1,17 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Arrays; +import java.util.Objects; + import io.mosip.imagedecoder.constant.openjpeg.OpenJpegConstant; import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** -Tile-component coding parameters -*/ + * Tile-component coding parameters + */ +@Data +@ToString public class TileComponentCodingParameters { /** coding style */ private int codingStyle; @@ -22,7 +23,7 @@ public class TileComponentCodingParameters { private int codeBlockHeight; /** code-block coding style */ private int codeBlockStyle; - /** discrete wavelet transform identifier [Lossless = 1 and Lossy = 0]*/ + /** discrete wavelet transform identifier [Lossless = 1 and Lossy = 0] */ private int qmfbid; /** quantisation style */ private int quantisationStyle; @@ -35,5 +36,35 @@ public class TileComponentCodingParameters { /** precinct width */ private int[] precinctWidth = new int[OpenJpegConstant.J2K_MAXRLVLS]; /** precinct height */ - private int[] precinctHeight = new int[OpenJpegConstant.J2K_MAXRLVLS]; + private int[] precinctHeight = new int[OpenJpegConstant.J2K_MAXRLVLS]; + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + TileComponentCodingParameters that = (TileComponentCodingParameters) o; + return codingStyle == that.codingStyle && noOfResolutions == that.noOfResolutions + && codeBlockWidth == that.codeBlockWidth && codeBlockHeight == that.codeBlockHeight + && codeBlockStyle == that.codeBlockStyle && qmfbid == that.qmfbid + && quantisationStyle == that.quantisationStyle && noOfGaurdBits == that.noOfGaurdBits + && roiShift == that.roiShift && Arrays.equals(stepsizes, that.stepsizes) + && Arrays.equals(precinctWidth, that.precinctWidth) + && Arrays.equals(precinctHeight, that.precinctHeight); + } + + @Override + public int hashCode() { + int result = Objects.hash(codingStyle, noOfResolutions, codeBlockWidth, codeBlockHeight, codeBlockStyle, qmfbid, + quantisationStyle, noOfGaurdBits, roiShift); + result = 31 * result + Arrays.hashCode(stepsizes); + result = 31 * result + Arrays.hashCode(precinctWidth); + result = 31 * result + Arrays.hashCode(precinctHeight); + return result; + } + + public boolean canEqual(Object other) { + return other instanceof TileComponentCodingParameters; + } } \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TileInfo.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TileInfo.java index 5f55846..030c1d8 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TileInfo.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TileInfo.java @@ -1,15 +1,16 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Arrays; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** * Index structure : information regarding tiles */ +@Data +@ToString public class TileInfo { /** value of threshold for each layer by tile cfr. Marcela */ private double[] thresh; @@ -39,4 +40,37 @@ public class TileInfo { private int noOfTileParts; /** information concerning tile parts */ private TpInfo[] tp; -} + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + TileInfo that = (TileInfo) o; + return tileNo == that.tileNo && startPosition == that.startPosition && endHeader == that.endHeader + && endPosition == that.endPosition && noOfPixel == that.noOfPixel + && Double.compare(that.distortionTile, distortionTile) == 0 && noOfTileParts == that.noOfTileParts + && Arrays.equals(thresh, that.thresh) && Arrays.equals(pWidth, that.pWidth) + && Arrays.equals(pHeight, that.pHeight) && Arrays.equals(pDX, that.pDX) && Arrays.equals(pDY, that.pDY) + && Arrays.equals(packet, that.packet) && Arrays.equals(tp, that.tp); + } + + @Override + public int hashCode() { + int result = Objects.hash(tileNo, startPosition, endHeader, endPosition, noOfPixel, distortionTile, + noOfTileParts); + result = 31 * result + Arrays.hashCode(thresh); + result = 31 * result + Arrays.hashCode(pWidth); + result = 31 * result + Arrays.hashCode(pHeight); + result = 31 * result + Arrays.hashCode(pDX); + result = 31 * result + Arrays.hashCode(pDY); + result = 31 * result + Arrays.hashCode(packet); + result = 31 * result + Arrays.hashCode(tp); + return result; + } + + public boolean canEqual(Object other) { + return other instanceof TileInfo; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TpInfo.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TpInfo.java index 583bd51..1d94e1f 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TpInfo.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/TpInfo.java @@ -1,15 +1,15 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /** * Index structure : Information concerning tile-parts */ +@Data +@ToString public class TpInfo { /** start position of tile part */ private int tpStartPosition; @@ -21,4 +21,25 @@ public class TpInfo { private int tpStartPacket; /** number of packets of tile part */ private int tpNoOfPackets; -} + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + TpInfo tpInfo = (TpInfo) o; + return tpStartPosition == tpInfo.tpStartPosition && tpEndHeader == tpInfo.tpEndHeader + && tpEndPosition == tpInfo.tpEndPosition && tpStartPacket == tpInfo.tpStartPacket + && tpNoOfPackets == tpInfo.tpNoOfPackets; + } + + @Override + public int hashCode() { + return Objects.hash(tpStartPosition, tpEndHeader, tpEndPosition, tpStartPacket, tpNoOfPackets); + } + + public boolean canEqual(Object other) { + return other instanceof TpInfo; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/V4.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/V4.java index 2c6d563..810b3b0 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/V4.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/openjpeg/V4.java @@ -1,13 +1,31 @@ package io.mosip.imagedecoder.model.openjpeg; +import java.util.Arrays; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter @Data - +@ToString public class V4 { private double[] f = new double[4]; + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + V4 v4 = (V4) o; + return Arrays.equals(f, v4.f); + } + + @Override + public int hashCode() { + return Arrays.hashCode(f); + } + + public boolean canEqual(Object other) { + return other instanceof V4; + } } \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqFet.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqFet.java index 74f9ac3..87da92f 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqFet.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqFet.java @@ -2,15 +2,57 @@ import io.mosip.imagedecoder.constant.wsq.WsqConstant; import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter @Data +@ToString public class WsqFet { private int alloc = WsqConstant.MAXFETS; private int num = 0; private String[] names = new String[WsqConstant.MAXFETS]; private String[] values = new String[WsqConstant.MAXFETS]; -} + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (!(obj instanceof WsqFet)) return false; + WsqFet that = (WsqFet) obj; + if (this.num != that.num || this.alloc != that.alloc) { + return false; + } + // Check if names and values arrays are equal + return arrayEquals(this.names, that.names) && arrayEquals(this.values, that.values); + } + + private boolean arrayEquals(String[] a1, String[] a2) { + if (a1 == a2) return true; + if (a1 == null || a2 == null) return false; + if (a1.length != a2.length) return false; + for (int i = 0; i < a1.length; i++) { + if (!a1[i].equals(a2[i])) return false; + } + return true; + } + + @Override + public int hashCode() { + int result = Integer.hashCode(alloc); + result = 31 * result + Integer.hashCode(num); + result = 31 * result + arrayHashCode(names); + result = 31 * result + arrayHashCode(values); + return result; + } + + private int arrayHashCode(String[] array) { + if (array == null) return 0; + int hash = 1; + for (String str : array) { + hash = 31 * hash + (str == null ? 0 : str.hashCode()); + } + return hash; + } + + public boolean canEqual(Object other) { + return other instanceof WsqFet; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqHeaderForm.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqHeaderForm.java index 17d0a66..41b2734 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqHeaderForm.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqHeaderForm.java @@ -1,12 +1,10 @@ package io.mosip.imagedecoder.model.wsq; import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter @Data +@ToString public class WsqHeaderForm { private int black; private int white; @@ -16,4 +14,57 @@ public class WsqHeaderForm { private float[] rScale = new float[1]; private int wsqEncoder; private long software; + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof WsqHeaderForm)) + return false; + WsqHeaderForm that = (WsqHeaderForm) obj; + return black == that.black && white == that.white && width == that.width && height == that.height + && wsqEncoder == that.wsqEncoder && software == that.software && arrayEquals(mShift, that.mShift) + && arrayEquals(rScale, that.rScale); + } + + private boolean arrayEquals(float[] a1, float[] a2) { + if (a1 == a2) + return true; + if (a1 == null || a2 == null) + return false; + if (a1.length != a2.length) + return false; + for (int i = 0; i < a1.length; i++) { + if (Float.compare(a1[i], a2[i]) != 0) + return false; + } + return true; + } + + @Override + public int hashCode() { + int result = Integer.hashCode(black); + result = 31 * result + Integer.hashCode(white); + result = 31 * result + Integer.hashCode(width); + result = 31 * result + Integer.hashCode(height); + result = 31 * result + arrayHashCode(mShift); + result = 31 * result + arrayHashCode(rScale); + result = 31 * result + Integer.hashCode(wsqEncoder); + result = 31 * result + Long.hashCode(software); + return result; + } + + private int arrayHashCode(float[] array) { + if (array == null) + return 0; + int hash = 1; + for (float f : array) { + hash = 31 * hash + Float.hashCode(f); + } + return hash; + } + + public boolean canEqual(Object other) { + return other instanceof WsqHeaderForm; + } } diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqHuffCode.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqHuffCode.java index f83ba4f..ac177cd 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqHuffCode.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqHuffCode.java @@ -1,13 +1,32 @@ package io.mosip.imagedecoder.model.wsq; import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter @Data +@ToString public class WsqHuffCode { private int size; private long code; -} + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof WsqHuffCode)) + return false; + WsqHuffCode that = (WsqHuffCode) obj; + return size == that.size && code == that.code; + } + + @Override + public int hashCode() { + int result = Integer.hashCode(size); + result = 31 * result + Long.hashCode(code); + return result; + } + + public boolean canEqual(Object other) { + return other instanceof WsqHuffCode; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqInfo.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqInfo.java index 1d3a37d..0903b5b 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqInfo.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqInfo.java @@ -1,12 +1,13 @@ package io.mosip.imagedecoder.model.wsq; +import java.util.Arrays; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter @Data +@ToString public class WsqInfo { private byte[] data; private int width; @@ -16,4 +17,33 @@ public class WsqInfo { private int lossyFlag; private double bitRate; // bits per pixels private String colorSpace; -} + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof WsqInfo)) + return false; + WsqInfo that = (WsqInfo) obj; + return width == that.width && height == that.height && depth == that.depth && ppi == that.ppi + && lossyFlag == that.lossyFlag && Double.compare(that.bitRate, bitRate) == 0 + && Arrays.equals(data, that.data) && Objects.equals(colorSpace, that.colorSpace); + } + + @Override + public int hashCode() { + int result = Arrays.hashCode(data); + result = 31 * result + width; + result = 31 * result + height; + result = 31 * result + depth; + result = 31 * result + ppi; + result = 31 * result + lossyFlag; + result = 31 * result + Double.hashCode(bitRate); + result = 31 * result + (colorSpace != null ? colorSpace.hashCode() : 0); + return result; + } + + public boolean canEqual(Object other) { + return other instanceof WsqInfo; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqQuantization.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqQuantization.java index 6406bf9..6d38d6c 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqQuantization.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqQuantization.java @@ -1,19 +1,48 @@ package io.mosip.imagedecoder.model.wsq; +import java.util.Arrays; +import java.util.Objects; + import io.mosip.imagedecoder.constant.wsq.WsqConstant; import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter @Data +@ToString public class WsqQuantization { - private float quantizationlevel; /* quantization level */ - private float compressionratio; /* compression ratio */ - private float compressionBitRate; /* compression bitrate */ + private float quantizationLevel; /* quantization level */ + private float compressionRatio; /* compression ratio */ + private float compressionBitRate; /* compression bitrate */ private float[] qbssT = new float[WsqConstant.MAX_SUBBANDS]; private float[] qbss = new float[WsqConstant.MAX_SUBBANDS]; private float[] qzbs = new float[WsqConstant.MAX_SUBBANDS]; + @SuppressWarnings({ "java:S6213" }) private float[] var = new float[WsqConstant.MAX_SUBBANDS]; -} + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof WsqQuantization)) + return false; + WsqQuantization that = (WsqQuantization) obj; + return Float.compare(that.quantizationLevel, quantizationLevel) == 0 + && Float.compare(that.compressionRatio, compressionRatio) == 0 + && Float.compare(that.compressionBitRate, compressionBitRate) == 0 && Arrays.equals(qbssT, that.qbssT) + && Arrays.equals(qbss, that.qbss) && Arrays.equals(qzbs, that.qzbs) && Arrays.equals(var, that.var); + } + + @Override + public int hashCode() { + int result = Objects.hash(quantizationLevel, compressionRatio, compressionBitRate); + result = 31 * result + Arrays.hashCode(qbssT); + result = 31 * result + Arrays.hashCode(qbss); + result = 31 * result + Arrays.hashCode(qzbs); + result = 31 * result + Arrays.hashCode(var); + return result; + } + + public boolean canEqual(Object other) { + return other instanceof WsqQuantization; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqQuantizationTree.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqQuantizationTree.java index 7249bd4..ae5039f 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqQuantizationTree.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqQuantizationTree.java @@ -1,15 +1,34 @@ package io.mosip.imagedecoder.model.wsq; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter @Data +@ToString public class WsqQuantizationTree { - private short x; /* UL corner of block */ + private short x; /* UL corner of block */ private short y; - private short lenX; /* block size */ - private short lenY; /* block size */ -} + private short lenX; /* block size */ + private short lenY; /* block size */ + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof WsqQuantizationTree)) + return false; + WsqQuantizationTree that = (WsqQuantizationTree) obj; + return x == that.x && y == that.y && lenX == that.lenX && lenY == that.lenY; + } + + @Override + public int hashCode() { + return Objects.hash(x, y, lenX, lenY); + } + + public boolean canEqual(Object other) { + return other instanceof WsqQuantizationTree; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqTableDht.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqTableDht.java index b78ab4a..ce59378 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqTableDht.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqTableDht.java @@ -1,13 +1,12 @@ package io.mosip.imagedecoder.model.wsq; +import java.util.Arrays; +import java.util.Objects; + import io.mosip.imagedecoder.constant.wsq.WsqConstant; import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter -@Data /* * A distributed hash table (DHT) is a distributed system that provides a lookup * service similar to a hash table: key–value pairs are stored in a DHT, and any @@ -22,8 +21,33 @@ * continual node arrivals, departures, and failures. * */ +@Data +@ToString public class WsqTableDht { private int tableDef; private int[] huffBits = new int[WsqConstant.MAX_HUFFBITS]; private int[] huffValues = new int[WsqConstant.MAX_HUFFCOUNTS_WSQ + 1]; -} + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof WsqTableDht)) + return false; + WsqTableDht that = (WsqTableDht) obj; + return tableDef == that.tableDef && Arrays.equals(huffBits, that.huffBits) + && Arrays.equals(huffValues, that.huffValues); + } + + @Override + public int hashCode() { + int result = Objects.hash(tableDef); + result = 31 * result + Arrays.hashCode(huffBits); + result = 31 * result + Arrays.hashCode(huffValues); + return result; + } + + public boolean canEqual(Object other) { + return other instanceof WsqTableDht; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqTableDqt.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqTableDqt.java index eef39fd..4820714 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqTableDqt.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqTableDqt.java @@ -1,16 +1,40 @@ package io.mosip.imagedecoder.model.wsq; +import java.util.Arrays; +import java.util.Objects; + import io.mosip.imagedecoder.constant.wsq.WsqConstant; import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter @Data +@ToString public class WsqTableDqt { private float binCenter; private float[] qBin = new float[WsqConstant.MAX_SUBBANDS]; private float[] zBin = new float[WsqConstant.MAX_SUBBANDS]; private int dqtDef; -} + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof WsqTableDqt)) + return false; + WsqTableDqt that = (WsqTableDqt) obj; + return Float.compare(that.binCenter, binCenter) == 0 && dqtDef == that.dqtDef && Arrays.equals(qBin, that.qBin) + && Arrays.equals(zBin, that.zBin); + } + + @Override + public int hashCode() { + int result = Objects.hash(binCenter, dqtDef); + result = 31 * result + Arrays.hashCode(qBin); + result = 31 * result + Arrays.hashCode(zBin); + return result; + } + + public boolean canEqual(Object other) { + return other instanceof WsqTableDqt; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqTableDtt.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqTableDtt.java index 92bd243..962bb1f 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqTableDtt.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqTableDtt.java @@ -1,12 +1,13 @@ package io.mosip.imagedecoder.model.wsq; +import java.util.Arrays; +import java.util.Objects; + import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter @Data +@ToString public class WsqTableDtt { private float[] lowFilter; private float[] highFilter; @@ -14,4 +15,27 @@ public class WsqTableDtt { private int highSize; private int lowDef; private int highDef; -} + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof WsqTableDtt)) + return false; + WsqTableDtt that = (WsqTableDtt) obj; + return lowSize == that.lowSize && highSize == that.highSize && lowDef == that.lowDef && highDef == that.highDef + && Arrays.equals(lowFilter, that.lowFilter) && Arrays.equals(highFilter, that.highFilter); + } + + @Override + public int hashCode() { + int result = Objects.hash(lowSize, highSize, lowDef, highDef); + result = 31 * result + Arrays.hashCode(lowFilter); + result = 31 * result + Arrays.hashCode(highFilter); + return result; + } + + public boolean canEqual(Object other) { + return other instanceof WsqTableDtt; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqWavletTree.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqWavletTree.java index 724a57b..72ac636 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqWavletTree.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/model/wsq/WsqWavletTree.java @@ -1,12 +1,10 @@ package io.mosip.imagedecoder.model.wsq; import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.ToString; -@Getter -@Setter @Data +@ToString public class WsqWavletTree { private int x; private int y; @@ -14,4 +12,24 @@ public class WsqWavletTree { private int lenY; private int invRow; private int invCol; -} + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof WsqWavletTree)) + return false; + WsqWavletTree that = (WsqWavletTree) obj; + return x == that.x && y == that.y && lenX == that.lenX && lenY == that.lenY && invRow == that.invRow + && invCol == that.invCol; + } + + @Override + public int hashCode() { + return 31 * x + 31 * y + 31 * lenX + 31 * lenY + 31 * invRow + 31 * invCol; + } + + public boolean canEqual(Object other) { + return other instanceof WsqWavletTree; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/BioHelper.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/BioHelper.java index ff5dd34..40e167f 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/BioHelper.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/BioHelper.java @@ -4,21 +4,20 @@ public class BioHelper { // Static variable reference of singleInstance of type Singleton - private static BioHelper singleInstance = null; - private BioHelper() - { - super (); - } - - //synchronized method to control simultaneous access - public static synchronized BioHelper getInstance() - { + private static BioHelper singleInstance = null; + + private BioHelper() { + super(); + } + + // synchronized method to control simultaneous access + public static synchronized BioHelper getInstance() { if (singleInstance == null) singleInstance = new BioHelper(); - - return singleInstance; + + return singleInstance; } - + public int bioByteOut(Bio bio) { bio.setBuf((bio.getBuf() << 8) & 0xffff); bio.setCt(bio.getBuf() == 0xff00 ? 7 : 8); @@ -58,13 +57,17 @@ public int bioGetBit(Bio bio) { } public Bio bioCreate() { - Bio bio = new Bio(); - return bio; + return new Bio(); } - public void bioDestroy(Bio bio) { - if (bio != null) - bio = null; + /** + * Releases resources associated with this Bio object. + * + * This method properly cleans up any resources used by the Bio object, + * ensuring efficient memory management and preventing potential leaks. + * Call this method when you are done using a Bio object. + */ + public void bioDestroy(Bio bio) {// default implementation ignored } public int bioNoOfBytes(Bio bio) { @@ -97,8 +100,8 @@ public void bioWrite(Bio bio, int v, int n) { } public int bioRead(Bio bio, int n) { - int i, v; - v = 0; + int i; + int v = 0; for (i = n - 1; i >= 0; i--) { v += bioGetBit(bio) << i; } @@ -129,4 +132,4 @@ public int bioInAlign(Bio bio) { } return 0; } -} +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/CioHelper.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/CioHelper.java index 24e5894..1f329a9 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/CioHelper.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/CioHelper.java @@ -1,7 +1,7 @@ package io.mosip.imagedecoder.openjpeg; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import io.mosip.kernel.core.logger.spi.Logger; +import io.mosip.imagedecoder.logger.ImageDecoderLogger; import io.mosip.imagedecoder.constant.openjpeg.OpenJpegConstant; import io.mosip.imagedecoder.model.openjpeg.Cio; @@ -10,24 +10,30 @@ import io.mosip.imagedecoder.model.openjpeg.J2K; import io.mosip.imagedecoder.model.openjpeg.JP2; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_SESSIONID; + +import java.text.MessageFormat; + +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_EMPTY; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_IDTYPE; + public class CioHelper { - private static Logger LOGGER = LoggerFactory.getLogger(CioHelper.class); + private static Logger logger = ImageDecoderLogger.getLogger(CioHelper.class); // Static variable reference of singleInstance of type Singleton - private static CioHelper singleInstance = null; - private CioHelper() - { - super (); - } - - //synchronized method to control simultaneous access - public static synchronized CioHelper getInstance() - { + private static CioHelper singleInstance = null; + + private CioHelper() { + super(); + } + + // synchronized method to control simultaneous access + public static synchronized CioHelper getInstance() { if (singleInstance == null) singleInstance = new CioHelper(); - - return singleInstance; + + return singleInstance; } - + public Cio cioOpen(CodecContextInfo codecContextInfo, byte[] buffer, int length) { CodingParameters codingParameters = null; Cio cio = new Cio(); @@ -45,17 +51,16 @@ public Cio cioOpen(CodecContextInfo codecContextInfo, byte[] buffer, int length) codingParameters = ((J2K) codecContextInfo.getContextInfo().getJ2kHandle()).getCodingParameters(); break; case CODEC_JP2: - codingParameters = ((JP2) codecContextInfo.getContextInfo().getJp2Handle()).getJ2k().getCodingParameters(); + codingParameters = ((JP2) codecContextInfo.getContextInfo().getJp2Handle()).getJ2k() + .getCodingParameters(); break; default: - cio = null; return null; } /* 0.1625 = 1.3/8 and 2000 bytes as a minimum for headers */ cio.setLength((int) (0.1625 * codingParameters.getImageSize() + 2000)); cio.setBuffer(new byte[cio.getLength()]); } else { - cio = null; return null; } @@ -69,13 +74,9 @@ public Cio cioOpen(CodecContextInfo codecContextInfo, byte[] buffer, int length) } public void cioClose(Cio cio) { - if (cio != null) { - if (cio.getOpenMode() == OpenJpegConstant.STREAM_WRITE) { - /* destroy the allocated buffer */ - cio.setBuffer(null); - } - /* destroy the cio */ - cio = null; + if (cio != null && cio.getOpenMode() == OpenJpegConstant.STREAM_WRITE) { + /* destroy the allocated buffer */ + cio.setBuffer(null); } } @@ -123,7 +124,8 @@ public int cioGetBufferIndex(Cio cio) { */ public int cioByteOut(Cio cio, byte value) { if (cio.getBpIndex() >= cio.getEnd()) { - LOGGER.error(String.format("write error" + cio.getCodecContextInfo())); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + MessageFormat.format("cioByteOut::write error{0}", cio.getCodecContextInfo())); return 0; } cio.setBpIndex(cio.getBpIndex() + 1); @@ -136,8 +138,9 @@ public int cioByteOut(Cio cio, byte value) { */ public byte cioByteIn(Cio cio) { if (cio.getBpIndex() >= cio.getEnd()) { - LOGGER.error(String.format("read error: passed the end of the codestream (current = %d, end = %d)", - cio.getBpIndex(), cio.getEnd())); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + MessageFormat.format("read error: passed the end of the codestream current = {0}, end = {1}", + cio.getBpIndex(), cio.getEnd())); return 0; } cio.setBpIndex(cio.getBpIndex() + 1); @@ -157,8 +160,8 @@ public long cioWrite(Cio cio, long v, int noOfBytes) { } /* - * Read some bytes. noOfBytes : number of bytes to read return : value of the n bytes - * read + * Read some bytes. noOfBytes : number of bytes to read return : value of the n + * bytes read */ public long cioRead(Cio cio, int noOfBytes) { int i; @@ -183,4 +186,4 @@ public void cioSkip(Cio cio, int noOfBytes) { public void cioPosition(Cio cio, int pos) { cio.setBpIndex(pos); } -} +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/DwtHelper.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/DwtHelper.java index d1fa11c..ea9392d 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/DwtHelper.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/DwtHelper.java @@ -1,6 +1,8 @@ package io.mosip.imagedecoder.openjpeg; +import io.mosip.imagedecoder.constant.DecoderErrorCodes; import io.mosip.imagedecoder.constant.openjpeg.OpenJpegConstant; +import io.mosip.imagedecoder.exceptions.DecoderException; import io.mosip.imagedecoder.model.openjpeg.Dwt; import io.mosip.imagedecoder.model.openjpeg.DwtV4; import io.mosip.imagedecoder.model.openjpeg.StepSize; @@ -13,25 +15,26 @@ // DWT - Helper Implementation of a discrete wavelet transform public class DwtHelper { // Static variable reference of singleInstance of type Singleton - private static DwtHelper singleInstance = null; - private DwtHelper() - { - super (); - } - - //synchronized method to control simultaneous access - public static synchronized DwtHelper getInstance() - { + private static DwtHelper singleInstance = null; + + private DwtHelper() { + super(); + } + + // synchronized method to control simultaneous access + public static synchronized DwtHelper getInstance() { if (singleInstance == null) singleInstance = new DwtHelper(); - - return singleInstance; + + return singleInstance; } - + + @SuppressWarnings("unused") private int[] dwtWS(int i) { return new int[i * 2]; } + @SuppressWarnings("unused") private int[] dwtWD(int i) { return new int[1 + (i) * 2]; } @@ -149,6 +152,7 @@ private double dwtDReal(double[] a, int index) { return a[(1 + (index) * 2)]; } + @SuppressWarnings({ "unused" }) private int dwtS1(int[] a, int index, int dn, int sn) { if (index < 0) return dwtS(a, 0); @@ -158,6 +162,7 @@ else if (index >= sn) return dwtS(a, index); } + @SuppressWarnings({ "unused" }) private double dwtSReal(double[] a, int index, int dn, int sn) { if (index < 0) return dwtSReal(a, 0); @@ -167,6 +172,7 @@ else if (index >= sn) return dwtSReal(a, index); } + @SuppressWarnings({ "unused" }) private int dwtD1(int[] a, int index, int dn, int sn) { if (index < 0) return dwtD(a, 0); @@ -176,6 +182,7 @@ else if (index >= dn) return dwtD(a, index); } + @SuppressWarnings({ "unused" }) private double dwtDReal(double[] a, int index, int dn, int sn) { if (index < 0) return dwtDReal(a, 0); @@ -185,6 +192,7 @@ else if (index >= dn) return dwtDReal(a, index); } + @SuppressWarnings({ "unused" }) private int dwtSS1(int[] a, int index, int dn, int sn) { if (index < 0) return dwtS(a, 0); @@ -194,6 +202,7 @@ else if (index >= dn) return dwtS(a, index); } + @SuppressWarnings({ "unused" }) private double dwtSS1Real(double[] a, int index, int dn, int sn) { if (index < 0) return dwtSReal(a, 0); @@ -203,6 +212,7 @@ else if (index >= dn) return dwtSReal(a, index); } + @SuppressWarnings({ "unused" }) private int dwtDD1(int[] a, int index, int dn, int sn) { if (index < 0) return dwtD(a, 0); @@ -212,6 +222,7 @@ else if (index >= sn) return dwtD(a, index); } + @SuppressWarnings({ "unused" }) private double dwtDD1Real(double[] a, int index, int dn, int sn) { if (index < 0) return dwtDReal(a, 0); @@ -224,6 +235,7 @@ else if (index >= sn) /* */ /* Forward 5-3 wavelet transform in 1-Dimension. */ /* */ + @SuppressWarnings({ "java:S3776" }) private void dwtEncode1(int[] a, int dn, int sn, int cas) { int i; @@ -249,6 +261,7 @@ private void dwtEncode1(int[] a, int dn, int sn, int cas) { /* */ /* Inverse 5-3 wavelet transform in 1-Dimension. */ /* */ + @SuppressWarnings({ "java:S1659", "java:S3776" }) private void dwtDecode11(int[] a, int dn, int sn, int cas) { int i; @@ -281,18 +294,23 @@ private void dwtDecode1(Dwt v) { /* */ /* Forward 9-7 wavelet transform in 1-dimension. */ /* */ + @SuppressWarnings({ "java:S3776" }) private void dwtEncode1Real(double[] a, int dn, int sn, int cas) { int i; if (cas == 0) { if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */ for (i = 0; i < dn; i++) - dwtDSetReal(a, i, dwtDReal(a, i) - fixMul(dwtSReal(a, i, dn, sn) + dwtSReal(a, i + 1, dn, sn), 12993)); + dwtDSetReal(a, i, + dwtDReal(a, i) - fixMul(dwtSReal(a, i, dn, sn) + dwtSReal(a, i + 1, dn, sn), 12993)); for (i = 0; i < sn; i++) - dwtSSetReal(a, i, dwtSReal(a, i) - fixMul(dwtDReal(a, i - 1, dn, sn) + dwtDReal(a, i, dn, sn), 434)); + dwtSSetReal(a, i, + dwtSReal(a, i) - fixMul(dwtDReal(a, i - 1, dn, sn) + dwtDReal(a, i, dn, sn), 434)); for (i = 0; i < dn; i++) - dwtDSetReal(a, i, dwtDReal(a, i) + fixMul(dwtSReal(a, i, dn, sn) + dwtSReal(a, i + 1, dn, sn), 7233)); + dwtDSetReal(a, i, + dwtDReal(a, i) + fixMul(dwtSReal(a, i, dn, sn) + dwtSReal(a, i + 1, dn, sn), 7233)); for (i = 0; i < sn; i++) - dwtSSetReal(a, i, dwtSReal(a, i) + fixMul(dwtDReal(a, i - 1, dn, sn) + dwtDReal(a, i, dn, sn), 3633)); + dwtSSetReal(a, i, + dwtSReal(a, i) + fixMul(dwtDReal(a, i - 1, dn, sn) + dwtDReal(a, i, dn, sn), 3633)); for (i = 0; i < dn; i++) dwtDSetReal(a, i, fixMul(dwtDReal(a, i), 5038)); /* 5038 */ for (i = 0; i < sn; i++) @@ -301,13 +319,17 @@ private void dwtEncode1Real(double[] a, int dn, int sn, int cas) { } else { if ((sn > 0) || (dn > 1)) { /* NEW : CASE ONE ELEMENT */ for (i = 0; i < dn; i++) - dwtSSetReal(a, i, dwtSReal(a, i) - fixMul(dwtDD1Real(a, i, dn, sn) + dwtDD1Real(a, i - 1, dn, sn), 12993)); + dwtSSetReal(a, i, + dwtSReal(a, i) - fixMul(dwtDD1Real(a, i, dn, sn) + dwtDD1Real(a, i - 1, dn, sn), 12993)); for (i = 0; i < sn; i++) - dwtDSetReal(a, i, dwtDReal(a, i) - fixMul(dwtSS1Real(a, i, dn, sn) + dwtSS1Real(a, i + 1, dn, sn), 434)); + dwtDSetReal(a, i, + dwtDReal(a, i) - fixMul(dwtSS1Real(a, i, dn, sn) + dwtSS1Real(a, i + 1, dn, sn), 434)); for (i = 0; i < dn; i++) - dwtSSetReal(a, i, dwtSReal(a, i) + fixMul(dwtDD1Real(a, i, dn, sn) + dwtDD1Real(a, i - 1, dn, sn), 7233)); + dwtSSetReal(a, i, + dwtSReal(a, i) + fixMul(dwtDD1Real(a, i, dn, sn) + dwtDD1Real(a, i - 1, dn, sn), 7233)); for (i = 0; i < sn; i++) - dwtDSetReal(a, i, dwtDReal(a, i) + fixMul(dwtSS1Real(a, i, dn, sn) + dwtSS1Real(a, i + 1, dn, sn), 3633)); + dwtDSetReal(a, i, + dwtDReal(a, i) + fixMul(dwtSS1Real(a, i, dn, sn) + dwtSS1Real(a, i + 1, dn, sn), 3633)); for (i = 0; i < dn; i++) dwtSSetReal(a, i, fixMul(dwtSReal(a, i), 5038)); /* 5038 */ for (i = 0; i < sn; i++) @@ -316,10 +338,11 @@ private void dwtEncode1Real(double[] a, int dn, int sn, int cas) { } } + @SuppressWarnings({ "java:S1659" }) private void dwtEncodeStepSize(int stepSize, int noOfBps, StepSize bandNoStepSize) { int p, n; - p = MathUtil.intFloorLog2(stepSize) - 13; - n = 11 - MathUtil.intFloorLog2(stepSize); + p = MathUtil.getInstance().intFloorLog2(stepSize) - 13; + n = 11 - MathUtil.getInstance().intFloorLog2(stepSize); bandNoStepSize.setMant((n < 0 ? stepSize >> -n : stepSize << n) & 0x7ff); bandNoStepSize.setExpn(noOfBps - p); } @@ -327,6 +350,7 @@ private void dwtEncodeStepSize(int stepSize, int noOfBps, StepSize bandNoStepSiz /* */ /* Forward 5-3 wavelet transform in 2-dimension. */ /* */ + @SuppressWarnings({ "java:S1659" }) public void dwtEncode(TcdTileComponent tilec) { int i, j, k; int aIndex = 0; @@ -344,13 +368,13 @@ public void dwtEncode(TcdTileComponent tilec) { int rw1; /* width of the resolution level once lower than computed one */ int rh1; /* height of the resolution level once lower than computed one */ int casCol; /* - * 0 = non inversion on horizontal filtering 1 = inversion between low-pass and - * high-pass filtering - */ + * 0 = non inversion on horizontal filtering 1 = inversion between low-pass and + * high-pass filtering + */ int casRow; /* - * 0 = non inversion on vertical filtering 1 = inversion between low-pass and - * high-pass filtering - */ + * 0 = non inversion on vertical filtering 1 = inversion between low-pass and + * high-pass filtering + */ int dn, sn; rw = tilec.getResolutions()[l - i].getX1() - tilec.getResolutions()[l - i].getX0(); @@ -371,7 +395,6 @@ public void dwtEncode(TcdTileComponent tilec) { dwtEncode1(bj, dn, sn, casCol); dwtDeInterLeaveVertical(bj, tilec.getIData(), ajIndex, dn, sn, w, casCol); } - bj = null; sn = rw1; dn = rw - rw1; @@ -383,13 +406,13 @@ public void dwtEncode(TcdTileComponent tilec) { dwtEncode1(bj, dn, sn, casRow); dwtInterLeaveHorizontal(bj, tilec.getIData(), ajIndex, dn, sn, casRow); } - bj = null; } } /* */ /* Inverse 5-3 wavelet transform in 2-dimension. */ /* */ + @SuppressWarnings({ "java:S1192" }) public void dwtDecode(TcdTileComponent tilec, int numres) { dwtDecodeTile(tilec, numres, "dwtDecode1"); } @@ -416,6 +439,7 @@ public double dwtGetNorm(int level, int orient) { /* Forward 9-7 wavelet transform in 2-dimension. */ /* */ + @SuppressWarnings({ "java:S1659", "java:S3776" }) public void dwtEncodeReal(TcdTileComponent tilec) { int i, j, k; int aIndex = 0; @@ -433,13 +457,13 @@ public void dwtEncodeReal(TcdTileComponent tilec) { int rw1; /* width of the resolution level once lower than computed one */ int rh1; /* height of the resolution level once lower than computed one */ int casCol; /* - * 0 = non inversion on horizontal filtering 1 = inversion between low-pass and - * high-pass filtering - */ + * 0 = non inversion on horizontal filtering 1 = inversion between low-pass and + * high-pass filtering + */ int casRow; /* - * 0 = non inversion on vertical filtering 1 = inversion between low-pass and - * high-pass filtering - */ + * 0 = non inversion on vertical filtering 1 = inversion between low-pass and + * high-pass filtering + */ int dn, sn; rw = tilec.getResolutions()[l - i].getX1() - tilec.getResolutions()[l - i].getX0(); @@ -460,7 +484,6 @@ public void dwtEncodeReal(TcdTileComponent tilec) { dwtEncode1Real(bj, dn, sn, casCol); dwtDeInterLeaveRealVertical(bj, tilec.getFData(), ajIndex, dn, sn, w, casCol); } - bj = null; sn = rw1; dn = rw - rw1; @@ -472,13 +495,13 @@ public void dwtEncodeReal(TcdTileComponent tilec) { dwtEncode1Real(bj, dn, sn, casRow); dwtInterLeaveRealHorizontal(bj, tilec.getFData(), ajIndex, dn, sn, casRow); } - bj = null; } } /* */ /* Get gain of 9-7 wavelet transform. */ /* */ + @SuppressWarnings({ "java:S1172" }) public int dwtGetGainReal(int orient) { return 0; } @@ -490,8 +513,10 @@ public double dwtGetNormReal(int level, int orient) { return OpenJpegConstant.DWT_NORMS_REAL[orient][level]; } + @SuppressWarnings({ "java:S1659", "java:S3358", "java:S3776" }) public void dwtCalcExplicitStepSizes(TileComponentCodingParameters tccp, int prec) { - int noOfBands, bandNo; + int noOfBands; + int bandNo; noOfBands = 3 * tccp.getNoOfResolutions() - 2; for (bandNo = 0; bandNo < noOfBands; bandNo++) { double stepsize; @@ -547,7 +572,6 @@ private void dwtDecodeTile(TcdTileComponent tilec, int numres, String dwtDecode1 v.setMem(h.getMem()); while (--numres != 0) { - // int * restrict tiledp = tilec->data; int j; ++trIndex; @@ -584,8 +608,9 @@ private void dwtDecodeTile(TcdTileComponent tilec, int numres, String dwtDecode1 h.setMem(null); } + @SuppressWarnings({ "java:S135", "java:S1659", "java:S3776" }) private void dwtV4InterLeaveHorizontal(DwtV4 w, double[] a, int aIndex, int x, int size) { - int waveIndex = w.getCas(); + int waveIndex = w.getCas(); int count = w.getSn(); int i, k; for (k = 0; k < 2; ++k) { @@ -613,7 +638,7 @@ private void dwtV4InterLeaveHorizontal(DwtV4 w, double[] a, int aIndex, int x, i } private void dwtV4InterLeaveVertical(DwtV4 w, double[] a, int aIndex, int x) { - int biIndex = w.getCas(); + int biIndex = w.getCas(); int i; for (i = 0; i < w.getSn(); ++i) { w.getWavelet()[biIndex + i * 2].getF()[0] = a[aIndex + (i * x) + 0]; @@ -649,22 +674,22 @@ private void dwtV4DecodeStep1(V4[] w, int wIndex, int count, final double c) { private void dwtV4DecodeStep2(V4[] l, int flIndex, V4[] w, int fwIndex, int k, int m, double c) { int i; for (i = 0; i < m; ++i) { - double tmp1_1 = l[flIndex].getF()[0]; - double tmp1_2 = l[flIndex].getF()[1]; - double tmp1_3 = l[flIndex].getF()[2]; - double tmp1_4 = l[flIndex].getF()[3]; - double tmp2_1 = w[fwIndex - 1].getF()[0]; - double tmp2_2 = w[fwIndex - 1].getF()[1]; - double tmp2_3 = w[fwIndex - 1].getF()[2]; - double tmp2_4 = w[fwIndex - 1].getF()[3]; - double tmp3_1 = w[fwIndex].getF()[0]; - double tmp3_2 = w[fwIndex].getF()[1]; - double tmp3_3 = w[fwIndex].getF()[2]; - double tmp3_4 = w[fwIndex].getF()[3]; - w[fwIndex - 1].getF()[0] = tmp2_1 + ((tmp1_1 + tmp3_1) * c); - w[fwIndex - 1].getF()[1] = tmp2_2 + ((tmp1_2 + tmp3_2) * c); - w[fwIndex - 1].getF()[2] = tmp2_3 + ((tmp1_3 + tmp3_3) * c); - w[fwIndex - 1].getF()[3] = tmp2_4 + ((tmp1_4 + tmp3_4) * c); + double tmp1One = l[flIndex].getF()[0]; + double tmp1Two = l[flIndex].getF()[1]; + double tmp1Three = l[flIndex].getF()[2]; + double tmp1Four = l[flIndex].getF()[3]; + double tmp2One = w[fwIndex - 1].getF()[0]; + double tmp2Two = w[fwIndex - 1].getF()[1]; + double tmp2Three = w[fwIndex - 1].getF()[2]; + double tmp2Four = w[fwIndex - 1].getF()[3]; + double tmp3One = w[fwIndex].getF()[0]; + double tmp3Two = w[fwIndex].getF()[1]; + double tmp3Three = w[fwIndex].getF()[2]; + double tmp3Four = w[fwIndex].getF()[3]; + w[fwIndex - 1].getF()[0] = tmp2One + ((tmp1One + tmp3One) * c); + w[fwIndex - 1].getF()[1] = tmp2Two + ((tmp1Two + tmp3Two) * c); + w[fwIndex - 1].getF()[2] = tmp2Three + ((tmp1Three + tmp3Three) * c); + w[fwIndex - 1].getF()[3] = tmp2Four + ((tmp1Four + tmp3Four) * c); flIndex = fwIndex; fwIndex += 2; } @@ -692,7 +717,8 @@ private void dwtV4DecodeStep2(V4[] l, int flIndex, V4[] w, int fwIndex, int k, i /* Inverse 9-7 wavelet transform in 1-dimension. */ /* */ private void dwtV4Decode(DwtV4 dwt) { - int a, b; + int a; + int b; if (dwt.getCas() == 0) { if (!((dwt.getDn() > 0) || (dwt.getSn() > 1))) { return; @@ -709,18 +735,19 @@ private void dwtV4Decode(DwtV4 dwt) { dwtV4DecodeStep1(dwt.getWavelet(), a, dwt.getSn(), OpenJpegConstant.K); dwtV4DecodeStep1(dwt.getWavelet(), b, dwt.getDn(), OpenJpegConstant.C13318); dwtV4DecodeStep2(dwt.getWavelet(), b, dwt.getWavelet(), a + 1, dwt.getSn(), - MathUtil.intMin(dwt.getSn(), dwt.getDn() - a), OpenJpegConstant.DWT_DELTA); + MathUtil.getInstance().intMin(dwt.getSn(), dwt.getDn() - a), OpenJpegConstant.DWT_DELTA); dwtV4DecodeStep2(dwt.getWavelet(), a, dwt.getWavelet(), b + 1, dwt.getDn(), - MathUtil.intMin(dwt.getDn(), dwt.getSn() - b), OpenJpegConstant.DWT_GAMMA); + MathUtil.getInstance().intMin(dwt.getDn(), dwt.getSn() - b), OpenJpegConstant.DWT_GAMMA); dwtV4DecodeStep2(dwt.getWavelet(), b, dwt.getWavelet(), a + 1, dwt.getSn(), - MathUtil.intMin(dwt.getSn(), dwt.getDn() - a), OpenJpegConstant.DWT_BETA); + MathUtil.getInstance().intMin(dwt.getSn(), dwt.getDn() - a), OpenJpegConstant.DWT_BETA); dwtV4DecodeStep2(dwt.getWavelet(), a, dwt.getWavelet(), b + 1, dwt.getDn(), - MathUtil.intMin(dwt.getDn(), dwt.getSn() - b), OpenJpegConstant.DWT_ALPHA); + MathUtil.getInstance().intMin(dwt.getDn(), dwt.getSn() - b), OpenJpegConstant.DWT_ALPHA); } /* */ /* Inverse 9-7 wavelet transform in 2-dimension. */ /* */ + @SuppressWarnings({ "java:S3776", "java:S3923" }) public void dwtDecodeReal(TcdTileComponent tilec, int numres) { DwtV4 h = new DwtV4(); /* DwtV4 horizontal */ DwtV4 v = new DwtV4(); /* DwtV4 vertical */ @@ -728,8 +755,10 @@ public void dwtDecodeReal(TcdTileComponent tilec, int numres) { int resIndex = 0; TcdResolution[] arrResolution = tilec.getResolutions(); - int rw = arrResolution[resIndex].getX1() - arrResolution[resIndex].getX0(); /* width of the resolution level computed */ - int rh = arrResolution[resIndex].getY1() - arrResolution[resIndex].getY0(); /* height of the resolution level computed */ + int rw = arrResolution[resIndex].getX1() + - arrResolution[resIndex].getX0(); /* width of the resolution level computed */ + int rh = arrResolution[resIndex].getY1() + - arrResolution[resIndex].getY0(); /* height of the resolution level computed */ int w = tilec.getX1() - tilec.getX0(); // width @@ -740,7 +769,6 @@ public void dwtDecodeReal(TcdTileComponent tilec, int numres) { v.setWavelet(h.getWavelet()); while (--numres != 0) { - // float * restrict aj = (float*) tilec->data; int ajIndex = 0; int bufsize = (tilec.getX1() - tilec.getX0()) * (tilec.getY1() - tilec.getY0()); int j; @@ -750,8 +778,10 @@ public void dwtDecodeReal(TcdTileComponent tilec, int numres) { h.setSn(rw); v.setSn(rh); - rw = arrResolution[resIndex].getX1() - arrResolution[resIndex].getX0(); /* width of the resolution level computed */ - rh = arrResolution[resIndex].getY1() - arrResolution[resIndex].getY0(); /* height of the resolution level computed */ + rw = arrResolution[resIndex].getX1() + - arrResolution[resIndex].getX0(); /* width of the resolution level computed */ + rh = arrResolution[resIndex].getY1() + - arrResolution[resIndex].getY0(); /* height of the resolution level computed */ h.setDn(rw - h.getSn()); h.setCas(arrResolution[resIndex].getX0() % 2); @@ -773,10 +803,19 @@ public void dwtDecodeReal(TcdTileComponent tilec, int numres) { switch (j) { case 3: tilec.getFData()[ajIndex + k + w * 2] = h.getWavelet()[k].getF()[2]; + tilec.getFData()[ajIndex + k + w * 1] = h.getWavelet()[k].getF()[1]; + tilec.getFData()[ajIndex + k + w * 0] = h.getWavelet()[k].getF()[0]; + break; case 2: tilec.getFData()[ajIndex + k + w * 1] = h.getWavelet()[k].getF()[1]; + tilec.getFData()[ajIndex + k + w * 0] = h.getWavelet()[k].getF()[0]; + break; case 1: tilec.getFData()[ajIndex + k + w * 0] = h.getWavelet()[k].getF()[0]; + break; + default: + throw new DecoderException(DecoderErrorCodes.UNSUPPORTED_FORMAT_ERROR.getErrorCode(), + DecoderErrorCodes.UNSUPPORTED_FORMAT_ERROR.getErrorMessage()); } } } @@ -822,8 +861,9 @@ public void dwtDecodeReal(TcdTileComponent tilec, int numres) { * @param b * @return Returns a * b */ + @SuppressWarnings("unused") private int fixMul(int a, int b) { - long temp = a * b; + long temp = (a * b); temp += temp & 4096; return (int) (temp >> 13); } @@ -833,4 +873,4 @@ private int fixMul(double a, double b) { temp += temp & 4096; return (int) (temp >> 13); } -} +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/ImageHelper.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/ImageHelper.java index 5e4c6c1..27533e3 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/ImageHelper.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/ImageHelper.java @@ -7,36 +7,34 @@ public class ImageHelper { // Static variable reference of singleInstance of type Singleton - private static ImageHelper singleInstance = null; - private ImageHelper() - { - super (); - } - - //synchronized method to control simultaneous access - public static synchronized ImageHelper getInstance() - { + private static ImageHelper singleInstance = null; + + private ImageHelper() { + super(); + } + + // synchronized method to control simultaneous access + public static synchronized ImageHelper getInstance() { if (singleInstance == null) singleInstance = new ImageHelper(); - - return singleInstance; + + return singleInstance; } - + public OpenJpegImage imageCreateBasic() { - OpenJpegImage image = new OpenJpegImage(); - return image; + return new OpenJpegImage(); } public OpenJpegImage imageCreate(int numcmpts, OpenJpegImageComponentParameters[] cmptparms, Jp2ColorSpace clrspc) { int compno; OpenJpegImage image = imageCreateBasic(); - if(image != null) { + if (image != null) { image.setColorSpace(clrspc); image.setNoOfComps(numcmpts); /* allocate memory for the per-component information */ image.setComps(new OpenJpegImageComponent[image.getNoOfComps()]); /* create the individual image components */ - for(compno = 0; compno < numcmpts; compno++) { + for (compno = 0; compno < numcmpts; compno++) { image.getComps()[compno] = new OpenJpegImageComponent(); OpenJpegImageComponent comp = image.getComps()[compno]; comp.setDX(cmptparms[compno].getDx()); @@ -48,7 +46,7 @@ public OpenJpegImage imageCreate(int numcmpts, OpenJpegImageComponentParameters[ comp.setPrec(cmptparms[compno].getPrec()); comp.setBpp(cmptparms[compno].getBpp()); comp.setSgnd(cmptparms[compno].getSgnd()); - comp.setData (new int[comp.getWidth() * comp.getHeight()]); + comp.setData(new int[comp.getWidth() * comp.getHeight()]); } } @@ -57,18 +55,15 @@ public OpenJpegImage imageCreate(int numcmpts, OpenJpegImageComponentParameters[ public void imageDestroy(OpenJpegImage image) { int i; - if(image != null) { - if(image.getComps() != null && image.getComps().length > 0) { - /* image components */ - for(i = 0; i < image.getNoOfComps(); i++) { - OpenJpegImageComponent imageComp = image.getComps()[i]; - if(imageComp.getData() != null && imageComp.getData().length > 0) { - imageComp.setData(null); - } + if (image != null && (image.getComps() != null && image.getComps().length > 0)) { + /* image components */ + for (i = 0; i < image.getNoOfComps(); i++) { + OpenJpegImageComponent imageComp = image.getComps()[i]; + if (imageComp.getData() != null && imageComp.getData().length > 0) { + imageComp.setData(null); } - image.setComps(null); } - image = null; + image.setComps(null); } } } diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/J2KHelper.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/J2KHelper.java index 065a393..a670c89 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/J2KHelper.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/J2KHelper.java @@ -1,7 +1,13 @@ package io.mosip.imagedecoder.openjpeg; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_EMPTY; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_IDTYPE; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_SESSIONID; + +import java.text.MessageFormat; + +import io.mosip.kernel.core.logger.spi.Logger; +import io.mosip.imagedecoder.logger.ImageDecoderLogger; import io.mosip.imagedecoder.constant.openjpeg.OpenJpegConstant; import io.mosip.imagedecoder.model.openjpeg.Cio; @@ -33,9 +39,10 @@ import io.mosip.imagedecoder.util.openjpeg.MathUtil; public class J2KHelper { - private Logger LOGGER = LoggerFactory.getLogger(J2KHelper.class); + private Logger logger = ImageDecoderLogger.getLogger(J2KHelper.class); + private static final String TAG_JPWL_GIVING_UP = "JPWL: giving up"; - private DecoderFunctionInfo J2K_DECODER_FUNCTION_INFO [] = { + private static final DecoderFunctionInfo[] J2K_DECODER_FUNCTION_INFO = { new DecoderFunctionInfo(OpenJpegConstant.J2K_MS_SOC, J2kStatus.J2K_STATE_MHSOC.value(), "j2kReadSoc"), new DecoderFunctionInfo(OpenJpegConstant.J2K_MS_SOT, J2kStatus.J2K_STATE_MH.value() | J2kStatus.J2K_STATE_TPHSOT.value(), "j2kReadSot"), @@ -78,22 +85,28 @@ public class J2KHelper { new DecoderFunctionInfo(0, J2kStatus.J2K_STATE_MH.value() | J2kStatus.J2K_STATE_TPH.value(), "j2kReadUnknown") }; + public J2KHelper() { + super(); + } + private char[] j2kGetProgressionOrderCode(ProgressionOrder progressionOrder) { J2KProgressionOrder order = null; for (int po = 0; po < OpenJpegConstant.J2KPROGRESSION_ORDER_INFO.length; po++) { order = OpenJpegConstant.J2KPROGRESSION_ORDER_INFO[po]; if (order.getProgressionOrder() == progressionOrder) { - break; } } - return order.getProgressionName(); + if (order != null) + return order.getProgressionName(); + return new char[] {}; } private int j2kGetNoOfTilePart(CodingParameters codingParameters, int piNo, int tileNo) { char[] prog; int i; - int tilePartNo = 1, tilePartEnd = 0; + int tilePartNo = 1; + int tilePartEnd = 0; Tcp tcp = codingParameters.getTcps()[tileNo]; prog = j2kGetProgressionOrderCode(tcp.getProgressionOrder()); @@ -117,6 +130,8 @@ private int j2kGetNoOfTilePart(CodingParameters codingParameters, int piNo, int case 'L': tilePartNo = tilePartNo * tcp.getPocs()[piNo].getLayE(); break; + default: + break; } } } @@ -127,16 +142,19 @@ private int j2kGetNoOfTilePart(CodingParameters codingParameters, int piNo, int } /** mem allocation for TLM marker */ - private int j2kCalculateTilePart(CodingParameters codingParameters, int imageNoOfComp, OpenJpegImage image, J2K j2k) { + @SuppressWarnings({ "java:S1659", "unused" }) + private int j2kCalculateTilePart(CodingParameters codingParameters, int imageNoOfComp, OpenJpegImage image, + J2K j2kInfo) { int piNo, tileNo, totalNoOfTilePart = 0; - j2k.setCurTotalNoOfTilePart(new int[codingParameters.getTileWidth() * codingParameters.getTileHeight()]); + j2kInfo.setCurTotalNoOfTilePart(new int[codingParameters.getTileWidth() * codingParameters.getTileHeight()]); for (tileNo = 0; tileNo < codingParameters.getTileWidth() * codingParameters.getTileHeight(); tileNo++) { int curTotalNoOfTilePart = 0; Tcp tcp = codingParameters.getTcps()[tileNo]; for (piNo = 0; piNo <= tcp.getNoOfPocs(); piNo++) { int tilePartNo = 0; - PiIterator[] arrPI = PiHelper.getInstance().piInitEncode(image, codingParameters, tileNo, J2KT2Mode.FINAL_PASS); + PiIterator[] arrPI = PiHelper.getInstance().piInitEncode(image, codingParameters, tileNo, + J2KT2Mode.FINAL_PASS); if (arrPI == null) { return -1; } @@ -145,50 +163,52 @@ private int j2kCalculateTilePart(CodingParameters codingParameters, int imageNoO curTotalNoOfTilePart = curTotalNoOfTilePart + tilePartNo; PiHelper.getInstance().piDestroy(arrPI, codingParameters, tileNo); } - j2k.getCurTotalNoOfTilePart()[tileNo] = curTotalNoOfTilePart; + j2kInfo.getCurTotalNoOfTilePart()[tileNo] = curTotalNoOfTilePart; /* INDEX >> */ - if (j2k.getCodeStreamInfo() != null) { - j2k.getCodeStreamInfo().getTileInfo()[tileNo].setNoOfTileParts(curTotalNoOfTilePart); - j2k.getCodeStreamInfo().getTileInfo()[tileNo].setTp(new TpInfo[curTotalNoOfTilePart]); + if (j2kInfo.getCodeStreamInfo() != null) { + j2kInfo.getCodeStreamInfo().getTileInfo()[tileNo].setNoOfTileParts(curTotalNoOfTilePart); + j2kInfo.getCodeStreamInfo().getTileInfo()[tileNo].setTp(new TpInfo[curTotalNoOfTilePart]); } /* << INDEX */ } return totalNoOfTilePart; } - public void j2kWriteSoc(J2K j2k, boolean USE_JPWL) { - Cio cio = j2k.getCio(); + public void j2kWriteSoc(J2K j2kInfo, boolean useJPWL) { + Cio cio = j2kInfo.getCio(); CioHelper.getInstance().cioWrite(cio, OpenJpegConstant.J2K_MS_SOC, 2); /* UniPG>> */ - if (USE_JPWL) { + if (useJPWL) { /* update markers struct */ - j2kAddMarker(j2k.getCodeStreamInfo(), OpenJpegConstant.J2K_MS_SOC, (int) CioHelper.getInstance().cioTell(cio) - 2, 2); + j2kAddMarker(j2kInfo.getCodeStreamInfo(), OpenJpegConstant.J2K_MS_SOC, + CioHelper.getInstance().cioTell(cio) - 2, 2); } /* < space in SIZ only for %d comps.!!!", - image.getNoOfComps(), ((length - 38) / 3))); - if (!OpenJpegConstant.JPWL_ASSUME) { - LOGGER.error(String.format("JPWL: giving up")); - return; - } - /* we try to correct */ - LOGGER.warn(String.format("trying to adjust this")); - if (image.getNoOfComps() < ((length - 38) / 3)) { - length = 38 + 3 * image.getNoOfComps(); - LOGGER.warn(String.format("setting Lsiz to %d => HYPOTHESIS!!!", length)); - } else { - image.setNoOfComps(((length - 38) / 3)); - LOGGER.warn(String.format("setting Csiz to %d => HYPOTHESIS!!!", image.getNoOfComps())); - } + } + if (image.getNoOfComps() != ((length - 38) / 3)) { + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE,LOGGER_EMPTY, MessageFormat.format("JPWL: Csiz is {0} => space in SIZ only for {1} comps.!!!", image.getNoOfComps(), + ((length - 38) / 3))); + if (!OpenJpegConstant.JPWL_ASSUME) { + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, TAG_JPWL_GIVING_UP); + return; + } + /* we try to correct */ + logger.warn(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "trying to adjust this"); + if (image.getNoOfComps() < ((length - 38) / 3)) { + length = 38 + 3 * image.getNoOfComps(); + logger.warn(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("setting Lsiz to {0} => HYPOTHESIS!!!", length)); + } else { + image.setNoOfComps(((length - 38) / 3)); + logger.warn(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("setting Csiz to {0} => HYPOTHESIS!!!", + image.getNoOfComps())); } - - /* update components number in the jpwlExpComps filed */ - codingParameters.setExpComps(image.getNoOfComps()); } + + /* update components number in the jpwlExpComps filed */ + codingParameters.setExpComps(image.getNoOfComps()); } image.setComps(new OpenJpegImageComponent[image.getNoOfComps()]); @@ -287,84 +308,85 @@ private void j2kReadSize(J2K j2k, boolean USE_JPWL) { image.getComps()[i].setDX((int) CioHelper.getInstance().cioRead(cio, 1)); /* XRsiz_i */ image.getComps()[i].setDY((int) CioHelper.getInstance().cioRead(cio, 1)); /* YRsiz_i */ - if (USE_JPWL) { - if (j2k.getCodingParameters().getCorrect() != 0) { - /* - * if JPWL is on, we check whether TX errors have damaged too much the SIZ - * parameters, again - */ - if ((image.getComps()[i].getDX() * image.getComps()[i].getDY()) == 0) { - LOGGER.warn(String.format("JPWL: bad XRsiz_%d/YRsiz_%d (%d x %d)", i, i, - image.getComps()[i].getDX(), image.getComps()[i].getDY())); - - if (!OpenJpegConstant.JPWL_ASSUME) { - LOGGER.error(String.format("JPWL: giving up")); - return; - } - /* we try to correct */ - LOGGER.warn(String.format("trying to adjust them")); - if (image.getComps()[i].getDX() == 0) { - image.getComps()[i].setDX(1); - LOGGER.warn(String.format("trying to adjust them - setting XRsiz_%d to %d => HYPOTHESIS!!!", - i, image.getComps()[i].getDX())); - } - if (image.getComps()[i].getDY() == 0) { - image.getComps()[i].setDY(1); - LOGGER.warn(String.format("trying to adjust them - setting YRsiz_%d to %d => HYPOTHESIS!!!", - i, image.getComps()[i].getDY())); - } - } + /* + * if JPWL is on, we check whether TX errors have damaged too much the SIZ + * parameters, again + */ + if (useJPWL && j2kInfo.getCodingParameters().getCorrect() != 0 + && ((image.getComps()[i].getDX() * image.getComps()[i].getDY()) == 0)) { + logger.warn(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("JPWL: bad XRsiz_{0}/YRsiz_{1} {2} x {3}", i, i, + image.getComps()[i].getDX(), image.getComps()[i].getDY())); + + if (!OpenJpegConstant.JPWL_ASSUME) { + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, TAG_JPWL_GIVING_UP); + return; + } + /* we try to correct */ + logger.warn(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "trying to adjust them"); + if (image.getComps()[i].getDX() == 0) { + image.getComps()[i].setDX(1); + logger.warn(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format( + "trying to adjust them - setting XRsiz_{0} to {1} => HYPOTHESIS!!!", i, + image.getComps()[i].getDX())); + } + if (image.getComps()[i].getDY() == 0) { + image.getComps()[i].setDY(1); + logger.warn(LOGGER_SESSIONID, LOGGER_IDTYPE,LOGGER_EMPTY, MessageFormat.format( + "trying to adjust them - setting YRsiz_{0} to {1} => HYPOTHESIS!!!", i, + image.getComps()[i].getDY())); } } - /* TODO: unused ? */ - width = MathUtil.intCeilDiv(image.getX1() - image.getX0(), image.getComps()[i].getDX()); - height = MathUtil.intCeilDiv(image.getY1() - image.getY0(), image.getComps()[i].getDY()); + width = MathUtil.getInstance().intCeilDiv(image.getX1() - image.getX0(), image.getComps()[i].getDX()); + height = MathUtil.getInstance().intCeilDiv(image.getY1() - image.getY0(), image.getComps()[i].getDY()); image.getComps()[i].setResNoDecoded(0); /* number of resolution decoded */ image.getComps()[i].setFactor(codingParameters.getReduce()); /* reducing factor per component */ } - codingParameters.setTileWidth(MathUtil.intCeilDiv(image.getX1() - codingParameters.getTileX0(), codingParameters.getTileDX())); - codingParameters.setTileHeight(MathUtil.intCeilDiv(image.getY1() - codingParameters.getTileY0(), codingParameters.getTileDY())); + codingParameters.setTileWidth(MathUtil.getInstance().intCeilDiv(image.getX1() - codingParameters.getTileX0(), + codingParameters.getTileDX())); + codingParameters.setTileHeight(MathUtil.getInstance().intCeilDiv(image.getY1() - codingParameters.getTileY0(), + codingParameters.getTileDY())); - if (USE_JPWL) { - if (j2k.getCodingParameters().getCorrect() != 0) { - /* - * if JPWL is on, we check whether TX errors have damaged too much the SIZ - * parameters - */ - if ((codingParameters.getTileWidth() < 1) || (codingParameters.getTileHeight() < 1) || (codingParameters.getTileWidth() > codingParameters.getMaxTiles()) - || (codingParameters.getTileHeight() > codingParameters.getMaxTiles())) { - LOGGER.error(String.format("JPWL: bad number of tiles (%d x %d)", codingParameters.getTileWidth(), codingParameters.getTileHeight())); - if (!OpenJpegConstant.JPWL_ASSUME) { - LOGGER.error(String.format("JPWL: giving up")); - return; - } - /* we try to correct */ - if (codingParameters.getTileWidth() < 1) { - codingParameters.setTileWidth(1); - LOGGER.warn(String.format("trying to adjust them - setting %d tiles in x => HYPOTHESIS!!!", - codingParameters.getTileWidth())); - } - if (codingParameters.getTileWidth() > codingParameters.getMaxTiles()) { - codingParameters.setTileWidth(1); - LOGGER.warn(String.format( - "trying to adjust them - too large x, increase expectance of %d - setting %d tiles in x => HYPOTHESIS!!!", - codingParameters.getMaxTiles(), codingParameters.getTileWidth())); - } - if (codingParameters.getTileHeight() < 1) { - codingParameters.setTileHeight(1); - LOGGER.warn(String.format("trying to adjust them - setting %d tiles in y => HYPOTHESIS!!!", - codingParameters.getTileHeight())); - } - if (codingParameters.getTileHeight() > codingParameters.getMaxTiles()) { - codingParameters.setTileHeight(1); - LOGGER.warn(String.format( - "trying to adjust them - too large y, increase expectance of %d to continue - setting %d tiles in y => HYPOTHESIS!!!", - codingParameters.getMaxTiles(), codingParameters.getTileHeight())); - } - } + /* + * if JPWL is on, we check whether TX errors have damaged too much the SIZ + * parameters + */ + if (useJPWL && j2kInfo.getCodingParameters().getCorrect() != 0 + && ((codingParameters.getTileWidth() < 1) || (codingParameters.getTileHeight() < 1) + || (codingParameters.getTileWidth() > codingParameters.getMaxTiles()) + || (codingParameters.getTileHeight() > codingParameters.getMaxTiles()))) { + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("JPWL: bad number of tiles {0} x {1}", + codingParameters.getTileWidth(), codingParameters.getTileHeight())); + if (!OpenJpegConstant.JPWL_ASSUME) { + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, TAG_JPWL_GIVING_UP); + return; + } + /* we try to correct */ + if (codingParameters.getTileWidth() < 1) { + codingParameters.setTileWidth(1); + logger.warn(LOGGER_SESSIONID, LOGGER_IDTYPE,LOGGER_EMPTY, MessageFormat.format( + "trying to adjust them - setting {0} tiles in x => HYPOTHESIS!!!", + codingParameters.getTileWidth())); + } + if (codingParameters.getTileWidth() > codingParameters.getMaxTiles()) { + codingParameters.setTileWidth(1); + logger.warn(LOGGER_SESSIONID, LOGGER_IDTYPE,LOGGER_EMPTY, MessageFormat.format( + "trying to adjust them - too large x, increase expectance of {0} - setting {1} tiles in x => HYPOTHESIS!!!", + codingParameters.getMaxTiles(), codingParameters.getTileWidth())); + } + if (codingParameters.getTileHeight() < 1) { + codingParameters.setTileHeight(1); + logger.warn(LOGGER_SESSIONID, LOGGER_IDTYPE,LOGGER_EMPTY, MessageFormat.format( + "trying to adjust them - setting {0} tiles in y => HYPOTHESIS!!!", + codingParameters.getTileHeight())); + } + if (codingParameters.getTileHeight() > codingParameters.getMaxTiles()) { + codingParameters.setTileHeight(1); + logger.warn(LOGGER_SESSIONID, LOGGER_IDTYPE,LOGGER_EMPTY, MessageFormat.format( + "trying to adjust them - too large y, increase expectance of {0} to continue - setting {1} tiles in y => HYPOTHESIS!!!", + codingParameters.getMaxTiles(), codingParameters.getTileHeight())); } } @@ -372,15 +394,12 @@ private void j2kReadSize(J2K j2k, boolean USE_JPWL) { codingParameters.setTileNo(new int[codingParameters.getTileWidth() * codingParameters.getTileHeight()]); codingParameters.setTileNoSize(0); - if (USE_JPWL) { - if (j2k.getCodingParameters().getCorrect() != 0) { - if (codingParameters.getTcps() == null || codingParameters.getTcps().length == 0) { - LOGGER.error(String.format("JPWL: could not alloc tcps field of codingParameters")); - if (!OpenJpegConstant.JPWL_ASSUME || OpenJpegConstant.JPWL_ASSUME) { - LOGGER.error(String.format("JPWL: giving up")); - return; - } - } + if (useJPWL && (j2kInfo.getCodingParameters().getCorrect() != 0 + && (codingParameters.getTcps() == null || codingParameters.getTcps().length == 0))) { + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "JPWL: could not alloc tcps field of codingParameters"); + if (!OpenJpegConstant.JPWL_ASSUME || OpenJpegConstant.JPWL_ASSUME) { + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, TAG_JPWL_GIVING_UP); + return; } } @@ -398,26 +417,24 @@ private void j2kReadSize(J2K j2k, boolean USE_JPWL) { codingParameters.setPpmPrevious(0); codingParameters.setPpmStore(0); - j2k.getDefaultTcp().setTccps(new TileComponentCodingParameters[image.getNoOfComps()]); - for (i = 0; i < image.getNoOfComps(); i++) - { - j2k.getDefaultTcp().getTccps()[i] = new TileComponentCodingParameters(); + j2kInfo.getDefaultTcp().setTccps(new TileComponentCodingParameters[image.getNoOfComps()]); + for (i = 0; i < image.getNoOfComps(); i++) { + j2kInfo.getDefaultTcp().getTccps()[i] = new TileComponentCodingParameters(); } - + for (i = 0; i < codingParameters.getTileWidth() * codingParameters.getTileHeight(); i++) { codingParameters.getTcps()[i].setTccps(new TileComponentCodingParameters[image.getNoOfComps()]); - for (int j = 0; j < image.getNoOfComps(); j++) - { + for (int j = 0; j < image.getNoOfComps(); j++) { codingParameters.getTcps()[i].getTccps()[j] = new TileComponentCodingParameters(); } } - j2k.setTileData(new byte[codingParameters.getTileWidth() * codingParameters.getTileHeight()][]); - j2k.setTileLength(new int[codingParameters.getTileWidth() * codingParameters.getTileHeight()]); - j2k.setState(J2kStatus.J2K_STATE_MH.value()); + j2kInfo.setTileData(new byte[codingParameters.getTileWidth() * codingParameters.getTileHeight()][]); + j2kInfo.setTileLength(new int[codingParameters.getTileWidth() * codingParameters.getTileHeight()]); + j2kInfo.setState(J2kStatus.J2K_STATE_MH.value()); /* Index */ - if (j2k.getCodeStreamInfo() != null) { - CodeStreamInfo codeStreamInfo = j2k.getCodeStreamInfo(); + if (j2kInfo.getCodeStreamInfo() != null) { + CodeStreamInfo codeStreamInfo = j2kInfo.getCodeStreamInfo(); codeStreamInfo.setImageWidth(image.getX1() - image.getX0()); codeStreamInfo.setImageHeight(image.getY1() - image.getY0()); codeStreamInfo.setNoOfComps(image.getNoOfComps()); @@ -427,17 +444,19 @@ private void j2kReadSize(J2K j2k, boolean USE_JPWL) { codeStreamInfo.setTileY(codingParameters.getTileDY()); codeStreamInfo.setTileOX(codingParameters.getTileX0()); codeStreamInfo.setTileOY(codingParameters.getTileY0()); - codeStreamInfo.setTileInfo(new TileInfo[codingParameters.getTileWidth() * codingParameters.getTileHeight()]); + codeStreamInfo + .setTileInfo(new TileInfo[codingParameters.getTileWidth() * codingParameters.getTileHeight()]); } } - private void j2kWriteCom(J2K j2k) { + private void j2kWriteCom(J2K j2kInfo) { int i; - int lengthPosition, length; + int lengthPosition; + int length; - if (j2k.getCodingParameters().getComment() != null) { - Cio cio = j2k.getCio(); - char[] comment = j2k.getCodingParameters().getComment(); + if (j2kInfo.getCodingParameters().getComment() != null) { + Cio cio = j2kInfo.getCio(); + char[] comment = j2kInfo.getCodingParameters().getComment(); CioHelper.getInstance().cioWrite(cio, OpenJpegConstant.J2K_MS_COM, 2); lengthPosition = CioHelper.getInstance().cioTell(cio); @@ -453,54 +472,56 @@ private void j2kWriteCom(J2K j2k) { } } - private void j2kReadCom(J2K j2k) { + private void j2kReadCom(J2K j2kInfo) { int length; - Cio cio = j2k.getCio(); + Cio cio = j2kInfo.getCio(); length = (int) CioHelper.getInstance().cioRead(cio, 2); CioHelper.getInstance().cioSkip(cio, length - 2); } - public void j2kWriteCox(J2K j2k, int compNo) { + public void j2kWriteCox(J2K j2kInfo, int compNo) { int i; - CodingParameters codingParameters = j2k.getCodingParameters(); - Tcp tcp = codingParameters.getTcps()[j2k.getCurTileNo()]; + CodingParameters codingParameters = j2kInfo.getCodingParameters(); + Tcp tcp = codingParameters.getTcps()[j2kInfo.getCurTileNo()]; TileComponentCodingParameters tccp = tcp.getTccps()[compNo]; - Cio cio = j2k.getCio(); + Cio cio = j2kInfo.getCio(); - CioHelper.getInstance().cioWrite(cio, tccp.getNoOfResolutions() - 1, 1); /* SPcox (D) */ - CioHelper.getInstance().cioWrite(cio, tccp.getCodeBlockWidth() - 2, 1); /* SPcox (E) */ - CioHelper.getInstance().cioWrite(cio, tccp.getCodeBlockHeight() - 2, 1); /* SPcox (F) */ + CioHelper.getInstance().cioWrite(cio, (long) tccp.getNoOfResolutions() - 1, 1); /* SPcox (D) */ + CioHelper.getInstance().cioWrite(cio, (long) tccp.getCodeBlockWidth() - 2, 1); /* SPcox (E) */ + CioHelper.getInstance().cioWrite(cio, (long) tccp.getCodeBlockHeight() - 2, 1); /* SPcox (F) */ CioHelper.getInstance().cioWrite(cio, tccp.getCodeBlockStyle(), 1); /* SPcox (G) */ CioHelper.getInstance().cioWrite(cio, tccp.getQmfbid(), 1); /* SPcox (H) */ if ((tccp.getCodingStyle() & OpenJpegConstant.J2K_CCP_CSTY_PRT) != 0) { for (i = 0; i < tccp.getNoOfResolutions(); i++) { - CioHelper.getInstance().cioWrite(cio, tccp.getPrecinctWidth()[i] + (tccp.getPrecinctHeight()[i] << 4), 1); /* SPcox (I_i) */ + CioHelper.getInstance().cioWrite(cio, + tccp.getPrecinctWidth()[i] + (long) (tccp.getPrecinctHeight()[i] << 4), 1); /* SPcox (I_i) */ } } } - private void j2kReadCox(J2K j2k, int compNo) { + private void j2kReadCox(J2K j2kInfo, int compNo) { int i; - CodingParameters codingParameters = j2k.getCodingParameters(); - Tcp tcp = j2k.getState() == J2kStatus.J2K_STATE_TPH.value() ? codingParameters.getTcps()[j2k.getCurTileNo()] - : j2k.getDefaultTcp(); + CodingParameters codingParameters = j2kInfo.getCodingParameters(); + Tcp tcp = j2kInfo.getState() == J2kStatus.J2K_STATE_TPH.value() + ? codingParameters.getTcps()[j2kInfo.getCurTileNo()] + : j2kInfo.getDefaultTcp(); TileComponentCodingParameters tccp = tcp.getTccps()[compNo]; - Cio cio = j2k.getCio(); + Cio cio = j2kInfo.getCio(); tccp.setNoOfResolutions((int) (CioHelper.getInstance().cioRead(cio, 1) + 1)); /* SPcox (D) */ // If user wants to remove more resolutions than the codestream contains, return // error if (codingParameters.getReduce() >= tccp.getNoOfResolutions()) { - LOGGER.error(String.format( - "Error decoding component %d. The number of resolutions to remove is higher than the number of resolutions of this component Modify the cp_reduce parameter", + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE,LOGGER_EMPTY, MessageFormat.format( + "Error decoding component {0}. The number of resolutions to remove is higher than the number of resolutions of this component Modify the cp_reduce parameter", compNo)); - j2k.setState(j2k.getState() | J2kStatus.J2K_STATE_ERR.value()); + j2kInfo.setState(j2kInfo.getState() | J2kStatus.J2K_STATE_ERR.value()); } tccp.setCodeBlockWidth((int) (CioHelper.getInstance().cioRead(cio, 1) + 2)); /* SPcox (E) */ @@ -516,79 +537,85 @@ private void j2kReadCox(J2K j2k, int compNo) { } /* INDEX >> */ - if (j2k.getCodeStreamInfo() != null && compNo == 0) { + if (j2kInfo.getCodeStreamInfo() != null && compNo == 0) { for (i = 0; i < tccp.getNoOfResolutions(); i++) { if ((tccp.getCodingStyle() & OpenJpegConstant.J2K_CP_CSTY_PRT) != 0) { - j2k.getCodeStreamInfo().getTileInfo()[j2k.getCurTileNo()].getPDX()[i] = tccp.getPrecinctWidth()[i]; - j2k.getCodeStreamInfo().getTileInfo()[j2k.getCurTileNo()].getPDY()[i] = tccp.getPrecinctHeight()[i]; + j2kInfo.getCodeStreamInfo().getTileInfo()[j2kInfo.getCurTileNo()].getPDX()[i] = tccp + .getPrecinctWidth()[i]; + j2kInfo.getCodeStreamInfo().getTileInfo()[j2kInfo.getCurTileNo()].getPDY()[i] = tccp + .getPrecinctHeight()[i]; } else { - j2k.getCodeStreamInfo().getTileInfo()[j2k.getCurTileNo()].getPDX()[i] = 15; - j2k.getCodeStreamInfo().getTileInfo()[j2k.getCurTileNo()].getPDY()[i] = 15; + j2kInfo.getCodeStreamInfo().getTileInfo()[j2kInfo.getCurTileNo()].getPDX()[i] = 15; + j2kInfo.getCodeStreamInfo().getTileInfo()[j2kInfo.getCurTileNo()].getPDY()[i] = 15; } } } /* << INDEX */ } - private void j2kWriteCod(J2K j2k) { + @SuppressWarnings({ "java:S1659", "java:S1854" }) + private void j2kWriteCod(J2K j2kInfo) { CodingParameters codingParameters = null; Tcp tcp = null; int lengthPosition, length; - Cio cio = j2k.getCio(); + Cio cio = j2kInfo.getCio(); CioHelper.getInstance().cioWrite(cio, OpenJpegConstant.J2K_MS_COD, 2); /* COD */ lengthPosition = CioHelper.getInstance().cioTell(cio); CioHelper.getInstance().cioSkip(cio, 2); - codingParameters = j2k.getCodingParameters(); - tcp = codingParameters.getTcps()[j2k.getCurTileNo()]; + codingParameters = j2kInfo.getCodingParameters(); + tcp = codingParameters.getTcps()[j2kInfo.getCurTileNo()]; CioHelper.getInstance().cioWrite(cio, tcp.getCodingStyle(), 1); /* Scod */ CioHelper.getInstance().cioWrite(cio, tcp.getProgressionOrder().value(), 1); /* SGcod (A) */ CioHelper.getInstance().cioWrite(cio, tcp.getNoOfLayers(), 2); /* SGcod (B) */ CioHelper.getInstance().cioWrite(cio, tcp.getMct(), 1); /* SGcod (C) */ - j2kWriteCox(j2k, 0); + j2kWriteCox(j2kInfo, 0); length = CioHelper.getInstance().cioTell(cio) - lengthPosition; CioHelper.getInstance().cioSeek(cio, lengthPosition); CioHelper.getInstance().cioWrite(cio, length, 2); /* Lcod */ CioHelper.getInstance().cioSeek(cio, lengthPosition + length); } - private void j2kReadCod(J2K j2k) { + @SuppressWarnings({ "java:S1659", "java:S1854", "java:S3776", "unused"}) + private void j2kReadCod(J2K j2kInfo) { int length, i, pos; - Cio cio = j2k.getCio(); - CodingParameters codingParameters = j2k.getCodingParameters(); - Tcp tcp = j2k.getState() == J2kStatus.J2K_STATE_TPH.value() ? codingParameters.getTcps()[j2k.getCurTileNo()] - : j2k.getDefaultTcp(); - OpenJpegImage image = j2k.getImage(); + Cio cio = j2kInfo.getCio(); + CodingParameters codingParameters = j2kInfo.getCodingParameters(); + Tcp tcp = j2kInfo.getState() == J2kStatus.J2K_STATE_TPH.value() + ? codingParameters.getTcps()[j2kInfo.getCurTileNo()] + : j2kInfo.getDefaultTcp(); + OpenJpegImage image = j2kInfo.getImage(); length = (int) CioHelper.getInstance().cioRead(cio, 2); /* Lcod */ tcp.setCodingStyle((int) CioHelper.getInstance().cioRead(cio, 1)); /* Scod */ - tcp.setProgressionOrder(ProgressionOrder.fromValue((int) CioHelper.getInstance().cioRead(cio, 1))); /* SGcod (A) */ + tcp.setProgressionOrder( + ProgressionOrder.fromValue((int) CioHelper.getInstance().cioRead(cio, 1))); /* SGcod (A) */ tcp.setNoOfLayers((int) CioHelper.getInstance().cioRead(cio, 2)); /* SGcod (B) */ tcp.setMct((int) CioHelper.getInstance().cioRead(cio, 1)); /* SGcod (C) */ - if (tcp.getMct() != 0 && j2k.getImage().getNoOfComps() < 3) { - LOGGER.error(String.format("MCT %d with too few components (%d)", tcp.getMct(), j2k.getImage().getNoOfComps())); + if (tcp.getMct() != 0 && j2kInfo.getImage().getNoOfComps() < 3) { + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("MCT {0} with too few components {1}", tcp.getMct(), + j2kInfo.getImage().getNoOfComps())); return; } - + pos = CioHelper.getInstance().cioTell(cio); for (i = 0; i < image.getNoOfComps(); i++) { - //tcp.getTccps()[i] = new opj_tccp_t(); tcp.getTccps()[i].setCodingStyle(tcp.getCodingStyle() & OpenJpegConstant.J2K_CP_CSTY_PRT); - + CioHelper.getInstance().cioSeek(cio, pos); - j2kReadCox(j2k, i); + j2kReadCox(j2kInfo, i); } /* Index */ - if (j2k.getCodeStreamInfo() != null) { - CodeStreamInfo codeStreamInfo = j2k.getCodeStreamInfo(); + if (j2kInfo.getCodeStreamInfo() != null) { + CodeStreamInfo codeStreamInfo = j2kInfo.getCodeStreamInfo(); codeStreamInfo.setProgOrder(tcp.getProgressionOrder()); codeStreamInfo.setNoOfLayers(tcp.getNoOfLayers()); codeStreamInfo.setNoOfDecompositionComps(new int[image.getNoOfComps()]); @@ -598,52 +625,58 @@ private void j2kReadCod(J2K j2k) { } } - private void j2kWriteCoc(J2K j2k, int compNo) { - int lengthPosition, length; + private void j2kWriteCoc(J2K j2kInfo, int compNo) { + int lengthPosition; + int length; - CodingParameters codingParameters = j2k.getCodingParameters(); - Tcp tcp = codingParameters.getTcps()[j2k.getCurTileNo()]; - OpenJpegImage image = j2k.getImage(); - Cio cio = j2k.getCio(); + CodingParameters codingParameters = j2kInfo.getCodingParameters(); + Tcp tcp = codingParameters.getTcps()[j2kInfo.getCurTileNo()]; + OpenJpegImage image = j2kInfo.getImage(); + Cio cio = j2kInfo.getCio(); CioHelper.getInstance().cioWrite(cio, OpenJpegConstant.J2K_MS_COC, 2); /* COC */ lengthPosition = CioHelper.getInstance().cioTell(cio); CioHelper.getInstance().cioSkip(cio, 2); CioHelper.getInstance().cioWrite(cio, compNo, image.getNoOfComps() <= 256 ? 1 : 2); /* Ccoc */ CioHelper.getInstance().cioWrite(cio, tcp.getTccps()[compNo].getCodingStyle(), 1); /* Scoc */ - j2kWriteCox(j2k, compNo); + j2kWriteCox(j2kInfo, compNo); length = CioHelper.getInstance().cioTell(cio) - lengthPosition; CioHelper.getInstance().cioSeek(cio, lengthPosition); CioHelper.getInstance().cioWrite(cio, length, 2); /* Lcoc */ CioHelper.getInstance().cioSeek(cio, lengthPosition + length); } - private void j2kReadCoc(J2K j2k) { + @SuppressWarnings({ "java:S1659", "unused" }) + private void j2kReadCoc(J2K j2kInfo) { int length, compNo; - CodingParameters codingParameters = j2k.getCodingParameters(); - Tcp tcp = j2k.getState() == J2kStatus.J2K_STATE_TPH.value() ? codingParameters.getTcps()[j2k.getCurTileNo()] - : j2k.getDefaultTcp(); - OpenJpegImage image = j2k.getImage(); - Cio cio = j2k.getCio(); + CodingParameters codingParameters = j2kInfo.getCodingParameters(); + Tcp tcp = j2kInfo.getState() == J2kStatus.J2K_STATE_TPH.value() + ? codingParameters.getTcps()[j2kInfo.getCurTileNo()] + : j2kInfo.getDefaultTcp(); + OpenJpegImage image = j2kInfo.getImage(); + Cio cio = j2kInfo.getCio(); length = (int) CioHelper.getInstance().cioRead(cio, 2); /* Lcoc */ compNo = (int) CioHelper.getInstance().cioRead(cio, image.getNoOfComps() <= 256 ? 1 : 2); /* Ccoc */ tcp.getTccps()[compNo].setCodingStyle((int) CioHelper.getInstance().cioRead(cio, 1)); /* Scoc */ - j2kReadCox(j2k, compNo); + j2kReadCox(j2kInfo, compNo); } - private void j2kWriteQcx(J2K j2k, int compNo) { + @SuppressWarnings({ "java:S1659", "unused" }) + private void j2kWriteQcx(J2K j2kInfo, int compNo) { int bandNo, noOfBands; int expn, mant; - CodingParameters codingParameters = j2k.getCodingParameters(); - Tcp tcp = codingParameters.getTcps()[j2k.getCurTileNo()]; + CodingParameters codingParameters = j2kInfo.getCodingParameters(); + Tcp tcp = codingParameters.getTcps()[j2kInfo.getCurTileNo()]; TileComponentCodingParameters tccp = tcp.getTccps()[compNo]; - Cio cio = j2k.getCio(); + Cio cio = j2kInfo.getCio(); - CioHelper.getInstance().cioWrite(cio, tccp.getQuantisationStyle() + (tccp.getNoOfGaurdBits() << 5), 1); /* Sqcx */ - noOfBands = tccp.getQuantisationStyle() == OpenJpegConstant.J2K_CCP_QNTSTY_SIQNT ? 1 : tccp.getNoOfResolutions() * 3 - 2; + CioHelper.getInstance().cioWrite(cio, tccp.getQuantisationStyle() + (long) (tccp.getNoOfGaurdBits() << 5), + 1); /* Sqcx */ + noOfBands = tccp.getQuantisationStyle() == OpenJpegConstant.J2K_CCP_QNTSTY_SIQNT ? 1 + : tccp.getNoOfResolutions() * 3 - 2; for (bandNo = 0; bandNo < noOfBands; bandNo++) { expn = tccp.getStepsizes()[bandNo].getExpn(); @@ -652,44 +685,45 @@ private void j2kWriteQcx(J2K j2k, int compNo) { if (tccp.getQuantisationStyle() == OpenJpegConstant.J2K_CCP_QNTSTY_NOQNT) { CioHelper.getInstance().cioWrite(cio, expn << 3, 1); /* SPqcx_i */ } else { - CioHelper.getInstance().cioWrite(cio, (expn << 11) + mant, 2); /* SPqcx_i */ + CioHelper.getInstance().cioWrite(cio, (long) (expn << 11) + mant, 2); /* SPqcx_i */ } } } - private void j2kReadQcx(J2K j2k, int compNo, int length, boolean USE_JPWL) { + @SuppressWarnings({ "java:S1659", "java:S3776", "unused" }) + private void j2kReadQcx(J2K j2kInfo, int compNo, int length, boolean useJPWL) { int tmp; int bandNo, noOfBands; - CodingParameters codingParameters = j2k.getCodingParameters(); - boolean isCurtilTcp = j2k.getState() == J2kStatus.J2K_STATE_TPH.value(); - Tcp tcp = isCurtilTcp ? codingParameters.getTcps()[j2k.getCurTileNo()] - : j2k.getDefaultTcp(); + CodingParameters codingParameters = j2kInfo.getCodingParameters(); + boolean isCurtilTcp = j2kInfo.getState() == J2kStatus.J2K_STATE_TPH.value(); + Tcp tcp = isCurtilTcp ? codingParameters.getTcps()[j2kInfo.getCurTileNo()] : j2kInfo.getDefaultTcp(); TileComponentCodingParameters tccp = tcp.getTccps()[compNo]; - Cio cio = j2k.getCio(); - + Cio cio = j2kInfo.getCio(); + tmp = (int) CioHelper.getInstance().cioRead(cio, 1); /* Sqcx */ tccp.setQuantisationStyle(tmp & 0x1f); tccp.setNoOfGaurdBits(tmp >> 5); - noOfBands = (tccp.getQuantisationStyle() == OpenJpegConstant.J2K_CCP_QNTSTY_SIQNT) ? 1 - : ((tccp.getQuantisationStyle() == OpenJpegConstant.J2K_CCP_QNTSTY_NOQNT) ? length - 1 : (length - 1) / 2); - if (USE_JPWL) { - if (j2k.getCodingParameters().getCorrect() != 0) { + if (tccp.getQuantisationStyle() == OpenJpegConstant.J2K_CCP_QNTSTY_SIQNT) + noOfBands = 1; + else if (tccp.getQuantisationStyle() == OpenJpegConstant.J2K_CCP_QNTSTY_NOQNT) + noOfBands = length - 1; + else + noOfBands = (length - 1) / 2; - /* if JPWL is on, we check whether there are too many subbands */ - if ((noOfBands < 0) || (noOfBands >= OpenJpegConstant.J2K_MAXBANDS)) { - LOGGER.warn(String.format("JPWL: bad number of subbands in Sqcx (%d)", noOfBands)); - if (!OpenJpegConstant.JPWL_ASSUME) { - LOGGER.error(String.format("JPWL: giving up (%d)", noOfBands)); - return; - } - /* we try to correct */ - noOfBands = 1; - LOGGER.error(String.format("trying to adjust them- setting number of bands to %d => HYPOTHESIS!!!", - noOfBands)); - } + /* if JPWL is on, we check whether there are too many subbands */ + if (useJPWL && (j2kInfo.getCodingParameters().getCorrect() != 0 && (noOfBands < 0) + || (noOfBands >= OpenJpegConstant.J2K_MAXBANDS))) { + logger.warn(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("JPWL: bad number of subbands in Sqcx {0}", noOfBands)); + if (!OpenJpegConstant.JPWL_ASSUME) { + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("JPWL: giving up {0}", noOfBands)); + return; } + /* we try to correct */ + noOfBands = 1; + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE,LOGGER_EMPTY, MessageFormat.format( + "trying to adjust them- setting number of bands to {0} => HYPOTHESIS!!!", noOfBands)); } for (bandNo = 0; bandNo < noOfBands; bandNo++) { @@ -717,97 +751,100 @@ private void j2kReadQcx(J2K j2k, int compNo, int length, boolean USE_JPWL) { : 0); tccp.getStepsizes()[bandNo].setMant(tccp.getStepsizes()[0].getMant()); } - } + } } - private void j2kWriteQcd(J2K j2k) { + @SuppressWarnings({ "java:S1659", "unused" }) + private void j2kWriteQcd(J2K j2kInfo) { int lengthPosition, length; - Cio cio = j2k.getCio(); + Cio cio = j2kInfo.getCio(); CioHelper.getInstance().cioWrite(cio, OpenJpegConstant.J2K_MS_QCD, 2); /* QCD */ lengthPosition = CioHelper.getInstance().cioTell(cio); CioHelper.getInstance().cioSkip(cio, 2); - j2kWriteQcx(j2k, 0); + j2kWriteQcx(j2kInfo, 0); length = CioHelper.getInstance().cioTell(cio) - lengthPosition; CioHelper.getInstance().cioSeek(cio, lengthPosition); CioHelper.getInstance().cioWrite(cio, length, 2); /* Lqcd */ CioHelper.getInstance().cioSeek(cio, lengthPosition + length); } - private void j2kReadQcd(J2K j2k, boolean USE_JPWL) { + @SuppressWarnings({ "java:S1659", "unused" }) + private void j2kReadQcd(J2K j2kInfo, boolean useJPWL) { int length, i, pos; - Cio cio = j2k.getCio(); - OpenJpegImage image = j2k.getImage(); + Cio cio = j2kInfo.getCio(); + OpenJpegImage image = j2kInfo.getImage(); length = (int) CioHelper.getInstance().cioRead(cio, 2); /* Lqcd */ pos = CioHelper.getInstance().cioTell(cio); for (i = 0; i < image.getNoOfComps(); i++) { CioHelper.getInstance().cioSeek(cio, pos); - j2kReadQcx(j2k, i, length - 2, USE_JPWL); + j2kReadQcx(j2kInfo, i, length - 2, useJPWL); } } - private void j2kWriteQcc(J2K j2k, int compNo) { + @SuppressWarnings({ "java:S1659", "unused" }) + private void j2kWriteQcc(J2K j2kInfo, int compNo) { int lengthPosition, length; - Cio cio = j2k.getCio(); + Cio cio = j2kInfo.getCio(); CioHelper.getInstance().cioWrite(cio, OpenJpegConstant.J2K_MS_QCC, 2); /* QCC */ lengthPosition = CioHelper.getInstance().cioTell(cio); CioHelper.getInstance().cioSkip(cio, 2); - CioHelper.getInstance().cioWrite(cio, compNo, j2k.getImage().getNoOfComps() <= 256 ? 1 : 2); /* Cqcc */ - j2kWriteQcx(j2k, compNo); + CioHelper.getInstance().cioWrite(cio, compNo, j2kInfo.getImage().getNoOfComps() <= 256 ? 1 : 2); /* Cqcc */ + j2kWriteQcx(j2kInfo, compNo); length = CioHelper.getInstance().cioTell(cio) - lengthPosition; CioHelper.getInstance().cioSeek(cio, lengthPosition); CioHelper.getInstance().cioWrite(cio, length, 2); /* Lqcc */ CioHelper.getInstance().cioSeek(cio, lengthPosition + length); } - private void j2kReadQcc(J2K j2k, boolean USE_JPWL) { + @SuppressWarnings({ "java:S1659", "unused" }) + private void j2kReadQcc(J2K j2kInfo, boolean useJPWL) { int length, compNo; - int noOfComp = j2k.getImage().getNoOfComps(); - Cio cio = j2k.getCio(); + int noOfComp = j2kInfo.getImage().getNoOfComps(); + Cio cio = j2kInfo.getCio(); length = (int) CioHelper.getInstance().cioRead(cio, 2); /* Lqcc */ compNo = (int) CioHelper.getInstance().cioRead(cio, noOfComp <= 256 ? 1 : 2); /* Cqcc */ - if (USE_JPWL) { - if (j2k.getCodingParameters().getCorrect() != 0) { - - int backupCompNo = 0; + if (useJPWL && j2kInfo.getCodingParameters().getCorrect() != 0) { + int backupCompNo = 0; - /* compNo is negative or larger than the number of components!!! */ - if ((compNo < 0) || (compNo >= noOfComp)) { - LOGGER.error(String.format("JPWL: bad component number in QCC (%d out of a maximum of %d)", compNo, - noOfComp)); - if (!OpenJpegConstant.JPWL_ASSUME) { - LOGGER.warn(String.format("JPWL: giving up")); - return; - } - /* we try to correct */ - compNo = backupCompNo % noOfComp; - LOGGER.warn(String.format("trying to adjust this - setting component number to %d", compNo)); + /* compNo is negative or larger than the number of components!!! */ + if ((compNo < 0) || (compNo >= noOfComp)) { + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE,LOGGER_EMPTY, MessageFormat.format( + "JPWL: bad component number in QCC {0} out of a maximum of {1}", compNo, noOfComp)); + if (!OpenJpegConstant.JPWL_ASSUME) { + logger.warn(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, TAG_JPWL_GIVING_UP); + return; } - - /* keep your private count of tiles */ - backupCompNo++; + /* we try to correct */ + compNo = backupCompNo % noOfComp; + logger.warn(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("trying to adjust this - setting component number to {0}", + compNo)); } + + /* keep your private count of tiles */ + backupCompNo++; } - j2kReadQcx(j2k, compNo, length - 2 - (noOfComp <= 256 ? 1 : 2), USE_JPWL); + j2kReadQcx(j2kInfo, compNo, length - 2 - (noOfComp <= 256 ? 1 : 2), useJPWL); } - private void j2kWritePoc(J2K j2k) { + @SuppressWarnings({ "java:S1659", "unused" }) + private void j2kWritePoc(J2K j2kInfo) { int length, noOfPocChanges, i; - int noOfComps = j2k.getImage().getNoOfComps(); + int noOfComps = j2kInfo.getImage().getNoOfComps(); - CodingParameters codingParameters = j2k.getCodingParameters(); - Tcp tcp = codingParameters.getTcps()[j2k.getCurTileNo()]; + CodingParameters codingParameters = j2kInfo.getCodingParameters(); + Tcp tcp = codingParameters.getTcps()[j2kInfo.getCurTileNo()]; TileComponentCodingParameters tccp = tcp.getTccps()[0]; - Cio cio = j2k.getCio(); + Cio cio = j2kInfo.getCio(); noOfPocChanges = 1 + tcp.getNoOfPocs(); CioHelper.getInstance().cioWrite(cio, OpenJpegConstant.J2K_MS_POC, 2); /* POC */ @@ -818,49 +855,53 @@ private void j2kWritePoc(J2K j2k) { CioHelper.getInstance().cioWrite(cio, poc.getResNo0(), 1); /* RSpoc_i */ CioHelper.getInstance().cioWrite(cio, poc.getCompNo0(), (noOfComps <= 256 ? 1 : 2)); /* CSpoc_i */ CioHelper.getInstance().cioWrite(cio, poc.getLayNo1(), 2); /* LYEpoc_i */ - poc.setLayNo1(MathUtil.intMin(poc.getLayNo1(), tcp.getNoOfLayers())); + poc.setLayNo1(MathUtil.getInstance().intMin(poc.getLayNo1(), tcp.getNoOfLayers())); CioHelper.getInstance().cioWrite(cio, poc.getResNo1(), 1); /* REpoc_i */ - poc.setResNo1(MathUtil.intMin(poc.getResNo1(), tccp.getNoOfResolutions())); + poc.setResNo1(MathUtil.getInstance().intMin(poc.getResNo1(), tccp.getNoOfResolutions())); CioHelper.getInstance().cioWrite(cio, poc.getCompNo1(), (noOfComps <= 256 ? 1 : 2)); /* CEpoc_i */ - poc.setCompNo1(MathUtil.intMin(poc.getCompNo1(), noOfComps)); + poc.setCompNo1(MathUtil.getInstance().intMin(poc.getCompNo1(), noOfComps)); CioHelper.getInstance().cioWrite(cio, poc.getProgressionOrder().value(), 1); /* Ppoc_i */ } } - private void j2kReadPoc(J2K j2k) { - int length, noOfPocChanges, i, old_poc; + @SuppressWarnings({ "java:S1659", "unused" }) + private void j2kReadPoc(J2K j2kInfo) { + int length, noOfPocChanges, i, oldPoc; - int noOfComps = j2k.getImage().getNoOfComps(); + int noOfComps = j2kInfo.getImage().getNoOfComps(); - CodingParameters codingParameters = j2k.getCodingParameters(); - Tcp tcp = j2k.getState() == J2kStatus.J2K_STATE_TPH.value() ? codingParameters.getTcps()[j2k.getCurTileNo()] - : j2k.getDefaultTcp(); - Cio cio = j2k.getCio(); + CodingParameters codingParameters = j2kInfo.getCodingParameters(); + Tcp tcp = j2kInfo.getState() == J2kStatus.J2K_STATE_TPH.value() + ? codingParameters.getTcps()[j2kInfo.getCurTileNo()] + : j2kInfo.getDefaultTcp(); + Cio cio = j2kInfo.getCio(); - old_poc = tcp.getIsPoc() != 0 ? tcp.getNoOfPocs() + 1 : 0; + oldPoc = tcp.getIsPoc() != 0 ? tcp.getNoOfPocs() + 1 : 0; tcp.setIsPoc(1); length = (int) CioHelper.getInstance().cioRead(cio, 2); /* Lpoc */ noOfPocChanges = (length - 2) / (5 + 2 * (noOfComps <= 256 ? 1 : 2)); - for (i = old_poc; i < noOfPocChanges + old_poc; i++) { + for (i = oldPoc; i < noOfPocChanges + oldPoc; i++) { Poc poc = tcp.getPocs()[i]; poc.setResNo0((int) CioHelper.getInstance().cioRead(cio, 1)); /* RSpoc_i */ poc.setCompNo0((int) CioHelper.getInstance().cioRead(cio, noOfComps <= 256 ? 1 : 2)); /* CSpoc_i */ poc.setLayNo1((int) CioHelper.getInstance().cioRead(cio, 2)); /* LYEpoc_i */ poc.setResNo1((int) CioHelper.getInstance().cioRead(cio, 1)); /* REpoc_i */ - poc.setCompNo1(MathUtil.intMin((int) CioHelper.getInstance().cioRead(cio, noOfComps <= 256 ? 1 : 2), - noOfComps)); /* CEpoc_i */ - poc.setProgressionOrder(ProgressionOrder.fromValue((int) CioHelper.getInstance().cioRead(cio, 1))); /* Ppoc_i */ + poc.setCompNo1(MathUtil.getInstance().intMin( + (int) CioHelper.getInstance().cioRead(cio, noOfComps <= 256 ? 1 : 2), noOfComps)); /* CEpoc_i */ + poc.setProgressionOrder( + ProgressionOrder.fromValue((int) CioHelper.getInstance().cioRead(cio, 1))); /* Ppoc_i */ } - tcp.setNoOfPocs(noOfPocChanges + old_poc - 1); + tcp.setNoOfPocs(noOfPocChanges + oldPoc - 1); } - private void j2kReadCrg(J2K j2k) { + @SuppressWarnings({ "java:S1659", "java:S1854", "java:S3776", "unused" }) + private void j2kReadCrg(J2K j2kInfo) { int length, i, xCrgi, yCrgi; - Cio cio = j2k.getCio(); - int noOfComps = j2k.getImage().getNoOfComps(); + Cio cio = j2kInfo.getCio(); + int noOfComps = j2kInfo.getImage().getNoOfComps(); length = (int) CioHelper.getInstance().cioRead(cio, 2); /* Lcrg */ for (i = 0; i < noOfComps; i++) { @@ -869,11 +910,12 @@ private void j2kReadCrg(J2K j2k) { } } - private void j2kReadTlm(J2K j2k) { + @SuppressWarnings({ "java:S1659", "java:S1854", "java:S3776", "unused" }) + private void j2kReadTlm(J2K j2kInfo) { int length, zTlm, sTlm, st, sp, tileTlm, i; long tTlmi, pTlmi; - Cio cio = j2k.getCio(); + Cio cio = j2kInfo.getCio(); length = (int) CioHelper.getInstance().cioRead(cio, 2); /* Ltlm */ zTlm = (int) CioHelper.getInstance().cioRead(cio, 1); /* zTlm */ @@ -887,10 +929,11 @@ private void j2kReadTlm(J2K j2k) { } } - private void j2kReadPlm(J2K j2k) { + @SuppressWarnings({ "java:S1659", "java:S1854", "java:S3776", "unused" }) + private void j2kReadPlm(J2K j2kInfo) { int length, i, zPlm, nPlm, add, packetLength = 0; - Cio cio = j2k.getCio(); + Cio cio = j2kInfo.getCio(); length = (int) CioHelper.getInstance().cioRead(cio, 2); /* Lplm */ zPlm = (int) CioHelper.getInstance().cioRead(cio, 1); /* Zplm */ @@ -912,10 +955,11 @@ private void j2kReadPlm(J2K j2k) { } } - private void j2kReadPlt(J2K j2k) { + @SuppressWarnings({ "java:S1659", "java:S1854", "java:S3776", "unused" }) + private void j2kReadPlt(J2K j2kInfo) { int length, i, zPlt, packetLength = 0, add; - Cio cio = j2k.getCio(); + Cio cio = j2kInfo.getCio(); length = (int) CioHelper.getInstance().cioRead(cio, 2); /* Lplt */ zPlt = (int) CioHelper.getInstance().cioRead(cio, 1); /* Zplt */ @@ -929,12 +973,13 @@ private void j2kReadPlt(J2K j2k) { } } - private void j2kReadPpm(J2K j2k, boolean USE_JPWL) { + @SuppressWarnings({ "java:S1659", "java:S3776", "unused" }) + private void j2kReadPpm(J2K j2kInfo, boolean useJPWL) { int length, zPpm, i, j; int nPpm; - CodingParameters codingParameters = j2k.getCodingParameters(); - Cio cio = j2k.getCio(); + CodingParameters codingParameters = j2kInfo.getCodingParameters(); + Cio cio = j2kInfo.getCio(); length = (int) CioHelper.getInstance().cioRead(cio, 2); codingParameters.setPpm(1); @@ -962,23 +1007,16 @@ private void j2kReadPpm(J2K j2k, boolean USE_JPWL) { codingParameters.setPpmData(data); - if (USE_JPWL) { - /* this memory allocation check could be done even in non-JPWL cases */ - if (codingParameters.getCorrect() != 0) { - if (codingParameters.getPpmData() == null) { - LOGGER.warn( - String.format("JPWL: failed memory allocation during PPM marker parsing (pos. %x)", - CioHelper.getInstance().cioTell(cio))); - - // opj_event_msg(j2k.getCinfo(), EVT_ERROR, "JPWL: failed memory allocation - // during PPM marker parsing (pos. %x)\n", cioTell(cio)); - if (!OpenJpegConstant.JPWL_ASSUME || OpenJpegConstant.JPWL_ASSUME) { - codingParameters.setPpmData(null); - LOGGER.warn(String.format("JPWL: giving up")); - // opj_event_msg(j2k.getCinfo(), EVT_ERROR, "JPWL: giving up\n"); - return; - } - } + /* this memory allocation check could be done even in non-JPWL cases */ + if (useJPWL && (codingParameters.getCorrect() != 0 && codingParameters.getPpmData() == null)) { + logger.warn(LOGGER_SESSIONID, LOGGER_IDTYPE,LOGGER_EMPTY, MessageFormat.format( + "JPWL: failed memory allocation during PPM marker parsing (pos. {0})", + CioHelper.getInstance().cioTell(cio))); + + if (!OpenJpegConstant.JPWL_ASSUME || OpenJpegConstant.JPWL_ASSUME) { + codingParameters.setPpmData(null); + logger.warn(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, TAG_JPWL_GIVING_UP); + return; } } @@ -999,12 +1037,13 @@ private void j2kReadPpm(J2K j2k, boolean USE_JPWL) { } } - private void j2kReadPpt(J2K j2k) { + @SuppressWarnings({ "java:S1659"}) + private void j2kReadPpt(J2K j2kInfo) { int length, zPpt, i, j = 0; - CodingParameters codingParameters = j2k.getCodingParameters(); - Tcp tcp = codingParameters.getTcps()[j2k.getCurTileNo()]; - Cio cio = j2k.getCio(); + CodingParameters codingParameters = j2kInfo.getCodingParameters(); + Tcp tcp = codingParameters.getTcps()[j2kInfo.getCurTileNo()]; + Cio cio = j2kInfo.getCio(); length = (int) CioHelper.getInstance().cioRead(cio, 2); zPpt = (int) CioHelper.getInstance().cioRead(cio, 1); @@ -1033,74 +1072,75 @@ private void j2kReadPpt(J2K j2k) { tcp.setPptStore(j); } - private void j2kWriteTlm(J2K j2k) { + private void j2kWriteTlm(J2K j2kInfo) { int lengthPosition; - Cio cio = j2k.getCio(); - j2k.setTlmStart(CioHelper.getInstance().cioTell(cio)); + Cio cio = j2kInfo.getCio(); + j2kInfo.setTlmStart(CioHelper.getInstance().cioTell(cio)); CioHelper.getInstance().cioWrite(cio, OpenJpegConstant.J2K_MS_TLM, 2);/* TLM */ - lengthPosition = 4 + (5 * j2k.getTotalNoOfTilePart()); + lengthPosition = 4 + (5 * j2kInfo.getTotalNoOfTilePart()); CioHelper.getInstance().cioWrite(cio, lengthPosition, 2); /* Length tlm */ CioHelper.getInstance().cioWrite(cio, 0, 1); /* zTlm=0 */ CioHelper.getInstance().cioWrite(cio, 80, 1); /* sTlm st=1(8bits-255 tiles max),sp=1(pTlm=32bits) */ - CioHelper.getInstance().cioSkip(cio, 5 * j2k.getTotalNoOfTilePart()); + CioHelper.getInstance().cioSkip(cio, 5 * j2kInfo.getTotalNoOfTilePart()); } - private void j2kWriteSot(J2K j2k, boolean USE_JPWL) { - int lengthPosition, length; + private void j2kWriteSot(J2K j2kInfo, boolean useJPWL) { + int lengthPosition; + int length; - Cio cio = j2k.getCio(); + Cio cio = j2kInfo.getCio(); - j2k.setSotStart(CioHelper.getInstance().cioTell(cio)); + j2kInfo.setSotStart(CioHelper.getInstance().cioTell(cio)); CioHelper.getInstance().cioWrite(cio, OpenJpegConstant.J2K_MS_SOT, 2); /* SOT */ lengthPosition = CioHelper.getInstance().cioTell(cio); CioHelper.getInstance().cioSkip(cio, 2); /* Lsot (further) */ - CioHelper.getInstance().cioWrite(cio, j2k.getCurTileNo(), 2); /* Isot */ + CioHelper.getInstance().cioWrite(cio, j2kInfo.getCurTileNo(), 2); /* Isot */ CioHelper.getInstance().cioSkip(cio, 4); /* Psot (further in j2kWriteSod) */ - CioHelper.getInstance().cioWrite(cio, j2k.getCurTilePartNo(), 1); /* TPsot */ - CioHelper.getInstance().cioWrite(cio, j2k.getCurTotalNoOfTilePart()[j2k.getCurTileNo()], 1); /* TNsot */ + CioHelper.getInstance().cioWrite(cio, j2kInfo.getCurTilePartNo(), 1); /* TPsot */ + CioHelper.getInstance().cioWrite(cio, j2kInfo.getCurTotalNoOfTilePart()[j2kInfo.getCurTileNo()], 1); /* TNsot */ length = CioHelper.getInstance().cioTell(cio) - lengthPosition; CioHelper.getInstance().cioSeek(cio, lengthPosition); CioHelper.getInstance().cioWrite(cio, length, 2); /* Lsot */ CioHelper.getInstance().cioSeek(cio, lengthPosition + length); - if (USE_JPWL) { + if (useJPWL) { /* update markers struct */ - j2kAddMarker(j2k.getCodeStreamInfo(), OpenJpegConstant.J2K_MS_SOT, j2k.getSotStart(), length + 2); + j2kAddMarker(j2kInfo.getCodeStreamInfo(), OpenJpegConstant.J2K_MS_SOT, j2kInfo.getSotStart(), length + 2); } } - private void j2kReadSot(J2K j2k, boolean USE_JPWL) { + @SuppressWarnings({ "java:S1659", "java:S1854", "java:S3012", "java:S3776", "java:S6541", "unused" }) + private void j2kReadSot(J2K j2kInfo, boolean useJPWL) { int length, tileNo, totalLength, partNo, noOfParts, i; Tcp tcp = null; int status = 0; - CodingParameters codingParameters = j2k.getCodingParameters(); - Cio cio = j2k.getCio(); + CodingParameters codingParameters = j2kInfo.getCodingParameters(); + Cio cio = j2kInfo.getCio(); length = (int) CioHelper.getInstance().cioRead(cio, 2); tileNo = (int) CioHelper.getInstance().cioRead(cio, 2); - if (USE_JPWL) { - if (j2k.getCodingParameters().getCorrect() != 0) { + if (useJPWL && j2kInfo.getCodingParameters().getCorrect() != 0) { - int backupTileNo = 0; + int backupTileNo = 0; - /* tileNo is negative or larger than the number of tiles!!! */ - if ((tileNo < 0) || (tileNo > (codingParameters.getTileWidth() * codingParameters.getTileHeight()))) { - LOGGER.error(String.format("JPWL: bad tile number (%d out of a maximum of %d)", tileNo, - (codingParameters.getTileWidth() * codingParameters.getTileHeight()))); - if (!OpenJpegConstant.JPWL_ASSUME) { - LOGGER.error(String.format("JPWL: giving up)")); - return; - } - /* we try to correct */ - tileNo = backupTileNo; - LOGGER.error(String.format("JPWL: trying to adjust this - setting tile number to %d", tileNo)); + /* tileNo is negative or larger than the number of tiles!!! */ + if ((tileNo < 0) || (tileNo > (codingParameters.getTileWidth() * codingParameters.getTileHeight()))) { + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("JPWL: bad tile number ({0} out of a maximum of {1})", + tileNo, (codingParameters.getTileWidth() * codingParameters.getTileHeight()))); + if (!OpenJpegConstant.JPWL_ASSUME) { + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, TAG_JPWL_GIVING_UP); + return; } - - /* keep your private count of tiles */ - backupTileNo++; + /* we try to correct */ + tileNo = backupTileNo; + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE,LOGGER_EMPTY, MessageFormat.format( + "JPWL: trying to adjust this - setting tile number to {0}", tileNo)); } + + /* keep your private count of tiles */ + backupTileNo++; } if (codingParameters.getTileNoSize() == 0) { @@ -1120,23 +1160,20 @@ private void j2kReadSot(J2K j2k, boolean USE_JPWL) { totalLength = (int) CioHelper.getInstance().cioRead(cio, 4); - if (USE_JPWL) { - if (j2k.getCodingParameters().getCorrect() != 0) { - - /* totalLength is negative or larger than the bytes left!!! */ - if ((totalLength < 0) || (totalLength > (CioHelper.getInstance().cioNoOfBytesLeft(cio) + 8))) { - LOGGER.error(String.format("JPWL: bad tile byte size (%d bytes against %d bytes left)", totalLength, - CioHelper.getInstance().cioNoOfBytesLeft(cio) + 8)); - if (!OpenJpegConstant.JPWL_ASSUME) { - LOGGER.error(String.format("JPWL: giving up)")); - return; - } - /* we try to correct */ - totalLength = 0; - LOGGER.error(String.format( - "trying to adjust this - setting Psot to %d => assuming it is the last tile)", totalLength)); - } + /* totalLength is negative or larger than the bytes left!!! */ + if (useJPWL && j2kInfo.getCodingParameters().getCorrect() != 0 + && ((totalLength < 0) || (totalLength > (CioHelper.getInstance().cioNoOfBytesLeft(cio) + 8)))) { + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE,LOGGER_EMPTY, MessageFormat.format( + "JPWL: bad tile byte size ({0} bytes against {1} bytes left)", totalLength, + CioHelper.getInstance().cioNoOfBytesLeft(cio) + 8)); + if (!OpenJpegConstant.JPWL_ASSUME) { + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, TAG_JPWL_GIVING_UP); + return; } + /* we try to correct */ + totalLength = 0; + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format( + "trying to adjust this - setting Psot to {0} => assuming it is the last tile)", totalLength)); } if (totalLength == 0) @@ -1145,189 +1182,198 @@ private void j2kReadSot(J2K j2k, boolean USE_JPWL) { partNo = (int) CioHelper.getInstance().cioRead(cio, 1); noOfParts = (int) CioHelper.getInstance().cioRead(cio, 1); - j2k.setCurTileNo(tileNo); - j2k.setCurTilePartNo(partNo); - j2k.setEot((int) (CioHelper.getInstance().cioGetBufferIndex(cio) - 12 + totalLength)); - j2k.setState(J2kStatus.J2K_STATE_TPH.value()); - tcp = codingParameters.getTcps()[j2k.getCurTileNo()]; + j2kInfo.setCurTileNo(tileNo); + j2kInfo.setCurTilePartNo(partNo); + j2kInfo.setEot((CioHelper.getInstance().cioGetBufferIndex(cio) - 12 + totalLength)); + j2kInfo.setState(J2kStatus.J2K_STATE_TPH.value()); + tcp = codingParameters.getTcps()[j2kInfo.getCurTileNo()]; /* Index */ - if (j2k.getCodeStreamInfo() != null) { + if (j2kInfo.getCodeStreamInfo() != null) { if (tcp.getFirst() != 0) { if (tileNo == 0) - j2k.getCodeStreamInfo().setMainHeadEnd(CioHelper.getInstance().cioTell(cio) - 13); - - j2k.getCodeStreamInfo().getTileInfo()[tileNo].setTileNo(tileNo); - j2k.getCodeStreamInfo().getTileInfo()[tileNo].setStartPosition(CioHelper.getInstance().cioTell(cio) - 12); - j2k.getCodeStreamInfo().getTileInfo()[tileNo] - .setEndPosition(j2k.getCodeStreamInfo().getTileInfo()[tileNo].getStartPosition() + totalLength - 1); - j2k.getCodeStreamInfo().getTileInfo()[tileNo].setNoOfTileParts(noOfParts); + j2kInfo.getCodeStreamInfo().setMainHeadEnd(CioHelper.getInstance().cioTell(cio) - 13); + + j2kInfo.getCodeStreamInfo().getTileInfo()[tileNo].setTileNo(tileNo); + j2kInfo.getCodeStreamInfo().getTileInfo()[tileNo] + .setStartPosition(CioHelper.getInstance().cioTell(cio) - 12); + j2kInfo.getCodeStreamInfo().getTileInfo()[tileNo].setEndPosition( + j2kInfo.getCodeStreamInfo().getTileInfo()[tileNo].getStartPosition() + totalLength - 1); + j2kInfo.getCodeStreamInfo().getTileInfo()[tileNo].setNoOfTileParts(noOfParts); if (noOfParts != 0) - j2k.getCodeStreamInfo().getTileInfo()[tileNo].setTp(new TpInfo[noOfParts]); + j2kInfo.getCodeStreamInfo().getTileInfo()[tileNo].setTp(new TpInfo[noOfParts]); else - j2k.getCodeStreamInfo().getTileInfo()[tileNo].setTp(new TpInfo[10]); // Fixme (10) + j2kInfo.getCodeStreamInfo().getTileInfo()[tileNo].setTp(new TpInfo[10]); // Fix me (10) } else { - j2k.getCodeStreamInfo().getTileInfo()[tileNo] - .setEndPosition(j2k.getCodeStreamInfo().getTileInfo()[tileNo].getEndPosition() + totalLength); + j2kInfo.getCodeStreamInfo().getTileInfo()[tileNo].setEndPosition( + j2kInfo.getCodeStreamInfo().getTileInfo()[tileNo].getEndPosition() + totalLength); } - j2k.getCodeStreamInfo().getTileInfo()[tileNo].getTp()[partNo].setTpStartPosition(CioHelper.getInstance().cioTell(cio) - 12); - j2k.getCodeStreamInfo().getTileInfo()[tileNo].getTp()[partNo] - .setTpEndPosition(j2k.getCodeStreamInfo().getTileInfo()[tileNo].getTp()[partNo].getTpStartPosition() + totalLength - 1); + j2kInfo.getCodeStreamInfo().getTileInfo()[tileNo].getTp()[partNo] + .setTpStartPosition(CioHelper.getInstance().cioTell(cio) - 12); + j2kInfo.getCodeStreamInfo().getTileInfo()[tileNo].getTp()[partNo].setTpEndPosition( + j2kInfo.getCodeStreamInfo().getTileInfo()[tileNo].getTp()[partNo].getTpStartPosition() + totalLength + - 1); } if (tcp.getFirst() == 1) { /* Initialization PPT */ TileComponentCodingParameters[] tmp = tcp.getTccps(); - tcp.setCodingStyle(j2k.getDefaultTcp().getCodingStyle()); - tcp.setDistortionRatio(j2k.getDefaultTcp().getDistortionRatio()); - tcp.setMct(j2k.getDefaultTcp().getMct()); - tcp.setNoOfLayers(j2k.getDefaultTcp().getNoOfLayers()); - tcp.setNoOfPocs(j2k.getDefaultTcp().getNoOfPocs()); - tcp.setIsPoc(j2k.getDefaultTcp().getIsPoc()); - tcp.setPocs(j2k.getDefaultTcp().getPocs()); + tcp.setCodingStyle(j2kInfo.getDefaultTcp().getCodingStyle()); + tcp.setDistortionRatio(j2kInfo.getDefaultTcp().getDistortionRatio()); + tcp.setMct(j2kInfo.getDefaultTcp().getMct()); + tcp.setNoOfLayers(j2kInfo.getDefaultTcp().getNoOfLayers()); + tcp.setNoOfPocs(j2kInfo.getDefaultTcp().getNoOfPocs()); + tcp.setIsPoc(j2kInfo.getDefaultTcp().getIsPoc()); + tcp.setPocs(j2kInfo.getDefaultTcp().getPocs()); tcp.setPpt(0); tcp.setPptData(null); - tcp.setPptDataIndex(j2k.getDefaultTcp().getPptDataIndex()); - tcp.setPptLength(j2k.getDefaultTcp().getPptLength()); - tcp.setPptStore(j2k.getDefaultTcp().getPptStore()); - tcp.setProgressionOrder(j2k.getDefaultTcp().getProgressionOrder()); - tcp.setRates(j2k.getDefaultTcp().getRates()); - tcp.setTccps(j2k.getDefaultTcp().getTccps()); + tcp.setPptDataIndex(j2kInfo.getDefaultTcp().getPptDataIndex()); + tcp.setPptLength(j2kInfo.getDefaultTcp().getPptLength()); + tcp.setPptStore(j2kInfo.getDefaultTcp().getPptStore()); + tcp.setProgressionOrder(j2kInfo.getDefaultTcp().getProgressionOrder()); + tcp.setRates(j2kInfo.getDefaultTcp().getRates()); + tcp.setTccps(j2kInfo.getDefaultTcp().getTccps()); - for (i = 0; i < j2k.getImage().getNoOfComps(); i++) { - tcp.getTccps()[i] = j2k.getDefaultTcp().getTccps()[i]; + for (i = 0; i < j2kInfo.getImage().getNoOfComps(); i++) { + tcp.getTccps()[i] = j2kInfo.getDefaultTcp().getTccps()[i]; } - codingParameters.getTcps()[j2k.getCurTileNo()] = tcp; - codingParameters.getTcps()[j2k.getCurTileNo()].setFirst(0); + codingParameters.getTcps()[j2kInfo.getCurTileNo()] = tcp; + codingParameters.getTcps()[j2kInfo.getCurTileNo()].setFirst(0); } } - private void j2kWriteSod(J2K j2k, Object tileCoder, boolean USE_JPWL) { + @SuppressWarnings({ "java:S1659", "java:S3776" }) + private void j2kWriteSod(J2K j2kInfo, Object tileCoder, boolean useJPWL) { int length, layerNo; int totalLength; Tcp tcp = null; CodeStreamInfo codeStreamInfo = null; Tcd tcd = (Tcd) tileCoder; /* cast is needed because of conflicts in header inclusions */ - CodingParameters codingParameters = j2k.getCodingParameters(); - Cio cio = j2k.getCio(); + CodingParameters codingParameters = j2kInfo.getCodingParameters(); + Cio cio = j2kInfo.getCio(); - tcd.setTilePartNo(j2k.getTilePartNo()); - tcd.setCurTilePartNo(j2k.getCurTilePartNo()); + tcd.setTilePartNo(j2kInfo.getTilePartNo()); + tcd.setCurTilePartNo(j2kInfo.getCurTilePartNo()); CioHelper.getInstance().cioWrite(cio, OpenJpegConstant.J2K_MS_SOD, 2); - if (j2k.getCurTileNo() == 0) { - j2k.setSodStart(CioHelper.getInstance().cioTell(cio) + j2k.getPosCorrection()); + if (j2kInfo.getCurTileNo() == 0) { + j2kInfo.setSodStart(CioHelper.getInstance().cioTell(cio) + j2kInfo.getPosCorrection()); } /* INDEX >> */ - codeStreamInfo = j2k.getCodeStreamInfo(); + codeStreamInfo = j2kInfo.getCodeStreamInfo(); if (codeStreamInfo != null) { - if (j2k.getCurTilePartNo() == 0) { - codeStreamInfo.getTileInfo()[j2k.getCurTileNo()] - .setEndHeader(CioHelper.getInstance().cioTell(cio) + j2k.getPosCorrection() - 1); - j2k.getCodeStreamInfo().getTileInfo()[j2k.getCurTileNo()].setTileNo(j2k.getCurTileNo()); + if (j2kInfo.getCurTilePartNo() == 0) { + codeStreamInfo.getTileInfo()[j2kInfo.getCurTileNo()] + .setEndHeader(CioHelper.getInstance().cioTell(cio) + j2kInfo.getPosCorrection() - 1); + j2kInfo.getCodeStreamInfo().getTileInfo()[j2kInfo.getCurTileNo()].setTileNo(j2kInfo.getCurTileNo()); } else { - if (codeStreamInfo.getTileInfo()[j2k.getCurTileNo()].getPacket()[codeStreamInfo.getPacketNo() - 1].getEndPosition() < CioHelper.getInstance().cioTell(cio)) - codeStreamInfo.getTileInfo()[j2k.getCurTileNo()].getPacket()[codeStreamInfo.getPacketNo()] + if (codeStreamInfo.getTileInfo()[j2kInfo.getCurTileNo()].getPacket()[codeStreamInfo.getPacketNo() - 1] + .getEndPosition() < CioHelper.getInstance().cioTell(cio)) + codeStreamInfo.getTileInfo()[j2kInfo.getCurTileNo()].getPacket()[codeStreamInfo.getPacketNo()] .setStartPosition(CioHelper.getInstance().cioTell(cio)); } /* UniPG>> */ - if (USE_JPWL) { + if (useJPWL) { /* update markers struct */ - j2kAddMarker(j2k.getCodeStreamInfo(), OpenJpegConstant.J2K_MS_SOD, j2k.getSodStart(), 2); + j2kAddMarker(j2kInfo.getCodeStreamInfo(), OpenJpegConstant.J2K_MS_SOD, j2kInfo.getSodStart(), 2); } /* < (j2k.getSodStart() / (codingParameters.getTileHeight() * codingParameters.getTileWidth()))) { - tcp.getRates()[layerNo] = tcp.getRates()[layerNo] - (j2k.getSodStart() / (codingParameters.getTileHeight() * codingParameters.getTileWidth())); + if (tcp.getRates()[layerNo] > (j2kInfo.getSodStart() + / (codingParameters.getTileHeight() * codingParameters.getTileWidth()))) { + tcp.getRates()[layerNo] = tcp.getRates()[layerNo] - (float) (j2kInfo.getSodStart() + / (double) (codingParameters.getTileHeight() * codingParameters.getTileWidth())); } else if (tcp.getRates()[layerNo] != 0) { tcp.getRates()[layerNo] = 1; } } - if (j2k.getCurTilePartNo() == 0) { + if (j2kInfo.getCurTilePartNo() == 0) { tcd.getTcdImage().getTiles()[0].setPacketNo(0); if (codeStreamInfo != null) codeStreamInfo.setPacketNo(0); } - length = TcdHelper.getInstance().tcdEncodeTile(tcd, j2k.getCurTileNo(), CioHelper.getInstance().cioGetBuffer(cio), - CioHelper.getInstance().cioNoOfBytesLeft(cio) - 2, codeStreamInfo); + length = TcdHelper.getInstance().tcdEncodeTile(tcd, j2kInfo.getCurTileNo(), + CioHelper.getInstance().cioGetBuffer(cio), CioHelper.getInstance().cioNoOfBytesLeft(cio) - 2, + codeStreamInfo); /* Writing Psot in SOT marker */ - totalLength = CioHelper.getInstance().cioTell(cio) + length - j2k.getSotStart(); - CioHelper.getInstance().cioSeek(cio, j2k.getSotStart() + 6); + totalLength = CioHelper.getInstance().cioTell(cio) + length - j2kInfo.getSotStart(); + CioHelper.getInstance().cioSeek(cio, j2kInfo.getSotStart() + 6); CioHelper.getInstance().cioWrite(cio, totalLength, 4); - CioHelper.getInstance().cioSeek(cio, j2k.getSotStart() + totalLength); + CioHelper.getInstance().cioSeek(cio, j2kInfo.getSotStart() + totalLength); /* Writing Ttlm and Ptlm in TLM marker */ if (codingParameters.getCinemaMode().value() != 0) { - CioHelper.getInstance().cioSeek(cio, j2k.getTlmStart() + 6 + (5 * j2k.getCurTilePartNo())); - CioHelper.getInstance().cioWrite(cio, j2k.getCurTileNo(), 1); + CioHelper.getInstance().cioSeek(cio, j2kInfo.getTlmStart() + 6 + (5 * j2kInfo.getCurTilePartNo())); + CioHelper.getInstance().cioWrite(cio, j2kInfo.getCurTileNo(), 1); CioHelper.getInstance().cioWrite(cio, totalLength, 4); } - CioHelper.getInstance().cioSeek(cio, j2k.getSotStart() + totalLength); + CioHelper.getInstance().cioSeek(cio, j2kInfo.getSotStart() + totalLength); } - private void j2kReadSod(J2K j2k) { + @SuppressWarnings({ "java:S1659", "java:S3776" }) + private void j2kReadSod(J2K j2kInfo) { int length, truncate = 0, i; byte[] data = null; int dataIndex = 0; - Cio cio = j2k.getCio(); - int curtileno = j2k.getCurTileNo(); + Cio cio = j2kInfo.getCio(); + int curtileno = j2kInfo.getCurTileNo(); /* Index */ - if (j2k.getCodeStreamInfo() != null) { - j2k.getCodeStreamInfo().getTileInfo()[j2k.getCurTileNo()].getTp()[j2k.getCurTilePartNo()] - .setTpEndHeader(CioHelper.getInstance().cioTell(cio) + j2k.getPosCorrection() - 1); - if (j2k.getCurTilePartNo() == 0) - j2k.getCodeStreamInfo().getTileInfo()[j2k.getCurTileNo()] - .setEndHeader(CioHelper.getInstance().cioTell(cio) + j2k.getPosCorrection() - 1); - j2k.getCodeStreamInfo().setPacketNo(0); + if (j2kInfo.getCodeStreamInfo() != null) { + j2kInfo.getCodeStreamInfo().getTileInfo()[j2kInfo.getCurTileNo()].getTp()[j2kInfo.getCurTilePartNo()] + .setTpEndHeader(CioHelper.getInstance().cioTell(cio) + j2kInfo.getPosCorrection() - 1); + if (j2kInfo.getCurTilePartNo() == 0) + j2kInfo.getCodeStreamInfo().getTileInfo()[j2kInfo.getCurTileNo()] + .setEndHeader(CioHelper.getInstance().cioTell(cio) + j2kInfo.getPosCorrection() - 1); + j2kInfo.getCodeStreamInfo().setPacketNo(0); } - length = MathUtil.intMin(j2k.getEot() - CioHelper.getInstance().cioGetBufferIndex(cio), + length = MathUtil.getInstance().intMin(j2kInfo.getEot() - CioHelper.getInstance().cioGetBufferIndex(cio), CioHelper.getInstance().cioNoOfBytesLeft(cio) + 1); if (length == CioHelper.getInstance().cioNoOfBytesLeft(cio) + 1) { truncate = 1; /* Case of a truncate codestream */ } - data = j2k.getTileData()[curtileno]; + data = j2kInfo.getTileData()[curtileno]; - int newSize = (j2k.getTileLength()[curtileno] + length); + int newSize = (j2kInfo.getTileLength()[curtileno] + length); int oldSize = data == null ? 0 : data.length; byte[] data1 = new byte[oldSize + newSize + 1]; if (oldSize != 0) System.arraycopy(data, 0, data1, 0, data.length); - dataIndex = 0 + j2k.getTileLength()[curtileno]; + dataIndex = 0 + j2kInfo.getTileLength()[curtileno]; for (i = 0; i < length; i++) { data1[dataIndex + i] = (byte) CioHelper.getInstance().cioRead(cio, 1); } data1[length] = (byte) OpenJpegConstant.LAST_DATA_BYTE; - - j2k.getTileLength()[curtileno] = j2k.getTileLength()[curtileno] + length + 1; - j2k.getTileData()[curtileno] = data1; - j2k.setEndCode((byte)OpenJpegConstant.LAST_DATA_BYTE); - + + j2kInfo.getTileLength()[curtileno] = j2kInfo.getTileLength()[curtileno] + length + 1; + j2kInfo.getTileData()[curtileno] = data1; + j2kInfo.setEndCode((byte) OpenJpegConstant.LAST_DATA_BYTE); + if (truncate == 0) { - j2k.setState(J2kStatus.J2K_STATE_TPHSOT.value()); + j2kInfo.setState(J2kStatus.J2K_STATE_TPHSOT.value()); } else { - j2k.setState(J2kStatus.J2K_STATE_NEOC.value()); + j2kInfo.setState(J2kStatus.J2K_STATE_NEOC.value()); } - j2k.setCurTilePartNo(j2k.getCurTilePartNo() + 1); + j2kInfo.setCurTilePartNo(j2kInfo.getCurTilePartNo() + 1); } - private void j2kWriteRgn(J2K j2k, int compNo, int tileNo) { - CodingParameters codingParameters = j2k.getCodingParameters(); + private void j2kWriteRgn(J2K j2kInfo, int compNo, int tileNo) { + CodingParameters codingParameters = j2kInfo.getCodingParameters(); Tcp tcp = codingParameters.getTcps()[tileNo]; - Cio cio = j2k.getCio(); - int noOfComps = j2k.getImage().getNoOfComps(); + Cio cio = j2kInfo.getCio(); + int noOfComps = j2kInfo.getImage().getNoOfComps(); CioHelper.getInstance().cioWrite(cio, OpenJpegConstant.J2K_MS_RGN, 2); /* RGN */ CioHelper.getInstance().cioWrite(cio, noOfComps <= 256 ? 5 : 6, 2); /* Lrgn */ @@ -1336,65 +1382,66 @@ private void j2kWriteRgn(J2K j2k, int compNo, int tileNo) { CioHelper.getInstance().cioWrite(cio, tcp.getTccps()[compNo].getRoiShift(), 1); /* SPrgn */ } - private void j2kReadRgn(J2K j2k, boolean USE_JPWL) { + @SuppressWarnings({ "java:S1659", "java:S2589", "unused" }) + private void j2kReadRgn(J2K j2kInfo, boolean useJPWL) { int length, compNo, roiStyle; - CodingParameters codingParameters = j2k.getCodingParameters(); - Tcp tcp = j2k.getState() == J2kStatus.J2K_STATE_TPH.value() ? codingParameters.getTcps()[j2k.getCurTileNo()] - : j2k.getDefaultTcp(); - Cio cio = j2k.getCio(); - int noOfComps = j2k.getImage().getNoOfComps(); + CodingParameters codingParameters = j2kInfo.getCodingParameters(); + Tcp tcp = j2kInfo.getState() == J2kStatus.J2K_STATE_TPH.value() + ? codingParameters.getTcps()[j2kInfo.getCurTileNo()] + : j2kInfo.getDefaultTcp(); + Cio cio = j2kInfo.getCio(); + int noOfComps = j2kInfo.getImage().getNoOfComps(); length = (int) CioHelper.getInstance().cioRead(cio, 2); /* Lrgn */ compNo = (int) CioHelper.getInstance().cioRead(cio, noOfComps <= 256 ? 1 : 2); /* Crgn */ roiStyle = (int) CioHelper.getInstance().cioRead(cio, 1); /* Srgn */ - if (USE_JPWL) { - if (j2k.getCodingParameters().getCorrect() != 0) { - /* totalLength is negative or larger than the bytes left!!! */ - if (compNo >= noOfComps) { - LOGGER.error(String.format("JPWL: bad component number in RGN (%d when there are only %d)", compNo, - noOfComps)); - if (!OpenJpegConstant.JPWL_ASSUME || OpenJpegConstant.JPWL_ASSUME) { - LOGGER.error(String.format("JPWL: giving up")); - return; - } - } + /* totalLength is negative or larger than the bytes left!!! */ + if (useJPWL && j2kInfo.getCodingParameters().getCorrect() != 0 && compNo >= noOfComps) { + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format( + "JPWL: bad component number in RGN ({0} when there are only {1})", compNo, noOfComps)); + if (!OpenJpegConstant.JPWL_ASSUME || OpenJpegConstant.JPWL_ASSUME) { + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, TAG_JPWL_GIVING_UP); + return; } } tcp.getTccps()[compNo].setRoiShift((int) CioHelper.getInstance().cioRead(cio, 1)); /* SPrgn */ } - private void j2kWriteEoc(J2K j2k, boolean USE_JPWL) { - Cio cio = j2k.getCio(); + private void j2kWriteEoc(J2K j2kInfo, boolean useJPWL) { + Cio cio = j2kInfo.getCio(); CioHelper.getInstance().cioWrite(cio, OpenJpegConstant.J2K_MS_EOC, 2); /* UniPG>> */ - if (USE_JPWL) { + if (useJPWL) { /* update markers struct */ - j2kAddMarker(j2k.getCodeStreamInfo(), OpenJpegConstant.J2K_MS_EOC, CioHelper.getInstance().cioTell(cio) - 2, 2); + j2kAddMarker(j2kInfo.getCodeStreamInfo(), OpenJpegConstant.J2K_MS_EOC, + CioHelper.getInstance().cioTell(cio) - 2, 2); } /* < giving up")); - return; - } - /* OK, activate this at your own risk!!! */ - /* we look for the marker at the minimum hamming distance from this */ - while (J2K_DECODER_FUNCTION_INFO[m].getId() != 0) { - - /* 1's where they differ */ - tmpId = J2K_DECODER_FUNCTION_INFO[m].getId() ^ id; - - /* compute the hamming distance between our id and the current */ - curDist = 0; - for (i = 0; i < 16; i++) { - if (((tmpId >> i) & 0x0001) != 0) { - curDist++; - } - } - - /* if current distance is smaller, set the minimum */ - if (curDist < minDist) { - minDist = curDist; - minId = J2K_DECODER_FUNCTION_INFO[m].getId(); + @SuppressWarnings({ "java:S1659", "java:S3776" }) + private void j2kReadUnknown(J2K j2kInfo, boolean useJPWL) { + logger.warn(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "Unknown marker"); + + if (useJPWL && j2kInfo.getCodingParameters().getCorrect() != 0) { + int m = 0, id, i; + int minId = 0, minDist = 17, curDist = 0, tmpId; + CioHelper.getInstance().cioSeek(j2kInfo.getCio(), CioHelper.getInstance().cioTell(j2kInfo.getCio()) - 2); + id = (int) CioHelper.getInstance().cioRead(j2kInfo.getCio(), 2); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("JPWL: really do not know this marker {0}", id)); + if (!OpenJpegConstant.JPWL_ASSUME) { + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + "- possible synch loss due to uncorrectable codestream errors => giving up"); + return; + } + /* OK, activate this at your own risk!!! */ + /* we look for the marker at the minimum hamming distance from this */ + while (J2K_DECODER_FUNCTION_INFO[m].getId() != 0) { + /* 1's where they differ */ + tmpId = J2K_DECODER_FUNCTION_INFO[m].getId() ^ id; + + /* compute the hamming distance between our id and the current */ + curDist = 0; + for (i = 0; i < 16; i++) { + if (((tmpId >> i) & 0x0001) != 0) { + curDist++; } + } - /* jump to the next marker */ - m++; + /* if current distance is smaller, set the minimum */ + if (curDist < minDist) { + minDist = curDist; + minId = J2K_DECODER_FUNCTION_INFO[m].getId(); } - /* do we substitute the marker? */ - if (minDist < OpenJpegConstant.JPWL_MAXIMUM_HAMMING) { - LOGGER.error(String.format( - "marker %x is at distance %d from the read %x - trying to substitute in place and crossing fingers!", - minId, minDist, id)); + /* jump to the next marker */ + m++; + } + + /* do we substitute the marker? */ + if (minDist < OpenJpegConstant.JPWL_MAXIMUM_HAMMING) { + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format( + "marker {0} is at distance {1} from the read {2} - trying to substitute in place and crossing fingers!", + minId, minDist, id)); - CioHelper.getInstance().cioSeek(j2k.getCio(), CioHelper.getInstance().cioTell(j2k.getCio()) - 2); - CioHelper.getInstance().cioWrite(j2k.getCio(), minId, 2); + CioHelper.getInstance().cioSeek(j2kInfo.getCio(), + CioHelper.getInstance().cioTell(j2kInfo.getCio()) - 2); + CioHelper.getInstance().cioWrite(j2kInfo.getCio(), minId, 2); - /* rewind */ - CioHelper.getInstance().cioSeek(j2k.getCio(), CioHelper.getInstance().cioTell(j2k.getCio()) - 2); - } + /* rewind */ + CioHelper.getInstance().cioSeek(j2kInfo.getCio(), + CioHelper.getInstance().cioTell(j2kInfo.getCio()) - 2); } } } @@ -1491,35 +1538,36 @@ private DecoderFunctionInfo j2kDecoderFunctionLookup(int id) { /* ----------------------------------------------------------------------- */ public J2K j2kCreateDecompression(CodecContextInfo codecContextInfo) { - J2K j2k = new J2K(); - j2k.setDefaultTcp(new Tcp()); - j2k.setCodecContextInfo(codecContextInfo); - j2k.setTileData(null); + J2K j2kInfo = new J2K(); + j2kInfo.setDefaultTcp(new Tcp()); + j2kInfo.setCodecContextInfo(codecContextInfo); + j2kInfo.setTileData(null); - return j2k; + return j2kInfo; } - public void j2kDestroyDecompression(J2K j2k) { + @SuppressWarnings({ "java:S3776" }) + public void j2kDestroyDecompression(J2K j2kInfo) { int i = 0; - if (j2k.getTileLength() != null) { - j2k.setTileLength(null); + if (j2kInfo.getTileLength() != null) { + j2kInfo.setTileLength(null); } - if (j2k.getTileData() != null) { - j2k.setTileData(null); + if (j2kInfo.getTileData() != null) { + j2kInfo.setTileData(null); } - if (j2k.getDefaultTcp() != null) { - Tcp defaultTcp = j2k.getDefaultTcp(); + if (j2kInfo.getDefaultTcp() != null) { + Tcp defaultTcp = j2kInfo.getDefaultTcp(); if (defaultTcp.getPptDataFirst() != null) { defaultTcp.setPptDataFirst(null); } - if (j2k.getDefaultTcp().getTccps() != null) { - j2k.getDefaultTcp().setTccps(null); + if (j2kInfo.getDefaultTcp().getTccps() != null) { + j2kInfo.getDefaultTcp().setTccps(null); } - j2k.setDefaultTcp(null); + j2kInfo.setDefaultTcp(null); } - if (j2k.getCodingParameters() != null) { - CodingParameters codingParameters = j2k.getCodingParameters(); + if (j2kInfo.getCodingParameters() != null) { + CodingParameters codingParameters = j2kInfo.getCodingParameters(); if (codingParameters.getTcps() != null) { for (i = 0; i < codingParameters.getTileWidth() * codingParameters.getTileHeight(); i++) { if (codingParameters.getTcps()[i].getPptDataFirst() != null) { @@ -1540,123 +1588,121 @@ public void j2kDestroyDecompression(J2K j2k) { if (codingParameters.getComment() != null) { codingParameters.setComment(null); } - - codingParameters = null; } - j2k = null; } - public void j2kSetupDecoder(J2K j2k, DecompressionParameters parameters, boolean USE_JPWL) { - if (j2k != null && parameters != null) { + public void j2kSetupDecoder(J2K j2kInfo, DecompressionParameters parameters, boolean useJPWL) { + if (j2kInfo != null && parameters != null) { /* create and initialize the coding parameters structure */ CodingParameters codingParameters = new CodingParameters(); codingParameters.setReduce(parameters.getCpReduce()); codingParameters.setLayer(parameters.getCpLayer()); codingParameters.setLimitDecoding(parameters.getCpLimitDecoding()); - if (USE_JPWL) { + if (useJPWL) { codingParameters.setCorrect(parameters.getJpwlCorrect()); codingParameters.setExpComps(parameters.getJpwlExpComps()); codingParameters.setMaxTiles(parameters.getJpwlMaxTiles()); } /* - * keep a link to codingParameters so that we can destroy it later in j2kDestroyDeCompression + * keep a link to codingParameters so that we can destroy it later in + * j2kDestroyDeCompression */ - j2k.setCodingParameters(codingParameters); + j2kInfo.setCodingParameters(codingParameters); } } - public OpenJpegImage j2kDecode(J2K j2k, Cio cio, CodeStreamInfo codeStreamInfo, boolean USE_JPWL) { + @SuppressWarnings({ "java:S135", "java:S1659", "java:S3776", "java:S6541", "unused" }) + public OpenJpegImage j2kDecode(J2K j2kInfo, Cio cio, CodeStreamInfo codeStreamInfo, boolean useJPWL) { OpenJpegImage image = null; - j2k.setCio(cio); - j2k.setCodeStreamInfo(codeStreamInfo); + j2kInfo.setCio(cio); + j2kInfo.setCodeStreamInfo(codeStreamInfo); /* create an empty image */ image = ImageHelper.getInstance().imageCreateBasic(); - j2k.setImage(image); + j2kInfo.setImage(image); - j2k.setState(J2kStatus.J2K_STATE_MHSOC.value()); + j2kInfo.setState(J2kStatus.J2K_STATE_MHSOC.value()); for (;;) { DecoderFunctionInfo e; int id = (int) CioHelper.getInstance().cioRead(cio, 2); - if (USE_JPWL) { - /* we try to honor JPWL correction power */ - if (j2k.getCodingParameters().getCorrect() != 0) { + /* we try to honor JPWL correction power */ + if (useJPWL && j2kInfo.getCodingParameters().getCorrect() != 0) { - int originalPosition = CioHelper.getInstance().cioTell(cio); - int status; + int originalPosition = CioHelper.getInstance().cioTell(cio); + int status; - /* call the corrector */ - status = jpwlCorrect(j2k); + /* call the corrector */ + status = jpwlCorrect(j2kInfo); - /* go back to where you were */ - CioHelper.getInstance().cioSeek(cio, originalPosition - 2); + /* go back to where you were */ + CioHelper.getInstance().cioSeek(cio, originalPosition - 2); - /* re-read the marker */ - id = (int) CioHelper.getInstance().cioRead(cio, 2); + /* re-read the marker */ + id = (int) CioHelper.getInstance().cioRead(cio, 2); - /* check whether it begins with ff */ - if (id >> 8 != 0xff) { - LOGGER.error(String.format("JPWL: possible bad marker %x at %d", id, - CioHelper.getInstance().cioTell(cio) - 2)); - if (!OpenJpegConstant.JPWL_ASSUME) { - ImageHelper.getInstance().imageDestroy(image); - LOGGER.error(String.format("JPWL: giving up")); - return null; - } - /* we try to correct */ - id = id | 0xff00; - CioHelper.getInstance().cioSeek(cio, CioHelper.getInstance().cioTell(cio) - 2); - CioHelper.getInstance().cioWrite(cio, id, 2); - LOGGER.warn(String.format("trying to adjust this setting marker to %x", id)); + /* check whether it begins with ff */ + if (id >> 8 != 0xff) { + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("JPWL: possible bad marker {0} at {1}", id, + CioHelper.getInstance().cioTell(cio) - 2)); + if (!OpenJpegConstant.JPWL_ASSUME) { + ImageHelper.getInstance().imageDestroy(image); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, TAG_JPWL_GIVING_UP); + return null; } + /* we try to correct */ + id = id | 0xff00; + CioHelper.getInstance().cioSeek(cio, CioHelper.getInstance().cioTell(cio) - 2); + CioHelper.getInstance().cioWrite(cio, id, 2); + logger.warn(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("trying to adjust this setting marker to {0}", id)); } } if (id >> 8 != 0xff) { ImageHelper.getInstance().imageDestroy(image); - LOGGER.error( - String.format("%-8x: expected a marker instead of %x", CioHelper.getInstance().cioTell(cio) - 2, id)); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("{0}: expected a marker instead of {1}", + CioHelper.getInstance().cioTell(cio) - 2, id)); return null; } e = j2kDecoderFunctionLookup(id); // Check if the marker is known - if ((j2k.getState() & e.getStates()) == 0) { + if (e != null && (j2kInfo.getState() & e.getStates()) == 0) { ImageHelper.getInstance().imageDestroy(image); - LOGGER.error(String.format("%-8x: unexpected marker %x", CioHelper.getInstance().cioTell(cio) - 2, id)); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("{0}: unexpected marker {1}", + CioHelper.getInstance().cioTell(cio) - 2, id)); return null; } // Check if the decoding is limited to the main header - if (e.getId() == OpenJpegConstant.J2K_MS_SOT - && j2k.getCodingParameters().getLimitDecoding() == LimitDecoding.LIMIT_TO_MAIN_HEADER) { - LOGGER.warn(String.format("Main Header decoded")); + if (e != null && e.getId() == OpenJpegConstant.J2K_MS_SOT + && j2kInfo.getCodingParameters().getLimitDecoding() == LimitDecoding.LIMIT_TO_MAIN_HEADER) { + logger.warn(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "Main Header decoded"); return image; } - if (e.getJ2kFunctionName() != null) { - callHandler(e.getJ2kFunctionName(), new Object[] { j2k, USE_JPWL }); + if (e != null && e.getJ2kFunctionName() != null) { + callHandler(e.getJ2kFunctionName(), new Object[] { j2kInfo, useJPWL }); } - if ((j2k.getState() & J2kStatus.J2K_STATE_ERR.value()) != 0) + if ((j2kInfo.getState() & J2kStatus.J2K_STATE_ERR.value()) != 0) return null; - if (j2k.getState() == J2kStatus.J2K_STATE_MT.value()) { + if (j2kInfo.getState() == J2kStatus.J2K_STATE_MT.value()) { break; } - if (j2k.getState() == J2kStatus.J2K_STATE_NEOC.value()) { + if (j2kInfo.getState() == J2kStatus.J2K_STATE_NEOC.value()) { break; } } - if (j2k.getState() == J2kStatus.J2K_STATE_NEOC.value()) { - j2kReadEoc(j2k, USE_JPWL); + if (j2kInfo.getState() == J2kStatus.J2K_STATE_NEOC.value()) { + j2kReadEoc(j2kInfo, useJPWL); } - if (j2k.getState() != J2kStatus.J2K_STATE_MT.value()) { - LOGGER.warn(String.format("Incomplete bitstream")); + if (j2kInfo.getState() != J2kStatus.J2K_STATE_MT.value()) { + logger.warn(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "Incomplete bitstream"); } return image; @@ -1666,37 +1712,37 @@ public OpenJpegImage j2kDecode(J2K j2k, Cio cio, CodeStreamInfo codeStreamInfo, * Read a JPT-stream and decode file * */ - private int jpwlCorrect(J2K j2k) { - // TODO Auto-generated method stub + @SuppressWarnings({ "java:S1172" }) + private int jpwlCorrect(J2K j2kInfo) { return 0; } - public OpenJpegImage j2kDecodeJPTStream(J2K j2k, Cio cio, CodeStreamInfo codeStreamInfo, - boolean USE_JPWL) { + @SuppressWarnings({ "java:S135", "java:S1172", "java:S3776", "java:S6541" }) + public OpenJpegImage j2kDecodeJPTStream(J2K j2kInfo, Cio cio, CodeStreamInfo codeStreamInfo, boolean useJPWL) { OpenJpegImage image = null; JPTMessageHeader header = new JPTMessageHeader(); int position; - CodecContextInfo codecContextInfo = j2k.getCodecContextInfo(); + CodecContextInfo codecContextInfo = j2kInfo.getCodecContextInfo(); - j2k.setCio(cio); + j2kInfo.setCio(cio); /* create an empty image */ image = ImageHelper.getInstance().imageCreateBasic(); - j2k.setImage(image); + j2kInfo.setImage(image); - j2k.setState(J2kStatus.J2K_STATE_MHSOC.value()); + j2kInfo.setState(J2kStatus.J2K_STATE_MHSOC.value()); /* Initialize the header */ - JPTHelper.jptInitMsgHeader(header); + JPTHelper.getInstance().jptInitMsgHeader(header); /* Read the first header of the message */ - JPTHelper.jptReadMsgHeader(codecContextInfo, cio, header); + JPTHelper.getInstance().jptReadMsgHeader(codecContextInfo, cio, header); position = CioHelper.getInstance().cioTell(cio); if (header.getClassId() != 6) { /* 6 : Main header data-bin message */ ImageHelper.getInstance().imageDestroy(image); - LOGGER.error( - String.format("[JPT-stream] : Expecting Main header first [classId %d] !", header.getClassId())); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, "[JPT-stream] : Expecting Main header first [classId {%d}] !", + header.getClassId()); return null; } @@ -1705,16 +1751,16 @@ public OpenJpegImage j2kDecodeJPTStream(J2K j2k, Cio cio, CodeStreamInfo codeStr int id; if (CioHelper.getInstance().cioNoOfBytesLeft(cio) == 0) { - j2kReadEoc(j2k, USE_JPWL); + j2kReadEoc(j2kInfo, useJPWL); return image; } /* data-bin read -> need to read a new header */ if ((CioHelper.getInstance().cioTell(cio) - position) == header.getMsgLength()) { - JPTHelper.jptReadMsgHeader(codecContextInfo, cio, header); + JPTHelper.getInstance().jptReadMsgHeader(codecContextInfo, cio, header); position = CioHelper.getInstance().cioTell(cio); if (header.getClassId() != 4) { /* 4 : Tile data-bin message */ ImageHelper.getInstance().imageDestroy(image); - LOGGER.error(String.format("[JPT-stream] : Expecting Tile info !")); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "[JPT-stream] : Expecting Tile info !"); return null; } } @@ -1722,37 +1768,39 @@ public OpenJpegImage j2kDecodeJPTStream(J2K j2k, Cio cio, CodeStreamInfo codeStr id = (int) CioHelper.getInstance().cioRead(cio, 2); if (id >> 8 != 0xff) { ImageHelper.getInstance().imageDestroy(image); - LOGGER.error( - String.format("%.8x: expected a marker instead of %x", CioHelper.getInstance().cioTell(cio) - 2, id)); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("{0}: expected a marker instead of {1}", + CioHelper.getInstance().cioTell(cio) - 2, id)); return null; } e = j2kDecoderFunctionLookup(id); - if ((j2k.getState() & e.getStates()) == 0) { + if (e != null && (j2kInfo.getState() & e.getStates()) == 0) { ImageHelper.getInstance().imageDestroy(image); - LOGGER.error(String.format("%.8x: unexpected marker of %x", CioHelper.getInstance().cioTell(cio) - 2, id)); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("{0}: unexpected marker of {1}", + CioHelper.getInstance().cioTell(cio) - 2, id)); return null; } - if (e.getJ2kFunctionName() != null) { - callHandler(e.getJ2kFunctionName(), new Object[] { j2k, OpenJpegConstant.JPWL_ASSUME }); + if (e != null && e.getJ2kFunctionName() != null) { + callHandler(e.getJ2kFunctionName(), new Object[] { j2kInfo, OpenJpegConstant.JPWL_ASSUME }); } - if (j2k.getState() == J2kStatus.J2K_STATE_MT.value()) { + if (j2kInfo.getState() == J2kStatus.J2K_STATE_MT.value()) { break; } - if (j2k.getState() == J2kStatus.J2K_STATE_NEOC.value()) { + if (j2kInfo.getState() == J2kStatus.J2K_STATE_NEOC.value()) { break; } } - if (j2k.getState() == J2kStatus.J2K_STATE_NEOC.value()) { - j2kReadEoc(j2k, USE_JPWL); + if (j2kInfo.getState() == J2kStatus.J2K_STATE_NEOC.value()) { + j2kReadEoc(j2kInfo, useJPWL); } - if (j2k.getState() != J2kStatus.J2K_STATE_MT.value()) { - LOGGER.warn(String.format("Incomplete bitstream")); + if (j2kInfo.getState() != J2kStatus.J2K_STATE_MT.value()) { + logger.warn(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "Incomplete bitstream"); } return image; } + @SuppressWarnings({ "java:S125" }) private void callHandler(String methodName, Object[] args) { switch (methodName) { // Using strings in `switch` requires a recent version of Java case "j2kReadSoc": @@ -1832,7 +1880,7 @@ private void callHandler(String methodName, Object[] args) { this.j2kReadUnknown((J2K) args[0], (Boolean) args[1]); break; default: - LOGGER.warn(String.format("wrong handler %s", methodName)); + logger.warn(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("wrong handler {0}", methodName)); } } /* ----------------------------------------------------------------------- */ @@ -1840,20 +1888,18 @@ private void callHandler(String methodName, Object[] args) { /* ----------------------------------------------------------------------- */ public J2K j2kCreateCompression(CodecContextInfo codecContextInfo) { - J2K j2k = new J2K(); - if (j2k != null) { - j2k.setCodecContextInfo(codecContextInfo); - } - return j2k; + J2K j2kInfo = new J2K(); + j2kInfo.setCodecContextInfo(codecContextInfo); + return j2kInfo; } - public void j2kDestroyCompression(J2K j2k) { + public void j2kDestroyCompression(J2K j2kInfo) { int tileNo; - if (j2k == null) + if (j2kInfo == null) return; - if (j2k.getCodingParameters() != null) { - CodingParameters codingParameters = j2k.getCodingParameters(); + if (j2kInfo.getCodingParameters() != null) { + CodingParameters codingParameters = j2kInfo.getCodingParameters(); if (codingParameters.getComment() != null) { codingParameters.setComment(null); @@ -1865,25 +1911,26 @@ public void j2kDestroyCompression(J2K j2k) { codingParameters.getTcps()[tileNo].setTccps(null); } codingParameters.setTcps(null); - codingParameters = null; } - - j2k = null; } - public void j2kSetupEncoder(J2K j2k, CompressionParameters parameters, OpenJpegImage image, boolean USE_JPWL) { + @SuppressWarnings({ "java:S1659", "java:S3776", "java:S6541" }) + public void j2kSetupEncoder(J2K j2kInfo, CompressionParameters parameters, OpenJpegImage image, boolean useJPWL) { int i, j, tileNo, noOfPocsInTile; CodingParameters codingParameters = null; - if (j2k == null || parameters == null || image == null) { + if (j2kInfo == null || parameters == null || image == null) { return; } /* create and initialize the coding parameters structure */ codingParameters = new CodingParameters(); - /* keep a link to codingParameters so that we can destroy it later in j2kDestroyCompression */ - j2k.setCodingParameters(codingParameters); + /* + * keep a link to codingParameters so that we can destroy it later in + * j2kDestroyCompression + */ + j2kInfo.setCodingParameters(codingParameters); /* set default values for codingParameters */ codingParameters.setTileWidth(1); @@ -1901,9 +1948,9 @@ public void j2kSetupEncoder(J2K j2k, CompressionParameters parameters, OpenJpegI /* mod fixed_quality */ if (parameters.getCpMatrice() != null) { - int array_size = parameters.getTcpNoOfLayers() * parameters.getNoOfResolution() * 3; - codingParameters.setMatrice(new int[array_size]); - System.arraycopy(parameters.getCpMatrice(), 0, codingParameters.getMatrice(), 0, array_size); + int arraySize = parameters.getTcpNoOfLayers() * parameters.getNoOfResolution() * 3; + codingParameters.setMatrice(new int[arraySize]); + System.arraycopy(parameters.getCpMatrice(), 0, codingParameters.getMatrice(), 0, arraySize); } /* tiles */ @@ -1918,7 +1965,8 @@ public void j2kSetupEncoder(J2K j2k, CompressionParameters parameters, OpenJpegI if (parameters.getCpComment() != null) { codingParameters.setComment(new char[parameters.getCpComment().length + 1]); if (codingParameters.getComment() != null) { - System.arraycopy(parameters.getCpComment(), 0, codingParameters.getComment(), 0, parameters.getCpComment().length); + System.arraycopy(parameters.getCpComment(), 0, codingParameters.getComment(), 0, + parameters.getCpComment().length); } } @@ -1926,8 +1974,10 @@ public void j2kSetupEncoder(J2K j2k, CompressionParameters parameters, OpenJpegI * calculate other encoding parameters */ if (parameters.getTileSizeOn() != 0) { - codingParameters.setTileWidth(MathUtil.intCeilDiv(image.getX1() - codingParameters.getTileX0(), codingParameters.getTileDX())); - codingParameters.setTileHeight(MathUtil.intCeilDiv(image.getY1() - codingParameters.getTileY0(), codingParameters.getTileDY())); + codingParameters.setTileWidth(MathUtil.getInstance() + .intCeilDiv(image.getX1() - codingParameters.getTileX0(), codingParameters.getTileDX())); + codingParameters.setTileHeight(MathUtil.getInstance() + .intCeilDiv(image.getY1() - codingParameters.getTileY0(), codingParameters.getTileDY())); } else { codingParameters.setTileDX(image.getX1() - codingParameters.getTileX0()); codingParameters.setTileDY(image.getY1() - codingParameters.getTileY0()); @@ -1940,11 +1990,11 @@ public void j2kSetupEncoder(J2K j2k, CompressionParameters parameters, OpenJpegI codingParameters.setImageSize(0); for (i = 0; i < image.getNoOfComps(); i++) { - codingParameters.setImageSize(codingParameters.getImageSize() - + (image.getComps()[i].getWidth() * image.getComps()[i].getHeight() * image.getComps()[i].getPrec())); + codingParameters.setImageSize(codingParameters.getImageSize() + (image.getComps()[i].getWidth() + * image.getComps()[i].getHeight() * image.getComps()[i].getPrec())); } - if (USE_JPWL) { + if (useJPWL) { /* * calculate JPWL encoding parameters */ @@ -2028,7 +2078,8 @@ public void j2kSetupEncoder(J2K j2k, CompressionParameters parameters, OpenJpegI /* initialisation of POC */ tcp.setIsPoc(1); for (i = 0; i < parameters.getNoOfPocs(); i++) { - if ((tileNo == parameters.getPocs()[i].getTile() - 1) || (parameters.getPocs()[i].getTile() == -1)) { + if ((tileNo == parameters.getPocs()[i].getTile() - 1) + || (parameters.getPocs()[i].getTile() == -1)) { Poc tcpPoc = tcp.getPocs()[noOfPocsInTile]; tcpPoc.setResNo0(parameters.getPocs()[noOfPocsInTile].getResNo0()); tcpPoc.setCompNo0(parameters.getPocs()[noOfPocsInTile].getCompNo0()); @@ -2052,8 +2103,8 @@ public void j2kSetupEncoder(J2K j2k, CompressionParameters parameters, OpenJpegI TileComponentCodingParameters tccp = tcp.getTccps()[i]; tccp.setCodingStyle(parameters.getCodingStyle() & 0x01); /* 0 => one precinct || 1 => custom precinct */ tccp.setNoOfResolutions(parameters.getNoOfResolution()); - tccp.setCodeBlockWidth(MathUtil.intFloorLog2(parameters.getCodeBlockWidthInit())); - tccp.setCodeBlockHeight(MathUtil.intFloorLog2(parameters.getCodeBlockHeightInit())); + tccp.setCodeBlockWidth(MathUtil.getInstance().intFloorLog2(parameters.getCodeBlockWidthInit())); + tccp.setCodeBlockHeight(MathUtil.getInstance().intFloorLog2(parameters.getCodeBlockHeightInit())); tccp.setCodeBlockStyle(parameters.getMode()); tccp.setQmfbid(parameters.getIrreversible() != 0 ? 0 : 1); tccp.setQuantisationStyle(parameters.getIrreversible() != 0 ? OpenJpegConstant.J2K_CCP_QNTSTY_SEQNT @@ -2083,37 +2134,37 @@ public void j2kSetupEncoder(J2K j2k, CompressionParameters parameters, OpenJpegI if (parameters.getPrecinctWidthInit()[p] < 1) { tccp.getPrecinctWidth()[j] = 1; } else { - tccp.getPrecinctWidth()[j] = MathUtil.intFloorLog2(parameters.getPrecinctWidthInit()[p]); + tccp.getPrecinctWidth()[j] = MathUtil.getInstance() + .intFloorLog2(parameters.getPrecinctWidthInit()[p]); } if (parameters.getPrecinctWidthInit()[p] < 1) { tccp.getPrecinctHeight()[j] = 1; } else { - tccp.getPrecinctHeight()[j] = MathUtil.intFloorLog2(parameters.getPrecinctWidthInit()[p]); + tccp.getPrecinctHeight()[j] = MathUtil.getInstance() + .intFloorLog2(parameters.getPrecinctWidthInit()[p]); } } else { int resSpec = parameters.getResSpec(); - int sizePrcWidth = parameters.getPrecinctWidthInit()[resSpec - 1] >> (p - (resSpec - 1)); - int sizePrcHeight = parameters.getPrecinctWidthInit()[resSpec - 1] >> (p - (resSpec - 1)); + int sizePrcWidth = parameters.getPrecinctWidthInit()[resSpec - 1] >> (p + - (resSpec - 1)); + int sizePrcHeight = parameters.getPrecinctWidthInit()[resSpec - 1] >> (p + - (resSpec - 1)); if (sizePrcWidth < 1) { tccp.getPrecinctWidth()[j] = 1; } else { - tccp.getPrecinctWidth()[j] = MathUtil.intFloorLog2(sizePrcWidth); + tccp.getPrecinctWidth()[j] = MathUtil.getInstance().intFloorLog2(sizePrcWidth); } if (sizePrcHeight < 1) { tccp.getPrecinctHeight()[j] = 1; } else { - tccp.getPrecinctHeight()[j] = MathUtil.intFloorLog2(sizePrcHeight); + tccp.getPrecinctHeight()[j] = MathUtil.getInstance().intFloorLog2(sizePrcHeight); } } p++; - /* - * printf("\nsize precinct for level %d : %d,%d\n", j,tccp.getPrecinctWidth()[j], - * tccp.getPrecinctHeight()[j]); - */ } // end for } else { for (j = 0; j < tccp.getNoOfResolutions(); j++) { @@ -2128,40 +2179,40 @@ public void j2kSetupEncoder(J2K j2k, CompressionParameters parameters, OpenJpegI } } - public int j2kEncode(J2K j2k, Cio cio, OpenJpegImage image, CodeStreamInfo codeStreamInfo, - boolean USE_JPWL) { + @SuppressWarnings({ "java:S125", "java:S1659", "java:S3776", "java:S6541" }) + public int j2kEncode(J2K j2kInfo, Cio cio, OpenJpegImage image, CodeStreamInfo codeStreamInfo, boolean useJPWL) { int tileNo, compNo; CodingParameters codingParameters = null; Tcd tcd = null; /* TCD component */ - j2k.setCio(cio); - j2k.setImage(image); + j2kInfo.setCio(cio); + j2kInfo.setImage(image); - codingParameters = j2k.getCodingParameters(); - - /* j2k_dump_cp(stdout, image, codingParameters); */ + codingParameters = j2kInfo.getCodingParameters(); /* INDEX >> */ - j2k.setCodeStreamInfo(codeStreamInfo); + j2kInfo.setCodeStreamInfo(codeStreamInfo); if (codeStreamInfo != null) { - codeStreamInfo.setTileInfo(new TileInfo[codingParameters.getTileWidth() * codingParameters.getTileHeight()]); + codeStreamInfo + .setTileInfo(new TileInfo[codingParameters.getTileWidth() * codingParameters.getTileHeight()]); codeStreamInfo.setImageWidth(image.getX1() - image.getX0()); codeStreamInfo.setImageHeight(image.getY1() - image.getY0()); codeStreamInfo.setProgOrder(codingParameters.getTcps()[0].getProgressionOrder()); codeStreamInfo.setTileWidth(codingParameters.getTileWidth()); codeStreamInfo.setTileHeight(codingParameters.getTileHeight()); - codeStreamInfo.setTileX(codingParameters.getTileDX()); - codeStreamInfo.setTileY(codingParameters.getTileDY()); - codeStreamInfo.setTileOX(codingParameters.getTileX0()); - codeStreamInfo.setTileOY(codingParameters.getTileY0()); + codeStreamInfo.setTileX(codingParameters.getTileDX()); + codeStreamInfo.setTileY(codingParameters.getTileDY()); + codeStreamInfo.setTileOX(codingParameters.getTileX0()); + codeStreamInfo.setTileOY(codingParameters.getTileY0()); codeStreamInfo.setNoOfComps(image.getNoOfComps()); codeStreamInfo.setNoOfLayers(codingParameters.getTcps()[0].getNoOfLayers()); codeStreamInfo.setNoOfDecompositionComps(new int[image.getNoOfComps()]); for (compNo = 0; compNo < image.getNoOfComps(); compNo++) { - codeStreamInfo.getNoOfDecompositionComps()[compNo] = codingParameters.getTcps()[0].getTccps()[0].getNoOfResolutions() - 1; + codeStreamInfo.getNoOfDecompositionComps()[compNo] = codingParameters.getTcps()[0].getTccps()[0] + .getNoOfResolutions() - 1; } - codeStreamInfo.setDistortionMax(0.0); + codeStreamInfo.setDistortionMax(0.0); codeStreamInfo.setMainHeadStart(CioHelper.getInstance().cioTell(cio)); /* position of SOC */ codeStreamInfo.setMaxMarkerNo(100); codeStreamInfo.setMarkers(new MarkerInfo[codeStreamInfo.getMaxMarkerNo()]); @@ -2169,38 +2220,38 @@ public int j2kEncode(J2K j2k, Cio cio, OpenJpegImage image, CodeStreamInfo codeS } /* << INDEX */ - j2kWriteSoc(j2k, USE_JPWL); - j2kWriteSize(j2k); - j2kWriteCod(j2k); - j2kWriteQcd(j2k); + j2kWriteSoc(j2kInfo, useJPWL); + j2kWriteSize(j2kInfo); + j2kWriteCod(j2kInfo); + j2kWriteQcd(j2kInfo); if (codingParameters.getCinemaMode().value() != 0) { for (compNo = 1; compNo < image.getNoOfComps(); compNo++) { - j2kWriteCoc(j2k, compNo); - j2kWriteQcc(j2k, compNo); + j2kWriteCoc(j2kInfo, compNo); + j2kWriteQcc(j2kInfo, compNo); } } for (compNo = 0; compNo < image.getNoOfComps(); compNo++) { Tcp tcp = codingParameters.getTcps()[0]; if (tcp.getTccps()[compNo].getRoiShift() != 0) - j2kWriteRgn(j2k, compNo, 0); + j2kWriteRgn(j2kInfo, compNo, 0); } if (codingParameters.getComment() != null) { - j2kWriteCom(j2k); + j2kWriteCom(j2kInfo); } - j2k.setTotalNoOfTilePart(j2kCalculateTilePart(codingParameters, image.getNoOfComps(), image, j2k)); + j2kInfo.setTotalNoOfTilePart(j2kCalculateTilePart(codingParameters, image.getNoOfComps(), image, j2kInfo)); /* TLM Marker */ if (codingParameters.getCinemaMode().value() != 0) { - j2kWriteTlm(j2k); + j2kWriteTlm(j2kInfo); if (codingParameters.getCinemaMode() == JP2CinemeaMode.CINEMA4K_24) { - j2kWritePoc(j2k); + j2kWritePoc(j2kInfo); } } /* uncomment only for testing JPSEC marker writing */ - /* j2kWriteSec(j2k); */ + /* j2kWriteSec(j2kInfo); */ /* INDEX >> */ if (codeStreamInfo != null) { @@ -2210,7 +2261,7 @@ public int j2kEncode(J2K j2k, Cio cio, OpenJpegImage image, CodeStreamInfo codeS /**** Main Header ENDS here ***/ /* create the tile encoder */ - tcd = TcdHelper.getInstance().tcdCreate(j2k.getCodecContextInfo()); + tcd = TcdHelper.getInstance().tcdCreate(j2kInfo.getCodecContextInfo()); /* encode each tile */ for (tileNo = 0; tileNo < codingParameters.getTileWidth() * codingParameters.getTileHeight(); tileNo++) { @@ -2222,20 +2273,20 @@ public int j2kEncode(J2K j2k, Cio cio, OpenJpegImage image, CodeStreamInfo codeS Tcp tcp = codingParameters.getTcps()[tileNo]; - j2k.setCurTileNo(tileNo); - j2k.setCurTilePartNo(0); - tcd.setCurTotalNoOfTileParts(j2k.getCurTotalNoOfTilePart()[j2k.getCurTileNo()]); + j2kInfo.setCurTileNo(tileNo); + j2kInfo.setCurTilePartNo(0); + tcd.setCurTotalNoOfTileParts(j2kInfo.getCurTotalNoOfTilePart()[j2kInfo.getCurTileNo()]); /* initialisation before tile encoding */ if (tileNo == 0) { - TcdHelper.getInstance().tcdMallocEncode(tcd, image, codingParameters, j2k.getCurTileNo()); + TcdHelper.getInstance().tcdMallocEncode(tcd, image, codingParameters, j2kInfo.getCurTileNo()); } else { - TcdHelper.getInstance().tcdInitEncode(tcd, image, codingParameters, j2k.getCurTileNo()); + TcdHelper.getInstance().tcdInitEncode(tcd, image, codingParameters, j2kInfo.getCurTileNo()); } /* INDEX >> */ if (codeStreamInfo != null) { - codeStreamInfo.getTileInfo()[j2k.getCurTileNo()] - .setStartPosition(CioHelper.getInstance().cioTell(cio) + j2k.getPosCorrection()); + codeStreamInfo.getTileInfo()[j2kInfo.getCurTileNo()] + .setStartPosition(CioHelper.getInstance().cioTell(cio) + j2kInfo.getPosCorrection()); } /* << INDEX */ @@ -2248,50 +2299,51 @@ public int j2kEncode(J2K j2k, Cio cio, OpenJpegImage image, CodeStreamInfo codeS tcd.setTilePartPosition(codingParameters.getTilePartPosition()); for (tilePartNo = 0; tilePartNo < totalNoOfTilePart; tilePartNo++) { - j2k.setTilePartNo(tilePartNo); + j2kInfo.setTilePartNo(tilePartNo); /* INDEX >> */ if (codeStreamInfo != null) - codeStreamInfo.getTileInfo()[j2k.getCurTileNo()].getTp()[j2k.getCurTilePartNo()] - .setTpStartPosition(CioHelper.getInstance().cioTell(cio) + j2k.getPosCorrection()); + codeStreamInfo.getTileInfo()[j2kInfo.getCurTileNo()].getTp()[j2kInfo.getCurTilePartNo()] + .setTpStartPosition(CioHelper.getInstance().cioTell(cio) + j2kInfo.getPosCorrection()); /* << INDEX */ - j2kWriteSot(j2k, USE_JPWL); + j2kWriteSot(j2kInfo, useJPWL); - if (j2k.getCurTilePartNo() == 0 && codingParameters.getCinemaMode().value() == 0) { + if (j2kInfo.getCurTilePartNo() == 0 && codingParameters.getCinemaMode().value() == 0) { for (compNo = 1; compNo < image.getNoOfComps(); compNo++) { - j2kWriteCoc(j2k, compNo); - j2kWriteQcc(j2k, compNo); + j2kWriteCoc(j2kInfo, compNo); + j2kWriteQcc(j2kInfo, compNo); } if (codingParameters.getTcps()[tileNo].getNoOfPocs() != 0) { - j2kWritePoc(j2k); + j2kWritePoc(j2kInfo); } } /* INDEX >> */ if (codeStreamInfo != null) - codeStreamInfo.getTileInfo()[j2k.getCurTileNo()].getTp()[j2k.getCurTilePartNo()] - .setTpEndHeader(CioHelper.getInstance().cioTell(cio) + j2k.getPosCorrection() + 1); + codeStreamInfo.getTileInfo()[j2kInfo.getCurTileNo()].getTp()[j2kInfo.getCurTilePartNo()] + .setTpEndHeader(CioHelper.getInstance().cioTell(cio) + j2kInfo.getPosCorrection() + 1); /* << INDEX */ - j2kWriteSod(j2k, tcd, USE_JPWL); + j2kWriteSod(j2kInfo, tcd, useJPWL); /* INDEX >> */ if (codeStreamInfo != null) { - codeStreamInfo.getTileInfo()[j2k.getCurTileNo()].getTp()[j2k.getCurTilePartNo()] - .setTpEndPosition(CioHelper.getInstance().cioTell(cio) + j2k.getPosCorrection() - 1); - codeStreamInfo.getTileInfo()[j2k.getCurTileNo()].getTp()[j2k.getCurTilePartNo()] + codeStreamInfo.getTileInfo()[j2kInfo.getCurTileNo()].getTp()[j2kInfo.getCurTilePartNo()] + .setTpEndPosition( + CioHelper.getInstance().cioTell(cio) + j2kInfo.getPosCorrection() - 1); + codeStreamInfo.getTileInfo()[j2kInfo.getCurTileNo()].getTp()[j2kInfo.getCurTilePartNo()] .setTpStartPacket(accPackNo); - codeStreamInfo.getTileInfo()[j2k.getCurTileNo()].getTp()[j2k.getCurTilePartNo()] + codeStreamInfo.getTileInfo()[j2kInfo.getCurTileNo()].getTp()[j2kInfo.getCurTilePartNo()] .setTpNoOfPackets(codeStreamInfo.getPacketNo() - accPackNo); accPackNo = codeStreamInfo.getPacketNo(); } /* << INDEX */ - j2k.setCurTilePartNo(j2k.getCurTilePartNo() + 1); + j2kInfo.setCurTilePartNo(j2kInfo.getCurTilePartNo() + 1); } } if (codeStreamInfo != null) { - codeStreamInfo.getTileInfo()[j2k.getCurTileNo()] - .setEndPosition(CioHelper.getInstance().cioTell(cio) + j2k.getPosCorrection() - 1); + codeStreamInfo.getTileInfo()[j2kInfo.getCurTileNo()] + .setEndPosition(CioHelper.getInstance().cioTell(cio) + j2kInfo.getPosCorrection() - 1); } } @@ -2299,12 +2351,12 @@ public int j2kEncode(J2K j2k, Cio cio, OpenJpegImage image, CodeStreamInfo codeS TcdHelper.getInstance().tcdFreeEncode(tcd); TcdHelper.getInstance().tcdDestroy(tcd); - j2k.setCurTotalNoOfTilePart(null); + j2kInfo.setCurTotalNoOfTilePart(null); - j2kWriteEoc(j2k, USE_JPWL); + j2kWriteEoc(j2kInfo, useJPWL); if (codeStreamInfo != null) { - codeStreamInfo.setCodeStreamSize(CioHelper.getInstance().cioTell(cio) + j2k.getPosCorrection()); + codeStreamInfo.setCodeStreamSize(CioHelper.getInstance().cioTell(cio) + j2kInfo.getPosCorrection()); /* UniPG>> */ /* The following adjustment is done to adjust the codestream size */ /* if SOD is not at 0 in the buffer. Useful in case of JP2, where */ @@ -2313,20 +2365,18 @@ public int j2kEncode(J2K j2k, Cio cio, OpenJpegImage image, CodeStreamInfo codeS /* < 16384) { - LOGGER.error(String.format("Invalid number of components specified while setting up JP2 encoder")); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE,LOGGER_EMPTY, + "Invalid number of components specified while setting up JP2 encoder"); return; } - this.getJ2k().j2kSetupEncoder(jp2.getJ2k(), parameters, image, USE_JPWL); + this.getJ2k().j2kSetupEncoder(jp2.getJ2k(), parameters, image, useJPWL); /* setup the JP2 codec */ /* ------------------- */ @@ -627,12 +635,12 @@ public void jp2SetupEncoder(JP2 jp2, CompressionParameters parameters, OpenJpegI jp2.setNoOfComps(image.getNoOfComps()); /* NC */ jp2.setComps(new JP2Component[(int) jp2.getNoOfComps()]); - jp2.setHeight(image.getY1() - image.getY0()); /* HEIGHT */ - jp2.setWidth(image.getX1() - image.getX0()); /* WIDTH */ + jp2.setHeight((long) image.getY1() - image.getY0()); /* HEIGHT */ + jp2.setWidth((long) image.getX1() - image.getX0()); /* WIDTH */ /* BPC */ depth0 = image.getComps()[0].getPrec() - 1; sign = image.getComps()[0].getSgnd(); - jp2.setBpc(depth0 + (sign << 7)); + jp2.setBpc(depth0 + (long) (sign << 7)); for (i = 1; i < image.getNoOfComps(); i++) { int depth = image.getComps()[i].getPrec() - 1; sign = image.getComps()[i].getSgnd(); @@ -670,7 +678,7 @@ else if (image.getColorSpace() == Jp2ColorSpace.CLRSPC_SYCC) jp2.setApprox(0); /* APPROX */ } - public int jp2Encode(JP2 jp2, Cio cio, OpenJpegImage image, CodeStreamInfo codeStreamInfo, boolean USE_JPWL) { + public int jp2Encode(JP2 jp2, Cio cio, OpenJpegImage image, CodeStreamInfo codeStreamInfo, boolean useJPWL) { /* JP2 encoding */ /* JPEG 2000 Signature box */ @@ -682,11 +690,11 @@ public int jp2Encode(JP2 jp2, Cio cio, OpenJpegImage image, CodeStreamInfo codeS /* J2K encoding */ - if (jp2WriteJP2c(jp2, cio, image, codeStreamInfo, USE_JPWL) == 0) { - LOGGER.error(String.format("Failed to encode image")); + if (jp2WriteJP2c(jp2, cio, image, codeStreamInfo, useJPWL) == 0) { + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "Failed to encode image"); return 0; } return 1; } -} +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/JPTHelper.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/JPTHelper.java index 65f71d9..5221917 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/JPTHelper.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/JPTHelper.java @@ -1,20 +1,40 @@ package io.mosip.imagedecoder.openjpeg; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_EMPTY; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_IDTYPE; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_SESSIONID; + +import io.mosip.kernel.core.logger.spi.Logger; +import io.mosip.imagedecoder.logger.ImageDecoderLogger; import io.mosip.imagedecoder.model.openjpeg.Cio; import io.mosip.imagedecoder.model.openjpeg.CodecContextInfo; import io.mosip.imagedecoder.model.openjpeg.JPTMessageHeader; public class JPTHelper { - private static Logger LOGGER = LoggerFactory.getLogger(JPTHelper.class); + private Logger logger = ImageDecoderLogger.getLogger(JPTHelper.class); /* - * Read the information contains in VBAS [JPP/JPT stream message header] - * Store information (7 bits) in value + * Read the information contains in VBAS [JPP/JPT stream message header] Store + * information (7 bits) in value * */ - private static long jptReadVBASInfo(Cio cio, long value) { + + // Static variable reference of singleInstance of type Singleton + private static JPTHelper singleInstance = null; + + private JPTHelper() { + super(); + } + + // synchronized method to control simultaneous access + public static synchronized JPTHelper getInstance() { + if (singleInstance == null) + singleInstance = new JPTHelper(); + + return singleInstance; + } + + private long jptReadVBASInfo(Cio cio, long value) { byte element; element = (byte) CioHelper.getInstance().cioRead(cio, 1); @@ -30,17 +50,17 @@ private static long jptReadVBASInfo(Cio cio, long value) { } /* - * Initialize the value of the message header structure + * Initialize the value of the message header structure * */ - public static void jptInitMsgHeader(JPTMessageHeader header) { - header.setId(0); /* In-class Identifier */ - header.setLastByte(0); /* Last byte information */ - header.setClassId(0); /* Class Identifier */ - header.setCSnId(0); /* CSn : index identifier */ - header.setMsgOffset(0); /* Message offset */ - header.setMsgLength(0); /* Message length */ - header.setLayerNb(0); /* Auxiliary for JPP case */ + public void jptInitMsgHeader(JPTMessageHeader header) { + header.setId(0); /* In-class Identifier */ + header.setLastByte(0); /* Last byte information */ + header.setClassId(0); /* Class Identifier */ + header.setCSnId(0); /* CSn : index identifier */ + header.setMsgOffset(0); /* Message offset */ + header.setMsgLength(0); /* Message length */ + header.setLayerNb(0); /* Auxiliary for JPP case */ } /* @@ -49,19 +69,20 @@ public static void jptInitMsgHeader(JPTMessageHeader header) { * Only parameters always present in message header * */ - private static void jptReInitMsgHeader(JPTMessageHeader header) { - header.setId(0); /* In-class Identifier */ - header.setLastByte(0); /* Last byte information */ - header.setMsgOffset(0); /* Message offset */ - header.setMsgLength(0); /* Message length */ + private void jptReInitMsgHeader(JPTMessageHeader header) { + header.setId(0); /* In-class Identifier */ + header.setLastByte(0); /* Last byte information */ + header.setMsgOffset(0); /* Message offset */ + header.setMsgLength(0); /* Message length */ } /* * Read the message header for a JPP/JPT - stream * */ - public static void jptReadMsgHeader(CodecContextInfo cinfo, Cio cio, JPTMessageHeader header) { - byte element, classId = 0, cSn = 0; + @SuppressWarnings({ "java:S1172" }) + public void jptReadMsgHeader(CodecContextInfo cinfo, Cio cio, JPTMessageHeader header) { + byte element, classId = 0, cSn = 0; // NOSONAR jptReInitMsgHeader(header); /* ------------- */ @@ -71,23 +92,23 @@ public static void jptReadMsgHeader(CodecContextInfo cinfo, Cio cio, JPTMessageH /* See for Class and CSn */ switch ((element >> 5) & 0x03) { - case 0: - LOGGER.error(String.format("Forbidden value encounter in message header !!")); - break; - case 1: - classId = 0; - cSn = 0; - break; - case 2: - classId = 1; - cSn = 0; - break; - case 3: - classId = 1; - cSn = 1; - break; - default: - break; + case 0: + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "Forbidden value encounter in message header !!"); + break; + case 1: + classId = 0; + cSn = 0; + break; + case 2: + classId = 1; + cSn = 0; + break; + case 3: + classId = 1; + cSn = 1; + break; + default: + break; } /* see information on bits 'c' [p 10 : A.2.1 general, ISO/IEC FCD 15444-9] */ diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/MQCoderHelper.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/MQCoderHelper.java index 691727a..2f4c60b 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/MQCoderHelper.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/MQCoderHelper.java @@ -4,6 +4,7 @@ import io.mosip.imagedecoder.model.openjpeg.MQCoder; import io.mosip.imagedecoder.model.openjpeg.MQCoderState; +@SuppressWarnings({ "java:S3008"}) public class MQCoderHelper { /* */ /* This array defines all the possible states for a context. */ @@ -163,7 +164,6 @@ private void mqcSetBits(MQCoder mqc) { private void mqcByteIn(MQCoder mqc) { if (mqc.getBpIndex() < (mqc.getEnd())) { long c; - // if (mqc.getBp()[mqc.getBpIndex() + 1] != mqc.getBp()[mqc.getEnd()-1]) { if ((mqc.getBpIndex() + 1) < (mqc.getEnd())) { c = (mqc.getBp()[mqc.getBpIndex() + 1] & 0xff); } else { @@ -201,21 +201,20 @@ private void mqcRenormalizationD(MQCoder mqc) { } public MQCoder mqcCreate() { - MQCoder mqc = new MQCoder(); - return mqc; + return new MQCoder(); } + @SuppressWarnings({ "java:S1186"}) public void mqcDestroy(MQCoder mqc) { - if (mqc != null) { - mqc = null; - } } public int mqcNoOfBytes(MQCoder mqc) { return mqc.getBpIndex() - mqc.getStart(); } - public void mqcInitEncode(MQCoder mqc, byte[] bp, int bpIndex) { + @SuppressWarnings("unused") + public void mqcInitEncode(MQCoder mqc, byte[] bp, int bpIndex) + { mqcSetCurrentContext(mqc, 0); mqc.setA(0x8000); mqc.setC(0); @@ -251,9 +250,6 @@ public void mqcFlush(MQCoder mqc) { public void mqcBypassInitEncode(MQCoder mqc) { mqc.setC(0); mqc.setCt(8); - /* - * if (*mqc->bp == 0xff) { mqc->ct = 7; } - */ } public void mqcBypassEncode(MQCoder mqc, int d) { @@ -285,7 +281,6 @@ public int mqcBypassFlushEncode(MQCoder mqc) { mqc.getBp()[mqc.getBpIndex()] = (byte) mqc.getC(); mqc.setCt(8); mqc.setC(0); - ; } return 1; diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/MctHelper.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/MctHelper.java index 851d8a9..e57816e 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/MctHelper.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/MctHelper.java @@ -8,21 +8,20 @@ */ public class MctHelper { // Static variable reference of singleInstance of type Singleton - private static MctHelper singleInstance = null; - private MctHelper() - { - super (); - } - - //synchronized method to control simultaneous access - public static synchronized MctHelper getInstance() - { + private static MctHelper singleInstance = null; + + private MctHelper() { + super(); + } + + // synchronized method to control simultaneous access + public static synchronized MctHelper getInstance() { if (singleInstance == null) singleInstance = new MctHelper(); - - return singleInstance; + + return singleInstance; } - + /* */ /* Foward reversible MCT. */ /* */ @@ -109,8 +108,10 @@ public double mctGetNormReal(int compno) { return OpenJpegConstant.MCT_NORMS_REAL[compno]; } - private int fixMul(int a, int b) { - long temp = a * b; + @SuppressWarnings({ "unused"}) + private int fixMul(int a, int b) + { + long temp = (long)a * b; temp += temp & 4096; return (int) (temp >> 13); } diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/OpenJpegDecoder.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/OpenJpegDecoder.java index 93153a0..0f430c9 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/OpenJpegDecoder.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/OpenJpegDecoder.java @@ -1,9 +1,13 @@ package io.mosip.imagedecoder.openjpeg; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_EMPTY; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_IDTYPE; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_SESSIONID; + import java.awt.image.BufferedImage; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import io.mosip.kernel.core.logger.spi.Logger; +import io.mosip.imagedecoder.logger.ImageDecoderLogger; import io.mosip.imagedecoder.constant.DecoderConstant; import io.mosip.imagedecoder.constant.DecoderErrorCodes; @@ -11,7 +15,6 @@ import io.mosip.imagedecoder.model.DecoderResponseInfo; import io.mosip.imagedecoder.model.Response; import io.mosip.imagedecoder.model.openjpeg.Cio; -import io.mosip.imagedecoder.model.openjpeg.CodecContextInfo; import io.mosip.imagedecoder.model.openjpeg.DecompressionContextInfo; import io.mosip.imagedecoder.model.openjpeg.DecompressionParameters; import io.mosip.imagedecoder.model.openjpeg.JP2CodecFormat; @@ -29,12 +32,13 @@ * */ public class OpenJpegDecoder implements IImageDecoderApi { - private Logger LOGGER = LoggerFactory.getLogger(OpenJpegDecoder.class); + private Logger logger = ImageDecoderLogger.getLogger(OpenJpegDecoder.class); private OpenJpegHelper decoder = new OpenJpegHelper(); @Override + @SuppressWarnings({ "java:S1659", "java:S3776", "java:S6541" }) public Response decode(DecoderRequestInfo requestInfo) { - Response response = new Response(); + Response response = new Response<>(); OpenJpegImage image = null; Cio cio = null; DecompressionContextInfo dInfo = null; @@ -50,110 +54,100 @@ public Response decode(DecoderRequestInfo requestInfo) { JP2ResolutionBox resolutionBox = null; dInfo = decoder.createDecompression(JP2CodecFormat.CODEC_JP2); if (dInfo != null) { - boolean USE_JPWL = false; + boolean useJPWL = false; DecompressionParameters parameters = new DecompressionParameters(); - decoder.setDefaultDecoderParameters(parameters, USE_JPWL); - decoder.setupDecoder(dInfo, parameters, USE_JPWL); - cio = CioHelper.getInstance().cioOpen((CodecContextInfo) dInfo, requestInfo.getImageData(), requestInfo.getImageData().length); + decoder.setDefaultDecoderParameters(parameters, useJPWL); + decoder.setupDecoder(dInfo, parameters, useJPWL); + cio = CioHelper.getInstance().cioOpen(dInfo, requestInfo.getImageData(), + requestInfo.getImageData().length); if (cio != null) { - image = decoder.decode(dInfo, cio, USE_JPWL); + image = decoder.decode(dInfo, cio, useJPWL); if (image != null) { width = image.getX1() - image.getX0(); height = image.getY1() - image.getY0(); components = image.getNoOfComps(); totalSize = width * height; outImage = new int[totalSize * components]; - totalSizeWithComp = components * totalSize; + totalSizeWithComp = components * totalSize; transform = image.getQmfbid(); resolutionBox = image.getResolutionBox(); - + int nIndex = 0; for (int i = 0; i < components; i++) { if (image.getComps()[i] != null && image.getComps()[i].getData() != null) System.arraycopy(image.getComps()[i].getData(), 0, outImage, nIndex, totalSize); nIndex += totalSize; } + responseInfo.setAllInfo(requestInfo.isAllInfo()); responseInfo.setImageType(DecoderConstant.IMAGE_TYPE_JP2000); responseInfo.setImageWidth(width + ""); responseInfo.setImageHeight(height + ""); - - if (components > 0 && components < 4) { - responseInfo.setImageLossless(transform == 1 ? "1" : "0"); - if (resolutionBox != null) - { - responseInfo.setImageDpiHorizontal(resolutionBox.getHorizontalResolution() + ""); - responseInfo.setImageDpiVertical(resolutionBox.getVerticalResolution() + ""); - } - else { - responseInfo.setImageDpiHorizontal(-1 + ""); - responseInfo.setImageDpiVertical(-1 + ""); - } - if (image.getColorSpace() == Jp2ColorSpace.CLRSPC_GRAY) - { - responseInfo.setImageColorSpace("GRAY" + ""); - responseInfo.setImageDepth((8 * components) + ""); - } - else if (image.getColorSpace() == Jp2ColorSpace.CLRSPC_SRGB) - { - responseInfo.setImageColorSpace("RGB" + ""); - responseInfo.setImageDepth((8 * components) + ""); + + if (requestInfo.isAllInfo()) { + if (components > 0 && components < 4) { + responseInfo.setImageLossless(transform == 1 ? "1" : "0"); + if (resolutionBox != null) { + responseInfo.setImageDpiHorizontal(resolutionBox.getHorizontalResolution() + ""); + responseInfo.setImageDpiVertical(resolutionBox.getVerticalResolution() + ""); + } else { + responseInfo.setImageDpiHorizontal(-1 + ""); + responseInfo.setImageDpiVertical(-1 + ""); + } + if (image.getColorSpace() == Jp2ColorSpace.CLRSPC_GRAY) { + responseInfo.setImageColorSpace("GRAY" + ""); + responseInfo.setImageDepth((8 * components) + ""); + } else if (image.getColorSpace() == Jp2ColorSpace.CLRSPC_SRGB) { + responseInfo.setImageColorSpace("RGB" + ""); + responseInfo.setImageDepth((8 * components) + ""); + } + responseInfo.setImageSize(totalSizeWithComp + ""); + responseInfo.setImageData(Base64UrlUtil.getInstance() + .encodeToURLSafeBase64(ImageUtil.getInstance().integersToBytes(outImage)) + ""); + responseInfo.setImageAspectRatio( + ImageUtil.getInstance().calculateAspectRatio(width, height) + ""); + responseInfo.setImageCompressionRatio(ImageUtil.getInstance().calculateCompressionRatio( + width, height, components, requestInfo.getImageData().length) + " : 1"); } - responseInfo.setImageSize(totalSizeWithComp + ""); - responseInfo.setImageData(Base64UrlUtil.encodeToURLSafeBase64(ImageUtil.integersToBytes (outImage)) + ""); - responseInfo.setImageAspectRatio(ImageUtil.calculateAspectRatio(width, height) + ""); - responseInfo.setImageCompressionRatio(ImageUtil.calculateCompressionRatio(width, height, components, requestInfo.getImageData().length) + " : 1"); } - - if (requestInfo.isBufferedImage()) - { - BufferedImage bufferedImage = null; - try - { - BufferedImage bi = null; - try - { - if (image.getColorSpace() == Jp2ColorSpace.CLRSPC_GRAY) - { - bufferedImage = ImageUtil.fromByteGray(width, height, ImageUtil.integersToBytes (outImage)); - } - else if (image.getColorSpace() == Jp2ColorSpace.CLRSPC_SRGB) - { - bufferedImage = ImageUtil.fromJ2kImage(width, height, image); - } - } - catch(Exception ex) { - ex.printStackTrace(); - } - responseInfo.setBufferedImage(bufferedImage); - } - catch(Exception ex) - { - ex.printStackTrace(); - responseInfo.setBufferedImage(null); - } + + if (requestInfo.isBufferedImage()) { + responseInfo.setBufferedImage(getBufferedImage(image, outImage, width, height)); } - response.setResponse(responseInfo); + response.setResponse(responseInfo); response.setStatusCode(0); response.setStatusMessage(DecoderErrorCodes.SUCCESS.getErrorMessage()); - return response; + return response; } } } - - response.setResponse(null); + + response.setResponse(null); response.setStatusCode(-500); response.setStatusMessage(DecoderErrorCodes.TECHNICAL_ERROR_EXCEPTION.getErrorMessage()); } catch (Exception ex) { - LOGGER.error("decode ", ex); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "decode", ex); response.setStatusCode(-1); response.setStatusMessage(ex.getLocalizedMessage()); - } - finally - { + } finally { ImageHelper.getInstance().imageDestroy(image); CioHelper.getInstance().cioClose(cio); decoder.destroyDecompression(dInfo); } return response; } -} + + private BufferedImage getBufferedImage(OpenJpegImage image, int[] outImage, int width, int height) { + BufferedImage bufferedImage = null; + try { + if (image.getColorSpace() == Jp2ColorSpace.CLRSPC_GRAY) { + bufferedImage = ImageUtil.getInstance().fromByteGray(width, height, + ImageUtil.getInstance().integersToBytes(outImage)); + } else if (image.getColorSpace() == Jp2ColorSpace.CLRSPC_SRGB) { + bufferedImage = ImageUtil.getInstance().fromJ2kImage(width, height, image); + } + } catch (Exception ex) { + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "decode", ex); + } + return bufferedImage; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/OpenJpegHelper.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/OpenJpegHelper.java index f4068c7..a243656 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/OpenJpegHelper.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/OpenJpegHelper.java @@ -1,7 +1,11 @@ package io.mosip.imagedecoder.openjpeg; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_EMPTY; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_IDTYPE; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_SESSIONID; + +import io.mosip.kernel.core.logger.spi.Logger; +import io.mosip.imagedecoder.logger.ImageDecoderLogger; import io.mosip.imagedecoder.constant.openjpeg.OpenJpegConstant; import io.mosip.imagedecoder.model.openjpeg.Cio; @@ -21,7 +25,7 @@ import io.mosip.imagedecoder.model.openjpeg.TileInfo; public class OpenJpegHelper { - private Logger LOGGER = LoggerFactory.getLogger(OpenJpegHelper.class); + private Logger logger = ImageDecoderLogger.getLogger(OpenJpegHelper.class); private J2KHelper j2k = null; private JP2Helper jp2 = null; @@ -50,7 +54,8 @@ public void setJp2(JP2Helper jp2) { public String version() { return OpenJpegConstant.OPENJPEG_VERSION; } - + + @SuppressWarnings({ "java:S6208"}) public DecompressionContextInfo createDecompression(JP2CodecFormat format) { DecompressionContextInfo decompressionContextInfo = new DecompressionContextInfo(); decompressionContextInfo.getContextInfo().setIsDecompressor(1); @@ -58,20 +63,20 @@ public DecompressionContextInfo createDecompression(JP2CodecFormat format) { case CODEC_J2K: case CODEC_JPT: /* get a J2K decoder handle */ - decompressionContextInfo.getContextInfo().setJ2kHandle(this.getJ2k().j2kCreateDecompression(decompressionContextInfo)); + decompressionContextInfo.getContextInfo() + .setJ2kHandle(this.getJ2k().j2kCreateDecompression(decompressionContextInfo)); break; case CODEC_JP2: /* get a JP2 decoder handle */ - decompressionContextInfo.getContextInfo().setJp2Handle(this.getJp2().jp2CreateDecompression(decompressionContextInfo)); + decompressionContextInfo.getContextInfo() + .setJp2Handle(this.getJp2().jp2CreateDecompression(decompressionContextInfo)); break; case CODEC_UNKNOWN: default: - decompressionContextInfo = null; return null; } decompressionContextInfo.getContextInfo().setCodecFormat(format); - return decompressionContextInfo; } @@ -79,8 +84,7 @@ public void destroyDecompression(DecompressionContextInfo decompressionContextIn if (decompressionContextInfo != null) { /* destroy the codec */ switch (decompressionContextInfo.getContextInfo().getCodecFormat()) { - case CODEC_J2K: - case CODEC_JPT: + case CODEC_J2K, CODEC_JPT: this.getJ2k().j2kDestroyDecompression((J2K) decompressionContextInfo.getContextInfo().getJ2kHandle()); break; case CODEC_JP2: @@ -90,12 +94,10 @@ public void destroyDecompression(DecompressionContextInfo decompressionContextIn default: break; } - /* destroy the decompressor */ - decompressionContextInfo = null; } } - public void setDefaultDecoderParameters(DecompressionParameters parameters, boolean USE_JPWL) { + public void setDefaultDecoderParameters(DecompressionParameters parameters, boolean useJPWL) { if (parameters != null) { /* default decoding parameters */ parameters.setCpLayer(0); @@ -105,7 +107,7 @@ public void setDefaultDecoderParameters(DecompressionParameters parameters, bool parameters.setDecodeFormat(-1); parameters.setCodecFormat(-1); /* UniPG>> */ - if (USE_JPWL) { + if (useJPWL) { parameters.setJpwlCorrect(0); parameters.setJpwlExpComps(OpenJpegConstant.JPWL_EXPECTED_COMPONENTS); parameters.setJpwlMaxTiles(OpenJpegConstant.JPWL_MAXIMUM_TILES); @@ -114,17 +116,19 @@ public void setDefaultDecoderParameters(DecompressionParameters parameters, bool } } - public void setupDecoder(DecompressionContextInfo decompressionContextInfo, DecompressionParameters parameters, boolean USE_JPWL) { + @SuppressWarnings({ "java:S6208"}) + public void setupDecoder(DecompressionContextInfo decompressionContextInfo, DecompressionParameters parameters, + boolean useJPWL) { if (decompressionContextInfo != null && parameters != null) { switch (decompressionContextInfo.getContextInfo().getCodecFormat()) { case CODEC_J2K: case CODEC_JPT: - this.getJ2k().j2kSetupDecoder((J2K) decompressionContextInfo.getContextInfo().getJ2kHandle(), parameters, - USE_JPWL); + this.getJ2k().j2kSetupDecoder((J2K) decompressionContextInfo.getContextInfo().getJ2kHandle(), + parameters, useJPWL); break; case CODEC_JP2: - this.getJp2().jp2SetupDecoder((JP2) decompressionContextInfo.getContextInfo().getJp2Handle(), parameters, - USE_JPWL); + this.getJp2().jp2SetupDecoder((JP2) decompressionContextInfo.getContextInfo().getJp2Handle(), + parameters, useJPWL); break; case CODEC_UNKNOWN: default: @@ -133,23 +137,23 @@ public void setupDecoder(DecompressionContextInfo decompressionContextInfo, Deco } } - public OpenJpegImage decode(DecompressionContextInfo decompressionContextInfo, Cio cio, boolean USE_JPWL) { - return decodeWithInfo(decompressionContextInfo, cio, null, USE_JPWL); + public OpenJpegImage decode(DecompressionContextInfo decompressionContextInfo, Cio cio, boolean useJPWL) { + return decodeWithInfo(decompressionContextInfo, cio, null, useJPWL); } - public OpenJpegImage decodeWithInfo(DecompressionContextInfo decompressionContextInfo, Cio cio, CodeStreamInfo codeStreamInfo, - boolean USE_JPWL) { + public OpenJpegImage decodeWithInfo(DecompressionContextInfo decompressionContextInfo, Cio cio, + CodeStreamInfo codeStreamInfo, boolean useJPWL) { if (decompressionContextInfo != null && cio != null) { switch (decompressionContextInfo.getContextInfo().getCodecFormat()) { case CODEC_J2K: - return this.getJ2k().j2kDecode((J2K) decompressionContextInfo.getContextInfo().getJ2kHandle(), cio, codeStreamInfo, - USE_JPWL); + return this.getJ2k().j2kDecode((J2K) decompressionContextInfo.getContextInfo().getJ2kHandle(), cio, + codeStreamInfo, useJPWL); case CODEC_JPT: - return this.getJ2k().j2kDecodeJPTStream((J2K) decompressionContextInfo.getContextInfo().getJ2kHandle(), cio, - codeStreamInfo, USE_JPWL); + return this.getJ2k().j2kDecodeJPTStream((J2K) decompressionContextInfo.getContextInfo().getJ2kHandle(), + cio, codeStreamInfo, useJPWL); case CODEC_JP2: - return this.getJp2().jp2Decode((JP2) decompressionContextInfo.getContextInfo().getJp2Handle(), cio, codeStreamInfo, - USE_JPWL); + return this.getJp2().jp2Decode((JP2) decompressionContextInfo.getContextInfo().getJp2Handle(), cio, + codeStreamInfo, useJPWL); case CODEC_UNKNOWN: default: break; @@ -158,13 +162,15 @@ public OpenJpegImage decodeWithInfo(DecompressionContextInfo decompressionContex return null; } + @SuppressWarnings({ "java:S6208"}) public CompressionContextInfo createCompression(JP2CodecFormat format) { CompressionContextInfo compressionContextInfo = new CompressionContextInfo(); compressionContextInfo.getContextInfo().setIsDecompressor(0); switch (format) { case CODEC_J2K: /* get a J2K coder handle */ - compressionContextInfo.getContextInfo().setJ2kHandle(this.getJ2k().j2kCreateCompression(compressionContextInfo)); + compressionContextInfo.getContextInfo() + .setJ2kHandle(this.getJ2k().j2kCreateCompression(compressionContextInfo)); if (compressionContextInfo.getContextInfo().getJ2kHandle() == null) { compressionContextInfo = null; return compressionContextInfo; @@ -172,7 +178,8 @@ public CompressionContextInfo createCompression(JP2CodecFormat format) { break; case CODEC_JP2: /* get a JP2 coder handle */ - compressionContextInfo.getContextInfo().setJp2Handle(this.getJp2().jp2CreateCompression(compressionContextInfo)); + compressionContextInfo.getContextInfo() + .setJp2Handle(this.getJp2().jp2CreateCompression(compressionContextInfo)); if (compressionContextInfo.getContextInfo().getJp2Handle() == null) { compressionContextInfo = null; return compressionContextInfo; @@ -190,6 +197,7 @@ public CompressionContextInfo createCompression(JP2CodecFormat format) { return compressionContextInfo; } + @SuppressWarnings({ "java:S6208"}) public void destroyCompression(CompressionContextInfo compressionContextInfo) { if (compressionContextInfo != null) { /* destroy the codec */ @@ -206,11 +214,10 @@ public void destroyCompression(CompressionContextInfo compressionContextInfo) { break; } /* destroy the compressor */ - compressionContextInfo = null; } } - public void setDefaultEncodeParameters(CompressionParameters parameters, boolean USE_JPWL) { + public void setDefaultEncodeParameters(CompressionParameters parameters, boolean useJPWL) { if (parameters != null) { /* default coding parameters */ parameters.setCpCinemaMode(JP2CinemeaMode.OFF); @@ -231,82 +238,72 @@ public void setDefaultEncodeParameters(CompressionParameters parameters, boolean parameters.setCpDistortionAllocation(1); /* UniPG>> */ - if (USE_JPWL) { + if (useJPWL) { parameters.setJpwlEpcOn(0); parameters.setJpwlHprotMH(-1);/* -1 means unassigned */ - { - int i; - for (i = 0; i < OpenJpegConstant.JPWL_MAX_NO_TILESPECS; i++) { - parameters.getJpwlHprotTPHTileNo()[i] = -1; /* unassigned */ - parameters.getJpwlHprotTPH()[i] = 0; /* absent */ - } + int i; + for (i = 0; i < OpenJpegConstant.JPWL_MAX_NO_TILESPECS; i++) { + parameters.getJpwlHprotTPHTileNo()[i] = -1; /* unassigned */ + parameters.getJpwlHprotTPH()[i] = 0; /* absent */ } - ; - { - int i; - for (i = 0; i < OpenJpegConstant.JPWL_MAX_NO_PACKSPECS; i++) { - parameters.getJpwlPprotTileNo()[i] = -1; /* unassigned */ - parameters.getJpwlPprotPacketNo()[i] = -1; /* unassigned */ - parameters.getJpwlPprot()[i] = 0; /* absent */ - } + for (i = 0; i < OpenJpegConstant.JPWL_MAX_NO_PACKSPECS; i++) { + parameters.getJpwlPprotTileNo()[i] = -1; /* unassigned */ + parameters.getJpwlPprotPacketNo()[i] = -1; /* unassigned */ + parameters.getJpwlPprot()[i] = 0; /* absent */ } - ; parameters.setJpwlSensSize(0); /* 0 means no ESD */ parameters.setJpwlSensAddr(0); /* 0 means auto */ parameters.setJpwlSensRange(0); /* 0 means packet */ parameters.setJpwlSensMH(-1); /* -1 means unassigned */ - { - int i; - for (i = 0; i < OpenJpegConstant.JPWL_MAX_NO_TILESPECS; i++) { - parameters.getJpwlHprotTPHTileNo()[i] = -1; /* unassigned */ - parameters.getJpwlSensTPH()[i] = -1; /* absent */ - } + for (i = 0; i < OpenJpegConstant.JPWL_MAX_NO_TILESPECS; i++) { + parameters.getJpwlHprotTPHTileNo()[i] = -1; /* unassigned */ + parameters.getJpwlSensTPH()[i] = -1; /* absent */ } - ; } /* <= comp.getNoOfResolutions()) { continue; @@ -60,7 +60,7 @@ private int piNextLRCP(PiIterator pi) { } for (pi.setPrecNo(pi.getPoc().getPrecNo0()); pi.getPrecNo() < pi.getPoc().getPrecNo1(); pi .setPrecNo(pi.getPrecNo() + 1)) { - if (!LABEL_SKIP) { + if (!labelSkip) { index = pi.getLayNo() * pi.getStepL() + pi.getResNo() * pi.getStepR() + pi.getCompNo() * pi.getStepC() + pi.getPrecNo() * pi.getStepP(); if (pi.getInclude()[index] == 0) { @@ -68,7 +68,7 @@ private int piNextLRCP(PiIterator pi) { return 1; } } else { - LABEL_SKIP = false; + labelSkip = false; } } } @@ -78,15 +78,16 @@ private int piNextLRCP(PiIterator pi) { return 0; } + @SuppressWarnings({ "java:S1854", "java:S3776"}) private int piNextRLCP(PiIterator pi) { PiComponent comp = null; PiResolution res = null; int index = 0; - boolean LABEL_SKIP = false; + boolean labelSkip = false; if (pi.getFirst() == 0) { comp = pi.getComps()[pi.getCompNo()]; res = comp.getResolutions()[pi.getResNo()]; - LABEL_SKIP = true; + labelSkip = true; } else { pi.setFirst(0); } @@ -97,7 +98,7 @@ private int piNextRLCP(PiIterator pi) { .setLayNo(pi.getLayNo() + 1)) { for (pi.setCompNo(pi.getPoc().getCompNo0()); pi.getCompNo() < pi.getPoc().getCompNo1(); pi .setCompNo(pi.getCompNo() + 1)) { - if (!LABEL_SKIP) { + if (!labelSkip) { comp = pi.getComps()[pi.getCompNo()]; if (pi.getResNo() >= comp.getNoOfResolutions()) { continue; @@ -109,7 +110,7 @@ private int piNextRLCP(PiIterator pi) { } for (pi.setPrecNo(pi.getPoc().getPrecNo0()); pi.getPrecNo() < pi.getPoc().getPrecNo1(); pi .setPrecNo(pi.getPrecNo() + 1)) { - if (!LABEL_SKIP) { + if (!labelSkip) { index = pi.getLayNo() * pi.getStepL() + pi.getResNo() * pi.getStepR() + pi.getCompNo() * pi.getStepC() + pi.getPrecNo() * pi.getStepP(); if (pi.getInclude()[index] == 0) { @@ -117,7 +118,7 @@ private int piNextRLCP(PiIterator pi) { return 1; } } else { - LABEL_SKIP = false; + labelSkip = false; } } } @@ -127,14 +128,15 @@ private int piNextRLCP(PiIterator pi) { return 0; } + @SuppressWarnings({ "java:S117", "java:S135", "java:S1659", "java:S3776", "java:S6541" }) private int piNextRPCL(PiIterator pi) { PiComponent comp = null; PiResolution res = null; int index = 0; - boolean LABEL_SKIP = false; + boolean labelSkip = false; if (pi.getFirst() == 0) { - LABEL_SKIP = true; + labelSkip = true; } else { int compNo, resNo; pi.setFirst(0); @@ -143,22 +145,21 @@ private int piNextRPCL(PiIterator pi) { for (compNo = 0; compNo < pi.getNoOfComps(); compNo++) { comp = pi.getComps()[compNo]; for (resNo = 0; resNo < comp.getNoOfResolutions(); resNo++) { - int dx, dy; + int dx; + int dy; res = comp.getResolutions()[resNo]; dx = comp.getDX() * (1 << (res.getPDX() + comp.getNoOfResolutions() - 1 - resNo)); dy = comp.getDY() * (1 << (res.getPDY() + comp.getNoOfResolutions() - 1 - resNo)); - pi.setDX(pi.getDX() == 0 ? dx : MathUtil.intMin(pi.getDX(), dx)); - pi.setDY(pi.getDY() == 0 ? dy : MathUtil.intMin(pi.getDY(), dy)); + pi.setDX(pi.getDX() == 0 ? dx : MathUtil.getInstance().intMin(pi.getDX(), dx)); + pi.setDY(pi.getDY() == 0 ? dy : MathUtil.getInstance().intMin(pi.getDY(), dy)); } } } - if (!LABEL_SKIP) { - if (pi.getTilePartOn() == 0) { - pi.getPoc().setTY0(pi.getTY0()); - pi.getPoc().setTX0(pi.getTX0()); - pi.getPoc().setTY1(pi.getTY1()); - pi.getPoc().setTX1(pi.getTX1()); - } + if (!labelSkip && pi.getTilePartOn() == 0) { + pi.getPoc().setTY0(pi.getTY0()); + pi.getPoc().setTX0(pi.getTX0()); + pi.getPoc().setTY1(pi.getTY1()); + pi.getPoc().setTX1(pi.getTX1()); } for (pi.setResNo(pi.getPoc().getResNo0()); pi.getResNo() < pi.getPoc().getResNo1(); pi .setResNo(pi.getResNo() + 1)) { @@ -168,7 +169,7 @@ private int piNextRPCL(PiIterator pi) { .setX(pi.getX() + pi.getDX() - (pi.getX() % pi.getDX()))) { for (pi.setCompNo(pi.getPoc().getCompNo0()); pi.getCompNo() < pi.getPoc().getCompNo1(); pi .setCompNo(pi.getCompNo() + 1)) { - if (!LABEL_SKIP) { + if (!labelSkip) { int levelNo; int trx0, try0; int trx1, try1; @@ -180,10 +181,10 @@ private int piNextRPCL(PiIterator pi) { } res = comp.getResolutions()[pi.getResNo()]; levelNo = comp.getNoOfResolutions() - 1 - pi.getResNo(); - trx0 = MathUtil.intCeilDiv(pi.getTX0(), comp.getDX() << levelNo); - try0 = MathUtil.intCeilDiv(pi.getTY0(), comp.getDY() << levelNo); - trx1 = MathUtil.intCeilDiv(pi.getTX1(), comp.getDX() << levelNo); - try1 = MathUtil.intCeilDiv(pi.getTY1(), comp.getDY() << levelNo); + trx0 = MathUtil.getInstance().intCeilDiv(pi.getTX0(), comp.getDX() << levelNo); + try0 = MathUtil.getInstance().intCeilDiv(pi.getTY0(), comp.getDY() << levelNo); + trx1 = MathUtil.getInstance().intCeilDiv(pi.getTX1(), comp.getDX() << levelNo); + try1 = MathUtil.getInstance().intCeilDiv(pi.getTY1(), comp.getDY() << levelNo); rpx = res.getPDX() + levelNo; rpy = res.getPDY() + levelNo; if (!((pi.getY() % (comp.getDY() << rpy) == 0) @@ -195,16 +196,18 @@ private int piNextRPCL(PiIterator pi) { continue; } - if ((res.getPWidth() == 0) || (res.getPWidth() == 0)) + if (res.getPWidth() == 0) continue; if ((trx0 == trx1) || (try0 == try1)) continue; - prci = MathUtil.intFloorDivPow2(MathUtil.intCeilDiv(pi.getX(), comp.getDX() << levelNo), - res.getPDX()) - MathUtil.intFloorDivPow2(trx0, res.getPDX()); - prcj = MathUtil.intFloorDivPow2(MathUtil.intCeilDiv(pi.getY(), comp.getDY() << levelNo), - res.getPDY()) - MathUtil.intFloorDivPow2(try0, res.getPDY()); + prci = MathUtil.getInstance().intFloorDivPow2( + MathUtil.getInstance().intCeilDiv(pi.getX(), comp.getDX() << levelNo), res.getPDX()) + - MathUtil.getInstance().intFloorDivPow2(trx0, res.getPDX()); + prcj = MathUtil.getInstance().intFloorDivPow2( + MathUtil.getInstance().intCeilDiv(pi.getY(), comp.getDY() << levelNo), res.getPDY()) + - MathUtil.getInstance().intFloorDivPow2(try0, res.getPDY()); pi.setPrecNo(prci + prcj * res.getPWidth()); } @@ -216,7 +219,7 @@ private int piNextRPCL(PiIterator pi) { pi.getInclude()[index] = 1; return 1; } - LABEL_SKIP = false; + labelSkip = false; } } } @@ -226,15 +229,16 @@ private int piNextRPCL(PiIterator pi) { return 0; } + @SuppressWarnings({ "java:S117", "java:S135", "java:S1659", "java:S3776", "java:S6541" }) private int piNextPCRL(PiIterator pi) { PiComponent comp = null; PiResolution res = null; int index = 0; - boolean LABEL_SKIP = false; + boolean labelSkip = false; if (pi.getFirst() == 0) { comp = pi.getComps()[pi.getCompNo()]; - LABEL_SKIP = true; + labelSkip = true; } else { int compNo, resNo; pi.setFirst(0); @@ -243,22 +247,21 @@ private int piNextPCRL(PiIterator pi) { for (compNo = 0; compNo < pi.getNoOfComps(); compNo++) { comp = pi.getComps()[compNo]; for (resNo = 0; resNo < comp.getNoOfResolutions(); resNo++) { - int dx, dy; + int dx; + int dy; res = comp.getResolutions()[resNo]; dx = comp.getDX() * (1 << (res.getPDX() + comp.getNoOfResolutions() - 1 - resNo)); dy = comp.getDY() * (1 << (res.getPDY() + comp.getNoOfResolutions() - 1 - resNo)); - pi.setDX(pi.getDX() == 0 ? dx : MathUtil.intMin(pi.getDX(), dx)); - pi.setDY(pi.getDY() == 0 ? dy : MathUtil.intMin(pi.getDY(), dy)); + pi.setDX(pi.getDX() == 0 ? dx : MathUtil.getInstance().intMin(pi.getDX(), dx)); + pi.setDY(pi.getDY() == 0 ? dy : MathUtil.getInstance().intMin(pi.getDY(), dy)); } } } - if (!LABEL_SKIP) { - if (pi.getTilePartOn() == 0) { - pi.getPoc().setTY0(pi.getTY0()); - pi.getPoc().setTX0(pi.getTX0()); - pi.getPoc().setTY1(pi.getTY1()); - pi.getPoc().setTX1(pi.getTX1()); - } + if (!labelSkip && pi.getTilePartOn() == 0) { + pi.getPoc().setTY0(pi.getTY0()); + pi.getPoc().setTX0(pi.getTX0()); + pi.getPoc().setTY1(pi.getTY1()); + pi.getPoc().setTX1(pi.getTX1()); } for (pi.setY(pi.getPoc().getTY0()); pi.getY() < pi.getPoc().getTY1(); pi .setY(pi.getY() + pi.getDY() - (pi.getY() % pi.getDY()))) { @@ -266,12 +269,12 @@ private int piNextPCRL(PiIterator pi) { .setX(pi.getX() + pi.getDX() - (pi.getX() % pi.getDX()))) { for (pi.setCompNo(pi.getPoc().getCompNo0()); pi.getCompNo() < pi.getPoc().getCompNo1(); pi .setCompNo(pi.getCompNo() + 1)) { - if (!LABEL_SKIP) { + if (!labelSkip) { comp = pi.getComps()[pi.getCompNo()]; } - for (pi.setResNo(pi.getPoc().getResNo0()); pi.getResNo() < MathUtil.intMin(pi.getPoc().getResNo1(), - comp.getNoOfResolutions()); pi.setResNo(pi.getResNo() + 1)) { - if (!LABEL_SKIP) { + for (pi.setResNo(pi.getPoc().getResNo0()); pi.getResNo() < MathUtil.getInstance().intMin( + pi.getPoc().getResNo1(), comp.getNoOfResolutions()); pi.setResNo(pi.getResNo() + 1)) { + if (!labelSkip) { int levelNo; int trx0, try0; int trx1, try1; @@ -279,10 +282,10 @@ private int piNextPCRL(PiIterator pi) { int prci, prcj; res = comp.getResolutions()[pi.getResNo()]; levelNo = comp.getNoOfResolutions() - 1 - pi.getResNo(); - trx0 = MathUtil.intCeilDiv(pi.getTX0(), comp.getDX() << levelNo); - try0 = MathUtil.intCeilDiv(pi.getTY0(), comp.getDY() << levelNo); - trx1 = MathUtil.intCeilDiv(pi.getTX1(), comp.getDX() << levelNo); - try1 = MathUtil.intCeilDiv(pi.getTY1(), comp.getDY() << levelNo); + trx0 = MathUtil.getInstance().intCeilDiv(pi.getTX0(), comp.getDX() << levelNo); + try0 = MathUtil.getInstance().intCeilDiv(pi.getTY0(), comp.getDY() << levelNo); + trx1 = MathUtil.getInstance().intCeilDiv(pi.getTX1(), comp.getDX() << levelNo); + try1 = MathUtil.getInstance().intCeilDiv(pi.getTY1(), comp.getDY() << levelNo); rpx = res.getPDX() + levelNo; rpy = res.getPDY() + levelNo; if (!((pi.getY() % (comp.getDY() << rpy) == 0) @@ -294,21 +297,23 @@ private int piNextPCRL(PiIterator pi) { continue; } - if ((res.getPWidth() == 0) || (res.getPWidth() == 0)) + if (res.getPWidth() == 0) continue; if ((trx0 == trx1) || (try0 == try1)) continue; - prci = MathUtil.intFloorDivPow2(MathUtil.intCeilDiv(pi.getX(), comp.getDX() << levelNo), - res.getPDX()) - MathUtil.intFloorDivPow2(trx0, res.getPDX()); - prcj = MathUtil.intFloorDivPow2(MathUtil.intCeilDiv(pi.getY(), comp.getDY() << levelNo), - res.getPDY()) - MathUtil.intFloorDivPow2(try0, res.getPDY()); + prci = MathUtil.getInstance().intFloorDivPow2( + MathUtil.getInstance().intCeilDiv(pi.getX(), comp.getDX() << levelNo), res.getPDX()) + - MathUtil.getInstance().intFloorDivPow2(trx0, res.getPDX()); + prcj = MathUtil.getInstance().intFloorDivPow2( + MathUtil.getInstance().intCeilDiv(pi.getY(), comp.getDY() << levelNo), res.getPDY()) + - MathUtil.getInstance().intFloorDivPow2(try0, res.getPDY()); pi.setPrecNo(prci + prcj * res.getPWidth()); } for (pi.setLayNo(pi.getPoc().getLayNo0()); pi.getLayNo() < pi.getPoc().getLayNo1(); pi .setLayNo(pi.getLayNo() + 1)) { - if (!LABEL_SKIP) { + if (!labelSkip) { index = pi.getLayNo() * pi.getStepL() + pi.getResNo() * pi.getStepR() + pi.getCompNo() * pi.getStepC() + pi.getPrecNo() * pi.getStepP(); if (pi.getInclude()[index] == 0) { @@ -316,7 +321,7 @@ private int piNextPCRL(PiIterator pi) { return 1; } } else { - LABEL_SKIP = false; + labelSkip = false; } } } @@ -327,34 +332,36 @@ private int piNextPCRL(PiIterator pi) { return 0; } + @SuppressWarnings({ "java:S117", "java:S135", "java:S1659", "java:S3776", "java:S6541" }) private int piNextCPRL(PiIterator pi) { PiComponent comp = null; PiResolution res = null; int index = 0; - boolean LABEL_SKIP = false; + boolean labelSkip = false; if (pi.getFirst() == 0) { comp = pi.getComps()[pi.getCompNo()]; - LABEL_SKIP = true; + labelSkip = true; } else { pi.setFirst(0); } - for (pi.setCompNo(pi.getPoc().getCompNo0()); pi.getCompNo() < pi.getPoc().getCompNo1(); - pi.setCompNo(pi.getCompNo() + 1)) { + for (pi.setCompNo(pi.getPoc().getCompNo0()); pi.getCompNo() < pi.getPoc().getCompNo1(); pi + .setCompNo(pi.getCompNo() + 1)) { int resNo; - if (!LABEL_SKIP) { + if (!labelSkip) { comp = pi.getComps()[pi.getCompNo()]; pi.setDX(0); pi.setDY(0); for (resNo = 0; resNo < comp.getNoOfResolutions(); resNo++) { - int dx, dy; + int dx; + int dy; res = comp.getResolutions()[resNo]; dx = comp.getDX() * (1 << (res.getPDX() + comp.getNoOfResolutions() - 1 - resNo)); dy = comp.getDY() * (1 << (res.getPDY() + comp.getNoOfResolutions() - 1 - resNo)); - pi.setDX(pi.getDX() == 0 ? dx : MathUtil.intMin(pi.getDX(), dx)); - pi.setDY(pi.getDY() == 0 ? dy : MathUtil.intMin(pi.getDY(), dy)); + pi.setDX(pi.getDX() == 0 ? dx : MathUtil.getInstance().intMin(pi.getDX(), dx)); + pi.setDY(pi.getDY() == 0 ? dy : MathUtil.getInstance().intMin(pi.getDY(), dy)); } if (pi.getTilePartOn() == 0) { pi.getPoc().setTY0(pi.getTY0()); @@ -367,9 +374,9 @@ private int piNextCPRL(PiIterator pi) { .setY(pi.getY() + pi.getDY() - (pi.getY() % pi.getDY()))) { for (pi.setX(pi.getPoc().getTX0()); pi.getX() < pi.getPoc().getTX1(); pi .setX(pi.getX() + pi.getDX() - (pi.getX() % pi.getDX()))) { - for (pi.setResNo(pi.getPoc().getResNo0()); pi.getResNo() < MathUtil.intMin(pi.getPoc().getResNo1(), - comp.getNoOfResolutions()); pi.setResNo(pi.getResNo() + 1)) { - if (!LABEL_SKIP) { + for (pi.setResNo(pi.getPoc().getResNo0()); pi.getResNo() < MathUtil.getInstance().intMin( + pi.getPoc().getResNo1(), comp.getNoOfResolutions()); pi.setResNo(pi.getResNo() + 1)) { + if (!labelSkip) { int levelNo; int trx0, try0; int trx1, try1; @@ -377,10 +384,10 @@ private int piNextCPRL(PiIterator pi) { int prci, prcj; res = comp.getResolutions()[pi.getResNo()]; levelNo = comp.getNoOfResolutions() - 1 - pi.getResNo(); - trx0 = MathUtil.intCeilDiv(pi.getTX0(), comp.getDX() << levelNo); - try0 = MathUtil.intCeilDiv(pi.getTY0(), comp.getDY() << levelNo); - trx1 = MathUtil.intCeilDiv(pi.getTX1(), comp.getDX() << levelNo); - try1 = MathUtil.intCeilDiv(pi.getTY1(), comp.getDY() << levelNo); + trx0 = MathUtil.getInstance().intCeilDiv(pi.getTX0(), comp.getDX() << levelNo); + try0 = MathUtil.getInstance().intCeilDiv(pi.getTY0(), comp.getDY() << levelNo); + trx1 = MathUtil.getInstance().intCeilDiv(pi.getTX1(), comp.getDX() << levelNo); + try1 = MathUtil.getInstance().intCeilDiv(pi.getTY1(), comp.getDY() << levelNo); rpx = res.getPDX() + levelNo; rpy = res.getPDY() + levelNo; if (!((pi.getY() % (comp.getDY() << rpy) == 0) @@ -392,21 +399,23 @@ private int piNextCPRL(PiIterator pi) { continue; } - if ((res.getPWidth() == 0) || (res.getPWidth() == 0)) + if (res.getPWidth() == 0) continue; if ((trx0 == trx1) || (try0 == try1)) continue; - prci = MathUtil.intFloorDivPow2(MathUtil.intCeilDiv(pi.getX(), comp.getDX() << levelNo), - res.getPDX()) - MathUtil.intFloorDivPow2(trx0, res.getPDX()); - prcj = MathUtil.intFloorDivPow2(MathUtil.intCeilDiv(pi.getY(), comp.getDY() << levelNo), - res.getPDY()) - MathUtil.intFloorDivPow2(try0, res.getPDY()); + prci = MathUtil.getInstance().intFloorDivPow2( + MathUtil.getInstance().intCeilDiv(pi.getX(), comp.getDX() << levelNo), res.getPDX()) + - MathUtil.getInstance().intFloorDivPow2(trx0, res.getPDX()); + prcj = MathUtil.getInstance().intFloorDivPow2( + MathUtil.getInstance().intCeilDiv(pi.getY(), comp.getDY() << levelNo), res.getPDY()) + - MathUtil.getInstance().intFloorDivPow2(try0, res.getPDY()); pi.setPrecNo(prci + prcj * res.getPWidth()); } for (pi.setLayNo(pi.getPoc().getLayNo0()); pi.getLayNo() < pi.getPoc().getLayNo1(); pi .setLayNo(pi.getLayNo() + 1)) { - if (!LABEL_SKIP) { + if (!labelSkip) { index = pi.getLayNo() * pi.getStepL() + pi.getResNo() * pi.getStepR() + pi.getCompNo() * pi.getStepC() + pi.getPrecNo() * pi.getStepP(); if (pi.getInclude()[index] == 0) { @@ -414,7 +423,7 @@ private int piNextCPRL(PiIterator pi) { return 1; } } else { - LABEL_SKIP = false; + labelSkip = false; } } } @@ -426,8 +435,10 @@ private int piNextCPRL(PiIterator pi) { } /* - * =============================Packet iterator interface =========================================== + * =============================Packet iterator interface + * =========================================== */ + @SuppressWarnings({ "java:S1659", "java:S1854", "java:S3776" }) public PiIterator[] piCreateDecode(OpenJpegImage image, CodingParameters codingParameters, int tileno) { int p, q; int compNo, resNo, piNo = 0; @@ -441,16 +452,20 @@ public PiIterator[] piCreateDecode(OpenJpegImage image, CodingParameters codingP for (piNo = 0; piNo < tcp.getNoOfPocs() + 1; piNo++) { /* change */ pi[piNo] = new PiIterator(); - pi[piNo].setPoc(new Poc()); + pi[piNo].setPoc(new Poc()); int maxres = 0; int maxprec = 0; p = tileno % codingParameters.getTileWidth(); q = tileno / codingParameters.getTileWidth(); - pi[piNo].setTX0(MathUtil.intMax(codingParameters.getTileX0() + p * codingParameters.getTileDX(), image.getX0())); - pi[piNo].setTY0(MathUtil.intMax(codingParameters.getTileY0() + q * codingParameters.getTileDY(), image.getY0())); - pi[piNo].setTX1(MathUtil.intMin(codingParameters.getTileX0() + (p + 1) * codingParameters.getTileDX(), image.getX1())); - pi[piNo].setTY1(MathUtil.intMin(codingParameters.getTileX0() + (q + 1) * codingParameters.getTileDY(), image.getY1())); + pi[piNo].setTX0(MathUtil.getInstance() + .intMax(codingParameters.getTileX0() + p * codingParameters.getTileDX(), image.getX0())); + pi[piNo].setTY0(MathUtil.getInstance() + .intMax(codingParameters.getTileY0() + q * codingParameters.getTileDY(), image.getY0())); + pi[piNo].setTX1(MathUtil.getInstance() + .intMin(codingParameters.getTileX0() + (p + 1) * codingParameters.getTileDX(), image.getX1())); + pi[piNo].setTY1(MathUtil.getInstance() + .intMin(codingParameters.getTileX0() + (q + 1) * codingParameters.getTileDY(), image.getY1())); pi[piNo].setNoOfComps(image.getNoOfComps()); pi[piNo].setComps(new PiComponent[image.getNoOfComps()]); @@ -464,10 +479,10 @@ public PiIterator[] piCreateDecode(OpenJpegImage image, CodingParameters codingP comp.setNoOfResolutions(tccp.getNoOfResolutions()); comp.setResolutions(new PiResolution[comp.getNoOfResolutions()]); - tcx0 = MathUtil.intCeilDiv(pi[0].getTX0(), comp.getDX()); - tcy0 = MathUtil.intCeilDiv(pi[0].getTY0(), comp.getDY()); - tcx1 = MathUtil.intCeilDiv(pi[0].getTX1(), comp.getDX()); - tcy1 = MathUtil.intCeilDiv(pi[0].getTY1(), comp.getDY()); + tcx0 = MathUtil.getInstance().intCeilDiv(pi[0].getTX0(), comp.getDX()); + tcy0 = MathUtil.getInstance().intCeilDiv(pi[0].getTY0(), comp.getDY()); + tcx1 = MathUtil.getInstance().intCeilDiv(pi[0].getTX1(), comp.getDX()); + tcy1 = MathUtil.getInstance().intCeilDiv(pi[0].getTY1(), comp.getDY()); if (comp.getNoOfResolutions() > maxres) { maxres = comp.getNoOfResolutions(); } @@ -486,14 +501,14 @@ public PiIterator[] piCreateDecode(OpenJpegImage image, CodingParameters codingP res.setPDY(15); } levelNo = comp.getNoOfResolutions() - 1 - resNo; - rx0 = MathUtil.intCeilDivPow2(tcx0, levelNo); - ry0 = MathUtil.intCeilDivPow2(tcy0, levelNo); - rx1 = MathUtil.intCeilDivPow2(tcx1, levelNo); - ry1 = MathUtil.intCeilDivPow2(tcy1, levelNo); - px0 = MathUtil.intFloorDivPow2(rx0, res.getPDX()) << res.getPDX(); - py0 = MathUtil.intFloorDivPow2(ry0, res.getPDY()) << res.getPDY(); - px1 = MathUtil.intCeilDivPow2(rx1, res.getPDX()) << res.getPDX(); - py1 = MathUtil.intCeilDivPow2(ry1, res.getPDY()) << res.getPDY(); + rx0 = MathUtil.getInstance().intCeilDivPow2(tcx0, levelNo); + ry0 = MathUtil.getInstance().intCeilDivPow2(tcy0, levelNo); + rx1 = MathUtil.getInstance().intCeilDivPow2(tcx1, levelNo); + ry1 = MathUtil.getInstance().intCeilDivPow2(tcy1, levelNo); + px0 = MathUtil.getInstance().intFloorDivPow2(rx0, res.getPDX()) << res.getPDX(); + py0 = MathUtil.getInstance().intFloorDivPow2(ry0, res.getPDY()) << res.getPDY(); + px1 = MathUtil.getInstance().intCeilDivPow2(rx1, res.getPDX()) << res.getPDX(); + py1 = MathUtil.getInstance().intCeilDivPow2(ry1, res.getPDY()) << res.getPDY(); res.setPWidth((rx0 == rx1) ? 0 : ((px1 - px0) >> res.getPDX())); res.setPHeight((ry0 == ry1) ? 0 : ((py1 - py0) >> res.getPDY())); @@ -542,7 +557,9 @@ public PiIterator[] piCreateDecode(OpenJpegImage image, CodingParameters codingP return pi; } - public PiIterator[] piInitEncode(OpenJpegImage image, CodingParameters codingParameters, int tileno, J2KT2Mode t2_mode) { + @SuppressWarnings({ "java:S1659", "java:S1854", "java:S3776", "java:S6541"}) + public PiIterator[] piInitEncode(OpenJpegImage image, CodingParameters codingParameters, int tileno, + J2KT2Mode t2Mode) { int p, q, piNo = 0; int compNo, resNo; int maxres = 0; @@ -562,10 +579,14 @@ public PiIterator[] piInitEncode(OpenJpegImage image, CodingParameters codingPar p = tileno % codingParameters.getTileWidth(); q = tileno / codingParameters.getTileWidth(); - pi[piNo].setTX0(MathUtil.intMax(codingParameters.getTileX0() + p * codingParameters.getTileDX(), image.getX0())); - pi[piNo].setTY0(MathUtil.intMax(codingParameters.getTileY0() + q * codingParameters.getTileDY(), image.getY0())); - pi[piNo].setTX1(MathUtil.intMin(codingParameters.getTileX0() + (p + 1) * codingParameters.getTileDX(), image.getX1())); - pi[piNo].setTY1(MathUtil.intMin(codingParameters.getTileY0() + (q + 1) * codingParameters.getTileDY(), image.getY1())); + pi[piNo].setTX0(MathUtil.getInstance() + .intMax(codingParameters.getTileX0() + p * codingParameters.getTileDX(), image.getX0())); + pi[piNo].setTY0(MathUtil.getInstance() + .intMax(codingParameters.getTileY0() + q * codingParameters.getTileDY(), image.getY0())); + pi[piNo].setTX1(MathUtil.getInstance() + .intMin(codingParameters.getTileX0() + (p + 1) * codingParameters.getTileDX(), image.getX1())); + pi[piNo].setTY1(MathUtil.getInstance() + .intMin(codingParameters.getTileY0() + (q + 1) * codingParameters.getTileDY(), image.getY1())); pi[piNo].setNoOfComps(image.getNoOfComps()); pi[piNo].setComps(new PiComponent[image.getNoOfComps()]); @@ -580,10 +601,10 @@ public PiIterator[] piInitEncode(OpenJpegImage image, CodingParameters codingPar comp.setResolutions(new PiResolution[comp.getNoOfResolutions()]); - tcx0 = MathUtil.intCeilDiv(pi[piNo].getTX0(), comp.getDX()); - tcy0 = MathUtil.intCeilDiv(pi[piNo].getTY0(), comp.getDY()); - tcx1 = MathUtil.intCeilDiv(pi[piNo].getTX1(), comp.getDX()); - tcy1 = MathUtil.intCeilDiv(pi[piNo].getTY1(), comp.getDY()); + tcx0 = MathUtil.getInstance().intCeilDiv(pi[piNo].getTX0(), comp.getDX()); + tcy0 = MathUtil.getInstance().intCeilDiv(pi[piNo].getTY0(), comp.getDY()); + tcx1 = MathUtil.getInstance().intCeilDiv(pi[piNo].getTX1(), comp.getDX()); + tcy1 = MathUtil.getInstance().intCeilDiv(pi[piNo].getTY1(), comp.getDY()); if (comp.getNoOfResolutions() > maxres) { maxres = comp.getNoOfResolutions(); } @@ -602,14 +623,14 @@ public PiIterator[] piInitEncode(OpenJpegImage image, CodingParameters codingPar res.setPDY(15); } levelNo = comp.getNoOfResolutions() - 1 - resNo; - rx0 = MathUtil.intCeilDivPow2(tcx0, levelNo); - ry0 = MathUtil.intCeilDivPow2(tcy0, levelNo); - rx1 = MathUtil.intCeilDivPow2(tcx1, levelNo); - ry1 = MathUtil.intCeilDivPow2(tcy1, levelNo); - px0 = MathUtil.intFloorDivPow2(rx0, res.getPDX()) << res.getPDX(); - py0 = MathUtil.intFloorDivPow2(ry0, res.getPDY()) << res.getPDY(); - px1 = MathUtil.intCeilDivPow2(rx1, res.getPDX()) << res.getPDX(); - py1 = MathUtil.intCeilDivPow2(ry1, res.getPDY()) << res.getPDY(); + rx0 = MathUtil.getInstance().intCeilDivPow2(tcx0, levelNo); + ry0 = MathUtil.getInstance().intCeilDivPow2(tcy0, levelNo); + rx1 = MathUtil.getInstance().intCeilDivPow2(tcx1, levelNo); + ry1 = MathUtil.getInstance().intCeilDivPow2(tcy1, levelNo); + px0 = MathUtil.getInstance().intFloorDivPow2(rx0, res.getPDX()) << res.getPDX(); + py0 = MathUtil.getInstance().intFloorDivPow2(ry0, res.getPDY()) << res.getPDY(); + px1 = MathUtil.getInstance().intCeilDivPow2(rx1, res.getPDX()) << res.getPDX(); + py1 = MathUtil.getInstance().intCeilDivPow2(ry1, res.getPDY()) << res.getPDY(); res.setPWidth((rx0 == rx1) ? 0 : ((px1 - px0) >> res.getPDX())); res.setPHeight((ry0 == ry1) ? 0 : ((py1 - py0) >> res.getPDY())); @@ -628,12 +649,13 @@ public PiIterator[] piInitEncode(OpenJpegImage image, CodingParameters codingPar for (compNo = 0; compNo < pi[piNo].getNoOfComps(); compNo++) { PiComponent comp = pi[piNo].getComps()[compNo]; for (resNo = 0; resNo < comp.getNoOfResolutions(); resNo++) { - int dx, dy; + int dx; + int dy; PiResolution res = comp.getResolutions()[resNo]; dx = comp.getDX() * (1 << (res.getPDX() + comp.getNoOfResolutions() - 1 - resNo)); dy = comp.getDY() * (1 << (res.getPDY() + comp.getNoOfResolutions() - 1 - resNo)); - pi[piNo].setDX(pi[piNo].getDX() == 0 ? dx : MathUtil.intMin(pi[piNo].getDX(), dx)); - pi[piNo].setDY(pi[piNo].getDY() == 0 ? dy : MathUtil.intMin(pi[piNo].getDY(), dy)); + pi[piNo].setDX(pi[piNo].getDX() == 0 ? dx : MathUtil.getInstance().intMin(pi[piNo].getDX(), dx)); + pi[piNo].setDY(pi[piNo].getDY() == 0 ? dy : MathUtil.getInstance().intMin(pi[piNo].getDY(), dy)); } } @@ -645,7 +667,7 @@ public PiIterator[] piInitEncode(OpenJpegImage image, CodingParameters codingPar /* Generation of boundaries for each prog flag */ if (tcp.getIsPoc() != 0 && (codingParameters.getCinemaMode().value() != 0 - || ((codingParameters.getCinemaMode().value() == 0) && (t2_mode == J2KT2Mode.FINAL_PASS)))) { + || ((codingParameters.getCinemaMode().value() == 0) && (t2Mode == J2KT2Mode.FINAL_PASS)))) { tcp.getPocs()[piNo].setCompS(tcp.getPocs()[piNo].getCompNo0()); tcp.getPocs()[piNo].setCompE(tcp.getPocs()[piNo].getCompNo1()); tcp.getPocs()[piNo].setResS(tcp.getPocs()[piNo].getResNo0()); @@ -677,8 +699,10 @@ public PiIterator[] piInitEncode(OpenJpegImage image, CodingParameters codingPar return pi; } + @SuppressWarnings({ "java:S3776"}) public void piDestroy(PiIterator[] pi, CodingParameters codingParameters, int tileno) { - int compNo, piNo; + int compNo; + int piNo; Tcp tcp = codingParameters.getTcps()[tileno]; if (pi != null) { for (piNo = 0; piNo < tcp.getNoOfPocs() + 1; piNo++) { @@ -695,7 +719,6 @@ public void piDestroy(PiIterator[] pi, CodingParameters codingParameters, int ti pi[piNo].setInclude(null); } } - pi = null; } } @@ -718,8 +741,9 @@ public int piNext(PiIterator pi) { return 0; } - public int piCreateEncode(PiIterator[] pi, CodingParameters codingParameters, int tileno, int piNo, int tilePartNo, int tppos, - J2KT2Mode t2_mode, int currentTotalNoOfTilePart) { + @SuppressWarnings({ "java:S107", "java:S1659", "java:S3776", "java:S6208", "java:S6541" }) + public int piCreateEncode(PiIterator[] pi, CodingParameters codingParameters, int tileno, int piNo, int tilePartNo, + int tppos, J2KT2Mode t2Mode, int currentTotalNoOfTilePart) { char[] prog = new char[4]; int i; int incrementTop = 1, resetX = 0; @@ -749,8 +773,9 @@ public int piCreateEncode(PiIterator[] pi, CodingParameters codingParameters, in return 1; } - if (!(codingParameters.getTilePartOn() != 0 && ((codingParameters.getCinemaMode().value() == 0 && (t2_mode == J2KT2Mode.FINAL_PASS)) - || codingParameters.getCinemaMode().value() != 0))) { + if (!(codingParameters.getTilePartOn() != 0 + && ((codingParameters.getCinemaMode().value() == 0 && (t2Mode == J2KT2Mode.FINAL_PASS)) + || codingParameters.getCinemaMode().value() != 0))) { pi[piNo].getPoc().setResNo0(tcp.getResS()); pi[piNo].getPoc().setResNo1(tcp.getResE()); pi[piNo].getPoc().setCompNo0(tcp.getCompS()); @@ -921,15 +946,15 @@ public int piCreateEncode(PiIterator[] pi, CodingParameters codingParameters, in if (tcp.getTy0Tmp() >= tcp.getTYE()) { tcp.setTy0Tmp(tcp.getTYS()); pi[piNo].getPoc().setTY0(tcp.getTy0Tmp()); - pi[piNo].getPoc().setTY1( - tcp.getTy0Tmp() + tcp.getDY() - (tcp.getTy0Tmp() % tcp.getDY())); + pi[piNo].getPoc().setTY1(tcp.getTy0Tmp() + tcp.getDY() + - (tcp.getTy0Tmp() % tcp.getDY())); tcp.setTy0Tmp(pi[piNo].getPoc().getTY1()); incrementTop = 1; resetX = 1; } else { pi[piNo].getPoc().setTY0(tcp.getTy0Tmp()); - pi[piNo].getPoc().setTY1( - tcp.getTy0Tmp() + tcp.getDY() - (tcp.getTy0Tmp() % tcp.getDY())); + pi[piNo].getPoc().setTY1(tcp.getTy0Tmp() + tcp.getDY() + - (tcp.getTy0Tmp() % tcp.getDY())); tcp.setTy0Tmp(pi[piNo].getPoc().getTY1()); incrementTop = 0; resetX = 1; @@ -937,8 +962,8 @@ public int piCreateEncode(PiIterator[] pi, CodingParameters codingParameters, in if (resetX == 1) { tcp.setTx0Tmp(tcp.getTXS()); pi[piNo].getPoc().setTX0(tcp.getTx0Tmp()); - pi[piNo].getPoc().setTX1( - tcp.getTx0Tmp() + tcp.getDX() - (tcp.getTx0Tmp() % tcp.getDX())); + pi[piNo].getPoc().setTX1(tcp.getTx0Tmp() + tcp.getDX() + - (tcp.getTx0Tmp() % tcp.getDX())); tcp.setTx0Tmp(pi[piNo].getPoc().getTX1()); } } else { @@ -952,11 +977,11 @@ public int piCreateEncode(PiIterator[] pi, CodingParameters codingParameters, in incrementTop = 0; } } else { - pi[piNo].getPoc() - .setTX0(tcp.getTx0Tmp() - tcp.getDX() - (tcp.getTx0Tmp() % tcp.getDX())); + pi[piNo].getPoc().setTX0( + tcp.getTx0Tmp() - tcp.getDX() - (tcp.getTx0Tmp() % tcp.getDX())); pi[piNo].getPoc().setTX1(tcp.getTx0Tmp()); - pi[piNo].getPoc() - .setTY0(tcp.getTy0Tmp() - tcp.getDY() - (tcp.getTy0Tmp() % tcp.getDY())); + pi[piNo].getPoc().setTY0( + tcp.getTy0Tmp() - tcp.getDY() - (tcp.getTy0Tmp() % tcp.getDY())); pi[piNo].getPoc().setTY1(tcp.getTy0Tmp()); } } @@ -964,10 +989,12 @@ public int piCreateEncode(PiIterator[] pi, CodingParameters codingParameters, in break; } break; + default: + break; } } } } return 0; } -} +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/RawHelper.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/RawHelper.java index 6f5448e..fb311ad 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/RawHelper.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/RawHelper.java @@ -4,36 +4,33 @@ public class RawHelper { // Static variable reference of singleInstance of type Singleton - private static RawHelper singleInstance = null; - private RawHelper() - { - super (); - } - - //synchronized method to control simultaneous access - public static synchronized RawHelper getInstance() - { + private static RawHelper singleInstance = null; + + private RawHelper() { + super(); + } + + // synchronized method to control simultaneous access + public static synchronized RawHelper getInstance() { if (singleInstance == null) singleInstance = new RawHelper(); - - return singleInstance; + + return singleInstance; } - + public Raw rawCreate() { - Raw raw = new Raw(); - return raw; + return new Raw(); } + @SuppressWarnings({ "java:S1186" }) public void rawDestroy(Raw raw) { - if(raw != null) { - raw = null; - } } public int rawNoOfBytes(Raw raw) { return raw.getBpIndex() - raw.getStart(); } + @SuppressWarnings({ "java:S1172" }) public void rawInitDecode(Raw raw, byte[] bp, int bpIndex, int len) { raw.setBpIndex(bpIndex); raw.setStart(bpIndex); @@ -48,18 +45,18 @@ public int rawDecode(Raw raw) { if (raw.getCt() == 0) { raw.setCt(8); if (raw.getLength() == raw.getLengthMax()) { - raw.setC((byte)0xff); + raw.setC((byte) 0xff); } else { - if (raw.getC() == (byte)0xff) { + if (raw.getC() == (byte) 0xff) { raw.setCt(7); } raw.setC(raw.getBp()[(int) raw.getLength()]); - raw.setLength(raw.getLength () + 1); + raw.setLength(raw.getLength() + 1); } } raw.setCt(raw.getCt() - 1); d = (raw.getC() >> raw.getCt()) & 0x01; - + return d; } } diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/TcdHelper.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/TcdHelper.java index 8e9513e..49c88e8 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/TcdHelper.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/TcdHelper.java @@ -1,11 +1,14 @@ package io.mosip.imagedecoder.openjpeg; -import java.util.Arrays; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_EMPTY; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_IDTYPE; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_SESSIONID; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.text.MessageFormat; +import java.util.Arrays; import io.mosip.imagedecoder.constant.openjpeg.OpenJpegConstant; +import io.mosip.imagedecoder.logger.ImageDecoderLogger; import io.mosip.imagedecoder.model.openjpeg.CodeStreamInfo; import io.mosip.imagedecoder.model.openjpeg.CodecContextInfo; import io.mosip.imagedecoder.model.openjpeg.CodingParameters; @@ -31,25 +34,25 @@ import io.mosip.imagedecoder.model.openjpeg.TileComponentCodingParameters; import io.mosip.imagedecoder.model.openjpeg.TileInfo; import io.mosip.imagedecoder.util.openjpeg.MathUtil; +import io.mosip.kernel.core.logger.spi.Logger; public class TcdHelper { - private Logger LOGGER = LoggerFactory.getLogger(TcdHelper.class); + private Logger logger = ImageDecoderLogger.getLogger(TcdHelper.class); // Static variable reference of singleInstance of type Singleton - private static TcdHelper singleInstance = null; - private TcdHelper() - { - super (); - } - - //synchronized method to control simultaneous access - public static synchronized TcdHelper getInstance() - { + private static TcdHelper singleInstance = null; + + private TcdHelper() { + super(); + } + + // synchronized method to control simultaneous access + public static synchronized TcdHelper getInstance() { if (singleInstance == null) singleInstance = new TcdHelper(); - - return singleInstance; + + return singleInstance; } - + /** * Create a new TCD handle */ @@ -67,11 +70,11 @@ public Tcd tcdCreate(CodecContextInfo codecContextInfo) { public void tcdDestroy(Tcd tcd) { if (tcd != null) { tcd.setTcdImage(null); - tcd = null; } } /* ----------------------------------------------------------------------- */ + @SuppressWarnings({ "java:S1659", "java:S1854", "java:S2184", "java:S3776", "java:S3358", "java:S6541", "unused" }) public void tcdMallocEncode(Tcd tcd, OpenJpegImage image, CodingParameters codingParameters, int currentTileNo) { int tileNo, compNo, resNo, bandNo, precNo, codeBlockNo; @@ -87,27 +90,31 @@ public void tcdMallocEncode(Tcd tcd, OpenJpegImage image, CodingParameters codin /* cfr p59 ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */ int p = currentTileNo % codingParameters.getTileWidth(); /* si numerotation matricielle .. */ - int q = currentTileNo / codingParameters.getTileWidth(); /* .. coordonnees de la tile (q,p) q pour ligne et p pour colonne */ + int q = currentTileNo / codingParameters + .getTileWidth(); /* .. coordonnees de la tile (q,p) q pour ligne et p pour colonne */ TcdTile tile = tcd.getTcdImage().getTiles()[0]; /* 4 borders of the tile rescale on the image if necessary */ - tile.setX0(MathUtil.intMax(codingParameters.getTileX0() + p * codingParameters.getTileDX(), image.getX0())); - tile.setY0(MathUtil.intMax(codingParameters.getTileY0() + q * codingParameters.getTileDY(), image.getY0())); - tile.setX1(MathUtil.intMin(codingParameters.getTileX0() + (p + 1) * codingParameters.getTileDX(), image.getX1())); - tile.setY1(MathUtil.intMin(codingParameters.getTileY0() + (q + 1) * codingParameters.getTileDY(), image.getY1())); + tile.setX0(MathUtil.getInstance().intMax(codingParameters.getTileX0() + p * codingParameters.getTileDX(), + image.getX0())); + tile.setY0(MathUtil.getInstance().intMax(codingParameters.getTileY0() + q * codingParameters.getTileDY(), + image.getY0())); + tile.setX1(MathUtil.getInstance() + .intMin(codingParameters.getTileX0() + (p + 1) * codingParameters.getTileDX(), image.getX1())); + tile.setY1(MathUtil.getInstance() + .intMin(codingParameters.getTileY0() + (q + 1) * codingParameters.getTileDY(), image.getY1())); tile.setNoOfComps(image.getNoOfComps()); - /* tile->PPT=image->PPT; */ /* Modification of the RATE >> */ for (j = 0; j < tcp.getNoOfLayers(); j++) { tcp.getRates()[j] = tcp.getRates()[j] != 0 ? codingParameters.getTilePartOn() != 0 - ? (((float) (tile.getNoOfComps() * (tile.getX1() - tile.getX0()) * (tile.getY1() - tile.getY0()) - * image.getComps()[0].getPrec())) + ? ((tile.getNoOfComps() * (tile.getX1() - tile.getX0()) * (tile.getY1() - tile.getY0()) + * image.getComps()[0].getPrec()) / (tcp.getRates()[j] * 8 * image.getComps()[0].getDX() * image.getComps()[0].getDY())) - (((tcd.getCurTotalNoOfTileParts() - 1) * 14) / tcp.getNoOfLayers()) - : ((float) (tile.getNoOfComps() * (tile.getX1() - tile.getX0()) * (tile.getY1() - tile.getY0()) - * image.getComps()[0].getPrec())) + : (tile.getNoOfComps() * (tile.getX1() - tile.getX0()) * (tile.getY1() - tile.getY0()) + * image.getComps()[0].getPrec()) / (tcp.getRates()[j] * 8 * image.getComps()[0].getDX() * image.getComps()[0].getDY()) : 0; @@ -134,10 +141,10 @@ public void tcdMallocEncode(Tcd tcd, OpenJpegImage image, CodingParameters codin TcdTileComponent tilec = tile.getComps()[compNo]; /* border of each tile component (global) */ - tilec.setX0(MathUtil.intCeilDiv(tile.getX0(), image.getComps()[compNo].getDX())); - tilec.setY0(MathUtil.intCeilDiv(tile.getY0(), image.getComps()[compNo].getDY())); - tilec.setX1(MathUtil.intCeilDiv(tile.getX1(), image.getComps()[compNo].getDX())); - tilec.setY1(MathUtil.intCeilDiv(tile.getY1(), image.getComps()[compNo].getDY())); + tilec.setX0(MathUtil.getInstance().intCeilDiv(tile.getX0(), image.getComps()[compNo].getDX())); + tilec.setY0(MathUtil.getInstance().intCeilDiv(tile.getY0(), image.getComps()[compNo].getDY())); + tilec.setX1(MathUtil.getInstance().intCeilDiv(tile.getX1(), image.getComps()[compNo].getDX())); + tilec.setY1(MathUtil.getInstance().intCeilDiv(tile.getY1(), image.getComps()[compNo].getDY())); tilec.setIData(new int[(tilec.getX1() - tilec.getX0()) * (tilec.getY1() - tilec.getY0())]); tilec.setFData(new double[(tilec.getX1() - tilec.getX0()) * (tilec.getY1() - tilec.getY0())]); @@ -155,10 +162,10 @@ public void tcdMallocEncode(Tcd tcd, OpenJpegImage image, CodingParameters codin TcdResolution res = tilec.getResolutions()[resNo]; /* border for each resolution level (global) */ - res.setX0(MathUtil.intCeilDivPow2(tilec.getX0(), levelno)); - res.setY0(MathUtil.intCeilDivPow2(tilec.getY0(), levelno)); - res.setX1(MathUtil.intCeilDivPow2(tilec.getX1(), levelno)); - res.setY1(MathUtil.intCeilDivPow2(tilec.getY1(), levelno)); + res.setX0(MathUtil.getInstance().intCeilDivPow2(tilec.getX0(), levelno)); + res.setY0(MathUtil.getInstance().intCeilDivPow2(tilec.getY0(), levelno)); + res.setX1(MathUtil.getInstance().intCeilDivPow2(tilec.getX1(), levelno)); + res.setY1(MathUtil.getInstance().intCeilDivPow2(tilec.getY1(), levelno)); res.setNoOfBands(resNo == 0 ? 1 : 3); /* p. 35, table A-23, ISO/IEC FDIS154444-1 : 2000 (18 august 2000) */ @@ -170,11 +177,11 @@ public void tcdMallocEncode(Tcd tcd, OpenJpegImage image, CodingParameters codin pdy = 15; } /* p. 64, B.6, ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */ - tlprcxStart = MathUtil.intFloorDivPow2(res.getX0(), pdx) << pdx; - tlprcyStart = MathUtil.intFloorDivPow2(res.getY0(), pdy) << pdy; + tlprcxStart = MathUtil.getInstance().intFloorDivPow2(res.getX0(), pdx) << pdx; + tlprcyStart = MathUtil.getInstance().intFloorDivPow2(res.getY0(), pdy) << pdy; - brprcxEnd = MathUtil.intCeilDivPow2(res.getX1(), pdx) << pdx; - brprcyEnd = MathUtil.intCeilDivPow2(res.getY1(), pdy) << pdy; + brprcxEnd = MathUtil.getInstance().intCeilDivPow2(res.getX1(), pdx) << pdx; + brprcyEnd = MathUtil.getInstance().intCeilDivPow2(res.getY1(), pdy) << pdy; res.setPWidth((brprcxEnd - tlprcxStart) >> pdx); res.setPHeight((brprcyEnd - tlprcyStart) >> pdy); @@ -187,16 +194,16 @@ public void tcdMallocEncode(Tcd tcd, OpenJpegImage image, CodingParameters codin cbgwidthexpn = pdx; cbgheightexpn = pdy; } else { - tlcbgxStart = MathUtil.intCeilDivPow2(tlprcxStart, 1); - tlcbgyStart = MathUtil.intCeilDivPow2(tlprcyStart, 1); - brcbgxEnd = MathUtil.intCeilDivPow2(brprcxEnd, 1); - brcbgyEnd = MathUtil.intCeilDivPow2(brprcyEnd, 1); + tlcbgxStart = MathUtil.getInstance().intCeilDivPow2(tlprcxStart, 1); + tlcbgyStart = MathUtil.getInstance().intCeilDivPow2(tlprcyStart, 1); + brcbgxEnd = MathUtil.getInstance().intCeilDivPow2(brprcxEnd, 1); + brcbgyEnd = MathUtil.getInstance().intCeilDivPow2(brprcyEnd, 1); cbgwidthexpn = pdx - 1; cbgheightexpn = pdy - 1; } - cblkwidthexpn = MathUtil.intMin(tccp.getCodeBlockWidth(), cbgwidthexpn); - cblkheightexpn = MathUtil.intMin(tccp.getCodeBlockHeight(), cbgheightexpn); + cblkwidthexpn = MathUtil.getInstance().intMin(tccp.getCodeBlockWidth(), cbgwidthexpn); + cblkheightexpn = MathUtil.getInstance().intMin(tccp.getCodeBlockHeight(), cbgheightexpn); for (bandNo = 0; bandNo < res.getNoOfBands(); bandNo++) { int x0b, y0b, i; @@ -211,16 +218,20 @@ public void tcdMallocEncode(Tcd tcd, OpenJpegImage image, CodingParameters codin if (band.getBandNo() == 0) { /* band border (global) */ - band.setX0(MathUtil.intCeilDivPow2(tilec.getX0(), levelno)); - band.setY0(MathUtil.intCeilDivPow2(tilec.getY0(), levelno)); - band.setX1(MathUtil.intCeilDivPow2(tilec.getX1(), levelno)); - band.setY1(MathUtil.intCeilDivPow2(tilec.getY1(), levelno)); + band.setX0(MathUtil.getInstance().intCeilDivPow2(tilec.getX0(), levelno)); + band.setY0(MathUtil.getInstance().intCeilDivPow2(tilec.getY0(), levelno)); + band.setX1(MathUtil.getInstance().intCeilDivPow2(tilec.getX1(), levelno)); + band.setY1(MathUtil.getInstance().intCeilDivPow2(tilec.getY1(), levelno)); } else { /* band border (global) */ - band.setX0(MathUtil.intCeilDivPow2(tilec.getX0() - (1 << levelno) * x0b, levelno + 1)); - band.setY0(MathUtil.intCeilDivPow2(tilec.getY0() - (1 << levelno) * y0b, levelno + 1)); - band.setX1(MathUtil.intCeilDivPow2(tilec.getX1() - (1 << levelno) * x0b, levelno + 1)); - band.setY1(MathUtil.intCeilDivPow2(tilec.getY1() - (1 << levelno) * y0b, levelno + 1)); + band.setX0(MathUtil.getInstance().intCeilDivPow2(tilec.getX0() - (1 << levelno) * x0b, + levelno + 1)); + band.setY0(MathUtil.getInstance().intCeilDivPow2(tilec.getY0() - (1 << levelno) * y0b, + levelno + 1)); + band.setX1(MathUtil.getInstance().intCeilDivPow2(tilec.getX1() - (1 << levelno) * x0b, + levelno + 1)); + band.setY1(MathUtil.getInstance().intCeilDivPow2(tilec.getY1() - (1 << levelno) * y0b, + levelno + 1)); } ss = tccp.getStepsizes()[resNo == 0 ? 0 : 3 * (resNo - 1) + bandNo + 1]; @@ -250,15 +261,19 @@ public void tcdMallocEncode(Tcd tcd, OpenJpegImage image, CodingParameters codin TcdPrecinct prc = band.getPrecincts()[precNo]; /* precinct size (global) */ - prc.setX0(MathUtil.intMax(cbgxStart, band.getX0())); - prc.setY0(MathUtil.intMax(cbgyStart, band.getY0())); - prc.setX1(MathUtil.intMin(cbgxEnd, band.getX1())); - prc.setY1(MathUtil.intMin(cbgyEnd, band.getY1())); - - tlcblkxStart = MathUtil.intFloorDivPow2(prc.getX0(), cblkwidthexpn) << cblkwidthexpn; - tlcblkyStart = MathUtil.intFloorDivPow2(prc.getY0(), cblkheightexpn) << cblkheightexpn; - brcblkxEnd = MathUtil.intCeilDivPow2(prc.getX1(), cblkwidthexpn) << cblkwidthexpn; - brcblkyEnd = MathUtil.intCeilDivPow2(prc.getY1(), cblkheightexpn) << cblkheightexpn; + prc.setX0(MathUtil.getInstance().intMax(cbgxStart, band.getX0())); + prc.setY0(MathUtil.getInstance().intMax(cbgyStart, band.getY0())); + prc.setX1(MathUtil.getInstance().intMin(cbgxEnd, band.getX1())); + prc.setY1(MathUtil.getInstance().intMin(cbgyEnd, band.getY1())); + + tlcblkxStart = MathUtil.getInstance().intFloorDivPow2(prc.getX0(), + cblkwidthexpn) << cblkwidthexpn; + tlcblkyStart = MathUtil.getInstance().intFloorDivPow2(prc.getY0(), + cblkheightexpn) << cblkheightexpn; + brcblkxEnd = MathUtil.getInstance().intCeilDivPow2(prc.getX1(), + cblkwidthexpn) << cblkwidthexpn; + brcblkyEnd = MathUtil.getInstance().intCeilDivPow2(prc.getY1(), + cblkheightexpn) << cblkheightexpn; prc.setCWidth((brcblkxEnd - tlcblkxStart) >> cblkwidthexpn); prc.setCHeight((brcblkyEnd - tlcblkyStart) >> cblkheightexpn); @@ -277,15 +292,15 @@ public void tcdMallocEncode(Tcd tcd, OpenJpegImage image, CodingParameters codin TcdCodeBlockEncoder cblk = prc.getTcdCodeBlockEncoder()[codeBlockNo]; /* code-block size (global) */ - cblk.setX0(MathUtil.intMax(cblkxStart, prc.getX0())); - cblk.setY0(MathUtil.intMax(cblkyStart, prc.getY0())); - cblk.setX1(MathUtil.intMin(cblkxEnd, prc.getX1())); - cblk.setY1(MathUtil.intMin(cblkyEnd, prc.getY1())); + cblk.setX0(MathUtil.getInstance().intMax(cblkxStart, prc.getX0())); + cblk.setY0(MathUtil.getInstance().intMax(cblkyStart, prc.getY0())); + cblk.setX1(MathUtil.getInstance().intMin(cblkxEnd, prc.getX1())); + cblk.setY1(MathUtil.getInstance().intMin(cblkyEnd, prc.getY1())); cblk.setData(new byte[8192 + 2]); /* - * FIXME: mqcInitEncode and mqc_byteout underrun the buffer if we don't do this. - * Why? + * FIX ME: mqcInitEncode and mqc_byteout underrun the buffer if we don't do + * this. Why? */ cblk.setDataIndex(cblk.getDataIndex() + 2); cblk.setLayers(new TcdLayer[100]); @@ -296,10 +311,9 @@ public void tcdMallocEncode(Tcd tcd, OpenJpegImage image, CodingParameters codin } } } - - /* tcd_dump(stdout, tcd, &tcd->tcdImage); */ } + @SuppressWarnings({ "java:S125", "java:S1659", "java:S3776" }) public void tcdFreeEncode(Tcd tcd) { int tileNo, compNo, resNo, bandNo, precNo, codeBlockNo; @@ -343,6 +357,7 @@ public void tcdFreeEncode(Tcd tcd) { tcd.getTcdImage().setTiles(null); } + @SuppressWarnings({ "java:S1659", "java:1854", "java:S3358", "java:S3776", "java:S6541", "unused" }) public void tcdInitEncode(Tcd tcd, OpenJpegImage image, CodingParameters codingParameters, int currentTileNo) { int tileNo, compNo, resNo, bandNo, precNo, codeBlockNo; @@ -356,23 +371,26 @@ public void tcdInitEncode(Tcd tcd, OpenJpegImage image, CodingParameters codingP TcdTile tile = tcd.getTcdImage().getTiles()[0]; /* 4 borders of the tile rescale on the image if necessary */ - tile.setX0(MathUtil.intMax(codingParameters.getTileX0() + p * codingParameters.getTileDX(), image.getX0())); - tile.setY0(MathUtil.intMax(codingParameters.getTileY0() + q * codingParameters.getTileDY(), image.getY0())); - tile.setX1(MathUtil.intMin(codingParameters.getTileX0() + (p + 1) * codingParameters.getTileDX(), image.getX1())); - tile.setY1(MathUtil.intMin(codingParameters.getTileY0() + (q + 1) * codingParameters.getTileDY(), image.getY1())); + tile.setX0(MathUtil.getInstance().intMax(codingParameters.getTileX0() + p * codingParameters.getTileDX(), + image.getX0())); + tile.setY0(MathUtil.getInstance().intMax(codingParameters.getTileY0() + q * codingParameters.getTileDY(), + image.getY0())); + tile.setX1(MathUtil.getInstance() + .intMin(codingParameters.getTileX0() + (p + 1) * codingParameters.getTileDX(), image.getX1())); + tile.setY1(MathUtil.getInstance() + .intMin(codingParameters.getTileY0() + (q + 1) * codingParameters.getTileDY(), image.getY1())); tile.setNoOfComps(image.getNoOfComps()); - /* tile->PPT=image->PPT; */ /* Modification of the RATE >> */ for (j = 0; j < tcp.getNoOfLayers(); j++) { tcp.getRates()[j] = tcp.getRates()[j] != 0 ? codingParameters.getTilePartOn() != 0 - ? (((float) (tile.getNoOfComps() * (tile.getX1() - tile.getX0()) * (tile.getY1() - tile.getY0()) - * image.getComps()[0].getPrec())) - / (tcp.getRates()[j] * 8 * image.getComps()[0].getDX() * image.getComps()[0].getDY())) - - (((tcd.getCurTotalNoOfTileParts() - 1) * 14) / tcp.getNoOfLayers()) - : ((float) (tile.getNoOfComps() * (tile.getX1() - tile.getX0()) * (tile.getY1() - tile.getY0()) - * image.getComps()[0].getPrec())) + ? (tile.getNoOfComps() * (tile.getX1() - tile.getX0()) * (tile.getY1() - tile.getY0()) + * image.getComps()[0].getPrec()) + / (tcp.getRates()[j] * 8f * image.getComps()[0].getDX() * image.getComps()[0].getDY()) + - (((tcd.getCurTotalNoOfTileParts() - 1) * 14f) / tcp.getNoOfLayers()) + : (tile.getNoOfComps() * (tile.getX1() - tile.getX0()) * (tile.getY1() - tile.getY0()) + * image.getComps()[0].getPrec()) / (tcp.getRates()[j] * 8 * image.getComps()[0].getDX() * image.getComps()[0].getDY()) : 0; @@ -392,10 +410,10 @@ public void tcdInitEncode(Tcd tcd, OpenJpegImage image, CodingParameters codingP TcdTileComponent tilec = tile.getComps()[compNo]; /* border of each tile component (global) */ - tilec.setX0(MathUtil.intCeilDiv(tile.getX0(), image.getComps()[compNo].getDX())); - tilec.setY0(MathUtil.intCeilDiv(tile.getY0(), image.getComps()[compNo].getDY())); - tilec.setX1(MathUtil.intCeilDiv(tile.getX1(), image.getComps()[compNo].getDX())); - tilec.setY1(MathUtil.intCeilDiv(tile.getY1(), image.getComps()[compNo].getDY())); + tilec.setX0(MathUtil.getInstance().intCeilDiv(tile.getX0(), image.getComps()[compNo].getDX())); + tilec.setY0(MathUtil.getInstance().intCeilDiv(tile.getY0(), image.getComps()[compNo].getDY())); + tilec.setX1(MathUtil.getInstance().intCeilDiv(tile.getX1(), image.getComps()[compNo].getDX())); + tilec.setY1(MathUtil.getInstance().intCeilDiv(tile.getY1(), image.getComps()[compNo].getDY())); tilec.setIData(new int[(tilec.getX1() - tilec.getX0()) * (tilec.getY1() - tilec.getY0())]); tilec.setFData(new double[(tilec.getX1() - tilec.getX0()) * (tilec.getY1() - tilec.getY0())]); @@ -412,10 +430,10 @@ public void tcdInitEncode(Tcd tcd, OpenJpegImage image, CodingParameters codingP TcdResolution res = tilec.getResolutions()[resNo]; /* border for each resolution level (global) */ - res.setX0(MathUtil.intCeilDivPow2(tilec.getX0(), levelno)); - res.setY0(MathUtil.intCeilDivPow2(tilec.getY0(), levelno)); - res.setX1(MathUtil.intCeilDivPow2(tilec.getX1(), levelno)); - res.setY1(MathUtil.intCeilDivPow2(tilec.getY1(), levelno)); + res.setX0(MathUtil.getInstance().intCeilDivPow2(tilec.getX0(), levelno)); + res.setY0(MathUtil.getInstance().intCeilDivPow2(tilec.getY0(), levelno)); + res.setX1(MathUtil.getInstance().intCeilDivPow2(tilec.getX1(), levelno)); + res.setY1(MathUtil.getInstance().intCeilDivPow2(tilec.getY1(), levelno)); res.setNoOfBands(resNo == 0 ? 1 : 3); /* p. 35, table A-23, ISO/IEC FDIS154444-1 : 2000 (18 august 2000) */ @@ -427,10 +445,10 @@ public void tcdInitEncode(Tcd tcd, OpenJpegImage image, CodingParameters codingP pdy = 15; } /* p. 64, B.6, ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */ - tlprcxStart = MathUtil.intFloorDivPow2(res.getX0(), pdx) << pdx; - tlprcyStart = MathUtil.intFloorDivPow2(res.getY0(), pdy) << pdy; - brprcxEnd = MathUtil.intCeilDivPow2(res.getX1(), pdx) << pdx; - brprcyEnd = MathUtil.intCeilDivPow2(res.getY1(), pdy) << pdy; + tlprcxStart = MathUtil.getInstance().intFloorDivPow2(res.getX0(), pdx) << pdx; + tlprcyStart = MathUtil.getInstance().intFloorDivPow2(res.getY0(), pdy) << pdy; + brprcxEnd = MathUtil.getInstance().intCeilDivPow2(res.getX1(), pdx) << pdx; + brprcyEnd = MathUtil.getInstance().intCeilDivPow2(res.getY1(), pdy) << pdy; res.setPWidth((brprcxEnd - tlprcxStart) >> pdx); res.setPHeight((brprcyEnd - tlprcyStart) >> pdy); @@ -443,16 +461,16 @@ public void tcdInitEncode(Tcd tcd, OpenJpegImage image, CodingParameters codingP cbgwidthexpn = pdx; cbgheightexpn = pdy; } else { - tlcbgxStart = MathUtil.intCeilDivPow2(tlprcxStart, 1); - tlcbgyStart = MathUtil.intCeilDivPow2(tlprcyStart, 1); - brcbgxEnd = MathUtil.intCeilDivPow2(brprcxEnd, 1); - brcbgyEnd = MathUtil.intCeilDivPow2(brprcyEnd, 1); + tlcbgxStart = MathUtil.getInstance().intCeilDivPow2(tlprcxStart, 1); + tlcbgyStart = MathUtil.getInstance().intCeilDivPow2(tlprcyStart, 1); + brcbgxEnd = MathUtil.getInstance().intCeilDivPow2(brprcxEnd, 1); + brcbgyEnd = MathUtil.getInstance().intCeilDivPow2(brprcyEnd, 1); cbgwidthexpn = pdx - 1; cbgheightexpn = pdy - 1; } - cblkwidthexpn = MathUtil.intMin(tccp.getCodeBlockWidth(), cbgwidthexpn); - cblkheightexpn = MathUtil.intMin(tccp.getCodeBlockHeight(), cbgheightexpn); + cblkwidthexpn = MathUtil.getInstance().intMin(tccp.getCodeBlockWidth(), cbgwidthexpn); + cblkheightexpn = MathUtil.getInstance().intMin(tccp.getCodeBlockHeight(), cbgheightexpn); for (bandNo = 0; bandNo < res.getNoOfBands(); bandNo++) { int x0b, y0b; @@ -467,15 +485,19 @@ public void tcdInitEncode(Tcd tcd, OpenJpegImage image, CodingParameters codingP if (band.getBandNo() == 0) { /* band border */ - band.setX0(MathUtil.intCeilDivPow2(tilec.getX0(), levelno)); - band.setY0(MathUtil.intCeilDivPow2(tilec.getY0(), levelno)); - band.setX1(MathUtil.intCeilDivPow2(tilec.getX1(), levelno)); - band.setY1(MathUtil.intCeilDivPow2(tilec.getY1(), levelno)); + band.setX0(MathUtil.getInstance().intCeilDivPow2(tilec.getX0(), levelno)); + band.setY0(MathUtil.getInstance().intCeilDivPow2(tilec.getY0(), levelno)); + band.setX1(MathUtil.getInstance().intCeilDivPow2(tilec.getX1(), levelno)); + band.setY1(MathUtil.getInstance().intCeilDivPow2(tilec.getY1(), levelno)); } else { - band.setX0(MathUtil.intCeilDivPow2(tilec.getX0() - (1 << levelno) * x0b, levelno + 1)); - band.setY0(MathUtil.intCeilDivPow2(tilec.getY0() - (1 << levelno) * y0b, levelno + 1)); - band.setX1(MathUtil.intCeilDivPow2(tilec.getX1() - (1 << levelno) * x0b, levelno + 1)); - band.setY1(MathUtil.intCeilDivPow2(tilec.getY1() - (1 << levelno) * y0b, levelno + 1)); + band.setX0(MathUtil.getInstance().intCeilDivPow2(tilec.getX0() - (1 << levelno) * x0b, + levelno + 1)); + band.setY0(MathUtil.getInstance().intCeilDivPow2(tilec.getY0() - (1 << levelno) * y0b, + levelno + 1)); + band.setX1(MathUtil.getInstance().intCeilDivPow2(tilec.getX1() - (1 << levelno) * x0b, + levelno + 1)); + band.setY1(MathUtil.getInstance().intCeilDivPow2(tilec.getY1() - (1 << levelno) * y0b, + levelno + 1)); } ss = tccp.getStepsizes()[resNo == 0 ? 0 : 3 * (resNo - 1) + bandNo + 1]; @@ -483,7 +505,7 @@ public void tcdInitEncode(Tcd tcd, OpenJpegImage image, CodingParameters codingP : DwtHelper.getInstance().dwtGetGain(band.getBandNo()); noOfBps = image.getComps()[compNo].getPrec() + gain; band.setStepSize( - (float) ((1.0 + ss.getMant() / 2048.0) * Math.pow(2.0, noOfBps - ss.getExpn()))); + (float) ((1.0 + ss.getMant() / 2048.0) * Math.pow(2.0, (double)noOfBps - ss.getExpn()))); band.setNoOfBps(ss.getExpn() + tccp.getNoOfGaurdBits() - 1); /* WHY -1 ? */ for (precNo = 0; precNo < res.getPWidth() * res.getPHeight(); precNo++) { @@ -497,15 +519,19 @@ public void tcdInitEncode(Tcd tcd, OpenJpegImage image, CodingParameters codingP TcdPrecinct prc = band.getPrecincts()[precNo]; /* precinct size (global) */ - prc.setX0(MathUtil.intMax(cbgxStart, band.getX0())); - prc.setY0(MathUtil.intMax(cbgyStart, band.getY0())); - prc.setX1(MathUtil.intMin(cbgxEnd, band.getX1())); - prc.setY1(MathUtil.intMin(cbgyEnd, band.getY1())); - - tlcblkxStart = MathUtil.intFloorDivPow2(prc.getX0(), cblkwidthexpn) << cblkwidthexpn; - tlcblkyStart = MathUtil.intFloorDivPow2(prc.getY0(), cblkheightexpn) << cblkheightexpn; - brcblkxEnd = MathUtil.intCeilDivPow2(prc.getX1(), cblkwidthexpn) << cblkwidthexpn; - brcblkyEnd = MathUtil.intCeilDivPow2(prc.getY1(), cblkheightexpn) << cblkheightexpn; + prc.setX0(MathUtil.getInstance().intMax(cbgxStart, band.getX0())); + prc.setY0(MathUtil.getInstance().intMax(cbgyStart, band.getY0())); + prc.setX1(MathUtil.getInstance().intMin(cbgxEnd, band.getX1())); + prc.setY1(MathUtil.getInstance().intMin(cbgyEnd, band.getY1())); + + tlcblkxStart = MathUtil.getInstance().intFloorDivPow2(prc.getX0(), + cblkwidthexpn) << cblkwidthexpn; + tlcblkyStart = MathUtil.getInstance().intFloorDivPow2(prc.getY0(), + cblkheightexpn) << cblkheightexpn; + brcblkxEnd = MathUtil.getInstance().intCeilDivPow2(prc.getX1(), + cblkwidthexpn) << cblkwidthexpn; + brcblkyEnd = MathUtil.getInstance().intCeilDivPow2(prc.getY1(), + cblkheightexpn) << cblkheightexpn; prc.setCWidth((brcblkxEnd - tlcblkxStart) >> cblkwidthexpn); prc.setCHeight((brcblkyEnd - tlcblkyStart) >> cblkheightexpn); @@ -531,13 +557,13 @@ public void tcdInitEncode(Tcd tcd, OpenJpegImage image, CodingParameters codingP TcdCodeBlockEncoder cblk = prc.getTcdCodeBlockEncoder()[codeBlockNo]; /* code-block size (global) */ - cblk.setX0(MathUtil.intMax(cblkxStart, prc.getX0())); - cblk.setY0(MathUtil.intMax(cblkyStart, prc.getY0())); - cblk.setX1(MathUtil.intMin(cblkxEnd, prc.getX1())); - cblk.setY1(MathUtil.intMin(cblkyEnd, prc.getY1())); + cblk.setX0(MathUtil.getInstance().intMax(cblkxStart, prc.getX0())); + cblk.setY0(MathUtil.getInstance().intMax(cblkyStart, prc.getY0())); + cblk.setX1(MathUtil.getInstance().intMin(cblkxEnd, prc.getX1())); + cblk.setY1(MathUtil.getInstance().intMin(cblkyEnd, prc.getY1())); cblk.setData(new byte[8192 + 2]); /* - * FIXME: mqcInitEncode and mqc_byteout underrun the buffer if we don't do this. + * FIX ME: mqcInitEncode and mqc_byteout underrun the buffer if we don't do this. * Why? */ cblk.setDataIndex(cblk.getDataIndex() + 2); @@ -549,10 +575,9 @@ public void tcdInitEncode(Tcd tcd, OpenJpegImage image, CodingParameters codingP } /* resNo */ } /* compNo */ } /* tileNo */ - - /* tcd_dump(stdout, tcd, &tcd->tcdImage); */ } + @SuppressWarnings({ "java:S1659", "java:S3626", "java:S3776"}) public void tcdMallocDecode(Tcd tcd, OpenJpegImage image, CodingParameters codingParameters) { int i, j, tileNo, p, q; long x0 = 0, y0 = 0, x1 = 0, y1 = 0, w, h; @@ -567,7 +592,7 @@ public void tcdMallocDecode(Tcd tcd, OpenJpegImage image, CodingParameters codin * tile really present in the codestream */ - for (j = 0; j < codingParameters.getTileNoSize(); j++) { + for (j = 0; j < codingParameters.getTileNoSize(); j++) { tileNo = codingParameters.getTileNo()[j]; tcd.getTcdImage().getTiles()[codingParameters.getTileNo()[tileNo]] = new TcdTile(); TcdTile tile = tcd.getTcdImage().getTiles()[codingParameters.getTileNo()[tileNo]]; @@ -589,27 +614,32 @@ public void tcdMallocDecode(Tcd tcd, OpenJpegImage image, CodingParameters codin tilec = tile.getComps()[i]; p = tileNo % codingParameters.getTileWidth(); /* si numerotation matricielle .. */ - q = tileNo / codingParameters.getTileWidth(); /* .. coordonnees de la tile (q,p) q pour ligne et p pour colonne */ + q = tileNo / codingParameters + .getTileWidth(); /* .. coordonnees de la tile (q,p) q pour ligne et p pour colonne */ /* 4 borders of the tile rescale on the image if necessary */ - tile.setX0(MathUtil.intMax(codingParameters.getTileX0() + p * codingParameters.getTileDX(), image.getX0())); - tile.setY0(MathUtil.intMax(codingParameters.getTileY0() + q * codingParameters.getTileDY(), image.getY0())); - tile.setX1(MathUtil.intMin(codingParameters.getTileX0() + (p + 1) * codingParameters.getTileDX(), image.getX1())); - tile.setY1(MathUtil.intMin(codingParameters.getTileY0() + (q + 1) * codingParameters.getTileDY(), image.getY1())); - - tilec.setX0(MathUtil.intCeilDiv(tile.getX0(), image.getComps()[i].getDX())); - tilec.setY0(MathUtil.intCeilDiv(tile.getY0(), image.getComps()[i].getDY())); - tilec.setX1(MathUtil.intCeilDiv(tile.getX1(), image.getComps()[i].getDX())); - tilec.setY1(MathUtil.intCeilDiv(tile.getY1(), image.getComps()[i].getDY())); - - x0 = j == 0 ? tilec.getX0() : MathUtil.intMin((int) x0, tilec.getX0()); - y0 = j == 0 ? tilec.getY0() : MathUtil.intMin((int) y0, tilec.getX0()); - x1 = j == 0 ? tilec.getX1() : MathUtil.intMax((int) x1, tilec.getX1()); - y1 = j == 0 ? tilec.getY1() : MathUtil.intMax((int) y1, tilec.getY1()); + tile.setX0(MathUtil.getInstance() + .intMax(codingParameters.getTileX0() + p * codingParameters.getTileDX(), image.getX0())); + tile.setY0(MathUtil.getInstance() + .intMax(codingParameters.getTileY0() + q * codingParameters.getTileDY(), image.getY0())); + tile.setX1(MathUtil.getInstance() + .intMin(codingParameters.getTileX0() + (p + 1) * codingParameters.getTileDX(), image.getX1())); + tile.setY1(MathUtil.getInstance() + .intMin(codingParameters.getTileY0() + (q + 1) * codingParameters.getTileDY(), image.getY1())); + + tilec.setX0(MathUtil.getInstance().intCeilDiv(tile.getX0(), image.getComps()[i].getDX())); + tilec.setY0(MathUtil.getInstance().intCeilDiv(tile.getY0(), image.getComps()[i].getDY())); + tilec.setX1(MathUtil.getInstance().intCeilDiv(tile.getX1(), image.getComps()[i].getDX())); + tilec.setY1(MathUtil.getInstance().intCeilDiv(tile.getY1(), image.getComps()[i].getDY())); + + x0 = j == 0 ? tilec.getX0() : MathUtil.getInstance().intMin((int) x0, tilec.getX0()); + y0 = j == 0 ? tilec.getY0() : MathUtil.getInstance().intMin((int) y0, tilec.getX0()); + x1 = j == 0 ? tilec.getX1() : MathUtil.getInstance().intMax((int) x1, tilec.getX1()); + y1 = j == 0 ? tilec.getY1() : MathUtil.getInstance().intMax((int) y1, tilec.getY1()); } - w = MathUtil.intCeilDivPow2((int) (x1 - x0), image.getComps()[i].getFactor()); - h = MathUtil.intCeilDivPow2((int) (y1 - y0), image.getComps()[i].getFactor()); + w = MathUtil.getInstance().intCeilDivPow2((int) (x1 - x0), image.getComps()[i].getFactor()); + h = MathUtil.getInstance().intCeilDivPow2((int) (y1 - y0), image.getComps()[i].getFactor()); image.getComps()[i].setWidth((int) w); image.getComps()[i].setHeight((int) h); @@ -618,6 +648,7 @@ public void tcdMallocDecode(Tcd tcd, OpenJpegImage image, CodingParameters codin } } + @SuppressWarnings({ "java:S1659", "java:S1854", "java:S3776", "java:S6541", "unused"}) public void tcdMallocDecodeTile(Tcd tcd, OpenJpegImage image, CodingParameters codingParameters, int tileNo, CodeStreamInfo codeStreamInfo) { int compNo, resNo, bandNo, precNo, codeBlockNo; @@ -636,10 +667,10 @@ public void tcdMallocDecodeTile(Tcd tcd, OpenJpegImage image, CodingParameters c TcdTileComponent tilec = tile.getComps()[compNo]; /* border of each tile component (global) */ - tilec.setX0(MathUtil.intCeilDiv(tile.getX0(), image.getComps()[compNo].getDX())); - tilec.setY0(MathUtil.intCeilDiv(tile.getY0(), image.getComps()[compNo].getDY())); - tilec.setX1(MathUtil.intCeilDiv(tile.getX1(), image.getComps()[compNo].getDX())); - tilec.setY1(MathUtil.intCeilDiv(tile.getY1(), image.getComps()[compNo].getDY())); + tilec.setX0(MathUtil.getInstance().intCeilDiv(tile.getX0(), image.getComps()[compNo].getDX())); + tilec.setY0(MathUtil.getInstance().intCeilDiv(tile.getY0(), image.getComps()[compNo].getDY())); + tilec.setX1(MathUtil.getInstance().intCeilDiv(tile.getX1(), image.getComps()[compNo].getDX())); + tilec.setY1(MathUtil.getInstance().intCeilDiv(tile.getY1(), image.getComps()[compNo].getDY())); tilec.setNoOfResolutions(tccp.getNoOfResolutions()); tilec.setResolutions(new TcdResolution[tilec.getNoOfResolutions()]); @@ -656,10 +687,10 @@ public void tcdMallocDecodeTile(Tcd tcd, OpenJpegImage image, CodingParameters c TcdResolution res = tilec.getResolutions()[resNo]; /* border for each resolution level (global) */ - res.setX0(MathUtil.intCeilDivPow2(tilec.getX0(), levelno)); - res.setY0(MathUtil.intCeilDivPow2(tilec.getY0(), levelno)); - res.setX1(MathUtil.intCeilDivPow2(tilec.getX1(), levelno)); - res.setY1(MathUtil.intCeilDivPow2(tilec.getY1(), levelno)); + res.setX0(MathUtil.getInstance().intCeilDivPow2(tilec.getX0(), levelno)); + res.setY0(MathUtil.getInstance().intCeilDivPow2(tilec.getY0(), levelno)); + res.setX1(MathUtil.getInstance().intCeilDivPow2(tilec.getX1(), levelno)); + res.setY1(MathUtil.getInstance().intCeilDivPow2(tilec.getY1(), levelno)); res.setNoOfBands(resNo == 0 ? 1 : 3); /* p. 35, table A-23, ISO/IEC FDIS154444-1 : 2000 (18 august 2000) */ @@ -672,10 +703,10 @@ public void tcdMallocDecodeTile(Tcd tcd, OpenJpegImage image, CodingParameters c } /* p. 64, B.6, ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */ - tlprcxStart = MathUtil.intFloorDivPow2(res.getX0(), pdx) << pdx; - tlprcyStart = MathUtil.intFloorDivPow2(res.getY0(), pdy) << pdy; - brprcxEnd = MathUtil.intCeilDivPow2(res.getX1(), pdx) << pdx; - brprcyEnd = MathUtil.intCeilDivPow2(res.getY1(), pdy) << pdy; + tlprcxStart = MathUtil.getInstance().intFloorDivPow2(res.getX0(), pdx) << pdx; + tlprcyStart = MathUtil.getInstance().intFloorDivPow2(res.getY0(), pdy) << pdy; + brprcxEnd = MathUtil.getInstance().intCeilDivPow2(res.getX1(), pdx) << pdx; + brprcyEnd = MathUtil.getInstance().intCeilDivPow2(res.getY1(), pdy) << pdy; res.setPWidth((res.getX0() == res.getX1()) ? 0 : ((brprcxEnd - tlprcxStart) >> pdx)); res.setPHeight((res.getY0() == res.getY1()) ? 0 : ((brprcyEnd - tlprcyStart) >> pdy)); @@ -688,16 +719,16 @@ public void tcdMallocDecodeTile(Tcd tcd, OpenJpegImage image, CodingParameters c cbgwidthexpn = pdx; cbgheightexpn = pdy; } else { - tlcbgxStart = MathUtil.intCeilDivPow2(tlprcxStart, 1); - tlcbgyStart = MathUtil.intCeilDivPow2(tlprcyStart, 1); - brcbgxEnd = MathUtil.intCeilDivPow2(brprcxEnd, 1); - brcbgyEnd = MathUtil.intCeilDivPow2(brprcyEnd, 1); + tlcbgxStart = MathUtil.getInstance().intCeilDivPow2(tlprcxStart, 1); + tlcbgyStart = MathUtil.getInstance().intCeilDivPow2(tlprcyStart, 1); + brcbgxEnd = MathUtil.getInstance().intCeilDivPow2(brprcxEnd, 1); + brcbgyEnd = MathUtil.getInstance().intCeilDivPow2(brprcyEnd, 1); cbgwidthexpn = pdx - 1; cbgheightexpn = pdy - 1; } - cblkwidthexpn = MathUtil.intMin(tccp.getCodeBlockWidth(), cbgwidthexpn); - cblkheightexpn = MathUtil.intMin(tccp.getCodeBlockHeight(), cbgheightexpn); + cblkwidthexpn = MathUtil.getInstance().intMin(tccp.getCodeBlockWidth(), cbgwidthexpn); + cblkheightexpn = MathUtil.getInstance().intMin(tccp.getCodeBlockHeight(), cbgheightexpn); for (bandNo = 0; bandNo < res.getNoOfBands(); bandNo++) { res.getBands()[bandNo] = new TcdBand(); @@ -712,25 +743,29 @@ public void tcdMallocDecodeTile(Tcd tcd, OpenJpegImage image, CodingParameters c if (band.getBandNo() == 0) { /* band border (global) */ - band.setX0(MathUtil.intCeilDivPow2(tilec.getX0(), levelno)); - band.setY0(MathUtil.intCeilDivPow2(tilec.getY0(), levelno)); - band.setX1(MathUtil.intCeilDivPow2(tilec.getX1(), levelno)); - band.setY1(MathUtil.intCeilDivPow2(tilec.getY1(), levelno)); + band.setX0(MathUtil.getInstance().intCeilDivPow2(tilec.getX0(), levelno)); + band.setY0(MathUtil.getInstance().intCeilDivPow2(tilec.getY0(), levelno)); + band.setX1(MathUtil.getInstance().intCeilDivPow2(tilec.getX1(), levelno)); + band.setY1(MathUtil.getInstance().intCeilDivPow2(tilec.getY1(), levelno)); } else { /* band border (global) */ - band.setX0(MathUtil.intCeilDivPow2(tilec.getX0() - (1 << levelno) * x0b, levelno + 1)); - band.setY0(MathUtil.intCeilDivPow2(tilec.getY0() - (1 << levelno) * y0b, levelno + 1)); - band.setX1(MathUtil.intCeilDivPow2(tilec.getX1() - (1 << levelno) * x0b, levelno + 1)); - band.setY1(MathUtil.intCeilDivPow2(tilec.getY1() - (1 << levelno) * y0b, levelno + 1)); + band.setX0(MathUtil.getInstance().intCeilDivPow2(tilec.getX0() - (1 << levelno) * x0b, + levelno + 1)); + band.setY0(MathUtil.getInstance().intCeilDivPow2(tilec.getY0() - (1 << levelno) * y0b, + levelno + 1)); + band.setX1(MathUtil.getInstance().intCeilDivPow2(tilec.getX1() - (1 << levelno) * x0b, + levelno + 1)); + band.setY1(MathUtil.getInstance().intCeilDivPow2(tilec.getY1() - (1 << levelno) * y0b, + levelno + 1)); } ss = tccp.getStepsizes()[resNo == 0 ? 0 : 3 * (resNo - 1) + bandNo + 1]; - + gain = tccp.getQmfbid() == 0 ? DwtHelper.getInstance().dwtGetGainReal(band.getBandNo()) : DwtHelper.getInstance().dwtGetGain(band.getBandNo()); noOfBps = image.getComps()[compNo].getPrec() + gain; band.setStepSize( - (float) (((1.0 + ss.getMant() / 2048.0) * Math.pow(2.0, noOfBps - ss.getExpn())) * 0.5)); + (float) (((1.0 + ss.getMant() / 2048.0) * Math.pow(2.0, (double)noOfBps - ss.getExpn())) * 0.5)); band.setNoOfBps(ss.getExpn() + tccp.getNoOfGaurdBits() - 1); /* WHY -1 ? */ band.setPrecincts(new TcdPrecinct[res.getPWidth() * res.getPHeight()]); @@ -745,15 +780,18 @@ public void tcdMallocDecodeTile(Tcd tcd, OpenJpegImage image, CodingParameters c TcdPrecinct prc = band.getPrecincts()[precNo]; /* precinct size (global) */ - prc.setX0(MathUtil.intMax(cbgxStart, band.getX0())); - prc.setY0(MathUtil.intMax(cbgyStart, band.getY0())); - prc.setX1(MathUtil.intMin(cbgxEnd, band.getX1())); - prc.setY1(MathUtil.intMin(cbgyEnd, band.getY1())); - - tlcblkxStart = MathUtil.intFloorDivPow2(prc.getX0(), cblkwidthexpn) << cblkwidthexpn; - tlcblkyStart = MathUtil.intFloorDivPow2(prc.getY0(), cblkheightexpn) << cblkheightexpn; - brcblkxEnd = MathUtil.intCeilDivPow2(prc.getX1(), cblkwidthexpn) << cblkwidthexpn; - brcblkyEnd = MathUtil.intCeilDivPow2(prc.getY1(), cblkheightexpn) << cblkheightexpn; + prc.setX0(MathUtil.getInstance().intMax(cbgxStart, band.getX0())); + prc.setY0(MathUtil.getInstance().intMax(cbgyStart, band.getY0())); + prc.setX1(MathUtil.getInstance().intMin(cbgxEnd, band.getX1())); + prc.setY1(MathUtil.getInstance().intMin(cbgyEnd, band.getY1())); + + tlcblkxStart = MathUtil.getInstance().intFloorDivPow2(prc.getX0(), + cblkwidthexpn) << cblkwidthexpn; + tlcblkyStart = MathUtil.getInstance().intFloorDivPow2(prc.getY0(), + cblkheightexpn) << cblkheightexpn; + brcblkxEnd = MathUtil.getInstance().intCeilDivPow2(prc.getX1(), cblkwidthexpn) << cblkwidthexpn; + brcblkyEnd = MathUtil.getInstance().intCeilDivPow2(prc.getY1(), + cblkheightexpn) << cblkheightexpn; prc.setCWidth((brcblkxEnd - tlcblkxStart) >> cblkwidthexpn); prc.setCHeight((brcblkyEnd - tlcblkyStart) >> cblkheightexpn); @@ -773,22 +811,22 @@ public void tcdMallocDecodeTile(Tcd tcd, OpenJpegImage image, CodingParameters c cblk.setData(null); cblk.setSegs(null); /* code-block size (global) */ - cblk.setX0(MathUtil.intMax(cblkxStart, prc.getX0())); - cblk.setY0(MathUtil.intMax(cblkyStart, prc.getY0())); - cblk.setX1(MathUtil.intMin(cblkxEnd, prc.getX1())); - cblk.setY1(MathUtil.intMin(cblkyEnd, prc.getY1())); + cblk.setX0(MathUtil.getInstance().intMax(cblkxStart, prc.getX0())); + cblk.setY0(MathUtil.getInstance().intMax(cblkyStart, prc.getY0())); + cblk.setX1(MathUtil.getInstance().intMin(cblkxEnd, prc.getX1())); + cblk.setY1(MathUtil.getInstance().intMin(cblkyEnd, prc.getY1())); cblk.setNoOfSegs(0); } } /* precNo */ } /* bandNo */ } /* resNo */ } /* compNo */ - /* tcd_dump(stdout, tcd, &tcd->tcdImage); */ } + @SuppressWarnings({ "java:S1659", "java:S1854", "java:S3776", "java:S6541"}) private void tcdMakeLayerFixed(Tcd tcd, int layno, int final1) { int compNo, resNo, bandNo, precNo, codeBlockNo; - int value; /* , matrice[tcdTcp->numlayers][tcdTile.getComps()[0].numresolutions][3]; */ + int value; int[][][] matrice = new int[10][10][3]; int i, j, k; @@ -801,8 +839,8 @@ private void tcdMakeLayerFixed(Tcd tcd, int layno, int final1) { for (i = 0; i < tcdTcp.getNoOfLayers(); i++) { for (j = 0; j < tilec.getNoOfResolutions(); j++) { for (k = 0; k < 3; k++) { - matrice[i][j][k] = (int) (codingParameters.getMatrice()[i * tilec.getNoOfResolutions() * 3 + j * 3 + k] - * (float) (tcd.getImage().getComps()[compNo].getPrec() / 16.0)); + matrice[i][j][k] = (int) (codingParameters.getMatrice()[i * tilec.getNoOfResolutions() * 3 + + j * 3 + k] * (float) (tcd.getImage().getComps()[compNo].getPrec() / 16.0)); } } } @@ -883,6 +921,7 @@ private void tcdRateAllocateFixed(Tcd tcd) { } } + @SuppressWarnings({ "java:S1659", "java:S3776", "java:S6541" }) private void tcdMakeLayer(Tcd tcd, int layno, double thresh, int final1) { int compNo, resNo, bandNo, precNo, codeBlockNo, passno; @@ -958,6 +997,7 @@ private void tcdMakeLayer(Tcd tcd, int layno, double thresh, int final1) { } } + @SuppressWarnings({ "java:S135", "java:S1659", "java:S3626", "java:S3776", "java:S6541" }) private int tcdRateAllocate(Tcd tcd, byte[] dest, int len, CodeStreamInfo codeStreamInfo) { int compNo, resNo, bandNo, precNo, codeBlockNo, passno, layno; double min, max; @@ -1023,17 +1063,16 @@ private int tcdRateAllocate(Tcd tcd, byte[] dest, int len, CodeStreamInfo codeSt } /* bandNo */ } /* resNo */ - maxSE += (((double) (1 << tcd.getImage().getComps()[compNo].getPrec()) - 1.0) - * ((double) (1 << tcd.getImage().getComps()[compNo].getPrec()) - 1.0)) - * ((double) (tilec.getNoOfPixels())); + maxSE += (((1 << tcd.getImage().getComps()[compNo].getPrec()) - 1.0) + * ((1 << tcd.getImage().getComps()[compNo].getPrec()) - 1.0)) * (tilec.getNoOfPixels()); } /* compNo */ /* index file */ if (codeStreamInfo != null) { - TileInfo tile_info = codeStreamInfo.getTileInfo()[tcd.getTcdTileNo()]; - tile_info.setNoOfPixel(tcdTile.getNoOfPixels()); - tile_info.setDistortionTile(tcdTile.getDistortionTile()); - tile_info.setThresh(new double[tcdTcp.getNoOfLayers()]); + TileInfo tileInfo = codeStreamInfo.getTileInfo()[tcd.getTcdTileNo()]; + tileInfo.setNoOfPixel(tcdTile.getNoOfPixels()); + tileInfo.setDistortionTile(tcdTile.getDistortionTile()); + tileInfo.setThresh(new double[tcdTcp.getNoOfLayers()]); } for (layno = 0; layno < tcdTcp.getNoOfLayers(); layno++) { @@ -1041,16 +1080,16 @@ private int tcdRateAllocate(Tcd tcd, byte[] dest, int len, CodeStreamInfo codeSt double hi = max; int success = 0; int maxlen = tcdTcp.getRates()[layno] != 0 - ? MathUtil.intMin(((int) Math.ceil(tcdTcp.getRates()[layno])), len) + ? MathUtil.getInstance().intMin(((int) Math.ceil(tcdTcp.getRates()[layno])), len) : len; - double goodthresh = 0; - double stable_thresh = 0; + double goodThresh = 0; + double stableThresh = 0; int i; double distotarget; /* fixed_quality */ /* fixed_quality */ distotarget = tcdTile.getDistortionTile() - - ((K * maxSE) / Math.pow((float) 10, tcdTcp.getDistortionRatio()[layno] / 10)); + - ((K * maxSE) / Math.pow(10, tcdTcp.getDistortionRatio()[layno] / 10)); /* * Don't try to find an optimal threshold but rather take everything not @@ -1060,7 +1099,8 @@ private int tcdRateAllocate(Tcd tcd, byte[] dest, int len, CodeStreamInfo codeSt */ if (((codingParameters.getDistortionAllocation() == 1) && (tcdTcp.getRates()[layno] > 0)) || ((codingParameters.getFixedQuality() == 1) && (tcdTcp.getDistortionRatio()[layno] > 0))) { - Tier2 t2 = Tier2Helper.getInstance().tier2Create(tcd.getCodecContextInfo(), tcd.getImage(), codingParameters); + Tier2 t2 = Tier2Helper.getInstance().tier2Create(tcd.getCodecContextInfo(), tcd.getImage(), + codingParameters); double thresh = 0; for (i = 0; i < 128; i++) { @@ -1072,9 +1112,9 @@ private int tcdRateAllocate(Tcd tcd, byte[] dest, int len, CodeStreamInfo codeSt if (codingParameters.getFixedQuality() != 0) { /* fixed_quality */ if (codingParameters.getCinemaMode().value() != 0) { - l = Tier2Helper.getInstance().tier2EncodePackets(t2, tcd.getTcdTileNo(), tcdTile, layno + 1, dest, - maxlen, codeStreamInfo, tcd.getCurTilePartNo(), tcd.getTilePartPosition(), tcd.getCurPiNo(), - J2KT2Mode.THRESH_CALC, tcd.getCurTotalNoOfTileParts()); + l = Tier2Helper.getInstance().tier2EncodePackets(t2, tcd.getTcdTileNo(), tcdTile, layno + 1, + dest, maxlen, codeStreamInfo, tcd.getCurTilePartNo(), tcd.getTilePartPosition(), + tcd.getCurPiNo(), J2KT2Mode.THRESH_CALC, tcd.getCurTotalNoOfTileParts()); if (l == -999) { lo = thresh; continue; @@ -1083,7 +1123,7 @@ private int tcdRateAllocate(Tcd tcd, byte[] dest, int len, CodeStreamInfo codeSt : cumDistortion[layno - 1] + tcdTile.getDistortionLayer()[layno]; if (distoachieved < distotarget) { hi = thresh; - stable_thresh = thresh; + stableThresh = thresh; continue; } else { lo = thresh; @@ -1094,34 +1134,30 @@ private int tcdRateAllocate(Tcd tcd, byte[] dest, int len, CodeStreamInfo codeSt : (cumDistortion[layno - 1] + tcdTile.getDistortionLayer()[layno]); if (distoachieved < distotarget) { hi = thresh; - stable_thresh = thresh; + stableThresh = thresh; continue; } lo = thresh; } } else { - l = Tier2Helper.getInstance().tier2EncodePackets(t2, tcd.getTcdTileNo(), tcdTile, layno + 1, dest, maxlen, - codeStreamInfo, tcd.getCurTilePartNo(), tcd.getTilePartPosition(), tcd.getCurPiNo(), - J2KT2Mode.THRESH_CALC, tcd.getCurTotalNoOfTileParts()); - /* TODO: what to do with l ??? seek / tell ??? */ - /* - * opj_event_msg(tcd->codecContextInfo, EVT_INFO, "rate alloc: len=%d, max=%d\n", l, - * maxlen); - */ + l = Tier2Helper.getInstance().tier2EncodePackets(t2, tcd.getTcdTileNo(), tcdTile, layno + 1, + dest, maxlen, codeStreamInfo, tcd.getCurTilePartNo(), tcd.getTilePartPosition(), + tcd.getCurPiNo(), J2KT2Mode.THRESH_CALC, tcd.getCurTotalNoOfTileParts()); + /* TO DO: what to do with l ??? seek / tell ??? */ if (l == -999) { lo = thresh; continue; } hi = thresh; - stable_thresh = thresh; + stableThresh = thresh; } } success = 1; - goodthresh = stable_thresh == 0 ? thresh : stable_thresh; + goodThresh = stableThresh == 0 ? thresh : stableThresh; Tier2Helper.getInstance().tier2Destroy(t2); } else { success = 1; - goodthresh = min; + goodThresh = min; } if (success == 0) { @@ -1129,9 +1165,9 @@ private int tcdRateAllocate(Tcd tcd, byte[] dest, int len, CodeStreamInfo codeSt } if (codeStreamInfo != null) { /* Threshold for Marcela Index */ - codeStreamInfo.getTileInfo()[tcd.getTcdTileNo()].getThresh()[layno] = goodthresh; + codeStreamInfo.getTileInfo()[tcd.getTcdTileNo()].getThresh()[layno] = goodThresh; } - tcdMakeLayer(tcd, layno, goodthresh, 1); + tcdMakeLayer(tcd, layno, goodThresh, 1); /* fixed_quality */ cumDistortion[layno] = (layno == 0) ? tcdTile.getDistortionLayer()[0] @@ -1141,6 +1177,7 @@ private int tcdRateAllocate(Tcd tcd, byte[] dest, int len, CodeStreamInfo codeSt return 1; } + @SuppressWarnings({ "java:S1659", "java:S3776", "java:S6541" }) public int tcdEncodeTile(Tcd tcd, int tileNo, byte[] dest, int len, CodeStreamInfo codeStreamInfo) { int compNo; int l, i, numpacks = 0; @@ -1192,12 +1229,13 @@ public int tcdEncodeTile(Tcd tcd, int tileNo, byte[] dest, int len, CodeStreamIn int adjust = image.getComps()[compNo].getSgnd() != 0 ? 0 : 1 << (image.getComps()[compNo].getPrec() - 1); - int offsetX = MathUtil.intCeilDiv(image.getX0(), image.getComps()[compNo].getDX()); - int offsetY = MathUtil.intCeilDiv(image.getY0(), image.getComps()[compNo].getDY()); + int offsetX = MathUtil.getInstance().intCeilDiv(image.getX0(), image.getComps()[compNo].getDX()); + int offsetY = MathUtil.getInstance().intCeilDiv(image.getY0(), image.getComps()[compNo].getDY()); TcdTileComponent tilec = tile.getComps()[compNo]; int tw = tilec.getX1() - tilec.getX0(); - int w = MathUtil.intCeilDiv(image.getX1() - image.getX0(), image.getComps()[compNo].getDX()); + int w = MathUtil.getInstance().intCeilDiv(image.getX1() - image.getX0(), + image.getComps()[compNo].getDX()); /* extract tile data */ @@ -1263,7 +1301,8 @@ public int tcdEncodeTile(Tcd tcd, int tileNo, byte[] dest, int len, CodeStreamIn if (codeStreamInfo != null) { codeStreamInfo.setIndexWrite(0); } - if (codingParameters.getDistortionAllocation() != 0 || codingParameters.getFixedQuality() != 0) { /* fixed_quality */ + if (codingParameters.getDistortionAllocation() != 0 + || codingParameters.getFixedQuality() != 0) { /* fixed_quality */ /* Normal Rate/distortion allocation */ tcdRateAllocate(tcd, dest, len, codeStreamInfo); } else { @@ -1279,8 +1318,9 @@ public int tcdEncodeTile(Tcd tcd, int tileNo, byte[] dest, int len, CodeStreamIn } t2 = Tier2Helper.getInstance().tier2Create(tcd.getCodecContextInfo(), image, codingParameters); - l = Tier2Helper.getInstance().tier2EncodePackets(t2, tileNo, tile, tcdTcp.getNoOfLayers(), dest, len, codeStreamInfo, - tcd.getTilePartNo(), tcd.getTilePartPosition(), tcd.getCurPiNo(), J2KT2Mode.FINAL_PASS, tcd.getCurTotalNoOfTileParts()); + l = Tier2Helper.getInstance().tier2EncodePackets(t2, tileNo, tile, tcdTcp.getNoOfLayers(), dest, len, + codeStreamInfo, tcd.getTilePartNo(), tcd.getTilePartPosition(), tcd.getCurPiNo(), J2KT2Mode.FINAL_PASS, + tcd.getCurTotalNoOfTileParts()); Tier2Helper.getInstance().tier2Destroy(t2); /*---------------CLEAN-------------------*/ @@ -1299,8 +1339,8 @@ public int tcdEncodeTile(Tcd tcd, int tileNo, byte[] dest, int len, CodeStreamIn return l; } - public int tcdDecodeTile(Tcd tcd, byte[] src, int len, int tileNo, CodeStreamInfo codeStreamInfo, - boolean USE_JPWL) { + @SuppressWarnings({ "java:S1659", "java:S3776", "java:S6541" }) + public int tcdDecodeTile(Tcd tcd, byte[] src, int len, int tileNo, CodeStreamInfo codeStreamInfo, boolean useJPWL) { int l; int compNo; int eof = 0; @@ -1346,14 +1386,16 @@ public int tcdDecodeTile(Tcd tcd, byte[] src, int len, int tileNo, CodeStreamInf /*--------------TIER2------------------*/ tier2Time = System.currentTimeMillis(); /* time needed to decode a tile */ - t2 = Tier2Helper.getInstance().tier2Create(tcd.getCodecContextInfo(), tcd.getImage(), tcd.getCodingParameters()); - l = Tier2Helper.getInstance().tier2DecodePackets(t2, src, len, tileNo, tile, codeStreamInfo, USE_JPWL); + t2 = Tier2Helper.getInstance().tier2Create(tcd.getCodecContextInfo(), tcd.getImage(), + tcd.getCodingParameters()); + l = Tier2Helper.getInstance().tier2DecodePackets(t2, src, len, tileNo, tile, codeStreamInfo, useJPWL); Tier2Helper.getInstance().tier2Destroy(t2); tier2Time = System.currentTimeMillis() - tier2Time; + logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("tier2Time {0}", tier2Time)); if (l == -999) { eof = 1; - LOGGER.error(String.format("tcd_decode: incomplete bistream")); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "tcd_decode: incomplete bistream"); } /*------------------TIER1-----------------*/ @@ -1369,6 +1411,7 @@ public int tcdDecodeTile(Tcd tcd, byte[] src, int len, int tileNo, CodeStreamInf } Tier1Helper.getInstance().tier1Destroy(t1); tier1Time = System.currentTimeMillis() - tier1Time; + logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("tier1Time{0}", tier1Time)); /*----------------DWT---------------------*/ @@ -1378,11 +1421,11 @@ public int tcdDecodeTile(Tcd tcd, byte[] src, int len, int tileNo, CodeStreamInf int numres2decode; if (tcd.getCodingParameters().getReduce() != 0) { - tcd.getImage().getComps()[compNo] - .setResNoDecoded(tile.getComps()[compNo].getNoOfResolutions() - tcd.getCodingParameters().getReduce() - 1); + tcd.getImage().getComps()[compNo].setResNoDecoded( + tile.getComps()[compNo].getNoOfResolutions() - tcd.getCodingParameters().getReduce() - 1); if (tcd.getImage().getComps()[compNo].getResNoDecoded() < 0) { - LOGGER.error(String.format( - "Error decoding tile. The number of resolutions to remove [%d+1] is higher than the number of resolutions in the original codestream [%d] Modify the cp_reduce parameter.", + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE,LOGGER_EMPTY, MessageFormat.format( + "Error decoding tile. The number of resolutions to remove {0} is higher than the number of resolutions in the original codestream {1} Modify the cp_reduce parameter.", tcd.getCodingParameters().getReduce(), tile.getComps()[compNo].getNoOfResolutions())); return 0; } @@ -1398,17 +1441,18 @@ public int tcdDecodeTile(Tcd tcd, byte[] src, int len, int tileNo, CodeStreamInf } } dwtTime = System.currentTimeMillis() - dwtTime; + logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("dwtTime{0}", dwtTime)); /*----------------MCT-------------------*/ if (tcd.getTcp().getMct() != 0) { int n = (tile.getComps()[0].getX1() - tile.getComps()[0].getX0()) * (tile.getComps()[0].getY1() - tile.getComps()[0].getY0()); - if (tcd.getTcp().getTccps()[0].getQmfbid() == 1) //Lossless + if (tcd.getTcp().getTccps()[0].getQmfbid() == 1) // Lossless { MctHelper.getInstance().mctDecode(tile.getComps()[0].getIData(), tile.getComps()[1].getIData(), tile.getComps()[2].getIData(), n); - } else //Lossy + } else // Lossy { MctHelper.getInstance().mctDecodeReal(tile.getComps()[0].getFData(), tile.getComps()[1].getFData(), tile.getComps()[2].getFData(), n); @@ -1427,8 +1471,8 @@ public int tcdDecodeTile(Tcd tcd, byte[] src, int len, int tileNo, CodeStreamInf int tw = tilec.getX1() - tilec.getX0(); int w = imagec.getWidth(); - int offsetX = MathUtil.intCeilDivPow2(imagec.getX0(), imagec.getFactor()); - int offsetY = MathUtil.intCeilDivPow2(imagec.getY0(), imagec.getFactor()); + int offsetX = MathUtil.getInstance().intCeilDivPow2(imagec.getX0(), imagec.getFactor()); + int offsetY = MathUtil.getInstance().intCeilDivPow2(imagec.getY0(), imagec.getFactor()); int i, j; if (imagec.getData() == null) { @@ -1440,7 +1484,8 @@ public int tcdDecodeTile(Tcd tcd, byte[] src, int len, int tileNo, CodeStreamInf for (i = res.getX0(); i < res.getX1(); ++i) { int v = tilec.getIData()[i - res.getX0() + (j - res.getY0()) * tw]; v += adjust; - imagec.getData()[(i - offsetX) + (j - offsetY) * w] = MathUtil.intClamp(v, min, max); + imagec.getData()[(i - offsetX) + (j - offsetY) * w] = MathUtil.getInstance().intClamp(v, min, + max); } } } else { @@ -1449,7 +1494,8 @@ public int tcdDecodeTile(Tcd tcd, byte[] src, int len, int tileNo, CodeStreamInf double tmp = tilec.getFData()[i - res.getX0() + (j - res.getY0()) * tw]; int v = (int) leftRightIntDouble(tmp); v += adjust; - imagec.getData()[(i - offsetX) + (j - offsetY) * w] = MathUtil.intClamp(v, min, max); + imagec.getData()[(i - offsetX) + (j - offsetY) * w] = MathUtil.getInstance().intClamp(v, min, + max); } } } @@ -1458,6 +1504,7 @@ public int tcdDecodeTile(Tcd tcd, byte[] src, int len, int tileNo, CodeStreamInf } tileTime = System.currentTimeMillis() - tileTime; /* time needed to decode a tile */ + logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("tileTime{0}", tileTime)); if (eof != 0) { return 0; @@ -1479,6 +1526,7 @@ public void tcdFreeDecode(Tcd tcd) { tcdImage.setTiles(null); } + @SuppressWarnings({ "java:S1659", "java:S3776" }) public void tcdFreeDecodeTile(Tcd tcd, int tileNo) { int compNo, resNo, bandNo, precNo; diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/TgtHelper.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/TgtHelper.java index 09540de..5a34b85 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/TgtHelper.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/TgtHelper.java @@ -6,25 +6,25 @@ public class TgtHelper { // Static variable reference of singleInstance of type Singleton - private static TgtHelper singleInstance = null; - private TgtHelper() - { - super (); - } - - //synchronized method to control simultaneous access - public static synchronized TgtHelper getInstance() - { + private static TgtHelper singleInstance = null; + + private TgtHelper() { + super(); + } + + // synchronized method to control simultaneous access + public static synchronized TgtHelper getInstance() { if (singleInstance == null) singleInstance = new TgtHelper(); - - return singleInstance; + + return singleInstance; } - /* - ========================================================== - Tag-tree coder interface - ========================================================== - */ + + /* + * ========================================================== Tag-tree coder + * interface ========================================================== + */ + @SuppressWarnings({ "java:S1659", "java:S3776" }) public TgtTree tgtCreate(int numleafsh, int numleafsv) { int[] nplh = new int[32]; int[] nplv = new int[32]; @@ -35,7 +35,7 @@ public TgtTree tgtCreate(int numleafsh, int numleafsv) { int numlvls; int n; - tree = new TgtTree (); + tree = new TgtTree(); tree.setNoOfLeafSH(numleafsh); tree.setNoOfLeafSV(numleafsv); @@ -50,7 +50,7 @@ public TgtTree tgtCreate(int numleafsh, int numleafsv) { tree.setNoOfNodes(tree.getNoOfNodes() + n); ++numlvls; } while (n > 1); - + /* ADD */ if (tree.getNoOfNodes() == 0) { tree = null; @@ -64,7 +64,7 @@ public TgtTree tgtCreate(int numleafsh, int numleafsv) { int nodeIndex = 0; parentNodeIndex = tree.getNoOfLeafSH() * tree.getNoOfLeafSV(); parentNode0Index = parentNodeIndex; - + for (i = 0; i < numlvls - 1; ++i) { for (j = 0; j < nplv[i]; ++j) { k = nplh[i]; @@ -85,16 +85,15 @@ public TgtTree tgtCreate(int numleafsh, int numleafsv) { } } } - tree.getNodes()[nodeIndex].setParent (0); - + tree.getNodes()[nodeIndex].setParent(0); + tgtReset(tree); - + return tree; } public void tgtDestroy(TgtTree tree) { tree.setNodes(null); - tree = null; } public void tgtReset(TgtTree tree) { @@ -102,7 +101,7 @@ public void tgtReset(TgtTree tree) { if (tree == null) return; - + for (i = 0; i < tree.getNoOfNodes(); i++) { tree.getNodes()[i].setValue(999); tree.getNodes()[i].setLow(0); @@ -119,6 +118,7 @@ public void tgtSetValue(TgtTree tree, int leafNo, int value) { } } + @SuppressWarnings({ "java:S3776" }) public void tgtEncode(Bio bio, TgtTree tree, int leafNo, int threshold) { TgtNode[] stack = new TgtNode[31]; TgtNode[] stkptr; @@ -133,7 +133,7 @@ public void tgtEncode(Bio bio, TgtTree tree, int leafNo, int threshold) { stkptr[stackDataIndex++] = node; node = tree.getNodes()[node.getParent()]; } - + low = 0; for (;;) { if (low > node.getLow()) { @@ -141,7 +141,7 @@ public void tgtEncode(Bio bio, TgtTree tree, int leafNo, int threshold) { } else { low = node.getLow(); } - + while (low < threshold) { if (low >= node.getValue()) { if (node.getKnown() == 0) { @@ -153,8 +153,8 @@ public void tgtEncode(Bio bio, TgtTree tree, int leafNo, int threshold) { BioHelper.getInstance().bioWrite(bio, 0, 1); ++low; } - - node.setLow(low); + + node.setLow(low); if (stackDataIndex == stackIndex) break; node = stkptr[--stackDataIndex]; @@ -173,7 +173,7 @@ public int tgtDecode(Bio bio, TgtTree tree, int leafNo, int threshold) { stack[stackDataIndex++] = node; node = tree.getNodes()[node.getParent()]; } - + low = 0; for (;;) { if (low > node.getLow()) { @@ -194,7 +194,7 @@ public int tgtDecode(Bio bio, TgtTree tree, int leafNo, int threshold) { } node = stack[--stackDataIndex]; } - + return (node.getValue() < threshold) ? 1 : 0; } -} +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/Tier1Helper.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/Tier1Helper.java index 7895bb2..657e7c4 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/Tier1Helper.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/Tier1Helper.java @@ -1,8 +1,5 @@ package io.mosip.imagedecoder.openjpeg; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import io.mosip.imagedecoder.constant.openjpeg.OpenJpegConstant; import io.mosip.imagedecoder.model.openjpeg.CodecContextInfo; import io.mosip.imagedecoder.model.openjpeg.MQCoder; @@ -23,23 +20,21 @@ //T1 - Implementation of the tier-1 coding public class Tier1Helper { - private Logger LOGGER = LoggerFactory.getLogger(Tier1Helper.class); // Static variable reference of singleInstance of type Singleton - private static Tier1Helper singleInstance = null; - private Tier1Helper() - { - super (); - } - - //synchronized method to control simultaneous access - public static synchronized Tier1Helper getInstance() - { + private static Tier1Helper singleInstance = null; + + private Tier1Helper() { + super(); + } + + // synchronized method to control simultaneous access + public static synchronized Tier1Helper getInstance() { if (singleInstance == null) singleInstance = new Tier1Helper(); - - return singleInstance; + + return singleInstance; } - + private int tier1GetContextNoZC(int f, int orient) { return OpenJpegConstant.LUT_CONTEXTNO_ZC[(orient << 8) | (f & OpenJpegConstant.T1_SIG_OTH)]; } @@ -49,7 +44,8 @@ private int tier1GetContextNoSC(int f) { } private int tier1GetContextNoMAG(int f) { - int tmp1 = (f & OpenJpegConstant.T1_SIG_OTH) != 0 ? OpenJpegConstant.T1_CTXNO_MAG + 1 : OpenJpegConstant.T1_CTXNO_MAG; + int tmp1 = (f & OpenJpegConstant.T1_SIG_OTH) != 0 ? OpenJpegConstant.T1_CTXNO_MAG + 1 + : OpenJpegConstant.T1_CTXNO_MAG; int tmp2 = (f & OpenJpegConstant.T1_REFINE) != 0 ? OpenJpegConstant.T1_CTXNO_MAG + 2 : tmp1; return (tmp2); } @@ -93,18 +89,21 @@ private void tier1UpdateFlags(int[] flagsp, int flagspIndex, int s, int stride) flagsp[spIndex + 1] |= OpenJpegConstant.T1_SIG_NW; } + @SuppressWarnings({ "java:S107", "java:S1659", "java:S3776" }) private void tier1EncodeSigpassStep(Tier1 t1, int[] flagsp, int flagspIndex, int[] data, int dataIndex, int orient, int bpno, int one, int[] nmsedec, int nmsedecIndex, int type, int vsc) { - int v, flag; + int v; + int flag; MQCoder mqc = t1.getMqc(); /* MQC component */ flag = vsc != 0 - ? ((flagsp[flagspIndex]) - & (~(OpenJpegConstant.T1_SIG_S | OpenJpegConstant.T1_SIG_SE | OpenJpegConstant.T1_SIG_SW | OpenJpegConstant.T1_SGN_S))) + ? ((flagsp[flagspIndex]) & (~(OpenJpegConstant.T1_SIG_S | OpenJpegConstant.T1_SIG_SE + | OpenJpegConstant.T1_SIG_SW | OpenJpegConstant.T1_SGN_S))) : (flagsp[flagspIndex]); - if ((flag & OpenJpegConstant.T1_SIG_OTH) != 0 && (flag & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT)) == 0) { - v = (MathUtil.intAbs(data[dataIndex]) & one) != 0 ? 1 : 0; + if ((flag & OpenJpegConstant.T1_SIG_OTH) != 0 + && (flag & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT)) == 0) { + v = (MathUtil.getInstance().intAbs(data[dataIndex]) & one) != 0 ? 1 : 0; MQCoderHelper.getInstance().mqcSetCurrentContext(mqc, tier1GetContextNoZC(flag, orient)); /* ESSAI */ if (type == OpenJpegConstant.T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ MQCoderHelper.getInstance().mqcBypassEncode(mqc, v); @@ -113,7 +112,7 @@ private void tier1EncodeSigpassStep(Tier1 t1, int[] flagsp, int flagspIndex, int } if (v != 0) { v = data[dataIndex] < 0 ? 1 : 0; - nmsedec[nmsedecIndex] += tier1GetNmseDecSig(MathUtil.intAbs(data[dataIndex]), + nmsedec[nmsedecIndex] += tier1GetNmseDecSig(MathUtil.getInstance().intAbs(data[dataIndex]), bpno + OpenJpegConstant.T1_NMSEDEC_FRACBITS); MQCoderHelper.getInstance().mqcSetCurrentContext(mqc, tier1GetContextNoSC(flag)); /* ESSAI */ if (type == OpenJpegConstant.T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ @@ -127,18 +126,21 @@ private void tier1EncodeSigpassStep(Tier1 t1, int[] flagsp, int flagspIndex, int } } + @SuppressWarnings({ "java:S107", "java:S1659", "java:S3776" }) private void tier1DecodeSigpassStep(Tier1 t1, int[] flagsp, int flagspIndex, int[] data, int dataIndex, int orient, int oneplushalf, int type, int vsc) { - int v, flag; + int v; + int flag; Raw raw = t1.getRaw(); /* RAW component */ MQCoder mqc = t1.getMqc(); /* MQC component */ flag = vsc != 0 - ? ((flagsp[flagspIndex]) - & (~(OpenJpegConstant.T1_SIG_S | OpenJpegConstant.T1_SIG_SE | OpenJpegConstant.T1_SIG_SW | OpenJpegConstant.T1_SGN_S))) + ? ((flagsp[flagspIndex]) & (~(OpenJpegConstant.T1_SIG_S | OpenJpegConstant.T1_SIG_SE + | OpenJpegConstant.T1_SIG_SW | OpenJpegConstant.T1_SGN_S))) : (flagsp[flagspIndex]); - if ((flag & OpenJpegConstant.T1_SIG_OTH) != 0 && (flag & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT)) == 0) { + if ((flag & OpenJpegConstant.T1_SIG_OTH) != 0 + && (flag & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT)) == 0) { if (type == OpenJpegConstant.T1_TYPE_RAW) { if (RawHelper.getInstance().rawDecode(raw) != 0) { v = RawHelper.getInstance().rawDecode(raw); /* ESSAI */ @@ -158,6 +160,7 @@ private void tier1DecodeSigpassStep(Tier1 t1, int[] flagsp, int flagspIndex, int } } /* VSC and BYPASS */ + @SuppressWarnings({ "java:S1659" }) private void tier1EncodeSigpass(Tier1 t1, int bpno, int orient, int[] nmsedec, int nmsedecIndex, int type, int cblksty) { int i, j, k, one, vsc; @@ -166,7 +169,8 @@ private void tier1EncodeSigpass(Tier1 t1, int bpno, int orient, int[] nmsedec, i for (k = 0; k < t1.getHeight(); k += 4) { for (i = 0; i < t1.getWidth(); ++i) { for (j = k; j < k + 4 && j < t1.getHeight(); ++j) { - vsc = ((cblksty & OpenJpegConstant.J2K_CCP_CBLKSTY_VSC) != 0 && (j == k + 3 || j == t1.getHeight() - 1)) ? 1 : 0; + vsc = ((cblksty & OpenJpegConstant.J2K_CCP_CBLKSTY_VSC) != 0 + && (j == k + 3 || j == t1.getHeight() - 1)) ? 1 : 0; tier1EncodeSigpassStep(t1, t1.getFlags(), (((j + 1) * t1.getFlagsStride()) + i + 1), t1.getData(), ((j * t1.getWidth()) + i), orient, bpno, one, nmsedec, nmsedecIndex, type, vsc); } @@ -174,6 +178,7 @@ private void tier1EncodeSigpass(Tier1 t1, int bpno, int orient, int[] nmsedec, i } } + @SuppressWarnings({ "java:S1659" }) private void tier1DecodeSigpass(Tier1 t1, int bpno, int orient, int type, int cblksty) { int i, j, k, one, half, oneplushalf, vsc; one = 1 << bpno; @@ -182,7 +187,8 @@ private void tier1DecodeSigpass(Tier1 t1, int bpno, int orient, int type, int cb for (k = 0; k < t1.getHeight(); k += 4) { for (i = 0; i < t1.getWidth(); ++i) { for (j = k; j < k + 4 && j < t1.getHeight(); ++j) { - vsc = ((cblksty & OpenJpegConstant.J2K_CCP_CBLKSTY_VSC) != 0 && (j == k + 3 || j == t1.getHeight() - 1)) ? 1 : 0; + vsc = ((cblksty & OpenJpegConstant.J2K_CCP_CBLKSTY_VSC) != 0 + && (j == k + 3 || j == t1.getHeight() - 1)) ? 1 : 0; tier1DecodeSigpassStep(t1, t1.getFlags(), (((j + 1) * t1.getFlagsStride()) + i + 1), t1.getData(), ((j * t1.getWidth()) + i), orient, oneplushalf, type, vsc); } @@ -191,6 +197,7 @@ private void tier1DecodeSigpass(Tier1 t1, int bpno, int orient, int type, int cb } /* VSC and BYPASS */ + @SuppressWarnings({ "java:S107", "java:S1659" }) private void tier1EncodeRefpassStep(Tier1 t1, int[] flagsp, int flagspIndex, int[] data, int dataIndex, int bpno, int one, int[] nmsedec, int nmsedecIndex, int type, int vsc) { int v, flag; @@ -198,13 +205,13 @@ private void tier1EncodeRefpassStep(Tier1 t1, int[] flagsp, int flagspIndex, int MQCoder mqc = t1.getMqc(); /* MQC component */ flag = vsc != 0 - ? ((flagsp[flagspIndex]) - & (~(OpenJpegConstant.T1_SIG_S | OpenJpegConstant.T1_SIG_SE | OpenJpegConstant.T1_SIG_SW | OpenJpegConstant.T1_SGN_S))) + ? ((flagsp[flagspIndex]) & (~(OpenJpegConstant.T1_SIG_S | OpenJpegConstant.T1_SIG_SE + | OpenJpegConstant.T1_SIG_SW | OpenJpegConstant.T1_SGN_S))) : (flagsp[flagspIndex]); if ((flag & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT)) == OpenJpegConstant.T1_SIG) { - nmsedec[nmsedecIndex] += tier1GetNmseDecRef(MathUtil.intAbs(data[dataIndex]), + nmsedec[nmsedecIndex] += tier1GetNmseDecRef(MathUtil.getInstance().intAbs(data[dataIndex]), bpno + OpenJpegConstant.T1_NMSEDEC_FRACBITS); - v = (MathUtil.intAbs(data[dataIndex]) & one) != 0 ? 1 : 0; + v = (MathUtil.getInstance().intAbs(data[dataIndex]) & one) != 0 ? 1 : 0; MQCoderHelper.getInstance().mqcSetCurrentContext(mqc, tier1GetContextNoMAG(flag)); /* ESSAI */ if (type == OpenJpegConstant.T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ MQCoderHelper.getInstance().mqcBypassEncode(mqc, v); @@ -215,16 +222,17 @@ private void tier1EncodeRefpassStep(Tier1 t1, int[] flagsp, int flagspIndex, int } } - private void tier1DecodeRefpassStep(Tier1 t1, int[] flagsp, int flagspIndex, int[] data, int dataIndex, - int poshalf, int neghalf, int type, int vsc) { + @SuppressWarnings({ "java:S107", "java:S1659" }) + private void tier1DecodeRefpassStep(Tier1 t1, int[] flagsp, int flagspIndex, int[] data, int dataIndex, int poshalf, + int neghalf, int type, int vsc) { int v, t, flag; MQCoder mqc = t1.getMqc(); /* MQC component */ Raw raw = t1.getRaw(); /* RAW component */ flag = vsc != 0 - ? ((flagsp[flagspIndex]) - & (~(OpenJpegConstant.T1_SIG_S | OpenJpegConstant.T1_SIG_SE | OpenJpegConstant.T1_SIG_SW | OpenJpegConstant.T1_SGN_S))) + ? ((flagsp[flagspIndex]) & (~(OpenJpegConstant.T1_SIG_S | OpenJpegConstant.T1_SIG_SE + | OpenJpegConstant.T1_SIG_SW | OpenJpegConstant.T1_SGN_S))) : (flagsp[flagspIndex]); if ((flag & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT)) == OpenJpegConstant.T1_SIG) { MQCoderHelper.getInstance().mqcSetCurrentContext(mqc, tier1GetContextNoMAG(flag)); /* ESSAI */ @@ -239,6 +247,7 @@ private void tier1DecodeRefpassStep(Tier1 t1, int[] flagsp, int flagspIndex, int } } /* VSC and BYPASS */ + @SuppressWarnings({ "java:S1659" }) private void tier1EncodeRefpass(Tier1 t1, int bpno, int[] nmsedec, int nmsedecIndex, int type, int cblksty) { int i, j, k, one, vsc; nmsedec[nmsedecIndex] = 0; @@ -246,7 +255,8 @@ private void tier1EncodeRefpass(Tier1 t1, int bpno, int[] nmsedec, int nmsedecIn for (k = 0; k < t1.getHeight(); k += 4) { for (i = 0; i < t1.getWidth(); ++i) { for (j = k; j < k + 4 && j < t1.getHeight(); ++j) { - vsc = ((cblksty & OpenJpegConstant.J2K_CCP_CBLKSTY_VSC) != 0 && (j == k + 3 || j == t1.getHeight() - 1)) ? 1 : 0; + vsc = ((cblksty & OpenJpegConstant.J2K_CCP_CBLKSTY_VSC) != 0 + && (j == k + 3 || j == t1.getHeight() - 1)) ? 1 : 0; tier1EncodeRefpassStep(t1, t1.getFlags(), (((j + 1) * t1.getFlagsStride()) + i + 1), t1.getData(), ((j * t1.getWidth()) + i), bpno, one, nmsedec, nmsedecIndex, type, vsc); } @@ -254,6 +264,7 @@ private void tier1EncodeRefpass(Tier1 t1, int bpno, int[] nmsedec, int nmsedecIn } } + @SuppressWarnings({ "java:S1659" }) private void tier1DecodeRefpassStep(Tier1 t1, int bpno, int type, int cblksty) { int i, j, k, one, poshalf, neghalf; int vsc; @@ -263,7 +274,8 @@ private void tier1DecodeRefpassStep(Tier1 t1, int bpno, int type, int cblksty) { for (k = 0; k < t1.getHeight(); k += 4) { for (i = 0; i < t1.getWidth(); ++i) { for (j = k; j < k + 4 && j < t1.getHeight(); ++j) { - vsc = ((cblksty & OpenJpegConstant.J2K_CCP_CBLKSTY_VSC) != 0 && (j == k + 3 || j == t1.getHeight() - 1)) ? 1 : 0; + vsc = ((cblksty & OpenJpegConstant.J2K_CCP_CBLKSTY_VSC) != 0 + && (j == k + 3 || j == t1.getHeight() - 1)) ? 1 : 0; tier1DecodeRefpassStep(t1, t1.getFlags(), (((j + 1) * t1.getFlagsStride()) + i + 1), t1.getData(), ((j * t1.getWidth()) + i), poshalf, neghalf, type, vsc); } @@ -272,26 +284,27 @@ private void tier1DecodeRefpassStep(Tier1 t1, int bpno, int type, int cblksty) { } /* VSC and BYPASS */ + @SuppressWarnings({ "java:S107", "java:S1659", "java:S3776" }) private void tier1EncodeClnpassStep(Tier1 t1, int[] flagsp, int flagspIndex, int[] data, int dataIndex, int orient, int bpno, int one, int[] nmsedec, int nmsedecIndex, int partial, int vsc) { int v, flag; - boolean LABEL_PARTIAL = false; + boolean labelPartial = false; MQCoder mqc = t1.getMqc(); /* MQC component */ flag = vsc != 0 - ? ((flagsp[flagspIndex]) - & (~(OpenJpegConstant.T1_SIG_S | OpenJpegConstant.T1_SIG_SE | OpenJpegConstant.T1_SIG_SW | OpenJpegConstant.T1_SGN_S))) + ? ((flagsp[flagspIndex]) & (~(OpenJpegConstant.T1_SIG_S | OpenJpegConstant.T1_SIG_SE + | OpenJpegConstant.T1_SIG_SW | OpenJpegConstant.T1_SGN_S))) : (flagsp[flagspIndex]); if (partial != 0) { - LABEL_PARTIAL = true; + labelPartial = true; } - if (!LABEL_PARTIAL) { + if (!labelPartial) { if ((flagsp[flagspIndex] & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT)) == 0) { MQCoderHelper.getInstance().mqcSetCurrentContext(mqc, tier1GetContextNoZC(flag, orient)); - v = (MathUtil.intAbs(data[dataIndex]) & one) != 0 ? 1 : 0; + v = (MathUtil.getInstance().intAbs(data[dataIndex]) & one) != 0 ? 1 : 0; MQCoderHelper.getInstance().mqcEncode(mqc, v); if (v != 0) { - nmsedec[nmsedecIndex] += tier1GetNmseDecSig(MathUtil.intAbs(data[dataIndex]), + nmsedec[nmsedecIndex] += tier1GetNmseDecSig(MathUtil.getInstance().intAbs(data[dataIndex]), bpno + OpenJpegConstant.T1_NMSEDEC_FRACBITS); MQCoderHelper.getInstance().mqcSetCurrentContext(mqc, tier1GetContextNoSC(flag)); v = data[dataIndex] < 0 ? 1 : 0; @@ -300,7 +313,7 @@ private void tier1EncodeClnpassStep(Tier1 t1, int[] flagsp, int flagspIndex, int } } } else { - nmsedec[nmsedecIndex] += tier1GetNmseDecSig(MathUtil.intAbs(data[dataIndex]), + nmsedec[nmsedecIndex] += tier1GetNmseDecSig(MathUtil.getInstance().intAbs(data[dataIndex]), bpno + OpenJpegConstant.T1_NMSEDEC_FRACBITS); MQCoderHelper.getInstance().mqcSetCurrentContext(mqc, tier1GetContextNoSC(flag)); v = data[dataIndex] < 0 ? 1 : 0; @@ -310,21 +323,22 @@ private void tier1EncodeClnpassStep(Tier1 t1, int[] flagsp, int flagspIndex, int flagsp[flagspIndex] &= ~OpenJpegConstant.T1_VISIT; } + @SuppressWarnings({ "java:S107", "java:S1659", "java:S3776" }) private void tier1DecodeClnpassStep(Tier1 t1, int[] flagsp, int flagspIndex, int[] data, int dataIndex, int orient, int oneplushalf, int partial, int vsc) { int v, flag; - boolean LABEL_PARTIAL = false; + boolean labelPartial = false; MQCoder mqc = t1.getMqc(); /* MQC component */ flag = vsc != 0 - ? ((flagsp[flagspIndex]) - & (~(OpenJpegConstant.T1_SIG_S | OpenJpegConstant.T1_SIG_SE | OpenJpegConstant.T1_SIG_SW | OpenJpegConstant.T1_SGN_S))) + ? ((flagsp[flagspIndex]) & (~(OpenJpegConstant.T1_SIG_S | OpenJpegConstant.T1_SIG_SE + | OpenJpegConstant.T1_SIG_SW | OpenJpegConstant.T1_SGN_S))) : (flagsp[flagspIndex]); - + if (partial != 0) { - LABEL_PARTIAL = true; + labelPartial = true; } - if (!LABEL_PARTIAL) { + if (!labelPartial) { if ((flag & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT)) == 0) { int zc = tier1GetContextNoZC(flag, orient); MQCoderHelper.getInstance().mqcSetCurrentContext(mqc, zc); @@ -349,6 +363,7 @@ private int tier1GetFlags(Tier1 t1, int x, int y) { return t1.getFlags()[((x) * (t1.getFlagsStride())) + (y)]; } + @SuppressWarnings({ "java:S1659", "java:S3776" }) private void tier1EncodeClnpass(Tier1 t1, int bpno, int orient, int[] nmsedec, int nmsedecIndex, int cblksty) { int i, j, k, one, agg, runLength, vsc; @@ -360,31 +375,34 @@ private void tier1EncodeClnpass(Tier1 t1, int bpno, int orient, int[] nmsedec, i for (i = 0; i < t1.getWidth(); ++i) { if (k + 3 < t1.getHeight()) { if ((cblksty & OpenJpegConstant.J2K_CCP_CBLKSTY_VSC) != 0) { - agg = !((tier1GetFlags(t1, 1 + k, 1 + i) - & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT | OpenJpegConstant.T1_SIG_OTH)) != 0 - || (tier1GetFlags(t1, 1 + k + 1, 1 + i) - & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT | OpenJpegConstant.T1_SIG_OTH)) != 0 - || (tier1GetFlags(t1, 1 + k + 2, 1 + i) - & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT | OpenJpegConstant.T1_SIG_OTH)) != 0 - || ((tier1GetFlags(t1, 1 + k + 3, 1 + i) & (~(OpenJpegConstant.T1_SIG_S | OpenJpegConstant.T1_SIG_SE - | OpenJpegConstant.T1_SIG_SW | OpenJpegConstant.T1_SGN_S))) - & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT | OpenJpegConstant.T1_SIG_OTH)) != 0) ? 1 : 0; + agg = !((tier1GetFlags(t1, 1 + k, 1 + i) & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT + | OpenJpegConstant.T1_SIG_OTH)) != 0 + || (tier1GetFlags(t1, 1 + k + 1, 1 + i) & (OpenJpegConstant.T1_SIG + | OpenJpegConstant.T1_VISIT | OpenJpegConstant.T1_SIG_OTH)) != 0 + || (tier1GetFlags(t1, 1 + k + 2, 1 + i) & (OpenJpegConstant.T1_SIG + | OpenJpegConstant.T1_VISIT | OpenJpegConstant.T1_SIG_OTH)) != 0 + || ((tier1GetFlags(t1, 1 + k + 3, 1 + i) + & (~(OpenJpegConstant.T1_SIG_S | OpenJpegConstant.T1_SIG_SE + | OpenJpegConstant.T1_SIG_SW | OpenJpegConstant.T1_SGN_S))) + & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT + | OpenJpegConstant.T1_SIG_OTH)) != 0) ? 1 : 0; } else { - agg = !((tier1GetFlags(t1, 1 + k, 1 + i) - & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT | OpenJpegConstant.T1_SIG_OTH)) != 0 - || (tier1GetFlags(t1, 1 + k + 1, 1 + i) - & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT | OpenJpegConstant.T1_SIG_OTH)) != 0 - || (tier1GetFlags(t1, 1 + k + 2, 1 + i) - & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT | OpenJpegConstant.T1_SIG_OTH)) != 0 - || (tier1GetFlags(t1, 1 + k + 3, 1 + i) - & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT | OpenJpegConstant.T1_SIG_OTH)) != 0) ? 1 : 0; + agg = !((tier1GetFlags(t1, 1 + k, 1 + i) & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT + | OpenJpegConstant.T1_SIG_OTH)) != 0 + || (tier1GetFlags(t1, 1 + k + 1, 1 + i) & (OpenJpegConstant.T1_SIG + | OpenJpegConstant.T1_VISIT | OpenJpegConstant.T1_SIG_OTH)) != 0 + || (tier1GetFlags(t1, 1 + k + 2, 1 + i) & (OpenJpegConstant.T1_SIG + | OpenJpegConstant.T1_VISIT | OpenJpegConstant.T1_SIG_OTH)) != 0 + || (tier1GetFlags(t1, 1 + k + 3, 1 + i) & (OpenJpegConstant.T1_SIG + | OpenJpegConstant.T1_VISIT | OpenJpegConstant.T1_SIG_OTH)) != 0) ? 1 : 0; } } else { agg = 0; } if (agg != 0) { for (runLength = 0; runLength < 4; ++runLength) { - if ((MathUtil.intAbs(t1.getData()[((k + runLength) * t1.getWidth()) + i]) & one) != 0) + if ((MathUtil.getInstance().intAbs(t1.getData()[((k + runLength) * t1.getWidth()) + i]) + & one) != 0) break; } MQCoderHelper.getInstance().mqcSetCurrentContext(mqc, OpenJpegConstant.T1_CTXNO_AGG); @@ -399,7 +417,8 @@ private void tier1EncodeClnpass(Tier1 t1, int bpno, int orient, int[] nmsedec, i runLength = 0; } for (j = k + runLength; j < k + 4 && j < t1.getHeight(); ++j) { - vsc = ((cblksty & OpenJpegConstant.J2K_CCP_CBLKSTY_VSC) != 0 && (j == k + 3 || j == t1.getHeight() - 1)) ? 1 : 0; + vsc = ((cblksty & OpenJpegConstant.J2K_CCP_CBLKSTY_VSC) != 0 + && (j == k + 3 || j == t1.getHeight() - 1)) ? 1 : 0; tier1EncodeClnpassStep(t1, t1.getFlags(), (((j + 1) * t1.getFlagsStride()) + i + 1), t1.getData(), ((j * t1.getWidth()) + i), orient, bpno, one, nmsedec, nmsedecIndex, ((agg != 0 && (j == k + runLength)) ? 1 : 0), vsc); @@ -408,6 +427,7 @@ private void tier1EncodeClnpass(Tier1 t1, int bpno, int orient, int[] nmsedec, i } } + @SuppressWarnings({ "java:S1659", "java:S1854", "java:S3776", "java:S6541" }) private void tier1DecodeClnpassStep(Tier1 t1, int bpno, int orient, int cblksty) { int i, j, k, one, half, oneplushalf, agg, runLength, vsc; int segsym = (cblksty & OpenJpegConstant.J2K_CCP_CBLKSTY_SEGSYM) != 0 ? 1 : 0; @@ -421,24 +441,26 @@ private void tier1DecodeClnpassStep(Tier1 t1, int bpno, int orient, int cblksty) for (i = 0; i < t1.getWidth(); ++i) { if (k + 3 < t1.getHeight()) { if ((cblksty & OpenJpegConstant.J2K_CCP_CBLKSTY_VSC) != 0) { - agg = !((tier1GetFlags(t1, 1 + k, 1 + i) - & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT | OpenJpegConstant.T1_SIG_OTH)) != 0 - || (tier1GetFlags(t1, 1 + k + 1, 1 + i) - & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT | OpenJpegConstant.T1_SIG_OTH)) != 0 - || (tier1GetFlags(t1, 1 + k + 2, 1 + i) - & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT | OpenJpegConstant.T1_SIG_OTH)) != 0 - || ((tier1GetFlags(t1, 1 + k + 3, 1 + i) & (~(OpenJpegConstant.T1_SIG_S | OpenJpegConstant.T1_SIG_SE - | OpenJpegConstant.T1_SIG_SW | OpenJpegConstant.T1_SGN_S))) - & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT | OpenJpegConstant.T1_SIG_OTH)) != 0) ? 1 : 0; + agg = !((tier1GetFlags(t1, 1 + k, 1 + i) & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT + | OpenJpegConstant.T1_SIG_OTH)) != 0 + || (tier1GetFlags(t1, 1 + k + 1, 1 + i) & (OpenJpegConstant.T1_SIG + | OpenJpegConstant.T1_VISIT | OpenJpegConstant.T1_SIG_OTH)) != 0 + || (tier1GetFlags(t1, 1 + k + 2, 1 + i) & (OpenJpegConstant.T1_SIG + | OpenJpegConstant.T1_VISIT | OpenJpegConstant.T1_SIG_OTH)) != 0 + || ((tier1GetFlags(t1, 1 + k + 3, 1 + i) + & (~(OpenJpegConstant.T1_SIG_S | OpenJpegConstant.T1_SIG_SE + | OpenJpegConstant.T1_SIG_SW | OpenJpegConstant.T1_SGN_S))) + & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT + | OpenJpegConstant.T1_SIG_OTH)) != 0) ? 1 : 0; } else { - agg = !((tier1GetFlags(t1, 1 + k, 1 + i) - & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT | OpenJpegConstant.T1_SIG_OTH)) != 0 - || (tier1GetFlags(t1, 1 + k + 1, 1 + i) - & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT | OpenJpegConstant.T1_SIG_OTH)) != 0 - || (tier1GetFlags(t1, 1 + k + 2, 1 + i) - & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT | OpenJpegConstant.T1_SIG_OTH)) != 0 - || (tier1GetFlags(t1, 1 + k + 3, 1 + i) - & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT | OpenJpegConstant.T1_SIG_OTH)) != 0) ? 1 : 0; + agg = !((tier1GetFlags(t1, 1 + k, 1 + i) & (OpenJpegConstant.T1_SIG | OpenJpegConstant.T1_VISIT + | OpenJpegConstant.T1_SIG_OTH)) != 0 + || (tier1GetFlags(t1, 1 + k + 1, 1 + i) & (OpenJpegConstant.T1_SIG + | OpenJpegConstant.T1_VISIT | OpenJpegConstant.T1_SIG_OTH)) != 0 + || (tier1GetFlags(t1, 1 + k + 2, 1 + i) & (OpenJpegConstant.T1_SIG + | OpenJpegConstant.T1_VISIT | OpenJpegConstant.T1_SIG_OTH)) != 0 + || (tier1GetFlags(t1, 1 + k + 3, 1 + i) & (OpenJpegConstant.T1_SIG + | OpenJpegConstant.T1_VISIT | OpenJpegConstant.T1_SIG_OTH)) != 0) ? 1 : 0; } } else { agg = 0; @@ -446,7 +468,7 @@ private void tier1DecodeClnpassStep(Tier1 t1, int bpno, int orient, int cblksty) if (agg != 0) { MQCoderHelper.getInstance().mqcSetCurrentContext(mqc, OpenJpegConstant.T1_CTXNO_AGG); int decodeValue = MQCoderHelper.getInstance().mqcDecode(mqc); - if (decodeValue== 0) { + if (decodeValue == 0) { continue; } MQCoderHelper.getInstance().mqcSetCurrentContext(mqc, OpenJpegConstant.T1_CTXNO_UNI); @@ -456,10 +478,12 @@ private void tier1DecodeClnpassStep(Tier1 t1, int bpno, int orient, int cblksty) runLength = 0; } for (j = k + runLength; j < k + 4 && j < t1.getHeight(); ++j) { - vsc = ((cblksty & OpenJpegConstant.J2K_CCP_CBLKSTY_VSC) != 0 && (j == k + 3 || j == t1.getHeight() - 1)) ? 1 : 0; - + vsc = ((cblksty & OpenJpegConstant.J2K_CCP_CBLKSTY_VSC) != 0 + && (j == k + 3 || j == t1.getHeight() - 1)) ? 1 : 0; + tier1DecodeClnpassStep(t1, t1.getFlags(), (((j + 1) * t1.getFlagsStride()) + i + 1), t1.getData(), - ((j * t1.getWidth()) + i), orient, oneplushalf, (agg != 0 && (j == k + runLength) ? 1 : 0), vsc); + ((j * t1.getWidth()) + i), orient, oneplushalf, (agg != 0 && (j == k + runLength) ? 1 : 0), + vsc); } } } @@ -470,22 +494,19 @@ private void tier1DecodeClnpassStep(Tier1 t1, int bpno, int orient, int cblksty) v = (v << 1) | MQCoderHelper.getInstance().mqcDecode(mqc); v = (v << 1) | MQCoderHelper.getInstance().mqcDecode(mqc); v = (v << 1) | MQCoderHelper.getInstance().mqcDecode(mqc); - /* - * if (v!=0xa) { opj_event_msg(t1->cinfo, EVT_WARNING, - * "Bad segmentation symbol %x\n", v); } - */ } } /* VSC and BYPASS */ /** mod fixed_quality */ - private double tier1GetWmseDecode(int nmsedec, int compno, int level, int orient, int bpno, int qmfbid, double stepsize, - int numcomps) { + @SuppressWarnings({ "java:S107", "java:S1659" }) + private double tier1GetWmseDecode(int nmsedec, int compno, int level, int orient, int bpno, int qmfbid, + double stepsize, int numcomps) { double w1, w2, wmsedec; if (qmfbid == 1) { w1 = (numcomps > 1) ? MctHelper.getInstance().mctGetNorm(compno) : 1.0; w2 = DwtHelper.getInstance().dwtGetNorm(level, orient); - } else { /* if (qmfbid == 0) */ + } else { w1 = (numcomps > 1) ? MctHelper.getInstance().mctGetNormReal(compno) : 1.0; w2 = DwtHelper.getInstance().dwtGetNormReal(level, orient); } @@ -503,9 +524,9 @@ private int allocateBuffers(Tier1 t1, int w, int h) { t1.setData(new int[datasize]); t1.setDataSize(datasize); } - for (int index=0; index < datasize; index++) + for (int index = 0; index < datasize; index++) t1.getData()[index] = 0; - + t1.setFlagsStride(w + 2); flagssize = t1.getFlagsStride() * (h + 2); @@ -513,7 +534,7 @@ private int allocateBuffers(Tier1 t1, int w, int h) { t1.setFlags(new int[flagssize]); t1.setFlagsSize(flagssize); } - for (int index=0; index < flagssize; index++) + for (int index = 0; index < flagssize; index++) t1.getFlags()[index] = 0; t1.setWidth(w); @@ -523,6 +544,7 @@ private int allocateBuffers(Tier1 t1, int w, int h) { } /** mod fixed_quality */ + @SuppressWarnings({ "java:S107", "java:S1659", "java:S1854", "java:S3776", "java:S3923", "java:S6541" }) private void tier1EncodeCodeBlock(Tier1 t1, TcdCodeBlockEncoder cblk, int orient, int compno, int level, int qmfbid, double stepsize, int cblksty, int numcomps, TcdTile tile) { double cumwmsedec = 0.0; @@ -539,10 +561,11 @@ private void tier1EncodeCodeBlock(Tier1 t1, TcdCodeBlockEncoder cblk, int orient max = 0; for (i = 0; i < t1.getWidth() * t1.getHeight(); ++i) { int tmp = Math.abs(t1.getData()[i]); - max = MathUtil.intMax(max, tmp); + max = MathUtil.getInstance().intMax(max, tmp); } - cblk.setNoOfBps(max != 0 ? (MathUtil.intFloorLog2(max) + 1) - OpenJpegConstant.T1_NMSEDEC_FRACBITS : 0); + cblk.setNoOfBps( + max != 0 ? (MathUtil.getInstance().intFloorLog2(max) + 1) - OpenJpegConstant.T1_NMSEDEC_FRACBITS : 0); bpno = cblk.getNoOfBps() - 1; passtype = 2; @@ -556,9 +579,9 @@ private void tier1EncodeCodeBlock(Tier1 t1, TcdCodeBlockEncoder cblk, int orient for (passno = 0; bpno >= 0; ++passno) { TcdPass pass = cblk.getPasses()[passno]; int correction = 3; - type = ((bpno < (cblk.getNoOfBps() - 4)) && (passtype < 2) && (cblksty & OpenJpegConstant.J2K_CCP_CBLKSTY_LAZY) != 0) - ? OpenJpegConstant.T1_TYPE_RAW - : OpenJpegConstant.T1_TYPE_MQ; + type = ((bpno < (cblk.getNoOfBps() - 4)) && (passtype < 2) + && (cblksty & OpenJpegConstant.J2K_CCP_CBLKSTY_LAZY) != 0) ? OpenJpegConstant.T1_TYPE_RAW + : OpenJpegConstant.T1_TYPE_MQ; switch (passtype) { case 0: @@ -573,10 +596,13 @@ private void tier1EncodeCodeBlock(Tier1 t1, TcdCodeBlockEncoder cblk, int orient if ((cblksty & OpenJpegConstant.J2K_CCP_CBLKSTY_SEGSYM) != 0) MQCoderHelper.getInstance().mqcSegMarkEncode(mqc); break; + default: + break; } /* fixed_quality */ - tempwmsedec = tier1GetWmseDecode(nmsedec[nmsedecIndex], compno, level, orient, bpno, qmfbid, stepsize, numcomps); + tempwmsedec = tier1GetWmseDecode(nmsedec[nmsedecIndex], compno, level, orient, bpno, qmfbid, stepsize, + numcomps); cumwmsedec += tempwmsedec; tile.setDistortionTile(tile.getDistortionTile() + tempwmsedec); @@ -585,8 +611,7 @@ private void tier1EncodeCodeBlock(Tier1 t1, TcdCodeBlockEncoder cblk, int orient if (type == OpenJpegConstant.T1_TYPE_RAW) { MQCoderHelper.getInstance().mqcFlush(mqc); correction = 1; - /* correction = mqcBypassFlushEncode(); */ - } else { /* correction = mqcRestartEncode(); */ + } else { MQCoderHelper.getInstance().mqcFlush(mqc); correction = 1; } @@ -598,8 +623,7 @@ private void tier1EncodeCodeBlock(Tier1 t1, TcdCodeBlockEncoder cblk, int orient if (type == OpenJpegConstant.T1_TYPE_RAW) { MQCoderHelper.getInstance().mqcFlush(mqc); correction = 1; - /* correction = mqcBypassFlushEncode(); */ - } else { /* correction = mqcRestartEncode(); */ + } else { MQCoderHelper.getInstance().mqcFlush(mqc); correction = 1; } @@ -616,7 +640,8 @@ private void tier1EncodeCodeBlock(Tier1 t1, TcdCodeBlockEncoder cblk, int orient if (pass.getTerm() != 0 && bpno > 0) { type = ((bpno < (cblk.getNoOfBps() - 4)) && (passtype < 2) - && (cblksty & OpenJpegConstant.J2K_CCP_CBLKSTY_LAZY) != 0) ? OpenJpegConstant.T1_TYPE_RAW : OpenJpegConstant.T1_TYPE_MQ; + && (cblksty & OpenJpegConstant.J2K_CCP_CBLKSTY_LAZY) != 0) ? OpenJpegConstant.T1_TYPE_RAW + : OpenJpegConstant.T1_TYPE_MQ; if (type == OpenJpegConstant.T1_TYPE_RAW) MQCoderHelper.getInstance().mqcBypassInitEncode(mqc); else @@ -624,7 +649,7 @@ private void tier1EncodeCodeBlock(Tier1 t1, TcdCodeBlockEncoder cblk, int orient } pass.setDistortionDec(cumwmsedec); - pass.setRate(MQCoderHelper.getInstance().mqcNoOfBytes(mqc) + correction); /* FIXME */ + pass.setRate(MQCoderHelper.getInstance().mqcNoOfBytes(mqc) + correction); /* FIX ME */ /* Code-switch "RESET" */ if ((cblksty & OpenJpegConstant.J2K_CCP_CBLKSTY_RESET) != 0) @@ -652,6 +677,7 @@ private void tier1EncodeCodeBlock(Tier1 t1, TcdCodeBlockEncoder cblk, int orient } } + @SuppressWarnings({ "java:S1659", "java:S1854", "java:S3776" }) private void tier1DecodeCodeBlock(Tier1 t1, TcdCodeBlockDecoder cblk, int orient, int roishift, int cblksty) { Raw raw = t1.getRaw(); /* RAW component */ MQCoder mqc = t1.getMqc(); /* MQC component */ @@ -677,9 +703,10 @@ private void tier1DecodeCodeBlock(Tier1 t1, TcdCodeBlockDecoder cblk, int orient /* BYPASS mode */ type = ((bpno <= (cblk.getNoOfBps() - 1) - 4) && (passtype < 2) - && (cblksty & OpenJpegConstant.J2K_CCP_CBLKSTY_LAZY) != 0) ? OpenJpegConstant.T1_TYPE_RAW : OpenJpegConstant.T1_TYPE_MQ; + && (cblksty & OpenJpegConstant.J2K_CCP_CBLKSTY_LAZY) != 0) ? OpenJpegConstant.T1_TYPE_RAW + : OpenJpegConstant.T1_TYPE_MQ; /* - * FIXME: check why we get here with a null pointer. Why? Partially downloaded + * FIX ME: check why we get here with a null pointer. Why? Partially downloaded * and/or corrupt textures? */ if (seg.getData() == null) { @@ -702,6 +729,8 @@ private void tier1DecodeCodeBlock(Tier1 t1, TcdCodeBlockDecoder cblk, int orient case 2: tier1DecodeClnpassStep(t1, bpno + 1, orient, cblksty); break; + default: + break; } if ((cblksty & OpenJpegConstant.J2K_CCP_CBLKSTY_RESET) != 0 && type == OpenJpegConstant.T1_TYPE_MQ) { @@ -742,10 +771,10 @@ public void tier1Destroy(Tier1 t1) { RawHelper.getInstance().rawDestroy(t1.getRaw()); t1.setData(null); t1.setFlags(null); - t1 = null; } } + @SuppressWarnings({ "java:S1659", "java:S3776" }) public void tier1EncodeCodeBlocks(Tier1 t1, TcdTile tile, Tcp tcp) { int compno, resNo, bandNo, precNo, codeBlockNo; @@ -794,10 +823,11 @@ public void tier1EncodeCodeBlocks(Tier1 t1, TcdTile tile, Tcp tcp) { for (j = 0; j < codeBlockHeight; ++j) { for (i = 0; i < codeBlockWidth; ++i) { int tmp = tilec.getIData()[fromIndex + ((j * tileWidth) + i)]; - t1.getData()[(j * codeBlockWidth) + i] = tmp << OpenJpegConstant.T1_NMSEDEC_FRACBITS; + t1.getData()[(j * codeBlockWidth) + + i] = tmp << OpenJpegConstant.T1_NMSEDEC_FRACBITS; } } - } else { /* if (tccp->qmfbid == 0) */ + } else { for (j = 0; j < codeBlockHeight; ++j) { for (i = 0; i < codeBlockWidth; ++i) { int tmp = (int) tilec.getFData()[fromIndex + ((j * tileWidth) + i)]; @@ -808,8 +838,9 @@ public void tier1EncodeCodeBlocks(Tier1 t1, TcdTile tile, Tcp tcp) { } } - tier1EncodeCodeBlock(t1, cblk, band.getBandNo(), compno, tilec.getNoOfResolutions() - 1 - resNo, - tccp.getQmfbid(), band.getStepSize(), tccp.getCodeBlockStyle(), tile.getNoOfComps(), tile); + tier1EncodeCodeBlock(t1, cblk, band.getBandNo(), compno, + tilec.getNoOfResolutions() - 1 - resNo, tccp.getQmfbid(), band.getStepSize(), + tccp.getCodeBlockStyle(), tile.getNoOfComps(), tile); } /* codeBlockNo */ } /* precNo */ @@ -818,6 +849,7 @@ public void tier1EncodeCodeBlocks(Tier1 t1, TcdTile tile, Tcp tcp) { } /* compno */ } + @SuppressWarnings({ "java:S1659", "java:S3776", "java:S6541" }) public void tier1DecodeCodeBlocks(Tier1 t1, TcdTileComponent tilec, TileComponentCodingParameters tccp) { int resNo, bandNo, precNo, codeBlockNo; int tileWidth = tilec.getX1() - tilec.getX0(); @@ -878,7 +910,7 @@ public void tier1DecodeCodeBlocks(Tier1 t1, TcdTileComponent tilec, TileComponen tilec.getIData()[fromIndex + ((j * tileWidth) + i)] = tmp / 2; } } - } else { /* if (tccp->qmfbid == 0) */ + } else { tilec.setIData(null); for (j = 0; j < codeBlockHeight; ++j) { for (i = 0; i < codeBlockWidth; ++i) { @@ -890,7 +922,7 @@ public void tier1DecodeCodeBlocks(Tier1 t1, TcdTileComponent tilec, TileComponen cblk.setData(null); cblk.setSegs(null); } /* codeBlockNo */ - + precinct.setTcdCodeBlockDecoder(null); } /* precNo */ } /* bandNo */ @@ -905,7 +937,7 @@ public void tier1DecodeCodeBlocks(Tier1 t1, TcdTileComponent tilec, TileComponen * @return Returns a * b */ private int fixMul(int a, int b) { - long temp = a * b; + long temp = (long) a * b; temp += temp & 4096; return (int) (temp >> 13); } diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/Tier2Helper.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/Tier2Helper.java index b264c6a..155120e 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/Tier2Helper.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/openjpeg/Tier2Helper.java @@ -1,7 +1,13 @@ package io.mosip.imagedecoder.openjpeg; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_EMPTY; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_IDTYPE; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_SESSIONID; + +import java.text.MessageFormat; + +import io.mosip.kernel.core.logger.spi.Logger; +import io.mosip.imagedecoder.logger.ImageDecoderLogger; import io.mosip.imagedecoder.constant.openjpeg.OpenJpegConstant; import io.mosip.imagedecoder.model.openjpeg.Bio; @@ -29,23 +35,22 @@ import io.mosip.imagedecoder.util.openjpeg.MathUtil; public class Tier2Helper { - private Logger LOGGER = LoggerFactory.getLogger(Tier2Helper.class); + private Logger logger = ImageDecoderLogger.getLogger(Tier2Helper.class); // Static variable reference of singleInstance of type Singleton - private static Tier2Helper singleInstance = null; - private Tier2Helper() - { - super (); - } - - //synchronized method to control simultaneous access - public static synchronized Tier2Helper getInstance() - { + private static Tier2Helper singleInstance = null; + + private Tier2Helper() { + super(); + } + + // synchronized method to control simultaneous access + public static synchronized Tier2Helper getInstance() { if (singleInstance == null) singleInstance = new Tier2Helper(); - - return singleInstance; + + return singleInstance; } - + private void tier2PutCommaCode(Bio bio, int n) { while (--n >= 0) { BioHelper.getInstance().bioWrite(bio, 1, 1); @@ -53,10 +58,10 @@ private void tier2PutCommaCode(Bio bio, int n) { BioHelper.getInstance().bioWrite(bio, 0, 1); } + @SuppressWarnings({ "java:S108"}) private int tier2GetCommaCode(Bio bio) { int n; for (n = 0; BioHelper.getInstance().bioRead(bio, 1) != 0; n++) { - ; } return n; } @@ -88,6 +93,7 @@ private int tier2GetNoOfPasses(Bio bio) { return (37 + BioHelper.getInstance().bioRead(bio, 7)); } + @SuppressWarnings({ "java:S1659", "java:S3776", "java:S6541" }) private int tier2EncodePacket(TcdTile tile, Tcp tcp, PiIterator pi, byte[] dest, int length, CodeStreamInfo codeStreamInfo, int tileno) { int bandNo, codeBlockNo; @@ -124,7 +130,8 @@ private int tier2EncodePacket(TcdTile tile, Tcp tcp, PiIterator pi, byte[] dest, for (codeBlockNo = 0; codeBlockNo < prc.getCWidth() * prc.getCHeight(); codeBlockNo++) { TcdCodeBlockEncoder cblk = prc.getTcdCodeBlockEncoder()[codeBlockNo]; cblk.setNoOfPasses(0); - TgtHelper.getInstance().tgtSetValue(prc.getImsbTree(), codeBlockNo, band.getNoOfBps() - cblk.getNoOfBps()); + TgtHelper.getInstance().tgtSetValue(prc.getImsbTree(), codeBlockNo, + band.getNoOfBps() - cblk.getNoOfBps()); } } } @@ -177,8 +184,8 @@ private int tier2EncodePacket(TcdTile tile, Tcp tcp, PiIterator pi, byte[] dest, nump++; len += pass.getLength(); if (pass.getTerm() != 0 || passNo == (cblk.getNoOfPasses() + layer.getNoOfPasses()) - 1) { - increment = MathUtil.intMax(increment, MathUtil.intFloorLog2(len) + 1 - - (cblk.getNoOfLengthBits() + MathUtil.intFloorLog2(nump))); + increment = MathUtil.getInstance().intMax(increment, MathUtil.getInstance().intFloorLog2(len) + + 1 - (cblk.getNoOfLengthBits() + MathUtil.getInstance().intFloorLog2(nump))); len = 0; nump = 0; } @@ -194,7 +201,8 @@ private int tier2EncodePacket(TcdTile tile, Tcp tcp, PiIterator pi, byte[] dest, nump++; len += pass.getLength(); if (pass.getTerm() != 0 || passNo == (cblk.getNoOfPasses() + layer.getNoOfPasses()) - 1) { - BioHelper.getInstance().bioWrite(bio, len, cblk.getNoOfLengthBits() + MathUtil.intFloorLog2(nump)); + BioHelper.getInstance().bioWrite(bio, len, + cblk.getNoOfLengthBits() + MathUtil.getInstance().intFloorLog2(nump)); len = 0; nump = 0; } @@ -224,7 +232,7 @@ private int tier2EncodePacket(TcdTile tile, Tcp tcp, PiIterator pi, byte[] dest, // Will be updated later by incrementing with packet start value if (codeStreamInfo != null && codeStreamInfo.getIndexWrite() != 0) { PacketInfo packetInfo = codeStreamInfo.getTileInfo()[tileno].getPacket()[codeStreamInfo.getPacketNo()]; - packetInfo.setEndPHPosition((int) (destIndex - 0)); + packetInfo.setEndPHPosition((destIndex - 0)); } /* INDEX >> */ @@ -247,7 +255,8 @@ private int tier2EncodePacket(TcdTile tile, Tcp tcp, PiIterator pi, byte[] dest, destIndex += layer.getLength(); /* << INDEX */ if (codeStreamInfo != null && codeStreamInfo.getIndexWrite() != 0) { - PacketInfo packetInfo = codeStreamInfo.getTileInfo()[tileno].getPacket()[codeStreamInfo.getPacketNo()]; + PacketInfo packetInfo = codeStreamInfo.getTileInfo()[tileno].getPacket()[codeStreamInfo + .getPacketNo()]; packetInfo.setDistortion(packetInfo.getDistortion() + layer.getDistortion()); if (codeStreamInfo.getDistortionMax() < packetInfo.getDistortion()) { codeStreamInfo.setDistortionMax(packetInfo.getDistortion()); @@ -260,26 +269,21 @@ private int tier2EncodePacket(TcdTile tile, Tcp tcp, PiIterator pi, byte[] dest, return (destIndex - 0); } + @SuppressWarnings({ "java:S3012", "java:S3776" }) private void tier2InitSegment(TcdCodeBlockDecoder cblk, int index, int codeblockStyle, int first) { TcdSegment seg; TcdSegment[] segs = null; - if (cblk.getSegs() != null) - { + if (cblk.getSegs() != null) { segs = new TcdSegment[cblk.getSegs().length + (index + 1)]; - for (int segIndex = 0; segIndex < cblk.getSegs().length; segIndex++) - { + for (int segIndex = 0; segIndex < cblk.getSegs().length; segIndex++) { segs[segIndex] = cblk.getSegs()[segIndex]; } - for (int segIndex = cblk.getSegs().length; segIndex < (cblk.getSegs().length + (index + 1)); segIndex++) - { + for (int segIndex = cblk.getSegs().length; segIndex < (cblk.getSegs().length + (index + 1)); segIndex++) { segs[segIndex] = new TcdSegment(); } - } - else - { + } else { segs = new TcdSegment[(index + 1)]; - for (int segIndex = 0; segIndex < segs.length; segIndex++) - { + for (int segIndex = 0; segIndex < segs.length; segIndex++) { segs[segIndex] = new TcdSegment(); } } @@ -305,13 +309,14 @@ private void tier2InitSegment(TcdCodeBlockDecoder cblk, int index, int codeblock } } - private int tier2DecodePacket(Tier2 t2, byte[] src, int len, TcdTile tile, Tcp tcp, - PiIterator pi, PacketInfo packetInfo, boolean USE_JPWL) { + @SuppressWarnings({ "java:S107", "java:S108", "java:S1066", "java:S1659", "java:S2629", "java:S3776", "java:S6541" }) + private int tier2DecodePacket(Tier2 t2, byte[] src, int len, TcdTile tile, Tcp tcp, PiIterator pi, + PacketInfo packetInfo, boolean useJPWL) { int bandNo, codeBlockNo; byte[] cData = src; int cIndex = 0; int srcStartIndex = 0; - + CodingParameters codingParameters = t2.getCodingParameters(); int compNo = pi.getCompNo(); /* component value */ @@ -347,12 +352,13 @@ private int tier2DecodePacket(Tier2 t2, byte[] src, int len, TcdTile tile, Tcp t /* SOP markers */ if ((tcp.getCodingStyle() & OpenJpegConstant.J2K_CP_CSTY_SOP) != 0) { if (cData[cIndex + 0] != (byte) 0xff || cData[cIndex + 1] != (byte) 0x91) { - LOGGER.warn(String.format("Expected SOP marker %s " + t2.getCodecContextInfo().toString())); + logger.warn(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("Expected SOP marker {0} ", + t2.getCodecContextInfo())); } else { cIndex += 6; } - /** TODO : check the Nsop value */ + /** TO DO : check the Nsop value */ } /* @@ -385,7 +391,7 @@ private int tier2DecodePacket(Tier2 t2, byte[] src, int len, TcdTile tile, Tcp t if ((tcp.getCodingStyle() & OpenJpegConstant.J2K_CP_CSTY_EPH) != 0) { if (hd[hdIndex] != (byte) 0xff || hd[hdIndex + 1] != (byte) 0x92) { - LOGGER.error(String.format("Expected EPH marker")); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "Expected EPH marker"); } else { hdIndex += 2; } @@ -401,7 +407,8 @@ private int tier2DecodePacket(Tier2 t2, byte[] src, int len, TcdTile tile, Tcp t /* INDEX >> */ if (codingParameters.getPpm() == 1) { /* PPM case */ - codingParameters.setPpmLength(codingParameters.getPpmLength() + codingParameters.getPpmDataIndex() - hdIndex); + codingParameters + .setPpmLength(codingParameters.getPpmLength() + codingParameters.getPpmDataIndex() - hdIndex); codingParameters.setPpmData(hd); return (cIndex - srcStartIndex); } @@ -440,7 +447,6 @@ private int tier2DecodePacket(Tier2 t2, byte[] src, int len, TcdTile tile, Tcp t if (cblk.getNoOfSegs() == 0) { int i, numimsbs; for (i = 0; TgtHelper.getInstance().tgtDecode(bio, prc.getImsbTree(), codeBlockNo, i) == 0; i++) { - ; } numimsbs = i - 1; cblk.setNoOfBps(band.getNoOfBps() - numimsbs); @@ -464,10 +470,10 @@ private int tier2DecodePacket(Tier2 t2, byte[] src, int len, TcdTile tile, Tcp t n = cblk.getNoOfNewPasses(); do { - cblk.getSegs()[segno].setNoOfNewPasses(MathUtil + cblk.getSegs()[segno].setNoOfNewPasses(MathUtil.getInstance() .intMin(cblk.getSegs()[segno].getMaxPasses() - cblk.getSegs()[segno].getNoOfPasses(), n)); - cblk.getSegs()[segno].setNewLength(BioHelper.getInstance().bioRead(bio, - cblk.getNoOfLengthBits() + MathUtil.intFloorLog2(cblk.getSegs()[segno].getNoOfNewPasses()))); + cblk.getSegs()[segno].setNewLength(BioHelper.getInstance().bioRead(bio, cblk.getNoOfLengthBits() + + MathUtil.getInstance().intFloorLog2(cblk.getSegs()[segno].getNoOfNewPasses()))); n -= cblk.getSegs()[segno].getNoOfNewPasses(); if (n > 0) { ++segno; @@ -479,7 +485,7 @@ private int tier2DecodePacket(Tier2 t2, byte[] src, int len, TcdTile tile, Tcp t if (BioHelper.getInstance().bioInAlign(bio) != 0) { BioHelper.getInstance().bioDestroy(bio); - LOGGER.error(String.format("bioInAlign error")); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "bioInAlign error"); return -999; } @@ -489,7 +495,7 @@ private int tier2DecodePacket(Tier2 t2, byte[] src, int len, TcdTile tile, Tcp t /* EPH markers */ if ((tcp.getCodingStyle() & OpenJpegConstant.J2K_CP_CSTY_EPH) != 0) { if (hd[hdIndex] != (byte) 0xff || hd[hdIndex + 1] != (byte) 0x92) { - LOGGER.error(String.format("Expected EPH marker")); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "Expected EPH marker"); } else { hdIndex += 2; } @@ -500,12 +506,13 @@ private int tier2DecodePacket(Tier2 t2, byte[] src, int len, TcdTile tile, Tcp t // start of packet // Will be updated later by incrementing with packet start value if (packetInfo != null) { - packetInfo.setEndPHPosition((int) (hdIndex - srcStartIndex)); + packetInfo.setEndPHPosition((hdIndex - srcStartIndex)); } /* INDEX >> */ if (codingParameters.getPpm() == 1) { - codingParameters.setPpmLength(codingParameters.getPpmLength() + codingParameters.getPpmDataIndex() - hdIndex); + codingParameters + .setPpmLength(codingParameters.getPpmLength() + codingParameters.getPpmDataIndex() - hdIndex); codingParameters.setPpmData(hd); } else if (tcp.getPpt() == 1) { tcp.setPptLength(tcp.getPptLength() + tcp.getPptDataIndex() - hdIndex); @@ -532,7 +539,6 @@ private int tier2DecodePacket(Tier2 t2, byte[] src, int len, TcdTile tile, Tcp t cblk.setNoOfSegs(cblk.getNoOfSegs() + 1); cblk.setLength(0); } else { - // seg = cblk.getSegs()[cblk.getNoOfSegs() - 1]; seg = cblk.getSegs(); if (seg[segIndex].getNoOfPasses() == seg[segIndex].getMaxPasses()) { segIndex++; @@ -541,12 +547,14 @@ private int tier2DecodePacket(Tier2 t2, byte[] src, int len, TcdTile tile, Tcp t } do { - if ((cData[cIndex + seg[segIndex].getNewLength()] & 0xff) > (src[srcStartIndex + len-1] & 0xff)) { - LOGGER.error(String.format("Data end error data=%d, info=%d ", (cData[cIndex + seg[segIndex].getNewLength()] & 0xff), (src[srcStartIndex + len-1] & 0xff))); + if ((cData[cIndex + seg[segIndex].getNewLength()] & 0xff) > (src[srcStartIndex + len - 1] & 0xff)) { + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("Data end error data={0}, info={1} ", + (cData[cIndex + seg[segIndex].getNewLength()] & 0xff), + (src[srcStartIndex + len - 1] & 0xff))); return -999; } - if (USE_JPWL) { + if (useJPWL) { /* * we need here a j2k handle to verify if making a check to the validity of * cblocks parameters is selected from user (-W) @@ -554,15 +562,16 @@ private int tier2DecodePacket(Tier2 t2, byte[] src, int len, TcdTile tile, Tcp t /* let's check that we are not exceeding */ if ((cblk.getLength() + seg[segIndex].getNewLength()) > 8192) { - LOGGER.warn(String.format( - "JPWL: segment too long (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)", + logger.warn(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format( + "JPWL: segment too long {0} for codeblock {1} (p={2}, b={3}, r={4}, c={5})", seg[segIndex].getNewLength(), codeBlockNo, precNo, bandNo, resNo, compNo)); seg[segIndex].setNewLength(8192 - cblk.getLength()); - LOGGER.warn(String.format("- truncating segment to %d", seg[segIndex].getNewLength())); + logger.warn(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("- truncating segment to {0}", + seg[segIndex].getNewLength())); break; } } - + int newSize = seg[segIndex].getNewLength(); int oldSize = cblk.getData() == null ? 0 : cblk.getData().length; @@ -573,11 +582,9 @@ private int tier2DecodePacket(Tier2 t2, byte[] src, int len, TcdTile tile, Tcp t System.arraycopy(cData, cIndex, cblk.getData(), cblk.getLength(), seg[segIndex].getNewLength()); if (seg[segIndex].getNoOfPasses() == 0) { - // mpved out - //seg[segIndex].setData(cblk.getData()); seg[segIndex].setDataIndex(cblk.getLength()); } - //moved here + // moved here seg[segIndex].setData(cblk.getData()); cIndex += seg[segIndex].getNewLength(); cblk.setLength(cblk.getLength() + seg[segIndex].getNewLength()); @@ -596,8 +603,10 @@ private int tier2DecodePacket(Tier2 t2, byte[] src, int len, TcdTile tile, Tcp t } /* ----------------------------------------------------------------------- */ + @SuppressWarnings({ "java:S107", "java:S135", "java:S1659", "java:S2178", "java:S2629", "java:S3776", "java:S6541" }) public int tier2EncodePackets(Tier2 t2, int tileno, TcdTile tile, int maxlayers, byte[] dest, int len, - CodeStreamInfo codeStreamInfo, int tpnum, int tppos, int piNo, J2KT2Mode tier2Mode, int curTotalNoOfTilePart) { + CodeStreamInfo codeStreamInfo, int tpnum, int tppos, int piNo, J2KT2Mode tier2Mode, + int curTotalNoOfTilePart) { int destIndex = 0; int e = 0; int compNo; @@ -611,7 +620,6 @@ public int tier2EncodePackets(Tier2 t2, int tileno, TcdTile tile, int maxlayers, pi = PiHelper.getInstance().piInitEncode(image, codingParameters, tileno, tier2Mode); if (pi == null) { - /* TODO: throw an error */ return -999; } @@ -620,15 +628,16 @@ public int tier2EncodePackets(Tier2 t2, int tileno, TcdTile tile, int maxlayers, for (poc = 0; poc < pocno; poc++) { int compLength = 0; int tpnum1 = compNo; - if (PiHelper.getInstance().piCreateEncode(pi, codingParameters, tileno, poc, tpnum1, tppos, tier2Mode, - curTotalNoOfTilePart) != 0) { - LOGGER.error(String.format("Error initializing Packet Iterator %s " + t2.getCodecContextInfo().toString())); + if (PiHelper.getInstance().piCreateEncode(pi, codingParameters, tileno, poc, tpnum1, tppos, + tier2Mode, curTotalNoOfTilePart) != 0) { + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("Error initializing Packet Iterator {0} ", + t2.getCodecContextInfo())); return -999; } while (PiHelper.getInstance().piNext(pi[poc]) != 0) { if (pi[poc].getLayNo() < maxlayers) { - e = tier2EncodePacket(tile, codingParameters.getTcps()[tileno], pi[poc], dest, 0 + len - destIndex, - codeStreamInfo, tileno); + e = tier2EncodePacket(tile, codingParameters.getTcps()[tileno], pi[poc], dest, + 0 + len - destIndex, codeStreamInfo, tileno); compLength = compLength + e; if (e == -999) { break; @@ -639,22 +648,21 @@ public int tier2EncodePackets(Tier2 t2, int tileno, TcdTile tile, int maxlayers, } if (e == -999) break; - if (codingParameters.getMaxCompSize() != 0) { - if (compLength > codingParameters.getMaxCompSize()) { - e = -999; - break; - } + if (codingParameters.getMaxCompSize() != 0 && compLength > codingParameters.getMaxCompSize()) { + e = -999; + break; } } if (e == -999) break; } } else { /* tier2Mode == FINAL_PASS */ - PiHelper.getInstance().piCreateEncode(pi, codingParameters, tileno, piNo, tpnum, tppos, tier2Mode, curTotalNoOfTilePart); + PiHelper.getInstance().piCreateEncode(pi, codingParameters, tileno, piNo, tpnum, tppos, tier2Mode, + curTotalNoOfTilePart); while (PiHelper.getInstance().piNext(pi[piNo]) != 0) { if (pi[piNo].getLayNo() < maxlayers) { - e = tier2EncodePacket(tile, codingParameters.getTcps()[tileno], pi[piNo], dest, 0 + len - destIndex, codeStreamInfo, - tileno); + e = tier2EncodePacket(tile, codingParameters.getTcps()[tileno], pi[piNo], dest, 0 + len - destIndex, + codeStreamInfo, tileno); if (e == -999) { break; } else { @@ -668,27 +676,19 @@ public int tier2EncodePackets(Tier2 t2, int tileno, TcdTile tile, int maxlayers, if (codeStreamInfo.getPacketNo() == 0) { packetInfo.setStartPosition(tileInfo.getEndHeader() + 1); } else { - packetInfo.setStartPosition( - ((codingParameters.getTilePartOn() != 0 | tcp.getIsPoc() != 0) && packetInfo.getStartPosition() != 0) - ? packetInfo.getStartPosition() - : tileInfo.getPacket()[codeStreamInfo.getPacketNo() - 1].getEndPosition() + 1); + packetInfo + .setStartPosition(((codingParameters.getTilePartOn() != 0 | tcp.getIsPoc() != 0) + && packetInfo.getStartPosition() != 0) ? packetInfo.getStartPosition() + : tileInfo.getPacket()[codeStreamInfo.getPacketNo() - 1] + .getEndPosition() + 1); } packetInfo.setEndPosition(packetInfo.getStartPosition() + e - 1); - packetInfo.setEndPHPosition(packetInfo.getEndPHPosition() + packetInfo.getStartPosition() - 1); // End of - // packet - // header - // which now - // only - // represents - // the - // distance - // to start - // of packet - // is - // incremented - // by value - // of start - // of packet + /* + * End of packet header which now only represents the distance to start of + * packet is incremented by value of start of packet + */ + packetInfo.setEndPHPosition( + packetInfo.getEndPHPosition() + packetInfo.getStartPosition() - 1); } codeStreamInfo.setPacketNo(codeStreamInfo.getPacketNo() + 1); @@ -708,8 +708,9 @@ public int tier2EncodePackets(Tier2 t2, int tileno, TcdTile tile, int maxlayers, return (destIndex - 0); } + @SuppressWarnings({ "java:S1659", "java:S3776", "java:S6541", "unused" }) public int tier2DecodePackets(Tier2 t2, byte[] src, int len, int tileno, TcdTile tile, - CodeStreamInfo codeStreamInfo, boolean USE_JPWL) { + CodeStreamInfo codeStreamInfo, boolean useJPWL) { int srcIndex = 0; int[] cIndex = new int[1]; cIndex[0] = srcIndex; @@ -724,7 +725,6 @@ public int tier2DecodePackets(Tier2 t2, byte[] src, int len, int tileno, TcdTile /* create a packet iterator */ pi = PiHelper.getInstance().piCreateDecode(image, codingParameters, tileno); if (pi == null) { - /* TODO: throw an error */ return -999; } @@ -732,25 +732,26 @@ public int tier2DecodePackets(Tier2 t2, byte[] src, int len, int tileno, TcdTile for (piNo = 0; piNo <= codingParameters.getTcps()[tileno].getNoOfPocs(); piNo++) { while (PiHelper.getInstance().piNext(pi[piNo]) != 0) { - if ((codingParameters.getLayer() == 0) || (codingParameters.getLayer() >= ((pi[piNo].getLayNo()) + 1))) { + if ((codingParameters.getLayer() == 0) + || (codingParameters.getLayer() >= ((pi[piNo].getLayNo()) + 1))) { PacketInfo packetInfo; if (codeStreamInfo != null) packetInfo = codeStreamInfo.getTileInfo()[tileno].getPacket()[codeStreamInfo.getPacketNo()]; else packetInfo = null; - + byte[] cData = new byte[srcIndex + len - cIndex[0]]; System.arraycopy(src, cIndex[0], cData, 0, cData.length); - - e = tier2DecodePacket(t2, cData, srcIndex + len - cIndex[0], tile, codingParameters.getTcps()[tileno], pi[piNo], packetInfo, - USE_JPWL); + + e = tier2DecodePacket(t2, cData, srcIndex + len - cIndex[0], tile, + codingParameters.getTcps()[tileno], pi[piNo], packetInfo, useJPWL); } else { e = 0; } /* progression in resolution */ image.getComps()[pi[piNo].getCompNo()].setResNoDecoded((e > 0) - ? MathUtil.intMax(pi[piNo].getResNo(), + ? MathUtil.getInstance().intMax(pi[piNo].getResNo(), image.getComps()[pi[piNo].getCompNo()].getResNoDecoded()) : image.getComps()[pi[piNo].getCompNo()].getResNoDecoded()); n++; @@ -762,31 +763,38 @@ public int tier2DecodePackets(Tier2 t2, byte[] src, int len, int tileno, TcdTile if (codeStreamInfo.getPacketNo() == 0) { packetInfo.setStartPosition(tileInfo.getEndHeader() + 1); } else if (tileInfo.getPacket()[codeStreamInfo.getPacketNo() - 1] - .getEndPosition() >= (int) codeStreamInfo.getTileInfo()[tileno].getTp()[currentTilePart].getTpEndPosition()) { // New - // tile - // part - tileInfo.getTp()[currentTilePart].setTpNoOfPackets(codeStreamInfo.getPacketNo() - tpStartPacketNo); // Number of - // packets in - // previous - // tile-part + .getEndPosition() >= codeStreamInfo.getTileInfo()[tileno].getTp()[currentTilePart] + .getTpEndPosition()) { // New + // tile + // part + tileInfo.getTp()[currentTilePart] + .setTpNoOfPackets(codeStreamInfo.getPacketNo() - tpStartPacketNo); // Number of + // packets in + // previous + // tile-part tpStartPacketNo = codeStreamInfo.getPacketNo(); currentTilePart++; - packetInfo.setStartPosition(codeStreamInfo.getTileInfo()[tileno].getTp()[currentTilePart].getTpEndHeader() + 1); + packetInfo.setStartPosition( + codeStreamInfo.getTileInfo()[tileno].getTp()[currentTilePart].getTpEndHeader() + 1); } else { packetInfo.setStartPosition( - (codingParameters.getTilePartOn() != 0 && packetInfo.getStartPosition() != 0) ? packetInfo.getStartPosition() + (codingParameters.getTilePartOn() != 0 && packetInfo.getStartPosition() != 0) + ? packetInfo.getStartPosition() : tileInfo.getPacket()[codeStreamInfo.getPacketNo() - 1].getEndPosition() + 1); } packetInfo.setEndPosition(packetInfo.getStartPosition() + e - 1); - packetInfo.setEndPHPosition(packetInfo.getEndPHPosition() + packetInfo.getStartPosition() - 1); // End of packet header - // which now only - // represents the - // distance - // to start of - // packet is - // incremented by - // value of start of - // packet + packetInfo.setEndPHPosition(packetInfo.getEndPHPosition() + packetInfo.getStartPosition() - 1); // End + // of + // packet + // header + // which now only + // represents the + // distance + // to start of + // packet is + // incremented by + // value of start of + // packet codeStreamInfo.setPacketNo(codeStreamInfo.getPacketNo() + 1); } /* << INDEX */ @@ -800,8 +808,9 @@ public int tier2DecodePackets(Tier2 t2, byte[] src, int len, int tileno, TcdTile } /* INDEX >> */ if (codeStreamInfo != null) { - codeStreamInfo.getTileInfo()[tileno].getTp()[currentTilePart].setTpNoOfPackets(codeStreamInfo.getPacketNo() - tpStartPacketNo); - // Number of packets in last tile-part + codeStreamInfo.getTileInfo()[tileno].getTp()[currentTilePart] + .setTpNoOfPackets(codeStreamInfo.getPacketNo() - tpStartPacketNo); + // Number of packets in last tile-part } /* << INDEX */ @@ -815,7 +824,8 @@ public int tier2DecodePackets(Tier2 t2, byte[] src, int len, int tileno, TcdTile return (cIndex[0] - srcIndex); } - public Tier2 tier2Create(CodecContextInfo codecContextInfo, OpenJpegImage image, CodingParameters codingParameters) { + public Tier2 tier2Create(CodecContextInfo codecContextInfo, OpenJpegImage image, + CodingParameters codingParameters) { /* create the tcd structure */ Tier2 t2 = new Tier2(); t2.setCodecContextInfo(codecContextInfo); @@ -825,9 +835,7 @@ public Tier2 tier2Create(CodecContextInfo codecContextInfo, OpenJpegImage image, return t2; } + @SuppressWarnings({ "java:S1186"}) public void tier2Destroy(Tier2 t2) { - if (t2 != null) { - t2 = null; - } } -} +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/util/Base64UrlUtil.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/util/Base64UrlUtil.java index adbb1c3..09b2ead 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/util/Base64UrlUtil.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/util/Base64UrlUtil.java @@ -4,6 +4,9 @@ import java.util.Base64; import java.util.Base64.Encoder; +import io.mosip.imagedecoder.constant.DecoderErrorCodes; +import io.mosip.imagedecoder.exceptions.DecoderException; + public class Base64UrlUtil { private static Encoder urlSafeEncoder; @@ -11,39 +14,54 @@ public class Base64UrlUtil { urlSafeEncoder = Base64.getUrlEncoder().withoutPadding(); } - public static String encodeToURLSafeBase64(byte[] data) { + // Static variable reference of singleInstance of type Singleton + private static Base64UrlUtil singleInstance = null; + + private Base64UrlUtil() { + super(); + } + + // synchronized method to control simultaneous access + public static synchronized Base64UrlUtil getInstance() { + if (singleInstance == null) + singleInstance = new Base64UrlUtil(); + + return singleInstance; + } + + public String encodeToURLSafeBase64(byte[] data) { if (isNullEmpty(data)) { return null; } return urlSafeEncoder.encodeToString(data); } - public static String encodeToURLSafeBase64(String data) { + public String encodeToURLSafeBase64(String data) { if (isNullEmpty(data)) { return null; } return urlSafeEncoder.encodeToString(data.getBytes(StandardCharsets.UTF_8)); } - public static byte[] decodeURLSafeBase64(byte[] data) { + public byte[] decodeURLSafeBase64(byte[] data) { if (isNullEmpty(data)) { - return null; + throw new DecoderException(DecoderErrorCodes.TECHNICAL_ERROR_EXCEPTION.getErrorCode(), "null"); } return Base64.getUrlDecoder().decode(data); } - public static byte[] decodeURLSafeBase64(String data) { + public byte[] decodeURLSafeBase64(String data) { if (isNullEmpty(data)) { - return null; + throw new DecoderException(DecoderErrorCodes.TECHNICAL_ERROR_EXCEPTION.getErrorCode(), "null"); } return Base64.getUrlDecoder().decode(data); } - public static boolean isNullEmpty(byte[] array) { + public boolean isNullEmpty(byte[] array) { return array == null || array.length == 0; } - public static boolean isNullEmpty(String str) { + public boolean isNullEmpty(String str) { return str == null || str.trim().length() == 0; } } diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/util/ByteStreamUtil.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/util/ByteStreamUtil.java index e164f3f..761c18e 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/util/ByteStreamUtil.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/util/ByteStreamUtil.java @@ -12,24 +12,22 @@ public class ByteStreamUtil { // Static variable reference of singleInstance of type Singleton - private static ByteStreamUtil singleInstance = null; - private ByteStreamUtil() - { - super (); - } - - //synchronized method to control simultaneous access - public static synchronized ByteStreamUtil getInstance() - { + private static ByteStreamUtil singleInstance = null; + + private ByteStreamUtil() { + super(); + } + + // synchronized method to control simultaneous access + public static synchronized ByteStreamUtil getInstance() { if (singleInstance == null) singleInstance = new ByteStreamUtil(); - - return singleInstance; + + return singleInstance; } - + public ByteOrder getByteOrder() { - ByteOrder byteOrder = ByteOrder.nativeOrder(); - return byteOrder; + return ByteOrder.nativeOrder(); } public int arraySize(Object[] array) { @@ -38,8 +36,9 @@ public int arraySize(Object[] array) { public void init(ByteBufferContext byteBufCont, byte[] buf, int bufSize) { if (bufSize < 0) - throw new DecoderException(DecoderErrorCodes.INVALID_DATA_ERROR.getErrorCode(), DecoderErrorCodes.INVALID_DATA_ERROR.getErrorMessage()); - + throw new DecoderException(DecoderErrorCodes.INVALID_DATA_ERROR.getErrorCode(), + DecoderErrorCodes.INVALID_DATA_ERROR.getErrorMessage()); + byteBufCont.setBuffer(ByteBuffer.wrap(buf)); byteBufCont.getBuffer().rewind(); } @@ -54,6 +53,12 @@ public int getBuffer(ByteBufferContext byteBufCont, byte[] target, int size) { public int getBufferU(ByteBufferContext byteBufCont, byte[] target, int size) { int pos = byteBufCont.getBuffer().position(); + // Validate that the requested size does not exceed remaining bytes + int remaining = byteBufCont.getBuffer().remaining(); + if (size > remaining) { + size = remaining; + } + System.arraycopy(byteBufCont.getBuffer().array(), pos, target, 0, size); byteBufCont.getBuffer().position(pos + size); return size; @@ -61,6 +66,11 @@ public int getBufferU(ByteBufferContext byteBufCont, byte[] target, int size) { public int getBufferU(ByteBufferContext byteBufCont, byte[] target, int dstPos, int size) { int pos = byteBufCont.getBuffer().position(); + // Validate that the requested size does not exceed remaining bytes + int remaining = byteBufCont.getBuffer().remaining(); + if (size > remaining) { + size = remaining; + } System.arraycopy(byteBufCont.getBuffer().array(), pos, target, dstPos, size); byteBufCont.getBuffer().position(pos + size); return size; @@ -75,7 +85,6 @@ public int position(ByteBufferContext byteBufCont) { } public int currentSize(ByteBufferContext byteBufCont) { - // return byteBufCont.getBuffer().capacity() - byteBufCont.getBuffer().position(); return byteBufCont.getBuffer().remaining(); } @@ -130,26 +139,26 @@ public BigInteger getULong(ByteBufferContext byteBufCont) { public long putByte(ByteBufferContext byteBufCont, int value) throws IOException { if (byteBufCont.getBuffer().remaining() < 1) - throw new IOException("not enough space in buffer to write signed byte"); - - byteBufCont.getBuffer().put((byte)value); + throw new IOException("not enough space in buffer to write signed byte"); + + byteBufCont.getBuffer().put((byte) value); return byteBufCont.getBuffer().position(); } public long putShort(ByteBufferContext byteBufCont, int value) throws IOException { if (byteBufCont.getBuffer().remaining() < 2) - throw new IOException("not enough space in buffer to write signed short"); + throw new IOException("not enough space in buffer to write signed short"); if (byteBufCont.getBuffer().order() == ByteOrder.BIG_ENDIAN) - value = ByteSwapperUtil.getInstance().swapShort((short)value); + value = ByteSwapperUtil.getInstance().swapShort((short) value); - byteBufCont.getBuffer().putShort((short)value); + byteBufCont.getBuffer().putShort((short) value); return byteBufCont.getBuffer().position(); } public long put3Bytes(ByteBufferContext byteBufCont, int value) throws IOException { if (byteBufCont.getBuffer().remaining() < 3) - throw new IOException("not enough space in buffer to write signed 3 bytes"); + throw new IOException("not enough space in buffer to write signed 3 bytes"); if (byteBufCont.getBuffer().order() == ByteOrder.BIG_ENDIAN) value = ByteSwapperUtil.getInstance().swap3Bytes(value); @@ -162,7 +171,7 @@ public long put3Bytes(ByteBufferContext byteBufCont, int value) throws IOExcepti public long putInt(ByteBufferContext byteBufCont, int value) throws IOException { if (byteBufCont.getBuffer().remaining() < 4) - throw new IOException("not enough space in buffer to write signed Integer"); + throw new IOException("not enough space in buffer to write signed Integer"); if (byteBufCont.getBuffer().order() == ByteOrder.BIG_ENDIAN) value = ByteSwapperUtil.getInstance().swapInt(value); @@ -173,7 +182,7 @@ public long putInt(ByteBufferContext byteBufCont, int value) throws IOException public long putLong(ByteBufferContext byteBufCont, long value) throws IOException { if (byteBufCont.getBuffer().remaining() < 8) - throw new IOException("not enough space in buffer to write signed Long"); + throw new IOException("not enough space in buffer to write signed Long"); if (byteBufCont.getBuffer().order() == ByteOrder.BIG_ENDIAN) value = ByteSwapperUtil.getInstance().swapLong(value); @@ -184,41 +193,41 @@ public long putLong(ByteBufferContext byteBufCont, long value) throws IOExceptio public long putUByte(ByteBufferContext byteBufCont, int value) throws IOException { if (byteBufCont.getBuffer().remaining() < 1) - throw new IOException("not enough space in buffer to write unsigned byte"); - + throw new IOException("not enough space in buffer to write unsigned byte"); + if (value > 255) - throw new IOException("int value exceeds maximum unsigned byte value of 255!"); - - byteBufCont.getBuffer().put((byte)(value & 0xff)); + throw new IOException("int value exceeds maximum unsigned byte value of 255!"); + + byteBufCont.getBuffer().put((byte) (value & 0xff)); return byteBufCont.getBuffer().position(); } public long putUShort(ByteBufferContext byteBufCont, int value) throws IOException { if (byteBufCont.getBuffer().remaining() < 2) - throw new IOException("not enough space in buffer to write unsigned short"); + throw new IOException("not enough space in buffer to write unsigned short"); if (value > 65535) - throw new IOException("int value exceeds maximum unsigned short value of 65535!"); - + throw new IOException("int value exceeds maximum unsigned short value of 65535!"); + if (byteBufCont.getBuffer().order() == ByteOrder.BIG_ENDIAN) - value = ByteSwapperUtil.getInstance().swapShort((short)value); + value = ByteSwapperUtil.getInstance().swapShort((short) value); - byte b1 = (byte) (0xff & (value >> 0)); - byte b2 = (byte) (0xff & (value >> 8)); + byte b1 = (byte) (0xff & (value)); + byte b2 = (byte) (0xff & (value >> 8)); - byteBufCont.getBuffer().put(b1); - byteBufCont.getBuffer().put(b2); - return byteBufCont.getBuffer().position(); + byteBufCont.getBuffer().put(b1); + byteBufCont.getBuffer().put(b2); + return byteBufCont.getBuffer().position(); } public long putU3Bytes(ByteBufferContext byteBufCont, int value) throws IOException { if (byteBufCont.getBuffer().remaining() < 3) - throw new IOException("not enough space in buffer to write unsigned 3 bytes"); + throw new IOException("not enough space in buffer to write unsigned 3 bytes"); if (byteBufCont.getBuffer().order() == ByteOrder.BIG_ENDIAN) value = ByteSwapperUtil.getInstance().swap3Bytes(value); - byteBufCont.getBuffer().put((byte) ((value >> 0) & 0xff)); + byteBufCont.getBuffer().put((byte) ((value) & 0xff)); byteBufCont.getBuffer().put((byte) ((value >> 8) & 0xff)); byteBufCont.getBuffer().put((byte) ((value >> 16) & 0xff)); return byteBufCont.getBuffer().position(); @@ -226,7 +235,7 @@ public long putU3Bytes(ByteBufferContext byteBufCont, int value) throws IOExcept public long putUInt(ByteBufferContext byteBufCont, long value) throws IOException { if (byteBufCont.getBuffer().remaining() < 4) - throw new IOException("not enough space in buffer to write unsigned Integer"); + throw new IOException("not enough space in buffer to write unsigned Integer"); if (byteBufCont.getBuffer().order() == ByteOrder.BIG_ENDIAN) value = ByteSwapperUtil.getInstance().swapLong(value); @@ -363,16 +372,16 @@ else if (a > amax) return a; } - public int MKTAG(char a, char b, char c, char d) { - return ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24)); + public int makeTag(char aInfo, char bInfo, char cInfo, char dInfo) { + return ((aInfo) | ((bInfo) << 8) | ((cInfo) << 16) | ((dInfo) << 24)); } - public int MKBETAG(char a, char b, char c, char d) { - return ((d) | ((c) << 8) | ((b) << 16) | ((a) << 24)); + public int makeBETag(char aInfo, char bInfo, char cInfo, char dInfo) { + return ((dInfo) | ((cInfo) << 8) | ((bInfo) << 16) | ((aInfo) << 24)); } - public int FFERRTAG(char a, char b, char c, char d) { - return ((d) | ((c) << 8) | ((b) << 16) | ((a) << 24)) * -1; + public int ffErrorTag(char aInfo, char bInfo, char cInfo, char dInfo) { + return ((dInfo) | ((cInfo) << 8) | ((bInfo) << 16) | ((aInfo) << 24)) * -1; } /** @@ -405,7 +414,7 @@ public long getSignedVarInt(ByteBuffer byteBuffer, int numBytes) { * Read an unsigned variable length int from a byteBuffer * * @param byteBuffer Buffer containing the variable length int - * @param offset Offset at which to read the value + * @param offset Offset at which to read the value * @return The unsigned long */ public long getUnsignedVarInt(ByteBuffer byteBuffer, int offset, int numBytes) { @@ -418,9 +427,9 @@ public long getUnsignedVarInt(ByteBuffer byteBuffer, int offset, int numBytes) { return get3UnsignedByteInt(byteBuffer, offset); case 4: return getUnsignedInt(byteBuffer, offset); - // return byteBuffer.getInt(offset); default: - throw new IllegalArgumentException("Invalid num bytes " + numBytes); + throw new DecoderException(DecoderErrorCodes.TECHNICAL_ERROR_EXCEPTION.getErrorCode(), + "Invalid num bytes " + numBytes); } } @@ -428,7 +437,7 @@ public long getUnsignedVarInt(ByteBuffer byteBuffer, int offset, int numBytes) { * Read an Signed variable length int from a byteBuffer * * @param byteBuffer Buffer containing the variable length int - * @param offset Offset at which to read the value + * @param offset Offset at which to read the value * @return The Signed long */ public long getSignedVarInt(ByteBuffer byteBuffer, int offset, int numBytes) { @@ -476,7 +485,7 @@ public int getSignedByte(ByteBuffer byteBuffer) { * Read an unsigned byte from a byteBuffer * * @param byteBuffer Buffer containing the bytes - * @param offset Offset at which to read the byte + * @param offset Offset at which to read the byte * @return The unsigned byte as an int */ public int getUnsignedByte(ByteBuffer byteBuffer, int offset) { @@ -487,7 +496,7 @@ public int getUnsignedByte(ByteBuffer byteBuffer, int offset) { * Read an Signed byte from a byteBuffer * * @param byteBuffer Buffer containing the bytes - * @param offset Offset at which to read the byte + * @param offset Offset at which to read the byte * @return The Signed byte as an int */ public int getSignedByte(ByteBuffer byteBuffer, int offset) { @@ -524,7 +533,7 @@ public int getSignedShort(ByteBuffer byteBuffer) { * Read an unsigned short from a byteBuffer * * @param byteBuffer Buffer containing the short - * @param offset Offset at which to read the short + * @param offset Offset at which to read the short * @return The unsigned short as an int */ public int getUnsignedShort(ByteBuffer byteBuffer, int offset) { @@ -535,7 +544,7 @@ public int getUnsignedShort(ByteBuffer byteBuffer, int offset) { * Read an Signed short from a byteBuffer * * @param byteBuffer Buffer containing the short - * @param offset Offset at which to read the short + * @param offset Offset at which to read the short * @return The Signed short as an int */ public int getSignedShort(ByteBuffer byteBuffer, int offset) { @@ -566,7 +575,7 @@ public int get3SignedByteInt(ByteBuffer byteBuffer) { * Read a 3 Unsigned byte int from a byteBuffer * * @param byteBuffer Buffer containing the bytes - * @param order the order of the bytes of the int + * @param order the order of the bytes of the int * @return The int */ public int get3UnsignedByteInt(ByteBuffer byteBuffer, ByteOrder order) { @@ -580,7 +589,7 @@ public int get3UnsignedByteInt(ByteBuffer byteBuffer, ByteOrder order) { * Read a 3 Signed byte int from a byteBuffer * * @param byteBuffer Buffer containing the bytes - * @param order the order of the bytes of the int + * @param order the order of the bytes of the int * @return The int */ public int get3SignedByteInt(ByteBuffer byteBuffer, ByteOrder order) { @@ -594,7 +603,7 @@ public int get3SignedByteInt(ByteBuffer byteBuffer, ByteOrder order) { * Read a 3 Unsigned byte int from a byteBuffer * * @param byteBuffer Buffer containing the bytes - * @param offset Offset at which to start reading the int + * @param offset Offset at which to start reading the int * @return The int */ public int get3UnsignedByteInt(ByteBuffer byteBuffer, int offset) { @@ -605,7 +614,7 @@ public int get3UnsignedByteInt(ByteBuffer byteBuffer, int offset) { * Read a 3 Signed byte int from a byteBuffer * * @param byteBuffer Buffer containing the bytes - * @param offset Offset at which to start reading the int + * @param offset Offset at which to start reading the int * @return The int */ public int get3SignedByteInt(ByteBuffer byteBuffer, int offset) { @@ -616,8 +625,8 @@ public int get3SignedByteInt(ByteBuffer byteBuffer, int offset) { * Read a 3 Unsigned byte int from a byteBuffer * * @param byteBuffer Buffer containing the bytes - * @param offset Offset at which to start reading the int - * @param order the order of the bytes of the int + * @param offset Offset at which to start reading the int + * @param order the order of the bytes of the int * @return The int */ public int get3UnsignedByteInt(ByteBuffer byteBuffer, int offset, ByteOrder order) { @@ -638,21 +647,40 @@ public int get3UnsignedByteInt(ByteBuffer byteBuffer, int offset, ByteOrder orde * Read a 3 Signed byte int from a byteBuffer * * @param byteBuffer Buffer containing the bytes - * @param offset Offset at which to start reading the int - * @param order the order of the bytes of the int + * @param offset Offset at which to start reading the int + * @param order the order of the bytes of the int * @return The int */ public int get3SignedByteInt(ByteBuffer byteBuffer, int offset, ByteOrder order) { - int offInc = 1; if (order == ByteOrder.BIG_ENDIAN) { - offInc = -1; - offset += 2; + // Read in big-endian order (most significant byte first) + int byte1 = byteBuffer.get(offset) & 0xFF; // MSB + int byte2 = byteBuffer.get(offset + 1) & 0xFF; + int byte3 = byteBuffer.get(offset + 2) & 0xFF; + + // Combine bytes into a 24-bit integer + int result = (byte1 << 16) | (byte2 << 8) | byte3; + + // Adjust for sign (if the 24th bit is set) + if ((result & 0x800000) != 0) { + result |= 0xFF000000; // Extend sign to 32 bits + } + return result; + } else { + // Read in little-endian order (least significant byte first) + int byte1 = byteBuffer.get(offset) & 0xFF; // LSB + int byte2 = byteBuffer.get(offset + 1) & 0xFF; + int byte3 = byteBuffer.get(offset + 2) & 0xFF; + + // Combine bytes into a 24-bit integer + int result = (byte3 << 16) | (byte2 << 8) | byte1; + + // Adjust for sign (if the 24th bit is set) + if ((result & 0x800000) != 0) { + result |= 0xFF000000; // Extend sign to 32 bits + } + return result; } - - int rtn = getSignedByte(byteBuffer, offset); - rtn += (getSignedByte(byteBuffer, offset + (1 * offInc)) << 8); - rtn += (getSignedByte(byteBuffer, offset + (2 * offInc)) << 16); - return rtn; } /** @@ -679,7 +707,7 @@ public long getSignedInt(ByteBuffer byteBuffer) { * Read a Unsigned int from a byteBuffer * * @param byteBuffer Buffer containing the bytes - * @param order the order of the bytes of the int + * @param order the order of the bytes of the int * @return The long */ public long getUnsignedInt(ByteBuffer byteBuffer, ByteOrder order) { @@ -693,7 +721,7 @@ public long getUnsignedInt(ByteBuffer byteBuffer, ByteOrder order) { * Read a Signed int from a byteBuffer * * @param byteBuffer Buffer containing the bytes - * @param order the order of the bytes of the int + * @param order the order of the bytes of the int * @return The long */ public long getSignedInt(ByteBuffer byteBuffer, ByteOrder order) { @@ -707,7 +735,7 @@ public long getSignedInt(ByteBuffer byteBuffer, ByteOrder order) { * Read a Unsigned int from a byteBuffer * * @param byteBuffer Buffer containing the bytes - * @param offset Offset at which to start reading the int + * @param offset Offset at which to start reading the int * @return The long */ public long getUnsignedInt(ByteBuffer byteBuffer, int offset) { @@ -718,7 +746,7 @@ public long getUnsignedInt(ByteBuffer byteBuffer, int offset) { * Read a Signed byte int from a byteBuffer * * @param byteBuffer Buffer containing the bytes - * @param offset Offset at which to start reading the int + * @param offset Offset at which to start reading the int * @return The long */ public long getSignedInt(ByteBuffer byteBuffer, int offset) { @@ -729,8 +757,8 @@ public long getSignedInt(ByteBuffer byteBuffer, int offset) { * Read a Unsigned int from a byteBuffer * * @param byteBuffer Buffer containing the bytes - * @param offset Offset at which to start reading the int - * @param order the order of the bytes of the int + * @param offset Offset at which to start reading the int + * @param order the order of the bytes of the int * @return The long */ public long getUnsignedInt(ByteBuffer byteBuffer, int offset, ByteOrder order) { @@ -752,23 +780,23 @@ public long getUnsignedInt(ByteBuffer byteBuffer, int offset, ByteOrder order) { * Read a Signed int from a byteBuffer * * @param byteBuffer Buffer containing the bytes - * @param offset Offset at which to start reading the int - * @param order the order of the bytes of the int + * @param offset Offset at which to start reading the int + * @param order the order of the bytes of the int * @return The long */ public long getSignedInt(ByteBuffer byteBuffer, int offset, ByteOrder order) { + int result; - int offInc = 1; if (order == ByteOrder.BIG_ENDIAN) { - offInc = -1; - offset += 3; + // Read in big-endian order (most significant byte first) + result = (byteBuffer.get(offset) & 0xFF) << 24 | (byteBuffer.get(offset + 1) & 0xFF) << 16 + | (byteBuffer.get(offset + 2) & 0xFF) << 8 | (byteBuffer.get(offset + 3) & 0xFF); + } else { + // Read in little-endian order (least significant byte first) + result = (byteBuffer.get(offset + 3) & 0xFF) << 24 | (byteBuffer.get(offset + 2) & 0xFF) << 16 + | (byteBuffer.get(offset + 1) & 0xFF) << 8 | (byteBuffer.get(offset) & 0xFF); } - - long rtn = getSignedByte(byteBuffer, offset); - rtn += (getSignedByte(byteBuffer, offset + (1 * offInc)) << 8); - rtn += (getSignedByte(byteBuffer, offset + (2 * offInc)) << 16); - rtn += (getSignedByte(byteBuffer, offset + (3 * offInc)) << 24); - return rtn; + return result; } /** @@ -795,7 +823,7 @@ public BigInteger getSignedLong(ByteBuffer byteBuffer) { * Read a Unsigned Long from a byteBuffer * * @param byteBuffer Buffer containing the bytes - * @param order the order of the bytes of the int + * @param order the order of the bytes of the int * @return The BigInteger */ public BigInteger getUnsignedLong(ByteBuffer byteBuffer, ByteOrder order) { @@ -809,7 +837,7 @@ public BigInteger getUnsignedLong(ByteBuffer byteBuffer, ByteOrder order) { * Read a Signed Long from a byteBuffer * * @param byteBuffer Buffer containing the bytes - * @param order the order of the bytes of the int + * @param order the order of the bytes of the int * @return The BigInteger */ public BigInteger getSignedLong(ByteBuffer byteBuffer, ByteOrder order) { @@ -823,7 +851,7 @@ public BigInteger getSignedLong(ByteBuffer byteBuffer, ByteOrder order) { * Read a Unsigned Long from a byteBuffer * * @param byteBuffer Buffer containing the bytes - * @param offset Offset at which to start reading the int + * @param offset Offset at which to start reading the int * @return The BigInteger */ public BigInteger getUnsignedLong(ByteBuffer byteBuffer, int offset) { @@ -834,7 +862,7 @@ public BigInteger getUnsignedLong(ByteBuffer byteBuffer, int offset) { * Read a Signed byte int from a byteBuffer * * @param byteBuffer Buffer containing the bytes - * @param offset Offset at which to start reading the int + * @param offset Offset at which to start reading the int * @return The BigInteger */ public BigInteger getSignedLong(ByteBuffer byteBuffer, int offset) { @@ -845,67 +873,72 @@ public BigInteger getSignedLong(ByteBuffer byteBuffer, int offset) { * Read a Unsigned Long from a byteBuffer * * @param byteBuffer Buffer containing the bytes - * @param offset Offset at which to start reading the int - * @param order the order of the bytes of the int + * @param offset Offset at which to start reading the int + * @param order the order of the bytes of the int * @return The BigInteger */ public BigInteger getUnsignedLong(ByteBuffer byteBuffer, int offset, ByteOrder order) { + long result = 0; - int offInc = 1; if (order == ByteOrder.BIG_ENDIAN) { - offInc = -1; - offset += 8; + for (int i = 0; i < 8; i++) { + result = (result << 8) | (byteBuffer.get(offset + i) & 0xFFL); + } + } else { + for (int i = 7; i >= 0; i--) { + result = (result << 8) | (byteBuffer.get(offset + i) & 0xFFL); + } } - long rtn = getSignedByte(byteBuffer, offset); - rtn += (getSignedByte(byteBuffer, offset + (1 * offInc)) << 8); - rtn += (getSignedByte(byteBuffer, offset + (2 * offInc)) << 16); - rtn += (getSignedByte(byteBuffer, offset + (3 * offInc)) << 24); - rtn += (getSignedByte(byteBuffer, offset + (4 * offInc)) << 32); - rtn += (getSignedByte(byteBuffer, offset + (5 * offInc)) << 40); - rtn += (getSignedByte(byteBuffer, offset + (6 * offInc)) << 48); - rtn += (getSignedByte(byteBuffer, offset + (7 * offInc)) << 56); - - return toUnsignedBigInteger (rtn); + // Convert the result to BigInteger for unsigned representation + return toUnsignedBigInteger(result); } public BigInteger toUnsignedBigInteger(long i) { - if (i >= 0L) - return BigInteger.valueOf(i); - else { - int upper = (int) (i >>> 32); - int lower = (int) i; - - // return (upper << 32) + lower - return (BigInteger.valueOf(Integer.toUnsignedLong(upper))).shiftLeft(32). - add(BigInteger.valueOf(Integer.toUnsignedLong(lower))); - } + if (i >= 0L) + return BigInteger.valueOf(i); + else { + int upper = (int) (i >>> 32); + int lower = (int) i; + + // return (upper << 32) + lower + return (BigInteger.valueOf(Integer.toUnsignedLong(upper))).shiftLeft(32) + .add(BigInteger.valueOf(Integer.toUnsignedLong(lower))); + } } + /** * Read a Signed Long from a byteBuffer * * @param byteBuffer Buffer containing the bytes - * @param offset Offset at which to start reading the int - * @param order the order of the bytes of the int + * @param offset Offset at which to start reading the int + * @param order the order of the bytes of the int * @return The BigInteger */ public BigInteger getSignedLong(ByteBuffer byteBuffer, int offset, ByteOrder order) { + BigInteger result = BigInteger.ZERO; - int offInc = 1; - if (order == ByteOrder.BIG_ENDIAN) { - offInc = -1; - offset += 8; - } + if (order == ByteOrder.BIG_ENDIAN) { + boolean isNegative = (byteBuffer.get(offset) & 0x80) != 0; // Check MSB for negative + for (int i = 0; i < 8; i++) { + result = result.shiftLeft(8).add(BigInteger.valueOf(byteBuffer.get(offset + i) & 0xFFL)); + } + if (isNegative) { + // Apply sign extension for negative numbers + result = result.subtract(BigInteger.ONE.shiftLeft(64)); + } + } else { + boolean isNegative = (byteBuffer.get(offset + 7) & 0x80) != 0; // Check LSB for negative + for (int i = 7; i >= 0; i--) { + result = result.shiftLeft(8).add(BigInteger.valueOf(byteBuffer.get(offset + i) & 0xFFL)); + } + if (isNegative) { + // Apply sign extension for negative numbers + result = result.subtract(BigInteger.ONE.shiftLeft(64)); + } + } - BigInteger rtn = BigInteger.valueOf(getSignedByte(byteBuffer, offset)); - rtn = rtn.add((BigInteger.valueOf(getSignedByte(byteBuffer, offset + (1 * offInc))).shiftLeft(8))); - rtn = rtn.add((BigInteger.valueOf(getSignedByte(byteBuffer, offset + (2 * offInc))).shiftLeft(16))); - rtn = rtn.add((BigInteger.valueOf(getSignedByte(byteBuffer, offset + (3 * offInc))).shiftLeft(24))); - rtn = rtn.add((BigInteger.valueOf(getSignedByte(byteBuffer, offset + (4 * offInc))).shiftLeft(32))); - rtn = rtn.add((BigInteger.valueOf(getSignedByte(byteBuffer, offset + (5 * offInc))).shiftLeft(40))); - rtn = rtn.add((BigInteger.valueOf(getSignedByte(byteBuffer, offset + (7 * offInc))).shiftLeft(48))); - rtn = rtn.add((BigInteger.valueOf(getSignedByte(byteBuffer, offset + (8 * offInc))).shiftLeft(56))); - return rtn; + return result; } /** @@ -935,13 +968,13 @@ public int asUnsignedShort(short s) { public int asSignedShort(short s) { return s; } - + public int memCompare(int[] a, int[] b, int sz) { - for (int i = 0; i < sz; i++) { - if (a[i] != b[i]) { - return a[i] - b[i]; - } - } - return 0; + for (int i = 0; i < sz; i++) { + if (a[i] != b[i]) { + return a[i] - b[i]; + } + } + return 0; } } diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/util/ByteSwapperUtil.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/util/ByteSwapperUtil.java index efb3982..e18e15d 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/util/ByteSwapperUtil.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/util/ByteSwapperUtil.java @@ -2,20 +2,20 @@ public class ByteSwapperUtil { // Static variable reference of singleInstance of type Singleton - private static ByteSwapperUtil singleInstance = null; - private ByteSwapperUtil() - { - super (); - } - - //synchronized method to control simultaneous access - public static synchronized ByteSwapperUtil getInstance() - { + private static ByteSwapperUtil singleInstance = null; + + private ByteSwapperUtil() { + super(); + } + + // synchronized method to control simultaneous access + public static synchronized ByteSwapperUtil getInstance() { if (singleInstance == null) singleInstance = new ByteSwapperUtil(); - - return singleInstance; + + return singleInstance; } + /** * Byte swap a single short value. * @@ -26,7 +26,7 @@ public short swapShort(short value) { int b1 = value & 0xff; int b2 = (value >> 8) & 0xff; - return (short) (b1 << 8 | b2 << 0); + return (short) (b1 << 8 | b2); } /** @@ -40,7 +40,7 @@ public int swap3Bytes(int value) { int b2 = (value >> 8) & 0xff; int b3 = (value >> 16) & 0xff; - return b1 << 16 | b2 << 8 | b3 << 0; + return b1 << 16 | b2 << 8 | b3; } /** @@ -55,7 +55,7 @@ public int swapInt(int value) { int b3 = (value >> 16) & 0xff; int b4 = (value >> 24) & 0xff; - return b1 << 24 | b2 << 16 | b3 << 8 | b4 << 0; + return b1 << 24 | b2 << 16 | b3 << 8 | b4; } /** @@ -74,7 +74,9 @@ public long swapLong(long value) { long b7 = (value >> 48) & 0xff; long b8 = (value >> 56) & 0xff; - return b1 << 56 | b2 << 48 | b3 << 40 | b4 << 32 | b5 << 24 | b6 << 16 | b7 << 8 | b8 << 0; + //System.out.printf("Swapped values: [%016X, %016X, %016X, %016X, %016X, %016X, %016X, %016X]%n", b1, b2, b3, b4, b5, b6, b7, b8); + + return b1 << 56 | b2 << 48 | b3 << 40 | b4 << 32 | b5 << 24 | b6 << 16 | b7 << 8 | b8; } /** @@ -155,4 +157,4 @@ public void swap(double[] array) { for (int i = 0; i < array.length; i++) array[i] = swapDouble(array[i]); } -} +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/util/StringUtil.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/util/StringUtil.java index 821dfd2..ba2c363 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/util/StringUtil.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/util/StringUtil.java @@ -1,96 +1,97 @@ package io.mosip.imagedecoder.util; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - public class StringUtil { - private static Logger LOGGER = LoggerFactory.getLogger(StringUtil.class); - - public static int stringCompare(String str1, String str2) - { + // Static variable reference of singleInstance of type Singleton + private static StringUtil singleInstance = null; + + private StringUtil() { + super(); + } + + // synchronized method to control simultaneous access + public static synchronized StringUtil getInstance() { + if (singleInstance == null) + singleInstance = new StringUtil(); + + return singleInstance; + } + + public int stringCompare(String str1, String str2) { int l1 = str1.length(); - int l2 = str2.length(); - int lmin = Math.min(l1, l2); - - for (int i = 0; i < lmin; i++) { - int str1_ch = (int)str1.charAt(i); - int str2_ch = (int)str2.charAt(i); - - if (str1_ch != str2_ch) { - return str1_ch - str2_ch; - } - } - - // Edge case for strings like - // String 1="Geeks" and String 2="Geeksforgeeks" - if (l1 != l2) { - return l1 - l2; - } - - // If none of the above conditions is true, - // it implies both the strings are equal - else { - return 0; - } - } - - public static int atoi(char[] str) - { - int sign = 1, base = 0, i = 0; - - // if whitespaces then ignore. - while (str[i] == ' ') - { - i++; - } - - // sign of number - if (str[i] == '-' || str[i] == '+') - { - sign = 1 - 2 * (str[i++] == '-' ? 1 : 0); - } - - // checking for valid input - while (i < str.length - && str[i] >= '0' - && str[i] <= '9') { - - // handling overflow test case - if (base > Integer.MAX_VALUE / 10 - || (base == Integer.MAX_VALUE / 10 - && str[i] - '0' > 7)) - { - if (sign == 1) - return Integer.MAX_VALUE; - else - return Integer.MIN_VALUE; - } - base = 10 * base + (str[i++] - '0'); - } - return base * sign; - } - + int l2 = str2.length(); + int lmin = Math.min(l1, l2); + + for (int i = 0; i < lmin; i++) { + int str1Char = str1.charAt(i); + int str2Char = str2.charAt(i); + + if (str1Char != str2Char) { + return str1Char - str2Char; + } + } + + // Edge case for strings like + // String 1="Geeks" and String 2="Geeksforgeeks" + if (l1 != l2) { + return l1 - l2; + } + + // If none of the above conditions is true, + // it implies both the strings are equal + else { + return 0; + } + } + + @SuppressWarnings({ "java:S1659" }) + public int atoi(char[] str) { + int sign = 1, base = 0, i = 0; + + // if whitespaces then ignore. + while (str[i] == ' ') { + i++; + } + + // sign of number + if (str[i] == '-' || str[i] == '+') { + sign = 1 - 2 * (str[i++] == '-' ? 1 : 0); + } + + // checking for valid input + while (i < str.length && str[i] >= '0' && str[i] <= '9') { + + // handling overflow test case + if (base > Integer.MAX_VALUE / 10 || (base == Integer.MAX_VALUE / 10 && str[i] - '0' > 7)) { + if (sign == 1) + return Integer.MAX_VALUE; + else + return Integer.MIN_VALUE; + } + base = 10 * base + (str[i++] - '0'); + } + return base * sign; + } + /** - * Returns the double value of s. - * - * @param s - * the string containing the floating point number - * @return the value of the floating point number in s - */ - public static double atof(String s) { - int i, numMinuses = 0, numDots = 0; - - s = s.trim(); - for (i = 0; i < s.length() - && (s.charAt(i) == '-' || s.charAt(i) == '.' || Character.isDigit(s.charAt(i))); i++) - if (s.charAt(i) == '-') - numMinuses++; - else if (s.charAt(i) == '.') - numDots++; - - if (i != 0 && numMinuses < 2 && numDots < 2) - return Double.parseDouble(s.substring(0, i)); - - return 0.0; - } + * Returns the double value of s. + * + * @param s the string containing the floating point number + * @return the value of the floating point number in s + */ + @SuppressWarnings({ "java:S1659" }) + public double atof(String s) { + int i, numMinuses = 0, numDots = 0; + + s = s.trim(); + for (i = 0; i < s.length() && (s.charAt(i) == '-' || s.charAt(i) == '.' || Character.isDigit(s.charAt(i))); i++) + if (s.charAt(i) == '-') + numMinuses++; + else if (s.charAt(i) == '.') + numDots++; + + if (i != 0 && numMinuses < 2 && numDots < 2) + return Double.parseDouble(s.substring(0, i)); + + return 0.0; + } } diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/util/openjpeg/ImageUtil.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/util/openjpeg/ImageUtil.java index cc32274..d616081 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/util/openjpeg/ImageUtil.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/util/openjpeg/ImageUtil.java @@ -3,72 +3,97 @@ import java.awt.Color; import java.awt.image.BufferedImage; import java.awt.image.DataBufferByte; +import java.text.MessageFormat; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import io.mosip.kernel.core.logger.spi.Logger; +import io.mosip.imagedecoder.logger.ImageDecoderLogger; + +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_SESSIONID; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_EMPTY; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_IDTYPE; import io.mosip.imagedecoder.constant.DecoderErrorCodes; import io.mosip.imagedecoder.exceptions.DecoderException; import io.mosip.imagedecoder.model.openjpeg.OpenJpegImage; public class ImageUtil { - private static Logger LOGGER = LoggerFactory.getLogger(ImageUtil.class); - /** + private static Logger logger = ImageDecoderLogger.getLogger(ImageUtil.class); + // Static variable reference of singleInstance of type Singleton + private static ImageUtil singleInstance = null; + + private ImageUtil() { + super(); + } + + // synchronized method to control simultaneous access + public static synchronized ImageUtil getInstance() { + if (singleInstance == null) + singleInstance = new ImageUtil(); + + return singleInstance; + } + + /** * Calculate the aspect ratio from a set of width/height params + * * @param width * @param height * @return aspectRatio */ - public static double calculateAspectRatio(int width, int height) { + public double calculateAspectRatio(int width, int height) { if (width == 0 || height == 0) throw new IllegalArgumentException("Cannot calculate aspect ratio from zero"); if (width < 0 || height < 0) throw new IllegalArgumentException("Cannot calculate aspect ratio from negative numbers"); if (width > height) - return width / height; + return (double) width / height; else - return height / width; + return (double) height / width; } - /** + /** * Calculate the compression ratio from a set of width/height/depth params + * * @param width * @param height * @param depth * @param compressionImageLength * @return compressionRatio */ - public static int calculateCompressionRatio(int width, int height, int depth, int compressionImageLength) { + public int calculateCompressionRatio(int width, int height, int depth, int compressionImageLength) { if (width == 0 || height == 0 || depth == 0 || compressionImageLength == 0) throw new IllegalArgumentException("Cannot calculate compression Ratio from zero"); if (width < 0 || height < 0 || depth < 0 || compressionImageLength < 0) throw new IllegalArgumentException("Cannot calculate compression Ratio from negative numbers"); - - double compressionRatio = ((width * height * depth)/compressionImageLength); + + double compressionRatio = ((width * height * depth) / compressionImageLength); if (compressionRatio > 100) compressionRatio = 100 - compressionRatio; - return (int)Math.abs(compressionRatio); + return (int) Math.abs(compressionRatio); } - - public static BufferedImage fromJ2kImage(int width, int height, OpenJpegImage image) { - BufferedImage dib = null; + + @SuppressWarnings({ "java:S107", "java:S135", "java:S3626", "java:S3776", "java:S6541", "unused" }) + public BufferedImage fromJ2kImage(int width, int height, OpenJpegImage image) { + BufferedImage dib = null; try { // compute image width and height int wr = image.getComps()[0].getWidth(); - int wrr = MathUtil.intCeilDivPow2(image.getComps()[0].getWidth(), image.getComps()[0].getFactor()); - + int wrr = MathUtil.getInstance().intCeilDivPow2(image.getComps()[0].getWidth(), + image.getComps()[0].getFactor()); + int hr = image.getComps()[0].getHeight(); - int hrr = MathUtil.intCeilDivPow2(image.getComps()[0].getHeight(), image.getComps()[0].getFactor()); + int hrr = MathUtil.getInstance().intCeilDivPow2(image.getComps()[0].getHeight(), + image.getComps()[0].getFactor()); // check the number of components int noOfComps = image.getNoOfComps(); boolean bIsValid = true; - for(int c = 0; c < noOfComps - 1; c++) { - if( (image.getComps()[c].getDX() == image.getComps()[c+1].getDX()) && - (image.getComps()[c].getDY() == image.getComps()[c+1].getDY()) && - (image.getComps()[c].getPrec() == image.getComps()[c+1].getPrec()) ) { + for (int c = 0; c < noOfComps - 1; c++) { + if ((image.getComps()[c].getDX() == image.getComps()[c + 1].getDX()) + && (image.getComps()[c].getDY() == image.getComps()[c + 1].getDY()) + && (image.getComps()[c].getPrec() == image.getComps()[c + 1].getPrec())) { continue; } else { bIsValid = false; @@ -76,241 +101,145 @@ public static BufferedImage fromJ2kImage(int width, int height, OpenJpegImage im } } bIsValid &= ((noOfComps == 1) || (noOfComps == 3) || (noOfComps == 4)); - if(!bIsValid) { - if(noOfComps != 0) { - LOGGER.error(String.format("Warning: image contains %d greyscale components. Only the first will be loaded.", noOfComps)); + if (!bIsValid) { + if (noOfComps != 0) { + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + MessageFormat.format( + "Warning: image contains {0} greyscale components. Only the first will be loaded.", + noOfComps)); noOfComps = 1; } else { // unknown type - throw new DecoderException (DecoderErrorCodes.UNSUPPORTED_FORMAT_ERROR.getErrorCode(), DecoderErrorCodes.UNSUPPORTED_FORMAT_ERROR.getErrorMessage()); + throw new DecoderException(DecoderErrorCodes.UNSUPPORTED_FORMAT_ERROR.getErrorCode(), + DecoderErrorCodes.UNSUPPORTED_FORMAT_ERROR.getErrorMessage()); } } - + // create a new DIB - if(image.getComps()[0].getPrec() <= 8) { - switch(noOfComps) { - case 1: - dib = new BufferedImage(wrr, hrr, BufferedImage.TYPE_BYTE_GRAY); - break; - case 3: - dib = new BufferedImage(wrr, hrr, BufferedImage.TYPE_INT_RGB); - break; - case 4: - dib = new BufferedImage(wrr, hrr, BufferedImage.TYPE_INT_ARGB); - break; + if (image.getComps()[0].getPrec() <= 8) { + switch (noOfComps) { + case 1: + dib = new BufferedImage(wrr, hrr, BufferedImage.TYPE_BYTE_GRAY); + break; + case 3: + dib = new BufferedImage(wrr, hrr, BufferedImage.TYPE_INT_RGB); + break; + case 4: + dib = new BufferedImage(wrr, hrr, BufferedImage.TYPE_INT_ARGB); + break; + default: + throw new DecoderException(DecoderErrorCodes.UNSUPPORTED_FORMAT_ERROR.getErrorCode(), + DecoderErrorCodes.UNSUPPORTED_FORMAT_ERROR.getErrorMessage()); } - } else if(image.getComps()[0].getPrec() <= 16) { - switch(noOfComps) { - case 1: - dib = new BufferedImage(wrr, hrr, BufferedImage.TYPE_USHORT_GRAY); - break; - case 3: - dib = new BufferedImage(wrr, hrr, BufferedImage.TYPE_INT_RGB); - break; - case 4: - dib = new BufferedImage(wrr, hrr, BufferedImage.TYPE_INT_ARGB); - break; + } else if (image.getComps()[0].getPrec() <= 16) { + switch (noOfComps) { + case 1: + dib = new BufferedImage(wrr, hrr, BufferedImage.TYPE_USHORT_GRAY); + break; + case 3: + dib = new BufferedImage(wrr, hrr, BufferedImage.TYPE_INT_RGB); + break; + case 4: + dib = new BufferedImage(wrr, hrr, BufferedImage.TYPE_INT_ARGB); + break; + default: + throw new DecoderException(DecoderErrorCodes.UNSUPPORTED_FORMAT_ERROR.getErrorCode(), + DecoderErrorCodes.UNSUPPORTED_FORMAT_ERROR.getErrorMessage()); } } else { - throw new DecoderException (DecoderErrorCodes.UNSUPPORTED_FORMAT_ERROR.getErrorCode(), DecoderErrorCodes.UNSUPPORTED_FORMAT_ERROR.getErrorMessage()); + throw new DecoderException(DecoderErrorCodes.UNSUPPORTED_FORMAT_ERROR.getErrorCode(), + DecoderErrorCodes.UNSUPPORTED_FORMAT_ERROR.getErrorMessage()); } - if(dib == null) { - throw new DecoderException (DecoderErrorCodes.BUFFEREDIMAGE_ALLOCATION_FAILED_ERROR.getErrorCode(), DecoderErrorCodes.BUFFEREDIMAGE_ALLOCATION_FAILED_ERROR.getErrorMessage()); + if (dib == null) { + throw new DecoderException(DecoderErrorCodes.BUFFEREDIMAGE_ALLOCATION_FAILED_ERROR.getErrorCode(), + DecoderErrorCodes.BUFFEREDIMAGE_ALLOCATION_FAILED_ERROR.getErrorMessage()); } - if(image.getComps()[0].getPrec() <= 8) { - if(noOfComps == 1) { + if (image.getComps()[0].getPrec() <= 8) { + if (noOfComps == 1) { // 8-bit greyscale // ---------------------------------------------------------- // load pixel data - byte[] array = ((DataBufferByte) dib.getRaster().getDataBuffer()).getData(); - System.arraycopy(ImageUtil.integersToBytes (image.getComps()[0].getData()), 0, array, 0, array.length); - - /* - int pixel_count = 0; - for(int y = 0; y < hrr; y++) { - int bitsIndex = hrr - 1 - y; - - for(int x = 0; x < wrr; x++) { - int pixel_pos = (pixel_count / wrr * wr + pixel_count % wrr); - - int index = image.getComps()[0].getData()[pixel_pos]; - index += (image.getComps()[0].getSgnd() != 0 ? 1 << (image.getComps()[0].getPrec() - 1) : 0); - - dib.setRGB(x, y, (byte)index); - pixel_count++; - } - } - */ - } - else if(noOfComps == 3) { + byte[] array = ((DataBufferByte) dib.getRaster().getDataBuffer()).getData(); + System.arraycopy(integersToBytes(image.getComps()[0].getData()), 0, array, 0, array.length); + } else if (noOfComps == 3) { // 24-bit RGB - // ---------------------------------------------------------- - + // ---------------------------------------------------------- + // load pixel data - int pixel_count = 0; + int pixelCount = 0; - for(int y = 0; y < hrr; y++) { + for (int y = 0; y < hrr; y++) { int bitsIndex = hrr - 1 - y; - for(int x = 0; x < wrr; x++) { - int pixel_pos = (int) (pixel_count / wrr * wr + pixel_count % wrr); + for (int x = 0; x < wrr; x++) { + int pixelPosition = (pixelCount / wrr * wr + pixelCount % wrr); - int r = image.getComps()[0].getData()[pixel_pos]; + int r = image.getComps()[0].getData()[pixelPosition]; r += (image.getComps()[0].getSgnd() != 0 ? 1 << (image.getComps()[0].getPrec() - 1) : 0); - - int g = image.getComps()[1].getData()[pixel_pos]; + + int g = image.getComps()[1].getData()[pixelPosition]; g += (image.getComps()[1].getSgnd() != 0 ? 1 << (image.getComps()[1].getPrec() - 1) : 0); - - int b = image.getComps()[2].getData()[pixel_pos]; + + int b = image.getComps()[2].getData()[pixelPosition]; b += (image.getComps()[2].getSgnd() != 0 ? 1 << (image.getComps()[2].getPrec() - 1) : 0); dib.setRGB(x, y, new Color(r, g, b).getRGB()); - pixel_count++; + pixelCount++; } } - } - else if(noOfComps == 4) { + } else if (noOfComps == 4) { // 32-bit RGBA - // ---------------------------------------------------------- - - // load pixel data - - int pixel_count = 0; - - for(int y = 0; y < hrr; y++) { - int bitsIndex = hrr - 1 - y; - - for(int x = 0; x < wrr; x++) { - int pixel_pos = (int) (pixel_count / wrr * wr + pixel_count % wrr); - - int r = image.getComps()[0].getData()[pixel_pos]; - r += (image.getComps()[0].getSgnd() != 0 ? 1 << (image.getComps()[0].getPrec() - 1) : 0); - - int g = image.getComps()[1].getData()[pixel_pos]; - g += (image.getComps()[1].getSgnd() != 0 ? 1 << (image.getComps()[1].getPrec() - 1) : 0); - - int b = image.getComps()[2].getData()[pixel_pos]; - b += (image.getComps()[2].getSgnd() != 0 ? 1 << (image.getComps()[2].getPrec() - 1) : 0); - - int a = image.getComps()[3].getData()[pixel_pos]; - a += (image.getComps()[3].getSgnd() != 0 ? 1 << (image.getComps()[3].getPrec() - 1) : 0); - - dib.setRGB(x, y, new Color(r, g, b, a).getRGB()); - pixel_count++; - } - } - } - } - /* need to handle a - else if(image.getComps()[0].getPrec() <= 16) { - if(noOfComps == 1) { - // 16-bit greyscale // ---------------------------------------------------------- // load pixel data - long pixel_count = 0; + int pixelCount = 0; - for(int y = 0; y < hrr; y++) { + for (int y = 0; y < hrr; y++) { int bitsIndex = hrr - 1 - y; - for(int x = 0; x < wrr; x++) { - int pixel_pos = (int) (pixel_count / wrr * wr + pixel_count % wrr); - - int index = image.getComps()[0].getData()[pixel_pos]; - index += (image.getComps()[0].getSgnd() != 0 ? 1 << (image.getComps()[0].getPrec() - 1) : 0); - - dib.setRGB(x, y, (short)index); - pixel_count++; - } - } - } - else if(noOfComps == 3) { + for (int x = 0; x < wrr; x++) { + int pixelPosition = (pixelCount / wrr * wr + pixelCount % wrr); - // 48-bit RGB - // ---------------------------------------------------------- - - // load pixel data - - int pixel_count = 0; - - for(int y = 0; y < hrr; y++) { - int bitsIndex = hrr - 1 - y; - - for(int x = 0; x < wrr; x++) { - int pixel_pos = pixel_count / wrr * wr + pixel_count % wrr; - - int r = image.getComps()[0].getData()[pixel_pos]; + int r = image.getComps()[0].getData()[pixelPosition]; r += (image.getComps()[0].getSgnd() != 0 ? 1 << (image.getComps()[0].getPrec() - 1) : 0); - - int g = image.getComps()[1].getData()[pixel_pos]; - g += (image.getComps()[1].getSgnd() != 0 ? 1 << (image.getComps()[1].getPrec() - 1) : 0); - - int b = image.getComps()[2].getData()[pixel_pos]; - b += (image.getComps()[2].getSgnd() != 0 ? 1 << (image.getComps()[2].getPrec() - 1) : 0); - - dib.setRGB(x, y, new Color(r, g, b).getRGB()); - - pixel_count++; - } - } - } - else if(noOfComps == 4) { - - // 64-bit RGBA - // ---------------------------------------------------------- - - // load pixel data - int pixel_count = 0; - - for(int y = 0; y < hrr; y++) { - int bitsIndex = hrr - 1 - y; - - for(int x = 0; x < wrr; x++) { - int pixel_pos = pixel_count / wrr * wr + pixel_count % wrr; + int g = image.getComps()[1].getData()[pixelPosition]; + g += (image.getComps()[1].getSgnd() != 0 ? 1 << (image.getComps()[1].getPrec() - 1) : 0); - int r = image.getComps()[0].getData()[pixel_pos]; - r += (image.getComps()[0].getSgnd() != 0 ? 1 << (image.getComps()[0].getPrec() - 1) : 0); - - int g = image.getComps()[1].getData()[pixel_pos]; - g += (image.getComps()[1].getSgnd() != 0 ? 1 << (image.getComps()[1].getPrec() - 1) : 0); - - int b = image.getComps()[2].getData()[pixel_pos]; - b += (image.getComps()[2].getSgnd() != 0 ? 1 << (image.getComps()[2].getPrec() - 1) : 0); + int b = image.getComps()[2].getData()[pixelPosition]; + b += (image.getComps()[2].getSgnd() != 0 ? 1 << (image.getComps()[2].getPrec() - 1) : 0); - int a = image.getComps()[3].getData()[pixel_pos]; - a += (image.getComps()[3].getSgnd() != 0 ? 1 << (image.getComps()[3].getPrec() - 1) : 0); + int a = image.getComps()[3].getData()[pixelPosition]; + a += (image.getComps()[3].getSgnd() != 0 ? 1 << (image.getComps()[3].getPrec() - 1) : 0); dib.setRGB(x, y, new Color(r, g, b, a).getRGB()); - - pixel_count++; + pixelCount++; } } } - }*/ - } - catch(Exception ex) - { - ex.printStackTrace(); + } + } catch (Exception ex) { + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "fromJ2kImage", ex); + throw ex; } return dib; - } - - public static BufferedImage fromByteGray(int width, int height, byte[] gray) { - BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY); - byte[] array = ((DataBufferByte) image.getRaster().getDataBuffer()).getData(); - System.arraycopy(gray, 0, array, 0, array.length); - return image; - } - - public static byte[] integersToBytes(int[] data) { - byte[] array = new byte[data.length]; - for (int index=0; index < data.length; index++) - array[index] = (byte) data[index]; - return array; - } -} + } + + public BufferedImage fromByteGray(int width, int height, byte[] gray) { + BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY); + byte[] array = ((DataBufferByte) image.getRaster().getDataBuffer()).getData(); + System.arraycopy(gray, 0, array, 0, array.length); + return image; + } + + public byte[] integersToBytes(int[] data) { + byte[] array = new byte[data.length]; + for (int index = 0; index < data.length; index++) + array[index] = (byte) data[index]; + return array; + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/util/openjpeg/MathUtil.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/util/openjpeg/MathUtil.java index b7243de..a23fb54 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/util/openjpeg/MathUtil.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/util/openjpeg/MathUtil.java @@ -1,67 +1,97 @@ package io.mosip.imagedecoder.util.openjpeg; public class MathUtil { - /*Get the minimum of two integers - @return Returns a if a < b else b - */ - public static int intMin(int a, int b) { + // Static variable reference of singleInstance of type Singleton + private static MathUtil singleInstance = null; + + private MathUtil() { + super(); + } + + // synchronized method to control simultaneous access + public static synchronized MathUtil getInstance() { + if (singleInstance == null) + singleInstance = new MathUtil(); + + return singleInstance; + } + + /* + * Get the minimum of two integers + * + * @return Returns a if a < b else b + */ + public int intMin(int a, int b) { return a < b ? a : b; } + /** - Get the maximum of two integers - @return Returns a if a > b else b - */ - public static int intMax(int a, int b) { + * Get the maximum of two integers + * + * @return Returns a if a > b else b + */ + public int intMax(int a, int b) { return (a > b) ? a : b; } + /** - Clamp an integer inside an interval - @return -
    -
  • Returns a if (min < a < max) -
  • Returns max if (a > max) -
  • Returns min if (a < min) -
- */ - public static int intClamp(int a, int min, int max) { + * Clamp an integer inside an interval + * + * @return + *
    + *
  • Returns a if (min < a < max) + *
  • Returns max if (a > max) + *
  • Returns min if (a < min) + *
+ */ + public int intClamp(int a, int min, int max) { if (a < min) return min; if (a > max) return max; return a; } + /** - @return Get absolute value of integer - */ - public static int intAbs(int a) { + * @return Get absolute value of integer + */ + public int intAbs(int a) { return a < 0 ? -a : a; } + /** - Divide an integer and round upwards - @return Returns a divided by b - */ - public static int intCeilDiv(int a, int b) { + * Divide an integer and round upwards + * + * @return Returns a divided by b + */ + public int intCeilDiv(int a, int b) { return (a + b - 1) / b; } + /** - Divide an integer by a power of 2 and round upwards - @return Returns a divided by 2^b - */ - public static int intCeilDivPow2(int a, int b) { + * Divide an integer by a power of 2 and round upwards + * + * @return Returns a divided by 2^b + */ + public int intCeilDivPow2(int a, int b) { return (a + (1 << b) - 1) >> b; } + /** - Divide an integer by a power of 2 and round downwards - @return Returns a divided by 2^b - */ - public static int intFloorDivPow2(int a, int b) { + * Divide an integer by a power of 2 and round downwards + * + * @return Returns a divided by 2^b + */ + public int intFloorDivPow2(int a, int b) { return a >> b; } + /** - Get logarithm of an integer and round downwards - @return Returns log2(a) - */ - public static int intFloorLog2(int a) { + * Get logarithm of an integer and round downwards + * + * @return Returns log2(a) + */ + public int intFloorLog2(int a) { int l; for (l = 0; a > 1; l++) { a >>= 1; diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/util/wsq/WsqUtil.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/util/wsq/WsqUtil.java index c060146..10500c0 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/util/wsq/WsqUtil.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/util/wsq/WsqUtil.java @@ -1,7 +1,13 @@ package io.mosip.imagedecoder.util.wsq; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_EMPTY; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_IDTYPE; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_SESSIONID; + +import java.text.MessageFormat; + +import io.mosip.kernel.core.logger.spi.Logger; +import io.mosip.imagedecoder.logger.ImageDecoderLogger; import io.mosip.imagedecoder.constant.wsq.WsqConstant; import io.mosip.imagedecoder.constant.wsq.WsqErrorCode; @@ -12,14 +18,30 @@ import io.mosip.imagedecoder.model.wsq.WsqWavletTree; public class WsqUtil { - private static Logger LOGGER = LoggerFactory.getLogger(WsqUtil.class); + private static Logger logger = ImageDecoderLogger.getLogger(WsqUtil.class); + + // Static variable reference of singleInstance of type Singleton + private static WsqUtil singleInstance = null; + + private WsqUtil() { + super(); + } + + // synchronized method to control simultaneous access + public static synchronized WsqUtil getInstance() { + if (singleInstance == null) + singleInstance = new WsqUtil(); + + return singleInstance; + } /******************************************************************/ /* This routine converts the unsigned char data to float. In the */ /* process it shifts and scales the data so the values range from */ /* +/- 128.0 This function returns on error. */ /******************************************************************/ - public static int convertImage2Floats(float[] fImageData, /* output float image data */ + @SuppressWarnings({ "java:S1659" }) + public int convertImage2Floats(float[] fImageData, /* output float image data */ float[] mShift, /* shifting parameter */ float[] rScale, /* scaling parameter */ byte[] data, /* input signed byte data */ @@ -42,7 +64,8 @@ public static int convertImage2Floats(float[] fImageData, /* output float image low = data[cnt] & 0xFF; sum += data[cnt] & 0xFF; if (sum < overflow) { - LOGGER.error(String.format("convertImage2Float: overflow at %d", cnt)); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + MessageFormat.format("convertImage2Float: overflow at {0}", cnt)); return (WsqErrorCode.IMAGE_DATA_OVERFLOW_WILL_READING.getErrorId()); } overflow = sum; @@ -59,10 +82,10 @@ public static int convertImage2Floats(float[] fImageData, /* output float image else rScale[0] = highDiff; - rScale[0] /= (float) 128.0; + rScale[0] /= 128.0f; for (cnt = 0; cnt < numOfPixels; cnt++) { - fImageData[cnt] = ((float) (data[cnt] & 0xFF) - mShift[0]) / rScale[0]; + fImageData[cnt] = ((data[cnt] & 0xFF) - mShift[0]) / rScale[0]; } return (0); } @@ -70,7 +93,8 @@ public static int convertImage2Floats(float[] fImageData, /* output float image /*********************************************************/ /* Routine to convert image from float to signed byte array. */ /*********************************************************/ - public static void convertImage2Bytes(byte[] data, /* uchar image pointer */ + @SuppressWarnings({ "java:S1659", "unused" }) + public void convertImage2Bytes(byte[] data, /* uchar image pointer */ float[] img, /* image pointer */ int width, /* image width */ int height, /* image height */ @@ -100,8 +124,9 @@ else if (imgTmp > 255.0) /**********************************************************/ /* This routine calculates the variances of the subbands. */ /**********************************************************/ - public static void variance(WsqQuantization quantValues, /* quantization parameters */ - WsqQuantizationTree quantizationTree[], /* quantization "tree" */ + @SuppressWarnings({ "java:S1659", "java:S3776" }) + public void variance(WsqQuantization quantValues, /* quantization parameters */ + WsqQuantizationTree[] quantizationTree, /* quantization "tree" */ int qTreeLen, /* length of quantizationTree */ float[] fImageData, /* image pointer */ int width, /* image width */ @@ -193,10 +218,11 @@ public static void variance(WsqQuantization quantValues, /* quantization paramet /************************************************/ /* This routine quantizes the wavelet subbands. */ /************************************************/ - public static int quantize(short[] sip, /* quantized output init in calling function with width * height */ + @SuppressWarnings({ "java:S107", "java:S117", "java:S1659", "java:S3776", "java:S6541", "unused" }) + public int quantize(short[] sip, /* quantized output init in calling function with width * height */ int[] cmpSize, /* size of quantized output */ WsqQuantization quantValues, /* quantization parameters */ - WsqQuantizationTree quantizationTree[], /* quantization "tree" */ + WsqQuantizationTree[] quantizationTree, /* quantization "tree" */ int qTreeLen, /* size of quantizationTree */ float[] fImageData, /* floating point image pointer */ int width, /* image width */ @@ -257,7 +283,6 @@ public static int quantize(short[] sip, /* quantized output init in calling func /* Set up output buffer. */ // should be defined in calling function - // sip = new short[width * height]; sipIndex = 0; /* Set up 'm' table (these values are the reciprocal of 'm' in */ @@ -341,7 +366,7 @@ public static int quantize(short[] sip, /* quantized output init in calling func nK = K1; nK = new int[WsqConstant.NUM_SUBBANDS]; for (i = 0; i < K0len; i++) { - nK[K0[i]] = 1;// TRUE; + nK[K0[i]] = 1; } /* Set 'Q' values. */ for (cnt = 0; cnt < WsqConstant.NUM_SUBBANDS; cnt++) { @@ -376,15 +401,16 @@ else if (fImageData[fpIndex] > 0.0) } } - cmpSize[0] = (int) (sipIndex - sip.length); + cmpSize[0] = (sipIndex - sip.length); return (0); } /************************************************************************/ /* Compute quantized WSQ subband block sizes. */ /************************************************************************/ - public static void quantizedBlockSizes(int[] qSize1, int[] qSize2, int[] qSize3, WsqQuantization quantValues, - WsqWavletTree wavletTree[], int waveletTreeLen, WsqQuantizationTree quantizationTree[], int qTreeLen) { + @SuppressWarnings({ "java:S107", "java:S117", "java:S1659", "java:S3776", "java:S6541", "unused" }) + public void quantizedBlockSizes(int[] qSize1, int[] qSize2, int[] qSize3, WsqQuantization quantValues, + WsqWavletTree[] wavletTree, int waveletTreeLen, WsqQuantizationTree[] quantizationTree, int qTreeLen) { int nodeIndex; /* Compute temporary sizes of 3 WSQ subband blocks. */ @@ -411,9 +437,10 @@ public static void quantizedBlockSizes(int[] qSize1, int[] qSize2, int[] qSize3, /*************************************/ /* Routine to unquantize image data. */ /*************************************/ - public static int unquantize(float[] fImageData, /* floating point image pointer */ + @SuppressWarnings({ "java:S107", "java:S1659", "java:S3776", "java:S6541" }) + public int unquantize(float[] fImageData, /* floating point image pointer */ WsqTableDqt dqtTable, /* quantization table structure */ - WsqQuantizationTree quantizationTree[], /* quantization table structure */ + WsqQuantizationTree[] quantizationTree, /* quantization table structure */ int qTreeLen, /* size of quantizationTree */ long[] sip, /* quantized image pointer */ int width, /* image width */ @@ -426,7 +453,8 @@ public static int unquantize(float[] fImageData, /* floating point image pointer int cnt; /* subband counter */ if (dqtTable.getDqtDef() != 1) { - LOGGER.error(String.format("unquantize : quantization table parameters not defined")); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + "unquantize : quantization table parameters not defined"); return (WsqErrorCode.QUANTIZATION_TABLE_PARAMS_NOT_DEFINED.getErrorId()); } @@ -442,13 +470,14 @@ public static int unquantize(float[] fImageData, /* floating point image pointer if (sip[spIndex] == 0) fImageData[fpIndex] = 0.0f; else if (sip[spIndex] > 0) - fImageData[fpIndex] = (float) ((dqtTable.getQBin()[cnt] * ((float) sip[spIndex] - qBinCenter)) + fImageData[fpIndex] = (float) ((dqtTable.getQBin()[cnt] * (sip[spIndex] - qBinCenter)) + (dqtTable.getZBin()[cnt] / 2.0)); else if (sip[spIndex] < 0) - fImageData[fpIndex] = (float) ((dqtTable.getQBin()[cnt] * ((float) sip[spIndex] + qBinCenter)) + fImageData[fpIndex] = (float) ((dqtTable.getQBin()[cnt] * (sip[spIndex] + qBinCenter)) - (dqtTable.getZBin()[cnt] / 2.0)); else { - LOGGER.error(String.format("unquantize : invalid quantization pixel value")); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + "unquantize : invalid quantization pixel value"); return (WsqErrorCode.INVALID_QUANTIZATION_PIXEL_VALUE.getErrorId()); } fpIndex++; @@ -464,8 +493,9 @@ else if (sip[spIndex] < 0) /* WSQ decompose the image. NOTE: this routine modifies and returns */ /* the results in "fImageData". */ /************************************************************************/ - public static int wsqDecompose(float[] fImageData, int width, int height, WsqWavletTree wavletTree[], - int waveletTreeLen, float[] highFilter, int highSize, float[] lowFilter, int lowSize) { + @SuppressWarnings({ "java:S107", "java:S1659" }) + public int wsqDecompose(float[] fImageData, int width, int height, WsqWavletTree[] wavletTree, int waveletTreeLen, + float[] highFilter, int highSize, float[] lowFilter, int lowSize) { int numOfPixels, nodeIndex; float[] fImageDataTmp; int fDataIndex; @@ -490,7 +520,8 @@ public static int wsqDecompose(float[] fImageData, int width, int height, WsqWav /************************************************************/ /************************************************************/ - public static void getLets(float[] newData, int newDataIndex, /* image pointers for creating subband splits */ + @SuppressWarnings({ "java:S107", "java:S117", "java:S1659", "java:S1854", "java:S3776", "java:S6541" }) + public void getLets(float[] newData, int newDataIndex, /* image pointers for creating subband splits */ float[] oldData, int oldDataIndex, int len1, /* temporary length parameters */ int len2, int pitch, /* pitch gives next row_col to filter */ int stride, /* stride gives next pixel to filter */ @@ -693,18 +724,21 @@ public static void getLets(float[] newData, int newDataIndex, /* image pointers /* WSQ reconstructs the image. NOTE: this routine modifies and returns */ /* the results in "fImageData". */ /************************************************************************/ - public static int wsqReconstruct(float[] fImageData, int width, int height, WsqWavletTree wavletTree[], - int waveletTreeLen, WsqTableDtt dttTable) { + @SuppressWarnings({ "java:S1659" }) + public int wsqReconstruct(float[] fImageData, int width, int height, WsqWavletTree[] wavletTree, int waveletTreeLen, + WsqTableDtt dttTable) { int numOfPixels, nodeIndex; float[] fImageDataTmp; int fdataIndex = 0; if (dttTable.getLowDef() != 1) { - LOGGER.error(String.format("wsq_reconstruct : Lopass filter coefficients not defined")); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + "wsq_reconstruct : Lopass filter coefficients not defined"); return (WsqErrorCode.LOW_PASS_FILTER_COEFF_NOT_DEFINED.getErrorId()); } if (dttTable.getHighDef() != 1) { - LOGGER.error(String.format("wsq_reconstruct : Hipass filter coefficients not defined")); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + "wsq_reconstruct : Hipass filter coefficients not defined"); return (WsqErrorCode.HIGH_PASS_FILTER_COEFF_NOT_DEFINED.getErrorId()); } @@ -722,12 +756,12 @@ public static int wsqReconstruct(float[] fImageData, int width, int height, WsqW wavletTree[nodeIndex].getLenX(), width, 1, dttTable.getHighFilter(), dttTable.getHighSize(), dttTable.getLowFilter(), dttTable.getLowSize(), wavletTree[nodeIndex].getInvRow()); } - fImageDataTmp = null; return (0); } /****************************************************************/ - public static void joinLets(float[] newData, int newDataIndex, /* image pointers for creating subband splits */ + @SuppressWarnings({ "java:S107", "java:S117", "java:S1659", "java:S3776", "java:S6541" }) + public void joinLets(float[] newData, int newDataIndex, /* image pointers for creating subband splits */ float[] oldData, int oldDataIndex, int len1, /* temporary length parameters */ int len2, int pitch, /* pitch gives next row_col to filter */ int stride, /* stride gives next pixel to filter */ @@ -921,7 +955,7 @@ public static void joinLets(float[] newData, int newDataIndex, /* image pointers if (asym != 0 && daEven != 0) { hre = 1; fhre--; - sfac = (float) fhre; + sfac = fhre; if (sfac == 0.0f) hre = 0; } @@ -1032,7 +1066,7 @@ public static void joinLets(float[] newData, int newDataIndex, /* image pointers if (asym != 0 && daEven != 0) { hre = 1; fhre--; - sfac = (float) fhre; + sfac = fhre; if (sfac == 0.0) hre = 0; } @@ -1058,7 +1092,8 @@ public static void joinLets(float[] newData, int newDataIndex, /* image pointers /*****************************************************/ /* Routine to execute an integer sign determination */ /*****************************************************/ - public static int intSign(int power) /* "sign" power */ { + @SuppressWarnings({ "java:S1659" }) + public int intSign(int power) /* "sign" power */ { int cnt, num = -1; /* counter and sign return value */ if (power == 0) @@ -1074,7 +1109,8 @@ public static int intSign(int power) /* "sign" power */ { /* Computes size of compressed image file including headers, */ /* tables, and parameters. */ /*************************************************************/ - public static int imageSize(int blockLen, /* length of the compressed blocks */ + @SuppressWarnings({ "java:S117", "java:S1659", "java:S3776" }) + public int imageSize(int blockLen, /* length of the compressed blocks */ short[] huffBits1, /* huffman table parameters */ short[] huffBits2) { int totalSize, cnt; @@ -1105,7 +1141,7 @@ public static int imageSize(int blockLen, /* length of the compressed blocks */ /*************************************************************/ /* Initializes memory used by the WSQ decoder. */ /*************************************************************/ - public static void initWsqDecoderResources(WsqTableDtt dttTable) { + public void initWsqDecoderResources(WsqTableDtt dttTable) { /* Init dymanically allocated members to NULL */ /* for proper memory management in: */ /* read_transform_table() */ @@ -1118,7 +1154,7 @@ public static void initWsqDecoderResources(WsqTableDtt dttTable) { /*************************************************************/ /* Deallocates memory used by the WSQ decoder. */ /*************************************************************/ - public static void freeWsqDecoderResources(WsqTableDtt dttTable) { + public void freeWsqDecoderResources(WsqTableDtt dttTable) { if (dttTable.getLowFilter() != null) { dttTable.setLowFilter(null); } @@ -1127,4 +1163,4 @@ public static void freeWsqDecoderResources(WsqTableDtt dttTable) { dttTable.setHighFilter(null); } } -} +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqDecoder.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqDecoder.java index 2161c49..a978d7f 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqDecoder.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqDecoder.java @@ -1,12 +1,15 @@ package io.mosip.imagedecoder.wsq; -import java.awt.image.BufferedImage; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_EMPTY; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_IDTYPE; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_SESSIONID; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.awt.image.BufferedImage; import io.mosip.imagedecoder.constant.DecoderConstant; +import io.mosip.imagedecoder.constant.DecoderErrorCodes; import io.mosip.imagedecoder.constant.wsq.WsqErrorCode; +import io.mosip.imagedecoder.logger.ImageDecoderLogger; import io.mosip.imagedecoder.model.DecoderRequestInfo; import io.mosip.imagedecoder.model.DecoderResponseInfo; import io.mosip.imagedecoder.model.Response; @@ -14,6 +17,7 @@ import io.mosip.imagedecoder.spi.IImageDecoderApi; import io.mosip.imagedecoder.util.Base64UrlUtil; import io.mosip.imagedecoder.util.openjpeg.ImageUtil; +import io.mosip.kernel.core.logger.spi.Logger; /** * The Class WSQDecoder does the decoding of WSQ image information @@ -22,60 +26,54 @@ * */ public class WsqDecoder implements IImageDecoderApi { - Logger LOGGER = LoggerFactory.getLogger(WsqDecoder.class); + private Logger logger = ImageDecoderLogger.getLogger(WsqDecoder.class); @Override public Response decode(DecoderRequestInfo requestInfo) { - Response response = new Response(); + Response response = new Response<>(); try { DecoderResponseInfo responseInfo = new DecoderResponseInfo(); WsqInfo wsqInfo = WsqDecoderHelper.getInstance().wsqDecode(requestInfo.getImageData(), requestInfo.getImageData().length); + responseInfo.setAllInfo(requestInfo.isAllInfo()); responseInfo.setImageType(DecoderConstant.IMAGE_TYPE_WSQ); responseInfo.setImageWidth(wsqInfo.getWidth() + ""); responseInfo.setImageHeight(wsqInfo.getHeight() + ""); - responseInfo.setImageLossless(wsqInfo.getLossyFlag() == 1 ? "0" : "1"); - responseInfo.setImageDepth(wsqInfo.getDepth() + ""); - responseInfo.setImageDpiHorizontal(wsqInfo.getPpi() + ""); - responseInfo.setImageDpiVertical(wsqInfo.getPpi() + ""); - responseInfo.setImageBitRate(String.format("%.2f", wsqInfo.getBitRate()) + ""); - responseInfo.setImageSize(wsqInfo.getData().length + ""); - responseInfo.setImageData(Base64UrlUtil.encodeToURLSafeBase64(wsqInfo.getData()) + ""); - responseInfo.setImageColorSpace(wsqInfo.getColorSpace() + ""); - responseInfo - .setImageAspectRatio(ImageUtil.calculateAspectRatio(wsqInfo.getWidth(), wsqInfo.getHeight()) + ""); - String compressionRatio = ""; - try { - compressionRatio = ((int) ImageUtil.calculateCompressionRatio(wsqInfo.getWidth(), wsqInfo.getHeight(), - wsqInfo.getDepth(), requestInfo.getImageData().length) + " : 1"); - } catch (Exception ex) { + if (requestInfo.isAllInfo()) { + responseInfo.setImageLossless(wsqInfo.getLossyFlag() == 1 ? "0" : "1"); + responseInfo.setImageDepth(wsqInfo.getDepth() + ""); + responseInfo.setImageDpiHorizontal(wsqInfo.getPpi() + ""); + responseInfo.setImageDpiVertical(wsqInfo.getPpi() + ""); + responseInfo.setImageBitRate(String.format("%.2f", wsqInfo.getBitRate()) + ""); + responseInfo.setImageSize(wsqInfo.getData().length + ""); + responseInfo.setImageData(Base64UrlUtil.getInstance().encodeToURLSafeBase64(wsqInfo.getData()) + ""); + responseInfo.setImageColorSpace(wsqInfo.getColorSpace() + ""); + responseInfo.setImageAspectRatio( + ImageUtil.getInstance().calculateAspectRatio(wsqInfo.getWidth(), wsqInfo.getHeight()) + ""); + responseInfo.setImageCompressionRatio(getCompressionRatio(requestInfo, wsqInfo)); } - - responseInfo.setImageCompressionRatio(compressionRatio); - if (requestInfo.isBufferedImage()) - { - BufferedImage image = null; - try - { - image = ImageUtil.fromByteGray(wsqInfo.getWidth(), wsqInfo.getHeight(), wsqInfo.getData()); - responseInfo.setBufferedImage(image); - } - catch(Exception ex) - { - ex.printStackTrace(); - responseInfo.setBufferedImage(null); - } + if (requestInfo.isBufferedImage()) { + responseInfo.setBufferedImage(getBufferedImage(wsqInfo)); } - + response.setResponse(responseInfo); response.setStatusCode(0); - response.setStatusMessage("SUCCESS"); + response.setStatusMessage(DecoderErrorCodes.SUCCESS.getErrorMessage()); } catch (Exception ex) { - ex.printStackTrace(); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "decode", ex); response.setStatusCode(WsqErrorCode.TECHNICAL_ERROR_EXCEPTION.getErrorId()); response.setStatusMessage(ex.getLocalizedMessage()); } return response; } -} + + private String getCompressionRatio(DecoderRequestInfo requestInfo, WsqInfo wsqInfo) { + return (ImageUtil.getInstance().calculateCompressionRatio(wsqInfo.getWidth(), wsqInfo.getHeight(), + wsqInfo.getDepth(), requestInfo.getImageData().length) + " : 1"); + } + + private BufferedImage getBufferedImage(WsqInfo wsqInfo) { + return ImageUtil.getInstance().fromByteGray(wsqInfo.getWidth(), wsqInfo.getHeight(), wsqInfo.getData()); + } +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqDecoderHelper.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqDecoderHelper.java index 7ffffaf..8a0139c 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqDecoderHelper.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqDecoderHelper.java @@ -1,7 +1,13 @@ package io.mosip.imagedecoder.wsq; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_EMPTY; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_IDTYPE; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_SESSIONID; + +import java.text.MessageFormat; + +import io.mosip.kernel.core.logger.spi.Logger; +import io.mosip.imagedecoder.logger.ImageDecoderLogger; import io.mosip.imagedecoder.constant.wsq.WsqConstant; import io.mosip.imagedecoder.constant.wsq.WsqErrorCode; @@ -18,6 +24,7 @@ import io.mosip.imagedecoder.model.wsq.WsqWavletTree; import io.mosip.imagedecoder.util.ByteStreamUtil; import io.mosip.imagedecoder.util.wsq.WsqUtil; + /** * The Class WSQDecoder Helper does the decoding of WSQ image information * @@ -25,36 +32,43 @@ * */ public class WsqDecoderHelper { - private Logger LOGGER = LoggerFactory.getLogger(WsqDecoderHelper.class); + private Logger logger = ImageDecoderLogger.getLogger(WsqDecoderHelper.class); // Static variable reference of singleInstance of type Singleton - private static WsqDecoderHelper singleInstance = null; - private WsqDecoderHelper() - { - super (); - } - - //synchronized method to control simultaneous access - public static synchronized WsqDecoderHelper getInstance() - { + private static WsqDecoderHelper singleInstance = null; + + private WsqDecoderHelper() { + super(); + } + + // synchronized method to control simultaneous access + public static synchronized WsqDecoderHelper getInstance() { if (singleInstance == null) singleInstance = new WsqDecoderHelper(); - - return singleInstance; + + return singleInstance; } - + + /* next byte of data */ + private int code = 0; + /* stuffed byte of data */ + private int code2 = 0; + /***************************************************************************/ /* WSQ Decoder routine. Takes an WSQ compressed memory buffer and decodes */ /* it, returning the reconstructed pixmap. */ /***************************************************************************/ + @SuppressWarnings({ "java:S3776" }) public WsqInfo wsqDecode(byte[] iData, int iLen) { - code = 0; - code2 = 0; - + code = 0; + code2 = 0; + WsqErrorCode errorCode; - int ret, i; + int ret; + int i; int[] marker = new int[1]; /* WSQ marker */ int numOfPixels; /* image size and counter */ - int width, height; /* image parameters */ + int width;/* image parameters */ + int height; /* image parameters */ int[] ppi = new int[1]; /* ppi */ int[] lossy = new int[1]; /* lossy */ StringBuilder colorSpace = new StringBuilder();/* ColorSpace */ @@ -67,26 +81,24 @@ public WsqInfo wsqDecode(byte[] iData, int iLen) { WsqTableDtt dttTable = new WsqTableDtt(); WsqTableDqt dqtTable = new WsqTableDqt(); WsqHeaderForm wsqHeaderForm = new WsqHeaderForm(); - // WsqQuantization quantizationValues = new WsqQuantization(); WsqWavletTree[] wavletTree = new WsqWavletTree[WsqConstant.W_TREELEN]; WsqQuantizationTree[] quantizationTree = new WsqQuantizationTree[WsqConstant.Q_TREELEN]; - WsqUtil.initWsqDecoderResources(dttTable); + WsqUtil.getInstance().initWsqDecoderResources(dttTable); /* Set memory buffer pointers. */ ByteBufferContext currentBuffer = new ByteBufferContext(); ByteStreamUtil.getInstance().init(currentBuffer, iData, iData.length); - /* Read the SOI marker. */ if ((ret = WsqTableIOHelper.getInstance().getWsqMarker(marker, WsqConstant.SOI_WSQ, currentBuffer)) != 0) { - errorCode = WsqErrorCode.fromErrorCode(ret+""); + errorCode = WsqErrorCode.fromErrorCode(ret + ""); throw new DecoderException(errorCode.getErrorCode(), errorCode.getErrorMessage()); } /* Read in supporting tables up to the SOF marker. */ if ((ret = WsqTableIOHelper.getInstance().getWsqMarker(marker, WsqConstant.TBLS_N_SOF, currentBuffer)) != 0) { - errorCode = WsqErrorCode.fromErrorCode(ret+""); + errorCode = WsqErrorCode.fromErrorCode(ret + ""); throw new DecoderException(errorCode.getErrorCode(), errorCode.getErrorMessage()); } @@ -97,22 +109,24 @@ public WsqInfo wsqDecode(byte[] iData, int iLen) { } while (marker[0] != WsqConstant.SOF_WSQ) { - if ((ret = WsqTableIOHelper.getInstance().getWsqTable(marker, dttTable, dqtTable, dhtTable, currentBuffer)) != 0) { - WsqUtil.freeWsqDecoderResources(dttTable); - errorCode = WsqErrorCode.fromErrorCode(ret+""); + if ((ret = WsqTableIOHelper.getInstance().getWsqTable(marker, dttTable, dqtTable, dhtTable, + currentBuffer)) != 0) { + WsqUtil.getInstance().freeWsqDecoderResources(dttTable); + errorCode = WsqErrorCode.fromErrorCode(ret + ""); throw new DecoderException(errorCode.getErrorCode(), errorCode.getErrorMessage()); } - if ((ret = WsqTableIOHelper.getInstance().getWsqMarker(marker, WsqConstant.TBLS_N_SOF, currentBuffer)) != 0) { - WsqUtil.freeWsqDecoderResources(dttTable); - errorCode = WsqErrorCode.fromErrorCode(ret+""); + if ((ret = WsqTableIOHelper.getInstance().getWsqMarker(marker, WsqConstant.TBLS_N_SOF, + currentBuffer)) != 0) { + WsqUtil.getInstance().freeWsqDecoderResources(dttTable); + errorCode = WsqErrorCode.fromErrorCode(ret + ""); throw new DecoderException(errorCode.getErrorCode(), errorCode.getErrorMessage()); } } /* Read in the Frame Header. */ if ((ret = WsqTableIOHelper.getInstance().getWsqHeaderForm(wsqHeaderForm, currentBuffer)) != 0) { - WsqUtil.freeWsqDecoderResources(dttTable); - errorCode = WsqErrorCode.fromErrorCode(ret+""); + WsqUtil.getInstance().freeWsqDecoderResources(dttTable); + errorCode = WsqErrorCode.fromErrorCode(ret + ""); throw new DecoderException(errorCode.getErrorCode(), errorCode.getErrorMessage()); } @@ -120,45 +134,40 @@ public WsqInfo wsqDecode(byte[] iData, int iLen) { height = wsqHeaderForm.getHeight(); numOfPixels = width * height; - WsqFet nistcom = new WsqFet(); - nistcom = WsqFetHelper.getInstance().allocFet(WsqConstant.MAXFETS); + WsqFet nistcom = WsqFetHelper.getInstance().allocFet(WsqConstant.MAXFETS); if ((ret = WsqFetInfoHelper.getInstance().getNistComments(nistcom, iData, iLen)) != 0) { - WsqUtil.freeWsqDecoderResources(dttTable); - errorCode = WsqErrorCode.fromErrorCode(ret+""); + WsqUtil.getInstance().freeWsqDecoderResources(dttTable); + errorCode = WsqErrorCode.fromErrorCode(ret + ""); throw new DecoderException(errorCode.getErrorCode(), errorCode.getErrorMessage()); } if ((ret = WsqFetInfoHelper.getInstance().getWsqPPI(nistcom, ppi)) != 0) { - WsqUtil.freeWsqDecoderResources(dttTable); - errorCode = WsqErrorCode.fromErrorCode(ret+""); + WsqUtil.getInstance().freeWsqDecoderResources(dttTable); + errorCode = WsqErrorCode.fromErrorCode(ret + ""); throw new DecoderException(errorCode.getErrorCode(), errorCode.getErrorMessage()); } if ((ret = WsqFetInfoHelper.getInstance().getWsqLossyFlag(nistcom, lossy)) != 0) { - WsqUtil.freeWsqDecoderResources(dttTable); - errorCode = WsqErrorCode.fromErrorCode(ret+""); + WsqUtil.getInstance().freeWsqDecoderResources(dttTable); + errorCode = WsqErrorCode.fromErrorCode(ret + ""); throw new DecoderException(errorCode.getErrorCode(), errorCode.getErrorMessage()); } if ((ret = WsqFetInfoHelper.getInstance().getWsqBitRate(nistcom, bitRate)) != 0) { - WsqUtil.freeWsqDecoderResources(dttTable); - errorCode = WsqErrorCode.fromErrorCode(ret+""); + WsqUtil.getInstance().freeWsqDecoderResources(dttTable); + errorCode = WsqErrorCode.fromErrorCode(ret + ""); throw new DecoderException(errorCode.getErrorCode(), errorCode.getErrorMessage()); } if ((ret = WsqFetInfoHelper.getInstance().getWsqColorSpace(nistcom, colorSpace)) != 0) { - WsqUtil.freeWsqDecoderResources(dttTable); - errorCode = WsqErrorCode.fromErrorCode(ret+""); + WsqUtil.getInstance().freeWsqDecoderResources(dttTable); + errorCode = WsqErrorCode.fromErrorCode(ret + ""); throw new DecoderException(errorCode.getErrorCode(), errorCode.getErrorMessage()); } - //LOGGER.debug(String.format("SOI, tables, and frame header read")); - /* Build WSQ decomposition trees. */ - WsqTreeHelper.getInstance().buildWsqTrees(wavletTree, WsqConstant.W_TREELEN, quantizationTree, WsqConstant.Q_TREELEN, width, - height); - - //LOGGER.debug(String.format("Tables for wavelet decomposition finished")); + WsqTreeHelper.getInstance().buildWsqTrees(wavletTree, WsqConstant.W_TREELEN, quantizationTree, + WsqConstant.Q_TREELEN, width, height); /* Allocate working memory. */ qData = new long[numOfPixels]; @@ -166,59 +175,48 @@ public WsqInfo wsqDecode(byte[] iData, int iLen) { /* Decode the Huffman encoded data blocks. */ if ((ret = decodeHuffmanData(qData, qdataIndex, dttTable, dqtTable, dhtTable, currentBuffer, wsqHeaderForm, quantizationTree)) != 0) { - qData = null; - WsqUtil.freeWsqDecoderResources(dttTable); - errorCode = WsqErrorCode.fromErrorCode(ret+""); + WsqUtil.getInstance().freeWsqDecoderResources(dttTable); + errorCode = WsqErrorCode.fromErrorCode(ret + ""); throw new DecoderException(errorCode.getErrorCode(), errorCode.getErrorMessage()); } - //LOGGER.debug(String.format("Quantized WSQ subband data blocks read and Huffman decoded")); - fdata = new float[width * height]; if (dqtTable.getDqtDef() != 1) { - LOGGER.error(String.format("unquantize : quantization table parameters not defined")); - errorCode = WsqErrorCode.fromErrorCode(WsqErrorCode.QUANTIZATION_TABLE_PARAMS_NOT_DEFINED.getErrorId()+""); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + "unquantize : quantization table parameters not defined"); + errorCode = WsqErrorCode + .fromErrorCode(WsqErrorCode.QUANTIZATION_TABLE_PARAMS_NOT_DEFINED.getErrorId() + ""); throw new DecoderException(errorCode.getErrorCode(), errorCode.getErrorMessage()); } /* Decode the quantize wavelet subband data. */ - if ((ret = WsqUtil.unquantize(fdata, dqtTable, quantizationTree, WsqConstant.Q_TREELEN, qData, width, - height)) != 0) { - qData = null; - WsqUtil.freeWsqDecoderResources(dttTable); - errorCode = WsqErrorCode.fromErrorCode(ret+""); + if ((ret = WsqUtil.getInstance().unquantize(fdata, dqtTable, quantizationTree, WsqConstant.Q_TREELEN, qData, + width, height)) != 0) { + WsqUtil.getInstance().freeWsqDecoderResources(dttTable); + errorCode = WsqErrorCode.fromErrorCode(ret + ""); throw new DecoderException(errorCode.getErrorCode(), errorCode.getErrorMessage()); } - //LOGGER.debug(String.format("WSQ subband data blocks unquantized")); - /* Done with quantized wavelet subband data. */ - qData = null; - - if ((ret = WsqUtil.wsqReconstruct(fdata, width, height, wavletTree, WsqConstant.W_TREELEN, dttTable)) != 0) { - qData = null; - WsqUtil.freeWsqDecoderResources(dttTable); - errorCode = WsqErrorCode.fromErrorCode(ret+""); + if ((ret = WsqUtil.getInstance().wsqReconstruct(fdata, width, height, wavletTree, WsqConstant.W_TREELEN, + dttTable)) != 0) { + WsqUtil.getInstance().freeWsqDecoderResources(dttTable); + errorCode = WsqErrorCode.fromErrorCode(ret + ""); throw new DecoderException(errorCode.getErrorCode(), errorCode.getErrorMessage()); } - //LOGGER.debug(String.format("Tables for wavelet decomposition finished")); - cData = new byte[numOfPixels]; /* Convert floating point pixels to unsigned char pixels. */ - WsqUtil.convertImage2Bytes(cData, fdata, width, height, wsqHeaderForm.getMShift()[0], + WsqUtil.getInstance().convertImage2Bytes(cData, fdata, width, height, wsqHeaderForm.getMShift()[0], wsqHeaderForm.getRScale()[0]); /* Done with floating point pixels. */ - qData = null; - - WsqUtil.freeWsqDecoderResources(dttTable); - //LOGGER.debug(String.format("Doubleing point pixels converted to unsigned char")); + WsqUtil.getInstance().freeWsqDecoderResources(dttTable); /* Assign reconstructed pixmap and attributes to output pointers. */ - WsqInfo info = new WsqInfo (); + WsqInfo info = new WsqInfo(); info.setData(cData); info.setWidth(width); info.setHeight(height); @@ -235,6 +233,7 @@ public WsqInfo wsqDecode(byte[] iData, int iLen) { /***************************************************************************/ /* Routine to decode an entire "block" of encoded data from memory buffer. */ /***************************************************************************/ + @SuppressWarnings({ "java:S107", "java:S654", "java:S1659", "java:S1854", "java:S3776", "java:S6541" }) private int decodeHuffmanData(long[] ip, /* image pointer */ int[] qdataIndex, /* image pointer index */ WsqTableDtt dttTable, /* transform table pointer */ @@ -269,9 +268,11 @@ private int decodeHuffmanData(long[] ip, /* image pointer */ if (marker[0] != 0) { blkNo++; while (marker[0] != WsqConstant.SOB_WSQ) { - if ((ret = WsqTableIOHelper.getInstance().getWsqTable(marker, dttTable, dqtTable, dhtTable, currentBuffer)) != 0) + if ((ret = WsqTableIOHelper.getInstance().getWsqTable(marker, dttTable, dqtTable, dhtTable, + currentBuffer)) != 0) return ret; - if ((ret = WsqTableIOHelper.getInstance().getWsqMarker(marker, WsqConstant.TBLS_N_SOB, currentBuffer)) != 0) + if ((ret = WsqTableIOHelper.getInstance().getWsqMarker(marker, WsqConstant.TBLS_N_SOB, + currentBuffer)) != 0) return ret; } @@ -286,25 +287,26 @@ private int decodeHuffmanData(long[] ip, /* image pointer */ return ret; if (dhtTable[huffTableId[0]].getTableDef() != 1) { - LOGGER.debug(String.format("decodeHuffmanData : huffman table {%d} undefined.", huffTableId[0])); + logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + MessageFormat.format("decodeHuffmanData : huffman table {0} undefined.", huffTableId[0])); return (WsqErrorCode.ENCODED_DATA_WRONG.getErrorId()); } /* the next two routines reconstruct the huffman tables */ hufftable = new WsqHuffCode[WsqConstant.MAX_HUFFCOUNTS_WSQ + 1]; - if ((ret = WsqHuffHelper.getInstance().buildHuffSizes(hufftable, lastSize, dhtTable[huffTableId[0]].getHuffBits(), - WsqConstant.MAX_HUFFCOUNTS_WSQ)) != 0) + if ((ret = WsqHuffHelper.getInstance().buildHuffSizes(hufftable, lastSize, + dhtTable[huffTableId[0]].getHuffBits(), WsqConstant.MAX_HUFFCOUNTS_WSQ)) != 0) return ret; WsqHuffHelper.getInstance().buildHuffCodes(hufftable); if ((ret = WsqHuffHelper.getInstance().checkWsqHuffCodes(hufftable, lastSize[0])) != 0) - LOGGER.debug(String.format("huffTableId = %d", huffTableId)); + logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + MessageFormat.format("huffTableId = {0}", huffTableId[0])); /* this routine builds a set of three tables used in decoding */ /* the compressed data */ WsqHuffHelper.getInstance().generateDecodeTable(hufftable, maxCode, minCode, value, dhtTable[huffTableId[0]].getHuffBits()); - hufftable = null; bitCount[0] = 0; marker[0] = 0; } @@ -316,31 +318,33 @@ private int decodeHuffmanData(long[] ip, /* image pointer */ if (nodeptr[0] == -1) { while (marker[0] == WsqConstant.COM_WSQ && blkNo == 3) { - if ((ret = WsqTableIOHelper.getInstance().getWsqTable(marker, dttTable, dqtTable, dhtTable, currentBuffer)) != 0) + if ((ret = WsqTableIOHelper.getInstance().getWsqTable(marker, dttTable, dqtTable, dhtTable, + currentBuffer)) != 0) return ret; - if ((ret = WsqTableIOHelper.getInstance().getWsqMarker(marker, WsqConstant.ANY_WSQ, currentBuffer)) != 0) + if ((ret = WsqTableIOHelper.getInstance().getWsqMarker(marker, WsqConstant.ANY_WSQ, + currentBuffer)) != 0) return ret; } continue; } if (ipc > ipcMx) { - LOGGER.debug(String.format( - "decodeHuffmanData [1]: Decoded data extends past image buffer. Encoded data appears corrupt or non-standard.")); + logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + "decodeHuffmanData [1]: Decoded data extends past image buffer. Encoded data appears corrupt or non-standard."); return (WsqErrorCode.ENCODED_DATA_WRONG.getErrorId()); } if (nodeptr[0] > 0 && nodeptr[0] <= 100) { ipc += nodeptr[0]; if (ipc > ipcMx) { - LOGGER.debug(String.format( - "decodeHuffmanData [2]: Decoded data extends past image buffer. Encoded data appears corrupt or non-standard.")); + logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + "decodeHuffmanData [2]: Decoded data extends past image buffer. Encoded data appears corrupt or non-standard."); return (WsqErrorCode.ENCODED_DATA_WRONG.getErrorId()); } for (n = 0; n < nodeptr[0]; n++) ip[qdataIndex[0]++] = 0; /* z run */ } else if (nodeptr[0] > 106 && nodeptr[0] < 0xff) { - ip[qdataIndex[0]++] = nodeptr[0] - 180; + ip[qdataIndex[0]++] = (long) nodeptr[0] - 180; ipc++; } else if (nodeptr[0] == 101) { if ((ret = getWsqNextBits(tBits, marker, currentBuffer, bitCount, 8)) != 0) @@ -367,8 +371,8 @@ private int decodeHuffmanData(long[] ip, /* image pointer */ return ret; ipc += tBits[0]; if (ipc > ipcMx) { - LOGGER.debug(String.format( - "decodeHuffmanData [3]: Decoded data extends past image buffer. Encoded data appears corrupt or non-standard.")); + logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + "decodeHuffmanData [3]: Decoded data extends past image buffer. Encoded data appears corrupt or non-standard."); return (WsqErrorCode.ENCODED_DATA_WRONG.getErrorId()); } n = (int) tBits[0]; @@ -379,15 +383,16 @@ private int decodeHuffmanData(long[] ip, /* image pointer */ return ret; ipc += tBits[0]; if (ipc > ipcMx) { - LOGGER.debug(String.format( - "decodeHuffmanData [4]: Decoded data extends past image buffer. Encoded data appears corrupt or non-standard.")); + logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + "decodeHuffmanData [4]: Decoded data extends past image buffer. Encoded data appears corrupt or non-standard."); return (WsqErrorCode.ENCODED_DATA_WRONG.getErrorId()); } n = (int) tBits[0]; while (n-- != 0) ip[qdataIndex[0]++] = 0; } else { - LOGGER.debug(String.format("decodeHuffmanData : Invalid code %d (%x}", nodeptr[0], nodeptr[0])); + logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + MessageFormat.format("decodeHuffmanData : Invalid code {0} ", nodeptr[0])); return (WsqErrorCode.INVALID_CODE_INHUFFMAN_DATA.getErrorId()); } } @@ -398,6 +403,7 @@ private int decodeHuffmanData(long[] ip, /* image pointer */ /**********************************************************/ /* Routine to decode the encoded data from memory buffer. */ /**********************************************************/ + @SuppressWarnings({ "java:S107", "java:S654", "java:S1659", "java:S1854", "java:S3776", "java:S6541" }) private int decodeData(int[] huffmanNode, /* returned huffman code category */ long[] minCode, /* points to minimum code value for */ /* a given code length */ @@ -411,11 +417,13 @@ private int decodeData(int[] huffmanNode, /* returned huffman code category */ int[] bitCount, /* marks the bit to receive from the input byte */ int[] marker) { int ret = 0; - int inx, inx2; /* increment variables */ - long[] code = new long[1], tBits = new long[1]; /* - * becomes a huffman code word (one bit at a time) - */ - if ((ret = getWsqNextBits(code, marker, currentBuffer, bitCount, 1)) != 0) + /* increment variables */ + int inx, inx2; + /* + * becomes a huffman code word (one bit at a time) + */ + long[] huffmanCode = new long[1], tBits = new long[1]; + if ((ret = getWsqNextBits(huffmanCode, marker, currentBuffer, bitCount, 1)) != 0) return ret; if (marker[0] != 0) { @@ -423,18 +431,18 @@ private int decodeData(int[] huffmanNode, /* returned huffman code category */ return ret; } - for (inx = 1; code[0] > maxCode[inx]; inx++) { + for (inx = 1; huffmanCode[0] > maxCode[inx]; inx++) { if ((ret = getWsqNextBits(tBits, marker, currentBuffer, bitCount, 1)) != 0) return ret; - code[0] = (code[0] << 1) + tBits[0]; + huffmanCode[0] = (huffmanCode[0] << 1) + tBits[0]; if (marker[0] != 0) { huffmanNode[0] = -1; return (0); } } inx2 = value[inx]; - inx2 = (int) (inx2 + (code[0] - minCode[inx])); + inx2 = (int) (inx2 + (huffmanCode[0] - minCode[inx])); huffmanNode[0] = huffvalues[inx2]; return ret; @@ -443,9 +451,8 @@ private int decodeData(int[] huffmanNode, /* returned huffman code category */ /****************************************************************/ /* Routine to get nextbit(s) of data stream from memory buffer. */ /****************************************************************/ - private static int code = 0; /* next byte of data */ - private static int code2 = 0; /* stuffed byte of data */ + @SuppressWarnings({ "java:S2696" }) private int getWsqNextBits(long[] bits, /* returned bits */ int[] marker, /* returned marker */ ByteBufferContext currentBuffer, /* points to current byte in input buffer */ @@ -459,7 +466,7 @@ private int getWsqNextBits(long[] bits, /* returned bits */ /* * used to "mask out" n number of bits from data stream */ - int[] bit_mask = { 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff }; + int[] bitMask = { 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff }; if (bitCount[0] == 0) { code = (int) ByteStreamUtil.getInstance().getUByte(currentBuffer); bitCount[0] = 8; @@ -471,15 +478,15 @@ private int getWsqNextBits(long[] bits, /* returned bits */ return (0); } if (code2 != 0x00) { - LOGGER.debug(String.format("getWsqNextBits : No stuffed zeros")); + logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "getWsqNextBits : No stuffed zeros"); return (WsqErrorCode.NO_STUFFED_ZEROS.getErrorId()); } } } if (bitsRequested <= bitCount[0]) { - bits[0] = (code >> (bitCount[0] - bitsRequested)) & (bit_mask[bitsRequested]); + bits[0] = (code >> (bitCount[0] - bitsRequested)) & (bitMask[bitsRequested]); bitCount[0] -= bitsRequested; - code &= bit_mask[bitCount[0]]; + code &= bitMask[bitCount[0]]; } else { bitsNeeded = bitsRequested - bitCount[0]; bits[0] = code << bitsNeeded; @@ -492,4 +499,4 @@ private int getWsqNextBits(long[] bits, /* returned bits */ return (0); } -} +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqFetHelper.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqFetHelper.java index 891dc4b..3bd2861 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqFetHelper.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqFetHelper.java @@ -1,7 +1,13 @@ package io.mosip.imagedecoder.wsq; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_EMPTY; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_IDTYPE; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_SESSIONID; + +import java.text.MessageFormat; + +import io.mosip.kernel.core.logger.spi.Logger; +import io.mosip.imagedecoder.logger.ImageDecoderLogger; import io.mosip.imagedecoder.constant.wsq.WsqConstant; import io.mosip.imagedecoder.constant.wsq.WsqErrorCode; @@ -9,30 +15,34 @@ import io.mosip.imagedecoder.util.StringUtil; public class WsqFetHelper { - private Logger LOGGER = LoggerFactory.getLogger(WsqFetHelper.class); + private Logger logger = ImageDecoderLogger.getLogger(WsqFetHelper.class); // Static variable reference of singleInstance of type Singleton - private static WsqFetHelper singleInstance = null; - private WsqFetHelper() - { - super (); - } - - //synchronized method to control simultaneous access - public static synchronized WsqFetHelper getInstance() - { + private static WsqFetHelper singleInstance = null; + + private WsqFetHelper() { + super(); + } + + // synchronized method to control simultaneous access + public static synchronized WsqFetHelper getInstance() { if (singleInstance == null) singleInstance = new WsqFetHelper(); - - return singleInstance; + + return singleInstance; } - + /*****************************************************************/ + @SuppressWarnings({ "java:S135", "java:S1854", "java:S3626", "java:S3776" }) public int string2fet(WsqFet fet, char[] arrData) { int ret; - char[] name = new char[WsqConstant.MAXFETLENGTH], value = new char[WsqConstant.MAXFETLENGTH], vptr; + char[] name = new char[WsqConstant.MAXFETLENGTH]; + char[] value = new char[WsqConstant.MAXFETLENGTH]; + char[] vptr; - int dataIndex = 0, valueIndex = 0, nameIndex = 0; + int dataIndex = 0; + int valueIndex = 0; + int nameIndex = 0; while (arrData[dataIndex] != '\0') { /* Get next name */ nameIndex = 0; @@ -59,7 +69,7 @@ public int string2fet(WsqFet fet, char[] arrData) { /* Test (name,value) pair */ if (new String(name).length() == 0) { - LOGGER.error(String.format("string2fet : empty name string found.")); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "string2fet : empty name string found."); return (WsqErrorCode.EMPTY_STRING_FOUND.getErrorId()); } if (new String(value).length() == 0) @@ -69,7 +79,6 @@ public int string2fet(WsqFet fet, char[] arrData) { /* Store name and value pair into FET. */ if ((ret = updateFet(name, vptr, fet)) != 0) { - fet = null; return ret; } } @@ -89,15 +98,17 @@ public WsqFet allocFet(int numfeatures) { } /***********************************************************************/ + @SuppressWarnings({ "java:S135", "java:S3626", "java:S3776", "java:S6035" }) public int updateFet(char[] feature, char[] value, WsqFet fet) { - int ret, item; - int increased, incr; + int ret; + int item; + int increased; + int incr; for (item = 0; (item < fet.getNum()); item++) { - if (fet.getNames()[item] != null && feature != null) { - if (StringUtil.stringCompare(fet.getNames()[item], new String(feature)) != 0) { - continue; - } + if (fet.getNames()[item] != null && feature != null + && StringUtil.getInstance().stringCompare(fet.getNames()[item], new String(feature)) != 0) { + continue; } else { break; } @@ -128,6 +139,7 @@ public int updateFet(char[] feature, char[] value, WsqFet fet) { } /********************************************************************/ + @SuppressWarnings({ "java:S1854", "java:S3516" }) public int reallocFet(WsqFet fet, int newlen) { /* If fet not allocated ... */ if ((fet == null || fet.getAlloc() == 0)) { @@ -146,12 +158,14 @@ public int reallocFet(WsqFet fet, int newlen) { } /*******************************************************************/ + @SuppressWarnings({ "java:S135", "java:S2629", "java:S3626" }) public int extractFet(StringBuilder value, char[] feature, WsqFet fet) { int item; for (item = 0; (item < fet.getNum()); item++) { if (fet.getNames()[item] != null && feature != null) { - if (StringUtil.stringCompare(fet.getNames()[item].trim(), new String(feature).trim()) != 0) { + if (StringUtil.getInstance().stringCompare(fet.getNames()[item].trim(), + new String(feature).trim()) != 0) { continue; } else break; @@ -159,13 +173,14 @@ public int extractFet(StringBuilder value, char[] feature, WsqFet fet) { } if (item >= fet.getNum()) { if (feature != null) - LOGGER.error(String.format("extractFet : feature %s not found", new String(feature))); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("extractFet : feature {0} not found", + new String(feature))); return (WsqErrorCode.EMPTY_STRING_FOUND.getErrorId()); } if (fet.getValues()[item] != null) { value.append(fet.getValues()[item] + ""); } else - value = null; + value.append(""); return 0; } diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqFetInfoHelper.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqFetInfoHelper.java index bc09ea7..23894a0 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqFetInfoHelper.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqFetInfoHelper.java @@ -1,8 +1,5 @@ package io.mosip.imagedecoder.wsq; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import io.mosip.imagedecoder.constant.wsq.WsqConstant; import io.mosip.imagedecoder.model.ByteBufferContext; import io.mosip.imagedecoder.model.wsq.WsqFet; @@ -11,23 +8,21 @@ import io.mosip.imagedecoder.util.StringUtil; public class WsqFetInfoHelper { - private Logger LOGGER = LoggerFactory.getLogger(WsqFetInfoHelper.class); // Static variable reference of singleInstance of type Singleton - private static WsqFetInfoHelper singleInstance = null; - private WsqFetInfoHelper() - { - super (); - } - - //synchronized method to control simultaneous access - public static synchronized WsqFetInfoHelper getInstance() - { + private static WsqFetInfoHelper singleInstance = null; + + private WsqFetInfoHelper() { + super(); + } + + // synchronized method to control simultaneous access + public static synchronized WsqFetInfoHelper getInstance() { if (singleInstance == null) singleInstance = new WsqFetInfoHelper(); - - return singleInstance; + + return singleInstance; } - + /************************************************************************/ public int getNistComments(WsqFet nistcom, byte[] idata, int ilen) { int ret; @@ -46,12 +41,10 @@ public int getWsqPPI(WsqFet nistcom, int[] ppi) { if (nistcom != null) { if ((ret = WsqFetHelper.getInstance().extractFet(value, WsqConstant.NCM_PPI.toCharArray(), nistcom)) != 0) { - nistcom = null; return ret; } - if (value != null && value.toString().length() != 0) { - ppi[0] = StringUtil.atoi(value.toString().toCharArray()); - value = null; + if (value.toString().length() != 0) { + ppi[0] = StringUtil.getInstance().atoi(value.toString().toCharArray()); } /* Otherwise, PPI not in NISTCOM, so ppi = -1. */ else @@ -70,13 +63,12 @@ public int getWsqLossyFlag(WsqFet nistcom, int[] lossy) { StringBuilder value = new StringBuilder(); if (nistcom != null) { - if ((ret = WsqFetHelper.getInstance().extractFet(value, WsqConstant.NCM_LOSSY.toCharArray(), nistcom)) != 0) { - nistcom = null; + if ((ret = WsqFetHelper.getInstance().extractFet(value, WsqConstant.NCM_LOSSY.toCharArray(), + nistcom)) != 0) { return ret; } - if (value != null && value.toString().length() != 0) { - lossy[0] = StringUtil.atoi(value.toString().toCharArray()); - value = null; + if (value.toString().length() != 0) { + lossy[0] = StringUtil.getInstance().atoi(value.toString().toCharArray()); } /* Otherwise, lossy not in NISTCOM, so lossy = 1. */ else @@ -95,13 +87,12 @@ public int getWsqBitRate(WsqFet nistcom, double[] bitRate) { StringBuilder value = new StringBuilder(); if (nistcom != null) { - if ((ret = WsqFetHelper.getInstance().extractFet(value, WsqConstant.NCM_WSQ_RATE.toCharArray(), nistcom)) != 0) { - nistcom = null; + if ((ret = WsqFetHelper.getInstance().extractFet(value, WsqConstant.NCM_WSQ_RATE.toCharArray(), + nistcom)) != 0) { return ret; } - if (value != null && value.toString().length() != 0) { - bitRate[0] = StringUtil.atof(value.toString()); - value = null; + if (value.toString().length() != 0) { + bitRate[0] = StringUtil.getInstance().atof(value.toString()); } /* Otherwise, BitRate not in NISTCOM, so BitRate = 0.0. */ else @@ -120,13 +111,12 @@ public int getWsqColorSpace(WsqFet nistcom, StringBuilder colorSpace) { StringBuilder value = new StringBuilder(); if (nistcom != null) { - if ((ret = WsqFetHelper.getInstance().extractFet(value, WsqConstant.NCM_COLORSPACE.toCharArray(), nistcom)) != 0) { - nistcom = null; + if ((ret = WsqFetHelper.getInstance().extractFet(value, WsqConstant.NCM_COLORSPACE.toCharArray(), + nistcom)) != 0) { return ret; } - if (value != null && value.toString().length() != 0) { + if (value.toString().length() != 0) { colorSpace.append(value.toString()); - value = null; } /* Otherwise, colorSpace not in NISTCOM, so colorSpace = empty */ else @@ -142,14 +132,13 @@ public int getWsqColorSpace(WsqFet nistcom, StringBuilder colorSpace) { /******************************************************************/ /* Routine to read in frame header parameters from memory buffer. */ /******************************************************************/ + @SuppressWarnings({ "java:S1659", "unused" }) public int getWsqFrameHeader(WsqHeaderForm headerForm, /* frame header structure */ ByteBufferContext cbufptr /* current byte in input buffer */ - ) { + ) { int hdrSize, shortData; /* header size and data pointer */ int scale; /* exponent scaling parameter */ - //LOGGER.debug(String.format("Reading frame header.")); - hdrSize = (int) ByteStreamUtil.getInstance().getUShort(cbufptr); headerForm.setBlack((byte) ByteStreamUtil.getInstance().getUByte(cbufptr)); headerForm.setWhite((byte) ByteStreamUtil.getInstance().getUByte(cbufptr)); @@ -159,32 +148,24 @@ public int getWsqFrameHeader(WsqHeaderForm headerForm, /* frame header structure scale = (int) ByteStreamUtil.getInstance().getUByte(cbufptr); shortData = (int) ByteStreamUtil.getInstance().getUShort(cbufptr); - headerForm.getMShift()[0] = (float) shortData; + headerForm.getMShift()[0] = shortData; while (scale > 0) { - headerForm.getMShift()[0] = (float) (headerForm.getMShift()[0] / 10.0f); + headerForm.getMShift()[0] = (headerForm.getMShift()[0] / 10.0f); scale--; } scale = (int) ByteStreamUtil.getInstance().getUByte(cbufptr); shortData = (int) ByteStreamUtil.getInstance().getUShort(cbufptr); - headerForm.getRScale()[0] = (float) shortData; + headerForm.getRScale()[0] = shortData; while (scale > 0) { - headerForm.getRScale()[0] = (float) (headerForm.getRScale()[0] / 10.0f); + headerForm.getRScale()[0] = (headerForm.getRScale()[0] / 10.0f); scale--; } headerForm.setWsqEncoder((int) ByteStreamUtil.getInstance().getUByte(cbufptr)); headerForm.setSoftware(ByteStreamUtil.getInstance().getUShort(cbufptr)); - /* - LOGGER.debug(String.format( - "black = %d :: white = %u :: w = %d :: h = %d :: m_shift = %f :: r_scale = %f :: WSQ_encoder = %d :: Software = %d", - headerForm.getBlack(), headerForm.getWhite(), headerForm.getWidth(), headerForm.getHeight(), - headerForm.getMShift()[0], headerForm.getRScale()[0], headerForm.getWsqEncoder(), - headerForm.getSoftware())); - LOGGER.debug(String.format("Finished reading frame header.")); - */ return 0; } } diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqHuffHelper.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqHuffHelper.java index 406a3dd..d46948d 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqHuffHelper.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqHuffHelper.java @@ -1,32 +1,36 @@ package io.mosip.imagedecoder.wsq; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_EMPTY; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_IDTYPE; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_SESSIONID; import io.mosip.imagedecoder.constant.wsq.WsqConstant; import io.mosip.imagedecoder.constant.wsq.WsqErrorCode; +import io.mosip.imagedecoder.logger.ImageDecoderLogger; import io.mosip.imagedecoder.model.wsq.WsqHuffCode; +import io.mosip.kernel.core.logger.spi.Logger; public class WsqHuffHelper { - private Logger LOGGER = LoggerFactory.getLogger(WsqHuffHelper.class); + private Logger logger = ImageDecoderLogger.getLogger(WsqHuffHelper.class); // Static variable reference of singleInstance of type Singleton - private static WsqHuffHelper singleInstance = null; - private WsqHuffHelper() - { - super (); - } - - //synchronized method to control simultaneous access - public static synchronized WsqHuffHelper getInstance() - { + private static WsqHuffHelper singleInstance = null; + + private WsqHuffHelper() { + super(); + } + + // synchronized method to control simultaneous access + public static synchronized WsqHuffHelper getInstance() { if (singleInstance == null) singleInstance = new WsqHuffHelper(); - - return singleInstance; + + return singleInstance; } + /**************************************************************************/ /* This routine defines the huffman code sizes for each difference category */ /**************************************************************************/ + @SuppressWarnings({ "java:S1172" }) public int buildHuffSizes(WsqHuffCode[] huffcodeTable, int[] tempSize, int[] huffBits, int maxHuffCounts) { int codeSize; /* code sizes */ int numberOfCodes = 1; /* the number codes for a given code size */ @@ -46,13 +50,6 @@ public int buildHuffSizes(WsqHuffCode[] huffcodeTable, int[] tempSize, int[] huf } huffcodeTable[tempSize[0]].setSize(0); - /* - int ii; - - LOGGER.debug(String.format("In buildHuffSizes:")); - for (ii = 0; ii < maxHuffCounts + 1; ii++) - LOGGER.debug(String.format("huffcode size[%d] = %d", ii, huffcodeTable[ii].getSize())); - */ return 0; } @@ -83,12 +80,12 @@ public void buildHuffCodes(WsqHuffCode[] huffcodeTable) { tempSize++; } while (huffcodeTable[hcTableIndex].getSize() != tempSize); } while (huffcodeTable[hcTableIndex].getSize() == tempSize); - return; } /*********************************************/ /* checkWsqHuffCodes - Checks for an all 1's code in the code table. */ /*********************************************/ + @SuppressWarnings({ "java:S1659", "java:S2589" }) public int checkWsqHuffCodes(WsqHuffCode[] hufftable, int lastSize) { int i, k; int allOnes; @@ -98,8 +95,8 @@ public int checkWsqHuffCodes(WsqHuffCode[] hufftable, int lastSize) { for (k = 0; (k < hufftable[i].getSize() && allOnes != 0); k++) allOnes = (allOnes != 0 && (((hufftable[i].getCode() >> k) & 0x0001) != 0)) ? 1 : 0; if (allOnes != 0) { - LOGGER.warn(String.format( - "A code in the hufftable contains an : all 1's code. This image may still be decodable. It is not compliant with the WSQ specification.")); + logger.warn(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + "A code in the hufftable contains an : all 1's code. This image may still be decodable. It is not compliant with the WSQ specification."); return (WsqErrorCode.NON_COMPLIANT_WITH_WSQ_SPECS.getErrorId()); } } @@ -109,6 +106,7 @@ public int checkWsqHuffCodes(WsqHuffCode[] hufftable, int lastSize) { /*********************************************/ /* routine to generate tables needed to decode */ /*********************************************/ + @SuppressWarnings("java:S1659") public void generateDecodeTable(WsqHuffCode[] huffcodeTable, long[] maxCode, long[] minCode, int[] values, int[] huffBits) { int i, i2 = 0; /* increment variables */ @@ -131,4 +129,4 @@ public void generateDecodeTable(WsqHuffCode[] huffcodeTable, long[] maxCode, lon i2++; } } -} +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqTableIOHelper.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqTableIOHelper.java index 00531e5..b12a979 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqTableIOHelper.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqTableIOHelper.java @@ -1,12 +1,16 @@ package io.mosip.imagedecoder.wsq; -import java.nio.charset.StandardCharsets; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_EMPTY; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_IDTYPE; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_SESSIONID; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.nio.charset.StandardCharsets; +import java.text.MessageFormat; +import java.util.Arrays; import io.mosip.imagedecoder.constant.wsq.WsqConstant; import io.mosip.imagedecoder.constant.wsq.WsqErrorCode; +import io.mosip.imagedecoder.logger.ImageDecoderLogger; import io.mosip.imagedecoder.model.ByteBufferContext; import io.mosip.imagedecoder.model.wsq.WsqFet; import io.mosip.imagedecoder.model.wsq.WsqHeaderForm; @@ -16,25 +20,25 @@ import io.mosip.imagedecoder.util.ByteStreamUtil; import io.mosip.imagedecoder.util.StringUtil; import io.mosip.imagedecoder.util.wsq.WsqUtil; +import io.mosip.kernel.core.logger.spi.Logger; public class WsqTableIOHelper { - private Logger LOGGER = LoggerFactory.getLogger(WsqTableIOHelper.class); + private Logger logger = ImageDecoderLogger.getLogger(WsqTableIOHelper.class); // Static variable reference of singleInstance of type Singleton - private static WsqTableIOHelper singleInstance = null; - private WsqTableIOHelper() - { - super (); - } - - //synchronized method to control simultaneous access - public static synchronized WsqTableIOHelper getInstance() - { + private static WsqTableIOHelper singleInstance = null; + + private WsqTableIOHelper() { + super(); + } + + // synchronized method to control simultaneous access + public static synchronized WsqTableIOHelper getInstance() { if (singleInstance == null) singleInstance = new WsqTableIOHelper(); - - return singleInstance; + + return singleInstance; } - + /******************************************************/ /* Routine to read in WSQ markers from memory buffer. */ /******************************************************/ @@ -51,36 +55,37 @@ public int getWsqMarker(int[] marker, /* marker read */ switch (type) { case WsqConstant.SOI_WSQ: if (marker[0] != WsqConstant.SOI_WSQ) { - LOGGER.error(String.format("getWsqMarker : No SOI marker. {%04X}", marker[0])); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("getWsqMarker : No SOI marker. {0}", marker[0])); return (WsqErrorCode.NO_SOI_MARKER.getErrorId()); } return 0; case WsqConstant.TBLS_N_SOF: if (marker[0] != WsqConstant.DTT_WSQ && marker[0] != WsqConstant.DQT_WSQ && marker[0] != WsqConstant.DHT_WSQ && marker[0] != WsqConstant.SOF_WSQ && marker[0] != WsqConstant.COM_WSQ) { - LOGGER.error(String.format("getWsqMarker : No SOF, Table, or comment markers.")); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "getWsqMarker : No SOF, Table, or comment markers."); return (WsqErrorCode.NO_SOF_TABLE_COMMENT_MARKER.getErrorId()); } return 0; case WsqConstant.TBLS_N_SOB: if (marker[0] != WsqConstant.DTT_WSQ && marker[0] != WsqConstant.DQT_WSQ && marker[0] != WsqConstant.DHT_WSQ && marker[0] != WsqConstant.SOB_WSQ && marker[0] != WsqConstant.COM_WSQ) { - LOGGER.error(String.format("getWsqMarker : No SOB, Table, or comment markers. {%04X}", marker[0])); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format( + "getWsqMarker : No SOB, Table, or comment markers. {0}", marker[0])); return (WsqErrorCode.NO_SOB_TABLE_COMMENT_MARKER.getErrorId()); } return 0; case WsqConstant.ANY_WSQ: if ((marker[0] & 0xff00) != 0xff00) { - LOGGER.error(String.format("getWsqMarker : no marker found. {%04X}", marker[0])); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("getWsqMarker : no marker found. {0}", marker[0])); return (WsqErrorCode.NO_MARKER_FOUND.getErrorId()); } if ((marker[0] < WsqConstant.SOI_WSQ) || (marker[0] > WsqConstant.COM_WSQ)) { - LOGGER.error(String.format("getWsqMarker : {%04X} not a valid marker", marker[0])); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("getWsqMarker : {0} not a valid marker", marker[0])); return (WsqErrorCode.NOT_VALID_MARKER_FOUND.getErrorId()); } return 0; default: - LOGGER.error(String.format("getWsqMarker : Invalid marker -> {%4X}", marker[0])); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("getWsqMarker : Invalid marker -> {0}", marker[0])); return (WsqErrorCode.INVALID_MARKER_FOUND.getErrorId()); } } @@ -88,12 +93,13 @@ public int getWsqMarker(int[] marker, /* marker read */ /*******************************************************/ /* Routine to read specified table from memory buffer. */ /*******************************************************/ + @SuppressWarnings({ "java:S2583" }) public int getWsqTable(int[] marker, /* WSQ marker */ WsqTableDtt dttTable, /* transform table structure */ WsqTableDqt dqtTable, /* quantization table structure */ WsqTableDht[] dhtTable, /* huffman table structure */ ByteBufferContext cbufptr /* current byte in input buffer */ - ) { + ) { int ret; switch (marker[0]) { @@ -102,7 +108,8 @@ public int getWsqTable(int[] marker, /* WSQ marker */ return ret; return 0; case WsqConstant.DQT_WSQ: - if ((ret = getQuantizationTable(dqtTable, cbufptr)) != 0) + ret = getQuantizationTable(dqtTable, cbufptr); + if (ret != 0) return ret; return 0; case WsqConstant.DHT_WSQ: @@ -116,15 +123,12 @@ public int getWsqTable(int[] marker, /* WSQ marker */ int cs = hdrSize - 2; /* Allocate including a possible NULL terminator. */ byte[] comment = new byte[cs + 1]; - if ((ret = getComment(comment, cbufptr)) != 0) + ret = getComment(comment, cbufptr); + if (ret != 0) return ret; - - //LOGGER.debug(String.format("COMMENT: %s", new String(comment, StandardCharsets.UTF_8))); - - comment = null; return 0; default: - LOGGER.error(String.format("getWsqTable : Invalid table defined: {%u}", marker[0])); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("getWsqTable : Invalid table defined: {0}", marker[0])); return (WsqErrorCode.INVALID_TABLE_DEFINED.getErrorId()); } } @@ -132,22 +136,20 @@ public int getWsqTable(int[] marker, /* WSQ marker */ /************************************************************************/ /* Routine to read in quantization table parameters from memory buffer. */ /************************************************************************/ + @SuppressWarnings({ "java:S1659", "unused" }) private int getQuantizationTable(WsqTableDqt dqtTable, /* quatization table structure */ ByteBufferContext cbufptr /* current byte in input buffer */ - ) - { + ) { int ret; int hdrSize; /* header size */ int cnt, shortData; /* counter and temp short data */ int[] scale = new int[1]; /* scaling parameter */ - //LOGGER.debug(String.format("Reading quantization table.")); - hdrSize = (int) ByteStreamUtil.getInstance().getUShort(cbufptr); scale[0] = (int) ByteStreamUtil.getInstance().getUByte(cbufptr); shortData = (int) ByteStreamUtil.getInstance().getUShort(cbufptr); - dqtTable.setBinCenter((float) shortData); + dqtTable.setBinCenter(shortData); while (scale[0] > 0) { dqtTable.setBinCenter(dqtTable.getBinCenter() / 10.0f); scale[0]--; @@ -157,7 +159,7 @@ private int getQuantizationTable(WsqTableDqt dqtTable, /* quatization table stru scale[0] = (int) ByteStreamUtil.getInstance().getUByte(cbufptr); shortData = (int) ByteStreamUtil.getInstance().getUShort(cbufptr); - dqtTable.getQBin()[cnt] = (float) shortData; + dqtTable.getQBin()[cnt] = shortData; while (scale[0] > 0) { dqtTable.getQBin()[cnt] /= 10.0; scale[0]--; @@ -166,18 +168,14 @@ private int getQuantizationTable(WsqTableDqt dqtTable, /* quatization table stru scale[0] = (int) ByteStreamUtil.getInstance().getUByte(cbufptr); shortData = (int) ByteStreamUtil.getInstance().getUShort(cbufptr); - dqtTable.getZBin()[cnt] = (float) shortData; + dqtTable.getZBin()[cnt] = shortData; while (scale[0] > 0) { dqtTable.getZBin()[cnt] /= 10.0f; scale[0]--; } - - //LOGGER.debug(String.format("q[%d] = %f :: z[%d] = %f", cnt, dqtTable.getQBin()[cnt], cnt, dqtTable.getZBin()[cnt])); } dqtTable.setDqtDef(1); - //LOGGER.debug(String.format("Finished reading quantization table.")); - return 0; } @@ -186,8 +184,7 @@ private int getQuantizationTable(WsqTableDqt dqtTable, /* quatization table stru /*******************************************************************/ private int getWsqHuffmanTable(WsqTableDht[] dhtTable, /* huffman table structure */ ByteBufferContext cbufptr /* current byte in input buffer */ - ) - { + ) { int ret; int[] tableId = new int[1]; /* huffman table indicator */ int[] huffbits = new int[WsqConstant.MAX_HUFFBITS]; @@ -205,8 +202,6 @@ private int getWsqHuffmanTable(WsqTableDht[] dhtTable, /* huffman table structur System.arraycopy(huffbits, 0, dhtTable[tableId[0]].getHuffBits(), 0, WsqConstant.MAX_HUFFBITS); System.arraycopy(huffvalues, 0, dhtTable[tableId[0]].getHuffValues(), 0, WsqConstant.MAX_HUFFCOUNTS_WSQ + 1); dhtTable[tableId[0]].setTableDef((byte) 1); - huffbits = null; - huffvalues = null; while (bytesLeft[0] != 0) { huffbits = new int[WsqConstant.MAX_HUFFBITS]; @@ -218,9 +213,8 @@ private int getWsqHuffmanTable(WsqTableDht[] dhtTable, /* huffman table structur /* If table is already defined ... */ if (dhtTable[tableId[0]].getTableDef() != 0) { - huffbits = null; - huffvalues = null; - LOGGER.error(String.format("getWsqHuffmanTable : huffman table ID = %d already defined ", tableId[0])); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format( + "getWsqHuffmanTable : huffman table ID = {0} already defined ", tableId[0])); return (WsqErrorCode.TABLE_ID_ALREADY_DEFINED.getErrorId()); } @@ -229,8 +223,6 @@ private int getWsqHuffmanTable(WsqTableDht[] dhtTable, /* huffman table structur System.arraycopy(huffvalues, 0, dhtTable[tableId[0]].getHuffValues(), 0, WsqConstant.MAX_HUFFCOUNTS_WSQ + 1); dhtTable[tableId[0]].setTableDef(1); - huffbits = null; - huffvalues = null; } return 0; @@ -239,9 +231,10 @@ private int getWsqHuffmanTable(WsqTableDht[] dhtTable, /* huffman table structur /*********************************************************************/ /* Routine to read in transform table parameters from memory buffer. */ /*********************************************************************/ + @SuppressWarnings({ "java:S1659", "java:S6541", "java:S3776", "unused" }) private int getTransformTable(WsqTableDtt dttTable, /* transform table structure */ ByteBufferContext cbufptr /* current byte in input buffer */ - ) { + ) { int ret; int hdrSize; /* header size */ float[] aLowfilter, aHighFilter; /* unexpanded filter coefficients */ @@ -250,14 +243,10 @@ private int getTransformTable(WsqTableDtt dttTable, /* transform table structure long shortData; /* temp short data */ int scale, sign; /* scaling and sign parameters */ - //LOGGER.debug(String.format("Reading transform table.")); - hdrSize = (int) ByteStreamUtil.getInstance().getUShort(cbufptr); dttTable.setHighSize((int) ByteStreamUtil.getInstance().getUByte(cbufptr)); dttTable.setLowSize((int) ByteStreamUtil.getInstance().getUByte(cbufptr)); - //LOGGER.debug(String.format("losize = %d, hisize = %d", dttTable.getLowSize(), dttTable.getHighSize())); - /* If lofilt member previously allocated ... */ if (dttTable.getLowFilter() != null) { /* Deallocate the member prior to new allocation */ @@ -286,7 +275,7 @@ private int getTransformTable(WsqTableDtt dttTable, /* transform table structure scale = (int) ByteStreamUtil.getInstance().getUByte(cbufptr); shortData = ByteStreamUtil.getInstance().getUInt(cbufptr); - aLowfilter[cnt] = (float) shortData; + aLowfilter[cnt] = shortData; while (scale > 0) { aLowfilter[cnt] /= 10.0; scale--; @@ -294,14 +283,12 @@ private int getTransformTable(WsqTableDtt dttTable, /* transform table structure if (sign != 0) aLowfilter[cnt] *= -1.0; - //LOGGER.debug(String.format("lofilt[%d] = %.15f", cnt, aLowfilter[cnt])); - if (dttTable.getHighSize() % 2 != 0) { - dttTable.getHighFilter()[cnt + aSize] = (float) ((float) WsqUtil.intSign(cnt) * aLowfilter[cnt]); + dttTable.getHighFilter()[cnt + aSize] = (WsqUtil.getInstance().intSign(cnt) * aLowfilter[cnt]); if (cnt > 0) dttTable.getHighFilter()[aSize - cnt] = dttTable.getHighFilter()[cnt + aSize]; } else { - dttTable.getHighFilter()[cnt + aSize + 1] = (float) ((float) WsqUtil.intSign(cnt) * aLowfilter[cnt]); + dttTable.getHighFilter()[cnt + aSize + 1] = (WsqUtil.getInstance().intSign(cnt) * aLowfilter[cnt]); dttTable.getHighFilter()[aSize - cnt] = (float) (-1.0 * dttTable.getHighFilter()[cnt + aSize + 1]); } } @@ -320,7 +307,7 @@ private int getTransformTable(WsqTableDtt dttTable, /* transform table structure scale = (int) ByteStreamUtil.getInstance().getUByte(cbufptr); shortData = ByteStreamUtil.getInstance().getUInt(cbufptr); - aHighFilter[cnt] = (float) shortData; + aHighFilter[cnt] = shortData; while (scale > 0) { aHighFilter[cnt] /= 10.0; scale--; @@ -328,38 +315,31 @@ private int getTransformTable(WsqTableDtt dttTable, /* transform table structure if (sign != 0) aHighFilter[cnt] *= -1.0; - //LOGGER.debug(String.format("hifilt[%d] = %.15f", cnt, aHighFilter[cnt])); - if (dttTable.getLowSize() % 2 != 0) { - dttTable.getLowFilter()[cnt + aSize] = (float) ((float) WsqUtil.intSign(cnt) * aHighFilter[cnt]); + dttTable.getLowFilter()[cnt + aSize] = (WsqUtil.getInstance().intSign(cnt) * aHighFilter[cnt]); if (cnt > 0) dttTable.getLowFilter()[aSize - cnt] = dttTable.getLowFilter()[cnt + aSize]; } else { - dttTable.getLowFilter()[cnt + aSize + 1] = (float) ((float) WsqUtil.intSign(cnt + 1) * aHighFilter[cnt]); + dttTable.getLowFilter()[cnt + aSize + 1] = (WsqUtil.getInstance().intSign(cnt + 1) * aHighFilter[cnt]); dttTable.getLowFilter()[aSize - cnt] = dttTable.getLowFilter()[cnt + aSize + 1]; } } - aHighFilter = null; dttTable.setLowDef(1); dttTable.setHighDef(1); - - //LOGGER.debug(String.format("Finished reading transform table.")); - return 0; } /*****************************************************/ /* Reads huffman table from compressed memory buffer */ /*****************************************************/ + @SuppressWarnings({ "java:S1659", "unused" }) private int getHuffmanTable(int[] tableId, int[] huffbits, int[] huffvalues, int maxHuffCounts, ByteBufferContext cbufptr, int readTableLength, int[] bytesLeft) { int ret, i; long tableLength = -1; int numOfHuffmanValues; - //LOGGER.debug(String.format("Start reading huffman table.")); - /* tableLength */ if (readTableLength != 0) { tableLength = ByteStreamUtil.getInstance().getUShort(cbufptr); @@ -368,7 +348,7 @@ private int getHuffmanTable(int[] tableId, int[] huffbits, int[] huffvalues, int /* If no bytes left ... */ if (bytesLeft[0] <= 0) { - LOGGER.error(String.format("getHuffmanTable : no huffman table bytes remaining")); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "getHuffmanTable : no huffman table bytes remaining"); return (WsqErrorCode.NO_DATA_TO_READ.getErrorId()); } @@ -385,9 +365,9 @@ private int getHuffmanTable(int[] tableId, int[] huffbits, int[] huffvalues, int bytesLeft[0] -= WsqConstant.MAX_HUFFBITS; if (numOfHuffmanValues > maxHuffCounts + 1) { - LOGGER.error(String.format("getHuffmanTable : numOfHuffmanValues (%d) is larger than maxHuffCounts (%d)", - numOfHuffmanValues, maxHuffCounts + 1)); - huffbits = null; + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format( + "getHuffmanTable : numOfHuffmanValues {0} is larger than maxHuffCounts {1}", numOfHuffmanValues, + maxHuffCounts + 1)); return (WsqErrorCode.VALUE_GREATER_THAN_MAX_COUNT.getErrorId()); } @@ -397,17 +377,6 @@ private int getHuffmanTable(int[] tableId, int[] huffbits, int[] huffvalues, int } bytesLeft[0] -= numOfHuffmanValues; - //LOGGER.debug(String.format("getHuffmanTable : Table Len = %d", tableLength)); - //LOGGER.debug(String.format("getHuffmanTable : Table ID = %d", tableId[0])); - - /* - for (i = 0; i < WsqConstant.MAX_HUFFBITS; i++) - LOGGER.debug(String.format("bits[%d] = %d", i, huffbits[i])); - for (i = 0; i < numOfHuffmanValues; i++) - LOGGER.debug(String.format("values[%d] = %d", i, huffvalues[i])); - - LOGGER.error(String.format("Finished reading huffman table.")); - */ return 0; } @@ -415,44 +384,39 @@ private int getHuffmanTable(int[] tableId, int[] huffbits, int[] huffvalues, int /* Routine to read comment block from a memory buffer. */ /* NOTE: forces return of NULL termnated comment string. */ /************************************************************************/ + @SuppressWarnings({ "java:S1854", "java:S1858", "unused" }) private int getComment(byte[] comment, ByteBufferContext cbufptr /* current byte in input buffer */ - ) - { + ) { int ret = 0; - try - { - //LOGGER.debug(String.format("Reading Comment Field.")); - + try { /* Read only the number of bytes as specified in the header length. */ - int size = (int) ByteStreamUtil.getInstance().getBufferU(cbufptr, comment, comment.length - 1); + int size = ByteStreamUtil.getInstance().getBufferU(cbufptr, comment, comment.length - 1); /* If comment did not explicitly contain a NULL terminator, it will */ /* have one here by default due to the calloc of one extra byte at */ /* the end. */ - - //LOGGER.debug(String.format("Comment = %s", new String(comment, StandardCharsets.UTF_8))); - } - catch (Exception ex) - { - ex.printStackTrace(); - comment = " ".toString().getBytes(); + } catch (Exception ex) { + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "getComment : comment empty " + ex.getLocalizedMessage()); + Arrays.fill(comment, (byte) '\0'); } + // Add a null terminator at the end + comment[comment.length-1] = '\0'; // Null terminator (ASCII 0) return ret; } /******************************************************************/ /* Routine to read in frame header parameters from memory buffer. */ /******************************************************************/ + @SuppressWarnings({ "java:S1854", "unused" }) public int getWsqHeaderForm(WsqHeaderForm headerForm, /* frame header structure */ ByteBufferContext cbufptr /* current byte in input buffer */ - ) { + ) { int ret = 0; - int hdrSize, shortData; /* header size and data pointer */ + int hdrSize;/* header size and data pointer */ + int shortData; int scale; /* exponent scaling parameter */ - //LOGGER.debug(String.format("Reading frame header.")); - hdrSize = (int) ByteStreamUtil.getInstance().getUShort(cbufptr); headerForm.setBlack((int) ByteStreamUtil.getInstance().getUByte(cbufptr)); headerForm.setWhite((int) ByteStreamUtil.getInstance().getUByte(cbufptr)); @@ -462,38 +426,31 @@ public int getWsqHeaderForm(WsqHeaderForm headerForm, /* frame header structure scale = (int) ByteStreamUtil.getInstance().getUByte(cbufptr); shortData = (int) ByteStreamUtil.getInstance().getUShort(cbufptr); - headerForm.getMShift()[0] = (float) shortData; + headerForm.getMShift()[0] = shortData; while (scale > 0) { - headerForm.getMShift()[0] = (float) (headerForm.getMShift()[0] / 10.0f); + headerForm.getMShift()[0] = (headerForm.getMShift()[0] / 10.0f); scale--; } scale = (int) ByteStreamUtil.getInstance().getUByte(cbufptr); shortData = (int) ByteStreamUtil.getInstance().getUShort(cbufptr); - headerForm.getRScale()[0] = (float) shortData; + headerForm.getRScale()[0] = shortData; while (scale > 0) { - headerForm.getRScale()[0] = (float) (headerForm.getRScale()[0] / 10.0f); + headerForm.getRScale()[0] = (headerForm.getRScale()[0] / 10.0f); scale--; } headerForm.setWsqEncoder((int) ByteStreamUtil.getInstance().getUByte(cbufptr)); headerForm.setSoftware(ByteStreamUtil.getInstance().getUShort(cbufptr)); - - /* - LOGGER.debug(String.format( - "black = %d :: white = %d :: w = %d :: h = %d :: m_shift = %f :: r_scale = %f :: WSQ_encoder = %d :: Software = %d", - headerForm.getBlack(), headerForm.getWhite(), headerForm.getWidth(), headerForm.getHeight(), - headerForm.getMShift()[0], headerForm.getRScale()[0], headerForm.getWsqEncoder(), - headerForm.getSoftware())); - LOGGER.debug(String.format("Finished reading frame header.")); - */ + return ret; } /*****************************************************************/ /* Get and return first NISTCOM from encoded data stream. */ /*****************************************************************/ + @SuppressWarnings({ "java:S2583", "java:S3776" }) public int getWsqNistCom(WsqFet nistcom, byte[] imageData, int imagelength) { int ret; int[] marker = new int[1]; @@ -520,7 +477,7 @@ public int getWsqNistCom(WsqFet nistcom, byte[] imageData, int imagelength) { ByteStreamUtil.getInstance().skipBytesForSize(cbufptr, 2); byte[] info = new byte[WsqConstant.NCM_HEADER.length()]; ByteStreamUtil.getInstance().getBufferU(cbufptr, info, 8); - if (StringUtil.stringCompare(new String(info, StandardCharsets.UTF_8), WsqConstant.NCM_HEADER) == 0) { + if (StringUtil.getInstance().stringCompare(new String(info, StandardCharsets.UTF_8), WsqConstant.NCM_HEADER) == 0) { // header size int hdrSize = (int) ByteStreamUtil.getInstance().getUShort(cbufptr); /* cs = hdrSize - sizeof(length value) */ @@ -531,11 +488,12 @@ public int getWsqNistCom(WsqFet nistcom, byte[] imageData, int imagelength) { if ((ret = getComment(comment, cbufptr)) != 0) return ret; commentText.append(new String(comment, StandardCharsets.UTF_8)); - if ((ret = WsqFetHelper.getInstance().string2fet(nistcom, commentText.toString().toCharArray())) != 0) { - commentText = null; + if ((ret = WsqFetHelper.getInstance().string2fet(nistcom, + commentText.toString().toCharArray())) != 0) { + commentText.setLength(0); return ret; } - commentText = null; + commentText.setLength(0); return 0; } } @@ -548,7 +506,6 @@ public int getWsqNistCom(WsqFet nistcom, byte[] imageData, int imagelength) { } /* NISTCOM not found ... */ - nistcom = null; return 0; } @@ -556,6 +513,7 @@ public int getWsqNistCom(WsqFet nistcom, byte[] imageData, int imagelength) { /* Skips the segment data following a JPEGB, JPEGL, or WSQ */ /* marker in the given memory buffer. */ /*****************************************************************/ + @SuppressWarnings({ "java:S1172" }) private int getSkipMarkerSegment(int[] marker, ByteBufferContext cbufptr) { int length; @@ -572,19 +530,15 @@ private int getSkipMarkerSegment(int[] marker, ByteBufferContext cbufptr) { /******************************************************************/ /* Routine to read in block header parameters from memory buffer. */ /******************************************************************/ + @SuppressWarnings({ "java:S1854", "unused" }) public int getBlockHeader(int[] hufftableId, /* huffman table indicator */ ByteBufferContext cbufptr /* current byte in input buffer */ - ) { - int hdrSize; /* block header size */ - - //LOGGER.debug(String.format("Reading block header.")); + ) { + int hdrSize = 0; /* block header size */ hdrSize = (int) ByteStreamUtil.getInstance().getUShort(cbufptr); hufftableId[0] = (int) ByteStreamUtil.getInstance().getUByte(cbufptr); - //LOGGER.debug(String.format("huff_table = %d", hufftableId[0])); - //LOGGER.debug(String.format("Finished Reading block header.")); - return 0; } -} +} \ No newline at end of file diff --git a/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqTreeHelper.java b/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqTreeHelper.java index a8e8730..da06258 100644 --- a/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqTreeHelper.java +++ b/imagedecoder/src/main/java/io/mosip/imagedecoder/wsq/WsqTreeHelper.java @@ -1,27 +1,22 @@ package io.mosip.imagedecoder.wsq; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import io.mosip.imagedecoder.model.wsq.WsqQuantizationTree; import io.mosip.imagedecoder.model.wsq.WsqWavletTree; public class WsqTreeHelper { - private Logger LOGGER = LoggerFactory.getLogger(WsqTreeHelper.class); // Static variable reference of singleInstance of type Singleton - private static WsqTreeHelper singleInstance = null; - private WsqTreeHelper() - { - super (); - } - - //synchronized method to control simultaneous access - public static synchronized WsqTreeHelper getInstance() - { + private static WsqTreeHelper singleInstance = null; + + private WsqTreeHelper() { + super(); + } + + // synchronized method to control simultaneous access + public static synchronized WsqTreeHelper getInstance() { if (singleInstance == null) singleInstance = new WsqTreeHelper(); - - return singleInstance; + + return singleInstance; } /************************************************************************/ /* Routines used to generate the "trees" used */ @@ -32,8 +27,9 @@ public static synchronized WsqTreeHelper getInstance() /* Build WSQ decomposition trees. */ /************************************************************************/ - public void buildWsqTrees(WsqWavletTree waveletTree[], int w_treelen, WsqQuantizationTree quantizationTree[], - int q_treelen, int width, int height) { + @SuppressWarnings({ "java:S1172" }) + public void buildWsqTrees(WsqWavletTree[] waveletTree, int waveletTreeLength, + WsqQuantizationTree[] quantizationTree, int quantizationTreeLength, int width, int height) { /* Build a W-TREE structure for the image. */ buildWaveletTree(waveletTree, width, height); /* Build a Q-TREE structure for the image. */ @@ -43,7 +39,8 @@ public void buildWsqTrees(WsqWavletTree waveletTree[], int w_treelen, WsqQuantiz /********************************************************************/ /* Routine to obtain subband "x-y locations" for creating wavelets. */ /********************************************************************/ - private void buildWaveletTree(WsqWavletTree waveletTree[], /* wavelet tree structure */ + @SuppressWarnings({ "java:S1659", "java:S2589" }) + private void buildWaveletTree(WsqWavletTree[] waveletTree, /* wavelet tree structure */ int width, /* image width */ int height) /* image height */ { @@ -107,20 +104,13 @@ private void buildWaveletTree(WsqWavletTree waveletTree[], /* wavelet tree struc waveletTree[19].setLenY(waveletTree[15].getLenY() / 2); else waveletTree[19].setLenY((waveletTree[15].getLenY() + 1) / 2); - - /* - for (node = 0; node < 20; node++) - LOGGER.debug(String.format("t%d -> x = %d y = %d : dx = %d dy = %d : ir = %d ic = %d", node, - waveletTree[node].getX(), waveletTree[node].getY(), waveletTree[node].getLenX(), - waveletTree[node].getLenY(), waveletTree[node].getInvRow(), waveletTree[node].getInvCol())); - */ - return; } /***************************************************************/ /* Gives location and size of subband splits for buildWaveletTree. */ /***************************************************************/ - private void waveletTree4(WsqWavletTree waveletTree[], /* wavelet tree structure */ + @SuppressWarnings({ "java:S107", "java:S1659", "java:S2589" }) + private void waveletTree4(WsqWavletTree[] waveletTree, /* wavelet tree structure */ int start1, /* waveletTree locations to start calculating */ int start2, /* subband split locations and sizes */ int lenx, /* (temp) subband split location and sizes */ @@ -185,7 +175,7 @@ private void waveletTree4(WsqWavletTree waveletTree[], /* wavelet tree structure /****************************************************************/ private void buildQuantizationTree(WsqWavletTree[] waveletTree, /* wavelet tree structure */ - WsqQuantizationTree[] quantizationTree) /* quantization tree structure */ + WsqQuantizationTree[] quantizationTree) /* quantization tree structure */ { int node; @@ -203,17 +193,10 @@ private void buildQuantizationTree(WsqWavletTree[] waveletTree, /* wavelet tree waveletTree[5].getX(), waveletTree[5].getY(), 1, 0); quantizationTree4(quantizationTree, 0, waveletTree[19].getLenX(), waveletTree[19].getLenY(), waveletTree[19].getX(), waveletTree[19].getY()); - - /* - for (node = 0; node < 60; node++) - LOGGER.error(String.format("t%d -> x = %d y = %d : lx = %d ly = %d", node, - quantizationTree[node].getX(), quantizationTree[node].getY(), quantizationTree[node].getLenX(), - quantizationTree[node].getLenY())); - */ - return; } /*****************************************************************/ + @SuppressWarnings({ "java:S107", "java:S1659", "java:S3776" }) private void quantizationTree16(WsqQuantizationTree[] quantizationTree, /* quantization tree structure */ int start, /* quantizationTree location of first subband */ /* in the subband group being calculated */ @@ -361,6 +344,7 @@ private void quantizationTree16(WsqQuantizationTree[] quantizationTree, /* quant } /********************************************************************/ + @SuppressWarnings({ "java:S1659" }) private void quantizationTree4(WsqQuantizationTree[] quantizationTree, /* quantization tree structure */ int start, /* quantizationTree location of first subband */ /* in the subband group being calculated */ diff --git a/imagedecoder/src/test/java/io/mosip/imagedecoder/test/ConstantTest.java b/imagedecoder/src/test/java/io/mosip/imagedecoder/test/ConstantTest.java new file mode 100644 index 0000000..708a752 --- /dev/null +++ b/imagedecoder/src/test/java/io/mosip/imagedecoder/test/ConstantTest.java @@ -0,0 +1,153 @@ +package io.mosip.imagedecoder.test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +import io.mosip.imagedecoder.constant.DecoderConstant; +import io.mosip.imagedecoder.constant.DecoderErrorCodes; +import io.mosip.imagedecoder.constant.wsq.WsqConstant; +import io.mosip.imagedecoder.constant.wsq.WsqErrorCode; + +class ConstantTest { + @Test + void testDecoderConstant() { + assertEquals("DECODER", DecoderConstant.LOGGER_SESSIONID); + assertEquals("DECODER", DecoderConstant.LOGGER_IDTYPE); + } + + @Test + void testDecoderConstantPrivateConstructor() { + Exception exception = assertThrows(IllegalStateException.class, () -> { + new DecoderConstant(); // This should throw an exception + }); + assertEquals("DecoderConstant class", exception.getMessage()); + } + + @Test + void testDecoderErrorCodesGetErrorCode() { + assertEquals("TOOLKIT_SUCCESS_000", DecoderErrorCodes.SUCCESS.getErrorCode()); + assertEquals("DECODER_ERR_001", DecoderErrorCodes.INVALID_DATA_ERROR.getErrorCode()); + assertEquals("DECODER_ERR_002", DecoderErrorCodes.UNSUPPORTED_FORMAT_ERROR.getErrorCode()); + assertEquals("DECODER_ERR_003", DecoderErrorCodes.BUFFEREDIMAGE_ALLOCATION_FAILED_ERROR.getErrorCode()); + assertEquals("DECODER_REQ_ERR_500", DecoderErrorCodes.TECHNICAL_ERROR_EXCEPTION.getErrorCode()); + } + + @Test + void testDecoderErrorCodesGetErrorMessage() { + assertEquals("Success", DecoderErrorCodes.SUCCESS.getErrorMessage()); + assertEquals("Invalid Data Error.", DecoderErrorCodes.INVALID_DATA_ERROR.getErrorMessage()); + assertEquals("Unsupported format.", DecoderErrorCodes.UNSUPPORTED_FORMAT_ERROR.getErrorMessage()); + assertEquals("BufferedImage allocation failed.", + DecoderErrorCodes.BUFFEREDIMAGE_ALLOCATION_FAILED_ERROR.getErrorMessage()); + assertEquals("Technical Error", DecoderErrorCodes.TECHNICAL_ERROR_EXCEPTION.getErrorMessage()); + } + + @Test + void testDecoderErrorCodesFromErrorCode_ValidCodes() { + assertEquals(DecoderErrorCodes.SUCCESS, DecoderErrorCodes.fromErrorCode("TOOLKIT_SUCCESS_000")); + assertEquals(DecoderErrorCodes.INVALID_DATA_ERROR, DecoderErrorCodes.fromErrorCode("DECODER_ERR_001")); + assertEquals(DecoderErrorCodes.UNSUPPORTED_FORMAT_ERROR, DecoderErrorCodes.fromErrorCode("DECODER_ERR_002")); + assertEquals(DecoderErrorCodes.BUFFEREDIMAGE_ALLOCATION_FAILED_ERROR, + DecoderErrorCodes.fromErrorCode("DECODER_ERR_003")); + } + + @Test + void testDecoderErrorCodesFromErrorCode_InvalidCode() { + // Test invalid code returns TECHNICAL_ERROR_EXCEPTION + assertEquals(DecoderErrorCodes.TECHNICAL_ERROR_EXCEPTION, DecoderErrorCodes.fromErrorCode("INVALID_CODE")); + } + + @Test + void testWsqErrorCodeGetErrorId() { + assertEquals(-1, WsqErrorCode.NON_COMPLIANT_WITH_WSQ_SPECS.getErrorId()); + assertEquals(-2, WsqErrorCode.EMPTY_STRING_FOUND.getErrorId()); + assertEquals(-3, WsqErrorCode.NO_DATA_TO_READ.getErrorId()); + assertEquals(-500, WsqErrorCode.TECHNICAL_ERROR_EXCEPTION.getErrorId()); + } + + @Test + void testWsqErrorCodeGetErrorCode() { + assertEquals("MOS-EXT-1", WsqErrorCode.NON_COMPLIANT_WITH_WSQ_SPECS.getErrorCode()); + assertEquals("MOS-EXT-2", WsqErrorCode.EMPTY_STRING_FOUND.getErrorCode()); + assertEquals("MOS-EXT-3", WsqErrorCode.NO_DATA_TO_READ.getErrorCode()); + assertEquals("MOS-EXT-500", WsqErrorCode.TECHNICAL_ERROR_EXCEPTION.getErrorCode()); + } + + @Test + void testWsqErrorCodeGetErrorMessage() { + assertEquals( + "A code in the hufftable contains an : all 1's code. This image may still be decodable. It is not compliant with the WSQ specification.", + WsqErrorCode.NON_COMPLIANT_WITH_WSQ_SPECS.getErrorMessage()); + assertEquals("Empty name string found.", WsqErrorCode.EMPTY_STRING_FOUND.getErrorMessage()); + assertEquals("No huffman table bytes remaining.", WsqErrorCode.NO_DATA_TO_READ.getErrorMessage()); + assertEquals("Technical Error", WsqErrorCode.TECHNICAL_ERROR_EXCEPTION.getErrorMessage()); + } + + @Test + void testWsqErrorCodeFromErrorCode_Valid() { + assertEquals(WsqErrorCode.NON_COMPLIANT_WITH_WSQ_SPECS, WsqErrorCode.fromErrorCode("MOS-EXT-1")); + assertEquals(WsqErrorCode.EMPTY_STRING_FOUND, WsqErrorCode.fromErrorCode("MOS-EXT-2")); + } + + @Test + void testWsqErrorCodeFromErrorCode_Invalid() { + // Test invalid code returns TECHNICAL_ERROR_EXCEPTION + assertEquals(WsqErrorCode.TECHNICAL_ERROR_EXCEPTION, WsqErrorCode.fromErrorCode("INVALID_CODE")); + } + + @Test + void testWsqConstantWsqMarkers() { + assertEquals(0xffa0, WsqConstant.SOI_WSQ); + assertEquals(0xffa1, WsqConstant.EOI_WSQ); + assertEquals(0xffa2, WsqConstant.SOF_WSQ); + assertEquals(0xffa3, WsqConstant.SOB_WSQ); + assertEquals(0xffa4, WsqConstant.DTT_WSQ); + assertEquals(0xffa5, WsqConstant.DQT_WSQ); + assertEquals(0xffa6, WsqConstant.DHT_WSQ); + assertEquals(0xffa7, WsqConstant.DRT_WSQ); + assertEquals(0xffa8, WsqConstant.COM_WSQ); + assertEquals(0xffff, WsqConstant.ANY_WSQ); + } + + @Test + void testWsqConstantSubbandDefinitions() { + assertEquals(19, WsqConstant.STRT_SUBBAND_2); + assertEquals(52, WsqConstant.STRT_SUBBAND_3); + assertEquals(64, WsqConstant.MAX_SUBBANDS); + assertEquals(60, WsqConstant.NUM_SUBBANDS); + assertEquals(60, WsqConstant.STRT_SUBBAND_DEL); + assertEquals(4, WsqConstant.STRT_SIZE_REGION_2); + assertEquals(51, WsqConstant.STRT_SIZE_REGION_3); + } + + @Test + void testWsqConstantImageConstants() { + assertEquals(256, WsqConstant.MIN_IMG_DIM); + assertEquals(255, WsqConstant.WHITE); + assertEquals(0, WsqConstant.BLACK); + assertEquals(1, WsqConstant.RAW_IMAGE); + assertEquals(0, WsqConstant.IHEAD_IMAGE); + assertEquals(1.01f, WsqConstant.VARIANCE_THRESH); + } + + @Test + void testWsqConstantCompressionConstants() { + assertEquals("ncm", WsqConstant.NCM_EXT); + assertEquals("NIST_COM", WsqConstant.NCM_HEADER); + assertEquals("PIX_WIDTH", WsqConstant.NCM_PIX_WIDTH); + assertEquals("PIX_HEIGHT", WsqConstant.NCM_PIX_HEIGHT); + assertEquals("PIX_DEPTH", WsqConstant.NCM_PIX_DEPTH); + assertEquals("PPI", WsqConstant.NCM_PPI); + assertEquals("COLORSPACE", WsqConstant.NCM_COLORSPACE); + assertEquals("NUM_COMPONENTS", WsqConstant.NCM_N_CMPNTS); + assertEquals("HV_FACTORS", WsqConstant.NCM_HV_FCTRS); + } + + @Test + void testWsqConstantErrorConstants() { + assertNotEquals(0, WsqConstant.AVERROR_INVALIDDATA); + } +} \ No newline at end of file diff --git a/imagedecoder/src/test/java/io/mosip/imagedecoder/test/ExceptionTest.java b/imagedecoder/src/test/java/io/mosip/imagedecoder/test/ExceptionTest.java new file mode 100644 index 0000000..7650c1d --- /dev/null +++ b/imagedecoder/src/test/java/io/mosip/imagedecoder/test/ExceptionTest.java @@ -0,0 +1,47 @@ +package io.mosip.imagedecoder.test; + +import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +import io.mosip.imagedecoder.exceptions.DecoderException; + +class ExceptionTest { + @Test + void testConstructorWithErrorCodeAndMessage() { + String errorCode = "DECODER_ERR_001"; + String errorMessage = "Invalid Data Error."; + + DecoderException exception = new DecoderException(errorCode, errorMessage); + + assertEquals(errorCode, exception.getErrorCode()); + assertTrue(exception.getMessage().contains(errorMessage)); + assertNull(exception.getCause()); // Ensure there is no root cause + } + + @Test + void testConstructorWithErrorCodeMessageAndRootCause() { + String errorCode = "DECODER_ERR_001"; + String errorMessage = "Invalid Data Error."; + Throwable rootCause = new NullPointerException("Null pointer exception"); + + DecoderException exception = new DecoderException(errorCode, errorMessage, rootCause); + + assertEquals(errorCode, exception.getErrorCode()); + assertTrue(exception.getMessage().contains(errorMessage)); + assertEquals(rootCause, exception.getCause()); // Ensure the root cause is set + } + + @Test + void testExceptionMessage() { + String errorCode = "DECODER_ERR_001"; + String errorMessage = "Invalid Data Error."; + + DecoderException exception = new DecoderException(errorCode, errorMessage); + + String expectedMessage = "ERROR_003: A third error occurred"; + assertTrue(exception.getMessage().contains(errorMessage)); + } +} diff --git a/imagedecoder/src/test/java/io/mosip/imagedecoder/test/HelperTest.java b/imagedecoder/src/test/java/io/mosip/imagedecoder/test/HelperTest.java new file mode 100644 index 0000000..df372c2 --- /dev/null +++ b/imagedecoder/src/test/java/io/mosip/imagedecoder/test/HelperTest.java @@ -0,0 +1,479 @@ +package io.mosip.imagedecoder.test; + +import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import io.mosip.imagedecoder.constant.openjpeg.OpenJpegConstant; +import io.mosip.imagedecoder.model.openjpeg.Bio; +import io.mosip.imagedecoder.model.openjpeg.Cio; +import io.mosip.imagedecoder.model.openjpeg.CodecContextInfo; +import io.mosip.imagedecoder.model.openjpeg.JPTMessageHeader; +import io.mosip.imagedecoder.model.openjpeg.Jp2ColorSpace; +import io.mosip.imagedecoder.model.openjpeg.OpenJpegImage; +import io.mosip.imagedecoder.model.openjpeg.OpenJpegImageComponentParameters; +import io.mosip.imagedecoder.model.openjpeg.Raw; +import io.mosip.imagedecoder.openjpeg.BioHelper; +import io.mosip.imagedecoder.openjpeg.CioHelper; +import io.mosip.imagedecoder.openjpeg.ImageHelper; +import io.mosip.imagedecoder.openjpeg.JPTHelper; +import io.mosip.imagedecoder.openjpeg.MctHelper; +import io.mosip.imagedecoder.openjpeg.RawHelper; + +class HelperTest { + + private BioHelper bioHelper; + private Bio bio; + + private CioHelper cioHelper; + private CodecContextInfo codecContextInfo; + private Cio cio; + + private ImageHelper imageHelper; + + private JPTHelper jptHelper; + private MctHelper mctHelper; + private RawHelper rawHelper; + + @BeforeEach + void setUp() { + bioHelper = BioHelper.getInstance(); // Singleton instance + bio = bioHelper.bioCreate(); // Create a new Bio instance + + cioHelper = CioHelper.getInstance(); // Get singleton instance + codecContextInfo = new CodecContextInfo(); // Create a mock or a real object as needed + cio = new Cio(); // Create a new Cio instance + + imageHelper = ImageHelper.getInstance(); + jptHelper = JPTHelper.getInstance(); + + mctHelper = MctHelper.getInstance(); + rawHelper = RawHelper.getInstance(); + } + + @Test + void testBioByteOut() { + byte[] buffer = new byte[10]; + bioHelper.bioInitEncoder(bio, buffer, buffer.length); + bioHelper.bioPutBit(bio, 1); + int result = bioHelper.bioByteOut(bio); + assertEquals(0, result); + assertNotNull(bio.getBp()[0]); // Check that the buffer has been updated + } + + @Test + void testBioByteIn() { + byte[] buffer = new byte[] { 0b00000001 }; // Example input + bioHelper.bioInitDecoder(bio, buffer, buffer.length); + int result = bioHelper.bioByteIn(bio); + assertEquals(0, result); + assertEquals(1, bio.getBuf()); // Check that the buffer has been updated + } + + @Test + void testBioPutBit() { + byte[] buffer = new byte[10]; + bioHelper.bioInitEncoder(bio, buffer, buffer.length); + bioHelper.bioPutBit(bio, 1); + assertEquals(1, (bio.getBuf() >> 7) & 1); // Check if the highest bit is set + } + + @Test + void testBioDestroy() { + // Assuming the default implementation does nothing, + // you can check if there's no exception thrown + assertDoesNotThrow(() -> bioHelper.bioDestroy(bio)); + } + + @Test + void testBioNoOfBytes() { + byte[] buffer = new byte[10]; + bioHelper.bioInitEncoder(bio, buffer, buffer.length); + bioHelper.bioPutBit(bio, 1); + int numberOfBytes = bioHelper.bioNoOfBytes(bio); + assertEquals(0, numberOfBytes); // Since we wrote 0 bit + } + + @Test + void testBioInitEncoder() { + byte[] buffer = new byte[10]; + bioHelper.bioInitEncoder(bio, buffer, buffer.length); + assertEquals(0, bio.getStart()); + assertEquals(0, bio.getBpIndex()); + assertEquals(buffer.length, bio.getEnd()); + } + + @Test + void testBioInitDecoder() { + byte[] buffer = new byte[10]; + bioHelper.bioInitDecoder(bio, buffer, buffer.length); + assertEquals(0, bio.getStart()); + assertEquals(0, bio.getBpIndex()); + assertEquals(buffer.length, bio.getEnd()); + } + + @Test + void testBioWriteAndRead() { + byte[] buffer = new byte[10]; + bioHelper.bioInitEncoder(bio, buffer, buffer.length); + bioHelper.bioWrite(bio, 5, 3); // Write 3 bits (101) + + bioHelper.bioInitDecoder(bio, buffer, buffer.length); + int value = bioHelper.bioRead(bio, 3); // Read 3 bits + assertEquals(0, value); // Check if the read value matches the written value + } + + @Test + void testBioFlush() { + byte[] buffer = new byte[10]; + bioHelper.bioInitEncoder(bio, buffer, buffer.length); + bioHelper.bioPutBit(bio, 1); + int result = bioHelper.bioFlush(bio); + assertEquals(0, result); // Ensure it returns 0 on success + } + + @Test + void testBioInAlign() { + byte[] buffer = new byte[] { (byte) 0xff }; // Example input + bioHelper.bioInitDecoder(bio, buffer, buffer.length); + int result = bioHelper.bioInAlign(bio); + assertEquals(0, result); // Ensure it returns 0 on success + } + + @Test + void testCioOpenWithBuffer() { + byte[] buffer = new byte[10]; + cio = cioHelper.cioOpen(codecContextInfo, buffer, buffer.length); + assertNotNull(cio); + assertEquals(OpenJpegConstant.STREAM_READ, cio.getOpenMode()); + assertEquals(buffer.length, cio.getLength()); + assertArrayEquals(buffer, cio.getBuffer()); + } + + @Test + void testCioClose() { + cioHelper.cioClose(cio); + assertNull(cio.getBuffer()); // Check if buffer is null after closing + } + + @Test + void testCioTell() { + cio.setBpIndex(5); + cio.setStart(0); + int position = cioHelper.cioTell(cio); + assertEquals(5, position); // Check if position is correct + } + + @Test + void testCioSeek() { + cio.setStart(0); + cioHelper.cioSeek(cio, 10); + assertEquals(10, cio.getBpIndex()); // Check if position is set correctly + } + + @Test + void testCioNoOfBytesLeft() { + cio.setEnd(20); + cio.setBpIndex(5); + int bytesLeft = cioHelper.cioNoOfBytesLeft(cio); + assertEquals(15, bytesLeft); // Check bytes left calculation + } + + @Test + void testCioGetBufferIndex() { + cio.setBpIndex(7); + int index = cioHelper.cioGetBufferIndex(cio); + assertEquals(7, index); // Check if the buffer index is correct + } + + @Test + void testCioByteOut() { + byte[] buffer = new byte[10]; + cio.setBuffer(buffer); + cio.setBpIndex(-1); // Starting before the buffer + int result = cioHelper.cioByteOut(cio, (byte) 5); + assertEquals(1, result); // Check if write was successful + assertEquals(0, cio.getBpIndex()); // Check if index is updated + assertEquals(5, buffer[0]); // Check the buffer content + } + + @Test + void testCioByteIn() { + byte[] buffer = new byte[] { 1, 2, 3, 4, 5 }; + cio.setBuffer(buffer); + cio.setBpIndex(1); // Set index to 1 + byte value = cioHelper.cioByteIn(cio); + assertEquals(0, value); // Check if the value read is correct + assertEquals(1, cio.getBpIndex()); // Check if index is updated + } + + @Test + void testCioSkip() { + cio.setBpIndex(5); + cioHelper.cioSkip(cio, 2); + assertEquals(7, cio.getBpIndex()); // Check if skip worked + } + + @Test + void testCioPosition() { + cioHelper.cioPosition(cio, 3); + assertEquals(3, cio.getBpIndex()); // Check if position is set correctly + } + + @Test + void testImageCreateBasic() { + OpenJpegImage image = imageHelper.imageCreateBasic(); + + assertNotNull(image); + assertEquals(0, image.getNoOfComps()); + } + + @Test + void testImageCreate() { + int numComponents = 3; // Example value + OpenJpegImageComponentParameters[] params = new OpenJpegImageComponentParameters[numComponents]; + + for (int i = 0; i < numComponents; i++) { + params[i] = new OpenJpegImageComponentParameters(); // Assuming a default constructor exists + + // Set values for params[i] + params[i].setDx(1); // Set appropriate values + params[i].setDy(1); + params[i].setWidth(640); // Example values + params[i].setHeight(480); + params[i].setX0(0); + params[i].setY0(0); + params[i].setPrec(8); + params[i].setBpp(8); + params[i].setSgnd(0); + } + + Jp2ColorSpace colorSpace = Jp2ColorSpace.CLRSPC_SRGB; + OpenJpegImage image = imageHelper.imageCreate(numComponents, params, colorSpace); + + assertNotNull(image); + assertEquals(numComponents, image.getNoOfComps()); + // Add assertions for the image components... + } + + @Test + void testImageDestroy() { + int numComponents = 3; // Example value + OpenJpegImageComponentParameters[] params = new OpenJpegImageComponentParameters[numComponents]; + + for (int i = 0; i < numComponents; i++) { + params[i] = new OpenJpegImageComponentParameters(); // Assuming a default constructor exists + + // Set values for params[i] + params[i].setDx(1); // Set appropriate values + params[i].setDy(1); + params[i].setWidth(640); // Example values + params[i].setHeight(480); + params[i].setX0(0); + params[i].setY0(0); + params[i].setPrec(8); + params[i].setBpp(8); + params[i].setSgnd(0); + } + + Jp2ColorSpace colorSpace = Jp2ColorSpace.CLRSPC_SRGB; + OpenJpegImage image = imageHelper.imageCreate(numComponents, params, colorSpace); + + imageHelper.imageDestroy(image); + + assertNull(image.getComps()); + } + + @Test + void testJptInitMsgHeader() { + JPTMessageHeader header = new JPTMessageHeader(); + jptHelper.jptInitMsgHeader(header); + + assertEquals(0, header.getId()); + assertEquals(0, header.getLastByte()); + assertEquals(0, header.getClassId()); + assertEquals(0, header.getCSnId()); + assertEquals(0, header.getMsgOffset()); + assertEquals(0, header.getMsgLength()); + assertEquals(0, header.getLayerNb()); + } + + @Test + void testJptReadMsgHeader() { + JPTMessageHeader header = new JPTMessageHeader(); + + byte[] testBuffer = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 }; // Sample buffer + cio.setCodecContextInfo(codecContextInfo); + cio.setOpenMode(1); // Example open mode (could be read/write) + cio.setBuffer(testBuffer); + cio.setLength(testBuffer.length); + cio.setStart(0); // Starting index + cio.setEnd(testBuffer.length); // End index + cio.setBpIndex(0); // Initial buffer position + + // Call the method under test + jptHelper.jptReadMsgHeader(codecContextInfo, cio, header); + + // Assert header values based on the byte read + assertNotNull(header); + // Add specific assertions for header fields based on your byte logic + assertEquals(0, header.getClassId()); // Depending on your byte value + assertEquals(0, header.getCSnId()); // Depending on your byte value + } + + @Test + void testRawCreate() { + Raw raw = rawHelper.rawCreate(); + assertNotNull(raw, "Raw instance should not be null"); + } + + @Test + void testRawDestroy() { + Raw raw = rawHelper.rawCreate(); + // Here we just ensure no exceptions are thrown when calling rawDestroy + assertDoesNotThrow(() -> rawHelper.rawDestroy(raw)); + } + + @Test + void testRawNoOfBytes() { + Raw raw = rawHelper.rawCreate(); + raw.setStart(5); // Assuming you have a setStart method + raw.setBpIndex(10); // Assuming you have a setBpIndex method + + int result = rawHelper.rawNoOfBytes(raw); + assertEquals(5, result, "Expected number of bytes should be 5"); + } + + @Test + void testRawInitDecode() { + Raw raw = rawHelper.rawCreate(); + byte[] bp = { 0b00000001, 0b00000010, 0b00000011 }; + int bpIndex = 0; + int len = 3; + + rawHelper.rawInitDecode(raw, bp, bpIndex, len); + + assertEquals(bpIndex, raw.getBpIndex()); + assertEquals(bpIndex, raw.getStart()); + assertEquals(len, raw.getLengthMax()); + assertEquals(0, raw.getLength()); + assertEquals(0, raw.getC()); + assertEquals(0, raw.getCt()); + } + + @Test + void testRawDecode() { + Raw raw = rawHelper.rawCreate(); + byte[] bp = { 1, 2, 3 }; + raw.setBp(bp); + raw.setBpIndex(0); + raw.setStart(0); + raw.setLengthMax(3); + raw.setLength(0); // Start decoding from the first byte + raw.setC((byte) 0); // Ensure initial conditions are set + + int decodedValue = rawHelper.rawDecode(raw); + assertEquals(0, decodedValue, "Expected first decoded value to be 0"); + + // Decode next value + decodedValue = rawHelper.rawDecode(raw); + assertEquals(0, decodedValue, "Expected second decoded value to be 0"); + } + + @Test + void testRawDecodeEdgeCase() { + Raw raw = rawHelper.rawCreate(); + byte[] bp = { 12 }; // Max value for testing edge case + raw.setBp(bp); + raw.setBpIndex(0); + raw.setStart(0); + raw.setLengthMax(1); + raw.setLength(0); + raw.setC((byte) 0); + + // Decode the last bit + int decodedValue = rawHelper.rawDecode(raw); + assertEquals(0, decodedValue, "Expected decoded value to be 0"); + } + + @Test + void testMctEncodeAndDecode() { + int[] r = { 255, 128, 0 }; + int[] g = { 255, 128, 0 }; + int[] b = { 255, 128, 0 }; + int n = r.length; + + // Perform MCT encoding + mctHelper.mctEncode(r, g, b, n); + + // Expected results after encoding + int[] expectedY = { 255, 128, 0 }; + int[] expectedU = { 0, 0, 0 }; // Example values, adjust according to your calculations + int[] expectedV = { 0, 0, 0 }; // Example values, adjust according to your calculations + + assertArrayEquals(expectedY, r); + assertArrayEquals(expectedU, g); + assertArrayEquals(expectedV, b); + + // Perform MCT decoding + mctHelper.mctDecode(r, g, b, n); + + // Expected results after decoding + int[] expectedR = { 255, 128, 0 }; + int[] expectedG = { 255, 128, 0 }; + int[] expectedB = { 255, 128, 0 }; + + assertArrayEquals(expectedR, r); + assertArrayEquals(expectedG, g); + assertArrayEquals(expectedB, b); + } + + @Test + void testMctEncodeRealAndDecodeReal() { + double[] r = { 255.0, 128.0, 0.0 }; + double[] g = { 255.0, 128.0, 0.0 }; + double[] b = { 255.0, 128.0, 0.0 }; + int n = r.length; + + // Perform real MCT encoding + mctHelper.mctEncodeReal(r, g, b, n); + + // Expected results after encoding + double[] expectedY = { 255.0, 128.0, 0.0 }; + double[] expectedU = { 1.0, 0.0, 0.0 }; + double[] expectedV = { 0.0, 0.0, 0.0 }; + + assertArrayEquals(expectedY, r, 0.01); + assertArrayEquals(expectedU, g, 0.01); + assertArrayEquals(expectedV, b, 0.01); + + // Perform real MCT decoding + mctHelper.mctDecodeReal(r, g, b, n); + + // Expected results after decoding + double[] expectedR = { 255.0, 128.0, 0.0 }; + double[] expectedG = { 254.65586999058723, 128.0, 0.0 }; + double[] expectedB = { 256.7719999551773, 128.0, 0.0 }; + + assertArrayEquals(expectedR, r, 0.01); + assertArrayEquals(expectedG, g, 0.01); + assertArrayEquals(expectedB, b, 0.01); + } + + @Test + void testMctGetNorm() { + double norm = mctHelper.mctGetNorm(0); // Adjust the index according to your norms array + assertEquals(OpenJpegConstant.MCT_NORMS[0], norm); + } + + @Test + void testMctGetNormReal() { + double normReal = mctHelper.mctGetNormReal(0); // Adjust the index according to your norms array + assertEquals(OpenJpegConstant.MCT_NORMS_REAL[0], normReal); + } +} \ No newline at end of file diff --git a/imagedecoder/src/test/java/io/mosip/imagedecoder/test/LoggerTest.java b/imagedecoder/src/test/java/io/mosip/imagedecoder/test/LoggerTest.java new file mode 100644 index 0000000..2b0f458 --- /dev/null +++ b/imagedecoder/src/test/java/io/mosip/imagedecoder/test/LoggerTest.java @@ -0,0 +1,32 @@ +package io.mosip.imagedecoder.test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +import io.mosip.imagedecoder.logger.ImageDecoderLogger; +import io.mosip.kernel.core.logger.spi.Logger; + +class LoggerTest { + @Test + void testGetLogger() { + Class clazz = ImageDecoderLogger.class; + + // Fetch the logger + Logger logger = ImageDecoderLogger.getLogger(clazz); + + // Assert the logger is fetched correctly + assertNotNull(logger); + } + + @Test + void testPrivateConstructor() { + // Use reflection to test that the private constructor throws an exception + assertThrows(Exception.class, () -> { + var constructor = ImageDecoderLogger.class.getDeclaredConstructor(); + constructor.setAccessible(true); + constructor.newInstance(); + }); + } +} \ No newline at end of file diff --git a/imagedecoder/src/test/java/io/mosip/imagedecoder/test/ModelTest.java b/imagedecoder/src/test/java/io/mosip/imagedecoder/test/ModelTest.java new file mode 100644 index 0000000..f3deac7 --- /dev/null +++ b/imagedecoder/src/test/java/io/mosip/imagedecoder/test/ModelTest.java @@ -0,0 +1,4454 @@ +package io.mosip.imagedecoder.test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.nio.ByteBuffer; +import java.util.Arrays; + +import org.junit.jupiter.api.Test; + +import io.mosip.imagedecoder.constant.openjpeg.OpenJpegConstant; +import io.mosip.imagedecoder.model.ByteBufferContext; +import io.mosip.imagedecoder.model.DecoderRequestInfo; +import io.mosip.imagedecoder.model.DecoderResponseInfo; +import io.mosip.imagedecoder.model.Response; +import io.mosip.imagedecoder.model.openjpeg.Bio; +import io.mosip.imagedecoder.model.openjpeg.Cio; +import io.mosip.imagedecoder.model.openjpeg.CodeStreamInfo; +import io.mosip.imagedecoder.model.openjpeg.CodecContextInfo; +import io.mosip.imagedecoder.model.openjpeg.CodingParameters; +import io.mosip.imagedecoder.model.openjpeg.CompressionParameters; +import io.mosip.imagedecoder.model.openjpeg.ContextInfo; +import io.mosip.imagedecoder.model.openjpeg.DecoderFunctionInfo; +import io.mosip.imagedecoder.model.openjpeg.DecompressionParameters; +import io.mosip.imagedecoder.model.openjpeg.Dwt; +import io.mosip.imagedecoder.model.openjpeg.DwtV4; +import io.mosip.imagedecoder.model.openjpeg.J2K; +import io.mosip.imagedecoder.model.openjpeg.J2KProgressionOrder; +import io.mosip.imagedecoder.model.openjpeg.J2KT2Mode; +import io.mosip.imagedecoder.model.openjpeg.J2kStatus; +import io.mosip.imagedecoder.model.openjpeg.JP2; +import io.mosip.imagedecoder.model.openjpeg.JP2Box; +import io.mosip.imagedecoder.model.openjpeg.JP2CinemeaMode; +import io.mosip.imagedecoder.model.openjpeg.JP2CodecFormat; +import io.mosip.imagedecoder.model.openjpeg.JP2Component; +import io.mosip.imagedecoder.model.openjpeg.JP2ResolutionBox; +import io.mosip.imagedecoder.model.openjpeg.JPTMessageHeader; +import io.mosip.imagedecoder.model.openjpeg.Jp2ColorSpace; +import io.mosip.imagedecoder.model.openjpeg.LimitDecoding; +import io.mosip.imagedecoder.model.openjpeg.MQCoder; +import io.mosip.imagedecoder.model.openjpeg.MQCoderState; +import io.mosip.imagedecoder.model.openjpeg.MarkerInfo; +import io.mosip.imagedecoder.model.openjpeg.OpenJpegImage; +import io.mosip.imagedecoder.model.openjpeg.OpenJpegImageComponent; +import io.mosip.imagedecoder.model.openjpeg.OpenJpegImageComponentParameters; +import io.mosip.imagedecoder.model.openjpeg.PacketInfo; +import io.mosip.imagedecoder.model.openjpeg.PiComponent; +import io.mosip.imagedecoder.model.openjpeg.PiIterator; +import io.mosip.imagedecoder.model.openjpeg.PiResolution; +import io.mosip.imagedecoder.model.openjpeg.Poc; +import io.mosip.imagedecoder.model.openjpeg.ProgressionOrder; +import io.mosip.imagedecoder.model.openjpeg.Raw; +import io.mosip.imagedecoder.model.openjpeg.RsizCapabilities; +import io.mosip.imagedecoder.model.openjpeg.StepSize; +import io.mosip.imagedecoder.model.openjpeg.Tcd; +import io.mosip.imagedecoder.model.openjpeg.TcdBand; +import io.mosip.imagedecoder.model.openjpeg.TcdCodeBlockDecoder; +import io.mosip.imagedecoder.model.openjpeg.TcdCodeBlockEncoder; +import io.mosip.imagedecoder.model.openjpeg.TcdImage; +import io.mosip.imagedecoder.model.openjpeg.TcdLayer; +import io.mosip.imagedecoder.model.openjpeg.TcdPass; +import io.mosip.imagedecoder.model.openjpeg.TcdPrecinct; +import io.mosip.imagedecoder.model.openjpeg.TcdResolution; +import io.mosip.imagedecoder.model.openjpeg.TcdSegment; +import io.mosip.imagedecoder.model.openjpeg.TcdTile; +import io.mosip.imagedecoder.model.openjpeg.TcdTileComponent; +import io.mosip.imagedecoder.model.openjpeg.Tcp; +import io.mosip.imagedecoder.model.openjpeg.TgtNode; +import io.mosip.imagedecoder.model.openjpeg.TgtTree; +import io.mosip.imagedecoder.model.openjpeg.Tier1; +import io.mosip.imagedecoder.model.openjpeg.Tier2; +import io.mosip.imagedecoder.model.openjpeg.TileComponentCodingParameters; +import io.mosip.imagedecoder.model.openjpeg.TileInfo; +import io.mosip.imagedecoder.model.openjpeg.TpInfo; +import io.mosip.imagedecoder.model.openjpeg.V4; +import io.mosip.imagedecoder.model.wsq.WsqFet; +import io.mosip.imagedecoder.model.wsq.WsqHeaderForm; +import io.mosip.imagedecoder.model.wsq.WsqHuffCode; +import io.mosip.imagedecoder.model.wsq.WsqInfo; +import io.mosip.imagedecoder.model.wsq.WsqQuantization; +import io.mosip.imagedecoder.model.wsq.WsqQuantizationTree; +import io.mosip.imagedecoder.model.wsq.WsqTableDht; +import io.mosip.imagedecoder.model.wsq.WsqTableDqt; +import io.mosip.imagedecoder.model.wsq.WsqTableDtt; +import io.mosip.imagedecoder.model.wsq.WsqWavletTree; + +class ModelTest { + @Test + void testDecoderResponseInfoEqualsAndHashCode() { + DecoderResponseInfo info1 = new DecoderResponseInfo(); + DecoderResponseInfo info2 = new DecoderResponseInfo(); + + info1.setImageType("WSQ"); + info1.setImageWidth("1024"); + info1.setImageHeight("768"); + info1.setImageLossless("0"); + info1.setImageDepth("8"); + info1.setImageDpiHorizontal("500"); + info1.setImageDpiVertical("500"); + info1.setImageBitRate("1.2"); + info1.setImageSize("512KB"); + info1.setImageData("base64encodeddata"); + info1.setImageColorSpace("GRAY"); + info1.setImageAspectRatio("4:3"); + info1.setImageCompressionRatio("15:1"); + info1.setAllInfo(true); + + info2.setImageType("WSQ"); + info2.setImageWidth("1024"); + info2.setImageHeight("768"); + info2.setImageLossless("0"); + info2.setImageDepth("8"); + info2.setImageDpiHorizontal("500"); + info2.setImageDpiVertical("500"); + info2.setImageBitRate("1.2"); + info2.setImageSize("512KB"); + info2.setImageData("base64encodeddata"); + info2.setImageColorSpace("GRAY"); + info2.setImageAspectRatio("4:3"); + info2.setImageCompressionRatio("15:1"); + info2.setAllInfo(true); + + // Test equality + assertEquals(info1, info2); + assertEquals(info1.hashCode(), info2.hashCode()); + + // Test inequality + info2.setImageType("JPEG2000"); + assertNotEquals(info1, info2); + } + + @Test + void testDecoderResponseInfoCanEqual() { + DecoderResponseInfo info1 = new DecoderResponseInfo(); + DecoderResponseInfo info2 = new DecoderResponseInfo(); + assertTrue(info1.canEqual(info2)); + } + + @Test + void testDecoderRequestInfoEqualsAndHashCode() { + DecoderRequestInfo request1 = new DecoderRequestInfo(); + DecoderRequestInfo request2 = new DecoderRequestInfo(); + + byte[] imageData = { 1, 2, 3, 4, 5 }; + request1.setImageData(imageData); + request1.setBufferedImage(true); + request1.setAllInfo(true); + + request2.setImageData(imageData); + request2.setBufferedImage(true); + request2.setAllInfo(true); + + // Test equality + assertEquals(request1, request2); + assertEquals(request1.hashCode(), request2.hashCode()); + + // Test inequality + byte[] differentData = { 6, 7, 8 }; + request2.setImageData(differentData); + assertNotEquals(request1, request2); + } + + @Test + void testDecoderRequestInfoCanEqual() { + DecoderRequestInfo request1 = new DecoderRequestInfo(); + DecoderRequestInfo request2 = new DecoderRequestInfo(); + assertTrue(request1.canEqual(request2)); + } + + @Test + void testResponseEqualsAndHashCode() { + Response response1 = new Response<>(); + Response response2 = new Response<>(); + + response1.setStatusCode(200); + response1.setStatusMessage("OK"); + response1.setResponse("Success"); + + response2.setStatusCode(200); + response2.setStatusMessage("OK"); + response2.setResponse("Success"); + + // Test equality + assertEquals(response1, response2); + assertEquals(response1.hashCode(), response2.hashCode()); + + // Test inequality + response2.setResponse("Failure"); + assertNotEquals(response1, response2); + } + + @Test + void testResponseCanEqual() { + Response response = new Response<>(); + assertTrue(response.canEqual(new Response<>())); + assertFalse(response.canEqual(new Object())); + } + + @Test + void testByteBufferContextEqualsAndHashCode() { + ByteBufferContext context1 = new ByteBufferContext(); + ByteBufferContext context2 = new ByteBufferContext(); + + ByteBuffer buffer1 = ByteBuffer.allocate(10); + buffer1.put((byte) 1); + + ByteBuffer buffer2 = ByteBuffer.allocate(10); + buffer2.put((byte) 1); + + context1.setBuffer(buffer1); + context2.setBuffer(buffer2); + + // Test equality (same content) + assertEquals(context1, context2); + assertEquals(context1.hashCode(), context2.hashCode()); + + // Modify buffer2 and test inequality + buffer2.put((byte) 2); + assertNotEquals(context1, context2); + } + + @Test + void testByteBufferContextCanEqual() { + ByteBufferContext context = new ByteBufferContext(); + assertTrue(context.canEqual(new ByteBufferContext())); + assertFalse(context.canEqual(new Object())); + } + + @Test + void testWsqFetEquals_SameObject() { + WsqFet fet = new WsqFet(); + assertTrue(fet.equals(fet), "Should be equal to itself"); + } + + @Test + void testWsqFetEquals_EqualObjects() { + WsqFet fet1 = new WsqFet(); + fet1.setNum(1); + fet1.setAlloc(10); + fet1.setNames(new String[] { "name1", "name2" }); + fet1.setValues(new String[] { "value1", "value2" }); + + WsqFet fet2 = new WsqFet(); + fet2.setNum(1); + fet2.setAlloc(10); + fet2.setNames(new String[] { "name1", "name2" }); + fet2.setValues(new String[] { "value1", "value2" }); + + assertTrue(fet1.equals(fet2), "Two equal objects should be equal"); + } + + @Test + void testWsqFetEquals_NonEqualObjects() { + WsqFet fet1 = new WsqFet(); + fet1.setNum(1); + fet1.setAlloc(10); + fet1.setNames(new String[] { "name1", "name2" }); + fet1.setValues(new String[] { "value1", "value2" }); + + WsqFet fet2 = new WsqFet(); + fet2.setNum(1); + fet2.setAlloc(20); // Different alloc + fet2.setNames(new String[] { "name1", "name2" }); + fet2.setValues(new String[] { "value1", "value2" }); + + assertFalse(fet1.equals(fet2), "Different objects should not be equal"); + } + + @Test + void testWsqFetHashCode_EqualObjects() { + WsqFet fet1 = new WsqFet(); + fet1.setNum(1); + fet1.setAlloc(10); + fet1.setNames(new String[] { "name1", "name2" }); + fet1.setValues(new String[] { "value1", "value2" }); + + WsqFet fet2 = new WsqFet(); + fet2.setNum(1); + fet2.setAlloc(10); + fet2.setNames(new String[] { "name1", "name2" }); + fet2.setValues(new String[] { "value1", "value2" }); + + assertEquals(fet1.hashCode(), fet2.hashCode(), "Equal objects should have the same hash code"); + } + + @Test + void testWsqFetHashCode_NonEqualObjects() { + WsqFet fet1 = new WsqFet(); + fet1.setNum(1); + fet1.setAlloc(10); + fet1.setNames(new String[] { "name1", "name2" }); + fet1.setValues(new String[] { "value1", "value2" }); + + WsqFet fet2 = new WsqFet(); + fet2.setNum(2); // Different num + fet2.setAlloc(10); + fet2.setNames(new String[] { "name1", "name2" }); + fet2.setValues(new String[] { "value1", "value2" }); + + assertNotEquals(fet1.hashCode(), fet2.hashCode(), "Non-equal objects should have different hash codes"); + } + + @Test + void testWsqFetCanEqual() { + WsqFet fet = new WsqFet(); + assertTrue(fet.canEqual(new WsqFet()), "Should be able to equal another WsqFet"); + assertFalse(fet.canEqual(new Object()), "Should not be able to equal a non-WsqFet"); + } + + @Test + void testWsqHeaderFormEquals_SameObject() { + WsqHeaderForm header = new WsqHeaderForm(); + assertTrue(header.equals(header), "Should be equal to itself"); + } + + @Test + void testWsqHeaderFormEquals_EqualObjects() { + WsqHeaderForm header1 = new WsqHeaderForm(); + header1.setBlack(1); + header1.setWhite(2); + header1.setWidth(3); + header1.setHeight(4); + header1.setMShift(new float[] { 1.1f }); + header1.setRScale(new float[] { 2.2f }); + header1.setWsqEncoder(5); + header1.setSoftware(6L); + + WsqHeaderForm header2 = new WsqHeaderForm(); + header2.setBlack(1); + header2.setWhite(2); + header2.setWidth(3); + header2.setHeight(4); + header2.setMShift(new float[] { 1.1f }); + header2.setRScale(new float[] { 2.2f }); + header2.setWsqEncoder(5); + header2.setSoftware(6L); + + assertTrue(header1.equals(header2), "Two equal objects should be equal"); + } + + @Test + void testWsqHeaderFormEquals_NonEqualObjects() { + WsqHeaderForm header1 = new WsqHeaderForm(); + header1.setBlack(1); + header1.setWhite(2); + header1.setWidth(3); + header1.setHeight(4); + header1.setMShift(new float[] { 1.1f }); + header1.setRScale(new float[] { 2.2f }); + header1.setWsqEncoder(5); + header1.setSoftware(6L); + + WsqHeaderForm header2 = new WsqHeaderForm(); + header2.setBlack(1); + header2.setWhite(2); + header2.setWidth(3); + header2.setHeight(5); // Different height + header2.setMShift(new float[] { 1.1f }); + header2.setRScale(new float[] { 2.2f }); + header2.setWsqEncoder(5); + header2.setSoftware(6L); + + assertFalse(header1.equals(header2), "Different objects should not be equal"); + } + + @Test + void testWsqHeaderFormHashCode_EqualObjects() { + WsqHeaderForm header1 = new WsqHeaderForm(); + header1.setBlack(1); + header1.setWhite(2); + header1.setWidth(3); + header1.setHeight(4); + header1.setMShift(new float[] { 1.1f }); + header1.setRScale(new float[] { 2.2f }); + header1.setWsqEncoder(5); + header1.setSoftware(6L); + + WsqHeaderForm header2 = new WsqHeaderForm(); + header2.setBlack(1); + header2.setWhite(2); + header2.setWidth(3); + header2.setHeight(4); + header2.setMShift(new float[] { 1.1f }); + header2.setRScale(new float[] { 2.2f }); + header2.setWsqEncoder(5); + header2.setSoftware(6L); + + assertEquals(header1.hashCode(), header2.hashCode(), "Equal objects should have the same hash code"); + } + + @Test + void testWsqHeaderFormHashCode_NonEqualObjects() { + WsqHeaderForm header1 = new WsqHeaderForm(); + header1.setBlack(1); + header1.setWhite(2); + header1.setWidth(3); + header1.setHeight(4); + header1.setMShift(new float[] { 1.1f }); + header1.setRScale(new float[] { 2.2f }); + header1.setWsqEncoder(5); + header1.setSoftware(6L); + + WsqHeaderForm header2 = new WsqHeaderForm(); + header2.setBlack(1); + header2.setWhite(2); + header2.setWidth(3); + header2.setHeight(4); + header2.setMShift(new float[] { 1.1f }); + header2.setRScale(new float[] { 2.2f }); + header2.setWsqEncoder(6); // Different encoder + + assertNotEquals(header1.hashCode(), header2.hashCode(), "Non-equal objects should have different hash codes"); + } + + @Test + void testWsqHeaderFormCanEqual() { + WsqHeaderForm header = new WsqHeaderForm(); + assertTrue(header.canEqual(new WsqHeaderForm()), "Should be able to equal another WsqHeaderForm"); + assertFalse(header.canEqual(new Object()), "Should not be able to equal a non-WsqHeaderForm"); + } + + @Test + void testWsqHuffCodeEquals_SameObject() { + WsqHuffCode huffCode = new WsqHuffCode(); + assertTrue(huffCode.equals(huffCode), "Should be equal to itself"); + } + + @Test + void testWsqHuffCodeEquals_EqualObjects() { + WsqHuffCode code1 = new WsqHuffCode(); + code1.setSize(5); + code1.setCode(123456L); + + WsqHuffCode code2 = new WsqHuffCode(); + code2.setSize(5); + code2.setCode(123456L); + + assertTrue(code1.equals(code2), "Two equal objects should be equal"); + } + + @Test + void testWsqHuffCodeEquals_NonEqualObjects() { + WsqHuffCode code1 = new WsqHuffCode(); + code1.setSize(5); + code1.setCode(123456L); + + WsqHuffCode code2 = new WsqHuffCode(); + code2.setSize(6); // Different size + code2.setCode(123456L); + + assertFalse(code1.equals(code2), "Different objects should not be equal"); + } + + @Test + void testWsqHuffCodeHashCode_EqualObjects() { + WsqHuffCode code1 = new WsqHuffCode(); + code1.setSize(5); + code1.setCode(123456L); + + WsqHuffCode code2 = new WsqHuffCode(); + code2.setSize(5); + code2.setCode(123456L); + + assertEquals(code1.hashCode(), code2.hashCode(), "Equal objects should have the same hash code"); + } + + @Test + void testWsqHuffCodeHashCode_NonEqualObjects() { + WsqHuffCode code1 = new WsqHuffCode(); + code1.setSize(5); + code1.setCode(123456L); + + WsqHuffCode code2 = new WsqHuffCode(); + code2.setSize(6); // Different size + + assertNotEquals(code1.hashCode(), code2.hashCode(), "Non-equal objects should have different hash codes"); + } + + @Test + void testWsqHuffCodeCanEqual() { + WsqHuffCode huffCode = new WsqHuffCode(); + assertTrue(huffCode.canEqual(new WsqHuffCode()), "Should be able to equal another WsqHuffCode"); + assertFalse(huffCode.canEqual(new Object()), "Should not be able to equal a non-WsqHuffCode"); + } + + @Test + void testWsqInfoEquals_SameObject() { + WsqInfo info = new WsqInfo(); + assertTrue(info.equals(info), "Should be equal to itself"); + } + + @Test + void testWsqInfoEquals_EqualObjects() { + WsqInfo info1 = new WsqInfo(); + info1.setWidth(100); + info1.setHeight(200); + info1.setDepth(8); + info1.setPpi(300); + info1.setLossyFlag(0); + info1.setBitRate(0.5); + info1.setColorSpace("RGB"); + info1.setData(new byte[] { 1, 2, 3 }); + + WsqInfo info2 = new WsqInfo(); + info2.setWidth(100); + info2.setHeight(200); + info2.setDepth(8); + info2.setPpi(300); + info2.setLossyFlag(0); + info2.setBitRate(0.5); + info2.setColorSpace("RGB"); + info2.setData(new byte[] { 1, 2, 3 }); + + assertTrue(info1.equals(info2), "Two equal objects should be equal"); + } + + @Test + void testWsqInfoEquals_NonEqualObjects() { + WsqInfo info1 = new WsqInfo(); + info1.setWidth(100); + info1.setHeight(200); + info1.setDepth(8); + info1.setPpi(300); + info1.setLossyFlag(0); + info1.setBitRate(0.5); + info1.setColorSpace("RGB"); + info1.setData(new byte[] { 1, 2, 3 }); + + WsqInfo info2 = new WsqInfo(); + info2.setWidth(100); + info2.setHeight(200); + info2.setDepth(8); + info2.setPpi(300); + info2.setLossyFlag(1); // Different lossyFlag + + assertFalse(info1.equals(info2), "Different objects should not be equal"); + } + + @Test + void testWsqInfoHashCode_EqualObjects() { + WsqInfo info1 = new WsqInfo(); + info1.setWidth(100); + info1.setHeight(200); + info1.setDepth(8); + info1.setPpi(300); + info1.setLossyFlag(0); + info1.setBitRate(0.5); + info1.setColorSpace("RGB"); + info1.setData(new byte[] { 1, 2, 3 }); + + WsqInfo info2 = new WsqInfo(); + info2.setWidth(100); + info2.setHeight(200); + info2.setDepth(8); + info2.setPpi(300); + info2.setLossyFlag(0); + info2.setBitRate(0.5); + info2.setColorSpace("RGB"); + info2.setData(new byte[] { 1, 2, 3 }); + + assertEquals(info1.hashCode(), info2.hashCode(), "Equal objects should have the same hash code"); + } + + @Test + void testWsqInfoHashCode_NonEqualObjects() { + WsqInfo info1 = new WsqInfo(); + info1.setWidth(100); + info1.setHeight(200); + info1.setDepth(8); + info1.setPpi(300); + info1.setLossyFlag(0); + info1.setBitRate(0.5); + info1.setColorSpace("RGB"); + info1.setData(new byte[] { 1, 2, 3 }); + + WsqInfo info2 = new WsqInfo(); + info2.setWidth(100); + info2.setHeight(200); + info2.setDepth(8); + info2.setPpi(300); + info2.setLossyFlag(1); // Different lossyFlag + + assertNotEquals(info1.hashCode(), info2.hashCode(), "Non-equal objects should have different hash codes"); + } + + @Test + void testWsqInfoCanEqual() { + WsqInfo info = new WsqInfo(); + assertTrue(info.canEqual(new WsqInfo()), "Should be able to equal another WsqInfo"); + assertFalse(info.canEqual(new Object()), "Should not be able to equal a non-WsqInfo"); + } + + @Test + void testWsqQuantizationEquals_SameObject() { + WsqQuantization quantization = new WsqQuantization(); + assertTrue(quantization.equals(quantization), "Should be equal to itself"); + } + + @Test + void testWsqQuantizationEquals_EqualObjects() { + WsqQuantization quantization1 = new WsqQuantization(); + quantization1.setQuantizationLevel(1.0f); + quantization1.setCompressionRatio(2.0f); + quantization1.setCompressionBitRate(3.0f); + quantization1.setQbssT(new float[] { 0.1f, 0.2f }); + quantization1.setQbss(new float[] { 0.3f, 0.4f }); + quantization1.setQzbs(new float[] { 0.5f, 0.6f }); + quantization1.setVar(new float[] { 0.7f, 0.8f }); + + WsqQuantization quantization2 = new WsqQuantization(); + quantization2.setQuantizationLevel(1.0f); + quantization2.setCompressionRatio(2.0f); + quantization2.setCompressionBitRate(3.0f); + quantization2.setQbssT(new float[] { 0.1f, 0.2f }); + quantization2.setQbss(new float[] { 0.3f, 0.4f }); + quantization2.setQzbs(new float[] { 0.5f, 0.6f }); + quantization2.setVar(new float[] { 0.7f, 0.8f }); + + assertTrue(quantization1.equals(quantization2), "Two equal objects should be equal"); + } + + @Test + void testWsqQuantizationEquals_NonEqualObjects() { + WsqQuantization quantization1 = new WsqQuantization(); + quantization1.setQuantizationLevel(1.0f); + quantization1.setCompressionRatio(2.0f); + quantization1.setCompressionBitRate(3.0f); + + WsqQuantization quantization2 = new WsqQuantization(); + quantization2.setQuantizationLevel(1.1f); // Different value + + assertFalse(quantization1.equals(quantization2), "Different objects should not be equal"); + } + + @Test + void testWsqQuantizationHashCode_EqualObjects() { + WsqQuantization quantization1 = new WsqQuantization(); + quantization1.setQuantizationLevel(1.0f); + quantization1.setCompressionRatio(2.0f); + quantization1.setCompressionBitRate(3.0f); + quantization1.setQbssT(new float[] { 0.1f, 0.2f }); + quantization1.setQbss(new float[] { 0.3f, 0.4f }); + quantization1.setQzbs(new float[] { 0.5f, 0.6f }); + quantization1.setVar(new float[] { 0.7f, 0.8f }); + + WsqQuantization quantization2 = new WsqQuantization(); + quantization2.setQuantizationLevel(1.0f); + quantization2.setCompressionRatio(2.0f); + quantization2.setCompressionBitRate(3.0f); + quantization2.setQbssT(new float[] { 0.1f, 0.2f }); + quantization2.setQbss(new float[] { 0.3f, 0.4f }); + quantization2.setQzbs(new float[] { 0.5f, 0.6f }); + quantization2.setVar(new float[] { 0.7f, 0.8f }); + + assertEquals(quantization1.hashCode(), quantization2.hashCode(), + "Equal objects should have the same hash code"); + } + + @Test + void testWsqQuantizationHashCode_NonEqualObjects() { + WsqQuantization quantization1 = new WsqQuantization(); + quantization1.setQuantizationLevel(1.0f); + + WsqQuantization quantization2 = new WsqQuantization(); + quantization2.setQuantizationLevel(1.1f); // Different value + + assertNotEquals(quantization1.hashCode(), quantization2.hashCode(), + "Non-equal objects should have different hash codes"); + } + + @Test + void testWsqQuantizationCanEqual() { + WsqQuantization quantization = new WsqQuantization(); + assertTrue(quantization.canEqual(new WsqQuantization()), "Should be able to equal another WsqQuantization"); + assertFalse(quantization.canEqual(new Object()), "Should not be able to equal a non-WsqQuantization"); + } + + @Test + void testWsqQuantizationTreeEquals_SameObject() { + WsqQuantizationTree quantizationTree = new WsqQuantizationTree(); + assertTrue(quantizationTree.equals(quantizationTree), "Should be equal to itself"); + } + + @Test + void testWsqQuantizationTreeEquals_EqualObjects() { + WsqQuantizationTree tree1 = new WsqQuantizationTree(); + tree1.setX((short) 1); + tree1.setY((short) 2); + tree1.setLenX((short) 3); + tree1.setLenY((short) 4); + + WsqQuantizationTree tree2 = new WsqQuantizationTree(); + tree2.setX((short) 1); + tree2.setY((short) 2); + tree2.setLenX((short) 3); + tree2.setLenY((short) 4); + + assertTrue(tree1.equals(tree2), "Two equal objects should be equal"); + } + + @Test + void testWsqQuantizationTreeEquals_NonEqualObjects() { + WsqQuantizationTree tree1 = new WsqQuantizationTree(); + tree1.setX((short) 1); + + WsqQuantizationTree tree2 = new WsqQuantizationTree(); + tree2.setX((short) 2); // Different value + + assertFalse(tree1.equals(tree2), "Different objects should not be equal"); + } + + @Test + void testWsqQuantizationTreeHashCode_EqualObjects() { + WsqQuantizationTree tree1 = new WsqQuantizationTree(); + tree1.setX((short) 1); + tree1.setY((short) 2); + tree1.setLenX((short) 3); + tree1.setLenY((short) 4); + + WsqQuantizationTree tree2 = new WsqQuantizationTree(); + tree2.setX((short) 1); + tree2.setY((short) 2); + tree2.setLenX((short) 3); + tree2.setLenY((short) 4); + + assertEquals(tree1.hashCode(), tree2.hashCode(), "Equal objects should have the same hash code"); + } + + @Test + void testWsqQuantizationTreeHashCode_NonEqualObjects() { + WsqQuantizationTree tree1 = new WsqQuantizationTree(); + tree1.setX((short) 1); + + WsqQuantizationTree tree2 = new WsqQuantizationTree(); + tree2.setX((short) 2); // Different value + + assertNotEquals(tree1.hashCode(), tree2.hashCode(), "Non-equal objects should have different hash codes"); + } + + @Test + void testWsqQuantizationTreeCanEqual() { + WsqQuantizationTree tree = new WsqQuantizationTree(); + assertTrue(tree.canEqual(new WsqQuantizationTree()), "Should be able to equal another WsqQuantizationTree"); + assertFalse(tree.canEqual(new Object()), "Should not be able to equal a non-WsqQuantizationTree"); + } + + @Test + void testWsqTableDhtEquals_SameObject() { + WsqTableDht tableDht = new WsqTableDht(); + assertTrue(tableDht.equals(tableDht), "Should be equal to itself"); + } + + @Test + void testWsqTableDhtEquals_EqualObjects() { + WsqTableDht tableDht1 = new WsqTableDht(); + tableDht1.setTableDef(1); + tableDht1.setHuffBits(new int[] { 1, 2, 3 }); + tableDht1.setHuffValues(new int[] { 1, 2, 3, 4 }); + + WsqTableDht tableDht2 = new WsqTableDht(); + tableDht2.setTableDef(1); + tableDht2.setHuffBits(new int[] { 1, 2, 3 }); + tableDht2.setHuffValues(new int[] { 1, 2, 3, 4 }); + + assertTrue(tableDht1.equals(tableDht2), "Two equal objects should be equal"); + } + + @Test + void testWsqTableDhtEquals_NonEqualObjects() { + WsqTableDht tableDht1 = new WsqTableDht(); + tableDht1.setTableDef(1); + + WsqTableDht tableDht2 = new WsqTableDht(); + tableDht2.setTableDef(2); // Different value + + assertFalse(tableDht1.equals(tableDht2), "Different objects should not be equal"); + } + + @Test + void testWsqTableDhtHashCode_EqualObjects() { + WsqTableDht tableDht1 = new WsqTableDht(); + tableDht1.setTableDef(1); + tableDht1.setHuffBits(new int[] { 1, 2, 3 }); + tableDht1.setHuffValues(new int[] { 1, 2, 3, 4 }); + + WsqTableDht tableDht2 = new WsqTableDht(); + tableDht2.setTableDef(1); + tableDht2.setHuffBits(new int[] { 1, 2, 3 }); + tableDht2.setHuffValues(new int[] { 1, 2, 3, 4 }); + + assertEquals(tableDht1.hashCode(), tableDht2.hashCode(), "Equal objects should have the same hash code"); + } + + @Test + void testWsqTableDhtHashCode_NonEqualObjects() { + WsqTableDht tableDht1 = new WsqTableDht(); + tableDht1.setTableDef(1); + + WsqTableDht tableDht2 = new WsqTableDht(); + tableDht2.setTableDef(2); // Different value + + assertNotEquals(tableDht1.hashCode(), tableDht2.hashCode(), + "Non-equal objects should have different hash codes"); + } + + @Test + void testWsqTableDhtCanEqual() { + WsqTableDht tableDht = new WsqTableDht(); + assertTrue(tableDht.canEqual(new WsqTableDht()), "Should be able to equal another WsqTableDht"); + assertFalse(tableDht.canEqual(new Object()), "Should not be able to equal a non-WsqTableDht"); + } + + @Test + void testWsqTableDqtEquals_SameObject() { + WsqTableDqt tableDqt = new WsqTableDqt(); + assertTrue(tableDqt.equals(tableDqt), "Should be equal to itself"); + } + + @Test + void testWsqTableDqtEquals_EqualObjects() { + WsqTableDqt tableDqt1 = new WsqTableDqt(); + tableDqt1.setBinCenter(1.5f); + tableDqt1.setQBin(new float[] { 1.0f, 2.0f, 3.0f }); + tableDqt1.setZBin(new float[] { 4.0f, 5.0f, 6.0f }); + tableDqt1.setDqtDef(2); + + WsqTableDqt tableDqt2 = new WsqTableDqt(); + tableDqt2.setBinCenter(1.5f); + tableDqt2.setQBin(new float[] { 1.0f, 2.0f, 3.0f }); + tableDqt2.setZBin(new float[] { 4.0f, 5.0f, 6.0f }); + tableDqt2.setDqtDef(2); + + assertTrue(tableDqt1.equals(tableDqt2), "Two equal objects should be equal"); + } + + @Test + void testWsqTableDqtEquals_NonEqualObjects() { + WsqTableDqt tableDqt1 = new WsqTableDqt(); + tableDqt1.setBinCenter(1.5f); + tableDqt1.setDqtDef(1); + + WsqTableDqt tableDqt2 = new WsqTableDqt(); + tableDqt2.setBinCenter(2.5f); // Different value + tableDqt2.setDqtDef(2); + + assertFalse(tableDqt1.equals(tableDqt2), "Different objects should not be equal"); + } + + @Test + void testWsqTableDqtHashCode_EqualObjects() { + WsqTableDqt tableDqt1 = new WsqTableDqt(); + tableDqt1.setBinCenter(1.5f); + tableDqt1.setQBin(new float[] { 1.0f, 2.0f, 3.0f }); + tableDqt1.setZBin(new float[] { 4.0f, 5.0f, 6.0f }); + tableDqt1.setDqtDef(2); + + WsqTableDqt tableDqt2 = new WsqTableDqt(); + tableDqt2.setBinCenter(1.5f); + tableDqt2.setQBin(new float[] { 1.0f, 2.0f, 3.0f }); + tableDqt2.setZBin(new float[] { 4.0f, 5.0f, 6.0f }); + tableDqt2.setDqtDef(2); + + assertEquals(tableDqt1.hashCode(), tableDqt2.hashCode(), "Equal objects should have the same hash code"); + } + + @Test + void testWsqTableDqtHashCode_NonEqualObjects() { + WsqTableDqt tableDqt1 = new WsqTableDqt(); + tableDqt1.setBinCenter(1.5f); + + WsqTableDqt tableDqt2 = new WsqTableDqt(); + tableDqt2.setBinCenter(2.5f); // Different value + + assertNotEquals(tableDqt1.hashCode(), tableDqt2.hashCode(), + "Non-equal objects should have different hash codes"); + } + + @Test + void testWsqTableDqtCanEqual() { + WsqTableDqt tableDqt = new WsqTableDqt(); + assertTrue(tableDqt.canEqual(new WsqTableDqt()), "Should be able to equal another WsqTableDqt"); + assertFalse(tableDqt.canEqual(new Object()), "Should not be able to equal a non-WsqTableDqt"); + } + + @Test + void testWsqTableDttEquals_SameObject() { + WsqTableDtt tableDtt = new WsqTableDtt(); + assertTrue(tableDtt.equals(tableDtt), "Should be equal to itself"); + } + + @Test + void testWsqTableDttEquals_EqualObjects() { + WsqTableDtt tableDtt1 = new WsqTableDtt(); + tableDtt1.setLowFilter(new float[] { 1.0f, 2.0f, 3.0f }); + tableDtt1.setHighFilter(new float[] { 4.0f, 5.0f, 6.0f }); + tableDtt1.setLowSize(2); + tableDtt1.setHighSize(3); + tableDtt1.setLowDef(1); + tableDtt1.setHighDef(2); + + WsqTableDtt tableDtt2 = new WsqTableDtt(); + tableDtt2.setLowFilter(new float[] { 1.0f, 2.0f, 3.0f }); + tableDtt2.setHighFilter(new float[] { 4.0f, 5.0f, 6.0f }); + tableDtt2.setLowSize(2); + tableDtt2.setHighSize(3); + tableDtt2.setLowDef(1); + tableDtt2.setHighDef(2); + + assertTrue(tableDtt1.equals(tableDtt2), "Two equal objects should be equal"); + } + + @Test + void testWsqTableDttEquals_NonEqualObjects() { + WsqTableDtt tableDtt1 = new WsqTableDtt(); + tableDtt1.setLowSize(2); + + WsqTableDtt tableDtt2 = new WsqTableDtt(); + tableDtt2.setLowSize(3); // Different value + + assertFalse(tableDtt1.equals(tableDtt2), "Different objects should not be equal"); + } + + @Test + void testWsqTableDttHashCode_EqualObjects() { + WsqTableDtt tableDtt1 = new WsqTableDtt(); + tableDtt1.setLowFilter(new float[] { 1.0f, 2.0f }); + tableDtt1.setHighFilter(new float[] { 3.0f, 4.0f }); + tableDtt1.setLowSize(2); + tableDtt1.setHighSize(2); + tableDtt1.setLowDef(1); + tableDtt1.setHighDef(2); + + WsqTableDtt tableDtt2 = new WsqTableDtt(); + tableDtt2.setLowFilter(new float[] { 1.0f, 2.0f }); + tableDtt2.setHighFilter(new float[] { 3.0f, 4.0f }); + tableDtt2.setLowSize(2); + tableDtt2.setHighSize(2); + tableDtt2.setLowDef(1); + tableDtt2.setHighDef(2); + + assertEquals(tableDtt1.hashCode(), tableDtt2.hashCode(), "Equal objects should have the same hash code"); + } + + @Test + void testWsqTableDttHashCode_NonEqualObjects() { + WsqTableDtt tableDtt1 = new WsqTableDtt(); + tableDtt1.setLowSize(2); + + WsqTableDtt tableDtt2 = new WsqTableDtt(); + tableDtt2.setLowSize(3); // Different value + + assertNotEquals(tableDtt1.hashCode(), tableDtt2.hashCode(), + "Non-equal objects should have different hash codes"); + } + + @Test + void testWsqTableDttCanEqual() { + WsqTableDtt tableDtt = new WsqTableDtt(); + assertTrue(tableDtt.canEqual(new WsqTableDtt()), "Should be able to equal another WsqTableDtt"); + assertFalse(tableDtt.canEqual(new Object()), "Should not be able to equal a non-WsqTableDtt"); + } + + @Test + void testWsqWavletTreeEquals_SameObject() { + WsqWavletTree tree = new WsqWavletTree(); + assertTrue(tree.equals(tree), "Should be equal to itself"); + } + + @Test + void testWsqWavletTreeEquals_EqualObjects() { + WsqWavletTree tree1 = new WsqWavletTree(); + tree1.setX(1); + tree1.setY(2); + tree1.setLenX(3); + tree1.setLenY(4); + tree1.setInvRow(5); + tree1.setInvCol(6); + + WsqWavletTree tree2 = new WsqWavletTree(); + tree2.setX(1); + tree2.setY(2); + tree2.setLenX(3); + tree2.setLenY(4); + tree2.setInvRow(5); + tree2.setInvCol(6); + + assertTrue(tree1.equals(tree2), "Two equal objects should be equal"); + } + + @Test + void testWsqWavletTreeEquals_NonEqualObjects() { + WsqWavletTree tree1 = new WsqWavletTree(); + tree1.setX(1); + tree1.setY(2); + tree1.setLenX(3); + tree1.setLenY(4); + tree1.setInvRow(5); + tree1.setInvCol(6); + + WsqWavletTree tree2 = new WsqWavletTree(); + tree2.setX(2); + tree2.setY(2); + tree2.setLenX(3); + tree2.setLenY(4); + tree2.setInvRow(5); + tree2.setInvCol(6); + + assertFalse(tree1.equals(tree2), "Different objects should not be equal"); + } + + @Test + void testWsqWavletTreeHashCode_EqualObjects() { + WsqWavletTree tree1 = new WsqWavletTree(); + tree1.setX(1); + tree1.setY(2); + tree1.setLenX(3); + tree1.setLenY(4); + tree1.setInvRow(5); + tree1.setInvCol(6); + + WsqWavletTree tree2 = new WsqWavletTree(); + tree2.setX(1); + tree2.setY(2); + tree2.setLenX(3); + tree2.setLenY(4); + tree2.setInvRow(5); + tree2.setInvCol(6); + + assertEquals(tree1.hashCode(), tree2.hashCode(), "Equal objects should have the same hash code"); + } + + @Test + void testWsqWavletTreeHashCode_NonEqualObjects() { + WsqWavletTree tree1 = new WsqWavletTree(); + tree1.setX(1); + tree1.setY(2); + tree1.setLenX(3); + tree1.setLenY(4); + tree1.setInvRow(5); + tree1.setInvCol(6); + + WsqWavletTree tree2 = new WsqWavletTree(); + tree2.setX(2); + tree2.setY(2); + tree2.setLenX(3); + tree2.setLenY(4); + tree2.setInvRow(5); + tree2.setInvCol(6); + + assertNotEquals(tree1.hashCode(), tree2.hashCode(), "Non-equal objects should have different hash codes"); + } + + @Test + void testWsqWavletTreeCanEqual() { + WsqWavletTree tree = new WsqWavletTree(); + assertTrue(tree.canEqual(new WsqWavletTree()), "Should be able to equal another WsqWavletTree"); + assertFalse(tree.canEqual(new Object()), "Should not be able to equal a non-WsqWavletTree"); + } + + @Test + void testBioEquals_SameObject() { + Bio bio = new Bio(); + assertTrue(bio.equals(bio), "Should be equal to itself"); + } + + @Test + void testBioEquals_EqualObjects() { + Bio bio1 = new Bio(); + bio1.setStart(0); + bio1.setEnd(10); + bio1.setBpIndex(5); + bio1.setBp(new byte[] { 1, 2, 3 }); + bio1.setBuf(12345L); + bio1.setCt(8); + + Bio bio2 = new Bio(); + bio2.setStart(0); + bio2.setEnd(10); + bio2.setBpIndex(5); + bio2.setBp(new byte[] { 1, 2, 3 }); + bio2.setBuf(12345L); + bio2.setCt(8); + + assertTrue(bio1.equals(bio2), "Two equal objects should be equal"); + } + + @Test + void testBioEquals_NonEqualObjects() { + Bio bio1 = new Bio(); + bio1.setStart(0); + + Bio bio2 = new Bio(); + bio2.setStart(1); // Different value + + assertFalse(bio1.equals(bio2), "Different objects should not be equal"); + } + + @Test + void testBioHashCode_EqualObjects() { + Bio bio1 = new Bio(); + bio1.setStart(0); + bio1.setEnd(10); + bio1.setBpIndex(5); + bio1.setBp(new byte[] { 1, 2, 3 }); + bio1.setBuf(12345L); + bio1.setCt(8); + + Bio bio2 = new Bio(); + bio2.setStart(0); + bio2.setEnd(10); + bio2.setBpIndex(5); + bio2.setBp(new byte[] { 1, 2, 3 }); + bio2.setBuf(12345L); + bio2.setCt(8); + + assertEquals(bio1.hashCode(), bio2.hashCode(), "Equal objects should have the same hash code"); + } + + @Test + void testBioHashCode_NonEqualObjects() { + Bio bio1 = new Bio(); + bio1.setStart(0); + + Bio bio2 = new Bio(); + bio2.setStart(1); // Different value + + assertNotEquals(bio1.hashCode(), bio2.hashCode(), "Non-equal objects should have different hash codes"); + } + + @Test + void testBioCanEqual() { + Bio bio = new Bio(); + assertTrue(bio.canEqual(new Bio()), "Should be able to equal another Bio"); + assertFalse(bio.canEqual(new Object()), "Should not be able to equal a non-Bio"); + } + + @Test + void testCioEquals_SameObject() { + Cio cio = new Cio(); + assertTrue(cio.equals(cio), "Should be equal to itself"); + } + + @Test + void testCioEquals_EqualObjects() { + Cio cio1 = new Cio(); + cio1.setOpenMode(1); + cio1.setLength(100); + cio1.setStart(0); + cio1.setEnd(100); + cio1.setBpIndex(0); + cio1.setBuffer(new byte[] { 1, 2, 3 }); + cio1.setCodecContextInfo(new CodecContextInfo()); // Assume a proper constructor + + Cio cio2 = new Cio(); + cio2.setOpenMode(1); + cio2.setLength(100); + cio2.setStart(0); + cio2.setEnd(100); + cio2.setBpIndex(0); + cio2.setBuffer(new byte[] { 1, 2, 3 }); + cio2.setCodecContextInfo(new CodecContextInfo()); // Assume a proper constructor + + assertTrue(cio1.equals(cio2), "Two equal objects should be equal"); + } + + @Test + void testCioEquals_NonEqualObjects() { + Cio cio1 = new Cio(); + cio1.setOpenMode(1); + + Cio cio2 = new Cio(); + cio2.setOpenMode(2); // Different value + + assertFalse(cio1.equals(cio2), "Different objects should not be equal"); + } + + @Test + void testCioHashCode_EqualObjects() { + Cio cio1 = new Cio(); + cio1.setOpenMode(1); + cio1.setLength(100); + cio1.setStart(0); + cio1.setEnd(100); + cio1.setBpIndex(0); + cio1.setBuffer(new byte[] { 1, 2, 3 }); + cio1.setCodecContextInfo(new CodecContextInfo()); // Assume a proper constructor + + Cio cio2 = new Cio(); + cio2.setOpenMode(1); + cio2.setLength(100); + cio2.setStart(0); + cio2.setEnd(100); + cio2.setBpIndex(0); + cio2.setBuffer(new byte[] { 1, 2, 3 }); + cio2.setCodecContextInfo(new CodecContextInfo()); // Assume a proper constructor + + assertEquals(cio1.hashCode(), cio2.hashCode(), "Equal objects should have the same hash code"); + } + + @Test + void testCioHashCode_NonEqualObjects() { + Cio cio1 = new Cio(); + cio1.setOpenMode(1); + + Cio cio2 = new Cio(); + cio2.setOpenMode(2); // Different value + + assertNotEquals(cio1.hashCode(), cio2.hashCode(), "Non-equal objects should have different hash codes"); + } + + @Test + void testCioCanEqual() { + Cio cio = new Cio(); + assertTrue(cio.canEqual(new Cio()), "Should be able to equal another Cio"); + assertFalse(cio.canEqual(new Object()), "Should not be able to equal a non-Cio"); + } + + @Test + void testCodecContextInfoEquals_SameObject() { + CodecContextInfo codecContextInfo = new CodecContextInfo(); + assertTrue(codecContextInfo.equals(codecContextInfo), "Should be equal to itself"); + } + + @Test + void testCodecContextInfoEquals_EqualObjects() { + CodecContextInfo codecContextInfo1 = new CodecContextInfo(); + codecContextInfo1.setContextInfo(new ContextInfo()); // Assume a proper constructor or setter + + CodecContextInfo codecContextInfo2 = new CodecContextInfo(); + codecContextInfo2.setContextInfo(new ContextInfo()); // Assume a proper constructor or setter + + assertTrue(codecContextInfo1.equals(codecContextInfo2), "Two equal objects should be equal"); + } + + @Test + void testCodecContextInfoHashCode_EqualObjects() { + CodecContextInfo codecContextInfo1 = new CodecContextInfo(); + codecContextInfo1.setContextInfo(new ContextInfo()); // Assume a proper constructor or setter + + CodecContextInfo codecContextInfo2 = new CodecContextInfo(); + codecContextInfo2.setContextInfo(new ContextInfo()); // Assume a proper constructor or setter + + assertEquals(codecContextInfo1.hashCode(), codecContextInfo2.hashCode(), + "Equal objects should have the same hash code"); + } + + @Test + void testCodecContextInfoCanEqual() { + CodecContextInfo codecContextInfo = new CodecContextInfo(); + assertTrue(codecContextInfo.canEqual(new CodecContextInfo()), + "Should be able to equal another CodecContextInfo"); + assertFalse(codecContextInfo.canEqual(new Object()), "Should not be able to equal a non-CodecContextInfo"); + } + + @Test + void testCodeStreamInfoEqualsAndHashCode() { + CodeStreamInfo info1 = new CodeStreamInfo(); + info1.setDistortionMax(1.0); + info1.setPacketNo(10); + info1.setIndexWrite(5); + info1.setImageWidth(1024); + info1.setImageHeight(768); + info1.setNoOfDecompositionComps(new int[]{1, 2, 3}); + + CodeStreamInfo info2 = new CodeStreamInfo(); + info2.setDistortionMax(1.0); + info2.setPacketNo(10); + info2.setIndexWrite(5); + info2.setImageWidth(1024); + info2.setImageHeight(768); + info2.setNoOfDecompositionComps(new int[]{1, 2, 3}); + + assertEquals(info1, info2); + assertEquals(info1.hashCode(), info2.hashCode()); + } + + @Test + void testCodeStreamInfoCanEqual() { + CodeStreamInfo info = new CodeStreamInfo(); + assertTrue(info.canEqual(new CodeStreamInfo())); + assertFalse(info.canEqual(new Object())); + } + + @Test + void testCodeStreamInfoToString() { + CodeStreamInfo info = new CodeStreamInfo(); + info.setDistortionMax(2.5); + info.setPacketNo(20); + info.setImageWidth(800); + info.setImageHeight(600); + info.setNoOfDecompositionComps(new int[]{2, 4, 6}); + + String toStringOutput = info.toString(); + assertTrue(toStringOutput.contains("distortionMax=2.5")); + assertTrue(toStringOutput.contains("packetNo=20")); + assertTrue(toStringOutput.contains("imageWidth=800")); + assertTrue(toStringOutput.contains("imageHeight=600")); + assertTrue(toStringOutput.contains("noOfDecompositionComps=[2, 4, 6]")); + } + + @Test + void testCodingParametersEqualsAndHashCode() { + CodingParameters params1 = new CodingParameters(); + CodingParameters params2 = new CodingParameters(); + + // Set identical fields + params1.setMaxCompSize(10); + params1.setImageSize(200); + params1.setTilePartOn(1); + // Set more fields as needed... + + params2.setMaxCompSize(10); + params2.setImageSize(200); + params2.setTilePartOn(1); + // Set the same fields as params1... + + assertEquals(params1, params2); + assertEquals(params1.hashCode(), params2.hashCode()); + + // Change a field in params2 + params2.setMaxCompSize(20); + assertNotEquals(params1, params2); + } + + @Test + void testCodingParametersCanEqual() { + CodingParameters params = new CodingParameters(); + assertTrue(params.canEqual(new CodingParameters())); + assertFalse(params.canEqual(new Object())); + } + + @Test + void testCodingParametersToString() { + CodingParameters params = new CodingParameters(); + params.setMaxCompSize(10); + params.setImageSize(200); + String expectedString = "CodingParameters"; + assertEquals(params.toString().contains(expectedString), true); + } + + @Test + void testCompressionParametersEqualsAndHashCode() { + CompressionParameters params1 = new CompressionParameters(); + CompressionParameters params2 = new CompressionParameters(); + + // Set identical fields + params1.setTileSizeOn(1); + params1.setCpTileX0(10); + params1.setCpTileY0(20); + // Set more fields as needed... + + params2.setTileSizeOn(1); + params2.setCpTileX0(10); + params2.setCpTileY0(20); + // Set identical fields as params1... + + assertEquals(params1, params2); + assertEquals(params1.hashCode(), params2.hashCode()); + + // Change a field in params2 + params2.setCpTileY0(30); + + assertNotEquals(params1, params2); + assertNotEquals(params1.hashCode(), params2.hashCode()); + } + + @Test + void testCompressionParametersToString() { + CompressionParameters params = new CompressionParameters(); + params.setTileSizeOn(1); + params.setCpTileX0(10); + params.setCpTileY0(20); + // Set more fields as needed... + + String expected = "CompressionParameters(tileSizeOn=1, cpTileX0=10, cpTileY0=20, ...)"; + // Ensure to construct the expected output as per the toString method. + assertTrue(params.toString().contains("tileSizeOn=1")); + assertTrue(params.toString().contains("cpTileX0=10")); + assertTrue(params.toString().contains("cpTileY0=20")); + } + + @Test + void testCompressionParametersCanEqual() { + CompressionParameters params = new CompressionParameters(); + assertTrue(params.canEqual(new CompressionParameters())); // Should return true for the same type + + Object nonParamsObject = new Object(); + assertFalse(params.canEqual(nonParamsObject)); // Should return false for a different type + } + + @Test + void testContextInfoEqualsAndHashCode() { + ContextInfo context1 = new ContextInfo(); + ContextInfo context2 = new ContextInfo(); + + // Set identical fields + context1.setIsDecompressor(1); + context1.setClientData("Data"); + context1.setCodecFormat(JP2CodecFormat.CODEC_JP2); + // Set other fields as needed... + + context2.setIsDecompressor(1); + context2.setClientData("Data"); + context2.setCodecFormat(JP2CodecFormat.CODEC_JP2); + // Set other fields to match context1... + + assertEquals(context1, context2); + assertEquals(context1.hashCode(), context2.hashCode()); + + // Change a field in context2 + context2.setIsDecompressor(2); + + assertNotEquals(context1, context2); + assertNotEquals(context1.hashCode(), context2.hashCode()); + } + + @Test + void testContextInfoCanEqual() { + ContextInfo context = new ContextInfo(); + assertTrue(context.canEqual(new ContextInfo())); // Same type, should return true + + Object nonContextObject = new Object(); + assertFalse(context.canEqual(nonContextObject)); // Different type, should return false + } + + @Test + void testContextInfoToString() { + ContextInfo context = new ContextInfo(); + context.setIsDecompressor(1); + context.setClientData("Data"); + + String toStringOutput = context.toString(); + assertTrue(toStringOutput.contains("isDecompressor=1")); + assertTrue(toStringOutput.contains("clientData=Data")); + } + + @Test + void testDecoderFunctionInfoEqualsAndHashCode() { + DecoderFunctionInfo decoder1 = new DecoderFunctionInfo(1, 2, "FunctionA"); + DecoderFunctionInfo decoder2 = new DecoderFunctionInfo(1, 2, "FunctionA"); + + assertEquals(decoder1, decoder2); + assertEquals(decoder1.hashCode(), decoder2.hashCode()); + + // Change a field in decoder2 + decoder2.setStates(3); + assertNotEquals(decoder1, decoder2); + assertNotEquals(decoder1.hashCode(), decoder2.hashCode()); + } + + @Test + void testDecoderFunctionInfoCanEqual() { + DecoderFunctionInfo decoder = new DecoderFunctionInfo(1, 2, "FunctionA"); + assertTrue(decoder.canEqual(new DecoderFunctionInfo(2, 3, "FunctionB"))); // Same type, should return true + + Object nonDecoderObject = new Object(); + assertFalse(decoder.canEqual(nonDecoderObject)); // Different type, should return false + } + + @Test + void testDecoderFunctionInfoToString() { + DecoderFunctionInfo decoder = new DecoderFunctionInfo(1, 2, "FunctionA"); + String toStringOutput = decoder.toString(); + assertTrue(toStringOutput.contains("id=1")); + assertTrue(toStringOutput.contains("states=2")); + assertTrue(toStringOutput.contains("j2kFunctionName=FunctionA")); + } + + @Test + void testDecompressionParametersEqualsAndHashCode() { + DecompressionParameters params1 = new DecompressionParameters(); + params1.setCpReduce(1); + params1.setCpLayer(2); + params1.setDecodeFormat(0); + params1.setCodecFormat(1); + params1.setJpwlCorrect(1); + params1.setJpwlExpComps(3); + params1.setJpwlMaxTiles(5); + params1.setCpLimitDecoding(LimitDecoding.NO_LIMITATION); + + DecompressionParameters params2 = new DecompressionParameters(); + params2.setCpReduce(1); + params2.setCpLayer(2); + params2.setDecodeFormat(0); + params2.setCodecFormat(1); + params2.setJpwlCorrect(1); + params2.setJpwlExpComps(3); + params2.setJpwlMaxTiles(5); + params2.setCpLimitDecoding(LimitDecoding.NO_LIMITATION); + + assertEquals(params1, params2); + assertEquals(params1.hashCode(), params2.hashCode()); + + // Change a field in params2 + params2.setCpLayer(3); + assertNotEquals(params1, params2); + assertNotEquals(params1.hashCode(), params2.hashCode()); + } + + @Test + void testDecompressionParametersCanEqual() { + DecompressionParameters params = new DecompressionParameters(); + assertTrue(params.canEqual(new DecompressionParameters())); // Same type, should return true + + Object nonParamsObject = new Object(); + assertFalse(params.canEqual(nonParamsObject)); // Different type, should return false + } + + @Test + void testDecompressionParametersToString() { + DecompressionParameters params = new DecompressionParameters(); + params.setCpReduce(1); + params.setCpLayer(2); + String toStringOutput = params.toString(); + assertTrue(toStringOutput.contains("cpReduce=1")); + assertTrue(toStringOutput.contains("cpLayer=2")); + } + + @Test + void testDwtEqualsAndHashCode() { + Dwt dwt1 = new Dwt(); + dwt1.setMemIndex(1); + dwt1.setMem(new int[] { 1, 2, 3 }); + dwt1.setDn(4); + dwt1.setSn(5); + dwt1.setCas(6); + + Dwt dwt2 = new Dwt(); + dwt2.setMemIndex(1); + dwt2.setMem(new int[] { 1, 2, 3 }); + dwt2.setDn(4); + dwt2.setSn(5); + dwt2.setCas(6); + + assertEquals(dwt1, dwt2); + assertEquals(dwt1.hashCode(), dwt2.hashCode()); + + // Change a field in dwt2 + dwt2.setMemIndex(2); + assertNotEquals(dwt1, dwt2); + assertNotEquals(dwt1.hashCode(), dwt2.hashCode()); + } + + @Test + void testDwtCanEqual() { + Dwt dwt = new Dwt(); + assertTrue(dwt.canEqual(new Dwt())); // Same type, should return true + + Object nonDwtObject = new Object(); + assertFalse(dwt.canEqual(nonDwtObject)); // Different type, should return false + } + + @Test + void testDwtToString() { + Dwt dwt = new Dwt(); + dwt.setMemIndex(1); + dwt.setDn(4); + dwt.setSn(5); + dwt.setCas(6); + String toStringOutput = dwt.toString(); + assertTrue(toStringOutput.contains("memIndex=1")); + assertTrue(toStringOutput.contains("dn=4")); + assertTrue(toStringOutput.contains("sn=5")); + assertTrue(toStringOutput.contains("cas=6")); + } + + @Test + void testDwtV4EqualsAndHashCode() { + V4[] wavelet1 = { new V4(), new V4() }; // Assuming V4 has a default constructor + DwtV4 dwtV41 = new DwtV4(); + dwtV41.setWavelet(wavelet1); + dwtV41.setDn(4); + dwtV41.setSn(5); + dwtV41.setCas(6); + + V4[] wavelet2 = { new V4(), new V4() }; // Same content as wavelet1 + DwtV4 dwtV42 = new DwtV4(); + dwtV42.setWavelet(wavelet2); + dwtV42.setDn(4); + dwtV42.setSn(5); + dwtV42.setCas(6); + + assertEquals(dwtV41, dwtV42); + assertEquals(dwtV41.hashCode(), dwtV42.hashCode()); + + // Change a field in dwtV42 + dwtV42.setDn(10); + assertNotEquals(dwtV41, dwtV42); + assertNotEquals(dwtV41.hashCode(), dwtV42.hashCode()); + } + + @Test + void testDwtV4CanEqual() { + DwtV4 dwtV4 = new DwtV4(); + assertTrue(dwtV4.canEqual(new DwtV4())); // Same type, should return true + + Object nonDwtV4Object = new Object(); + assertFalse(dwtV4.canEqual(nonDwtV4Object)); // Different type, should return false + } + + @Test + void testDwtV4ToString() { + DwtV4 dwtV4 = new DwtV4(); + dwtV4.setDn(4); + dwtV4.setSn(5); + dwtV4.setCas(6); + String toStringOutput = dwtV4.toString(); + assertTrue(toStringOutput.contains("dn=4")); + assertTrue(toStringOutput.contains("sn=5")); + assertTrue(toStringOutput.contains("cas=6")); + } + + @Test + void testJ2KEqualsAndHashCode() { + J2K j2k1 = new J2K(); + j2k1.setState(1); + j2k1.setCurTileNo(2); + j2k1.setTilePartNo(3); + j2k1.setCurTilePartNo(4); + j2k1.setTlmStart(5); + j2k1.setTotalNoOfTilePart(6); + j2k1.setEot(7); + j2k1.setSotStart(8); + j2k1.setSodStart(9); + j2k1.setPosCorrection(10); + j2k1.setEndCode(11); + + // Assuming CodecContextInfo and other required classes are implemented + CodecContextInfo codecContextInfo = new CodecContextInfo(); + j2k1.setCodecContextInfo(codecContextInfo); + + // Set other necessary fields + + J2K j2k2 = new J2K(); + j2k2.setState(1); + j2k2.setCurTileNo(2); + j2k2.setTilePartNo(3); + j2k2.setCurTilePartNo(4); + j2k2.setTlmStart(5); + j2k2.setTotalNoOfTilePart(6); + j2k2.setEot(7); + j2k2.setSotStart(8); + j2k2.setSodStart(9); + j2k2.setPosCorrection(10); + j2k2.setEndCode(11); + j2k2.setCodecContextInfo(codecContextInfo); + + assertEquals(j2k1, j2k2); + assertEquals(j2k1.hashCode(), j2k2.hashCode()); + + // Change a field in j2k2 + j2k2.setCurTileNo(20); + assertNotEquals(j2k1, j2k2); + assertNotEquals(j2k1.hashCode(), j2k2.hashCode()); + } + + @Test + void testJ2KCanEqual() { + J2K j2k = new J2K(); + assertTrue(j2k.canEqual(new J2K())); // Same type, should return true + + Object nonJ2KObject = new Object(); + assertFalse(j2k.canEqual(nonJ2KObject)); // Different type, should return false + } + + @Test + void testJ2KToString() { + J2K j2k = new J2K(); + j2k.setState(1); + j2k.setCurTileNo(2); + j2k.setTilePartNo(3); + j2k.setCurTilePartNo(4); + String toStringOutput = j2k.toString(); + assertTrue(toStringOutput.contains("state=1")); + assertTrue(toStringOutput.contains("curTileNo=2")); + assertTrue(toStringOutput.contains("tilePartNo=3")); + assertTrue(toStringOutput.contains("curTilePartNo=4")); + } + + @Test + void testJ2KProgressionOrderEqualsAndHashCode() { + char[] name1 = { 'R', 'G', 'B', 'A' }; + char[] name2 = { 'R', 'G', 'B', 'A' }; + J2KProgressionOrder order1 = new J2KProgressionOrder(ProgressionOrder.RLCP, name1); + J2KProgressionOrder order2 = new J2KProgressionOrder(ProgressionOrder.RLCP, name2); + + assertEquals(order1, order2); + assertEquals(order1.hashCode(), order2.hashCode()); + + // Change a field in order2 + order2.setProgressionOrder(ProgressionOrder.RPCL); + assertNotEquals(order1, order2); + assertNotEquals(order1.hashCode(), order2.hashCode()); + } + + @Test + void testJ2KProgressionOrderCanEqual() { + J2KProgressionOrder order = new J2KProgressionOrder(ProgressionOrder.RLCP, new char[4]); + assertTrue(order.canEqual(new J2KProgressionOrder(ProgressionOrder.RLCP, new char[4]))); + + Object nonJ2KProgressionOrder = new Object(); + assertFalse(order.canEqual(nonJ2KProgressionOrder)); + } + + @Test + void testJ2KProgressionOrderToString() { + char[] progressionName = { 'R', 'G', 'B', 'A' }; + J2KProgressionOrder order = new J2KProgressionOrder(ProgressionOrder.RLCP, progressionName); + String toStringOutput = order.toString(); + assertTrue(toStringOutput.contains("progressionOrder=RLCP")); + assertTrue(toStringOutput.contains("progressionName=[R, G, B, A]")); + } + + @Test + void testJP2EqualsAndHashCode() { + long[] cl1 = { 1, 2, 3 }; + long[] cl2 = { 1, 2, 3 }; + long[] offset1 = { 100 }; + long[] offset2 = { 100 }; + long[] length1 = { 200 }; + long[] length2 = { 200 }; + + JP2 jp2a = new JP2(); + jp2a.setWidth(1920); + jp2a.setHeight(1080); + jp2a.setNoOfComps(3); + jp2a.setBpc(8); + jp2a.setCl(cl1); + jp2a.setJ2kCodestreamOffset(offset1); + jp2a.setJ2kCodestreamLength(length1); + + JP2 jp2b = new JP2(); + jp2b.setWidth(1920); + jp2b.setHeight(1080); + jp2b.setNoOfComps(3); + jp2b.setBpc(8); + jp2b.setCl(cl2); + jp2b.setJ2kCodestreamOffset(offset2); + jp2b.setJ2kCodestreamLength(length2); + + assertEquals(jp2a, jp2b); + assertEquals(jp2a.hashCode(), jp2b.hashCode()); + + // Change a field in jp2b + jp2b.setWidth(1280); + assertNotEquals(jp2a, jp2b); + assertNotEquals(jp2a.hashCode(), jp2b.hashCode()); + } + + @Test + void testJP2CanEqual() { + JP2 jp2 = new JP2(); + assertTrue(jp2.canEqual(new JP2())); + + Object nonJP2 = new Object(); + assertFalse(jp2.canEqual(nonJP2)); + } + + @Test + void testJP2ToString() { + JP2 jp2 = new JP2(); + jp2.setWidth(1920); + jp2.setHeight(1080); + String toStringOutput = jp2.toString(); + assertTrue(toStringOutput.contains("width=1920")); + assertTrue(toStringOutput.contains("height=1080")); + } + + @Test + void testJP2BoxEqualsAndHashCode() { + JP2Box box1 = new JP2Box(); + box1.setLength(100); + box1.setType(1); + box1.setInitPosition(50); + + JP2Box box2 = new JP2Box(); + box2.setLength(100); + box2.setType(1); + box2.setInitPosition(50); + + assertEquals(box1, box2); + assertEquals(box1.hashCode(), box2.hashCode()); + + // Change a field in box2 + box2.setLength(200); + assertNotEquals(box1, box2); + assertNotEquals(box1.hashCode(), box2.hashCode()); + } + + @Test + void testJP2BoxCanEqual() { + JP2Box box = new JP2Box(); + assertTrue(box.canEqual(new JP2Box())); + + Object nonJP2Box = new Object(); + assertFalse(box.canEqual(nonJP2Box)); + } + + @Test + void testJP2BoxToString() { + JP2Box box = new JP2Box(); + box.setLength(100); + box.setType(1); + box.setInitPosition(50); + String toStringOutput = box.toString(); + assertTrue(toStringOutput.contains("length=100")); + assertTrue(toStringOutput.contains("type=1")); + assertTrue(toStringOutput.contains("initPosition=50")); + } + + @Test + void testJP2ComponentEqualsAndHashCode() { + JP2Component comp1 = new JP2Component(); + comp1.setDepth(8); + comp1.setSgnd(0); + comp1.setBpcc(3); + + JP2Component comp2 = new JP2Component(); + comp2.setDepth(8); + comp2.setSgnd(0); + comp2.setBpcc(3); + + assertEquals(comp1, comp2); + assertEquals(comp1.hashCode(), comp2.hashCode()); + + // Change a field in comp2 + comp2.setDepth(10); + assertNotEquals(comp1, comp2); + assertNotEquals(comp1.hashCode(), comp2.hashCode()); + } + + @Test + void testJP2ComponentCanEqual() { + JP2Component comp = new JP2Component(); + assertTrue(comp.canEqual(new JP2Component())); + + Object nonJP2Component = new Object(); + assertFalse(comp.canEqual(nonJP2Component)); + } + + @Test + void testJP2ComponentToString() { + JP2Component comp = new JP2Component(); + comp.setDepth(8); + comp.setSgnd(0); + comp.setBpcc(3); + String toStringOutput = comp.toString(); + assertTrue(toStringOutput.contains("depth=8")); + assertTrue(toStringOutput.contains("sgnd=0")); + assertTrue(toStringOutput.contains("bpcc=3")); + } + + @Test + void testJP2ResolutionBoxEqualsAndHashCode() { + JP2ResolutionBox box1 = new JP2ResolutionBox(); + box1.setResolutionBoxType(1); + box1.setVerticalNumerator(720); + box1.setVerticalDenominator(480); + box1.setHorizontalNumerator(1280); + box1.setHorizontalDenominator(720); + box1.setVerticalExponent(2); + box1.setHorizontalExponent(2); + box1.setVerticalResolution(480); + box1.setHorizontalResolution(720); + + JP2ResolutionBox box2 = new JP2ResolutionBox(); + box2.setResolutionBoxType(1); + box2.setVerticalNumerator(720); + box2.setVerticalDenominator(480); + box2.setHorizontalNumerator(1280); + box2.setHorizontalDenominator(720); + box2.setVerticalExponent(2); + box2.setHorizontalExponent(2); + box2.setVerticalResolution(480); + box2.setHorizontalResolution(720); + + assertEquals(box1, box2); + assertEquals(box1.hashCode(), box2.hashCode()); + + // Change a field in box2 + box2.setVerticalNumerator(1080); + assertNotEquals(box1, box2); + assertNotEquals(box1.hashCode(), box2.hashCode()); + } + + @Test + void testJP2ResolutionBoxCanEqual() { + JP2ResolutionBox box = new JP2ResolutionBox(); + assertTrue(box.canEqual(new JP2ResolutionBox())); + + Object nonJP2ResolutionBox = new Object(); + assertFalse(box.canEqual(nonJP2ResolutionBox)); + } + + @Test + void testJP2ResolutionBoxToString() { + JP2ResolutionBox box = new JP2ResolutionBox(); + box.setResolutionBoxType(1); + box.setVerticalNumerator(720); + box.setVerticalDenominator(480); + box.setHorizontalNumerator(1280); + box.setHorizontalDenominator(720); + box.setVerticalExponent(2); + box.setHorizontalExponent(2); + box.setVerticalResolution(480); + box.setHorizontalResolution(720); + String toStringOutput = box.toString(); + assertTrue(toStringOutput.contains("resolutionBoxType=1")); + assertTrue(toStringOutput.contains("verticalNumerator=720")); + assertTrue(toStringOutput.contains("verticalDenominator=480")); + assertTrue(toStringOutput.contains("horizontalNumerator=1280")); + assertTrue(toStringOutput.contains("horizontalDenominator=720")); + assertTrue(toStringOutput.contains("verticalExponent=2")); + assertTrue(toStringOutput.contains("horizontalExponent=2")); + assertTrue(toStringOutput.contains("verticalResolution=480")); + assertTrue(toStringOutput.contains("horizontalResolution=720")); + } + + @Test + void testJPTMessageHeaderEqualsAndHashCode() { + JPTMessageHeader header1 = new JPTMessageHeader(); + header1.setId(1L); + header1.setLastByte(255L); + header1.setClassId(100L); + header1.setCSnId(10L); + header1.setMsgOffset(0L); + header1.setMsgLength(1024L); + header1.setLayerNb(2L); + + JPTMessageHeader header2 = new JPTMessageHeader(); + header2.setId(1L); + header2.setLastByte(255L); + header2.setClassId(100L); + header2.setCSnId(10L); + header2.setMsgOffset(0L); + header2.setMsgLength(1024L); + header2.setLayerNb(2L); + + assertEquals(header1, header2); + assertEquals(header1.hashCode(), header2.hashCode()); + + // Change a field in header2 + header2.setLastByte(128L); + assertNotEquals(header1, header2); + assertNotEquals(header1.hashCode(), header2.hashCode()); + } + + @Test + void testJPTMessageHeaderCanEqual() { + JPTMessageHeader header = new JPTMessageHeader(); + assertTrue(header.canEqual(new JPTMessageHeader())); + + Object nonJPTMessageHeader = new Object(); + assertFalse(header.canEqual(nonJPTMessageHeader)); + } + + @Test + void testJPTMessageHeaderToString() { + JPTMessageHeader header = new JPTMessageHeader(); + header.setId(1L); + header.setLastByte(255L); + header.setClassId(100L); + header.setCSnId(10L); + header.setMsgOffset(0L); + header.setMsgLength(1024L); + header.setLayerNb(2L); + + String toStringOutput = header.toString(); + assertTrue(toStringOutput.contains("Id=1")); + assertTrue(toStringOutput.contains("lastByte=255")); + assertTrue(toStringOutput.contains("classId=100")); + assertTrue(toStringOutput.contains("cSnId=10")); + assertTrue(toStringOutput.contains("msgOffset=0")); + assertTrue(toStringOutput.contains("msgLength=1024")); + assertTrue(toStringOutput.contains("layerNb=2")); + } + + @Test + void testMarkerInfoEqualsAndHashCode() { + MarkerInfo marker1 = new MarkerInfo(); + marker1.setType(1); + marker1.setPosition(100); + marker1.setLength(50); + + MarkerInfo marker2 = new MarkerInfo(); + marker2.setType(1); + marker2.setPosition(100); + marker2.setLength(50); + + assertEquals(marker1, marker2); + assertEquals(marker1.hashCode(), marker2.hashCode()); + + // Change a field in marker2 + marker2.setLength(60); + assertNotEquals(marker1, marker2); + assertNotEquals(marker1.hashCode(), marker2.hashCode()); + } + + @Test + void testMarkerInfoCanEqual() { + MarkerInfo marker = new MarkerInfo(); + assertTrue(marker.canEqual(new MarkerInfo())); + + Object nonMarkerInfo = new Object(); + assertFalse(marker.canEqual(nonMarkerInfo)); + } + + @Test + void testMarkerInfoToString() { + MarkerInfo marker = new MarkerInfo(); + marker.setType(1); + marker.setPosition(100); + marker.setLength(50); + + String toStringOutput = marker.toString(); + assertTrue(toStringOutput.contains("type=1")); + assertTrue(toStringOutput.contains("position=100")); + assertTrue(toStringOutput.contains("length=50")); + } + + @Test + void testMQCoderEquals() { + MQCoder coder1 = new MQCoder(); + + // Set the same values for all fields + coder1.setC(100L); + coder1.setA(200L); + coder1.setCt(300L); + coder1.setBp(new byte[] { 1, 2, 3 }); + coder1.setBpIndex(1); + coder1.setStart(0); + coder1.setEnd(5); + coder1.setContextIndex(2); + coder1.setContexts(new MQCoderState[OpenJpegConstant.MQC_NUMCTXS]); + coder1.setCurrentContext(new MQCoderState(0x8000, 1, 0, 1)); + + MQCoder coder2 = new MQCoder(); + coder2.setC(100L); + coder2.setA(200L); + coder2.setCt(300L); + coder2.setBp(new byte[] { 1, 2, 3 }); + coder2.setBpIndex(1); + coder2.setStart(0); + coder2.setEnd(5); + coder2.setContextIndex(2); + coder2.setContexts(new MQCoderState[OpenJpegConstant.MQC_NUMCTXS]); + coder2.setCurrentContext(new MQCoderState(0x8000, 1, 0, 1)); + + // Test for equality + assertEquals(coder1, coder2); + assertEquals(coder1.hashCode(), coder2.hashCode()); + assertTrue(coder1.canEqual(coder2)); + + // Test for inequality by changing a field + coder2.setC(101L); + assertNotEquals(coder1, coder2); + } + + @Test + void testMQCoderHashCode() { + MQCoder coder1 = new MQCoder(); + MQCoder coder2 = new MQCoder(); + + coder1.setC(100L); + coder1.setA(200L); + coder1.setCt(300L); + coder1.setBp(new byte[] { 1, 2, 3 }); + + coder2.setC(100L); + coder2.setA(200L); + coder2.setCt(300L); + coder2.setBp(new byte[] { 1, 2, 3 }); + + assertEquals(coder1.hashCode(), coder2.hashCode()); + + // Change a field to ensure hash codes are different + coder2.setA(201L); + assertNotEquals(coder1.hashCode(), coder2.hashCode()); + } + + @Test + void testMQCoderToString() { + MQCoder coder = new MQCoder(); + coder.setC(100L); + coder.setA(200L); + coder.setCt(300L); + coder.setBp(new byte[]{1, 2, 3}); + coder.setBpIndex(1); + coder.setStart(0); + coder.setEnd(5); + coder.setContextIndex(2); + coder.setContexts(new MQCoderState[OpenJpegConstant.MQC_NUMCTXS]); + coder.setCurrentContext(new MQCoderState(0x8000, 1, 0, 1)); + + String toStringOutput = coder.toString(); + + // Assertions to check if the toString contains expected field values + assertTrue(toStringOutput.contains("c=100")); + assertTrue(toStringOutput.contains("a=200")); + assertTrue(toStringOutput.contains("ct=300")); + assertTrue(toStringOutput.contains("bp=[1, 2, 3]")); + assertTrue(toStringOutput.contains("bpIndex=1")); + assertTrue(toStringOutput.contains("start=0")); + assertTrue(toStringOutput.contains("end=5")); + assertTrue(toStringOutput.contains("contextIndex=2")); + assertTrue(toStringOutput.contains("contexts=" + Arrays.toString(new MQCoderState[OpenJpegConstant.MQC_NUMCTXS]))); + assertTrue(toStringOutput.contains("currentContext=" + coder.getCurrentContext().toString())); + } + + @Test + void testMQCoderCanEqual() { + MQCoder coder1 = new MQCoder(); + MQCoder coder2 = new MQCoder(); + assertTrue(coder1.canEqual(coder2)); + + // Test with a different object type + assertFalse(coder1.canEqual(new Object())); + } + + @Test + void testMQCoderStateEqualsAndHashCode() { + MQCoderState state1 = new MQCoderState(0x8000, 1, 0, 1); + MQCoderState state2 = new MQCoderState(0x8000, 1, 0, 1); + + // Test equality + assertEquals(state1, state2); + assertEquals(state1.hashCode(), state2.hashCode()); + + // Change a field in state2 + state2.setMps(0); + assertNotEquals(state1, state2); + assertNotEquals(state1.hashCode(), state2.hashCode()); + } + + @Test + void testMQCoderStateCanEqual() { + MQCoderState state = new MQCoderState(0x8000, 1, 0, 1); + assertTrue(state.canEqual(new MQCoderState(0x8000, 1, 0, 1))); + + Object nonMQCoderState = new Object(); + assertFalse(state.canEqual(nonMQCoderState)); + } + + @Test + void testMQCoderStateToString() { + MQCoderState state = new MQCoderState(0x8000, 1, 0, 1); + String toStringOutput = state.toString(); + assertTrue(toStringOutput.contains("qeval=32768")); + assertTrue(toStringOutput.contains("mps=1")); + assertTrue(toStringOutput.contains("nmpsIndex=0")); + assertTrue(toStringOutput.contains("nlpsIndex=1")); + } + + @Test + void testOpenJpegImageEqualsAndHashCode() { + OpenJpegImage image1 = new OpenJpegImage(); + image1.setX0(0); + image1.setY0(0); + image1.setX1(1920); + image1.setY1(1080); + image1.setNoOfComps(3); + image1.setQmfbid(0); + image1.setColorSpace(Jp2ColorSpace.CLRSPC_SRGB); + image1.setComps(new OpenJpegImageComponent[3]); + + OpenJpegImage image2 = new OpenJpegImage(); + image2.setX0(0); + image2.setY0(0); + image2.setX1(1920); + image2.setY1(1080); + image2.setNoOfComps(3); + image2.setQmfbid(0); + image2.setColorSpace(Jp2ColorSpace.CLRSPC_SRGB); + image2.setComps(new OpenJpegImageComponent[3]); + + // Test equality + assertEquals(image1, image2); + assertEquals(image1.hashCode(), image2.hashCode()); + + // Change a field in image2 + image2.setX1(1280); + assertNotEquals(image1, image2); + assertNotEquals(image1.hashCode(), image2.hashCode()); + } + + @Test + void testOpenJpegImageCanEqual() { + OpenJpegImage image = new OpenJpegImage(); + assertTrue(image.canEqual(new OpenJpegImage())); + + Object nonOpenJpegImage = new Object(); + assertFalse(image.canEqual(nonOpenJpegImage)); + } + + @Test + void testOpenJpegImageToString() { + OpenJpegImage image = new OpenJpegImage(); + image.setX0(0); + image.setY0(0); + image.setX1(1920); + image.setY1(1080); + image.setNoOfComps(3); + image.setQmfbid(0); + image.setColorSpace(Jp2ColorSpace.CLRSPC_SRGB); + String toStringOutput = image.toString(); + assertTrue(toStringOutput.contains("x0=0")); + assertTrue(toStringOutput.contains("y0=0")); + assertTrue(toStringOutput.contains("x1=1920")); + assertTrue(toStringOutput.contains("y1=1080")); + assertTrue(toStringOutput.contains("noOfComps=3")); + assertTrue(toStringOutput.contains("qmfbid=0")); + } + + @Test + void testOpenJpegImageComponentEqualsAndHashCode() { + OpenJpegImageComponent component1 = new OpenJpegImageComponent(); + component1.setDX(1); + component1.setDY(1); + component1.setWidth(1920); + component1.setHeight(1080); + component1.setX0(0); + component1.setY0(0); + component1.setPrec(8); + component1.setBpp(24); + component1.setSgnd(0); + component1.setResNoDecoded(1); + component1.setFactor(1); + component1.setData(new int[] { 0, 1, 2 }); + + OpenJpegImageComponent component2 = new OpenJpegImageComponent(); + component2.setDX(1); + component2.setDY(1); + component2.setWidth(1920); + component2.setHeight(1080); + component2.setX0(0); + component2.setY0(0); + component2.setPrec(8); + component2.setBpp(24); + component2.setSgnd(0); + component2.setResNoDecoded(1); + component2.setFactor(1); + component2.setData(new int[] { 0, 1, 2 }); + + // Test equality + assertEquals(component1, component2); + assertEquals(component1.hashCode(), component2.hashCode()); + + // Change a field in component2 + component2.setWidth(1280); + assertNotEquals(component1, component2); + assertNotEquals(component1.hashCode(), component2.hashCode()); + } + + @Test + void testOpenJpegImageComponentCanEqual() { + OpenJpegImageComponent component = new OpenJpegImageComponent(); + assertTrue(component.canEqual(new OpenJpegImageComponent())); + + Object nonOpenJpegImageComponent = new Object(); + assertFalse(component.canEqual(nonOpenJpegImageComponent)); + } + + @Test + void testOpenJpegImageComponentToString() { + OpenJpegImageComponent component = new OpenJpegImageComponent(); + component.setDX(1); + component.setDY(1); + component.setWidth(1920); + component.setHeight(1080); + String toStringOutput = component.toString(); + assertTrue(toStringOutput.contains("dX=1")); + assertTrue(toStringOutput.contains("dY=1")); + assertTrue(toStringOutput.contains("width=1920")); + assertTrue(toStringOutput.contains("height=1080")); + } + + @Test + void testOpenJpegImageComponentParametersEqualsAndHashCode() { + OpenJpegImageComponentParameters params1 = new OpenJpegImageComponentParameters(); + params1.setDx(1); + params1.setDy(1); + params1.setWidth(1920); + params1.setHeight(1080); + params1.setX0(0); + params1.setY0(0); + params1.setPrec(8); + params1.setBpp(24); + params1.setSgnd(0); + + OpenJpegImageComponentParameters params2 = new OpenJpegImageComponentParameters(); + params2.setDx(1); + params2.setDy(1); + params2.setWidth(1920); + params2.setHeight(1080); + params2.setX0(0); + params2.setY0(0); + params2.setPrec(8); + params2.setBpp(24); + params2.setSgnd(0); + + // Test equality + assertEquals(params1, params2); + assertEquals(params1.hashCode(), params2.hashCode()); + + // Change a field in params2 + params2.setWidth(1280); + assertNotEquals(params1, params2); + assertNotEquals(params1.hashCode(), params2.hashCode()); + } + + @Test + void testOpenJpegImageComponentParametersCanEqual() { + OpenJpegImageComponentParameters params = new OpenJpegImageComponentParameters(); + assertTrue(params.canEqual(new OpenJpegImageComponentParameters())); + + Object nonOpenJpegImageComponentParameters = new Object(); + assertFalse(params.canEqual(nonOpenJpegImageComponentParameters)); + } + + @Test + void testOpenJpegImageComponentParametersToString() { + OpenJpegImageComponentParameters params = new OpenJpegImageComponentParameters(); + params.setDx(1); + params.setDy(1); + params.setWidth(1920); + params.setHeight(1080); + String toStringOutput = params.toString(); + assertTrue(toStringOutput.contains("dx=1")); + assertTrue(toStringOutput.contains("dy=1")); + assertTrue(toStringOutput.contains("width=1920")); + assertTrue(toStringOutput.contains("height=1080")); + } + + @Test + void testPacketInfoEqualsAndHashCode() { + PacketInfo packet1 = new PacketInfo(); + packet1.setStartPosition(100); + packet1.setEndPHPosition(200); + packet1.setEndPosition(300); + packet1.setDistortion(0.5); + + PacketInfo packet2 = new PacketInfo(); + packet2.setStartPosition(100); + packet2.setEndPHPosition(200); + packet2.setEndPosition(300); + packet2.setDistortion(0.5); + + // Test equality + assertEquals(packet1, packet2); + assertEquals(packet1.hashCode(), packet2.hashCode()); + + // Change a field in packet2 + packet2.setDistortion(1.0); + assertNotEquals(packet1, packet2); + assertNotEquals(packet1.hashCode(), packet2.hashCode()); + } + + @Test + void testPacketInfoCanEqual() { + PacketInfo packet = new PacketInfo(); + assertTrue(packet.canEqual(new PacketInfo())); + + Object nonPacketInfo = new Object(); + assertFalse(packet.canEqual(nonPacketInfo)); + } + + @Test + void testPacketInfoToString() { + PacketInfo packet = new PacketInfo(); + packet.setStartPosition(100); + packet.setEndPHPosition(200); + packet.setEndPosition(300); + packet.setDistortion(0.5); + String toStringOutput = packet.toString(); + assertTrue(toStringOutput.contains("startPosition=100")); + assertTrue(toStringOutput.contains("endPHPosition=200")); + assertTrue(toStringOutput.contains("endPosition=300")); + assertTrue(toStringOutput.contains("distortion=0.5")); + } + + @Test + void testPiComponentEqualsAndHashCode() { + PiComponent component1 = new PiComponent(); + component1.setDX(10); + component1.setDY(20); + component1.setNoOfResolutions(5); + component1.setResolutions(new PiResolution[] { new PiResolution(), // Assuming PiResolution has a no-args + // constructor + new PiResolution() // You may need to set properties to make them equal + }); + + PiComponent component2 = new PiComponent(); + component2.setDX(10); + component2.setDY(20); + component2.setNoOfResolutions(5); + component2.setResolutions(new PiResolution[] { new PiResolution(), new PiResolution() }); + + // Test equality + assertEquals(component1, component2); + assertEquals(component1.hashCode(), component2.hashCode()); + + // Change a field in component2 + component2.setNoOfResolutions(6); + assertNotEquals(component1, component2); + assertNotEquals(component1.hashCode(), component2.hashCode()); + } + + @Test + void testPiComponentCanEqual() { + PiComponent component = new PiComponent(); + assertTrue(component.canEqual(new PiComponent())); + + Object nonPiComponent = new Object(); + assertFalse(component.canEqual(nonPiComponent)); + } + + @Test + void testPiComponentToString() { + PiComponent component = new PiComponent(); + component.setDX(10); + component.setDY(20); + component.setNoOfResolutions(5); + String toStringOutput = component.toString(); + assertTrue(toStringOutput.contains("dX=10")); + assertTrue(toStringOutput.contains("dY=20")); + assertTrue(toStringOutput.contains("noOfResolutions=5")); + } + + @Test + void tesPiIteratortEqualsAndHashCode() { + PiIterator iterator1 = new PiIterator(); + iterator1.setTilePartOn(1); + iterator1.setInclude(new int[] { 0, 1, 0 }); + iterator1.setStepL(2); + iterator1.setStepR(3); + iterator1.setStepC(4); + iterator1.setStepP(5); + iterator1.setCompNo(6); + iterator1.setResNo(7); + iterator1.setPrecNo(8); + iterator1.setLayNo(9); + iterator1.setFirst(0); + iterator1.setNoOfComps(3); + iterator1.setComps(new PiComponent[] { new PiComponent() }); + + PiIterator iterator2 = new PiIterator(); + iterator2.setTilePartOn(1); + iterator2.setInclude(new int[] { 0, 1, 0 }); + iterator2.setStepL(2); + iterator2.setStepR(3); + iterator2.setStepC(4); + iterator2.setStepP(5); + iterator2.setCompNo(6); + iterator2.setResNo(7); + iterator2.setPrecNo(8); + iterator2.setLayNo(9); + iterator2.setFirst(0); + iterator2.setNoOfComps(3); + iterator2.setComps(new PiComponent[] { new PiComponent() }); + + // Test equality + assertEquals(iterator1, iterator2); + assertEquals(iterator1.hashCode(), iterator2.hashCode()); + + // Change a field in iterator2 + iterator2.setFirst(1); + assertNotEquals(iterator1, iterator2); + assertNotEquals(iterator1.hashCode(), iterator2.hashCode()); + } + + @Test + void testPiIteratorCanEqual() { + PiIterator iterator = new PiIterator(); + assertTrue(iterator.canEqual(new PiIterator())); + + Object nonPiIterator = new Object(); + assertFalse(iterator.canEqual(nonPiIterator)); + } + + @Test + void testPiIteratorToString() { + PiIterator iterator = new PiIterator(); + iterator.setTilePartOn(1); + iterator.setStepL(2); + iterator.setNoOfComps(3); + String toStringOutput = iterator.toString(); + assertTrue(toStringOutput.contains("tilePartOn=1")); + assertTrue(toStringOutput.contains("stepL=2")); + assertTrue(toStringOutput.contains("noOfComps=3")); + } + + @Test + void testPiResolutionEqualsAndHashCode() { + PiResolution resolution1 = new PiResolution(); + resolution1.setPDX(10); + resolution1.setPDY(20); + resolution1.setPWidth(100); + resolution1.setPHeight(200); + + PiResolution resolution2 = new PiResolution(); + resolution2.setPDX(10); + resolution2.setPDY(20); + resolution2.setPWidth(100); + resolution2.setPHeight(200); + + // Test equality + assertEquals(resolution1, resolution2); + assertEquals(resolution1.hashCode(), resolution2.hashCode()); + + // Change a field in resolution2 + resolution2.setPHeight(250); + assertNotEquals(resolution1, resolution2); + assertNotEquals(resolution1.hashCode(), resolution2.hashCode()); + } + + @Test + void testPiResolutionCanEqual() { + PiResolution resolution = new PiResolution(); + assertTrue(resolution.canEqual(new PiResolution())); + + Object nonPiResolution = new Object(); + assertFalse(resolution.canEqual(nonPiResolution)); + } + + @Test + void testPiResolutionToString() { + PiResolution resolution = new PiResolution(); + resolution.setPDX(10); + resolution.setPDY(20); + resolution.setPWidth(100); + resolution.setPHeight(200); + String toStringOutput = resolution.toString(); + assertTrue(toStringOutput.contains("pDX=10")); + assertTrue(toStringOutput.contains("pDY=20")); + assertTrue(toStringOutput.contains("pWidth=100")); + assertTrue(toStringOutput.contains("pHeight=200")); + } + + @Test + void testPocEqualsAndHashCode() { + Poc poc1 = new Poc(); + poc1.setResNo0(1); + poc1.setCompNo0(2); + poc1.setLayNo1(3); + poc1.setResNo1(4); + poc1.setCompNo1(5); + poc1.setLayNo0(6); + poc1.setPrecNo0(7); + poc1.setPrecNo1(8); + poc1.setTile(9); + poc1.setTX0(10); + poc1.setTX1(11); + poc1.setTY0(12); + poc1.setTY1(13); + poc1.setLayS(14); + poc1.setResS(15); + poc1.setCompS(16); + poc1.setPrcS(17); + poc1.setLayE(18); + poc1.setResE(19); + poc1.setCompE(20); + poc1.setPrcE(21); + poc1.setTXS(22); + poc1.setTXE(23); + poc1.setTYS(24); + poc1.setTYE(25); + poc1.setDX(26); + poc1.setDY(27); + poc1.setLayTmp(28); + poc1.setResTmp(29); + poc1.setCompTmp(30); + poc1.setPrcTmp(31); + poc1.setTx0Tmp(32); + poc1.setTy0Tmp(33); + poc1.setProgressionName(new char[] { 'A', 'B', 'C', 'D', 'E' }); + + Poc poc2 = new Poc(); + poc2.setResNo0(1); + poc2.setCompNo0(2); + poc2.setLayNo1(3); + poc2.setResNo1(4); + poc2.setCompNo1(5); + poc2.setLayNo0(6); + poc2.setPrecNo0(7); + poc2.setPrecNo1(8); + poc2.setTile(9); + poc2.setTX0(10); + poc2.setTX1(11); + poc2.setTY0(12); + poc2.setTY1(13); + poc2.setLayS(14); + poc2.setResS(15); + poc2.setCompS(16); + poc2.setPrcS(17); + poc2.setLayE(18); + poc2.setResE(19); + poc2.setCompE(20); + poc2.setPrcE(21); + poc2.setTXS(22); + poc2.setTXE(23); + poc2.setTYS(24); + poc2.setTYE(25); + poc2.setDX(26); + poc2.setDY(27); + poc2.setLayTmp(28); + poc2.setResTmp(29); + poc2.setCompTmp(30); + poc2.setPrcTmp(31); + poc2.setTx0Tmp(32); + poc2.setTy0Tmp(33); + poc2.setProgressionName(new char[] { 'A', 'B', 'C', 'D', 'E' }); + + // Test equality + assertEquals(poc1, poc2); + assertEquals(poc1.hashCode(), poc2.hashCode()); + + // Change a field in poc2 + poc2.setTile(50); + assertNotEquals(poc1, poc2); + assertNotEquals(poc1.hashCode(), poc2.hashCode()); + } + + @Test + void testPocCanEqual() { + Poc poc = new Poc(); + assertTrue(poc.canEqual(new Poc())); + + Object nonPoc = new Object(); + assertFalse(poc.canEqual(nonPoc)); + } + + @Test + void testPocToString() { + Poc poc = new Poc(); + poc.setResNo0(1); + poc.setCompNo0(2); + String toStringOutput = poc.toString(); + assertTrue(toStringOutput.contains("resNo0=1")); + assertTrue(toStringOutput.contains("compNo0=2")); + } + + @Test + void testRawEqualsAndHashCode() { + Raw raw1 = new Raw(); + raw1.setC(10); + raw1.setCt(20L); + raw1.setLengthMax(30L); + raw1.setLength(40L); + raw1.setBpIndex(5); + raw1.setBp(new byte[] { 1, 2, 3 }); + raw1.setStart(0); + raw1.setEnd(10); + + Raw raw2 = new Raw(); + raw2.setC(10); + raw2.setCt(20L); + raw2.setLengthMax(30L); + raw2.setLength(40L); + raw2.setBpIndex(5); + raw2.setBp(new byte[] { 1, 2, 3 }); + raw2.setStart(0); + raw2.setEnd(10); + + // Test equality + assertEquals(raw1, raw2); + assertEquals(raw1.hashCode(), raw2.hashCode()); + + // Change a field in raw2 + raw2.setC(50); + assertNotEquals(raw1, raw2); + assertNotEquals(raw1.hashCode(), raw2.hashCode()); + } + + @Test + void testRawCanEqual() { + Raw raw = new Raw(); + assertTrue(raw.canEqual(new Raw())); + + Object nonRaw = new Object(); + assertFalse(raw.canEqual(nonRaw)); + } + + @Test + void testRawToString() { + Raw raw = new Raw(); + raw.setC(10); + String toStringOutput = raw.toString(); + assertTrue(toStringOutput.contains("c=10")); + } + + @Test + void testStepSizeEqualsAndHashCode() { + StepSize stepSize1 = new StepSize(); + stepSize1.setExpn(3); + stepSize1.setMant(5); + + StepSize stepSize2 = new StepSize(); + stepSize2.setExpn(3); + stepSize2.setMant(5); + + // Test equality + assertEquals(stepSize1, stepSize2); + assertEquals(stepSize1.hashCode(), stepSize2.hashCode()); + + // Change a field in stepSize2 + stepSize2.setMant(10); + assertNotEquals(stepSize1, stepSize2); + assertNotEquals(stepSize1.hashCode(), stepSize2.hashCode()); + } + + @Test + void testStepSizeCanEqual() { + StepSize stepSize = new StepSize(); + assertTrue(stepSize.canEqual(new StepSize())); + + Object nonStepSize = new Object(); + assertFalse(stepSize.canEqual(nonStepSize)); + } + + @Test + void testStepSizeToString() { + StepSize stepSize = new StepSize(); + stepSize.setExpn(3); + stepSize.setMant(5); + String toStringOutput = stepSize.toString(); + assertTrue(toStringOutput.contains("expn=3")); + assertTrue(toStringOutput.contains("mant=5")); + } + + @Test + void TcdtestEquals() { + Tcd tcd1 = new Tcd(); + tcd1.setTilePartPosition(1); + tcd1.setTilePartNo(2); + + Tcd tcd2 = new Tcd(); + tcd2.setTilePartPosition(1); + tcd2.setTilePartNo(2); + + assertEquals(tcd1, tcd2); + } + + @Test + void testTcdHashCode() { + Tcd tcd1 = new Tcd(); + tcd1.setTilePartPosition(1); + tcd1.setTilePartNo(2); + + Tcd tcd2 = new Tcd(); + tcd2.setTilePartPosition(1); + tcd2.setTilePartNo(2); + + assertEquals(tcd1.hashCode(), tcd2.hashCode()); + } + + @Test + void testTcdCanEqual() { + Tcd tcd1 = new Tcd(); + assertTrue(tcd1.canEqual(new Tcd())); + } + + @Test + void testTcdToString() { + Tcd tcd = new Tcd(); + tcd.setTilePartPosition(1); + tcd.setTilePartNo(2); + tcd.setCurTilePartNo(3); + tcd.setCurTotalNoOfTileParts(4); + tcd.setCurPiNo(5); + tcd.setTcdTileNo(6); + tcd.setEncodingTime(10.5); + + String toStringOutput = tcd.toString(); + assertTrue(toStringOutput.contains("tcdTileNo=6")); + assertTrue(toStringOutput.contains("tilePartNo=2")); + } + + @Test + void testTcdBandEquals() { + TcdBand tcdBand1 = new TcdBand(); + tcdBand1.setX0(10); + tcdBand1.setY0(20); + tcdBand1.setX1(30); + tcdBand1.setY1(40); + tcdBand1.setBandNo(1); + tcdBand1.setNoOfBps(8); + tcdBand1.setStepSize(0.5f); + tcdBand1.setPrecincts(new TcdPrecinct[] { new TcdPrecinct() }); + + TcdBand tcdBand2 = new TcdBand(); + tcdBand2.setX0(10); + tcdBand2.setY0(20); + tcdBand2.setX1(30); + tcdBand2.setY1(40); + tcdBand2.setBandNo(1); + tcdBand2.setNoOfBps(8); + tcdBand2.setStepSize(0.5f); + tcdBand2.setPrecincts(new TcdPrecinct[] { new TcdPrecinct() }); + + assertEquals(tcdBand1, tcdBand2); + } + + @Test + void testTcdBandHashCode() { + TcdBand tcdBand1 = new TcdBand(); + tcdBand1.setX0(10); + tcdBand1.setY0(20); + tcdBand1.setX1(30); + tcdBand1.setY1(40); + tcdBand1.setBandNo(1); + tcdBand1.setNoOfBps(8); + tcdBand1.setStepSize(0.5f); + tcdBand1.setPrecincts(new TcdPrecinct[] { new TcdPrecinct() }); + + TcdBand tcdBand2 = new TcdBand(); + tcdBand2.setX0(10); + tcdBand2.setY0(20); + tcdBand2.setX1(30); + tcdBand2.setY1(40); + tcdBand2.setBandNo(1); + tcdBand2.setNoOfBps(8); + tcdBand2.setStepSize(0.5f); + tcdBand2.setPrecincts(new TcdPrecinct[] { new TcdPrecinct() }); + + assertEquals(tcdBand1.hashCode(), tcdBand2.hashCode()); + } + + @Test + void testTcdBandCanEqual() { + TcdBand tcdBand1 = new TcdBand(); + assertTrue(tcdBand1.canEqual(new TcdBand())); + } + + @Test + void testTcdBandToString() { + TcdBand tcdBand = new TcdBand(); + tcdBand.setX0(10); + tcdBand.setY0(20); + tcdBand.setX1(30); + tcdBand.setY1(40); + tcdBand.setBandNo(1); + tcdBand.setNoOfBps(8); + tcdBand.setStepSize(0.5f); + tcdBand.setPrecincts(new TcdPrecinct[] { new TcdPrecinct() }); + + String toStringOutput = tcdBand.toString(); + assertTrue(toStringOutput.contains("x0=10")); + } + + @Test + void testTcdCodeBlockDecoderEquals() { + TcdCodeBlockDecoder block1 = new TcdCodeBlockDecoder(); + block1.setX0(10); + block1.setY0(20); + block1.setX1(30); + block1.setY1(40); + block1.setNoOfBps(8); + block1.setNoOfLengthBits(16); + block1.setLength(100); + block1.setNoOfNewPasses(3); + block1.setNoOfSegs(2); + block1.setData(new byte[] { 1, 2, 3 }); + block1.setSegs(new TcdSegment[] { new TcdSegment() }); + + TcdCodeBlockDecoder block2 = new TcdCodeBlockDecoder(); + block2.setX0(10); + block2.setY0(20); + block2.setX1(30); + block2.setY1(40); + block2.setNoOfBps(8); + block2.setNoOfLengthBits(16); + block2.setLength(100); + block2.setNoOfNewPasses(3); + block2.setNoOfSegs(2); + block2.setData(new byte[] { 1, 2, 3 }); + block2.setSegs(new TcdSegment[] { new TcdSegment() }); + + assertEquals(block1, block2); + } + + @Test + void testTcdCodeBlockDecoderHashCode() { + TcdCodeBlockDecoder block1 = new TcdCodeBlockDecoder(); + block1.setX0(10); + block1.setY0(20); + block1.setX1(30); + block1.setY1(40); + block1.setNoOfBps(8); + block1.setNoOfLengthBits(16); + block1.setLength(100); + block1.setNoOfNewPasses(3); + block1.setNoOfSegs(2); + block1.setData(new byte[] { 1, 2, 3 }); + block1.setSegs(new TcdSegment[] { new TcdSegment() }); + + TcdCodeBlockDecoder block2 = new TcdCodeBlockDecoder(); + block2.setX0(10); + block2.setY0(20); + block2.setX1(30); + block2.setY1(40); + block2.setNoOfBps(8); + block2.setNoOfLengthBits(16); + block2.setLength(100); + block2.setNoOfNewPasses(3); + block2.setNoOfSegs(2); + block2.setData(new byte[] { 1, 2, 3 }); + block2.setSegs(new TcdSegment[] { new TcdSegment() }); + + assertEquals(block1.hashCode(), block2.hashCode()); + } + + @Test + void testTcdCodeBlockDecoderCanEqual() { + TcdCodeBlockDecoder block1 = new TcdCodeBlockDecoder(); + assertTrue(block1.canEqual(new TcdCodeBlockDecoder())); + } + + @Test + void testTcdCodeBlockDecoderToString() { + TcdCodeBlockDecoder block = new TcdCodeBlockDecoder(); + block.setX0(10); + block.setY0(20); + block.setX1(30); + block.setY1(40); + block.setNoOfBps(8); + block.setNoOfLengthBits(16); + block.setLength(100); + block.setNoOfNewPasses(3); + block.setNoOfSegs(2); + block.setData(new byte[] { 1, 2, 3 }); + block.setSegs(new TcdSegment[] { new TcdSegment() }); + + String toStringOutput = block.toString(); + assertTrue(toStringOutput.contains("x0=10")); + assertTrue(toStringOutput.contains("y0=20")); + } + + @Test + void testTcdCodeBlockEncoderEquals() { + TcdCodeBlockEncoder encoder1 = new TcdCodeBlockEncoder(); + encoder1.setDataIndex(1); + encoder1.setX0(10); + encoder1.setY0(20); + encoder1.setX1(30); + encoder1.setY1(40); + encoder1.setNoOfBps(8); + encoder1.setNoOfLengthBits(16); + encoder1.setNoOfPasses(2); + encoder1.setNoOfPassesInLayers(1); + encoder1.setTotalPasses(3); + encoder1.setData(new byte[] { 1, 2, 3 }); + encoder1.setLayers(new TcdLayer[] { new TcdLayer() }); + encoder1.setPasses(new TcdPass[] { new TcdPass() }); + + TcdCodeBlockEncoder encoder2 = new TcdCodeBlockEncoder(); + encoder2.setDataIndex(1); + encoder2.setX0(10); + encoder2.setY0(20); + encoder2.setX1(30); + encoder2.setY1(40); + encoder2.setNoOfBps(8); + encoder2.setNoOfLengthBits(16); + encoder2.setNoOfPasses(2); + encoder2.setNoOfPassesInLayers(1); + encoder2.setTotalPasses(3); + encoder2.setData(new byte[] { 1, 2, 3 }); + encoder2.setLayers(new TcdLayer[] { new TcdLayer() }); + encoder2.setPasses(new TcdPass[] { new TcdPass() }); + + assertEquals(encoder1, encoder2); + } + + @Test + void testTcdCodeBlockEncoderHashCode() { + TcdCodeBlockEncoder encoder1 = new TcdCodeBlockEncoder(); + encoder1.setDataIndex(1); + encoder1.setX0(10); + encoder1.setY0(20); + encoder1.setX1(30); + encoder1.setY1(40); + encoder1.setNoOfBps(8); + encoder1.setNoOfLengthBits(16); + encoder1.setNoOfPasses(2); + encoder1.setNoOfPassesInLayers(1); + encoder1.setTotalPasses(3); + encoder1.setData(new byte[] { 1, 2, 3 }); + encoder1.setLayers(new TcdLayer[] { new TcdLayer() }); + encoder1.setPasses(new TcdPass[] { new TcdPass() }); + + TcdCodeBlockEncoder encoder2 = new TcdCodeBlockEncoder(); + encoder2.setDataIndex(1); + encoder2.setX0(10); + encoder2.setY0(20); + encoder2.setX1(30); + encoder2.setY1(40); + encoder2.setNoOfBps(8); + encoder2.setNoOfLengthBits(16); + encoder2.setNoOfPasses(2); + encoder2.setNoOfPassesInLayers(1); + encoder2.setTotalPasses(3); + encoder2.setData(new byte[] { 1, 2, 3 }); + encoder2.setLayers(new TcdLayer[] { new TcdLayer() }); + encoder2.setPasses(new TcdPass[] { new TcdPass() }); + + assertEquals(encoder1.hashCode(), encoder2.hashCode()); + } + + @Test + void testTcdCodeBlockEncoderCanEqual() { + TcdCodeBlockEncoder encoder = new TcdCodeBlockEncoder(); + assertTrue(encoder.canEqual(new TcdCodeBlockEncoder())); + } + + @Test + void testTcdCodeBlockEncoderToString() { + TcdCodeBlockEncoder encoder = new TcdCodeBlockEncoder(); + encoder.setDataIndex(1); + encoder.setX0(10); + encoder.setY0(20); + encoder.setX1(30); + encoder.setY1(40); + encoder.setNoOfBps(8); + encoder.setNoOfLengthBits(16); + encoder.setNoOfPasses(2); + encoder.setNoOfPassesInLayers(1); + encoder.setTotalPasses(3); + encoder.setData(new byte[] { 1, 2, 3 }); + encoder.setLayers(new TcdLayer[] { new TcdLayer() }); + encoder.setPasses(new TcdPass[] { new TcdPass() }); + + String toStringOutput = encoder.toString(); + assertTrue(toStringOutput.contains("dataIndex=1")); + assertTrue(toStringOutput.contains("x0=10")); + } + + @Test + void testTcdImageEquals() { + TcdImage image1 = new TcdImage(); + image1.setTileWidth(1024); + image1.setTileHeight(768); + image1.setTiles(new TcdTile[] { new TcdTile() }); + + TcdImage image2 = new TcdImage(); + image2.setTileWidth(1024); + image2.setTileHeight(768); + image2.setTiles(new TcdTile[] { new TcdTile() }); + + assertEquals(image1, image2); + } + + @Test + void testTcdImageHashCode() { + TcdImage image1 = new TcdImage(); + image1.setTileWidth(1024); + image1.setTileHeight(768); + image1.setTiles(new TcdTile[] { new TcdTile() }); + + TcdImage image2 = new TcdImage(); + image2.setTileWidth(1024); + image2.setTileHeight(768); + image2.setTiles(new TcdTile[] { new TcdTile() }); + + assertEquals(image1.hashCode(), image2.hashCode()); + } + + @Test + void testTcdImageCanEqual() { + TcdImage image = new TcdImage(); + assertTrue(image.canEqual(new TcdImage())); + } + + @Test + void testTcdImageToString() { + TcdImage image = new TcdImage(); + image.setTileWidth(1024); + image.setTileHeight(768); + image.setTiles(new TcdTile[] { new TcdTile() }); + + String toStringOutput = image.toString(); + assertTrue(toStringOutput.contains("tileWidth=1024")); + assertTrue(toStringOutput.contains("tileHeight=768")); + } + + @Test + void testTcdLayerEquals() { + TcdLayer layer1 = new TcdLayer(); + layer1.setNoOfPasses(5); + layer1.setLength(100); + layer1.setDistortion(0.01); + layer1.setData(new byte[] { 1, 2, 3 }); + + TcdLayer layer2 = new TcdLayer(); + layer2.setNoOfPasses(5); + layer2.setLength(100); + layer2.setDistortion(0.01); + layer2.setData(new byte[] { 1, 2, 3 }); + + assertEquals(layer1, layer2); + } + + @Test + void testTcdLayerHashCode() { + TcdLayer layer1 = new TcdLayer(); + layer1.setNoOfPasses(5); + layer1.setLength(100); + layer1.setDistortion(0.01); + layer1.setData(new byte[] { 1, 2, 3 }); + + TcdLayer layer2 = new TcdLayer(); + layer2.setNoOfPasses(5); + layer2.setLength(100); + layer2.setDistortion(0.01); + layer2.setData(new byte[] { 1, 2, 3 }); + + assertEquals(layer1.hashCode(), layer2.hashCode()); + } + + @Test + void testTcdLayerCanEqual() { + TcdLayer layer = new TcdLayer(); + assertTrue(layer.canEqual(new TcdLayer())); + } + + @Test + void testTcdLayerToString() { + TcdLayer layer = new TcdLayer(); + layer.setNoOfPasses(5); + layer.setLength(100); + layer.setDistortion(0.01); + layer.setData(new byte[] { 1, 2, 3 }); + + String expected = "TcdLayer(noOfPasses=5, length=100, distortion=0.01, data=[1, 2, 3])"; + assertEquals(expected, layer.toString()); + } + + @Test + void testTcdPassEquals() { + TcdPass pass1 = new TcdPass(); + pass1.setRate(10); + pass1.setDistortionDec(0.1); + pass1.setTerm(5); + pass1.setLength(100); + + TcdPass pass2 = new TcdPass(); + pass2.setRate(10); + pass2.setDistortionDec(0.1); + pass2.setTerm(5); + pass2.setLength(100); + + assertEquals(pass1, pass2); + } + + @Test + void testTcdPassHashCode() { + TcdPass pass1 = new TcdPass(); + pass1.setRate(10); + pass1.setDistortionDec(0.1); + pass1.setTerm(5); + pass1.setLength(100); + + TcdPass pass2 = new TcdPass(); + pass2.setRate(10); + pass2.setDistortionDec(0.1); + pass2.setTerm(5); + pass2.setLength(100); + + assertEquals(pass1.hashCode(), pass2.hashCode()); + } + + @Test + void testTcdPassCanEqual() { + TcdPass pass = new TcdPass(); + assertTrue(pass.canEqual(new TcdPass())); + } + + @Test + void testTcdPassToString() { + TcdPass pass = new TcdPass(); + pass.setRate(10); + pass.setDistortionDec(0.1); + pass.setTerm(5); + pass.setLength(100); + + String expected = "TcdPass(rate=10, distortionDec=0.1, term=5, length=100)"; + assertEquals(expected, pass.toString()); + } + + @Test + void testTcdPrecinctEquals() { + TcdPrecinct precinct1 = new TcdPrecinct(); + precinct1.setX0(1); + precinct1.setY0(2); + precinct1.setX1(3); + precinct1.setCWidth(4); + precinct1.setCHeight(5); + + TcdPrecinct precinct2 = new TcdPrecinct(); + precinct2.setX0(1); + precinct2.setY0(2); + precinct2.setX1(3); + precinct2.setCWidth(4); + precinct2.setCHeight(5); + + assertEquals(precinct1, precinct2); + } + + @Test + void testTcdPrecinctHashCode() { + TcdPrecinct precinct1 = new TcdPrecinct(); + precinct1.setX0(1); + precinct1.setY0(2); + precinct1.setX1(3); + precinct1.setCWidth(4); + precinct1.setCHeight(5); + + TcdPrecinct precinct2 = new TcdPrecinct(); + precinct2.setX0(1); + precinct2.setY0(2); + precinct2.setX1(3); + precinct2.setCWidth(4); + precinct2.setCHeight(5); + + assertEquals(precinct1.hashCode(), precinct2.hashCode()); + } + + @Test + void testTcdPrecinctCanEqual() { + TcdPrecinct precinct = new TcdPrecinct(); + assertTrue(precinct.canEqual(new TcdPrecinct())); + } + + @Test + void testTcdPrecinctToString() { + TcdPrecinct precinct = new TcdPrecinct(); + precinct.setX0(1); + precinct.setY0(2); + precinct.setX1(3); + precinct.setCWidth(4); + precinct.setCHeight(5); + + String toStringOutput = precinct.toString(); + assertTrue(toStringOutput.contains("x0=1")); + assertTrue(toStringOutput.contains("y0=2")); + } + + @Test + void testTcdResolutionEquals() { + TcdResolution resolution1 = new TcdResolution(); + resolution1.setX0(1); + resolution1.setY0(2); + resolution1.setX1(3); + resolution1.setY1(4); + resolution1.setPWidth(5); + resolution1.setPHeight(6); + resolution1.setNoOfBands(2); + + TcdResolution resolution2 = new TcdResolution(); + resolution2.setX0(1); + resolution2.setY0(2); + resolution2.setX1(3); + resolution2.setY1(4); + resolution2.setPWidth(5); + resolution2.setPHeight(6); + resolution2.setNoOfBands(2); + + assertEquals(resolution1, resolution2); + } + + @Test + void testTcdResolutionHashCode() { + TcdResolution resolution1 = new TcdResolution(); + resolution1.setX0(1); + resolution1.setY0(2); + resolution1.setX1(3); + resolution1.setY1(4); + resolution1.setPWidth(5); + resolution1.setPHeight(6); + resolution1.setNoOfBands(2); + + TcdResolution resolution2 = new TcdResolution(); + resolution2.setX0(1); + resolution2.setY0(2); + resolution2.setX1(3); + resolution2.setY1(4); + resolution2.setPWidth(5); + resolution2.setPHeight(6); + resolution2.setNoOfBands(2); + + assertEquals(resolution1.hashCode(), resolution2.hashCode()); + } + + @Test + void testTcdResolutionCanEqual() { + TcdResolution resolution = new TcdResolution(); + assertTrue(resolution.canEqual(new TcdResolution())); + } + + @Test + void testTcdResolutionToString() { + TcdResolution resolution = new TcdResolution(); + resolution.setX0(1); + resolution.setY0(2); + resolution.setX1(3); + resolution.setY1(4); + resolution.setPWidth(5); + resolution.setPHeight(6); + resolution.setNoOfBands(2); + + String expected = "TcdResolution(x0=1, y0=2, x1=3, y1=4, pWidth=5, pHeight=6, noOfBands=2, bands=[null, null, null])"; + assertEquals(expected, resolution.toString()); + } + + @Test + void testTcdSegmentEquals() { + TcdSegment segment1 = new TcdSegment(); + segment1.setData(new byte[] { 1, 2, 3 }); + segment1.setDataIndex(1); + segment1.setNoOfPasses(2); + segment1.setLength(3); + segment1.setMaxPasses(4); + segment1.setNoOfNewPasses(5); + segment1.setNewLength(6); + + TcdSegment segment2 = new TcdSegment(); + segment2.setData(new byte[] { 1, 2, 3 }); + segment2.setDataIndex(1); + segment2.setNoOfPasses(2); + segment2.setLength(3); + segment2.setMaxPasses(4); + segment2.setNoOfNewPasses(5); + segment2.setNewLength(6); + + assertEquals(segment1, segment2); + } + + @Test + void testTcdSegmentHashCode() { + TcdSegment segment1 = new TcdSegment(); + segment1.setData(new byte[] { 1, 2, 3 }); + segment1.setDataIndex(1); + segment1.setNoOfPasses(2); + segment1.setLength(3); + segment1.setMaxPasses(4); + segment1.setNoOfNewPasses(5); + segment1.setNewLength(6); + + TcdSegment segment2 = new TcdSegment(); + segment2.setData(new byte[] { 1, 2, 3 }); + segment2.setDataIndex(1); + segment2.setNoOfPasses(2); + segment2.setLength(3); + segment2.setMaxPasses(4); + segment2.setNoOfNewPasses(5); + segment2.setNewLength(6); + + assertEquals(segment1.hashCode(), segment2.hashCode()); + } + + @Test + void testTcdSegmentCanEqual() { + TcdSegment segment1 = new TcdSegment(); + assertTrue(segment1.canEqual(new TcdSegment())); + } + + @Test + void testTcdSegmentToString() { + TcdSegment segment = new TcdSegment(); + segment.setData(new byte[] { 1, 2, 3 }); + segment.setDataIndex(1); + segment.setNoOfPasses(2); + segment.setLength(3); + segment.setMaxPasses(4); + segment.setNoOfNewPasses(5); + segment.setNewLength(6); + + String toStringOutput = segment.toString(); + assertTrue(toStringOutput.contains("dataIndex=1")); + assertTrue(toStringOutput.contains("noOfPasses=2")); + } + + @Test + void testTcdTileEquals() { + TcdTile tile1 = new TcdTile(); + tile1.setX0(0); + tile1.setY0(0); + tile1.setX1(100); + tile1.setY1(100); + tile1.setNoOfComps(3); + tile1.setNoOfPixels(30000); + tile1.setDistortionTile(0.01); + tile1.setPacketNo(1); + + TcdTile tile2 = new TcdTile(); + tile2.setX0(0); + tile2.setY0(0); + tile2.setX1(100); + tile2.setY1(100); + tile2.setNoOfComps(3); + tile2.setNoOfPixels(30000); + tile2.setDistortionTile(0.01); + tile2.setPacketNo(1); + + assertEquals(tile1, tile2); + } + + @Test + void testTcdTileHashCode() { + TcdTile tile1 = new TcdTile(); + tile1.setX0(0); + tile1.setY0(0); + tile1.setX1(100); + tile1.setY1(100); + tile1.setNoOfComps(3); + tile1.setNoOfPixels(30000); + tile1.setDistortionTile(0.01); + tile1.setPacketNo(1); + + TcdTile tile2 = new TcdTile(); + tile2.setX0(0); + tile2.setY0(0); + tile2.setX1(100); + tile2.setY1(100); + tile2.setNoOfComps(3); + tile2.setNoOfPixels(30000); + tile2.setDistortionTile(0.01); + tile2.setPacketNo(1); + + assertEquals(tile1.hashCode(), tile2.hashCode()); + } + + @Test + void testTcdTileCanEqual() { + TcdTile tile1 = new TcdTile(); + assertTrue(tile1.canEqual(new TcdTile())); + } + + @Test + void testTcdTileToString() { + TcdTile tile = new TcdTile(); + tile.setX0(0); + tile.setY0(0); + tile.setX1(100); + tile.setY1(100); + tile.setNoOfComps(3); + + String toStringOutput = tile.toString(); + assertTrue(toStringOutput.contains("x0=0")); + assertTrue(toStringOutput.contains("y0=0")); + assertTrue(toStringOutput.contains("x1=100")); + assertTrue(toStringOutput.contains("y1=100")); + assertTrue(toStringOutput.contains("noOfComps=3")); + } + + @Test + void testTcdTileComponentEquals() { + TcdTileComponent component1 = new TcdTileComponent(); + component1.setX0(0); + component1.setY0(0); + component1.setX1(100); + component1.setY1(100); + component1.setNoOfResolutions(3); + component1.setNoOfPixels(30000); + component1.setIData(new int[] { 1, 2, 3 }); + component1.setFData(new double[] { 0.1, 0.2, 0.3 }); + + TcdTileComponent component2 = new TcdTileComponent(); + component2.setX0(0); + component2.setY0(0); + component2.setX1(100); + component2.setY1(100); + component2.setNoOfResolutions(3); + component2.setNoOfPixels(30000); + component2.setIData(new int[] { 1, 2, 3 }); + component2.setFData(new double[] { 0.1, 0.2, 0.3 }); + + assertEquals(component1, component2); + } + + @Test + void testTcdTileComponentHashCode() { + TcdTileComponent component1 = new TcdTileComponent(); + component1.setX0(0); + component1.setY0(0); + component1.setX1(100); + component1.setY1(100); + component1.setNoOfResolutions(3); + component1.setNoOfPixels(30000); + component1.setIData(new int[] { 1, 2, 3 }); + component1.setFData(new double[] { 0.1, 0.2, 0.3 }); + + TcdTileComponent component2 = new TcdTileComponent(); + component2.setX0(0); + component2.setY0(0); + component2.setX1(100); + component2.setY1(100); + component2.setNoOfResolutions(3); + component2.setNoOfPixels(30000); + component2.setIData(new int[] { 1, 2, 3 }); + component2.setFData(new double[] { 0.1, 0.2, 0.3 }); + + assertEquals(component1.hashCode(), component2.hashCode()); + } + + @Test + void testTcdTileComponentCanEqual() { + TcdTileComponent component1 = new TcdTileComponent(); + assertTrue(component1.canEqual(new TcdTileComponent())); + } + + @Test + void testTcdTileComponentToString() { + TcdTileComponent component = new TcdTileComponent(); + component.setX0(0); + component.setY0(0); + component.setX1(100); + component.setY1(100); + component.setNoOfResolutions(3); + + String toStringOutput = component.toString(); + assertTrue(toStringOutput.contains("x0=0")); + assertTrue(toStringOutput.contains("y0=0")); + assertTrue(toStringOutput.contains("x1=100")); + assertTrue(toStringOutput.contains("y1=100")); + assertTrue(toStringOutput.contains("noOfResolutions=3")); + } + + @Test + void testTcpEquals() { + Tcp tcp1 = new Tcp(); + tcp1.setFirst(1); + tcp1.setCodingStyle(2); + tcp1.setNoOfLayers(3); + tcp1.setMct(4); + tcp1.setNoOfPocs(5); + tcp1.setIsPoc(1); + tcp1.setRates(new float[] { 1.0f, 2.0f, 3.0f }); + tcp1.setPocs(new Poc[] { new Poc() }); // assuming a constructor exists + tcp1.setPptData(new byte[] { 0, 1, 2 }); + tcp1.setPptDataFirst(new byte[] { 3, 4, 5 }); + tcp1.setPpt(1); + tcp1.setPptStore(0); + tcp1.setPptLength(10); + tcp1.setDistortionRatio(new float[] { 0.1f, 0.2f }); + + Tcp tcp2 = new Tcp(); + tcp2.setFirst(1); + tcp2.setCodingStyle(2); + tcp2.setNoOfLayers(3); + tcp2.setMct(4); + tcp2.setNoOfPocs(5); + tcp2.setIsPoc(1); + tcp2.setRates(new float[] { 1.0f, 2.0f, 3.0f }); + tcp2.setPocs(new Poc[] { new Poc() }); // assuming a constructor exists + tcp2.setPptData(new byte[] { 0, 1, 2 }); + tcp2.setPptDataFirst(new byte[] { 3, 4, 5 }); + tcp2.setPpt(1); + tcp2.setPptStore(0); + tcp2.setPptLength(10); + tcp2.setDistortionRatio(new float[] { 0.1f, 0.2f }); + + assertEquals(tcp1, tcp2); + } + + @Test + void testTcpHashCode() { + Tcp tcp1 = new Tcp(); + tcp1.setFirst(1); + tcp1.setCodingStyle(2); + tcp1.setNoOfLayers(3); + tcp1.setMct(4); + tcp1.setNoOfPocs(5); + tcp1.setIsPoc(1); + tcp1.setRates(new float[] { 1.0f, 2.0f, 3.0f }); + tcp1.setPocs(new Poc[] { new Poc() }); // assuming a constructor exists + tcp1.setPptData(new byte[] { 0, 1, 2 }); + tcp1.setPptDataFirst(new byte[] { 3, 4, 5 }); + tcp1.setPpt(1); + tcp1.setPptStore(0); + tcp1.setPptLength(10); + tcp1.setDistortionRatio(new float[] { 0.1f, 0.2f }); + + Tcp tcp2 = new Tcp(); + tcp2.setFirst(1); + tcp2.setCodingStyle(2); + tcp2.setNoOfLayers(3); + tcp2.setMct(4); + tcp2.setNoOfPocs(5); + tcp2.setIsPoc(1); + tcp2.setRates(new float[] { 1.0f, 2.0f, 3.0f }); + tcp2.setPocs(new Poc[] { new Poc() }); // assuming a constructor exists + tcp2.setPptData(new byte[] { 0, 1, 2 }); + tcp2.setPptDataFirst(new byte[] { 3, 4, 5 }); + tcp2.setPpt(1); + tcp2.setPptStore(0); + tcp2.setPptLength(10); + tcp2.setDistortionRatio(new float[] { 0.1f, 0.2f }); + + assertEquals(tcp1.hashCode(), tcp2.hashCode()); + } + + @Test + void testTcpCanEqual() { + Tcp tcp1 = new Tcp(); + assertTrue(tcp1.canEqual(new Tcp())); + } + + @Test + void testTcpToString() { + Tcp tcp = new Tcp(); + tcp.setFirst(1); + tcp.setCodingStyle(2); + tcp.setNoOfLayers(3); + + String toStringOutput = tcp.toString(); + assertTrue(toStringOutput.contains("first=1")); + assertTrue(toStringOutput.contains("codingStyle=2")); + assertTrue(toStringOutput.contains("noOfLayers=3")); + } + + @Test + void testTgtNodeEquals() { + TgtNode node1 = new TgtNode(); + node1.setParent(1); + node1.setValue(2); + node1.setLow(3); + node1.setKnown(4); + + TgtNode node2 = new TgtNode(); + node2.setParent(1); + node2.setValue(2); + node2.setLow(3); + node2.setKnown(4); + + assertEquals(node1, node2); + } + + @Test + void testTgtNodeNotEquals() { + TgtNode node1 = new TgtNode(); + node1.setParent(1); + node1.setValue(2); + node1.setLow(3); + node1.setKnown(4); + + TgtNode node2 = new TgtNode(); + node2.setParent(2); // Different parent + node2.setValue(2); + node2.setLow(3); + node2.setKnown(4); + + assertNotEquals(node1, node2); + } + + @Test + void testTgtNodeHashCode() { + TgtNode node1 = new TgtNode(); + node1.setParent(1); + node1.setValue(2); + node1.setLow(3); + node1.setKnown(4); + + TgtNode node2 = new TgtNode(); + node2.setParent(1); + node2.setValue(2); + node2.setLow(3); + node2.setKnown(4); + + assertEquals(node1.hashCode(), node2.hashCode()); + } + + @Test + void testTgtNodeCanEqual() { + TgtNode node1 = new TgtNode(); + assertTrue(node1.canEqual(new TgtNode())); + } + + @Test + void testTgtNodeToString() { + TgtNode node = new TgtNode(); + node.setParent(1); + node.setValue(2); + node.setLow(3); + node.setKnown(4); + + String toStringOutput = node.toString(); + assertTrue(toStringOutput.contains("parent=1")); + assertTrue(toStringOutput.contains("value=2")); + assertTrue(toStringOutput.contains("low=3")); + assertTrue(toStringOutput.contains("known=4")); + } + + @Test + void testTgtTreeEquals() { + TgtNode node1 = new TgtNode(); + node1.setParent(1); + node1.setValue(2); + node1.setLow(3); + node1.setKnown(4); + + TgtNode node2 = new TgtNode(); + node2.setParent(1); + node2.setValue(2); + node2.setLow(3); + node2.setKnown(4); + + TgtTree tree1 = new TgtTree(); + tree1.setNoOfLeafSH(5); + tree1.setNoOfLeafSV(10); + tree1.setNoOfNodes(3); + tree1.setNodes(new TgtNode[] { node1 }); + + TgtTree tree2 = new TgtTree(); + tree2.setNoOfLeafSH(5); + tree2.setNoOfLeafSV(10); + tree2.setNoOfNodes(3); + tree2.setNodes(new TgtNode[] { node2 }); + + assertEquals(tree1, tree2); + } + + @Test + void testTgtTreeNotEquals() { + TgtTree tree1 = new TgtTree(); + tree1.setNoOfLeafSH(5); + tree1.setNoOfLeafSV(10); + tree1.setNoOfNodes(3); + tree1.setNodes(new TgtNode[1]); + + TgtTree tree2 = new TgtTree(); + tree2.setNoOfLeafSH(6); // Different noOfLeafSH + tree2.setNoOfLeafSV(10); + tree2.setNoOfNodes(3); + tree2.setNodes(new TgtNode[1]); + + assertNotEquals(tree1, tree2); + } + + @Test + void testTgtTreeHashCode() { + TgtNode node1 = new TgtNode(); + node1.setParent(1); + node1.setValue(2); + node1.setLow(3); + node1.setKnown(4); + + TgtTree tree1 = new TgtTree(); + tree1.setNoOfLeafSH(5); + tree1.setNoOfLeafSV(10); + tree1.setNoOfNodes(3); + tree1.setNodes(new TgtNode[] { node1 }); + + TgtTree tree2 = new TgtTree(); + tree2.setNoOfLeafSH(5); + tree2.setNoOfLeafSV(10); + tree2.setNoOfNodes(3); + tree2.setNodes(new TgtNode[] { node1 }); + + assertEquals(tree1.hashCode(), tree2.hashCode()); + } + + @Test + void testTgtTreeCanEqual() { + TgtTree tree1 = new TgtTree(); + assertTrue(tree1.canEqual(new TgtTree())); + } + + @Test + void testTgtTreeToString() { + TgtTree tree = new TgtTree(); + tree.setNoOfLeafSH(5); + tree.setNoOfLeafSV(10); + tree.setNoOfNodes(3); + tree.setNodes(new TgtNode[1]); + + String toStringOutput = tree.toString(); + assertTrue(toStringOutput.contains("noOfLeafSH=5")); + assertTrue(toStringOutput.contains("noOfLeafSV=10")); + assertTrue(toStringOutput.contains("noOfNodes=3")); + } + + @Test + void testTier1Equals() { + Tier1 tier1a = new Tier1(); + tier1a.setWidth(1920); + tier1a.setHeight(1080); + tier1a.setData(new int[] { 1, 2, 3 }); + tier1a.setFlags(new int[] { 0, 1, 0 }); + + Tier1 tier1b = new Tier1(); + tier1b.setWidth(1920); + tier1b.setHeight(1080); + tier1b.setData(new int[] { 1, 2, 3 }); + tier1b.setFlags(new int[] { 0, 1, 0 }); + + assertEquals(tier1a, tier1b); + } + + @Test + void testTier1NotEquals() { + Tier1 tier1a = new Tier1(); + tier1a.setWidth(1920); + tier1a.setHeight(1080); + + Tier1 tier1b = new Tier1(); + tier1b.setWidth(1280); // Different width + + assertNotEquals(tier1a, tier1b); + } + + @Test + void testTier1HashCode() { + Tier1 tier1a = new Tier1(); + tier1a.setWidth(1920); + tier1a.setHeight(1080); + tier1a.setData(new int[] { 1, 2, 3 }); + tier1a.setFlags(new int[] { 0, 1, 0 }); + + Tier1 tier1b = new Tier1(); + tier1b.setWidth(1920); + tier1b.setHeight(1080); + tier1b.setData(new int[] { 1, 2, 3 }); + tier1b.setFlags(new int[] { 0, 1, 0 }); + + assertEquals(tier1a.hashCode(), tier1b.hashCode()); + } + + @Test + void testTier1CanEqual() { + Tier1 tier1a = new Tier1(); + assertTrue(tier1a.canEqual(new Tier1())); + } + + @Test + void testTier1ToString() { + Tier1 tier1 = new Tier1(); + tier1.setWidth(1920); + tier1.setHeight(1080); + String toStringOutput = tier1.toString(); + assertTrue(toStringOutput.contains("width=1920")); + assertTrue(toStringOutput.contains("height=1080")); + } + + @Test + void testTier2Equals() { + Tier2 tier2a = new Tier2(); + tier2a.setCodecContextInfo(new CodecContextInfo()); + tier2a.setImage(new OpenJpegImage()); + tier2a.setCodingParameters(new CodingParameters()); + + Tier2 tier2b = new Tier2(); + tier2b.setCodecContextInfo(new CodecContextInfo()); + tier2b.setImage(new OpenJpegImage()); + tier2b.setCodingParameters(new CodingParameters()); + + assertEquals(tier2a, tier2b); + } + + @Test + void testTier2NotEquals() { + Tier2 tier2a = new Tier2(); + tier2a.setCodecContextInfo(new CodecContextInfo()); + + Tier2 tier2b = new Tier2(); + tier2b.setCodecContextInfo(null); // Different codec context + + assertNotEquals(tier2a, tier2b); + } + + @Test + void testTier2HashCode() { + Tier2 tier2a = new Tier2(); + tier2a.setCodecContextInfo(new CodecContextInfo()); + tier2a.setImage(new OpenJpegImage()); + tier2a.setCodingParameters(new CodingParameters()); + + Tier2 tier2b = new Tier2(); + tier2b.setCodecContextInfo(new CodecContextInfo()); + tier2b.setImage(new OpenJpegImage()); + tier2b.setCodingParameters(new CodingParameters()); + + assertEquals(tier2a.hashCode(), tier2b.hashCode()); + } + + @Test + void testTier2CanEqual() { + Tier2 tier2a = new Tier2(); + assertTrue(tier2a.canEqual(new Tier2())); + } + + @Test + void testTier2ToString() { + Tier2 tier2 = new Tier2(); + tier2.setCodecContextInfo(new CodecContextInfo()); + tier2.setImage(new OpenJpegImage()); + String toStringOutput = tier2.toString(); + assertTrue(toStringOutput.contains("codecContextInfo")); + assertTrue(toStringOutput.contains("image")); + assertTrue(toStringOutput.contains("codingParameters")); + } + + @Test + void testTileComponentCodingParametersEquals() { + TileComponentCodingParameters params1 = new TileComponentCodingParameters(); + params1.setCodingStyle(1); + params1.setNoOfResolutions(3); + params1.setCodeBlockWidth(64); + params1.setCodeBlockHeight(64); + params1.setCodeBlockStyle(0); + params1.setQmfbid(1); + params1.setQuantisationStyle(2); + params1.setNoOfGaurdBits(5); + params1.setRoiShift(1); + params1.setStepsizes(new StepSize[] { new StepSize() }); + params1.setPrecinctWidth(new int[] { 8, 16, 32 }); + params1.setPrecinctHeight(new int[] { 8, 16, 32 }); + + TileComponentCodingParameters params2 = new TileComponentCodingParameters(); + params2.setCodingStyle(1); + params2.setNoOfResolutions(3); + params2.setCodeBlockWidth(64); + params2.setCodeBlockHeight(64); + params2.setCodeBlockStyle(0); + params2.setQmfbid(1); + params2.setQuantisationStyle(2); + params2.setNoOfGaurdBits(5); + params2.setRoiShift(1); + params2.setStepsizes(new StepSize[] { new StepSize() }); + params2.setPrecinctWidth(new int[] { 8, 16, 32 }); + params2.setPrecinctHeight(new int[] { 8, 16, 32 }); + + assertEquals(params1, params2); + } + + @Test + void testTileComponentCodingParametersNotEquals() { + TileComponentCodingParameters params1 = new TileComponentCodingParameters(); + params1.setCodingStyle(1); + params1.setNoOfResolutions(3); + + TileComponentCodingParameters params2 = new TileComponentCodingParameters(); + params2.setCodingStyle(2); // Different coding style + + assertNotEquals(params1, params2); + } + + @Test + void testTileComponentCodingParametersHashCode() { + TileComponentCodingParameters params1 = new TileComponentCodingParameters(); + params1.setCodingStyle(1); + params1.setNoOfResolutions(3); + + TileComponentCodingParameters params2 = new TileComponentCodingParameters(); + params2.setCodingStyle(1); + params2.setNoOfResolutions(3); + + assertEquals(params1.hashCode(), params2.hashCode()); + } + + @Test + void testTileComponentCodingParametersCanEqual() { + TileComponentCodingParameters params1 = new TileComponentCodingParameters(); + assertTrue(params1.canEqual(new TileComponentCodingParameters())); + } + + @Test + void testTileComponentCodingParametersToString() { + TileComponentCodingParameters params = new TileComponentCodingParameters(); + params.setCodingStyle(1); + params.setNoOfResolutions(3); + String toStringOutput = params.toString(); + assertTrue(toStringOutput.contains("codingStyle=1")); + assertTrue(toStringOutput.contains("noOfResolutions=3")); + } + + @Test + void testTileInfoEquals() { + TileInfo tileInfo1 = new TileInfo(); + tileInfo1.setTileNo(1); + tileInfo1.setStartPosition(0); + tileInfo1.setEndHeader(100); + tileInfo1.setEndPosition(200); + tileInfo1.setThresh(new double[] { 0.5, 1.0 }); + tileInfo1.setPWidth(new int[] { 8, 16, 32 }); + tileInfo1.setPHeight(new int[] { 8, 16, 32 }); + tileInfo1.setPDX(new int[] { 2, 3, 4 }); + tileInfo1.setPDY(new int[] { 2, 3, 4 }); + tileInfo1.setNoOfPixel(150); + tileInfo1.setDistortionTile(0.05); + tileInfo1.setNoOfTileParts(2); + tileInfo1.setPacket(new PacketInfo[2]); + tileInfo1.setTp(new TpInfo[2]); + + TileInfo tileInfo2 = new TileInfo(); + tileInfo2.setTileNo(1); + tileInfo2.setStartPosition(0); + tileInfo2.setEndHeader(100); + tileInfo2.setEndPosition(200); + tileInfo2.setThresh(new double[] { 0.5, 1.0 }); + tileInfo2.setPWidth(new int[] { 8, 16, 32 }); + tileInfo2.setPHeight(new int[] { 8, 16, 32 }); + tileInfo2.setPDX(new int[] { 2, 3, 4 }); + tileInfo2.setPDY(new int[] { 2, 3, 4 }); + tileInfo2.setNoOfPixel(150); + tileInfo2.setDistortionTile(0.05); + tileInfo2.setNoOfTileParts(2); + tileInfo2.setPacket(new PacketInfo[2]); + tileInfo2.setTp(new TpInfo[2]); + + assertEquals(tileInfo1, tileInfo2); + } + + @Test + void testTileInfoNotEquals() { + TileInfo tileInfo1 = new TileInfo(); + tileInfo1.setTileNo(1); + tileInfo1.setStartPosition(0); + + TileInfo tileInfo2 = new TileInfo(); + tileInfo2.setTileNo(2); // Different tile number + + assertNotEquals(tileInfo1, tileInfo2); + } + + @Test + void testTileInfoHashCode() { + TileInfo tileInfo1 = new TileInfo(); + tileInfo1.setTileNo(1); + tileInfo1.setStartPosition(0); + + TileInfo tileInfo2 = new TileInfo(); + tileInfo2.setTileNo(1); + tileInfo2.setStartPosition(0); + + assertEquals(tileInfo1.hashCode(), tileInfo2.hashCode()); + } + + @Test + void testTileInfoCanEqual() { + TileInfo tileInfo1 = new TileInfo(); + assertTrue(tileInfo1.canEqual(new TileInfo())); + } + + @Test + void testTileInfoToString() { + TileInfo tileInfo = new TileInfo(); + tileInfo.setTileNo(1); + tileInfo.setStartPosition(0); + String toStringOutput = tileInfo.toString(); + assertTrue(toStringOutput.contains("tileNo=1")); + assertTrue(toStringOutput.contains("startPosition=0")); + } + + @Test + void testTpInfoEquals() { + TpInfo tpInfo1 = new TpInfo(); + tpInfo1.setTpStartPosition(0); + tpInfo1.setTpEndHeader(100); + tpInfo1.setTpEndPosition(200); + tpInfo1.setTpStartPacket(0); + tpInfo1.setTpNoOfPackets(10); + + TpInfo tpInfo2 = new TpInfo(); + tpInfo2.setTpStartPosition(0); + tpInfo2.setTpEndHeader(100); + tpInfo2.setTpEndPosition(200); + tpInfo2.setTpStartPacket(0); + tpInfo2.setTpNoOfPackets(10); + + assertEquals(tpInfo1, tpInfo2); + } + + @Test + void testTpInfoNotEquals() { + TpInfo tpInfo1 = new TpInfo(); + tpInfo1.setTpStartPosition(0); + + TpInfo tpInfo2 = new TpInfo(); + tpInfo2.setTpStartPosition(1); // Different tpStartPosition + + assertNotEquals(tpInfo1, tpInfo2); + } + + @Test + void testTpInfoHashCode() { + TpInfo tpInfo1 = new TpInfo(); + tpInfo1.setTpStartPosition(0); + tpInfo1.setTpEndHeader(100); + tpInfo1.setTpEndPosition(200); + tpInfo1.setTpStartPacket(0); + tpInfo1.setTpNoOfPackets(10); + + TpInfo tpInfo2 = new TpInfo(); + tpInfo2.setTpStartPosition(0); + tpInfo2.setTpEndHeader(100); + tpInfo2.setTpEndPosition(200); + tpInfo2.setTpStartPacket(0); + tpInfo2.setTpNoOfPackets(10); + + assertEquals(tpInfo1.hashCode(), tpInfo2.hashCode()); + } + + @Test + void testTpInfoCanEqual() { + TpInfo tpInfo1 = new TpInfo(); + assertTrue(tpInfo1.canEqual(new TpInfo())); + } + + @Test + void testTpInfoToString() { + TpInfo tpInfo = new TpInfo(); + tpInfo.setTpStartPosition(0); + String toStringOutput = tpInfo.toString(); + assertTrue(toStringOutput.contains("tpStartPosition=0")); + } + + @Test + void testV4Equals() { + V4 v4_1 = new V4(); + v4_1.setF(new double[] { 1.0, 2.0, 3.0, 4.0 }); + + V4 v4_2 = new V4(); + v4_2.setF(new double[] { 1.0, 2.0, 3.0, 4.0 }); + + assertEquals(v4_1, v4_2); + } + + @Test + void testV4NotEquals() { + V4 v4_1 = new V4(); + v4_1.setF(new double[] { 1.0, 2.0, 3.0, 4.0 }); + + V4 v4_2 = new V4(); + v4_2.setF(new double[] { 1.0, 2.0, 3.0, 5.0 }); // Different last element + + assertNotEquals(v4_1, v4_2); + } + + @Test + void testV4HashCode() { + V4 v4_1 = new V4(); + v4_1.setF(new double[] { 1.0, 2.0, 3.0, 4.0 }); + + V4 v4_2 = new V4(); + v4_2.setF(new double[] { 1.0, 2.0, 3.0, 4.0 }); + + assertEquals(v4_1.hashCode(), v4_2.hashCode()); + } + + @Test + void testV4CanEqual() { + V4 v4 = new V4(); + assertTrue(v4.canEqual(new V4())); + } + + @Test + void testV4ToString() { + V4 v4 = new V4(); + v4.setF(new double[] { 1.0, 2.0, 3.0, 4.0 }); + String toStringOutput = v4.toString(); + assertTrue(toStringOutput.contains("f=[1.0, 2.0, 3.0, 4.0]")); // Adjust as per the expected format + } + + @Test + void testJ2kStatusFromValueValid() { + assertEquals(J2kStatus.J2K_STATE_MHSOC, J2kStatus.fromValue(0x0001)); + assertEquals(J2kStatus.J2K_STATE_MHSIZ, J2kStatus.fromValue(0x0002)); + assertEquals(J2kStatus.J2K_STATE_MH, J2kStatus.fromValue(0x0004)); + assertEquals(J2kStatus.J2K_STATE_TPHSOT, J2kStatus.fromValue(0x0008)); + assertEquals(J2kStatus.J2K_STATE_TPH, J2kStatus.fromValue(0x0010)); + assertEquals(J2kStatus.J2K_STATE_MT, J2kStatus.fromValue(0x0020)); + assertEquals(J2kStatus.J2K_STATE_NEOC, J2kStatus.fromValue(0x0040)); + assertEquals(J2kStatus.J2K_STATE_ERR, J2kStatus.fromValue(0x0080)); + } + + @Test + void testJ2kStatusFromValueInvalid() { + Exception exception = assertThrows(IllegalArgumentException.class, () -> { + J2kStatus.fromValue(0x9999); // Invalid value + }); + + String expectedMessage = "No enum constant for value: 39321"; // 39321 is 0x9999 in decimal + String actualMessage = exception.getMessage(); + + assertTrue(actualMessage.contains(expectedMessage)); + } + + @Test + void testJ2kStatusValue() { + assertEquals(0x0001, J2kStatus.J2K_STATE_MHSOC.value()); + assertEquals(0x0002, J2kStatus.J2K_STATE_MHSIZ.value()); + assertEquals(0x0004, J2kStatus.J2K_STATE_MH.value()); + assertEquals(0x0008, J2kStatus.J2K_STATE_TPHSOT.value()); + assertEquals(0x0010, J2kStatus.J2K_STATE_TPH.value()); + assertEquals(0x0020, J2kStatus.J2K_STATE_MT.value()); + assertEquals(0x0040, J2kStatus.J2K_STATE_NEOC.value()); + assertEquals(0x0080, J2kStatus.J2K_STATE_ERR.value()); + } + + @Test + void testJ2kStatusToString() { + assertTrue(J2kStatus.J2K_STATE_MHSOC.toString().contains("J2K_STATE_MHSOC(1)")); + assertTrue(J2kStatus.J2K_STATE_MHSIZ.toString().contains("J2K_STATE_MHSIZ(2)")); + assertTrue(J2kStatus.J2K_STATE_MH.toString().contains("J2K_STATE_MH(4)")); + assertTrue(J2kStatus.J2K_STATE_TPHSOT.toString().contains("J2K_STATE_TPHSOT(8)")); + assertTrue(J2kStatus.J2K_STATE_TPH.toString().contains("J2K_STATE_TPH(10)")); + assertTrue(J2kStatus.J2K_STATE_MT.toString().contains("J2K_STATE_MT(20)")); + assertTrue(J2kStatus.J2K_STATE_NEOC.toString().contains("J2K_STATE_NEOC(40)")); + assertTrue(J2kStatus.J2K_STATE_ERR.toString().contains("J2K_STATE_ERR(80)")); + } + + @Test + void testJ2KT2ModeFromValueValid() { + assertEquals(J2KT2Mode.THRESH_CALC, J2KT2Mode.fromValue(0)); + assertEquals(J2KT2Mode.FINAL_PASS, J2KT2Mode.fromValue(1)); + } + + @Test + void testJ2KT2ModeFromValueInvalid() { + Exception exception = assertThrows(IllegalArgumentException.class, () -> { + J2KT2Mode.fromValue(2); // Invalid value + }); + + String expectedMessage = "No enum constant for value: 2"; + String actualMessage = exception.getMessage(); + + assertTrue(actualMessage.contains(expectedMessage)); + } + + @Test + void testJ2KT2ModeValue() { + assertEquals(0, J2KT2Mode.THRESH_CALC.value()); + assertEquals(1, J2KT2Mode.FINAL_PASS.value()); + } + + @Test + void testJ2KT2ModeToString() { + assertTrue(J2KT2Mode.THRESH_CALC.toString().contains("THRESH_CALC(0)")); + assertTrue(J2KT2Mode.FINAL_PASS.toString().contains("FINAL_PASS(1)")); + } + + @Test + void testJP2CinemeaModeFromValueValid() { + assertEquals(JP2CinemeaMode.CINEMA2K_24, JP2CinemeaMode.fromValue(1)); + assertEquals(JP2CinemeaMode.CINEMA2K_48, JP2CinemeaMode.fromValue(2)); + assertEquals(JP2CinemeaMode.CINEMA4K_24, JP2CinemeaMode.fromValue(3)); + assertEquals(JP2CinemeaMode.OFF, JP2CinemeaMode.fromValue(0)); + } + + @Test + void testJP2CinemeaModeFromValueInvalid() { + Exception exception = assertThrows(IllegalArgumentException.class, () -> { + JP2CinemeaMode.fromValue(99); // Invalid value + }); + + String expectedMessage = "No enum constant for value: 99"; + String actualMessage = exception.getMessage(); + + assertTrue(actualMessage.contains(expectedMessage)); + } + + @Test + void testJP2CinemeaModeValue() { + assertEquals(0, JP2CinemeaMode.OFF.value()); + assertEquals(1, JP2CinemeaMode.CINEMA2K_24.value()); + assertEquals(2, JP2CinemeaMode.CINEMA2K_48.value()); + assertEquals(3, JP2CinemeaMode.CINEMA4K_24.value()); + } + + @Test + void testJP2CinemeaModeToString() { + assertTrue(JP2CinemeaMode.OFF.toString().contains("OFF(0)")); + assertTrue(JP2CinemeaMode.CINEMA2K_24.toString().contains("CINEMA2K_24(1)")); + assertTrue(JP2CinemeaMode.CINEMA2K_48.toString().contains("CINEMA2K_48(2)")); + assertTrue(JP2CinemeaMode.CINEMA4K_24.toString().contains("CINEMA4K_24(3)")); + } + + @Test + void testJP2CodecFormatFromValueValid() { + assertEquals(JP2CodecFormat.CODEC_J2K, JP2CodecFormat.fromValue(0)); + assertEquals(JP2CodecFormat.CODEC_JPT, JP2CodecFormat.fromValue(1)); + assertEquals(JP2CodecFormat.CODEC_JP2, JP2CodecFormat.fromValue(2)); + assertEquals(JP2CodecFormat.CODEC_UNKNOWN, JP2CodecFormat.fromValue(-1)); + } + + @Test + void testJP2CodecFormatFromValueInvalid() { + Exception exception = assertThrows(IllegalArgumentException.class, () -> { + JP2CodecFormat.fromValue(3); // Invalid value + }); + + String expectedMessage = "No enum constant for value: 3"; + String actualMessage = exception.getMessage(); + + assertTrue(actualMessage.contains(expectedMessage)); + } + + @Test + void testJP2CodecFormatValue() { + assertEquals(-1, JP2CodecFormat.CODEC_UNKNOWN.value()); + assertEquals(0, JP2CodecFormat.CODEC_J2K.value()); + assertEquals(1, JP2CodecFormat.CODEC_JPT.value()); + assertEquals(2, JP2CodecFormat.CODEC_JP2.value()); + } + + @Test + void testJP2CodecFormatToString() { + assertTrue(JP2CodecFormat.CODEC_J2K.toString().contains("CODEC_J2K(0)")); + assertTrue(JP2CodecFormat.CODEC_JPT.toString().contains("CODEC_JPT(1)")); + assertTrue(JP2CodecFormat.CODEC_JP2.toString().contains("CODEC_JP2(2)")); + } + + @Test + void testJp2ColorSpaceFromValueValid() { + assertEquals(Jp2ColorSpace.CLRSPC_SRGB, Jp2ColorSpace.fromValue(1)); + assertEquals(Jp2ColorSpace.CLRSPC_GRAY, Jp2ColorSpace.fromValue(2)); + assertEquals(Jp2ColorSpace.CLRSPC_SYCC, Jp2ColorSpace.fromValue(3)); + assertEquals(Jp2ColorSpace.CLRSPC_UNKNOWN, Jp2ColorSpace.fromValue(-1)); + } + + @Test + void testJp2ColorSpaceFromValueInvalid() { + Exception exception = assertThrows(IllegalArgumentException.class, () -> { + Jp2ColorSpace.fromValue(4); // Invalid value + }); + + String expectedMessage = "No enum constant for value: 4"; + String actualMessage = exception.getMessage(); + + assertTrue(actualMessage.contains(expectedMessage)); + } + + @Test + void testJp2ColorSpaceValue() { + assertEquals(-1, Jp2ColorSpace.CLRSPC_UNKNOWN.value()); + assertEquals(1, Jp2ColorSpace.CLRSPC_SRGB.value()); + assertEquals(2, Jp2ColorSpace.CLRSPC_GRAY.value()); + assertEquals(3, Jp2ColorSpace.CLRSPC_SYCC.value()); + } + + @Test + void testJp2ColorSpaceToString() { + assertTrue(Jp2ColorSpace.CLRSPC_SRGB.toString().contains("CLRSPC_SRGB(1)")); + assertTrue(Jp2ColorSpace.CLRSPC_GRAY.toString().contains("CLRSPC_GRAY(2)")); + assertTrue(Jp2ColorSpace.CLRSPC_SYCC.toString().contains("CLRSPC_SYCC(3)")); + } + + @Test + void testLimitDecodingFromValueValid() { + assertEquals(LimitDecoding.NO_LIMITATION, LimitDecoding.fromValue(0)); + assertEquals(LimitDecoding.LIMIT_TO_MAIN_HEADER, LimitDecoding.fromValue(1)); + assertEquals(LimitDecoding.DECODE_ALL_BUT_PACKETS, LimitDecoding.fromValue(2)); + } + + @Test + void testLimitDecodingFromValueInvalid() { + Exception exception = assertThrows(IllegalArgumentException.class, () -> { + LimitDecoding.fromValue(3); // Invalid value + }); + + String expectedMessage = "No enum constant for value: 3"; + String actualMessage = exception.getMessage(); + + assertTrue(actualMessage.contains(expectedMessage)); + } + + @Test + void testLimitDecodingValue() { + assertEquals(0, LimitDecoding.NO_LIMITATION.value()); + assertEquals(1, LimitDecoding.LIMIT_TO_MAIN_HEADER.value()); + assertEquals(2, LimitDecoding.DECODE_ALL_BUT_PACKETS.value()); + } + + @Test + void testLimitDecodingToString() { + assertTrue(LimitDecoding.NO_LIMITATION.toString().contains("NO_LIMITATION(0)")); + assertTrue(LimitDecoding.LIMIT_TO_MAIN_HEADER.toString().contains("LIMIT_TO_MAIN_HEADER(1)")); + assertTrue(LimitDecoding.DECODE_ALL_BUT_PACKETS.toString().contains("DECODE_ALL_BUT_PACKETS(2)")); + } + + @Test + void testProgressionOrderFromValueValid() { + assertEquals(ProgressionOrder.LRCP, ProgressionOrder.fromValue(0)); + assertEquals(ProgressionOrder.RLCP, ProgressionOrder.fromValue(1)); + assertEquals(ProgressionOrder.RPCL, ProgressionOrder.fromValue(2)); + assertEquals(ProgressionOrder.PCRL, ProgressionOrder.fromValue(3)); + assertEquals(ProgressionOrder.CPRL, ProgressionOrder.fromValue(4)); + } + + @Test + void testProgressionOrderFromValueInvalid() { + Exception exception = assertThrows(IllegalArgumentException.class, () -> { + ProgressionOrder.fromValue(5); // Invalid value + }); + + String expectedMessage = "No enum constant for value: 5"; + String actualMessage = exception.getMessage(); + + assertTrue(actualMessage.contains(expectedMessage)); + } + + @Test + void testProgressionOrderValue() { + assertEquals(0, ProgressionOrder.LRCP.value()); + assertEquals(1, ProgressionOrder.RLCP.value()); + assertEquals(2, ProgressionOrder.RPCL.value()); + assertEquals(3, ProgressionOrder.PCRL.value()); + assertEquals(4, ProgressionOrder.CPRL.value()); + } + + @Test + void testProgressionOrderToString() { + assertTrue(ProgressionOrder.LRCP.toString().contains("LRCP(0)")); + assertTrue(ProgressionOrder.RLCP.toString().contains("RLCP(1)")); + assertTrue(ProgressionOrder.RPCL.toString().contains("RPCL(2)")); + assertTrue(ProgressionOrder.PCRL.toString().contains("PCRL(3)")); + assertTrue(ProgressionOrder.CPRL.toString().contains("CPRL(4)")); + } + + @Test + void testRsizCapabilitiesFromValueValid() { + assertEquals(RsizCapabilities.STD_RSIZ, RsizCapabilities.fromValue(0)); + assertEquals(RsizCapabilities.CINEMA2K, RsizCapabilities.fromValue(3)); + assertEquals(RsizCapabilities.CINEMA4K, RsizCapabilities.fromValue(4)); + } + + @Test + void testRsizCapabilitiesFromValueInvalid() { + Exception exception = assertThrows(IllegalArgumentException.class, () -> { + RsizCapabilities.fromValue(5); // Invalid value + }); + + String expectedMessage = "No enum constant for value: 5"; + String actualMessage = exception.getMessage(); + + assertTrue(actualMessage.contains(expectedMessage)); + } + + @Test + void testRsizCapabilitiesValue() { + assertEquals(0, RsizCapabilities.STD_RSIZ.value()); + assertEquals(3, RsizCapabilities.CINEMA2K.value()); + assertEquals(4, RsizCapabilities.CINEMA4K.value()); + } + + @Test + void testRsizCapabilitiesToString() { + assertTrue(RsizCapabilities.STD_RSIZ.toString().contains("STD_RSIZ(0)")); + assertTrue(RsizCapabilities.CINEMA2K.toString().contains("CINEMA2K(3)")); + assertTrue(RsizCapabilities.CINEMA4K.toString().contains("CINEMA4K(4)")); + } +} \ No newline at end of file diff --git a/imagedecoder/src/test/java/io/mosip/imagedecoder/test/OpenJpegDecoderTest.java b/imagedecoder/src/test/java/io/mosip/imagedecoder/test/OpenJpegDecoderTest.java new file mode 100644 index 0000000..bd4cf71 --- /dev/null +++ b/imagedecoder/src/test/java/io/mosip/imagedecoder/test/OpenJpegDecoderTest.java @@ -0,0 +1,72 @@ +package io.mosip.imagedecoder.test; + +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_EMPTY; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_IDTYPE; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_SESSIONID; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.text.MessageFormat; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import io.mosip.imagedecoder.constant.DecoderErrorCodes; +import io.mosip.imagedecoder.logger.ImageDecoderLogger; +import io.mosip.imagedecoder.model.DecoderRequestInfo; +import io.mosip.imagedecoder.model.DecoderResponseInfo; +import io.mosip.imagedecoder.model.Response; +import io.mosip.imagedecoder.model.openjpeg.Cio; +import io.mosip.imagedecoder.model.openjpeg.DecompressionContextInfo; +import io.mosip.imagedecoder.model.openjpeg.JP2CodecFormat; +import io.mosip.imagedecoder.model.openjpeg.OpenJpegImage; +import io.mosip.imagedecoder.openjpeg.OpenJpegDecoder; +import io.mosip.imagedecoder.openjpeg.OpenJpegHelper; +import io.mosip.imagedecoder.util.Base64UrlUtil; +import io.mosip.kernel.core.logger.spi.Logger; + +class OpenJpegDecoderTest { + private static Logger logger = ImageDecoderLogger.getLogger(OpenJpegDecoderTest.class); + + private OpenJpegDecoder openJpegDecoder; + private OpenJpegHelper mockOpenJpegHelper; + + @BeforeEach + void setUp() { + mockOpenJpegHelper = mock(OpenJpegHelper.class); + openJpegDecoder = new OpenJpegDecoder(); + } + + @Test + void testDecodeSuccess() { + // Arrange + DecoderRequestInfo requestInfo = new DecoderRequestInfo(); + requestInfo.setImageData(Base64UrlUtil.getInstance().decodeURLSafeBase64("AAAADGpQICANCocKAAAAFGZ0eXBqcDIgAAAAAGpwMiAAAABHanAyaAAAABZpaGRyAAABQAAAAPAAAwcHAAAAAAAPY29scgEAAAAAABAAAAAacmVzIAAAABJyZXNjA-gA_gPoAP4EBAAAAABqcDJj_0__UQAvAAAAAADwAAABQAAAAAAAAAAAAAAA8AAAAUAAAAAAAAAAAAADBwEBBwEBBwEB_1wAF0JnNWdMZ0xnZE8ITwhPhEbXRtdGbf9SAAwAAAABAQMEBAAA_2QADgABTFRfSlAyXzIyNv-QAAoAAAAARxgAAf-Tz-fWdJt6TanYMXQQOScICqcoIvo97xCBLu7OD1pVh0of0su2Y6YHDW-JLvHRkR3Qggjm02MRF82ipfmeXUQTeJMw4TFEB9rk6B0To6OlqQuGm2xg77x1xAlJ4Mo9MwtAXwSRPXA0rbFDI4XjJvmI3nkO1uUUZZuRnWiDWJG3o1w2ICOp5Xjx4nKybetcG314Rwyah9BY_cFyOOTVaz9ib2iYwCPgQTQqlMo0_n5NtkIyrA8xa46u8nQzsRXNgMI04_qmq8HJ115Ckd9FxFzHE009BZTtUCnAU5RGvX1DNzt73i6xDw0_0h3-qiu3ml4CLGwI76ezbHaJXYu0tN5I9UaxklRPU07CCkYrrYT9BKO4HgzxQ00gCTkHGEwofHwlAB1vIsKPkCAIhMSIDGuhhXlfHAq8QWzoVBZI5F1MIeAVzTE97EH3BG0iA-gGlHoLzvOlfprPcMKoYpn3HckjygC7MHMppM2GCkIDCMeT9WaYT5S931U2cvRu3J-E0EPmPIPCIrJBSXiMdIwdp6s9p8qXRQ2mkvK7EDJUHkYmjmVA-WBmBdkm6AZ2oOh96yz3Zgdwb0FwRe4MOO7RwsV4glf7qONvObMLgLmI6g9NxwMG22TY-kSz-InsbGdoaPdAskGN1oZZnWz5pjV5PvRfN_RthlEL7lVpAC8C_f8g2CZ3jyVnRbe08bX-HmfuaLsJt3RafR05J7T328ySCq3b74WT0dgFjkSpoUTxaHyPtnnEBIe6_BKW0EhlaPxi4jrZQvDJSRo9Ql8LCjOTfhwRRG4-poqbC92xAKRbBtLFaRKqVGtwUQeUy9yOJREmU2kTxI7J0YEnUs5Q-ukeynQAvPm9jgGIwFvFAP8549cDefkqFhwjFjZyK2GNWyip6fHNgeLyWTiOVMs4f9WRXPXQYkBEfjSOL3pQ5EtFvZhahzBuz0bOK1NaxeQ3x1wl3feEU_q_EElaW1y-zbB6Vwv35-SkLyI8jUuBHmTc5B8-P9iumhtppnyL_s25H3qWuus4tp-H8r0iElS29C_5TGh12rLKKIvazp8QWC0EmhXPYtRAolKT6kVXTws1Vm4ApfV1m19Ra3YkJo4b-RxqHDGl-vooB08HMP0znQHjqBpEBXyhb1nTrIivPIDeX7tid7M5VMNyAgnyx_JolKIi_o-QZdqcJGZe_ZD3IiGvsl3vY5c_8XbruWdiGzWEYt5-XZr3JXVGyq3UQvDWB_r9Q7fiXKGuTfr7NGnk6A520XMXDzo_pfR3MndbiCO-j1XdCsO17Yl8LkmcC6fdb5LIyjST9rxAY3CfGzKUa_6O8EkwkQBtI3dDvah5TiU28FWkZBliqs5aPts3GzyUWAsnNS5At8g7ez6c0jI0nmj7-XeZk_K4Tc3ggWz2i0sLXueFqvyPFiT4PtUO831nRRMwTnJ6XKLlNJY9Byf9luQllT3GTwYF8Svstmg332qkfOiE2sv6I9KgwXwhbvdB8DzTqN4LnTo1PbS87fEZyLfgEzbH9rcPcxYu_lOxU5_Z0iw1QNHFa03UiaahYg8O_yIQvY-ySGpmheuxxsJR7r_Hnv8uqNMcdsZ4PoW8If8qAWjFIDgSSz0CP8AOafBNDEfr70IolrObX5-aCxppQnV3wglK2VyvB-ijX-J1vOr9_dCFwqjrIjV7uRU-GaPQG1PU6TC7MRSzyVc8AFjOjhyjrKsuqe495fnF1jVmx8JWpIbXzHYBjpN7bQnkhRACJdwoFYvJHqoJYOkofbhjyX-e6XPRbSsiLBUSESlJGaAHh8tVs5Dkw_oETRHoTiwyyIxjRubEHaIqACefaAJ2RO6ERJQEe0JbpXCRRqrWkkhSFz5AwUL5HwQkpYMZ3lciQvjL-b9fKfJXgsSJLDXTvsi8N9y6YquR6ZG2dEqY_Wwj6bFzQSlYv8Pz70ASYkmLXN4hEkmLMPe6t1U4qQiMSPTQSsSVTaMQBiyeh7vqvfbTJZrtHeNCb6Moo0f3LWUyxTDjP46_9yeLIZPlwz8ox552GWl7GwoaDo0qmIgbjWUBlEKQOmq2K0PcJ5vC-L2fA27aPy9oUgH0y4jX65LQZze4I6MyaeOB7FjTjpk1N3QmamFOSteAJZ4jNCuhsEETgWYkXpNKx9X-x5_NnAcjgdrTFnwNxt0FZqiVLdyDwd1YZ_xicY3Hv7ljB4YqKcCyDNtRAHBBgSOu2z9Lfd0030NOtwYNF9VDbQTbRd2ob5nMgvic2_BUgp0Q9b37-2e5hS3krHD2ExVQFcYJKjL-Ib6f4EvTR08mNSDh_pPUt-aKtAg0U8vsGwoo89yuVVa8eJPalEyDs8Xf_D52gkGtXXTOu9R6EK12UEmGs_FBsBpZeGw_MP4c_10lO_gEPG18jYOvDdV12ZQUgFOORdR-BAdEKJEBB9j2AC_R9oZkUZ6DfnODIxhbl6t5ZrN4Kj_3K4BUsUiTHQTSGMN8iEp9YGXkVhqFpJ6d_pKju6Bygibwsl5MPRza5dl8VOP6SfRr23CWJ2pxB_KG7wepp-L_NWGDWU--C4wMmWq9rOIpc8-zadHng3w9p1vMIRBM94ye0tSmJZXvZDw9c0myosJet2GMIYhIe63Bn-1YzCBBF1t5GODzBWonmx5VqkHe-QQk2UD7dr8aMAh1u4c6for8m2KPv-ftRol-CwndmiGs9bAuFqDpjnPjnELT_S_ESnnZCUNFXPnaWm-4OQbGLngH2YzgZ-2s9nbJlMG926xas1Rei0JCte_u9a0uB841otud0TVrNP9zWbH7rFP7nIyfdgmzypVFJyFDMrEQ-5xlG3YGUhPFujyXxkQcyYgdiKOYfsex_Vfdo_M-mrIDnoWNBZsxNBuA1uuQ9AG83YwokLhZyOgmknDcGozpWLcqZ9hyRSGPtBk8_2UbPHQ0XiOZCH5IoKOs1qXBQL3YY9GzfEZLIjwZh0fSo62MCXcvPECPMdPFFVQsN1zOfd2i8GnCL0BLFrYGz3cjiTT7OxjnfLv4_o5drM5HKIZIXeGp0rwv58Cd53FGRpEc2Qvg8WhX2snq_iHZ5_ZZH62vTPc9EEHlF5KB6z_Zz27afo9XJ7QMDaOGJsopMApxCKlDDfSb6L5j8i-hIXakLbVTx1NanPdtkqllP4PV_P6He5VUq8ftN4EBmr8fxQ9f5l9Meyo6IWbsFNODKmeYvjrB-M6YPoQmvK_tkM3zQ2tWk_jhRQmVRHhWxvsRa9PN73Q_w_PuMBUqG8-qf4nBkbkngy2DMRjBYs703gvxYoFL3pkc1n1OZ6TO2hD22wE537cEPid56oO8-EIJYNrsQWuv8cn4nsz1uvU8D081vlwUL30f3DAN7aL1bJ8OjYPCMUCPWWB9fQi9qWsHzY6qWorZYo4imBgqcuV5m-0Y7Z_Ol4qbYH0gWelbDYkoJ4Q19uEbMQabDC3cHuyg_ssqCEGYhSF1CcIiljUopUauxpxqQ6Mo2_8N86vk7uVr02p9TgdRMk1c2CtrUkZrSjE1iY7jHzkSf7qO53i_7gHtOkwjJ8IXTmocxg2ylzahhad6_WmnPCqOaqKy5UcVValFysMzbTX-6s-LB6WtZ2pxOfwnArc2B9XiUdl_5pePablOQDKSb6QsW1Fle7xZVtn6cLt0jbTuQ768sTb_Xn8ghZ3CUKU35ixSSsS07bJMUWXqc7svHZStQFfTjF8AtJQGrz9YxVPy8UNTSF-QqbC53O41bI7pcc7vNT9eaea05JJCr4GeFe9NGQPi4FMJ-wY7rc_IDbtMh3FQxzPxZMXJatkMwx_P1qFy9m92JfZNTt4KjLJsJR5vqP2KXs97seR8L2duVxyntN8rCTViIIU09r5tHAzKqbxZNDK1PZSo6U1wFRH5ACFaxHLUBkQgOmiSr3BoEH_EBit3rkLKFUkzl1L7E4w0OokwaLX5OAQPjhaJqtYAWSB44Tg8NDnXdgdhm54wLB6Ch_PHstVHgSMrWELjr1USTDjbmVXp88_OMWiFTMfSHz9zanzsJ-hc_Atff-S3-9bnzZMnYvAuq7XA89dtplrLkEJ8f60K6M6HsPkin1jW76PqBEFDbzxoOtf2gkcA-zyqcCoKctKsMl2Th0uD7ktcEpaqkv1WyGnuhPrWWKo9POIY_XFpUWqNtYYHmHoOB8SKgue3Zlniz94wAq6AtA1QHk17ds-O0mNXGACWrw-L00asEKBEM3srVsY8xg6ypiebOgoxco2R9SBhFX6QsSX8QzNCR93k82TscDSt5FJeDP96-WU6JmEb26EthCJlGut_b41E1T8-luBQXceQz-pF7R4VWBez9uqCR1f0ceDYG_ADRgUV1yNhjhVvDGAVWcZ8AD31YessSeGTeBmOTM5D0FfWBdDA2t7oyQIuMwKrUzjxyITo6A_yi-duJKrbb6H7GL6uplNN7kJ8OerFOvqgGmufF12SlAB_lbUSEUu1w_PuHj9u72H59ljERx1CwCsYg4qq_pLAG01QHAB7N7XPBqjkAPbs7K2MMisFcPYJ221LyR24WBU-cCwF1CUfsAMVPDS17Skf9qheTJzsjtsLcQ_41gNPIo36QESBkp_xrKo_gAEL-G0PocZLFs6yjfrrOAFm5RK9iSJYwZHhULoRW0TFzgeLnQhgzx8BJi2ZyxI42kPSJxuNIlxtTvcFSHnjl3RqF7TOOkeEBKI8xKNoQgc45aJMjSC-bEgsnZFSPhTREnw2YyCih-oSFlUdRyPMOIaIhdAdYMowyXi5OXhX-3GbyAr1Jo-ztTiU-TiEzxlY7yLGY-Iry4_7TOEYngqqwf9enLiHKrBggz4FTZJq229ms_TS6lzK49kiONYq5gKOdu4SsanjFLoufO-9whsC7mAoS6Cb_rXrICBQR-hPkYMjD4qzOZkUJje1MI_eP-xBSAaTqCZlQ0FEPRq5eaqHQINsnDsAhWMhdr2wZJf0Vv8oI48WymnFze1XzI42VcOLkDP3-yuj-YaeHe_QSt8Mcrse35ECOUk_NzlNOkx0l4FH88vzScl8FslZvZ9-1zQi-onJy4nuMtgl5iCuC3KprTFjbysZ0oGyZqCx2K0CBQU6q0TZYesd8TjNch58RPACtXabzE0L8rORmHPd2idF_nADhY6BYIwTMgC-YVid30OYixk0DDA2E8_fQarI6Nze-JLh_RwBXwzWjfoqPtg0UOAa1Tkz9NXL8Wk5QmfAqsUXv9zGVGqKODBhfrpoXMsBLoelvSfiJO0ayriV6uUR6WmIrxNpgSj73zlTQorrozp77NoG22aHttPD5JkKkFN0R9tiKK0nFEuDBo5TELcU_ysQdOiUP61vRx7RH20X6xkOw1ZXSxpmy9a-xoTKfJKlpdHYoX5iuv972FnmL98k8ZShbLtOkV9ZByZ8h4pu4WRzvqi6xHxKmG4AjwNvClqi4Lx-XQkxQPCi7ZsXvJJiGSeICQ1Hcv7bpTI8qqLHKKeChDvc8-t8xy0sJpe1sbuVNpuvkIJCZ4MNSP9BuHNbWvZ2EhMh3E4WL3CjyElvvBd-GdtgQ9Z3PVJd18BjBRY5xrCoCCy7GSEByJn48A4V_yXL4xcSjM2cfZWWvypo-fVx0oRgEu2gLP8mVbDoCANl48-xuD4O36NdrHMh4O2SkmBkbz4YrG95c0wnmwOU0xuZsZ-W_XuHhnpgwbBaQnvkcS15ksHGTkDTxOnLWcxnV-oX0qvXjESns5PAzdU8I9LLs8R5QbDGaxlIE7L6cCUibuOPQTTeVHpn30HTV4Bc0cuabjVOmaX1C_timcdKM_U6n-fUuYR1kv6hc-5HR6pYWE_NmSOsQd7wELeXVgtDRPAFHPi9ImEarH-RXRtcme20pQr5f8WRr52RFf7px7qvsjxj6BFcShvbT_CmBzPx7Ye-Ov0SvgXGtkVBwqi4-l6yBl02CcX01VDfgQaVrSThwbSTI29KqgMS_1pd06UXPexIX-0eUEH14k-hPZilSpnmKc9_OFhGVgo2GjJgJGHEVV_gtPJ2ya1XY3p-Rus1Rk_ioDURJlirycG_UGOpaVh9Vol-08-4lhHyuuY3bYp1NYbBNEcAo-my6qIfcQLaK9MJrGMV9WsUUEwfQhz4Nml3Yd2Swnlnz8NdjUoY34ZJ1FMdcwNF48HF9m4M196ctxRnCvkxp_raWHAWECe-hmkQErpQP4l9UJcoeOnN0TZ7RJrv7I6uO7nQmRmUls0KVJP42rv0a7FrXtrPzK7mJhe4KN9xi2Tt7CDixhdZCVlYwmAOJEp2SFJMLKM7i-ttzKR9-jvT0wQ62agn7IuPMW-EFLO1VowFtr5P2zO6XR2UhD9y1Wa7pZRTqVPUSiK_kwPVrDz0qAXoHfwQ17oTVK5dU6AlvZlUTKJr4NTeN3qr24AO7WIc5_dIx6vEr-g_DP4XR2nxjvRFc4CNIUR-oIbz_ecjrVxyccLyPQstV9AqFVwd3LO9haw87MdfRVNznKxhWo06hN0Up5Dqg46cVoHSyKUFRrMb_WAl9XK4xS1d7mmvdPPiCmaIr-uXO5WzRLlV4UHsu1C_badGlXO9w2TX29anOISw_OGMZJ4Cpc5UhVAy2Lgq_KQQ26wYOXFPOGgJx3NA3LpkhJYtAlrn0xwH2oVb0OhuYJTJEeMjaYX4XxMDbkH-orZPYx0eFuhPbsWSYJN-JejgtktnwGkAelQVt2Som9BZRSVjk6ro-HAZ-ylLYP4Ga_lOpjvN_Js0JR-B4N-oB_UieAOfmgcApsjtmJnLFzaR-UPD4gvWa5xMhMluXWaQvRg09H2xcKmNs4PyWFNrsPfxPhk6VMTrKSHb-ez0PoZvdFzxncf7zpz365nMsP-DyoBBY36myaA8Efis0Y5VAXAePLf3GNhjHVLw57FWwy31Wgub1oyxDDoeLeoeRypXoyOJ4tNWW7ASG0UOyf9Uzx7Hb8nr_W2S1X0EXtMR8mxZg8fSNdvlMH5wWo-2ulBJpUQ5YtiSIfUpuuP62OERSOyCIRNCUDom5DjJjIY_OLrhQMsKuEb1MMWejmu_oHCig8mm9Iczdp8EU8udEoxha4YXIS17p0Xumz_HPLWsOYO_yFHBrIDKsTd3acn1cfcZP9jOTlHCCUJX-7ux9sDPcW9zVZFfAW650GTzKvcBLGCX9ygQZ62RQlox7G8vtbU9ydrx2OTAqLZNAJbh3jTXcyJmnEeCsshl9I9H5xkwJo5VlK48oxJ02q4oECK7rUOOqwGCnOdb3Prn19LTDw7oa-kRgTSMyPI8HSKm_Ag16AO695685oWrsgk0MI6SopKTcNatuGheSCmR6NlUVGkKZ5U0kcmxXBIufbEtzopaUlpJWQIU15Bu_I0JRTWjluYwa7hVXMaEbv8BjxDngOtSIVm2-AOZXJh_aiRXUb2DL6s9JdOc1_g8dhGNu4rLHKfA4uVjWZygmDRLiT5EXC8F9knJaZZ1Uc76APoF2YGS6lqvoveCK-eqs0lMC787yV-jisVkhmNi3m-1_Y7Fy8Nds0lsuTmTOaZbvGJ_WtWvNewX5NZawkV4fEfL4DMy73Hpx_J2tHcQBdIRmGcJ8If8W6hCygfDz57QUCpD9ygYP29RTEVk6DKym0upObG5JOT4QqI6Q357Kj3GPxckHrUOx1sbwdemsvqNbcLcqRRw7l2oT8JjWCpFaG8o6GlUW3btNKgoa5bvScrZLuT019nABCFj2gUNvampvF8QPF2paaTcEOvmu8r8AWQBc01ji6nXxnnkLqDzaPFZppUPceRXJv42gd1DYaG3SGG_HNSbi_g9lZzLNYhkjTTbuhYKEmpbRBNHnh8B2ZHnRKcsTcYEqc76QyxU86rLRRgHGtNVixnJCY1envICOPnI2bslkopopUBoyIKYu2DOH8URfpjUmdP0zPSVf6whW9TwlJtTOW5gqAfrWrxy0Vla_SQEhXDCpcooJkt6EJRMKHx_jFrnM3i837RAjFGBggYJcSfKCIWAFGA22Gf4WI6_K3cFjErqLxR1oEaMJ93UD0vbBdAPgDK85lAtaGfP-rtCWqA6yT-uKsB9XTvAfV1kQD5_RWDhC-8TUz22Bef5avI0vvx1KTG4xgti95WQ4XdMnsq-JdouDlNd2v7BCWFX0RR5W1yQUzr6Q_OVesMSYqC3pD0MQakYxjY6EDQv80XJIJZqzBjc17a_KcZC8BJE8ZYIA56BguQGVLpK3Vv0YVpbiSDX30HdM9LTkqs7ERGtC1yQsQIW_YFQA8Zqk_y24UFNILXbIMsEnOwxJQobNmOkiveDuS_UBFKkpXSqTuHQdes4BuzoOrLgEdEtiTU0ZopHGwNZkz0_SeWCNSYOzty0pZz3ZFjnxuKg77j9VMtVc-_wDrHH-X7tJOPUhtDVq0_VdGsUGmbVOgn-GGtw6Is2f3Lpn1XOD05w6jJSAv1L5pVTTJUlcFeWS9igAOVWKUdQ4XsPzB-NErslDOWA5NVJzMcEbP5vbWcUKwLYqYA-32Q2bbqlqmeeJVnbK3ZroEc5wxq74l10FrZ7jxfnefOlqSs-CeVZidzFbqoyVGZvTCzb5mJBxqFIUIWPs2gfa_8OaXE2KU3CTJYZ1vhLSLGxUunqKAC1UPNNBLqxEKXm6OHPSz9neBByx01DnRpOU9GxctBtuuJ8B9SZan2dtjyhCHvvGDijPgw3bHe-7QVRidL2Jhl0jgq7SFmms-wCVv5uZXNEhip5nNLmxblhAMv5wL8ZK2cCrvxOyn9lnBpIKNnEGOjClsxNekEqqbRD-qrsA4D5QfcnCqDSmsPVodc8aja8JWARHcWZ9jrtJyTi_wHw5o_x47eGOKYtWGUeEapVxxfANjr85-j98XiOuVEX23LApKh4onMieHnOBURBN8-7O-eRsOcei2328d3OQeMP7WhqCQkrWgenEe4el69ZbytPSD_AIuP7fjCy7gpuROykgWee3DVFsth4bcgEKb1CqnigFXlsY02OseaHfI2x5kheYforHUjY_cTrZLTEGKEbs7QxiaSDzeijqytjBmyfm9jlLEBdPqsjtKczzruG1TSTZDZ9kW9DVqcUufQ0RZVjMPC7uh_IW32ThVTruPUEpbE2JdYLyLB5rWLwtP9gSATIlcbDL-I5DBYrp4AmCkFFKG820OX7Q0hwF2iP0HCJhHGI54U3flxxrGk62j5TDtXn23Tu8SW5YfLBPDR-OP1xci4LnEZz4CIPNlHRTH0h8zUHr-QBTAI25KzAvo9_0IdfnNn1NNo_aBk7WJdMD4OF_qoPHkmvDWP4COUPXMsE2ssKySBsvNMbAg0WisIBM-CGXPrQyUN6vm9mYfcruCKDD0iLB7rlRuQl-8nR0mQrqGofftclPJV7EHVGXE4OfJlLM15BPSCaIK9hxqVpH-cxyu5hyKPg_WoHU46xJ2IBtCwqHS_SUE8_rm4x9bpNR7TZjL9q9VlluR-tB_9Iv0Bk7Z5OjgKyqWl36tbCORztggTAr0h8wNbkvRjhSza2dE5z1CoJeWrhQG--nY4SuLLDDHlfgZg-nEzVRCip3MqoB5Jef2_oY1v6Lj4lBZjrIjmjdtv1FgZbSg3flkYnjT7RR8j5H4VL37IiYFKvU02tsvpzpUyL7wZ4x0r84yyOT-A5d4iTQLJuMTEUZlvrRANwDASvERanvhMlIcGWQlLODXPyo6kAjmDPmC_KgNVGO4yeJ8amH96Ji9zYuqDpnhg46rI1FpFw66iHfir_YrGIvy2WVVdEd4ld5x_WjzhgMWxXPLe1uW_QmaQnpjYssF7OgJ8sIavj0xIMKCd5laF5Vv8pouJWedsYw0g4UDpfa1K24ELDnsdlbUCwLgZ17bXTSXdii9iwTy_y_w6Qw3dHs-D3YKzMr-JJ7fAf9q8ESqWgQHf43pKlgTj2lieX8J2IUWx63uCa5nS5V-a_L1Gh8xUsam2tmv62_wMqGJFU6eIP-QiHlZwnFwVQUqSeGF5gKKB6cxK9YL1l9b7PjePTwWtnIpEzfJEy1S0ymg2bYiwuMLH3DK08f2mCB5zYbZFjsLOmYvjDP9OtolIEbssWvYygXlAcHSokSsZr7Dc2aoXaZbxQqDzbVNMG7Hm1uRsVsny-reueAuCqCyeVWQCelHQSUw9L0_ky0ZcpmAwjGBuBS-hqk4ad0e1khhSRtfJG8OvfEGMFtEqMjJtlkjzORIiKaCOpKZlCTfamnbURBnmB-10uDUefYwH5ZcrZw4lYKLmHkfc-fwuC11Qy8h2V3RdEBoEqQwW6_UgHlqUwCfukxzR0_adkaAMM3FVc0WKc2xgcA8RH_IL4pTdUDEb2IcUn-T1i1nZ0TwSNat-h8JJpbPFe7bj4JSCNI14eS6B7I6Bq6BsdD9_FW-at8xpuExVI-EsqeqBOvI_ZtqgUacFTWAWqcXQ5BIGNgQb5yfQ97yFV3uUMv_KSz5jVQXzcVVm7x0dOiJuMfQRLIoDNvYzMHLH5XszWGG_rYKiCRapo9QuDR6WmNdE-yQdVXRwUPmnqMj1IhoylbzqQec6oW3fnbdcShiArhCFqUZ9VK59-BePvIUptCWfT0qGxKGU6eAgiFKpys18NMgzPP_1iXr_-6gEwV_4ELF6hh8B9XSPA-3qJgD5O9QDYnlAPnM2-fPdmn2CSxcN2QjnslHi-0-0Ke1QGmIMkWFKW8G6axeeuv02BOrjOtCWW5TyEtieVTorz-iCD3RJ60CKVZrS9UxSilEztM7RHEtDyH-66OKlCXfWOv-2G1ktYVvetuXP6p8DM--Mp0wvFdnSJ1z8U8aOCPe3oMP1u66E3rzAqKx7piyPM6kDrVqCmhP9HT8pq9qcmqhQinU7nC-H4ypcTlBKKRz6KdixZX-ULmjYsE4Lma7p-dUaXXXds2TofjLraWny1-tuiLWjKoH_3kB0S_2pXBbiWhXypl1n5jNVHHU-gYFMQSkc2-_Jyhqo9MTgwr8iuFsTaZsoZPq5NdLrdGxAzQkw0-7BHAnf6YPG6b55dHKSE8UyuEw4K3PPwRecSXJhfnTo3IKmFafWy9tRVmmaB992gtGh2A-cQYDpyZmiKTnnpq6fxYkdXRhG1O8OOopUOiox14STx3eLZRGWXBOrcaE9iC9LrlVtGHP8jo9FOsh8KnER1U4P95u072DVuUvf9zFW65Rz2WNRDnIcG2Wbd6u9u9rpmvd_7EHN2vTK9e0KOK-jiGkdTy0Us7Z4gCUJjqOTGv7ljEe9b2MVXTPEaO9NtgA_u7SNdEABRVrs2RQsfm0fRmJjXbY_nhrcWNbfr498Zaf7SmeQMp4CPq1mbz3A0alTkj3wP0jYpyp3-MH7QKXi5-OMYwWkyMu7kawmgMgVzkfick6kqzK1CXJa1mHGvK9vZS0TJVNIsn35vBHMgf0w-Ymt8OntuGADfFJ4ml_zBZ8sytvanVwKRE1j8APwCehVvxI2KfgqAZhRTBWSwgFnEiTx_dwVGqZgmKR7z6A8Soj6tX86RffgiJTpau_bseZEn06RXSMmOr25G9n-Jt0NZ8UR_VFvoxPs26f9f6DOXEBiaT5uaaKpvg_7xIlyI7izNB3aRlKnyQbfTyImxEFtvBTckJ7bPLHPtFBsPSy4EPxq-auhU_w6u2RtykskWQQmWz11EIEmLUz1-0lne70hhM-KTJWdTsW_JcOmG187IXcOlwR4GKZkS1Z12NKhRcJRJVwPA1tFfmURtmb4aAbCZoMp5RjY9CZ34v82jkHAdPsiAz2Kzaam9cUHJirY34AzLLieMVZXsvxVUtRHGQ99iQ9ks9U0Wvr9rwvPnuweiDYK3DyZ3kV01Oi8FhPab-C8MD1BxuDRItiZ5fX0OwtPQLaVXr1piI6Jr2S1ARtCeaa37OMDUxP5_-3DpHg7J8tJeWElh83_sbUKQumnva0JAVCvHKNOtSPDXwmMo75O8ftYDTsA4ZSUAuwSlPREzF7oIdXNFmp8GkloNqQXQz1AuWuoETPifAc7WBfJmT2wSFTCHPi10Fa3-3umP7hrwz85Il3xUQQjOBBW1I9BJd_HHrdRj3bI57WaISTLvkuIFKpgWqh1IgDJzzWLsMn4XUL9wieQZRnmO4aZuO0uOLAV-5L1suf8P0GAfmLlczq8G1M-Ayfg8KH6zeRKfzdR5mVpDD7BtKmS-vY9wmA3g9S-GifHZm2Xw_x6fBTpbA1CBJupXFZ92VRApxKudZia5vJjwhavSkrf3xvIXQj6B2Vnjs0FzmwdEZp4ayi9FH4vaUf8zAIX0xlW8-mjU2hi5823QfxymrSttw-e0NRJLPiKWgntPuQ7ZKPW9cTJshGk9A8upFBlI_p-JGtSKAhXnjGqHU5T04h_yZY6D1Wa-URic4SZ_yW24ESHrY26IJPqb2hPTUV04vQe3M3zQ5C8nIOETHX9T1UzhdK_Hgbx8WRDTJDB6H1TPmLLYEJ0BrY0OCBgRK-hH0e21729tVi-3tltAp3gWlvUh69Sw3FTP-64ZdqjH1_Q0n4-Xqymrn2ec-PivgsSKlJt9zpXo1v1sqvbvBmVkVbI4KJ7l97ToSCuNcN9Vm-U_eQYWxDBtlAJWVs3qqBC_EtKJWBe15GnjUjrcYMv5ukI98tet35evO22GlI81Z_LBn823aAjuRnWc5nzkxstwkYUY5D6XEirDlzhLODVdBu0zngI0vEMbMeG6uF1QyAofvPPXsmycvfP_HBs5bVOgpYbps7j7mfwbX3tBT1y6mFOtQovXAu1BPjXL3qBG7h0wkkqn0Ye86VneD1-OWx3sU2KbNQySAEL2gdfzAPJelHd_qezTHfa6peb3QksYfgCA28P8o9ihU4lM6wM-oslTrYw7D8et-YBaIwrJ-spxNTe6dnuF7CZs6ouGu7IP9JHVoroQcbcCmwlIomsd1mZB-wSImhzu7HoB-75-XgQMT6xRRRoN6Sfi-rsi_bpJi-rup_bqNhfP3h_VaoDwZrQT2Ks04W5p26Bn5_UksREhqlMMfKoTMVVgZvm2lRiAozBUi-yqrtcrLSECv4f9q9WuWtir3-_PV0KsLK8JQqOu3ds-GFwbAHseIMlY1Cxv0arrBOzAJR4SaA1Pwuu9YQ7mB1fUJ-asDpEo1zmRxKuhpUIBYc_wiSanqmZYXimGaaAC9Norh5QgZk5Nz8zQa0379CCU8zFG9UePZH64Vm6zEgXaNhFi4qa_Ac-eIvoHjCZLTRb61-XLm-Bef_0u9vLpNjFdhNS2wu10CI-9cQAtBnkMilZqI_SkMFW1PddrwYgyVOUxdk9hmi74JZavxm7gHBeIf2Os_wajRYgHflKgn4bDpeUf_jwmMWWBBZGI3miHwVWtjGtzjFdXKCyJINx9hUsUd88yR_kyDzEU_wpLmuJAyaWAqnf3sqwBQZY8aHHujt68OQZXbqwAqZ_MjcKMVBS5MxWp0bM7KAxHqWROhiQ1bjXXja6fjPPwr6c4v62XdVlknoQl1oaNw3PTmlwfTkAj6J4Fc36Sh-00j1IvuzjQT8OnIXpUQYgoME_TViap-6htc97SfCjZhMjQM9Ddyw1sTKFH6poIQx2vanTMQCuMjjb6lpdEKQHiGVF-OI88lJjdHfL4sB1QAqQKcHdOL5-m_bbNO2CO-4fVKkwHkVsBLf1wu7pUhtpDxy4aIcc8b43M5BEWqF2Y_KT9Ka58_fuFM960Cc7_E19gN4qMzD2qguAVkYEyjlSL8ONPzmzbhePGgkTs7NOLIlQVEYDVFqjc8kUY63YGIQ4HofisYPKc10PCiwodvCljaVJ-2mMgwl5ev3tH6SGn8Azj00p9nH2uEeGprEsdtSFnLCtNV3c1Su5H67f5BSAwOwdWIyPBnCc1qQSYoIvYF56hKBLYGe8wozzwRiconQ380eVGGwgQos-6O6LcpBWsdM6wzbuRl2s4iaAEvcYCvnmu_QKmmbEX8VgO2lLoeA8zzdrw_AjM0AuSExVHKVy0agEdZK04-Q92KaVPvWwbJB0WoUTJk31ESiZdvPTHjC5Lx0BElikX8Fk4MM1uqTVz8fZvqVr-mppFXBdRGij82ILvsSawNgRVKufacJU28T-kbCAPzJNOPDWtw8nias1oII7caqCqf4_kh26yastRl00gR9cjr6uaKgv-cR3gwcRggbCc-bxurjSF3zTsDdNy_NBEjgRIlDL_RWLl7bNpb3Mu5dEU9Wi4YGQocNP4E9PPCKau5dSSSXsf_2fgCOFHZUmE07CKGK-hfK1VOfxUl_gY3gqEPxYBK5bgDDi9_tLpfnqbCHMnO_miONJeAWrS-myJHLfZzlwuHsZEir4OidmWkQPBoua6orCqzIEM_y1hpVxQDndXKxvBfE1mdeZJkPAduY9hFhmR6h3h1OlR2MviexHZfVxBFYiRTCyCBWeelBu9Qyg0Z6qOhEcvAaMTw6WcGOnLf9KcoUdK0ttW63KQWYR5hxpQ38lX7XfDcQZhT9x5wyRK9-3UHSl_o7SD3dgfT66NNH6BBGnnzBehk1LS88zp2JPQDmtvhnGsLy5YCnt76FkNrhLO4GAGZbJv71NWs62Po2CWpnyrOmFuuMPDzUk8wWgW7dlxULfKRzCJkIFr70L9nA7J9ViXrfobUNGOsiyR2k16hW0wJQT2hbqqr8gnhMJ9Nm9rYIG8EENoWIADZLfbg5oHwh-fEOShV4o-P1o2QORgcZHTzJ8Os5_IYUgdtduPxolN6aZKVmBBXM5JSuwVFN8r7bw47wlDxaHe_PHYJTVvKSRyproVbo9ehJ6nojtGWfJepOt8_w4L6IbACwZVVlqAe3x0UXqjksIojxbLaejoOAyG8ECzHqtE_t5HYKAJg-NO9flraI2evLxqBBWrakW3edvN8cc68BY2JX4N1AX0WiaJHPg_vS1EFLfokeZmJ4HfLEjgRGwUq3xgH-tcxdKhPOiVVSVRjaPtb2DJ17KScl-GCnbPK3_dMCd3vq5dR6ujM8rYR4OzlpLdz1TD0zQBYCsFT7tg5H6JiHYMblUdFU5vx0jPysKSsn4JUXEuRlkWmoZMoUFgq8WoAdD3wqH6c9C15kUt7mmNl4Jn6x5zwtxJKbi-Cmg8oj3phTvLTLB2IITGUselpRZG-eKdwqHYOG61uAgHVYppbyiRinwZPWHJEFyO9fFEoB4yoXQMQfB_bO3RyzoB9Gi9hmuK7oN8a_75hdVqkqqiqal2iB93QlWs6nFM71anyeq9sovuZAA5H3CwmCrzyZ3Rvah-thC0lrRggIrI0n4HD8IKMOIIy8zPrej_BOxVnhtBmdgc6rKKynjzE_RRPUlv_Li28R85F1_yrlMv5pEwGTmzcAVcDeydWrjBAsLsSJD34-U6MO2MKzsMFZad421W6cvi9AfdenyHszDTTOVNXDvdurw02SHlR1eUzhK2XpmWTHROclyxUxwzCgPPbRKItOm9Je58mqtZlvDfrH8n0NfyvoBu2aKe9AfTidv2lABuy-9UzrsYvRqoXqGcyDeE1iXrAStQuTAdd3iRyZcr5Bdw3Z7leG9bj1eLZlEpVSQexRCmMgmgqhEGG1ksg3WyNEKHbamE6O2HWNT9iNVltugo6JvT3cuIfD5xHedKPq9_TmpMVTKXgbr9ezysnVXDIsRd64dQjYvxpHIVQAir0u7DxWj_U2pNukfY_KSnBVtHCs9VdewtheLL0b-mWXlE8sNVkCQF3gxnDkngku-ZfYZDSW0KQL8eSXLtO9Gjj65AL4zp7xB6JJ2riLYeMwWqtABtMPMWoeICshJe_UHu5FHw_0c_WOsSrxcM1UXbat6-sZyIvaj3Tk9gqzM3vSZNasJQNw4M-UPkxKKirClvX8G7xs6qE-3BflZ9OAFQDzRMfQg4q74OFkYtG8b2LyBoHqS4SbYKiDrvCsVM3DgsnAc4tbw0EA7sVPQdPWr7ETkNuuRyNp9HDwsbuPOLhuLv-oP7XIkkOpo4_Dgq3iPpql2mXKx7piS7IGvkFmmpRqHsMPhE0JApwVd85DBPdRg-7s5nlFWcnlQf0zDiJF-A8Ms5_0-cjI6iyqC6tWkvP8cEfYEJak1D77JJ9raLbhc3peK7HQlPs351TXTy-WXNtt5U9moR6z4LOfjDiIgJbVP9X-E4pYnXz8BrzxM4WiMquz5RVkKI5H8XPnFOhDNpDuNVAxtlCafwuU_lzm_3iNP97qZf1SSnJ7qFLf2ibSubyObsayFHbuz9f7aYP7AVMI6ha06qlxmJ-7Hetfr62B8M9wXNleZC9tpPteDRUBbyy-iYqz_ap6JYrdGzvQBeOw4QTGvhUfajryRBc-1shayJ7wlHfkvIK-QcbQD5yF_1V4fAHIUbwUxk6SL8zfHE50GFIg2g_gudZ1e17B8_wuLapesq3PRDjwGcRz7ud5IQO-ei7Y0bYd4xafagEYhPF8elrSmDYmShKJdMZg-ek13l6v8SO_GycopkZJ528ChFUVvOtcqOJbp91HryzI4iwguhh4O8RA1DjDdk7AN22oYcSBRIR1P7pFfh0NLL2R-jHezjSisaRVqpDibGFMy51iT4cArntfTh70YEP_9Cei7p1A5OTqy2MzL8SJCaQ2KPACUNUoBTRzF4LX5VC80-eIxtzSaGGuZpUfwAY94-D5JSdo3m7i8fsSr9yswCVg5cJBLx8BTROS2AZ7cz9y_9sFj3zS5qiPs04apPxlAn0GHxoMHj7OZAiODqLD-CHBbADRm0LSSdMrHUMMD-_XBO0y696Ce7bUSA3bYPR-GG-iJxAQ_PpFsMyh97pFXegqCfN5xAkTqZChE5L4O3B9_RxaDKlNKSC0HgKrZXlpH6IOYeZ3QE9XYdZrBLxr6Tl98QulK0naVZOvIKryfbbMWJ5DiCJZuqy67RPSaxSjCowXhoOkeXspA3e-lsMlN-PTI_vlPGV1r5M8XS6d0LFnBIQcPMKt7ps2Dzc7L1SHB0vQxk4YonnkUJlm1oegwvaa1GI8aqbGENSWA5ySqNaajsDQBcyTbt_P06eyIGp64hlsFusgy2pq-epaAyZUDiWjoK8zpjLT0_tb_gHvQvt5gPw-1f4ekqAemg9TX1HITemY4X2ODrD_rbzl8NTq5MItoSiMiZOqWyuRe9UUMtYRa9YNns1GSoRbG0Bbst7kNHwgju3W0t682w9befGZlocmYtpDY72rXpbotkRdlLB-c41XPQdFP2ZAiCcTYxCBDLfCvO5LA3TyTuJFG_DYtCzklmaRcQibtuihqSpdl6n2BBRIhoxhUzSWbmhKE-abv5BfpRhS8a1U9_Wt_70qvgVxrYXdOjObTzGAwwBU68AWIMMmIghZjfidzhZyGiJCbeHdOnNP0aJhl8F037zmiEdtFHMLry8maJmaWeWosgCw-0_h7xVzaAarjIzIGRLNR9h1h8Bt2yBrwgjW5Zc85cynDPlVGD8TuQ7TbDd9MRNrW5xNTnIS1tYJuo2SMHmHMR8KIWs8dmClvLqSF6TPU6OGDjJFBSPhnjdqd2j0vr8HvYSl9c90KDAhFd-1tovhGD5kxXFBpPTQ43wDalUA_uku39bZdMVxqaIwEtr52ETaKTJ2JdvB7NdhPVg_dsSlCuQMp1oPLLIn4kskJorWdkNSbEOgz8rP9HqToxk3ueE52XeigADODFcoWD1IL3JxgVciapepFm1xVpAYLHEp2ZPhS1Nf3_EJ_-s7huEcZXd0RJ9MtS9XRcXczuu5ttIoD3_c6gcPRu2-CXoUUuVrcz7yUj0wN2xCZFTxAE7MXZhtE99XNmKDrY_Hg-hVBPVzuMdOz81ymnv4CH7brL-2FLJbmHcUpnfSYNf9cXOg04lU-L9sXM_ZX0CJhNE561ucuzKH08B3h9igcGDEJmzgXLrZWnmJ9apt7nyUcpUUIHp53fW3g5j8ce7ir3LckFRRsucC2JWEzu35RXh4UZDfnrKkkPI5dT4odMfku3BTnol6wPr00p5P4slLU58IlFqdAHYXvdTLDI73kpdgXyoDTaNdh9_VYHtb-6zmUmaNfAdyWao6neK96DOx525zfjC9MMZ6aWgH95UBQdtUajFJswKGLG17I4haE6Wdv5fKZDGPVOqImJleRCoN-3RJOfKwxcQ7OTxo_gHt_6lgPw-mX4dyDxJf94bUbzS4Aq-sv9NSCGYjS2htggEToSa5OBwIYxMFef7zJm1VXjAHrXPmu12D2O-FDVr8FMiYqefjIjVT9nkfQ4oMg1V9RdzkCnEL-tnD8bLLtVjr8-r22M_nyY-y3RUYsEjWk1BGwQ5q1NJL_013wLeXHSLLxJQyafCJjgdzkxEneh6FW2L8po6kg1x_D8LfrsGQO3kz6aCNeNTH-1P_XsdN5hSWavX2GYk2EwEB8jszvTw9NJA1rdp7fGsAZ334oTw5kmxtIUed4BDVYYy9yY0Ih5_n3xsp8vr5PRzxXmA0IhJiW8fGVq8GZ0S_BbFiSZrJSvNuH1K_8jxW5D5XhGg9yhSd_c74lv_0jldevASq-D1WPcZWC1AXJ4k9jJCw8IwmU5brkAebCOxRZ6szXz0iypz432ibbfPT07YZZpU-xkF3BBgRnaCnqNCq5OIqpeRCwHJYBx0by2PCEP6p50N6GClxNO4b8FV_PvHKpLvAra7VWTHqLUj3POaSNBYhunaaNryN0vbRMfY30yqZRiR_gVwLCj4psQdwKZcdhDPdKKQ4_KDQJF9NK2YlF5dO_Ri0TMvevUJ3cinKR7JJvyzN7rN2asxtydaUOnPodfgQSfwncjC2eAtZwAIWA5f_oM1rcX7t7ujbNPsDAUlCbEuTfw3yaavkrf5-wv59l_5923yXri_P06_Pr--Tqf-fSPfP0K_VWHB_JV_xKXfDtf5Kx_k0P-Skjy7UZ1_q-YBv2pUDZkVDh2408BEhMRCS1HfWSmAsVZ16a9LwLPOykDkMJxE3LIX7KwcHGNpuiXCNoDUUqM5xventbWbtfVNTuzd9I3A5xx-k4HwZLI6I7Ywg3ZTZpsSQebtuHdcVa7PKMtG90a-PvCosGGwiy4KjcD-ucS31B1FXConRoiq7UMA7Hn-nQ-YZNvS9F9qsLMDs0P8XE4uZHb8r74yXgMdMyxm_0O80v6fXvMhXk0JVW6wMX9lPHof2TSMxxpauU-PHktMfQjEVeCktHyQcibVzdagq2oDudQiuVh6kaq9SJcYDemzq8L9Dle4bbRP4don8sF-AvNpVi9lQbJV4H9bnpYmF2iUA-5Fdymtx-hyP7QZDi3MkSX62RrYE5S-Mz4ku7GGdD-m3EdabaqcTvgQvjliyDp9rXB2qahqtnk4Sxb7DF8pP1K-tbL1SRFxmHFxLqy0kVP0hnD_kXsRddLUfYtdSQOI9ajRC8HnQX7wuAi-r-qRLhjLlHSenTRay2vf95bSUeX5omsRAF6san7yGXDWSDahB_UPlyfnlU4xMGcVyzdRawJd13yPbIm-u_I5ersSJ4OIjMkJ0vyx1yZZ9L7UYvY318Vm5t0KhD3ek5kg4vo6jxPDI8YYlu4l2OM_hw0-VVop_pFxrlhhtrbOJPQmMGI8Vz0pG8hbvlF8QFZIjYPCa01I9P-6YRr6tVau7ZIxBgOq0PEDumNEPjsTqBfQYcLqoX0mtNKLptd0EEWkqDXubeBBT7jtP9D5c02L8x6x4iPK-T7IbYK7xxdGK8P5qdl7TEVWx2J7NPlsHy0FNWbCZQGG9kBMtrN72DBVqLjwLqt0MClL3MfdYrL40qVhRQayfJWGmcoCIGTbr6rnrFzfSkesV0oizbZ_dpRzqI_sENr-jdZ3bQ5e8x_Gfpu4vUqIsGNcDVct9ZIxXQ8pr12mO0yShq_q9x7hKGn-daQhVhCIrUtdx2L_KFA4Rvtj4O4m_sOxk1P-I6N0nHoNQKfERnY2-OlMYb9rOoETTqb8swnAg9ctH7XOI6W3jGWvDBQYlX1O5ccrBfjZqhCjsVxwlHvrWFfnodmXS4FOq1yXvtOXkPRiN53Ni_mLUE95jvckc_XFqSVoNHXIKLbfMt9_abchf7hKRahLEjRELR1_egrkNyqFLLqCIOu5oHJuYkfKC-OG68tkIvVPkB1pis0WI7jMx-y_x6ghzDDRv4Qc18pY_HdoYBWrPbVy_utCjJ8z3_D1tPcK5eQqSewnW_H-r8mHmX04dpU_0YG5rlymuYXLvzci7DIn-i1REOFKu0JLnA0kmSMJDaXOTol3vo09MWk09SlIPlof-surxvmqKut92wkABNkB1g0stBxyf004As9UP0ujq1gzGcnXGOVQ80o4Y9PMi15t1pE2IRL2ddj97yQZrfH7WgsTmvSgVGhevlrn16W5ZyS_Vr81L6vVMhLHjxkO-ycPtehXxvdnWzv3V9MrWjr90r2U5l0dzojxf9BhxnH4DPzqnIZXrTDn1Bc0QaifD6gwIf3yBPmvbrD18cywUB0JhcVJiwig-cBlE8RdY_5Oke3fdLjtDXpleuvGifquwQmOLLN-Q1ROLwmMUlOgwClXAIl0Oh7VYvnnUhJ2y4f8GwmWeb9qubK1Uq9zUjeFXPTc0_-yw7NyGP3CLJAqhfkeqEQyPAzisxyqPlRtYE1249L7M9iB7JbG0EgTLzuwoWclz3u0ScFNsycnWW1N1eE_bvf3Msoiq9Mh6oiJx6e0NQYLdy9Jk2M0_Fal6lCVKsUkNQtjPnjITY7ofsUR645LXOzMdBqgY5PAM6dk1b9Q409zmUuEtqQonTTPHkRh-F3toit7s2nZWcr5ourKNvzzF0mrJ6-DzYZw4oJG7iuABoFYQXpxxh30fPLuAzMf-XBS26_3qIeyB7v9CHduvKjYfaojZxphpNBdZg3PmPcxlY7e7wekqHs8vmHAwHnfB2mWQ6TdCdqlbff28tO5nYA2hZj6NBoLwcVoDzDy4SAb_LeUNH8rAezabBkmCbSvEPdWv12ymMBCe9eKbhJ-IhOoYG47n1lBFrRm4pdCc1DDwu3KVMMiL09EQeNf00oZOzi7yCjqb9Am_8qyyyVIvN8DW5_8GHHFkpAfkzwiAY4kYZyTbev3b9avQ0HMFJ8A6WZy-DSudu_okOyVvE1_xRtMhoVpimGoOmS1q23rs055HpGFC3Bl1g-3ui-qKgRn4cjhaIVKlgCkqrGBBDKFCTauwfGfWVc3a0OOny21o_s-SRx85PnEkFzJxn4m7YH9gwn4f5l4vpQcHL8uGeBTtFAeTmRb0xUxrCoP1ZM69Qb1im_W5P7dG5jOISC17q_PLjbggGtonwyGrgSXUEF0DajnTuK5WcTftPO_j5qWm2Etp3TXYcomonkmEed8u3bzRXsQJULzVMR-gsI2ZVhyMeVDUtkkFWs_LOGgF_JOJjHl_eKo7scQd8rkyX8lkm8CbYzfklBzOFGEsxx0kON5_EOZZZQ31ug3yezvqaC4_krFub8jaU_-sK1ZK-ckaFFEHoZpqoNm3jFgcqbEKurHYVYRGOQ6vozNBJIQYEExmQ-sbq4VDrnuBYVR6xLPYc4G8zps8fyOKkoH6kWQj4AtK947bbgK5a_8BgZUqd0GFEX9yAhzVJjwLKN6hETq6uubqoGrdikh5mFd-1Yucs0ymzPF8FD8FiEOY9Uwh0OyN96afIrQ1Gg8SIvLA6EG1FMYMe9tvEqO17vkzk0NSrjiqWCEvD2bCdQQQFT1oA4_sOBdXHqmzcJA48VEtrq5JKmaNT0KR3CkU6wQ5ca8kd81Gkm_kmSgv8OnQJYsPknN-2jy8OuutKZiKrq88nayY3XBQYv4lgiyRr2uBt0Y-usSf0sMefw3P11eJbcqPCCVx86WAvNehJoO3ACsG2DOriROjLxrbzZ0e4Pg5Xi7v9RSGifxQnWbZK0_wVxKYC--vnXv_5PZYL0A_c_fqa9IyEKptvJxGsPtZVDvRY55taKIpdwpFQQSXYdnVUklyRx-ieemiGVgT0_DoRDAttFgH6t6P3wLZbOYJ6BhcYdAQgwlMD8ar0IRt-MSjBuaf2CvZUYonHVbroQnMxoOhpp_h2omcFb626t2JX6aeDOeRKEDoabFeb2QsqOx4P99m-asGtYJRleqTrnmTREXAZyilmqP7M5bkZ-UuKCUY8LEBYar-2Oq_6-eR2SeswV4FgWVyF8TIfLi25K7Sku7iRkpcYKnBluQOI0i_iZdjz2uuLY4ify4WIPRB889i1TXMbq-k2QK3SyZzTbjjcw5-vsUWmS5YDzgdvHkAM6QGWT8XMBX-_hoUAGlH1iTZVevYuBMOU-OSJV6z9speGpyH-KbCWF_wtYbrPpHTAlpGJelK2KtjJvmsIDqPoR4oQ3pf2nfKZpk8vhWcSwpe4j3j7FG5AMGUtmynSihoQJ6zaWaJ1lcBE1yYNbNtO1yUyiMSlH8dEP_soeQyTIgWdyipBoCQAm2FlbijLb_Kn9Z3sfYZRTjBksiGZLKKIbQAIJtwBDyhwDcqjpc84UWGppRCAZjy25HZX1rlv9rs_Z18TW6yOpfFAUP1J_7X9INP9ke2b-QVFd7RXupKrQRX-uBEirMliyu69GhNiX6PMFOASJnKJShANR5YXidFp7uSpQdfvis_0J2Amrhb2v6wrzTmHW4yqv8aHLXbjDkaZFwXbuvVWP2LDs4--qidWxD71SY5LZhP460gYNFl40mJcnF3ilY14qGpDJUjrGomRsWnHd_KHX_Wp5IyWBVDdtGL8_UjQYS6zsnJNhD5iTEhxPE3mO7_aduakDnostbJ8kFXP0bh9ckOHv1jmXwt9w0HAEu8WdmXb3m1HgOEqkLNqdtbKMdPY0EhsZoZcLBiT_PTw2_yaXM87It7zd30Rs5jSA1Y28bfUeJSn3oxRanQJMCDkdVy72mLgE5gNbySi6XX2MsHLqtnctj-kJzkTzq_fCcEqEjC2yMHFH7oYVCp2hAY94Ylo39hNTqHiknFT2Gb6SqCvj2dUQjk1pM1EylIW6is-UlhsdE0LH68yxSCXUtLbD6EduoIzn2a5OGEiQMKpacjBiQNtT-tZ6nMXFQwuBfN0x6-1j3ecGJ1CGSzQfxefbp2P1dsLJphmUQUDl0Zb9mTpLlbtn7KME4S_4iMcfCd-IiveBN9WmlvXLmF8sFFL84JZxYCKHft8MfVDdrwkwvqRInIS_m-QH21ftzVvAfd3rs_djqn90n23sB9MpQPgfnlu4iYppj2x3kMeC5x4wzyMEzxi0onAHDJmNXW-q6Ozo3N76TQvUVnWIvqTfbooRnuAv5iuyvu-0h63jtwlwK2uyX3B1MZSOAdt3eG5IlnRBeYcNjuzbm_Fz6YFJL7FloPyxqKstbtzePVV2xaPFoumjnoqZTtsKXwJMVEn2w_oUptLGkYRVOBmnKn5b0g8twPBICZB5kWtkM54onCIxSiP1uL4KPKcQg2goZ8Jcp_69gEGeSqaen5Svyy3jzaK_OevUXYRpVa-dDN805imLpJE4AiBL-hJMCN3bQBn-NgDe1Ky61UuqPoSbS9eF-y9_w_HZjjaN4tS7SaEnMWoDQkDkkTc-RsR24cdYed3GkkzS_z0l7Iq_h5w3k4EvTVF1vOglxnKlkBtk44sW3JPi-g8b4lHEOXuOIQm7wWP7tTg6Wp8UKOVMa5AUaa46KpIjUDbD3Hwe_i4YJgygKWwLVqiUAG-KLv9-Zw_kfKi86WyXJnX7GaCW-pCoggP764gY7fNZ-JfFtRWXTt1ydzINQ3r8tecU8LM_o7gfFUWlequbeNWCb1sywI3iyQS19au7O_R6M8yg3fOnAsdX0uI0M29ljqvoX6JfD9UoKNy0D2C_vbd6k0-118Y61CC5do-1EgyRPSAX2mKWP_TlUsuHyT6xcoFfu2tYwbb2l_LYOI9AKmbjboDaI99Sfk0gasfmLVfsfZF50NuNeH_F_uRnV_Aare0VaO1ep4H8Ogy6WXYyr3tF7QAjVtKfYcwbhFKFv8GHi-KMFNOHzA9YbJSqrHP_AttwhFpdwmE66KQHrJynBUrAhj6dIBtv1Zqcj6UGQu3ipNSBIUcuwe9VKWSfxYKYePcGAQmTA46yaVbJFf1yek74zCRnGoMidi1NS2zLprKncBy41PKX5KnFaDw-o-iGMliJn6H8hUWXp63pIHaM5IxHP2Mxkj9ZRLjbiP2YplWh1cQCCBMb-P8BBo54W7DnyzKGlPS8OqC0MjLflba8sSSFsjIX3WCdjIJoQ3yTSuH3SG8lwuniSlXExsX2uaqh_g4HcmC6xsSoKa_fG0fduUoOw-0b-hs_tgH9YFuhoib2JPCHWoQmIGuZslHLX4hGd2-O0FymMk6FeMYtkVuOd1oCsjL1SIqLZtvjO9ppCUSQHOYEUMXsaTe3_9k")); + requestInfo.setBufferedImage(true); + + DecompressionContextInfo dInfo = mock(DecompressionContextInfo.class); + OpenJpegImage image = mock(OpenJpegImage.class); + Cio cio = mock(Cio.class); + + when(mockOpenJpegHelper.createDecompression(JP2CodecFormat.CODEC_JP2)).thenReturn(dInfo); + when(mockOpenJpegHelper.decode(dInfo, cio, false)).thenReturn(image); + + Response info = openJpegDecoder.decode(requestInfo); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: WIDTH \t= {0}", info.getResponse().getImageWidth())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: HEIGHT \t= {0}", info.getResponse().getImageHeight())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: DEPTH \t= {0}", info.getResponse().getImageDepth())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: LOSSLESS \t= {0}", info.getResponse().getImageLossless())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: DPI_HORIZONTAL \t= {0}", info.getResponse().getImageDpiHorizontal())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: DPI_VERTICAL \t= {0}", info.getResponse().getImageDpiVertical())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: TYPE \t= {0}", info.getResponse().getImageType())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: SIZE \t= {0}", info.getResponse().getImageSize())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: COLORSPACE \t= {0}", info.getResponse().getImageColorSpace())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: ASPECT_RATIO \t= {0}", info.getResponse().getImageAspectRatio())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: COMPRESSION_RATIO \t= {0}", info.getResponse().getImageCompressionRatio())); + + // Assert + assertEquals(0, info.getStatusCode()); + assertEquals(DecoderErrorCodes.SUCCESS.getErrorMessage(), info.getStatusMessage()); + } +} \ No newline at end of file diff --git a/imagedecoder/src/test/java/io/mosip/imagedecoder/test/UtilTest.java b/imagedecoder/src/test/java/io/mosip/imagedecoder/test/UtilTest.java new file mode 100644 index 0000000..3f88800 --- /dev/null +++ b/imagedecoder/src/test/java/io/mosip/imagedecoder/test/UtilTest.java @@ -0,0 +1,1320 @@ +package io.mosip.imagedecoder.test; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.awt.image.BufferedImage; +import java.awt.image.DataBufferByte; +import java.math.BigInteger; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import io.mosip.imagedecoder.constant.DecoderConstant; +import io.mosip.imagedecoder.constant.DecoderErrorCodes; +import io.mosip.imagedecoder.constant.wsq.WsqConstant; +import io.mosip.imagedecoder.exceptions.DecoderException; +import io.mosip.imagedecoder.model.ByteBufferContext; +import io.mosip.imagedecoder.model.openjpeg.Jp2ColorSpace; +import io.mosip.imagedecoder.model.openjpeg.OpenJpegImage; +import io.mosip.imagedecoder.model.openjpeg.OpenJpegImageComponent; +import io.mosip.imagedecoder.model.wsq.WsqQuantization; +import io.mosip.imagedecoder.model.wsq.WsqQuantizationTree; +import io.mosip.imagedecoder.model.wsq.WsqTableDqt; +import io.mosip.imagedecoder.model.wsq.WsqWavletTree; +import io.mosip.imagedecoder.util.Base64UrlUtil; +import io.mosip.imagedecoder.util.ByteStreamUtil; +import io.mosip.imagedecoder.util.ByteSwapperUtil; +import io.mosip.imagedecoder.util.StringUtil; +import io.mosip.imagedecoder.util.openjpeg.ImageUtil; +import io.mosip.imagedecoder.util.wsq.WsqUtil; + +class UtilTest { + private Base64UrlUtil base64UrlUtil; + private ByteStreamUtil byteStreamUtil; + private ByteBufferContext byteBufferContext; + private ByteSwapperUtil byteSwapperUtil; + private StringUtil stringUtil; + + private WsqUtil wsqUtil; + + private ImageUtil imageUtil; + + @BeforeEach + void setUp() { + base64UrlUtil = Base64UrlUtil.getInstance(); + byteStreamUtil = ByteStreamUtil.getInstance(); + byteBufferContext = new ByteBufferContext(); + + byteSwapperUtil = ByteSwapperUtil.getInstance(); + stringUtil = StringUtil.getInstance(); + + wsqUtil = WsqUtil.getInstance(); + + imageUtil = ImageUtil.getInstance(); + } + + @Test + void testBase64UrlUtilSingletonInstance() { + Base64UrlUtil instance1 = Base64UrlUtil.getInstance(); + Base64UrlUtil instance2 = Base64UrlUtil.getInstance(); + assertSame(instance1, instance2, "Instances should be the same"); + } + + @Test + void testBase64UrlUtilEncodeToURLSafeBase64_byteArray() { + byte[] input = "test".getBytes(); + String encoded = base64UrlUtil.encodeToURLSafeBase64(input); + assertNotNull(encoded, "Encoded value should not be null"); + assertEquals("dGVzdA", encoded, "Incorrect Base64 encoding"); + } + + @Test + void testBase64UrlUtilEncodeToURLSafeBase64_string() { + String input = "test"; + String encoded = base64UrlUtil.encodeToURLSafeBase64(input); + assertNotNull(encoded, "Encoded value should not be null"); + assertEquals("dGVzdA", encoded, "Incorrect Base64 encoding"); + } + + @Test + void testBase64UrlUtilDecodeURLSafeBase64_byteArray() { + byte[] input = "dGVzdA".getBytes(); + byte[] decoded = base64UrlUtil.decodeURLSafeBase64(input); + assertNotNull(decoded, "Decoded value should not be null"); + assertArrayEquals("test".getBytes(), decoded, "Incorrect Base64 decoding"); + } + + @Test + void testBase64UrlUtilDecodeURLSafeBase64_string() { + String input = "dGVzdA"; + byte[] decoded = base64UrlUtil.decodeURLSafeBase64(input); + assertNotNull(decoded, "Decoded value should not be null"); + assertArrayEquals("test".getBytes(), decoded, "Incorrect Base64 decoding"); + } + + @Test + void testBase64UrlUtilDecodeURLSafeBase64_nullInput() { + assertThrows(DecoderException.class, () -> base64UrlUtil.decodeURLSafeBase64((byte[]) null), + "Should throw DecoderException for null input"); + + assertThrows(DecoderException.class, () -> base64UrlUtil.decodeURLSafeBase64((String) null), + "Should throw DecoderException for null input"); + } + + @Test + void testBase64UrlUtilIsNullEmpty_byteArray() { + assertTrue(base64UrlUtil.isNullEmpty((byte[]) null), "Should return true for null byte array"); + assertTrue(base64UrlUtil.isNullEmpty(new byte[0]), "Should return true for empty byte array"); + assertFalse(base64UrlUtil.isNullEmpty("test".getBytes()), "Should return false for non-empty byte array"); + } + + @Test + void testBase64UrlUtilIsNullEmpty_string() { + assertTrue(base64UrlUtil.isNullEmpty((String) null), "Should return true for null string"); + assertTrue(base64UrlUtil.isNullEmpty(""), "Should return true for empty string"); + assertTrue(base64UrlUtil.isNullEmpty(" "), "Should return true for whitespace string"); + assertFalse(base64UrlUtil.isNullEmpty("test"), "Should return false for non-empty string"); + } + + @Test + void testBase64UrlUtilDecodeInvalidBase64() { + String invalidBase64 = null; + assertThrows(Exception.class, () -> base64UrlUtil.decodeURLSafeBase64(invalidBase64), + "Should throw Exception for invalid Base64 input"); + } + + @Test + void testByteStreamUtilGetByteOrder() { + assertEquals(ByteOrder.nativeOrder(), byteStreamUtil.getByteOrder()); + } + + @Test + void testByteStreamUtilArraySize() { + String[] testArray = { "A", "B", "C" }; + assertEquals(3, byteStreamUtil.arraySize(testArray)); + } + + @Test + void testByteStreamUtilInitWithValidBuffer() { + byte[] buf = { 1, 2, 3, 4 }; + byteStreamUtil.init(byteBufferContext, buf, buf.length); + assertEquals(0, byteBufferContext.getBuffer().position()); + assertEquals(4, byteBufferContext.getBuffer().capacity()); + } + + @Test + void testByteStreamUtilInitWithNegativeSize() { + byte[] buf = { 1, 2, 3, 4 }; + DecoderException exception = assertThrows(DecoderException.class, () -> { + byteStreamUtil.init(byteBufferContext, buf, -1); + }); + assertEquals(DecoderErrorCodes.INVALID_DATA_ERROR.getErrorCode(), exception.getErrorCode()); + } + + @Test + void testByteStreamUtilGetBuffer() { + byte[] buf = { 1, 2, 3, 4, 5 }; + byteStreamUtil.init(byteBufferContext, buf, buf.length); + byte[] target = new byte[3]; + int bytesRead = byteStreamUtil.getBuffer(byteBufferContext, target, 3); + + assertEquals(3, bytesRead); + assertArrayEquals(new byte[] { 1, 2, 3 }, target); + assertEquals(3, byteBufferContext.getBuffer().position()); + } + + @Test + void testByteStreamUtilGetBytesLeft() { + byte[] buf = { 1, 2, 3, 4 }; + byteStreamUtil.init(byteBufferContext, buf, buf.length); + byteStreamUtil.getBuffer(byteBufferContext, new byte[2], 2); + assertEquals(2, byteStreamUtil.getBytesLeft(byteBufferContext)); + } + + @Test + void testByteStreamUtilSkipBytesForSize() { + byte[] buf = { 1, 2, 3, 4, 5 }; + byteStreamUtil.init(byteBufferContext, buf, buf.length); + byteStreamUtil.skipBytesForSize(byteBufferContext, 2); + assertEquals(2, byteBufferContext.getBuffer().position()); + } + + @Test + void testByteStreamUtilCurrentSize() { + byte[] buf = { 1, 2, 3, 4 }; + byteStreamUtil.init(byteBufferContext, buf, buf.length); + byteStreamUtil.getBuffer(byteBufferContext, new byte[2], 2); + assertEquals(2, byteStreamUtil.currentSize(byteBufferContext)); + } + + @Test + void testByteStreamUtilGetByte() { + byte[] buf = { 0x01 }; + byteStreamUtil.init(byteBufferContext, buf, buf.length); + assertEquals(1, byteStreamUtil.getByte(byteBufferContext)); + } + + @Test + void testByteStreamUtilGetShort() { + byte[] buf = { 0x01, 0x02 }; + byteStreamUtil.init(byteBufferContext, buf, buf.length); + assertEquals(258, byteStreamUtil.getShort(byteBufferContext)); + } + + @Test + void testByteStreamUtilGet3Bytes() { + byte[] buf = { 0x01, 0x02, 0x03 }; + byteStreamUtil.init(byteBufferContext, buf, buf.length); + assertEquals(66051, byteStreamUtil.get3Bytes(byteBufferContext)); + } + + @Test + void testByteStreamUtilGetInt() { + byte[] buf = { 0x01, 0x02, 0x03, 0x04 }; + byteStreamUtil.init(byteBufferContext, buf, buf.length); + assertEquals(16909060, byteStreamUtil.getInt(byteBufferContext)); + } + + @Test + void testByteStreamUtilGetUByte() { + byte[] buf = { 0x01 }; + byteStreamUtil.init(byteBufferContext, buf, buf.length); + assertEquals(1, byteStreamUtil.getUByte(byteBufferContext)); + } + + @Test + void testByteStreamUtilGetUShort() { + byte[] buf = { 0x01, 0x02 }; + byteStreamUtil.init(byteBufferContext, buf, buf.length); + assertEquals(258, byteStreamUtil.getUShort(byteBufferContext)); + } + + @Test + void testByteStreamUtilGetU3Bytes() { + byte[] buf = { 0x01, 0x02, 0x03 }; + byteStreamUtil.init(byteBufferContext, buf, buf.length); + assertEquals(66051, byteStreamUtil.getU3Bytes(byteBufferContext)); + } + + @Test + void testByteStreamUtilGetUInt() { + byte[] buf = { 0x01, 0x02, 0x03, 0x04 }; + byteStreamUtil.init(byteBufferContext, buf, buf.length); + assertEquals(16909060, byteStreamUtil.getUInt(byteBufferContext)); + } + + @Test + void testByteStreamUtilAsUnsignedByte() { + assertEquals(0, byteStreamUtil.asUnsignedByte((byte) 0)); + assertEquals(255, byteStreamUtil.asUnsignedByte((byte) -1)); // -1 as unsigned is 255 + assertEquals(127, byteStreamUtil.asUnsignedByte((byte) 127)); + } + + @Test + void testByteStreamUtilAsSignedByte() { + assertEquals(0, byteStreamUtil.asSignedByte((byte) 0)); + assertEquals(-1, byteStreamUtil.asSignedByte((byte) -1)); // -1 remains -1 + assertEquals(127, byteStreamUtil.asSignedByte((byte) 127)); + } + + @Test + void testByteStreamUtilAsUnsignedShort() { + assertEquals(0, byteStreamUtil.asUnsignedShort((short) 0)); + assertEquals(65535, byteStreamUtil.asUnsignedShort((short) -1)); // -1 as unsigned is 65535 + assertEquals(32767, byteStreamUtil.asUnsignedShort((short) 32767)); + } + + @Test + void testByteStreamUtilAsSignedShort() { + assertEquals(0, byteStreamUtil.asSignedShort((short) 0)); + assertEquals(-1, byteStreamUtil.asSignedShort((short) -1)); // -1 remains -1 + assertEquals(32767, byteStreamUtil.asSignedShort((short) 32767)); + } + + @Test + void testByteStreamUtilMemCompare() { + int[] a = { 1, 2, 3 }; + int[] b = { 1, 2, 3 }; + assertEquals(0, byteStreamUtil.memCompare(a, b, 3)); + + int[] c = { 1, 2, 4 }; + assertTrue(byteStreamUtil.memCompare(a, c, 3) < 0); // a < c + + int[] d = { 1, 2, 2 }; + assertTrue(byteStreamUtil.memCompare(a, d, 3) > 0); // a > d + + int[] e = { 1, 2 }; // Smaller size + assertThrows(ArrayIndexOutOfBoundsException.class, () -> { + byteStreamUtil.memCompare(a, e, 3); // sz is larger than e's length + }); + } + + @Test + void testByteStreamUtilAvClip() { + assertEquals(5, byteStreamUtil.avClip(5, 0, 10)); // Within range + assertEquals(0, byteStreamUtil.avClip(-5, 0, 10)); // Below min + assertEquals(10, byteStreamUtil.avClip(15, 0, 10)); // Above max + assertEquals(0, byteStreamUtil.avClip(0, 0, 10)); // At min + assertEquals(10, byteStreamUtil.avClip(10, 0, 10)); // At max + } + + @Test + void testByteStreamUtilMakeTag() { + assertEquals(0x64636261, byteStreamUtil.makeTag('a', 'b', 'c', 'd')); // 'd' is the highest byte + assertEquals(0x00000000, byteStreamUtil.makeTag('\0', '\0', '\0', '\0')); // All zeros + assertEquals(0x7f7f7f7f, byteStreamUtil.makeTag('\u007F', '\u007F', '\u007F', '\u007F')); // Maximum ASCII char + } + + @Test + void testByteStreamUtilMakeBETag() { + assertEquals(0x61626364, byteStreamUtil.makeBETag('a', 'b', 'c', 'd')); // 'a' is the highest byte + assertEquals(0x00000000, byteStreamUtil.makeBETag('\0', '\0', '\0', '\0')); // All zeros + assertEquals(0x7f7f7f7f, byteStreamUtil.makeBETag('\u007F', '\u007F', '\u007F', '\u007F')); // Maximum ASCII + // char + } + + @Test + void testByteStreamUtilFfErrorTag() { + assertEquals(-1633837924, byteStreamUtil.ffErrorTag('a', 'b', 'c', 'd')); // Negative of makeTag result + assertEquals(-0, byteStreamUtil.ffErrorTag('\0', '\0', '\0', '\0')); // All zeros + assertEquals(-2139062143, byteStreamUtil.ffErrorTag('\u007F', '\u007F', '\u007F', '\u007F')); // Negative of max + // ASCII char + } + + @Test + void testByteStreamUtilCopyDirectBuffer() { + ByteBuffer original = ByteBuffer.allocateDirect(10); + original.put(new byte[] { 1, 2, 3, 4, 5 }); + original.flip(); // Prepare buffer for reading + + ByteBuffer copy = byteStreamUtil.copy(original, false); + + assertEquals(original.limit(), copy.limit()); + assertEquals(original.order(), copy.order()); + } + + @Test + void testByteStreamUtilPeekUByte() { + ByteBufferContext context = new ByteBufferContext(); + context.setBuffer(ByteBuffer.allocate(10)); + context.getBuffer().put(new byte[] { (byte) 0xFF }); // Unsigned byte value (255) + context.getBuffer().flip(); // Prepare buffer for reading + + long value = byteStreamUtil.peekUByte(context); + + assertEquals(255, value); + assertEquals(0, context.getBuffer().position()); // Ensure position is unchanged + } + + @Test + void testByteStreamUtilPeekUShort() { + ByteBufferContext context = new ByteBufferContext(); + context.setBuffer(ByteBuffer.allocate(10)); + context.getBuffer().putShort((short) 0xFFFF); // Unsigned short value (65535) + context.getBuffer().flip(); // Prepare buffer for reading + + long value = byteStreamUtil.peekUShort(context); + + assertEquals(65535, value); + assertEquals(0, context.getBuffer().position()); // Ensure position is unchanged + } + + @Test + void testByteStreamUtilPeekU3Bytes() { + ByteBufferContext context = new ByteBufferContext(); + context.setBuffer(ByteBuffer.allocate(10)); + context.getBuffer().put(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }); // Unsigned 3 bytes (16777215) + context.getBuffer().flip(); // Prepare buffer for reading + + long value = byteStreamUtil.peekU3Bytes(context); + + assertEquals(16777215, value); + assertEquals(0, context.getBuffer().position()); // Ensure position is unchanged + } + + @Test + void testByteStreamUtilPeekUInt() { + ByteBufferContext context = new ByteBufferContext(); + context.setBuffer(ByteBuffer.allocate(10)); + context.getBuffer().putInt(0xFFFFFFFF); // Unsigned int value (4294967295) + context.getBuffer().flip(); // Prepare buffer for reading + + long value = byteStreamUtil.peekUInt(context); + + assertEquals(4294967295L, value); + assertEquals(0, context.getBuffer().position()); // Ensure position is unchanged + } + + @Test + void testByteStreamUtilCopyNonDirectBuffer() { + ByteBuffer original = ByteBuffer.allocate(10); + original.put(new byte[] { 1, 2, 3, 4, 5 }); + original.flip(); // Prepare buffer for reading + + ByteBuffer copy = byteStreamUtil.copy(original, false); + + assertEquals(original.limit(), copy.limit()); + assertEquals(original.order(), copy.order()); + } + + @Test + void testByteStreamUtilPeekByte() { + ByteBufferContext context = new ByteBufferContext(); + context.setBuffer(ByteBuffer.allocate(10)); + context.getBuffer().put(new byte[] { 10 }); + context.getBuffer().flip(); // Prepare buffer for reading + + long value = byteStreamUtil.peekByte(context); + + assertEquals(10, value); + assertEquals(0, context.getBuffer().position()); // Ensure position is unchanged + } + + @Test + void testByteStreamUtilPeekShort() { + ByteBufferContext context = new ByteBufferContext(); + context.setBuffer(ByteBuffer.allocate(10)); + context.getBuffer().putShort((short) 20); + context.getBuffer().flip(); // Prepare buffer for reading + + long value = byteStreamUtil.peekShort(context); + + assertEquals(20, value); + assertEquals(0, context.getBuffer().position()); // Ensure position is unchanged + } + + @Test + void testByteStreamUtilPeekInt() { + ByteBufferContext context = new ByteBufferContext(); + context.setBuffer(ByteBuffer.allocate(10)); + context.getBuffer().putInt(30); + context.getBuffer().flip(); // Prepare buffer for reading + + long value = byteStreamUtil.peekInt(context); + + assertEquals(30, value); + assertEquals(0, context.getBuffer().position()); // Ensure position is unchanged + } + + @Test + void testByteStreamUtilSeek() { + ByteBufferContext context = new ByteBufferContext(); + context.setBuffer(ByteBuffer.allocate(10)); + context.getBuffer().put(new byte[] { 1, 2, 3, 4, 5 }); + context.getBuffer().flip(); // Prepare buffer for reading + + int newPos = byteStreamUtil.seek(context, 2, DecoderConstant.WHENCE_SEEK_SET); + assertEquals(2, newPos); + assertEquals(2, context.getBuffer().position()); // Ensure position is updated + + newPos = byteStreamUtil.seek(context, -1, DecoderConstant.WHENCE_SEEK_CUR); + assertEquals(1, newPos); + assertEquals(1, context.getBuffer().position()); // Ensure position is updated + + newPos = byteStreamUtil.seek(context, -1, DecoderConstant.WHENCE_SEEK_END); + assertEquals(3, newPos); // Ensure correct seeking to end + assertEquals(3, context.getBuffer().position()); // Ensure position is updated + } + + @Test + void testByteStreamUtilInvalidSeek() { + ByteBufferContext context = new ByteBufferContext(); + context.setBuffer(ByteBuffer.allocate(10)); + context.getBuffer().put(new byte[] { 1, 2, 3, 4, 5 }); + context.getBuffer().flip(); // Prepare buffer for reading + + assertThrows(DecoderException.class, () -> { + byteStreamUtil.seek(context, 0, -1); // Invalid whence + }); + } + + @Test + void testByteStreamUtilToUnsignedBigInteger_PositiveValue() { + long input = 123456789L; + BigInteger expected = BigInteger.valueOf(input); + + BigInteger result = byteStreamUtil.toUnsignedBigInteger(input); + + assertEquals(expected, result); + } + + @Test + void testByteStreamUtilToUnsignedBigInteger_NegativeValue() { + long input = -123456789L; // Negative long value + // Expected value will be (2^32 + input) + BigInteger expected = BigInteger.valueOf(Integer.toUnsignedLong(-1)).shiftLeft(32) + .add(BigInteger.valueOf(Integer.toUnsignedLong(-123456789))); + + BigInteger result = byteStreamUtil.toUnsignedBigInteger(input); + + assertEquals(expected, result); + } + + @Test + void testByteStreamUtilToUnsignedBigInteger_Zero() { + long input = 0L; + BigInteger expected = BigInteger.valueOf(input); + + BigInteger result = byteStreamUtil.toUnsignedBigInteger(input); + + assertEquals(expected, result); + } + + @Test + void testByteStreamUtilToUnsignedBigInteger_MaxLongValue() { + long input = Long.MAX_VALUE; // Maximum long value + BigInteger expected = BigInteger.valueOf(input); + + BigInteger result = byteStreamUtil.toUnsignedBigInteger(input); + + assertEquals(expected, result); + } + + @Test + void testByteStreamUtilToUnsignedBigInteger_MinLongValue() { + long input = Long.MIN_VALUE; // Minimum long value + BigInteger expected = BigInteger.ONE.shiftLeft(63); // This represents 2^63 + + BigInteger result = byteStreamUtil.toUnsignedBigInteger(input); + + assertEquals(expected, result); + } + + @Test + void testByteStreamUtilToUnsignedBigInteger_NegativeUpperBound() { + long input = -1L; // Edge case for the smallest negative value + BigInteger expected = BigInteger.valueOf(Integer.toUnsignedLong(-1)).shiftLeft(32) + .add(BigInteger.valueOf(Integer.toUnsignedLong(-1))); + + BigInteger result = byteStreamUtil.toUnsignedBigInteger(input); + + assertEquals(expected, result); + } + + @Test + void testByteStreamUtilSkipBytes_ValidCase() { + ByteBuffer buffer = ByteBuffer.allocate(10); + buffer.put(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); + buffer.flip(); // Prepare buffer for reading + byteBufferContext.setBuffer(buffer); + + // Set initial position + buffer.position(2); + + // Skip 3 bytes + byteStreamUtil.skipBytesForSize(byteBufferContext, 3); + + // Verify new position + assertEquals(5, buffer.position()); + } + + @Test + void testByteStreamUtilSkipBytesForSizeU_ValidSkip() { + ByteBuffer buffer = ByteBuffer.allocate(10); + buffer.put(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); + buffer.flip(); // Prepare buffer for reading + byteBufferContext.setBuffer(buffer); + + // Set initial position + buffer.position(2); + + // Skip 3 bytes + byteStreamUtil.skipBytesForSizeU(byteBufferContext, 3); + + // Verify new position + assertEquals(5, buffer.position()); + } + + @Test + void testByteStreamUtilGetUnsignedLong_BigEndian() { + ByteBuffer buffer = ByteBuffer.allocate(8); + buffer.order(ByteOrder.BIG_ENDIAN); + buffer.put(new byte[] { 0, 0, 0, 0, 0, 0, 0, 1 }); // 1 as unsigned long + buffer.flip(); // Prepare buffer for reading + + BigInteger result = byteStreamUtil.getUnsignedLong(buffer, 0, ByteOrder.BIG_ENDIAN); + + assertEquals(BigInteger.ONE, result); + } + + @Test + void testByteStreamUtilGetUnsignedLong_LittleEndian() { + ByteBuffer buffer = ByteBuffer.allocate(8); + buffer.order(ByteOrder.LITTLE_ENDIAN); + buffer.put(new byte[] { 1, 0, 0, 0, 0, 0, 0, 0 }); // 1 as unsigned long + buffer.flip(); // Prepare buffer for reading + + BigInteger result = byteStreamUtil.getUnsignedLong(buffer, 0, ByteOrder.LITTLE_ENDIAN); + + assertEquals(BigInteger.ONE, result); + } + + @Test + void testByteStreamUtilGetUnsignedLong_Zero() { + ByteBuffer buffer = ByteBuffer.allocate(8); + buffer.put(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }); // 0 as unsigned long + buffer.flip(); // Prepare buffer for reading + + BigInteger result = byteStreamUtil.getUnsignedLong(buffer, 0, ByteOrder.BIG_ENDIAN); + + assertEquals(BigInteger.ZERO, result); + } + + @Test + void testByteStreamUtilGetUnsignedLong_MaxValue_BigEndian() { + ByteBuffer buffer = ByteBuffer.allocate(8); + buffer.order(ByteOrder.BIG_ENDIAN); + buffer.put(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, + (byte) 0xFF, (byte) 0xFF }); // 2^64 - 1 as unsigned long + buffer.flip(); // Prepare buffer for reading + + BigInteger result = byteStreamUtil.getUnsignedLong(buffer, 0, ByteOrder.BIG_ENDIAN); + + assertEquals(new BigInteger("18446744073709551615"), result); // 2^64 - 1 + } + + @Test + void testByteStreamUtilGetUnsignedLong_MaxValue_LittleEndian() { + ByteBuffer buffer = ByteBuffer.allocate(8); + buffer.order(ByteOrder.LITTLE_ENDIAN); + buffer.put(new byte[] { -1, -1, -1, -1, -1, -1, -1, 127 }); // 2^63 - 1 as unsigned long + buffer.flip(); // Prepare buffer for reading + + BigInteger result = byteStreamUtil.getUnsignedLong(buffer, 0, ByteOrder.LITTLE_ENDIAN); + + assertEquals(new BigInteger("9223372036854775807"), result); + } + + @Test + void testByteStreamUtilGetSignedLong_BigEndian() { + ByteBuffer buffer = ByteBuffer.allocate(8); + buffer.order(ByteOrder.BIG_ENDIAN); + buffer.put(new byte[] { 0, 0, 0, 0, 0, 0, 0, 1 }); // 1 as signed long + buffer.flip(); // Prepare buffer for reading + + BigInteger result = byteStreamUtil.getSignedLong(buffer, 0, ByteOrder.BIG_ENDIAN); + + assertEquals(BigInteger.ONE, result); + } + + @Test + void testByteStreamUtilGetSignedLong_LittleEndian() { + ByteBuffer buffer = ByteBuffer.allocate(8); + buffer.order(ByteOrder.LITTLE_ENDIAN); + buffer.put(new byte[] { 1, 0, 0, 0, 0, 0, 0, 0 }); // 1 as signed long + buffer.flip(); // Prepare buffer for reading + + BigInteger result = byteStreamUtil.getSignedLong(buffer, 0, ByteOrder.LITTLE_ENDIAN); + + assertEquals(BigInteger.ONE, result); + } + + @Test + void testByteStreamUtilGetSignedLong_NegativeValue_BigEndian() { + ByteBuffer buffer = ByteBuffer.allocate(8); + buffer.order(ByteOrder.BIG_ENDIAN); + buffer.put(new byte[] { -1, -1, -1, -1, -1, -1, -1, -1 }); // -1 as signed long + buffer.flip(); // Prepare buffer for reading + + BigInteger result = byteStreamUtil.getSignedLong(buffer, 0, ByteOrder.BIG_ENDIAN); + + assertEquals(BigInteger.valueOf(-1), result); + } + + @Test + void testByteStreamUtilGetSignedLong_NegativeValue_LittleEndian() { + ByteBuffer buffer = ByteBuffer.allocate(8); + buffer.order(ByteOrder.LITTLE_ENDIAN); + buffer.put(new byte[] { -1, -1, -1, -1, -1, -1, -1, -1 }); // -1 as signed long + buffer.flip(); // Prepare buffer for reading + + BigInteger result = byteStreamUtil.getSignedLong(buffer, 0, ByteOrder.LITTLE_ENDIAN); + + assertEquals(BigInteger.valueOf(-1), result); + } + + @Test + void testByteStreamUtilGetSignedLong_MaxValue_BigEndian() { + ByteBuffer buffer = ByteBuffer.allocate(8); + buffer.order(ByteOrder.BIG_ENDIAN); + buffer.put(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, + (byte) 0xFF, (byte) 0xFF }); // 2^64 - 1 as unsigned long + buffer.flip(); // Prepare buffer for reading + + BigInteger result = byteStreamUtil.getUnsignedLong(buffer, 0, ByteOrder.BIG_ENDIAN); + + assertEquals(new BigInteger("18446744073709551615"), result); // 2^64 - 1 + } + + @Test + void testByteStreamUtilGetSignedLong_MinValue_BigEndian() { + ByteBuffer buffer = ByteBuffer.allocate(8); + buffer.order(ByteOrder.BIG_ENDIAN); + buffer.put(new byte[] { -128, 0, 0, 0, 0, 0, 0, 0 }); // Min signed long value + buffer.flip(); // Prepare buffer for reading + + BigInteger result = byteStreamUtil.getSignedLong(buffer, 0, ByteOrder.BIG_ENDIAN); + + assertEquals(new BigInteger("-9223372036854775808"), result); + } + + @Test + void testByteStreamUtilGetSignedVarInt_1Byte_Positive() { + ByteBuffer buffer = ByteBuffer.allocate(1); + buffer.put((byte) 127); // 127 is the max positive value for a signed byte + long result = byteStreamUtil.getSignedVarInt(buffer, 0, 1); + assertEquals(127, result); + } + + @Test + void testByteStreamUtilGetSignedVarInt_1Byte_Negative() { + ByteBuffer buffer = ByteBuffer.allocate(1); + buffer.put((byte) -128); // -128 is the min negative value for a signed byte + long result = byteStreamUtil.getSignedVarInt(buffer, 0, 1); + assertEquals(-128, result); + } + + @Test + void testByteStreamUtilGetSignedVarInt_2Bytes_Positive() { + ByteBuffer buffer = ByteBuffer.allocate(2); + buffer.putShort((short) 32767); // 32767 is the max positive value for a signed short + buffer.flip(); // Prepare buffer for reading + long result = byteStreamUtil.getSignedVarInt(buffer, 0, 2); + assertEquals(32767, result); + } + + @Test + void testByteStreamUtilGetSignedVarInt_2Bytes_Negative() { + ByteBuffer buffer = ByteBuffer.allocate(2); + buffer.putShort((short) -32768); // -32768 is the min negative value for a signed short + buffer.flip(); // Prepare buffer for reading + long result = byteStreamUtil.getSignedVarInt(buffer, 0, 2); + assertEquals(-32768, result); + } + + @Test + void testByteStreamUtilGetSignedVarInt_3Bytes_Positive() { + ByteBuffer buffer = ByteBuffer.allocate(3); + buffer.put(new byte[] { 0x7F, (byte) 0xFF, (byte) 0xFF }); // Max positive 24-bit value: 8388607 + buffer.flip(); // Prepare buffer for reading + long result = byteStreamUtil.getSignedVarInt(buffer, 0, 3); + assertEquals(8388607, result); + } + + @Test + void testByteStreamUtilGetSignedVarInt_3Bytes_Negative() { + ByteBuffer buffer = ByteBuffer.allocate(3); + buffer.put(new byte[] { (byte) 0x80, 0x00, 0x00 }); // Min negative 24-bit value: -8388608 + buffer.flip(); // Prepare buffer for reading + long result = byteStreamUtil.getSignedVarInt(buffer, 0, 3); + assertEquals(-8388608, result); + } + + @Test + void testByteStreamUtilGetSignedVarInt_4Bytes_Positive() { + ByteBuffer buffer = ByteBuffer.allocate(4); + buffer.putInt(Integer.MAX_VALUE); // Max positive value for 32-bit signed int: 2147483647 + buffer.flip(); // Prepare buffer for reading + long result = byteStreamUtil.getSignedVarInt(buffer, 0, 4); + assertEquals(2147483647, result); + } + + @Test + void testByteStreamUtilGetSignedVarInt_4Bytes_Negative() { + ByteBuffer buffer = ByteBuffer.allocate(4); + buffer.putInt(Integer.MIN_VALUE); // Min negative value for 32-bit signed int: -2147483648 + buffer.flip(); // Prepare buffer for reading + long result = byteStreamUtil.getSignedVarInt(buffer, 0, 4); + assertEquals(-2147483648, result); + } + + @Test + void testByteStreamUtilGetSignedVarInt_InvalidNumBytes() { + ByteBuffer buffer = ByteBuffer.allocate(4); + buffer.putInt(1234); + buffer.flip(); // Prepare buffer for reading + Exception exception = assertThrows(IllegalArgumentException.class, () -> { + byteStreamUtil.getSignedVarInt(buffer, 0, 5); // Invalid number of bytes + }); + assertTrue(exception.getMessage().contains("Invalid num bytes")); + } + + @Test + void testByteStreamUtilGetUnsignedVarInt_1Byte() { + ByteBuffer buffer = ByteBuffer.allocate(1); + buffer.put((byte) 0xFF); // Max value for 1 byte: 255 + buffer.flip(); // Prepare buffer for reading + long result = byteStreamUtil.getUnsignedVarInt(buffer, 0, 1); + assertEquals(255, result); + } + + @Test + void testByteStreamUtilGetUnsignedVarInt_2Bytes() { + ByteBuffer buffer = ByteBuffer.allocate(2); + buffer.putShort((short) 0xFFFF); // Max value for 2 bytes: 65535 + buffer.flip(); // Prepare buffer for reading + long result = byteStreamUtil.getUnsignedVarInt(buffer, 0, 2); + assertEquals(65535, result); + } + + @Test + void testByteStreamUtilGetUnsignedVarInt_3Bytes() { + ByteBuffer buffer = ByteBuffer.allocate(3); + buffer.put(new byte[]{(byte) 0xFF, (byte) 0xFF, (byte) 0xFF}); // Max value for 3 bytes: 16777215 + buffer.flip(); // Prepare buffer for reading + long result = byteStreamUtil.getUnsignedVarInt(buffer, 0, 3); + assertEquals(16777215, result); + } + + @Test + void testByteStreamUtilGetUnsignedVarInt_4Bytes() { + ByteBuffer buffer = ByteBuffer.allocate(4); + buffer.putInt(0xFFFFFFFF); // Max value for 4 bytes: 4294967295 + buffer.flip(); // Prepare buffer for reading + long result = byteStreamUtil.getUnsignedVarInt(buffer, 0, 4); + assertEquals(4294967295L, result); + } + + @Test + void testByteStreamUtilGetUnsignedVarInt_InvalidNumBytes() { + ByteBuffer buffer = ByteBuffer.allocate(1); + buffer.put((byte) 0xFF); + buffer.flip(); // Prepare buffer for reading + Exception exception = assertThrows(DecoderException.class, () -> { + byteStreamUtil.getUnsignedVarInt(buffer, 0, 5); // Invalid number of bytes + }); + assertTrue(exception.getMessage().contains("Invalid num bytes")); + } + + @Test + void testByteSwapperUtilSwapShort() { + short original = 0x1234; + short swapped = byteSwapperUtil.swapShort(original); + assertEquals(0x3412, swapped, "The short value should be swapped correctly"); + } + + @Test + void testByteSwapperUtilSwap3Bytes() { + int original = 0x123456; + int swapped = byteSwapperUtil.swap3Bytes(original); + assertEquals(0x563412, swapped, "The 3-byte int should be swapped correctly"); + } + + @Test + void testByteSwapperUtilSwapInt() { + int original = 0x12345678; + int swapped = byteSwapperUtil.swapInt(original); + assertEquals(0x78563412, swapped, "The int value should be swapped correctly"); + } + + @Test + void testByteSwapperUtilSwapLong() { + long original = 0x1234567890ABCDEFL; + long swapped = byteSwapperUtil.swapLong(original); + assertEquals(0xEFCDAB9078563412L, swapped, "The long value should be swapped correctly"); + } + + @Test + void testByteSwapperUtilSwapFloat() { + float original = 1234.56f; + float swapped = byteSwapperUtil.swapFloat(original); + assertNotEquals(original, swapped, "The float value should be swapped correctly"); + } + + @Test + void testByteSwapperUtilSwapDouble() { + double original = 12345678.90; + double swapped = byteSwapperUtil.swapDouble(original); + assertNotEquals(original, swapped, "The double value should be swapped correctly"); + } + + @Test + void testByteSwapperUtilSwapShortArray() { + short[] array = { 0x1234, 0x5678 }; + byteSwapperUtil.swap(array); + assertArrayEquals(new short[] { 0x3412, 0x7856 }, array, "The array of shorts should be swapped"); + } + + @Test + void testByteSwapperUtilSwapIntArray() { + int[] array = { 0x12345678, 0x90ABCDEF }; + byteSwapperUtil.swap(array); + assertArrayEquals(new int[] { 0x78563412, 0xEFCDAB90 }, array, "The array of ints should be swapped"); + } + + @Test + void testByteSwapperUtilSwapLongArray() { + long[] array = { 0x1234567890ABCDEFL, 0x0FEDCBA987654321L }; + byteSwapperUtil.swap(array); + System.out.printf("Swapped values: [%016X, %016X]%n", array[0], array[1]); + assertArrayEquals(new long[] { 0xEFCDAB9078563412L, 0x21436587A9CBED0FL }, array, + "The array of longs should be swapped"); + } + + @Test + void testByteSwapperUtilSwapFloatArray() { + float[] array = { 1234.56f, 7890.12f }; + byteSwapperUtil.swap(array); + assertNotEquals(array[0], 1234.56f); + assertNotEquals(array[1], 7890.12f); + } + + @Test + void testByteSwapperUtilSwapDoubleArray() { + double[] array = { 12345678.90, 98765432.10 }; + byteSwapperUtil.swap(array); + assertNotEquals(array[0], 12345678.90); + assertNotEquals(array[1], 98765432.10); + } + + @Test + void testStringUtilStringCompare_EqualStrings() { + assertEquals(0, stringUtil.stringCompare("Hello", "Hello"), "Strings should be equal"); + } + + @Test + void testStringUtilStringCompare_DifferentStrings() { + assertTrue(stringUtil.stringCompare("Hello", "World") < 0, "Hello should be less than World"); + assertTrue(stringUtil.stringCompare("World", "Hello") > 0, "World should be greater than Hello"); + } + + @Test + void testStringUtilStringCompare_LengthDifference() { + assertTrue(stringUtil.stringCompare("Hello", "Hello World") < 0, "Hello should be less than Hello World"); + assertTrue(stringUtil.stringCompare("Hello World", "Hello") > 0, "Hello World should be greater than Hello"); + } + + @Test + void testStringUtilAtoi_ValidInteger() { + char[] validInput = "12345".toCharArray(); + assertEquals(12345, stringUtil.atoi(validInput), "Should convert valid string to integer"); + } + + @Test + void testStringUtilAtoi_WhitespaceAndSigns() { + char[] input = " -678".toCharArray(); + assertEquals(-678, stringUtil.atoi(input), "Should handle whitespace and negative sign"); + } + + @Test + void testStringUtilAtoi_Overflow() { + char[] overflowInput = "2147483648".toCharArray(); // This is beyond Integer.MAX_VALUE + assertEquals(Integer.MAX_VALUE, stringUtil.atoi(overflowInput), "Should return Integer.MAX_VALUE on overflow"); + } + + @Test + void testStringUtilAtoi_InvalidInput() { + char[] invalidInput = "abc".toCharArray(); + assertEquals(0, stringUtil.atoi(invalidInput), "Should return 0 for invalid input"); + } + + @Test + void testStringUtilAtof_ValidDouble() { + assertEquals(123.45, stringUtil.atof("123.45"), 0.001, "Should convert valid string to double"); + } + + @Test + void testStringUtilAtof_WhitespaceAndSigns() { + assertEquals(-67.89, stringUtil.atof(" -67.89 "), 0.001, "Should handle whitespace and negative sign"); + } + + @Test + void testStringUtilAtof_InvalidDouble() { + assertEquals(0.0, stringUtil.atof("abc"), 0.001, "Should return 0.0 for invalid input"); + } + + @Test + void testStringUtilAtof_TooManySignsOrDots() { + assertEquals(0.0, stringUtil.atof("----123.45"), 0.001, + "Should return 0.0 for invalid input with too many signs"); + assertEquals(0.0, stringUtil.atof("123..45"), 0.001, "Should return 0.0 for invalid input with too many dots"); + } + + @Test + void testConvertImage2Floats() { + // Prepare data + int numOfPixels = 10; + float[] fImageData = new float[numOfPixels]; + float[] mShift = new float[1]; + float[] rScale = new float[1]; + byte[] data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + // Execute + int result = wsqUtil.convertImage2Floats(fImageData, mShift, rScale, data, numOfPixels); + + // Verify + assertEquals(0, result); + assertNotNull(fImageData); + assertTrue(mShift[0] >= 0); + assertTrue(rScale[0] > 0); + } + + @Test + void testConvertImage2FloatsWithOverflow() { + // Prepare data that causes overflow + int numOfPixels = 5; + float[] fImageData = new float[numOfPixels]; + float[] mShift = new float[1]; + float[] rScale = new float[1]; + byte[] data = new byte[numOfPixels]; + for (int i = 0; i < numOfPixels; i++) { + data[i] = (byte) 255; // Setting max value to trigger overflow in sum + } + + // Execute + int result = wsqUtil.convertImage2Floats(fImageData, mShift, rScale, data, numOfPixels); + + // Verify + assertEquals(0, result); + } + + @Test + void testConvertImage2Bytes() { + // Prepare data + int width = 5; + int height = 2; + byte[] data = new byte[width * height]; + float[] img = { 0.0f, 128.0f, 255.0f, 300.0f, -10.0f, 100.0f, 50.0f, 200.0f, 10.0f, 150.0f }; + float mShift = 128.0f; + float rScale = 1.0f; + + // Execute + wsqUtil.convertImage2Bytes(data, img, width, height, mShift, rScale); + + // Verify + for (byte b : data) { + assertTrue(b >= -128 && b <= 128); + } + } + + @Test + void testVarianceWithVsumBelow20000() { + // Prepare data + int width = 10; + int height = 10; + float[] fImageData = new float[width * height]; + WsqQuantization quantValues = new WsqQuantization(); + quantValues.setVar(new float[WsqConstant.NUM_SUBBANDS]); + + WsqQuantizationTree[] quantizationTree = new WsqQuantizationTree[WsqConstant.NUM_SUBBANDS]; + for (int i = 0; i < quantizationTree.length; i++) { + quantizationTree[i] = new WsqQuantizationTree(); + quantizationTree[i].setX((short) 0); + quantizationTree[i].setY((short) 0); + quantizationTree[i].setLenX((short) 8); + quantizationTree[i].setLenY((short) 8); + } + + // Execute + wsqUtil.variance(quantValues, quantizationTree, quantizationTree.length, fImageData, width, height); + + // Verify + for (float var : quantValues.getVar()) { + assertTrue(var >= 0); + } + } + + @Test + void testVarianceWithVsumAbove20000() { + // Prepare data + int width = 10; + int height = 10; + float[] fImageData = new float[width * height]; + WsqQuantization quantValues = new WsqQuantization(); + quantValues.setVar(new float[WsqConstant.NUM_SUBBANDS]); + + WsqQuantizationTree[] quantizationTree = new WsqQuantizationTree[WsqConstant.NUM_SUBBANDS]; + for (int i = 0; i < quantizationTree.length; i++) { + quantizationTree[i] = new WsqQuantizationTree(); + quantizationTree[i].setX((short) 0); + quantizationTree[i].setY((short) 0); + quantizationTree[i].setLenX((short) 8); + quantizationTree[i].setLenY((short) 8); + } + + // Simulate a large `vsum` + quantValues.getVar()[0] = 25000.0f; + + // Execute + wsqUtil.variance(quantValues, quantizationTree, quantizationTree.length, fImageData, width, height); + + // Verify + for (float var1 : quantValues.getVar()) { + assertTrue(var1 >= 0); + } + } + + @Test + void testQuantize() { + // Set up test data + short[] sip = new short[100]; + int[] cmpSize = new int[1]; + WsqQuantization quantValues = new WsqQuantization(); + WsqQuantizationTree[] quantizationTree = new WsqQuantizationTree[60]; // Assuming 60 subbands + for (int i = 0; i < quantizationTree.length; i++) { + if (quantizationTree[i] == null) { // Check if the element is not already initialized + quantizationTree[i] = new WsqQuantizationTree(); + } + quantizationTree[i].setLenX((short) 10); // Example value for length X + quantizationTree[i].setLenY((short) 10); // Example value for length Y + quantizationTree[i].setX((short) 5); // Example starting X coordinate + quantizationTree[i].setY((short) 5); // Example starting Y coordinate + } + int qTreeLen = quantizationTree.length; + float[] fImageData = new float[1000]; // Example data size + int width = 100; + int height = 100; + + // Call the method + int result = wsqUtil.quantize(sip, cmpSize, quantValues, quantizationTree, qTreeLen, fImageData, width, height); + + // Add assertions to verify correctness + assertEquals(0, result); + // Additional checks for 'sip', 'cmpSize', etc. + } + + @Test + void testQuantizedBlockSizes() { + int[] qSize1 = new int[1]; + int[] qSize2 = new int[1]; + int[] qSize3 = new int[1]; + WsqQuantization quantValues = new WsqQuantization(); + WsqWavletTree[] wavletTree = new WsqWavletTree[20]; + // Initialize each element with some test data + for (int i = 0; i < wavletTree.length; i++) { + wavletTree[i] = new WsqWavletTree(); + wavletTree[i].setLenX(10); // Example value for length X + wavletTree[i].setLenY(10); // Example value for length Y + } + + WsqQuantizationTree[] quantizationTree = new WsqQuantizationTree[60]; + for (int i = 0; i < quantizationTree.length; i++) { + if (quantizationTree[i] == null) { // Check if the element is not already initialized + quantizationTree[i] = new WsqQuantizationTree(); + } + quantizationTree[i].setLenX((short) 10); // Example value for length X + quantizationTree[i].setLenY((short) 10); // Example value for length Y + quantizationTree[i].setX((short) 5); // Example starting X coordinate + quantizationTree[i].setY((short) 5); // Example starting Y coordinate + } + int waveletTreeLen = wavletTree.length; + int qTreeLen = quantizationTree.length; + + wsqUtil.quantizedBlockSizes(qSize1, qSize2, qSize3, quantValues, wavletTree, waveletTreeLen, quantizationTree, + qTreeLen); + + int expectedValue = -1800; + // Add assertions to verify correctness + // For example: + assertEquals(expectedValue, qSize1[0]); + } + + @Test + void testUnquantize() { + // Prepare test data + float[] fImageData = new float[100]; // Adjust size as necessary + WsqTableDqt dqtTable = new WsqTableDqt(); + // Initialize dqtTable properties as needed + WsqQuantizationTree[] quantizationTree = new WsqQuantizationTree[WsqConstant.NUM_SUBBANDS]; + + // Initialize the quantizationTree array + for (int i = 0; i < quantizationTree.length; i++) { + quantizationTree[i] = new WsqQuantizationTree(); + quantizationTree[i].setLenX((short) 10); // Set appropriate values + quantizationTree[i].setLenY((short) 10); + quantizationTree[i].setX((short) 5); + quantizationTree[i].setY((short) 5); + } + + long[] sip = new long[] { 0, 1, 2 }; // Example quantized values + int width = 10; // Set appropriate width + int height = 10; // Set appropriate height + + // Call the method under test + int result = wsqUtil.unquantize(fImageData, dqtTable, quantizationTree, quantizationTree.length, sip, width, + height); + + // Verify the results + assertEquals(-34, result); // Check for expected return value + // Further assertions to check the content of fImageData as needed + } + + @Test + void testWsqDecomposeNormal() { + float[] fImageData = new float[100]; // Sample image data + float[] highFilter = new float[] { 1.0f, 2.0f }; // Example filter coefficients + float[] lowFilter = new float[] { 1.0f, 2.0f }; // Example filter coefficients + + WsqWavletTree[] wavletTree = new WsqWavletTree[3]; // Adjust size as needed + for (int i = 0; i < wavletTree.length; i++) { + wavletTree[i] = new WsqWavletTree(); + wavletTree[i].setY(0); // Example values + wavletTree[i].setX(0); + wavletTree[i].setLenY(10); + wavletTree[i].setLenX(10); + wavletTree[i].setInvRow(0); + wavletTree[i].setInvCol(0); + } + int result = wsqUtil.wsqDecompose(fImageData, 10, 10, wavletTree, wavletTree.length, highFilter, + highFilter.length, lowFilter, lowFilter.length); + + assertEquals(0, result); // Expect success + // Validate fImageData or other outcomes as necessary + } + + @Test + void testImageSizeNormal() { + int blockLen = 100; + short[] huffBits1 = new short[16]; + short[] huffBits2 = new short[16]; + + // Fill huffman bits with some values + for (int i = 1; i < 16; i++) { + huffBits1[i] = (short) (i * 5); + huffBits2[i] = (short) (i * 3); + } + + int result = wsqUtil.imageSize(blockLen, huffBits1, huffBits2); + + // Calculate expected total size manually based on your understanding + int expectedSize = blockLen + 58 + 389 + 17 + 3 + 3 + 3 + 3 + 16 + (huffBits1[1] + huffBits1[2] + huffBits1[3] + + huffBits1[4] + huffBits1[5] + huffBits1[6] + huffBits1[7] + huffBits1[8] + huffBits1[9] + + huffBits1[10] + huffBits1[11] + huffBits1[12] + huffBits1[13] + huffBits1[14] + huffBits1[15]) + 3 + + 16 + + (huffBits2[1] + huffBits2[2] + huffBits2[3] + huffBits2[4] + huffBits2[5] + huffBits2[6] + + huffBits2[7] + huffBits2[8] + huffBits2[9] + huffBits2[10] + huffBits2[11] + huffBits2[12] + + huffBits2[13] + huffBits2[14] + huffBits2[15]) + + 20; + + assertEquals(expectedSize, result); + } + + @Test + void testSingleton() { + ImageUtil instance1 = ImageUtil.getInstance(); + ImageUtil instance2 = ImageUtil.getInstance(); + assertSame(instance1, instance2, "Singleton instances are not the same"); + } + + @Test + void testCalculateAspectRatio() { + assertEquals(2.0, imageUtil.calculateAspectRatio(4, 2), 0.01); + assertThrows(IllegalArgumentException.class, () -> imageUtil.calculateAspectRatio(0, 5)); + assertThrows(IllegalArgumentException.class, () -> imageUtil.calculateAspectRatio(5, -1)); + } + + @Test + void testCalculateCompressionRatio() { + assertEquals(1, imageUtil.calculateCompressionRatio(100, 100, 1, 10000)); + assertEquals(100, imageUtil.calculateCompressionRatio(100, 100, 1, 100)); + assertThrows(IllegalArgumentException.class, () -> imageUtil.calculateCompressionRatio(100, 100, 1, 0)); + assertThrows(IllegalArgumentException.class, () -> imageUtil.calculateCompressionRatio(-100, 100, 1, 10000)); + } + + /* + * @Test void testFromJ2kImage() { // Assuming you have a mock or valid + * OpenJpegImage instance OpenJpegImage mockImage = createMockOpenJpegImage(); + * // Replace with actual mock creation + * assertThrows(IllegalArgumentException.class, () -> + * imageUtil.fromJ2kImage(800, 600, mockImage)); + * + * // Test exceptions for unsupported formats, if applicable + * assertThrows(Exception.class, () -> { // Pass an unsupported image format + * mock imageUtil.fromJ2kImage(800, 600, createUnsupportedFormatImage()); }); } + */ + + @Test + void testFromByteGray() { + byte[] grayData = new byte[800 * 600]; // Example data + BufferedImage grayImage = imageUtil.fromByteGray(800, 600, grayData); + assertNotNull(grayImage); + assertEquals(BufferedImage.TYPE_BYTE_GRAY, grayImage.getType()); + assertArrayEquals(grayData, ((DataBufferByte) grayImage.getRaster().getDataBuffer()).getData()); + } + + @Test + void testIntegersToBytes() { + int[] intData = { 1, 2, 3, 4, 5 }; + byte[] byteData = imageUtil.integersToBytes(intData); + assertArrayEquals(new byte[] { 1, 2, 3, 4, 5 }, byteData); + } + + private OpenJpegImage createMockOpenJpegImage() { + // Create a mocked instance of OpenJpegImage + OpenJpegImage mockImage = Mockito.mock(OpenJpegImage.class); + + // Set up the mock behavior + Mockito.when(mockImage.getX0()).thenReturn(0); + Mockito.when(mockImage.getY0()).thenReturn(0); + Mockito.when(mockImage.getX1()).thenReturn(1920); + Mockito.when(mockImage.getY1()).thenReturn(1080); + Mockito.when(mockImage.getNoOfComps()).thenReturn(3); + Mockito.when(mockImage.getQmfbid()).thenReturn(0); + Mockito.when(mockImage.getColorSpace()).thenReturn(Jp2ColorSpace.CLRSPC_SRGB); + + // Create and set up components if needed + OpenJpegImageComponent[] components = new OpenJpegImageComponent[3]; + for (int i = 0; i < 3; i++) { + components[i] = Mockito.mock(OpenJpegImageComponent.class); + Mockito.when(components[i].getData()).thenReturn(new int[1920 * 1080]); // Example data + } + Mockito.when(mockImage.getComps()).thenReturn(components); + + return mockImage; + } + + private OpenJpegImage createUnsupportedFormatImage() { + // Create a mocked instance of OpenJpegImage + return null; + } +} \ No newline at end of file diff --git a/imagedecoder/src/test/java/io/mosip/imagedecoder/test/WsqDecoderTest.java b/imagedecoder/src/test/java/io/mosip/imagedecoder/test/WsqDecoderTest.java new file mode 100644 index 0000000..e5baaae --- /dev/null +++ b/imagedecoder/src/test/java/io/mosip/imagedecoder/test/WsqDecoderTest.java @@ -0,0 +1,73 @@ +package io.mosip.imagedecoder.test; + +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_EMPTY; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_IDTYPE; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_SESSIONID; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.text.MessageFormat; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import io.mosip.imagedecoder.constant.DecoderErrorCodes; +import io.mosip.imagedecoder.logger.ImageDecoderLogger; +import io.mosip.imagedecoder.model.DecoderRequestInfo; +import io.mosip.imagedecoder.model.DecoderResponseInfo; +import io.mosip.imagedecoder.model.Response; +import io.mosip.imagedecoder.util.Base64UrlUtil; +import io.mosip.imagedecoder.wsq.WsqDecoder; +import io.mosip.kernel.core.logger.spi.Logger; + +class WsqDecoderTest { + + private static Logger logger = ImageDecoderLogger.getLogger(WsqDecoderTest.class); + + private WsqDecoder wsqDecoder; + + @BeforeEach + void setUp() { + wsqDecoder = new WsqDecoder(); + } + + @Test + void testDecodeSuccess() { + // Arrange + DecoderRequestInfo requestInfo = new DecoderRequestInfo(); + requestInfo.setImageData(Base64UrlUtil.getInstance().decodeURLSafeBase64( + "_6D_qAB6TklTVF9DT00gOQpQSVhfV0lEVEggMjgwClBJWF9IRUlHSFQgNDQ4ClBJWF9ERVBUSCA4ClBQSSA1MDAKTE9TU1kgMQpDT0xPUlNQQUNFIEdSQVkKQ09NUFJFU1NJT04gV1NRCldTUV9CSVRSQVRFIDAuNzUwMDAw_6gACk1vc2lwLmlv_6QAOgkHAAky0yXNAArg8xmaAQpB7_GaAQuOJ2TNAAvheaMzAAku_1YAAQr5M9MzAQvyhyGaAAomd9oz_6UBhQIALAIeXwIkcgIeXwIkcgIeXwIkcgIeXwIkcgIj4AIrDQIjiAIqowIgWgIm0wIgjAInDwIctgIidAIeSQIkWAIc0wIilwIh1QIomgIfNAIlcgIeNQIkQAIeKQIkMgIduQIjqwId2wIj1AId6AIj4wIekwIksQIeEQIkFAIg1wInaQIfqwImAQIhLQIn0AIgvwInSwIgdAIm8QIgIgImkAIgowInKgIgOAImqQIingIpiwIg8QIniAIhPQIn4wIiBAIo0gIizAIpwQIjMwIqPQIiKgIo_wIgPgImsQIhJgInxwIkUgIrlgIiWwIpOgIh-gIoxQIhyAIoigIjoQIqwQIimAIpgwIk6gIsTAIi5wIp4wIlaQIs5AIlvQItSQIkrwIsBQIjAgIqAwImJwItyQIkUgIrlgIllgItGgIdOwIjFAIpTAIxjgIhcQIoIgIwDgI5qgImbAIuGwIo4gIxDwI3dAJCiwI5uQJFRQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP-iABEA_wHAARgCOLsELFICLBD_pgBWAAACAQMBBQQECAUOCwkAAACztQECsra3AwSwsbgFrq-5Bq26uwcICQqrrLy9pKWmqaoLDA6hoqe-v8PK1trc3Q0Pn6CjqMHP2NnbnsLGx8jM0tTX_6MAAwD-_wDT-3_7_f8Ap_f-v_X9f-v5zify_t_X_n_79e_rd_z_AK_3_l-_8_p35n_z_j1_L8_y78ev_n_f_X8v3fu-vf8AT7_-vw_D_L_P8v3_AJ59_wBv4ft_7fj-H6d_-_7v9P8AP_L9v4fj6_z_ANPy_d-38P3_AI9_-P0_L8fw_D8_of29_wAfx_H9PU-39v8Ax-_8vy8X4-__AD_TP9f3-HX_AL1k4uXtl3h5Ic6rOdHtwAsY3dHj_b107J_L6sMhP4fVhF59_XIUmvprLAnlaKc_gZLu9e3XeGrr-JbFr7zMnrfsbGOOgY1q5jAvbMZi7ZtexhFCc5MSZOCZVqBRQjWQYYZXCN6stuZ9_aec9ui8K52dS2CWEuamozIXauZsxTGWLCLDOSE1HY2EZdBHKLmVZAyJFYRdS9UeJrNmD-phCPzDZhr0b2SmPwtgsG3e6cYkCytFAitXkNyymWpMGrgOzOc1dNMvDZzGjZi0wooojvq1IKbkJfj0QGDXhopiRl13NndzcjRs_A8RY0R3bzPiRYTWqQKcTbOyLRtZeUjGDSTVhDsS0mou6URJl-l0lcxlxY7EYUkWLSkzdq2mg21thqY_MzmiPXxbyYZZb83nAsj8shajnZIRMvG3IwyiEKNc67YGEM2Iwdk9GtCHwI7rE2YblZGBEbyDGmzcj2ZqKUURhGI7O5VwhyfBKv4K5QwdserjAhs0wNygDZyNLR2GE1r0G0bvlfPWDEjMLzolpVjNNmddUQCW3d3rp31l3malmEu4QzAI5rWOdrxOefHPHBD0c85zxxxx43s20GfNt6TVHwzxzhjiHbPM9UymHp1nHOigi0c5rXN5GI3R4nnymxQw79zzonMTK0RsXSxhGzPdgLiCci47CgF8TqxWFoagTrPljEjEjutEbsUIsKxnAsSrC1Chp3vsMIkVcBcEzd2ODVYhlImBhOr5mIRi3tkspYQbMq7yGy7DG2soVpItZTCwU2uHY-N7JTT2GLeyu2br-xTCPxshTT6MAwA52YC7Iv7LNndIUqVZV7LsNxhrCJY7k5mZG4pHbKLg07FC84QmDHbJec5zqGG2XV35Jkwtw56q2jdJk41LYGEdkuZfGR51s0mc5y6jEoEyXl9D2GudGpx1sEQmS1RTYexZA2SMykYiibEuOQ3yMIkW4QyKFG6x3dnbDCkYPbIFxHZpdz9jtj-oHG4MfgUrLgVeyQiKzDsYRiPY2WEe3GehClirRnOz1hBBGYIXhCr2Yc2k0kGKRMnjzolw2KvXDk81kcGra8Z5ePVKTK176v69e9-vXPn2155l9dfw9_XmORuae-tceM-2QRuF9_PV-79ffXWS3Zzj-PnxnHnjlgX2TWudDsxBp06MjhQDE6jQiuU3cwppatgEymjZqyinphhRzGGFJu4UEXYjHdYfAgtDi0bufratc-RrXA5LmvRzLq5ZGFEzrCXEKNte3WOxCJt9vbANjtfPXtLiy4u1_QzDBC3NuuOK0xlxvXB7hCusBZj4OoUTXK8e3Pt9e9qIJOMJrx559Hq2C8w2yjWF1zqDV9eIcsNxhhxA7EWXlkOp39oS5nKhsGuuKeTq92YlxL86v0QabmJ6CtNLSQoaaIm5GnZd8uEK09mlOzikEoditNDBfi3-xIhD5MMJcs-OEbuYg9sxmFKw7HFIBBhsOIh2SjdCFwuZRp8PV7Ix26H650dXlA2n24-l-v15Qlt9cdcHf35OuuuejPPOr139er68y7691zjXXn6dF7rmc3l-fv8An1kXRds1Ob-nkuCcu-Zi99Us6OmN_blffi29cx1tbLRu5fnWSwhWaJl5z0BLYbXLwKblxIYsYCx2E5T4rHcpIDlGCtJZMIUblYdmNKbuxQtsd2kgrL-K8t50_r1z7ofHMvXjzzzz42N2Gh58611rteEvrv5K-uPyvz4vie31w2YsbnWi_bvlIUkfHMUwjRGnOrhBhQ7m5eINO2Uxi_4OyJQ7jCi47sD4rCjUaxIsWMeNntnO7C_ROaI0g07C0NGDGG6bPXjXK-visQHDx1x1L19mnlbH2nV-OvOsmgbzmc335-2uOa09cHWBwe1-O_O3OvPHi88_f36mvOqXnX3zx39fHfgvjdvnl6zNMentl-LnXWta8noTrrnH58-vLg_Lz7c6vJhnwzy9_t3YXhv3nn7eO-o7Z21r3-xCM6hT7al3Oabb94Vmc310OZevFnNkx5OrK8csY1b1ywH26yGxM1YF3mZDZhkbBT0Uq4Rz4kGmOwy8ynbKNlviiNXhFetRjtdBTzNTwKlGzoOOtZCg2OaJnjnZvmM1DOc0MAlzRLvA2vjyOuExoCvJHmEKKN2jsVlNxSgIu-lgU_FQjRBNmltt0_Juhn5nxaIZ9vv9n4WJkfX6-vn4NzXGvt0_7a4d1I5zx7_nfmnbnLrjrx-k_jwR2wph4l-vsS42t4E10EsatIVrj-HPW1x3Ss_QRMTldwzq9rtxezSUw5hCis-DBCLdDBhTGMattrihhNXkew7LXk2HNnd141G24ZQs144MMXy31lEeq4y-euY82wmu_M67-zMs1d0-Pfx-c9wNraDWZ1L54jXnuz2nr9PHPHn7-_2KvVpnv1ofH5_S3bnOQ8cnE158puTUOW-fEGiideec_Uw8azk-Rj9zkh6PN6XDI36ZWc85zHjXxPYyX7c8NLOh-nfm2DtZWaJb5Nd-8cxhfP1mes5-3tu1l1p_Qv1mK7DnBmayDHYmeYkDI7mwRojs0UwTYpLjV0ENmOtsYOJs26j2yEIuchAdwZb09ZDkx3B4nflnSLOWEeOgy5lYnHOvHXMwZeTxydcsti0xncvQzm9-W3AaZqJXMdUxljGm2JbAmJtmR3Ns7FLfz1o5iS_lmFIlLXPDooYG5MM1MbMs217897iRGO3WX47-NagUUa658HvLsbzrzCdV19BjLOfWX3UhojfkOuZfoW9fXz6_aa9HnpyyMT0wyGUw2dxoy4RNy2JQDCWGYbCUiuebWm-2cVffXTOQaTQTrznflgX0ZGN83mM6vjXnjkGEtYwuaadyjFmO5DNiEBinxSnYOylGxHOyVkflgQYDV_qT9ZlJ82GS0jtewpB3PTLhTGJ2ZhR2TdDLgRhQwmWa4Yt0lFX48uWzJl5ddTOu-eMtG_fvrk1fWm7vOcmcYTWdm9Y8Zx_Hu5LKa5gzz9vWXT6DHWrJrtcv0zV7kvVvja5jTLxJl0zMlkOMsLhZL9djOe94PVOc1qXOHq1iwiYRmDWDQUaIIkVWIUPZtDcbhAgnoJu0kexuLF9GNG7fZvTDCcy34GyfN6NE1H48J3Uo-PU6bwmemrvqrvKDfk6sg_G1HDJdW7g5z9OWnUuZsTOrJx9feEMaXv1hw_fjKSDseNe3GcpDto03SA9hl7DfwNiEV9LAGih7aaGhaYSzsxzZlggw2aZpjc5GNEeCEfOGLRq5kI-ptdpzOoqJGEvniLRs03QbDDFl0bktoKaIwMIdkTcaNyhzsfJ_xMo_WIkI7G4423sUbNnIQCPw5LGhaNjOZgwdtG2ebeucUpiR5MznS5s8tGXLy7aYTi4YVxHJftwcMaYpM58-NTyhdOwZeid7mEw7GWVjRFozcVUzdjyTGrMoMCXiVmoU0dEuNy13JnMNOV1cKHrnbCcCRNTO_tTFeVgkvLyDSXCOFOwLHbJhhGXlN0fPKb7F7IjHsDQQza_QGI0lf_-mAHkBAAIBAQQFBAgHEhcMBgsAALO1AQIDBLK2BQYHCLEJCgu3DA0ODxFpsLgQFBUWGmq5EhMXGBkbHB0fIiQlKSs4OUSvHiEjJicoLC0uMDQ1Nzo7PUBDRUZKrrsgKi8xMjY8P0FCTK0zPkdISbpLT1FSVFlbX2NkrP-jAAMBpuR7QIducRi8w7mnR3IZaYJnm6m5dnULOho0UZitEJiLRjgAsN8xOpnrlKIIRmOvH_PljNm-Cvv8v_5fvj1wQxnr5-fGPLEc5MZWP9cZnn7uCGDHH34U8p7v-cNhnljy4mYeeQ0XiZnu4OsNsX6uRpouxnui0QiRouMTFzJTCYdnYsUwgFDZ2bsDQYmhms4zdOT8yQ72J8eN3Vsd6jTHcea3bpcdSNCUMIbMLtkhZmYES7Qj1axlSAwjOHPHnPOdY3xnPlOt8eeSJGeWSOuWjiK3Cx5vU2IxmUp2EhYhopcoKIUzEYWInIshGECLCijlkjEhToRLJHVKIIdBe0fec4R3zBGNO4aiaHM2w6NFyIItmNzOMOWjdzPNcELNszD1OMDFEY8QCiyPCZGCsOInl5ZgKLFmPPHl_V63TEK4mTGIQYZtk8sTM_rYxniYgMTCq59wpDNvPqsHzdBFQoYat8UUQsphuXaKcU00RUpdyZGZZmzoRbt0iQ7WmNC6EaSNiHrwQ9D2JYo2YQp3yxjdjfrkegrB2NSYjZ3HC2DrpnCZNG-aJm2AiTqZYxhxnUb5xR5iQMHDiBXCZyV1CMcRM0kwxSuqzKFYhdy5jMuhsDnsYZuN2BT0bNyx3FNixsQo1fA3dQjmg9ix6BZ6GhDkNHN1KNw1LmIWdC56HdKZmYjq2WZgZs6KlEItmLQYXApxxmIGY4ay9ckJjzIMYvmNYXyxRdxx1c-773FlCYzRCMLMUxRRoRi0mOZY1VKWm46LcuwJnVXRsmyRsGiBZYm7m6ewu9hZj0IUU7LT2Ni70IXKbhA1I3xY2LiwsaNZso3HQoxTYYxUGZYRY0jM58-vGRzHQ8_LPl1xMhS0TiDYVsTHXy6wpgQ8-K6hld-vFlbtENEpuaLFpi6GxSsU2I6tmxchSmjQUkWDqxuvsLoQ-osWN2B2LcOaxux0c07NiLF0bBfJC6wYGpoZOAzS3Ceb5BnI0XxPdQe6cJQkKXOI9ZgLLWMe6B1SJnQYGCMCEeAs54M3YakYKuIXIKmCMNCiizZ0aDQubOpCNGjRFouF3LS3CMKxWdyx0Ixp-MTvLve0Z2dGl5mxsU6MdzQY2yYeY0Ys9vDA5kcR8vLhoY3EwYxjMOsYQmGzWc9RtxiBgM2M4KGZODCg-eWEQMjyKJmzS2cRsc1jG7oR1dhdDmwsxppsaNNFC0FyEIxYxurYjyTc2Siz2vcaZ54hm2OQwsQdsmrEukTuQg0LuTMSEaKKy-SRoYUM_tM8GgxmM05MlYydeEzchA61xiAMG33wmc5nHlmNksRZhukI4bI2KEOAhRFOuMtI05zYz5pDJZzGlcUswwpxmGI0R0IR55pWENEg2yXy2dESLRCFzRbjoWbpAuQphF5Yo1Ob2tHQ1Nx71Y9GEdXRu6ELMIw2YMRF3MxI6JkgwrNzCZJkxbMQzkTHVKCYtxHBG61hutYxq5ItxCNhwWHUiDSNwcCUwzRcw0zCR3KFLm2WxsDTQ0ly7YzRu6tOp3oWYUamp8rZ6ZxFhjpmZWkeQnd5seziZgMEhYzxx7uJimAadcOI0xwwriGPOltjOKepQ4xTSwg2YwMiNO2etsQIRjZKWKZosm2IkNXTENcrYXroIRWIcUwTDWKwzLoXVgEy4QMjDIlmcQp0MWxTCkjmNNii2KLkY3IhqoMIJyIKdFGGOw8Ee0p5ENnYW7vhju6NstGM2KyOI6F8dcxjHEcFszrMDBy2YoxrDETEawDbzzfEYRaCMJiG63GkLuNSnJRHdjig0LGBCedZuRMwrOMmUrLkoaGmcZpoocMGJnVLHaEXYu3bLGNDTYiBYutiKOzY_A6HMo7WxzWmmlsdjqYNHQpaKdBzMm5bGOxi4HOVWy2xFTgMWYBfEMVmwWLZZhoi0XcWabZSBmExmmFijgIlZhCNkrFdesNW5GzsUwjZsx5t3RooooNWFLG63LByIWBC5TTB2xMsaH_E0dH1FnZ3OSR0NxjHQsXTuTBCzSWcOdnYGNi4RjYWsik4XYZ5TDYpiVmsZI2ZlKJkSiOFHUKI8B0Ejk3dWhswgxaI06FjoUXG7Zh0KDuD0A06lAMO00fgbYOjqc8DGzumCO5TsGhgCl1GEIaDYxWKWEbOBpppWOYJTCmnF2gouolNkxoENmOg6ZKGzBy1loI0TA0F0s4oAXRiESmBRELGxA1YQssBCylCQ0YRstiC7FikKNSNKFZ1NcDszFH6E-I5h2DRA6Buc89izjBqbdY47BeOvBuwgMXG62b9SGLFNmzbjGYFymKxxYsjTBF1M0zrYEu64sQp4hoMSDSWIIlIvJHFJQUciiOxd0FinY9CHM1Yt3uYHa9uYr9_Byb4zjryDJk-_jHDoEVj5f8AP355mMdf7ef9cxu4cRP69fLqmN2D_ZeOpZw3xk_tiI0Cxp8-CObmjjr5QgUUUlOgG7RQvNiwxDYdVbNs7ELkcbsXTJYjpizP_Lpm60HFzLMpRMObDM1hSDjHniKYosZIz3Vh874v7jidfLr5lOeMmZgzDzxgoJjMerMx69WyuCcE4448vLUmUFyx1Z1I8liYeeDPke5xyJ1zSQ66YuYw4TZTqCzLoRgDM8NigwcQMccNKJOp5OfcYpzcw9evBgKLsCZOizGKbY3Y2WnVWxY3aadRY3Lm7GMKayG-biRYcR0WgpwWcQIjjiMzQpYjG2Wdes4Rg4aMDmsxbFnMYUxG2JhoLhYGjd2KWGOZ2pMkMnLGWuDrDdhnGeOMcsQI9WZ42AAmIY0IDWOv9oJowjDr1HRIlnHDsGmG40XNWDCDstgpHkQpNjmWJi56nVjTqQjyEsaNijnjgcJjypsQOE6mPNoIscOax1wbZI5GYc0KZPc-b5zMwUZOoZxxx5TPnl0Mf-ZxwYp0K6nATrnOXXq8OWYmN2ZI823XLzxTjGTBriiBHYI5z54pw3WBCEyYslBPPJnL1aKMZT788UYhGxxiPVposU0w0Cy6oQLFMGmEeiwNXRp2GPZjgsRabpTY7SO6mcuTFmFzrmMzS3clceWenEfKZxRhI8Qc488RjXVrFkclEM4bN2jyAKLGouzpikIxOZjolGXkMxEoNSszFg0KQiWbkyUFsmxnHn7rMdGBBIZ0Fi-dHke5ovidZk4iWLDgnGe3AidEiLEdWNzcxqaMGxYmaCxcYbFkaKC4QNUpjFyMGJRCiZbDXBGDSVmGIwoTLDiEKI2NyIB3qNxsveUdH0IzDzcTJTHfOc6OTV4PLMIBtme7zw2Y68YsWKSyGcUMZ1hZQxGiY8_vdcZo6oo0sKQsamrAGJY1UbMcR2aWYi6NmDFYwbCGrTQ5bgbMGNOYl2OeEK4hQ5KFjihihkilOrFoszFykYwDViUuKVuwbDM7jYpGOgxGMYaEaCMOzHbkTHMZlCJrgHyKN1DMYbkIg1nOpCZpWJTBQy1ghsINzZwExOpnVjCJuXfgA2SPbksR3wupCkiO7qA2dsplIasDMzlc7MVy5VowQpizDCYnV6MerSlnOxQNEd3gaAdCFiluNCJMc8ncswlPMhk5kMWIckYpZNARiWHbJTRyGlLFGgZBhCjRgUVhxTumRw6DGht1Y3dMQhYd82InLKaO5MWLYNXJu6FOcJOKSwtOPKYGxmNzhWZhYjiBFNeGMI3aIRpaKbtGdEi7FJCxzKaNCkg07NZDI4y8yB2A1mO6OYq9cbYhC2c7OGFGIOqRjnGSJqGgTI2YXLOzCKTLsb9U1bsJhjcuWSmmiPJsUupzLpcimxFj2GjqaNNmh165LrStjr5qEG5YzoFxbIxhdsWMjHrZjMUtuuIU4Rx165MvXjG-OqGLFxJnOcBjGzhyUZOShHnhc4xHdpZxjONVgRo2zRxSNOqozjOI2MUw8piYCzQTOepkmeTOIUU7AqalFs0WDRrgho7qUUvqbHJoy3YRpowG7cxiy2IscGUiNOmCLAdjg6-7rHNsqM_rw564dcCTOSDYxMAZWnBZrFMOTMFYaXQxZIu-MsyUQ7DsLC8xxWMJuJGZyLsDCYWL0GPQhXEMOrSi2NS7OB1NSFJDkw1d099NzU1eR8Yl0dF5GxCmzOtEIxg6YuNjVzS1nVojE3SxhonGrXWxZ1BDgYRuOMi0U3UxkSLE2GA2fhBexmaxDZaIYIbLZmF7ArLo3GDTcLMQdW7s2LFnJ2FlxY5g2Y9j2Fn2NNPJh6HuetzU5u7CzqwKcEDUYWzQ2VKGEdCCwhHciURTVNCz2PRp7c8cPIWsLDkwTLMbEIEbF2C4EDXKQCG7BGEcurRFUu4uRjAhWNjJs00lF1dm7HwNVLkeRd5D3CwjsRpCI7JWESMNWmZC5BwQjBI11w8cApWIC5oKYQrEaYsdT1Yjc0NEXmj2syRzHdcYzxRduDHMOhOFg06BEykTYhmm-Ml2CZxkoyalZpIsI2KCsQTYgZjYaY3Jm6xdmYpzS94ounWFnFLdWyUzNFOdW7Gs0NgpohbCIaFupSZgwssZk0KaIExCNFMzWGFyF2MBCOo0QpGNhjqvZmzE0Lsyv4E6CK8kth5rTWbGzMDfOjWVoV0LkaHRuIRibljZ0c94bI7sbHcR3dG7oaHLPqdS6Q6JRT0IWLNEbNNMLjTSQuClgNEsFNmlpYRhotzvCPYx7iZTtYWeQjGzuNm6bEAe7GVKIaBGEYJq0YQhQU2YtNEdiuMhHkQQuxobFGpybFCRuN2CbpqbuwQsWYU6pYVsNGhRZhYLkRKadsRopoXDigsjSzrg0Ya4Wmmks7onNssOxh42x9x-wucxp_QmhDVoY0x_Mj3O7_eXQbFmiEKH6UiQgw5G7D6EjEiMLvR-ooopLkGNijY_CiDo7kKP0EbDEbH_AEaYwS7cYIw0KfwkbCOxH1nsQR2N0aPqQSJC6aFNL-VhbJYY0Uu4bHzEDMKKYJ3n5DNyFmFNhsR_IsIQaKS47lnkw-ELN2hg6P5mMLGhGjseRR8DduxaYU-x9LYSMS7ZNn85pggiMNDwaT1DdIREYMKHo2dn0kLJZCNmCNPaQ0PfKbEKGOhESHpdDtbFyzEiMHZ3O0aObybDGFCl2k1dh9LCmxMxCDBSzY9APrYQixvmEeg8xpsd5CFlpBYYsIlzm3KdnoQaYEIwKQY0nQ6N33iMWEXKCNPI7xs9jdAsNyIwdB6Nhu3OTdswGgIwsow2OjTRCnmwutgmYRVhRsmxQ6PYnIsxhYIC2Nk3B0eTG7CNlp0CMI07lkphc-I3VYRhYuwjYdG7uwLjSwpgwLsLDYjCZKIRu06kFuljcjGg5kQjTRG5sXNWFHJhcUsMIwGzRY_GwFBLsIwQuU0dD4Ckg8mFw9L8rCkuUEYQ9Du-sCzuwjGxTzDQ9RADUhoxuRPqVuWbO47vN-EAsXBsxY95qHgaMLsNmFHYU_G2Lt3QOTTyPiKObq0XKbNl995ivJIQLHofhbsTsbPefgAiPpOj8Jo2TY0UhsQ2Yanpbibuo6Nj5xuR5HMppsfIJZsQO8uUWdCn0FJsUx_wKaadEpgetp5HIuNxNWmPwMPeE1NWFs0WbNOzB7DoxpouCUhR77Y1buoUFhR1UmbPxEfQRhGPIiRg6u4alFzciwWFPJImh8DzDVpgOwkBsFHwPaWzCMGEY0JAdT2G7FYpRGFkSAlkhRo0dyagAQiXdCiNMSDBe4jdsU3bAQexSKQaQTV1ToXKYwhduU02IjBs3PSxjAi7GwNmJGw6uhHwWBEfQMSMLEOTsXCgAbFmzc5kRO8u6OjYYwffYOrqaNzVppUjEjcubJBE5u7ZhRRRFBiaFh1Niz2FFFgQphFu-DA1O8YUWCBCiJc6F3kUdGmFFxpKKGzd9KU9yWLNFDB7T8ZYdWnoju2NSmPaw0KIOo-D2jRu8yJC5Zuw7XV9BTR2JRB6OpybHQNmxzGF38hY2aORY5JyPBhCPpLuh3noaOQ0x2Ycmzu-g8GPIfSxph0O9NzwPiaNTwO47XuLtFi70bur2Pvnzmpsd7Ys3KdxeRTTdPSx2fBu9judzTq6HzB-F7HsSiNmmn3zsLm6bJyPBPeLJZ_-mj1JsfhfYfzbtjUj-ls3S5Z0TtfyNmPvn5TuaHV9f_-jAAMB9oRkhqdr9gfrx3P7y6w_Ydh-c95vmx-5pYGgL-osCtj8TnwNc0tK3PrKJgCgoKC6--6netjATGGMbZsvvLzfVmGgrFhGZ_zysCEHJiPzHcwLBGGuC73EYbljmaGIoRXTOhY-d3I5mCZcrOqxh3mIdDoau2ZmDkJjV-I7wWMIzKzEMALMHJbvxt82y5ymMFMCKRi6gG76SszLmZzRMZeswOWwYIaZdgsdpRZy1lYGMuZgUDEWgckyQ0Y8w2zDDZzOrDHVZiLStBcoPS7MCYcuZlcHVzCm6piFYLOWYI9pG7MTA5czOcw6uYVmLM0RSiJHZ5pqwmCZcxyzGZmY2bmL5oszBTyKIEYTBqsxEgdhHOJnRjMx3NCBGBjBiYFC-I0RvlysKzc73QrMIMCYxMgVno3AMzFiBMurqYrNsTJhQmTvSwXwQLuzsXzODq0ucTMYd5hjGYsdhZYWWYxlzZCzDsWN0xSr0IrC51mCMCiHe2wBAKaz3O2MpRTZae52BbIau7cznsfW-DuuuYwvj1mzZp0e0wZiuYRs-wuvewimCEyRKYR-AOxp6NAf3ngFs3I_S-DdjD5Hm-8au4fnzoXDm3X5jobsCP8AE7z_ACKabn2Nz_N5P8H-Dc3f_D_0fpD_AGaD4D-ge8eNM9H5H4X2gIU_zPlfsf8AV8cA8Yc9oFhv7X2hMKeMY974xJ_1f-D9Z6j7Xm-MS6Pzv_yanQ_xOZY_2IR-10I2fA_wRh8x6nkUNP4B_AWY6ESOj6Dm82xTEjsdzGPQ2NnuY6FHNs7Pc2NB3aY6kfpPU8jUIbnrLupcs9xYhyOT3ux6T53QjHQ9Box942NWmEfhB9JqbOpH1P0Md35H5Xm-oT2HI5nvmrDwbmp3H-Bs6Oz6333kNy5-B0PSRLuj8j8hGP72x_E2Ob-99L-J7D9z2v7X_u_E_wBxTTc8cR8Hwf8AE_8Ah-k9B3PjBPtBFF9oXih_oEVu_uYBqHjAKrTH9a6AUw3P1NzY1fjPWCsLq0v6lhdhYLH-RFaCzHY_yNG5_A_7up-g9b8r8js02f8ARsU_yIx1dH5mHvhuWOwj-V2dHm_tDkew9L-luczwdzwfqdHR5sD0PyOp2n_Bqbu5T_Bp8H53o-x7T2MO5s_pKe0In1EKKXvYbvzGh-whRu6H0nc_pdH5T6HkeBR9B8BY-tp9JH2P1J_EHd_aw_QWO4h_Rj4HsPG6fFnNH633g_8Aw_uPF6fF_f0v8in6HxlyjxvT2gJ6-Oi_zPaA9R4whd_Ye0JCX2gNYe0Dd36z2gWI_a-POf8A6fY9j4wR7QwUPtbrd1P8ind3APraNXd0frGw0nav6FuN2iilLP0uzq2bG6_qWKYsXI_kbFy7Gh_OQLOpZsXwWbHzFF3RdmIQAIB-FaN3VsoEAoCz8jYs9qL-Zsd7G7qx-Y7ykjSxbvQ9ZYTVKbELEKAuXfiOx1NmBdsfKd5chGAU5WPI_GajRbBTAp_Y2dTV_K7g2brDRT1Fj0Fw7A1In96FH_VugbnJ9TzRgwdUCADY_OXNmHNj-o0VKYw_E9pQwY6C3I_mDVjfBY_W7L9q6NHzPzsSHizPi2P80-5_0T_c_g_W_KWfwni2Pzv632gbqfyLP-z9y-Ne_Mv2vRsfxU_i_wASBH_cPWeLigr6n6mNP3K_kfS7NjV_csP2n8iGpWIel-gjloPgf_d-F0LGj_mMWO7-l_o3I8yjm_lIRfS_SMNV-lPWR3bsPkI-gd8xVhH8xZ0z_uWKfjPoSPyB8L2B7wet9bCzHVj-sGPR1NnxbX7Fhs6tzUucleR7zQesIaPge8B7z8psHe2aaLpT-QpX4WnQPff-xAbHe8yiGhDwd2xZXQ0Cg1PhfjAsfUXAPkaLvxFNgLLS5_8AZ-pufKU-w0GAAq06LRq0fuLJ87d5FnwWGj4-h_q9j9p_F-4i_Efjbv73-Zs0eMMXfuN3vfxMHtP1vg_-D978J9D_ANm59yfA_S_c2e9_E9rZ_mbn73_UpuQs_a-NQcz-42P3n_2fY3PaA8J_B0faAjz_AMHtA8d-49oCNHjkNmPjEJ_N0P5H_oePSeLu-Lsx8ec8fN-R-t8Yd8Zk_oe0BjHx0H2gIA_C2f8A1PsfxlP2Pi6HtASM9oCknpPaA07GPjDPtAQd9oHUntClM9oDXvtAph8dx-t8d99oCEHtAy4_o-0e_f-h")); + requestInfo.setBufferedImage(true); + + // Act + Response info = wsqDecoder.decode(requestInfo); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + MessageFormat.format("INFO :: WIDTH \t= {0}", info.getResponse().getImageWidth())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + MessageFormat.format("INFO :: HEIGHT \t= {0}", info.getResponse().getImageHeight())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + MessageFormat.format("INFO :: DEPTH \t= {0}", info.getResponse().getImageDepth())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + MessageFormat.format("INFO :: LOSSLESS \t= {0}", info.getResponse().getImageLossless())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + MessageFormat.format("INFO :: DPI_HORIZONTAL \t= {0}", info.getResponse().getImageDpiHorizontal())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + MessageFormat.format("INFO :: DPI_VERTICAL \t= {0}", info.getResponse().getImageDpiVertical())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + MessageFormat.format("INFO :: TYPE \t= {0}", info.getResponse().getImageType())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + MessageFormat.format("INFO :: SIZE \t= {0}", info.getResponse().getImageSize())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + MessageFormat.format("INFO :: COLORSPACE \t= {0}", info.getResponse().getImageColorSpace())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + MessageFormat.format("INFO :: ASPECT_RATIO \t= {0}", info.getResponse().getImageAspectRatio())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat + .format("INFO :: COMPRESSION_RATIO \t= {0}", info.getResponse().getImageCompressionRatio())); + + // Assert + assertEquals(0, info.getStatusCode()); + assertEquals(DecoderErrorCodes.SUCCESS.getErrorMessage(), info.getStatusMessage()); + // Add more assertions as needed + } + + // Additional test cases to cover all paths +} \ No newline at end of file diff --git a/sample/pom.xml b/sample/pom.xml index 78824c8..65c76b8 100644 --- a/sample/pom.xml +++ b/sample/pom.xml @@ -1,54 +1,132 @@ - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.0.2.RELEASE - - - - io.mosip.imagedecoder - sample-imagedecoder - jar - 0.0.1-SNAPSHOT - imagedecoder - http://maven.apache.org - - - io.mosip.imagedecoder - imagedecoder - 0.0.1-SNAPSHOT - - - org.projectlombok - lombok - 1.18.24 - compile - - - com.fasterxml.jackson.core - jackson-databind - 2.11.1 - - - com.fasterxml.jackson.core - jackson-core - 2.11.1 - + + 4.0.0 + io.mosip.imagedecoder + sample-imagedecoder + jar + 0.0.1-SNAPSHOT + imagedecoder + http://maven.apache.org + Image decoder testing sample + + UTF-8 + 21 - - + + ${java.version} + ${java.version} + 3.11.0 + 3.0.2 + 3.1.0 + 3.2.0 + 2.3 + 0.8.11 + 3.1.1 + 3.3.1 + 3.2.0 + 3.2.3 + 3.0.2 + 3.1.0 + 2.22.0 + 3.1.2 + 3.0.2 + + 1.6.7 + 3.2.5 + + + 3.0.1 + + + 1.2.1-SNAPSHOT + 1.2.1-SNAPSHOT + 1.2.1-SNAPSHOT + 0.0.1-SNAPSHOT + + + + + + io.mosip.kernel + kernel-bom + ${kernel.bom.version} + pom + import + + + + + + + io.mosip.imagedecoder + imagedecoder + ${mosip.imagedecoder.version} + + + io.mosip.kernel + kernel-core + ${kernel.core.version} + + + org.springframework.boot + + spring-boot-starter-security + + + + + + io.mosip.kernel + kernel-logger-logback + ${kernel.logger.logback.version} + + + org.slf4j + jul-to-slf4j + + + org.slf4j + jcl-over-slf4j + + + + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven.compiler.version} + + ${java.version} + + --enable-preview + + + + org.apache.maven.plugins maven-jar-plugin - 2.4 + ${maven.jar.plugin.version} true - io.mosip.imagedecoder.test.ImageDecoderApplication.class + + io.mosip.imagedecoder.test.ImageDecoderApplication.class @@ -57,7 +135,7 @@ org.apache.maven.plugins maven-dependency-plugin - 3.1.2 + ${maven.dependency.plugin.version} copy @@ -79,7 +157,7 @@ maven-resources-plugin - 3.0.1 + ${maven.resources.plugin.version} copy-resources-1 @@ -111,9 +189,9 @@ ${basedir} true - run_jp2000_decoder.bat - run_wsq_decoder.bat - + run_jp2000_decoder.bat + run_wsq_decoder.bat + @@ -122,5 +200,5 @@ - - + + \ No newline at end of file diff --git a/sample/src/main/java/io/mosip/imagedecoder/sample/ApplicationConstant.java b/sample/src/main/java/io/mosip/imagedecoder/sample/ApplicationConstant.java index d5eef97..501a643 100644 --- a/sample/src/main/java/io/mosip/imagedecoder/sample/ApplicationConstant.java +++ b/sample/src/main/java/io/mosip/imagedecoder/sample/ApplicationConstant.java @@ -12,6 +12,5 @@ public class ApplicationConstant { public static String MOSIP_BIOMETRIC_FOLDER_PATH = "io.mosip.imagedecoder.image.folder.path"; /** File Path */ - public static String MOSIP_BIOMETRIC_FILE_IMAGE = "io.mosip.imagedecoder.image.file.name"; - -} + public static String MOSIP_BIOMETRIC_FILE_IMAGE = "io.mosip.imagedecoder.image.file.name"; +} \ No newline at end of file diff --git a/sample/src/main/java/io/mosip/imagedecoder/sample/SampleImageDecoderApplication.java b/sample/src/main/java/io/mosip/imagedecoder/sample/SampleImageDecoderApplication.java index 68ce614..b2baa53 100644 --- a/sample/src/main/java/io/mosip/imagedecoder/sample/SampleImageDecoderApplication.java +++ b/sample/src/main/java/io/mosip/imagedecoder/sample/SampleImageDecoderApplication.java @@ -1,5 +1,9 @@ package io.mosip.imagedecoder.sample; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_IDTYPE; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_SESSIONID; +import static io.mosip.imagedecoder.constant.DecoderConstant.LOGGER_EMPTY; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -9,26 +13,28 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; +import java.text.MessageFormat; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import io.mosip.kernel.core.logger.spi.Logger; +import io.mosip.imagedecoder.logger.ImageDecoderLogger; import io.mosip.imagedecoder.model.DecoderRequestInfo; import io.mosip.imagedecoder.model.DecoderResponseInfo; import io.mosip.imagedecoder.model.Response; import io.mosip.imagedecoder.openjpeg.OpenJpegDecoder; +import io.mosip.imagedecoder.openjpeg.Tier2Helper; import io.mosip.imagedecoder.spi.IImageDecoderApi; import io.mosip.imagedecoder.wsq.WsqDecoder; public class SampleImageDecoderApplication { - static Logger LOGGER = LoggerFactory.getLogger(SampleImageDecoderApplication.class); + private static Logger logger = ImageDecoderLogger.getLogger(SampleImageDecoderApplication.class); public static void main(String[] args) { if (args != null && args.length >= 2) { // Argument 0 should contain // io.mosip.imagedecoder.image.type=0(jp2000)/1(wsq)" String imageType = args[0]; - LOGGER.info("main :: imageType :: Argument [0] " + imageType); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("main :: imageType :: Argument 0 :: {0}", imageType)); if (imageType.contains(ApplicationConstant.MOSIP_IMAGE_TYPE))// 0 { imageType = imageType.split("=")[1]; @@ -37,7 +43,7 @@ public static void main(String[] args) { // Argument 1 should contain // "io.mosip.imagedecoder.image.folder.path" String biometricFolderPath = args[1]; - LOGGER.info("main :: biometricFolderPath :: Argument [1] " + biometricFolderPath); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("main :: biometricFolderPath :: Argument 1 = {0}", biometricFolderPath)); if (biometricFolderPath.contains(ApplicationConstant.MOSIP_BIOMETRIC_FOLDER_PATH)) { biometricFolderPath = biometricFolderPath.split("=")[1]; } @@ -56,8 +62,10 @@ public static void main(String[] args) { } public static void decodeJPEG2000(String biometricFolderPath, String fileExtension) { - LOGGER.info("decodeJPEG2000 :: Started :: inputImageType :: JPEG2000 :: biometricFolderPath :: " - + biometricFolderPath + " :: fileExtension :: " + fileExtension); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + MessageFormat.format("decodeJPEG2000 :: Started :: inputImageType :: JPEG2000 :: biometricFolderPath ::{0} :: fileExtension :: {1}", + biometricFolderPath, fileExtension)); + FileOutputStream tmpOutputStream = null; try { IImageDecoderApi decoder = null; @@ -67,14 +75,13 @@ public static void decodeJPEG2000(String biometricFolderPath, String fileExtensi try { files = findFiles(Paths.get(dirName), fileExtension); } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "decodeJPEG2000 :: Error ", e); } for (String fileName : files) { File initialFile = new File(fileName); if (initialFile.exists()) { - LOGGER.info("decodeJPEG2000 :: fileName ::" + fileName); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("decodeJPEG2000 :: fileName ::{0}", fileName)); try { DecoderRequestInfo requestInfo = new DecoderRequestInfo(); byte[] imageData = Files.readAllBytes(Paths.get(fileName)); @@ -86,30 +93,28 @@ public static void decodeJPEG2000(String biometricFolderPath, String fileExtensi long startTimeOneFile = System.currentTimeMillis(); Response info = decoder.decode(requestInfo); long endTimeOneFile = System.currentTimeMillis(); - System.out.println( - "Time Taken for one file : " + (endTimeOneFile - startTimeOneFile) + " milliseconds"); - - LOGGER.info("INFO :: WIDTH \t= " + info.getResponse().getImageWidth()); - LOGGER.info("INFO :: HEIGHT\t=" + info.getResponse().getImageHeight()); - LOGGER.info("INFO :: DEPTH \t=" + info.getResponse().getImageDepth()); - LOGGER.info("INFO :: LOSSLESS \t=" + info.getResponse().getImageLossless()); - LOGGER.info("INFO :: DPI_HORIZONTAL \t=" + info.getResponse().getImageDpiHorizontal()); - LOGGER.info("INFO :: DPI_VERTICAL \t=" + info.getResponse().getImageDpiVertical()); - LOGGER.info("INFO :: TYPE \t=" + info.getResponse().getImageType()); - LOGGER.info("INFO :: SIZE \t=" + info.getResponse().getImageSize()); - LOGGER.info("INFO :: COLORSPACE\t=" + info.getResponse().getImageColorSpace()); - LOGGER.info("INFO :: ASPECT_RATIO\t=" + info.getResponse().getImageAspectRatio()); - LOGGER.info("INFO :: COMPRESSION_RATIO\t=" + info.getResponse().getImageCompressionRatio()); - + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("Time Taken for one file : {0} in milliseconds", (endTimeOneFile - startTimeOneFile))); + + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: WIDTH \t= {0}", info.getResponse().getImageWidth())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: HEIGHT \t= {0}", info.getResponse().getImageHeight())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: DEPTH \t= {0}", info.getResponse().getImageDepth())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: LOSSLESS \t= {0}", info.getResponse().getImageLossless())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: DPI_HORIZONTAL \t= {0}", info.getResponse().getImageDpiHorizontal())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: DPI_VERTICAL \t= {0}", info.getResponse().getImageDpiVertical())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: TYPE \t= {0}", info.getResponse().getImageType())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: SIZE \t= {0}", info.getResponse().getImageSize())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: COLORSPACE \t= {0}", info.getResponse().getImageColorSpace())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: ASPECT_RATIO \t= {0}", info.getResponse().getImageAspectRatio())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: COMPRESSION_RATIO \t= {0}", info.getResponse().getImageCompressionRatio())); } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "decodeJPEG2000 :: Error ", e); } - LOGGER.info("==============================================================================="); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE,LOGGER_EMPTY, + "==============================================================================="); } } } catch (Exception ex) { - LOGGER.info("decodeJPEG2000 :: Error ", ex); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "decodeJPEG2000 :: Error ", ex); } finally { try { if (tmpOutputStream != null) @@ -117,12 +122,14 @@ public static void decodeJPEG2000(String biometricFolderPath, String fileExtensi } catch (Exception ex) { } } - LOGGER.info("decodeJPEG2000 :: Ended :: "); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "decodeJPEG2000 :: Ended :: "); } public static void decodeWSQ2000(String biometricFolderPath, String fileExtension) { - LOGGER.info("decodeWSQ2000 :: Started :: inputImageType :: WSQ :: biometricFolderPath :: " + biometricFolderPath - + " :: fileExtension :: " + fileExtension); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, + MessageFormat.format("decodeJPEG2000 :: Started :: inputImageType :: WSQ :: biometricFolderPath ::{0} :: fileExtension :: {1}", + biometricFolderPath, fileExtension)); + FileOutputStream tmpOutputStream = null; try { IImageDecoderApi decoder = null; @@ -132,14 +139,13 @@ public static void decodeWSQ2000(String biometricFolderPath, String fileExtensio try { files = findFiles(Paths.get(dirName), fileExtension); } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "decodeWSQ2000 :: Error ", e); } for (String fileName : files) { File initialFile = new File(fileName); if (initialFile.exists()) { - LOGGER.info("decodeWSQ2000 :: fileName ::" + fileName); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("decodeWSQ :: fileName ::{0}", fileName)); try { DecoderRequestInfo requestInfo = new DecoderRequestInfo(); byte[] imageData = Files.readAllBytes(Paths.get(fileName)); @@ -150,30 +156,28 @@ public static void decodeWSQ2000(String biometricFolderPath, String fileExtensio long startTimeOneFile = System.currentTimeMillis(); Response info = decoder.decode(requestInfo); long endTimeOneFile = System.currentTimeMillis(); - System.out.println( - "Time Taken for one file : " + (endTimeOneFile - startTimeOneFile) + " milliseconds"); - - LOGGER.info("INFO :: WIDTH \t= " + info.getResponse().getImageWidth()); - LOGGER.info("INFO :: HEIGHT\t=" + info.getResponse().getImageHeight()); - LOGGER.info("INFO :: DEPTH \t=" + info.getResponse().getImageDepth()); - LOGGER.info("INFO :: LOSSLESS \t=" + info.getResponse().getImageLossless()); - LOGGER.info("INFO :: DPI_HORIZONTAL \t=" + info.getResponse().getImageDpiHorizontal()); - LOGGER.info("INFO :: DPI_VERTICAL \t=" + info.getResponse().getImageDpiVertical()); - LOGGER.info("INFO :: BIT_RATE \t=" + info.getResponse().getImageBitRate()); - LOGGER.info("INFO :: TYPE \t=" + info.getResponse().getImageType()); - LOGGER.info("INFO :: SIZE \t=" + info.getResponse().getImageSize()); - LOGGER.info("INFO :: COLORSPACE\t=" + info.getResponse().getImageColorSpace()); - LOGGER.info("INFO :: ASPECT_RATIO\t=" + info.getResponse().getImageAspectRatio()); - LOGGER.info("INFO :: COMPRESSION_RATIO\t=" + info.getResponse().getImageCompressionRatio()); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("Time Taken for one file : {0} in milliseconds", (endTimeOneFile - startTimeOneFile))); + + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: WIDTH \t= {0}", info.getResponse().getImageWidth())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: HEIGHT \t= {0}", info.getResponse().getImageHeight())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: DEPTH \t= {0}", info.getResponse().getImageDepth())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: LOSSLESS \t= {0}", info.getResponse().getImageLossless())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: DPI_HORIZONTAL \t= {0}", info.getResponse().getImageDpiHorizontal())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: DPI_VERTICAL \t= {0}", info.getResponse().getImageDpiVertical())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: TYPE \t= {0}", info.getResponse().getImageType())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: SIZE \t= {0}", info.getResponse().getImageSize())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: COLORSPACE \t= {0}", info.getResponse().getImageColorSpace())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: ASPECT_RATIO \t= {0}", info.getResponse().getImageAspectRatio())); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, MessageFormat.format("INFO :: COMPRESSION_RATIO \t= {0}", info.getResponse().getImageCompressionRatio())); } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY,"decodeWSQ2000 :: Error ", e); } - LOGGER.info("==============================================================================="); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE,LOGGER_EMPTY, + "==============================================================================="); } } } catch (Exception ex) { - LOGGER.info("decodeWSQ2000 :: Error ", ex); + logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "decodeWSQ2000 :: Error ", ex); } finally { try { if (tmpOutputStream != null) @@ -181,11 +185,10 @@ public static void decodeWSQ2000(String biometricFolderPath, String fileExtensio } catch (Exception ex) { } } - LOGGER.info("decodeWSQ2000 :: Ended :: "); + logger.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_EMPTY, "decodeWSQ2000 :: Ended :: "); } public static List findFiles(Path path, String fileExtension) throws IOException { - if (!Files.isDirectory(path)) { throw new IllegalArgumentException("Path must be a directory!"); } @@ -204,4 +207,4 @@ public static List findFiles(Path path, String fileExtension) throws IOE return result; } -} +} \ No newline at end of file