Rename GP_Context -> GP_Pixmap
[gfxprim.git] / include / core / GP_GammaCorrection.h
blob37f9f3a7eef9419bdc8539a0096a63ec133eb380
1 /*****************************************************************************
2 * This file is part of gfxprim library. *
3 * *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
8 * *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
18 * *
19 * Copyright (C) 2009-2012 Cyril Hrubis <metan@ucw.cz> *
20 * *
21 *****************************************************************************/
25 Gamma correction.
27 What is gamma and what is it doing in my computer?
28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
30 First of all gamma is a function, or better there is a gamma function and
31 it's inverse function. Both gamma function and it's inverse are defined on
32 interval [0,1] and are defined as out = in^(gamma) and it's inverse as
33 out = in^(1/gamma).
35 The purpose of this function is to compensate nonlinearity of human eye
36 perception. The human eye is more sensitive to dark tones than the light ones
37 so without gamma correction storage and manipulation with image data would
38 either be less efficient in space (in case you decided to use more bits and
39 encode the image lineary) or quantization in darker tones would be more
40 visible resulting in "pixelated" images (aliasing).
42 So there is a gamma, the internet seems to suggest that usual values for
43 gamma are 2.5 for old CRT monitors and about 2.2 for LCD ones, ideally you
44 should have color profile for your device (you need special hardware to
45 measure it). So if you are trying to draw linear gradient on the screen
46 you need to generate sequence of numbers accordinly to gamma function
47 (the 50% intensity is around 186 for gamma = 2.2 and 8bit grayscale pixel).
49 Moreover image formats tend to save data in nonlinear fashion (some formats
50 include gama value used to for the image) so before you apply filter that
51 manipulates with pixel values, you need to convert it to linear space (adding
52 some more bits to compensate for rounding errors).
54 Also it's important to take gamma into accound if you start drawing anti
55 aliased shapes, you can't get right results if you don't consider gamma.
59 #ifndef CORE_GP_GAMMA_CORRECTION_H
60 #define CORE_GP_GAMMA_CORRECTION_H
62 #include <stdint.h>
64 #include "GP_Pixmap.h"
66 #include "GP_GammaCorrection.gen.h"
68 #endif /* CORE_GP_GAMMA_CORRECTION_H */