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/566ed587e8f01232c84c2aba46d1861a20cd…
commit 566ed587e8f01232c84c2aba46d1861a20cd0c27
Author: Cyril Hrubis <metan(a)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(a)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(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
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
via 870edf9002091a710e94dd929c2e9583af590f34 (commit)
from 30d9e3ba8aa2412e028bb51b34d3be44ddf7a92b (commit)
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/870edf9002091a710e94dd929c2e9583af59…
commit 870edf9002091a710e94dd929c2e9583af590f34
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jan 6 20:27:13 2012 +0100
pylib: Propagate math python buildins to templates
Now we can use int() float() and round() in templates too.
diff --git a/pylib/gfxprim/render_utils.py b/pylib/gfxprim/render_utils.py
index d99aa3d..b115b91 100644
--- a/pylib/gfxprim/render_utils.py
+++ b/pylib/gfxprim/render_utils.py
@@ -28,6 +28,10 @@ def create_environment(config, template_dir):
env.globals['len'] = len
env.globals['error'] = template_error
env.globals['hex'] = lambda(x): hex(x).rstrip('L')
+ # Propagate some python buildins
+ env.globals['int'] = int;
+ env.globals['float'] = float;
+ env.globals['round'] = round;
return env
-----------------------------------------------------------------------
Summary of changes:
pylib/gfxprim/render_utils.py | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
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
via 30d9e3ba8aa2412e028bb51b34d3be44ddf7a92b (commit)
from 183e450a847b698b96f2f7ecbd08ed785e58879f (commit)
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/30d9e3ba8aa2412e028bb51b34d3be44ddf7…
commit 30d9e3ba8aa2412e028bb51b34d3be44ddf7a92b
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jan 6 00:57:28 2012 +0100
loaders: use png conversion to RGB for unknown palettes.
diff --git a/libs/loaders/GP_PNG.c b/libs/loaders/GP_PNG.c
index 51c645e..c430e72 100644
--- a/libs/loaders/GP_PNG.c
+++ b/libs/loaders/GP_PNG.c
@@ -16,7 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2010 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
@@ -127,7 +127,7 @@ GP_RetCode GP_ReadPNG(FILE *f, GP_Context **res,
GP_DEBUG(2, "Have %s%s interlace %s PNG%s size %ux%u depth %i",
interlace_type_name(interlace_type),
- color_type & PNG_COLOR_MASK_PALETTE ? "pallete " : "",
+ color_type & PNG_COLOR_MASK_PALETTE ? " pallete " : "",
color_type & PNG_COLOR_MASK_COLOR ? "color" : "gray",
color_type & PNG_COLOR_MASK_ALPHA ? " with alpha channel" : "",
(unsigned int)w, (unsigned int)h, depth);
@@ -169,6 +169,12 @@ GP_RetCode GP_ReadPNG(FILE *f, GP_Context **res,
break;
}
}
+
+ /* Convert everything else to RGB888 */
+ //TODO: add palette matching to G2 G4 and G8
+ png_set_palette_to_rgb(png);
+ png_set_bgr(png);
+ pixel_type = GP_PIXEL_RGB888;
break;
}
-----------------------------------------------------------------------
Summary of changes:
libs/loaders/GP_PNG.c | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")