ReactOS 0.4.15-dev-7998-gdb93cb1
pngsup.cpp File Reference
#include "uxthemep.h"
#include <ole2.h>
#include <objidl.h>
#include <gdiplus.h>
#include <gdipluscolor.h>
#include <winreg.h>
#include <shlwapi.h>
Include dependency graph for pngsup.cpp:

Go to the source code of this file.

Functions

BOOL MSSTYLES_TryLoadPng (_In_ HINSTANCE hTheme, _In_ LPCWSTR szFile, _In_ LPCWSTR type, _Out_ HBITMAP *phBitmap)
 
BOOL prepare_png_alpha (_In_ HBITMAP png, _Out_ BOOL *hasAlpha)
 

Function Documentation

◆ MSSTYLES_TryLoadPng()

BOOL MSSTYLES_TryLoadPng ( _In_ HINSTANCE  hTheme,
_In_ LPCWSTR  szFile,
_In_ LPCWSTR  type,
_Out_ HBITMAP phBitmap 
)

Definition at line 18 of file pngsup.cpp.

23{
24 BOOL ret = FALSE;
25
26 HRSRC hRes = FindResourceW(hTheme, szFile, type);
27 if (!hRes)
28 return FALSE;
29
30 HGLOBAL hAlloc = LoadResource(hTheme, hRes);
31 if (!hAlloc)
32 return FALSE;
33
34 DWORD dwSize = SizeofResource(hTheme, hRes);
35 LPVOID pData = LockResource(hAlloc);
36 if ((!pData) || (dwSize <= 0))
37 {
38 FreeResource(hAlloc);
39 return FALSE;
40 }
41
43 if (stream)
44 {
45 Gdiplus::Bitmap* gdipBitmap = Gdiplus::Bitmap::FromStream(stream, FALSE);
46 stream->Release();
47 if (gdipBitmap)
48 {
49 ret = gdipBitmap->GetHBITMAP(Gdiplus::Color(0, 0, 0, 0), phBitmap) == Gdiplus::Ok;
50 delete gdipBitmap;
51 }
52 }
53
55 FreeResource(hAlloc);
56 return ret;
57}
#define FALSE
Definition: types.h:117
BOOL WINAPI FreeResource(HGLOBAL handle)
Definition: res.c:559
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
IStream *WINAPI SHCreateMemStream(const BYTE *lpbData, UINT dwDataLen)
Definition: regstream.c:652
Definition: parse.h:23
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830
int ret
#define UnlockResource(handle)
Definition: winbase.h:3372
unsigned char BYTE
Definition: xxhash.c:193

Referenced by MSSTYLES_LoadBitmap().

◆ prepare_png_alpha()

BOOL prepare_png_alpha ( _In_ HBITMAP  png,
_Out_ BOOL hasAlpha 
)

Definition at line 60 of file pngsup.cpp.

63{
65 int n;
66 BYTE* p;
67
68 *hasAlpha = FALSE;
69
70 if (!png || GetObjectW( png, sizeof(dib), &dib ) != sizeof(dib))
71 return FALSE;
72
73 if (dib.dsBm.bmBitsPixel != 32)
74 /* nothing to do */
75 return TRUE;
76
77 p = (BYTE*)dib.dsBm.bmBits;
78 n = dib.dsBmih.biHeight * dib.dsBmih.biWidth;
79 while (n-- > 0)
80 {
81 int a = p[3] + 1;
82 if (a < 256)
83 {
84 p[0] = MulDiv(p[0], 256, a);
85 p[1] = MulDiv(p[1], 256, a);
86 p[2] = MulDiv(p[2], 256, a);
87
88 *hasAlpha = TRUE;
89 }
90 p += 4;
91 }
92
93 return TRUE;
94}
while(CdLookupNextInitialFileDirent(IrpContext, Fcb, FileContext))
#define TRUE
Definition: types.h:120
GLdouble n
Definition: glext.h:7729
GLfloat GLfloat p
Definition: glext.h:8902
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
static const BYTE dib[]
Definition: ole2.c:201
INT WINAPI MulDiv(INT nNumber, INT nNumerator, INT nDenominator)
Definition: muldiv.c:25
int WINAPI GetObjectW(_In_ HANDLE h, _In_ int c, _Out_writes_bytes_opt_(c) LPVOID pv)

Referenced by MSSTYLES_LoadBitmap().