ReactOS 0.4.15-dev-7958-gcd0bb1a
CImageDx Class Reference

#include <atlimagedx.h>

Classes

struct  SHARED
 

Public Member Functions

 CImageDx ()
 
 ~CImageDx ()
 
void Attach (HBITMAP hbm)
 
HBITMAP Detach ()
 
BOOL GetResolution (Gdiplus::GpImage *pImage, float *pxDpi, float *pyDpi)
 
BOOL SetResolution (Gdiplus::GpBitmap *pBitmap, float xDpi, float yDpi)
 
HRESULT LoadDx (LPCWSTR pszFileName, float *pxDpi, float *pyDpi) throw ()
 
HRESULT SaveDx (LPCWSTR pszFileName, REFGUID guidFileType=GUID_NULL, float xDpi=0, float yDpi=0) throw ()
 

Static Public Member Functions

static BOOL IsExtensionSupported (PWCHAR pchDotExt)
 

Protected Types

using FN_Startup = decltype(&Gdiplus::GdiplusStartup)
 
using FN_Shutdown = decltype(&Gdiplus::GdiplusShutdown)
 
using FN_GetImageHorizontalResolution = decltype(&GPDE::GdipGetImageHorizontalResolution)
 
using FN_GetImageVerticalResolution = decltype(&GPDE::GdipGetImageVerticalResolution)
 
using FN_BitmapSetResolution = decltype(&GPDE::GdipBitmapSetResolution)
 
using FN_CreateBitmapFromHBITMAP = decltype(&GPDE::GdipCreateBitmapFromHBITMAP)
 
using FN_CreateBitmapFromFile = decltype(&GPDE::GdipCreateBitmapFromFile)
 
using FN_CreateHBITMAPFromBitmap = decltype(&GPDE::GdipCreateHBITMAPFromBitmap)
 
using FN_SaveImageToFile = decltype(&GPDE::GdipSaveImageToFile)
 
using FN_DisposeImage = decltype(&GPDE::GdipDisposeImage)
 
using FN_GetImageEncodersSize = decltype(&GPDE::GdipGetImageEncodersSize)
 
using FN_GetImageEncoders = decltype(&GPDE::GdipGetImageEncoders)
 

Static Protected Member Functions

static SHARED_shared ()
 
static Gdiplus::ImageCodecInfo * GetAllEncoders (UINT &cEncoders)
 
template<typename FN_T >
static bool get_fn (FN_T &fn, const char *name)
 
static CLSID FindCodecForExtension (LPCWSTR dotext, const Gdiplus::ImageCodecInfo *pCodecs, UINT nCodecs)
 
static CLSID FindCodecForFileType (REFGUID guidFileType, const Gdiplus::ImageCodecInfo *pCodecs, UINT nCodecs)
 

Protected Attributes

HBITMAP m_hBitmap = NULL
 

Detailed Description

Definition at line 14 of file atlimagedx.h.

Member Typedef Documentation

◆ FN_BitmapSetResolution

using CImageDx::FN_BitmapSetResolution = decltype(&GPDE::GdipBitmapSetResolution)
protected

Definition at line 185 of file atlimagedx.h.

◆ FN_CreateBitmapFromFile

using CImageDx::FN_CreateBitmapFromFile = decltype(&GPDE::GdipCreateBitmapFromFile)
protected

Definition at line 187 of file atlimagedx.h.

◆ FN_CreateBitmapFromHBITMAP

using CImageDx::FN_CreateBitmapFromHBITMAP = decltype(&GPDE::GdipCreateBitmapFromHBITMAP)
protected

Definition at line 186 of file atlimagedx.h.

◆ FN_CreateHBITMAPFromBitmap

using CImageDx::FN_CreateHBITMAPFromBitmap = decltype(&GPDE::GdipCreateHBITMAPFromBitmap)
protected

Definition at line 188 of file atlimagedx.h.

◆ FN_DisposeImage

using CImageDx::FN_DisposeImage = decltype(&GPDE::GdipDisposeImage)
protected

Definition at line 190 of file atlimagedx.h.

◆ FN_GetImageEncoders

using CImageDx::FN_GetImageEncoders = decltype(&GPDE::GdipGetImageEncoders)
protected

Definition at line 192 of file atlimagedx.h.

◆ FN_GetImageEncodersSize

using CImageDx::FN_GetImageEncodersSize = decltype(&GPDE::GdipGetImageEncodersSize)
protected

Definition at line 191 of file atlimagedx.h.

◆ FN_GetImageHorizontalResolution

using CImageDx::FN_GetImageHorizontalResolution = decltype(&GPDE::GdipGetImageHorizontalResolution)
protected

Definition at line 183 of file atlimagedx.h.

◆ FN_GetImageVerticalResolution

using CImageDx::FN_GetImageVerticalResolution = decltype(&GPDE::GdipGetImageVerticalResolution)
protected

Definition at line 184 of file atlimagedx.h.

◆ FN_SaveImageToFile

using CImageDx::FN_SaveImageToFile = decltype(&GPDE::GdipSaveImageToFile)
protected

Definition at line 189 of file atlimagedx.h.

◆ FN_Shutdown

using CImageDx::FN_Shutdown = decltype(&Gdiplus::GdiplusShutdown)
protected

Definition at line 182 of file atlimagedx.h.

◆ FN_Startup

using CImageDx::FN_Startup = decltype(&Gdiplus::GdiplusStartup)
protected

Definition at line 181 of file atlimagedx.h.

Constructor & Destructor Documentation

◆ CImageDx()

CImageDx::CImageDx ( )
inline

Definition at line 20 of file atlimagedx.h.

21 {
22 _shared()->AddRef();
23 }
static SHARED * _shared()
Definition: atlimagedx.h:257

◆ ~CImageDx()

CImageDx::~CImageDx ( )
inline

Definition at line 25 of file atlimagedx.h.

26 {
27 if (m_hBitmap)
29
30 _shared()->Release();
31 }
HBITMAP m_hBitmap
Definition: atlimagedx.h:17
pKey DeleteObject()

Member Function Documentation

◆ _shared()

static SHARED * CImageDx::_shared ( )
inlinestaticprotected

Definition at line 257 of file atlimagedx.h.

258 {
259 static SHARED s_shared;
260 return &s_shared;
261 }

Referenced by CImageDx(), get_fn(), GetAllEncoders(), GetResolution(), IsExtensionSupported(), LoadDx(), SaveDx(), SetResolution(), and ~CImageDx().

◆ Attach()

void CImageDx::Attach ( HBITMAP  hbm)
inline

Definition at line 33 of file atlimagedx.h.

34 {
35 if (m_hBitmap)
37 m_hBitmap = hbm;
38 }
_In_ HBITMAP hbm
Definition: ntgdi.h:2776

Referenced by LoadDx().

◆ Detach()

HBITMAP CImageDx::Detach ( )
inline

Definition at line 40 of file atlimagedx.h.

41 {
42 HBITMAP hbmOld = m_hBitmap;
44 return hbmOld;
45 }
#define NULL
Definition: types.h:112
static HBITMAP
Definition: button.c:44

◆ FindCodecForExtension()

static CLSID CImageDx::FindCodecForExtension ( LPCWSTR  dotext,
const Gdiplus::ImageCodecInfo *  pCodecs,
UINT  nCodecs 
)
inlinestaticprotected

Definition at line 303 of file atlimagedx.h.

304 {
305 for (UINT i = 0; i < nCodecs; ++i)
306 {
307 CStringW strSpecs(pCodecs[i].FilenameExtension);
308 int ichOld = 0, ichSep;
309 for (;;)
310 {
311 ichSep = strSpecs.Find(L';', ichOld);
312
313 CStringW strSpec;
314 if (ichSep < 0)
315 strSpec = strSpecs.Mid(ichOld);
316 else
317 strSpec = strSpecs.Mid(ichOld, ichSep - ichOld);
318
319 int ichDot = strSpec.ReverseFind(L'.');
320 if (ichDot >= 0)
321 strSpec = strSpec.Mid(ichDot);
322
323 if (!dotext || strSpec.CompareNoCase(dotext) == 0)
324 return pCodecs[i].Clsid;
325
326 if (ichSep < 0)
327 break;
328
329 ichOld = ichSep + 1;
330 }
331 }
332 return CLSID_NULL;
333 }
int CompareNoCase(_In_z_ PCXSTR psz) const
Definition: cstringt.h:743
CStringT Mid(int iFirst, int nCount) const
Definition: cstringt.h:748
int ReverseFind(_In_ XCHAR ch) const noexcept
Definition: cstringt.h:730
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
#define CLSID_NULL
Definition: guiddef.h:99

Referenced by IsExtensionSupported(), and SaveDx().

◆ FindCodecForFileType()

static CLSID CImageDx::FindCodecForFileType ( REFGUID  guidFileType,
const Gdiplus::ImageCodecInfo *  pCodecs,
UINT  nCodecs 
)
inlinestaticprotected

Definition at line 337 of file atlimagedx.h.

338 {
339 for (UINT iInfo = 0; iInfo < nCodecs; ++iInfo)
340 {
341 if (::IsEqualGUID(pCodecs[iInfo].FormatID, guidFileType))
342 return pCodecs[iInfo].Clsid;
343 }
344 return CLSID_NULL;
345 }
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147

Referenced by SaveDx().

◆ get_fn()

template<typename FN_T >
static bool CImageDx::get_fn ( FN_T &  fn,
const char name 
)
inlinestaticprotected

Definition at line 292 of file atlimagedx.h.

293 {
294 if (fn)
295 return true;
296 HINSTANCE hGdiPlus = _shared()->Init();
297 fn = reinterpret_cast<FN_T>(::GetProcAddress(hGdiPlus, name));
298 return fn != NULL;
299 }
#define GetProcAddress(x, y)
Definition: compat.h:753
HINSTANCE Init()
Definition: atlimagedx.h:211
Definition: name.c:39
static GLenum _GLUfuncptr fn
Definition: wgl_font.c:159

Referenced by GetAllEncoders(), GetResolution(), LoadDx(), SaveDx(), and SetResolution().

◆ GetAllEncoders()

static Gdiplus::ImageCodecInfo * CImageDx::GetAllEncoders ( UINT cEncoders)
inlinestaticprotected

Definition at line 263 of file atlimagedx.h.

264 {
265 Gdiplus::ImageCodecInfo *ret = NULL;
266 UINT total_size;
267
268 if (!get_fn(_shared()->m_GetImageEncodersSize, "GdipGetImageEncodersSize") ||
269 !get_fn(_shared()->m_GetImageEncoders, "GdipGetImageEncoders"))
270 {
271 cEncoders = 0;
272 return NULL;
273 }
274
275 _shared()->m_GetImageEncodersSize(&cEncoders, &total_size);
276 if (total_size == 0)
277 return NULL;
278
279 ret = new Gdiplus::ImageCodecInfo[total_size / sizeof(ret[0])];
280 if (ret == NULL)
281 {
282 cEncoders = 0;
283 return NULL;
284 }
285
286 _shared()->m_GetImageEncoders(cEncoders, total_size, ret);
287
288 return ret; // needs delete[]
289 }
static bool get_fn(FN_T &fn, const char *name)
Definition: atlimagedx.h:292
FN_GetImageEncoders m_GetImageEncoders
Definition: atlimagedx.h:209
FN_GetImageEncodersSize m_GetImageEncodersSize
Definition: atlimagedx.h:208
int ret

Referenced by IsExtensionSupported(), and SaveDx().

◆ GetResolution()

BOOL CImageDx::GetResolution ( Gdiplus::GpImage *  pImage,
float pxDpi,
float pyDpi 
)
inline

Definition at line 47 of file atlimagedx.h.

48 {
49 if (!get_fn(_shared()->m_GetImageHorizontalResolution, "GdipGetImageHorizontalResolution") ||
50 !get_fn(_shared()->m_GetImageVerticalResolution, "GdipGetImageVerticalResolution"))
51 {
52 return FALSE;
53 }
54
55 if (pxDpi)
57 if (pyDpi)
58 _shared()->m_GetImageVerticalResolution(pImage, pyDpi);
59
60 return TRUE;
61 }
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
FN_GetImageHorizontalResolution m_GetImageHorizontalResolution
Definition: atlimagedx.h:200
FN_GetImageVerticalResolution m_GetImageVerticalResolution
Definition: atlimagedx.h:201

Referenced by LoadDx().

◆ IsExtensionSupported()

static BOOL CImageDx::IsExtensionSupported ( PWCHAR  pchDotExt)
inlinestatic

Definition at line 165 of file atlimagedx.h.

166 {
167 _shared()->AddRef();
168
169 UINT cEncoders;
170 Gdiplus::ImageCodecInfo* pEncoders = GetAllEncoders(cEncoders);
171
172 CLSID clsid = FindCodecForExtension(pchDotExt, pEncoders, cEncoders);
174 delete[] pEncoders;
175
176 _shared()->Release();
177 return ret;
178 }
static Gdiplus::ImageCodecInfo * GetAllEncoders(UINT &cEncoders)
Definition: atlimagedx.h:263
static CLSID FindCodecForExtension(LPCWSTR dotext, const Gdiplus::ImageCodecInfo *pCodecs, UINT nCodecs)
Definition: atlimagedx.h:303
unsigned int BOOL
Definition: ntddk_ex.h:94
REFCLSID clsid
Definition: msctf.c:82

Referenced by CMainWindow::saveImage().

◆ LoadDx()

HRESULT CImageDx::LoadDx ( LPCWSTR  pszFileName,
float pxDpi,
float pyDpi 
)
throw (
)
inline

Definition at line 72 of file atlimagedx.h.

73 {
74 using namespace Gdiplus;
75
76 _shared()->AddRef();
77
78 if (!get_fn(_shared()->m_CreateBitmapFromFile, "GdipCreateBitmapFromFile") ||
79 !get_fn(_shared()->m_CreateHBITMAPFromBitmap, "GdipCreateHBITMAPFromBitmap") ||
80 !get_fn(_shared()->m_DisposeImage, "GdipDisposeImage"))
81 {
82 _shared()->Release();
83 return E_FAIL;
84 }
85
86 // create a GpBitmap object from file
87 GpBitmap *pBitmap = NULL;
88 if (_shared()->m_CreateBitmapFromFile(pszFileName, &pBitmap) != Ok)
89 {
90 _shared()->Release();
91 return E_FAIL;
92 }
93
94 // get an HBITMAP
96 Color color(0xFF, 0xFF, 0xFF);
97 Status status = _shared()->m_CreateHBITMAPFromBitmap(pBitmap, &hbm, color.GetValue());
98
99 // get the resolution
100 if (pxDpi || pyDpi)
101 GetResolution((GpImage*)pBitmap, pxDpi, pyDpi);
102
103 // delete GpBitmap
104 _shared()->m_DisposeImage(pBitmap);
105
106 // attach it
107 if (status == Ok)
108 Attach(hbm);
109
110 _shared()->Release();
111 return (status == Ok ? S_OK : E_FAIL);
112 }
BOOL GetResolution(Gdiplus::GpImage *pImage, float *pxDpi, float *pyDpi)
Definition: atlimagedx.h:47
void Attach(HBITMAP hbm)
Definition: atlimagedx.h:33
#define E_FAIL
Definition: ddrawi.h:102
Status
Definition: gdiplustypes.h:25
@ Ok
Definition: gdiplustypes.h:26
GLuint color
Definition: glext.h:6243
#define S_OK
Definition: intsafe.h:52
FN_DisposeImage m_DisposeImage
Definition: atlimagedx.h:207
FN_CreateHBITMAPFromBitmap m_CreateHBITMAPFromBitmap
Definition: atlimagedx.h:205
Definition: ps.c:97
WORD WORD PSZ PSZ pszFileName
Definition: vdmdbg.h:44

◆ SaveDx()

HRESULT CImageDx::SaveDx ( LPCWSTR  pszFileName,
REFGUID  guidFileType = GUID_NULL,
float  xDpi = 0,
float  yDpi = 0 
)
throw (
)
inline

Definition at line 114 of file atlimagedx.h.

116 {
117 using namespace Gdiplus;
118
119 _shared()->AddRef();
120
121 if (!get_fn(_shared()->m_CreateBitmapFromHBITMAP, "GdipCreateBitmapFromHBITMAP") ||
122 !get_fn(_shared()->m_SaveImageToFile, "GdipSaveImageToFile") ||
123 !get_fn(_shared()->m_DisposeImage, "GdipDisposeImage"))
124 {
125 _shared()->Release();
126 return E_FAIL;
127 }
128
129 // create a GpBitmap from HBITMAP
130 GpBitmap *pBitmap = NULL;
132
133 // set the resolution
134 SetResolution(pBitmap, xDpi, yDpi);
135
136 // Get encoders
137 UINT cEncoders = 0;
138 ImageCodecInfo* pEncoders = GetAllEncoders(cEncoders);
139
140 // if the file type is null, get the file type from extension
141 CLSID clsid;
142 if (::IsEqualGUID(guidFileType, GUID_NULL))
143 {
145 clsid = FindCodecForExtension(strExt, pEncoders, cEncoders);
146 }
147 else
148 {
149 clsid = FindCodecForFileType(guidFileType, pEncoders, cEncoders);
150 }
151
152 delete[] pEncoders;
153
154 // save to file
156
157 // destroy GpBitmap
158 _shared()->m_DisposeImage(pBitmap);
159
160 _shared()->Release();
161
162 return (status == Ok ? S_OK : E_FAIL);
163 }
static CLSID FindCodecForFileType(REFGUID guidFileType, const Gdiplus::ImageCodecInfo *pCodecs, UINT nCodecs)
Definition: atlimagedx.h:337
LPWSTR WINAPI PathFindExtensionW(LPCWSTR lpszPath)
Definition: path.c:447
#define GUID_NULL
Definition: ks.h:106
FN_CreateBitmapFromHBITMAP m_CreateBitmapFromHBITMAP
Definition: atlimagedx.h:203
FN_SaveImageToFile m_SaveImageToFile
Definition: atlimagedx.h:206
_In_ BOOLEAN SetResolution
Definition: exfuncs.h:1078

◆ SetResolution()

BOOL CImageDx::SetResolution ( Gdiplus::GpBitmap *  pBitmap,
float  xDpi,
float  yDpi 
)
inline

Definition at line 63 of file atlimagedx.h.

64 {
65 if (!get_fn(_shared()->m_BitmapSetResolution, "GdipBitmapSetResolution"))
66 return FALSE;
67
68 _shared()->m_BitmapSetResolution(pBitmap, xDpi, yDpi);
69 return TRUE;
70 }
FN_BitmapSetResolution m_BitmapSetResolution
Definition: atlimagedx.h:202

Member Data Documentation

◆ m_hBitmap

HBITMAP CImageDx::m_hBitmap = NULL
protected

Definition at line 17 of file atlimagedx.h.

Referenced by Attach(), Detach(), SaveDx(), and ~CImageDx().


The documentation for this class was generated from the following file: