Loading...
Searching...
No Matches
pixelFormat.h
Go to the documentation of this file.
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#ifndef BALL_VIEW_RENDERING_PIXELFORMAT_H
#define BALL_VIEW_RENDERING_PIXELFORMAT_H
#include <BALL/COMMON/global.h>
#include <iostream>
namespace BALL
{
namespace VIEW
{
struct ChannelFormat {
enum ChannelID {
NO_CHANNEL = 0, // no channel info
EMPTY_CHANNEL, // used for specifying empty space in a pixel
RED_CHANNEL,
GREEN_CHANNEL,
BLUE_CHANNEL,
LUMINANCE_CHANNEL,
ALPHA_CHANNEL,
DEPTH_CHANNEL,
Y_CHANNEL,
U_CHANNEL,
V_CHANNEL
};
enum ChannelType {
SIGNED_INT_CHANNEL,
UNSIGNED_INT_CHANNEL,
FLOAT_CHANNEL
};
ChannelID id : 8;
ChannelType type : 8;
unsigned int bitSize : 8;
ChannelFormat() : id(NO_CHANNEL) { }
ChannelFormat(ChannelID id, ChannelType type, unsigned int bitSize) :
id(id), type(type), bitSize(bitSize)
{ }
bool operator==(const ChannelFormat &f) const {
return id == f.id && type == f.type && bitSize == f.bitSize;
}
bool operator!=(const ChannelFormat &f) const {
return id != f.id || type != f.type || bitSize != f.bitSize;
}
};
class PixelFormat {
public:
enum { MAX_NUMBER_OF_CHANNELS = 4 };
// Flags
enum {
// framebuffer data structure
PLANAR_FRAMEBUFFER = 1<<1 // otherwise interlaced
};
PixelFormat() : numChannels(0), flags(0) { }
#define _RTSG_FB_SETCH(i,v) \
this->channels[(i)] = v; \
if (v.id != ChannelFormat::NO_CHANNEL) \
++numChannels
PixelFormat(const ChannelFormat &c0,
unsigned int flags = 0) :
numChannels(0), flags(flags)
{
_RTSG_FB_SETCH(0,c0);
}
PixelFormat(const ChannelFormat &c0,
const ChannelFormat &c1,
unsigned int flags = 0) :
numChannels(0), flags(flags)
{
_RTSG_FB_SETCH(0,c0);
_RTSG_FB_SETCH(1,c1);
}
PixelFormat(const ChannelFormat &c0,
const ChannelFormat &c1,
const ChannelFormat &c2,
unsigned int flags = 0) :
numChannels(0), flags(flags)
{
_RTSG_FB_SETCH(0,c0);
_RTSG_FB_SETCH(1,c1);
_RTSG_FB_SETCH(2,c2);
}
PixelFormat(const ChannelFormat &c0,
const ChannelFormat &c1,
const ChannelFormat &c2,
const ChannelFormat &c3,
unsigned int flags = 0) :
numChannels(0), flags(flags)
{
_RTSG_FB_SETCH(0,c0);
_RTSG_FB_SETCH(1,c1);
_RTSG_FB_SETCH(2,c2);
_RTSG_FB_SETCH(3,c3);
}
#undef _RTSG_FB_SETCH
unsigned int getNumChannels() const { return numChannels; }
const ChannelFormat &getChannel(unsigned int i) const
{
return channels[i];
}
ChannelFormat &getChannel(unsigned int i)
{
return channels[i];
}
const ChannelFormat &operator[](unsigned int i) const
{
return channels[i];
}
ChannelFormat &operator[](unsigned int i)
{
return channels[i];
}
unsigned int getFlags() const { return flags; }
void setFlags(unsigned int f) { flags = f; }
unsigned int computeBitSize() const {
unsigned int bitSize = 0;
for (unsigned int i = 0; i < numChannels; i++) {
bitSize += channels[i].bitSize;
}
return bitSize;
}
unsigned int computeByteSize() const {
unsigned int bitSize = computeBitSize();
return (bitSize / 8) + ((bitSize % 8) > 0 ? 1 : 0) ;
}
PixelFormat &operator=(const PixelFormat &f)
{
numChannels = f.numChannels;
flags = f.flags;
for (unsigned int i = 0; i < numChannels; i++) {
channels[i] = f.channels[i];
}
return *this;
}
bool operator==(const PixelFormat &f) const
{
if (numChannels != f.numChannels || flags != f.flags)
return false;
for (unsigned int i = 0; i < numChannels; i++) {
if (channels[i] != f.channels[i])
return false;
}
return true;
}
bool operator!=(const PixelFormat &f) const {
return !(*this == f);
}
void print(std::ostream &o) const;
static const PixelFormat RGB_24;
static const PixelFormat BGR_24;
static const PixelFormat RGB_32;
static const PixelFormat RGBA_32;
static const PixelFormat BGR_32;
static const PixelFormat BGRA_32;
static const PixelFormat RGB_3_2_2;
static const PixelFormat RGBF_96;
private:
ChannelFormat channels[MAX_NUMBER_OF_CHANNELS];
unsigned int numChannels;
unsigned int flags;
};
inline std::ostream &operator<<(std::ostream &o, const PixelFormat &f)
{
f.print(o);
return o;
}
} // namespace VIEW
} // namespace BALL
#endif //BALL_VIEW_RENDERING_PIXELFORMAT_H
global.h
BALL::VIEW::PixelFormat
Definition pixelFormat.h:61
BALL::VIEW::PixelFormat::PixelFormat
PixelFormat()
Definition pixelFormat.h:73
BALL::VIEW::PixelFormat::BGR_32
static const PixelFormat BGR_32
Definition pixelFormat.h:194
BALL::VIEW::PixelFormat::RGBA_32
static const PixelFormat RGBA_32
Definition pixelFormat.h:193
BALL::VIEW::PixelFormat::RGBF_96
static const PixelFormat RGBF_96
Definition pixelFormat.h:201
BALL::VIEW::PixelFormat::BGR_24
static const PixelFormat BGR_24
Definition pixelFormat.h:190
BALL::VIEW::PixelFormat::print
void print(std::ostream &o) const
BALL::VIEW::PixelFormat::operator[]
const ChannelFormat & operator[](unsigned int i) const
Definition pixelFormat.h:135
BALL::VIEW::PixelFormat::RGB_32
static const PixelFormat RGB_32
Definition pixelFormat.h:192
BALL::VIEW::PixelFormat::PixelFormat
PixelFormat(const ChannelFormat &c0, const ChannelFormat &c1, const ChannelFormat &c2, const ChannelFormat &c3, unsigned int flags=0)
Definition pixelFormat.h:108
BALL::VIEW::PixelFormat::setFlags
void setFlags(unsigned int f)
Definition pixelFormat.h:147
BALL::VIEW::PixelFormat::RGB_3_2_2
static const PixelFormat RGB_3_2_2
Definition pixelFormat.h:198
BALL::VIEW::PixelFormat::getChannel
ChannelFormat & getChannel(unsigned int i)
Definition pixelFormat.h:130
BALL::VIEW::PixelFormat::computeByteSize
unsigned int computeByteSize() const
Definition pixelFormat.h:157
BALL::VIEW::PixelFormat::BGRA_32
static const PixelFormat BGRA_32
Definition pixelFormat.h:195
BALL::VIEW::PixelFormat::PixelFormat
PixelFormat(const ChannelFormat &c0, const ChannelFormat &c1, const ChannelFormat &c2, unsigned int flags=0)
Definition pixelFormat.h:97
BALL::VIEW::PixelFormat::PLANAR_FRAMEBUFFER
@ PLANAR_FRAMEBUFFER
Definition pixelFormat.h:69
BALL::VIEW::PixelFormat::operator=
PixelFormat & operator=(const PixelFormat &f)
Definition pixelFormat.h:162
BALL::VIEW::PixelFormat::getChannel
const ChannelFormat & getChannel(unsigned int i) const
Definition pixelFormat.h:125
BALL::VIEW::PixelFormat::computeBitSize
unsigned int computeBitSize() const
Definition pixelFormat.h:149
BALL::VIEW::PixelFormat::operator[]
ChannelFormat & operator[](unsigned int i)
Definition pixelFormat.h:140
BALL::VIEW::PixelFormat::PixelFormat
PixelFormat(const ChannelFormat &c0, unsigned int flags=0)
Definition pixelFormat.h:81
BALL::VIEW::PixelFormat::getNumChannels
unsigned int getNumChannels() const
Definition pixelFormat.h:123
BALL::VIEW::PixelFormat::operator==
bool operator==(const PixelFormat &f) const
Definition pixelFormat.h:172
BALL::VIEW::PixelFormat::MAX_NUMBER_OF_CHANNELS
@ MAX_NUMBER_OF_CHANNELS
Definition pixelFormat.h:64
BALL::VIEW::PixelFormat::PixelFormat
PixelFormat(const ChannelFormat &c0, const ChannelFormat &c1, unsigned int flags=0)
Definition pixelFormat.h:88
BALL::VIEW::PixelFormat::operator!=
bool operator!=(const PixelFormat &f) const
Definition pixelFormat.h:183
BALL::VIEW::PixelFormat::RGB_24
static const PixelFormat RGB_24
Definition pixelFormat.h:189
BALL::VIEW::PixelFormat::getFlags
unsigned int getFlags() const
Definition pixelFormat.h:145
BALL::VIEW
Definition constraints.h:35
BALL::VIEW::operator<<
std::ostream & operator<<(std::ostream &o, const PixelFormat &f)
Definition pixelFormat.h:209
BALL
Definition constants.h:13
_RTSG_FB_SETCH
#define _RTSG_FB_SETCH(i, v)
Definition pixelFormat.h:75
BALL::VIEW::ChannelFormat
Definition pixelFormat.h:18
BALL::VIEW::ChannelFormat::bitSize
unsigned int bitSize
Definition pixelFormat.h:42
BALL::VIEW::ChannelFormat::ChannelType
ChannelType
Definition pixelFormat.h:34
BALL::VIEW::ChannelFormat::FLOAT_CHANNEL
@ FLOAT_CHANNEL
Definition pixelFormat.h:37
BALL::VIEW::ChannelFormat::SIGNED_INT_CHANNEL
@ SIGNED_INT_CHANNEL
Definition pixelFormat.h:35
BALL::VIEW::ChannelFormat::UNSIGNED_INT_CHANNEL
@ UNSIGNED_INT_CHANNEL
Definition pixelFormat.h:36
BALL::VIEW::ChannelFormat::operator!=
bool operator!=(const ChannelFormat &f) const
Definition pixelFormat.h:54
BALL::VIEW::ChannelFormat::id
ChannelID id
Definition pixelFormat.h:40
BALL::VIEW::ChannelFormat::operator==
bool operator==(const ChannelFormat &f) const
Definition pixelFormat.h:50
BALL::VIEW::ChannelFormat::type
ChannelType type
Definition pixelFormat.h:41
BALL::VIEW::ChannelFormat::ChannelFormat
ChannelFormat(ChannelID id, ChannelType type, unsigned int bitSize)
Definition pixelFormat.h:46
BALL::VIEW::ChannelFormat::ChannelID
ChannelID
Definition pixelFormat.h:20
BALL::VIEW::ChannelFormat::EMPTY_CHANNEL
@ EMPTY_CHANNEL
Definition pixelFormat.h:22
BALL::VIEW::ChannelFormat::LUMINANCE_CHANNEL
@ LUMINANCE_CHANNEL
Definition pixelFormat.h:26
BALL::VIEW::ChannelFormat::NO_CHANNEL
@ NO_CHANNEL
Definition pixelFormat.h:21
BALL::VIEW::ChannelFormat::GREEN_CHANNEL
@ GREEN_CHANNEL
Definition pixelFormat.h:24
BALL::VIEW::ChannelFormat::U_CHANNEL
@ U_CHANNEL
Definition pixelFormat.h:30
BALL::VIEW::ChannelFormat::Y_CHANNEL
@ Y_CHANNEL
Definition pixelFormat.h:29
BALL::VIEW::ChannelFormat::BLUE_CHANNEL
@ BLUE_CHANNEL
Definition pixelFormat.h:25
BALL::VIEW::ChannelFormat::ALPHA_CHANNEL
@ ALPHA_CHANNEL
Definition pixelFormat.h:27
BALL::VIEW::ChannelFormat::RED_CHANNEL
@ RED_CHANNEL
Definition pixelFormat.h:23
BALL::VIEW::ChannelFormat::DEPTH_CHANNEL
@ DEPTH_CHANNEL
Definition pixelFormat.h:28
BALL::VIEW::ChannelFormat::V_CHANNEL
@ V_CHANNEL
Definition pixelFormat.h:31
BALL::VIEW::ChannelFormat::ChannelFormat
ChannelFormat()
Definition pixelFormat.h:44