Panda3D
convert_srgb.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file convert_srgb.h
10  * @author rdb
11  * @date 2014-11-13
12  */
13 
14 #ifndef CONVERT_SRGB_H
15 #define CONVERT_SRGB_H
16 
17 #include "pandabase.h"
18 #include "luse.h"
19 #include "pnmimage_base.h"
20 
21 // The below functions can encode and decode sRGB colors in various
22 // representations. Some of them are implemented using look-up tables, some
23 // others using SSE2 intrinsics.
24 extern EXPCL_PANDA_PNMIMAGE const unsigned char to_srgb8_table[256];
25 extern EXPCL_PANDA_PNMIMAGE const unsigned char to_linear_uchar_table[256];
26 extern EXPCL_PANDA_PNMIMAGE const float to_linear_float_table[256];
27 
28 BEGIN_PUBLISH
29 
30 EXPCL_PANDA_PNMIMAGE INLINE float decode_sRGB_float(unsigned char val);
31 EXPCL_PANDA_PNMIMAGE INLINE float decode_sRGB_float(float val);
32 EXPCL_PANDA_PNMIMAGE INLINE unsigned char decode_sRGB_uchar(unsigned char val);
33 EXPCL_PANDA_PNMIMAGE INLINE unsigned char decode_sRGB_uchar(float val);
34 
35 EXPCL_PANDA_PNMIMAGE INLINE float encode_sRGB_float(unsigned char val);
36 EXPCL_PANDA_PNMIMAGE INLINE float encode_sRGB_float(float val);
37 EXPCL_PANDA_PNMIMAGE INLINE unsigned char encode_sRGB_uchar(unsigned char val);
38 EXPCL_PANDA_PNMIMAGE INLINE unsigned char encode_sRGB_uchar(float val);
39 
40 END_PUBLISH
41 
42 // These functions convert more than one component in one go, which can be
43 // faster due to vectorization.
44 EXPCL_PANDA_PNMIMAGE INLINE void encode_sRGB_uchar(const LColorf &from,
45  xel &into);
46 EXPCL_PANDA_PNMIMAGE INLINE void encode_sRGB_uchar(const LColorf &from,
47  xel &into, xelval &into_alpha);
48 
49 EXPCL_PANDA_PNMIMAGE INLINE void encode_sRGB_uchar(const LColord &from,
50  xel &into);
51 EXPCL_PANDA_PNMIMAGE INLINE void encode_sRGB_uchar(const LColord &from,
52  xel &into, xelval &into_alpha);
53 
54 // Use these functions if you know that SSE2 support is available. Otherwise,
55 // they will crash!
56 #if defined(__SSE2__) || defined(__i386__) || defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64)
57 EXPCL_PANDA_PNMIMAGE unsigned char encode_sRGB_uchar_sse2(float val);
58 EXPCL_PANDA_PNMIMAGE void encode_sRGB_uchar_sse2(const LColorf &from,
59  xel &into);
60 EXPCL_PANDA_PNMIMAGE void encode_sRGB_uchar_sse2(const LColorf &from,
61  xel &into, xelval &into_alpha);
62 
63 // Use the following to find out if you can call either of the above.
64 EXPCL_PANDA_PNMIMAGE bool has_sse2_sRGB_encode();
65 #else
66 // The target architecture can't support the SSE2 extension at all.
67 #define encode_sRGB_uchar_sse2 encode_sRGB_uchar
68 #define has_sse2_sRGB_encode() (false)
69 #endif
70 
71 #include "convert_srgb.I"
72 
73 #endif
EXPCL_PANDA_PNMIMAGE unsigned char decode_sRGB_uchar(unsigned char val)
Decodes the sRGB-encoded unsigned char value to a linearized unsigned char value.
Definition: convert_srgb.I:37
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
BEGIN_PUBLISH EXPCL_PANDA_PNMIMAGE float decode_sRGB_float(unsigned char val)
Decodes the sRGB-encoded unsigned char value to a linearized float in the range 0-1.
Definition: convert_srgb.I:18
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
EXPCL_PANDA_PNMIMAGE unsigned char encode_sRGB_uchar(unsigned char val)
Encodes the linearized unsigned char value to an sRGB-encoded unsigned char value.
Definition: convert_srgb.I:80
EXPCL_PANDA_PNMIMAGE float encode_sRGB_float(unsigned char val)
Encodes the linearized unsigned char value to an sRGB-encoded floating- point value in ther range 0-1...
Definition: convert_srgb.I:56