/src/platform/Bitmap256.cpp

https://bitbucket.org/randrian/openclonk2 · C++ · 105 lines · 68 code · 13 blank · 24 comment · 5 complexity · b8317b17bea4a15b5bfc6732a14a40ec MD5 · raw file

  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. /* A structure for handling 256-color bitmap files */
  20. #include <Standard.h>
  21. #include <Bitmap256.h>
  22. CBitmapInfo::CBitmapInfo()
  23. {
  24. Default();
  25. }
  26. void CBitmapInfo::Default()
  27. {
  28. ZeroMem(this,sizeof(CBitmapInfo));
  29. }
  30. int CBitmapInfo::FileBitsOffset()
  31. {
  32. return Head.bfOffBits-sizeof(CBitmapInfo);
  33. }
  34. void CBitmapInfo::Set(int iWdt, int iHgt, int iBitDepth)
  35. {
  36. Default();
  37. // Set header
  38. Head.bfType=*((WORD*)"BM");
  39. Head.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+DWordAligned(iWdt)*iHgt;
  40. Head.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
  41. // Set bitmap info
  42. Info.biSize=sizeof(BITMAPINFOHEADER);
  43. Info.biWidth=iWdt;
  44. Info.biHeight=iHgt;
  45. Info.biPlanes=1;
  46. Info.biBitCount=iBitDepth;
  47. Info.biCompression=0;
  48. Info.biSizeImage=iWdt*iHgt;
  49. Info.biClrUsed=Info.biClrImportant=0;
  50. }
  51. CBitmap256Info::CBitmap256Info()
  52. {
  53. Default();
  54. }
  55. bool CBitmap256Info::Valid()
  56. {
  57. if (Head.bfType != *((WORD*)"BM") ) return false;
  58. if ((Info.biBitCount!=8) || (Info.biCompression!=0)) return false;
  59. return true;
  60. }
  61. int CBitmap256Info::FileBitsOffset()
  62. {
  63. return Head.bfOffBits-sizeof(CBitmap256Info);
  64. }
  65. void CBitmap256Info::Set(int iWdt, int iHgt, BYTE *bypPalette)
  66. {
  67. Default();
  68. // Set header
  69. Head.bfType=*((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
  73. Info.biSize=sizeof(BITMAPINFOHEADER);
  74. Info.biWidth=iWdt;
  75. Info.biHeight=iHgt;
  76. Info.biPlanes=1;
  77. Info.biBitCount=8;
  78. Info.biCompression=0;
  79. Info.biSizeImage=iWdt*iHgt;
  80. Info.biClrUsed=Info.biClrImportant=256;
  81. // Set palette
  82. for (int cnt=0; cnt<256; cnt++)
  83. {
  84. Colors[cnt].rgbRed = bypPalette[cnt*3+0];
  85. Colors[cnt].rgbGreen = bypPalette[cnt*3+1];
  86. Colors[cnt].rgbBlue = bypPalette[cnt*3+2];
  87. }
  88. }
  89. void CBitmap256Info::Default()
  90. {
  91. ZeroMem(this,sizeof(CBitmap256Info));
  92. }