From 680a8c314f3b597b2ee18d9aae408a9da4f0ca10 Mon Sep 17 00:00:00 2001 From: William Kendrick Date: Mon, 30 Jan 2006 01:24:50 +0000 Subject: [PATCH] Properly handles a variety of PNG formats when loading Starter images and turning them into thumbnails. (Tested with indexed PNGs, and PNGs where RGB colors were stored, even where pixels were fully transparent.) --- docs/CHANGES.txt | 7 ++++++- src/tuxpaint.c | 39 +++++++++++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index f4e1f6fb9..e7900f5e7 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -9,7 +9,7 @@ http://www.newbreedsoftware.com/tuxpaint/ $Id$ -2006.January.22 (0.9.16) +2006.January.29 (0.9.16) * Interface improvements: ----------------------- * Modified "Text" tool so that it correctly handles the 16-bit unicode @@ -45,6 +45,11 @@ $Id$ * Added GetSystemFontDir() and amended WIN32 code so that the system fonts option work correctly on Windows. + * Properly handles a variety of PNG formats when loading Starter images + and turning them into thumbnails. (Tested with indexed PNGs, and + PNGs where RGB colors were stored, even where pixels were + fully transparent.) + 2005.November.26 (0.9.15b) diff --git a/src/tuxpaint.c b/src/tuxpaint.c index d6e045825..dbffa3986 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -1557,6 +1557,8 @@ static SDL_Surface * img_tools[NUM_TOOLS], * img_tool_names[NUM_TOOLS]; static SDL_Surface * thumbnail(SDL_Surface * src, int max_x, int max_y, int keep_aspect); +static SDL_Surface * thumbnail2(SDL_Surface * src, int max_x, int max_y, + int keep_aspect, int keep_alpha); ////////////////////////////////////////////////////////////////////// // font stuff @@ -10285,6 +10287,12 @@ static void draw_none(void) static SDL_Surface * thumbnail(SDL_Surface * src, int max_x, int max_y, int keep_aspect) +{ + return(thumbnail2(src, max_x, max_y, keep_aspect, 1)); +} + +static SDL_Surface * thumbnail2(SDL_Surface * src, int max_x, int max_y, + int keep_aspect, int keep_alpha) { int x, y; float src_x, src_y, off_x, off_y; @@ -10398,11 +10406,26 @@ static SDL_Surface * thumbnail(SDL_Surface * src, int max_x, int max_y, tg = tg / tmp; ta = ta / tmp; - putpixel(s, x + off_x, y + off_y, SDL_MapRGBA(s->format, - (Uint8) tr, - (Uint8) tg, - (Uint8) tb, - (Uint8) ta)); + if (keep_alpha == 0 && s->format->Amask != 0) + { + tr = ((ta * tr) / 255) + (255 - ta); + tg = ((ta * tg) / 255) + (255 - ta); + tb = ((ta * tb) / 255) + (255 - ta); + + putpixel(s, x + off_x, y + off_y, SDL_MapRGBA(s->format, + (Uint8) tr, + (Uint8) tg, + (Uint8) tb, + 0xff)); + } + else + { + putpixel(s, x + off_x, y + off_y, SDL_MapRGBA(s->format, + (Uint8) tr, + (Uint8) tg, + (Uint8) tb, + (Uint8) ta)); + } } #else src_x = x * xscale; @@ -14031,9 +14054,9 @@ void do_open(void) else { /* Turn it into a thumbnail: */ - - img1 = SDL_DisplayFormat(img); - img2 = thumbnail(img1, THUMB_W - 20, THUMB_H - 20, 0); + + img1 = SDL_DisplayFormatAlpha(img); + img2 = thumbnail2(img1, THUMB_W - 20, THUMB_H - 20, 0, 0); SDL_FreeSurface(img1); show_progress_bar();