color.c 3.12 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 <https://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
    /* TRANSLATORS: the string 'black' should not be translated */
26
    description (("The color to render (defaults to 'black')"))
27
    ui_meta     ("role", "color-primary")
28 29 30 31

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

32 33
#else

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

38
#include "gegl-op.h"
39

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

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

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

57
static gboolean
58 59 60
gegl_color_op_process (GeglOperation       *operation,
                       void                *out_buf,
                       glong                n_pixels,
61 62
                       const GeglRectangle *roi,
                       gint                 level)
63
{
64
  GeglProperties *o = GEGL_PROPERTIES (operation);
65 66 67
  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);
68

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

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

73
  return TRUE;
74 75 76 77
}


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

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

86 87 88
  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;
89

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

101
#endif