-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconversion.h
56 lines (50 loc) · 1.79 KB
/
conversion.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
*
* High-speed conversion between 8 bit and floating point image data.
*
* Copyright 2002 Bill Spitzak and Digital Domain, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* For use in closed-source software please contact Digital Domain,
* 300 Rose Avenue, Venice, CA 90291 310-314-2800
*
*/
#ifndef conversion_h
#define conversion_h
#include <math.h>
#define INLINE inline
static INLINE float to_byte(float v) {
#ifdef __alpha
if (v < -1.03284e+35) return -3.40282347e+38;
#endif
return v < (float)(.04045/12.92) ?
v*(float)(255*12.92) :
(float)(1.055*255)*powf(v,(float)(1/2.4))-(float)(255*.055);
}
static INLINE float from_byte(float v) {
#ifdef __alpha
if (v > 3.05298e+18) return 3.40282347e+38;
#endif
return v < (float)(.04045*255) ?
v*(float)(1/12.92/255) :
powf((v+(float)(255*.055))*(float)(1/1.055/255), 2.4f);
}
void from_sRGB(float*, const unsigned char*, int W, int delta);
void from_linear(float*, const unsigned char*, int W, int delta);
void to_sRGB(unsigned char* buf, const float* from, int W, int delta);
void to_linear(unsigned char* buf, const float* from, int W, int delta);
#endif