gdkpixbuf-render.c
void
gdk_pixbuf_render_threshold_alpha (GdkPixbuf *pixbuf,
GdkBitmap *bitmap,
int src_x, int src_y,
int dest_x, int dest_y,
int width, int height,
int alpha_threshold)
{
GdkGC *gc;
GdkColor color;
int x, y;
guchar *p;
int start, start_status;
int status;
g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
g_return_if_fail (pixbuf->colorspace == GDK_COLORSPACE_RGB);
g_return_if_fail (pixbuf->n_channels == 3 || pixbuf->n_channels == 4);
g_return_if_fail (pixbuf->bits_per_sample == 8);
if (width == -1)
width = pixbuf->width;
if (height == -1)
height = pixbuf->height;
g_return_if_fail (bitmap != NULL);
g_return_if_fail (width >= 0 && height >= 0);
g_return_if_fail (src_x >= 0 && src_x + width <= pixbuf->width);
g_return_if_fail (src_y >= 0 && src_y + height <= pixbuf->height);
g_return_if_fail (alpha_threshold >= 0 && alpha_threshold <= 255);
if (width == 0 || height == 0)
return;
gc = _gdk_drawable_get_scratch_gc (bitmap, FALSE);
if (!pixbuf->has_alpha)
{
color.pixel = (alpha_threshold == 255) ? 0 : 1;
gdk_gc_set_foreground (gc, &color);
gdk_draw_rectangle (bitmap, gc, TRUE, dest_x, dest_y, width, height);
return;
}
color.pixel = 0;
gdk_gc_set_foreground (gc, &color);
gdk_gc_set_transparent_enable (gc);
gdk_draw_rectangle (bitmap, gc, TRUE, dest_x, dest_y, width, height);
gdk_gc_set_transparent_disable (gc);
color.pixel = 1;
gdk_gc_set_foreground (gc, &color);
for (y = 0; y < height; y++)
{
p = (pixbuf->pixels + (y + src_y) * pixbuf->rowstride + src_x * pixbuf->n_channels
+ pixbuf->n_channels - 1);
start = 0;
start_status = *p < alpha_threshold;
for (x = 0; x < width; x++)
{
status = *p < alpha_threshold;
if (status != start_status)
{
if (!start_status)
gdk_draw_line (bitmap, gc,
start + dest_x, y + dest_y,
x - 1 + dest_x, y + dest_y);
start = x;
start_status = status;
}
p += pixbuf->n_channels;
}
if (!start_status)
gdk_draw_line (bitmap, gc,
start + dest_x, y + dest_y,
x - 1 + dest_x, y + dest_y);
}
}
////////////////////////////////////////////////////////////////////////////
gdkgc.h
typedef enum
{
GDK_GC_FOREGROUND = 1 << 0,
GDK_GC_BACKGROUND = 1 << 1,
GDK_GC_FONT = 1 << 2,
GDK_GC_FUNCTION = 1 << 3,
GDK_GC_FILL = 1 << 4,
GDK_GC_TILE = 1 << 5,
GDK_GC_STIPPLE = 1 << 6,
GDK_GC_CLIP_MASK = 1 << 7,
GDK_GC_SUBWINDOW = 1 << 8,
GDK_GC_TS_X_ORIGIN = 1 << 9,
GDK_GC_TS_Y_ORIGIN = 1 << 10,
GDK_GC_CLIP_X_ORIGIN = 1 << 11,
GDK_GC_CLIP_Y_ORIGIN = 1 << 12,
GDK_GC_EXPOSURES = 1 << 13,
GDK_GC_LINE_WIDTH = 1 << 14,
GDK_GC_LINE_STYLE = 1 << 15,
GDK_GC_CAP_STYLE = 1 << 16,
GDK_GC_JOIN_STYLE = 1 << 17,
GDK_GC_TRANS_ENABLE = 1 << 18,
GDK_GC_TRANS_DISABLE = 1 << 19
} GdkGCValuesMask;
//
void gdk_gc_get_values (GdkGC *gc,
GdkGCValues *values);
void gdk_gc_set_values (GdkGC *gc,
GdkGCValues *values,
GdkGCValuesMask values_mask);
void gdk_gc_set_foreground (GdkGC *gc,
const GdkColor *color);
void gdk_gc_set_background (GdkGC *gc,
const GdkColor *color);
void gdk_gc_set_transparent_enable (GdkGC *gc);
void gdk_gc_set_transparent_disable (GdkGC *gc);
#ifndef GDK_DISABLE_DEPRECATED
///////////////////////////////////////////////////////////////////
gdkgc.c
gdk_gc_set_background (GdkGC *gc,
const GdkColor *color)
{
GdkGCValues values;
g_return_if_fail (GDK_IS_GC (gc));
g_return_if_fail (color != NULL);
values.background = *color;
gdk_gc_set_values (gc, &values, GDK_GC_BACKGROUND);
}
void
gdk_gc_set_transparent_enable (GdkGC *gc)
{
GdkGCValues values;
g_return_if_fail (GDK_IS_GC (gc));
gdk_gc_set_values (gc, &values, GDK_GC_TRANS_ENABLE);
}
void
gdk_gc_set_transparent_disable (GdkGC *gc)
{
GdkGCValues values;
g_return_if_fail (GDK_IS_GC (gc));
gdk_gc_set_values (gc, &values, GDK_GC_TRANS_DISABLE);
}
//////////////////////////////////////////////////////////////
gdkenumtypes.c
GType
gdk_gc_values_mask_get_type (void)
{
static GType etype = 0;
if (G_UNLIKELY(etype == 0)) {
static const GFlagsValue values[] = {
{ GDK_GC_FOREGROUND, "GDK_GC_FOREGROUND", "foreground" },
{ GDK_GC_BACKGROUND, "GDK_GC_BACKGROUND", "background" },
{ GDK_GC_FONT, "GDK_GC_FONT", "font" },
{ GDK_GC_FUNCTION, "GDK_GC_FUNCTION", "function" },
{ GDK_GC_FILL, "GDK_GC_FILL", "fill" },
{ GDK_GC_TILE, "GDK_GC_TILE", "tile" },
{ GDK_GC_STIPPLE, "GDK_GC_STIPPLE", "stipple" },
{ GDK_GC_CLIP_MASK, "GDK_GC_CLIP_MASK", "clip-mask" },
{ GDK_GC_SUBWINDOW, "GDK_GC_SUBWINDOW", "subwindow" },
{ GDK_GC_TS_X_ORIGIN, "GDK_GC_TS_X_ORIGIN", "ts-x-origin" },
{ GDK_GC_TS_Y_ORIGIN, "GDK_GC_TS_Y_ORIGIN", "ts-y-origin" },
{ GDK_GC_CLIP_X_ORIGIN, "GDK_GC_CLIP_X_ORIGIN", "clip-x-origin" },
{ GDK_GC_CLIP_Y_ORIGIN, "GDK_GC_CLIP_Y_ORIGIN", "clip-y-origin" },
{ GDK_GC_EXPOSURES, "GDK_GC_EXPOSURES", "exposures" },
{ GDK_GC_LINE_WIDTH, "GDK_GC_LINE_WIDTH", "line-width" },
{ GDK_GC_LINE_STYLE, "GDK_GC_LINE_STYLE", "line-style" },
{ GDK_GC_CAP_STYLE, "GDK_GC_CAP_STYLE", "cap-style" },
{ GDK_GC_JOIN_STYLE, "GDK_GC_JOIN_STYLE", "join-style" },
{ GDK_GC_TRANS_ENABLE, "GDK_GC_TRANS_ENABLE", "trans-enable" },
{ GDK_GC_TRANS_DISABLE, "GDK_GC_TRANS_DISABLE", "trans-disable" },
{ 0, NULL, NULL }
};
etype = g_flags_register_static (g_intern_static_string ("GdkGCValuesMask"), values);
}
return etype;
}
//////////////////////////////////////////////////////
gdkalaisdef.c
#undef gdk_gc_set_values
extern __typeof (gdk_gc_set_values) gdk_gc_set_values __attribute((alias("IA__gdk_gc_set_values"), visibility("default")));
#undef gdk_gc_set_foreground
extern __typeof (gdk_gc_set_foreground) gdk_gc_set_foreground
__attribute((alias("IA__gdk_gc_set_foreground"),
visibility("default")));
#undef gdk_gc_set_background
extern __typeof (gdk_gc_set_background) gdk_gc_set_background
__attribute((alias("IA__gdk_gc_set_background"),
visibility("default")));
#undef gdk_gc_set_transparent_enable
extern __typeof (gdk_gc_set_transparent_enable)
gdk_gc_set_transparent_enable
__attribute((alias("IA__gdk_gc_set_background"),
visibility("default")));
#undef gdk_gc_set_transparent_disable
extern __typeof (gdk_gc_set_transparent_disable)
gdk_gc_set_transparent_disable
__attribute((alias("IA__gdk_gc_set_background"),
visibility("default")));
#undef gdk_gc_set_function
extern __typeof (gdk_gc_set_function) gdk_gc_set_function
__attribute((alias("IA__gdk_gc_set_function"), visibility("default")));
/////////////////////////////////////////////////////////////////////////
gdkalais.h
extern __typeof (gdk_gc_set_foreground) IA__gdk_gc_set_foreground __attribute((visibility("hidden")));
#define gdk_gc_set_foreground IA__gdk_gc_set_foreground
extern __typeof (gdk_gc_set_background) IA__gdk_gc_set_background __attribute((visibility("hidden")));
#define gdk_gc_set_background IA__gdk_gc_set_background
extern __typeof (gdk_gc_set_transparent_enable) IA__gdk_gc_set_transparent_enable __attribute((visibility("hidden")));
#define gdk_gc_set_transparent_enable IA__gdk_gc_set_transparent_enable
extern __typeof (gdk_gc_set_transparent_disable) IA__gdk_gc_set_transparent_disable __attribute((visibility("hidden")));
#define gdk_gc_set_transparent_disable IA__gdk_gc_set_transparent_disable
extern __typeof (gdk_gc_set_function) IA__gdk_gc_set_function __attribute((visibility("hidden")));
#define gdk_gc_set_function IA__gdk_gc_set_function
////////////////////////////////////////////////////////////////
gdkgc-directfb.c
static void
gdk_directfb_gc_set_values (GdkGC *gc,
GdkGCValues *values,
GdkGCValuesMask values_mask)
{
GdkGCDirectFB *private = GDK_GC_DIRECTFB (gc);
if (values_mask & GDK_GC_FOREGROUND)
{
private->values.foreground = values->foreground;
private->values_mask |= GDK_GC_FOREGROUND;
}
if (values_mask & GDK_GC_BACKGROUND)
{
private->values.background = values->background;
private->values_mask |= GDK_GC_BACKGROUND;
}
if (values_mask & GDK_GC_FONT)
{
GdkFont *oldf = private->values.font;
private->values.font = gdk_font_ref (values->font);
private->values_mask |= GDK_GC_FONT;
if (oldf)
gdk_font_unref (oldf);
}
if (values_mask & GDK_GC_FUNCTION)
{
private->values.function = values->function;
private->values_mask |= GDK_GC_FUNCTION;
}
if (values_mask & GDK_GC_FILL)
{
private->values.fill = values->fill;
private->values_mask |= GDK_GC_FILL;
}
if (values_mask & GDK_GC_TILE)
{
GdkPixmap *oldpm = private->values.tile;
if (values->tile)
g_assert (GDK_PIXMAP_OBJECT (values->tile)->depth > 1);
private->values.tile = values->tile ? g_object_ref (values->tile) : NULL;
private->values_mask |= GDK_GC_TILE;
if (oldpm)
g_object_unref (oldpm);
}
if (values_mask & GDK_GC_STIPPLE)
{
GdkPixmap *oldpm = private->values.stipple;
if (values->stipple)
g_assert (GDK_PIXMAP_OBJECT (values->stipple)->depth == 1);
private->values.stipple = (values->stipple ?
g_object_ref (values->stipple) : NULL);
private->values_mask |= GDK_GC_STIPPLE;
if (oldpm)
g_object_unref (oldpm);
}
if (values_mask & GDK_GC_CLIP_MASK)
{
GdkPixmap *oldpm = private->values.clip_mask;
private->values.clip_mask = (values->clip_mask ?
g_object_ref (values->clip_mask) : NULL);
private->values_mask |= GDK_GC_CLIP_MASK;
if (oldpm)
g_object_unref (oldpm);
temp_region_reset (&private->clip_region);
}
if (values_mask & GDK_GC_SUBWINDOW)
{
private->values.subwindow_mode = values->subwindow_mode;
private->values_mask |= GDK_GC_SUBWINDOW;
}
if (values_mask & GDK_GC_TS_X_ORIGIN)
{
private->values.ts_x_origin = values->ts_x_origin;
private->values_mask |= GDK_GC_TS_X_ORIGIN;
}
if (values_mask & GDK_GC_TS_Y_ORIGIN)
{
private->values.ts_y_origin = values->ts_y_origin;
private->values_mask |= GDK_GC_TS_Y_ORIGIN;
}
if (values_mask & GDK_GC_CLIP_X_ORIGIN)
{
private->values.clip_x_origin = GDK_GC (gc)->clip_x_origin = values->clip_x_origin;
private->values_mask |= GDK_GC_CLIP_X_ORIGIN;
}
if (values_mask & GDK_GC_CLIP_Y_ORIGIN)
{
private->values.clip_y_origin = GDK_GC (gc)->clip_y_origin = values->clip_y_origin;
private->values_mask |= GDK_GC_CLIP_Y_ORIGIN;
}
if (values_mask & GDK_GC_EXPOSURES)
{
private->values.graphics_exposures = values->graphics_exposures;
private->values_mask |= GDK_GC_EXPOSURES;
}
if (values_mask & GDK_GC_LINE_WIDTH)
{
private->values.line_width = values->line_width;
private->values_mask |= GDK_GC_LINE_WIDTH;
}
if (values_mask & GDK_GC_LINE_STYLE)
{
private->values.line_style = values->line_style;
private->values_mask |= GDK_GC_LINE_STYLE;
}
if (values_mask & GDK_GC_CAP_STYLE)
{
private->values.cap_style = values->cap_style;
private->values_mask |= GDK_GC_CAP_STYLE;
}
if (values_mask & GDK_GC_JOIN_STYLE)
{
private->values.join_style = values->join_style;
private->values_mask |= GDK_GC_JOIN_STYLE;
}
if (values_mask & GDK_GC_TRANS_ENABLE)
{
private->values_mask |= GDK_GC_TRANS_ENABLE;
}
if (values_mask & GDK_GC_TRANS_DISABLE)
{
private->values_mask &= ~GDK_GC_TRANS_ENABLE;
}
}
沒有留言:
張貼留言