Commit bbdb9f68 authored by Danny Robson's avatar Danny Robson Committed by Martin Nordholts

operations: Add gegl:rgbe-load and gegl:rgbe-save

Add a radiance (rgbe) HDR image format reader and writer. Implements
reading of uncompressed and new-rle scanlines, and writing of
uncompressed scanlines.

The RGBE load and save code is put in a separate library so it's easy
to move out of the GEGL tree or replace with something else.

Also add test cases for both loading and saving.
parent 3dcd343e
AUTOMAKE_OPTIONS = dist-bzip2
# The libs directory needs to be before anything which can depend on its
# libraries, otherwise any potentially rebuilt libs won't be picked up until
# the next run of make.
SUBDIRS=\
libs \
gegl \
operations \
bin \
......
......@@ -1006,6 +1006,8 @@ gegl/module/Makefile
gegl/operation/Makefile
gegl/process/Makefile
gegl/property-types/Makefile
libs/Makefile
libs/rgbe/Makefile
operations/Makefile
operations/affine/Makefile
operations/core/Makefile
......
/Makefile
/Makefile.in
SUBDIRS = rgbe
/.deps
/.libs
/Makefile
/Makefile.in
/librgbe.la
/librgbe_la-rgbe.lo
noinst_LTLIBRARIES = librgbe.la
librgbe_la_SOURCES = rgbe.c rgbe.h
librgbe_la_CFLAGS = $(DEP_CFLAGS) -fPIC
This diff is collapsed.
/* 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 2010 Danny Robson <danny@blubinc.net>
*/
#ifndef __RGBE_H__
#define __RGBE_H__
#include <glib.h>
typedef struct _rgbe_file rgbe_file;
/**
* rgbe_save_path:
* @param path: the path to write the rgbe file to
* @param width: the width of the image
* @param height: the height of the image
* @param pixels: RGB floating point pixel data
*
* Writes raw pixel data into an RGBE format file. The pixel data should be
* 'width x height' elements long, and consist of RGB floats.
*
* Returns TRUE on success.
*/
gboolean rgbe_save_path (const gchar *path,
guint width,
guint height,
gfloat *pixels);
/**
* rgbe_load_path:
* @param path: the path to an RGBE format image file
*
* Reads the metadata for an RGBE formatted image, and allows future access
* to the pixel data and some elements of the image metadata (see
* rgbe_get_size and rgbe_read_scanlines).
*
* The caller should use rgbe_file_free when finished with the file structure.
*
* Returns NULL on failure.
*/
rgbe_file * rgbe_load_path (const gchar *path);
/**
* rgbe_file_free:
* @param file: file structure to dispose of
*
* Destroy resources associated with an RGBE file. The pointer will become
* invalid after this operation. It is safe to pass a NULL pointer to this
* function.
*/
void rgbe_file_free (rgbe_file *file);
/**
* rgbe_get_size:
* @param file: the image file to query
* @param x: pointer to store the width
* @param y: pointer to store the height
*
* Query the image for its width and height.
*
* Returns TRUE on success.
*/
gboolean rgbe_get_size (rgbe_file *file,
guint *x,
guint *y);
/**
* rgbe_read_scanlines:
* @param file: an open image structure to read from
*
* Returns the image's RGBA formatted pixel data. It is the user's
* responsibility to free the memory when finished.
*/
gfloat * rgbe_read_scanlines (rgbe_file *file);
#endif /* __RGBE_H__ */
......@@ -104,5 +104,14 @@ ppm_load_la_LIBADD = $(op_libs)
ppm_save_la_SOURCES = ppm-save.c
ppm_save_la_LIBADD = $(op_libs)
# Dependencies are in our source tree
ops += rgbe-load.la rgbe-save.la
rgbe_load_la_SOURCES = rgbe-load.c
rgbe_load_la_CFLAGS = $(AM_CFLAGS) -I $(top_srcdir)/libs
rgbe_load_la_LIBADD = $(op_libs) $(top_builddir)/libs/rgbe/librgbe.la
rgbe_save_la_SOURCES = rgbe-save.c
rgbe_save_la_CFLAGS = $(AM_CFLAGS) -I $(top_srcdir)/libs
rgbe_save_la_LIBADD = $(op_libs) $(top_builddir)/libs/rgbe/librgbe.la
opdir = $(libdir)/gegl-@GEGL_API_VERSION@
op_LTLIBRARIES = $(ops)
/* 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 2010 Danny Robson <danny@blubinc.net>
*/
#include "config.h"
#include <glib/gi18n-lib.h>
#ifdef GEGL_CHANT_PROPERTIES
gegl_chant_file_path (path, _("File"), "", _("Path of file to load."))
#else
#define GEGL_CHANT_TYPE_SOURCE
#define GEGL_CHANT_C_FILE "rgbe-load.c"
#include "gegl-chant.h"
#include "rgbe/rgbe.h"
#include <errno.h>
#include <stdio.h>
static const gchar* FORMAT = "RGBA float";
static GeglRectangle
gegl_rgbe_load_get_bounding_box (GeglOperation *operation)
{
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
GeglRectangle result = {0,0,0,0};
rgbe_file *file;
guint width, height;
gegl_operation_set_format (operation,
"output",
babl_format (FORMAT));
file = rgbe_load_path (o->path);
if (!file)
goto cleanup;
if (!rgbe_get_size (file, &width, &height))
goto cleanup;
result.width = width;
result.height = height;
cleanup:
rgbe_file_free (file);
return result;
}
static gboolean
gegl_rgbe_load_process (GeglOperation *operation,
GeglBuffer *output,
const GeglRectangle *result)
{
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
gboolean success = FALSE;
gfloat *pixels = NULL;
rgbe_file *file;
guint width, height;
file = rgbe_load_path (o->path);
if (!file)
goto cleanup;
if (!rgbe_get_size (file, &width, &height))
goto cleanup;
if (width != result->width ||
height != result->height)
goto cleanup;
pixels = rgbe_read_scanlines (file);
if (!pixels)
goto cleanup;
gegl_buffer_set (output, result, babl_format (FORMAT), pixels,
GEGL_AUTO_ROWSTRIDE);
success = TRUE;
cleanup:
g_free (pixels);
rgbe_file_free (file);
return success;
}
static GeglRectangle
gegl_rgbe_load_get_cached_region (GeglOperation *operation,
const GeglRectangle *roi)
{
return gegl_rgbe_load_get_bounding_box (operation);
}
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 = gegl_rgbe_load_process;
operation_class->get_bounding_box = gegl_rgbe_load_get_bounding_box;
operation_class->get_cached_region = gegl_rgbe_load_get_cached_region;
operation_class->name = "gegl:rgbe-load";
operation_class->categories = "hidden";
operation_class->description = _("RGBE image loader (Radiance HDR format).");
gegl_extension_handler_register (".hdr", "gegl:rgbe-load");
gegl_extension_handler_register (".pic", "gegl:rgbe-load");
}
#endif
/* 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 2010 Danny Robson <danny@blubinc.net>
*/
#include "config.h"
#include <glib/gi18n-lib.h>
#ifdef GEGL_CHANT_PROPERTIES
gegl_chant_string (path, _("File"), "",
_("Target path and filename, use '-' for stdout."))
#else
#define GEGL_CHANT_TYPE_SINK
#define GEGL_CHANT_C_FILE "rgbe-save.c"
#include "gegl-chant.h"
#include "rgbe/rgbe.h"
static const gchar *FORMAT = "RGB float";
static gboolean
gegl_rgbe_save_process (GeglOperation *operation,
GeglBuffer *input,
const GeglRectangle *rect)
{
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
gfloat *pixels = NULL;
gboolean success = FALSE;
/* Write the scanlines */
pixels = g_malloc (rect->width *
rect->height *
sizeof (pixels[0]) *
babl_format_get_n_components (babl_format (FORMAT)));
gegl_buffer_get (input, 1.0, rect, babl_format (FORMAT), pixels,
GEGL_AUTO_ROWSTRIDE);
if (!rgbe_save_path (o->path, rect->width, rect->height, pixels))
goto cleanup;
success = TRUE;
cleanup:
g_free (pixels);
return success;
}
static void
gegl_chant_class_init (GeglChantClass *klass)
{
GeglOperationClass *operation_class;
GeglOperationSinkClass *sink_class;
operation_class = GEGL_OPERATION_CLASS (klass);
sink_class = GEGL_OPERATION_SINK_CLASS (klass);
sink_class->process = gegl_rgbe_save_process;
sink_class->needs_full = TRUE;
operation_class->name = "gegl:rgbe-save";
operation_class->categories = "output";
operation_class->description =
_("RGBE image saver (Radiance HDR format)");
gegl_extension_handler_register_saver (".hdr", "gegl:rgbe-save");
gegl_extension_handler_register_saver (".pic", "gegl:rgbe-save");
}
#endif
<?xml version='1.0' encoding='UTF-8'?>
<gegl>
<node operation='gegl:rgbe-load'>
<params>
<param name='path'>data/car-stack-eighth.hdr</param>
</params>
</node>
</gegl>
<?xml version='1.0' encoding='UTF-8'?>
<gegl>
<node operation='gegl:scale'>
<params>
<param name='x'>0.25</param>
<param name='y'>0.25</param>
</params>
</node>
<node operation='gegl:load'>
<params>
<param name='path'>data/car-stack.png</param>
</params>
</node>
</gegl>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment