Sure it was here :D. And I'll be happy if this go in !

2011/2/19 Carsten Haitzler <ras...@rasterman.com>

> On Fri, 11 Feb 2011 15:21:42 +0100 (CET) Vincent Torri <
> vto...@univ-evry.fr>
> said:
>
> fyi = i'm waiting on an updated patch - if you can provide one that
> actually
> detects libraw-lite as suggested below... i'd be happy to put it in.
>
> > On Fri, 11 Feb 2011, michael bouchaud wrote:
> >
> > > 2011/2/11 Vincent Torri <vto...@univ-evry.fr>
> > >
> > >
> > >>
> > >> On Fri, 11 Feb 2011, michael bouchaud wrote:
> > >>
> > >>  On Thu, 10 Feb 2011, michael bouchaud wrote:
> > >>>>>
> > >>>>>  Hi, everybody I have wrote an evas_image loader for raw image
> type. I
> > >>>>> use
> > >>>>>
> > >>>>>> libraw-lite to do this jobs, who is licensed under lgpl
> > >>>>>> This is not perfect, so please review this code. Any comments are
> > >>>>>> welcome
> > >>>>>> !
> > >>>>>>
> > >>>>>>
> > >>>>> some things:
> > >>>>>
> > >>>>> 1) ChangeLog
> > >>>>> 2) remove all the Evil stuff, I'll test it later on Windows
> > >>>>> 3) the check in EVAS_CHECK_LOADER_DEP_RAW is wrong, use pkg-config
> (see
> > >>>>> EVAS_CHECK_LOADER_DEP_EET for example)
> > >>>>>
> > >>>>
> > >>>>  This is a new version of this patch. I don't change the m4 macro
> because
> > >>> libraw_lite aren't correctly packaged for now. So pkg-config can't
> detect
> > >>> them. I added an entry in changelog and change the double loop.  I
> have
> > >>> also
> > >>> changed the header loading code.
> > >>> Any comments still are welcome !
> > >>>
> > >>
> > >> he problem is that if someone installs libraw in another dir than
> /usr, the
> > >> detection will fail.
> > >>
> > >> There is a .pc file that is provided with libraw (actually, there are
> 2
> > >> .pc, one for thread safe libn another for non thread safe lib). You
> should
> > >> (must) use one of them
> > >>
> > >> Vincent
> > >>
> > >
> > > yeah 2 pc files are given with libraw (under gpl) but not with
> libraw-lite
> > > (under lgpl). Sure the test of this macro is definitely bad. But I
> don't
> > > know how to detect this without pc files. go here
> > > http://www.libraw.org/libraw-lite to download libraw-lite not libraw
> >
> > haaa, i certainly downloaded libraw. Ok, then look at the tiff m4 macro
> > (note that it has 3 AC_CHECK_LIB because the name of the lib is not
> always
> > the same and because it can have some dependencies. You should just use
> > one AC_CHECK_LIB
> >
> > Vincent
> >
> >
> ------------------------------------------------------------------------------
> > The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
> > Pinpoint memory and threading errors before they happen.
> > Find and fix more than 250 security defects in the development cycle.
> > Locate bottlenecks in serial and parallel code that limit performance.
> > http://p.sf.net/sfu/intel-dev2devfeb
> > _______________________________________________
> > enlightenment-devel mailing list
> > enlightenment-devel@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/enlightenment-devel
> >
>
>
> --
> ------------- Codito, ergo sum - "I code, therefore I am" --------------
> The Rasterman (Carsten Haitzler)    ras...@rasterman.com
>
>


-- 
Michaël Bouchaud
Index: m4/evas_check_loader.m4
===================================================================
--- m4/evas_check_loader.m4     (révision 57210)
+++ m4/evas_check_loader.m4     (copie de travail)
@@ -368,6 +368,38 @@
 
 ])
 
+dnl use: EVAS_CHECK_LOADER_DEP_RAW(loader, want_static[, ACTION-IF-FOUND[, 
ACTION-IF-NOT-FOUND]])
+
+AC_DEFUN([EVAS_CHECK_LOADER_DEP_RAW],
+[
+
+have_dep="no"
+evas_image_loader_[]$1[]_cflags=""
+evas_image_loader_[]$1[]_libs=""
+
+AC_CHECK_HEADER([libraw_lite/libraw.h], [have_dep="yes"])
+if test "x${have_dep}"  = "xyes" ; then
+   AC_CHECK_LIB([raw-lite],
+      [libraw_init],
+      [
+       evas_image_loader_[]$1[]_libs=""
+       evas_image_loader_[]$1[]_cflags=""
+      ],
+      [have_dep="no"]
+   )
+fi
+
+AC_SUBST([evas_image_loader_$1_cflags])
+AC_SUBST([evas_image_loader_$1_libs])
+
+if test "x${have_dep}" = "xyes" ; then
+  m4_default([$3], [:])
+else
+  m4_default([$4], [:])
+fi
+
+])
+
 dnl use: EVAS_CHECK_IMAGE_LOADER(loader, want_loader, macro)
 
 
Index: src/lib/engines/common/evas_image_load.c
===================================================================
--- src/lib/engines/common/evas_image_load.c    (révision 57210)
+++ src/lib/engines/common/evas_image_load.c    (copie de travail)
@@ -30,12 +30,28 @@
    { "pnm", "pmaps" },
    { "bmp", "bmp" },
    { "tga", "tga" },
-   { "wbmp", "wbmp" }
+   { "wbmp", "wbmp" },
+   { "arw", "raw" },
+   { "sr2", "raw" },
+   { "srf", "raw" },
+   { "cr2", "raw" },
+   { "crw", "raw" },
+   { "dcr", "raw" },
+   { "dng", "raw" },
+   { "k25", "raw" },
+   { "kdc", "raw" },
+   { "mrw", "raw" },
+   { "nef", "raw" },
+   { "orf", "raw" },
+   { "raw", "raw" },
+   { "pef", "raw" },
+   { "raf", "raw" },
+   { "x3f", "raw" },
 };
 
 static const char *loaders_name[] =
 {
-  "png", "jpeg", "eet", "xpm", "tiff", "gif", "svg", "pmaps", "edb", "bmp", 
"tga", "wbmp"
+  "png", "jpeg", "eet", "xpm", "tiff", "gif", "svg", "pmaps", "edb", "bmp", 
"tga", "wbmp", "raw",
 };
 
 struct evas_image_foreach_loader_data
Index: src/modules/loaders/raw/evas_image_load_raw.c
===================================================================
--- src/modules/loaders/raw/evas_image_load_raw.c       (révision 0)
+++ src/modules/loaders/raw/evas_image_load_raw.c       (révision 0)
@@ -0,0 +1,233 @@
+#define _XOPEN_SOURCE
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#include <math.h>
+#include <libraw.h>
+#include <netinet/in.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+
+#include "evas_common.h"
+#include "evas_private.h"
+
+
+static Eina_Bool evas_image_load_file_head_raw(Image_Entry *ie, const char 
*file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
+static Eina_Bool evas_image_load_file_data_raw(Image_Entry *ie, const char 
*file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
+
+static Evas_Image_Load_Func evas_image_load_raw_func =
+{
+   EINA_TRUE,
+   evas_image_load_file_head_raw,
+   evas_image_load_file_data_raw
+};
+
+static Eina_Bool
+evas_image_load_file_head_raw(Image_Entry *ie, const char *file, const char 
*key, int *error)
+{
+   int fd;
+   unsigned char *seg = MAP_FAILED, *filedata;
+   struct stat ss;
+   int ret = -1;
+   libraw_data_t* raw_data = NULL;
+   libraw_processed_image_t *image = NULL;
+
+   fd = open(file, O_RDONLY);
+
+   *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
+   if (fd < 0) return EINA_FALSE;
+
+   *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
+
+   if (stat(file, &ss) < 0) goto close_file;
+
+   seg = mmap(0, ss.st_size, PROT_READ, MAP_SHARED, fd, 0);
+   if (seg == MAP_FAILED) goto close_file;
+   filedata = seg;
+
+   raw_data = libraw_init(0);
+
+   if ((ret = libraw_open_buffer(raw_data, seg, ss.st_size)) != LIBRAW_SUCCESS)
+     goto close_file;
+
+   if ((ret = libraw_adjust_sizes_info_only(raw_data)) != LIBRAW_SUCCESS)
+     {
+        if (LIBRAW_FATAL_ERROR(ret))
+          goto close_file;
+     }
+   if ((raw_data->sizes.width < 1) || (raw_data->sizes.height < 1) ||
+       (raw_data->sizes.width > IMG_MAX_SIZE) ||
+       (raw_data->sizes.height > IMG_MAX_SIZE))
+     {
+        *error = EVAS_LOAD_ERROR_GENERIC;
+        goto close_file;
+     }
+   if (IMG_TOO_BIG(raw_data->sizes.width, raw_data->sizes.height))
+     {
+        *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
+        goto close_file;
+     }
+
+   ie->w = raw_data->sizes.width;
+   ie->h = raw_data->sizes.height;
+   if (seg != MAP_FAILED) munmap(seg, ss.st_size);
+   if (raw_data)
+     libraw_close(raw_data);
+   if (image)
+     free (image);
+   close(fd);
+   *error = EVAS_LOAD_ERROR_NONE;
+   return EINA_TRUE;
+close_file:
+   if (seg != MAP_FAILED) munmap(seg, ss.st_size);
+   if (raw_data)
+     libraw_close(raw_data);
+   if (image)
+     free (image);
+   close(fd);
+   return EINA_FALSE;
+}
+
+static Eina_Bool
+evas_image_load_file_data_raw(Image_Entry *ie, const char *file, const char 
*key __UNUSED__, int *error)
+{
+   int fd;
+   int ret = -1;
+   int count;
+   unsigned char *seg = MAP_FAILED, *filedata;
+   struct stat ss;
+   unsigned int *surface, *dataptr;
+   unsigned char *bufptr, *bufend;
+   libraw_data_t* raw_data = NULL;
+   libraw_processed_image_t *image = NULL;
+
+   fd = open(file, O_RDONLY);
+
+   *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
+   if (fd < 0) return EINA_FALSE;
+
+   *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
+
+   if (stat(file, &ss) < 0) goto close_file;
+
+   seg = mmap(0, ss.st_size, PROT_READ, MAP_SHARED, fd, 0);
+   if (seg == MAP_FAILED) goto close_file;
+   filedata = seg;
+
+   raw_data = libraw_init(0);
+
+   raw_data->params.half_size = 0; /* dcraw -h */
+   raw_data->params.user_qual = 2; /* dcraw -h */
+
+   if ((ret = libraw_open_buffer(raw_data, seg, ss.st_size)) != LIBRAW_SUCCESS)
+     goto close_file;
+
+   if ((ret = libraw_unpack(raw_data)) != LIBRAW_SUCCESS)
+     goto close_file;
+
+   if ((ret = libraw_dcraw_process(raw_data)) != LIBRAW_SUCCESS)
+     {
+        if(LIBRAW_FATAL_ERROR(ret))
+          goto close_file;
+     }
+
+   image = dcraw_make_mem_image(raw_data,&ret);
+   if (image)
+     {
+        if ((image->width < 1) || (image->height < 1) ||
+            (image->width > IMG_MAX_SIZE) || (image->height > IMG_MAX_SIZE))
+          {
+             *error = EVAS_LOAD_ERROR_GENERIC;
+             goto close_file;
+          }
+        else if (IMG_TOO_BIG(image->width, image->height))
+          {
+             *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
+             goto close_file;
+          }
+        ie->w = image->width;
+        ie->h = image->height;
+        evas_cache_image_surface_alloc(ie, image->width, image->height);
+        surface = evas_cache_image_pixels(ie);
+        if (!surface)
+          {
+             *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
+             goto close_file;
+          }
+        if (image->type != LIBRAW_IMAGE_BITMAP)
+          goto close_file;
+        if (image->colors != 3)
+          goto close_file;
+#define SWAP(a,b) { a ^= b; a ^= (b ^= a); }
+        if ((image->bits == 16) && (htons(0x55aa)) != 0x55aa)
+          for (count = 0; count < image->data_size; count += 2)
+            SWAP(image->data[count], image->data[count + 1]);
+#undef SWAP
+        dataptr = surface;
+        bufptr = image->data;
+        for (count = image->width * image->height; count > 0; --count)
+          {
+             *dataptr = ARGB_JOIN(0xff, bufptr[0], bufptr[1], bufptr[2]);
+             dataptr++;
+             bufptr += 3;
+          }
+        free(image);
+     }
+   libraw_close(raw_data);
+
+//=============================================//
+   evas_common_image_premul(ie);
+
+   if (seg != MAP_FAILED) munmap(seg, ss.st_size);
+   *error = EVAS_LOAD_ERROR_NONE;
+   close(fd);
+   return EINA_TRUE;
+
+close_file:
+   if (seg != MAP_FAILED) munmap(seg, ss.st_size);
+   if (raw_data)
+     libraw_close(raw_data);
+   close(fd);
+   return EINA_FALSE;
+}
+
+static int
+module_open(Evas_Module *em)
+{
+   if (!em) return 0;
+   em->functions = (void *)(&evas_image_load_raw_func);
+   return 1;
+}
+
+static void
+module_close(Evas_Module *em __UNUSED__)
+{
+}
+
+static Evas_Module_Api evas_modapi =
+{
+   EVAS_MODULE_API_VERSION,
+   "raw",
+   "none",
+   {
+     module_open,
+     module_close
+   }
+};
+
+EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_IMAGE_LOADER, image_loader, raw);
+
+#ifndef EVAS_STATIC_BUILD_RAW
+EVAS_EINA_MODULE_DEFINE(image_loader, raw);
+#endif
+
Index: src/modules/loaders/raw/Makefile.am
===================================================================
--- src/modules/loaders/raw/Makefile.am (révision 0)
+++ src/modules/loaders/raw/Makefile.am (révision 0)
@@ -0,0 +1,32 @@
+
+MAINTAINERCLEANFILES = Makefile.in
+
+AM_CPPFLAGS = \
+-I. \
+-I$(top_srcdir)/src/lib \
+-I$(top_srcdir)/src/lib/include \
+@FREETYPE_CFLAGS@ \
+@EINA_CFLAGS@ \
+@evas_image_loader_raw_cflags@
+
+
+if BUILD_LOADER_RAW
+if !EVAS_STATIC_BUILD_RAW
+
+pkgdir = $(libdir)/evas/modules/loaders/raw/$(MODULE_ARCH)
+pkg_LTLIBRARIES = module.la
+
+module_la_SOURCES = evas_image_load_raw.c
+
+module_la_LIBADD = @EINA_LIBS@ @evas_image_loader_raw_libs@ @EVIL_LIBS@ 
$(top_builddir)/src/lib/libevas.la
+module_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -module 
-avoid-version
+module_la_LIBTOOLFLAGS = --tag=disable-static
+
+else
+
+noinst_LTLIBRARIES = libevas_loader_raw.la
+libevas_loader_raw_la_SOURCES = evas_image_load_raw.c
+libevas_loader_raw_la_LIBADD = @evas_image_loader_raw_libs@
+
+endif
+endif
Index: src/modules/loaders/Makefile.am
===================================================================
--- src/modules/loaders/Makefile.am     (révision 57210)
+++ src/modules/loaders/Makefile.am     (copie de travail)
@@ -74,3 +74,9 @@
 endif
 endif
 
+if BUILD_LOADER_RAW
+if !EVAS_STATIC_BUILD_RAW
+SUBDIRS += raw
+endif
+endif
+
Index: evas.spec.in
===================================================================
--- evas.spec.in        (révision 57210)
+++ evas.spec.in        (copie de travail)
@@ -45,6 +45,7 @@
 %bcond_without module_loader_xpm
 %bcond_without module_loader_bmp
 %bcond_without module_loader_tga
+%bcond_without module_loader_raw
 
 # This just keeps a missing doxygen from killing the build.
 %define _missing_doc_files_terminate_build 0
@@ -61,6 +62,7 @@
 %define ac_with_module_loader_svg 
--%{?with_module_loader_svg:en}%{!?with_module_loader_svg:dis}able-image-loader-svg
 %define ac_with_module_loader_bmp 
--%{?with_module_loader_bmp:en}%{!?with_module_loader_bmp:dis}able-image-loader-bmp
 %define ac_with_module_loader_tga 
--%{?with_module_loader_tga:en}%{!?with_module_loader_tga:dis}able-image-loader-tga
+%define ac_with_module_loader_raw 
--%{?with_module_loader_raw:en}%{!?with_module_loader_raw:dis}able-image-loader-raw
 %define ac_with_module_saver_eet 
--%{?with_module_saver_eet:en}%{!?with_module_saver_eet:dis}able-image-saver-eet
 %define ac_with_module_saver_jpeg 
--%{?with_module_saver_jpeg:en}%{!?with_module_saver_jpeg:dis}able-image-saver-jpeg
 %define ac_with_module_saver_png 
--%{?with_module_saver_png:en}%{!?with_module_saver_png:dis}able-image-saver-png
@@ -256,6 +258,15 @@
 TGA Image loader module for Evas
 %endif
 
+%if %{with module_loader_raw}
+%package module_loader_raw
+Summary: RAW Image loader module for Evas
+Group: System Environment/Libraries
+BuildRequires: libraw-lite
+%description module_loader_raw
+RAW Image loader module for Evas
+%endif
+
 %package module_engine_software_generic
 Summary: Software X11 rendering engine module for Evas
 Group: System Environment/Libraries
Index: configure.ac
===================================================================
--- configure.ac        (révision 57210)
+++ configure.ac        (copie de travail)
@@ -126,6 +126,7 @@
 want_evas_image_loader_bmp="yes"
 want_evas_image_loader_tga="yes"
 want_evas_image_loader_wbmp="yes"
+want_evas_image_loader_raw="yes"
 
 want_evas_font_loader_eet="yes"
 
@@ -819,7 +820,9 @@
 
 EVAS_CHECK_IMAGE_LOADER([WBMP], [${want_evas_image_loader_wbmp}])
 
+EVAS_CHECK_IMAGE_LOADER([RAW], [${want_evas_image_loader_raw}])
 
+
 #####################################################################
 ## Cpu based optimizations
 
@@ -1595,6 +1598,7 @@
 src/modules/loaders/xpm/Makefile
 src/modules/loaders/bmp/Makefile
 src/modules/loaders/tga/Makefile
+src/modules/loaders/raw/Makefile
 src/modules/loaders/svg/Makefile
 src/modules/loaders/pmaps/Makefile
 src/modules/loaders/wbmp/Makefile
@@ -1701,6 +1705,7 @@
 echo "  BMP.....................: $have_evas_image_loader_bmp"
 echo "  TGA.....................: $have_evas_image_loader_tga"
 echo "  WBMP....................: $have_evas_image_loader_wbmp"
+echo "  RAW.....................: $have_evas_image_loader_raw"
 echo
 echo "Font Sourcing Systems:"
 echo "  EET.....................: $have_evas_font_loader_eet"
Index: ChangeLog
===================================================================
--- ChangeLog   (révision 57210)
+++ ChangeLog   (copie de travail)
@@ -116,3 +116,6 @@
        * Fixed bug with memory access of old utf8 string when
           comparing prev and cur state with text obj.
 
+2011-02-21 Michaël Bouchaud (yoz)
+
+        * Added raw loader
------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to