color.c 3 KB
Newer Older
1 2 3 4 5
/* 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
6
 * version 3 of the License, or (at your option) any later version.
7 8 9 10 11 12 13
 *
 * 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
14
 * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
15 16 17
 *
 * Copyright 2006 Øyvind Kolås <pippin@gimp.org>
 */
18 19 20 21

#include "config.h"
#include <glib/gi18n-lib.h>

22
#ifdef GEGL_PROPERTIES
23 24

property_color (value, _("Color"), "black")
25
    description (("The color to render (defaults to 'black')"))
26
    ui_meta     ("role", "color-primary")
27 28 29 30

property_format (format, _("Babl Format"), 666)
    description (_("The babl format of the output"))

31 32
#else

33
#define GEGL_OP_POINT_RENDER
34
#define GEGL_OP_NAME     color
35
#define GEGL_OP_C_SOURCE color.c
36

37
#include "gegl-op.h"
38

39
static void
40
gegl_color_op_prepare (GeglOperation *operation)
41
{
42
  GeglProperties *o = GEGL_PROPERTIES (operation);
43 44 45 46 47

  if (o->format)
    gegl_operation_set_format (operation, "output", o->format);
  else
    gegl_operation_set_format (operation, "output", babl_format ("RGBA float"));
48 49
}

50
static GeglRectangle
51
gegl_color_op_get_bounding_box (GeglOperation *operation)
52
{
53
  return gegl_rectangle_infinite_plane ();
54 55
}

56
static gboolean
57 58 59
gegl_color_op_process (GeglOperation       *operation,
                       void                *out_buf,
                       glong                n_pixels,
60 61
                       const GeglRectangle *roi,
                       gint                 level)
62
{
63
  GeglProperties *o = GEGL_PROPERTIES (operation);
64 65 66
  const Babl *out_format = gegl_operation_get_format (operation, "output");
  gint        pixel_size = babl_format_get_bytes_per_pixel (out_format);
  void       *out_color  = alloca(pixel_size);
67

68
  gegl_color_get_pixel (o->value, out_format, out_color);
69

70
  gegl_memset_pattern (out_buf, out_color, pixel_size, n_pixels);
71

72
  return TRUE;
73 74 75 76
}


static void
77
gegl_op_class_init (GeglOpClass *klass)
78
{
79 80
  GeglOperationClass            *operation_class;
  GeglOperationPointRenderClass *point_render_class;
81

82
  operation_class    = GEGL_OPERATION_CLASS (klass);
83
  point_render_class = GEGL_OPERATION_POINT_RENDER_CLASS (klass);
84

85 86 87
  point_render_class->process       = gegl_color_op_process;
  operation_class->get_bounding_box = gegl_color_op_get_bounding_box;
  operation_class->prepare          = gegl_color_op_prepare;
88

89
  gegl_operation_class_set_keys (operation_class,
90 91
    "name",        "gegl:color",
    "title",      _("Color"),
92 93 94
    "categories" , "render",
    "description",
      _("Generates a buffer entirely filled with the specified color, "
95
        "use gegl:crop to get smaller dimensions."),
96
    NULL);
97 98
}

99
#endif