1 /* Libart_LGPL - library of basic graphic primitives
2 * Copyright (C) 1998 Raph Levien
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library 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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 /* Some functions to build alphagamma tables */
23 #include "art_alphagamma.h"
28 * art_alphagamma_new: Create a new #ArtAlphaGamma.
29 * @gamma: Gamma value.
31 * Create a new #ArtAlphaGamma for a specific value of @gamma. When
32 * correctly implemented (which is generally not the case in libart),
33 * alpha compositing with an alphagamma parameter is equivalent to
34 * applying the gamma transformation to source images, doing the alpha
35 * compositing (in linear intensity space), then applying the inverse
36 * gamma transformation, bringing it back to a gamma-adjusted
39 * Return value: The newly created #ArtAlphaGamma.
42 art_alphagamma_new (double gamma)
45 ArtAlphaGamma *alphagamma;
51 tablesize = ceil (gamma * 8);
55 alphagamma = (ArtAlphaGamma *)art_alloc (sizeof(ArtAlphaGamma) +
56 ((1 << tablesize) - 1) *
58 alphagamma->gamma = gamma;
59 alphagamma->invtable_size = tablesize;
61 table = alphagamma->table;
62 for (i = 0; i < 256; i++)
63 table[i] = (int)floor (((1 << tablesize) - 1) *
64 pow (i * (1.0 / 255), gamma) + 0.5);
66 invtable = alphagamma->invtable;
67 s = 1.0 / ((1 << tablesize) - 1);
68 r_gamma = 1.0 / gamma;
69 for (i = 0; i < 1 << tablesize; i++)
70 invtable[i] = (int)floor (255 * pow (i * s, r_gamma) + 0.5);
76 * art_alphagamma_free: Free an #ArtAlphaGamma.
77 * @alphagamma: An #ArtAlphaGamma.
79 * Frees the #ArtAlphaGamma.
82 art_alphagamma_free (ArtAlphaGamma *alphagamma)
84 art_free (alphagamma);