Added WebP support
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Tue, 9 Mar 2021 16:55:24 +0000 (18:55 +0200)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Tue, 9 Mar 2021 16:55:24 +0000 (18:55 +0200)
src/main/java/eu/svjatoslav/meviz/encoder/FormatsRegistry.java
src/main/java/eu/svjatoslav/meviz/encoder/converters/Convert.java
src/main/java/eu/svjatoslav/meviz/encoder/converters/Cwebp.java [new file with mode: 0644]

index d03b2e0..c0de0fd 100755 (executable)
@@ -22,6 +22,7 @@ public class FormatsRegistry {
 
         // image conversion
         registerEncoder(new Convert());
+        registerEncoder(new Cwebp());
 
         // image to text (OCR)
         registerEncoder(new Ocr());
index 9de771f..1b02131 100644 (file)
@@ -1,11 +1,7 @@
 /*
- * Meviz - Various tools collection to work with multimedia.
- * Copyright (C) 2012 -- 2017-2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 3 of the GNU Lesser General Public License
- * or later as published by the Free Software Foundation.
-*/
+ * 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;
 
diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Cwebp.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Cwebp.java
new file mode 100644 (file)
index 0000000..ca329e0
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * 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;
+    }
+
+}