Commit 00b3a9c7 authored by Michael Natterer's avatar Michael Natterer 😴

libgimpcolor: add Cairo <-> GEGL utility functions from app/

parent d766ec6a
......@@ -37,34 +37,6 @@
static cairo_user_data_key_t surface_data_key = { 0, };
GeglBuffer *
gimp_cairo_image_surface_create_buffer (cairo_surface_t *surface)
{
const Babl *format;
gint width;
gint height;
g_return_val_if_fail (surface != NULL, NULL);
g_return_val_if_fail (cairo_surface_get_type (surface) ==
CAIRO_SURFACE_TYPE_IMAGE, NULL);
width = cairo_image_surface_get_width (surface);
height = cairo_image_surface_get_height (surface);
if (cairo_surface_get_content (surface) == CAIRO_CONTENT_COLOR_ALPHA)
format = babl_format ("cairo-ARGB32");
else
format = babl_format ("cairo-RGB24");
return
gegl_buffer_linear_new_from_data (cairo_image_surface_get_data (surface),
format,
GEGL_RECTANGLE (0, 0, width, height),
cairo_image_surface_get_stride (surface),
(GDestroyNotify) cairo_surface_destroy,
cairo_surface_reference (surface));
}
cairo_pattern_t *
gimp_cairo_stipple_pattern_create (const GimpRGB *fg,
const GimpRGB *bg,
......
......@@ -25,21 +25,19 @@
#define __APP_GIMP_CAIRO_H__
GeglBuffer * gimp_cairo_image_surface_create_buffer (cairo_surface_t *surface);
cairo_pattern_t * gimp_cairo_stipple_pattern_create (const GimpRGB *fg,
const GimpRGB *bg,
gint index);
cairo_pattern_t * gimp_cairo_stipple_pattern_create (const GimpRGB *fg,
const GimpRGB *bg,
gint index);
void gimp_cairo_add_arc (cairo_t *cr,
gdouble center_x,
gdouble center_y,
gdouble radius,
gdouble start_angle,
gdouble slice_angle);
void gimp_cairo_add_segments (cairo_t *cr,
GimpSegment *segs,
gint n_segs);
void gimp_cairo_add_arc (cairo_t *cr,
gdouble center_x,
gdouble center_y,
gdouble radius,
gdouble start_angle,
gdouble slice_angle);
void gimp_cairo_add_segments (cairo_t *cr,
GimpSegment *segs,
gint n_segs);
#endif /* __APP_GIMP_CAIRO_H__ */
......@@ -36,7 +36,6 @@
#include "gegl/gimp-gegl-utils.h"
#include "core/gimp.h"
#include "core/gimp-cairo.h"
#include "core/gimp-utils.h"
#include "core/gimpcontext.h"
#include "core/gimpcontainer.h"
......@@ -671,7 +670,7 @@ gimp_text_layer_render_layout (GimpTextLayer *layer,
cairo_surface_flush (surface);
buffer = gimp_cairo_image_surface_create_buffer (surface);
buffer = gimp_cairo_surface_create_buffer (surface);
gegl_buffer_copy (buffer, NULL,
gimp_drawable_get_buffer (drawable), NULL);
......
......@@ -33,7 +33,6 @@
#include "widgets-types.h"
#include "core/gimp-cairo.h"
#include "core/gimpcontext.h"
#include "core/gimpmarshal.h"
#include "core/gimptempbuf.h"
......@@ -1037,7 +1036,7 @@ gimp_view_render_temp_buf_to_surface (GimpViewRenderer *renderer,
width, height);
src_buffer = gimp_temp_buf_create_buffer (temp_buf);
dest_buffer = gimp_cairo_image_surface_create_buffer (alpha_surface);
dest_buffer = gimp_cairo_surface_create_buffer (alpha_surface);
gegl_buffer_copy (src_buffer,
GEGL_RECTANGLE (x - temp_buf_x,
......@@ -1066,7 +1065,7 @@ gimp_view_render_temp_buf_to_surface (GimpViewRenderer *renderer,
cairo_surface_flush (surface);
src_buffer = gimp_temp_buf_create_buffer (temp_buf);
dest_buffer = gimp_cairo_image_surface_create_buffer (surface);
dest_buffer = gimp_cairo_surface_create_buffer (surface);
gegl_buffer_copy (src_buffer,
GEGL_RECTANGLE (x - temp_buf_x,
......
......@@ -22,8 +22,8 @@
#include "config.h"
#include <glib-object.h>
#include <cairo.h>
#include <gegl.h>
#include "libgimpbase/gimpbase.h"
......@@ -140,3 +140,49 @@ gimp_cairo_checkerboard_create (cairo_t *cr,
return pattern;
}
const Babl *
gimp_cairo_surface_get_format (cairo_surface_t *surface)
{
g_return_val_if_fail (surface != NULL, NULL);
g_return_val_if_fail (cairo_surface_get_type (surface) ==
CAIRO_SURFACE_TYPE_IMAGE, NULL);
switch (cairo_image_surface_get_format (surface))
{
case CAIRO_FORMAT_RGB24:
return babl_format ("cairo-ARGB32");
case CAIRO_FORMAT_ARGB32:
return babl_format ("cairo-RGB24");
default:
break;
}
g_return_val_if_reached (NULL);
}
GeglBuffer *
gimp_cairo_surface_create_buffer (cairo_surface_t *surface)
{
const Babl *format;
gint width;
gint height;
g_return_val_if_fail (surface != NULL, NULL);
g_return_val_if_fail (cairo_surface_get_type (surface) ==
CAIRO_SURFACE_TYPE_IMAGE, NULL);
width = cairo_image_surface_get_width (surface);
height = cairo_image_surface_get_height (surface);
format = gimp_cairo_surface_get_format (surface);
return
gegl_buffer_linear_new_from_data (cairo_image_surface_get_data (surface),
format,
GEGL_RECTANGLE (0, 0, width, height),
cairo_image_surface_get_stride (surface),
(GDestroyNotify) cairo_surface_destroy,
cairo_surface_reference (surface));
}
......@@ -24,15 +24,18 @@
#define __GIMP_CAIRO_H__
void gimp_cairo_set_source_rgb (cairo_t *cr,
const GimpRGB *color);
void gimp_cairo_set_source_rgba (cairo_t *cr,
const GimpRGB *color);
cairo_pattern_t * gimp_cairo_checkerboard_create (cairo_t *cr,
gint size,
const GimpRGB *light,
const GimpRGB *dark);
void gimp_cairo_set_source_rgb (cairo_t *cr,
const GimpRGB *color);
void gimp_cairo_set_source_rgba (cairo_t *cr,
const GimpRGB *color);
cairo_pattern_t * gimp_cairo_checkerboard_create (cairo_t *cr,
gint size,
const GimpRGB *light,
const GimpRGB *dark);
const Babl * gimp_cairo_surface_get_format (cairo_surface_t *surface);
GeglBuffer * gimp_cairo_surface_create_buffer (cairo_surface_t *surface);
/* some useful macros for writing directly to a Cairo surface */
......
......@@ -10,6 +10,8 @@ EXPORTS
gimp_cairo_checkerboard_create
gimp_cairo_set_source_rgb
gimp_cairo_set_source_rgba
gimp_cairo_surface_create_buffer
gimp_cairo_surface_get_format
gimp_cmyk_get_type
gimp_cmyk_get_uchar
gimp_cmyk_set
......
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