added 3dengfx into the repo, probably not the correct version for this
[summerhack] / src / 3dengfx / src / gfx / color.hpp
1 /*
2 Copyright 2004 John Tsiombikas <nuclear@siggraph.org>
3
4 This file is part of the graphics core library.
5
6 The graphics core library is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 The graphics core library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with the graphics core library; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 /* colors
22  * author: John Tsiombikas 2004
23  */
24
25 #ifndef _COLOR2_H_
26 #define _COLOR2_H_
27
28 #include "3dengfx_config.h"
29 #include "color_bits.h"
30
31 #ifdef SINGLE_PRECISION_MATH
32 typedef float scalar_t;
33 #else
34 typedef double scalar_t;
35 #endif  // DOUBLE_PRECISION_MATH
36
37 class Color {
38 public:
39         scalar_t r, g, b, a;
40
41         Color(scalar_t intensity = 1.0f);
42         Color(scalar_t r, scalar_t g, scalar_t b, scalar_t a = 1.0f);
43
44         Color operator +(const Color &col) const;
45         Color operator -(const Color &col) const;
46         Color operator *(const Color &col) const;
47         Color operator *(scalar_t scalar) const;
48
49         void operator +=(const Color &col);
50         void operator -=(const Color &col);
51         void operator *=(const Color &col);
52         void operator *=(scalar_t scalar);
53
54         unsigned long get_packed32() const;
55         unsigned short get_packed16() const;
56         unsigned short get_packed15() const;
57         unsigned char get_nearest8(const unsigned char **pal) const;
58 };
59
60 inline Color int_color(int r, int g, int b, int a = 255);
61
62 inline unsigned long pack_color32(const Color &col);
63 inline unsigned short pack_color16(const Color &col);
64 inline unsigned short pack_color15(const Color &col);
65 unsigned char match_nearest8(const Color &col, const unsigned char **pal);
66
67 inline Color unpack_color32(unsigned long pcol);
68 inline Color unpack_color16(unsigned short pcol);
69 inline Color unpack_color15(unsigned short pcol);
70 inline Color lookup_color8(int index, const unsigned char **pal);
71
72 Color blend_colors(const Color &c1, const Color &c2, scalar_t t);
73
74 #include "color.inl"
75
76 #endif  // _COLOR2_H_