4 * Implementation of OLE IPicture and related interfaces
6 * Copyright 2000 Huw D M Davies for CodeWeavers.
7 * Copyright 2001 Marcus Meissner
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 * Support PICTYPE_BITMAP and PICTYPE_ICON, altough only bitmaps very well..
26 * Lots of methods are just stubs.
29 * NOTES (or things that msdn doesn't tell you)
31 * The width and height properties are returned in HIMETRIC units (0.01mm)
32 * IPicture::Render also uses these to select a region of the src picture.
33 * A bitmap's size is converted into these units by using the screen resolution
34 * thus an 8x8 bitmap on a 96dpi screen has a size of 212x212 (8/96 * 2540).
39 #include "wine/port.h"
48 /* Must be before wine includes, the header has things conflicting with
52 #define NONAMELESSUNION
53 #define NONAMELESSSTRUCT
65 #include "wine/debug.h"
66 #include "wine/unicode.h"
68 #include "wine/wingdi16.h"
71 /* This is a hack, so jpeglib.h does not redefine INT32 and the like*/
73 #define UINT8 JPEG_UINT8
74 #define UINT16 JPEG_UINT16
76 #define boolean jpeg_boolean
89 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
102 } CURSORICONFILEDIRENTRY
;
109 CURSORICONFILEDIRENTRY idEntries
[1];
114 /*************************************************************************
115 * Declaration of implementation class
118 typedef struct OLEPictureImpl
{
121 * IPicture handles IUnknown
124 const IPictureVtbl
*lpVtbl
;
125 const IDispatchVtbl
*lpvtblIDispatch
;
126 const IPersistStreamVtbl
*lpvtblIPersistStream
;
127 const IConnectionPointContainerVtbl
*lpvtblIConnectionPointContainer
;
129 /* Object reference count */
132 /* We own the object and must destroy it ourselves */
135 /* Picture description */
138 /* These are the pixel size of a bitmap */
142 /* And these are the size of the picture converted into HIMETRIC units */
143 OLE_XSIZE_HIMETRIC himetricWidth
;
144 OLE_YSIZE_HIMETRIC himetricHeight
;
146 IConnectionPoint
*pCP
;
151 /* Bitmap transparency mask */
159 BOOL bIsDirty
; /* Set to TRUE if picture has changed */
160 unsigned int loadtime_magic
; /* If a length header was found, saves value */
161 unsigned int loadtime_format
; /* for PICTYPE_BITMAP only, keeps track of image format (GIF/BMP/JPEG) */
165 * Macros to retrieve pointer to IUnknown (IPicture) from the other VTables.
168 static inline OLEPictureImpl
*impl_from_IDispatch( IDispatch
*iface
)
170 return (OLEPictureImpl
*)((char*)iface
- FIELD_OFFSET(OLEPictureImpl
, lpvtblIDispatch
));
173 static inline OLEPictureImpl
*impl_from_IPersistStream( IPersistStream
*iface
)
175 return (OLEPictureImpl
*)((char*)iface
- FIELD_OFFSET(OLEPictureImpl
, lpvtblIPersistStream
));
178 static inline OLEPictureImpl
*impl_from_IConnectionPointContainer( IConnectionPointContainer
*iface
)
180 return (OLEPictureImpl
*)((char*)iface
- FIELD_OFFSET(OLEPictureImpl
, lpvtblIConnectionPointContainer
));
184 * Predeclare VTables. They get initialized at the end.
186 static const IPictureVtbl OLEPictureImpl_VTable
;
187 static const IDispatchVtbl OLEPictureImpl_IDispatch_VTable
;
188 static const IPersistStreamVtbl OLEPictureImpl_IPersistStream_VTable
;
189 static const IConnectionPointContainerVtbl OLEPictureImpl_IConnectionPointContainer_VTable
;
191 /***********************************************************************
192 * Implementation of the OLEPictureImpl class.
195 static void OLEPictureImpl_SetBitmap(OLEPictureImpl
*This
) {
199 TRACE("bitmap handle %p\n", This
->desc
.u
.bmp
.hbitmap
);
200 if(GetObjectA(This
->desc
.u
.bmp
.hbitmap
, sizeof(bm
), &bm
) != sizeof(bm
)) {
201 ERR("GetObject fails\n");
204 This
->origWidth
= bm
.bmWidth
;
205 This
->origHeight
= bm
.bmHeight
;
206 /* The width and height are stored in HIMETRIC units (0.01 mm),
207 so we take our pixel width divide by pixels per inch and
208 multiply by 25.4 * 100 */
209 /* Should we use GetBitmapDimension if available? */
210 hdcRef
= CreateCompatibleDC(0);
211 This
->himetricWidth
=(bm
.bmWidth
*2540)/GetDeviceCaps(hdcRef
, LOGPIXELSX
);
212 This
->himetricHeight
=(bm
.bmHeight
*2540)/GetDeviceCaps(hdcRef
, LOGPIXELSY
);
216 static void OLEPictureImpl_SetIcon(OLEPictureImpl
* This
)
220 TRACE("icon handle %p\n", This
->desc
.u
.icon
.hicon
);
221 if (GetIconInfo(This
->desc
.u
.icon
.hicon
, &infoIcon
)) {
225 TRACE("bitmap handle for icon is %p\n", infoIcon
.hbmColor
);
226 if(GetObjectA(infoIcon
.hbmColor
? infoIcon
.hbmColor
: infoIcon
.hbmMask
, sizeof(bm
), &bm
) != sizeof(bm
)) {
227 ERR("GetObject fails on icon bitmap\n");
231 This
->origWidth
= bm
.bmWidth
;
232 This
->origHeight
= infoIcon
.hbmColor
? bm
.bmHeight
: bm
.bmHeight
/ 2;
233 /* see comment on HIMETRIC on OLEPictureImpl_SetBitmap() */
235 This
->himetricWidth
= (This
->origWidth
*2540)/GetDeviceCaps(hdcRef
, LOGPIXELSX
);
236 This
->himetricHeight
= (This
->origHeight
*2540)/GetDeviceCaps(hdcRef
, LOGPIXELSY
);
237 ReleaseDC(0, hdcRef
);
239 DeleteObject(infoIcon
.hbmMask
);
240 if (infoIcon
.hbmColor
) DeleteObject(infoIcon
.hbmColor
);
242 ERR("GetIconInfo() fails on icon %p\n", This
->desc
.u
.icon
.hicon
);
246 /************************************************************************
247 * OLEPictureImpl_Construct
249 * This method will construct a new instance of the OLEPictureImpl
252 * The caller of this method must release the object when it's
255 static OLEPictureImpl
* OLEPictureImpl_Construct(LPPICTDESC pictDesc
, BOOL fOwn
)
257 OLEPictureImpl
* newObject
= 0;
260 TRACE("(%p) type = %d\n", pictDesc
, pictDesc
->picType
);
263 * Allocate space for the object.
265 newObject
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(OLEPictureImpl
));
271 * Initialize the virtual function table.
273 newObject
->lpVtbl
= &OLEPictureImpl_VTable
;
274 newObject
->lpvtblIDispatch
= &OLEPictureImpl_IDispatch_VTable
;
275 newObject
->lpvtblIPersistStream
= &OLEPictureImpl_IPersistStream_VTable
;
276 newObject
->lpvtblIConnectionPointContainer
= &OLEPictureImpl_IConnectionPointContainer_VTable
;
278 newObject
->pCP
= NULL
;
279 CreateConnectionPoint((IUnknown
*)newObject
,&IID_IPropertyNotifySink
,&newObject
->pCP
);
282 HeapFree(GetProcessHeap(), 0, newObject
);
287 * Start with one reference count. The caller of this function
288 * must release the interface pointer when it is done.
291 newObject
->hDCCur
= 0;
293 newObject
->fOwn
= fOwn
;
295 /* dunno about original value */
296 newObject
->keepOrigFormat
= TRUE
;
298 newObject
->hbmMask
= NULL
;
299 newObject
->hbmXor
= NULL
;
300 newObject
->loadtime_magic
= 0xdeadbeef;
301 newObject
->loadtime_format
= 0;
302 newObject
->bIsDirty
= FALSE
;
305 memcpy(&newObject
->desc
, pictDesc
, sizeof(PICTDESC
));
307 switch(pictDesc
->picType
) {
309 OLEPictureImpl_SetBitmap(newObject
);
312 case PICTYPE_METAFILE
:
313 TRACE("metafile handle %p\n", pictDesc
->u
.wmf
.hmeta
);
314 newObject
->himetricWidth
= pictDesc
->u
.wmf
.xExt
;
315 newObject
->himetricHeight
= pictDesc
->u
.wmf
.yExt
;
319 /* not sure what to do here */
320 newObject
->himetricWidth
= newObject
->himetricHeight
= 0;
324 OLEPictureImpl_SetIcon(newObject
);
326 case PICTYPE_ENHMETAFILE
:
328 FIXME("Unsupported type %d\n", pictDesc
->picType
);
329 newObject
->himetricWidth
= newObject
->himetricHeight
= 0;
333 newObject
->desc
.picType
= PICTYPE_UNINITIALIZED
;
336 TRACE("returning %p\n", newObject
);
340 /************************************************************************
341 * OLEPictureImpl_Destroy
343 * This method is called by the Release method when the reference
344 * count goes down to 0. It will free all resources used by
346 static void OLEPictureImpl_Destroy(OLEPictureImpl
* Obj
)
348 TRACE("(%p)\n", Obj
);
351 IConnectionPoint_Release(Obj
->pCP
);
353 if(Obj
->fOwn
) { /* We need to destroy the picture */
354 switch(Obj
->desc
.picType
) {
356 DeleteObject(Obj
->desc
.u
.bmp
.hbitmap
);
357 if (Obj
->hbmMask
!= NULL
) DeleteObject(Obj
->hbmMask
);
358 if (Obj
->hbmXor
!= NULL
) DeleteObject(Obj
->hbmXor
);
360 case PICTYPE_METAFILE
:
361 DeleteMetaFile(Obj
->desc
.u
.wmf
.hmeta
);
364 DestroyIcon(Obj
->desc
.u
.icon
.hicon
);
366 case PICTYPE_ENHMETAFILE
:
367 DeleteEnhMetaFile(Obj
->desc
.u
.emf
.hemf
);
370 case PICTYPE_UNINITIALIZED
:
374 FIXME("Unsupported type %d - unable to delete\n", Obj
->desc
.picType
);
378 HeapFree(GetProcessHeap(), 0, Obj
->data
);
379 HeapFree(GetProcessHeap(), 0, Obj
);
383 /************************************************************************
384 * OLEPictureImpl_AddRef (IUnknown)
386 * See Windows documentation for more details on IUnknown methods.
388 static ULONG WINAPI
OLEPictureImpl_AddRef(
391 OLEPictureImpl
*This
= (OLEPictureImpl
*)iface
;
392 ULONG refCount
= InterlockedIncrement(&This
->ref
);
394 TRACE("(%p)->(ref before=%d)\n", This
, refCount
- 1);
399 /************************************************************************
400 * OLEPictureImpl_Release (IUnknown)
402 * See Windows documentation for more details on IUnknown methods.
404 static ULONG WINAPI
OLEPictureImpl_Release(
407 OLEPictureImpl
*This
= (OLEPictureImpl
*)iface
;
408 ULONG refCount
= InterlockedDecrement(&This
->ref
);
410 TRACE("(%p)->(ref before=%d)\n", This
, refCount
+ 1);
413 * If the reference count goes down to 0, perform suicide.
415 if (!refCount
) OLEPictureImpl_Destroy(This
);
420 /************************************************************************
421 * OLEPictureImpl_QueryInterface (IUnknown)
423 * See Windows documentation for more details on IUnknown methods.
425 static HRESULT WINAPI
OLEPictureImpl_QueryInterface(
430 OLEPictureImpl
*This
= (OLEPictureImpl
*)iface
;
431 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppvObject
);
434 * Perform a sanity check on the parameters.
436 if ( (This
==0) || (ppvObject
==0) )
440 * Initialize the return parameter.
445 * Compare the riid with the interface IDs implemented by this object.
447 if (IsEqualIID(&IID_IUnknown
, riid
) || IsEqualIID(&IID_IPicture
, riid
))
448 *ppvObject
= (IPicture
*)This
;
449 else if (IsEqualIID(&IID_IDispatch
, riid
))
450 *ppvObject
= (IDispatch
*)&(This
->lpvtblIDispatch
);
451 else if (IsEqualIID(&IID_IPictureDisp
, riid
))
452 *ppvObject
= (IDispatch
*)&(This
->lpvtblIDispatch
);
453 else if (IsEqualIID(&IID_IPersist
, riid
) || IsEqualIID(&IID_IPersistStream
, riid
))
454 *ppvObject
= (IPersistStream
*)&(This
->lpvtblIPersistStream
);
455 else if (IsEqualIID(&IID_IConnectionPointContainer
, riid
))
456 *ppvObject
= (IConnectionPointContainer
*)&(This
->lpvtblIConnectionPointContainer
);
459 * Check that we obtained an interface.
463 FIXME("() : asking for un supported interface %s\n",debugstr_guid(riid
));
464 return E_NOINTERFACE
;
468 * Query Interface always increases the reference count by one when it is
471 OLEPictureImpl_AddRef((IPicture
*)This
);
476 /***********************************************************************
477 * OLEPicture_SendNotify (internal)
479 * Sends notification messages of changed properties to any interested
482 static void OLEPicture_SendNotify(OLEPictureImpl
* this, DISPID dispID
)
484 IEnumConnections
*pEnum
;
487 if (IConnectionPoint_EnumConnections(this->pCP
, &pEnum
))
489 while(IEnumConnections_Next(pEnum
, 1, &CD
, NULL
) == S_OK
) {
490 IPropertyNotifySink
*sink
;
492 IUnknown_QueryInterface(CD
.pUnk
, &IID_IPropertyNotifySink
, (LPVOID
)&sink
);
493 IPropertyNotifySink_OnChanged(sink
, dispID
);
494 IPropertyNotifySink_Release(sink
);
495 IUnknown_Release(CD
.pUnk
);
497 IEnumConnections_Release(pEnum
);
501 /************************************************************************
502 * OLEPictureImpl_get_Handle
504 static HRESULT WINAPI
OLEPictureImpl_get_Handle(IPicture
*iface
,
507 OLEPictureImpl
*This
= (OLEPictureImpl
*)iface
;
508 TRACE("(%p)->(%p)\n", This
, phandle
);
509 switch(This
->desc
.picType
) {
511 case PICTYPE_UNINITIALIZED
:
515 *phandle
= (OLE_HANDLE
)This
->desc
.u
.bmp
.hbitmap
;
517 case PICTYPE_METAFILE
:
518 *phandle
= (OLE_HANDLE
)This
->desc
.u
.wmf
.hmeta
;
521 *phandle
= (OLE_HANDLE
)This
->desc
.u
.icon
.hicon
;
523 case PICTYPE_ENHMETAFILE
:
524 *phandle
= (OLE_HANDLE
)This
->desc
.u
.emf
.hemf
;
527 FIXME("Unimplemented type %d\n", This
->desc
.picType
);
530 TRACE("returning handle %08x\n", *phandle
);
534 /************************************************************************
535 * OLEPictureImpl_get_hPal
537 static HRESULT WINAPI
OLEPictureImpl_get_hPal(IPicture
*iface
,
540 OLEPictureImpl
*This
= (OLEPictureImpl
*)iface
;
542 TRACE("(%p)->(%p)\n", This
, phandle
);
547 switch (This
->desc
.picType
) {
548 case (UINT
)PICTYPE_UNINITIALIZED
:
554 *phandle
= (OLE_HANDLE
)This
->desc
.u
.bmp
.hpal
;
558 case PICTYPE_METAFILE
:
559 case PICTYPE_ENHMETAFILE
:
561 FIXME("unimplemented for type %d. Returning 0 palette.\n",
567 TRACE("returning 0x%08x, palette handle %08x\n", hres
, *phandle
);
571 /************************************************************************
572 * OLEPictureImpl_get_Type
574 static HRESULT WINAPI
OLEPictureImpl_get_Type(IPicture
*iface
,
577 OLEPictureImpl
*This
= (OLEPictureImpl
*)iface
;
578 TRACE("(%p)->(%p): type is %d\n", This
, ptype
, This
->desc
.picType
);
579 *ptype
= This
->desc
.picType
;
583 /************************************************************************
584 * OLEPictureImpl_get_Width
586 static HRESULT WINAPI
OLEPictureImpl_get_Width(IPicture
*iface
,
587 OLE_XSIZE_HIMETRIC
*pwidth
)
589 OLEPictureImpl
*This
= (OLEPictureImpl
*)iface
;
590 TRACE("(%p)->(%p): width is %d\n", This
, pwidth
, This
->himetricWidth
);
591 *pwidth
= This
->himetricWidth
;
595 /************************************************************************
596 * OLEPictureImpl_get_Height
598 static HRESULT WINAPI
OLEPictureImpl_get_Height(IPicture
*iface
,
599 OLE_YSIZE_HIMETRIC
*pheight
)
601 OLEPictureImpl
*This
= (OLEPictureImpl
*)iface
;
602 TRACE("(%p)->(%p): height is %d\n", This
, pheight
, This
->himetricHeight
);
603 *pheight
= This
->himetricHeight
;
607 /************************************************************************
608 * OLEPictureImpl_Render
610 static HRESULT WINAPI
OLEPictureImpl_Render(IPicture
*iface
, HDC hdc
,
611 LONG x
, LONG y
, LONG cx
, LONG cy
,
612 OLE_XPOS_HIMETRIC xSrc
,
613 OLE_YPOS_HIMETRIC ySrc
,
614 OLE_XSIZE_HIMETRIC cxSrc
,
615 OLE_YSIZE_HIMETRIC cySrc
,
618 OLEPictureImpl
*This
= (OLEPictureImpl
*)iface
;
619 TRACE("(%p)->(%p, (%d,%d), (%d,%d) <- (%d,%d), (%d,%d), %p)\n",
620 This
, hdc
, x
, y
, cx
, cy
, xSrc
, ySrc
, cxSrc
, cySrc
, prcWBounds
);
622 TRACE("prcWBounds (%d,%d) - (%d,%d)\n", prcWBounds
->left
, prcWBounds
->top
,
623 prcWBounds
->right
, prcWBounds
->bottom
);
626 * While the documentation suggests this to be here (or after rendering?)
627 * it does cause an endless recursion in my sample app. -MM 20010804
628 OLEPicture_SendNotify(This,DISPID_PICT_RENDER);
631 switch(This
->desc
.picType
) {
637 /* Set a mapping mode that maps bitmap pixels into HIMETRIC units.
638 NB y-axis gets flipped */
640 hdcBmp
= CreateCompatibleDC(0);
641 SetMapMode(hdcBmp
, MM_ANISOTROPIC
);
642 SetWindowOrgEx(hdcBmp
, 0, 0, NULL
);
643 SetWindowExtEx(hdcBmp
, This
->himetricWidth
, This
->himetricHeight
, NULL
);
644 SetViewportOrgEx(hdcBmp
, 0, This
->origHeight
, NULL
);
645 SetViewportExtEx(hdcBmp
, This
->origWidth
, -This
->origHeight
, NULL
);
648 HDC hdcMask
= CreateCompatibleDC(0);
649 HBITMAP hOldbm
= SelectObject(hdcMask
, This
->hbmMask
);
651 hbmpOld
= SelectObject(hdcBmp
, This
->hbmXor
);
653 SetMapMode(hdcMask
, MM_ANISOTROPIC
);
654 SetWindowOrgEx(hdcMask
, 0, 0, NULL
);
655 SetWindowExtEx(hdcMask
, This
->himetricWidth
, This
->himetricHeight
, NULL
);
656 SetViewportOrgEx(hdcMask
, 0, This
->origHeight
, NULL
);
657 SetViewportExtEx(hdcMask
, This
->origWidth
, -This
->origHeight
, NULL
);
659 SetBkColor(hdc
, RGB(255, 255, 255));
660 SetTextColor(hdc
, RGB(0, 0, 0));
661 StretchBlt(hdc
, x
, y
, cx
, cy
, hdcMask
, xSrc
, ySrc
, cxSrc
, cySrc
, SRCAND
);
662 StretchBlt(hdc
, x
, y
, cx
, cy
, hdcBmp
, xSrc
, ySrc
, cxSrc
, cySrc
, SRCPAINT
);
664 SelectObject(hdcMask
, hOldbm
);
667 hbmpOld
= SelectObject(hdcBmp
, This
->desc
.u
.bmp
.hbitmap
);
668 StretchBlt(hdc
, x
, y
, cx
, cy
, hdcBmp
, xSrc
, ySrc
, cxSrc
, cySrc
, SRCCOPY
);
671 SelectObject(hdcBmp
, hbmpOld
);
676 FIXME("Not quite correct implementation of rendering icons...\n");
677 DrawIcon(hdc
,x
,y
,This
->desc
.u
.icon
.hicon
);
680 case PICTYPE_METAFILE
:
681 PlayMetaFile(hdc
, This
->desc
.u
.wmf
.hmeta
);
684 case PICTYPE_ENHMETAFILE
:
686 RECT rc
= { x
, y
, x
+ cx
, y
+ cy
};
687 PlayEnhMetaFile(hdc
, This
->desc
.u
.emf
.hemf
, &rc
);
692 FIXME("type %d not implemented\n", This
->desc
.picType
);
698 /************************************************************************
699 * OLEPictureImpl_set_hPal
701 static HRESULT WINAPI
OLEPictureImpl_set_hPal(IPicture
*iface
,
704 OLEPictureImpl
*This
= (OLEPictureImpl
*)iface
;
705 FIXME("(%p)->(%08x): stub\n", This
, hpal
);
706 OLEPicture_SendNotify(This
,DISPID_PICT_HPAL
);
710 /************************************************************************
711 * OLEPictureImpl_get_CurDC
713 static HRESULT WINAPI
OLEPictureImpl_get_CurDC(IPicture
*iface
,
716 OLEPictureImpl
*This
= (OLEPictureImpl
*)iface
;
717 TRACE("(%p), returning %p\n", This
, This
->hDCCur
);
718 if (phdc
) *phdc
= This
->hDCCur
;
722 /************************************************************************
723 * OLEPictureImpl_SelectPicture
725 static HRESULT WINAPI
OLEPictureImpl_SelectPicture(IPicture
*iface
,
728 OLE_HANDLE
*phbmpOut
)
730 OLEPictureImpl
*This
= (OLEPictureImpl
*)iface
;
731 TRACE("(%p)->(%p, %p, %p)\n", This
, hdcIn
, phdcOut
, phbmpOut
);
732 if (This
->desc
.picType
== PICTYPE_BITMAP
) {
733 SelectObject(hdcIn
,This
->desc
.u
.bmp
.hbitmap
);
736 *phdcOut
= This
->hDCCur
;
737 This
->hDCCur
= hdcIn
;
739 *phbmpOut
= (OLE_HANDLE
)This
->desc
.u
.bmp
.hbitmap
;
742 FIXME("Don't know how to select picture type %d\n",This
->desc
.picType
);
747 /************************************************************************
748 * OLEPictureImpl_get_KeepOriginalFormat
750 static HRESULT WINAPI
OLEPictureImpl_get_KeepOriginalFormat(IPicture
*iface
,
753 OLEPictureImpl
*This
= (OLEPictureImpl
*)iface
;
754 TRACE("(%p)->(%p)\n", This
, pfKeep
);
757 *pfKeep
= This
->keepOrigFormat
;
761 /************************************************************************
762 * OLEPictureImpl_put_KeepOriginalFormat
764 static HRESULT WINAPI
OLEPictureImpl_put_KeepOriginalFormat(IPicture
*iface
,
767 OLEPictureImpl
*This
= (OLEPictureImpl
*)iface
;
768 TRACE("(%p)->(%d)\n", This
, keep
);
769 This
->keepOrigFormat
= keep
;
770 /* FIXME: what DISPID notification here? */
774 /************************************************************************
775 * OLEPictureImpl_PictureChanged
777 static HRESULT WINAPI
OLEPictureImpl_PictureChanged(IPicture
*iface
)
779 OLEPictureImpl
*This
= (OLEPictureImpl
*)iface
;
780 TRACE("(%p)->()\n", This
);
781 OLEPicture_SendNotify(This
,DISPID_PICT_HANDLE
);
782 This
->bIsDirty
= TRUE
;
786 /************************************************************************
787 * OLEPictureImpl_SaveAsFile
789 static HRESULT WINAPI
OLEPictureImpl_SaveAsFile(IPicture
*iface
,
794 OLEPictureImpl
*This
= (OLEPictureImpl
*)iface
;
795 FIXME("(%p)->(%p, %d, %p), hacked stub.\n", This
, pstream
, SaveMemCopy
, pcbSize
);
796 return IStream_Write(pstream
,This
->data
,This
->datalen
,(ULONG
*)pcbSize
);
799 /************************************************************************
800 * OLEPictureImpl_get_Attributes
802 static HRESULT WINAPI
OLEPictureImpl_get_Attributes(IPicture
*iface
,
805 OLEPictureImpl
*This
= (OLEPictureImpl
*)iface
;
806 TRACE("(%p)->(%p).\n", This
, pdwAttr
);
808 switch (This
->desc
.picType
) {
809 case PICTYPE_BITMAP
: if (This
->hbmMask
) *pdwAttr
= PICTURE_TRANSPARENT
; break; /* not 'truly' scalable, see MSDN. */
810 case PICTYPE_ICON
: *pdwAttr
= PICTURE_TRANSPARENT
;break;
811 case PICTYPE_ENHMETAFILE
: /* fall through */
812 case PICTYPE_METAFILE
: *pdwAttr
= PICTURE_TRANSPARENT
|PICTURE_SCALABLE
;break;
813 default:FIXME("Unknown pictype %d\n",This
->desc
.picType
);break;
819 /************************************************************************
820 * IConnectionPointContainer
822 static HRESULT WINAPI
OLEPictureImpl_IConnectionPointContainer_QueryInterface(
823 IConnectionPointContainer
* iface
,
827 OLEPictureImpl
*This
= impl_from_IConnectionPointContainer(iface
);
829 return IPicture_QueryInterface((IPicture
*)This
,riid
,ppvoid
);
832 static ULONG WINAPI
OLEPictureImpl_IConnectionPointContainer_AddRef(
833 IConnectionPointContainer
* iface
)
835 OLEPictureImpl
*This
= impl_from_IConnectionPointContainer(iface
);
837 return IPicture_AddRef((IPicture
*)This
);
840 static ULONG WINAPI
OLEPictureImpl_IConnectionPointContainer_Release(
841 IConnectionPointContainer
* iface
)
843 OLEPictureImpl
*This
= impl_from_IConnectionPointContainer(iface
);
845 return IPicture_Release((IPicture
*)This
);
848 static HRESULT WINAPI
OLEPictureImpl_EnumConnectionPoints(
849 IConnectionPointContainer
* iface
,
850 IEnumConnectionPoints
** ppEnum
)
852 OLEPictureImpl
*This
= impl_from_IConnectionPointContainer(iface
);
854 FIXME("(%p,%p), stub!\n",This
,ppEnum
);
858 static HRESULT WINAPI
OLEPictureImpl_FindConnectionPoint(
859 IConnectionPointContainer
* iface
,
861 IConnectionPoint
**ppCP
)
863 OLEPictureImpl
*This
= impl_from_IConnectionPointContainer(iface
);
864 TRACE("(%p,%s,%p)\n",This
,debugstr_guid(riid
),ppCP
);
868 if (IsEqualGUID(riid
,&IID_IPropertyNotifySink
))
869 return IConnectionPoint_QueryInterface(This
->pCP
,&IID_IConnectionPoint
,(LPVOID
)ppCP
);
870 FIXME("no connection point for %s\n",debugstr_guid(riid
));
871 return CONNECT_E_NOCONNECTION
;
875 /************************************************************************
879 /************************************************************************
880 * OLEPictureImpl_IPersistStream_QueryInterface (IUnknown)
882 * See Windows documentation for more details on IUnknown methods.
884 static HRESULT WINAPI
OLEPictureImpl_IPersistStream_QueryInterface(
885 IPersistStream
* iface
,
889 OLEPictureImpl
*This
= impl_from_IPersistStream(iface
);
891 return IPicture_QueryInterface((IPicture
*)This
, riid
, ppvoid
);
894 /************************************************************************
895 * OLEPictureImpl_IPersistStream_AddRef (IUnknown)
897 * See Windows documentation for more details on IUnknown methods.
899 static ULONG WINAPI
OLEPictureImpl_IPersistStream_AddRef(
900 IPersistStream
* iface
)
902 OLEPictureImpl
*This
= impl_from_IPersistStream(iface
);
904 return IPicture_AddRef((IPicture
*)This
);
907 /************************************************************************
908 * OLEPictureImpl_IPersistStream_Release (IUnknown)
910 * See Windows documentation for more details on IUnknown methods.
912 static ULONG WINAPI
OLEPictureImpl_IPersistStream_Release(
913 IPersistStream
* iface
)
915 OLEPictureImpl
*This
= impl_from_IPersistStream(iface
);
917 return IPicture_Release((IPicture
*)This
);
920 /************************************************************************
921 * OLEPictureImpl_IPersistStream_GetClassID
923 static HRESULT WINAPI
OLEPictureImpl_GetClassID(
924 IPersistStream
* iface
,CLSID
* pClassID
)
926 TRACE("(%p)\n", pClassID
);
927 memcpy(pClassID
, &CLSID_StdPicture
, sizeof(*pClassID
));
931 /************************************************************************
932 * OLEPictureImpl_IPersistStream_IsDirty
934 static HRESULT WINAPI
OLEPictureImpl_IsDirty(
935 IPersistStream
* iface
)
937 OLEPictureImpl
*This
= impl_from_IPersistStream(iface
);
938 FIXME("(%p),stub!\n",This
);
942 #ifdef SONAME_LIBJPEG
944 static void *libjpeg_handle
;
945 #define MAKE_FUNCPTR(f) static typeof(f) * p##f
946 MAKE_FUNCPTR(jpeg_std_error
);
947 MAKE_FUNCPTR(jpeg_CreateDecompress
);
948 MAKE_FUNCPTR(jpeg_read_header
);
949 MAKE_FUNCPTR(jpeg_start_decompress
);
950 MAKE_FUNCPTR(jpeg_read_scanlines
);
951 MAKE_FUNCPTR(jpeg_finish_decompress
);
952 MAKE_FUNCPTR(jpeg_destroy_decompress
);
955 static void *load_libjpeg(void)
957 if((libjpeg_handle
= wine_dlopen(SONAME_LIBJPEG
, RTLD_NOW
, NULL
, 0)) != NULL
) {
959 #define LOAD_FUNCPTR(f) \
960 if((p##f = wine_dlsym(libjpeg_handle, #f, NULL, 0)) == NULL) { \
961 libjpeg_handle = NULL; \
965 LOAD_FUNCPTR(jpeg_std_error
);
966 LOAD_FUNCPTR(jpeg_CreateDecompress
);
967 LOAD_FUNCPTR(jpeg_read_header
);
968 LOAD_FUNCPTR(jpeg_start_decompress
);
969 LOAD_FUNCPTR(jpeg_read_scanlines
);
970 LOAD_FUNCPTR(jpeg_finish_decompress
);
971 LOAD_FUNCPTR(jpeg_destroy_decompress
);
974 return libjpeg_handle
;
977 /* for the jpeg decompressor source manager. */
978 static void _jpeg_init_source(j_decompress_ptr cinfo
) { }
980 static boolean
_jpeg_fill_input_buffer(j_decompress_ptr cinfo
) {
981 ERR("(), should not get here.\n");
985 static void _jpeg_skip_input_data(j_decompress_ptr cinfo
,long num_bytes
) {
986 TRACE("Skipping %ld bytes...\n", num_bytes
);
987 cinfo
->src
->next_input_byte
+= num_bytes
;
988 cinfo
->src
->bytes_in_buffer
-= num_bytes
;
991 static boolean
_jpeg_resync_to_restart(j_decompress_ptr cinfo
, int desired
) {
992 ERR("(desired=%d), should not get here.\n",desired
);
995 static void _jpeg_term_source(j_decompress_ptr cinfo
) { }
996 #endif /* SONAME_LIBJPEG */
1000 unsigned int curoff
;
1004 static int _gif_inputfunc(GifFileType
*gif
, GifByteType
*data
, int len
) {
1005 struct gifdata
*gd
= (struct gifdata
*)gif
->UserData
;
1007 if (len
+gd
->curoff
> gd
->len
) {
1008 FIXME("Trying to read %d bytes, but only %d available.\n",len
, gd
->len
-gd
->curoff
);
1009 len
= gd
->len
- gd
->curoff
;
1011 memcpy(data
, gd
->data
+gd
->curoff
, len
);
1017 static HRESULT
OLEPictureImpl_LoadGif(OLEPictureImpl
*This
, BYTE
*xbuf
, ULONG xread
)
1028 int transparent
= -1;
1035 gif
= DGifOpen((void*)&gd
, _gif_inputfunc
);
1036 ret
= DGifSlurp(gif
);
1037 if (ret
== GIF_ERROR
) {
1038 FIXME("Failed reading GIF using libgif.\n");
1041 TRACE("screen height %d, width %d\n", gif
->SWidth
, gif
->SHeight
);
1042 TRACE("color res %d, backgcolor %d\n", gif
->SColorResolution
, gif
->SBackGroundColor
);
1043 TRACE("imgcnt %d\n", gif
->ImageCount
);
1044 if (gif
->ImageCount
<1) {
1045 FIXME("GIF stream does not have images inside?\n");
1048 TRACE("curimage: %d x %d, on %dx%d, interlace %d\n",
1049 gif
->Image
.Width
, gif
->Image
.Height
,
1050 gif
->Image
.Left
, gif
->Image
.Top
,
1051 gif
->Image
.Interlace
1054 padding
= (gif
->SWidth
+3) & ~3;
1055 si
= gif
->SavedImages
+0;
1056 gid
= &(si
->ImageDesc
);
1058 if (!cm
) cm
= gif
->SColorMap
;
1059 bmi
= HeapAlloc(GetProcessHeap(),0,sizeof(BITMAPINFOHEADER
)+(cm
->ColorCount
)*sizeof(RGBQUAD
));
1060 bytes
= HeapAlloc(GetProcessHeap(),0,padding
*gif
->SHeight
);
1062 /* look for the transparent color extension */
1063 for (i
= 0; i
< si
->ExtensionBlockCount
; ++i
) {
1064 eb
= si
->ExtensionBlocks
+ i
;
1065 if (eb
->Function
== 0xF9 && eb
->ByteCount
== 4) {
1066 if ((eb
->Bytes
[0] & 1) == 1) {
1067 transparent
= (unsigned char)eb
->Bytes
[3];
1072 for (i
= 0; i
< cm
->ColorCount
; i
++) {
1073 bmi
->bmiColors
[i
].rgbRed
= cm
->Colors
[i
].Red
;
1074 bmi
->bmiColors
[i
].rgbGreen
= cm
->Colors
[i
].Green
;
1075 bmi
->bmiColors
[i
].rgbBlue
= cm
->Colors
[i
].Blue
;
1076 if (i
== transparent
) {
1077 This
->rgbTrans
= RGB(bmi
->bmiColors
[i
].rgbRed
,
1078 bmi
->bmiColors
[i
].rgbGreen
,
1079 bmi
->bmiColors
[i
].rgbBlue
);
1083 /* Map to in picture coordinates */
1084 for (i
= 0, j
= 0; i
< gid
->Height
; i
++) {
1085 if (gif
->Image
.Interlace
) {
1087 bytes
+ (gid
->Top
+ j
) * padding
+ gid
->Left
,
1088 si
->RasterBits
+ i
* gid
->Width
,
1091 /* Lower bits of interlaced counter encode current interlace */
1092 if (j
& 1) j
+= 2; /* Currently filling odd rows */
1093 else if (j
& 2) j
+= 4; /* Currently filling even rows not multiples of 4 */
1094 else j
+= 8; /* Currently filling every 8th row or 4th row in-between */
1096 if (j
>= gid
->Height
&& i
< gid
->Height
&& (j
& 1) == 0) {
1097 /* End of current interlace, go to next interlace */
1098 if (j
& 2) j
= 1; /* Next iteration fills odd rows */
1099 else if (j
& 4) j
= 2; /* Next iteration fills even rows not mod 4 and not mod 8 */
1100 else j
= 4; /* Next iteration fills rows in-between rows mod 6 */
1104 bytes
+ (gid
->Top
+ i
) * padding
+ gid
->Left
,
1105 si
->RasterBits
+ i
* gid
->Width
,
1110 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1111 bmi
->bmiHeader
.biWidth
= gif
->SWidth
;
1112 bmi
->bmiHeader
.biHeight
= -gif
->SHeight
;
1113 bmi
->bmiHeader
.biPlanes
= 1;
1114 bmi
->bmiHeader
.biBitCount
= 8;
1115 bmi
->bmiHeader
.biCompression
= BI_RGB
;
1116 bmi
->bmiHeader
.biSizeImage
= padding
*gif
->SHeight
;
1117 bmi
->bmiHeader
.biXPelsPerMeter
= 0;
1118 bmi
->bmiHeader
.biYPelsPerMeter
= 0;
1119 bmi
->bmiHeader
.biClrUsed
= cm
->ColorCount
;
1120 bmi
->bmiHeader
.biClrImportant
= 0;
1123 This
->desc
.u
.bmp
.hbitmap
=CreateDIBitmap(
1132 if (transparent
> -1) {
1133 /* Create the Mask */
1134 HDC hdc
= CreateCompatibleDC(0);
1135 HDC hdcMask
= CreateCompatibleDC(0);
1137 HBITMAP hOldbitmapmask
;
1139 unsigned int monopadding
= (((unsigned)(gif
->SWidth
+ 31)) >> 5) << 2;
1142 This
->hbmXor
= CreateDIBitmap(
1151 bmi
->bmiColors
[0].rgbRed
= 0;
1152 bmi
->bmiColors
[0].rgbGreen
= 0;
1153 bmi
->bmiColors
[0].rgbBlue
= 0;
1154 bmi
->bmiColors
[1].rgbRed
= 255;
1155 bmi
->bmiColors
[1].rgbGreen
= 255;
1156 bmi
->bmiColors
[1].rgbBlue
= 255;
1158 bmi
->bmiHeader
.biBitCount
= 1;
1159 bmi
->bmiHeader
.biSizeImage
= monopadding
*gif
->SHeight
;
1160 bmi
->bmiHeader
.biClrUsed
= 2;
1162 for (i
= 0; i
< gif
->SHeight
; i
++) {
1163 unsigned char * colorPointer
= bytes
+ padding
* i
;
1164 unsigned char * monoPointer
= bytes
+ monopadding
* i
;
1165 for (j
= 0; j
< gif
->SWidth
; j
++) {
1166 unsigned char pixel
= colorPointer
[j
];
1167 if ((j
& 7) == 0) monoPointer
[j
>> 3] = 0;
1168 if (pixel
== (transparent
& 0x000000FFU
)) monoPointer
[j
>> 3] |= 1 << (7 - (j
& 7));
1172 hTempMask
= CreateDIBitmap(
1182 bmi
->bmiHeader
.biHeight
= -bmi
->bmiHeader
.biHeight
;
1183 This
->hbmMask
= CreateBitmap(bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
, 1, 1, NULL
);
1184 hOldbitmap
= SelectObject(hdc
, hTempMask
);
1185 hOldbitmapmask
= SelectObject(hdcMask
, This
->hbmMask
);
1187 SetBkColor(hdc
, RGB(255, 255, 255));
1188 BitBlt(hdcMask
, 0, 0, bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
, hdc
, 0, 0, SRCCOPY
);
1190 /* We no longer need the original bitmap, so we apply the first
1191 transformation with the mask to speed up the rendering */
1192 SelectObject(hdc
, This
->hbmXor
);
1193 SetBkColor(hdc
, RGB(0,0,0));
1194 SetTextColor(hdc
, RGB(255,255,255));
1195 BitBlt(hdc
, 0, 0, bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
1196 hdcMask
, 0, 0, SRCAND
);
1198 SelectObject(hdc
, hOldbitmap
);
1199 SelectObject(hdcMask
, hOldbitmapmask
);
1202 DeleteObject(hTempMask
);
1206 This
->desc
.picType
= PICTYPE_BITMAP
;
1207 OLEPictureImpl_SetBitmap(This
);
1209 HeapFree(GetProcessHeap(),0,bytes
);
1213 static HRESULT
OLEPictureImpl_LoadJpeg(OLEPictureImpl
*This
, BYTE
*xbuf
, ULONG xread
)
1215 #ifdef SONAME_LIBJPEG
1216 struct jpeg_decompress_struct jd
;
1217 struct jpeg_error_mgr jerr
;
1220 JSAMPROW samprow
,oldsamprow
;
1221 BITMAPINFOHEADER bmi
;
1224 struct jpeg_source_mgr xjsm
;
1228 if(!libjpeg_handle
) {
1229 if(!load_libjpeg()) {
1230 FIXME("Failed reading JPEG because unable to find %s\n", SONAME_LIBJPEG
);
1235 /* This is basically so we can use in-memory data for jpeg decompression.
1236 * We need to have all the functions.
1238 xjsm
.next_input_byte
= xbuf
;
1239 xjsm
.bytes_in_buffer
= xread
;
1240 xjsm
.init_source
= _jpeg_init_source
;
1241 xjsm
.fill_input_buffer
= _jpeg_fill_input_buffer
;
1242 xjsm
.skip_input_data
= _jpeg_skip_input_data
;
1243 xjsm
.resync_to_restart
= _jpeg_resync_to_restart
;
1244 xjsm
.term_source
= _jpeg_term_source
;
1246 jd
.err
= pjpeg_std_error(&jerr
);
1247 /* jpeg_create_decompress is a macro that expands to jpeg_CreateDecompress - see jpeglib.h
1248 * jpeg_create_decompress(&jd); */
1249 pjpeg_CreateDecompress(&jd
, JPEG_LIB_VERSION
, (size_t) sizeof(struct jpeg_decompress_struct
));
1251 ret
=pjpeg_read_header(&jd
,TRUE
);
1252 jd
.out_color_space
= JCS_RGB
;
1253 pjpeg_start_decompress(&jd
);
1254 if (ret
!= JPEG_HEADER_OK
) {
1255 ERR("Jpeg image in stream has bad format, read header returned %d.\n",ret
);
1256 HeapFree(GetProcessHeap(),0,xbuf
);
1260 bits
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,
1261 (jd
.output_height
+1) * ((jd
.output_width
*jd
.output_components
+ 3) & ~3) );
1262 samprow
=HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,jd
.output_width
*jd
.output_components
);
1265 oldsamprow
= samprow
;
1266 while ( jd
.output_scanline
<jd
.output_height
) {
1267 x
= pjpeg_read_scanlines(&jd
,&samprow
,1);
1269 FIXME("failed to read current scanline?\n");
1272 /* We have to convert from RGB to BGR, see MSDN/ BITMAPINFOHEADER */
1273 for(i
=0;i
<jd
.output_width
;i
++,samprow
+=jd
.output_components
) {
1274 *(bits
++) = *(samprow
+2);
1275 *(bits
++) = *(samprow
+1);
1276 *(bits
++) = *(samprow
);
1278 bits
= (LPBYTE
)(((UINT_PTR
)bits
+ 3) & ~3);
1279 samprow
= oldsamprow
;
1283 bmi
.biSize
= sizeof(bmi
);
1284 bmi
.biWidth
= jd
.output_width
;
1285 bmi
.biHeight
= -jd
.output_height
;
1287 bmi
.biBitCount
= jd
.output_components
<<3;
1288 bmi
.biCompression
= BI_RGB
;
1289 bmi
.biSizeImage
= jd
.output_height
*jd
.output_width
*jd
.output_components
;
1290 bmi
.biXPelsPerMeter
= 0;
1291 bmi
.biYPelsPerMeter
= 0;
1293 bmi
.biClrImportant
= 0;
1295 HeapFree(GetProcessHeap(),0,samprow
);
1296 pjpeg_finish_decompress(&jd
);
1297 pjpeg_destroy_decompress(&jd
);
1299 This
->desc
.u
.bmp
.hbitmap
=CreateDIBitmap(
1308 This
->desc
.picType
= PICTYPE_BITMAP
;
1309 OLEPictureImpl_SetBitmap(This
);
1310 HeapFree(GetProcessHeap(),0,bits
);
1313 ERR("Trying to load JPEG picture, but JPEG supported not compiled in.\n");
1318 static HRESULT
OLEPictureImpl_LoadDIB(OLEPictureImpl
*This
, BYTE
*xbuf
, ULONG xread
)
1320 BITMAPFILEHEADER
*bfh
= (BITMAPFILEHEADER
*)xbuf
;
1321 BITMAPINFO
*bi
= (BITMAPINFO
*)(bfh
+1);
1324 /* Does not matter whether this is a coreheader or not, we only use
1325 * components which are in both
1328 This
->desc
.u
.bmp
.hbitmap
= CreateDIBitmap(
1332 xbuf
+bfh
->bfOffBits
,
1337 This
->desc
.picType
= PICTYPE_BITMAP
;
1338 OLEPictureImpl_SetBitmap(This
);
1342 /*****************************************************
1343 * start of PNG-specific code
1344 * currently only supports colortype PNG_COLOR_TYPE_RGB
1346 #ifdef SONAME_LIBPNG
1353 static void png_stream_read_data(png_structp png_ptr
, png_bytep data
,
1356 png_io
* io_ptr
= png_ptr
->io_ptr
;
1358 if(length
+ io_ptr
->position
> io_ptr
->size
){
1359 length
= io_ptr
->size
- io_ptr
->position
;
1362 memcpy(data
, io_ptr
->buff
+ io_ptr
->position
, length
);
1364 io_ptr
->position
+= length
;
1367 static void *libpng_handle
;
1368 #define MAKE_FUNCPTR(f) static typeof(f) * p##f
1369 MAKE_FUNCPTR(png_create_read_struct
);
1370 MAKE_FUNCPTR(png_create_info_struct
);
1371 MAKE_FUNCPTR(png_set_read_fn
);
1372 MAKE_FUNCPTR(png_read_info
);
1373 MAKE_FUNCPTR(png_read_image
);
1374 MAKE_FUNCPTR(png_get_rowbytes
);
1375 MAKE_FUNCPTR(png_set_bgr
);
1376 MAKE_FUNCPTR(png_destroy_read_struct
);
1377 MAKE_FUNCPTR(png_set_palette_to_rgb
);
1378 MAKE_FUNCPTR(png_read_update_info
);
1381 static void *load_libpng(void)
1383 if((libpng_handle
= wine_dlopen(SONAME_LIBPNG
, RTLD_NOW
, NULL
, 0)) != NULL
) {
1385 #define LOAD_FUNCPTR(f) \
1386 if((p##f = wine_dlsym(libpng_handle, #f, NULL, 0)) == NULL) { \
1387 libpng_handle = NULL; \
1390 LOAD_FUNCPTR(png_create_read_struct
);
1391 LOAD_FUNCPTR(png_create_info_struct
);
1392 LOAD_FUNCPTR(png_set_read_fn
);
1393 LOAD_FUNCPTR(png_read_info
);
1394 LOAD_FUNCPTR(png_read_image
);
1395 LOAD_FUNCPTR(png_get_rowbytes
);
1396 LOAD_FUNCPTR(png_set_bgr
);
1397 LOAD_FUNCPTR(png_destroy_read_struct
);
1398 LOAD_FUNCPTR(png_set_palette_to_rgb
);
1399 LOAD_FUNCPTR(png_read_update_info
);
1403 return libpng_handle
;
1405 #endif /* SONAME_LIBPNG */
1407 static HRESULT
OLEPictureImpl_LoadPNG(OLEPictureImpl
*This
, BYTE
*xbuf
, ULONG xread
)
1409 #ifdef SONAME_LIBPNG
1411 png_structp png_ptr
= NULL
;
1412 png_infop info_ptr
= NULL
;
1413 INT row
, rowsize
, height
, width
;
1414 png_bytep
* row_pointers
= NULL
;
1415 png_bytep pngdata
= NULL
;
1416 BITMAPINFOHEADER bmi
;
1419 BOOL set_bgr
= FALSE
;
1421 if(!libpng_handle
) {
1422 if(!load_libpng()) {
1423 ERR("Failed reading PNG because unable to find %s\n",SONAME_LIBPNG
);
1432 png_ptr
= ppng_create_read_struct(PNG_LIBPNG_VER_STRING
,
1435 if(setjmp(png_jmpbuf(png_ptr
))){
1436 TRACE("Error in libpng\n");
1441 info_ptr
= ppng_create_info_struct(png_ptr
);
1442 ppng_set_read_fn(png_ptr
, &io
, png_stream_read_data
);
1443 ppng_read_info(png_ptr
, info_ptr
);
1445 if(!(png_ptr
->color_type
== PNG_COLOR_TYPE_RGB
||
1446 png_ptr
->color_type
== PNG_COLOR_TYPE_PALETTE
)){
1447 FIXME("Unsupported .PNG type: %d\n", png_ptr
->color_type
);
1452 if (png_ptr
->color_type
== PNG_COLOR_TYPE_PALETTE
){
1453 ppng_set_palette_to_rgb(png_ptr
);
1457 if (png_ptr
->color_type
== PNG_COLOR_TYPE_RGB
||
1458 png_ptr
->color_type
== PNG_COLOR_TYPE_RGB_ALPHA
||
1460 ppng_set_bgr(png_ptr
);
1463 ppng_read_update_info(png_ptr
, info_ptr
);
1465 rowsize
= ppng_get_rowbytes(png_ptr
, info_ptr
);
1466 /* align rowsize to 4-byte boundary */
1467 rowsize
= (rowsize
+ 3) & ~3;
1468 height
= info_ptr
->height
;
1469 width
= info_ptr
->width
;
1471 pngdata
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, height
* rowsize
);
1472 row_pointers
= HeapAlloc(GetProcessHeap(), 0, height
* (sizeof(VOID
*)));
1474 if(!pngdata
|| !row_pointers
){
1479 for (row
= 0; row
< height
; row
++){
1480 row_pointers
[row
] = pngdata
+ row
* rowsize
;
1483 ppng_read_image(png_ptr
, row_pointers
);
1485 bmi
.biSize
= sizeof(bmi
);
1486 bmi
.biWidth
= width
;
1487 bmi
.biHeight
= -height
;
1489 bmi
.biBitCount
= info_ptr
->channels
* 8;
1490 bmi
.biCompression
= BI_RGB
;
1491 bmi
.biSizeImage
= height
* rowsize
;
1492 bmi
.biXPelsPerMeter
= 0;
1493 bmi
.biYPelsPerMeter
= 0;
1495 bmi
.biClrImportant
= 0;
1498 This
->desc
.u
.bmp
.hbitmap
= CreateDIBitmap(
1506 ReleaseDC(0, hdcref
);
1507 This
->desc
.picType
= PICTYPE_BITMAP
;
1508 OLEPictureImpl_SetBitmap(This
);
1513 ppng_destroy_read_struct(&png_ptr
,
1514 (info_ptr
? &info_ptr
: (png_infopp
) NULL
),
1516 HeapFree(GetProcessHeap(), 0, row_pointers
);
1517 HeapFree(GetProcessHeap(), 0, pngdata
);
1519 #else /* SONAME_LIBPNG */
1520 ERR("Trying to load PNG picture, but PNG supported not compiled in.\n");
1525 /*****************************************************
1526 * start of Icon-specific code
1529 static HRESULT
OLEPictureImpl_LoadIcon(OLEPictureImpl
*This
, BYTE
*xbuf
, ULONG xread
)
1532 CURSORICONFILEDIR
*cifd
= (CURSORICONFILEDIR
*)xbuf
;
1537 FIXME("icon.idReserved=%d\n",cifd->idReserved);
1538 FIXME("icon.idType=%d\n",cifd->idType);
1539 FIXME("icon.idCount=%d\n",cifd->idCount);
1541 for (i=0;i<cifd->idCount;i++) {
1542 FIXME("[%d] width %d\n",i,cifd->idEntries[i].bWidth);
1543 FIXME("[%d] height %d\n",i,cifd->idEntries[i].bHeight);
1544 FIXME("[%d] bColorCount %d\n",i,cifd->idEntries[i].bColorCount);
1545 FIXME("[%d] bReserved %d\n",i,cifd->idEntries[i].bReserved);
1546 FIXME("[%d] xHotspot %d\n",i,cifd->idEntries[i].xHotspot);
1547 FIXME("[%d] yHotspot %d\n",i,cifd->idEntries[i].yHotspot);
1548 FIXME("[%d] dwDIBSize %d\n",i,cifd->idEntries[i].dwDIBSize);
1549 FIXME("[%d] dwDIBOffset %d\n",i,cifd->idEntries[i].dwDIBOffset);
1553 /* If we have more than one icon, try to find the best.
1554 * this currently means '32 pixel wide'.
1556 if (cifd
->idCount
!=1) {
1557 for (i
=0;i
<cifd
->idCount
;i
++) {
1558 if (cifd
->idEntries
[i
].bWidth
== 32)
1561 if (i
==cifd
->idCount
) i
=0;
1564 hicon
= CreateIconFromResourceEx(
1565 xbuf
+cifd
->idEntries
[i
].dwDIBOffset
,
1566 cifd
->idEntries
[i
].dwDIBSize
,
1569 cifd
->idEntries
[i
].bWidth
,
1570 cifd
->idEntries
[i
].bHeight
,
1574 FIXME("CreateIcon failed.\n");
1577 This
->desc
.picType
= PICTYPE_ICON
;
1578 This
->desc
.u
.icon
.hicon
= hicon
;
1579 This
->origWidth
= cifd
->idEntries
[i
].bWidth
;
1580 This
->origHeight
= cifd
->idEntries
[i
].bHeight
;
1581 hdcRef
= CreateCompatibleDC(0);
1582 This
->himetricWidth
=(cifd
->idEntries
[i
].bWidth
*2540)/GetDeviceCaps(hdcRef
, LOGPIXELSX
);
1583 This
->himetricHeight
=(cifd
->idEntries
[i
].bHeight
*2540)/GetDeviceCaps(hdcRef
, LOGPIXELSY
);
1589 static HRESULT
OLEPictureImpl_LoadMetafile(OLEPictureImpl
*This
,
1590 const BYTE
*data
, ULONG size
)
1595 /* SetMetaFileBitsEx performs data check on its own */
1596 hmf
= SetMetaFileBitsEx(size
, data
);
1599 This
->desc
.picType
= PICTYPE_METAFILE
;
1600 This
->desc
.u
.wmf
.hmeta
= hmf
;
1601 This
->desc
.u
.wmf
.xExt
= 0;
1602 This
->desc
.u
.wmf
.yExt
= 0;
1604 This
->origWidth
= 0;
1605 This
->origHeight
= 0;
1606 This
->himetricWidth
= 0;
1607 This
->himetricHeight
= 0;
1612 hemf
= SetEnhMetaFileBits(size
, data
);
1613 if (!hemf
) return E_FAIL
;
1615 This
->desc
.picType
= PICTYPE_ENHMETAFILE
;
1616 This
->desc
.u
.emf
.hemf
= hemf
;
1618 This
->origWidth
= 0;
1619 This
->origHeight
= 0;
1620 This
->himetricWidth
= 0;
1621 This
->himetricHeight
= 0;
1626 /************************************************************************
1627 * OLEPictureImpl_IPersistStream_Load (IUnknown)
1629 * Loads the binary data from the IStream. Starts at current position.
1630 * There appears to be an 2 DWORD header:
1634 * Currently implemented: BITMAP, ICON, JPEG, GIF, WMF, EMF
1636 static HRESULT WINAPI
OLEPictureImpl_Load(IPersistStream
* iface
,IStream
*pStm
) {
1637 HRESULT hr
= E_FAIL
;
1638 BOOL headerisdata
= FALSE
;
1639 BOOL statfailed
= FALSE
;
1640 ULONG xread
, toread
;
1646 OLEPictureImpl
*This
= impl_from_IPersistStream(iface
);
1648 TRACE("(%p,%p)\n",This
,pStm
);
1650 /****************************************************************************************
1651 * Part 1: Load the data
1653 /* Sometimes we have a header, sometimes we don't. Apply some guesses to find
1654 * out whether we do.
1656 * UPDATE: the IStream can be mapped to a plain file instead of a stream in a
1657 * compound file. This may explain most, if not all, of the cases of "no
1658 * header", and the header validation should take this into account.
1659 * At least in Visual Basic 6, resource streams, valid headers are
1660 * header[0] == "lt\0\0",
1661 * header[1] == length_of_stream.
1663 * Also handle streams where we do not have a working "Stat" method by
1664 * reading all data until the end of the stream.
1666 hr
=IStream_Stat(pStm
,&statstg
,STATFLAG_NONAME
);
1668 TRACE("stat failed with hres %x, proceeding to read all data.\n",hr
);
1670 /* we will read at least 8 byte ... just right below */
1671 statstg
.cbSize
.QuadPart
= 8;
1676 headerisdata
= FALSE
;
1678 hr
=IStream_Read(pStm
,header
,8,&xread
);
1679 if (hr
|| xread
!=8) {
1680 FIXME("Failure while reading picture header (hr is %x, nread is %d).\n",hr
,xread
);
1683 headerread
+= xread
;
1686 if (!memcmp(&(header
[0]),"lt\0\0", 4) && (statfailed
|| (header
[1] + headerread
<= statstg
.cbSize
.QuadPart
))) {
1687 if (toread
!= 0 && toread
!= header
[1])
1688 FIXME("varying lengths of image data (prev=%u curr=%u), only last one will be used\n",
1691 if (toread
== 0) break;
1693 if (!memcmp(&(header
[0]), "GIF8", 4) || /* GIF header */
1694 !memcmp(&(header
[0]), "BM", 2) || /* BMP header */
1695 !memcmp(&(header
[0]), "\xff\xd8", 2) || /* JPEG header */
1696 (header
[0] == EMR_HEADER
) || /* EMF header */
1697 (header
[1] > statstg
.cbSize
.QuadPart
)|| /* invalid size */
1699 ) {/* Found start of bitmap data */
1700 headerisdata
= TRUE
;
1702 toread
= statstg
.cbSize
.QuadPart
-8;
1706 FIXME("Unknown stream header magic: %08x\n", header
[0]);
1710 } while (!headerisdata
);
1712 if (statfailed
) { /* we don't know the size ... read all we get */
1714 int origsize
= sizeinc
;
1717 TRACE("Reading all data from stream.\n");
1718 xbuf
= HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY
, origsize
);
1720 memcpy (xbuf
, &header
, 8);
1722 while (xread
< origsize
) {
1723 hr
= IStream_Read(pStm
,xbuf
+xread
,origsize
-xread
,&nread
);
1728 if (!nread
|| hr
) /* done, or error */
1730 if (xread
== origsize
) {
1731 origsize
+= sizeinc
;
1732 sizeinc
= 2*sizeinc
; /* exponential increase */
1733 xbuf
= HeapReAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY
, xbuf
, origsize
);
1737 TRACE("hr in no-stat loader case is %08x\n", hr
);
1738 TRACE("loaded %d bytes.\n", xread
);
1739 This
->datalen
= xread
;
1742 This
->datalen
= toread
+(headerisdata
?8:0);
1743 xbuf
= This
->data
= HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY
, This
->datalen
);
1746 memcpy (xbuf
, &header
, 8);
1748 while (xread
< This
->datalen
) {
1750 hr
= IStream_Read(pStm
,xbuf
+xread
,This
->datalen
-xread
,&nread
);
1755 if (xread
!= This
->datalen
)
1756 FIXME("Could only read %d of %d bytes out of stream?\n",xread
,This
->datalen
);
1758 if (This
->datalen
== 0) { /* Marks the "NONE" picture */
1759 This
->desc
.picType
= PICTYPE_NONE
;
1764 /****************************************************************************************
1765 * Part 2: Process the loaded data
1768 magic
= xbuf
[0] + (xbuf
[1]<<8);
1769 This
->loadtime_format
= magic
;
1772 case 0x4947: /* GIF */
1773 hr
= OLEPictureImpl_LoadGif(This
, xbuf
, xread
);
1775 case 0xd8ff: /* JPEG */
1776 hr
= OLEPictureImpl_LoadJpeg(This
, xbuf
, xread
);
1778 case 0x4d42: /* Bitmap */
1779 hr
= OLEPictureImpl_LoadDIB(This
, xbuf
, xread
);
1781 case 0x5089: /* PNG */
1782 hr
= OLEPictureImpl_LoadPNG(This
, xbuf
, xread
);
1784 case 0x0000: { /* ICON , first word is dwReserved */
1785 hr
= OLEPictureImpl_LoadIcon(This
, xbuf
, xread
);
1792 /* let's see if it's a metafile */
1793 hr
= OLEPictureImpl_LoadMetafile(This
, xbuf
, xread
);
1794 if (hr
== S_OK
) break;
1796 FIXME("Unknown magic %04x, %d read bytes:\n",magic
,xread
);
1798 for (i
=0;i
<xread
+8;i
++) {
1799 if (i
<8) MESSAGE("%02x ",((unsigned char*)&header
)[i
]);
1800 else MESSAGE("%02x ",xbuf
[i
-8]);
1801 if (i
% 10 == 9) MESSAGE("\n");
1807 This
->bIsDirty
= FALSE
;
1809 /* FIXME: this notify is not really documented */
1811 OLEPicture_SendNotify(This
,DISPID_PICT_TYPE
);
1815 static int serializeBMP(HBITMAP hBitmap
, void ** ppBuffer
, unsigned int * pLength
)
1819 BITMAPINFO
* pInfoBitmap
;
1820 int iNumPaletteEntries
;
1821 unsigned char * pPixelData
;
1822 BITMAPFILEHEADER
* pFileHeader
;
1823 BITMAPINFO
* pInfoHeader
;
1825 pInfoBitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1826 sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
1828 /* Find out bitmap size and padded length */
1830 pInfoBitmap
->bmiHeader
.biSize
= sizeof(pInfoBitmap
->bmiHeader
);
1831 GetDIBits(hDC
, hBitmap
, 0, 0, NULL
, pInfoBitmap
, DIB_RGB_COLORS
);
1833 /* Fetch bitmap palette & pixel data */
1835 pPixelData
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, pInfoBitmap
->bmiHeader
.biSizeImage
);
1836 GetDIBits(hDC
, hBitmap
, 0, pInfoBitmap
->bmiHeader
.biHeight
, pPixelData
, pInfoBitmap
, DIB_RGB_COLORS
);
1838 /* Calculate the total length required for the BMP data */
1839 if (pInfoBitmap
->bmiHeader
.biClrUsed
!= 0) {
1840 iNumPaletteEntries
= pInfoBitmap
->bmiHeader
.biClrUsed
;
1841 if (iNumPaletteEntries
> 256) iNumPaletteEntries
= 256;
1843 if (pInfoBitmap
->bmiHeader
.biBitCount
<= 8)
1844 iNumPaletteEntries
= 1 << pInfoBitmap
->bmiHeader
.biBitCount
;
1846 iNumPaletteEntries
= 0;
1849 sizeof(BITMAPFILEHEADER
) +
1850 sizeof(BITMAPINFOHEADER
) +
1851 iNumPaletteEntries
* sizeof(RGBQUAD
) +
1852 pInfoBitmap
->bmiHeader
.biSizeImage
;
1853 *ppBuffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, *pLength
);
1855 /* Fill the BITMAPFILEHEADER */
1856 pFileHeader
= (BITMAPFILEHEADER
*)(*ppBuffer
);
1857 pFileHeader
->bfType
= 0x4d42;
1858 pFileHeader
->bfSize
= *pLength
;
1859 pFileHeader
->bfOffBits
=
1860 sizeof(BITMAPFILEHEADER
) +
1861 sizeof(BITMAPINFOHEADER
) +
1862 iNumPaletteEntries
* sizeof(RGBQUAD
);
1864 /* Fill the BITMAPINFOHEADER and the palette data */
1865 pInfoHeader
= (BITMAPINFO
*)((unsigned char *)(*ppBuffer
) + sizeof(BITMAPFILEHEADER
));
1866 memcpy(pInfoHeader
, pInfoBitmap
, sizeof(BITMAPINFOHEADER
) + iNumPaletteEntries
* sizeof(RGBQUAD
));
1868 (unsigned char *)(*ppBuffer
) +
1869 sizeof(BITMAPFILEHEADER
) +
1870 sizeof(BITMAPINFOHEADER
) +
1871 iNumPaletteEntries
* sizeof(RGBQUAD
),
1872 pPixelData
, pInfoBitmap
->bmiHeader
.biSizeImage
);
1875 HeapFree(GetProcessHeap(), 0, pPixelData
);
1876 HeapFree(GetProcessHeap(), 0, pInfoBitmap
);
1880 static int serializeIcon(HICON hIcon
, void ** ppBuffer
, unsigned int * pLength
)
1885 *ppBuffer
= NULL
; *pLength
= 0;
1886 if (GetIconInfo(hIcon
, &infoIcon
)) {
1888 BITMAPINFO
* pInfoBitmap
;
1889 unsigned char * pIconData
= NULL
;
1890 unsigned int iDataSize
= 0;
1892 pInfoBitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
1894 /* Find out icon size */
1896 pInfoBitmap
->bmiHeader
.biSize
= sizeof(pInfoBitmap
->bmiHeader
);
1897 GetDIBits(hDC
, infoIcon
.hbmColor
, 0, 0, NULL
, pInfoBitmap
, DIB_RGB_COLORS
);
1899 /* Auxiliary pointers */
1900 CURSORICONFILEDIR
* pIconDir
;
1901 CURSORICONFILEDIRENTRY
* pIconEntry
;
1902 BITMAPINFOHEADER
* pIconBitmapHeader
;
1903 unsigned int iOffsetPalette
;
1904 unsigned int iOffsetColorData
;
1905 unsigned int iOffsetMaskData
;
1907 unsigned int iLengthScanLineColor
;
1908 unsigned int iLengthScanLineMask
;
1909 unsigned int iNumEntriesPalette
;
1911 iLengthScanLineMask
= ((pInfoBitmap
->bmiHeader
.biWidth
+ 31) >> 5) << 2;
1912 iLengthScanLineColor
= ((pInfoBitmap
->bmiHeader
.biWidth
* pInfoBitmap
->bmiHeader
.biBitCount
+ 31) >> 5) << 2;
1914 FIXME("DEBUG: bitmap size is %d x %d\n",
1915 pInfoBitmap->bmiHeader.biWidth,
1916 pInfoBitmap->bmiHeader.biHeight);
1917 FIXME("DEBUG: bitmap bpp is %d\n",
1918 pInfoBitmap->bmiHeader.biBitCount);
1919 FIXME("DEBUG: bitmap nplanes is %d\n",
1920 pInfoBitmap->bmiHeader.biPlanes);
1921 FIXME("DEBUG: bitmap biSizeImage is %u\n",
1922 pInfoBitmap->bmiHeader.biSizeImage);
1924 /* Let's start with one CURSORICONFILEDIR and one CURSORICONFILEDIRENTRY */
1925 iDataSize
+= 3 * sizeof(WORD
) + sizeof(CURSORICONFILEDIRENTRY
) + sizeof(BITMAPINFOHEADER
);
1926 pIconData
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, iDataSize
);
1928 /* Fill out the CURSORICONFILEDIR */
1929 pIconDir
= (CURSORICONFILEDIR
*)pIconData
;
1930 pIconDir
->idType
= 1;
1931 pIconDir
->idCount
= 1;
1933 /* Fill out the CURSORICONFILEDIRENTRY */
1934 pIconEntry
= (CURSORICONFILEDIRENTRY
*)(pIconData
+ 3 * sizeof(WORD
));
1935 pIconEntry
->bWidth
= (unsigned char)pInfoBitmap
->bmiHeader
.biWidth
;
1936 pIconEntry
->bHeight
= (unsigned char)pInfoBitmap
->bmiHeader
.biHeight
;
1937 pIconEntry
->bColorCount
=
1938 (pInfoBitmap
->bmiHeader
.biBitCount
< 8)
1939 ? 1 << pInfoBitmap
->bmiHeader
.biBitCount
1941 pIconEntry
->xHotspot
= pInfoBitmap
->bmiHeader
.biPlanes
;
1942 pIconEntry
->yHotspot
= pInfoBitmap
->bmiHeader
.biBitCount
;
1943 pIconEntry
->dwDIBSize
= 0;
1944 pIconEntry
->dwDIBOffset
= 3 * sizeof(WORD
) + sizeof(CURSORICONFILEDIRENTRY
);
1946 /* Fill out the BITMAPINFOHEADER */
1947 pIconBitmapHeader
= (BITMAPINFOHEADER
*)(pIconData
+ 3 * sizeof(WORD
) + sizeof(CURSORICONFILEDIRENTRY
));
1948 memcpy(pIconBitmapHeader
, &pInfoBitmap
->bmiHeader
, sizeof(BITMAPINFOHEADER
));
1950 /* Find out whether a palette exists for the bitmap */
1951 if ( (pInfoBitmap
->bmiHeader
.biBitCount
== 16 && pInfoBitmap
->bmiHeader
.biCompression
== BI_RGB
)
1952 || (pInfoBitmap
->bmiHeader
.biBitCount
== 24)
1953 || (pInfoBitmap
->bmiHeader
.biBitCount
== 32 && pInfoBitmap
->bmiHeader
.biCompression
== BI_RGB
)) {
1954 iNumEntriesPalette
= pInfoBitmap
->bmiHeader
.biClrUsed
;
1955 if (iNumEntriesPalette
> 256) iNumEntriesPalette
= 256;
1956 } else if ((pInfoBitmap
->bmiHeader
.biBitCount
== 16 || pInfoBitmap
->bmiHeader
.biBitCount
== 32)
1957 && pInfoBitmap
->bmiHeader
.biCompression
== BI_BITFIELDS
) {
1958 iNumEntriesPalette
= 3;
1959 } else if (pInfoBitmap
->bmiHeader
.biBitCount
<= 8) {
1960 iNumEntriesPalette
= 1 << pInfoBitmap
->bmiHeader
.biBitCount
;
1962 iNumEntriesPalette
= 0;
1965 /* Add bitmap size and header size to icon data size. */
1966 iOffsetPalette
= iDataSize
;
1967 iDataSize
+= iNumEntriesPalette
* sizeof(DWORD
);
1968 iOffsetColorData
= iDataSize
;
1969 iDataSize
+= pIconBitmapHeader
->biSizeImage
;
1970 iOffsetMaskData
= iDataSize
;
1971 iDataSize
+= pIconBitmapHeader
->biHeight
* iLengthScanLineMask
;
1972 pIconBitmapHeader
->biSizeImage
+= pIconBitmapHeader
->biHeight
* iLengthScanLineMask
;
1973 pIconBitmapHeader
->biHeight
*= 2;
1974 pIconData
= HeapReAlloc(GetProcessHeap(), 0, pIconData
, iDataSize
);
1975 pIconEntry
= (CURSORICONFILEDIRENTRY
*)(pIconData
+ 3 * sizeof(WORD
));
1976 pIconBitmapHeader
= (BITMAPINFOHEADER
*)(pIconData
+ 3 * sizeof(WORD
) + sizeof(CURSORICONFILEDIRENTRY
));
1977 pIconEntry
->dwDIBSize
= iDataSize
- (3 * sizeof(WORD
) + sizeof(CURSORICONFILEDIRENTRY
));
1979 /* Get the actual bitmap data from the icon bitmap */
1980 GetDIBits(hDC
, infoIcon
.hbmColor
, 0, pInfoBitmap
->bmiHeader
.biHeight
,
1981 pIconData
+ iOffsetColorData
, pInfoBitmap
, DIB_RGB_COLORS
);
1982 if (iNumEntriesPalette
> 0) {
1983 memcpy(pIconData
+ iOffsetPalette
, pInfoBitmap
->bmiColors
,
1984 iNumEntriesPalette
* sizeof(RGBQUAD
));
1987 /* Reset all values so that GetDIBits call succeeds */
1988 memset(pIconData
+ iOffsetMaskData
, 0, iDataSize
- iOffsetMaskData
);
1989 memset(pInfoBitmap
, 0, sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
1990 pInfoBitmap
->bmiHeader
.biSize
= sizeof(pInfoBitmap
->bmiHeader
);
1992 if (!(GetDIBits(hDC, infoIcon.hbmMask, 0, 0, NULL, pInfoBitmap, DIB_RGB_COLORS)
1993 && GetDIBits(hDC, infoIcon.hbmMask, 0, pIconEntry->bHeight,
1994 pIconData + iOffsetMaskData, pInfoBitmap, DIB_RGB_COLORS))) {
1996 printf("ERROR: unable to get bitmap mask (error %u)\n",
2001 GetDIBits(hDC
, infoIcon
.hbmMask
, 0, 0, NULL
, pInfoBitmap
, DIB_RGB_COLORS
);
2002 GetDIBits(hDC
, infoIcon
.hbmMask
, 0, pIconEntry
->bHeight
, pIconData
+ iOffsetMaskData
, pInfoBitmap
, DIB_RGB_COLORS
);
2004 /* Write out everything produced so far to the stream */
2005 *ppBuffer
= pIconData
; *pLength
= iDataSize
;
2009 printf("ERROR: unable to get bitmap information via GetDIBits() (error %u)\n",
2014 Remarks (from MSDN entry on GetIconInfo):
2016 GetIconInfo creates bitmaps for the hbmMask and hbmColor
2017 members of ICONINFO. The calling application must manage
2018 these bitmaps and delete them when they are no longer
2021 if (hDC
) ReleaseDC(0, hDC
);
2022 DeleteObject(infoIcon
.hbmMask
);
2023 if (infoIcon
.hbmColor
) DeleteObject(infoIcon
.hbmColor
);
2024 HeapFree(GetProcessHeap(), 0, pInfoBitmap
);
2026 printf("ERROR: Unable to get icon information (error %u)\n",
2032 static HRESULT WINAPI
OLEPictureImpl_Save(
2033 IPersistStream
* iface
,IStream
*pStm
,BOOL fClearDirty
)
2035 HRESULT hResult
= E_NOTIMPL
;
2037 unsigned int iDataSize
;
2039 int iSerializeResult
= 0;
2040 OLEPictureImpl
*This
= impl_from_IPersistStream(iface
);
2042 TRACE("%p %p %d\n", This
, pStm
, fClearDirty
);
2044 switch (This
->desc
.picType
) {
2046 if (This
->bIsDirty
|| !This
->data
) {
2047 if (!serializeIcon(This
->desc
.u
.icon
.hicon
, &pIconData
, &iDataSize
)) {
2048 ERR("(%p,%p,%d), serializeIcon() failed\n", This
, pStm
, fClearDirty
);
2052 HeapFree(GetProcessHeap(), 0, This
->data
);
2053 This
->data
= pIconData
;
2054 This
->datalen
= iDataSize
;
2056 if (This
->loadtime_magic
!= 0xdeadbeef) {
2059 header
[0] = This
->loadtime_magic
;
2060 header
[1] = This
->datalen
;
2061 IStream_Write(pStm
, header
, 2 * sizeof(DWORD
), &dummy
);
2063 IStream_Write(pStm
, This
->data
, This
->datalen
, &dummy
);
2067 case PICTYPE_BITMAP
:
2068 if (This
->bIsDirty
) {
2069 switch (This
->keepOrigFormat
? This
->loadtime_format
: 0x4d42) {
2071 iSerializeResult
= serializeBMP(This
->desc
.u
.bmp
.hbitmap
, &pIconData
, &iDataSize
);
2074 FIXME("(%p,%p,%d), PICTYPE_BITMAP (format JPEG) not implemented!\n",This
,pStm
,fClearDirty
);
2077 FIXME("(%p,%p,%d), PICTYPE_BITMAP (format GIF) not implemented!\n",This
,pStm
,fClearDirty
);
2080 FIXME("(%p,%p,%d), PICTYPE_BITMAP (format PNG) not implemented!\n",This
,pStm
,fClearDirty
);
2083 FIXME("(%p,%p,%d), PICTYPE_BITMAP (format UNKNOWN, using BMP?) not implemented!\n",This
,pStm
,fClearDirty
);
2086 if (iSerializeResult
) {
2088 if (This->loadtime_magic != 0xdeadbeef) {
2093 header
[0] = (This
->loadtime_magic
!= 0xdeadbeef) ? This
->loadtime_magic
: 0x0000746c;
2094 header
[1] = iDataSize
;
2095 IStream_Write(pStm
, header
, 2 * sizeof(DWORD
), &dummy
);
2097 IStream_Write(pStm
, pIconData
, iDataSize
, &dummy
);
2099 HeapFree(GetProcessHeap(), 0, This
->data
);
2100 This
->data
= pIconData
;
2101 This
->datalen
= iDataSize
;
2106 if (This->loadtime_magic != 0xdeadbeef) {
2111 header
[0] = (This
->loadtime_magic
!= 0xdeadbeef) ? This
->loadtime_magic
: 0x0000746c;
2112 header
[1] = This
->datalen
;
2113 IStream_Write(pStm
, header
, 2 * sizeof(DWORD
), &dummy
);
2115 IStream_Write(pStm
, This
->data
, This
->datalen
, &dummy
);
2119 case PICTYPE_METAFILE
:
2120 FIXME("(%p,%p,%d), PICTYPE_METAFILE not implemented!\n",This
,pStm
,fClearDirty
);
2122 case PICTYPE_ENHMETAFILE
:
2123 FIXME("(%p,%p,%d),PICTYPE_ENHMETAFILE not implemented!\n",This
,pStm
,fClearDirty
);
2126 FIXME("(%p,%p,%d), [unknown type] not implemented!\n",This
,pStm
,fClearDirty
);
2129 if (hResult
== S_OK
&& fClearDirty
) This
->bIsDirty
= FALSE
;
2133 static HRESULT WINAPI
OLEPictureImpl_GetSizeMax(
2134 IPersistStream
* iface
,ULARGE_INTEGER
*pcbSize
)
2136 OLEPictureImpl
*This
= impl_from_IPersistStream(iface
);
2137 FIXME("(%p,%p),stub!\n",This
,pcbSize
);
2142 /************************************************************************
2146 /************************************************************************
2147 * OLEPictureImpl_IDispatch_QueryInterface (IUnknown)
2149 * See Windows documentation for more details on IUnknown methods.
2151 static HRESULT WINAPI
OLEPictureImpl_IDispatch_QueryInterface(
2156 OLEPictureImpl
*This
= impl_from_IDispatch(iface
);
2158 return IPicture_QueryInterface((IPicture
*)This
, riid
, ppvoid
);
2161 /************************************************************************
2162 * OLEPictureImpl_IDispatch_AddRef (IUnknown)
2164 * See Windows documentation for more details on IUnknown methods.
2166 static ULONG WINAPI
OLEPictureImpl_IDispatch_AddRef(
2169 OLEPictureImpl
*This
= impl_from_IDispatch(iface
);
2171 return IPicture_AddRef((IPicture
*)This
);
2174 /************************************************************************
2175 * OLEPictureImpl_IDispatch_Release (IUnknown)
2177 * See Windows documentation for more details on IUnknown methods.
2179 static ULONG WINAPI
OLEPictureImpl_IDispatch_Release(
2182 OLEPictureImpl
*This
= impl_from_IDispatch(iface
);
2184 return IPicture_Release((IPicture
*)This
);
2187 /************************************************************************
2188 * OLEPictureImpl_GetTypeInfoCount (IDispatch)
2190 * See Windows documentation for more details on IDispatch methods.
2192 static HRESULT WINAPI
OLEPictureImpl_GetTypeInfoCount(
2194 unsigned int* pctinfo
)
2196 TRACE("(%p)\n", pctinfo
);
2203 /************************************************************************
2204 * OLEPictureImpl_GetTypeInfo (IDispatch)
2206 * See Windows documentation for more details on IDispatch methods.
2208 static HRESULT WINAPI
OLEPictureImpl_GetTypeInfo(
2212 ITypeInfo
** ppTInfo
)
2214 static const WCHAR stdole2tlb
[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
2218 TRACE("(iTInfo=%d, lcid=%04x, %p)\n", iTInfo
, (int)lcid
, ppTInfo
);
2223 hres
= LoadTypeLib(stdole2tlb
, &tl
);
2226 ERR("Could not load stdole2.tlb\n");
2230 hres
= ITypeLib_GetTypeInfoOfGuid(tl
, &IID_IPictureDisp
, ppTInfo
);
2232 ERR("Did not get IPictureDisp typeinfo from typelib, hres %x\n", hres
);
2237 /************************************************************************
2238 * OLEPictureImpl_GetIDsOfNames (IDispatch)
2240 * See Windows documentation for more details on IDispatch methods.
2242 static HRESULT WINAPI
OLEPictureImpl_GetIDsOfNames(
2245 LPOLESTR
* rgszNames
,
2255 /************************************************************************
2256 * OLEPictureImpl_Invoke (IDispatch)
2258 * See Windows documentation for more details on IDispatch methods.
2260 static HRESULT WINAPI
OLEPictureImpl_Invoke(
2262 DISPID dispIdMember
,
2266 DISPPARAMS
* pDispParams
,
2267 VARIANT
* pVarResult
,
2268 EXCEPINFO
* pExepInfo
,
2271 OLEPictureImpl
*This
= impl_from_IDispatch(iface
);
2273 /* validate parameters */
2275 if (!IsEqualIID(riid
, &IID_NULL
))
2277 ERR("riid was %s instead of IID_NULL\n", debugstr_guid(riid
));
2278 return DISP_E_UNKNOWNNAME
;
2283 ERR("null pDispParams not allowed\n");
2284 return DISP_E_PARAMNOTOPTIONAL
;
2287 if (wFlags
& DISPATCH_PROPERTYGET
)
2289 if (pDispParams
->cArgs
!= 0)
2291 ERR("param count for DISPATCH_PROPERTYGET was %d instead of 0\n", pDispParams
->cArgs
);
2292 return DISP_E_BADPARAMCOUNT
;
2296 ERR("null pVarResult not allowed when DISPATCH_PROPERTYGET specified\n");
2297 return DISP_E_PARAMNOTOPTIONAL
;
2300 else if (wFlags
& DISPATCH_PROPERTYPUT
)
2302 if (pDispParams
->cArgs
!= 1)
2304 ERR("param count for DISPATCH_PROPERTYPUT was %d instead of 1\n", pDispParams
->cArgs
);
2305 return DISP_E_BADPARAMCOUNT
;
2309 switch (dispIdMember
)
2311 case DISPID_PICT_HANDLE
:
2312 if (wFlags
& DISPATCH_PROPERTYGET
)
2314 TRACE("DISPID_PICT_HANDLE\n");
2315 V_VT(pVarResult
) = VT_I4
;
2316 return IPicture_get_Handle((IPicture
*)&This
->lpVtbl
, &V_UINT(pVarResult
));
2319 case DISPID_PICT_HPAL
:
2320 if (wFlags
& DISPATCH_PROPERTYGET
)
2322 TRACE("DISPID_PICT_HPAL\n");
2323 V_VT(pVarResult
) = VT_I4
;
2324 return IPicture_get_hPal((IPicture
*)&This
->lpVtbl
, &V_UINT(pVarResult
));
2326 else if (wFlags
& DISPATCH_PROPERTYPUT
)
2330 TRACE("DISPID_PICT_HPAL\n");
2332 VariantInit(&vararg
);
2333 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_I4
);
2337 hr
= IPicture_set_hPal((IPicture
*)&This
->lpVtbl
, V_I4(&vararg
));
2339 VariantClear(&vararg
);
2343 case DISPID_PICT_TYPE
:
2344 if (wFlags
& DISPATCH_PROPERTYGET
)
2346 TRACE("DISPID_PICT_TYPE\n");
2347 V_VT(pVarResult
) = VT_I2
;
2348 return OLEPictureImpl_get_Type((IPicture
*)&This
->lpVtbl
, &V_I2(pVarResult
));
2351 case DISPID_PICT_WIDTH
:
2352 if (wFlags
& DISPATCH_PROPERTYGET
)
2354 TRACE("DISPID_PICT_WIDTH\n");
2355 V_VT(pVarResult
) = VT_I4
;
2356 return IPicture_get_Width((IPicture
*)&This
->lpVtbl
, &V_I4(pVarResult
));
2359 case DISPID_PICT_HEIGHT
:
2360 if (wFlags
& DISPATCH_PROPERTYGET
)
2362 TRACE("DISPID_PICT_HEIGHT\n");
2363 V_VT(pVarResult
) = VT_I4
;
2364 return IPicture_get_Height((IPicture
*)&This
->lpVtbl
, &V_I4(pVarResult
));
2369 ERR("invalid dispid 0x%x or wFlags 0x%x\n", dispIdMember
, wFlags
);
2370 return DISP_E_MEMBERNOTFOUND
;
2374 static const IPictureVtbl OLEPictureImpl_VTable
=
2376 OLEPictureImpl_QueryInterface
,
2377 OLEPictureImpl_AddRef
,
2378 OLEPictureImpl_Release
,
2379 OLEPictureImpl_get_Handle
,
2380 OLEPictureImpl_get_hPal
,
2381 OLEPictureImpl_get_Type
,
2382 OLEPictureImpl_get_Width
,
2383 OLEPictureImpl_get_Height
,
2384 OLEPictureImpl_Render
,
2385 OLEPictureImpl_set_hPal
,
2386 OLEPictureImpl_get_CurDC
,
2387 OLEPictureImpl_SelectPicture
,
2388 OLEPictureImpl_get_KeepOriginalFormat
,
2389 OLEPictureImpl_put_KeepOriginalFormat
,
2390 OLEPictureImpl_PictureChanged
,
2391 OLEPictureImpl_SaveAsFile
,
2392 OLEPictureImpl_get_Attributes
2395 static const IDispatchVtbl OLEPictureImpl_IDispatch_VTable
=
2397 OLEPictureImpl_IDispatch_QueryInterface
,
2398 OLEPictureImpl_IDispatch_AddRef
,
2399 OLEPictureImpl_IDispatch_Release
,
2400 OLEPictureImpl_GetTypeInfoCount
,
2401 OLEPictureImpl_GetTypeInfo
,
2402 OLEPictureImpl_GetIDsOfNames
,
2403 OLEPictureImpl_Invoke
2406 static const IPersistStreamVtbl OLEPictureImpl_IPersistStream_VTable
=
2408 OLEPictureImpl_IPersistStream_QueryInterface
,
2409 OLEPictureImpl_IPersistStream_AddRef
,
2410 OLEPictureImpl_IPersistStream_Release
,
2411 OLEPictureImpl_GetClassID
,
2412 OLEPictureImpl_IsDirty
,
2413 OLEPictureImpl_Load
,
2414 OLEPictureImpl_Save
,
2415 OLEPictureImpl_GetSizeMax
2418 static const IConnectionPointContainerVtbl OLEPictureImpl_IConnectionPointContainer_VTable
=
2420 OLEPictureImpl_IConnectionPointContainer_QueryInterface
,
2421 OLEPictureImpl_IConnectionPointContainer_AddRef
,
2422 OLEPictureImpl_IConnectionPointContainer_Release
,
2423 OLEPictureImpl_EnumConnectionPoints
,
2424 OLEPictureImpl_FindConnectionPoint
2427 /***********************************************************************
2428 * OleCreatePictureIndirect (OLEAUT32.419)
2430 HRESULT WINAPI
OleCreatePictureIndirect(LPPICTDESC lpPictDesc
, REFIID riid
,
2431 BOOL fOwn
, LPVOID
*ppvObj
)
2433 OLEPictureImpl
* newPict
= NULL
;
2436 TRACE("(%p,%s,%d,%p)\n", lpPictDesc
, debugstr_guid(riid
), fOwn
, ppvObj
);
2447 * Try to construct a new instance of the class.
2449 newPict
= OLEPictureImpl_Construct(lpPictDesc
, fOwn
);
2451 if (newPict
== NULL
)
2452 return E_OUTOFMEMORY
;
2455 * Make sure it supports the interface required by the caller.
2457 hr
= IPicture_QueryInterface((IPicture
*)newPict
, riid
, ppvObj
);
2460 * Release the reference obtained in the constructor. If
2461 * the QueryInterface was unsuccessful, it will free the class.
2463 IPicture_Release((IPicture
*)newPict
);
2469 /***********************************************************************
2470 * OleLoadPicture (OLEAUT32.418)
2472 HRESULT WINAPI
OleLoadPicture( LPSTREAM lpstream
, LONG lSize
, BOOL fRunmode
,
2473 REFIID riid
, LPVOID
*ppvObj
)
2479 TRACE("(%p,%d,%d,%s,%p), partially implemented.\n",
2480 lpstream
, lSize
, fRunmode
, debugstr_guid(riid
), ppvObj
);
2482 hr
= OleCreatePictureIndirect(NULL
,riid
,!fRunmode
,(LPVOID
*)&newpic
);
2485 hr
= IPicture_QueryInterface(newpic
,&IID_IPersistStream
, (LPVOID
*)&ps
);
2487 FIXME("Could not get IPersistStream iface from Ole Picture?\n");
2488 IPicture_Release(newpic
);
2492 IPersistStream_Load(ps
,lpstream
);
2493 IPersistStream_Release(ps
);
2494 hr
= IPicture_QueryInterface(newpic
,riid
,ppvObj
);
2496 FIXME("Failed to get interface %s from IPicture.\n",debugstr_guid(riid
));
2497 IPicture_Release(newpic
);
2501 /***********************************************************************
2502 * OleLoadPictureEx (OLEAUT32.401)
2504 HRESULT WINAPI
OleLoadPictureEx( LPSTREAM lpstream
, LONG lSize
, BOOL fRunmode
,
2505 REFIID riid
, DWORD xsiz
, DWORD ysiz
, DWORD flags
, LPVOID
*ppvObj
)
2511 FIXME("(%p,%d,%d,%s,x=%d,y=%d,f=%x,%p), partially implemented.\n",
2512 lpstream
, lSize
, fRunmode
, debugstr_guid(riid
), xsiz
, ysiz
, flags
, ppvObj
);
2514 hr
= OleCreatePictureIndirect(NULL
,riid
,!fRunmode
,(LPVOID
*)&newpic
);
2517 hr
= IPicture_QueryInterface(newpic
,&IID_IPersistStream
, (LPVOID
*)&ps
);
2519 FIXME("Could not get IPersistStream iface from Ole Picture?\n");
2520 IPicture_Release(newpic
);
2524 IPersistStream_Load(ps
,lpstream
);
2525 IPersistStream_Release(ps
);
2526 hr
= IPicture_QueryInterface(newpic
,riid
,ppvObj
);
2528 FIXME("Failed to get interface %s from IPicture.\n",debugstr_guid(riid
));
2529 IPicture_Release(newpic
);
2533 /***********************************************************************
2534 * OleLoadPicturePath (OLEAUT32.424)
2536 HRESULT WINAPI
OleLoadPicturePath( LPOLESTR szURLorPath
, LPUNKNOWN punkCaller
,
2537 DWORD dwReserved
, OLE_COLOR clrReserved
, REFIID riid
,
2540 static const WCHAR file
[] = { 'f','i','l','e',':','/','/',0 };
2544 HGLOBAL hGlobal
= NULL
;
2545 DWORD dwBytesRead
= 0;
2548 IPersistStream
*pStream
;
2551 TRACE("(%s,%p,%d,%08x,%s,%p): stub\n",
2552 debugstr_w(szURLorPath
), punkCaller
, dwReserved
, clrReserved
,
2553 debugstr_guid(riid
), ppvRet
);
2555 if (!ppvRet
) return E_POINTER
;
2557 if (strncmpW(szURLorPath
, file
, 7) == 0) {
2560 hFile
= CreateFileW(szURLorPath
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
,
2562 if (hFile
== INVALID_HANDLE_VALUE
)
2563 return E_UNEXPECTED
;
2565 dwFileSize
= GetFileSize(hFile
, NULL
);
2566 if (dwFileSize
!= INVALID_FILE_SIZE
)
2568 hGlobal
= GlobalAlloc(GMEM_FIXED
,dwFileSize
);
2571 bRead
= ReadFile(hFile
, hGlobal
, dwFileSize
, &dwBytesRead
, NULL
);
2574 GlobalFree(hGlobal
);
2582 return E_UNEXPECTED
;
2584 hRes
= CreateStreamOnHGlobal(hGlobal
, TRUE
, &stream
);
2587 GlobalFree(hGlobal
);
2594 hRes
= CreateBindCtx(0, &pbc
);
2595 if (SUCCEEDED(hRes
))
2597 hRes
= CreateURLMoniker(NULL
, szURLorPath
, &pmnk
);
2598 if (SUCCEEDED(hRes
))
2600 hRes
= IMoniker_BindToStorage(pmnk
, pbc
, NULL
, &IID_IStream
, (LPVOID
*)&stream
);
2601 IMoniker_Release(pmnk
);
2603 IBindCtx_Release(pbc
);
2609 hRes
= CoCreateInstance(&CLSID_StdPicture
, punkCaller
, CLSCTX_INPROC_SERVER
,
2610 &IID_IPicture
, (LPVOID
*)&ipicture
);
2612 IStream_Release(stream
);
2616 hRes
= IPicture_QueryInterface(ipicture
, &IID_IPersistStream
, (LPVOID
*)&pStream
);
2618 IStream_Release(stream
);
2619 IPicture_Release(ipicture
);
2623 hRes
= IPersistStream_Load(pStream
, stream
);
2624 IPersistStream_Release(pStream
);
2625 IStream_Release(stream
);
2628 IPicture_Release(ipicture
);
2632 hRes
= IPicture_QueryInterface(ipicture
,riid
,ppvRet
);
2634 FIXME("Failed to get interface %s from IPicture.\n",debugstr_guid(riid
));
2636 IPicture_Release(ipicture
);
2640 /*******************************************************************************
2641 * StdPic ClassFactory
2645 /* IUnknown fields */
2646 const IClassFactoryVtbl
*lpVtbl
;
2648 } IClassFactoryImpl
;
2650 static HRESULT WINAPI
2651 SPCF_QueryInterface(LPCLASSFACTORY iface
,REFIID riid
,LPVOID
*ppobj
) {
2652 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
2654 FIXME("(%p)->(%s,%p),stub!\n",This
,debugstr_guid(riid
),ppobj
);
2655 return E_NOINTERFACE
;
2659 SPCF_AddRef(LPCLASSFACTORY iface
) {
2660 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
2661 return InterlockedIncrement(&This
->ref
);
2664 static ULONG WINAPI
SPCF_Release(LPCLASSFACTORY iface
) {
2665 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
2666 /* static class, won't be freed */
2667 return InterlockedDecrement(&This
->ref
);
2670 static HRESULT WINAPI
SPCF_CreateInstance(
2671 LPCLASSFACTORY iface
,LPUNKNOWN pOuter
,REFIID riid
,LPVOID
*ppobj
2673 /* Creates an uninitialized picture */
2674 return OleCreatePictureIndirect(NULL
,riid
,TRUE
,ppobj
);
2678 static HRESULT WINAPI
SPCF_LockServer(LPCLASSFACTORY iface
,BOOL dolock
) {
2679 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
2680 FIXME("(%p)->(%d),stub!\n",This
,dolock
);
2684 static const IClassFactoryVtbl SPCF_Vtbl
= {
2685 SPCF_QueryInterface
,
2688 SPCF_CreateInstance
,
2691 static IClassFactoryImpl STDPIC_CF
= {&SPCF_Vtbl
, 1 };
2693 void _get_STDPIC_CF(LPVOID
*ppv
) { *ppv
= (LPVOID
)&STDPIC_CF
; }