[maemo-commits] [maemo-commits] r11469 - in projects/haf/trunk/hildon-theme-tools: . src
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Mon May 7 11:10:31 EEST 2007
- Previous message: [maemo-commits] r11468 - projects/haf/hafbuildbot
- Next message: [maemo-commits] r11470 - in projects/haf/trunk/hildon-theme-tools: . debian src
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: mdk Date: 2007-05-07 11:10:27 +0300 (Mon, 07 May 2007) New Revision: 11469 Modified: projects/haf/trunk/hildon-theme-tools/ChangeLog projects/haf/trunk/hildon-theme-tools/src/common.c projects/haf/trunk/hildon-theme-tools/src/common.h projects/haf/trunk/hildon-theme-tools/src/slicer.c Log: Adding the option to specify the 'separate_alpha' keyword in the slicer data. This will force the alpha of the image to be saved as a separate file (%s_alpha.png). Modified: projects/haf/trunk/hildon-theme-tools/ChangeLog =================================================================== --- projects/haf/trunk/hildon-theme-tools/ChangeLog 2007-05-04 15:07:40 UTC (rev 11468) +++ projects/haf/trunk/hildon-theme-tools/ChangeLog 2007-05-07 08:10:27 UTC (rev 11469) @@ -1,3 +1,12 @@ +2007-05-07 Michael Dominic Kostrzewa <michael.kostrzewa at nokia.com> + + * src/common.c: + * src/common.h: + * src/slicer.h: + * src/slicer.c: Adding the option to specify the 'separate_alpha' + keyword in the slicer data. This will force the alpha of the image to + be saved as a separate file (%s_alpha.png). + 2007-02-22 Michael Dominic Kostrzewa <michael.kostrzewa at nokia.com> [0.3.0-1 release] Modified: projects/haf/trunk/hildon-theme-tools/src/common.c =================================================================== --- projects/haf/trunk/hildon-theme-tools/src/common.c 2007-05-04 15:07:40 UTC (rev 11468) +++ projects/haf/trunk/hildon-theme-tools/src/common.c 2007-05-07 08:10:27 UTC (rev 11469) @@ -198,11 +198,18 @@ element->Height = atoi (vals [3]); element->Name = g_strdup (name); + /* Primitive check for the 'alpha' keyword */ if (size >= 5 && strcmp (vals [4], "alpha") == 0) { element->ForcedAlpha = TRUE; } else element->ForcedAlpha = FALSE; + /* Primitive check for the 'separate_alpha' keyword */ + if (size >= 5 && strcmp (vals [4], "separate_alpha") == 0) { + element->SeparateAlpha = TRUE; + } else + element->SeparateAlpha = FALSE; + Done: if (vals != NULL) g_strfreev (vals); Modified: projects/haf/trunk/hildon-theme-tools/src/common.h =================================================================== --- projects/haf/trunk/hildon-theme-tools/src/common.h 2007-05-04 15:07:40 UTC (rev 11468) +++ projects/haf/trunk/hildon-theme-tools/src/common.h 2007-05-07 08:10:27 UTC (rev 11469) @@ -39,6 +39,7 @@ gint Width; gint Height; gboolean ForcedAlpha; + gboolean SeparateAlpha; } typedef Element; struct _Color Modified: projects/haf/trunk/hildon-theme-tools/src/slicer.c =================================================================== --- projects/haf/trunk/hildon-theme-tools/src/slicer.c 2007-05-04 15:07:40 UTC (rev 11468) +++ projects/haf/trunk/hildon-theme-tools/src/slicer.c 2007-05-07 08:10:27 UTC (rev 11469) @@ -45,6 +45,49 @@ return FALSE; } +/* Create a pixbuf copy with just the alpha channel */ +GdkPixbuf* extract_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; + + 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 * 4); + g_return_val_if_fail (new_pixels != NULL, NULL); + + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { + new_pixels [(y * width * 4) + (x * 4)] = pixels [(y * rowstride) + (x * bytes_per_pixel) + 3]; + new_pixels [(y * width * 4) + (x * 4) + 1] = pixels [(y * rowstride) + (x * bytes_per_pixel) + 3]; + new_pixels [(y * width * 4) + (x * 4) + 2] = pixels [(y * rowstride) + (x * bytes_per_pixel) + 3]; + new_pixels [(y * width * 4) + (x * 4) + 3] = pixels [(y * rowstride) + (x * bytes_per_pixel) + 3]; + } + } + + new = gdk_pixbuf_new_from_data (new_pixels, + GDK_COLORSPACE_RGB, + TRUE, + 8, + width, + height, + width * 4, + g_free, + (gpointer) new_pixels); + + return new; +} + /* Create a copy of the pixbuf with alpha removed */ GdkPixbuf* strip_alpha_from_pixbuf (GdkPixbuf *pixbuf) { @@ -135,7 +178,26 @@ else { gchar *fname = g_build_filename (directory, element->Name, NULL); - // FIXME This only covers one case (nnot stripping alpha when + // Save alpha as a separate filename if that's required + if (gdk_pixbuf_get_n_channels (sub) == 4 && + element->SeparateAlpha == TRUE && + strlen (fname) >= 4 && + strcmp (fname + (strlen (fname) - 4), ".png") == 0) { + + GdkPixbuf *alpha_pixbuf = extract_alpha_from_pixbuf (sub); + gchar *fname_alpha = g_strdup (fname); + fname_alpha [strlen (fname_alpha) - 4] = 0; + gchar *final_fname = g_strdup_printf ("%s_alpha.png", fname_alpha); + + g_print ("Saving separate alpha for %s to %s\n", element->Name, final_fname); + save_png (alpha_pixbuf, final_fname); + + g_free (fname_alpha); + g_free (final_fname); + gdk_pixbuf_unref (alpha_pixbuf); + } + + // FIXME This only covers one case (not stripping alpha when // forced alpha == TRUE). We should also support a case when // alpha needs to be added. if (gdk_pixbuf_get_n_channels (sub) == 4 &&
- Previous message: [maemo-commits] r11468 - projects/haf/hafbuildbot
- Next message: [maemo-commits] r11470 - in projects/haf/trunk/hildon-theme-tools: . debian src
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]