OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
Bitmap256.cpp
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2011-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 /* A structure for handling 256-color bitmap files */
19 
20 #include "C4Include.h"
21 #include "graphics/Bitmap256.h"
22 #include "lib/StdColors.h"
23 
25 {
26  InplaceReconstruct(this);
27 }
28 
30 {
31  return Head.bfOffBits-sizeof(C4BMPInfo);
32 }
33 
34 void C4BMPInfo::Set(int iWdt, int iHgt, int iBitDepth)
35 {
36  Default();
37  // Set header
38  Head.bfType=*((const WORD*)"BM");
39  Head.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+DWordAligned(iWdt)*iHgt;
41  // Set bitmap info
43  Info.biWidth=iWdt;
44  Info.biHeight=iHgt;
45  Info.biPlanes=1;
46  Info.biBitCount=iBitDepth;
48  Info.biSizeImage=iWdt*iHgt;
50 }
51 
52 
54 {
55  if (Head.bfType != *((const WORD*)"BM") ) return false;
56  if ((Info.biBitCount!=8) || (Info.biCompression!=0)) return false;
57  return true;
58 }
59 
61 {
62  return Head.bfOffBits-sizeof(C4BMP256Info);
63 }
64 
65 void C4BMP256Info::Set(int iWdt, int iHgt, CStdPalette *Palette)
66 {
67  Default();
68  // Set header
69  Head.bfType=*((const WORD*)"BM");
70  Head.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD)+DWordAligned(iWdt)*iHgt;
71  Head.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD);
72  // Set bitmap info
74  Info.biWidth=iWdt;
75  Info.biHeight=iHgt;
76  Info.biPlanes=1;
77  Info.biBitCount=8;
79  Info.biSizeImage=iWdt*iHgt;
81  // Set palette
82  for (int cnt=0; cnt<256; cnt++)
83  {
84  Colors[cnt].rgbRed = GetRedValue(Palette->Colors[cnt]);
85  Colors[cnt].rgbGreen = GetGreenValue(Palette->Colors[cnt]);
86  Colors[cnt].rgbBlue = GetBlueValue(Palette->Colors[cnt]);
87  }
88 }
89 
91 {
92  InplaceReconstruct(this);
93 }
94 
BYTE rgbRed
Definition: Bitmap256.h:54
int DWordAligned(int val)
Definition: Standard.h:47
#define GetGreenValue(rgb)
Definition: StdColors.h:28
struct tagRGBQUAD RGBQUAD
void Default()
Definition: Bitmap256.cpp:24
BITMAPINFOHEADER Info
Definition: Bitmap256.h:67
DWORD Colors[256]
Definition: StdColors.h:184
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
#define GetRedValue(rgb)
Definition: StdColors.h:29
void Default()
Definition: Bitmap256.cpp:90
void Set(int iWdt, int iHgt, int iBitDepth)
Definition: Bitmap256.cpp:34
int FileBitsOffset()
Definition: Bitmap256.cpp:29
BYTE rgbGreen
Definition: Bitmap256.h:53
bool Valid()
Definition: Bitmap256.cpp:53
#define GetBlueValue(rgb)
Definition: StdColors.h:27
std::enable_if< std::is_nothrow_default_constructible< T >::value >::type InplaceReconstruct(T *obj)
Definition: Standard.h:35
BYTE rgbBlue
Definition: Bitmap256.h:52
struct tagBITMAPFILEHEADER BITMAPFILEHEADER
BITMAPFILEHEADER Head
Definition: Bitmap256.h:66
void Set(int iWdt, int iHgt, CStdPalette *)
Definition: Bitmap256.cpp:65
int FileBitsOffset()
Definition: Bitmap256.cpp:60
uint16_t WORD
RGBQUAD Colors[256]
Definition: Bitmap256.h:76