gdkpixbuf: Implement gdk_pixbuf_render_threshold_alpha() with Cairo
This commit is contained in:
@ -57,8 +57,7 @@ gdk_pixbuf_render_threshold_alpha (GdkPixbuf *pixbuf,
|
|||||||
int height,
|
int height,
|
||||||
int alpha_threshold)
|
int alpha_threshold)
|
||||||
{
|
{
|
||||||
GdkGC *gc;
|
cairo_t *cr;
|
||||||
GdkColor color;
|
|
||||||
int x, y;
|
int x, y;
|
||||||
guchar *p;
|
guchar *p;
|
||||||
int start, start_status;
|
int start, start_status;
|
||||||
@ -84,22 +83,31 @@ gdk_pixbuf_render_threshold_alpha (GdkPixbuf *pixbuf,
|
|||||||
if (width == 0 || height == 0)
|
if (width == 0 || height == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
gc = _gdk_drawable_get_scratch_gc (bitmap, FALSE);
|
cr = gdk_cairo_create (bitmap);
|
||||||
|
cairo_rectangle (cr, dest_x, dest_y, width, height);
|
||||||
|
cairo_clip (cr);
|
||||||
|
|
||||||
if (!gdk_pixbuf_get_has_alpha (pixbuf))
|
if (!gdk_pixbuf_get_has_alpha (pixbuf))
|
||||||
{
|
{
|
||||||
color.pixel = (alpha_threshold == 255) ? 0 : 1;
|
cairo_set_source_rgba (cr, 0, 0, 0, alpha_threshold == 255 ? 0 : 1);
|
||||||
gdk_gc_set_foreground (gc, &color);
|
cairo_paint (cr);
|
||||||
gdk_draw_rectangle (bitmap, gc, TRUE, dest_x, dest_y, width, height);
|
cairo_destroy (cr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
color.pixel = 0;
|
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
|
||||||
gdk_gc_set_foreground (gc, &color);
|
cairo_paint (cr);
|
||||||
gdk_draw_rectangle (bitmap, gc, TRUE, dest_x, dest_y, width, height);
|
|
||||||
|
|
||||||
color.pixel = 1;
|
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
|
||||||
gdk_gc_set_foreground (gc, &color);
|
if (alpha_threshold == 128)
|
||||||
|
{
|
||||||
|
gdk_cairo_set_source_pixbuf (cr, pixbuf, src_x - dest_x, src_y - dest_y);
|
||||||
|
cairo_paint (cr);
|
||||||
|
cairo_destroy (cr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cairo_set_source_rgb (cr, 0, 0, 0);
|
||||||
|
|
||||||
for (y = 0; y < height; y++)
|
for (y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
@ -116,9 +124,9 @@ gdk_pixbuf_render_threshold_alpha (GdkPixbuf *pixbuf,
|
|||||||
if (status != start_status)
|
if (status != start_status)
|
||||||
{
|
{
|
||||||
if (!start_status)
|
if (!start_status)
|
||||||
gdk_draw_line (bitmap, gc,
|
cairo_rectangle (cr,
|
||||||
start + dest_x, y + dest_y,
|
start + dest_x, y + dest_y,
|
||||||
x - 1 + dest_x, y + dest_y);
|
x + dest_x, y + dest_y + 1);
|
||||||
|
|
||||||
start = x;
|
start = x;
|
||||||
start_status = status;
|
start_status = status;
|
||||||
@ -128,10 +136,13 @@ gdk_pixbuf_render_threshold_alpha (GdkPixbuf *pixbuf,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!start_status)
|
if (!start_status)
|
||||||
gdk_draw_line (bitmap, gc,
|
cairo_rectangle (cr,
|
||||||
start + dest_x, y + dest_y,
|
start + dest_x, y + dest_y,
|
||||||
x - 1 + dest_x, y + dest_y);
|
x + dest_x, y + dest_y + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cairo_fill (cr);
|
||||||
|
cairo_destroy (cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user