From: Svjatoslav Agejenko Date: Sun, 4 Jun 2023 15:52:59 +0000 (+0300) Subject: Support for decoding webp images X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=a5773d6ab6dd405129e2079cc4c71cc1427c142a;p=meviz.git Support for decoding webp images --- diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/FormatsRegistry.java b/src/main/java/eu/svjatoslav/meviz/encoder/FormatsRegistry.java index c0de0fd..4421846 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/FormatsRegistry.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/FormatsRegistry.java @@ -22,7 +22,8 @@ public class FormatsRegistry { // image conversion registerEncoder(new Convert()); - registerEncoder(new Cwebp()); + registerEncoder(new WebpEncoder()); + registerEncoder(new WebpDecoder()); // image to text (OCR) registerEncoder(new Ocr()); diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Cwebp.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Cwebp.java deleted file mode 100644 index ca329e0..0000000 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Cwebp.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Meviz - Various tools collection to work with multimedia. Author: Svjatoslav Agejenko. - * This project is released under Creative Commons Zero (CC0) license. - */ - -package eu.svjatoslav.meviz.encoder.converters; - -import eu.svjatoslav.meviz.encoder.EncodingOptions; - -import java.io.File; -import java.util.List; - -public class Cwebp extends AbstractConverter { - - @Override - public String getCommand(final File inputFile, final File targetFile, - final EncodingOptions options, String targetFormat) { - - String quality; - - switch (options.getVideoBitrate()) { - case LOW: - quality = " -q 10 "; - break; - case MEDIUM: - quality = " -q 50 "; - break; - case HIGH: - quality = " -q 80 "; - break; - case COPY: - case LOSSLESS: - default: - quality = " -lossless "; - } - - return "cwebp \"" + inputFile.getAbsolutePath() + "\"" + quality + " -o \"" - + targetFile.getAbsolutePath() + "\""; - } - - @Override - public List getSourceFileExtensions() { - return toList("tif", "tiff", "png", "jpg", "jpeg", "bmp", "gif"); - } - - @Override - public List getTargetFileExtensions() { - return toList("webp"); - } - - @Override - public boolean isTerminalMandatory() { - return false; - } - -} diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/WebpDecoder.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/WebpDecoder.java new file mode 100644 index 0000000..8d68562 --- /dev/null +++ b/src/main/java/eu/svjatoslav/meviz/encoder/converters/WebpDecoder.java @@ -0,0 +1,42 @@ +/* + * Meviz - Various tools collection to work with multimedia. Author: Svjatoslav Agejenko. + * This project is released under Creative Commons Zero (CC0) license. + */ + +package eu.svjatoslav.meviz.encoder.converters; + +import eu.svjatoslav.meviz.encoder.EncodingOptions; + +import java.io.File; +import java.util.List; + +/** + * webp decoder. + */ + +public class WebpDecoder extends AbstractConverter { + + @Override + public String getCommand(final File inputFile, final File targetFile, + final EncodingOptions options, String targetFormat) { + + return "dwebp \"" + inputFile.getAbsolutePath() + "\" -o \"" + + targetFile.getAbsolutePath() + "\""; + } + + @Override + public List getTargetFileExtensions() { + return toList("png"); + } + + @Override + public List getSourceFileExtensions() { + return toList("webp"); + } + + @Override + public boolean isTerminalMandatory() { + return false; + } + +} diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/WebpEncoder.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/WebpEncoder.java new file mode 100644 index 0000000..f3ac18e --- /dev/null +++ b/src/main/java/eu/svjatoslav/meviz/encoder/converters/WebpEncoder.java @@ -0,0 +1,59 @@ +/* + * Meviz - Various tools collection to work with multimedia. Author: Svjatoslav Agejenko. + * This project is released under Creative Commons Zero (CC0) license. + */ + +package eu.svjatoslav.meviz.encoder.converters; + +import eu.svjatoslav.meviz.encoder.EncodingOptions; + +import java.io.File; +import java.util.List; + +/** + * webp encoder. + */ +public class WebpEncoder extends AbstractConverter { + + @Override + public String getCommand(final File inputFile, final File targetFile, + final EncodingOptions options, String targetFormat) { + + String quality; + + switch (options.getVideoBitrate()) { + case LOW: + quality = " -q 10 "; + break; + case MEDIUM: + quality = " -q 50 "; + break; + case HIGH: + quality = " -q 80 "; + break; + case COPY: + case LOSSLESS: + default: + quality = " -lossless "; + } + + return "cwebp \"" + inputFile.getAbsolutePath() + "\"" + quality + " -o \"" + + targetFile.getAbsolutePath() + "\""; + } + + @Override + public List getSourceFileExtensions() { + return toList("tif", "tiff", "png", "jpg", "jpeg", "bmp", "gif"); + } + + @Override + public List getTargetFileExtensions() { + return toList("webp"); + } + + @Override + public boolean isTerminalMandatory() { + return false; + } + +}