2009-05-08 13:28:41 +00:00
|
|
|
/*
|
|
|
|
* OpenClonk, http://www.openclonk.org
|
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
|
2016-04-03 18:18:29 +00:00
|
|
|
* Copyright (c) 2013-2016, The OpenClonk Team and contributors
|
2009-05-08 13:28:41 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* Distributed under the terms of the ISC license; see accompanying file
|
|
|
|
* "COPYING" for details.
|
2009-05-08 13:28:41 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* "Clonk" is a registered trademark of Matthes Bender, used with permission.
|
|
|
|
* See accompanying file "TRADEMARK" for details.
|
2009-05-08 13:28:41 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* To redistribute this file separately, substitute the full license texts
|
|
|
|
* for the above references.
|
2009-05-08 13:28:41 +00:00
|
|
|
*/
|
|
|
|
// a class holding a 8 bpp memory surface
|
|
|
|
|
|
|
|
#ifndef INC_StdSurface8
|
|
|
|
#define INC_StdSurface8
|
|
|
|
|
|
|
|
class CSurface8
|
2010-03-28 17:58:21 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CSurface8();
|
|
|
|
~CSurface8();
|
|
|
|
CSurface8(int iWdt, int iHgt); // create new surface and init it
|
|
|
|
public:
|
|
|
|
int Wdt,Hgt,Pitch; // size of surface
|
|
|
|
int ClipX,ClipY,ClipX2,ClipY2;
|
|
|
|
BYTE *Bits;
|
|
|
|
CStdPalette *pPal; // pal for this surface (usually points to the main pal)
|
|
|
|
bool HasOwnPal(); // return whether the surface palette is owned
|
|
|
|
void HLine(int iX, int iX2, int iY, int iCol);
|
|
|
|
void Box(int iX, int iY, int iX2, int iY2, int iCol);
|
|
|
|
void Circle(int x, int y, int r, BYTE col);
|
|
|
|
void ClearBox8Only(int iX, int iY, int iWdt, int iHgt); // clear box in 8bpp-surface only
|
|
|
|
void SetPix(int iX, int iY, BYTE byCol)
|
2009-05-08 13:28:41 +00:00
|
|
|
{
|
2010-03-28 17:58:21 +00:00
|
|
|
// clip
|
|
|
|
if ((iX<ClipX) || (iX>ClipX2) || (iY<ClipY) || (iY>ClipY2)) return;
|
|
|
|
// set pix in local copy...
|
|
|
|
if (Bits) Bits[iY*Pitch+iX]=byCol;
|
|
|
|
}
|
2013-03-18 23:35:00 +00:00
|
|
|
void _SetPix(int iX, int iY, BYTE byCol)
|
|
|
|
{
|
|
|
|
// set pix in local copy without bounds or surface checks
|
|
|
|
Bits[iY*Pitch+iX]=byCol;
|
|
|
|
}
|
2015-06-22 22:56:04 +00:00
|
|
|
BYTE GetPix(int iX, int iY) const // get pixel
|
2010-03-28 17:58:21 +00:00
|
|
|
{
|
|
|
|
if (iX<0 || iY<0 || iX>=Wdt || iY>=Hgt) return 0;
|
|
|
|
return Bits ? Bits[iY*Pitch+iX] : 0;
|
|
|
|
}
|
2015-06-22 22:56:04 +00:00
|
|
|
inline BYTE _GetPix(int x, int y) const // get pixel (bounds not checked)
|
2010-03-28 17:58:21 +00:00
|
|
|
{
|
|
|
|
return Bits[y*Pitch+x];
|
|
|
|
}
|
2010-06-28 23:02:16 +00:00
|
|
|
bool Create(int iWdt, int iHgt);
|
2011-10-03 14:06:41 +00:00
|
|
|
void MoveFrom(C4Surface *psfcFrom); // grab data from other surface - invalidates other surface
|
2010-03-28 17:58:21 +00:00
|
|
|
void Clear();
|
|
|
|
void Clip(int iX, int iY, int iX2, int iY2);
|
|
|
|
void NoClip();
|
2010-06-28 23:02:16 +00:00
|
|
|
bool Read(class CStdStream &hGroup);
|
2016-11-02 23:58:02 +00:00
|
|
|
bool Save(const char *szFilename, CStdPalette * = nullptr);
|
2016-04-02 15:50:49 +00:00
|
|
|
void GetSurfaceSize(int &irX, int &irY) const; // get surface size
|
2010-03-28 17:58:21 +00:00
|
|
|
void AllowColor(BYTE iRngLo, BYTE iRngHi, bool fAllowZero=false);
|
|
|
|
void SetBuffer(BYTE *pbyToBuf, int Wdt, int Hgt, int Pitch);
|
|
|
|
void ReleaseBuffer();
|
|
|
|
protected:
|
|
|
|
void MapBytes(BYTE *bpMap);
|
|
|
|
bool ReadBytes(BYTE **lpbpData, void *bpTarget, int iSize);
|
|
|
|
};
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
#endif
|