~ubuntu-branches/ubuntu/intrepid/blender/intrepid-updates

« back to all changes in this revision

Viewing changes to source/blender/img/intern/IMG_Color.h

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-08-08 02:45:40 UTC
  • mfrom: (12.1.14 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080808024540-kkjp7ekfivzhuw3l
Tags: 2.46+dfsg-4
* Fix python syntax warning in import_dxf.py, which led to nasty output
  in installation/upgrade logs during byte-compilation, using a patch
  provided by the script author (Closes: #492280):
   - debian/patches/45_fix_python_syntax_warning

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * $Id: IMG_Color.h,v 1.6 2005/09/09 22:31:23 bjornmose Exp $
3
 
 *
4
 
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5
 
 *
6
 
 * This program is free software; you can redistribute it and/or
7
 
 * modify it under the terms of the GNU General Public License
8
 
 * as published by the Free Software Foundation; either version 2
9
 
 * of the License, or (at your option) any later version. The Blender
10
 
 * Foundation also sells licenses for use in proprietary software under
11
 
 * the Blender License.  See http://www.blender.org/BL/ for information
12
 
 * about this.
13
 
 *
14
 
 * This program is distributed in the hope that it will be useful,
15
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 
 * GNU General Public License for more details.
18
 
 *
19
 
 * You should have received a copy of the GNU General Public License
20
 
 * along with this program; if not, write to the Free Software Foundation,
21
 
 * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 
 *
23
 
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24
 
 * All rights reserved.
25
 
 *
26
 
 * The Original Code is: all of this file.
27
 
 *
28
 
 * Contributor(s): none yet.
29
 
 *
30
 
 * ***** END GPL/BL DUAL LICENSE BLOCK *****
31
 
 * @author      Maarten Gribnau
32
 
 * @date        March 7, 2001
33
 
 */
34
 
 
35
 
#ifndef _H_IMG_Color
36
 
#define _H_IMG_Color
37
 
 
38
 
class IMG_ColorRGBA;
39
 
 
40
 
/**
41
 
 * Implements a color with red, green and blue components.
42
 
 * Components are stored as floats.
43
 
 * @author      Maarten Gribnau
44
 
 * @date        March 7, 2001
45
 
 */
46
 
 
47
 
class IMG_ColorRGB {
48
 
public:
49
 
        /**
50
 
         * Constructs a color with the given values.
51
 
         * @param       r       requested red component of the color
52
 
         * @param       g       requested green component of the color
53
 
         * @param       b       requested blue component of the color
54
 
         */
55
 
        IMG_ColorRGB(float r=0, float g=0, float b=0)
56
 
                : m_r(r), m_g(g), m_b(b) {}
57
 
 
58
 
        /**
59
 
         * Copy constructor.
60
 
         * @param       c       the color to copy.
61
 
         */
62
 
        IMG_ColorRGB(const IMG_ColorRGB& c)
63
 
                : m_r(c.m_r), m_g(c.m_g), m_b(c.m_b) {}
64
 
 
65
 
        /**
66
 
         * Constructs a color without alpha from one with.
67
 
         * @param       c       the color to copy.
68
 
         */
69
 
        inline IMG_ColorRGB(const IMG_ColorRGBA& c);
70
 
 
71
 
        /** Red component of the color */
72
 
        float m_r;
73
 
        /** Green component of the color */
74
 
        float m_g;
75
 
        /** Blue component of the color */
76
 
        float m_b;
77
 
};
78
 
 
79
 
 
80
 
/**
81
 
 * Implements a color with red, green, blue and alpha components.
82
 
 * Components are stored as floats.
83
 
 * @author      Maarten Gribnau
84
 
 * @date        March 6, 2001
85
 
 */
86
 
 
87
 
class IMG_ColorRGBA {
88
 
public:
89
 
        /**
90
 
         * Constructs a color with the given values.
91
 
         * @param       r       requested red component of the color
92
 
         * @param       g       requested green component of the color
93
 
         * @param       b       requested blue component of the color
94
 
         * @param       a       requested alpha component of the color
95
 
         */
96
 
        IMG_ColorRGBA(float r=0, float g=0, float b=0, float a=0)
97
 
                : m_r(r), m_g(g), m_b(b), m_a(a) {}
98
 
 
99
 
        /**
100
 
         * Copy constructor.
101
 
         * @param       c       the color to copy.
102
 
         */
103
 
        IMG_ColorRGBA(const IMG_ColorRGBA& c)
104
 
                : m_r(c.m_r), m_g(c.m_g), m_b(c.m_b), m_a(c.m_a) {}
105
 
 
106
 
        /**
107
 
         * Constructs a color with alpha from one without.
108
 
         * @param       c       the color to copy.
109
 
         */
110
 
        IMG_ColorRGBA(const IMG_ColorRGB& c)
111
 
                : m_r(c.m_r), m_g(c.m_g), m_b(c.m_b), m_a(0) {}
112
 
 
113
 
        /**
114
 
         * Blends the given color with this color.
115
 
         * Uses the alpha of the given color for blending.
116
 
         * The alpha of this color is left untouched.
117
 
         * @param       c       the color to blend
118
 
         */
119
 
        inline void     blendColor(const IMG_ColorRGBA& c);
120
 
 
121
 
        /** Red component of the color */
122
 
        float m_r;
123
 
        /** Green component of the color */
124
 
        float m_g;
125
 
        /** Blue component of the color */
126
 
        float m_b;
127
 
        /** Alpha component of the color */
128
 
        float m_a;
129
 
};
130
 
 
131
 
inline IMG_ColorRGB::IMG_ColorRGB(const IMG_ColorRGBA& c)
132
 
        : m_r(c.m_r), m_g(c.m_g), m_b(c.m_b) {}
133
 
 
134
 
inline void     IMG_ColorRGBA::blendColor(const IMG_ColorRGBA& c)
135
 
{
136
 
        float r1 = 1 - c.m_a; // The reverse of alpha
137
 
#if IMG_REVERSED_ALPHA
138
 
        m_r = c.m_a * m_r + r1 * c.m_r;
139
 
        m_g = c.m_a * m_g + r1 * c.m_g;
140
 
        m_b = c.m_a * m_b + r1 * c.m_b;
141
 
#else
142
 
        m_r = r1 * m_r + c.m_a * c.m_r;
143
 
        m_g = r1 * m_g + c.m_a * c.m_g;
144
 
        m_b = r1 * m_b + c.m_a * c.m_b;
145
 
#endif
146
 
}
147
 
 
148
 
 
149
 
#endif // _H_IMG_Color
150