From 2182410c2ba39be9d20c5e28c0a8abf710ef304a Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Mon, 24 Oct 2022 17:04:23 +0900 Subject: [PATCH 1/9] update github ci settings --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/maven.yml | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index bdb90d2..2ed952f 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -38,7 +38,7 @@ jobs: # If this run was triggered by a pull request event, then checkout # the head of the pull request instead of the merge commit. - - run: git checkout HEAD^2 + - run: git checkout HEAD if: ${{ github.event_name == 'pull_request' }} # Initializes the CodeQL tools for scanning. diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 9ac0247..8c1bae7 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -8,11 +8,13 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v2 - name: Set up JDK 1.8 - uses: actions/setup-java@v1 + uses: actions/setup-java@v2 with: - java-version: 1.8 + java-version: '8' + distribution: 'adopt' + cache: maven - name: Build with Maven run: | mvn -B package --file pom.xml From 53a09c7e5add83a2efecf05e85fbae1050a65a41 Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Mon, 24 Oct 2022 17:17:20 +0900 Subject: [PATCH 2/9] update dependencies --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 10820b6..e5fe932 100644 --- a/pom.xml +++ b/pom.xml @@ -53,7 +53,7 @@ org.junit junit-bom - 5.8.2 + 5.9.0 pom import @@ -86,7 +86,7 @@ com.github.umjammer vavi-commons - 1.1.6 + 1.1.7 test From 58308f2e16fb9b9f0278b53e61e5ae275e9e7e37 Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Tue, 15 Nov 2022 14:42:39 +0900 Subject: [PATCH 3/9] update github ci settings --- .github/workflows/codeql-analysis.yml | 17 ++++------------- .github/workflows/maven.yml | 26 ++++++++++++++++---------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 2ed952f..215f656 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -30,20 +30,11 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 - with: - # We must fetch at least the immediate parents so that if this is - # a pull request then we can checkout the head. - fetch-depth: 2 - - # If this run was triggered by a pull request event, then checkout - # the head of the pull request instead of the merge commit. - - run: git checkout HEAD - if: ${{ github.event_name == 'pull_request' }} + uses: actions/checkout@v3 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v1 + uses: github/codeql-action/init@v2 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -54,7 +45,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v1 + uses: github/codeql-action/autobuild@v2 # ℹ️ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -68,4 +59,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 8c1bae7..20ed204 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -8,13 +8,19 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v2 - with: - java-version: '8' - distribution: 'adopt' - cache: maven - - name: Build with Maven - run: | - mvn -B package --file pom.xml + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Check w/o SNAPSHOT when "bump version" + if: ${{ contains(github.event.head_commit.message, 'bump version') }} + run: grep "" pom.xml | head -1 | grep -v SNAPSHOT + + - name: Set up JDK 8 + uses: actions/setup-java@v3 + with: + java-version: '8' + distribution: 'temurin' + cache: maven + + - name: Build with Maven + run: mvn -B package --file pom.xml From b2759d7e2697124c5b170a78ebafda0f875d4dbd Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Tue, 15 Nov 2022 14:42:51 +0900 Subject: [PATCH 4/9] update dependencies --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index e5fe932..873ecc6 100644 --- a/pom.xml +++ b/pom.xml @@ -53,7 +53,7 @@ org.junit junit-bom - 5.9.0 + 5.9.1 pom import @@ -86,7 +86,7 @@ com.github.umjammer vavi-commons - 1.1.7 + 1.1.8 test From 14f710ed28aab7f7f4b501ee26e2c7a39631da79 Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Thu, 7 Mar 2024 02:28:14 +0900 Subject: [PATCH 5/9] follow ide advices --- .../imageio/WebPImageReader.java | 21 ++- .../imageio/WebPImageReaderSpi.java | 6 +- .../javavp8decoder/imageio/WebPMetadata.java | 36 +++--- .../imageio/WebPMetadataFormat.java | 32 ++--- .../vp8Decoder/BoolDecoder.java | 32 ++--- .../sf/javavp8decoder/vp8Decoder/DeltaQ.java | 29 +++-- .../sf/javavp8decoder/vp8Decoder/Globals.java | 104 +++++++-------- .../sf/javavp8decoder/vp8Decoder/IDCT.java | 29 +++-- .../javavp8decoder/vp8Decoder/LoopFilter.java | 29 +++-- .../javavp8decoder/vp8Decoder/MacroBlock.java | 79 ++++++------ .../sf/javavp8decoder/vp8Decoder/Segment.java | 31 ++--- .../vp8Decoder/SegmentQuant.java | 31 ++--- .../vp8Decoder/SegmentQuants.java | 29 +++-- .../javavp8decoder/vp8Decoder/SubBlock.java | 41 +++--- .../javavp8decoder/vp8Decoder/VP8Decoder.java | 37 +++--- .../javavp8decoder/vp8Decoder/VP8Frame.java | 85 ++++++------ src/test/java/IVF.java | 40 +++--- src/test/java/{Test1.java => TestCase.java} | 20 +-- .../sf/javavp8decoder/tools/WebPViewer.java | 73 +++++++---- .../net/sf/javavp8decoder/tools/dwebp.java | 57 ++++---- .../sf/javavp8decoder/tools/plugintest.java | 40 +++--- .../tools/vp8inspector/IVFFile.java | 27 +++- .../tools/vp8inspector/Utils.java | 26 +++- .../tools/vp8inspector/VP8Inspector.java | 122 +++++++++++------- 24 files changed, 579 insertions(+), 477 deletions(-) rename src/test/java/{Test1.java => TestCase.java} (86%) diff --git a/src/main/java/net/sf/javavp8decoder/imageio/WebPImageReader.java b/src/main/java/net/sf/javavp8decoder/imageio/WebPImageReader.java index 298b2c0..fad8724 100644 --- a/src/main/java/net/sf/javavp8decoder/imageio/WebPImageReader.java +++ b/src/main/java/net/sf/javavp8decoder/imageio/WebPImageReader.java @@ -75,18 +75,20 @@ private void _setInput(Object input) { } } - private void checkIndex(int imageIndex) { + private static void checkIndex(int imageIndex) { if (imageIndex != 0) { throw new IndexOutOfBoundsException("bad index"); } } + @Override public int getHeight(int imageIndex) throws IIOException { checkIndex(imageIndex); readHeader(); return height; } + @Override public IIOMetadata getImageMetadata(int imageIndex) throws IIOException { if (imageIndex != 0) { throw new IndexOutOfBoundsException("imageIndex != 0!"); @@ -95,6 +97,7 @@ public IIOMetadata getImageMetadata(int imageIndex) throws IIOException { return metadata; } + @Override public Iterator getImageTypes(int imageIndex) throws IIOException { checkIndex(imageIndex); readHeader(); @@ -114,30 +117,37 @@ public Iterator getImageTypes(int imageIndex) throws IIOExce return l.iterator(); } + @Override public int getNumImages(boolean allowSearch) throws IIOException { return 1; // format can only encode a single image } + @Override public IIOMetadata getStreamMetadata() throws IIOException { return null; } + @Override public int getWidth(int imageIndex) throws IIOException { checkIndex(imageIndex); // must throw an exception if != 0 readHeader(); return width; } + @Override public void imageComplete(ImageReader source) { } + @Override public void imageProgress(ImageReader source, float percentageDone) { processImageProgress(percentageDone); } + @Override public void imageStarted(ImageReader source, int imageIndex) { } + @Override public BufferedImage read(int imageIndex, ImageReadParam param) throws IIOException { super.processImageStarted(0); readMetadata(); // Stream is positioned at start of image data @@ -153,6 +163,7 @@ public BufferedImage read(int imageIndex, ImageReadParam param) throws IIOExcept return dst; } + @Override public void readAborted(ImageReader source) { } @@ -234,34 +245,42 @@ public void readMetadata() throws IIOException { this.metadata = new WebPMetadata(); } + @Override public void sequenceComplete(ImageReader source) { } + @Override public void sequenceStarted(ImageReader source, int minIndex) { } + @Override public void setInput(Object input) { super.setInput(input); _setInput(input); } + @Override public void setInput(Object input, boolean isStreamable) { super.setInput(input, isStreamable); _setInput(input); } + @Override public void setInput(Object input, boolean seekForwardOnly, boolean ignoreMetadata) { super.setInput(input, seekForwardOnly, ignoreMetadata); _setInput(input); } + @Override public void thumbnailComplete(ImageReader source) { } + @Override public void thumbnailProgress(ImageReader source, float percentageDone) { } + @Override public void thumbnailStarted(ImageReader source, int imageIndex, int thumbnailIndex) { } } diff --git a/src/main/java/net/sf/javavp8decoder/imageio/WebPImageReaderSpi.java b/src/main/java/net/sf/javavp8decoder/imageio/WebPImageReaderSpi.java index 1810b6d..4a4179d 100644 --- a/src/main/java/net/sf/javavp8decoder/imageio/WebPImageReaderSpi.java +++ b/src/main/java/net/sf/javavp8decoder/imageio/WebPImageReaderSpi.java @@ -75,12 +75,12 @@ public WebPImageReaderSpi() { extraImageMetadataFormatClassNames); } + @Override public boolean canDecodeInput(Object input) { - if (!(input instanceof ImageInputStream)) { + if (!(input instanceof ImageInputStream stream)) { return false; } - ImageInputStream stream = (ImageInputStream) input; byte[] b = new byte[8]; try { stream.mark(); @@ -93,10 +93,12 @@ public boolean canDecodeInput(Object input) { return (b[0] == (byte) 'R' && b[1] == (byte) 'I' && b[2] == (byte) 'F' && b[3] == (byte) 'F'); } + @Override public ImageReader createReaderInstance(Object extension) { return new WebPImageReader(this); } + @Override public String getDescription(Locale locale) { // Localize as appropriate return "Description goes here"; diff --git a/src/main/java/net/sf/javavp8decoder/imageio/WebPMetadata.java b/src/main/java/net/sf/javavp8decoder/imageio/WebPMetadata.java index 98d506f..be1daa5 100644 --- a/src/main/java/net/sf/javavp8decoder/imageio/WebPMetadata.java +++ b/src/main/java/net/sf/javavp8decoder/imageio/WebPMetadata.java @@ -1,17 +1,18 @@ -/* This file is part of javavp8decoder. - - javavp8decoder is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - javavp8decoder is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with javavp8decoder. If not, see . +/* + * This file is part of javavp8decoder. + * + * javavp8decoder is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * javavp8decoder is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with javavp8decoder. If not, see . */ package net.sf.javavp8decoder.imageio; @@ -54,10 +55,11 @@ public WebPMetadata() { extraMetadataFormatClassNames); } - private void fatal(Node node, String reason) throws IIOInvalidTreeException { + private static void fatal(Node node, String reason) throws IIOInvalidTreeException { throw new IIOInvalidTreeException(reason, node); } + @Override public Node getAsTree(String formatName) { if (!formatName.equals(nativeMetadataFormatName)) { throw new IllegalArgumentException("Bad format name!"); @@ -79,6 +81,7 @@ public Node getAsTree(String formatName) { return root; } + @Override public IIOMetadataFormat getMetadataFormat(String formatName) { if (!formatName.equals(nativeMetadataFormatName)) { throw new IllegalArgumentException("Bad format name!"); @@ -86,10 +89,12 @@ public IIOMetadataFormat getMetadataFormat(String formatName) { return WebPMetadataFormat.getDefaultInstance(); } + @Override public boolean isReadOnly() { return false; } + @Override public void mergeTree(String formatName, Node root) throws IIOInvalidTreeException { if (!formatName.equals(nativeMetadataFormatName)) { throw new IllegalArgumentException("Bad format name!"); @@ -120,6 +125,7 @@ public void mergeTree(String formatName, Node root) throws IIOInvalidTreeExcepti } } + @Override public void reset() { this.keywords = new ArrayList<>(); this.values = new ArrayList<>(); diff --git a/src/main/java/net/sf/javavp8decoder/imageio/WebPMetadataFormat.java b/src/main/java/net/sf/javavp8decoder/imageio/WebPMetadataFormat.java index dbf42cf..f501887 100644 --- a/src/main/java/net/sf/javavp8decoder/imageio/WebPMetadataFormat.java +++ b/src/main/java/net/sf/javavp8decoder/imageio/WebPMetadataFormat.java @@ -1,17 +1,18 @@ -/* This file is part of javavp8decoder. - - javavp8decoder is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - javavp8decoder is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with javavp8decoder. If not, see . +/* + * This file is part of javavp8decoder. + * + * javavp8decoder is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * javavp8decoder is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with javavp8decoder. If not, see . */ package net.sf.javavp8decoder.imageio; @@ -23,7 +24,7 @@ public class WebPMetadataFormat extends IIOMetadataFormatImpl { /** Create a single instance of this class (singleton pattern) */ - private static WebPMetadataFormat defaultInstance = new WebPMetadataFormat(); + private static final WebPMetadataFormat defaultInstance = new WebPMetadataFormat(); /** Return the singleton instance */ public static WebPMetadataFormat getDefaultInstance() { @@ -48,6 +49,7 @@ private WebPMetadataFormat() { } /** Check for legal element name */ + @Override public boolean canNodeAppear(String elementName, ImageTypeSpecifier imageType) { return elementName.equals("KeywordValuePair"); } diff --git a/src/main/java/net/sf/javavp8decoder/vp8Decoder/BoolDecoder.java b/src/main/java/net/sf/javavp8decoder/vp8Decoder/BoolDecoder.java index 8700478..1358a4e 100644 --- a/src/main/java/net/sf/javavp8decoder/vp8Decoder/BoolDecoder.java +++ b/src/main/java/net/sf/javavp8decoder/vp8Decoder/BoolDecoder.java @@ -1,17 +1,18 @@ -/* This file is part of javavp8decoder. - - javavp8decoder is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - javavp8decoder is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with javavp8decoder. If not, see . +/* + * This file is part of javavp8decoder. + * + * javavp8decoder is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * javavp8decoder is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with javavp8decoder. If not, see . */ package net.sf.javavp8decoder.vp8Decoder; @@ -25,7 +26,7 @@ public class BoolDecoder { /** # of bits shifted out of value, at most 7 */ int bit_count; - ImageInputStream data; + final ImageInputStream data; /** pointer to next compressed data byte */ private long offset; @@ -145,5 +146,4 @@ public void seek() throws IOException { public String toString() { return "bc: " + value; } - } diff --git a/src/main/java/net/sf/javavp8decoder/vp8Decoder/DeltaQ.java b/src/main/java/net/sf/javavp8decoder/vp8Decoder/DeltaQ.java index d187b0f..e0b8a89 100644 --- a/src/main/java/net/sf/javavp8decoder/vp8Decoder/DeltaQ.java +++ b/src/main/java/net/sf/javavp8decoder/vp8Decoder/DeltaQ.java @@ -1,17 +1,18 @@ -/* This file is part of javavp8decoder. - - javavp8decoder is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - javavp8decoder is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with javavp8decoder. If not, see . +/* + * This file is part of javavp8decoder. + * + * javavp8decoder is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * javavp8decoder is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with javavp8decoder. If not, see . */ package net.sf.javavp8decoder.vp8Decoder; diff --git a/src/main/java/net/sf/javavp8decoder/vp8Decoder/Globals.java b/src/main/java/net/sf/javavp8decoder/vp8Decoder/Globals.java index 574fee9..ec3195b 100644 --- a/src/main/java/net/sf/javavp8decoder/vp8Decoder/Globals.java +++ b/src/main/java/net/sf/javavp8decoder/vp8Decoder/Globals.java @@ -1,17 +1,18 @@ -/* This file is part of javavp8decoder. - - javavp8decoder is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - javavp8decoder is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with javavp8decoder. If not, see . +/* + * This file is part of javavp8decoder. + * + * javavp8decoder is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * javavp8decoder is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with javavp8decoder. If not, see . */ package net.sf.javavp8decoder.vp8Decoder; @@ -34,19 +35,14 @@ public class Globals { * predicted */ public static String getModeAsString(int mode) { - switch (mode) { - case DC_PRED: - return "DC_PRED"; - case V_PRED: - return "V_PRED"; - case H_PRED: - return "H_PRED"; - case TM_PRED: - return "TM_PRED"; - case B_PRED: - return "B_PRED"; - } - return "not found"; + return switch (mode) { + case DC_PRED -> "DC_PRED"; + case V_PRED -> "V_PRED"; + case H_PRED -> "H_PRED"; + case TM_PRED -> "TM_PRED"; + case B_PRED -> "B_PRED"; + default -> "not found"; + }; } /* intra_bmode */ @@ -76,42 +72,32 @@ public static String getModeAsString(int mode) { public static final int B_HU_PRED = 9; /* ENE (horizontal up) "" */ public static String getSubBlockModeAsString(int mode) { - switch (mode) { - case B_DC_PRED: - return "B_DC_PRED"; - case B_TM_PRED: - return "B_TM_PRED"; - case B_VE_PRED: - return "B_VE_PRED"; - case B_HE_PRED: - return "B_HE_PRED"; - case B_LD_PRED: - return "B_LD_PRED"; - case B_RD_PRED: - return "B_RD_PRED"; - case B_VR_PRED: - return "B_VR_PRED"; - case B_VL_PRED: - return "B_VL_PRED"; - case B_HD_PRED: - return "B_HD_PRED"; - case B_HU_PRED: - return "B_HU_PRED"; - } - return "not found"; + return switch (mode) { + case B_DC_PRED -> "B_DC_PRED"; + case B_TM_PRED -> "B_TM_PRED"; + case B_VE_PRED -> "B_VE_PRED"; + case B_HE_PRED -> "B_HE_PRED"; + case B_LD_PRED -> "B_LD_PRED"; + case B_RD_PRED -> "B_RD_PRED"; + case B_VR_PRED -> "B_VR_PRED"; + case B_VL_PRED -> "B_VL_PRED"; + case B_HD_PRED -> "B_HD_PRED"; + case B_HU_PRED -> "B_HU_PRED"; + default -> "not found"; + }; } public static final int MAX_MB_SEGMENTS = 4; public static final int MB_LVL_MAX = 2; - public static int[] vp8MacroBlockFeatureDataBits = { + public static final int[] vp8MacroBlockFeatureDataBits = { 7, 6 }; public static final int MB_FEATURE_TREE_PROBS = 3; - public static int[] macroBlockSegmentTree = { + public static final int[] macroBlockSegmentTree = { 2, 4, /* root: "0", "1" subtrees */ -0, -1, @@ -120,11 +106,11 @@ public static String getSubBlockModeAsString(int mode) { /* "10" = 2nd value, "11" = 3rd value */ }; - public static int[] vp8KeyFrameYModeTree = { + public static final int[] vp8KeyFrameYModeTree = { -B_PRED, 2, 4, 6, -DC_PRED, -V_PRED, -H_PRED, -TM_PRED }; - public static int[] vp8SubBlockModeTree = { + public static final int[] vp8SubBlockModeTree = { -B_DC_PRED, 2, /* B_DC_PRED = * "0" */ -B_TM_PRED, 4, /* B_TM_PRED = "10" */ @@ -136,23 +122,23 @@ public static String getSubBlockModeAsString(int mode) { -B_HD_PRED, -B_HU_PRED /* HD = "11111110", HU = "11111111" */ }; - public static int[] vp8KeyFrameYModeProb = { + public static final int[] vp8KeyFrameYModeProb = { 145, 156, 163, 128 }; // uv - public static int[] vp8UVModeTree = { + public static final int[] vp8UVModeTree = { -DC_PRED, 2, /* root: DC_PRED = "0", * "1" subtree */ -V_PRED, 4, /* "1" subtree: V_PRED = "10", "11" subtree */ -H_PRED, -TM_PRED /* "11" subtree: H_PRED = "110", TM_PRED = "111" */ }; - public static int[] vp8KeyFrameUVModeProb = { + public static final int[] vp8KeyFrameUVModeProb = { 142, 114, 183 }; - public static int[][][] vp8KeyFrameSubBlockModeProb = { + public static final int[][][] vp8KeyFrameSubBlockModeProb = { { { 231, 120, 48, 89, 115, 113, 120, 152, 112 @@ -376,7 +362,7 @@ public static String getSubBlockModeAsString(int mode) { } }; - static int[][][][] vp8CoefUpdateProbs = new int[][][][] { + static final int[][][][] vp8CoefUpdateProbs = new int[][][][] { { { { diff --git a/src/main/java/net/sf/javavp8decoder/vp8Decoder/IDCT.java b/src/main/java/net/sf/javavp8decoder/vp8Decoder/IDCT.java index 7ee36a2..a6828a8 100644 --- a/src/main/java/net/sf/javavp8decoder/vp8Decoder/IDCT.java +++ b/src/main/java/net/sf/javavp8decoder/vp8Decoder/IDCT.java @@ -1,17 +1,18 @@ -/* This file is part of javavp8decoder. - - javavp8decoder is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - javavp8decoder is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with javavp8decoder. If not, see . +/* + * This file is part of javavp8decoder. + * + * javavp8decoder is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * javavp8decoder is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with javavp8decoder. If not, see . */ package net.sf.javavp8decoder.vp8Decoder; diff --git a/src/main/java/net/sf/javavp8decoder/vp8Decoder/LoopFilter.java b/src/main/java/net/sf/javavp8decoder/vp8Decoder/LoopFilter.java index 4f320fd..f37b2ad 100644 --- a/src/main/java/net/sf/javavp8decoder/vp8Decoder/LoopFilter.java +++ b/src/main/java/net/sf/javavp8decoder/vp8Decoder/LoopFilter.java @@ -1,17 +1,18 @@ -/* This file is part of javavp8decoder. - - javavp8decoder is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - javavp8decoder is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with javavp8decoder. If not, see . +/* + * This file is part of javavp8decoder. + * + * javavp8decoder is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * javavp8decoder is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with javavp8decoder. If not, see . */ package net.sf.javavp8decoder.vp8Decoder; diff --git a/src/main/java/net/sf/javavp8decoder/vp8Decoder/MacroBlock.java b/src/main/java/net/sf/javavp8decoder/vp8Decoder/MacroBlock.java index 1433247..19ec950 100644 --- a/src/main/java/net/sf/javavp8decoder/vp8Decoder/MacroBlock.java +++ b/src/main/java/net/sf/javavp8decoder/vp8Decoder/MacroBlock.java @@ -1,17 +1,18 @@ -/* This file is part of javavp8decoder. - - javavp8decoder is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - javavp8decoder is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with javavp8decoder. If not, see . +/* + * This file is part of javavp8decoder. + * + * javavp8decoder is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * javavp8decoder is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with javavp8decoder. If not, see . */ package net.sf.javavp8decoder.vp8Decoder; @@ -34,21 +35,22 @@ public class MacroBlock { private boolean skipInnerLoopFilter; - SubBlock[][] uSubBlocks; + final SubBlock[][] uSubBlocks; private int uVFilterLevel; private int uvMode; - SubBlock[][] vSubBlocks; + final SubBlock[][] vSubBlocks; - private int x, y; + private final int x; + private final int y; - SubBlock y2SubBlock; + final SubBlock y2SubBlock; private int yMode; - SubBlock[][] ySubBlocks; + final SubBlock[][] ySubBlocks; MacroBlock(int x, int y, boolean keepDebugInfo) { this.x = x - 1; @@ -288,18 +290,12 @@ public int getSkipCoeff() { } public SubBlock getSubBlock(SubBlock.PLANE plane, int i, int j) { - switch (plane) { - case Y1: - return getYSubBlock(i, j); - case U: - return getUSubBlock(i, j); - - case V: - return getVSubBlock(i, j); - case Y2: - return getY2SubBlock(); - } - return null; + return switch (plane) { + case Y1 -> getYSubBlock(i, j); + case U -> getUSubBlock(i, j); + case V -> getVSubBlock(i, j); + case Y2 -> getY2SubBlock(); + }; } public int getSubblockX(SubBlock sb) { @@ -398,7 +394,7 @@ public void predictUV(VP8Frame frame) { MacroBlock leftMb = frame.getMacroBlock(x - 1, y); switch (this.uvMode) { - case Globals.DC_PRED: + case Globals.DC_PRED: { logger.finer("UV DC_PRED"); boolean up_available = false; @@ -466,7 +462,8 @@ public void predictUV(VP8Frame frame) { } break; - case Globals.V_PRED: + } + case Globals.V_PRED: { logger.finer("UV V_PRED"); SubBlock[] aboveUSb = new SubBlock[2]; @@ -492,8 +489,8 @@ public void predictUV(VP8Frame frame) { } break; - - case Globals.H_PRED: + } + case Globals.H_PRED: { logger.finer("UV H_PRED"); SubBlock[] leftUSb = new SubBlock[2]; @@ -519,7 +516,8 @@ public void predictUV(VP8Frame frame) { } break; - case Globals.TM_PRED: + } + case Globals.TM_PRED: { // TODO: logger.finer("UV TM_PRED MB"); MacroBlock ALMb = frame.getMacroBlock(x - 1, y - 1); @@ -528,10 +526,10 @@ public void predictUV(VP8Frame frame) { SubBlock ALVSb = ALMb.getVSubBlock(1, 1); int alv = ALVSb.getDest()[3][3]; - aboveUSb = new SubBlock[2]; - leftUSb = new SubBlock[2]; - aboveVSb = new SubBlock[2]; - leftVSb = new SubBlock[2]; + SubBlock[] aboveUSb = new SubBlock[2]; + SubBlock[] leftUSb = new SubBlock[2]; + SubBlock[] aboveVSb = new SubBlock[2]; + SubBlock[] leftVSb = new SubBlock[2]; for (int x = 0; x < 2; x++) { aboveUSb[x] = aboveMb.getUSubBlock(x, 1); leftUSb[x] = leftMb.getUSubBlock(1, x); @@ -559,6 +557,7 @@ public void predictUV(VP8Frame frame) { } break; + } default: System.out.println("TODO predict_mb_uv: " + this.yMode); System.exit(0); diff --git a/src/main/java/net/sf/javavp8decoder/vp8Decoder/Segment.java b/src/main/java/net/sf/javavp8decoder/vp8Decoder/Segment.java index b5a32f2..6b4a69c 100644 --- a/src/main/java/net/sf/javavp8decoder/vp8Decoder/Segment.java +++ b/src/main/java/net/sf/javavp8decoder/vp8Decoder/Segment.java @@ -1,17 +1,18 @@ -/* This file is part of javavp8decoder. - - javavp8decoder is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - javavp8decoder is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with javavp8decoder. If not, see . +/* + * This file is part of javavp8decoder. + * + * javavp8decoder is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * javavp8decoder is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with javavp8decoder. If not, see . */ package net.sf.javavp8decoder.vp8Decoder; @@ -22,7 +23,7 @@ public class Segment { int Q0, Q1, Q2, Q3; public String toString() { - return "" + Globals.toHex(P3) + " " + Globals.toHex(P2) + " " + Globals.toHex(P1) + " " + Globals.toHex(P0) + " " + return Globals.toHex(P3) + " " + Globals.toHex(P2) + " " + Globals.toHex(P1) + " " + Globals.toHex(P0) + " " + Globals.toHex(Q0) + " " + Globals.toHex(Q1) + " " + Globals.toHex(Q2) + " " + Globals.toHex(Q3); } } diff --git a/src/main/java/net/sf/javavp8decoder/vp8Decoder/SegmentQuant.java b/src/main/java/net/sf/javavp8decoder/vp8Decoder/SegmentQuant.java index dc5476c..2efe00b 100644 --- a/src/main/java/net/sf/javavp8decoder/vp8Decoder/SegmentQuant.java +++ b/src/main/java/net/sf/javavp8decoder/vp8Decoder/SegmentQuant.java @@ -1,17 +1,18 @@ -/* This file is part of javavp8decoder. - - javavp8decoder is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - javavp8decoder is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with javavp8decoder. If not, see . +/* + * This file is part of javavp8decoder. + * + * javavp8decoder is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * javavp8decoder is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with javavp8decoder. If not, see . */ package net.sf.javavp8decoder.vp8Decoder; @@ -33,7 +34,7 @@ public class SegmentQuant { private int y2dc; - private int clip(int val, int max) { + private static int clip(int val, int max) { int r = Math.min(val, max); if (r < 0) r = 0; diff --git a/src/main/java/net/sf/javavp8decoder/vp8Decoder/SegmentQuants.java b/src/main/java/net/sf/javavp8decoder/vp8Decoder/SegmentQuants.java index 770f82b..e10e657 100644 --- a/src/main/java/net/sf/javavp8decoder/vp8Decoder/SegmentQuants.java +++ b/src/main/java/net/sf/javavp8decoder/vp8Decoder/SegmentQuants.java @@ -1,17 +1,18 @@ -/* This file is part of javavp8decoder. - - javavp8decoder is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - javavp8decoder is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with javavp8decoder. If not, see . +/* + * This file is part of javavp8decoder. + * + * javavp8decoder is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * javavp8decoder is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with javavp8decoder. If not, see . */ package net.sf.javavp8decoder.vp8Decoder; diff --git a/src/main/java/net/sf/javavp8decoder/vp8Decoder/SubBlock.java b/src/main/java/net/sf/javavp8decoder/vp8Decoder/SubBlock.java index 895bdd9..74ba388 100644 --- a/src/main/java/net/sf/javavp8decoder/vp8Decoder/SubBlock.java +++ b/src/main/java/net/sf/javavp8decoder/vp8Decoder/SubBlock.java @@ -1,17 +1,18 @@ -/* This file is part of javavp8decoder. - - javavp8decoder is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - javavp8decoder is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with javavp8decoder. If not, see . +/* + * This file is part of javavp8decoder. + * + * javavp8decoder is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * javavp8decoder is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with javavp8decoder. If not, see . */ package net.sf.javavp8decoder.vp8Decoder; @@ -57,7 +58,7 @@ public static int planeToType(PLANE plane, Boolean withY2) { } - private SubBlock above; + private final SubBlock above; private int[][] dest; @@ -65,13 +66,13 @@ public static int planeToType(PLANE plane, Boolean withY2) { private boolean hasNoZeroToken; - private SubBlock left; + private final SubBlock left; - private MacroBlock macroBlock; + private final MacroBlock macroBlock; private int mode; - private PLANE plane; + private final PLANE plane; private int[][] predict; @@ -88,7 +89,7 @@ public SubBlock(MacroBlock macroBlock, SubBlock above, SubBlock left, SubBlock.P tokens[z] = 0; } - private int DCTextra(BoolDecoder bc2, int[] p) throws IOException { + private static int DCTextra(BoolDecoder bc2, int[] p) throws IOException { int v = 0; int offset = 0; do { @@ -140,7 +141,7 @@ else if (dv == Globals.DCT_0) } } - private int decodeToken(BoolDecoder bc2, int v) throws IOException { + private static int decodeToken(BoolDecoder bc2, int v) throws IOException { int r = v; if (v == Globals.dct_cat1) { diff --git a/src/main/java/net/sf/javavp8decoder/vp8Decoder/VP8Decoder.java b/src/main/java/net/sf/javavp8decoder/vp8Decoder/VP8Decoder.java index e02b456..1e66313 100644 --- a/src/main/java/net/sf/javavp8decoder/vp8Decoder/VP8Decoder.java +++ b/src/main/java/net/sf/javavp8decoder/vp8Decoder/VP8Decoder.java @@ -1,17 +1,18 @@ -/* This file is part of javavp8decoder. - - javavp8decoder is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - javavp8decoder is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with javavp8decoder. If not, see . +/* + * This file is part of javavp8decoder. + * + * javavp8decoder is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * javavp8decoder is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with javavp8decoder. If not, see . */ package net.sf.javavp8decoder.vp8Decoder; @@ -58,10 +59,10 @@ public int getWidth() { public void writeFile(int[][] data) throws IOException { try (FileOutputStream out = new FileOutputStream("outagain.raw")) { for (int y = 0; y < data[0].length; y++) - for (int x = 0; x < data.length; x++) { - out.write(data[x][y]); - out.write(data[x][y]); - out.write(data[x][y]); + for (int[] datum : data) { + out.write(datum[y]); + out.write(datum[y]); + out.write(datum[y]); } } } diff --git a/src/main/java/net/sf/javavp8decoder/vp8Decoder/VP8Frame.java b/src/main/java/net/sf/javavp8decoder/vp8Decoder/VP8Frame.java index f33fb2b..3a04228 100644 --- a/src/main/java/net/sf/javavp8decoder/vp8Decoder/VP8Frame.java +++ b/src/main/java/net/sf/javavp8decoder/vp8Decoder/VP8Frame.java @@ -1,18 +1,19 @@ -/* This file is part of javavp8decoder. - - javavp8decoder is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - javavp8decoder is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with javavp8decoder. If not, see . -*/ +/* + * This file is part of javavp8decoder. + * + * javavp8decoder is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * javavp8decoder is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with javavp8decoder. If not, see . + */ package net.sf.javavp8decoder.vp8Decoder; @@ -391,24 +392,21 @@ private void decodeMacroBlockRow(int mbRow) throws IOException { } public void fireLFProgressUpdate(float p) { - java.util.Iterator listeners = _listeners.iterator(); - while (listeners.hasNext()) { - listeners.next().imageProgress(null, (100f / buffersToCreate) + (p / buffersToCreate)); + for (IIOReadProgressListener listener : _listeners) { + listener.imageProgress(null, (100f / buffersToCreate) + (p / buffersToCreate)); } } private void fireProgressUpdate(int mb_row) { - java.util.Iterator listeners = _listeners.iterator(); - while (listeners.hasNext()) { - listeners.next().imageProgress(null, - (100.0f * ((float) (mb_row + 1) / (float) getMacroBlockRows())) / buffersToCreate); + for (IIOReadProgressListener listener : _listeners) { + listener.imageProgress(null, + (100.0f * ((float) (mb_row + 1) / (float) getMacroBlockRows())) / buffersToCreate); } } public void fireRGBProgressUpdate(float p) { - java.util.Iterator listeners = _listeners.iterator(); - while (listeners.hasNext()) { - listeners.next().imageProgress(null, ((bufferCount + 4) * (100f / buffersToCreate)) + (p / buffersToCreate)); + for (IIOReadProgressListener listener : _listeners) { + listener.imageProgress(null, ((bufferCount + 4) * (100f / buffersToCreate)) + (p / buffersToCreate)); } } @@ -488,12 +486,12 @@ public SubBlock getAboveSubBlock(SubBlock sb, SubBlock.PLANE plane) { return r; } - private boolean getBit(int data, int bit) { + private static boolean getBit(int data, int bit) { int r = data & (1 << bit); return r > 0; } - private int getBitAsInt(int data, int bit) { + private static int getBitAsInt(int data, int bit) { int r = data & (1 << bit); if (r > 0) return 1; @@ -1055,25 +1053,14 @@ private void readModes(BoolDecoder bc) throws IOException { mb.setFilterLevel(level); } } else { - int BMode; - - switch (y_mode) { - case Globals.DC_PRED: - BMode = Globals.B_DC_PRED; - break; - case Globals.V_PRED: - BMode = Globals.B_VE_PRED; - break; - case Globals.H_PRED: - BMode = Globals.B_HE_PRED; - break; - case Globals.TM_PRED: - BMode = Globals.B_TM_PRED; - break; - default: - BMode = Globals.B_DC_PRED; - break; - } + int BMode = switch (y_mode) { + case Globals.DC_PRED -> Globals.B_DC_PRED; + case Globals.V_PRED -> Globals.B_VE_PRED; + case Globals.H_PRED -> Globals.B_HE_PRED; + case Globals.TM_PRED -> Globals.B_TM_PRED; + default -> Globals.B_DC_PRED; + }; + for (int x = 0; x < 4; x++) { for (int y = 0; y < 4; y++) { SubBlock sb = mb.getYSubBlock(x, y); @@ -1094,17 +1081,17 @@ private int readPartitionSize(long l) throws IOException { } - private int readSubBlockMode(BoolDecoder bc, int A, int L) throws IOException { + private static int readSubBlockMode(BoolDecoder bc, int A, int L) throws IOException { int i = bc.readTree(Globals.vp8SubBlockModeTree, Globals.vp8KeyFrameSubBlockModeProb[A][L]); return i; } - private int readUvMode(BoolDecoder bc) throws IOException { + private static int readUvMode(BoolDecoder bc) throws IOException { int i = bc.readTree(Globals.vp8UVModeTree, Globals.vp8KeyFrameUVModeProb); return i; } - private int readYMode(BoolDecoder bc) throws IOException { + private static int readYMode(BoolDecoder bc) throws IOException { int i = bc.readTree(Globals.vp8KeyFrameYModeTree, Globals.vp8KeyFrameYModeProb); return i; } diff --git a/src/test/java/IVF.java b/src/test/java/IVF.java index 3b9afb2..05e3605 100644 --- a/src/test/java/IVF.java +++ b/src/test/java/IVF.java @@ -1,3 +1,20 @@ +/* + * This file is part of javavp8decoder. + * + * javavp8decoder is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * javavp8decoder is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with javavp8decoder. If not, see . + */ + import java.io.IOException; import java.io.InputStream; @@ -9,14 +26,10 @@ public class IVF { private static final int IVF_FRAME_HDR_SZ = 4 + 8; private static final int IVF_FILE_HDR_SZ = 32; - IVF() { - InputStream in; - try { - in = getClass().getResourceAsStream("bbb.ivf"); + IVF() throws IOException { + try (InputStream in = getClass().getResourceAsStream("bbb.ivf")) { System.out.println("IVF"); readFileHeader(in); - @SuppressWarnings("unused") - int[] frameData; @SuppressWarnings("unused") VP8Decoder f = new VP8Decoder(); @@ -24,19 +37,16 @@ public class IVF { @SuppressWarnings("unused") int x = 0; while (true) { - frameData = getFrame(in); + @SuppressWarnings("unused") + int[] frameData = getFrame(in); //f.decodeFrame(frameData, false); x++; } - - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); } } - private int[] getFrame(InputStream in) throws IOException { + private static int[] getFrame(InputStream in) throws IOException { int[] frame; int c; int frameSize = c = in.read(); @@ -57,15 +67,15 @@ private int[] getFrame(InputStream in) throws IOException { return frame; } - public static void main(String[] args) { + public static void main(String[] args) throws IOException { new IVF(); } - public String toHex(int c) { + public static String toHex(int c) { return String.format("%1$#x ", c); } - private boolean readFileHeader(InputStream in) throws IOException { + private static boolean readFileHeader(InputStream in) throws IOException { int c; System.out.print("IVF FILE HEADER: "); for (int x = 0; x < IVF_FILE_HDR_SZ; x++) { diff --git a/src/test/java/Test1.java b/src/test/java/TestCase.java similarity index 86% rename from src/test/java/Test1.java rename to src/test/java/TestCase.java index 1277e00..5d9ea49 100644 --- a/src/test/java/Test1.java +++ b/src/test/java/TestCase.java @@ -18,34 +18,35 @@ import org.junit.jupiter.api.Test; import vavi.util.Debug; +import static org.junit.jupiter.api.Assertions.fail; + /** - * Test1. + * TestCase. * * @author Naohide Sano (umjammer) * @version 0.00 2022/03/30 umjammer initial version
*/ -public class Test1 { +public class TestCase { @Test void test1() throws Exception { Path dir = Paths.get("src/test/resources/testdata"); Files.walk(dir).filter(p -> p.getFileName().toString().matches(".+\\.webp")).forEach(f -> { -Debug.println(Level.INFO, f); +Debug.println(Level.FINER, f); try { ImageIO.read(f.toFile()); Debug.println(Level.INFO, f + ": OK"); } catch (IOException e) { Debug.println(Level.WARNING, f + ": " + e); + fail(); } }); } - /** - * @param args - */ + /** */ public static void main(String[] args) throws Exception { - Test1 app = new Test1(); + TestCase app = new TestCase(); app.exec(); } @@ -53,10 +54,11 @@ public static void main(String[] args) throws Exception { /** */ void exec() throws IOException { - final JFrame frame = new JFrame(); + JFrame frame = new JFrame(); frame.setSize(600, 600); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - final JPanel panel = new JPanel() { + JPanel panel = new JPanel() { + @Override public void paintComponent(Graphics g) { g.drawImage(image, 0, 0, this); } diff --git a/src/test/java/net/sf/javavp8decoder/tools/WebPViewer.java b/src/test/java/net/sf/javavp8decoder/tools/WebPViewer.java index 93cca40..4181568 100644 --- a/src/test/java/net/sf/javavp8decoder/tools/WebPViewer.java +++ b/src/test/java/net/sf/javavp8decoder/tools/WebPViewer.java @@ -1,17 +1,18 @@ -/* This file is part of javavp8decoder. - - javavp8decoder is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - javavp8decoder is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with javavp8decoder. If not, see . +/* + * This file is part of javavp8decoder. + * + * javavp8decoder is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * javavp8decoder is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with javavp8decoder. If not, see . */ package net.sf.javavp8decoder.tools; @@ -33,6 +34,7 @@ import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; +import java.io.Serial; import javax.imageio.ImageIO; import javax.imageio.ImageReader; @@ -61,6 +63,7 @@ public class WebPViewer extends JFrame implements MouseMotionListener, MouseListener, MouseWheelListener, ActionListener { /** */ + @Serial private static final long serialVersionUID = 1L; public static void main(String[] args) { @@ -86,6 +89,7 @@ public static void main(String[] args) { app = new WebPViewer(); app.addWindowListener(new WindowAdapter() { + @Override public void windowClosing(WindowEvent e) { System.exit(0); } @@ -96,25 +100,25 @@ public void windowClosing(WindowEvent e) { private final JFileChooser fc = new JFileChooser(); - private JButton fileOpenButton = new JButton("Open"); + private final JButton fileOpenButton = new JButton("Open"); - private JMenuItem fileOpenMenu; + private final JMenuItem fileOpenMenu; private JPanel jp; - JMenuBar menuBar; + final JMenuBar menuBar; - private WebPViewer panel; + private final WebPViewer panel; private Point prevP; - JProgressBar progressBar; + final JProgressBar progressBar; private float scale = 1.0f; - private JScrollPane sp; + private final JScrollPane sp; - JToolBar toolBar; + final JToolBar toolBar; WebPViewer() { panel = this; @@ -152,16 +156,19 @@ public void windowClosing(WindowEvent e) { this.setSize(800, 600); } + @Override public void actionPerformed(ActionEvent e) { if (jp != null) jp.repaint(); if (e.getSource() == fileOpenMenu || e.getSource() == fileOpenButton && !progressBar.isVisible()) { fc.setFileFilter(new FileFilter() { + @Override public boolean accept(File f) { return f.isDirectory() || f.getName().toLowerCase().endsWith(".webp"); } + @Override public String getDescription() { return "webp image files"; } @@ -180,9 +187,10 @@ public String getDescription() { } } - private void loadImageData(final File f) { + private void loadImageData(File f) { new Thread() { + @Override public void run() { // File f = new File("src/test/resources/testdata/samples/1_original.webp"); try { @@ -196,31 +204,40 @@ public void run() { imageReader.setInput(iis, false); imageReader.addIIOReadProgressListener(new IIOReadProgressListener() { + @Override public void imageComplete(ImageReader source) { } + @Override public void imageProgress(ImageReader source, float percentageDone) { progressBar.setValue((int) percentageDone); } + @Override public void imageStarted(ImageReader source, int imageIndex) { } + @Override public void readAborted(ImageReader source) { } + @Override public void sequenceComplete(ImageReader source) { } + @Override public void sequenceStarted(ImageReader source, int minIndex) { } + @Override public void thumbnailComplete(ImageReader source) { } + @Override public void thumbnailProgress(ImageReader source, float percentageDone) { } + @Override public void thumbnailStarted(ImageReader source, int imageIndex, int thumbnailIndex) { } }); @@ -229,14 +246,16 @@ class ImagePanel extends JPanel { /** * */ + @Serial private static final long serialVersionUID = 1L; - private BufferedImage bi; + private final BufferedImage bi; public ImagePanel(BufferedImage bi) { this.bi = bi; } + @Override public void paintComponent(Graphics g) { super.paintComponent(g); BufferedImage bi = this.bi; @@ -280,9 +299,11 @@ public void paintComponent(Graphics g) { } + @Override public void mouseClicked(MouseEvent arg0) { } + @Override public void mouseDragged(MouseEvent e) { if (prevP == null) { prevP = new Point(e.getXOnScreen(), e.getYOnScreen()); @@ -299,25 +320,31 @@ public void mouseDragged(MouseEvent e) { setCursor(new Cursor(Cursor.MOVE_CURSOR)); } + @Override public void mouseEntered(MouseEvent arg0) { } + @Override public void mouseExited(MouseEvent arg0) { } + @Override public void mouseMoved(MouseEvent e) { } + @Override public void mousePressed(MouseEvent arg0) { } + @Override public void mouseReleased(MouseEvent arg0) { prevP = null; setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); jp.repaint(); } + @Override public void mouseWheelMoved(MouseWheelEvent e) { jp.repaint(); scale = scale - scale * ((e.getWheelRotation() * 0.1f)); diff --git a/src/test/java/net/sf/javavp8decoder/tools/dwebp.java b/src/test/java/net/sf/javavp8decoder/tools/dwebp.java index 2ef9ea6..0da731c 100644 --- a/src/test/java/net/sf/javavp8decoder/tools/dwebp.java +++ b/src/test/java/net/sf/javavp8decoder/tools/dwebp.java @@ -1,23 +1,23 @@ -/* This file is part of javavp8decoder. - - javavp8decoder is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - javavp8decoder is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with javavp8decoder. If not, see . +/* + * This file is part of javavp8decoder. + * + * javavp8decoder is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * javavp8decoder is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with javavp8decoder. If not, see . */ package net.sf.javavp8decoder.tools; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; import javax.imageio.ImageIO; @@ -29,10 +29,10 @@ public class dwebp { private static ImageInputStream getFrame(FileInputStream in) throws IOException { ImageInputStream iis = ImageIO.createImageInputStream(in); - System.out.print("" + toHex(in.read())); - System.out.print("" + toHex(in.read())); - System.out.print("" + toHex(in.read())); - System.out.print("" + toHex(in.read())); + System.out.print(toHex(in.read())); + System.out.print(toHex(in.read())); + System.out.print(toHex(in.read())); + System.out.print(toHex(in.read())); int frameSize = in.read(); frameSize += in.read() << 8; frameSize += in.read() << 16; @@ -65,9 +65,6 @@ public static void main(String[] args) { f.decodeFrame(frameData, false); f.writePGMFile(outname, f.getFrame()); - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -75,10 +72,10 @@ public static void main(String[] args) { } private static boolean readFileHeader(FileInputStream in) throws IOException { - System.out.print("" + toHex(in.read())); - System.out.print("" + toHex(in.read())); - System.out.print("" + toHex(in.read())); - System.out.print("" + toHex(in.read())); + System.out.print(toHex(in.read())); + System.out.print(toHex(in.read())); + System.out.print(toHex(in.read())); + System.out.print(toHex(in.read())); System.out.println(); int frameSize = in.read(); frameSize += in.read() << 8; @@ -86,10 +83,10 @@ private static boolean readFileHeader(FileInputStream in) throws IOException { frameSize += in.read() << 24; System.out.print("RIFF IMAGE DATA SIZE: " + frameSize); System.out.println(); - System.out.print("" + toHex(in.read())); - System.out.print("" + toHex(in.read())); - System.out.print("" + toHex(in.read())); - System.out.print("" + toHex(in.read())); + System.out.print(toHex(in.read())); + System.out.print(toHex(in.read())); + System.out.print(toHex(in.read())); + System.out.print(toHex(in.read())); System.out.println(); return true; } diff --git a/src/test/java/net/sf/javavp8decoder/tools/plugintest.java b/src/test/java/net/sf/javavp8decoder/tools/plugintest.java index 4bb4d47..5a09b73 100644 --- a/src/test/java/net/sf/javavp8decoder/tools/plugintest.java +++ b/src/test/java/net/sf/javavp8decoder/tools/plugintest.java @@ -1,17 +1,18 @@ -/* This file is part of javavp8decoder. - - javavp8decoder is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - javavp8decoder is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with javavp8decoder. If not, see . +/* + * This file is part of javavp8decoder. + * + * javavp8decoder is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * javavp8decoder is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with javavp8decoder. If not, see . */ package net.sf.javavp8decoder.tools; @@ -23,6 +24,7 @@ import java.awt.image.BufferedImage; import java.io.IOException; import java.io.InputStream; +import java.io.Serial; import javax.imageio.ImageIO; import javax.imageio.spi.IIORegistry; @@ -37,6 +39,7 @@ public class plugintest extends JFrame { /** * */ + @Serial private static final long serialVersionUID = 1L; public static void main(String[] args) { @@ -50,6 +53,7 @@ public static void main(String[] args) { plugintest app; app = new plugintest(); app.addWindowListener(new WindowAdapter() { + @Override public void windowClosing(WindowEvent e) { System.exit(0); } @@ -62,9 +66,9 @@ public void windowClosing(WindowEvent e) { private BufferedImage bi; - private JPanel jp; + private final JPanel jp; - private JScrollPane sp; + private final JScrollPane sp; plugintest() { @@ -84,14 +88,16 @@ class ImagePanel extends JPanel { /** * */ + @Serial private static final long serialVersionUID = 1L; - private BufferedImage bi; + private final BufferedImage bi; public ImagePanel(BufferedImage bi) { this.bi = bi; } + @Override public void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(bi, 0, 0, null); diff --git a/src/test/java/net/sf/javavp8decoder/tools/vp8inspector/IVFFile.java b/src/test/java/net/sf/javavp8decoder/tools/vp8inspector/IVFFile.java index d95b8d0..b23dbc5 100644 --- a/src/test/java/net/sf/javavp8decoder/tools/vp8inspector/IVFFile.java +++ b/src/test/java/net/sf/javavp8decoder/tools/vp8inspector/IVFFile.java @@ -1,9 +1,24 @@ +/* + * This file is part of javavp8decoder. + * + * javavp8decoder is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * javavp8decoder is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with javavp8decoder. If not, see . + */ package net.sf.javavp8decoder.tools.vp8inspector; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; @@ -12,7 +27,7 @@ public class IVFFile { private static final int IVF_FILE_HDR_SZ = (32); - File file; + final File file; FileInputStream in; @@ -24,14 +39,12 @@ public IVFFile(File file) { readFileHeader(in); } - catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { + catch (IOException e) { e.printStackTrace(); } } - private boolean readFileHeader(FileInputStream in) throws IOException { + private static boolean readFileHeader(FileInputStream in) throws IOException { for (int x = 0; x < IVF_FILE_HDR_SZ; x++) { in.read(); } @@ -89,7 +102,7 @@ public byte[] getNextFrame() { return frameData; } - private int getBitAsInt(int data, int bit) { + private static int getBitAsInt(int data, int bit) { int r = data & (1 << bit); if (r > 0) return 1; diff --git a/src/test/java/net/sf/javavp8decoder/tools/vp8inspector/Utils.java b/src/test/java/net/sf/javavp8decoder/tools/vp8inspector/Utils.java index 5ae9594..076647d 100644 --- a/src/test/java/net/sf/javavp8decoder/tools/vp8inspector/Utils.java +++ b/src/test/java/net/sf/javavp8decoder/tools/vp8inspector/Utils.java @@ -1,3 +1,19 @@ +/* + * This file is part of javavp8decoder. + * + * javavp8decoder is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * javavp8decoder is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with javavp8decoder. If not, see . + */ package net.sf.javavp8decoder.tools.vp8inspector; @@ -145,17 +161,13 @@ public static void main(String[] args) { try { // Set System L&F UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - } catch (UnsupportedLookAndFeelException e) { - // handle exception - } catch (ClassNotFoundException e) { - // handle exception - } catch (InstantiationException e) { - // handle exception - } catch (IllegalAccessException e) { + } catch (UnsupportedLookAndFeelException | IllegalAccessException | InstantiationException | + ClassNotFoundException e) { // handle exception } app = new VP8Inspector(); app.addWindowListener(new WindowAdapter() { + @Override public void windowClosing(WindowEvent e) { System.exit(0); } diff --git a/src/test/java/net/sf/javavp8decoder/tools/vp8inspector/VP8Inspector.java b/src/test/java/net/sf/javavp8decoder/tools/vp8inspector/VP8Inspector.java index ebf1a0c..94aaeb4 100644 --- a/src/test/java/net/sf/javavp8decoder/tools/vp8inspector/VP8Inspector.java +++ b/src/test/java/net/sf/javavp8decoder/tools/vp8inspector/VP8Inspector.java @@ -1,17 +1,18 @@ -/* This file is part of javavp8decoder. - - javavp8decoder is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - javavp8decoder is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with javavp8decoder. If not, see . +/* + * This file is part of javavp8decoder. + * + * javavp8decoder is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * javavp8decoder is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with javavp8decoder. If not, see . */ package net.sf.javavp8decoder.tools.vp8inspector; @@ -36,6 +37,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.io.Serial; import javax.imageio.ImageIO; import javax.imageio.ImageReader; @@ -70,27 +72,28 @@ public class VP8Inspector extends JFrame implements MouseMotionListener, MouseListener, MouseWheelListener, ActionListener { /** */ + @Serial private static final long serialVersionUID = 1L; private BufferedImage bi; - private JCheckBox colorCodeCheckBox = new JCheckBox("Colour Code"); + private final JCheckBox colorCodeCheckBox = new JCheckBox("Colour Code"); private File currentFile = null; - private JRadioButton destButton = new JRadioButton("Dest"); + private final JRadioButton destButton = new JRadioButton("Dest"); private JFileChooser fc = new JFileChooser(); - private JButton fileOpenButton = new JButton("Open"); + private final JButton fileOpenButton = new JButton("Open"); - private JMenuItem fileOpenMenu; + private final JMenuItem fileOpenMenu; private VP8Frame frame; - JToolBar infoBar = new JToolBar(); + final JToolBar infoBar = new JToolBar(); - JTextArea infoText = new JTextArea(); + final JTextArea infoText = new JTextArea(); private JPanel jp; @@ -98,43 +101,43 @@ public class VP8Inspector extends JFrame implements MouseMotionListener, MouseLi private IVFFile ivfFile; - private JCheckBox mBCheckBox = new JCheckBox("MB"); + private final JCheckBox mBCheckBox = new JCheckBox("MB"); - JMenuBar menuBar; + final JMenuBar menuBar; - private JButton nextButton = new JButton("next"); + private final JButton nextButton = new JButton("next"); - private VP8Inspector panel; + private final VP8Inspector panel; private BufferedImage predict; - private JRadioButton predictButton = new JRadioButton("Predict"); + private final JRadioButton predictButton = new JRadioButton("Predict"); - private JButton prevButton = new JButton("prev"); + private final JButton prevButton = new JButton("prev"); private Point prevP; - JProgressBar progressBar; + final JProgressBar progressBar; private BufferedImage residual; - private JRadioButton residualButton = new JRadioButton("Residual"); + private final JRadioButton residualButton = new JRadioButton("Residual"); - private JRadioButton rgbButton = new JRadioButton("RGB"); + private final JRadioButton rgbButton = new JRadioButton("RGB"); - private JCheckBox sBCheckBox = new JCheckBox("SB"); + private final JCheckBox sBCheckBox = new JCheckBox("SB"); private float scale = 1.0f; - private JSlider slider = new JSlider(); + private final JSlider slider = new JSlider(); - private JScrollPane sp; + private final JScrollPane sp; - JToolBar toolBar; + final JToolBar toolBar; private BufferedImage ub; - private JRadioButton uButton = new JRadioButton("U"); + private final JRadioButton uButton = new JRadioButton("U"); private BufferedImage upred; @@ -142,7 +145,7 @@ public class VP8Inspector extends JFrame implements MouseMotionListener, MouseLi private BufferedImage vb; - private JRadioButton vButton = new JRadioButton("V"); + private final JRadioButton vButton = new JRadioButton("V"); private BufferedImage vpred; @@ -150,7 +153,7 @@ public class VP8Inspector extends JFrame implements MouseMotionListener, MouseLi private BufferedImage yb; - private JRadioButton yButton = new JRadioButton("Y"); + private final JRadioButton yButton = new JRadioButton("Y"); private BufferedImage ypred; @@ -247,6 +250,7 @@ public class VP8Inspector extends JFrame implements MouseMotionListener, MouseLi this.setSize(800, 600); } + @Override public void actionPerformed(ActionEvent e) { if ((e.getSource() == nextButton)) @@ -258,11 +262,13 @@ public void actionPerformed(ActionEvent e) { fc = new JFileChooser(); fc.setFileFilter(new FileFilter() { + @Override public boolean accept(File f) { return f.isDirectory() || f.getName().toLowerCase().endsWith(".webp") || f.getName().toLowerCase().endsWith(".webm") || f.getName().toLowerCase().endsWith(".ivf"); } + @Override public String getDescription() { return "WebM/IVF/WebP Files"; } @@ -317,31 +323,40 @@ private boolean frameReader() throws IOException { return false; frame.addIIOReadProgressListener(new IIOReadProgressListener() { + @Override public void imageComplete(ImageReader source) { } + @Override public void imageProgress(ImageReader source, float percentageDone) { progressBar.setValue((int) percentageDone); } + @Override public void imageStarted(ImageReader source, int imageIndex) { } + @Override public void readAborted(ImageReader source) { } + @Override public void sequenceComplete(ImageReader source) { } + @Override public void sequenceStarted(ImageReader source, int minIndex) { } + @Override public void thumbnailComplete(ImageReader source) { } + @Override public void thumbnailProgress(ImageReader source, float percentageDone) { } + @Override public void thumbnailStarted(ImageReader source, int imageIndex, int thumbnailIndex) { } }); @@ -367,6 +382,7 @@ public void thumbnailStarted(ImageReader source, int imageIndex, int thumbnailIn private void loadImageData() { new Thread() { + @Override public void run() { try { setTitle("VP8Inspector - " + currentFile.getName() + " (Loading...)"); @@ -403,31 +419,32 @@ class ImagePanel extends JPanel { /** * */ + @Serial private static final long serialVersionUID = 1L; - private BufferedImage bi; + private final BufferedImage bi; - private BufferedImage predict; + private final BufferedImage predict; - private BufferedImage residual; + private final BufferedImage residual; - private BufferedImage ub; + private final BufferedImage ub; - private BufferedImage uPred; + private final BufferedImage uPred; - private BufferedImage uResidual; + private final BufferedImage uResidual; - private BufferedImage vb; + private final BufferedImage vb; - private BufferedImage vPred; + private final BufferedImage vPred; - private BufferedImage vResidual; + private final BufferedImage vResidual; - private BufferedImage yb; + private final BufferedImage yb; - private BufferedImage yPred; + private final BufferedImage yPred; - private BufferedImage yResidual; + private final BufferedImage yResidual; public ImagePanel(BufferedImage bi, BufferedImage yb, @@ -456,6 +473,7 @@ public ImagePanel(BufferedImage bi, } + @Override public void paintComponent(Graphics g) { super.paintComponent(g); BufferedImage bi = this.bi; @@ -659,9 +677,11 @@ private void loadNextFrame() { loadImageData(); } + @Override public void mouseClicked(MouseEvent arg0) { } + @Override public void mouseDragged(MouseEvent e) { if (prevP == null) { prevP = new Point(e.getXOnScreen(), e.getYOnScreen()); @@ -678,25 +698,31 @@ public void mouseDragged(MouseEvent e) { setCursor(new Cursor(Cursor.MOVE_CURSOR)); } + @Override public void mouseEntered(MouseEvent arg0) { } + @Override public void mouseExited(MouseEvent arg0) { } + @Override public void mouseMoved(MouseEvent e) { updateInfoText(e.getPoint()); } + @Override public void mousePressed(MouseEvent arg0) { } + @Override public void mouseReleased(MouseEvent arg0) { prevP = null; setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); jp.repaint(); } + @Override public void mouseWheelMoved(MouseWheelEvent e) { jp.repaint(); scale = scale - scale * ((e.getWheelRotation() * 0.1f)); From 9daa8e6e86f5376867922861447433ab893847bd Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Thu, 7 Mar 2024 04:22:18 +0900 Subject: [PATCH 6/9] use project version as spi version --- .../imageio/WebPImageReaderSpi.java | 22 ++++++++++- src/test/java/Integration.java | 37 +++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 src/test/java/Integration.java diff --git a/src/main/java/net/sf/javavp8decoder/imageio/WebPImageReaderSpi.java b/src/main/java/net/sf/javavp8decoder/imageio/WebPImageReaderSpi.java index 4a4179d..7f2f539 100644 --- a/src/main/java/net/sf/javavp8decoder/imageio/WebPImageReaderSpi.java +++ b/src/main/java/net/sf/javavp8decoder/imageio/WebPImageReaderSpi.java @@ -18,7 +18,9 @@ package net.sf.javavp8decoder.imageio; import java.io.IOException; +import java.io.InputStream; import java.util.Locale; +import java.util.Properties; import javax.imageio.ImageReader; import javax.imageio.spi.ImageReaderSpi; @@ -27,6 +29,23 @@ public class WebPImageReaderSpi extends ImageReaderSpi { + static { + try { + try (InputStream is = WebPImageReaderSpi.class.getResourceAsStream("/META-INF/maven/vavi/vavi-image-webp/pom.properties")) { + if (is != null) { + Properties props = new Properties(); + props.load(is); + version = props.getProperty("version", "undefined in pom.properties"); + } else { + version = System.getProperty("vavi.test.version", "undefined"); + } + } + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + + static final String version; static final String[] extraImageMetadataFormatClassNames = null; static final String[] extraImageMetadataFormatNames = null; static final String[] extraStreamMetadataFormatClassNames = null; @@ -48,8 +67,7 @@ public class WebPImageReaderSpi extends ImageReaderSpi { static final boolean supportsStandardImageMetadataFormat = false; // Metadata formats, more information below static final boolean supportsStandardStreamMetadataFormat = false; - static final String vendorName = "javavp8decoder"; - static final String version = "0.1"; + static final String vendorName = "https://github.com/umjammer/vavi-image-webp"; static final String[] writerSpiNames = { "net.sf.javavp8decoder.WebPImageReader" }; diff --git a/src/test/java/Integration.java b/src/test/java/Integration.java new file mode 100644 index 0000000..b0fc251 --- /dev/null +++ b/src/test/java/Integration.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 by Naohide Sano, All rights reserved. + * + * Programmed by Naohide Sano + */ + +import java.util.Iterator; +import javax.imageio.spi.IIORegistry; +import javax.imageio.spi.ImageReaderSpi; + + +/** + * Integration test. + * + * @author Naohide Sano (nsano) + * @version 0.00 2024-03-07 nsano initial version
+ */ +public class Integration { + + /** + * + * @param args 0: version + */ + public static void main(String[] args) throws Exception { + IIORegistry iioRegistry = IIORegistry.getDefaultInstance(); + Iterator i = iioRegistry.getServiceProviders(ImageReaderSpi.class, true); + while (i.hasNext()) { + ImageReaderSpi p = i.next(); + if (p.getClass() == net.sf.javavp8decoder.imageio.WebPImageReaderSpi.class) { +System.err.println("compare: " + p.getVersion() + " and " + args[0]); + assert p.getVersion().equals(args[0]) : "not equals version: " + p.getVersion() + " and " + args[0]; + return; + } + } + assert false : "no suitable spi"; + } +} From e91781f08c53125e13ae1de9434de9cf61181d2d Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Thu, 7 Mar 2024 04:22:35 +0900 Subject: [PATCH 7/9] make test more effective --- .../imageio/WebPImageReaderSpi.java | 2 +- src/test/java/TestCase.java | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/sf/javavp8decoder/imageio/WebPImageReaderSpi.java b/src/main/java/net/sf/javavp8decoder/imageio/WebPImageReaderSpi.java index 7f2f539..566a09a 100644 --- a/src/main/java/net/sf/javavp8decoder/imageio/WebPImageReaderSpi.java +++ b/src/main/java/net/sf/javavp8decoder/imageio/WebPImageReaderSpi.java @@ -54,7 +54,7 @@ public class WebPImageReaderSpi extends ImageReaderSpi { "image/webp" }; static final String[] names = { - "webp" + "webp", "WEBP" }; static final String nativeImageMetadataFormatClassName = "net.sf.javavp8decoder.imageio.WebPMetadata_0.1"; static final String nativeImageMetadataFormatName = "net.sf.javavp8decoder.imageio.WebPMetadata_0.1"; diff --git a/src/test/java/TestCase.java b/src/test/java/TestCase.java index 5d9ea49..68723d9 100644 --- a/src/test/java/TestCase.java +++ b/src/test/java/TestCase.java @@ -10,14 +10,20 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Arrays; import java.util.logging.Level; import javax.imageio.ImageIO; +import javax.imageio.ImageReader; +import javax.imageio.stream.ImageInputStream; import javax.swing.JFrame; import javax.swing.JPanel; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import vavi.util.Debug; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -29,6 +35,36 @@ */ public class TestCase { + String file = "src/test/resources/testdata/test.webp"; + + @Test + @DisplayName("spi") + void test00() throws Exception { + String[] rs = ImageIO.getReaderFormatNames(); +System.err.println("-- reader --"); +for (String r : rs) { + System.err.println(r); +} + assertTrue(Arrays.asList(rs).contains("WEBP")); + } + + @Test + @DisplayName("spi specified") + void test01() throws Exception { + ImageReader ir = ImageIO.getImageReadersByFormatName("webp").next(); + ImageInputStream iis = ImageIO.createImageInputStream(Files.newInputStream(Paths.get(file))); + ir.setInput(iis); + BufferedImage image = ir.read(0); + assertNotNull(image); + } + + @Test + @DisplayName("spi auto") + void test02() throws Exception { + BufferedImage image = ImageIO.read(Files.newInputStream(Paths.get(file))); + assertNotNull(image); + } + @Test void test1() throws Exception { Path dir = Paths.get("src/test/resources/testdata"); From 1a99058f5fbdaec0f4299d7cd2c6dbd5610200de Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Thu, 7 Mar 2024 04:23:47 +0900 Subject: [PATCH 8/9] update settings --- .github/workflows/codeql-analysis.yml | 19 +++++++-- .github/workflows/maven.yml | 8 ++-- README.md | 8 +++- jitpack.yml | 2 + pom.xml | 56 +++++++++++++++++++++++---- 5 files changed, 76 insertions(+), 17 deletions(-) create mode 100644 jitpack.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 215f656..837834f 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -18,6 +18,10 @@ jobs: analyze: name: Analyze runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write strategy: fail-fast: false @@ -30,11 +34,11 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@v3 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -44,8 +48,15 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + - name: Autobuild - uses: github/codeql-action/autobuild@v2 + uses: github/codeql-action/autobuild@v3 # ℹ️ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -59,4 +70,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@v3 diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 20ed204..1793071 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -9,16 +9,16 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Check w/o SNAPSHOT when "bump version" if: ${{ contains(github.event.head_commit.message, 'bump version') }} run: grep "" pom.xml | head -1 | grep -v SNAPSHOT - - name: Set up JDK 8 - uses: actions/setup-java@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v4 with: - java-version: '8' + java-version: '17' distribution: 'temurin' cache: maven diff --git a/README.md b/README.md index fcdfea9..b271a58 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ [![Release](https://jitpack.io/v/umjammer/vavi-image-webp.svg)](https://jitpack.io/#umjammer/vavi-image-webp) [![Java CI](https://github.com/umjammer/vavi-image-webp/actions/workflows/maven.yml/badge.svg)](https://github.com/umjammer/vavi-image-webp/actions/workflows/maven.yml) [![CodeQL](https://github.com/umjammer/vavi-image-webp/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/umjammer/vavi-image-webp/actions/workflows/codeql-analysis.yml) -![Java](https://img.shields.io/badge/Java-8-b07219) +![Java](https://img.shields.io/badge/Java-17-b07219) [![Parent](https://img.shields.io/badge/Parent-vavi--image--sandbox-pink)](https://github.com/umjammer/vavi-image-sandbox) # vavi-image-webp - +© Google An implementation of the VP8 image/video codec in _**pure Java**_. @@ -19,3 +19,7 @@ https://jitpack.io/#umjammer/vavi-image-webp ```java BufferedImage image = ImageIO.read(Paths.get("/foo/bar.webp").toFile()); ``` + +## Reference + + * [Original](https://sourceforge.net/projects/javavp8decoder/) diff --git a/jitpack.yml b/jitpack.yml new file mode 100644 index 0000000..efde7bf --- /dev/null +++ b/jitpack.yml @@ -0,0 +1,2 @@ +jdk: + - openjdk17 diff --git a/pom.xml b/pom.xml index 873ecc6..ad51cc4 100644 --- a/pom.xml +++ b/pom.xml @@ -15,29 +15,71 @@ pure Java webp Decoder + + + mac arm64 + + + mac + aarch64 + + + + /opt/homebrew + + + + org.apache.maven.plugins maven-compiler-plugin - 3.10.1 + 3.11.0 - 8 - 8 - UTF-8 + 17 org.apache.maven.plugins maven-surefire-plugin - 3.0.0-M7 + 3.2.2 -Djava.util.logging.config.file=${project.build.testOutputDirectory}/logging.properties + -Dvavi.test.version=${project.version} false + + + org.apache.maven.plugins + maven-antrun-plugin + 3.1.0 + + + integration-test + + run + + integration-test + + + + + + + + + + + + true + + + + @@ -53,7 +95,7 @@ org.junit junit-bom - 5.9.1 + 5.10.2 pom import @@ -86,7 +128,7 @@ com.github.umjammer vavi-commons - 1.1.8 + 1.1.10 test From bc848b8dc30ead9e6c0ffb54e2a8f5b062ff5ca1 Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Thu, 7 Mar 2024 04:25:21 +0900 Subject: [PATCH 9/9] bump version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ad51cc4..0549850 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ vavi vavi-image-webp - 0.2.4 + 0.2.5 Java VP8 Decoder