Hi, I'm writing on RAW support for GEGL. I was wondering a few things: 1/ what is the best pixel format I should use for the CFA data. I chose "Y u16" because it is 16-bits (from 10 to 14 actually) and just the luminance. But it there something more suited? 2/ how do I propagate metadata? I need to specify the CFA pattern, the min and max values and other things need for the proper interpolation. I have no idea how to do that from the GeglOperation Attached is the first shot at a patch that approximately output black only. Hub
Index: operations/external/Makefile.am =================================================================== --- operations/external/Makefile.am (revision 2531) +++ operations/external/Makefile.am (working copy) @@ -60,6 +60,13 @@ display_la_CFLAGS = $(SDL_CFLAGS) endif +if HAVE_OPENRAW +ops += openraw.la +openraw_la_SOURCES = openraw.c +openraw_la_LIBADD = $(op_libs) $(OPENRAW_LIBS) +openraw_la_CFLAGS = $(OPENRAW_CFLAGS) +endif + if HAVE_V4L ops += v4l.la v4l_la_SOURCES = v4l.c Index: operations/external/openraw.c =================================================================== --- operations/external/openraw.c (revision 0) +++ operations/external/openraw.c (revision 0) @@ -0,0 +1,191 @@ +/* This file is an image processing operation for GEGL + * + * GEGL is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * GEGL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with GEGL; if not, see <http://www.gnu.org/licenses/>. + * + * Copyright 2006 Øyvind Kolås <pippin@xxxxxxxx> + * Copyright 2008 Hubert Figuière <hub@xxxxxxxxxxxx> + */ + + +#ifdef GEGL_CHANT_PROPERTIES + +gegl_chant_path (path, "File", "", "Path of file to load.") + +#else + +#define GEGL_CHANT_TYPE_SOURCE +#define GEGL_CHANT_C_FILE "openraw.c" + +#include "gegl-chant.h" +#include <stdio.h> +#include <libopenraw/libopenraw.h> + +static gint +query_raw (const gchar *path, + gint *width, + gint *height) +{ + or_error err; + uint32_t x, y; + ORRawDataRef rawdata; + ORRawFileRef rawfile = or_rawfile_new(path, OR_RAWFILE_TYPE_UNKNOWN); + + if (!rawfile) { + return 1; + } + + rawdata = or_rawdata_new(); + err = or_rawfile_get_rawdata(rawfile, rawdata, OR_OPTIONS_NONE); + if(err == OR_ERROR_NONE) { + or_rawdata_dimensions(rawdata, &x, &y); + *width = x; + *height = y; + } + + or_rawdata_release(rawdata); + or_rawfile_release(rawfile); + return (err != OR_ERROR_NONE); +} + + +static gint +gegl_buffer_import_raw (GeglBuffer *gegl_buffer, + const gchar *path, + gint dest_x, + gint dest_y) +{ + ORRawDataRef rawdata; + ORRawFileRef rawfile = or_rawfile_new(path, OR_RAWFILE_TYPE_UNKNOWN); + or_error err; + + if (!rawfile) { + return 1; + } + + rawdata = or_rawdata_new(); + err = or_rawfile_get_rawdata(rawfile, rawdata, OR_OPTIONS_NONE); + + if(err != OR_ERROR_NONE) { + uint32_t x, y; + void *data; + /* TODO take the dest_x and dest_y into account */ + GeglRectangle rect = {0, 0, 0, 0}; + or_rawdata_dimensions(rawdata, &x, &y); + rect.width = x; + rect.height = y; + + data = or_rawdata_data(rawdata); + gegl_buffer_set(gegl_buffer, &rect, babl_format ("Y u16"), + data, GEGL_AUTO_ROWSTRIDE); + } + or_rawdata_release(rawdata); + or_rawfile_release(rawfile); + return (err != OR_ERROR_NONE); +} + + +static GeglRectangle +get_bounding_box (GeglOperation *operation) +{ + GeglChantO *o = GEGL_CHANT_PROPERTIES (operation); + GeglRectangle result = {0,0,0,0}; + gint width, height; + gint status; + gegl_operation_set_format (operation, "output", babl_format ("Y u16")); + status = query_raw (o->path, &width, &height); + + if (status) + { + /*g_warning ("calc have rect of %s failed", o->path);*/ + result.width = 10; + result.height = 10; + } + else + { + result.width = width; + result.height = height; + } + + return result; +} + + +static gboolean +process (GeglOperation *operation, + GeglBuffer *output, + const GeglRectangle *result) +{ + GeglChantO *o = GEGL_CHANT_PROPERTIES (operation); + GeglRectangle rect={0,0}; + gint problem; + + problem = query_raw (o->path, &rect.width, &rect.height); + + if (problem) + { + g_warning ("%s failed to open file %s for reading.", + G_OBJECT_TYPE_NAME (operation), o->path); + return FALSE; + } + + + problem = gegl_buffer_import_raw (output, o->path, 0, 0); + + if (problem) + { + g_warning ("%s failed to open file %s for reading.", + G_OBJECT_TYPE_NAME (operation), o->path); + + return FALSE; + } + + return TRUE; +} + +static void +gegl_chant_class_init (GeglChantClass *klass) +{ + GeglOperationClass *operation_class; + GeglOperationSourceClass *source_class; + + operation_class = GEGL_OPERATION_CLASS (klass); + source_class = GEGL_OPERATION_SOURCE_CLASS (klass); + + source_class->process = process; + operation_class->get_bounding_box = get_bounding_box; + + operation_class->name = "openraw-load"; + operation_class->categories = "hidden"; + operation_class->description = "Camera RAW image loader"; + +// static gboolean done=FALSE; +// if (done) +// return; + /* query libopenraw instead. need a new API */ + gegl_extension_handler_register (".cr2", "openraw-load"); + gegl_extension_handler_register (".CR2", "openraw-load"); + gegl_extension_handler_register (".crw", "openraw-load"); + gegl_extension_handler_register (".CRW", "openraw-load"); + gegl_extension_handler_register (".erf", "openraw-load"); + gegl_extension_handler_register (".ERF", "openraw-load"); + gegl_extension_handler_register (".mrw", "openraw-load"); + gegl_extension_handler_register (".MRW", "openraw-load"); + gegl_extension_handler_register (".nef", "openraw-load"); + gegl_extension_handler_register (".NEF", "openraw-load"); + gegl_extension_handler_register (".dng", "openraw-load"); + gegl_extension_handler_register (".DNG", "openraw-load"); +// done = TRUE; +} + +#endif Index: configure.ac =================================================================== --- configure.ac (revision 2531) +++ configure.ac (working copy) @@ -711,6 +711,20 @@ #################### +# Check for libopenraw +#################### + +dnl check for libopenraw +PKG_CHECK_MODULES(OPENRAW, libopenraw-1.0, + have_openraw="yes", + have_openraw="no (usable libopenraw not found)") +AM_CONDITIONAL(HAVE_OPENRAW, test "x$have_openraw" = "xyes") + +AC_SUBST(OPENRAW_CFLAGS) +AC_SUBST(OPENRAW_LIBS) + + +#################### # Check for graphviz #################### @@ -879,6 +893,7 @@ OpenEXR: $have_openexr rsvg: $have_librsvg SDL: $have_sdl + openraw: $have_openraw asciidoc: $have_asciidoc enscript: $have_enscript graphviz: $have_graphviz
_______________________________________________ Gegl-developer mailing list Gegl-developer@xxxxxxxxxxxxxxxxxxxxxx https://lists.XCF.Berkeley.EDU/mailman/listinfo/gegl-developer