summaryrefslogtreecommitdiff
path: root/tests/heif
diff options
context:
space:
mode:
authorMartin Reboredo <39890836+YakoYakoYokuYoku@users.noreply.github.com>2021-03-02 14:32:03 -0300
committerGitHub <noreply@github.com>2021-03-02 12:32:03 -0500
commit39c4644fa01f6b9f002119e4109e252bc665b8f1 (patch)
tree852d151b50717219ebff215b4b6f65a945ebf9f3 /tests/heif
parentd6a061850d40110a98364766f654030f929ec0ed (diff)
downloadlibgd-39c4644fa01f6b9f002119e4109e252bc665b8f1.tar.gz
HEIF support through libheif (#670)
With the adoption of AVIF by Firefox and Chromium based browsers (still in experimental phase), the newer incorporation of HEIF by Canon and Sony in their cameras and the newer support of both of them in modern software like ImageMagick, GIMP and Krita, `gd` haven't seen any endorsement for the formats up until this PR. Reading and writing is done by `libheif`, with functionality for chroma subsampling (for now `4:2:0`, `4:2:2` and `4:4:4`), quality (with new `200` for lossless) and compression (whether `HEVC` or `AV1`) selection. This was tested with `libheif` version `1.11.0` in my Solus machine. Also, fixes both #395 and #557.
Diffstat (limited to 'tests/heif')
-rw-r--r--tests/heif/CMakeLists.txt11
-rw-r--r--tests/heif/Makemodule.am11
-rw-r--r--tests/heif/avif_ptr_double_free.c31
-rw-r--r--tests/heif/heif_im2im.c49
-rw-r--r--tests/heif/heif_null.c20
-rw-r--r--tests/heif/heif_ptr_double_free.c31
-rw-r--r--tests/heif/heif_read.c23
-rw-r--r--tests/heif/label.avifbin0 -> 602 bytes
-rw-r--r--tests/heif/label.heicbin0 -> 1170 bytes
9 files changed, 176 insertions, 0 deletions
diff --git a/tests/heif/CMakeLists.txt b/tests/heif/CMakeLists.txt
new file mode 100644
index 0000000..4a41528
--- /dev/null
+++ b/tests/heif/CMakeLists.txt
@@ -0,0 +1,11 @@
+IF(HEIF_FOUND)
+LIST(APPEND TESTS_FILES
+ avif_ptr_double_free
+ heif_im2im
+ heif_null
+ heif_ptr_double_free
+ heif_read
+)
+ENDIF(HEIF_FOUND)
+
+ADD_GD_TESTS()
diff --git a/tests/heif/Makemodule.am b/tests/heif/Makemodule.am
new file mode 100644
index 0000000..675e8a9
--- /dev/null
+++ b/tests/heif/Makemodule.am
@@ -0,0 +1,11 @@
+if HAVE_LIBHEIF
+libgd_test_programs += \
+ heif/avif_ptr_double_free \
+ heif/heif_im2im \
+ heif/heif_null \
+ heif/heif_ptr_double_free \
+ heif/heif_read
+endif
+
+EXTRA_DIST += \
+ heif/CMakeLists.txt
diff --git a/tests/heif/avif_ptr_double_free.c b/tests/heif/avif_ptr_double_free.c
new file mode 100644
index 0000000..f294929
--- /dev/null
+++ b/tests/heif/avif_ptr_double_free.c
@@ -0,0 +1,31 @@
+/**
+ * Test that failure to convert to AVIF returns NULL
+ *
+ * We are creating an image, set its width to zero, and pass this image to
+ * `gdImageAvifPtr()` which is supposed to fail, and as such should return NULL.
+ *
+ * See also <https://github.com/libgd/libgd/issues/381>
+ */
+
+
+#include "gd.h"
+#include "gdtest.h"
+
+
+int main()
+{
+ gdImagePtr src, dst;
+ int size;
+
+ src = gdImageCreateTrueColor(1, 10);
+ gdTestAssert(src != NULL);
+
+ src->sx = 0;
+
+ dst = gdImageHeifPtrEx(src, &size, 100, GD_HEIF_CODEC_AV1, GD_HEIF_CHROMA_444);
+ gdTestAssert(dst == NULL);
+
+ gdImageDestroy(src);
+
+ return gdNumFailures();
+}
diff --git a/tests/heif/heif_im2im.c b/tests/heif/heif_im2im.c
new file mode 100644
index 0000000..6ab9cf6
--- /dev/null
+++ b/tests/heif/heif_im2im.c
@@ -0,0 +1,49 @@
+/**
+ * Check if it's any difference between the original bitmap and a encoded and
+ * decoded `4:4:4` HEIF lossless image.
+ */
+
+
+#include "gd.h"
+#include "gdtest.h"
+
+int main()
+{
+ gdImagePtr src, dst;
+ int r, g, b;
+ void *p;
+ int size = 0;
+ CuTestImageResult result = {0, 0};
+
+ src = gdImageCreateTrueColor(100, 100);
+ gdTestAssertMsg(src != NULL, "could not create src\n");
+ /* libheif seems to have some rounding issues */
+ r = gdImageColorAllocate(src, 0xFE, 0, 0);
+ g = gdImageColorAllocate(src, 0, 0xFE, 0);
+ b = gdImageColorAllocate(src, 0, 0, 0xFE);
+ gdImageFilledRectangle(src, 0, 0, 99, 99, r);
+ gdImageRectangle(src, 20, 20, 79, 79, g);
+ gdImageEllipse(src, 70, 25, 30, 20, b);
+
+ p = gdImageHeifPtrEx(src, &size, 200, GD_HEIF_CODEC_HEVC, GD_HEIF_CHROMA_444);
+ gdTestAssertMsg(p != NULL, "return value of gdImageHeifPtrEx() is null\n");
+ gdTestAssertMsg(size > 0, "gdImageHeifPtrEx() output size is non-positive\n");
+
+ dst = gdImageCreateFromHeifPtr(size, p);
+ gdTestAssertMsg(dst != NULL, "return value of gdImageCreateFromHeifPtr() is null\n");
+
+ if (gdTestAssertMsg(src != NULL && dst != NULL, "cannot compare with NULL buffer"))
+ gdTestImageDiff(src, dst, NULL, &result);
+ else
+ result.pixels_changed = 0;
+ gdTestAssertMsg(result.pixels_changed == 0, "pixels changed: %d\n", result.pixels_changed);
+
+ if (dst != NULL)
+ gdImageDestroy(dst);
+ if (p != NULL)
+ gdFree(p);
+ if (src != NULL)
+ gdImageDestroy(src);
+
+ return gdNumFailures();
+}
diff --git a/tests/heif/heif_null.c b/tests/heif/heif_null.c
new file mode 100644
index 0000000..0b5eac5
--- /dev/null
+++ b/tests/heif/heif_null.c
@@ -0,0 +1,20 @@
+/**
+ * Simple test case that confirms the failure of using `gdImageCreateFromHeif`
+ * with a NULL pointer.
+ */
+
+
+#include "gd.h"
+#include "gdtest.h"
+
+int main()
+{
+ gdImagePtr im;
+
+ im = gdImageCreateFromHeif(NULL);
+ if (!gdTestAssert(im == NULL))
+ gdImageDestroy(im);
+ gdImageHeif(im, NULL); /* noop safely */
+
+ return gdNumFailures();
+}
diff --git a/tests/heif/heif_ptr_double_free.c b/tests/heif/heif_ptr_double_free.c
new file mode 100644
index 0000000..14f1d25
--- /dev/null
+++ b/tests/heif/heif_ptr_double_free.c
@@ -0,0 +1,31 @@
+/**
+ * Test that failure to convert to HEIF returns NULL
+ *
+ * We are creating an image, set its width to zero, and pass this image to
+ * `gdImageHeifPtr()` which is supposed to fail, and as such should return NULL.
+ *
+ * See also <https://github.com/libgd/libgd/issues/381>
+ */
+
+
+#include "gd.h"
+#include "gdtest.h"
+
+
+int main()
+{
+ gdImagePtr src, dst;
+ int size;
+
+ src = gdImageCreateTrueColor(1, 10);
+ gdTestAssert(src != NULL);
+
+ src->sx = 0;
+
+ dst = gdImageHeifPtrEx(src, &size, 0, GD_HEIF_CODEC_HEVC, GD_HEIF_CHROMA_444);
+ gdTestAssert(dst == NULL);
+
+ gdImageDestroy(src);
+
+ return gdNumFailures();
+}
diff --git a/tests/heif/heif_read.c b/tests/heif/heif_read.c
new file mode 100644
index 0000000..469ea31
--- /dev/null
+++ b/tests/heif/heif_read.c
@@ -0,0 +1,23 @@
+/**
+ * Simple test case that confirms the failure of using `gdImageCreateFromHeif`
+ * with a NULL pointer.
+ */
+
+
+#include "gd.h"
+#include "gdtest.h"
+
+int main()
+{
+ gdImagePtr im;
+ FILE *fp;
+
+ fp = gdTestFileOpen2("heif", "label.heic");
+ gdTestAssert(fp != NULL);
+ im = gdImageCreateFromHeif(fp);
+ if (gdTestAssert(im != NULL))
+ gdImageDestroy(im);
+ fclose(fp);
+
+ return gdNumFailures();
+}
diff --git a/tests/heif/label.avif b/tests/heif/label.avif
new file mode 100644
index 0000000..2e84362
--- /dev/null
+++ b/tests/heif/label.avif
Binary files differ
diff --git a/tests/heif/label.heic b/tests/heif/label.heic
new file mode 100644
index 0000000..12814f7
--- /dev/null
+++ b/tests/heif/label.heic
Binary files differ