[maemo-commits] [maemo-commits] r18648 - in projects/haf/trunk/hildon-theme-tools: . src
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Mon Jun 8 14:09:11 EEST 2009
- Previous message: [maemo-commits] r18647 - projects/haf/tags/pango1.0
- Next message: [maemo-commits] r18649 - in projects/haf/trunk/hildon-thumbnail: . debian
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: danielb Date: 2009-06-08 14:09:08 +0300 (Mon, 08 Jun 2009) New Revision: 18648 Modified: projects/haf/trunk/hildon-theme-tools/ChangeLog projects/haf/trunk/hildon-theme-tools/src/common.c projects/haf/trunk/hildon-theme-tools/src/dither.c Log: 2009-06-08 Daniel Borgmann <danielb at openismus.com> * src/common.c (dither_pixbuf): New dither algorithm. * src/dither.c (main): Fix a crasher. Modified: projects/haf/trunk/hildon-theme-tools/ChangeLog =================================================================== --- projects/haf/trunk/hildon-theme-tools/ChangeLog 2009-06-08 10:01:09 UTC (rev 18647) +++ projects/haf/trunk/hildon-theme-tools/ChangeLog 2009-06-08 11:09:08 UTC (rev 18648) @@ -1,3 +1,8 @@ +2009-06-08 Daniel Borgmann <danielb at openismus.com> + + * src/common.c (dither_pixbuf): New dither algorithm. + * src/dither.c (main): Fix a crasher. + 2009-05-29 Daniel Borgmann <danielb at openismus.com> [0.6.1-1 release] Modified: projects/haf/trunk/hildon-theme-tools/src/common.c =================================================================== --- projects/haf/trunk/hildon-theme-tools/src/common.c 2009-06-08 10:01:09 UTC (rev 18647) +++ projects/haf/trunk/hildon-theme-tools/src/common.c 2009-06-08 11:09:08 UTC (rev 18648) @@ -254,55 +254,35 @@ /* Dither a pixmap to 5658 RGBA mode. */ void dither_pixbuf (GdkPixbuf *pixbuf) { - gint x, y; - guchar *gpixels; - guchar *pixit; - gint width, height; - gint rowstride; + /* http://en.wikipedia.org/wiki/Floyd-Steinberg_dithering */ + guchar *pixels; + gint width, height; + gint x, y; + gint bpp; + 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); + pixels = gdk_pixbuf_get_pixels (pixbuf); width = gdk_pixbuf_get_width (pixbuf); height = gdk_pixbuf_get_height (pixbuf); + bpp = gdk_pixbuf_get_n_channels (pixbuf); rowstride = gdk_pixbuf_get_rowstride (pixbuf); - + +#define DITHER_COL(OFFS, BITS, MASK) \ + dithered = ((gint)gpixels[x*bpp + OFFS] + (rand()&MASK)) & (~(MASK)); \ + dithered = dithered | dithered>>BITS; \ + if (dithered<0) dithered=0; \ + if (dithered>255) dithered=255; \ + gpixels[x*bpp + OFFS] = dithered; + 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 */ + guchar *gpixels = pixels + rowstride*y; 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++; + DITHER_COL(0, 5, 7) // RED - 5 bits + DITHER_COL(1, 6, 3) // GREEN - 6 bits + DITHER_COL(2, 5, 7) // BLUE - 5 bits } } } Modified: projects/haf/trunk/hildon-theme-tools/src/dither.c =================================================================== --- projects/haf/trunk/hildon-theme-tools/src/dither.c 2009-06-08 10:01:09 UTC (rev 18647) +++ projects/haf/trunk/hildon-theme-tools/src/dither.c 2009-06-08 11:09:08 UTC (rev 18648) @@ -61,10 +61,7 @@ return 1; } - g_print ("Dithering %s.\n", input_file); save_pixbuf (pixbuf, output_file, TRUE); - - gdk_pixbuf_unref (pixbuf); return 0; }
- Previous message: [maemo-commits] r18647 - projects/haf/tags/pango1.0
- Next message: [maemo-commits] r18649 - in projects/haf/trunk/hildon-thumbnail: . debian
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]