/*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 void cdgdkGetPixbufData(GdkPixbuf* pixbuf, unsigned char *r, unsigned char *g, unsigned char *b) { int w, h, y, x, bpp; guchar *pixdata, *pixline_data; int rowstride, channels; w = gdk_pixbuf_get_width(pixbuf); h = gdk_pixbuf_get_height(pixbuf); bpp = gdk_pixbuf_get_bits_per_sample(pixbuf)*gdk_pixbuf_get_n_channels(pixbuf); if (bpp!=24 && bpp!=32) return; pixdata = gdk_pixbuf_get_pixels(pixbuf); rowstride = gdk_pixbuf_get_rowstride(pixbuf); channels = gdk_pixbuf_get_n_channels(pixbuf); /* planes are separated in imgdata */ for (y=0; y<h; y++) { int lineoffset = (h-1 - y)*w; /* imgdata is bottom-top */ pixline_data = pixdata + y * rowstride; for(x=0;x<w;x++) { int pos = x*channels; r[lineoffset+x] = pixline_data[pos]; g[lineoffset+x] = pixline_data[pos+1]; b[lineoffset+x] = pixline_data[pos+2]; } } }
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; }
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; }
static void init_graphics2d_as_pixbuf (struct graphics2d *gr) { gint width, height; gint bits_per_sample = 8; gint total_channels = 4; gboolean has_alpha = TRUE; g_assert (gr != NULL); g_assert (gr->drawable != NULL); if (gr->debug) printf ("initializing graphics2d as pixbuf\n"); gdk_drawable_get_size (gr->drawable, &width, &height); gr->drawbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, has_alpha, bits_per_sample, width, height); g_assert (gr->drawbuf != NULL); g_assert (gdk_pixbuf_get_bits_per_sample (gr->drawbuf) == bits_per_sample); g_assert (gdk_pixbuf_get_n_channels (gr->drawbuf) == total_channels); gr->surface = cairo_surface_create_for_image (gdk_pixbuf_get_pixels (gr->drawbuf), CAIRO_FORMAT_ARGB32, gdk_pixbuf_get_width (gr->drawbuf), gdk_pixbuf_get_height (gr->drawbuf), gdk_pixbuf_get_rowstride (gr->drawbuf)); g_assert (gr->surface != NULL); g_assert (gr->cr != NULL); cairo_set_target_surface (gr->cr, gr->surface); }
static EIF_NATURAL_32 inline_F24_256 (EIF_POINTER arg1) { #if GTK_MAJOR_VERSION > 1 return gdk_pixbuf_get_bits_per_sample ((GdkPixbuf*)arg1); #endif ; }
// 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; }
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); }
/* 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]; }
/* 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; }
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; }
/** * 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); } }
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; }
/* 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; }
JNIEXPORT jintArray JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_getImagePixels (JNIEnv *env, jobject obj) { struct graphics2d *gr = NULL; jintArray java_pixels; jint* native_pixels; GdkPixbuf *buf = NULL; gint width, height; gint bits_per_sample = 8; gboolean has_alpha = TRUE; gint total_channels = 4; jint i; gdk_threads_enter(); if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return NULL; } gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); g_assert (gr != NULL); if (gr->debug) printf ("getImagePixels\n"); gdk_drawable_get_size (gr->drawable, &width, &height); buf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, has_alpha, bits_per_sample, width, height); g_assert (buf != NULL); g_assert (gdk_pixbuf_get_bits_per_sample (buf) == bits_per_sample); g_assert (gdk_pixbuf_get_n_channels (buf) == total_channels); /* copy pixels from drawable to pixbuf */ gdk_pixbuf_get_from_drawable (buf, gr->drawable, NULL, 0, 0, 0, 0, width, height); native_pixels= gdk_pixbuf_get_pixels (buf); #ifndef WORDS_BIGENDIAN /* convert pixels from 0xBBGGRRAA to 0xAARRGGBB */ for (i=0; i<width * height; i++) { native_pixels[i] = SWAPU32 ((unsigned)native_pixels[i]); } #endif java_pixels = (*env) -> NewIntArray (env, width * height); (*env)->SetIntArrayRegion(env, java_pixels, (jsize)0, (jsize) width*height, (jint*) native_pixels); gdk_threads_leave(); return java_pixels; }
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; }
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; } }
QImage imageForPixbuf(const GdkPixbuf* pixbuf, const QString &name) { QImage result; if (gdk_pixbuf_get_n_channels(pixbuf) == 3 && gdk_pixbuf_get_bits_per_sample(pixbuf) == 8 && !gdk_pixbuf_get_has_alpha(pixbuf)) { const QImage image = QImage(gdk_pixbuf_get_pixels(pixbuf), gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf), gdk_pixbuf_get_rowstride(pixbuf), QImage::QImage::Format_RGB888); result = image.convertToFormat(QImage::Format_ARGB32); } else { if (gdk_pixbuf_get_n_channels(pixbuf) != 4 || gdk_pixbuf_get_bits_per_sample(pixbuf) != 8 || !gdk_pixbuf_get_has_alpha(pixbuf)) { UQ_WARNING << "Pixbuf is not in the expected format. Trying to load it anyway, will most likely fail" << name; } const QImage image = QImage(gdk_pixbuf_get_pixels(pixbuf), gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf), gdk_pixbuf_get_rowstride(pixbuf), QImage::Format_ARGB32); #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN /* ABGR → ARGB */ result = image.rgbSwapped(); #else /* ABGR → BGRA */ /* Reference: https://bugs.launchpad.net/unity-2d/+bug/758782 */ result = QImage(image.size(), image.format()); for (int i = 0; i < swappedImage.height(); ++i) { QRgb* p = (QRgb*) image.constScanLine(i); QRgb* q = (QRgb*) swappedImage.scanLine(i); QRgb* end = p + image.width(); while (p < end) { *q = qRgba(qAlpha(*p), qRed(*p), qGreen(*p), qBlue(*p)); p++; q++; } } #endif } return result; }
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; }
/* 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 (); }
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; }
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; }
static size_t pixbuf_byte_size (GdkPixbuf *pixbuf) { /* This bit translated from gtk+/gdk-pixbuf/gdk-pixbuf.c:gdk_pixbuf_copy. The comment * there was: * * Calculate a semi-exact size. Here we copy with full rowstrides; * maybe we should copy each row individually with the minimum * rowstride? */ return (gdk_pixbuf_get_height (pixbuf) - 1) * gdk_pixbuf_get_rowstride (pixbuf) + + gdk_pixbuf_get_width (pixbuf) * ((gdk_pixbuf_get_n_channels (pixbuf)* gdk_pixbuf_get_bits_per_sample (pixbuf) + 7) / 8); }
/** * rb_gst_process_embedded_image: * @taglist: a #GstTagList containing an image * @tag: the tag name * * Converts embedded image data extracted from a tag list into * a #GdkPixbuf. The returned #GdkPixbuf is owned by the caller. * * Returns: a #GdkPixbuf, or NULL. */ GdkPixbuf * rb_gst_process_embedded_image (const GstTagList *taglist, const char *tag) { GstBuffer *buf; GdkPixbufLoader *loader; GdkPixbuf *pixbuf; GError *error = NULL; const GValue *val; val = gst_tag_list_get_value_index (taglist, tag, 0); if (val == NULL) { rb_debug ("no value for tag %s in the tag list" , tag); return NULL; } buf = gst_value_get_buffer (val); if (buf == NULL) { rb_debug ("apparently couldn't get image buffer"); return NULL; } /* probably should check media type? text/uri-list won't work too well in a pixbuf loader */ loader = gdk_pixbuf_loader_new (); rb_debug ("sending %d bytes to pixbuf loader", buf->size); if (gdk_pixbuf_loader_write (loader, buf->data, buf->size, &error) == FALSE) { rb_debug ("pixbuf loader doesn't like the data: %s", error->message); g_error_free (error); g_object_unref (loader); return NULL; } pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); if (pixbuf != NULL) { g_object_ref (pixbuf); } gdk_pixbuf_loader_close (loader, NULL); g_object_unref (loader); if (pixbuf == NULL) { rb_debug ("pixbuf loader didn't give us a pixbuf"); return NULL; } rb_debug ("returning embedded image: %d x %d / %d", gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf), gdk_pixbuf_get_bits_per_sample (pixbuf)); return pixbuf; }
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; }
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); } }
/** * 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); }
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 }
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); } } } }