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
29 #include "wincodecs_private.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs
);
35 /* WARNING: .NET Media Integration Layer (MIL) directly dereferences
36 * BitmapImpl members and depends on its exact layout.
38 typedef struct BitmapImpl
{
39 IMILUnknown1 IMILUnknown1_iface
;
41 IMILBitmapSource IMILBitmapSource_iface
;
42 IWICBitmap IWICBitmap_iface
;
43 IMILUnknown2 IMILUnknown2_iface
;
46 LONG lock
; /* 0 if not locked, -1 if locked for writing, count if locked for reading */
48 void *view
; /* used if data is a section created by an application */
49 UINT offset
; /* offset into view */
53 WICPixelFormatGUID pixelformat
;
58 typedef struct BitmapLockImpl
{
59 IWICBitmapLock IWICBitmapLock_iface
;
66 static inline BitmapImpl
*impl_from_IWICBitmap(IWICBitmap
*iface
)
68 return CONTAINING_RECORD(iface
, BitmapImpl
, IWICBitmap_iface
);
71 static inline BitmapImpl
*impl_from_IMILBitmapSource(IMILBitmapSource
*iface
)
73 return CONTAINING_RECORD(iface
, BitmapImpl
, IMILBitmapSource_iface
);
76 static inline BitmapImpl
*impl_from_IMILUnknown1(IMILUnknown1
*iface
)
78 return CONTAINING_RECORD(iface
, BitmapImpl
, IMILUnknown1_iface
);
81 static inline BitmapImpl
*impl_from_IMILUnknown2(IMILUnknown2
*iface
)
83 return CONTAINING_RECORD(iface
, BitmapImpl
, IMILUnknown2_iface
);
86 static inline BitmapLockImpl
*impl_from_IWICBitmapLock(IWICBitmapLock
*iface
)
88 return CONTAINING_RECORD(iface
, BitmapLockImpl
, IWICBitmapLock_iface
);
91 static BOOL
BitmapImpl_AcquireLock(BitmapImpl
*This
, int write
)
95 return 0 == InterlockedCompareExchange(&This
->lock
, -1, 0);
101 LONG prev_val
= This
->lock
;
104 if (prev_val
== InterlockedCompareExchange(&This
->lock
, prev_val
+1, prev_val
))
110 static void BitmapImpl_ReleaseLock(BitmapImpl
*This
)
114 LONG prev_val
= This
->lock
, new_val
;
118 new_val
= prev_val
- 1;
119 if (prev_val
== InterlockedCompareExchange(&This
->lock
, new_val
, prev_val
))
125 static HRESULT WINAPI
BitmapLockImpl_QueryInterface(IWICBitmapLock
*iface
, REFIID iid
,
128 BitmapLockImpl
*This
= impl_from_IWICBitmapLock(iface
);
129 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
131 if (!ppv
) return E_INVALIDARG
;
133 if (IsEqualIID(&IID_IUnknown
, iid
) ||
134 IsEqualIID(&IID_IWICBitmapLock
, iid
))
136 *ppv
= &This
->IWICBitmapLock_iface
;
141 return E_NOINTERFACE
;
144 IUnknown_AddRef((IUnknown
*)*ppv
);
148 static ULONG WINAPI
BitmapLockImpl_AddRef(IWICBitmapLock
*iface
)
150 BitmapLockImpl
*This
= impl_from_IWICBitmapLock(iface
);
151 ULONG ref
= InterlockedIncrement(&This
->ref
);
153 TRACE("(%p) refcount=%u\n", iface
, ref
);
158 static ULONG WINAPI
BitmapLockImpl_Release(IWICBitmapLock
*iface
)
160 BitmapLockImpl
*This
= impl_from_IWICBitmapLock(iface
);
161 ULONG ref
= InterlockedDecrement(&This
->ref
);
163 TRACE("(%p) refcount=%u\n", iface
, ref
);
167 BitmapImpl_ReleaseLock(This
->parent
);
168 IWICBitmap_Release(&This
->parent
->IWICBitmap_iface
);
169 HeapFree(GetProcessHeap(), 0, This
);
175 static HRESULT WINAPI
BitmapLockImpl_GetSize(IWICBitmapLock
*iface
,
176 UINT
*puiWidth
, UINT
*puiHeight
)
178 BitmapLockImpl
*This
= impl_from_IWICBitmapLock(iface
);
179 TRACE("(%p,%p,%p)\n", iface
, puiWidth
, puiHeight
);
181 if (!puiWidth
|| !puiHeight
)
184 *puiWidth
= This
->width
;
185 *puiHeight
= This
->height
;
190 static HRESULT WINAPI
BitmapLockImpl_GetStride(IWICBitmapLock
*iface
,
193 BitmapLockImpl
*This
= impl_from_IWICBitmapLock(iface
);
194 TRACE("(%p,%p)\n", iface
, pcbStride
);
199 *pcbStride
= This
->parent
->stride
;
204 static HRESULT WINAPI
BitmapLockImpl_GetDataPointer(IWICBitmapLock
*iface
,
205 UINT
*pcbBufferSize
, BYTE
**ppbData
)
207 BitmapLockImpl
*This
= impl_from_IWICBitmapLock(iface
);
208 TRACE("(%p,%p,%p)\n", iface
, pcbBufferSize
, ppbData
);
210 if (!pcbBufferSize
|| !ppbData
)
213 *pcbBufferSize
= This
->parent
->stride
* (This
->height
- 1) +
214 ((This
->parent
->bpp
* This
->width
) + 7)/8;
215 *ppbData
= This
->data
;
220 static HRESULT WINAPI
BitmapLockImpl_GetPixelFormat(IWICBitmapLock
*iface
,
221 WICPixelFormatGUID
*pPixelFormat
)
223 BitmapLockImpl
*This
= impl_from_IWICBitmapLock(iface
);
224 TRACE("(%p,%p)\n", iface
, pPixelFormat
);
226 return IWICBitmap_GetPixelFormat(&This
->parent
->IWICBitmap_iface
, pPixelFormat
);
229 static const IWICBitmapLockVtbl BitmapLockImpl_Vtbl
= {
230 BitmapLockImpl_QueryInterface
,
231 BitmapLockImpl_AddRef
,
232 BitmapLockImpl_Release
,
233 BitmapLockImpl_GetSize
,
234 BitmapLockImpl_GetStride
,
235 BitmapLockImpl_GetDataPointer
,
236 BitmapLockImpl_GetPixelFormat
239 static HRESULT WINAPI
BitmapImpl_QueryInterface(IWICBitmap
*iface
, REFIID iid
,
242 BitmapImpl
*This
= impl_from_IWICBitmap(iface
);
243 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
245 if (!ppv
) return E_INVALIDARG
;
247 if (IsEqualIID(&IID_IUnknown
, iid
) ||
248 IsEqualIID(&IID_IWICBitmapSource
, iid
) ||
249 IsEqualIID(&IID_IWICBitmap
, iid
))
251 *ppv
= &This
->IWICBitmap_iface
;
253 else if (IsEqualIID(&IID_IMILBitmapSource
, iid
))
255 *ppv
= &This
->IMILBitmapSource_iface
;
260 return E_NOINTERFACE
;
263 IUnknown_AddRef((IUnknown
*)*ppv
);
267 static ULONG WINAPI
BitmapImpl_AddRef(IWICBitmap
*iface
)
269 BitmapImpl
*This
= impl_from_IWICBitmap(iface
);
270 ULONG ref
= InterlockedIncrement(&This
->ref
);
272 TRACE("(%p) refcount=%u\n", iface
, ref
);
277 static ULONG WINAPI
BitmapImpl_Release(IWICBitmap
*iface
)
279 BitmapImpl
*This
= impl_from_IWICBitmap(iface
);
280 ULONG ref
= InterlockedDecrement(&This
->ref
);
282 TRACE("(%p) refcount=%u\n", iface
, ref
);
286 if (This
->palette
) IWICPalette_Release(This
->palette
);
287 This
->cs
.DebugInfo
->Spare
[0] = 0;
288 DeleteCriticalSection(&This
->cs
);
290 UnmapViewOfFile(This
->view
);
292 HeapFree(GetProcessHeap(), 0, This
->data
);
293 HeapFree(GetProcessHeap(), 0, This
);
299 static HRESULT WINAPI
BitmapImpl_GetSize(IWICBitmap
*iface
,
300 UINT
*puiWidth
, UINT
*puiHeight
)
302 BitmapImpl
*This
= impl_from_IWICBitmap(iface
);
303 TRACE("(%p,%p,%p)\n", iface
, puiWidth
, puiHeight
);
305 if (!puiWidth
|| !puiHeight
)
308 *puiWidth
= This
->width
;
309 *puiHeight
= This
->height
;
314 static HRESULT WINAPI
BitmapImpl_GetPixelFormat(IWICBitmap
*iface
,
315 WICPixelFormatGUID
*pPixelFormat
)
317 BitmapImpl
*This
= impl_from_IWICBitmap(iface
);
318 TRACE("(%p,%p)\n", iface
, pPixelFormat
);
323 memcpy(pPixelFormat
, &This
->pixelformat
, sizeof(GUID
));
328 static HRESULT WINAPI
BitmapImpl_GetResolution(IWICBitmap
*iface
,
329 double *pDpiX
, double *pDpiY
)
331 BitmapImpl
*This
= impl_from_IWICBitmap(iface
);
332 TRACE("(%p,%p,%p)\n", iface
, pDpiX
, pDpiY
);
334 if (!pDpiX
|| !pDpiY
)
337 EnterCriticalSection(&This
->cs
);
340 LeaveCriticalSection(&This
->cs
);
345 static HRESULT WINAPI
BitmapImpl_CopyPalette(IWICBitmap
*iface
,
346 IWICPalette
*pIPalette
)
348 BitmapImpl
*This
= impl_from_IWICBitmap(iface
);
349 TRACE("(%p,%p)\n", iface
, pIPalette
);
351 if (!This
->palette_set
)
352 return WINCODEC_ERR_PALETTEUNAVAILABLE
;
354 return IWICPalette_InitializeFromPalette(pIPalette
, This
->palette
);
357 static HRESULT WINAPI
BitmapImpl_CopyPixels(IWICBitmap
*iface
,
358 const WICRect
*prc
, UINT cbStride
, UINT cbBufferSize
, BYTE
*pbBuffer
)
360 BitmapImpl
*This
= impl_from_IWICBitmap(iface
);
361 TRACE("(%p,%p,%u,%u,%p)\n", iface
, prc
, cbStride
, cbBufferSize
, pbBuffer
);
363 return copy_pixels(This
->bpp
, This
->data
, This
->width
, This
->height
,
364 This
->stride
, prc
, cbStride
, cbBufferSize
, pbBuffer
);
367 static HRESULT WINAPI
BitmapImpl_Lock(IWICBitmap
*iface
, const WICRect
*prcLock
,
368 DWORD flags
, IWICBitmapLock
**ppILock
)
370 BitmapImpl
*This
= impl_from_IWICBitmap(iface
);
371 BitmapLockImpl
*result
;
374 TRACE("(%p,%p,%x,%p)\n", iface
, prcLock
, flags
, ppILock
);
376 if (!(flags
& (WICBitmapLockRead
|WICBitmapLockWrite
)) || !ppILock
)
382 rc
.Width
= This
->width
;
383 rc
.Height
= This
->height
;
386 else if (prcLock
->X
>= This
->width
|| prcLock
->Y
>= This
->height
||
387 prcLock
->X
+ prcLock
->Width
> This
->width
||
388 prcLock
->Y
+ prcLock
->Height
> This
->height
||
389 prcLock
->Width
<= 0 || prcLock
->Height
<= 0)
391 else if (((prcLock
->X
* This
->bpp
) % 8) != 0)
393 FIXME("Cannot lock at an X coordinate not at a full byte\n");
397 result
= HeapAlloc(GetProcessHeap(), 0, sizeof(BitmapLockImpl
));
399 return E_OUTOFMEMORY
;
401 if (!BitmapImpl_AcquireLock(This
, flags
& WICBitmapLockWrite
))
403 HeapFree(GetProcessHeap(), 0, result
);
404 return WINCODEC_ERR_ALREADYLOCKED
;
407 result
->IWICBitmapLock_iface
.lpVtbl
= &BitmapLockImpl_Vtbl
;
409 result
->parent
= This
;
410 result
->width
= prcLock
->Width
;
411 result
->height
= prcLock
->Height
;
412 result
->data
= This
->data
+ This
->stride
* prcLock
->Y
+
413 (This
->bpp
* prcLock
->X
)/8;
415 IWICBitmap_AddRef(&This
->IWICBitmap_iface
);
416 *ppILock
= &result
->IWICBitmapLock_iface
;
421 static HRESULT WINAPI
BitmapImpl_SetPalette(IWICBitmap
*iface
, IWICPalette
*pIPalette
)
423 BitmapImpl
*This
= impl_from_IWICBitmap(iface
);
426 TRACE("(%p,%p)\n", iface
, pIPalette
);
430 IWICPalette
*new_palette
;
431 hr
= PaletteImpl_Create(&new_palette
);
433 if (FAILED(hr
)) return hr
;
435 if (InterlockedCompareExchangePointer((void**)&This
->palette
, new_palette
, NULL
))
437 /* someone beat us to it */
438 IWICPalette_Release(new_palette
);
442 hr
= IWICPalette_InitializeFromPalette(This
->palette
, pIPalette
);
445 This
->palette_set
= 1;
450 static HRESULT WINAPI
BitmapImpl_SetResolution(IWICBitmap
*iface
,
451 double dpiX
, double dpiY
)
453 BitmapImpl
*This
= impl_from_IWICBitmap(iface
);
454 TRACE("(%p,%f,%f)\n", iface
, dpiX
, dpiY
);
456 EnterCriticalSection(&This
->cs
);
459 LeaveCriticalSection(&This
->cs
);
464 static const IWICBitmapVtbl BitmapImpl_Vtbl
= {
465 BitmapImpl_QueryInterface
,
469 BitmapImpl_GetPixelFormat
,
470 BitmapImpl_GetResolution
,
471 BitmapImpl_CopyPalette
,
472 BitmapImpl_CopyPixels
,
474 BitmapImpl_SetPalette
,
475 BitmapImpl_SetResolution
478 static HRESULT WINAPI
IMILBitmapImpl_QueryInterface(IMILBitmapSource
*iface
, REFIID iid
,
481 BitmapImpl
*This
= impl_from_IMILBitmapSource(iface
);
482 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
484 if (!ppv
) return E_INVALIDARG
;
486 if (IsEqualIID(&IID_IUnknown
, iid
) ||
487 IsEqualIID(&IID_IMILBitmapSource
, iid
))
489 IUnknown_AddRef(&This
->IMILBitmapSource_iface
);
490 *ppv
= &This
->IMILBitmapSource_iface
;
495 return E_NOINTERFACE
;
498 static ULONG WINAPI
IMILBitmapImpl_AddRef(IMILBitmapSource
*iface
)
500 BitmapImpl
*This
= impl_from_IMILBitmapSource(iface
);
501 return IWICBitmap_AddRef(&This
->IWICBitmap_iface
);
504 static ULONG WINAPI
IMILBitmapImpl_Release(IMILBitmapSource
*iface
)
506 BitmapImpl
*This
= impl_from_IMILBitmapSource(iface
);
507 return IWICBitmap_Release(&This
->IWICBitmap_iface
);
510 static HRESULT WINAPI
IMILBitmapImpl_GetSize(IMILBitmapSource
*iface
,
511 UINT
*width
, UINT
*height
)
513 BitmapImpl
*This
= impl_from_IMILBitmapSource(iface
);
514 return IWICBitmap_GetSize(&This
->IWICBitmap_iface
, width
, height
);
519 const GUID
*WIC_format
;
523 { &GUID_WICPixelFormatDontCare
, 0 },
524 { &GUID_WICPixelFormat1bppIndexed
, 1 },
525 { &GUID_WICPixelFormat2bppIndexed
, 2 },
526 { &GUID_WICPixelFormat4bppIndexed
, 3 },
527 { &GUID_WICPixelFormat8bppIndexed
, 4 },
528 { &GUID_WICPixelFormatBlackWhite
, 5 },
529 { &GUID_WICPixelFormat2bppGray
, 6 },
530 { &GUID_WICPixelFormat4bppGray
, 7 },
531 { &GUID_WICPixelFormat8bppGray
, 8 },
532 { &GUID_WICPixelFormat16bppBGR555
, 9 },
533 { &GUID_WICPixelFormat16bppBGR565
, 0x0a },
534 { &GUID_WICPixelFormat16bppGray
, 0x0b },
535 { &GUID_WICPixelFormat24bppBGR
, 0x0c },
536 { &GUID_WICPixelFormat24bppRGB
, 0x0d },
537 { &GUID_WICPixelFormat32bppBGR
, 0x0e },
538 { &GUID_WICPixelFormat32bppBGRA
, 0x0f },
539 { &GUID_WICPixelFormat32bppPBGRA
, 0x10 },
540 { &GUID_WICPixelFormat48bppRGB
, 0x15 },
541 { &GUID_WICPixelFormat64bppRGBA
, 0x16 },
542 { &GUID_WICPixelFormat64bppPRGBA
, 0x17 },
543 { &GUID_WICPixelFormat32bppCMYK
, 0x1c }
546 static HRESULT WINAPI
IMILBitmapImpl_GetPixelFormat(IMILBitmapSource
*iface
,
549 BitmapImpl
*This
= impl_from_IMILBitmapSource(iface
);
552 TRACE("(%p,%p)\n", iface
, format
);
554 if (!format
) return E_INVALIDARG
;
558 for (i
= 0; i
< sizeof(pixel_fmt_map
)/sizeof(pixel_fmt_map
[0]); i
++)
560 if (IsEqualGUID(pixel_fmt_map
[i
].WIC_format
, &This
->pixelformat
))
562 *format
= pixel_fmt_map
[i
].enum_format
;
570 static HRESULT WINAPI
IMILBitmapImpl_GetResolution(IMILBitmapSource
*iface
,
571 double *dpix
, double *dpiy
)
573 BitmapImpl
*This
= impl_from_IMILBitmapSource(iface
);
574 return IWICBitmap_GetResolution(&This
->IWICBitmap_iface
, dpix
, dpiy
);
577 static HRESULT WINAPI
IMILBitmapImpl_CopyPalette(IMILBitmapSource
*iface
,
578 IWICPalette
*palette
)
580 BitmapImpl
*This
= impl_from_IMILBitmapSource(iface
);
581 return IWICBitmap_CopyPalette(&This
->IWICBitmap_iface
, palette
);
584 static HRESULT WINAPI
IMILBitmapImpl_CopyPixels(IMILBitmapSource
*iface
,
585 const WICRect
*rc
, UINT stride
, UINT size
, BYTE
*buffer
)
587 BitmapImpl
*This
= impl_from_IMILBitmapSource(iface
);
588 return IWICBitmap_CopyPixels(&This
->IWICBitmap_iface
, rc
, stride
, size
, buffer
);
591 static HRESULT WINAPI
IMILBitmapImpl_UnknownMethod1(IMILBitmapSource
*iface
, void **ppv
)
593 BitmapImpl
*This
= impl_from_IMILBitmapSource(iface
);
595 TRACE("(%p,%p)\n", iface
, ppv
);
597 if (!ppv
) return E_INVALIDARG
;
599 IUnknown_AddRef(&This
->IMILUnknown1_iface
);
600 *ppv
= &This
->IMILUnknown1_iface
;
605 static const IMILBitmapSourceVtbl IMILBitmapImpl_Vtbl
=
607 IMILBitmapImpl_QueryInterface
,
608 IMILBitmapImpl_AddRef
,
609 IMILBitmapImpl_Release
,
610 IMILBitmapImpl_GetSize
,
611 IMILBitmapImpl_GetPixelFormat
,
612 IMILBitmapImpl_GetResolution
,
613 IMILBitmapImpl_CopyPalette
,
614 IMILBitmapImpl_CopyPixels
,
615 IMILBitmapImpl_UnknownMethod1
,
618 static HRESULT WINAPI
IMILUnknown1Impl_QueryInterface(IMILUnknown1
*iface
, REFIID iid
,
621 BitmapImpl
*This
= impl_from_IMILUnknown1(iface
);
623 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
625 if (!ppv
) return E_INVALIDARG
;
627 if (IsEqualIID(&IID_IUnknown
, iid
))
629 IUnknown_AddRef(&This
->IMILUnknown1_iface
);
634 return IWICBitmap_QueryInterface(&This
->IWICBitmap_iface
, iid
, ppv
);
637 static ULONG WINAPI
IMILUnknown1Impl_AddRef(IMILUnknown1
*iface
)
639 BitmapImpl
*This
= impl_from_IMILUnknown1(iface
);
640 return IWICBitmap_AddRef(&This
->IWICBitmap_iface
);
643 static ULONG WINAPI
IMILUnknown1Impl_Release(IMILUnknown1
*iface
)
645 BitmapImpl
*This
= impl_from_IMILUnknown1(iface
);
646 return IWICBitmap_Release(&This
->IWICBitmap_iface
);
649 static const IMILUnknown1Vtbl IMILUnknown1Impl_Vtbl
=
651 IMILUnknown1Impl_QueryInterface
,
652 IMILUnknown1Impl_AddRef
,
653 IMILUnknown1Impl_Release
,
656 static HRESULT WINAPI
IMILUnknown2Impl_QueryInterface(IMILUnknown2
*iface
, REFIID iid
,
659 BitmapImpl
*This
= impl_from_IMILUnknown2(iface
);
661 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
663 if (!ppv
) return E_INVALIDARG
;
665 if (IsEqualIID(&IID_IUnknown
, iid
))
667 IUnknown_AddRef(&This
->IMILUnknown2_iface
);
672 return IWICBitmap_QueryInterface(&This
->IWICBitmap_iface
, iid
, ppv
);
675 static ULONG WINAPI
IMILUnknown2Impl_AddRef(IMILUnknown2
*iface
)
677 BitmapImpl
*This
= impl_from_IMILUnknown2(iface
);
678 return IWICBitmap_AddRef(&This
->IWICBitmap_iface
);
681 static ULONG WINAPI
IMILUnknown2Impl_Release(IMILUnknown2
*iface
)
683 BitmapImpl
*This
= impl_from_IMILUnknown2(iface
);
684 return IWICBitmap_Release(&This
->IWICBitmap_iface
);
687 static HRESULT WINAPI
IMILUnknown2Impl_UnknownMethod1(IMILUnknown2
*iface
, void *arg1
, void *arg2
)
689 FIXME("(%p,%p,%p): stub\n", iface
, arg1
, arg2
);
693 static const IMILUnknown2Vtbl IMILUnknown2Impl_Vtbl
=
695 IMILUnknown2Impl_QueryInterface
,
696 IMILUnknown2Impl_AddRef
,
697 IMILUnknown2Impl_Release
,
698 IMILUnknown2Impl_UnknownMethod1
,
701 HRESULT
BitmapImpl_Create(UINT uiWidth
, UINT uiHeight
, UINT stride
, UINT datasize
, void *view
,
702 UINT offset
, REFWICPixelFormatGUID pixelFormat
, WICBitmapCreateCacheOption option
,
703 IWICBitmap
**ppIBitmap
)
710 hr
= get_pixelformat_bpp(pixelFormat
, &bpp
);
711 if (FAILED(hr
)) return hr
;
713 if (!stride
) stride
= (((bpp
*uiWidth
)+31)/32)*4;
714 if (!datasize
) datasize
= stride
* uiHeight
;
716 if (datasize
< stride
* uiHeight
) return WINCODEC_ERR_INSUFFICIENTBUFFER
;
717 if (stride
< ((bpp
*uiWidth
)+7)/8) return E_INVALIDARG
;
719 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(BitmapImpl
));
720 if (!This
) return E_OUTOFMEMORY
;
722 if (view
) data
= (BYTE
*)view
+ offset
;
723 else if (!(data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, datasize
)))
725 HeapFree(GetProcessHeap(), 0, This
);
726 return E_OUTOFMEMORY
;
729 This
->IWICBitmap_iface
.lpVtbl
= &BitmapImpl_Vtbl
;
730 This
->IMILBitmapSource_iface
.lpVtbl
= &IMILBitmapImpl_Vtbl
;
731 This
->IMILUnknown1_iface
.lpVtbl
= &IMILUnknown1Impl_Vtbl
;
732 This
->IMILUnknown2_iface
.lpVtbl
= &IMILUnknown2Impl_Vtbl
;
734 This
->palette
= NULL
;
735 This
->palette_set
= 0;
739 This
->offset
= offset
;
740 This
->width
= uiWidth
;
741 This
->height
= uiHeight
;
742 This
->stride
= stride
;
744 memcpy(&This
->pixelformat
, pixelFormat
, sizeof(GUID
));
745 This
->dpix
= This
->dpiy
= 0.0;
746 InitializeCriticalSection(&This
->cs
);
747 This
->cs
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": BitmapImpl.lock");
749 *ppIBitmap
= &This
->IWICBitmap_iface
;