2 * Copyright 2012 Vincent Povirk for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wincodecs_private.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs
);
36 /* WARNING: .NET Media Integration Layer (MIL) directly dereferences
37 * BitmapImpl members and depends on its exact layout.
39 typedef struct BitmapImpl
{
40 IMILUnknown1 IMILUnknown1_iface
;
42 IMILBitmapSource IMILBitmapSource_iface
;
43 IWICBitmap IWICBitmap_iface
;
44 IMILUnknown2 IMILUnknown2_iface
;
47 LONG lock
; /* 0 if not locked, -1 if locked for writing, count if locked for reading */
52 WICPixelFormatGUID pixelformat
;
57 typedef struct BitmapLockImpl
{
58 IWICBitmapLock IWICBitmapLock_iface
;
65 static inline BitmapImpl
*impl_from_IWICBitmap(IWICBitmap
*iface
)
67 return CONTAINING_RECORD(iface
, BitmapImpl
, IWICBitmap_iface
);
70 static inline BitmapImpl
*impl_from_IMILBitmapSource(IMILBitmapSource
*iface
)
72 return CONTAINING_RECORD(iface
, BitmapImpl
, IMILBitmapSource_iface
);
75 static inline BitmapImpl
*impl_from_IMILUnknown1(IMILUnknown1
*iface
)
77 return CONTAINING_RECORD(iface
, BitmapImpl
, IMILUnknown1_iface
);
80 static inline BitmapImpl
*impl_from_IMILUnknown2(IMILUnknown2
*iface
)
82 return CONTAINING_RECORD(iface
, BitmapImpl
, IMILUnknown2_iface
);
85 static inline BitmapLockImpl
*impl_from_IWICBitmapLock(IWICBitmapLock
*iface
)
87 return CONTAINING_RECORD(iface
, BitmapLockImpl
, IWICBitmapLock_iface
);
90 static BOOL
BitmapImpl_AcquireLock(BitmapImpl
*This
, int write
)
94 return 0 == InterlockedCompareExchange(&This
->lock
, -1, 0);
100 LONG prev_val
= This
->lock
;
103 if (prev_val
== InterlockedCompareExchange(&This
->lock
, prev_val
+1, prev_val
))
109 static void BitmapImpl_ReleaseLock(BitmapImpl
*This
)
113 LONG prev_val
= This
->lock
, new_val
;
117 new_val
= prev_val
- 1;
118 if (prev_val
== InterlockedCompareExchange(&This
->lock
, new_val
, prev_val
))
124 static HRESULT WINAPI
BitmapLockImpl_QueryInterface(IWICBitmapLock
*iface
, REFIID iid
,
127 BitmapLockImpl
*This
= impl_from_IWICBitmapLock(iface
);
128 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
130 if (!ppv
) return E_INVALIDARG
;
132 if (IsEqualIID(&IID_IUnknown
, iid
) ||
133 IsEqualIID(&IID_IWICBitmapLock
, iid
))
135 *ppv
= &This
->IWICBitmapLock_iface
;
140 return E_NOINTERFACE
;
143 IUnknown_AddRef((IUnknown
*)*ppv
);
147 static ULONG WINAPI
BitmapLockImpl_AddRef(IWICBitmapLock
*iface
)
149 BitmapLockImpl
*This
= impl_from_IWICBitmapLock(iface
);
150 ULONG ref
= InterlockedIncrement(&This
->ref
);
152 TRACE("(%p) refcount=%u\n", iface
, ref
);
157 static ULONG WINAPI
BitmapLockImpl_Release(IWICBitmapLock
*iface
)
159 BitmapLockImpl
*This
= impl_from_IWICBitmapLock(iface
);
160 ULONG ref
= InterlockedDecrement(&This
->ref
);
162 TRACE("(%p) refcount=%u\n", iface
, ref
);
166 BitmapImpl_ReleaseLock(This
->parent
);
167 IWICBitmap_Release(&This
->parent
->IWICBitmap_iface
);
168 HeapFree(GetProcessHeap(), 0, This
);
174 static HRESULT WINAPI
BitmapLockImpl_GetSize(IWICBitmapLock
*iface
,
175 UINT
*puiWidth
, UINT
*puiHeight
)
177 BitmapLockImpl
*This
= impl_from_IWICBitmapLock(iface
);
178 TRACE("(%p,%p,%p)\n", iface
, puiWidth
, puiHeight
);
180 if (!puiWidth
|| !puiHeight
)
183 *puiWidth
= This
->width
;
184 *puiHeight
= This
->height
;
189 static HRESULT WINAPI
BitmapLockImpl_GetStride(IWICBitmapLock
*iface
,
192 BitmapLockImpl
*This
= impl_from_IWICBitmapLock(iface
);
193 TRACE("(%p,%p)\n", iface
, pcbStride
);
198 *pcbStride
= This
->parent
->stride
;
203 static HRESULT WINAPI
BitmapLockImpl_GetDataPointer(IWICBitmapLock
*iface
,
204 UINT
*pcbBufferSize
, BYTE
**ppbData
)
206 BitmapLockImpl
*This
= impl_from_IWICBitmapLock(iface
);
207 TRACE("(%p,%p,%p)\n", iface
, pcbBufferSize
, ppbData
);
209 if (!pcbBufferSize
|| !ppbData
)
212 *pcbBufferSize
= This
->parent
->stride
* (This
->height
- 1) +
213 ((This
->parent
->bpp
* This
->width
) + 7)/8;
214 *ppbData
= This
->data
;
219 static HRESULT WINAPI
BitmapLockImpl_GetPixelFormat(IWICBitmapLock
*iface
,
220 WICPixelFormatGUID
*pPixelFormat
)
222 BitmapLockImpl
*This
= impl_from_IWICBitmapLock(iface
);
223 TRACE("(%p,%p)\n", iface
, pPixelFormat
);
225 return IWICBitmap_GetPixelFormat(&This
->parent
->IWICBitmap_iface
, pPixelFormat
);
228 static const IWICBitmapLockVtbl BitmapLockImpl_Vtbl
= {
229 BitmapLockImpl_QueryInterface
,
230 BitmapLockImpl_AddRef
,
231 BitmapLockImpl_Release
,
232 BitmapLockImpl_GetSize
,
233 BitmapLockImpl_GetStride
,
234 BitmapLockImpl_GetDataPointer
,
235 BitmapLockImpl_GetPixelFormat
238 static HRESULT WINAPI
BitmapImpl_QueryInterface(IWICBitmap
*iface
, REFIID iid
,
241 BitmapImpl
*This
= impl_from_IWICBitmap(iface
);
242 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
244 if (!ppv
) return E_INVALIDARG
;
246 if (IsEqualIID(&IID_IUnknown
, iid
) ||
247 IsEqualIID(&IID_IWICBitmapSource
, iid
) ||
248 IsEqualIID(&IID_IWICBitmap
, iid
))
250 *ppv
= &This
->IWICBitmap_iface
;
252 else if (IsEqualIID(&IID_IMILBitmapSource
, iid
))
254 *ppv
= &This
->IMILBitmapSource_iface
;
259 return E_NOINTERFACE
;
262 IUnknown_AddRef((IUnknown
*)*ppv
);
266 static ULONG WINAPI
BitmapImpl_AddRef(IWICBitmap
*iface
)
268 BitmapImpl
*This
= impl_from_IWICBitmap(iface
);
269 ULONG ref
= InterlockedIncrement(&This
->ref
);
271 TRACE("(%p) refcount=%u\n", iface
, ref
);
276 static ULONG WINAPI
BitmapImpl_Release(IWICBitmap
*iface
)
278 BitmapImpl
*This
= impl_from_IWICBitmap(iface
);
279 ULONG ref
= InterlockedDecrement(&This
->ref
);
281 TRACE("(%p) refcount=%u\n", iface
, ref
);
285 if (This
->palette
) IWICPalette_Release(This
->palette
);
286 This
->cs
.DebugInfo
->Spare
[0] = 0;
287 DeleteCriticalSection(&This
->cs
);
288 HeapFree(GetProcessHeap(), 0, This
->data
);
289 HeapFree(GetProcessHeap(), 0, This
);
295 static HRESULT WINAPI
BitmapImpl_GetSize(IWICBitmap
*iface
,
296 UINT
*puiWidth
, UINT
*puiHeight
)
298 BitmapImpl
*This
= impl_from_IWICBitmap(iface
);
299 TRACE("(%p,%p,%p)\n", iface
, puiWidth
, puiHeight
);
301 if (!puiWidth
|| !puiHeight
)
304 *puiWidth
= This
->width
;
305 *puiHeight
= This
->height
;
310 static HRESULT WINAPI
BitmapImpl_GetPixelFormat(IWICBitmap
*iface
,
311 WICPixelFormatGUID
*pPixelFormat
)
313 BitmapImpl
*This
= impl_from_IWICBitmap(iface
);
314 TRACE("(%p,%p)\n", iface
, pPixelFormat
);
319 memcpy(pPixelFormat
, &This
->pixelformat
, sizeof(GUID
));
324 static HRESULT WINAPI
BitmapImpl_GetResolution(IWICBitmap
*iface
,
325 double *pDpiX
, double *pDpiY
)
327 BitmapImpl
*This
= impl_from_IWICBitmap(iface
);
328 TRACE("(%p,%p,%p)\n", iface
, pDpiX
, pDpiY
);
330 if (!pDpiX
|| !pDpiY
)
333 EnterCriticalSection(&This
->cs
);
336 LeaveCriticalSection(&This
->cs
);
341 static HRESULT WINAPI
BitmapImpl_CopyPalette(IWICBitmap
*iface
,
342 IWICPalette
*pIPalette
)
344 BitmapImpl
*This
= impl_from_IWICBitmap(iface
);
345 TRACE("(%p,%p)\n", iface
, pIPalette
);
347 if (!This
->palette_set
)
348 return WINCODEC_ERR_PALETTEUNAVAILABLE
;
350 return IWICPalette_InitializeFromPalette(pIPalette
, This
->palette
);
353 static HRESULT WINAPI
BitmapImpl_CopyPixels(IWICBitmap
*iface
,
354 const WICRect
*prc
, UINT cbStride
, UINT cbBufferSize
, BYTE
*pbBuffer
)
356 BitmapImpl
*This
= impl_from_IWICBitmap(iface
);
357 TRACE("(%p,%p,%u,%u,%p)\n", iface
, prc
, cbStride
, cbBufferSize
, pbBuffer
);
359 return copy_pixels(This
->bpp
, This
->data
, This
->width
, This
->height
,
360 This
->stride
, prc
, cbStride
, cbBufferSize
, pbBuffer
);
363 static HRESULT WINAPI
BitmapImpl_Lock(IWICBitmap
*iface
, const WICRect
*prcLock
,
364 DWORD flags
, IWICBitmapLock
**ppILock
)
366 BitmapImpl
*This
= impl_from_IWICBitmap(iface
);
367 BitmapLockImpl
*result
;
370 TRACE("(%p,%p,%x,%p)\n", iface
, prcLock
, flags
, ppILock
);
372 if (!(flags
& (WICBitmapLockRead
|WICBitmapLockWrite
)) || !ppILock
)
378 rc
.Width
= This
->width
;
379 rc
.Height
= This
->height
;
382 else if (prcLock
->X
>= This
->width
|| prcLock
->Y
>= This
->height
||
383 prcLock
->X
+ prcLock
->Width
> This
->width
||
384 prcLock
->Y
+ prcLock
->Height
> This
->height
||
385 prcLock
->Width
<= 0 || prcLock
->Height
<= 0)
387 else if (((prcLock
->X
* This
->bpp
) % 8) != 0)
389 FIXME("Cannot lock at an X coordinate not at a full byte\n");
393 result
= HeapAlloc(GetProcessHeap(), 0, sizeof(BitmapLockImpl
));
395 return E_OUTOFMEMORY
;
397 if (!BitmapImpl_AcquireLock(This
, flags
& WICBitmapLockWrite
))
399 HeapFree(GetProcessHeap(), 0, result
);
400 return WINCODEC_ERR_ALREADYLOCKED
;
403 result
->IWICBitmapLock_iface
.lpVtbl
= &BitmapLockImpl_Vtbl
;
405 result
->parent
= This
;
406 result
->width
= prcLock
->Width
;
407 result
->height
= prcLock
->Height
;
408 result
->data
= This
->data
+ This
->stride
* prcLock
->Y
+
409 (This
->bpp
* prcLock
->X
)/8;
411 IWICBitmap_AddRef(&This
->IWICBitmap_iface
);
412 *ppILock
= &result
->IWICBitmapLock_iface
;
417 static HRESULT WINAPI
BitmapImpl_SetPalette(IWICBitmap
*iface
, IWICPalette
*pIPalette
)
419 BitmapImpl
*This
= impl_from_IWICBitmap(iface
);
422 TRACE("(%p,%p)\n", iface
, pIPalette
);
426 IWICPalette
*new_palette
;
427 hr
= PaletteImpl_Create(&new_palette
);
429 if (FAILED(hr
)) return hr
;
431 if (InterlockedCompareExchangePointer((void**)&This
->palette
, new_palette
, NULL
))
433 /* someone beat us to it */
434 IWICPalette_Release(new_palette
);
438 hr
= IWICPalette_InitializeFromPalette(This
->palette
, pIPalette
);
441 This
->palette_set
= 1;
446 static HRESULT WINAPI
BitmapImpl_SetResolution(IWICBitmap
*iface
,
447 double dpiX
, double dpiY
)
449 BitmapImpl
*This
= impl_from_IWICBitmap(iface
);
450 TRACE("(%p,%f,%f)\n", iface
, dpiX
, dpiY
);
452 EnterCriticalSection(&This
->cs
);
455 LeaveCriticalSection(&This
->cs
);
460 static const IWICBitmapVtbl BitmapImpl_Vtbl
= {
461 BitmapImpl_QueryInterface
,
465 BitmapImpl_GetPixelFormat
,
466 BitmapImpl_GetResolution
,
467 BitmapImpl_CopyPalette
,
468 BitmapImpl_CopyPixels
,
470 BitmapImpl_SetPalette
,
471 BitmapImpl_SetResolution
474 static HRESULT WINAPI
IMILBitmapImpl_QueryInterface(IMILBitmapSource
*iface
, REFIID iid
,
477 BitmapImpl
*This
= impl_from_IMILBitmapSource(iface
);
478 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
480 if (!ppv
) return E_INVALIDARG
;
482 if (IsEqualIID(&IID_IUnknown
, iid
) ||
483 IsEqualIID(&IID_IMILBitmapSource
, iid
))
485 IUnknown_AddRef(&This
->IMILBitmapSource_iface
);
486 *ppv
= &This
->IMILBitmapSource_iface
;
491 return E_NOINTERFACE
;
494 static ULONG WINAPI
IMILBitmapImpl_AddRef(IMILBitmapSource
*iface
)
496 BitmapImpl
*This
= impl_from_IMILBitmapSource(iface
);
497 return IWICBitmap_AddRef(&This
->IWICBitmap_iface
);
500 static ULONG WINAPI
IMILBitmapImpl_Release(IMILBitmapSource
*iface
)
502 BitmapImpl
*This
= impl_from_IMILBitmapSource(iface
);
503 return IWICBitmap_Release(&This
->IWICBitmap_iface
);
506 static HRESULT WINAPI
IMILBitmapImpl_GetSize(IMILBitmapSource
*iface
,
507 UINT
*width
, UINT
*height
)
509 BitmapImpl
*This
= impl_from_IMILBitmapSource(iface
);
510 return IWICBitmap_GetSize(&This
->IWICBitmap_iface
, width
, height
);
515 const GUID
*WIC_format
;
519 { &GUID_WICPixelFormatDontCare
, 0 },
520 { &GUID_WICPixelFormat1bppIndexed
, 1 },
521 { &GUID_WICPixelFormat2bppIndexed
, 2 },
522 { &GUID_WICPixelFormat4bppIndexed
, 3 },
523 { &GUID_WICPixelFormat8bppIndexed
, 4 },
524 { &GUID_WICPixelFormatBlackWhite
, 5 },
525 { &GUID_WICPixelFormat2bppGray
, 6 },
526 { &GUID_WICPixelFormat4bppGray
, 7 },
527 { &GUID_WICPixelFormat8bppGray
, 8 },
528 { &GUID_WICPixelFormat16bppBGR555
, 9 },
529 { &GUID_WICPixelFormat16bppBGR565
, 0x0a },
530 { &GUID_WICPixelFormat16bppGray
, 0x0b },
531 { &GUID_WICPixelFormat24bppBGR
, 0x0c },
532 { &GUID_WICPixelFormat24bppRGB
, 0x0d },
533 { &GUID_WICPixelFormat32bppBGR
, 0x0e },
534 { &GUID_WICPixelFormat32bppBGRA
, 0x0f },
535 { &GUID_WICPixelFormat32bppPBGRA
, 0x10 },
536 { &GUID_WICPixelFormat48bppRGB
, 0x15 },
537 { &GUID_WICPixelFormat64bppRGBA
, 0x16 },
538 { &GUID_WICPixelFormat64bppPRGBA
, 0x17 },
539 { &GUID_WICPixelFormat32bppCMYK
, 0x1c }
542 static HRESULT WINAPI
IMILBitmapImpl_GetPixelFormat(IMILBitmapSource
*iface
,
545 BitmapImpl
*This
= impl_from_IMILBitmapSource(iface
);
548 TRACE("(%p,%p)\n", iface
, format
);
550 if (!format
) return E_INVALIDARG
;
554 for (i
= 0; i
< sizeof(pixel_fmt_map
)/sizeof(pixel_fmt_map
[0]); i
++)
556 if (IsEqualGUID(pixel_fmt_map
[i
].WIC_format
, &This
->pixelformat
))
558 *format
= pixel_fmt_map
[i
].enum_format
;
566 static HRESULT WINAPI
IMILBitmapImpl_GetResolution(IMILBitmapSource
*iface
,
567 double *dpix
, double *dpiy
)
569 BitmapImpl
*This
= impl_from_IMILBitmapSource(iface
);
570 return IWICBitmap_GetResolution(&This
->IWICBitmap_iface
, dpix
, dpiy
);
573 static HRESULT WINAPI
IMILBitmapImpl_CopyPalette(IMILBitmapSource
*iface
,
574 IWICPalette
*palette
)
576 BitmapImpl
*This
= impl_from_IMILBitmapSource(iface
);
577 return IWICBitmap_CopyPalette(&This
->IWICBitmap_iface
, palette
);
580 static HRESULT WINAPI
IMILBitmapImpl_CopyPixels(IMILBitmapSource
*iface
,
581 const WICRect
*rc
, UINT stride
, UINT size
, BYTE
*buffer
)
583 BitmapImpl
*This
= impl_from_IMILBitmapSource(iface
);
584 return IWICBitmap_CopyPixels(&This
->IWICBitmap_iface
, rc
, stride
, size
, buffer
);
587 static HRESULT WINAPI
IMILBitmapImpl_UnknownMethod1(IMILBitmapSource
*iface
, void **ppv
)
589 BitmapImpl
*This
= impl_from_IMILBitmapSource(iface
);
591 TRACE("(%p,%p)\n", iface
, ppv
);
593 if (!ppv
) return E_INVALIDARG
;
595 IUnknown_AddRef(&This
->IMILUnknown1_iface
);
596 *ppv
= &This
->IMILUnknown1_iface
;
601 static const IMILBitmapSourceVtbl IMILBitmapImpl_Vtbl
=
603 IMILBitmapImpl_QueryInterface
,
604 IMILBitmapImpl_AddRef
,
605 IMILBitmapImpl_Release
,
606 IMILBitmapImpl_GetSize
,
607 IMILBitmapImpl_GetPixelFormat
,
608 IMILBitmapImpl_GetResolution
,
609 IMILBitmapImpl_CopyPalette
,
610 IMILBitmapImpl_CopyPixels
,
611 IMILBitmapImpl_UnknownMethod1
,
614 static HRESULT WINAPI
IMILUnknown1Impl_QueryInterface(IMILUnknown1
*iface
, REFIID iid
,
617 BitmapImpl
*This
= impl_from_IMILUnknown1(iface
);
619 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
621 if (!ppv
) return E_INVALIDARG
;
623 if (IsEqualIID(&IID_IUnknown
, iid
))
625 IUnknown_AddRef(&This
->IMILUnknown1_iface
);
630 return IWICBitmap_QueryInterface(&This
->IWICBitmap_iface
, iid
, ppv
);
633 static ULONG WINAPI
IMILUnknown1Impl_AddRef(IMILUnknown1
*iface
)
635 BitmapImpl
*This
= impl_from_IMILUnknown1(iface
);
636 return IWICBitmap_AddRef(&This
->IWICBitmap_iface
);
639 static ULONG WINAPI
IMILUnknown1Impl_Release(IMILUnknown1
*iface
)
641 BitmapImpl
*This
= impl_from_IMILUnknown1(iface
);
642 return IWICBitmap_Release(&This
->IWICBitmap_iface
);
645 static const IMILUnknown1Vtbl IMILUnknown1Impl_Vtbl
=
647 IMILUnknown1Impl_QueryInterface
,
648 IMILUnknown1Impl_AddRef
,
649 IMILUnknown1Impl_Release
,
652 static HRESULT WINAPI
IMILUnknown2Impl_QueryInterface(IMILUnknown2
*iface
, REFIID iid
,
655 BitmapImpl
*This
= impl_from_IMILUnknown2(iface
);
657 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
659 if (!ppv
) return E_INVALIDARG
;
661 if (IsEqualIID(&IID_IUnknown
, iid
))
663 IUnknown_AddRef(&This
->IMILUnknown2_iface
);
668 return IWICBitmap_QueryInterface(&This
->IWICBitmap_iface
, iid
, ppv
);
671 static ULONG WINAPI
IMILUnknown2Impl_AddRef(IMILUnknown2
*iface
)
673 BitmapImpl
*This
= impl_from_IMILUnknown2(iface
);
674 return IWICBitmap_AddRef(&This
->IWICBitmap_iface
);
677 static ULONG WINAPI
IMILUnknown2Impl_Release(IMILUnknown2
*iface
)
679 BitmapImpl
*This
= impl_from_IMILUnknown2(iface
);
680 return IWICBitmap_Release(&This
->IWICBitmap_iface
);
683 static HRESULT WINAPI
IMILUnknown2Impl_UnknownMethod1(IMILUnknown2
*iface
, void *arg1
, void *arg2
)
685 FIXME("(%p,%p,%p): stub\n", iface
, arg1
, arg2
);
689 static const IMILUnknown2Vtbl IMILUnknown2Impl_Vtbl
=
691 IMILUnknown2Impl_QueryInterface
,
692 IMILUnknown2Impl_AddRef
,
693 IMILUnknown2Impl_Release
,
694 IMILUnknown2Impl_UnknownMethod1
,
697 HRESULT
BitmapImpl_Create(UINT uiWidth
, UINT uiHeight
,
698 UINT stride
, UINT datasize
, BYTE
*bits
,
699 REFWICPixelFormatGUID pixelFormat
, WICBitmapCreateCacheOption option
,
700 IWICBitmap
**ppIBitmap
)
707 hr
= get_pixelformat_bpp(pixelFormat
, &bpp
);
708 if (FAILED(hr
)) return hr
;
710 if (!stride
) stride
= (((bpp
*uiWidth
)+31)/32)*4;
711 if (!datasize
) datasize
= stride
* uiHeight
;
713 if (datasize
< stride
* uiHeight
) return WINCODEC_ERR_INSUFFICIENTBUFFER
;
714 if (stride
< ((bpp
*uiWidth
)+7)/8) return E_INVALIDARG
;
716 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(BitmapImpl
));
717 data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, datasize
);
720 HeapFree(GetProcessHeap(), 0, This
);
721 HeapFree(GetProcessHeap(), 0, data
);
722 return E_OUTOFMEMORY
;
724 if (bits
) memcpy(data
, bits
, datasize
);
726 This
->IWICBitmap_iface
.lpVtbl
= &BitmapImpl_Vtbl
;
727 This
->IMILBitmapSource_iface
.lpVtbl
= &IMILBitmapImpl_Vtbl
;
728 This
->IMILUnknown1_iface
.lpVtbl
= &IMILUnknown1Impl_Vtbl
;
729 This
->IMILUnknown2_iface
.lpVtbl
= &IMILUnknown2Impl_Vtbl
;
731 This
->palette
= NULL
;
732 This
->palette_set
= 0;
735 This
->width
= uiWidth
;
736 This
->height
= uiHeight
;
737 This
->stride
= stride
;
739 memcpy(&This
->pixelformat
, pixelFormat
, sizeof(GUID
));
740 This
->dpix
= This
->dpiy
= 0.0;
741 InitializeCriticalSection(&This
->cs
);
742 This
->cs
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": BitmapImpl.lock");
744 *ppIBitmap
= &This
->IWICBitmap_iface
;