il_bmp.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //-----------------------------------------------------------------------------
  2. //
  3. // ImageLib Sources
  4. // Copyright (C) 2000-2002 by Denton Woods
  5. // Last modified: 09/01/2003 <--Y2K Compliant! =]
  6. //
  7. // Filename: src-IL/include/il_bmp.h
  8. //
  9. // Description: Reads and writes to a bitmap (.bmp) file.
  10. //
  11. //-----------------------------------------------------------------------------
  12. #ifndef BMP_H
  13. #define BMP_H
  14. #include "il_internal.h"
  15. #ifdef _WIN32
  16. #pragma pack(push, bmp_struct, 1)
  17. #endif
  18. typedef struct BMPHEAD {
  19. ILushort bfType;
  20. ILint bfSize;
  21. ILuint bfReserved;
  22. ILint bfDataOff;
  23. ILint biSize;
  24. ILint biWidth;
  25. ILint biHeight;
  26. ILshort biPlanes;
  27. ILshort biBitCount;
  28. ILint biCompression;
  29. ILint biSizeImage;
  30. ILint biXPelsPerMeter;
  31. ILint biYPelsPerMeter;
  32. ILint biClrUsed;
  33. ILint biClrImportant;
  34. } IL_PACKSTRUCT BMPHEAD;
  35. typedef struct OS2_HEAD
  36. {
  37. // Bitmap file header.
  38. ILushort bfType;
  39. ILuint biSize;
  40. ILshort xHotspot;
  41. ILshort yHotspot;
  42. ILuint DataOff;
  43. // Bitmap core header.
  44. ILuint cbFix;
  45. //2003-09-01: changed cx, cy to ushort according to MSDN
  46. ILushort cx;
  47. ILushort cy;
  48. ILushort cPlanes;
  49. ILushort cBitCount;
  50. } IL_PACKSTRUCT OS2_HEAD;
  51. #ifdef _WIN32
  52. #pragma pack(pop, bmp_struct)
  53. #endif
  54. // Internal functions
  55. ILboolean iGetBmpHead(BMPHEAD * const Header);
  56. ILboolean iGetOS2Head(OS2_HEAD * const Header);
  57. ILboolean iIsValidBmp();
  58. ILboolean iCheckBmp(const BMPHEAD *CONST_RESTRICT Header);
  59. ILboolean iCheckOS2(const OS2_HEAD *CONST_RESTRICT Header);
  60. ILboolean iLoadBitmapInternal();
  61. ILboolean iSaveBitmapInternal();
  62. ILboolean ilReadUncompBmp(BMPHEAD *Info);
  63. ILboolean ilReadRLE8Bmp(BMPHEAD *Info);
  64. ILboolean ilReadRLE4Bmp(BMPHEAD *Info);
  65. ILboolean iGetOS2Bmp(OS2_HEAD *Header);
  66. #ifdef IL_BMP_C
  67. #undef NOINLINE
  68. #undef INLINE
  69. #define INLINE
  70. #endif
  71. #ifndef NOINLINE
  72. INLINE void GetShiftFromMask(const ILuint Mask, ILuint * CONST_RESTRICT ShiftLeft, ILuint * CONST_RESTRICT ShiftRight) {
  73. ILuint Temp, i;
  74. if( Mask == 0 ) {
  75. *ShiftLeft = *ShiftRight = 0;
  76. return;
  77. }
  78. Temp = Mask;
  79. for( i = 0; i < 32; i++, Temp >>= 1 ) {
  80. if( Temp & 1 )
  81. break;
  82. }
  83. *ShiftRight = i;
  84. // Temp is preserved, so use it again:
  85. for( i = 0; i < 8; i++, Temp >>= 1 ) {
  86. if( !(Temp & 1) )
  87. break;
  88. }
  89. *ShiftLeft = 8 - i;
  90. return;
  91. }
  92. #endif
  93. #endif//BMP_H