pixbuf.c 2.42 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/* 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 2 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, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 * Copyright 2006 Øyvind Kolås <pippin@gimp.org>
 */
#if GEGL_CHANT_PROPERTIES
gegl_chant_pointer (pixbuf, "GdkPixbuf to use")
#else

#define GEGL_CHANT_SOURCE
#define GEGL_CHANT_NAME            pixbuf
#define GEGL_CHANT_DESCRIPTION     "Uses the GdkPixbuf located at the memory location in <em>pixbuf</em>."

#define GEGL_CHANT_SELF            "pixbuf.c"
29
#define GEGL_CHANT_CATEGORIES      "programming:input"
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#include "gegl-chant.h"

#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk-pixbuf/gdk-pixdata.h>

static gboolean
process (GeglOperation *operation)
{
  GeglOperationSource *op_source = GEGL_OPERATION_SOURCE(operation);
  GeglChantOperation  *self      = GEGL_CHANT_OPERATION (operation);

  if (self->pixbuf)
    op_source->output = g_object_new (GEGL_TYPE_BUFFER,
                                      "format", babl_format(gdk_pixbuf_get_has_alpha(self->pixbuf)?"R'G'B'A u8":"R'G'B' u8"),
                                      "x", 0,
                                      "y", 0,
                                      "width", gdk_pixbuf_get_width (self->pixbuf),
                                      "height", gdk_pixbuf_get_height (self->pixbuf),
                                      NULL);
49
  gegl_buffer_set (op_source->output, NULL, gdk_pixbuf_get_pixels (self->pixbuf), NULL);
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
  return TRUE;
}

static GeglRect
get_defined_region (GeglOperation *operation)
{
  GeglRect result = {0,0,0,0};
  GeglChantOperation *self = GEGL_CHANT_OPERATION (operation);

  if (!self->pixbuf)
    {
      return result;
    }
    
  result.x = 0;
  result.y = 0;
  result.w = gdk_pixbuf_get_width (self->pixbuf);
  result.h = gdk_pixbuf_get_height (self->pixbuf);
  return result;
}

#endif