Commit 14d360ba authored by Øyvind Kolås's avatar Øyvind Kolås

Made the tiled buffer babl-aware

parent 2f29f457
2006-06-02 Øyvind Kolås <pippin@gimp.org>
Made the gegl-buffer babl aware.
* configure.in: Added babl as a dependency
* gegl.pc.in: Added babl as a dependency
* gegl/Makefile.am: Added babl to includes / LDFLAGS
* gegl/buffer/Makefile.am: Install header files (just dumping then in
the GEGL dir for now).
* gegl/buffer/gegl-buffer.[ch]: (gegl_buffer_get_format),
(gegl_buffer_px_size), (gegl_buffer_size), (gegl_buffer_iterate),
(gegl_buffer_set), (gegl_buffer_get), (gegl_buffer_set_fmt),
(gegl_buffer_get_fmt): Added methods to set/get linear buffers through
babl backed conversions.
* gegl/buffer/gegl-storage.c: (get_property), (set_property),
(gegl_storage_dispose), (gegl_storage_constructor): completing renaming from
buffer->storage.
* gegl/buffer/gegl-tile-backend.c: (get_property), (set_property),
(constructor), (gegl_tile_backend_class_init):
* gegl/buffer/gegl-tile-backend.h: correctly set format when passed in
to constructor.
* gegl/gegl-init.c: (gegl_init), (gegl_exit): init/deinit babl.
* gegl/gegl.h: include gegl-buffer as well.
2006-06-02 Øyvind Kolås <pippin@gimp.org>
Made child rectangles be computed correctly when there are multiple
......
......@@ -201,6 +201,10 @@ AC_CHECK_LIB(lcms, cmsCreateProofingTransform, [
AC_SUBST(LCMS_LIBS)
AM_CONDITIONAL(HAVE_LCMS, test $have_lcms = yes)
PKG_CHECK_MODULES(BABL, babl >= 0.0)
AC_SUBST(BABL_CFLAGS)
AC_SUBST(BABL_LIBS)
AC_OUTPUT([
Makefile
......
......@@ -6,6 +6,6 @@ includedir=@includedir@
Name: Gegl
Description: Gegl Graphical Library
Version: @VERSION@
Requires: @GLIB_PACKAGES@
Requires: @GLIB_PACKAGES@ babl
Libs: -L${libdir} -lgegl-@GEGL_API_VERSION@
Cflags: -I${includedir}/gegl-1.0/gegl
......@@ -44,12 +44,12 @@ libgegl_1_0_la_LIBADD = $(libbuffer)
INCLUDES = \
-I$(top_srcdir) \
@DEP_CFLAGS@
@DEP_CFLAGS@ @BABL_CFLAGS@
AM_LDFLAGS = \
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
-no-undefined \
@DEP_LIBS@
@DEP_LIBS@ @BABL_LIBS@
libgeglincludedir = $(includedir)/gegl-1.0/gegl
......
......@@ -32,9 +32,12 @@ BUFFER_headers = \
gegl-tile-traits.h
libbuffer_la_SOURCES = $(BUFFER_sources) $(BUFFER_headers)
libbufferinclude_HEADERS = $(BUFFER_headers)
libbufferincludedir = $(includedir)/gegl-1.0/gegl/
INCLUDES = \
-I$(top_srcdir) \
-I$(top_srcdir)/gegl \
@DEP_CFLAGS@
@DEP_CFLAGS@ @BABL_CFLAGS@
/* For the storeback mechanism to work when shifted, both the shiftcount (or just
* the shifted tile indices) as well as the modulo remainder needs to be stored for
* the unref'ing of the tile.
*
* shifting should be transparent to the buffer code,.. or is the acess truely unnaligned?
*
*/
/* This file is part of GEGL.
*
* This library is free software; you can redistribute it and/or
......@@ -545,7 +537,7 @@ void *gegl_buffer_get_format (GeglBuffer *buffer)
g_assert (buffer);
if (buffer->format != NULL)
return buffer->format;
return gegl_buffer_backend (buffer)->babl_format;
return gegl_buffer_backend (buffer)->format;
}
void
......@@ -575,22 +567,38 @@ gegl_buffer_is_dirty (GeglBuffer *buffer,
GEGL_TILE_IS_DIRTY, x, y, z, NULL);
}
gint gegl_buffer_px_size (GeglBuffer *buffer)
{
return gegl_buffer_storage (buffer)->px_size;
}
gint gegl_buffer_size (GeglBuffer *buffer)
{
return gegl_buffer_storage (buffer)->px_size * buffer->width * buffer->height;
}
/* the setter and getter were merged into a single buf iterator,
* this iterator should be refactored to provide a linear buffer object
* that is iterating. Making it easier to reuse for other optimized traversals.
*
* babl conversion should probably be done on a tile by tile, or even scanline by
* scanline basis instead of allocating large temporary buffers. (using babl for "memcpy")
*/
#include <string.h>
static void
gegl_buffer_iterate (GeglBuffer *buffer,
guchar *buf,
void *buf,
gboolean write)
{
gint width = buffer->width;
gint height = buffer->height;
gint tile_width = gegl_buffer_storage (buffer)->tile_width;
gint tile_height = gegl_buffer_storage (buffer)->tile_height;
gint px_size = gegl_buffer_px_size (buffer);
gint bufy = 0;
while (bufy < height)
......@@ -621,8 +629,8 @@ gegl_buffer_iterate (GeglBuffer *buffer,
row++)
{
gint pixels;
guchar *bp = (buf) + ((bufy + row - offsety) * width + bufx) * 4;
guchar *tp = (dst) + (row * tile_width + offsetx) * 4;
guchar *bp = ((guchar*)buf) + ((bufy + row - offsety) * width + bufx) * px_size;
guchar *tp = ((guchar*)dst) + (row * tile_width + offsetx) * px_size;
if (width + offsetx - bufx < tile_width)
pixels = (width + offsetx - bufx) - offsetx;
......@@ -630,9 +638,9 @@ gegl_buffer_iterate (GeglBuffer *buffer,
pixels = tile_width - offsetx;
if (write)
memcpy (tp, bp, pixels * 4);
memcpy (tp, bp, pixels * px_size);
else
memcpy (bp, tp, pixels * 4);
memcpy (bp, tp, pixels * px_size);
}
}
if (write)
......@@ -647,7 +655,7 @@ gegl_buffer_iterate (GeglBuffer *buffer,
void
gegl_buffer_set (GeglBuffer *buffer,
guchar *src)
void *src)
{
gboolean write;
gegl_buffer_iterate (buffer, src, write = TRUE);
......@@ -655,8 +663,57 @@ gegl_buffer_set (GeglBuffer *buffer,
void
gegl_buffer_get (GeglBuffer *buffer,
guchar *dst)
void *dst)
{
gboolean write;
gegl_buffer_iterate (buffer, dst, write = FALSE);
}
#ifdef BABL
#undef BABL
#endif
#define BABL(o) ((Babl*)(o))
#ifdef FMTPXS
#undef FMTPXS
#endif
#define FMTPXS(fmt) (BABL(fmt)->format.bytes_per_pixel)
void
gegl_buffer_set_fmt (GeglBuffer *buffer,
void *src,
void *format)
{
guchar *tmp;
if (buffer->format == format)
{
gegl_buffer_set (buffer, src);
}
tmp = g_malloc (gegl_buffer_size (buffer));
g_assert (tmp);
babl_process (babl_fish (format, buffer->format),
src, tmp, buffer->width * buffer->height);
gegl_buffer_set (buffer, tmp);
g_free (tmp);
}
void
gegl_buffer_get_fmt (GeglBuffer *buffer,
void *dst,
void *format)
{
guchar *tmp;
if (buffer->format == format)
{
gegl_buffer_get (buffer, dst);
}
tmp = g_malloc (gegl_buffer_size (buffer));
g_assert (tmp);
gegl_buffer_get (buffer, tmp);
babl_process (babl_fish (buffer->format, format),
tmp, dst, buffer->width * buffer->height);
g_free (tmp);
}
......@@ -21,6 +21,7 @@
#include <glib-object.h>
#include "gegl-buffer-types.h"
#include <babl.h>
#ifndef _GEGL_BUFFER_H
#define _GEGL_BUFFER_H
......@@ -62,16 +63,12 @@ struct _GeglBufferClass
GType gegl_buffer_get_type (void) G_GNUC_CONST;
void gegl_buffer_set (GeglBuffer *buffer,
guchar *src);
void gegl_buffer_get (GeglBuffer *buffer,
guchar *dst);
void * gegl_buffer_get_format (GeglBuffer *buffer);
gint gegl_buffer_px_size (GeglBuffer *buffer);
gint gegl_buffer_size (GeglBuffer *buffer);
/***********************/
......@@ -90,4 +87,18 @@ gboolean gegl_buffer_is_dirty (GeglBuffer *buffer,
gint x,
gint y);
void gegl_buffer_set (GeglBuffer *buffer,
void *src);
void gegl_buffer_get (GeglBuffer *buffer,
void *dst);
void gegl_buffer_set_fmt (GeglBuffer *buffer,
void *src,
void *format);
void gegl_buffer_get_fmt (GeglBuffer *buffer,
void *dst,
void *format);
#endif
......@@ -32,7 +32,7 @@
#include "gegl-tile-log.h"
G_DEFINE_TYPE(GeglStorage, gegl_storage, GEGL_TYPE_TILE_TRAITS)
#define TILE_SIZE 128
#define TILE_SIZE 64
static GObjectClass *parent_class = NULL;
......@@ -54,33 +54,33 @@ get_property (GObject *gobject,
GValue *value,
GParamSpec *pspec)
{
GeglStorage *buffer = GEGL_STORAGE (gobject);
GeglStorage *storage = GEGL_STORAGE (gobject);
switch(property_id)
{
case PROP_WIDTH:
g_value_set_int (value, buffer->width);
g_value_set_int (value, storage->width);
break;
case PROP_HEIGHT:
g_value_set_int (value, buffer->height);
g_value_set_int (value, storage->height);
break;
case PROP_TILE_WIDTH:
g_value_set_int (value, buffer->tile_width);
g_value_set_int (value, storage->tile_width);
break;
case PROP_TILE_HEIGHT:
g_value_set_int (value, buffer->tile_height);
g_value_set_int (value, storage->tile_height);
break;
case PROP_TILE_SIZE:
g_value_set_int (value, buffer->tile_size);
g_value_set_int (value, storage->tile_size);
break;
case PROP_PX_SIZE:
g_value_set_int (value, buffer->px_size);
g_value_set_int (value, storage->px_size);
break;
case PROP_PATH:
if (buffer->path != NULL)
g_value_set_string (value, buffer->path);
if (storage->path != NULL)
g_value_set_string (value, storage->path);
break;
case PROP_FORMAT:
g_value_set_pointer (value, buffer->format);
g_value_set_pointer (value, storage->format);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
......@@ -94,34 +94,34 @@ set_property (GObject *gobject,
const GValue *value,
GParamSpec *pspec)
{
GeglStorage *buffer= GEGL_STORAGE (gobject);
GeglStorage *storage = GEGL_STORAGE (gobject);
switch(property_id)
{
case PROP_WIDTH:
buffer->width = g_value_get_int (value);
storage->width = g_value_get_int (value);
return;
case PROP_HEIGHT:
buffer->height = g_value_get_int (value);
storage->height = g_value_get_int (value);
return;
case PROP_TILE_WIDTH:
buffer->tile_width= g_value_get_int (value);
storage->tile_width= g_value_get_int (value);
break;
case PROP_TILE_HEIGHT:
buffer->tile_height = g_value_get_int (value);
storage->tile_height = g_value_get_int (value);
break;
case PROP_TILE_SIZE:
buffer->tile_size = g_value_get_int (value);
storage->tile_size = g_value_get_int (value);
break;
case PROP_PX_SIZE:
buffer->px_size = g_value_get_int (value);
storage->px_size = g_value_get_int (value);
break;
case PROP_PATH:
if (buffer->path)
g_free (buffer->path);
buffer->path = g_strdup (g_value_get_string (value));
if (storage->path)
g_free (storage->path);
storage->path = g_strdup (g_value_get_string (value));
break;
case PROP_FORMAT:
buffer->format = g_value_get_pointer (value);
storage->format = g_value_get_pointer (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
......@@ -132,10 +132,10 @@ set_property (GObject *gobject,
static void
gegl_storage_dispose (GObject *object)
{
GeglStorage *buffer;
GeglStorage *storage;
GeglTileTrait *trait;
buffer = (GeglStorage*) object;
storage = (GeglStorage*) object;
trait = GEGL_TILE_TRAIT (object);
(* G_OBJECT_CLASS (parent_class)->dispose) (object);
......@@ -163,6 +163,7 @@ gegl_storage_constructor (GType type,
"source", g_object_new (GEGL_TYPE_TILE_DISK_STORE,
"tile-width", storage->tile_width,
"tile-height", storage->tile_height,
"format", storage->format,
"path", storage->path,
NULL),
NULL);
......@@ -174,6 +175,7 @@ gegl_storage_constructor (GType type,
"source", g_object_new (GEGL_TYPE_TILE_MEM_STORE,
"tile-width", storage->tile_width,
"tile-height", storage->tile_height,
"format", storage->format,
NULL),
NULL);
}
......
......@@ -21,6 +21,7 @@
#include <glib-object.h>
#include <string.h>
#include <babl.h>
#include "gegl-tile-store.h"
#include "gegl-tile-backend.h"
......@@ -32,7 +33,8 @@ enum {
PROP_TILE_WIDTH,
PROP_TILE_HEIGHT,
PROP_PX_SIZE,
PROP_TILE_SIZE
PROP_TILE_SIZE,
PROP_FORMAT
};
static void
......@@ -56,6 +58,8 @@ get_property (GObject *gobject,
case PROP_PX_SIZE:
g_value_set_int (value, backend->px_size);
break;
case PROP_FORMAT:
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
break;
......@@ -77,6 +81,9 @@ set_property (GObject *gobject,
case PROP_TILE_HEIGHT:
backend->tile_height = g_value_get_int (value);
return;
case PROP_FORMAT:
backend->format = g_value_get_pointer (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
break;
......@@ -97,8 +104,9 @@ constructor (GType type,
g_assert (backend->tile_width > 0 &&
backend->tile_height > 0);
/* FIXME: use information from the babl format */
backend->px_size = 4;
g_assert (backend->format);
backend->px_size = ((Babl*)(backend->format))->format.bytes_per_pixel;
backend->tile_size = backend->tile_width * backend->tile_height * backend->px_size;
return object;
......@@ -133,6 +141,10 @@ gegl_tile_backend_class_init (GeglTileBackendClass * klass)
g_param_spec_int ("px-size", "px-size", "Size of a single pixel in bytes",
0, G_MAXINT, 0,
G_PARAM_READABLE));
g_object_class_install_property (gobject_class, PROP_FORMAT,
g_param_spec_pointer ("format", "format", "babl format",
G_PARAM_READWRITE|
G_PARAM_CONSTRUCT));
}
static void
......
......@@ -39,7 +39,7 @@ struct _GeglTileBackend
GeglTileStore parent_instance;
gint tile_width;
gint tile_height;
void *babl_format; /* defaults to the babl format "rgba8" */
void *format; /* defaults to the babl format "R'G'B'A u8" */
gint px_size; /* size of a single pixel in bytes */
gint tile_size; /* size of an entire tile in bytes */
};
......
......@@ -19,6 +19,7 @@
*/
#include "config.h"
#include <babl.h>
#include <glib-object.h>
#include "gegl-types.h"
#include "gegl-init.h"
......@@ -33,11 +34,13 @@ gegl_init (int *argc,
{
if (gegl_initialized)
return;
g_type_init ();
babl_init ();
gegl_initialized = TRUE;
}
void
gegl_exit (void)
{
babl_destroy ();
}
......@@ -35,5 +35,6 @@
#include <gegl-utils.h>
#include <gegl-visitable.h>
#include <gegl-visitor.h>
#include <gegl-buffer.h>
#endif /* __GEGL_H__ */
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