Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
3.5 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (c) 1995 - 1997 Microsoft Corporation. All Rights Reserved.
  4. * Copyright (C) 1994-1995 ATI Technologies Inc. All Rights Reserved.
  5. *
  6. * File: bmp.c
  7. * Content: Bitmap reader
  8. *
  9. ***************************************************************************/
  10. #include "foxbear.h"
  11. /*
  12. * gfxLoadBitmap
  13. */
  14. GFX_HBM gfxLoadBitmap(LPSTR szFileName)
  15. {
  16. HFASTFILE pfile;
  17. BITMAPFILEHEADER UNALIGNED *pbf;
  18. BITMAPINFOHEADER UNALIGNED *pbi;
  19. GFX_HBM hbm;
  20. BOOL trans = FALSE;
  21. pfile = FastFileOpen( szFileName );
  22. if( pfile == NULL )
  23. {
  24. return NULL;
  25. }
  26. pbf = (BITMAPFILEHEADER *)FastFileLock(pfile, 0, 0);
  27. pbi = (BITMAPINFOHEADER *)(pbf+1);
  28. if (pbf->bfType != 0x4d42 ||
  29. pbi->biSize != sizeof(BITMAPINFOHEADER))
  30. {
  31. Msg("Failed to load");
  32. Msg(szFileName);
  33. FastFileClose( pfile );
  34. return NULL;
  35. }
  36. /*
  37. * TOTAL HACK for FoxBear, FoxBear does not use any masks, it draws
  38. * sprites with transparent colors, but the code still loads the masks
  39. * if a mask exists the sprite is transparent, else it is not, so
  40. * you cant get rid of the masks or nothing will be transparent!!
  41. *
  42. * if the code tries to load a mask, just return a non-zero value.
  43. */
  44. if( pbi->biBitCount == 1 )
  45. {
  46. Msg("some code is still using masks, stop that!");
  47. FastFileClose( pfile );
  48. return NULL;
  49. }
  50. /*
  51. * ANOTHER TOTAL HACK for FoxBear, some of the bitmaps in FoxBear
  52. * are a solid color, detect these and dont waste VRAM on them.
  53. */
  54. if( !bTransDest && pbi->biBitCount == 8 )
  55. {
  56. int x,y;
  57. BYTE c;
  58. BYTE UNALIGNED *pb = (LPBYTE)pbi + pbi->biSize + 256 * sizeof(COLORREF);
  59. RGBQUAD UNALIGNED *prgb = (RGBQUAD *)((LPBYTE)pbi + pbi->biSize);
  60. COLORREF rgb;
  61. c = *pb;
  62. for(y=0; y<(int)pbi->biHeight; y++ )
  63. {
  64. for( x=0; x<(int)pbi->biWidth; x++ )
  65. {
  66. if (c != *pb++)
  67. goto not_solid;
  68. }
  69. pb += ((pbi->biWidth + 3) & ~3) - pbi->biWidth;
  70. }
  71. rgb = RGB(prgb[c].rgbRed,prgb[c].rgbGreen,prgb[c].rgbBlue);
  72. hbm = gfxCreateSolidColorBitmap(rgb);
  73. FastFileClose( pfile );
  74. return hbm;
  75. }
  76. not_solid:
  77. /*
  78. * figure out iff the bitmap has the transparent color in it.
  79. */
  80. if( pbi->biBitCount == 8 )
  81. {
  82. int x,y;
  83. BYTE UNALIGNED *pb = (LPBYTE)pbi + pbi->biSize + 256 * sizeof(COLORREF);
  84. DWORD UNALIGNED *prgb = (DWORD *)((LPBYTE)pbi + pbi->biSize);
  85. for(y=0; y<(int)pbi->biHeight && !trans; y++ )
  86. {
  87. for( x=0; x<(int)pbi->biWidth && !trans; x++ )
  88. {
  89. if (prgb[*pb++] == 0x00FFFFFF)
  90. trans=TRUE;
  91. }
  92. pb += ((pbi->biWidth + 3) & ~3) - pbi->biWidth;
  93. }
  94. }
  95. hbm = gfxCreateVramBitmap(pbi, trans);
  96. if( hbm == NULL )
  97. {
  98. FastFileClose( pfile );
  99. return GFX_FALSE;
  100. }
  101. #if 0
  102. {
  103. DDSCAPS ddscaps;
  104. IDirectDrawSurface_GetCaps(((GFX_BITMAP *)hbm)->lpSurface, &ddscaps);
  105. if( !(ddscaps.dwCaps & DDSCAPS_VIDEOMEMORY) )
  106. {
  107. Msg( "%s is in system memory", szFileName );
  108. }
  109. }
  110. #endif
  111. FastFileClose( pfile );
  112. return hbm;
  113. } /* gfxLoadBitmap */