home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Computer Panoráma
/
computer_panorama_1997-12-hibas.iso
/
SHARE
/
GRAPH
/
PTC051.ZIP
/
SRC
/
FORMAT.H
< prev
next >
Wrap
C/C++ Source or Header
|
1997-09-20
|
4KB
|
164 lines
////////////////////////
// pixel format class //
////////////////////////
#ifndef __FORMAT_H
#define __FORMAT_H
#include "misc.h"
#include "lang.h"
#include "color.h"
#include "globals.h"
#include <math.h>
#include <iostream.h>
class FORMAT
{
public:
// constructors
FORMAT();
FORMAT(int id);
FORMAT(uint c1_mask,uint c2_mask,uint c3_mask,uint c4_mask=0,
int model=RGBA,int bits=DEFAULT);
FORMAT(uint c1_position,uint c1_size,
uint c2_position,uint c2_size,
uint c3_position,uint c3_size,
uint c4_position=0,uint c4_size=0,
int model=RGBA,int bits=DEFAULT);
// initialize
int init(int id);
int init(uint c1_mask,uint c2_mask,uint c3_mask,uint c4_mask=0,
int model=RGBA,int bits=DEFAULT);
int init(uint c1_position,uint c1_size,
uint c2_position,uint c2_size,
uint c3_position,uint c3_size,
uint c4_position=0,uint c4_size=0,
int model=RGBA,int bits=DEFAULT);
// clear format
void clear();
// color packing/unpacking
int pack(COLOR const &color,void *data) const;
int pack(uchar c1,uchar c2,uchar c3,uchar c4,void *data,int model=RGBA) const;
int unpack(void *data,COLOR &color,int mode=ABSOLUTE,int model=RGBA) const;
int unpack(void *data,uchar &c1,uchar &c2,uchar &c3,uchar &c4,int model=RGBA);
// operators
inline void operator =(int const id);
inline void operator =(FORMAT const &other);
inline int operator ==(FORMAT const &other) const;
inline int operator !=(FORMAT const &other) const;
// format status
int ok() const;
// data
int id; // format id
int type; // format type
int model; // color model
int bits; // bits per pixel
int bytes; // bytes per pixel
// field information struct
struct FIELDINFO
{
uint position; // bit position of LSB
uint size; // size in bits
uint mask; // field mask
int shift; // shift magnitude to position (for uchar pack only - may be negative!)
};
// component information
FIELDINFO c1; // |R|C|C|H|H|Y|Y| Y|
FIELDINFO c2; // |G|M|M|S|L|I|U|Cb|
FIELDINFO c3; // |B|Y|Y|I|S|Q|V|Cr|
FIELDINFO c4; // |A|A|K|A|A|A|A| A|
private:
// setup masks and other data
void setup();
// get field information from mask
FIELDINFO getfieldinfo(uint mask);
};
inline void FORMAT::operator =(const int format_id)
{
// initialize with format id
init(format_id);
}
inline void FORMAT::operator =(FORMAT const &other)
{
// fail if identical assign
if (&other==this) return;
// assign
id=other.id;
type=other.type;
bits=other.bits;
bytes=other.bytes;
model=other.model;
c1=other.c1;
c2=other.c2;
c3=other.c3;
c4=other.c4;
}
inline int FORMAT::operator ==(FORMAT const &other) const
{
// check for id match
if (id==other.id && id>=FORMATBASE && id<=FORMATMAX) return 1;
// check data for match
if (type!=other.type || model!=other.model || bits!=other.bits || bytes!=other.bytes) return 0;
// check bits per pixel
if (bits!=other.bits) return 0;
// check components
if (c1.position!=other.c1.position || c1.size!=other.c1.size || c1.mask!=other.c1.mask || c1.shift!=other.c1.shift ||
c2.position!=other.c2.position || c2.size!=other.c2.size || c2.mask!=other.c2.mask || c2.shift!=other.c2.shift ||
c3.position!=other.c3.position || c3.size!=other.c3.size || c3.mask!=other.c3.mask || c3.shift!=other.c3.shift ||
c4.position!=other.c4.position || c4.size!=other.c4.size || c4.mask!=other.c4.mask || c4.shift!=other.c4.shift) return 0;
else return 1;
}
inline int FORMAT::operator !=(FORMAT const &other) const
{
return !(*this==other);
}
#endif