1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
void on_click_button_grey(GtkButton *button, gpointer user_data){
GtkBuilder *builder = (GtkBuilder*)user_data;
GdkPixbuf *pixbuf = NULL;
GtkImage *image1 = NULL;
int w = 0;
int h = 0;
int x = 0;
int y = 0;
int gris = 0;
guchar *red= NULL;
guchar *green = NULL;
guchar *blue = NULL;
guchar *buffer=NULL;
gint pos = 0;
gint row_size = 0;
image1 = GTK_IMAGE(gtk_builder_get_object(builder, "image1"));
pixbuf = gdk_pixbuf_new_from_file("image.png", NULL);
w = gdk_pixbuf_get_width(pixbuf);
h = gdk_pixbuf_get_height(pixbuf);
buffer = gdk_pixbuf_get_pixels(pixbuf);
row_size = gdk_pixbuf_get_rowstride(pixbuf);
for (y = 0; y < h; y++) {
for (x = 0; x < w; x++) {
if (gdk_pixbuf_get_has_alpha(pixbuf))
pos = (y * row_size) + (x * 4);
else
pos = (y * row_size) + (x * 3);
*red = buffer[pos];
*green = buffer[pos + 1];
*blue = buffer[pos + 2];
gris = (int)(*red*0.3 + *green*0.59 + *blue*0.11);
buffer[pos] = gris;
buffer[pos + 1] = gris;
buffer[pos + 2] = gris;
}
}
gtk_image_set_from_pixbuf(image1, pixbuf);
g_object_unref(pixbuf);
return;
} |
Partager