Commit 4f8dbd4a authored by Benjamin Otte's avatar Benjamin Otte

API: Remove gdk_draw_pixbuf()

parent 11ee2aba
......@@ -413,7 +413,6 @@ gdk_draw_point
gdk_draw_points
gdk_draw_line
gdk_draw_lines
gdk_draw_pixbuf
gdk_draw_segments
GdkSegment
gdk_draw_rectangle
......
......@@ -129,19 +129,6 @@ static gboolean accelerated_alpha_blending = FALSE;
static gpointer parent_class = NULL;
static const cairo_user_data_key_t gdk_directfb_cairo_key;
static void (*real_draw_pixbuf) (GdkDrawable *drawable,
GdkGC *gc,
GdkPixbuf *pixbuf,
gint src_x,
gint src_y,
gint dest_x,
gint dest_y,
gint width,
gint height,
GdkRgbDither dither,
gint x_dither,
gint y_dither);
/**********************************************************
* DirectFB specific implementations of generic functions *
......@@ -963,438 +950,6 @@ gdk_directfb_draw_image (GdkDrawable *drawable,
temp_region_deinit( &clip );
}
static void
composite (guchar *src_buf,
gint src_rowstride,
guchar *dest_buf,
gint dest_rowstride,
gint width,
gint height)
{
guchar *src = src_buf;
guchar *dest = dest_buf;
while (height--)
{
gint twidth = width;
guchar *p = src;
guchar *q = dest;
while (twidth--)
{
guchar a = p[3];
guint t;
t = a * p[0] + (255 - a) * q[0] + 0x80;
q[0] = (t + (t >> 8)) >> 8;
t = a * p[1] + (255 - a) * q[1] + 0x80;
q[1] = (t + (t >> 8)) >> 8;
t = a * p[2] + (255 - a) * q[2] + 0x80;
q[2] = (t + (t >> 8)) >> 8;
p += 4;
q += 3;
}
src += src_rowstride;
dest += dest_rowstride;
}
}
static void
composite_0888 (guchar *src_buf,
gint src_rowstride,
guchar *dest_buf,
gint dest_rowstride,
GdkByteOrder dest_byte_order,
gint width,
gint height)
{
guchar *src = src_buf;
guchar *dest = dest_buf;
while (height--)
{
gint twidth = width;
guchar *p = src;
guchar *q = dest;
if (dest_byte_order == GDK_LSB_FIRST)
{
while (twidth--)
{
guint t;
t = p[3] * p[2] + (255 - p[3]) * q[0] + 0x80;
q[0] = (t + (t >> 8)) >> 8;
t = p[3] * p[1] + (255 - p[3]) * q[1] + 0x80;
q[1] = (t + (t >> 8)) >> 8;
t = p[3] * p[0] + (255 - p[3]) * q[2] + 0x80;
q[2] = (t + (t >> 8)) >> 8;
p += 4;
q += 4;
}
}
else
{
while (twidth--)
{
guint t;
t = p[3] * p[0] + (255 - p[3]) * q[1] + 0x80;
q[1] = (t + (t >> 8)) >> 8;
t = p[3] * p[1] + (255 - p[3]) * q[2] + 0x80;
q[2] = (t + (t >> 8)) >> 8;
t = p[3] * p[2] + (255 - p[3]) * q[3] + 0x80;
q[3] = (t + (t >> 8)) >> 8;
p += 4;
q += 4;
}
}
src += src_rowstride;
dest += dest_rowstride;
}
}
/* change the last value to adjust the size of the device (1-4) */
#define SET_PIXEL_DUFFS_DEVICE( D, S, w ) \
SET_PIXEL_DUFFS_DEVICE_N( D, S, w, 2 )
/* From DirectFB's gfx/generic/generic.c" */
#define SET_PIXEL( D, S ) \
switch (S >> 26) { \
case 0: \
break; \
case 0x3f: \
D = ((S << 8) & 0xF800) | \
((S >> 5) & 0x07E0) | \
((S >> 19) & 0x001F); \
break; \
default: \
D = (((( (((S<<8) & 0xf800) | ((S>>19) & 0x001f)) \
- (D & 0xf81f)) * ((S>>26)+1) + ((D & 0xf81f)<<6)) & 0x003e07c0) \
+ \
((( ((S>>5) & 0x07e0) \
- (D & 0x07e0)) * ((S>>26)+1) + ((D & 0x07e0)<<6)) & 0x0001f800)) >> 6; \
}
static void
composite_565 (guchar *src_buf,
gint src_rowstride,
guchar *dest_buf,
gint dest_rowstride,
GdkByteOrder dest_byte_order,
gint width,
gint height)
{
while (height--) {
int w = width;
u16 *D = (u16*) dest_buf;
u32 *S = (u32*) src_buf;
#if 1
if ((unsigned long)D & 2) {
SET_PIXEL( D[0], S[0] );
w--;
D++;
S++;
}
int i;
int w2 = w / 2;
u32 *D32 = (u32*) D;
for (i=0; i<w2; i++) {
register u32 S0 = S[(i << 1) + 0];
register u32 S1 = S[(i << 1) + 1];
if ((S0 >> 26) == 0x3f && (S1 >> 26) == 0x3f) {
D32[i] = ((S0 << 8) & 0x0000F800) |
((S0 >> 5) & 0x000007E0) |
((S0 >> 19) & 0x0000001F) |
((S1 << 24) & 0xF8000000) |
((S1 << 11) & 0x07E00000) |
((S1 >> 3) & 0x001F0000);
}
else {
SET_PIXEL( D[(i << 1) + 0], S0 );
SET_PIXEL( D[(i << 1) + 1], S1 );
}
}
if (w & 1)
SET_PIXEL( D[w-1], S[w-1] );
#else
SET_PIXEL_DUFFS_DEVICE( D, S, w );
#endif
dest_buf += dest_rowstride;
src_buf += src_rowstride;
}
}
#undef SET_PIXEL
#undef SET_PIXEL_DUFFS_DEVICE
static void
gdk_directfb_draw_pixbuf (GdkDrawable *drawable,
GdkGC *gc,
GdkPixbuf *pixbuf,
gint src_x,
gint src_y,
gint dest_x,
gint dest_y,
gint width,
gint height,
GdkRgbDither dither,
gint x_dither,
gint y_dither)
{
GdkPixbuf *composited = NULL;
#if 0
cairo_region_t *clip;
cairo_region_t *drect;
GdkRectangle tmp_rect;
#endif
GdkDrawableImplDirectFB *impl = GDK_DRAWABLE_IMPL_DIRECTFB (drawable);
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);
g_return_if_fail (drawable != NULL);
if (width == -1)
width = pixbuf->width;
if (height == -1)
height = pixbuf->height;
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);
D_DEBUG_AT( GDKDFB_Drawable, "%s( %p, %p, %p, %4d,%4d -> %4d,%4d - %dx%d )\n", G_STRFUNC,
drawable, gc, pixbuf, src_x, src_y, dest_x, dest_y, width, height );
/* Clip to the drawable; this is required for get_from_drawable() so
* can't be done implicitly
*/
if (dest_x < 0)
{
src_x -= dest_x;
width += dest_x;
dest_x = 0;
}
if (dest_y < 0)
{
src_y -= dest_y;
height += dest_y;
dest_y = 0;
}
if ((dest_x + width) > impl->width)
width = impl->width - dest_x;
if ((dest_y + height) > impl->height)
height = impl->height - dest_y;
if (width <= 0 || height <= 0)
return;
#if 0
/* Clip to the clip region; this avoids getting more
* image data from the server than we need to.
*/
tmp_rect.x = dest_x;
tmp_rect.y = dest_y;
tmp_rect.width = width;
tmp_rect.height = height;
drect = cairo_region_create_rectangle (&tmp_rect);
clip = gdk_drawable_get_clip_region (drawable);
cairo_region_intersect (drect, clip);
cairo_region_get_extents (drect, &tmp_rect);
cairo_region_destroy (drect);
cairo_region_destroy (clip);
if (tmp_rect.width == 0 ||
tmp_rect.height == 0)
return;
#endif
if (pixbuf->has_alpha && impl->format == DSPF_RGB16) {
void *data;
int pitch;
if (impl->surface->Lock( impl->surface, DSLF_READ | DSLF_WRITE, &data, &pitch ) == DFB_OK) {
composite_565( pixbuf->pixels + src_y * pixbuf->rowstride + src_x * 4,
pixbuf->rowstride,
data + dest_y * pitch + dest_x * 2,
pitch,
#if G_BYTE_ORDER == G_BIG_ENDIAN
GDK_MSB_FIRST,
#else
GDK_LSB_FIRST,
#endif
width, height );
impl->surface->Unlock( impl->surface );
return;
}
}
/* Actually draw */
if (!gc)
gc = _gdk_drawable_get_scratch_gc (drawable, FALSE);
if (pixbuf->has_alpha)
{
GdkVisual *visual = gdk_drawable_get_visual (drawable);
void (*composite_func) (guchar *src_buf,
gint src_rowstride,
guchar *dest_buf,
gint dest_rowstride,
GdkByteOrder dest_byte_order,
gint width,
gint height) = NULL;
/* First we see if we have a visual-specific composition function that can composite
* the pixbuf data directly onto the image
*/
if (visual)
{
gint bits_per_pixel = _gdk_windowing_get_bits_for_depth (gdk_drawable_get_display (drawable),
visual->depth);
if (visual->byte_order == (G_BYTE_ORDER == G_BIG_ENDIAN ? GDK_MSB_FIRST : GDK_LSB_FIRST) &&
visual->depth == 16 &&
visual->red_mask == 0xf800 &&
visual->green_mask == 0x07e0 &&
visual->blue_mask == 0x001f)
composite_func = composite_565;
else if (visual->depth == 24 && bits_per_pixel == 32 &&
visual->red_mask == 0xff0000 &&
visual->green_mask == 0x00ff00 &&
visual->blue_mask == 0x0000ff)
composite_func = composite_0888;
}
/* We can't use our composite func if we are required to dither
*/
if (composite_func && !(dither == GDK_RGB_DITHER_MAX && visual->depth != 24))
{
#if 0
gint x0, y0;
for (y0 = 0; y0 < height; y0 += GDK_SCRATCH_IMAGE_HEIGHT)
{
gint height1 = MIN (height - y0, GDK_SCRATCH_IMAGE_HEIGHT);
for (x0 = 0; x0 < width; x0 += GDK_SCRATCH_IMAGE_WIDTH)
{
gint xs0, ys0;
gint width1 = MIN (width - x0, GDK_SCRATCH_IMAGE_WIDTH);
GdkImage *image = _gdk_image_get_scratch (gdk_drawable_get_screen (drawable),
width1, height1,
gdk_drawable_get_depth (drawable), &xs0, &ys0);
gdk_drawable_copy_to_image (drawable, image,
dest_x + x0, dest_y + y0,
xs0, ys0,
width1, height1);
(*composite_func) (pixbuf->pixels + (src_y + y0) * pixbuf->rowstride + (src_x + x0) * 4,
pixbuf->rowstride,
(guchar*)image->mem + ys0 * image->bpl + xs0 * image->bpp,
image->bpl,
visual->byte_order,
width1, height1);
gdk_draw_image (drawable, gc, image,
xs0, ys0,
dest_x + x0, dest_y + y0,
width1, height1);
}
}
#else
void *data;
int pitch;
if (impl->surface->Lock( impl->surface, DSLF_READ | DSLF_WRITE, &data, &pitch ) == DFB_OK) {
(*composite_func) (pixbuf->pixels + src_y * pixbuf->rowstride + src_x * 4,
pixbuf->rowstride,
data + dest_y * pitch + DFB_BYTES_PER_LINE( impl->format, dest_x ),
pitch,
visual->byte_order,
width, height);
impl->surface->Unlock( impl->surface );
}
#endif
goto out;
}
else
{
/* No special composition func, convert dest to 24 bit RGB data, composite against
* that, and convert back.
*/
composited = gdk_pixbuf_get_from_drawable (NULL,
drawable,
NULL,
dest_x, dest_y,
0, 0,
width, height);
if (composited)
composite (pixbuf->pixels + src_y * pixbuf->rowstride + src_x * 4,
pixbuf->rowstride,
composited->pixels,
composited->rowstride,
width, height);
}
}
if (composited)
{
src_x = 0;
src_y = 0;
pixbuf = composited;
}
if (pixbuf->n_channels == 4)
{
guchar *buf = pixbuf->pixels + src_y * pixbuf->rowstride + src_x * 4;
gdk_draw_rgb_32_image_dithalign (drawable, gc,
dest_x, dest_y,
width, height,
dither,
buf, pixbuf->rowstride,
x_dither, y_dither);
}
else /* n_channels == 3 */
{
guchar *buf = pixbuf->pixels + src_y * pixbuf->rowstride + src_x * 3;
gdk_draw_rgb_image_dithalign (drawable, gc,
dest_x, dest_y,
width, height,
dither,
buf, pixbuf->rowstride,
x_dither, y_dither);
}
out:
if (composited)
g_object_unref (composited);
}
static inline void
convert_rgba_pixbuf_to_image (guint32 *src,
guint src_pitch,
......
......@@ -560,7 +560,6 @@ gdk_draw_glyphs_transformed
gdk_draw_image
gdk_draw_line
gdk_draw_lines
gdk_draw_pixbuf
gdk_draw_point
gdk_draw_points
gdk_draw_polygon
......
......@@ -49,18 +49,6 @@ static GdkDrawable* gdk_drawable_real_get_composite_drawable (GdkDrawable *draw
gint *composite_x_offset,
gint *composite_y_offset);
static cairo_region_t * gdk_drawable_real_get_visible_region (GdkDrawable *drawable);
static void gdk_drawable_real_draw_pixbuf (GdkDrawable *drawable,
GdkGC *gc,
GdkPixbuf *pixbuf,
gint src_x,
gint src_y,
gint dest_x,
gint dest_y,
gint width,
gint height,
GdkRgbDither dither,
gint x_dither,
gint y_dither);
static void gdk_drawable_real_draw_drawable (GdkDrawable *drawable,
GdkGC *gc,
GdkDrawable *src,
......@@ -82,7 +70,6 @@ gdk_drawable_class_init (GdkDrawableClass *klass)
/* Default implementation for clip and visible region is the same */
klass->get_clip_region = gdk_drawable_real_get_visible_region;
klass->get_visible_region = gdk_drawable_real_get_visible_region;
klass->draw_pixbuf = gdk_drawable_real_draw_pixbuf;
klass->draw_drawable = gdk_drawable_real_draw_drawable;
}
......@@ -551,71 +538,6 @@ gdk_draw_image (GdkDrawable *drawable,
xdest, ydest, width, height);
}
/**
* gdk_draw_pixbuf:
* @drawable: Destination drawable.
* @gc: (allow-none): a #GdkGC, used for clipping, or %NULL
* @pixbuf: a #GdkPixbuf
* @src_x: Source X coordinate within pixbuf.
* @src_y: Source Y coordinates within pixbuf.
* @dest_x: Destination X coordinate within drawable.
* @dest_y: Destination Y coordinate within drawable.
* @width: Width of region to render, in pixels, or -1 to use pixbuf width.
* @height: Height of region to render, in pixels, or -1 to use pixbuf height.
* @dither: Dithering mode for #GdkRGB.
* @x_dither: X offset for dither.
* @y_dither: Y offset for dither.
*
* Renders a rectangular portion of a pixbuf to a drawable. The destination
* drawable must have a colormap. All windows have a colormap, however, pixmaps
* only have colormap by default if they were created with a non-%NULL window
* argument. Otherwise a colormap must be set on them with
* gdk_drawable_set_colormap().
*
* On older X servers, rendering pixbufs with an alpha channel involves round
* trips to the X server, and may be somewhat slow.
*
* If GDK is built with the Sun mediaLib library, the gdk_draw_pixbuf
* function is accelerated using mediaLib, which provides hardware
* acceleration on Intel, AMD, and Sparc chipsets. If desired, mediaLib
* support can be turned off by setting the GDK_DISABLE_MEDIALIB environment
* variable.
*
* Since: 2.2
**/
void
gdk_draw_pixbuf (GdkDrawable *drawable,
GdkGC *gc,
const GdkPixbuf *pixbuf,
gint src_x,
gint src_y,
gint dest_x,
gint dest_y,
gint width,
gint height,
GdkRgbDither dither,
gint x_dither,
gint y_dither)
{
g_return_if_fail (GDK_IS_DRAWABLE (drawable));
g_return_if_fail (gc == NULL || GDK_IS_GC (gc));
g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
if (width == 0 || height == 0)
return;
if (width == -1)
width = gdk_pixbuf_get_width (pixbuf);
if (height == -1)
height = gdk_pixbuf_get_height (pixbuf);
GDK_DRAWABLE_GET_CLASS (drawable)->draw_pixbuf (drawable, gc,
(GdkPixbuf *) pixbuf,
src_x, src_y, dest_x, dest_y,
width, height,
dither, x_dither, y_dither);
}
/**
* gdk_draw_points:
* @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
......@@ -1121,214 +1043,6 @@ _gdk_drawable_ref_cairo_surface (GdkDrawable *drawable)
return GDK_DRAWABLE_GET_CLASS (drawable)->ref_cairo_surface (drawable);
}
static void
composite (guchar *src_buf,
gint src_rowstride,
guchar *dest_buf,
gint dest_rowstride,
gint width,
gint height)
{
guchar *src = src_buf;
guchar *dest = dest_buf;
while (height--)
{
gint twidth = width;
guchar *p = src;
guchar *q = dest;
while (twidth--)
{
guchar a = p[3];
guint t;
t = a * p[0] + (255 - a) * q[0] + 0x80;
q[0] = (t + (t >> 8)) >> 8;
t = a * p[1] + (255 - a) * q[1] + 0x80;
q[1] = (t + (t >> 8)) >> 8;
t = a * p[2] + (255 - a) * q[2] + 0x80;
q[2] = (t + (t >> 8)) >> 8;
p += 4;
q += 3;
}
src += src_rowstride;
dest += dest_rowstride;
}
}
static void
composite_0888 (guchar *src_buf,
gint src_rowstride,
guchar *dest_buf,
gint dest_rowstride,
GdkByteOrder dest_byte_order,
gint width,
gint height)
{
guchar *src = src_buf;
guchar *dest = dest_buf;
while (height--)
{
gint twidth = width;
guchar *p = src;
guchar *q = dest;
if (dest_byte_order == GDK_LSB_FIRST)
{
while (twidth--)
{
guint t;
t = p[3] * p[2] + (255 - p[3]) * q[0] + 0x80;
q[0] = (t + (t >> 8)) >> 8;
t = p[3] * p[1] + (255 - p[3]) * q[1] + 0x80;
q[1] = (t + (t >> 8)) >> 8;
t = p[3] * p[0] + (255 - p[3]) * q[2] + 0x80;
q[2] = (t + (t >> 8)) >> 8;
p += 4;
q += 4;
}
}
else
{
while (twidth--)
{
guint t;
t = p[3] * p[0] + (255 - p[3]) * q[1] + 0x80;
q[1] = (t + (t >> 8)) >> 8;
t = p[3] * p[1] + (255 - p[3]) * q[2] + 0x80;
q[2] = (t + (t >> 8)) >> 8;
t = p[3] * p[2] + (255 - p[3]) * q[3] + 0x80;
q[3] = (t + (t >> 8)) >> 8;
p += 4;
q += 4;
}
}
src += src_rowstride;
dest += dest_rowstride;
}
}
#ifdef USE_MEDIALIB
static void
composite_0888_medialib (guchar *src_buf,
gint src_rowstride,
guchar *dest_buf,
gint dest_rowstride,
GdkByteOrder dest_byte_order,
gint width,
gint height)
{
guchar *src = src_buf;
guchar *dest = dest_buf;
mlib_image img_src, img_dst;
mlib_ImageSetStruct (&img_dst,
MLIB_BYTE,
4,
width,
height,
dest_rowstride,
dest_buf);
mlib_ImageSetStruct (&img_src,
MLIB_BYTE,
4,
width,
height,
src_rowstride,
src_buf);
if (dest_byte_order == GDK_LSB_FIRST)
mlib_ImageBlendRGBA2BGRA (&img_dst, &img_src);
else
mlib_ImageBlendRGBA2ARGB (&img_dst, &img_src);
}
#endif
static void
composite_565 (guchar *src_buf,
gint src_rowstride,
guchar *dest_buf,
gint dest_rowstride,
GdkByteOrder dest_byte_order,
gint width,
gint height)
{
guchar *src = src_buf;
guchar *dest = dest_buf;
while (height--)