This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated discards 730f353131afe02ce53c9957b1e80009abba59e4 (commit) via 566ed587e8f01232c84c2aba46d1861a20cd0c27 (commit)
This update added new revisions after undoing existing revisions. That is to say, the old revision is not a strict subset of the new revision. This situation occurs when you --force push a change and generate a repository containing something like this:
* -- * -- B -- O -- O -- O (730f353131afe02ce53c9957b1e80009abba59e4) N -- N -- N (566ed587e8f01232c84c2aba46d1861a20cd0c27)
When this happens we assume that you've already had alert emails for all of the O revisions, and so we here report only the revisions in the N branch from the common base, B.
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/566ed587e8f01232c84c2aba46d1861a20cd0...
commit 566ed587e8f01232c84c2aba46d1861a20cd0c27 Author: Cyril Hrubis metan@ucw.cz Date: Fri Jan 6 20:36:48 2012 +0100
core: Use table for gamma correction.
diff --git a/include/core/GP_GammaCorrection.h b/include/core/GP_GammaCorrection.h index d36b1a9..d7d9d9c 100644 --- a/include/core/GP_GammaCorrection.h +++ b/include/core/GP_GammaCorrection.h @@ -24,6 +24,36 @@
Gamma correction.
+ What is gamma and what is it doing in my computer? + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + First of all gamma is a function, or better there is a gamma function and + it's inverse function. Both gamma function and it's inverse are defined on + interval [0,1] and are defined as out = in^(gamma) and it's inverse as + out = in^(1/gamma). + + The purpose of this function is to compensate nonlinearity of human eye + perception. The human eye is more sensitive to dark tones than the light ones + so without gamma correction storage and manipulation with image data would + either be less efficient in space (in case you decided to use more bits and + encode the image lineary) or quantization in darker tones would be more + visible resulting in "pixelated" images (aliasing). + + So there is a gamma, the internet seems to suggest that usual values for + gamma are 2.5 for old CRT monitors and about 2.2 for LCD ones, ideally you + should have color profile for your device (you need special hardware to + measure it). So if you are trying to draw linear gradient on the screen + you need to generate sequence of numbers accordinly to gamma function + (the 50% intensity is around 186 for gamma = 2.2 and 8bit grayscale pixel). + + Moreover image formats tend to save data in nonlinear fashion (some formats + include gama value used to for the image) so before you apply filter that + manipulates with pixel values, you need to convert it to linear space (adding + some more bits to compensate for rounding errors). + + Also it's important to take gamma into accound if you start drawing anti + aliased shapes, you can't get right results if you don't consider gamma. + */
#ifndef CORE_GP_GAMMA_CORRECTION_H @@ -32,16 +62,17 @@ #include <stdint.h> #include <math.h>
-#define GP_GAMMA 2.2 +extern uint8_t *GP_LinearToGamma_8bit;
/* * Coverts linear 0 255 value into 0 255 gama value. * - * (this is used for Anti Aliased gfx primitives. + * (this is used for Anti Aliased gfx primitives.) */ -static inline uint8_t GP_GammaToLinear(uint8_t val) +static inline uint8_t GP_LinearToGamma(uint8_t val) { - return pow(1.00 * val/255, 1/GP_GAMMA) * 255 + 0.5; + + return GP_LinearToGamma_8bit[val]; }
#endif /* CORE_GP_GAMMA_CORRECTION_H */ diff --git a/libs/core/GP_GammaCorrection.gen.c.t b/libs/core/GP_GammaCorrection.gen.c.t new file mode 100644 index 0000000..0fdd467 --- /dev/null +++ b/libs/core/GP_GammaCorrection.gen.c.t @@ -0,0 +1,30 @@ +%% extends "base.c.t" + +{% block descr %}Gamma correction tables for Gamma = 2.2{% endblock %} + +%% block body + +/* + * Gamma correction tables. + * + * Copyright (c) 2012 Cyril Hrubis metan@ucw.cz + */ + +#include <stdint.h> + +/* + * 8-bit linear to gamma translation table. + */ +static uint8_t linear_to_gamma_8bit[] = { +%% for i in range(0, 256) + {{ int(((float(i)/255) ** (1/2.2)) * 255 + 0.5) }}, /* {{i}} */ +%% endfor +}; + +/* + * Pointer to 8 bit translation table. + */ +uint8_t *GP_LinearToGamma_8bit = linear_to_gamma_8bit; + + +%% endblock body diff --git a/libs/core/Makefile b/libs/core/Makefile index 3af4933..2baef75 100644 --- a/libs/core/Makefile +++ b/libs/core/Makefile @@ -1,5 +1,6 @@ TOPDIR=../.. -GENSOURCES=GP_Pixel.gen.c GP_Blit.gen.c GP_Convert.gen.c +GENSOURCES=GP_Pixel.gen.c GP_Blit.gen.c GP_Convert.gen.c + GP_GammaCorrection.gen.c CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c)) LIBNAME=core
diff --git a/libs/gfx/GP_RectAA.c b/libs/gfx/GP_RectAA.c index 69ddd8f..a48d72e 100644 --- a/libs/gfx/GP_RectAA.c +++ b/libs/gfx/GP_RectAA.c @@ -53,7 +53,7 @@ void GP_FillRectXYXY_AA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
/* Special case, vertical 1px line */ if (out_x0 == out_x1) { - uint8_t mix = GP_GammaToLinear(w); + uint8_t mix = GP_LinearToGamma(w); GP_Coord i;
/* Special case 1px 100% width line */ @@ -71,7 +71,7 @@ void GP_FillRectXYXY_AA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
/* Special case, horizontal 1px line */ if (out_y0 == out_y1) { - uint8_t mix = GP_GammaToLinear(h); + uint8_t mix = GP_LinearToGamma(h); GP_Coord i; /* Special case 1px 100% height line */ @@ -105,7 +105,7 @@ void GP_FillRectXYXY_AA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
/* if the outer and innter coordinates doesn't match, draw blurred edge */ if (in_y0 != out_y0) { - uint8_t mix = GP_GammaToLinear(GP_FP_FROM_INT(in_y0) + GP_FP_1_2 - y0); + uint8_t mix = GP_LinearToGamma(GP_FP_FROM_INT(in_y0) + GP_FP_1_2 - y0); GP_Coord i; for (i = out_x0; i <= out_x1; i++) { @@ -116,7 +116,7 @@ void GP_FillRectXYXY_AA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0, } if (in_y1 != out_y1) { - uint8_t mix = GP_GammaToLinear(y1 - GP_FP_FROM_INT(in_y0) - GP_FP_1_2); + uint8_t mix = GP_LinearToGamma(y1 - GP_FP_FROM_INT(in_y0) - GP_FP_1_2); GP_Coord i; for (i = out_x0; i <= out_x1; i++) { @@ -127,7 +127,7 @@ void GP_FillRectXYXY_AA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0, }
if (in_x0 != out_x0) { - uint8_t mix = GP_GammaToLinear(GP_FP_FROM_INT(in_x0) + GP_FP_1_2 - x0); + uint8_t mix = GP_LinearToGamma(GP_FP_FROM_INT(in_x0) + GP_FP_1_2 - x0); GP_Coord i; for (i = out_y0; i <= out_y1; i++) { @@ -138,7 +138,7 @@ void GP_FillRectXYXY_AA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0, }
if (in_x1 != out_x1) { - uint8_t mix = GP_GammaToLinear(x1 - GP_FP_FROM_INT(in_x1) - GP_FP_1_2); + uint8_t mix = GP_LinearToGamma(x1 - GP_FP_FROM_INT(in_x1) - GP_FP_1_2); GP_Coord i; for (i = out_y0; i <= out_y1; i++) {
-----------------------------------------------------------------------
Summary of changes: include/core/GP_GammaCorrection.h | 32 ++++++++++++++++++++++++++++++-- libs/core/GP_GammaCorrection.gen.c.t | 30 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 libs/core/GP_GammaCorrection.gen.c.t
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.