This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository legacy-imlib2.
View the commit online.
commit be721b0335845f4d127f6c9041aa98a1d5e7ee22
Author: Chema Gonzalez <[email protected]>
AuthorDate: Thu Mar 16 11:29:47 2023 -0700
imlib2: added loader for y4m files (uses liby4m and libyuv)
Implemented just `_load()` for now.
Summary:
Implements a loader for y4m images. Uses liby4m and libyuv.
Only implements the `_load()` function as of now
Tested:
```
$ ./configure
...
Configuration Options Summary:
Image loaders:
Regular image loaders
GIF.....................: yes
HEIF....................: yes
Y4M.....................: yes
...
$ make -j
...
$ sudo make install
...
$ feh image.y4m
-- image shows up
```
Tested with yuv420p, yuv422p, and yuv444p images.
---
configure.ac | 2 +
src/modules/loaders/Makefile.am | 9 +++
src/modules/loaders/loader_y4m.c | 145 +++++++++++++++++++++++++++++++++++++++
3 files changed, 156 insertions(+)
diff --git a/configure.ac b/configure.ac
index fbcda4d..340596b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -194,6 +194,7 @@ loader_check_gif() {
EC_LOADER_CHECK(GIF, auto, , loader_check_gif)
EC_LOADER_CHECK(HEIF, auto, libheif)
+EC_LOADER_CHECK(Y4M, auto, liby4m libyuv)
EC_LOADER_CHECK(JPEG, auto, libjpeg)
EC_LOADER_CHECK(J2K, auto, libopenjp2)
EC_LOADER_CHECK(JXL, auto, libjxl libjxl_threads)
@@ -305,6 +306,7 @@ echo "Image loaders:"
echo " Regular image loaders"
echo " GIF.....................: $gif_ok"
echo " HEIF....................: $heif_ok"
+echo " Y4M.....................: $y4m_ok"
echo " JPEG....................: $jpeg_ok"
echo " J2K.....................: $j2k_ok"
echo " JXL.....................: $jxl_ok"
diff --git a/src/modules/loaders/Makefile.am b/src/modules/loaders/Makefile.am
index cf359e8..75e493b 100644
--- a/src/modules/loaders/Makefile.am
+++ b/src/modules/loaders/Makefile.am
@@ -21,6 +21,9 @@ endif
if BUILD_HEIF_LOADER
pkg_LTLIBRARIES += heif.la
endif
+if BUILD_Y4M_LOADER
+pkg_LTLIBRARIES += y4m.la
+endif
if BUILD_JPEG_LOADER
pkg_LTLIBRARIES += jpeg.la
endif
@@ -91,6 +94,12 @@ heif_la_LDFLAGS = -module -avoid-version -Wl,-z,nodelete
heif_la_LIBADD = $(HEIF_LIBS) $(top_builddir)/src/lib/libImlib2.la
heif_la_LIBTOOLFLAGS = --tag=disable-static
+y4m_la_SOURCES = loader_y4m.c
+y4m_la_CPPFLAGS = $(Y4M_CFLAGS) $(AM_CPPFLAGS)
+y4m_la_LDFLAGS = -module -avoid-version -Wl,-z,nodelete
+y4m_la_LIBADD = $(Y4M_LIBS) $(top_builddir)/src/lib/libImlib2.la
+y4m_la_LIBTOOLFLAGS = --tag=disable-static
+
ico_la_SOURCES = loader_ico.c
ico_la_LDFLAGS = -module -avoid-version
ico_la_LIBADD = $(top_builddir)/src/lib/libImlib2.la
diff --git a/src/modules/loaders/loader_y4m.c b/src/modules/loaders/loader_y4m.c
new file mode 100644
index 0000000..b44fc31
--- /dev/null
+++ b/src/modules/loaders/loader_y4m.c
@@ -0,0 +1,145 @@
+/*
+ * Loader for Y4M images.
+ *
+ * Only loads the image.
+ */
+#include "config.h"
+#include "Imlib2_Loader.h"
+
+#include <fcntl.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <y4mTypes.h>
+#include <liby4m.h>
+#include <libyuv.h>
+
+static const char *const _formats[] = { "y4m" };
+
+// Notes:
+// * y4m does not support alpha channels.
+
+// in the following code, "encoded" refers to YUV data (as present in a
+// y4m file).
+static int
+_load(ImlibImage * im, int load_data)
+{
+ int rc = LOAD_FAIL;
+ int broken_image = 0;
+ uint32_t *ptr = NULL;
+
+ /* we do not support the file being loaded from memory */
+ if (!im->fi->fp)
+ goto quit;
+
+ /* guess whether this is a y4m file */
+ const char *fptr = im->fi->fdata;
+
+ if (strncmp(fptr, "YUV4MPEG2 ", 10) != 0)
+ goto quit;
+
+ /* format accepted */
+ rc = LOAD_BADIMAGE;
+
+ /* liby4m insists of getting control of the fp, so we will dup it */
+ FILE *fp2 = fdopen(dup(fileno(im->fi->fp)), "r");
+
+ /* read the input file pointer */
+ y4mFile_t y4m_file;
+
+ if (y4mOpenFp(&y4m_file, fp2))
+ {
+ broken_image = 1;
+ goto clean;
+ }
+
+ /* read image info */
+ im->w = y4mGetWidth(&y4m_file);
+ im->h = y4mGetHeight(&y4m_file);
+ if (!IMAGE_DIMENSIONS_OK(im->w, im->h))
+ goto clean;
+ /* y4m does not support alpha channels */
+ im->has_alpha = 0;
+
+ /* check whether we are done */
+ if (!load_data)
+ goto clean;
+
+ /* load data */
+ /* allocate space for the raw image */
+ ptr = __imlib_AllocateData(im);
+ if (!ptr)
+ goto clean;
+ uint8_t *data = "" *) ptr;
+ char *input_ptr = y4mGetFrameDataPointer(&y4m_file);
+
+ /* convert input to ARGB (as expected by imlib) */
+ if (y4m_file.colourspace == COLOUR_C422)
+ {
+ if (I422ToARGB((const uint8_t *)input_ptr, // src_y,
+ im->w, // src_stride_y
+ (const uint8_t *)(input_ptr + im->w * im->h), // src_u
+ im->w / 2, // src_stride_u
+ (const uint8_t *)(input_ptr + im->w * im->h * 3 / 2), // src_v
+ im->w / 2, // src_stride_v
+ data, // dst_bgra
+ im->w * 4, // dst_stride_bgra
+ im->w, // width
+ im->h) != 0) // height
+ goto clean;
+
+ }
+ else if (y4m_file.colourspace == COLOUR_C444)
+ {
+ if (I444ToARGB((const uint8_t *)input_ptr, // src_y,
+ im->w, // src_stride_y
+ (const uint8_t *)(input_ptr + im->w * im->h), // src_u
+ im->w, // src_stride_u
+ (const uint8_t *)(input_ptr + im->w * im->h * 2), // src_v
+ im->w, // src_stride_v
+ data, // dst_bgra
+ im->w * 4, // dst_stride_bgra
+ im->w, // width
+ im->h) != 0) // height
+ goto clean;
+
+ }
+ else
+ { /* 4:2:0 */
+ if (I420ToARGB((const uint8_t *)input_ptr, // src_y,
+ im->w, // src_stride_y
+ (const uint8_t *)(input_ptr + im->w * im->h), // src_u
+ im->w / 2, // src_stride_u
+ (const uint8_t *)(input_ptr + im->w * im->h * 5 / 4), // src_v
+ im->w / 2, // src_stride_v
+ data, // dst_bgra
+ im->w * 4, // dst_stride_bgra
+ im->w, // width
+ im->h) != 0) // height
+ goto clean;
+ }
+
+ rc = LOAD_SUCCESS;
+
+ /* implement progress callback */
+ if (im->lc)
+ __imlib_LoadProgressRows(im, 0, im->h);
+
+ clean:
+ y4mCloseFile(&y4m_file);
+ if (broken_image == 1)
+ {
+ QUIT_WITH_RC(LOAD_BADFILE);
+ }
+ if (!load_data)
+ QUIT_WITH_RC(LOAD_SUCCESS);
+ if (!ptr)
+ QUIT_WITH_RC(LOAD_OOM);
+ quit:
+ return rc;
+}
+
+IMLIB_LOADER(_formats, _load, NULL);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.