Re: Using GdkPixbuf buffers with GraphicsMagick
- From: Luka Napotnik <luka napotnik gmail com>
- To: jcupitt gmail com
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Using GdkPixbuf buffers with GraphicsMagick
- Date: Wed, 07 Jan 2009 10:29:17 +0100
Here's a sample code that fails:
--------------------------------------------
#include <gtk/gtk.h>
#include <string.h>
#include <wand/magick_wand.h>
guchar *
pixels_pack(guchar *data,
int width,
int height)
{
/* Allocate an array of dimensions width*height for
* RGBA with 16 bits per channel. */
guchar *pixels = g_malloc0(width*height*8);
guchar *pixel_old, *pixel_new;
int rowstride_old = width * 4;
int rowstride_new = width * 8;
int x, y;
guint16 value;
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
pixel_old = data + y * rowstride_old + x;
pixel_new = pixels + y * rowstride_new + x;
value = pixel_old[0];
memcpy(pixel_new, &value, sizeof(gint16));
pixel_new += 2;
value = pixel_old[1];
memcpy(pixel_new, &value, sizeof(gint16));
pixel_new += 2;
value = pixel_old[2];
memcpy(pixel_new, &value, sizeof(gint16));
pixel_new += 2;
value = pixel_old[3];
memcpy(pixel_new, &value, sizeof(gint16));
}
}
return pixels;
}
void
image_grayscale(guchar *image_data,
gint32 width,
gint32 height,
int n_channels)
{
MagickWand *magick_wand;
magick_wand = NewMagickWand();
MagickSetSize(magick_wand,800,600);
if (MagickReadImageBlob(magick_wand, image_data, width*height*8) ==
FALSE)
g_warning("Failed.");
}
int main(int argc, char **argv)
{
GtkWidget *window, *image, *image1;
GdkPixbuf *pixbuf, *pixbuf1;
guchar *data, *pixels;
gtk_init(&argc, &argv);
int width, height, rowstride;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
image = gtk_image_new_from_file("/home/napsy/back2.png");
pixbuf = gtk_image_get_pixbuf(image);
if (!pixbuf)
g_warning("pixbuf == NULL\n");
width = gdk_pixbuf_get_width(pixbuf);
height = gdk_pixbuf_get_height(pixbuf);
rowstride = gdk_pixbuf_get_rowstride(pixbuf);
data = gdk_pixbuf_get_pixels(pixbuf);
pixels = pixels_pack(data, width, height);
image_grayscale(pixels, width, height, 4);
g_free(pixels);
gtk_container_add(window, image);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
--------------------------------------------
Hope this helps.
Greets,
Luka
Dne 07.01.2009 (sre) ob 09:23 +0000 je jcupitt gmail com zapisal(a):
2009/1/7 Luka Napotnik <luka napotnik gmail com>:
I've converted the buffer to an RGBA array with 16-bits per channel. But
loading the blob still fails. Any other ideas?
We can't tell you what's wrong if you don't show any code. You need to
post a tiny (but complete) test program. It'll only take you 30
minutes to write something to load a Pixbuf, unpack to libMagick
format, filter, repack to Pixbuf and save again.
John
--
lp,
Luka
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]