Panda3D
Loading...
Searching...
No Matches
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.
24extern EXPCL_PANDA_PNMIMAGE const unsigned char to_srgb8_table[256];
25extern EXPCL_PANDA_PNMIMAGE const unsigned char to_linear_uchar_table[256];
26extern EXPCL_PANDA_PNMIMAGE const float to_linear_float_table[256];
27
28BEGIN_PUBLISH
29
30EXPCL_PANDA_PNMIMAGE INLINE float decode_sRGB_float(unsigned char val);
31EXPCL_PANDA_PNMIMAGE INLINE float decode_sRGB_float(float val);
32EXPCL_PANDA_PNMIMAGE INLINE unsigned char decode_sRGB_uchar(unsigned char val);
33EXPCL_PANDA_PNMIMAGE INLINE unsigned char decode_sRGB_uchar(float val);
34
35EXPCL_PANDA_PNMIMAGE INLINE float encode_sRGB_float(unsigned char val);
36EXPCL_PANDA_PNMIMAGE INLINE float encode_sRGB_float(float val);
37EXPCL_PANDA_PNMIMAGE INLINE unsigned char encode_sRGB_uchar(unsigned char val);
38EXPCL_PANDA_PNMIMAGE INLINE unsigned char encode_sRGB_uchar(float val);
39
40END_PUBLISH
41
42// These functions convert more than one component in one go, which can be
43// faster due to vectorization.
44EXPCL_PANDA_PNMIMAGE INLINE void encode_sRGB_uchar(const LColorf &from,
45 xel &into);
46EXPCL_PANDA_PNMIMAGE INLINE void encode_sRGB_uchar(const LColorf &from,
47 xel &into, xelval &into_alpha);
48
49EXPCL_PANDA_PNMIMAGE INLINE void encode_sRGB_uchar(const LColord &from,
50 xel &into);
51EXPCL_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)
57EXPCL_PANDA_PNMIMAGE unsigned char encode_sRGB_uchar_sse2(float val);
58EXPCL_PANDA_PNMIMAGE void encode_sRGB_uchar_sse2(const LColorf &from,
59 xel &into);
60EXPCL_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.
64EXPCL_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
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.
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...
EXPCL_PANDA_PNMIMAGE unsigned char encode_sRGB_uchar(unsigned char val)
Encodes the linearized unsigned char value to an sRGB-encoded unsigned char value.
EXPCL_PANDA_PNMIMAGE unsigned char decode_sRGB_uchar(unsigned char val)
Decodes the sRGB-encoded unsigned char value to a linearized unsigned char value.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.