2007-12-29 08:57:51 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpops.c
|
|
|
|
* Copyright (C) 2007 Øyvind Kolås <pippin@gimp.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2007-12-29 09:35:04 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2007-12-29 08:57:51 +08:00
|
|
|
#include <gegl.h>
|
|
|
|
#include <gegl/buffer/gegl-buffer.h>
|
|
|
|
|
|
|
|
#include "gegl/gegl-types.h"
|
2007-12-29 09:35:04 +08:00
|
|
|
|
|
|
|
#include "gegl-types.h"
|
|
|
|
|
|
|
|
#include "base/base-types.h"
|
|
|
|
#include "base/tile-manager.h"
|
|
|
|
#include "base/pixel-region.h"
|
|
|
|
|
2007-12-29 10:19:23 +08:00
|
|
|
#include "gimp-gegl-utils.h"
|
|
|
|
#include "gimpoperationtilesink.h"
|
2007-12-29 08:57:51 +08:00
|
|
|
|
2007-12-29 09:35:04 +08:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_TILE_MANAGER
|
|
|
|
};
|
|
|
|
|
2007-12-29 08:57:51 +08:00
|
|
|
|
2007-12-29 10:19:23 +08:00
|
|
|
static void tile_sink_get_property (GObject *gobject,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void tile_sink_set_property (GObject *gobject,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2007-12-29 08:57:51 +08:00
|
|
|
|
2007-12-29 10:19:23 +08:00
|
|
|
static gboolean tile_sink_process (GeglOperation *operation,
|
|
|
|
gpointer context_id);
|
2007-12-29 08:57:51 +08:00
|
|
|
|
|
|
|
|
2007-12-29 10:19:23 +08:00
|
|
|
G_DEFINE_TYPE (GimpOperationTileSink, gimp_operation_tile_sink,
|
|
|
|
GEGL_TYPE_OPERATION_SINK)
|
2007-12-29 08:57:51 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_operation_tile_sink_class_init (GimpOperationTileSinkClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (klass);
|
2007-12-29 09:35:04 +08:00
|
|
|
GeglOperationSinkClass *sink_class = GEGL_OPERATION_SINK_CLASS (klass);
|
2007-12-29 08:57:51 +08:00
|
|
|
|
2007-12-29 10:19:23 +08:00
|
|
|
object_class->set_property = tile_sink_set_property;
|
|
|
|
object_class->get_property = tile_sink_get_property;
|
2007-12-29 08:57:51 +08:00
|
|
|
|
2007-12-29 10:19:23 +08:00
|
|
|
sink_class->process = tile_sink_process;
|
2007-12-29 08:57:51 +08:00
|
|
|
|
|
|
|
gegl_operation_class_set_name (operation_class, "gimp-tilemanager-sink");;
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_TILE_MANAGER,
|
2007-12-29 09:35:04 +08:00
|
|
|
g_param_spec_pointer ("tile-manager",
|
|
|
|
"Tile Manager",
|
2007-12-29 08:57:51 +08:00
|
|
|
"The tile manager to use as a destination",
|
2007-12-29 09:35:04 +08:00
|
|
|
G_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT));
|
|
|
|
}
|
2007-12-29 08:57:51 +08:00
|
|
|
|
2007-12-29 09:35:04 +08:00
|
|
|
static void
|
|
|
|
gimp_operation_tile_sink_init (GimpOperationTileSink *self)
|
|
|
|
{
|
2007-12-29 08:57:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-12-29 10:19:23 +08:00
|
|
|
tile_sink_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2007-12-29 08:57:51 +08:00
|
|
|
{
|
|
|
|
GimpOperationTileSink *self = GIMP_OPERATION_TILE_SINK (object);
|
2007-12-29 09:35:04 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
2007-12-29 08:57:51 +08:00
|
|
|
{
|
2007-12-29 09:35:04 +08:00
|
|
|
case PROP_TILE_MANAGER:
|
|
|
|
g_value_set_pointer (value, self->tile_manager);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
2007-12-29 08:57:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-12-29 10:19:23 +08:00
|
|
|
tile_sink_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2007-12-29 08:57:51 +08:00
|
|
|
{
|
|
|
|
GimpOperationTileSink *self = GIMP_OPERATION_TILE_SINK (object);
|
2007-12-29 09:35:04 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
2007-12-29 08:57:51 +08:00
|
|
|
{
|
2007-12-29 09:35:04 +08:00
|
|
|
case PROP_TILE_MANAGER:
|
|
|
|
self->tile_manager = g_value_get_pointer (value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
2007-12-29 08:57:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2007-12-29 10:19:23 +08:00
|
|
|
tile_sink_process (GeglOperation *operation,
|
|
|
|
gpointer context_id)
|
2007-12-29 08:57:51 +08:00
|
|
|
{
|
2007-12-29 09:35:04 +08:00
|
|
|
GimpOperationTileSink *self = GIMP_OPERATION_TILE_SINK (operation);
|
2007-12-29 08:57:51 +08:00
|
|
|
|
|
|
|
if (self->tile_manager)
|
|
|
|
{
|
2007-12-29 10:28:28 +08:00
|
|
|
GeglBuffer *input;
|
|
|
|
const Babl *format;
|
|
|
|
const GeglRectangle *extent;
|
|
|
|
PixelRegion destPR;
|
|
|
|
gpointer pr;
|
2007-12-29 08:57:51 +08:00
|
|
|
|
|
|
|
/* is this somethings that should be done already for all sinks? */
|
|
|
|
input = GEGL_BUFFER (gegl_operation_get_data (operation, context_id,
|
|
|
|
"input"));
|
|
|
|
|
|
|
|
extent = gegl_operation_result_rect (operation, context_id);
|
|
|
|
|
|
|
|
pixel_region_init (&destPR, self->tile_manager,
|
2007-12-29 09:35:04 +08:00
|
|
|
extent->x, extent->y,
|
|
|
|
extent->width, extent->height,
|
|
|
|
TRUE);
|
2007-12-29 08:57:51 +08:00
|
|
|
|
2007-12-29 10:19:23 +08:00
|
|
|
format = gimp_bpp_to_babl_format (tile_manager_bpp (self->tile_manager));
|
2007-12-29 08:57:51 +08:00
|
|
|
|
2007-12-29 09:35:04 +08:00
|
|
|
for (pr = pixel_regions_register (1, &destPR);
|
|
|
|
pr;
|
|
|
|
pr = pixel_regions_process (pr))
|
2007-12-29 08:57:51 +08:00
|
|
|
{
|
2007-12-29 09:35:04 +08:00
|
|
|
GeglRectangle rect = { destPR.x, destPR.y, destPR.w, destPR.h };
|
2007-12-29 08:57:51 +08:00
|
|
|
|
|
|
|
gegl_buffer_get (input,
|
|
|
|
1.0, &rect, format,
|
|
|
|
destPR.data, destPR.rowstride);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_warning ("no tilemanager?");
|
|
|
|
}
|
2007-12-29 09:35:04 +08:00
|
|
|
|
2007-12-29 08:57:51 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|