OpenClonk
CSurface8 Class Reference

#include <CSurface8.h>

Collaboration diagram for CSurface8:
[legend]

Public Member Functions

 CSurface8 ()
 
 ~CSurface8 ()
 
 CSurface8 (int iWdt, int iHgt)
 
bool HasOwnPal ()
 
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)
 
void SetPix (int iX, int iY, BYTE byCol)
 
void _SetPix (int iX, int iY, BYTE byCol)
 
BYTE GetPix (int iX, int iY) const
 
BYTE _GetPix (int x, int y) const
 
bool Create (int iWdt, int iHgt)
 
void MoveFrom (C4Surface *psfcFrom)
 
void Clear ()
 
void Clip (int iX, int iY, int iX2, int iY2)
 
void NoClip ()
 
bool Read (class CStdStream &hGroup)
 
bool Save (const char *szFilename, CStdPalette *=nullptr)
 
void GetSurfaceSize (int &irX, int &irY) const
 
void AllowColor (BYTE iRngLo, BYTE iRngHi, bool fAllowZero=false)
 
void SetBuffer (BYTE *pbyToBuf, int Wdt, int Hgt, int Pitch)
 
void ReleaseBuffer ()
 

Public Attributes

int Wdt
 
int Hgt
 
int Pitch
 
int ClipX
 
int ClipY
 
int ClipX2
 
int ClipY2
 
BYTEBits
 
CStdPalettepPal
 

Protected Member Functions

void MapBytes (BYTE *bpMap)
 
bool ReadBytes (BYTE **lpbpData, void *bpTarget, int iSize)
 

Detailed Description

Definition at line 21 of file CSurface8.h.

Constructor & Destructor Documentation

◆ CSurface8() [1/2]

CSurface8::CSurface8 ( )

Definition at line 26 of file CSurface8.cpp.

27 {
28  Wdt=Hgt=Pitch=0;
30  Bits=nullptr;
31  pPal=nullptr;
32 }
int ClipY
Definition: CSurface8.h:29
CStdPalette * pPal
Definition: CSurface8.h:31
int Pitch
Definition: CSurface8.h:28
int ClipY2
Definition: CSurface8.h:29
int ClipX
Definition: CSurface8.h:29
BYTE * Bits
Definition: CSurface8.h:30
int Wdt
Definition: CSurface8.h:28
int ClipX2
Definition: CSurface8.h:29
int Hgt
Definition: CSurface8.h:28

References Bits, ClipX, ClipX2, ClipY, ClipY2, Hgt, Pitch, pPal, and Wdt.

◆ ~CSurface8()

CSurface8::~CSurface8 ( )

Definition at line 43 of file CSurface8.cpp.

44 {
45  Clear();
46 }
void Clear()
Definition: CSurface8.cpp:48

References Clear().

Here is the call graph for this function:

◆ CSurface8() [2/2]

CSurface8::CSurface8 ( int  iWdt,
int  iHgt 
)

Definition at line 34 of file CSurface8.cpp.

35 {
36  Wdt=Hgt=Pitch=0;
38  Bits=nullptr;
39  pPal=nullptr;
40  Create(iWdt, iHgt);
41 }
bool Create(int iWdt, int iHgt)
Definition: CSurface8.cpp:78

References Bits, ClipX, ClipX2, ClipY, ClipY2, Create(), Hgt, Pitch, pPal, and Wdt.

Here is the call graph for this function:

Member Function Documentation

◆ _GetPix()

BYTE CSurface8::_GetPix ( int  x,
int  y 
) const
inline

Definition at line 54 of file CSurface8.h.

55  {
56  return Bits[y*Pitch+x];
57  }

References Bits, and Pitch.

Referenced by C4Landscape::P::ChunkOZoom(), C4Landscape::P::CreateDefaultBkgSurface(), C4TextureShape::Draw(), and C4SolidMask::DensityProvider::GetDensity().

Here is the caller graph for this function:

◆ _SetPix()

void CSurface8::_SetPix ( int  iX,
int  iY,
BYTE  byCol 
)
inline

Definition at line 44 of file CSurface8.h.

45  {
46  // set pix in local copy without bounds or surface checks
47  Bits[iY*Pitch+iX]=byCol;
48  }

References Bits, and Pitch.

Referenced by C4Landscape::P::CreateDefaultBkgSurface(), and C4TextureShape::Load().

Here is the caller graph for this function:

◆ AllowColor()

void CSurface8::AllowColor ( BYTE  iRngLo,
BYTE  iRngHi,
bool  fAllowZero = false 
)

Definition at line 222 of file CSurface8.cpp.

223 {
224  // change colors
225  int xcnt,ycnt;
226  if (iRngHi<iRngLo) return;
227  for (ycnt=0; ycnt<Hgt; ycnt++)
228  {
229  for (xcnt=0; xcnt<Wdt; xcnt++)
230  {
231  BYTE px=GetPix(xcnt,ycnt);
232  if (px || !fAllowZero)
233  if ((px<iRngLo) || (px>iRngHi))
234  SetPix(xcnt, ycnt, iRngLo + px % (iRngHi-iRngLo+1));
235  }
236  }
237 }
uint8_t BYTE
BYTE GetPix(int iX, int iY) const
Definition: CSurface8.h:49
void SetPix(int iX, int iY, BYTE byCol)
Definition: CSurface8.h:37

References GetPix(), Hgt, SetPix(), and Wdt.

Here is the call graph for this function:

◆ Box()

void CSurface8::Box ( int  iX,
int  iY,
int  iX2,
int  iY2,
int  iCol 
)

Definition at line 57 of file CSurface8.cpp.

58 {
59  for (int cy=iY; cy<=iY2; cy++) HLine(iX,iX2,cy,iCol);
60 }
void HLine(int iX, int iX2, int iY, int iCol)
Definition: CSurface8.cpp:73

References HLine().

Here is the call graph for this function:

◆ Circle()

void CSurface8::Circle ( int  x,
int  y,
int  r,
BYTE  col 
)

Definition at line 212 of file CSurface8.cpp.

213 {
214  for (int ycnt=-r; ycnt<r; ycnt++)
215  {
216  int lwdt = (int) sqrt(float(r*r-ycnt*ycnt));
217  for (int xcnt = 2 * lwdt - 1; xcnt >= 0; xcnt--)
218  SetPix(x - lwdt + xcnt, y + ycnt, col);
219  }
220 }

References SetPix().

Here is the call graph for this function:

◆ Clear()

void CSurface8::Clear ( )

Definition at line 48 of file CSurface8.cpp.

49 {
50  // clear bitmap-copy
51  delete [] Bits; Bits=nullptr;
52  // clear pal
53  delete pPal;
54  pPal=nullptr;
55 }

References Bits, and pPal.

Referenced by C4TextureShape::Clear(), Create(), Read(), ReleaseBuffer(), SetBuffer(), and ~CSurface8().

Here is the caller graph for this function:

◆ ClearBox8Only()

void CSurface8::ClearBox8Only ( int  iX,
int  iY,
int  iWdt,
int  iHgt 
)

Definition at line 202 of file CSurface8.cpp.

203 {
204  // clear rect; assume clip already
205  for (int y=iY; y<iY+iHgt; ++y)
206  for (int x=iX; x<iX+iWdt; ++x)
207  Bits[y*Pitch+x] = 0;
208  // done
209 }

References Bits, and Pitch.

Referenced by C4MapCreator::Create().

Here is the caller graph for this function:

◆ Clip()

void CSurface8::Clip ( int  iX,
int  iY,
int  iX2,
int  iY2 
)

Definition at line 67 of file CSurface8.cpp.

68 {
69  ClipX=Clamp(iX,0,Wdt-1); ClipY=Clamp(iY,0,Hgt-1);
70  ClipX2=Clamp(iX2,0,Wdt-1); ClipY2=Clamp(iY2,0,Hgt-1);
71 }
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:44

References Clamp(), ClipX, ClipX2, ClipY, ClipY2, Hgt, and Wdt.

Here is the call graph for this function:

◆ Create()

bool CSurface8::Create ( int  iWdt,
int  iHgt 
)

Definition at line 78 of file CSurface8.cpp.

79 {
80  Clear();
81  // check size
82  if (!iWdt || !iHgt) return false;
83  Wdt=iWdt; Hgt=iHgt;
84 
85  // create pal
86  pPal = new CStdPalette;
87  if (!pPal) return false;
88  memset(pPal->Colors, 0, sizeof(pPal->Colors));
89 
90  Bits=new BYTE[Wdt*Hgt];
91  if (!Bits) return false;
92  memset(Bits, 0, Wdt*Hgt);
93  Pitch=Wdt;
94  // update clipping
95  NoClip();
96  return true;
97 }
void NoClip()
Definition: CSurface8.cpp:62
DWORD Colors[256]
Definition: StdColors.h:186

References Bits, Clear(), CStdPalette::Colors, Hgt, NoClip(), Pitch, pPal, and Wdt.

Referenced by CSurface8(), C4TextureShape::Load(), and Read().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetPix()

BYTE CSurface8::GetPix ( int  iX,
int  iY 
) const
inline

Definition at line 49 of file CSurface8.h.

50  {
51  if (iX<0 || iY<0 || iX>=Wdt || iY>=Hgt) return 0;
52  return Bits ? Bits[iY*Pitch+iX] : 0;
53  }

References Bits, Hgt, Pitch, and Wdt.

Referenced by AllowColor(), C4Draw::Blit8Fast(), C4Landscape::P::ChunkOZoom(), C4TextureShape::Draw(), C4MapCreator::GetPix(), and MapBytes().

Here is the caller graph for this function:

◆ GetSurfaceSize()

void CSurface8::GetSurfaceSize ( int &  irX,
int &  irY 
) const

Definition at line 195 of file CSurface8.cpp.

196 {
197  // simply assign stored values
198  irX=Wdt;
199  irY=Hgt;
200 }

References Hgt, and Wdt.

Referenced by C4Landscape::P::ChunkOZoom(), and C4Landscape::P::MapToLandscape().

Here is the caller graph for this function:

◆ HasOwnPal()

bool CSurface8::HasOwnPal ( )

◆ HLine()

void CSurface8::HLine ( int  iX,
int  iX2,
int  iY,
int  iCol 
)

Definition at line 73 of file CSurface8.cpp.

74 {
75  for (int cx=iX; cx<=iX2; cx++) SetPix(cx,iY,iCol);
76 }

References SetPix().

Referenced by Box().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MapBytes()

void CSurface8::MapBytes ( BYTE bpMap)
protected

Definition at line 189 of file CSurface8.cpp.

190 {
191  if (!bpMap) return;
192  for (int cnt=0; cnt<Wdt*Hgt; cnt++) SetPix(cnt%Wdt, cnt/Wdt, bpMap[GetPix(cnt%Wdt, cnt/Wdt)]);
193 }

References GetPix(), Hgt, SetPix(), and Wdt.

Here is the call graph for this function:

◆ MoveFrom()

void CSurface8::MoveFrom ( C4Surface psfcFrom)

◆ NoClip()

void CSurface8::NoClip ( )

Definition at line 62 of file CSurface8.cpp.

63 {
64  ClipX=0; ClipY=0; ClipX2=Wdt-1; ClipY2=Hgt-1;
65 }

References ClipX, ClipX2, ClipY, ClipY2, Hgt, and Wdt.

Referenced by Create(), and SetBuffer().

Here is the caller graph for this function:

◆ Read()

bool CSurface8::Read ( class CStdStream hGroup)

Definition at line 99 of file CSurface8.cpp.

100 {
101  int cnt,lcnt;
102  C4BMP256Info BitmapInfo;
103  // read bmpinfo-header
104  if (!hGroup.Read(&BitmapInfo,sizeof(C4BMPInfo))) return false;
105  // is it 8bpp?
106  if (BitmapInfo.Info.biBitCount == 8)
107  {
108  if (!hGroup.Read(((BYTE *) &BitmapInfo)+sizeof(C4BMPInfo),sizeof(BitmapInfo)-sizeof(C4BMPInfo))) return false;
109  if (!hGroup.Advance(BitmapInfo.FileBitsOffset())) return false;
110  }
111  else
112  {
113  // read 24bpp
114  if (BitmapInfo.Info.biBitCount != 24) return false;
115  if (!hGroup.Advance(((C4BMPInfo) BitmapInfo).FileBitsOffset())) return false;
116  }
117 
118  // Create and lock surface
119  if (!Create(BitmapInfo.Info.biWidth,BitmapInfo.Info.biHeight)) return false;
120 
121  if (BitmapInfo.Info.biBitCount == 8)
122  {
123  // Copy palette
124  for (cnt=0; cnt<256; cnt++)
125  {
126  pPal->Colors[cnt] = C4RGB(BitmapInfo.Colors[cnt].rgbRed,
127  BitmapInfo.Colors[cnt].rgbGreen,
128  BitmapInfo.Colors[cnt].rgbBlue);
129  }
130  }
131 
132  // create line buffer
133  int iBufSize=DWordAligned(BitmapInfo.Info.biWidth*BitmapInfo.Info.biBitCount/8);
134  BYTE *pBuf = new BYTE[iBufSize];
135  // Read lines
136  for (lcnt=Hgt-1; lcnt>=0; lcnt--)
137  {
138  if (!hGroup.Read(pBuf, iBufSize))
139  { Clear(); delete [] pBuf; return false; }
140  BYTE *pPix=pBuf;
141  for (int x=0; x<BitmapInfo.Info.biWidth; ++x)
142  switch (BitmapInfo.Info.biBitCount)
143  {
144  case 8:
145  SetPix(x, lcnt, *pPix++);
146  break;
147  case 24:
148  return false;
149  break;
150  }
151  }
152  // free buffer again
153  delete [] pBuf;
154 
155  return true;
156 }
int DWordAligned(int val)
Definition: Standard.h:47
#define C4RGB(r, g, b)
Definition: StdColors.h:26
BITMAPINFOHEADER Info
Definition: Bitmap256.h:67

References CStdStream::Advance(), tagBITMAPINFOHEADER::biBitCount, tagBITMAPINFOHEADER::biHeight, tagBITMAPINFOHEADER::biWidth, C4RGB, Clear(), C4BMP256Info::Colors, CStdPalette::Colors, Create(), DWordAligned(), Hgt, C4BMPInfo::Info, pPal, CStdStream::Read(), tagRGBQUAD::rgbBlue, tagRGBQUAD::rgbGreen, tagRGBQUAD::rgbRed, and SetPix().

Here is the call graph for this function:

◆ ReadBytes()

bool CSurface8::ReadBytes ( BYTE **  lpbpData,
void *  bpTarget,
int  iSize 
)
protected

◆ ReleaseBuffer()

void CSurface8::ReleaseBuffer ( )

Definition at line 251 of file CSurface8.cpp.

252 {
253  this->Bits = nullptr;
254  Clear();
255 }

References Bits, and Clear().

Here is the call graph for this function:

◆ Save()

bool CSurface8::Save ( const char *  szFilename,
CStdPalette bpPalette = nullptr 
)

Definition at line 158 of file CSurface8.cpp.

159 {
160  C4BMP256Info BitmapInfo;
161  BitmapInfo.Set(Wdt,Hgt, bpPalette ? bpPalette : pPal);
162 
163  // Create file & write info
164  CStdFile hFile;
165 
166  if ( !hFile.Create(szFilename)
167  || !hFile.Write(&BitmapInfo,sizeof(BitmapInfo)) )
168  { return false; }
169 
170  // Write lines
171  char bpEmpty[4]; ZeroMem(bpEmpty, 4);
172  const int iEmpty = DWordAligned(Wdt)-Wdt;
173  for (int cnt=Hgt-1; cnt>=0; cnt--)
174  {
175  if (!hFile.Write(Bits+(Pitch*cnt),Wdt))
176  { return false; }
177  if (iEmpty)
178  if (!hFile.Write(bpEmpty,iEmpty))
179  { return false; }
180  }
181 
182  // Close file
183  hFile.Close();
184 
185  // Success
186  return true;
187 }
std::enable_if< std::is_pod< T >::value >::type ZeroMem(T *lpMem, size_t dwSize)
Definition: Standard.h:60
void Set(int iWdt, int iHgt, CStdPalette *)
Definition: Bitmap256.cpp:65
bool Close(StdBuf **ppMemory=nullptr)
Definition: CStdFile.cpp:151
bool Create(const char *szFileName, bool fCompressed=false, bool fExecutable=false, bool fMemory=false)
Definition: CStdFile.cpp:49
bool Write(const void *pBuffer, int iSize)
Definition: CStdFile.cpp:240

References Bits, CStdFile::Close(), CStdFile::Create(), DWordAligned(), Hgt, Pitch, pPal, C4BMP256Info::Set(), Wdt, CStdFile::Write(), and ZeroMem().

Referenced by C4FoWAmbient::UpdateFromLandscape().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetBuffer()

void CSurface8::SetBuffer ( BYTE pbyToBuf,
int  Wdt,
int  Hgt,
int  Pitch 
)

Definition at line 239 of file CSurface8.cpp.

240 {
241  // release old
242  Clear();
243  // set new
244  this->Wdt=Wdt;
245  this->Hgt=Hgt;
246  this->Pitch=Pitch;
247  this->Bits = pbyToBuf;
248  NoClip();
249 }

References Bits, Clear(), Hgt, NoClip(), Pitch, and Wdt.

Here is the call graph for this function:

◆ SetPix()

void CSurface8::SetPix ( int  iX,
int  iY,
BYTE  byCol 
)
inline

Definition at line 37 of file CSurface8.h.

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  }

References Bits, ClipX, ClipX2, ClipY, ClipY2, and Pitch.

Referenced by AllowColor(), Circle(), HLine(), C4SolidMask::LoadMaskFromFile(), MapBytes(), Read(), C4MapCreator::SetPix(), and C4FoWAmbient::UpdateFromLandscape().

Here is the caller graph for this function:

Member Data Documentation

◆ Bits

◆ ClipX

int CSurface8::ClipX

Definition at line 29 of file CSurface8.h.

Referenced by Clip(), CSurface8(), NoClip(), and SetPix().

◆ ClipX2

int CSurface8::ClipX2

Definition at line 29 of file CSurface8.h.

Referenced by Clip(), CSurface8(), NoClip(), and SetPix().

◆ ClipY

int CSurface8::ClipY

Definition at line 29 of file CSurface8.h.

Referenced by Clip(), CSurface8(), NoClip(), and SetPix().

◆ ClipY2

int CSurface8::ClipY2

Definition at line 29 of file CSurface8.h.

Referenced by Clip(), CSurface8(), NoClip(), and SetPix().

◆ Hgt

◆ Pitch

◆ pPal

CStdPalette* CSurface8::pPal

Definition at line 31 of file CSurface8.h.

Referenced by C4Draw::Blit8Fast(), Clear(), Create(), CSurface8(), Read(), and Save().

◆ Wdt


The documentation for this class was generated from the following files: