You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

385 lines
6.2 KiB
C++

//:Header:20, "TxRGB", 3b93fb4c
//
// File: llgfx_txrgb.h
//
// G A M E.O.N.E - LOW LEVEL LIB V1.0
// Copyright (C) 2001 LEVEL ONE ENTERTAINMENT,
// Licensed under the terms of LGPL.
//:---------------------------------------------------------------------------
//:Description
//
// RGB 24 Bit Datentyp Klasse
//
//:-----------------------------------------------------------------------------
#if !defined(LLGFX_TXRGB_INCLUDED)
#define LLGFX_TXRGB_INCLUDED
//:Custom
#pragma pack(1)
typedef struct {
TxU8 b,g,r; //intel format
} _rgb24;
#pragma pack()
//:End Custom
//:> +-------------------------------+
//:>---------------------| TxRGB Class Declaration |----------------------
//:> +-------------------------------+
//:Class
class TxRGB:
public _rgb24
{
public:
//::1
// +---------------+
// | Constructor |
// +---------------+
inline TxRGB();
//::2
// +---------------+
// | Constructor |
// +---------------+
inline TxRGB(
unsigned long i); // 32Bit Farbwert
//::8
// +-----------------+
// | operator !=() |
// +-----------------+
inline bool operator !=(
TxRGB& fxRgb);
//::3
// +----------------+
// | operator &() |
// +----------------+
inline TxRGB operator &(
const TxRGB& i) const;
//::4
// +-----------------+
// | operator &=() |
// +-----------------+
inline void operator &=(
const TxRGB& i);
//::13
// +-----------------+
// | operator ^=() |
// +-----------------+
inline void operator ^=(
TxRGB &rgb);
//::14
// +-----------------+
// | operator ^=() |
// +-----------------+
inline void operator ^=(
unsigned long i);
//::5
// +-----------------+
// | operator |=() |
// +-----------------+
inline void operator |=(
const TxRGB& i);
//::15
// +----------------+
// | operator ~() |
// +----------------+
inline TxRGB operator ~();
//::9
// +----------------+
// | operator <() |
// +----------------+
inline bool operator <(
TxRGB& fxRgb);
//::11
// +-----------------+
// | operator <=() |
// +-----------------+
inline bool operator <=(
TxRGB& fxRgb);
//::6
// +-----------------+
// | operator ==() |
// +-----------------+
inline bool operator ==(
unsigned long i);
//::7
// +-----------------+
// | operator ==() |
// +-----------------+
inline bool operator ==(
TxRGB& fxRgb);
//::10
// +----------------+
// | operator >() |
// +----------------+
inline bool operator >(
TxRGB& fxRgb);
//::12
// +-----------------+
// | operator >=() |
// +-----------------+
inline bool operator >=(
TxRGB& fxRgb);
//::16
// +--------------------+
// | operator TxU32() |
// +--------------------+
inline operator TxU32();
};
//:> +------------------------------------------+
//:>----------------| Inline Member Function Definitions |----------------
//:> +------------------------------------------+
//::1
// +---------------+
// | Constructor |
// +---------------+
inline TxRGB::TxRGB()
{
}
//::2
// +---------------+
// | Constructor |
// +---------------+
inline TxRGB::TxRGB(
unsigned long i) // 32Bit Farbwert
{
r = TxU8(i >> 16);
g = TxU8(i >> 8);
b = TxU8(i);
}
//::8
// +-----------------+
// | operator !=() |
// +-----------------+
inline bool TxRGB::operator !=(
TxRGB& fxRgb)
{
if( r != fxRgb.r || *(TxU16*)(this) != *(TxU16*)(&fxRgb) )
return true;
else
return false;
}
//::3
// +----------------+
// | operator &() |
// +----------------+
inline TxRGB TxRGB::operator &(
const TxRGB& i) const
{
TxRGB t;
t.r = r & i.r;
t.g = g & i.g;
t.b = b & i.b;
return t;
}
//::4
// +-----------------+
// | operator &=() |
// +-----------------+
inline void TxRGB::operator &=(
const TxRGB& i)
{
*(TxU16*)(this) &= *(TxU16*)(&i);
r &= i.r;
}
//::13
// +-----------------+
// | operator ^=() |
// +-----------------+
inline void TxRGB::operator ^=(
TxRGB &rgb)
{
*(TxU16*)(this) ^= *(TxU16*)(&rgb);
r ^= rgb.r;
}
//::14
// +-----------------+
// | operator ^=() |
// +-----------------+
inline void TxRGB::operator ^=(
unsigned long i)
{
*(TxU16*)(this) ^= *(TxU16*)&i;
r ^= *(TxU8*)((TxU8*)(&i)+2);
}
//::5
// +-----------------+
// | operator |=() |
// +-----------------+
inline void TxRGB::operator |=(
const TxRGB& i)
{
*(TxU16*)(&b) |= *(TxU16*)(&i.b);
r |= i.r;
}
//::15
// +----------------+
// | operator ~() |
// +----------------+
inline TxRGB TxRGB::operator ~()
{
TxRGB fxrgb;
*(TxU16*)(&fxrgb) = ~ *(TxU16*)(this);
fxrgb.r = ~r;
return fxrgb;
}
//::9
// +----------------+
// | operator <() |
// +----------------+
inline bool TxRGB::operator <(
TxRGB& fxRgb)
{
TxU32 A= *(TxU32*)(this);
TxU32 B= *(TxU32*)(&fxRgb);
A<<=8;
B<<=8;
return(A<B);
}
//::11
// +-----------------+
// | operator <=() |
// +-----------------+
inline bool TxRGB::operator <=(
TxRGB& fxRgb)
{
TxU32 A= *(TxU32*)(this);
TxU32 B= *(TxU32*)(&fxRgb);
A<<=8;
B<<=8;
return(A<=B);
}
//::6
// +-----------------+
// | operator ==() |
// +-----------------+
inline bool TxRGB::operator ==(
unsigned long i)
{
//intel format
if( *(TxU16*)(&b) == *(TxU16*)&i && r == *(TxU8*)((TxU8*)(&i)+2) )
return true;
else
return false;
}
//::7
// +-----------------+
// | operator ==() |
// +-----------------+
inline bool TxRGB::operator ==(
TxRGB& fxRgb)
{
if( *(TxU16*)(this) == *(TxU16*)(&fxRgb) &&
r == fxRgb.r )
return true;
else
return false;
}
//::10
// +----------------+
// | operator >() |
// +----------------+
inline bool TxRGB::operator >(
TxRGB& fxRgb)
{
TxU32 A= *(TxU32*)(this);
TxU32 B= *(TxU32*)(&fxRgb);
A<<=8;
B<<=8;
return(A>B);
}
//::12
// +-----------------+
// | operator >=() |
// +-----------------+
inline bool TxRGB::operator >=(
TxRGB& fxRgb)
{
TxU32 A= *(TxU32*)(this);
TxU32 B= *(TxU32*)(&fxRgb);
A<<=8;
B<<=8;
return(A>=B);
}
//::16
// +--------------------+
// | operator TxU32() |
// +--------------------+
inline TxRGB::operator TxU32()
{
//intel format
//Unsicher wegen Zugriffsverletztung am Ende eines Datenblockes
//rgb+ geborgts a
//return( *(TxU32*)this & 0xFFFFFF ); <-- funkt nicht am Ende eines Blockes
return(((TxU32)r<<16)|((TxU32)g<<8)|b);
}
#endif // LLGFX_TXRGB_INCLUDED