1 /*
2 rgblinear.c
3
4 For Tux Paint
5 RGB to Linear and Linear to RGB functions
6
7 Copyright (c) 2002-2006 by Bill Kendrick and others
8 bill@newbreedsoftware.com
9 http://www.newbreedsoftware.com/tuxpaint/
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 (See COPYING.txt)
25
26 June 14, 2002 - February 18, 2006
27 $Id$
28 */
29
30 #include "rgblinear.h"
31 #include "debug.h"
32
33 /**
34 * Return sRGB mapping (0-255 byte) of a linear (0.0 to 1.0) value
35 * (see rgblinear.h)
36 *
37 * @param linear Linear (float) value
38 * @return sRGB (byte) value
39 */
linear_to_sRGB(float linear)40 unsigned char linear_to_sRGB(float linear)
41 {
42 unsigned slot;
43
44 slot = linear * 4096.0 + 0.5;
45 if (slot > 4095)
46 {
47 if (linear > 0.5)
48 slot = 4095;
49 else
50 slot = 0;
51 }
52 return linear_to_sRGB_table[slot];
53 }
54