Gamma corrected scaling.

This commit is contained in:
William Kendrick 2010-02-25 22:02:07 +00:00
parent b0d141fed3
commit f638afa63c
3 changed files with 39 additions and 4 deletions

View file

@ -7,7 +7,7 @@ bill@newbreedsoftware.com
http://www.tuxpaint.org/
June 17, 2002 - February 24, 2010
June 17, 2002 - February 25, 2010
$Id$
@ -92,6 +92,12 @@ $Id$
Public Domain. Archived at the Internet Archive:
http://www.archive.org/details/tornado
Gamma-correction in thumbnail/scaling routine based
example code from:
http://www.4p8.com/eric.brasseur/gamma.html
which was from "Gimp-gluas" plug-in for The GIMP:
http://pippin.gimp.org/plug-ins/gluas/
* Graphics

View file

@ -8,7 +8,7 @@ http://www.tuxpaint.org/
$Id$
2009.February.24 (0.9.22)
2009.February.25 (0.9.22)
* New Tools:
----------
* Label - A tool to add text to a drawing, which can be modified or
@ -45,6 +45,10 @@ $Id$
* Other Improvements:
-------------------
* Thumbnailing (of UI elements, stamps, saved images, etc.) is now
gamma-corrected. See:
http://www.4p8.com/eric.brasseur/gamma.html
* Template images are now supported. Similar to Starters, they are
pre-drawn pictures to begin a new drawing with, accessed via the
"New" dialog. The "Eraser" tool will erase back to the original

View file

@ -64,7 +64,6 @@
#include "debug.h"
#ifdef NOKIA_770
# define LOW_QUALITY_THUMBNAILS
# define LOW_QUALITY_STAMP_OUTLINE
@ -77,8 +76,12 @@
/* #define LOW_QUALITY_STAMP_OUTLINE */
/* #define NO_PROMPT_SHADOWS */
/* #define USE_HWSURFACE */
/* FIXME: Deal with this option properly -bjk 2010.02.25 */
#define GAMMA_CORRECTED_THUMBNAILS
#endif
/* Disable fancy cursors in fullscreen mode, to avoid SDL bug: */
/* (This bug is still around, as of SDL 1.2.9, October 2005) */
/* (Is it still in SDL 1.2.11 in May 2007, though!? -bjk) */
@ -8240,7 +8243,11 @@ static SDL_Surface *thumbnail2(SDL_Surface * src, int max_x, int max_y,
int x, y;
float src_x, src_y, off_x, off_y;
SDL_Surface *s;
#ifdef GAMMA_CORRECTED_THUMBNAILS
float tr, tg, tb, ta;
#else
Uint32 tr, tg, tb, ta;
#endif
Uint8 r, g, b, a;
float xscale, yscale;
int tmp;
@ -8248,7 +8255,6 @@ static SDL_Surface *thumbnail2(SDL_Surface * src, int max_x, int max_y,
Uint32(*getpixel) (SDL_Surface *, int, int) =
getpixels[src->format->BytesPerPixel];
/* FIXME: Deal with gamma, per: http://www.4p8.com/eric.brasseur/gamma.html */
/* Determine scale and centering offsets: */
if (!keep_aspect)
@ -8314,6 +8320,13 @@ static SDL_Surface *thumbnail2(SDL_Surface * src, int max_x, int max_y,
for (x = 0; x < max_x; x++)
{
#ifndef LOW_QUALITY_THUMBNAILS
#ifdef GAMMA_CORRECTED_THUMBNAILS
/* per: http://www.4p8.com/eric.brasseur/gamma.html */
float gamma = 2.2;
float gamma_invert = 1.0 / gamma;
#endif
tr = 0;
tg = 0;
tb = 0;
@ -8330,9 +8343,15 @@ static SDL_Surface *thumbnail2(SDL_Surface * src, int max_x, int max_y,
SDL_GetRGBA(getpixel(src, src_x, src_y),
src->format, &r, &g, &b, &a);
#ifdef GAMMA_CORRECTED_THUMBNAILS
tr = tr + pow((float)r, gamma);
tb = tb + pow((float)b, gamma);
tg = tg + pow((float)g, gamma);
#else
tr = tr + r;
tb = tb + b;
tg = tg + g;
#endif
ta = ta + a;
tmp++;
@ -8346,6 +8365,12 @@ static SDL_Surface *thumbnail2(SDL_Surface * src, int max_x, int max_y,
tg = tg / tmp;
ta = ta / tmp;
#ifdef GAMMA_CORRECTED_THUMBNAILS
tr = pow(tr, gamma_invert);
tg = pow(tg, gamma_invert);
tb = pow(tb, gamma_invert);
#endif
if (keep_alpha == 0 && s->format->Amask != 0)
{
tr = ((ta * tr) / 255) + (255 - ta);