1 #include "burner.h"
2 #include "png.h"
3
ImageToBitmap(HWND hwnd,IMAGE * img)4 HBITMAP ImageToBitmap(HWND hwnd, IMAGE* img)
5 {
6 BITMAPINFO bi;
7
8 if (hwnd == NULL || img == NULL) {
9 return NULL;
10 }
11
12 bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
13 bi.bmiHeader.biWidth = img->width;
14 bi.bmiHeader.biHeight = img->height;
15 bi.bmiHeader.biPlanes = 1;
16 bi.bmiHeader.biBitCount = 24;
17 bi.bmiHeader.biCompression = BI_RGB;
18 bi.bmiHeader.biSizeImage = img->imgbytes;
19 bi.bmiHeader.biXPelsPerMeter = 0;
20 bi.bmiHeader.biYPelsPerMeter = 0;
21 bi.bmiHeader.biClrUsed = 0;
22 bi.bmiHeader.biClrImportant = 0;
23
24 HDC hDC = GetDC(hwnd);
25 BYTE* pbits = NULL;
26 HBITMAP hBitmap = CreateDIBSection(hDC, &bi, DIB_RGB_COLORS, (void**)&pbits, NULL, 0);
27 if (pbits) {
28 memcpy(pbits, img->bmpbits, img->imgbytes);
29 }
30 ReleaseDC(hwnd, hDC);
31 img_free(img);
32
33 return hBitmap;
34 }
35
PNGLoadBitmap(HWND hWnd,FILE * fp,int nWidth,int nHeight,int nPreset)36 HBITMAP PNGLoadBitmap(HWND hWnd, FILE* fp, int nWidth, int nHeight, int nPreset)
37 {
38 IMAGE img = { nWidth, nHeight, 0, 0, NULL, NULL, 0};
39
40 if (PNGLoad(&img, fp, nPreset)) {
41 return NULL;
42 }
43
44 return ImageToBitmap(hWnd, &img);
45 }
46
LoadBitmap(HWND hWnd,FILE * fp,int nWidth,int nHeight,int nPreset)47 HBITMAP LoadBitmap(HWND hWnd, FILE* fp, int nWidth, int nHeight, int nPreset)
48 {
49 if (hWnd == NULL || fp == NULL) {
50 return NULL;
51 }
52
53 if (PNGIsImage(fp)) return PNGLoadBitmap(hWnd, fp, nWidth, nHeight, nPreset);
54
55 return NULL;
56 }
57