PageRenderTime 58ms CodeModel.GetById 22ms app.highlight 29ms RepoModel.GetById 1ms app.codeStats 0ms

/src/platform/Bitmap256.cpp

https://bitbucket.org/randrian/openclonk2
C++ | 105 lines | 68 code | 13 blank | 24 comment | 5 complexity | b8317b17bea4a15b5bfc6732a14a40ec MD5 | raw file
Possible License(s): WTFPL, 0BSD, LGPL-2.1, CC-BY-3.0
  1/*
  2 * OpenClonk, http://www.openclonk.org
  3 *
  4 * Copyright (c) 1998-2000  Matthes Bender
  5 * Copyright (c) 2002  Sven Eberhardt
  6 * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de
  7 *
  8 * Portions might be copyrighted by other authors who have contributed
  9 * to OpenClonk.
 10 *
 11 * Permission to use, copy, modify, and/or distribute this software for any
 12 * purpose with or without fee is hereby granted, provided that the above
 13 * copyright notice and this permission notice appear in all copies.
 14 * See isc_license.txt for full license and disclaimer.
 15 *
 16 * "Clonk" is a registered trademark of Matthes Bender.
 17 * See clonk_trademark_license.txt for full license.
 18 */
 19
 20/* A structure for handling 256-color bitmap files */
 21
 22#include <Standard.h>
 23#include <Bitmap256.h>
 24
 25CBitmapInfo::CBitmapInfo()
 26	{
 27	Default();
 28	}
 29
 30void CBitmapInfo::Default()
 31	{
 32	ZeroMem(this,sizeof(CBitmapInfo));
 33	}
 34
 35int CBitmapInfo::FileBitsOffset()
 36	{
 37	return Head.bfOffBits-sizeof(CBitmapInfo);
 38	}
 39
 40void CBitmapInfo::Set(int iWdt, int iHgt, int iBitDepth)
 41	{
 42	Default();
 43  // Set header
 44  Head.bfType=*((WORD*)"BM");
 45  Head.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+DWordAligned(iWdt)*iHgt;
 46  Head.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
 47  // Set bitmap info
 48  Info.biSize=sizeof(BITMAPINFOHEADER);
 49  Info.biWidth=iWdt;
 50  Info.biHeight=iHgt;
 51  Info.biPlanes=1;
 52  Info.biBitCount=iBitDepth;
 53  Info.biCompression=0;
 54  Info.biSizeImage=iWdt*iHgt;
 55  Info.biClrUsed=Info.biClrImportant=0;
 56	}
 57
 58
 59CBitmap256Info::CBitmap256Info()
 60	{
 61	Default();
 62	}
 63
 64bool CBitmap256Info::Valid()
 65	{
 66  if (Head.bfType != *((WORD*)"BM") ) return false;
 67  if ((Info.biBitCount!=8) || (Info.biCompression!=0)) return false;
 68	return true;
 69	}
 70
 71int CBitmap256Info::FileBitsOffset()
 72	{
 73	return Head.bfOffBits-sizeof(CBitmap256Info);
 74	}
 75
 76void CBitmap256Info::Set(int iWdt, int iHgt, BYTE *bypPalette)
 77	{
 78	Default();
 79  // Set header
 80  Head.bfType=*((WORD*)"BM");
 81  Head.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD)+DWordAligned(iWdt)*iHgt;
 82  Head.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD);
 83  // Set bitmap info
 84  Info.biSize=sizeof(BITMAPINFOHEADER);
 85  Info.biWidth=iWdt;
 86  Info.biHeight=iHgt;
 87  Info.biPlanes=1;
 88  Info.biBitCount=8;
 89  Info.biCompression=0;
 90  Info.biSizeImage=iWdt*iHgt;
 91  Info.biClrUsed=Info.biClrImportant=256;
 92	// Set palette
 93  for (int cnt=0; cnt<256; cnt++)
 94    {
 95    Colors[cnt].rgbRed	 = bypPalette[cnt*3+0];
 96    Colors[cnt].rgbGreen = bypPalette[cnt*3+1];
 97    Colors[cnt].rgbBlue  = bypPalette[cnt*3+2];
 98    }
 99	}
100
101void CBitmap256Info::Default()
102	{
103	ZeroMem(this,sizeof(CBitmap256Info));
104	}
105