Panda3D
 All Classes Functions Variables Enumerations
convert_srgb.h
1 // Filename: convert_srgb.h
2 // Created by: rdb (13Nov14)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef CONVERT_SRGB_H
16 #define CONVERT_SRGB_H
17 
18 #include "pandabase.h"
19 #include "luse.h"
20 #include "pnmimage_base.h"
21 
22 // The below functions can encode and decode sRGB colors in various
23 // representations. Some of them are implemented using look-up tables,
24 // some others using SSE2 intrinsics.
25 extern EXPCL_PANDA_PNMIMAGE const unsigned char to_srgb8_table[256];
26 extern EXPCL_PANDA_PNMIMAGE const unsigned char to_linear_uchar_table[256];
27 extern EXPCL_PANDA_PNMIMAGE const float to_linear_float_table[256];
28 
29 EXPCL_PANDA_PNMIMAGE INLINE float decode_sRGB_float(unsigned char val);
30 EXPCL_PANDA_PNMIMAGE INLINE float decode_sRGB_float(float val);
31 EXPCL_PANDA_PNMIMAGE INLINE unsigned char decode_sRGB_uchar(unsigned char val);
32 EXPCL_PANDA_PNMIMAGE INLINE unsigned char decode_sRGB_uchar(float val);
33 
34 EXPCL_PANDA_PNMIMAGE INLINE float encode_sRGB_float(unsigned char val);
35 EXPCL_PANDA_PNMIMAGE INLINE float encode_sRGB_float(float val);
36 EXPCL_PANDA_PNMIMAGE INLINE unsigned char encode_sRGB_uchar(unsigned char val);
37 EXPCL_PANDA_PNMIMAGE INLINE unsigned char encode_sRGB_uchar(float val);
38 
39 // These functions convert more than one component in one go,
40 // which can be faster due to vectorization.
41 EXPCL_PANDA_PNMIMAGE INLINE void encode_sRGB_uchar(const LColorf &from,
42  xel &into);
43 EXPCL_PANDA_PNMIMAGE INLINE void encode_sRGB_uchar(const LColorf &from,
44  xel &into, xelval &into_alpha);
45 
46 // Use these functions if you know that SSE2 support is available.
47 // Otherwise, they will crash!
48 EXPCL_PANDA_PNMIMAGE unsigned char encode_sRGB_uchar_sse2(float val);
49 EXPCL_PANDA_PNMIMAGE void encode_sRGB_uchar_sse2(const LColorf &from,
50  xel &into);
51 EXPCL_PANDA_PNMIMAGE void encode_sRGB_uchar_sse2(const LColorf &from,
52  xel &into, xelval &into_alpha);
53 
54 // Use the following to find out if you can call either of the above.
55 EXPCL_PANDA_PNMIMAGE bool has_sse2_sRGB_encode();
56 
57 #include "convert_srgb.I"
58 
59 #endif
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111