Separated out 16bit sources for ole2disp.dll.
[wine] / dlls / oleaut32 / olepicture.c
1 /*
2  * OLE Picture object
3  *
4  * Implementation of OLE IPicture and related interfaces
5  *
6  * Copyright 2000 Huw D M Davies for CodeWeavers.
7  * Copyright 2001 Marcus Meissner
8  *
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.
13  *
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.
18  *
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  *
23  * BUGS
24  *
25  * Support PICTYPE_BITMAP and PICTYPE_ICON, altough only bitmaps very well..
26  * Lots of methods are just stubs.
27  *
28  *
29  * NOTES (or things that msdn doesn't tell you)
30  *
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).
35  *
36  */
37
38 #include "config.h"
39
40 #ifdef HAVE_UNISTD_H
41 # include <unistd.h>
42 #endif
43 #include <stdio.h>
44 #include <string.h>
45 #include "winerror.h"
46 #include "winbase.h"
47 #include "wingdi.h"
48 #include "winuser.h"
49 #include "ole2.h"
50 #include "olectl.h"
51 #include "oleauto.h"
52 #include "wine/obj_picture.h"
53 #include "wine/obj_connection.h"
54 #include "connpt.h"
55 #include "wine/debug.h"
56
57 #include "wine/wingdi16.h"
58 #include "cursoricon.h"
59
60 #ifdef HAVE_LIBJPEG
61 /* This is a hack, so jpeglib.h does not redefine INT32 and the like*/
62 #define XMD_H
63 #define UINT8 JPEG_UINT8
64 #define UINT16 JPEG_UINT16
65 #ifdef HAVE_JPEGLIB_H
66 # include <jpeglib.h>
67 #endif
68 #undef UINT16
69 #endif
70
71 WINE_DEFAULT_DEBUG_CHANNEL(ole);
72
73 /*************************************************************************
74  *  Declaration of implementation class
75  */
76
77 typedef struct OLEPictureImpl {
78
79   /*
80    * IPicture handles IUnknown
81    */
82
83     ICOM_VTABLE(IPicture)       *lpvtbl1;
84     ICOM_VTABLE(IDispatch)      *lpvtbl2;
85     ICOM_VTABLE(IPersistStream) *lpvtbl3;
86     ICOM_VTABLE(IConnectionPointContainer) *lpvtbl4;
87
88   /* Object referenece count */
89     DWORD ref;
90
91   /* We own the object and must destroy it ourselves */
92     BOOL fOwn;
93
94   /* Picture description */
95     PICTDESC desc;
96
97   /* These are the pixel size of a bitmap */
98     DWORD origWidth;
99     DWORD origHeight;
100
101   /* And these are the size of the picture converted into HIMETRIC units */
102     OLE_XSIZE_HIMETRIC himetricWidth;
103     OLE_YSIZE_HIMETRIC himetricHeight;
104
105     IConnectionPoint *pCP;
106
107     BOOL keepOrigFormat;
108     HDC hDCCur;
109
110   /* data */
111     void* data;
112     int datalen;
113 } OLEPictureImpl;
114
115 /*
116  * Macros to retrieve pointer to IUnknown (IPicture) from the other VTables.
117  */
118 #define ICOM_THIS_From_IDispatch(impl, name) \
119     impl *This = (impl*)(((char*)name)-sizeof(void*));
120 #define ICOM_THIS_From_IPersistStream(impl, name) \
121     impl *This = (impl*)(((char*)name)-2*sizeof(void*));
122 #define ICOM_THIS_From_IConnectionPointContainer(impl, name) \
123     impl *This = (impl*)(((char*)name)-3*sizeof(void*));
124
125 /*
126  * Predeclare VTables.  They get initialized at the end.
127  */
128 static ICOM_VTABLE(IPicture) OLEPictureImpl_VTable;
129 static ICOM_VTABLE(IDispatch) OLEPictureImpl_IDispatch_VTable;
130 static ICOM_VTABLE(IPersistStream) OLEPictureImpl_IPersistStream_VTable;
131 static ICOM_VTABLE(IConnectionPointContainer) OLEPictureImpl_IConnectionPointContainer_VTable;
132
133 /***********************************************************************
134  * Implementation of the OLEPictureImpl class.
135  */
136
137 static void OLEPictureImpl_SetBitmap(OLEPictureImpl*This) {
138   BITMAP bm;
139   HDC hdcRef;
140
141   TRACE("bitmap handle %p\n", This->desc.u.bmp.hbitmap);
142   if(GetObjectA(This->desc.u.bmp.hbitmap, sizeof(bm), &bm) != sizeof(bm)) {
143     ERR("GetObject fails\n");
144     return;
145   }
146   This->origWidth = bm.bmWidth;
147   This->origHeight = bm.bmHeight;
148   /* The width and height are stored in HIMETRIC units (0.01 mm),
149      so we take our pixel width divide by pixels per inch and
150      multiply by 25.4 * 100 */
151   /* Should we use GetBitmapDimension if available? */
152   hdcRef = CreateCompatibleDC(0);
153   This->himetricWidth =(bm.bmWidth *2540)/GetDeviceCaps(hdcRef, LOGPIXELSX);
154   This->himetricHeight=(bm.bmHeight*2540)/GetDeviceCaps(hdcRef, LOGPIXELSY);
155   DeleteDC(hdcRef);
156 }
157
158 /************************************************************************
159  * OLEPictureImpl_Construct
160  *
161  * This method will construct a new instance of the OLEPictureImpl
162  * class.
163  *
164  * The caller of this method must release the object when it's
165  * done with it.
166  */
167 static OLEPictureImpl* OLEPictureImpl_Construct(LPPICTDESC pictDesc, BOOL fOwn)
168 {
169   OLEPictureImpl* newObject = 0;
170
171   if (pictDesc)
172       TRACE("(%p) type = %d\n", pictDesc, pictDesc->picType);
173
174   /*
175    * Allocate space for the object.
176    */
177   newObject = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(OLEPictureImpl));
178
179   if (newObject==0)
180     return newObject;
181
182   /*
183    * Initialize the virtual function table.
184    */
185   newObject->lpvtbl1 = &OLEPictureImpl_VTable;
186   newObject->lpvtbl2 = &OLEPictureImpl_IDispatch_VTable;
187   newObject->lpvtbl3 = &OLEPictureImpl_IPersistStream_VTable;
188   newObject->lpvtbl4 = &OLEPictureImpl_IConnectionPointContainer_VTable;
189
190   CreateConnectionPoint((IUnknown*)newObject,&IID_IPropertyNotifySink,&newObject->pCP);
191
192   /*
193    * Start with one reference count. The caller of this function
194    * must release the interface pointer when it is done.
195    */
196   newObject->ref        = 1;
197   newObject->hDCCur     = 0;
198
199   newObject->fOwn       = fOwn;
200
201   /* dunno about original value */
202   newObject->keepOrigFormat = TRUE;
203
204   if (pictDesc) {
205       if(pictDesc->cbSizeofstruct != sizeof(PICTDESC)) {
206           FIXME("struct size = %d\n", pictDesc->cbSizeofstruct);
207       }
208       memcpy(&newObject->desc, pictDesc, sizeof(PICTDESC));
209
210
211       switch(pictDesc->picType) {
212       case PICTYPE_BITMAP:
213         OLEPictureImpl_SetBitmap(newObject);
214         break;
215
216       case PICTYPE_METAFILE:
217         TRACE("metafile handle %p\n", pictDesc->u.wmf.hmeta);
218         newObject->himetricWidth = pictDesc->u.wmf.xExt;
219         newObject->himetricHeight = pictDesc->u.wmf.yExt;
220         break;
221
222       case PICTYPE_ICON:
223       case PICTYPE_ENHMETAFILE:
224       default:
225         FIXME("Unsupported type %d\n", pictDesc->picType);
226         newObject->himetricWidth = newObject->himetricHeight = 0;
227         break;
228       }
229   } else {
230       newObject->desc.picType = PICTYPE_UNINITIALIZED;
231   }
232
233   TRACE("returning %p\n", newObject);
234   return newObject;
235 }
236
237 /************************************************************************
238  * OLEPictureImpl_Destroy
239  *
240  * This method is called by the Release method when the reference
241  * count goes down to 0. It will free all resources used by
242  * this object.  */
243 static void OLEPictureImpl_Destroy(OLEPictureImpl* Obj)
244 {
245   TRACE("(%p)\n", Obj);
246
247   if(Obj->fOwn) { /* We need to destroy the picture */
248     switch(Obj->desc.picType) {
249     case PICTYPE_BITMAP:
250       DeleteObject(Obj->desc.u.bmp.hbitmap);
251       break;
252     case PICTYPE_METAFILE:
253       DeleteMetaFile(Obj->desc.u.wmf.hmeta);
254       break;
255     case PICTYPE_ICON:
256       DestroyIcon(Obj->desc.u.icon.hicon);
257       break;
258     case PICTYPE_ENHMETAFILE:
259       DeleteEnhMetaFile(Obj->desc.u.emf.hemf);
260       break;
261     default:
262       FIXME("Unsupported type %d - unable to delete\n", Obj->desc.picType);
263       break;
264     }
265   }
266   if (Obj->data) HeapFree(GetProcessHeap(), 0, Obj->data);
267   HeapFree(GetProcessHeap(), 0, Obj);
268 }
269
270 static ULONG WINAPI OLEPictureImpl_AddRef(IPicture* iface);
271
272 /************************************************************************
273  * OLEPictureImpl_QueryInterface (IUnknown)
274  *
275  * See Windows documentation for more details on IUnknown methods.
276  */
277 static HRESULT WINAPI OLEPictureImpl_QueryInterface(
278   IPicture*  iface,
279   REFIID  riid,
280   void**  ppvObject)
281 {
282   ICOM_THIS(OLEPictureImpl, iface);
283   TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppvObject);
284
285   /*
286    * Perform a sanity check on the parameters.
287    */
288   if ( (This==0) || (ppvObject==0) )
289     return E_INVALIDARG;
290
291   /*
292    * Initialize the return parameter.
293    */
294   *ppvObject = 0;
295
296   /*
297    * Compare the riid with the interface IDs implemented by this object.
298    */
299   if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0)
300   {
301     *ppvObject = (IPicture*)This;
302   }
303   else if (memcmp(&IID_IPicture, riid, sizeof(IID_IPicture)) == 0)
304   {
305     *ppvObject = (IPicture*)This;
306   }
307   else if (memcmp(&IID_IDispatch, riid, sizeof(IID_IDispatch)) == 0)
308   {
309     *ppvObject = (IDispatch*)&(This->lpvtbl2);
310   }
311   else if (memcmp(&IID_IPictureDisp, riid, sizeof(IID_IPictureDisp)) == 0)
312   {
313     *ppvObject = (IDispatch*)&(This->lpvtbl2);
314   }
315   else if (memcmp(&IID_IPersistStream, riid, sizeof(IID_IPersistStream)) == 0)
316   {
317   *ppvObject = (IPersistStream*)&(This->lpvtbl3);
318   }
319   else if (memcmp(&IID_IConnectionPointContainer, riid, sizeof(IID_IConnectionPointContainer)) == 0)
320   {
321   *ppvObject = (IConnectionPointContainer*)&(This->lpvtbl4);
322   }
323   /*
324    * Check that we obtained an interface.
325    */
326   if ((*ppvObject)==0)
327   {
328     FIXME("() : asking for un supported interface %s\n",debugstr_guid(riid));
329     return E_NOINTERFACE;
330   }
331
332   /*
333    * Query Interface always increases the reference count by one when it is
334    * successful
335    */
336   OLEPictureImpl_AddRef((IPicture*)This);
337
338   return S_OK;
339 }
340 /***********************************************************************
341  *    OLEPicture_SendNotify (internal)
342  *
343  * Sends notification messages of changed properties to any interested
344  * connections.
345  */
346 static void OLEPicture_SendNotify(OLEPictureImpl* this, DISPID dispID)
347 {
348   IEnumConnections *pEnum;
349   CONNECTDATA CD;
350
351   if (IConnectionPoint_EnumConnections(this->pCP, &pEnum))
352       return;
353   while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
354     IPropertyNotifySink *sink;
355
356     IUnknown_QueryInterface(CD.pUnk, &IID_IPropertyNotifySink, (LPVOID)&sink);
357     IPropertyNotifySink_OnChanged(sink, dispID);
358     IPropertyNotifySink_Release(sink);
359     IUnknown_Release(CD.pUnk);
360   }
361   IEnumConnections_Release(pEnum);
362   return;
363 }
364
365 /************************************************************************
366  * OLEPictureImpl_AddRef (IUnknown)
367  *
368  * See Windows documentation for more details on IUnknown methods.
369  */
370 static ULONG WINAPI OLEPictureImpl_AddRef(
371   IPicture* iface)
372 {
373   ICOM_THIS(OLEPictureImpl, iface);
374   TRACE("(%p)->(ref=%ld)\n", This, This->ref);
375   This->ref++;
376
377   return This->ref;
378 }
379
380 /************************************************************************
381  * OLEPictureImpl_Release (IUnknown)
382  *
383  * See Windows documentation for more details on IUnknown methods.
384  */
385 static ULONG WINAPI OLEPictureImpl_Release(
386       IPicture* iface)
387 {
388   ICOM_THIS(OLEPictureImpl, iface);
389   TRACE("(%p)->(ref=%ld)\n", This, This->ref);
390
391   /*
392    * Decrease the reference count on this object.
393    */
394   This->ref--;
395
396   /*
397    * If the reference count goes down to 0, perform suicide.
398    */
399   if (This->ref==0)
400   {
401     OLEPictureImpl_Destroy(This);
402
403     return 0;
404   }
405
406   return This->ref;
407 }
408
409
410 /************************************************************************
411  * OLEPictureImpl_get_Handle
412  */
413 static HRESULT WINAPI OLEPictureImpl_get_Handle(IPicture *iface,
414                                                 OLE_HANDLE *phandle)
415 {
416   ICOM_THIS(OLEPictureImpl, iface);
417   TRACE("(%p)->(%p)\n", This, phandle);
418   switch(This->desc.picType) {
419   case PICTYPE_BITMAP:
420     *phandle = (OLE_HANDLE)This->desc.u.bmp.hbitmap;
421     break;
422   case PICTYPE_METAFILE:
423     *phandle = (OLE_HANDLE)This->desc.u.wmf.hmeta;
424     break;
425   case PICTYPE_ICON:
426     *phandle = (OLE_HANDLE)This->desc.u.icon.hicon;
427     break;
428   case PICTYPE_ENHMETAFILE:
429     *phandle = (OLE_HANDLE)This->desc.u.emf.hemf;
430     break;
431   default:
432     FIXME("Unimplemented type %d\n", This->desc.picType);
433     return E_NOTIMPL;
434   }
435   TRACE("returning handle %08x\n", *phandle);
436   return S_OK;
437 }
438
439 /************************************************************************
440  * OLEPictureImpl_get_hPal
441  */
442 static HRESULT WINAPI OLEPictureImpl_get_hPal(IPicture *iface,
443                                               OLE_HANDLE *phandle)
444 {
445   ICOM_THIS(OLEPictureImpl, iface);
446   FIXME("(%p)->(%p): stub\n", This, phandle);
447   return E_NOTIMPL;
448 }
449
450 /************************************************************************
451  * OLEPictureImpl_get_Type
452  */
453 static HRESULT WINAPI OLEPictureImpl_get_Type(IPicture *iface,
454                                               short *ptype)
455 {
456   ICOM_THIS(OLEPictureImpl, iface);
457   TRACE("(%p)->(%p): type is %d\n", This, ptype, This->desc.picType);
458   *ptype = This->desc.picType;
459   return S_OK;
460 }
461
462 /************************************************************************
463  * OLEPictureImpl_get_Width
464  */
465 static HRESULT WINAPI OLEPictureImpl_get_Width(IPicture *iface,
466                                                OLE_XSIZE_HIMETRIC *pwidth)
467 {
468   ICOM_THIS(OLEPictureImpl, iface);
469   TRACE("(%p)->(%p): width is %ld\n", This, pwidth, This->himetricWidth);
470   *pwidth = This->himetricWidth;
471   return S_OK;
472 }
473
474 /************************************************************************
475  * OLEPictureImpl_get_Height
476  */
477 static HRESULT WINAPI OLEPictureImpl_get_Height(IPicture *iface,
478                                                 OLE_YSIZE_HIMETRIC *pheight)
479 {
480   ICOM_THIS(OLEPictureImpl, iface);
481   TRACE("(%p)->(%p): height is %ld\n", This, pheight, This->himetricHeight);
482   *pheight = This->himetricHeight;
483   return S_OK;
484 }
485
486 /************************************************************************
487  * OLEPictureImpl_Render
488  */
489 static HRESULT WINAPI OLEPictureImpl_Render(IPicture *iface, HDC hdc,
490                                             long x, long y, long cx, long cy,
491                                             OLE_XPOS_HIMETRIC xSrc,
492                                             OLE_YPOS_HIMETRIC ySrc,
493                                             OLE_XSIZE_HIMETRIC cxSrc,
494                                             OLE_YSIZE_HIMETRIC cySrc,
495                                             LPCRECT prcWBounds)
496 {
497   ICOM_THIS(OLEPictureImpl, iface);
498   TRACE("(%p)->(%p, (%ld,%ld), (%ld,%ld) <- (%ld,%ld), (%ld,%ld), %p)\n",
499         This, hdc, x, y, cx, cy, xSrc, ySrc, cxSrc, cySrc, prcWBounds);
500   if(prcWBounds)
501     TRACE("prcWBounds (%d,%d) - (%d,%d)\n", prcWBounds->left, prcWBounds->top,
502           prcWBounds->right, prcWBounds->bottom);
503
504   /*
505    * While the documentation suggests this to be here (or after rendering?)
506    * it does cause an endless recursion in my sample app. -MM 20010804
507   OLEPicture_SendNotify(This,DISPID_PICT_RENDER);
508    */
509
510   switch(This->desc.picType) {
511   case PICTYPE_BITMAP:
512     {
513       HBITMAP hbmpOld;
514       HDC hdcBmp;
515
516       /* Set a mapping mode that maps bitmap pixels into HIMETRIC units.
517          NB y-axis gets flipped */
518
519       hdcBmp = CreateCompatibleDC(0);
520       SetMapMode(hdcBmp, MM_ANISOTROPIC);
521       SetWindowOrgEx(hdcBmp, 0, 0, NULL);
522       SetWindowExtEx(hdcBmp, This->himetricWidth, This->himetricHeight, NULL);
523       SetViewportOrgEx(hdcBmp, 0, This->origHeight, NULL);
524       SetViewportExtEx(hdcBmp, This->origWidth, -This->origHeight, NULL);
525
526       hbmpOld = SelectObject(hdcBmp, This->desc.u.bmp.hbitmap);
527
528       StretchBlt(hdc, x, y, cx, cy, hdcBmp, xSrc, ySrc, cxSrc, cySrc, SRCCOPY);
529
530       SelectObject(hdcBmp, hbmpOld);
531       DeleteDC(hdcBmp);
532     }
533     break;
534   case PICTYPE_ICON:
535     FIXME("Not quite correct implementation of rendering icons...\n");
536     DrawIcon(hdc,x,y,This->desc.u.icon.hicon);
537     break;
538
539   case PICTYPE_METAFILE:
540   case PICTYPE_ENHMETAFILE:
541   default:
542     FIXME("type %d not implemented\n", This->desc.picType);
543     return E_NOTIMPL;
544   }
545   return S_OK;
546 }
547
548 /************************************************************************
549  * OLEPictureImpl_set_hPal
550  */
551 static HRESULT WINAPI OLEPictureImpl_set_hPal(IPicture *iface,
552                                               OLE_HANDLE hpal)
553 {
554   ICOM_THIS(OLEPictureImpl, iface);
555   FIXME("(%p)->(%08x): stub\n", This, hpal);
556   OLEPicture_SendNotify(This,DISPID_PICT_HPAL);
557   return E_NOTIMPL;
558 }
559
560 /************************************************************************
561  * OLEPictureImpl_get_CurDC
562  */
563 static HRESULT WINAPI OLEPictureImpl_get_CurDC(IPicture *iface,
564                                                HDC *phdc)
565 {
566   ICOM_THIS(OLEPictureImpl, iface);
567   TRACE("(%p), returning %p\n", This, This->hDCCur);
568   if (phdc) *phdc = This->hDCCur;
569   return S_OK;
570 }
571
572 /************************************************************************
573  * OLEPictureImpl_SelectPicture
574  */
575 static HRESULT WINAPI OLEPictureImpl_SelectPicture(IPicture *iface,
576                                                    HDC hdcIn,
577                                                    HDC *phdcOut,
578                                                    OLE_HANDLE *phbmpOut)
579 {
580   ICOM_THIS(OLEPictureImpl, iface);
581   TRACE("(%p)->(%p, %p, %p)\n", This, hdcIn, phdcOut, phbmpOut);
582   if (This->desc.picType == PICTYPE_BITMAP) {
583       SelectObject(hdcIn,This->desc.u.bmp.hbitmap);
584
585       if (phdcOut)
586           *phdcOut = This->hDCCur;
587       This->hDCCur = hdcIn;
588       if (phbmpOut)
589           *phbmpOut = (OLE_HANDLE)This->desc.u.bmp.hbitmap;
590       return S_OK;
591   } else {
592       FIXME("Don't know how to select picture type %d\n",This->desc.picType);
593       return E_FAIL;
594   }
595 }
596
597 /************************************************************************
598  * OLEPictureImpl_get_KeepOriginalFormat
599  */
600 static HRESULT WINAPI OLEPictureImpl_get_KeepOriginalFormat(IPicture *iface,
601                                                             BOOL *pfKeep)
602 {
603   ICOM_THIS(OLEPictureImpl, iface);
604   TRACE("(%p)->(%p)\n", This, pfKeep);
605   if (!pfKeep)
606       return E_POINTER;
607   *pfKeep = This->keepOrigFormat;
608   return S_OK;
609 }
610
611 /************************************************************************
612  * OLEPictureImpl_put_KeepOriginalFormat
613  */
614 static HRESULT WINAPI OLEPictureImpl_put_KeepOriginalFormat(IPicture *iface,
615                                                             BOOL keep)
616 {
617   ICOM_THIS(OLEPictureImpl, iface);
618   TRACE("(%p)->(%d)\n", This, keep);
619   This->keepOrigFormat = keep;
620   /* FIXME: what DISPID notification here? */
621   return S_OK;
622 }
623
624 /************************************************************************
625  * OLEPictureImpl_PictureChanged
626  */
627 static HRESULT WINAPI OLEPictureImpl_PictureChanged(IPicture *iface)
628 {
629   ICOM_THIS(OLEPictureImpl, iface);
630   TRACE("(%p)->()\n", This);
631   OLEPicture_SendNotify(This,DISPID_PICT_HANDLE);
632   return S_OK;
633 }
634
635 /************************************************************************
636  * OLEPictureImpl_SaveAsFile
637  */
638 static HRESULT WINAPI OLEPictureImpl_SaveAsFile(IPicture *iface,
639                                                 IStream *pstream,
640                                                 BOOL SaveMemCopy,
641                                                 LONG *pcbSize)
642 {
643   ICOM_THIS(OLEPictureImpl, iface);
644   FIXME("(%p)->(%p, %d, %p), hacked stub.\n", This, pstream, SaveMemCopy, pcbSize);
645   return IStream_Write(pstream,This->data,This->datalen,(ULONG*)pcbSize);
646 }
647
648 /************************************************************************
649  * OLEPictureImpl_get_Attributes
650  */
651 static HRESULT WINAPI OLEPictureImpl_get_Attributes(IPicture *iface,
652                                                     DWORD *pdwAttr)
653 {
654   ICOM_THIS(OLEPictureImpl, iface);
655   TRACE("(%p)->(%p).\n", This, pdwAttr);
656   *pdwAttr = 0;
657   switch (This->desc.picType) {
658   case PICTYPE_BITMAP:  break;  /* not 'truely' scalable, see MSDN. */
659   case PICTYPE_ICON: *pdwAttr     = PICTURE_TRANSPARENT;break;
660   case PICTYPE_METAFILE: *pdwAttr = PICTURE_TRANSPARENT|PICTURE_SCALABLE;break;
661   default:FIXME("Unknown pictype %d\n",This->desc.picType);break;
662   }
663   return S_OK;
664 }
665
666
667 /************************************************************************
668  *    IConnectionPointContainer
669  */
670
671 static HRESULT WINAPI OLEPictureImpl_IConnectionPointContainer_QueryInterface(
672   IConnectionPointContainer* iface,
673   REFIID riid,
674   VOID** ppvoid
675 ) {
676   ICOM_THIS_From_IConnectionPointContainer(IPicture,iface);
677
678   return IPicture_QueryInterface(This,riid,ppvoid);
679 }
680
681 static ULONG WINAPI OLEPictureImpl_IConnectionPointContainer_AddRef(
682   IConnectionPointContainer* iface)
683 {
684   ICOM_THIS_From_IConnectionPointContainer(IPicture, iface);
685
686   return IPicture_AddRef(This);
687 }
688
689 static ULONG WINAPI OLEPictureImpl_IConnectionPointContainer_Release(
690   IConnectionPointContainer* iface)
691 {
692   ICOM_THIS_From_IConnectionPointContainer(IPicture, iface);
693
694   return IPicture_Release(This);
695 }
696
697 static HRESULT WINAPI OLEPictureImpl_EnumConnectionPoints(
698   IConnectionPointContainer* iface,
699   IEnumConnectionPoints** ppEnum
700 ) {
701   ICOM_THIS_From_IConnectionPointContainer(IPicture, iface);
702
703   FIXME("(%p,%p), stub!\n",This,ppEnum);
704   return E_NOTIMPL;
705 }
706
707 static HRESULT WINAPI OLEPictureImpl_FindConnectionPoint(
708   IConnectionPointContainer* iface,
709   REFIID riid,
710   IConnectionPoint **ppCP
711 ) {
712   ICOM_THIS_From_IConnectionPointContainer(OLEPictureImpl, iface);
713   TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppCP);
714   if (!ppCP)
715       return E_POINTER;
716   *ppCP = NULL;
717   if (IsEqualGUID(riid,&IID_IPropertyNotifySink))
718       return IConnectionPoint_QueryInterface(This->pCP,&IID_IConnectionPoint,(LPVOID)ppCP);
719   FIXME("tried to find connection point on %s?\n",debugstr_guid(riid));
720   return 0x80040200;
721 }
722 /************************************************************************
723  *    IPersistStream
724  */
725 /************************************************************************
726  * OLEPictureImpl_IPersistStream_QueryInterface (IUnknown)
727  *
728  * See Windows documentation for more details on IUnknown methods.
729  */
730 static HRESULT WINAPI OLEPictureImpl_IPersistStream_QueryInterface(
731   IPersistStream* iface,
732   REFIID     riid,
733   VOID**     ppvoid)
734 {
735   ICOM_THIS_From_IPersistStream(IPicture, iface);
736
737   return IPicture_QueryInterface(This, riid, ppvoid);
738 }
739
740 /************************************************************************
741  * OLEPictureImpl_IPersistStream_AddRef (IUnknown)
742  *
743  * See Windows documentation for more details on IUnknown methods.
744  */
745 static ULONG WINAPI OLEPictureImpl_IPersistStream_AddRef(
746   IPersistStream* iface)
747 {
748   ICOM_THIS_From_IPersistStream(IPicture, iface);
749
750   return IPicture_AddRef(This);
751 }
752
753 /************************************************************************
754  * OLEPictureImpl_IPersistStream_Release (IUnknown)
755  *
756  * See Windows documentation for more details on IUnknown methods.
757  */
758 static ULONG WINAPI OLEPictureImpl_IPersistStream_Release(
759   IPersistStream* iface)
760 {
761   ICOM_THIS_From_IPersistStream(IPicture, iface);
762
763   return IPicture_Release(This);
764 }
765
766 /************************************************************************
767  * OLEPictureImpl_IPersistStream_GetClassID
768  */
769 static HRESULT WINAPI OLEPictureImpl_GetClassID(
770   IPersistStream* iface,CLSID* pClassID)
771 {
772   ICOM_THIS_From_IPersistStream(IPicture, iface);
773   FIXME("(%p),stub!\n",This);
774   return E_NOTIMPL;
775 }
776
777 /************************************************************************
778  * OLEPictureImpl_IPersistStream_IsDirty
779  */
780 static HRESULT WINAPI OLEPictureImpl_IsDirty(
781   IPersistStream* iface)
782 {
783   ICOM_THIS_From_IPersistStream(IPicture, iface);
784   FIXME("(%p),stub!\n",This);
785   return E_NOTIMPL;
786 }
787
788 #ifdef HAVE_LIBJPEG
789 /* for the jpeg decompressor source manager. */
790 static void _jpeg_init_source(j_decompress_ptr cinfo) { }
791
792 static boolean _jpeg_fill_input_buffer(j_decompress_ptr cinfo) {
793     ERR("(), should not get here.\n");
794     return FALSE;
795 }
796
797 static void _jpeg_skip_input_data(j_decompress_ptr cinfo,long num_bytes) {
798     ERR("(%ld), should not get here.\n",num_bytes);
799 }
800
801 static boolean _jpeg_resync_to_restart(j_decompress_ptr cinfo, int desired) {
802     ERR("(desired=%d), should not get here.\n",desired);
803     return FALSE;
804 }
805 static void _jpeg_term_source(j_decompress_ptr cinfo) { }
806 #endif /* HAVE_LIBJPEG */
807
808 /************************************************************************
809  * OLEPictureImpl_IPersistStream_Load (IUnknown)
810  *
811  * Loads the binary data from the IStream. Starts at current position.
812  * There appears to be an 2 DWORD header:
813  *      DWORD magic;
814  *      DWORD len;
815  *
816  * Currently implemented: BITMAP, ICON, JPEG.
817  */
818 static HRESULT WINAPI OLEPictureImpl_Load(IPersistStream* iface,IStream*pStm) {
819   HRESULT       hr = E_FAIL;
820   ULONG         xread;
821   BYTE          *xbuf;
822   DWORD         header[2];
823   WORD          magic;
824   ICOM_THIS_From_IPersistStream(OLEPictureImpl, iface);
825
826   TRACE("(%p,%p)\n",This,pStm);
827
828   hr=IStream_Read(pStm,header,8,&xread);
829   if (hr || xread!=8) {
830       FIXME("Failure while reading picture header (hr is %lx, nread is %ld).\n",hr,xread);
831       return hr;
832   }
833   xread = 0;
834   xbuf = This->data = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,header[1]);
835   This->datalen = header[1];
836   while (xread < header[1]) {
837     ULONG nread;
838     hr = IStream_Read(pStm,xbuf+xread,header[1]-xread,&nread);
839     xread+=nread;
840     if (hr || !nread)
841       break;
842   }
843   if (xread != header[1])
844     FIXME("Could only read %ld of %ld bytes?\n",xread,header[1]);
845
846   magic = xbuf[0] + (xbuf[1]<<8);
847   switch (magic) {
848   case 0xd8ff: { /* JPEG */
849 #ifdef HAVE_LIBJPEG
850     struct jpeg_decompress_struct       jd;
851     struct jpeg_error_mgr               jerr;
852     int                                 ret;
853     JDIMENSION                          x;
854     JSAMPROW                            samprow;
855     BITMAPINFOHEADER                    bmi;
856     LPBYTE                              bits;
857     HDC                                 hdcref;
858     struct jpeg_source_mgr              xjsm;
859
860     /* This is basically so we can use in-memory data for jpeg decompression.
861      * We need to have all the functions.
862      */
863     xjsm.next_input_byte        = xbuf;
864     xjsm.bytes_in_buffer        = xread;
865     xjsm.init_source            = _jpeg_init_source;
866     xjsm.fill_input_buffer      = _jpeg_fill_input_buffer;
867     xjsm.skip_input_data        = _jpeg_skip_input_data;
868     xjsm.resync_to_restart      = _jpeg_resync_to_restart;
869     xjsm.term_source            = _jpeg_term_source;
870
871     jd.err = jpeg_std_error(&jerr);
872     jpeg_create_decompress(&jd);
873     jd.src = &xjsm;
874     ret=jpeg_read_header(&jd,TRUE);
875     jpeg_start_decompress(&jd);
876     if (ret != JPEG_HEADER_OK) {
877         ERR("Jpeg image in stream has bad format, read header returned %d.\n",ret);
878         HeapFree(GetProcessHeap(),0,xbuf);
879         return E_FAIL;
880     }
881     bits = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(jd.output_height+1)*jd.output_width*jd.output_components);
882     samprow=HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,jd.output_width*jd.output_components);
883     while ( jd.output_scanline<jd.output_height ) {
884       x = jpeg_read_scanlines(&jd,&samprow,1);
885       if (x != 1) {
886         FIXME("failed to read current scanline?\n");
887         break;
888       }
889       memcpy( bits+jd.output_scanline*jd.output_width*jd.output_components,
890               samprow,
891               jd.output_width*jd.output_components
892       );
893     }
894     bmi.biSize          = sizeof(bmi);
895     bmi.biWidth         =  jd.output_width;
896     bmi.biHeight        = -jd.output_height;
897     bmi.biPlanes        = 1;
898     bmi.biBitCount      = jd.output_components<<3;
899     bmi.biCompression   = BI_RGB;
900     bmi.biSizeImage     = jd.output_height*jd.output_width*jd.output_components;
901     bmi.biXPelsPerMeter = 0;
902     bmi.biYPelsPerMeter = 0;
903     bmi.biClrUsed       = 0;
904     bmi.biClrImportant  = 0;
905
906     HeapFree(GetProcessHeap(),0,samprow);
907     jpeg_finish_decompress(&jd);
908     jpeg_destroy_decompress(&jd);
909     hdcref = GetDC(0);
910     This->desc.u.bmp.hbitmap=CreateDIBitmap(
911             hdcref,
912             &bmi,
913             CBM_INIT,
914             bits,
915             (BITMAPINFO*)&bmi,
916             DIB_RGB_COLORS
917     );
918     DeleteDC(hdcref);
919     This->desc.picType = PICTYPE_BITMAP;
920     OLEPictureImpl_SetBitmap(This);
921     hr = S_OK;
922     HeapFree(GetProcessHeap(),0,bits);
923 #else
924     ERR("Trying to load JPEG picture, but JPEG supported not compiled in.\n");
925     hr = E_FAIL;
926 #endif
927     break;
928   }
929   case 0x4d42: { /* Bitmap */
930     BITMAPFILEHEADER    *bfh = (BITMAPFILEHEADER*)xbuf;
931     BITMAPINFO          *bi = (BITMAPINFO*)(bfh+1);
932     HDC                 hdcref;
933
934     /* Does not matter whether this is a coreheader or not, we only use
935      * components which are in both
936      */
937     hdcref = GetDC(0);
938     This->desc.u.bmp.hbitmap = CreateDIBitmap(
939         hdcref,
940         &(bi->bmiHeader),
941         CBM_INIT,
942         xbuf+bfh->bfOffBits,
943         bi,
944         (bi->bmiHeader.biBitCount<=8)?DIB_PAL_COLORS:DIB_RGB_COLORS
945     );
946     DeleteDC(hdcref);
947     This->desc.picType = PICTYPE_BITMAP;
948     OLEPictureImpl_SetBitmap(This);
949     hr = S_OK;
950     break;
951   }
952   case 0x0000: { /* ICON , first word is dwReserved */
953     HICON hicon;
954     CURSORICONFILEDIR   *cifd = (CURSORICONFILEDIR*)xbuf;
955     int i;
956
957     /*
958     FIXME("icon.idReserved=%d\n",cifd->idReserved);
959     FIXME("icon.idType=%d\n",cifd->idType);
960     FIXME("icon.idCount=%d\n",cifd->idCount);
961
962     for (i=0;i<cifd->idCount;i++) {
963         FIXME("[%d] width %d\n",i,cifd->idEntries[i].bWidth);
964         FIXME("[%d] height %d\n",i,cifd->idEntries[i].bHeight);
965         FIXME("[%d] bColorCount %d\n",i,cifd->idEntries[i].bColorCount);
966         FIXME("[%d] bReserved %d\n",i,cifd->idEntries[i].bReserved);
967         FIXME("[%d] xHotspot %d\n",i,cifd->idEntries[i].xHotspot);
968         FIXME("[%d] yHotspot %d\n",i,cifd->idEntries[i].yHotspot);
969         FIXME("[%d] dwDIBSize %d\n",i,cifd->idEntries[i].dwDIBSize);
970         FIXME("[%d] dwDIBOffset %d\n",i,cifd->idEntries[i].dwDIBOffset);
971     }
972     */
973     i=0;
974     /* If we have more than one icon, try to find the best.
975      * this currently means '32 pixel wide'.
976      */
977     if (cifd->idCount!=1) {
978         for (i=0;i<cifd->idCount;i++) {
979             if (cifd->idEntries[i].bWidth == 32)
980                 break;
981         }
982         if (i==cifd->idCount) i=0;
983     }
984
985     hicon = CreateIconFromResourceEx(
986                 xbuf+cifd->idEntries[i].dwDIBOffset,
987                 cifd->idEntries[i].dwDIBSize,
988                 TRUE, /* is icon */
989                 0x00030000,
990                 cifd->idEntries[i].bWidth,
991                 cifd->idEntries[i].bHeight,
992                 0
993     );
994     if (!hicon) {
995         FIXME("CreateIcon failed.\n");
996         hr = E_FAIL;
997     } else {
998         This->desc.picType = PICTYPE_ICON;
999         This->desc.u.icon.hicon = hicon;
1000         hr = S_OK;
1001     }
1002     break;
1003   }
1004   default:
1005     FIXME("Unknown magic %04x\n",magic);
1006     hr=E_FAIL;
1007     break;
1008   }
1009
1010   /* FIXME: this notify is not really documented */
1011   if (hr==S_OK)
1012       OLEPicture_SendNotify(This,DISPID_PICT_TYPE);
1013   return hr;
1014 }
1015
1016 static HRESULT WINAPI OLEPictureImpl_Save(
1017   IPersistStream* iface,IStream*pStm,BOOL fClearDirty)
1018 {
1019   ICOM_THIS_From_IPersistStream(IPicture, iface);
1020   FIXME("(%p,%p,%d),stub!\n",This,pStm,fClearDirty);
1021   return E_NOTIMPL;
1022 }
1023
1024 static HRESULT WINAPI OLEPictureImpl_GetSizeMax(
1025   IPersistStream* iface,ULARGE_INTEGER*pcbSize)
1026 {
1027   ICOM_THIS_From_IPersistStream(IPicture, iface);
1028   FIXME("(%p,%p),stub!\n",This,pcbSize);
1029   return E_NOTIMPL;
1030 }
1031
1032 /************************************************************************
1033  *    IDispatch
1034  */
1035 /************************************************************************
1036  * OLEPictureImpl_IDispatch_QueryInterface (IUnknown)
1037  *
1038  * See Windows documentation for more details on IUnknown methods.
1039  */
1040 static HRESULT WINAPI OLEPictureImpl_IDispatch_QueryInterface(
1041   IDispatch* iface,
1042   REFIID     riid,
1043   VOID**     ppvoid)
1044 {
1045   ICOM_THIS_From_IDispatch(IPicture, iface);
1046
1047   return IPicture_QueryInterface(This, riid, ppvoid);
1048 }
1049
1050 /************************************************************************
1051  * OLEPictureImpl_IDispatch_AddRef (IUnknown)
1052  *
1053  * See Windows documentation for more details on IUnknown methods.
1054  */
1055 static ULONG WINAPI OLEPictureImpl_IDispatch_AddRef(
1056   IDispatch* iface)
1057 {
1058   ICOM_THIS_From_IDispatch(IPicture, iface);
1059
1060   return IPicture_AddRef(This);
1061 }
1062
1063 /************************************************************************
1064  * OLEPictureImpl_IDispatch_Release (IUnknown)
1065  *
1066  * See Windows documentation for more details on IUnknown methods.
1067  */
1068 static ULONG WINAPI OLEPictureImpl_IDispatch_Release(
1069   IDispatch* iface)
1070 {
1071   ICOM_THIS_From_IDispatch(IPicture, iface);
1072
1073   return IPicture_Release(This);
1074 }
1075
1076 /************************************************************************
1077  * OLEPictureImpl_GetTypeInfoCount (IDispatch)
1078  *
1079  * See Windows documentation for more details on IDispatch methods.
1080  */
1081 static HRESULT WINAPI OLEPictureImpl_GetTypeInfoCount(
1082   IDispatch*    iface,
1083   unsigned int* pctinfo)
1084 {
1085   FIXME("():Stub\n");
1086
1087   return E_NOTIMPL;
1088 }
1089
1090 /************************************************************************
1091  * OLEPictureImpl_GetTypeInfo (IDispatch)
1092  *
1093  * See Windows documentation for more details on IDispatch methods.
1094  */
1095 static HRESULT WINAPI OLEPictureImpl_GetTypeInfo(
1096   IDispatch*  iface,
1097   UINT      iTInfo,
1098   LCID        lcid,
1099   ITypeInfo** ppTInfo)
1100 {
1101   FIXME("():Stub\n");
1102
1103   return E_NOTIMPL;
1104 }
1105
1106 /************************************************************************
1107  * OLEPictureImpl_GetIDsOfNames (IDispatch)
1108  *
1109  * See Windows documentation for more details on IDispatch methods.
1110  */
1111 static HRESULT WINAPI OLEPictureImpl_GetIDsOfNames(
1112   IDispatch*  iface,
1113   REFIID      riid,
1114   LPOLESTR* rgszNames,
1115   UINT      cNames,
1116   LCID        lcid,
1117   DISPID*     rgDispId)
1118 {
1119   FIXME("():Stub\n");
1120
1121   return E_NOTIMPL;
1122 }
1123
1124 /************************************************************************
1125  * OLEPictureImpl_Invoke (IDispatch)
1126  *
1127  * See Windows documentation for more details on IDispatch methods.
1128  */
1129 static HRESULT WINAPI OLEPictureImpl_Invoke(
1130   IDispatch*  iface,
1131   DISPID      dispIdMember,
1132   REFIID      riid,
1133   LCID        lcid,
1134   WORD        wFlags,
1135   DISPPARAMS* pDispParams,
1136   VARIANT*    pVarResult,
1137   EXCEPINFO*  pExepInfo,
1138   UINT*     puArgErr)
1139 {
1140   FIXME("(dispid: %ld):Stub\n",dispIdMember);
1141
1142   VariantInit(pVarResult);
1143   V_VT(pVarResult) = VT_BOOL;
1144   V_UNION(pVarResult,boolVal) = FALSE;
1145   return S_OK;
1146 }
1147
1148
1149 static ICOM_VTABLE(IPicture) OLEPictureImpl_VTable =
1150 {
1151   ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1152   OLEPictureImpl_QueryInterface,
1153   OLEPictureImpl_AddRef,
1154   OLEPictureImpl_Release,
1155   OLEPictureImpl_get_Handle,
1156   OLEPictureImpl_get_hPal,
1157   OLEPictureImpl_get_Type,
1158   OLEPictureImpl_get_Width,
1159   OLEPictureImpl_get_Height,
1160   OLEPictureImpl_Render,
1161   OLEPictureImpl_set_hPal,
1162   OLEPictureImpl_get_CurDC,
1163   OLEPictureImpl_SelectPicture,
1164   OLEPictureImpl_get_KeepOriginalFormat,
1165   OLEPictureImpl_put_KeepOriginalFormat,
1166   OLEPictureImpl_PictureChanged,
1167   OLEPictureImpl_SaveAsFile,
1168   OLEPictureImpl_get_Attributes
1169 };
1170
1171 static ICOM_VTABLE(IDispatch) OLEPictureImpl_IDispatch_VTable =
1172 {
1173   ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1174   OLEPictureImpl_IDispatch_QueryInterface,
1175   OLEPictureImpl_IDispatch_AddRef,
1176   OLEPictureImpl_IDispatch_Release,
1177   OLEPictureImpl_GetTypeInfoCount,
1178   OLEPictureImpl_GetTypeInfo,
1179   OLEPictureImpl_GetIDsOfNames,
1180   OLEPictureImpl_Invoke
1181 };
1182
1183 static ICOM_VTABLE(IPersistStream) OLEPictureImpl_IPersistStream_VTable =
1184 {
1185   ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1186   OLEPictureImpl_IPersistStream_QueryInterface,
1187   OLEPictureImpl_IPersistStream_AddRef,
1188   OLEPictureImpl_IPersistStream_Release,
1189   OLEPictureImpl_GetClassID,
1190   OLEPictureImpl_IsDirty,
1191   OLEPictureImpl_Load,
1192   OLEPictureImpl_Save,
1193   OLEPictureImpl_GetSizeMax
1194 };
1195
1196 static ICOM_VTABLE(IConnectionPointContainer) OLEPictureImpl_IConnectionPointContainer_VTable =
1197 {
1198   ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1199   OLEPictureImpl_IConnectionPointContainer_QueryInterface,
1200   OLEPictureImpl_IConnectionPointContainer_AddRef,
1201   OLEPictureImpl_IConnectionPointContainer_Release,
1202   OLEPictureImpl_EnumConnectionPoints,
1203   OLEPictureImpl_FindConnectionPoint
1204 };
1205
1206 /***********************************************************************
1207  * OleCreatePictureIndirect (OLEAUT32.419)
1208  */
1209 HRESULT WINAPI OleCreatePictureIndirect(LPPICTDESC lpPictDesc, REFIID riid,
1210                             BOOL fOwn, LPVOID *ppvObj )
1211 {
1212   OLEPictureImpl* newPict = NULL;
1213   HRESULT      hr         = S_OK;
1214
1215   TRACE("(%p,%p,%d,%p)\n", lpPictDesc, riid, fOwn, ppvObj);
1216
1217   /*
1218    * Sanity check
1219    */
1220   if (ppvObj==0)
1221     return E_POINTER;
1222
1223   *ppvObj = NULL;
1224
1225   /*
1226    * Try to construct a new instance of the class.
1227    */
1228   newPict = OLEPictureImpl_Construct(lpPictDesc, fOwn);
1229
1230   if (newPict == NULL)
1231     return E_OUTOFMEMORY;
1232
1233   /*
1234    * Make sure it supports the interface required by the caller.
1235    */
1236   hr = IPicture_QueryInterface((IPicture*)newPict, riid, ppvObj);
1237
1238   /*
1239    * Release the reference obtained in the constructor. If
1240    * the QueryInterface was unsuccessful, it will free the class.
1241    */
1242   IPicture_Release((IPicture*)newPict);
1243
1244   return hr;
1245 }
1246
1247
1248 /***********************************************************************
1249  * OleLoadPicture (OLEAUT32.418)
1250  */
1251 HRESULT WINAPI OleLoadPicture( LPSTREAM lpstream, LONG lSize, BOOL fRunmode,
1252                             REFIID riid, LPVOID *ppvObj )
1253 {
1254   LPPERSISTSTREAM ps;
1255   IPicture      *newpic;
1256   HRESULT hr;
1257
1258   TRACE("(%p,%ld,%d,%s,%p), partially implemented.\n",
1259         lpstream, lSize, fRunmode, debugstr_guid(riid), ppvObj);
1260
1261   hr = OleCreatePictureIndirect(NULL,riid,!fRunmode,(LPVOID*)&newpic);
1262   if (hr)
1263     return hr;
1264   hr = IPicture_QueryInterface(newpic,&IID_IPersistStream, (LPVOID*)&ps);
1265   if (hr) {
1266       FIXME("Could not get IPersistStream iface from Ole Picture?\n");
1267       IPicture_Release(newpic);
1268       *ppvObj = NULL;
1269       return hr;
1270   }
1271   IPersistStream_Load(ps,lpstream);
1272   IPersistStream_Release(ps);
1273   hr = IPicture_QueryInterface(newpic,riid,ppvObj);
1274   if (hr)
1275       FIXME("Failed to get interface %s from IPicture.\n",debugstr_guid(riid));
1276   IPicture_Release(newpic);
1277   return hr;
1278 }
1279
1280 /***********************************************************************
1281  * OleLoadPictureEx (OLEAUT32.401)
1282  */
1283 HRESULT WINAPI OleLoadPictureEx( LPSTREAM lpstream, LONG lSize, BOOL fRunmode,
1284                             REFIID riid, DWORD xsiz, DWORD ysiz, DWORD flags, LPVOID *ppvObj )
1285 {
1286   LPPERSISTSTREAM ps;
1287   IPicture      *newpic;
1288   HRESULT hr;
1289
1290   FIXME("(%p,%ld,%d,%s,x=%ld,y=%ld,f=%lx,%p), partially implemented.\n",
1291         lpstream, lSize, fRunmode, debugstr_guid(riid), xsiz, ysiz, flags, ppvObj);
1292
1293   hr = OleCreatePictureIndirect(NULL,riid,!fRunmode,(LPVOID*)&newpic);
1294   if (hr)
1295     return hr;
1296   hr = IPicture_QueryInterface(newpic,&IID_IPersistStream, (LPVOID*)&ps);
1297   if (hr) {
1298       FIXME("Could not get IPersistStream iface from Ole Picture?\n");
1299       IPicture_Release(newpic);
1300       *ppvObj = NULL;
1301       return hr;
1302   }
1303   IPersistStream_Load(ps,lpstream);
1304   IPersistStream_Release(ps);
1305   hr = IPicture_QueryInterface(newpic,riid,ppvObj);
1306   if (hr)
1307       FIXME("Failed to get interface %s from IPicture.\n",debugstr_guid(riid));
1308   IPicture_Release(newpic);
1309   return hr;
1310 }