2011/2/10 michael bouchaud <[email protected]>
> well sure the changelog :P
> I'll make those changes soon
>
> 2011/2/10 Vincent Torri <[email protected]>
>
>
>> Hey,
>>
>>
>> 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)
>> 4) some formatting stuff :
>>
>> if(
>> --> if (
>>
>> + if (image->bits == 16 && htons(0x55aa) != 0x55aa)
>>
>> --> if ((image->bits == 16 && htons(0x55aa)) != 0x55aa)
>>
>> Also the double loop :
>>
>> + for (y = 0; y < image->height; y++)
>> + {
>> + for (x = 0; x < image->width; x++)
>> + {
>> + *dataptr = ARGB_JOIN(0xff, bufptr[0], bufptr[1],
>> bufptr[2]);
>> + dataptr++;
>> + bufptr += 3;
>> + }
>> + }
>>
>> is useless, only one is sufficient (loop over 0 to height*width-1)
>>
>> there are other m4 stuff i would like to change
>>
>> that's all for now, after a small review
>>
>> Vincent
>>
>>
>>
>> ps: I have quickly packaged libraw-lite with autotools, so I provide you
>>> this package to test it quickly
>>>
>>> --
>>> Michaël Bouchaud
>>>
>>
>
>
> --
> Michaël Bouchaud
>
>
>
>
> --
> Michaël Bouchaud
>
>
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 !
--
Michaël Bouchaud
Index: m4/evas_check_loader.m4
===================================================================
--- m4/evas_check_loader.m4 (révision 56939)
+++ m4/evas_check_loader.m4 (copie de travail)
@@ -368,6 +368,26 @@
])
+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="yes"
+evas_image_loader_[]$1[]_cflags="-I/usr/include/libraw_lite"
+evas_image_loader_[]$1[]_libs="-lm -lraw-lite -lstdc++"
+
+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 56939)
+++ 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;
+ }
+ else 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) ||
+ IMG_TOO_BIG(image->width, image->height))
+ {
+ if (IMG_TOO_BIG(image->width, image->height))
+ *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
+ else
+ *error = EVAS_LOAD_ERROR_GENERIC;
+ 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 56939)
+++ src/modules/loaders/Makefile.am (copie de travail)
@@ -74,3 +74,8 @@
endif
endif
+if BUILD_LOADER_RAW
+if !EVAS_STATIC_BUILD_RAW
+SUBDIRS += raw
+endif
+endif
Index: configure.ac
===================================================================
--- configure.ac (révision 56939)
+++ 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"
@@ -137,6 +138,7 @@
want_evas_image_loader_gif="no"
want_evas_image_loader_svg="no"
want_evas_image_loader_tiff="no"
+ want_evas_image_loader_raw="yes"
;;
mingw*)
want_evas_engine_software_gdi="yes"
@@ -145,10 +147,12 @@
want_evas_engine_software_16_ddraw="yes"
want_evas_image_loader_edb="no"
want_evas_image_loader_svg="no"
+ want_evas_image_loader_raw="yes"
;;
darwin*)
want_evas_engine_software_xlib="auto"
want_evas_engine_quartz="auto"
+ want_evas_image_loader_raw="yes"
;;
*)
want_evas_engine_software_xlib="auto"
@@ -819,7 +823,9 @@
EVAS_CHECK_IMAGE_LOADER([WBMP], [${want_evas_image_loader_wbmp}])
+EVAS_CHECK_IMAGE_LOADER([RAW], [${want_evas_image_loader_raw}])
+
#####################################################################
## Cpu based optimizations
@@ -1145,7 +1151,7 @@
AC_MSG_CHECKING(whether to build neon code)
AC_ARG_ENABLE(cpu-neon,
AC_HELP_STRING([--enable-cpu-neon], [build neon code, the code will be
- checked at run time to see if the CPU supports it]),
+ checked at run time to see if the CPU supports it]),
[
if test "x$enableval" = "xyes" ; then
AC_TRY_COMPILE([],
@@ -1595,6 +1601,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 +1708,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 56939)
+++ ChangeLog (copie de travail)
@@ -64,3 +64,8 @@
normal image cache to avoid excess texture uploads when
cycling images often. Should improve performance in some
cases.
+
+2011-02-11 Michael 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
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel