BALL
1.4.2
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
include
BALL
VIEW
RENDERING
pixelFormat.h
Go to the documentation of this file.
1
// -*- Mode: C++; tab-width: 2; -*-
2
// vi: set ts=2:
3
//
4
5
#ifndef BALL_VIEW_RENDERING_PIXELFORMAT_H
6
#define BALL_VIEW_RENDERING_PIXELFORMAT_H
7
8
#include <
BALL/COMMON/global.h
>
9
10
#include <iostream>
11
12
namespace
BALL
13
{
14
15
namespace
VIEW
16
{
17
18
struct
ChannelFormat
{
19
20
enum
ChannelID
{
21
NO_CHANNEL
= 0,
// no channel info
22
EMPTY_CHANNEL
,
// used for specifying empty space in a pixel
23
RED_CHANNEL
,
24
GREEN_CHANNEL
,
25
BLUE_CHANNEL
,
26
LUMINANCE_CHANNEL
,
27
ALPHA_CHANNEL
,
28
DEPTH_CHANNEL
,
29
Y_CHANNEL
,
30
U_CHANNEL
,
31
V_CHANNEL
32
};
33
34
enum
ChannelType
{
35
SIGNED_INT_CHANNEL
,
36
UNSIGNED_INT_CHANNEL
,
37
FLOAT_CHANNEL
38
};
39
40
ChannelID
id
: 8;
41
ChannelType
type
: 8;
42
unsigned
int
bitSize
: 8;
43
44
ChannelFormat
() :
id
(
NO_CHANNEL
) { }
45
46
ChannelFormat
(
ChannelID
id
,
ChannelType
type
,
unsigned
int
bitSize
) :
47
id(id), type(type), bitSize(bitSize)
48
{ }
49
50
bool
operator==
(
const
ChannelFormat
&
f
)
const
{
51
return
id
== f.
id
&&
type
== f.
type
&&
bitSize
== f.
bitSize
;
52
}
53
54
bool
operator!=
(
const
ChannelFormat
&
f
)
const
{
55
return
id
!= f.
id
||
type
!= f.
type
||
bitSize
!= f.
bitSize
;
56
}
57
58
};
59
60
61
class
PixelFormat
{
62
public
:
63
64
enum
{
MAX_NUMBER_OF_CHANNELS
= 4 };
65
66
// Flags
67
enum
{
68
// framebuffer data structure
69
PLANAR_FRAMEBUFFER
= 1<<1
// otherwise interlaced
70
};
71
72
73
PixelFormat
() :
numChannels
(0),
flags
(0) { }
74
75
#define _RTSG_FB_SETCH(i,v) \
76
this->channels[(i)] = v; \
77
if (v.id != ChannelFormat::NO_CHANNEL) \
78
++numChannels
79
80
81
PixelFormat
(
const
ChannelFormat
&c0,
82
unsigned
int
flags
= 0) :
83
numChannels
(0),
flags
(
flags
)
84
{
85
_RTSG_FB_SETCH
(0,c0);
86
}
87
88
PixelFormat
(
const
ChannelFormat
&c0,
89
const
ChannelFormat
&c1,
90
unsigned
int
flags
= 0) :
91
numChannels
(0),
flags
(
flags
)
92
{
93
_RTSG_FB_SETCH
(0,c0);
94
_RTSG_FB_SETCH
(1,c1);
95
}
96
97
PixelFormat
(
const
ChannelFormat
&c0,
98
const
ChannelFormat
&c1,
99
const
ChannelFormat
&c2,
100
unsigned
int
flags
= 0) :
101
numChannels
(0),
flags
(
flags
)
102
{
103
_RTSG_FB_SETCH
(0,c0);
104
_RTSG_FB_SETCH
(1,c1);
105
_RTSG_FB_SETCH
(2,c2);
106
}
107
108
PixelFormat
(
const
ChannelFormat
&c0,
109
const
ChannelFormat
&c1,
110
const
ChannelFormat
&c2,
111
const
ChannelFormat
&c3,
112
unsigned
int
flags
= 0) :
113
numChannels
(0),
flags
(
flags
)
114
{
115
_RTSG_FB_SETCH
(0,c0);
116
_RTSG_FB_SETCH
(1,c1);
117
_RTSG_FB_SETCH
(2,c2);
118
_RTSG_FB_SETCH
(3,c3);
119
}
120
121
#undef _RTSG_FB_SETCH
122
123
unsigned
int
getNumChannels
()
const
{
return
numChannels
; }
124
125
const
ChannelFormat
&
getChannel
(
unsigned
int
i)
const
126
{
127
return
channels
[i];
128
}
129
130
ChannelFormat
&
getChannel
(
unsigned
int
i)
131
{
132
return
channels
[i];
133
}
134
135
const
ChannelFormat
&
operator[]
(
unsigned
int
i)
const
136
{
137
return
channels
[i];
138
}
139
140
ChannelFormat
&
operator[]
(
unsigned
int
i)
141
{
142
return
channels
[i];
143
}
144
145
unsigned
int
getFlags
()
const
{
return
flags
; }
146
147
void
setFlags
(
unsigned
int
f
) {
flags
=
f
; }
148
149
unsigned
int
computeBitSize
()
const
{
150
unsigned
int
bitSize = 0;
151
for
(
unsigned
int
i = 0; i <
numChannels
; i++) {
152
bitSize +=
channels
[i].
bitSize
;
153
}
154
return
bitSize;
155
}
156
157
unsigned
int
computeByteSize
()
const
{
158
unsigned
int
bitSize =
computeBitSize
();
159
return
(bitSize / 8) + ((bitSize % 8) > 0 ? 1 : 0) ;
160
}
161
162
PixelFormat
&
operator=
(
const
PixelFormat
&
f
)
163
{
164
numChannels
= f.
numChannels
;
165
flags
= f.
flags
;
166
for
(
unsigned
int
i = 0; i <
numChannels
; i++) {
167
channels
[i] = f.
channels
[i];
168
}
169
return
*
this
;
170
}
171
172
bool
operator==
(
const
PixelFormat
&
f
)
const
173
{
174
if
(
numChannels
!= f.
numChannels
||
flags
!= f.
flags
)
175
return
false
;
176
for
(
unsigned
int
i = 0; i <
numChannels
; i++) {
177
if
(
channels
[i] != f.
channels
[i])
178
return
false
;
179
}
180
return
true
;
181
}
182
183
bool
operator!=
(
const
PixelFormat
&
f
)
const
{
184
return
!(*
this
==
f
);
185
}
186
187
void
print
(std::ostream &o)
const
;
188
189
static
const
PixelFormat
RGB_24
;
190
static
const
PixelFormat
BGR_24
;
191
192
static
const
PixelFormat
RGB_32
;
193
static
const
PixelFormat
RGBA_32
;
194
static
const
PixelFormat
BGR_32
;
195
static
const
PixelFormat
BGRA_32
;
196
197
198
static
const
PixelFormat
RGB_3_2_2
;
199
200
201
static
const
PixelFormat
RGBF_96
;
202
203
private
:
204
ChannelFormat
channels
[
MAX_NUMBER_OF_CHANNELS
];
205
unsigned
int
numChannels
;
206
unsigned
int
flags
;
207
};
208
209
inline
std::ostream &
operator<<
(std::ostream &o,
const
PixelFormat
&
f
)
210
{
211
f.
print
(o);
212
return
o;
213
}
214
215
}
// namespace VIEW
216
217
}
// namespace BALL
218
219
#endif //BALL_VIEW_RENDERING_PIXELFORMAT_H
Generated by
1.8.3.1