2009-05-08 13:28:41 +00:00
|
|
|
/*
|
|
|
|
* OpenClonk, http://www.openclonk.org
|
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* Copyright (c) 1998-2000, Matthes Bender
|
|
|
|
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
|
2016-04-03 18:18:29 +00:00
|
|
|
* Copyright (c) 2011-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 structure for handling 256-color bitmap files */
|
|
|
|
|
2009-10-20 03:39:24 +00:00
|
|
|
#include "C4Include.h"
|
2016-04-03 18:07:56 +00:00
|
|
|
#include "graphics/Bitmap256.h"
|
|
|
|
#include "lib/StdColors.h"
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2011-08-27 14:32:15 +00:00
|
|
|
void C4BMPInfo::Default()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2015-11-14 15:17:00 +00:00
|
|
|
InplaceReconstruct(this);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2011-08-27 14:32:15 +00:00
|
|
|
int C4BMPInfo::FileBitsOffset()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2011-08-27 14:32:15 +00:00
|
|
|
return Head.bfOffBits-sizeof(C4BMPInfo);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2011-08-27 14:32:15 +00:00
|
|
|
void C4BMPInfo::Set(int iWdt, int iHgt, int iBitDepth)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
Default();
|
2010-03-27 16:05:02 +00:00
|
|
|
// Set header
|
2015-08-31 18:52:39 +00:00
|
|
|
Head.bfType=*((const WORD*)"BM");
|
2010-03-27 16:05:02 +00:00
|
|
|
Head.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+DWordAligned(iWdt)*iHgt;
|
|
|
|
Head.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
|
|
|
|
// Set bitmap info
|
|
|
|
Info.biSize=sizeof(BITMAPINFOHEADER);
|
|
|
|
Info.biWidth=iWdt;
|
|
|
|
Info.biHeight=iHgt;
|
|
|
|
Info.biPlanes=1;
|
|
|
|
Info.biBitCount=iBitDepth;
|
|
|
|
Info.biCompression=0;
|
|
|
|
Info.biSizeImage=iWdt*iHgt;
|
|
|
|
Info.biClrUsed=Info.biClrImportant=0;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
|
2011-08-27 14:32:15 +00:00
|
|
|
bool C4BMP256Info::Valid()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2015-08-31 18:52:39 +00:00
|
|
|
if (Head.bfType != *((const WORD*)"BM") ) return false;
|
2010-03-27 16:05:02 +00:00
|
|
|
if ((Info.biBitCount!=8) || (Info.biCompression!=0)) return false;
|
2009-08-15 18:50:32 +00:00
|
|
|
return true;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2011-08-27 14:32:15 +00:00
|
|
|
int C4BMP256Info::FileBitsOffset()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2011-08-27 14:32:15 +00:00
|
|
|
return Head.bfOffBits-sizeof(C4BMP256Info);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2012-08-15 22:45:27 +00:00
|
|
|
void C4BMP256Info::Set(int iWdt, int iHgt, CStdPalette *Palette)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
Default();
|
2010-03-27 16:05:02 +00:00
|
|
|
// Set header
|
2015-08-31 18:52:39 +00:00
|
|
|
Head.bfType=*((const WORD*)"BM");
|
2010-03-27 16:05:02 +00:00
|
|
|
Head.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD)+DWordAligned(iWdt)*iHgt;
|
|
|
|
Head.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD);
|
|
|
|
// Set bitmap info
|
|
|
|
Info.biSize=sizeof(BITMAPINFOHEADER);
|
|
|
|
Info.biWidth=iWdt;
|
|
|
|
Info.biHeight=iHgt;
|
|
|
|
Info.biPlanes=1;
|
|
|
|
Info.biBitCount=8;
|
|
|
|
Info.biCompression=0;
|
|
|
|
Info.biSizeImage=iWdt*iHgt;
|
|
|
|
Info.biClrUsed=Info.biClrImportant=256;
|
2009-05-08 13:28:41 +00:00
|
|
|
// Set palette
|
2010-03-27 16:05:02 +00:00
|
|
|
for (int cnt=0; cnt<256; cnt++)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2012-08-15 22:45:27 +00:00
|
|
|
Colors[cnt].rgbRed = GetRedValue(Palette->Colors[cnt]);
|
|
|
|
Colors[cnt].rgbGreen = GetGreenValue(Palette->Colors[cnt]);
|
|
|
|
Colors[cnt].rgbBlue = GetBlueValue(Palette->Colors[cnt]);
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2011-08-27 14:32:15 +00:00
|
|
|
void C4BMP256Info::Default()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2015-11-14 15:17:00 +00:00
|
|
|
InplaceReconstruct(this);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|