@@ -2780,75 +2780,77 @@ void W3DDisplay::setShroudLevel( Int x, Int y, CellShroudStatus setting )
2780
2780
// =============================================================================
2781
2781
// /Utility function to dump data into a .BMP file
2782
2782
static void CreateBMPFile (LPTSTR pszFile, char *image, Int width, Int height)
2783
- {
2784
- HANDLE hf; // file handle
2785
- BITMAPFILEHEADER hdr; // bitmap file-header
2786
- PBITMAPINFOHEADER pbih; // bitmap info-header
2787
- LPBYTE lpBits; // memory pointer
2788
- DWORD dwTotal; // total count of bytes
2789
- DWORD cb; // incremental count of bytes
2790
- BYTE *hp; // byte pointer
2791
- DWORD dwTmp;
2792
-
2793
- PBITMAPINFO pbmi;
2794
-
2795
- pbmi = (PBITMAPINFO) LocalAlloc (LPTR,sizeof (BITMAPINFOHEADER));
2796
- pbmi->bmiHeader .biSize = sizeof (BITMAPINFOHEADER);
2797
- pbmi->bmiHeader .biWidth = width;
2798
- pbmi->bmiHeader .biHeight = height;
2799
- pbmi->bmiHeader .biPlanes = 1 ;
2800
- pbmi->bmiHeader .biBitCount = 24 ;
2801
- pbmi->bmiHeader .biCompression = BI_RGB;
2802
- pbmi->bmiHeader .biSizeImage = (pbmi->bmiHeader .biWidth + 7 ) /8 * pbmi->bmiHeader .biHeight * 24 ;
2803
- pbmi->bmiHeader .biClrImportant = 0 ;
2804
-
2805
-
2806
- pbih = (PBITMAPINFOHEADER) pbmi;
2807
- lpBits = (LPBYTE) image;
2808
-
2809
- // Create the .BMP file.
2810
- hf = CreateFile (pszFile,
2811
- GENERIC_READ | GENERIC_WRITE,
2812
- (DWORD) 0 ,
2813
- NULL ,
2814
- CREATE_ALWAYS,
2815
- FILE_ATTRIBUTE_NORMAL,
2816
- (HANDLE) NULL );
2817
- if (hf == INVALID_HANDLE_VALUE)
2818
- return ;
2819
- hdr.bfType = 0x4d42 ; // 0x42 = "B" 0x4d = "M"
2820
- // Compute the size of the entire file.
2821
- hdr.bfSize = (DWORD) (sizeof (BITMAPFILEHEADER) +
2822
- pbih->biSize + pbih->biClrUsed
2823
- * sizeof (RGBQUAD) + pbih->biSizeImage );
2824
- hdr.bfReserved1 = 0 ;
2825
- hdr.bfReserved2 = 0 ;
2826
-
2827
- // Compute the offset to the array of color indices.
2828
- hdr.bfOffBits = (DWORD) sizeof (BITMAPFILEHEADER) +
2829
- pbih->biSize + pbih->biClrUsed
2830
- * sizeof (RGBQUAD);
2831
-
2832
- // Copy the BITMAPFILEHEADER into the .BMP file.
2833
- if (!WriteFile (hf, (LPVOID) &hdr, sizeof (BITMAPFILEHEADER),
2834
- (LPDWORD) &dwTmp, NULL ))
2835
- return ;
2836
-
2837
- // Copy the BITMAPINFOHEADER and RGBQUAD array into the file.
2838
- if (!WriteFile (hf, (LPVOID) pbih, sizeof (BITMAPINFOHEADER) + pbih->biClrUsed * sizeof (RGBQUAD),(LPDWORD) &dwTmp, NULL ))
2783
+ {
2784
+ HANDLE hf; // file handle
2785
+ BITMAPFILEHEADER hdr; // bitmap file-header
2786
+ PBITMAPINFOHEADER pbih; // bitmap info-header
2787
+ LPBYTE lpBits; // memory pointer
2788
+ DWORD dwTotal; // total count of bytes
2789
+ DWORD cb; // incremental count of bytes
2790
+ BYTE *hp; // byte pointer
2791
+ DWORD dwTmp;
2792
+
2793
+ PBITMAPINFO pbmi;
2794
+
2795
+ pbmi = (PBITMAPINFO) LocalAlloc (LPTR,sizeof (BITMAPINFOHEADER));
2796
+ if (pbmi == NULL )
2839
2797
return ;
2840
2798
2841
- // Copy the array of color indices into the .BMP file.
2842
- dwTotal = cb = pbih->biSizeImage ;
2843
- hp = lpBits;
2844
- if (!WriteFile (hf, (LPSTR) hp, (int ) cb, (LPDWORD) &dwTmp,NULL ))
2845
- return ;
2799
+ pbmi->bmiHeader .biSize = sizeof (BITMAPINFOHEADER);
2800
+ pbmi->bmiHeader .biWidth = width;
2801
+ pbmi->bmiHeader .biHeight = height;
2802
+ pbmi->bmiHeader .biPlanes = 1 ;
2803
+ pbmi->bmiHeader .biBitCount = 24 ;
2804
+ pbmi->bmiHeader .biCompression = BI_RGB;
2805
+ pbmi->bmiHeader .biSizeImage = (pbmi->bmiHeader .biWidth + 7 ) /8 * pbmi->bmiHeader .biHeight * 24 ;
2806
+ pbmi->bmiHeader .biClrImportant = 0 ;
2807
+
2808
+ pbih = (PBITMAPINFOHEADER) pbmi;
2809
+ lpBits = (LPBYTE) image;
2810
+
2811
+ // Create the .BMP file.
2812
+ hf = CreateFile (pszFile,
2813
+ GENERIC_READ | GENERIC_WRITE,
2814
+ (DWORD) 0 ,
2815
+ NULL ,
2816
+ CREATE_ALWAYS,
2817
+ FILE_ATTRIBUTE_NORMAL,
2818
+ (HANDLE) NULL );
2819
+
2820
+ if (hf != INVALID_HANDLE_VALUE)
2821
+ {
2822
+ hdr.bfType = 0x4d42 ; // 0x42 = "B" 0x4d = "M"
2823
+ // Compute the size of the entire file.
2824
+ hdr.bfSize = (DWORD) (sizeof (BITMAPFILEHEADER) +
2825
+ pbih->biSize + pbih->biClrUsed
2826
+ * sizeof (RGBQUAD) + pbih->biSizeImage );
2827
+ hdr.bfReserved1 = 0 ;
2828
+ hdr.bfReserved2 = 0 ;
2829
+
2830
+ // Compute the offset to the array of color indices.
2831
+ hdr.bfOffBits = (DWORD) sizeof (BITMAPFILEHEADER) +
2832
+ pbih->biSize + pbih->biClrUsed
2833
+ * sizeof (RGBQUAD);
2834
+
2835
+ // Copy the BITMAPFILEHEADER into the .BMP file.
2836
+ if (WriteFile (hf, (LPVOID) &hdr, sizeof (BITMAPFILEHEADER),
2837
+ (LPDWORD) &dwTmp, NULL ))
2838
+ {
2839
+ // Copy the BITMAPINFOHEADER and RGBQUAD array into the file.
2840
+ if (WriteFile (hf, (LPVOID) pbih, sizeof (BITMAPINFOHEADER) + pbih->biClrUsed * sizeof (RGBQUAD),(LPDWORD) &dwTmp, NULL ))
2841
+ {
2842
+ // Copy the array of color indices into the .BMP file.
2843
+ dwTotal = cb = pbih->biSizeImage ;
2844
+ hp = lpBits;
2845
+ WriteFile (hf, (LPSTR) hp, (int ) cb, (LPDWORD) &dwTmp, NULL );
2846
+ }
2847
+ }
2846
2848
2847
- // Close the .BMP file.
2848
- if (! CloseHandle (hf))
2849
- return ;
2849
+ // Close the .BMP file.
2850
+ CloseHandle (hf);
2851
+ }
2850
2852
2851
- // Free memory.
2853
+ // Free memory.
2852
2854
LocalFree ( (HLOCAL) pbmi);
2853
2855
}
2854
2856
0 commit comments