BALL 1.5.0
Loading...
Searching...
No Matches
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
9
10#include <iostream>
11
12namespace BALL
13{
14
15 namespace VIEW
16 {
17
19
33
39
42 unsigned int bitSize : 8;
43
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
62 public:
63
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
82 unsigned int flags = 0) :
83 numChannels(0), flags(flags)
84 {
85 _RTSG_FB_SETCH(0,c0);
86 }
87
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
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
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
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:
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
#define _RTSG_FB_SETCH(i, v)
Definition pixelFormat.h:75
std::ostream & operator<<(std::ostream &o, const PixelFormat &f)
bool operator!=(const ChannelFormat &f) const
Definition pixelFormat.h:54
bool operator==(const ChannelFormat &f) const
Definition pixelFormat.h:50
ChannelFormat(ChannelID id, ChannelType type, unsigned int bitSize)
Definition pixelFormat.h:46
static const PixelFormat BGR_32
static const PixelFormat RGBA_32
static const PixelFormat RGBF_96
static const PixelFormat BGR_24
void print(std::ostream &o) const
const ChannelFormat & operator[](unsigned int i) const
static const PixelFormat RGB_32
PixelFormat(const ChannelFormat &c0, const ChannelFormat &c1, const ChannelFormat &c2, const ChannelFormat &c3, unsigned int flags=0)
void setFlags(unsigned int f)
static const PixelFormat RGB_3_2_2
ChannelFormat & getChannel(unsigned int i)
unsigned int computeByteSize() const
static const PixelFormat BGRA_32
PixelFormat(const ChannelFormat &c0, const ChannelFormat &c1, const ChannelFormat &c2, unsigned int flags=0)
Definition pixelFormat.h:97
PixelFormat & operator=(const PixelFormat &f)
const ChannelFormat & getChannel(unsigned int i) const
unsigned int computeBitSize() const
ChannelFormat & operator[](unsigned int i)
PixelFormat(const ChannelFormat &c0, unsigned int flags=0)
Definition pixelFormat.h:81
unsigned int getNumChannels() const
bool operator==(const PixelFormat &f) const
PixelFormat(const ChannelFormat &c0, const ChannelFormat &c1, unsigned int flags=0)
Definition pixelFormat.h:88
bool operator!=(const PixelFormat &f) const
static const PixelFormat RGB_24
unsigned int getFlags() const