BMP.H 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1999-2005 Id Software, Inc.
  4. This file is part of Quake III Arena source code.
  5. Quake III Arena source code is free software; you can redistribute it
  6. and/or modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. Quake III Arena source code is distributed in the hope that it will be
  10. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Foobar; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. ===========================================================================
  17. */
  18. #ifndef _BMP_H
  19. #define _BMP_H
  20. #define xBI_NONE 0
  21. #define xBI_RGB 0
  22. #define xBI_RLE4 2
  23. #define xBI_RLE8 1
  24. #define BMP_SIGNATURE_WORD 0x4d42
  25. #pragma pack(1)
  26. typedef struct {
  27. unsigned short bfType; // signature - 'BM'
  28. unsigned long bfSize; // file size in bytes
  29. unsigned short bfReserved1; // 0
  30. unsigned short bfReserved2; // 0
  31. unsigned long bfOffBits; // offset to bitmap
  32. } bmphd_t;
  33. typedef struct {
  34. unsigned long biSize; // size of this struct
  35. long biWidth; // bmap width in pixels
  36. long biHeight; // bmap height in pixels
  37. unsigned short biPlanes; // num planes - always 1
  38. unsigned short biBitCount; // bits perpixel
  39. unsigned long biCompression; // compression flag
  40. unsigned long biSizeImage; // image size in bytes
  41. long biXPelsPerMeter; // horz resolution
  42. long biYPelsPerMeter; // vert resolution
  43. unsigned long biClrUsed; // 0 -> color table size
  44. unsigned long biClrImportant; // important color count
  45. } binfo_t;
  46. typedef struct {
  47. unsigned char blue;
  48. unsigned char green;
  49. unsigned char red;
  50. unsigned char reserved;
  51. } drgb_t;
  52. // quake expects its palette to be bgr
  53. // this is totally backwards but what can you do
  54. typedef struct {
  55. unsigned char r;
  56. unsigned char g;
  57. unsigned char b;
  58. } rgb_t;
  59. typedef struct {
  60. unsigned char b;
  61. unsigned char g;
  62. unsigned char r;
  63. } bgr_t;
  64. typedef struct {
  65. int bpp; // bits per pixel
  66. int width;
  67. int height;
  68. unsigned char *data;
  69. rgb_t *palette;
  70. } bitmap_t;
  71. void LoadBMP(char *filename, bitmap_t *bit);
  72. void FreeBMP(bitmap_t *bitmap);
  73. void WriteBMP(char *filename, bitmap_t *bit);
  74. void NewBMP(int width, int height, int bpp, bitmap_t *bit);
  75. #endif