source: trunk/gsinstaller/bmpUtil.cpp@ 2013

Last change on this file since 2013 was 1397, checked in by cs025, 24 years ago

Initial revision

  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
Line 
1#include "bmpUtil.h"
2
3#include <stdio.h>
4#include <mem.h>
5#include <stdlib.h>
6
7HPALETTE bmpUtil_getDIBPalette(LPBITMAPINFO bmpInfo, unsigned int colours)
8{ LPBITMAPINFOHEADER bmpHeader;
9 LPLOGPALETTE logicalPalette;
10 HPALETTE reply = 0;
11
12 bmpHeader = (LPBITMAPINFOHEADER) bmpInfo;
13 MessageBox(0, "A", "A", MB_OK);
14
15 if (colours)
16 {
17 MessageBox(0, "A", "A", MB_OK);
18 logicalPalette = (LPLOGPALETTE) GlobalAlloc(GMEM_FIXED, sizeof (LOGPALETTE) + sizeof(PALETTEENTRY) * (colours));
19 if (logicalPalette == NULL)
20 { return reply;
21 }
22
23 logicalPalette->palVersion = 0x300;
24 logicalPalette->palNumEntries = colours;
25 MessageBox(0, "A", "A", MB_OK);
26 for (int i = 0; i < colours; i ++)
27 { logicalPalette->palPalEntry[i].peRed = bmpInfo->bmiColors[i].rgbRed;
28 logicalPalette->palPalEntry[i].peGreen = bmpInfo->bmiColors[i].rgbGreen;
29 logicalPalette->palPalEntry[i].peBlue = bmpInfo->bmiColors[i].rgbBlue;
30 logicalPalette->palPalEntry[i].peFlags = 0;
31 }
32 reply = CreatePalette(logicalPalette);
33 GlobalFree((HGLOBAL) logicalPalette);
34 }
35 return reply;
36}
37
38HBITMAP _export bmpUtil_loadBitmap(HDC device, char *filename)
39{ BYTE dummy[2];
40 BITMAPINFO bitmapInfo;
41 OFSTRUCT of;
42
43 HFILE file;
44 BITMAPFILEHEADER fileHeader;
45 LPRGBQUAD colours;
46 LPBITMAPINFO bitmapData;
47 LPBYTE image;
48 unsigned int colourCount;
49 HBITMAP reply;
50 char buffer[40];
51
52 file = OpenFile(filename, &of, OF_READ);
53 if (!file)
54 { return NULL;
55 }
56
57 if (!_lread(file, &fileHeader, sizeof(BITMAPFILEHEADER)))
58 { MessageBox(0, "M1", "M", MB_OK);
59 }
60 if (!_lread(file, &bitmapInfo.bmiHeader, 40))
61 { MessageBox(0, "M2", "M", MB_OK);
62 }
63
64 colourCount = 1 << bitmapInfo.bmiHeader.biBitCount;
65 bitmapData = (BITMAPINFO *) GlobalAlloc(GMEM_FIXED, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * colourCount);
66 if (!bitmapData)
67 { MessageBox(0, "M3", "M", MB_OK);
68 }
69
70 bitmapData->bmiHeader = bitmapInfo.bmiHeader;
71
72 colours = (RGBQUAD *) &bitmapData->bmiColors;
73 if (_lread(file, colours, sizeof(RGBQUAD) * colourCount) < colourCount)
74 { MessageBox(0, "M4", "M", MB_OK);
75 }
76
77 image = (BYTE FAR *) GlobalAlloc(GMEM_FIXED, sizeof(BYTE) * bitmapData->bmiHeader.biSizeImage);
78 if (!image)
79 { MessageBox(0, "M5", "M", MB_OK);
80 }
81 if (_lread(file, image, sizeof(BYTE) * bitmapData->bmiHeader.biSizeImage) < bitmapData->bmiHeader.biSizeImage)
82 { MessageBox(0, "M", "M6", MB_OK);
83 }
84
85 HPALETTE pal = bmpUtil_getDIBPalette(bitmapData, colourCount);
86 sprintf(buffer, "%d", (int) pal);
87 MessageBox(0, buffer, "M0", MB_OK);
88
89 reply = CreateCompatibleBitmap (device, 501, 228);
90 sprintf(buffer, "%d", reply);
91 MessageBox(0, buffer, "M1", MB_OK);
92 if (reply != NULL)
93 { int r = SetDIBits(device, reply, 0, bitmapData->bmiHeader.biHeight, image, bitmapData, DIB_RGB_COLORS);
94 sprintf(buffer, "%d", r);
95 MessageBox(0, buffer, "M2", MB_OK);
96 DeleteObject(reply);
97 }
98
99 reply = CreateDIBitmap( device, &bitmapData->bmiHeader, CBM_INIT, image, bitmapData, DIB_RGB_COLORS);
100 sprintf(buffer, "%d", reply);
101 MessageBox(0, buffer, "M", MB_OK);
102 GlobalFree((HLOCAL) bitmapData);
103 GlobalFree((HLOCAL) image);
104 _lclose(file);
105 return reply;
106}
Note: See TracBrowser for help on using the repository browser.