[maemo-commits] [maemo-commits] r8465 - in projects/haf/trunk/hildon-theme-tools: . src
From: www-data at stage.maemo.org www-data at stage.maemo.orgDate: Wed Nov 29 16:49:16 EET 2006
- Previous message: [maemo-commits] r8464 - projects/haf/branches/hildon-libs/0.14.5-1_check/debian
- Next message: [maemo-commits] r8466 - in projects/haf/branches/maemo-launcher: . 0.21 0.21/debian
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: mdk Date: 2006-11-29 16:49:15 +0200 (Wed, 29 Nov 2006) New Revision: 8465 Modified: projects/haf/trunk/hildon-theme-tools/ChangeLog projects/haf/trunk/hildon-theme-tools/src/slicer.c projects/haf/trunk/hildon-theme-tools/src/slicer.h Log: Detect if image needs alpha and save accordingly in slicer. Modified: projects/haf/trunk/hildon-theme-tools/ChangeLog =================================================================== --- projects/haf/trunk/hildon-theme-tools/ChangeLog 2006-11-29 14:38:51 UTC (rev 8464) +++ projects/haf/trunk/hildon-theme-tools/ChangeLog 2006-11-29 14:49:15 UTC (rev 8465) @@ -1,4 +1,9 @@ 2006-11-29 Michael Dominic Kostrzewa <michael.kostrzewa at nokia.com> + + * src/slicer.c: + * src/slicer.h: Detect if image needs alpha. + +2006-11-29 Michael Dominic Kostrzewa <michael.kostrzewa at nokia.com> * src/hildon-theme-rc-parser: * src/Makefile.am: Adding the new perl script to parse the rc files. Modified: projects/haf/trunk/hildon-theme-tools/src/slicer.c =================================================================== --- projects/haf/trunk/hildon-theme-tools/src/slicer.c 2006-11-29 14:38:51 UTC (rev 8464) +++ projects/haf/trunk/hildon-theme-tools/src/slicer.c 2006-11-29 14:49:15 UTC (rev 8465) @@ -21,6 +21,77 @@ #include "slicer.h" +/* Check if image actually uses alpha by scanning the pixels */ +gboolean check_if_pixbuf_needs_alpha (GdkPixbuf *pixbuf) +{ + guchar *pixels = gdk_pixbuf_get_pixels (pixbuf); + int bytes_per_pixel = gdk_pixbuf_get_n_channels (pixbuf); + int width = gdk_pixbuf_get_width (pixbuf); + int height = gdk_pixbuf_get_height (pixbuf); + long rowstride = gdk_pixbuf_get_rowstride (pixbuf); + int x = 0; + int y = 0; + + g_return_val_if_fail (pixbuf != NULL, FALSE); + g_return_val_if_fail (bytes_per_pixel == 4, FALSE); + + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { + if (pixels [(y * rowstride) + (x * bytes_per_pixel) + 3] != 255) + return TRUE; + } + } + + return FALSE; +} + +/* Create a copy of the pixbuf with alpha removed */ +GdkPixbuf* strip_alpha_from_pixbuf (GdkPixbuf *pixbuf) +{ + GdkPixbuf *new = NULL; + guchar *new_pixels = NULL; + guchar *pixels = gdk_pixbuf_get_pixels (pixbuf); + int bytes_per_pixel = gdk_pixbuf_get_n_channels (pixbuf); + int width = gdk_pixbuf_get_width (pixbuf); + int height = gdk_pixbuf_get_height (pixbuf); + long rowstride = gdk_pixbuf_get_rowstride (pixbuf); + int x = 0; + int y = 0; + int new_x = 0; + int new_y = 0; + + g_return_val_if_fail (width > 0, NULL); + g_return_val_if_fail (height > 0, NULL); + g_return_val_if_fail (bytes_per_pixel == 4, NULL); + g_return_val_if_fail (rowstride > 0, NULL); + + new_pixels = g_malloc (width * height * 3); + g_return_val_if_fail (new_pixels != NULL, NULL); + + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { + new_pixels [(new_y * width * 3) + (new_x * 3)] = pixels [(y * rowstride) + (x * bytes_per_pixel)]; + new_pixels [(new_y * width * 3) + (new_x * 3) + 1] = pixels [(y * rowstride) + (x * bytes_per_pixel) + 1]; + new_pixels [(new_y * width * 3) + (new_x * 3) + 2] = pixels [(y * rowstride) + (x * bytes_per_pixel) + 2]; + new_x++; + } + new_y++; + new_x = 0; + } + + new = gdk_pixbuf_new_from_data (new_pixels, + GDK_COLORSPACE_RGB, + FALSE, + 8, + width, + height, + width * 3, + g_free, + new_pixels); + + return new; +} + /* A helper function to save a png file */ void save_png (GdkPixbuf *pixbuf, gchar *filename) { @@ -63,7 +134,13 @@ g_warning ("Failed to process '%s'!", element->Name); else { gchar *fname = g_build_filename (directory, element->Name, NULL); - + + if (gdk_pixbuf_get_n_channels (sub) == 4 && check_if_pixbuf_needs_alpha (sub) == FALSE) { + GdkPixbuf *oldy = sub; + sub = strip_alpha_from_pixbuf (oldy); + gdk_pixbuf_unref (oldy); + } + if ((strlen (fname) >= 4 && strcmp (fname + (strlen (fname) - 4), ".jpg") == 0) || (strlen (fname) >= 5 && strcmp (fname + (strlen (fname) - 5), ".jpeg") == 0)) save_jpeg (sub, fname); Modified: projects/haf/trunk/hildon-theme-tools/src/slicer.h =================================================================== --- projects/haf/trunk/hildon-theme-tools/src/slicer.h 2006-11-29 14:38:51 UTC (rev 8464) +++ projects/haf/trunk/hildon-theme-tools/src/slicer.h 2006-11-29 14:49:15 UTC (rev 8465) @@ -38,3 +38,8 @@ void save_jpeg (GdkPixbuf *pixbuf, gchar *filename); void process (Template *templ, GdkPixbuf *pixbuf, gchar *directory); + +gboolean check_if_pixbuf_needs_alpha (GdkPixbuf *pixbuf); + +GdkPixbuf* strip_alpha_from_pixbuf (GdkPixbuf *pixbuf); +
- Previous message: [maemo-commits] r8464 - projects/haf/branches/hildon-libs/0.14.5-1_check/debian
- Next message: [maemo-commits] r8466 - in projects/haf/branches/maemo-launcher: . 0.21 0.21/debian
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]