OpenClonk
CSurface8.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2013-2016, The OpenClonk Team and contributors
6  *
7  * Distributed under the terms of the ISC license; see accompanying file
8  * "COPYING" for details.
9  *
10  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11  * See accompanying file "TRADEMARK" for details.
12  *
13  * To redistribute this file separately, substitute the full license texts
14  * for the above references.
15  */
16 // a class holding a 8 bpp memory surface
17 
18 #ifndef INC_StdSurface8
19 #define INC_StdSurface8
20 
21 class CSurface8
22 {
23 public:
24  CSurface8();
25  ~CSurface8();
26  CSurface8(int iWdt, int iHgt); // create new surface and init it
27 public:
28  int Wdt,Hgt,Pitch; // size of surface
31  CStdPalette *pPal; // pal for this surface (usually points to the main pal)
32  bool HasOwnPal(); // return whether the surface palette is owned
33  void HLine(int iX, int iX2, int iY, int iCol);
34  void Box(int iX, int iY, int iX2, int iY2, int iCol);
35  void Circle(int x, int y, int r, BYTE col);
36  void ClearBox8Only(int iX, int iY, int iWdt, int iHgt); // clear box in 8bpp-surface only
37  void SetPix(int iX, int iY, BYTE byCol)
38  {
39  // clip
40  if ((iX<ClipX) || (iX>ClipX2) || (iY<ClipY) || (iY>ClipY2)) return;
41  // set pix in local copy...
42  if (Bits) Bits[iY*Pitch+iX]=byCol;
43  }
44  void _SetPix(int iX, int iY, BYTE byCol)
45  {
46  // set pix in local copy without bounds or surface checks
47  Bits[iY*Pitch+iX]=byCol;
48  }
49  BYTE GetPix(int iX, int iY) const // get pixel
50  {
51  if (iX<0 || iY<0 || iX>=Wdt || iY>=Hgt) return 0;
52  return Bits ? Bits[iY*Pitch+iX] : 0;
53  }
54  inline BYTE _GetPix(int x, int y) const // get pixel (bounds not checked)
55  {
56  return Bits[y*Pitch+x];
57  }
58  bool Create(int iWdt, int iHgt);
59  void MoveFrom(C4Surface *psfcFrom); // grab data from other surface - invalidates other surface
60  void Clear();
61  void Clip(int iX, int iY, int iX2, int iY2);
62  void NoClip();
63  bool Read(class CStdStream &hGroup);
64  bool Save(const char *szFilename, CStdPalette * = nullptr);
65  void GetSurfaceSize(int &irX, int &irY) const; // get surface size
66  void AllowColor(BYTE iRngLo, BYTE iRngHi, bool fAllowZero=false);
67  void SetBuffer(BYTE *pbyToBuf, int Wdt, int Hgt, int Pitch);
68  void ReleaseBuffer();
69 protected:
70  void MapBytes(BYTE *bpMap);
71  bool ReadBytes(BYTE **lpbpData, void *bpTarget, int iSize);
72 };
73 
74 #endif
uint8_t BYTE
int iSize
Definition: TstC4NetIO.cpp:32
void ClearBox8Only(int iX, int iY, int iWdt, int iHgt)
Definition: CSurface8.cpp:202
void MoveFrom(C4Surface *psfcFrom)
int ClipY
Definition: CSurface8.h:29
void Clip(int iX, int iY, int iX2, int iY2)
Definition: CSurface8.cpp:67
bool Save(const char *szFilename, CStdPalette *=nullptr)
Definition: CSurface8.cpp:158
BYTE _GetPix(int x, int y) const
Definition: CSurface8.h:54
CStdPalette * pPal
Definition: CSurface8.h:31
BYTE GetPix(int iX, int iY) const
Definition: CSurface8.h:49
void HLine(int iX, int iX2, int iY, int iCol)
Definition: CSurface8.cpp:73
int Pitch
Definition: CSurface8.h:28
bool Create(int iWdt, int iHgt)
Definition: CSurface8.cpp:78
void AllowColor(BYTE iRngLo, BYTE iRngHi, bool fAllowZero=false)
Definition: CSurface8.cpp:222
void Circle(int x, int y, int r, BYTE col)
Definition: CSurface8.cpp:212
int ClipY2
Definition: CSurface8.h:29
void GetSurfaceSize(int &irX, int &irY) const
Definition: CSurface8.cpp:195
void Box(int iX, int iY, int iX2, int iY2, int iCol)
Definition: CSurface8.cpp:57
bool HasOwnPal()
void Clear()
Definition: CSurface8.cpp:48
void MapBytes(BYTE *bpMap)
Definition: CSurface8.cpp:189
bool ReadBytes(BYTE **lpbpData, void *bpTarget, int iSize)
void NoClip()
Definition: CSurface8.cpp:62
void _SetPix(int iX, int iY, BYTE byCol)
Definition: CSurface8.h:44
void SetPix(int iX, int iY, BYTE byCol)
Definition: CSurface8.h:37
int ClipX
Definition: CSurface8.h:29
BYTE * Bits
Definition: CSurface8.h:30
void ReleaseBuffer()
Definition: CSurface8.cpp:251
int Wdt
Definition: CSurface8.h:28
bool Read(class CStdStream &hGroup)
Definition: CSurface8.cpp:99
int ClipX2
Definition: CSurface8.h:29
int Hgt
Definition: CSurface8.h:28
void SetBuffer(BYTE *pbyToBuf, int Wdt, int Hgt, int Pitch)
Definition: CSurface8.cpp:239