Support for decoding webp images
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sun, 4 Jun 2023 15:52:59 +0000 (18:52 +0300)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sun, 4 Jun 2023 15:52:59 +0000 (18:52 +0300)
src/main/java/eu/svjatoslav/meviz/encoder/FormatsRegistry.java
src/main/java/eu/svjatoslav/meviz/encoder/converters/Cwebp.java [deleted file]
src/main/java/eu/svjatoslav/meviz/encoder/converters/WebpDecoder.java [new file with mode: 0644]
src/main/java/eu/svjatoslav/meviz/encoder/converters/WebpEncoder.java [new file with mode: 0644]

index c0de0fd..4421846 100755 (executable)
@@ -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 (file)
index ca329e0..0000000
+++ /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<String> getSourceFileExtensions() {
-        return toList("tif", "tiff", "png", "jpg", "jpeg", "bmp", "gif");
-    }
-
-    @Override
-    public List<String> 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 (file)
index 0000000..8d68562
--- /dev/null
@@ -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<String> getTargetFileExtensions() {
+        return toList("png");
+    }
+
+    @Override
+    public List<String> 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 (file)
index 0000000..f3ac18e
--- /dev/null
@@ -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<String> getSourceFileExtensions() {
+        return toList("tif", "tiff", "png", "jpg", "jpeg", "bmp", "gif");
+    }
+
+    @Override
+    public List<String> getTargetFileExtensions() {
+        return toList("webp");
+    }
+
+    @Override
+    public boolean isTerminalMandatory() {
+        return false;
+    }
+
+}