Ejemplo n.º 1
0
static void
x_pixbuf_tmp_draw_tile(int tile, int ofsx, int ofsy)
{
    int i, j, n;
    guint32 pixel;
    int width, height;
    int srcx, srcy;
    int dstx = ofsx, dsty = ofsy;

    width = Tile->unit_width;
    height = Tile->unit_height;
    srcx = (tile % tiles_per_row) * width;
    srcy = (tile / tiles_per_row) * height;

    if (dstx < 0) {
	srcx -= dstx;
	width += dstx;
	dstx = 0;
    }
    if (dsty < 0) {
	srcy -= dsty;
	height += dsty;
	dsty = 0;
    }
    if (dstx > 0)
	width -= dstx;
    if (dsty > 0)
	height -= dsty;

    if (!tmp_pixbuf) {
	tmp_pixbuf = gdk_pixbuf_new(gdk_pixbuf_get_colorspace(tile_pixbuf),
	  gdk_pixbuf_get_has_alpha(tile_pixbuf),
	  gdk_pixbuf_get_bits_per_sample(tile_pixbuf),
	  Tile->unit_width, Tile->unit_height);
	memset(gdk_pixbuf_get_pixels(tmp_pixbuf), 0,
	  Tile->unit_height * gdk_pixbuf_get_rowstride(tmp_pixbuf));
	gdk_pixbuf_copy_area(tile_pixbuf, srcx, srcy, width, height,
	  tmp_pixbuf, dstx, dsty);
	{
	    guchar *pixels;
	    int rowstride;
	    int n_channels;
	    guchar rgba[4];
	    g_return_if_fail(gdk_pixbuf_get_bits_per_sample(tmp_pixbuf) == 8 &&
	      gdk_pixbuf_get_colorspace(tmp_pixbuf) == GDK_COLORSPACE_RGB);
	    pixels = gdk_pixbuf_get_pixels(tmp_pixbuf);
	    rowstride = gdk_pixbuf_get_rowstride(tmp_pixbuf);
	    n_channels = gdk_pixbuf_get_n_channels(tmp_pixbuf);
	    for(j = 0; j < Tile->unit_height; j++)
		for(i = 0; i < Tile->unit_width; i++) {
		    nh_pixbuf_get_pixel(i, j, rgba);
		    rgba[3] = 255;
		    nh_pixbuf_put_pixel(i, j, rgba);
		}
	}
    }
    else
	gdk_pixbuf_composite(tile_pixbuf, tmp_pixbuf, dstx, dsty, width, height,
	  -srcx, -srcy, 1.0, 1.0, GDK_INTERP_NEAREST, 255.0);
}
Ejemplo n.º 2
0
/**
 * gdk_pixbuf_draw_cache_draw:
 * @cache: a #GdkPixbufDrawCache
 * @opts: the #GdkPixbufDrawOpts to use in this draw
 * @drawable: a #GdkDrawable to draw on
 *
 * Redraws the area specified in the pixbuf draw options in an
 * efficient way by using caching.
 **/
void
gdk_pixbuf_draw_cache_draw (GdkPixbufDrawCache *cache,
                            GdkPixbufDrawOpts  *opts,
                            GdkDrawable        *drawable)
{
    GdkRectangle this = opts->zoom_rect;
    GdkPixbufDrawMethod method =
        gdk_pixbuf_draw_cache_get_method (&cache->old, opts);
    int deltax = 0;
    int deltay = 0;
    if (method == GDK_PIXBUF_DRAW_METHOD_CONTAINS)
    {
        deltax = this.x - cache->old.zoom_rect.x;
        deltay = this.y - cache->old.zoom_rect.y;
    }
    else if (method == GDK_PIXBUF_DRAW_METHOD_SCROLL)
    {
        gdk_pixbuf_draw_cache_intersect_draw (cache, opts, drawable);
    }
    else if (method == GDK_PIXBUF_DRAW_METHOD_SCALE)
    {
        int last_width = gdk_pixbuf_get_width (cache->last_pixbuf);
        int last_height = gdk_pixbuf_get_height (cache->last_pixbuf);
        GdkColorspace new_cs = gdk_pixbuf_get_colorspace (opts->pixbuf);
        GdkColorspace last_cs =
            gdk_pixbuf_get_colorspace (cache->last_pixbuf);
        int new_bps = gdk_pixbuf_get_bits_per_sample (opts->pixbuf);
        int last_bps = gdk_pixbuf_get_bits_per_sample (cache->last_pixbuf);
        
        if (this.width > last_width || this.height > last_height ||
            new_cs != last_cs || new_bps != last_bps)
        {
            g_object_unref (cache->last_pixbuf);
            cache->last_pixbuf = gdk_pixbuf_new (new_cs, FALSE, new_bps,
                                                  this.width, this.height);
        }
        
        gdk_pixbuf_scale_blend (opts->pixbuf,
                                cache->last_pixbuf,
                                0, 0,
                                this.width, this.height,
                                (double) -this.x, (double) -this.y,
                                opts->zoom,
                                opts->interp,
                                this.x, this.y,
                                cache->check_size,
                                opts->check_color1,
                                opts->check_color2);
    }
    gdk_draw_pixbuf (drawable,
                     NULL,
                     cache->last_pixbuf,
                     deltax, deltay,
                     opts->widget_x, opts->widget_y,
                     this.width, this.height,
                     GDK_RGB_DITHER_MAX,
                     opts->widget_x, opts->widget_y);
    if (method != GDK_PIXBUF_DRAW_METHOD_CONTAINS)
        cache->old = *opts;
}
Ejemplo n.º 3
0
static GdkPixbuf*
create_spotlight_pixbuf(GdkPixbuf *src, guint32 color, guchar alpha)
{
	GdkPixbuf *dest;
	int i, j;
	int width, height, has_alpha, src_row_stride, dst_row_stride;
	guchar *target_pixels, *original_pixels;
	guchar *pixsrc, *pixdest;
	guchar r, g, b;
	gint n_channels;

	n_channels = gdk_pixbuf_get_n_channels(src);
	has_alpha = gdk_pixbuf_get_has_alpha(src);
	width = gdk_pixbuf_get_width(src);
	height = gdk_pixbuf_get_height(src);

	g_return_val_if_fail(gdk_pixbuf_get_colorspace(src) ==
			     GDK_COLORSPACE_RGB, NULL);
	g_return_val_if_fail((!has_alpha && n_channels == 3) ||
			     (has_alpha && n_channels == 4), NULL);
	g_return_val_if_fail(gdk_pixbuf_get_bits_per_sample(src) == 8, NULL);

	dest = gdk_pixbuf_new(gdk_pixbuf_get_colorspace(src), has_alpha,
			       gdk_pixbuf_get_bits_per_sample(src),
			       width, height);
	
	dst_row_stride = gdk_pixbuf_get_rowstride(dest);
	src_row_stride = gdk_pixbuf_get_rowstride(src);
	target_pixels = gdk_pixbuf_get_pixels(dest);
	original_pixels = gdk_pixbuf_get_pixels(src);

	r = (color & 0xff0000) >> 16;
	g = (color & 0xff00) >> 8;
	b = color & 0xff;

	for (i = 0; i < height; i++)
	{
		gint tmp;

		pixdest = target_pixels + i * dst_row_stride;
		pixsrc = original_pixels + i * src_row_stride;
		for (j = 0; j < width; j++)
		{
			tmp = (*pixsrc++ * alpha + r * (255 - alpha)) / 255;
			*pixdest++ = (guchar) MIN(255, tmp);
			tmp = (*pixsrc++ * alpha + g * (255 - alpha)) / 255;
			*pixdest++ = (guchar) MIN(255, tmp);
			tmp = (*pixsrc++ * alpha + b * (255 - alpha)) / 255;
			*pixdest++ = (guchar) MIN(255, tmp);
			if (has_alpha)
				*pixdest++ = *pixsrc++;
		}
	}

	return dest;
}
Ejemplo n.º 4
0
static void
filter_pixbuf (GdkPixbuf             *src_pixbuf,
               GdkPixbuf             *dst_pixbuf,
               GstyleColorFilterFunc  filter_func)
{
  gint width;
  gint height;
  gint rowstride;
  guint32 *src_data;
  guint32 *dst_data;
  guint32 *src_p;
  guint32 *dst_p;
  GdkRGBA rgba;
  GdkRGBA filtered_rgba;

  g_assert (gdk_pixbuf_get_colorspace (src_pixbuf) == GDK_COLORSPACE_RGB);
  g_assert (gdk_pixbuf_get_colorspace (dst_pixbuf) == GDK_COLORSPACE_RGB);
  g_assert (gdk_pixbuf_get_bits_per_sample (src_pixbuf) == 8);
  g_assert (gdk_pixbuf_get_bits_per_sample (dst_pixbuf) == 8);
  g_assert (gdk_pixbuf_get_has_alpha (src_pixbuf));
  g_assert (gdk_pixbuf_get_has_alpha (dst_pixbuf));

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"

  src_data = (guint32 *)gdk_pixbuf_get_pixels (src_pixbuf);
  dst_data = (guint32 *)gdk_pixbuf_get_pixels (dst_pixbuf);

#pragma GCC diagnostic pop

  width = gdk_pixbuf_get_width (src_pixbuf);
  height = gdk_pixbuf_get_height (src_pixbuf);
  rowstride = gdk_pixbuf_get_rowstride (src_pixbuf);

  for (gint y = 0; y < height; ++y)
    {
      src_p = src_data + y * (rowstride / 4);
      dst_p = dst_data + y * (rowstride / 4);

      for (gint x = 0; x < width; ++x)
        {
          unpack_rgba24 (src_p[x], &rgba);
          if (filter_func != NULL)
            filter_func (&rgba, &filtered_rgba, NULL);
          else
            filtered_rgba = rgba;

          dst_p[x] = pack_rgba24 (&filtered_rgba);
        }
    }
}
Ejemplo n.º 5
0
/*LGPL'd*/
GdkPixbuf *
eel_create_colorized_pixbuf (GdkPixbuf *src,
                             int red_value,
                             int green_value,
                             int blue_value)
{
    int i, j;
    int width, height, has_alpha, src_row_stride, dst_row_stride;
    guchar *target_pixels;
    guchar *original_pixels;
    guchar *pixsrc;
    guchar *pixdest;
    GdkPixbuf *dest;

    g_return_val_if_fail (gdk_pixbuf_get_colorspace (src) == GDK_COLORSPACE_RGB, NULL);
    g_return_val_if_fail ((!gdk_pixbuf_get_has_alpha (src)
                           && gdk_pixbuf_get_n_channels (src) == 3)
                          || (gdk_pixbuf_get_has_alpha (src)
                              && gdk_pixbuf_get_n_channels (src) == 4), NULL);
    g_return_val_if_fail (gdk_pixbuf_get_bits_per_sample (src) == 8, NULL);

    dest = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (src),
                           gdk_pixbuf_get_has_alpha (src),
                           gdk_pixbuf_get_bits_per_sample (src),
                           gdk_pixbuf_get_width (src),
                           gdk_pixbuf_get_height (src));

    has_alpha = gdk_pixbuf_get_has_alpha (src);
    width = gdk_pixbuf_get_width (src);
    height = gdk_pixbuf_get_height (src);
    src_row_stride = gdk_pixbuf_get_rowstride (src);
    dst_row_stride = gdk_pixbuf_get_rowstride (dest);
    target_pixels = gdk_pixbuf_get_pixels (dest);
    original_pixels = gdk_pixbuf_get_pixels (src);

    for (i = 0; i < height; i++) {
        pixdest = target_pixels + i*dst_row_stride;
        pixsrc = original_pixels + i*src_row_stride;
        for (j = 0; j < width; j++) {
            *pixdest++ = (*pixsrc++ * red_value) >> 8;
            *pixdest++ = (*pixsrc++ * green_value) >> 8;
            *pixdest++ = (*pixsrc++ * blue_value) >> 8;
            if (has_alpha) {
                *pixdest++ = *pixsrc++;
            }
        }
    }
    return dest;
}
static GdkPixbuf *
create_new_pixbuf (GdkPixbuf *src)
{
	g_assert (gdk_pixbuf_get_colorspace (src) == GDK_COLORSPACE_RGB);
	g_assert ((!gdk_pixbuf_get_has_alpha (src)
			       && gdk_pixbuf_get_n_channels (src) == 3)
			      || (gdk_pixbuf_get_has_alpha (src)
				  && gdk_pixbuf_get_n_channels (src) == 4));

	return gdk_pixbuf_new (gdk_pixbuf_get_colorspace (src),
			       gdk_pixbuf_get_has_alpha (src),
			       gdk_pixbuf_get_bits_per_sample (src),
			       gdk_pixbuf_get_width (src),
			       gdk_pixbuf_get_height (src));
}
Ejemplo n.º 7
0
static void put_pixel (GdkPixbuf *pixbuf, int x, int y, guchar red, guchar green, guchar blue, guchar alpha)
{
    int width, height, rowstride, n_channels;
    guchar *pixels, *p;

    n_channels = gdk_pixbuf_get_n_channels (pixbuf);

    g_assert (gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB);
    g_assert (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8);
    g_assert (gdk_pixbuf_get_has_alpha (pixbuf));
    g_assert (n_channels == 4);

    width = gdk_pixbuf_get_width (pixbuf);
    height = gdk_pixbuf_get_height (pixbuf);

    g_assert (x >= 0 && x < width);
    g_assert (y >= 0 && y < height);

    rowstride = gdk_pixbuf_get_rowstride (pixbuf);
    pixels = gdk_pixbuf_get_pixels (pixbuf);

    p = pixels + y * rowstride + x * n_channels;
    p[0] = red;
    p[1] = green;
    p[2] = blue;
    p[3] = alpha;

}
Ejemplo n.º 8
0
void
ev_document_misc_invert_pixbuf (GdkPixbuf *pixbuf)
{
    guchar *data, *p;
    guint   width, height, x, y, rowstride, n_channels;

    n_channels = gdk_pixbuf_get_n_channels (pixbuf);
    g_assert (gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB);
    g_assert (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8);

    /* First grab a pointer to the raw pixel data. */
    data = gdk_pixbuf_get_pixels (pixbuf);

    /* Find the number of bytes per row (could be padded). */
    rowstride = gdk_pixbuf_get_rowstride (pixbuf);

    width = gdk_pixbuf_get_width (pixbuf);
    height = gdk_pixbuf_get_height (pixbuf);
    for (x = 0; x < width; x++) {
        for (y = 0; y < height; y++) {
            /* Calculate pixel's offset into the data array. */
            p = data + x * n_channels + y * rowstride;
            /* Change the RGB values*/
            p[0] = 255 - p[0];
            p[1] = 255 - p[1];
            p[2] = 255 - p[2];
        }
    }
}
/**
 * gdk_pixbuf_xlib_render_to_drawable_alpha:
 * @pixbuf: A pixbuf.
 * @drawable: Destination drawable.
 * @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.
 * @height: Height of region to render, in pixels.
 * @alpha_mode: If the image does not have opacity information, this is ignored.
 * Otherwise, specifies how to handle transparency when rendering.
 * @alpha_threshold: If the image does have opacity information and @alpha_mode
 * is GDK_PIXBUF_ALPHA_BILEVEL, specifies the threshold value for opacity
 * values.
 * @dither: Dithering mode for XlibRGB.
 * @x_dither: X offset for dither.
 * @y_dither: Y offset for dither.
 *
 * Renders a rectangular portion of a pixbuf to a drawable.  This is done using
 * XlibRGB, so the specified drawable must have the XlibRGB visual and colormap.
 *
 * When used with #GDK_PIXBUF_ALPHA_BILEVEL, this function has to create a bitmap
 * out of the thresholded alpha channel of the image and, it has to set this
 * bitmap as the clipping mask for the GC used for drawing.  This can be a
 * significant performance penalty depending on the size and the complexity of
 * the alpha channel of the image.  If performance is crucial, consider handling
 * the alpha channel yourself (possibly by caching it in your application) and
 * using gdk_pixbuf_xlib_render_to_drawable() or GdkRGB directly instead.
 **/
void
gdk_pixbuf_xlib_render_to_drawable_alpha (GdkPixbuf *pixbuf, Drawable drawable,
					  int src_x, int src_y,
					  int dest_x, int dest_y,
					  int width, int height,
					  GdkPixbufAlphaMode alpha_mode,
					  int alpha_threshold,
					  XlibRgbDither dither,
					  int x_dither, int y_dither)
{
	Pixmap bitmap = 0;
	GC gc;
	XGCValues gcv;

	g_return_if_fail (pixbuf != NULL);
	g_return_if_fail (gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB);
	g_return_if_fail (gdk_pixbuf_get_n_channels (pixbuf) == 3 || gdk_pixbuf_get_n_channels (pixbuf) == 4);
	g_return_if_fail (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8);

	g_return_if_fail (drawable != 0);
	g_return_if_fail (width >= 0 && height >= 0);
	g_return_if_fail (src_x >= 0 && src_x + width <= gdk_pixbuf_get_width (pixbuf));
	g_return_if_fail (src_y >= 0 && src_y + height <= gdk_pixbuf_get_height (pixbuf));

	if (width == 0 || height == 0)
		return;

	gc = XCreateGC (gdk_pixbuf_dpy, drawable, 0, &gcv);

	if (gdk_pixbuf_get_has_alpha (pixbuf)) {
		/* Right now we only support GDK_PIXBUF_ALPHA_BILEVEL, so we
		 * unconditionally create the clipping mask.
		 */

		bitmap = XCreatePixmap (gdk_pixbuf_dpy,
					RootWindow (gdk_pixbuf_dpy,
						    gdk_pixbuf_screen),
					width, height, 1);
		gdk_pixbuf_xlib_render_threshold_alpha (pixbuf, bitmap,
							src_x, src_y,
							0, 0,
							width, height,
							alpha_threshold);

		XSetClipMask (gdk_pixbuf_dpy, gc, bitmap);
		XSetClipOrigin (gdk_pixbuf_dpy, gc, dest_x, dest_y);
	}

	gdk_pixbuf_xlib_render_to_drawable (pixbuf, drawable, gc,
					    src_x, src_y,
					    dest_x, dest_y,
					    width, height,
					    dither,
					    x_dither, y_dither);

	if (bitmap)
	        XFreePixmap (gdk_pixbuf_dpy, bitmap);

	XFreeGC (gdk_pixbuf_dpy, gc);
}
Ejemplo n.º 10
0
/* Taken from pixbuf doc */
static void
get_pixel (GdkPixbuf *pixbuf, int x, int y, guchar *red, guchar *green, guchar *blue)
{
  int width, height, rowstride, n_channels;
  guchar *pixels, *p;

  n_channels = gdk_pixbuf_get_n_channels (pixbuf);

  g_assert (gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB);
  g_assert (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8);
  g_assert (!gdk_pixbuf_get_has_alpha (pixbuf));
  g_assert (n_channels == 3);

  width = gdk_pixbuf_get_width (pixbuf);
  height = gdk_pixbuf_get_height (pixbuf);

  g_assert (x >= 0 && x < width);
  g_assert (y >= 0 && y < height);

  rowstride = gdk_pixbuf_get_rowstride (pixbuf);
  pixels = gdk_pixbuf_get_pixels (pixbuf);

  p = pixels + y * rowstride + x * n_channels;
  *red   = p[0];
  *green = p[1];
  *blue  = p[2];
}
Ejemplo n.º 11
0
void BallInfo() {
    gint width, height, rowstride, n_channels;
    guchar *pixels, *p;
    n_channels = gdk_pixbuf_get_n_channels(ballimage);
    g_assert(gdk_pixbuf_get_colorspace(ballimage) == GDK_COLORSPACE_RGB);
    g_assert(gdk_pixbuf_get_bits_per_sample(ballimage) == 8);
    width = gdk_pixbuf_get_width(ballimage);
    height = gdk_pixbuf_get_height(ballimage);
    rowstride = gdk_pixbuf_get_rowstride(ballimage);
    pixels = gdk_pixbuf_get_pixels(ballimage);
    gint x, y;
    ball->xsrc = width;
    ball->ysrc = height;
    ball->width = 0;
    ball->height = 0;
    for (x = 0; x < width; ++x) {
        for (y = 0; y < height; ++y) {
            p = pixels + y * rowstride + x * n_channels;
            if ((p[0] != 255) && (p[1] != 255) & (p[2] != 255)) {
                if (x < ball->xsrc)
                    ball->xsrc = x;
                if (y < ball->ysrc)
                    ball->ysrc = y;
                if (x - ball->xsrc > ball->width)
                    ball->width = x - ball->xsrc;
                if (y - ball->ysrc > ball->height)
                    ball->height = y - ball->ysrc;
            }
        }
    }
    //Correct for width & height need for inclusiveness
    ++ball->width;
    ++ball->height;
    return;
}
Ejemplo n.º 12
0
/**
 * Draws the volume meter on top of the icon.
 *
 * @param pixbuf the GdkPixbuf icon to draw the volume meter on
 * @param x offset
 * @param y offset
 * @param h height of the volume meter
 */
static void draw_vol_meter(GdkPixbuf *pixbuf, int x, int y, int h) {
  int width, height, rowstride, n_channels,i;
  guchar *pixels, *p;

  n_channels = gdk_pixbuf_get_n_channels (pixbuf);

  g_assert (gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB);
  g_assert (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8);
  g_assert (gdk_pixbuf_get_has_alpha (pixbuf));
  g_assert (n_channels == 4);

  width = gdk_pixbuf_get_width (pixbuf);
  height = gdk_pixbuf_get_height (pixbuf);

  g_assert (x >= 0 && x < width);
  g_assert ((y+h) >= 0 && y < height);

  rowstride = gdk_pixbuf_get_rowstride (pixbuf);
  pixels = gdk_pixbuf_get_pixels (pixbuf);

  y = (height - y);
  for (i = 0;i < h;i++) {
    p = pixels + (y-i) * rowstride + x * n_channels;
    memcpy(p,vol_meter_row,vol_meter_width);
  }
}
Ejemplo n.º 13
0
static GdkPixbuf *
scale_and_crop_pixbuf (const GdkPixbuf *source,
                       HDImageSize     *destination_size)
{
  HDImageSize image_size;
  double scale;
  GdkPixbuf *pixbuf;

  image_size.width = gdk_pixbuf_get_width (source);
  image_size.height = gdk_pixbuf_get_height (source);

  scale = get_scale_for_aspect_ratio (&image_size, destination_size);

  pixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (source),
                           gdk_pixbuf_get_has_alpha (source),
                           gdk_pixbuf_get_bits_per_sample (source),
                           destination_size->width,
                           destination_size->height);

  gdk_pixbuf_scale (source,
                    pixbuf,
                    0, 0,
                    destination_size->width,
                    destination_size->height,
                    - (image_size.width * scale - destination_size->width) / 2,
                    - (image_size.height * scale - destination_size->height) / 2,
                    scale,
                    scale,
                    GDK_INTERP_BILINEAR);

  return pixbuf;
}
Ejemplo n.º 14
0
static void
uni_nav_update_pixbuf (UniNav * nav)
{
    if (nav->pixbuf)
    {
        g_object_unref (nav->pixbuf);
        nav->pixbuf = NULL;
    }
    GdkPixbuf *pixbuf = uni_image_view_get_pixbuf (nav->view);
    if (!pixbuf)
        return;

    Size pw = uni_nav_get_preview_size (nav);

    nav->pixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (pixbuf),
                                  gdk_pixbuf_get_has_alpha (pixbuf),
                                  8, pw.width, pw.height);
    uni_pixbuf_scale_blend (pixbuf, nav->pixbuf,
                            0, 0, pw.width, pw.height,
                            0, 0,
                            uni_nav_get_zoom (nav),
                            GDK_INTERP_BILINEAR, 0, 0);
    // Lower the flag so the pixbuf isn't recreated more than
    // necessarily.
    nav->update_when_shown = FALSE;
}
Ejemplo n.º 15
0
static CoglBitmap *
bitmap_new_from_pixbuf (CoglContext *ctx,
                        GdkPixbuf *pixbuf)
{
  CoglBool has_alpha;
  GdkColorspace color_space;
  CoglPixelFormat pixel_format;
  int width;
  int height;
  int rowstride;
  int bits_per_sample;
  int n_channels;
  CoglBitmap *bmp;

  /* Get pixbuf properties */
  has_alpha       = gdk_pixbuf_get_has_alpha (pixbuf);
  color_space     = gdk_pixbuf_get_colorspace (pixbuf);
  width           = gdk_pixbuf_get_width (pixbuf);
  height          = gdk_pixbuf_get_height (pixbuf);
  rowstride       = gdk_pixbuf_get_rowstride (pixbuf);
  bits_per_sample = gdk_pixbuf_get_bits_per_sample (pixbuf);
  n_channels      = gdk_pixbuf_get_n_channels (pixbuf);

  /* According to current docs this should be true and so
   * the translation to cogl pixel format below valid */
  g_assert (bits_per_sample == 8);

  if (has_alpha)
    g_assert (n_channels == 4);
  else
    g_assert (n_channels == 3);

  /* Translate to cogl pixel format */
  switch (color_space)
    {
    case GDK_COLORSPACE_RGB:
      /* The only format supported by GdkPixbuf so far */
      pixel_format = has_alpha ?
	COGL_PIXEL_FORMAT_RGBA_8888 :
	COGL_PIXEL_FORMAT_RGB_888;
      break;

    default:
      /* Ouch, spec changed! */
      g_object_unref (pixbuf);
      return FALSE;
    }

  /* We just use the data directly from the pixbuf so that we don't
   * have to copy to a seperate buffer.
   */
  bmp = cogl_bitmap_new_for_data (ctx,
                                  width,
                                  height,
                                  pixel_format,
                                  rowstride,
                                  gdk_pixbuf_get_pixels (pixbuf));

  return bmp;
}
Ejemplo n.º 16
0
// Validate image size and format.  There's no point connecting to the
// size-prepared signal, since we only have a chance to stop the load
// after every BUFSIZE bytes, and we'll likely receive both signals while
// processing the first buffer.
static void area_prepared(GdkPixbufLoader *loader, void *data) {
  struct load_state *state = data;

  if (state->err) {
    return;
  }

  GdkPixbuf *pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);

  // validate image parameters
  // when adding RGBA support, note that gdk-pixbuf does not
  // premultiply alpha
  if (gdk_pixbuf_get_colorspace(pixbuf) != GDK_COLORSPACE_RGB ||
      gdk_pixbuf_get_bits_per_sample(pixbuf) != 8 ||
      gdk_pixbuf_get_has_alpha(pixbuf) ||
      gdk_pixbuf_get_n_channels(pixbuf) != 3) {
    g_set_error(&state->err, OPENSLIDE_ERROR, OPENSLIDE_ERROR_FAILED,
                "Unsupported pixbuf parameters");
    return;
  }
  int w = gdk_pixbuf_get_width(pixbuf);
  int h = gdk_pixbuf_get_height(pixbuf);
  if (w != state->w || h != state->h) {
    g_set_error(&state->err, OPENSLIDE_ERROR, OPENSLIDE_ERROR_FAILED,
                "Dimensional mismatch reading pixbuf: "
                "expected %dx%d, found %dx%d", state->w, state->h, w, h);
    return;
  }

  // commit
  state->pixbuf = pixbuf;
}
Ejemplo n.º 17
0
/* Pads a pixbuf to the specified size, by centering it in a larger transparent
 * pixbuf. Returns a new ref.
 */
static GdkPixbuf *
theme_boxes_pad_to_size (GdkPixbuf *pixbuf,
			 gint       width,
			 gint       height,
			 gint       extra_padding_right)
{
	gint       src_width, src_height;
	GdkPixbuf *padded;
	gint       x_offset, y_offset;

	src_width = gdk_pixbuf_get_width (pixbuf);
	src_height = gdk_pixbuf_get_height (pixbuf);

	x_offset = (width - src_width) / 2;
	y_offset = (height - src_height) / 2;

	padded = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (pixbuf),
				 TRUE, /* alpha */
				 gdk_pixbuf_get_bits_per_sample (pixbuf),
				 width + extra_padding_right,
				 height);

	gdk_pixbuf_fill (padded, 0);

	gdk_pixbuf_copy_area (pixbuf,
			      0, /* source coords */
			      0,
			      src_width,
			      src_height,
			      padded,
			      x_offset, /* dest coords */
			      y_offset);

	return padded;
}
/* Return a new GdkPixbuf enhancing/reducing brightness and contrast according
   to the specified values (from -1.0 to +1.0).  */
GdkPixbuf *
f_pixbuf_copy_apply_brightness_and_contrast (GdkPixbuf *src,
					     float brightness,
					     float contrast)
{
	GdkPixbuf *result_pixbuf;
	char *sp, *dp;
	int width, height;
	int line;
	int result_rowstride, src_rowstride;
	int bytes_per_pixel;

	g_return_val_if_fail ((brightness > -1.0 || F_DOUBLE_EQUAL (brightness, -1.0))
			       && (brightness < 1.0 || F_DOUBLE_EQUAL (brightness, 1.0)),
			      NULL);
	g_return_val_if_fail ((contrast > -1.0 || F_DOUBLE_EQUAL (contrast, -1.0))
			       && (contrast < 1.0 || F_DOUBLE_EQUAL (contrast, 1.0)),
			      NULL);

	if (F_DOUBLE_EQUAL (brightness, 0.0) && F_DOUBLE_EQUAL (contrast, 0.0))
		return gdk_pixbuf_copy (src);

	result_pixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (src),
					gdk_pixbuf_get_has_alpha (src),
					gdk_pixbuf_get_bits_per_sample (src),
					gdk_pixbuf_get_width (src),
					gdk_pixbuf_get_height (src));

	width = gdk_pixbuf_get_width (result_pixbuf);
	height = gdk_pixbuf_get_height (result_pixbuf);

	result_rowstride = gdk_pixbuf_get_rowstride (result_pixbuf);
	src_rowstride = gdk_pixbuf_get_rowstride (src);

	bytes_per_pixel = gdk_pixbuf_get_has_alpha (result_pixbuf) ? 4 : 3;

	sp = gdk_pixbuf_get_pixels (src);
	dp = gdk_pixbuf_get_pixels (result_pixbuf);

	for (line = 0; line < height; line ++) {
		char *sq = sp;
		char *dq = dp;
		int i;

		for (i = 0; i < width; i ++) {
			dq[0] = apply_brightness_and_contrast (sq[0], brightness, contrast);
			dq[1] = apply_brightness_and_contrast (sq[1], brightness, contrast);
			dq[2] = apply_brightness_and_contrast (sq[2], brightness, contrast);

			dq += bytes_per_pixel;
			sq += bytes_per_pixel;
		}

		sp += src_rowstride;
		dp += result_rowstride;
	}

	return result_pixbuf;
}
Ejemplo n.º 19
0
static void put_bounding_box(GdkPixbuf *pixbuf, ImageInfo *ii)
{
    int i, width, height, rowstride, n_channels;
    guchar *pixels, *p;
    const int bb_width = get_big_image_width_sub();
    const int bb_height = get_big_image_height_sub();
    int ns = ii->ns;
    int nl = ii->nl;

    n_channels = gdk_pixbuf_get_n_channels (pixbuf);

    g_assert (gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB);
    g_assert (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8);
    g_assert (!gdk_pixbuf_get_has_alpha (pixbuf));
    g_assert (n_channels == 3);

    width = gdk_pixbuf_get_width (pixbuf);
    height = gdk_pixbuf_get_height (pixbuf);

    rowstride = gdk_pixbuf_get_rowstride (pixbuf);
    pixels = gdk_pixbuf_get_pixels (pixbuf);

    int bb_min_x = (center_samp - bb_width*zoom/2) * width / ns;
    if (bb_min_x < 0) bb_min_x = 0;
    if (bb_min_x > width-1) bb_min_x = width-1;

    int bb_max_x = (center_samp + bb_width*zoom/2) * width / ns;
    if (bb_max_x < 0) bb_max_x = 0;
    if (bb_max_x > width-1) bb_max_x = width-1;

    int bb_min_y = (center_line - bb_height*zoom/2) * height / nl;
    if (bb_min_y < 0) bb_min_y = 0;
    if (bb_min_y > height-1) bb_min_y = height-1;

    int bb_max_y = (center_line + bb_height*zoom/2) * height / nl;
    if (bb_max_y < 0) bb_max_y = 0;
    if (bb_max_y > height-1) bb_max_y = height-1;

    for (i=bb_min_x; i<=bb_max_x; ++i) {
        p = pixels + bb_min_y * rowstride + i * n_channels;
        p[0] = 255;
        p[1] = p[2] = 0;
        p = pixels + bb_max_y * rowstride + i * n_channels;
        p[0] = 255;
        p[1] = p[2] = 0;
    }

    for (i=bb_min_y+1; i<bb_max_y; ++i) {
        p = pixels + i * rowstride + bb_min_x * n_channels;
        p[0] = 255;
        p[1] = p[2] = 0;
        p = pixels + i * rowstride + bb_max_x * n_channels;
        p[0] = 255;
        p[1] = p[2] = 0;
    }
}
Ejemplo n.º 20
0
static nsresult
moz_gdk_pixbuf_to_channel(GdkPixbuf* aPixbuf, nsIURI *aURI,
                          nsIChannel **aChannel)
{
  int width = gdk_pixbuf_get_width(aPixbuf);
  int height = gdk_pixbuf_get_height(aPixbuf);
  NS_ENSURE_TRUE(height < 256 && width < 256 && height > 0 && width > 0 &&
                 gdk_pixbuf_get_colorspace(aPixbuf) == GDK_COLORSPACE_RGB &&
                 gdk_pixbuf_get_bits_per_sample(aPixbuf) == 8 &&
                 gdk_pixbuf_get_has_alpha(aPixbuf) &&
                 gdk_pixbuf_get_n_channels(aPixbuf) == 4,
                 NS_ERROR_UNEXPECTED);

  const int n_channels = 4;
  gsize buf_size = 3 + n_channels * height * width;
  PRUint8 * const buf = (PRUint8*)NS_Alloc(buf_size);
  NS_ENSURE_TRUE(buf, NS_ERROR_OUT_OF_MEMORY);
  PRUint8 *out = buf;

  *(out++) = width;
  *(out++) = height;
  *(out++) = 8; // bits of alpha per pixel
  
  const guchar * const pixels = gdk_pixbuf_get_pixels(aPixbuf);
  int rowextra = gdk_pixbuf_get_rowstride(aPixbuf) - width * n_channels;

  // encode the RGB data and the A data
  const guchar * in = pixels;
  PRUint8 *alpha_out = out + height * width * 3;
#ifdef DEBUG
  PRUint8 * const alpha_start = alpha_out;
#endif
  for (int y = 0; y < height; ++y, in += rowextra) {
    for (int x = 0; x < width; ++x) {
      *(out++) = *(in++); // R
      *(out++) = *(in++); // G
      *(out++) = *(in++); // B
      *(alpha_out++) = *(in++); // A
    }
  }

  NS_ASSERTION(out == alpha_start && alpha_out == buf + buf_size,
               "size miscalculation");

  nsresult rv;
  nsCOMPtr<nsIInputStream> stream;
  rv = NS_NewByteInputStream(getter_AddRefs(stream), (char*)buf, buf_size);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIStringInputStream> sstream = do_QueryInterface(stream);
  sstream->AdoptData((char*)buf, buf_size); // previous call was |ShareData|

  rv = NS_NewInputStreamChannel(aChannel, aURI, stream,
                                NS_LITERAL_CSTRING("image/icon"));
  return rv;
}
Ejemplo n.º 21
0
ASImage *GdkPixbuf2ASImage (GdkPixbuf * pixbuf)
{
	ASImage *im = NULL;

	if (pixbuf) {
		guchar *pixels;
		int width = gdk_pixbuf_get_width (pixbuf);
		int height = gdk_pixbuf_get_height (pixbuf);
		int n_channels = gdk_pixbuf_get_n_channels (pixbuf);
		int rowstride = gdk_pixbuf_get_rowstride (pixbuf);
		int has_alpha = gdk_pixbuf_get_has_alpha (pixbuf) ? 1 : 0;

		if (gdk_pixbuf_get_colorspace (pixbuf) != GDK_COLORSPACE_RGB
				|| gdk_pixbuf_get_bits_per_sample (pixbuf) != 8
				|| width <= 0 || height <= 0 || rowstride <= 0
				|| n_channels != 3 + has_alpha)
			return NULL;

		if ((pixels = gdk_pixbuf_get_pixels (pixbuf)) != NULL) {
			ASScanline buf;
			int y;

			LOCAL_DEBUG_OUT ("stored image size %dx%d", width, height);
			im = create_asimage (width, height, 100);
			prepare_scanline (im->width, 0, &buf, False);

			for (y = 0; y < height; ++y) {
				raw2scanline (pixels + y * rowstride, &buf, NULL, width,
											gdk_pixbuf_get_colorspace (pixbuf) !=
											GDK_COLORSPACE_RGB, has_alpha);

				asimage_add_line (im, IC_RED, buf.red, y);
				asimage_add_line (im, IC_GREEN, buf.green, y);
				asimage_add_line (im, IC_BLUE, buf.blue, y);
				if (has_alpha)
					asimage_add_line (im, IC_ALPHA, buf.alpha, y);
			}
			free_scanline (&buf, True);
		}
	}
	return im;
}
/* Create and initalize global sticky notes instance */
void
stickynotes_applet_init (PanelApplet *panel_applet)
{
	stickynotes = g_new(StickyNotes, 1);

	stickynotes->notes = NULL;
	stickynotes->applets = NULL;
	stickynotes->last_timeout_data = 0;

	g_set_application_name (_("Sticky Notes"));

	/* Register size for icons */
	gtk_icon_size_register ("stickynotes_icon_size", 8,8);

	gtk_window_set_default_icon_name ("consort-sticky-notes-applet");

	stickynotes->icon_normal = gtk_icon_theme_load_icon (
			gtk_icon_theme_get_default (),
			"consort-sticky-notes-applet",
			48, 0, NULL);

	stickynotes->icon_prelight = gdk_pixbuf_new (
			gdk_pixbuf_get_colorspace (stickynotes->icon_normal),
			gdk_pixbuf_get_has_alpha (stickynotes->icon_normal),
			gdk_pixbuf_get_bits_per_sample (
				stickynotes->icon_normal),
			gdk_pixbuf_get_width (stickynotes->icon_normal),
			gdk_pixbuf_get_height (stickynotes->icon_normal));
	stickynotes_make_prelight_icon (stickynotes->icon_prelight,
			stickynotes->icon_normal, 30);
	stickynotes->gconf = gconf_client_get_default();
	stickynotes->visible = TRUE;

	stickynotes_applet_init_icons();
	stickynotes_applet_init_prefs();

	/* Watch GConf values */
	gconf_client_add_dir (stickynotes->gconf, GCONF_PATH,
			GCONF_CLIENT_PRELOAD_NONE, NULL);
	gconf_client_notify_add (stickynotes->gconf, GCONF_PATH "/defaults",
			(GConfClientNotifyFunc) preferences_apply_cb,
			NULL, NULL, NULL);
	gconf_client_notify_add (stickynotes->gconf, GCONF_PATH "/settings",
			(GConfClientNotifyFunc) preferences_apply_cb,
			NULL, NULL, NULL);

	/* Max height for large notes*/
	stickynotes->max_height = 0.8*gdk_screen_get_height( gdk_screen_get_default() );

	/* Load sticky notes */
	stickynotes_load (gtk_widget_get_screen (GTK_WIDGET (panel_applet)));

	install_check_click_on_desktop ();
}
Ejemplo n.º 23
0
gint capture() {
    gint x,y;
    GdkRectangle rect, screen_rect;
    int n_channels, rowstride;
    struct PixelData pixelData;
    int frame;

    if (!window)
    {
        printf("Specified window not found\n");
        return FALSE;
    }

    screen_rect.x      = 0;
    screen_rect.y      = 0;
    screen_rect.width  = gdk_screen_get_width (screen);
    screen_rect.height = gdk_screen_get_height (screen);
    gdk_window_get_origin(window, &x, &y);

    rect.x = x;
    rect.y = y;
    gdk_drawable_get_size (GDK_DRAWABLE (window), &rect.width, &rect.height);


    if (! gdk_rectangle_intersect (&rect, &screen_rect, &rect))
        return FALSE;

    pixbuf = gdk_pixbuf_get_from_drawable (NULL, window,
                                           NULL,
                                           rect.x - x,  rect.y - y , 0, 0,
                                           rect.width, rect.height);

    n_channels = gdk_pixbuf_get_n_channels (pixbuf);
    rowstride =  gdk_pixbuf_get_rowstride(pixbuf);

    g_assert (gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB);
    g_assert (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8);
    g_assert (n_channels >= 3);

    /* preparing pixeldata */
    pixelData.width = gdk_pixbuf_get_width (pixbuf);
    pixelData.height = gdk_pixbuf_get_height (pixbuf);
    pixelData.data = gdk_pixbuf_get_pixels (pixbuf);
    pixelData.rowOrder = TOPDOWN;
    pixelData.n_channels = n_channels;
    pixelData.rowPadding = rowstride - pixelData.width * n_channels;

    frame = ScreenVideo_addFrame(video, flv, &pixelData, timeStamp);

    g_object_unref(pixbuf);
    timeStamp += 1000 / FRAMERATE;

    return TRUE;
}
Ejemplo n.º 24
0
static gboolean
pixdata_equal (GdkPixbuf *p1, GdkPixbuf *p2)
{
  if (gdk_pixbuf_get_colorspace (p1) != gdk_pixbuf_get_colorspace (p2))
    return FALSE;
  if (gdk_pixbuf_get_n_channels (p1) != gdk_pixbuf_get_n_channels (p2))
    return FALSE;
  if (gdk_pixbuf_get_bits_per_sample (p1) != gdk_pixbuf_get_bits_per_sample (p2))
    return FALSE;
  if (gdk_pixbuf_get_width (p1) != gdk_pixbuf_get_width (p2))
    return FALSE;
  if (gdk_pixbuf_get_height (p1) != gdk_pixbuf_get_height (p2))
    return FALSE;
  if (gdk_pixbuf_get_rowstride (p1) != gdk_pixbuf_get_rowstride (p2))
    return FALSE;
  if (memcmp (gdk_pixbuf_get_pixels (p1), gdk_pixbuf_get_pixels (p2),
          gdk_pixbuf_get_byte_length (p1)) != 0)
    return FALSE;

  return TRUE;
}
Ejemplo n.º 25
0
int main(int argc, char** argv)
{
    GtkWidget *window;
	int x, y;

    gtk_init(&argc, &argv);

   /* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_opacity(window, 0.7);
	g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), "pressed");
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_widget_show(window);
    gtk_main();
	*/
	GdkPixbuf* photo = gdk_pixbuf_new_from_file_at_size("bluesky.jpg", 300, 200, NULL);
	//GdkPixbuf* image = gdk_pixbuf_new_from_data(photo,;
	//photo = gdk_pixbuf_flip(photo, FALSE);
	//gdk_pixbuf_fill(photo, 0xff00ff64);
	//gdk_pixbuf_rotate_simple(photo, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE);
	//gdk_pixbuf_save(photo, "thumbnail.png", "png", NULL, NULL);
	guchar *pixels, *p;
	int rowstride, n_channels, bits, width, height ;
	GdkColorspace cs;

	n_channels = gdk_pixbuf_get_n_channels(photo);
	rowstride = gdk_pixbuf_get_rowstride(photo);
	pixels = gdk_pixbuf_get_pixels(photo);
	bits = gdk_pixbuf_get_bits_per_sample(photo);
	cs = gdk_pixbuf_get_colorspace(photo);
	width = gdk_pixbuf_get_width(photo);
	height = gdk_pixbuf_get_height(photo);
	printf("n_channels %d\n", n_channels);
	printf("rowstride %d\n", rowstride);
	printf("bits %d\n", bits);
	printf("cs %d\n", cs);
	printf("width %d\n", width);
	printf("height %d\n", height);

	//photo = gdk_pixbuf_new_from_data(pixels, cs, TRUE, bits, width, height, rowstride, NULL, NULL);
	//gdk_pixbuf_add_alpha(photo, FALSE, 0, 0, 0);

	for(x = 0; x < width; x++)
	{
		for(y = 0; y < height; y++)
		{
			put_pixel(photo, x, y, 100);
		}
	}
	gdk_pixbuf_save(photo, "thumbnail.jpg", "jpeg", NULL, NULL);

    return 0;
}
GdkPixbuf *
eel_create_darkened_pixbuf (GdkPixbuf *src, int saturation, int darken)
{
	gint i, j;
	gint width, height, src_row_stride, dest_row_stride;
	gboolean has_alpha;
	guchar *target_pixels, *original_pixels;
	guchar *pixsrc, *pixdest;
	guchar intensity;
	guchar alpha;
	guchar negalpha;
	guchar r, g, b;
	GdkPixbuf *dest;

	g_return_val_if_fail (gdk_pixbuf_get_colorspace (src) == GDK_COLORSPACE_RGB, NULL);
	g_return_val_if_fail ((!gdk_pixbuf_get_has_alpha (src)
			       && gdk_pixbuf_get_n_channels (src) == 3)
			      || (gdk_pixbuf_get_has_alpha (src)
				  && gdk_pixbuf_get_n_channels (src) == 4), NULL);
	g_return_val_if_fail (gdk_pixbuf_get_bits_per_sample (src) == 8, NULL);

	dest = create_new_pixbuf (src);

	has_alpha = gdk_pixbuf_get_has_alpha (src);
	width = gdk_pixbuf_get_width (src);
	height = gdk_pixbuf_get_height (src);
	dest_row_stride = gdk_pixbuf_get_rowstride (dest);
	src_row_stride = gdk_pixbuf_get_rowstride (src);
	target_pixels = gdk_pixbuf_get_pixels (dest);
	original_pixels = gdk_pixbuf_get_pixels (src);

	for (i = 0; i < height; i++) {
		pixdest = target_pixels + i * dest_row_stride;
		pixsrc = original_pixels + i * src_row_stride;
		for (j = 0; j < width; j++) {
			r = *pixsrc++;
			g = *pixsrc++;
			b = *pixsrc++;
			intensity = (r * 77 + g * 150 + b * 28) >> 8;
			negalpha = ((255 - saturation) * darken) >> 8;
			alpha = (saturation * darken) >> 8;
			*pixdest++ = (negalpha * intensity + alpha * r) >> 8;
			*pixdest++ = (negalpha * intensity + alpha * g) >> 8;
			*pixdest++ = (negalpha * intensity + alpha * b) >> 8;
			if (has_alpha) {
				*pixdest++ = *pixsrc++;
			}
		}
	}
	return dest;
}
Ejemplo n.º 27
0
static void Gimp(char* filename)
{
	GError *Error=NULL;
	GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file(filename,&Error);
	if(NULL != pixbuf)
	{
		guchar *pixels, *p;
		int width, height, rowstride, n_channels;
		pixels=gdk_pixbuf_get_pixels(pixbuf);
		n_channels = gdk_pixbuf_get_n_channels (pixbuf);

		g_assert (gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB);
		g_assert (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8);

		g_assert (!gdk_pixbuf_get_has_alpha (pixbuf));
		g_assert (n_channels == 3);

		width = gdk_pixbuf_get_width (pixbuf);
		height = gdk_pixbuf_get_height (pixbuf);

		rowstride = gdk_pixbuf_get_rowstride (pixbuf);
		pixels = gdk_pixbuf_get_pixels (pixbuf);

		printf("static const uint8_t IMG%d_pixels[]=\n{\n\t",Index);
		for(int y=0;y<height;y++)
		{
			for(int x=0;x<width;x++)
			{
				p = pixels + y * rowstride + x * n_channels;
				printf("%-3d,%-3d,%-3d,  ",p[0],p[1],p[2]);
			}
			printf("\n\t");
		}
		printf("\n};\n");
		printf("static const SGIMPImage IMG%d_image=\n{/* %s */\n",Index,filename);
		printf("\t.dwWidth=%d,\n",width);
		printf("\t.dwHeight=%d,\n",height);
		printf("\t.dwBytes_per_pixel=%d,\n",3);
		printf("\t.pucPixel_data=IMG%d_pixels\n",Index);
		printf("};\n\n");

		Index++;
	}
	else
	{
		printf("Invalid arg: %s\n\tError:%s\n",filename,Error->message);
	}

}
Ejemplo n.º 28
0
static void
overlay_draw(struct graphics_priv *parent, struct graphics_priv *overlay, int window)
{
#if 0
	GdkPixbuf *pixbuf,*pixbuf2;
	GtkWidget *widget=parent->widget;
	guchar *pixels1, *pixels2, *p1, *p2;
	int x,y;
	int rowstride1,rowstride2;
	int n_channels1,n_channels2;

	if (! parent->drawable)
		return;

	pixbuf=gdk_pixbuf_get_from_drawable(NULL, overlay->drawable, NULL, 0, 0, 0, 0, overlay->width, overlay->height);
	pixbuf2=gdk_pixbuf_new(gdk_pixbuf_get_colorspace(pixbuf), TRUE, gdk_pixbuf_get_bits_per_sample(pixbuf), 
				gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf));

	rowstride1 = gdk_pixbuf_get_rowstride (pixbuf);
	rowstride2 = gdk_pixbuf_get_rowstride (pixbuf2);
	pixels1=gdk_pixbuf_get_pixels (pixbuf);	
	pixels2=gdk_pixbuf_get_pixels (pixbuf2);	
	n_channels1 = gdk_pixbuf_get_n_channels (pixbuf);
	n_channels2 = gdk_pixbuf_get_n_channels (pixbuf2);
	for (y = 0 ; y < overlay->height ; y++) {
		for (x = 0 ; x < overlay->width ; x++) {
			p1 = pixels1 + y * rowstride1 + x * n_channels1;
			p2 = pixels2 + y * rowstride2 + x * n_channels2;
			p2[0]=p1[0];
			p2[1]=p1[1];
			p2[2]=p1[2];
			p2[3]=127;
		}
	}
	if (window)
		gdk_draw_pixmap(parent->drawable, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], overlay->background, 0, 0, overlay->p.x, overlay->p.y, overlay->width, overlay->height);
	else
		gdk_draw_pixmap(overlay->background, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], parent->drawable, overlay->p.x, overlay->p.y, 0, 0, overlay->width, overlay->height);
	gdk_draw_pixbuf(parent->drawable, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], pixbuf2, 0, 0, overlay->p.x, overlay->p.y, overlay->width, overlay->height, GDK_RGB_DITHER_NONE, 0, 0);
	if (window)
		gdk_draw_pixmap(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], parent->drawable, overlay->p.x, overlay->p.y, overlay->p.x, overlay->p.y, overlay->width, overlay->height);
#if 0
	gdk_draw_pixmap(gr->gra->drawable,
                        gr->gra->widget->style->fg_gc[GTK_WIDGET_STATE(gr->gra->widget)],
                        img->gra->drawable,
                        0, 0, p->x, p->y, img->gra->width, img->gra->height);
#endif
#endif
}
/**
 * gdk_pixbuf_xlib_render_to_drawable:
 * @pixbuf: A pixbuf.
 * @drawable: Destination drawable.
 * @gc: GC used for rendering.
 * @src_x: Source X coordinate within pixbuf.
 * @src_y: Source Y coordinate within pixbuf.
 * @dest_x: Destination X coordinate within drawable.
 * @dest_y: Destination Y coordinate within drawable.
 * @width: Width of region to render, in pixels.
 * @height: Height of region to render, in pixels.
 * @dither: Dithering mode for XlibRGB.
 * @x_dither: X offset for dither.
 * @y_dither: Y offset for dither.
 *
 * Renders a rectangular portion of a pixbuf to a drawable while using the
 * specified GC.  This is done using XlibRGB, so the specified drawable must
 * have the XlibRGB visual and colormap.  Note that this function will ignore
 * the opacity information for images with an alpha channel; the GC must already
 * have the clipping mask set if you want transparent regions to show through.
 *
 * For an explanation of dither offsets, see the XlibRGB documentation.  In
 * brief, the dither offset is important when re-rendering partial regions of an
 * image to a rendered version of the full image, or for when the offsets to a
 * base position change, as in scrolling.  The dither matrix has to be shifted
 * for consistent visual results.  If you do not have any of these cases, the
 * dither offsets can be both zero.
 **/
void
gdk_pixbuf_xlib_render_to_drawable (GdkPixbuf *pixbuf,
				    Drawable drawable, GC gc,
				    int src_x, int src_y,
				    int dest_x, int dest_y,
				    int width, int height,
				    XlibRgbDither dither,
				    int x_dither, int y_dither)
{
	guchar *buf;
	int rowstride;

	g_return_if_fail (pixbuf != NULL);
	g_return_if_fail (gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB);
	g_return_if_fail (gdk_pixbuf_get_n_channels (pixbuf) == 3 || gdk_pixbuf_get_n_channels (pixbuf) == 4);
	g_return_if_fail (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8);

	g_return_if_fail (drawable != 0);
	g_return_if_fail (gc != 0);

	g_return_if_fail (width >= 0 && height >= 0);
	g_return_if_fail (src_x >= 0 && src_x + width <= gdk_pixbuf_get_width (pixbuf));
	g_return_if_fail (src_y >= 0 && src_y + height <= gdk_pixbuf_get_height (pixbuf));

	if (width == 0 || height == 0)
		return;

	/* This will have to be modified once we support other image types.
	 * Also, GdkRGB does not have gdk_draw_rgb_32_image_dithalign(), so we
	 * have to pack the buffer first.  Sigh.
	 */

	if (gdk_pixbuf_get_has_alpha (pixbuf))
		buf = remove_alpha (pixbuf, src_x, src_y, width, height, &rowstride);
	else {
		buf = gdk_pixbuf_get_pixels (pixbuf) + src_y * gdk_pixbuf_get_rowstride (pixbuf) + src_x * 3;
		rowstride = gdk_pixbuf_get_rowstride (pixbuf);
	}

	xlib_draw_rgb_image_dithalign (drawable, gc,
				       dest_x, dest_y,
				       width, height,
				       dither,
				       buf, rowstride,
				       x_dither, y_dither);

	if (gdk_pixbuf_get_has_alpha (pixbuf))
		g_free (buf);
}
Ejemplo n.º 30
0
static void get_alpha_mask(float_shape_t *shape)
{
   GdkColormap *colormap;
   GdkColor black;
   GdkColor white;
   GdkGC *gc;
   int rowstride, nchannels, x, y;
   guchar *pixels, *p;
   bool bright_green, has_alpha;

   colormap = gdk_colormap_get_system();
   gdk_color_black(colormap, &black);
   gdk_color_white(colormap, &white);

   shape->mask_bitmap =
      (GdkDrawable*)gdk_pixmap_new(NULL, shape->width, shape->height, 1);
   gc = gdk_gc_new(shape->mask_bitmap);
   
   gdk_gc_set_foreground(gc, &black);
   gdk_gc_set_background(gc, &white);
   gdk_draw_rectangle(shape->mask_bitmap, gc, TRUE, 0, 0,
                      shape->width, shape->height);

   nchannels = gdk_pixbuf_get_n_channels(shape->pixbuf);
   g_assert(gdk_pixbuf_get_colorspace(shape->pixbuf) == GDK_COLORSPACE_RGB);
   g_assert(gdk_pixbuf_get_bits_per_sample(shape->pixbuf) == 8);

   has_alpha = gdk_pixbuf_get_has_alpha(shape->pixbuf);
   
   rowstride = gdk_pixbuf_get_rowstride(shape->pixbuf);
   pixels = gdk_pixbuf_get_pixels(shape->pixbuf);

   gdk_gc_set_foreground(gc, &white);
   gdk_gc_set_background(gc, &black);
   
   for (y = 0; y < shape->height; y++) {
      for (x = 0; x < shape->width; x++) {
         p = pixels + y*rowstride + x*nchannels;
         bright_green = 0 == p[0] && 255 == p[1] && 0 == p[2];
         if (has_alpha) {
            if (255 == p[3])  // p[3] is alpha channel
               gdk_draw_point(shape->mask_bitmap, gc, x, y);
         } 
         else if (!bright_green) {   // Bright green is alpha for RGB images
            gdk_draw_point(shape->mask_bitmap, gc, x, y);
         }
      }
   }
}