~ubuntu-branches/ubuntu/lucid/blender/lucid

« back to all changes in this revision

Viewing changes to source/gameengine/VideoTexture/FilterColor.h

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2009-08-06 22:32:19 UTC
  • mfrom: (1.2.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090806223219-8z4eej1u8levu4pz
Tags: 2.49a+dfsg-0ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/control: Build-depend on python-2.6 rather than python-2.5.
  - debian/misc/*.desktop: Add Spanish translation to .desktop 
    files.
  - debian/pyversions: 2.6.
  - debian/rules: Clean *.o of source/blender/python/api2_2x/
* New upstream release (LP: #382153).
* Refreshed patches:
  - 01_sanitize_sys.patch
  - 02_tmp_in_HOME
  - 10_use_systemwide_ftgl
  - 70_portability_platform_detection
* Removed patches merged upstream:
  - 30_fix_python_syntax_warning
  - 90_ubuntu_ffmpeg_52_changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: FilterColor.h 19485 2009-03-31 22:34:34Z gsrb3d $
 
2
-----------------------------------------------------------------------------
 
3
This source file is part of blendTex library
 
4
 
 
5
Copyright (c) 2007 The Zdeno Ash Miklas
 
6
 
 
7
This program is free software; you can redistribute it and/or modify it under
 
8
the terms of the GNU Lesser General Public License as published by the Free Software
 
9
Foundation; either version 2 of the License, or (at your option) any later
 
10
version.
 
11
 
 
12
This program is distributed in the hope that it will be useful, but WITHOUT
 
13
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
14
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 
15
 
 
16
You should have received a copy of the GNU Lesser General Public License along with
 
17
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 
18
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
 
19
http://www.gnu.org/copyleft/lesser.txt.
 
20
-----------------------------------------------------------------------------
 
21
*/
 
22
 
 
23
#if !defined FILTERCOLOR_H
 
24
#define FILTERCOLOR_H
 
25
 
 
26
#include "Common.h"
 
27
 
 
28
#include "FilterBase.h"
 
29
 
 
30
 
 
31
/// pixel filter for gray scale
 
32
class FilterGray : public FilterBase
 
33
{
 
34
public:
 
35
        /// constructor
 
36
        FilterGray (void) {}
 
37
        /// destructor
 
38
        virtual ~FilterGray (void) {}
 
39
 
 
40
protected:
 
41
        /// filter pixel template, source int buffer
 
42
        template <class SRC> unsigned int tFilter (SRC src, short x, short y,
 
43
                short * size, unsigned int pixSize, unsigned int val)
 
44
        {
 
45
                // calculate gray value
 
46
                unsigned int gray = (28 * (VT_B(val)) + 151 * (VT_G(val))
 
47
                        + 77 * (VT_R(val))) >> 8;
 
48
                // return gray scale value
 
49
                VT_R(val) = gray;
 
50
                VT_G(val) = gray;
 
51
                VT_B(val) = gray;
 
52
                return val;
 
53
        }
 
54
 
 
55
        /// virtual filtering function for byte source
 
56
        virtual unsigned int filter (unsigned char * src, short x, short y,
 
57
                short * size, unsigned int pixSize, unsigned int val = 0)
 
58
        { return tFilter(src, x, y, size, pixSize, val); }
 
59
        /// virtual filtering function for unsigned int source
 
60
        virtual unsigned int filter (unsigned int * src, short x, short y,
 
61
                short * size, unsigned int pixSize, unsigned int val = 0)
 
62
        { return tFilter(src, x, y, size, pixSize, val); }
 
63
};
 
64
 
 
65
 
 
66
/// type for color matrix
 
67
typedef short ColorMatrix[4][5];
 
68
 
 
69
/// pixel filter for color calculation
 
70
class FilterColor : public FilterBase
 
71
{
 
72
public:
 
73
        /// constructor
 
74
        FilterColor (void);
 
75
        /// destructor
 
76
        virtual ~FilterColor (void) {}
 
77
 
 
78
        /// get color matrix
 
79
        ColorMatrix & getMatrix (void) { return m_matrix; }
 
80
        /// set color matrix
 
81
        void setMatrix (ColorMatrix & mat);
 
82
 
 
83
protected:
 
84
        ///  color calculation matrix
 
85
        ColorMatrix m_matrix;
 
86
 
 
87
        /// calculate one color component
 
88
        unsigned char calcColor (unsigned int val, short idx)
 
89
        {
 
90
                return (((m_matrix[idx][0]  * (VT_R(val)) + m_matrix[idx][1] * (VT_G(val))
 
91
                        + m_matrix[idx][2] * (VT_B(val)) + m_matrix[idx][3] * (VT_A(val))
 
92
                        + m_matrix[idx][4]) >> 8) & 0xFF);
 
93
        }
 
94
 
 
95
        /// filter pixel template, source int buffer
 
96
        template <class SRC> unsigned int tFilter (SRC src, short x, short y,
 
97
                short * size, unsigned int pixSize, unsigned int val)
 
98
        {
 
99
                // return calculated color
 
100
                int color;
 
101
                VT_RGBA(color, calcColor(val, 0), calcColor(val, 1), calcColor(val, 2), calcColor(val, 3));
 
102
                return color;
 
103
        }
 
104
 
 
105
        /// virtual filtering function for byte source
 
106
        virtual unsigned int filter (unsigned char * src, short x, short y,
 
107
                short * size, unsigned int pixSize, unsigned int val = 0)
 
108
        { return tFilter(src, x, y, size, pixSize, val); }
 
109
        /// virtual filtering function for unsigned int source
 
110
        virtual unsigned int filter (unsigned int * src, short x, short y,
 
111
                short * size, unsigned int pixSize, unsigned int val = 0)
 
112
        { return tFilter(src, x, y, size, pixSize, val); }
 
113
};
 
114
 
 
115
 
 
116
/// type for color levels
 
117
typedef unsigned short ColorLevel[4][3];
 
118
 
 
119
/// pixel filter for color calculation
 
120
class FilterLevel : public FilterBase
 
121
{
 
122
public:
 
123
        /// constructor
 
124
        FilterLevel (void);
 
125
        /// destructor
 
126
        virtual ~FilterLevel (void) {}
 
127
 
 
128
        /// get color matrix
 
129
        ColorLevel & getLevels (void) { return levels; }
 
130
        /// set color matrix
 
131
        void setLevels (ColorLevel & lev);
 
132
 
 
133
protected:
 
134
        ///  color calculation matrix
 
135
        ColorLevel levels;
 
136
 
 
137
        /// calculate one color component
 
138
        unsigned int calcColor (unsigned int val, short idx)
 
139
        {
 
140
                unsigned int col = VT_C(val,idx);;
 
141
                if (col <= levels[idx][0]) col = 0;
 
142
                else if (col >= levels[idx][1]) col = 0xFF;
 
143
                else col = (((col - levels[idx][0]) << 8) / levels[idx][2]) & 0xFF;
 
144
                return col; 
 
145
        }
 
146
 
 
147
        /// filter pixel template, source int buffer
 
148
        template <class SRC> unsigned int tFilter (SRC src, short x, short y,
 
149
                short * size, unsigned int pixSize, unsigned int val)
 
150
        {
 
151
                // return calculated color
 
152
                int color;
 
153
                VT_RGBA(color, calcColor(val, 0), calcColor(val, 1), calcColor(val, 2), calcColor(val, 3));
 
154
                return color;
 
155
        }
 
156
 
 
157
        /// virtual filtering function for byte source
 
158
        virtual unsigned int filter (unsigned char * src, short x, short y,
 
159
                short * size, unsigned int pixSize, unsigned int val = 0)
 
160
        { return tFilter(src, x, y, size, pixSize, val); }
 
161
        /// virtual filtering function for unsigned int source
 
162
        virtual unsigned int filter (unsigned int * src, short x, short y,
 
163
                short * size, unsigned int pixSize, unsigned int val = 0)
 
164
        { return tFilter(src, x, y, size, pixSize, val); }
 
165
};
 
166
 
 
167
 
 
168
#endif