[maemo-commits] [maemo-commits] r18452 - in projects/haf/trunk/hildon-theme-tools: . src
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Thu May 21 11:49:59 EEST 2009
- Previous message: [maemo-commits] r18451 - projects/haf/trunk/libmatchbox2/debian
- Next message: [maemo-commits] r18453 - in projects/haf/trunk/libmatchbox2: . debian matchbox/core
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: danielb Date: 2009-05-21 11:49:57 +0300 (Thu, 21 May 2009) New Revision: 18452 Added: projects/haf/trunk/hildon-theme-tools/src/dither.c projects/haf/trunk/hildon-theme-tools/src/dither.h Modified: projects/haf/trunk/hildon-theme-tools/ChangeLog projects/haf/trunk/hildon-theme-tools/src/Makefile.am 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 projects/haf/trunk/hildon-theme-tools/src/slicer.h Log: 2009-05-21 Daniel Borgmann <danielb at openismus.com> * src/Makefile.am: Add dither tool. * src/common.c (dither_pixbuf), (save_pixbuf): Add dither and save utility functions. * src/common.h: Add dither and save utility function declarations. * src/dither.c (show_usage), (main): Create. * src/dither.h: Create. * src/slicer.c (process): Use save_pixbuf() utility function, remove save_png() and save_jpg() helper functions. * src/slicer.h: Remove save_png() and save_jpg() declarations. Modified: projects/haf/trunk/hildon-theme-tools/ChangeLog =================================================================== --- projects/haf/trunk/hildon-theme-tools/ChangeLog 2009-05-21 08:10:33 UTC (rev 18451) +++ projects/haf/trunk/hildon-theme-tools/ChangeLog 2009-05-21 08:49:57 UTC (rev 18452) @@ -1,3 +1,18 @@ +2009-05-21 Daniel Borgmann <danielb at openismus.com> + + * src/Makefile.am: Add dither tool. + * src/common.c (dither_pixbuf), (save_pixbuf): Add dither and save utility functions. + * src/common.h: Add dither and save utility function declarations. + * src/dither.c (show_usage), (main): Create. + * src/dither.h: Create. + * src/slicer.c (process): Use save_pixbuf() utility function, remove + save_png() and save_jpg() helper functions. + * src/slicer.h: Remove save_png() and save_jpg() declarations. + +2009-05-06 Daniel Borgmann <danielb at openismus.com> + + * src/slicer.c (save_png): Set highest compression level for PNGs. + 2008-11-11 Daniel Borgmann <danielb at openismus.com> * scripts/hildon-theme-bootstrap: Update for devel theme Modified: projects/haf/trunk/hildon-theme-tools/src/Makefile.am =================================================================== --- projects/haf/trunk/hildon-theme-tools/src/Makefile.am 2009-05-21 08:10:33 UTC (rev 18451) +++ projects/haf/trunk/hildon-theme-tools/src/Makefile.am 2009-05-21 08:49:57 UTC (rev 18452) @@ -1,7 +1,8 @@ bin_PROGRAMS = hildon-theme-slicer \ hildon-theme-colourizer \ hildon-theme-regenerator \ - hildon-theme-outliner + hildon-theme-outliner \ + hildon-theme-dither # Slicer hildon_theme_slicer_CFLAGS = $(GTK_CFLAGS) @@ -23,10 +24,16 @@ hildon_theme_outliner_LDADD = $(GTK_LIBS) hildon_theme_outliner_SOURCES = outliner.c common.c +# Dither tool +hildon_theme_dither_CFLAGS = $(GTK_CFLAGS) +hildon_theme_dither_LDADD = $(GTK_LIBS) +hildon_theme_dither_SOURCES = dither.c common.c + MAINTAINERCLEANFILES = Makefile.in noinst_HEADERS = common.h \ colourizer.h \ regenerator.h \ outliner.h \ - slicer.h + slicer.h \ + dither.h Modified: projects/haf/trunk/hildon-theme-tools/src/common.c =================================================================== --- projects/haf/trunk/hildon-theme-tools/src/common.c 2009-05-21 08:10:33 UTC (rev 18451) +++ projects/haf/trunk/hildon-theme-tools/src/common.c 2009-05-21 08:49:57 UTC (rev 18452) @@ -250,3 +250,74 @@ return color; } + +/* Dither a pixmap to 5658 RGBA mode. */ +void dither_pixbuf (GdkPixbuf *pixbuf) +{ + gint x, y; + guchar *gpixels; + guchar *pixit; + gint width, height; + gint rowstride; + + if (gdk_pixbuf_get_bits_per_sample (pixbuf) != 8) + { + printf("Dithering failed: Can only use 8bpp\n"); + return; + } + + gpixels = gdk_pixbuf_get_pixels (pixbuf); + width = gdk_pixbuf_get_width (pixbuf); + height = gdk_pixbuf_get_height (pixbuf); + rowstride = gdk_pixbuf_get_rowstride (pixbuf); + + for (y=0;y<height;y++) + { + pixit = gpixels + rowstride * y; + + /* set dither error to 0 for the beginning of a new line */ + gint dither_error_red = 0; + gint dither_error_green = 0; + gint dither_error_blue = 0; + /* new line, dither each pixel */ + for (x=0;x<width;x++) + { + gint dithered; + // RED - 5 bits + dithered = ((gint)(*pixit) + dither_error_red) & (~(7)); + if (dithered<0) dithered=0; + if (dithered>255) dithered=255; + dither_error_red -= dithered - *pixit; + *(pixit++) = dithered; + // GREEN - 6 bits + dithered = ((gint)(*pixit) + dither_error_green) & (~(3)); + if (dithered<0) dithered=0; + if (dithered>255) dithered=255; + dither_error_green -= dithered - *pixit; + *(pixit++) = dithered; + // BLUE - 5 bits + dithered = ((gint)(*pixit) + dither_error_blue) & (~(7)); + if (dithered<0) dithered=0; + if (dithered>255) dithered=255; + dither_error_blue -= dithered - *pixit; + *(pixit++) = dithered; + // skip alpha + pixit++; + } + } +} + +/* Save image as jpeg or png with optional dithering. */ +void save_pixbuf (GdkPixbuf *pixbuf, gchar *filename, gboolean dither) +{ + if (dither) { + dither_pixbuf (pixbuf); + } + + if ((strlen (filename) >= 4 && strcmp (filename + (strlen (filename) - 4), ".jpg") == 0) || + (strlen (filename) >= 5 && strcmp (filename + (strlen (filename) - 5), ".jpeg") == 0)) + gdk_pixbuf_save (pixbuf, filename, "jpeg", NULL, "quality", JPEG_QUALITY, NULL); + else + gdk_pixbuf_save (pixbuf, filename, "png", NULL, "compression", "9", NULL); +} + Modified: projects/haf/trunk/hildon-theme-tools/src/common.h =================================================================== --- projects/haf/trunk/hildon-theme-tools/src/common.h 2009-05-21 08:10:33 UTC (rev 18451) +++ projects/haf/trunk/hildon-theme-tools/src/common.h 2009-05-21 08:49:57 UTC (rev 18452) @@ -22,7 +22,10 @@ #include <glib.h> #include <math.h> #include <string.h> +#include <gdk-pixbuf/gdk-pixbuf.h> +#define JPEG_QUALITY "99" + struct _Template { gint Width; @@ -67,3 +70,7 @@ Color* new_color_from_key (GKeyFile *key_file, gchar *name); void free_template (Template *templ); + +void dither_pixbuf (GdkPixbuf *pixbuf); + +void save_pixbuf (GdkPixbuf *pixbuf, gchar *filename, gboolean dither); Added: projects/haf/trunk/hildon-theme-tools/src/dither.c =================================================================== --- projects/haf/trunk/hildon-theme-tools/src/dither.c 2009-05-21 08:10:33 UTC (rev 18451) +++ projects/haf/trunk/hildon-theme-tools/src/dither.c 2009-05-21 08:49:57 UTC (rev 18452) @@ -0,0 +1,68 @@ +/* + * GPL license, Copyright (c) 2006 by Nokia Corporation + * + * Authors: + * Daniel Borgmann <danielb at openismus.com> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "dither.h" + +/* Show some info about basic usage of the tool */ +void show_usage (void) +{ + g_print ("Usage: %s <inputfile> [outputfile]\n\n", g_get_prgname ()); + g_print ("This tool will apply 16 bit dithering (RGBA 5658) to the specified image.\n" + "If you don't specify an output filename, the input file will be overwritten.\n\n"); + g_print ("The tool can save in PNG (.png) and JPEG (.jpg, .jpeg) formats.\n\n"); +} + +int main (int argc, char **argv) +{ + gchar *input_file = NULL; + gchar *output_file = NULL; + GdkPixbuf *pixbuf = NULL; + GError *error = 0; + + g_type_init (); + g_set_prgname (g_basename (argv [0])); + + if (argc < 2) { + show_usage (); + return 1; + } + + input_file = argv [1]; + + if (argc >= 3 && argv [2] != NULL) { + output_file = argv [2]; + } else { + output_file = input_file; + } + + pixbuf = gdk_pixbuf_new_from_file (input_file, &error); + + if (error || !pixbuf) + { + printf("Failed loading %s...\n", input_file); + return 1; + } + + g_print ("Dithering %s.\n", input_file); + save_pixbuf (pixbuf, output_file, TRUE); + + return 0; +} Added: projects/haf/trunk/hildon-theme-tools/src/dither.h =================================================================== --- projects/haf/trunk/hildon-theme-tools/src/dither.h 2009-05-21 08:10:33 UTC (rev 18451) +++ projects/haf/trunk/hildon-theme-tools/src/dither.h 2009-05-21 08:49:57 UTC (rev 18452) @@ -0,0 +1,32 @@ +/* + * GPL license, Copyright (c) 2006 by Nokia Corporation + * + * Authors: + * Daniel Borgmann <danielb at openismus.com> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "common.h" +#include <glib-2.0/glib.h> +#include <stdlib.h> +#include <string.h> + +int main (int argc, char **argv); + +void show_usage (void); + +void show_banner (void); + Modified: projects/haf/trunk/hildon-theme-tools/src/slicer.c =================================================================== --- projects/haf/trunk/hildon-theme-tools/src/slicer.c 2009-05-21 08:10:33 UTC (rev 18451) +++ projects/haf/trunk/hildon-theme-tools/src/slicer.c 2009-05-21 08:49:57 UTC (rev 18452) @@ -135,18 +135,6 @@ return new; } -/* A helper function to save a png file */ -void save_png (GdkPixbuf *pixbuf, gchar *filename) -{ - gdk_pixbuf_save (pixbuf, filename, "png", NULL, NULL); -} - -/* A helper function to save a jpeg image */ -void save_jpeg (GdkPixbuf *pixbuf, gchar *filename) -{ - gdk_pixbuf_save (pixbuf, filename, "jpeg", NULL, "quality", JPEG_QUALITY, NULL); -} - /* Do the work */ void process (Template *templ, GdkPixbuf *pixbuf, gchar *directory) { @@ -181,20 +169,16 @@ // 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 && + /* if ((gdk_pixbuf_get_n_channels (sub) == 4 && check_if_pixbuf_needs_alpha (sub) == FALSE && element->ForcedAlpha == FALSE) || element->NoAlpha == TRUE) { 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); - else - save_png (sub, fname); + }*/ + + save_pixbuf (sub, fname, TRUE); g_free (fname); @@ -219,7 +203,7 @@ g_print ("This tool will slice the input image into individual graphic pieces,\n" "as specified by the template. Optionally you can specify an output directory.\n" "If the directory is not present, it'll be created.\n\n"); - g_print ("The tool can cave in PNG (.png) and JPEG (.jpg, .jpeg) formats.\n\n"); + g_print ("The tool can save in PNG (.png) and JPEG (.jpg, .jpeg) formats.\n\n"); } /* This is the place where we came in... */ Modified: projects/haf/trunk/hildon-theme-tools/src/slicer.h =================================================================== --- projects/haf/trunk/hildon-theme-tools/src/slicer.h 2009-05-21 08:10:33 UTC (rev 18451) +++ projects/haf/trunk/hildon-theme-tools/src/slicer.h 2009-05-21 08:49:57 UTC (rev 18452) @@ -21,22 +21,15 @@ #include "common.h" #include <glib-2.0/glib.h> -#include <gdk-pixbuf/gdk-pixbuf.h> #include <stdlib.h> #include <string.h> -#define JPEG_QUALITY "99" - int main (int argc, char **argv); void show_usage (void); void show_banner (void); -void save_png (GdkPixbuf *pixbuf, gchar *filename); - -void save_jpeg (GdkPixbuf *pixbuf, gchar *filename); - void process (Template *templ, GdkPixbuf *pixbuf, gchar *directory); gboolean check_if_pixbuf_needs_alpha (GdkPixbuf *pixbuf);
- Previous message: [maemo-commits] r18451 - projects/haf/trunk/libmatchbox2/debian
- Next message: [maemo-commits] r18453 - in projects/haf/trunk/libmatchbox2: . debian matchbox/core
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]