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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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).
52 #include "wine/obj_picture.h"
53 #include "wine/obj_connection.h"
55 #include "wine/debug.h"
57 #include "wine/wingdi16.h"
58 #include "cursoricon.h"
61 /* This is a hack, so jpeglib.h does not redefine INT32 and the like*/
63 #define UINT8 JPEG_UINT8
64 #define UINT16 JPEG_UINT16
71 WINE_DEFAULT_DEBUG_CHANNEL(ole);
73 /*************************************************************************
74 * Declaration of implementation class
77 typedef struct OLEPictureImpl {
80 * IPicture handles IUnknown
83 ICOM_VTABLE(IPicture) *lpvtbl1;
84 ICOM_VTABLE(IDispatch) *lpvtbl2;
85 ICOM_VTABLE(IPersistStream) *lpvtbl3;
86 ICOM_VTABLE(IConnectionPointContainer) *lpvtbl4;
88 /* Object referenece count */
91 /* We own the object and must destroy it ourselves */
94 /* Picture description */
97 /* These are the pixel size of a bitmap */
101 /* And these are the size of the picture converted into HIMETRIC units */
102 OLE_XSIZE_HIMETRIC himetricWidth;
103 OLE_YSIZE_HIMETRIC himetricHeight;
105 IConnectionPoint *pCP;
116 * Macros to retrieve pointer to IUnknown (IPicture) from the other VTables.
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*));
126 * Predeclare VTables. They get initialized at the end.
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;
133 /***********************************************************************
134 * Implementation of the OLEPictureImpl class.
137 static void OLEPictureImpl_SetBitmap(OLEPictureImpl*This) {
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");
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);
158 /************************************************************************
159 * OLEPictureImpl_Construct
161 * This method will construct a new instance of the OLEPictureImpl
164 * The caller of this method must release the object when it's
167 static OLEPictureImpl* OLEPictureImpl_Construct(LPPICTDESC pictDesc, BOOL fOwn)
169 OLEPictureImpl* newObject = 0;
172 TRACE("(%p) type = %d\n", pictDesc, pictDesc->picType);
175 * Allocate space for the object.
177 newObject = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(OLEPictureImpl));
183 * Initialize the virtual function table.
185 newObject->lpvtbl1 = &OLEPictureImpl_VTable;
186 newObject->lpvtbl2 = &OLEPictureImpl_IDispatch_VTable;
187 newObject->lpvtbl3 = &OLEPictureImpl_IPersistStream_VTable;
188 newObject->lpvtbl4 = &OLEPictureImpl_IConnectionPointContainer_VTable;
190 CreateConnectionPoint((IUnknown*)newObject,&IID_IPropertyNotifySink,&newObject->pCP);
193 * Start with one reference count. The caller of this function
194 * must release the interface pointer when it is done.
197 newObject->hDCCur = 0;
199 newObject->fOwn = fOwn;
201 /* dunno about original value */
202 newObject->keepOrigFormat = TRUE;
205 if(pictDesc->cbSizeofstruct != sizeof(PICTDESC)) {
206 FIXME("struct size = %d\n", pictDesc->cbSizeofstruct);
208 memcpy(&newObject->desc, pictDesc, sizeof(PICTDESC));
211 switch(pictDesc->picType) {
213 OLEPictureImpl_SetBitmap(newObject);
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;
223 case PICTYPE_ENHMETAFILE:
225 FIXME("Unsupported type %d\n", pictDesc->picType);
226 newObject->himetricWidth = newObject->himetricHeight = 0;
230 newObject->desc.picType = PICTYPE_UNINITIALIZED;
233 TRACE("returning %p\n", newObject);
237 /************************************************************************
238 * OLEPictureImpl_Destroy
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
243 static void OLEPictureImpl_Destroy(OLEPictureImpl* Obj)
245 TRACE("(%p)\n", Obj);
247 if(Obj->fOwn) { /* We need to destroy the picture */
248 switch(Obj->desc.picType) {
250 DeleteObject(Obj->desc.u.bmp.hbitmap);
252 case PICTYPE_METAFILE:
253 DeleteMetaFile(Obj->desc.u.wmf.hmeta);
256 DestroyIcon(Obj->desc.u.icon.hicon);
258 case PICTYPE_ENHMETAFILE:
259 DeleteEnhMetaFile(Obj->desc.u.emf.hemf);
262 FIXME("Unsupported type %d - unable to delete\n", Obj->desc.picType);
266 if (Obj->data) HeapFree(GetProcessHeap(), 0, Obj->data);
267 HeapFree(GetProcessHeap(), 0, Obj);
270 static ULONG WINAPI OLEPictureImpl_AddRef(IPicture* iface);
272 /************************************************************************
273 * OLEPictureImpl_QueryInterface (IUnknown)
275 * See Windows documentation for more details on IUnknown methods.
277 static HRESULT WINAPI OLEPictureImpl_QueryInterface(
282 ICOM_THIS(OLEPictureImpl, iface);
283 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppvObject);
286 * Perform a sanity check on the parameters.
288 if ( (This==0) || (ppvObject==0) )
292 * Initialize the return parameter.
297 * Compare the riid with the interface IDs implemented by this object.
299 if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0)
301 *ppvObject = (IPicture*)This;
303 else if (memcmp(&IID_IPicture, riid, sizeof(IID_IPicture)) == 0)
305 *ppvObject = (IPicture*)This;
307 else if (memcmp(&IID_IDispatch, riid, sizeof(IID_IDispatch)) == 0)
309 *ppvObject = (IDispatch*)&(This->lpvtbl2);
311 else if (memcmp(&IID_IPictureDisp, riid, sizeof(IID_IPictureDisp)) == 0)
313 *ppvObject = (IDispatch*)&(This->lpvtbl2);
315 else if (memcmp(&IID_IPersistStream, riid, sizeof(IID_IPersistStream)) == 0)
317 *ppvObject = (IPersistStream*)&(This->lpvtbl3);
319 else if (memcmp(&IID_IConnectionPointContainer, riid, sizeof(IID_IConnectionPointContainer)) == 0)
321 *ppvObject = (IConnectionPointContainer*)&(This->lpvtbl4);
324 * Check that we obtained an interface.
328 FIXME("() : asking for un supported interface %s\n",debugstr_guid(riid));
329 return E_NOINTERFACE;
333 * Query Interface always increases the reference count by one when it is
336 OLEPictureImpl_AddRef((IPicture*)This);
340 /***********************************************************************
341 * OLEPicture_SendNotify (internal)
343 * Sends notification messages of changed properties to any interested
346 static void OLEPicture_SendNotify(OLEPictureImpl* this, DISPID dispID)
348 IEnumConnections *pEnum;
351 if (IConnectionPoint_EnumConnections(this->pCP, &pEnum))
353 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
354 IPropertyNotifySink *sink;
356 IUnknown_QueryInterface(CD.pUnk, &IID_IPropertyNotifySink, (LPVOID)&sink);
357 IPropertyNotifySink_OnChanged(sink, dispID);
358 IPropertyNotifySink_Release(sink);
359 IUnknown_Release(CD.pUnk);
361 IEnumConnections_Release(pEnum);
365 /************************************************************************
366 * OLEPictureImpl_AddRef (IUnknown)
368 * See Windows documentation for more details on IUnknown methods.
370 static ULONG WINAPI OLEPictureImpl_AddRef(
373 ICOM_THIS(OLEPictureImpl, iface);
374 TRACE("(%p)->(ref=%ld)\n", This, This->ref);
380 /************************************************************************
381 * OLEPictureImpl_Release (IUnknown)
383 * See Windows documentation for more details on IUnknown methods.
385 static ULONG WINAPI OLEPictureImpl_Release(
388 ICOM_THIS(OLEPictureImpl, iface);
389 TRACE("(%p)->(ref=%ld)\n", This, This->ref);
392 * Decrease the reference count on this object.
397 * If the reference count goes down to 0, perform suicide.
401 OLEPictureImpl_Destroy(This);
410 /************************************************************************
411 * OLEPictureImpl_get_Handle
413 static HRESULT WINAPI OLEPictureImpl_get_Handle(IPicture *iface,
416 ICOM_THIS(OLEPictureImpl, iface);
417 TRACE("(%p)->(%p)\n", This, phandle);
418 switch(This->desc.picType) {
420 *phandle = (OLE_HANDLE)This->desc.u.bmp.hbitmap;
422 case PICTYPE_METAFILE:
423 *phandle = (OLE_HANDLE)This->desc.u.wmf.hmeta;
426 *phandle = (OLE_HANDLE)This->desc.u.icon.hicon;
428 case PICTYPE_ENHMETAFILE:
429 *phandle = (OLE_HANDLE)This->desc.u.emf.hemf;
432 FIXME("Unimplemented type %d\n", This->desc.picType);
435 TRACE("returning handle %08x\n", *phandle);
439 /************************************************************************
440 * OLEPictureImpl_get_hPal
442 static HRESULT WINAPI OLEPictureImpl_get_hPal(IPicture *iface,
445 ICOM_THIS(OLEPictureImpl, iface);
446 FIXME("(%p)->(%p): stub\n", This, phandle);
450 /************************************************************************
451 * OLEPictureImpl_get_Type
453 static HRESULT WINAPI OLEPictureImpl_get_Type(IPicture *iface,
456 ICOM_THIS(OLEPictureImpl, iface);
457 TRACE("(%p)->(%p): type is %d\n", This, ptype, This->desc.picType);
458 *ptype = This->desc.picType;
462 /************************************************************************
463 * OLEPictureImpl_get_Width
465 static HRESULT WINAPI OLEPictureImpl_get_Width(IPicture *iface,
466 OLE_XSIZE_HIMETRIC *pwidth)
468 ICOM_THIS(OLEPictureImpl, iface);
469 TRACE("(%p)->(%p): width is %ld\n", This, pwidth, This->himetricWidth);
470 *pwidth = This->himetricWidth;
474 /************************************************************************
475 * OLEPictureImpl_get_Height
477 static HRESULT WINAPI OLEPictureImpl_get_Height(IPicture *iface,
478 OLE_YSIZE_HIMETRIC *pheight)
480 ICOM_THIS(OLEPictureImpl, iface);
481 TRACE("(%p)->(%p): height is %ld\n", This, pheight, This->himetricHeight);
482 *pheight = This->himetricHeight;
486 /************************************************************************
487 * OLEPictureImpl_Render
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,
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);
501 TRACE("prcWBounds (%d,%d) - (%d,%d)\n", prcWBounds->left, prcWBounds->top,
502 prcWBounds->right, prcWBounds->bottom);
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);
510 switch(This->desc.picType) {
516 /* Set a mapping mode that maps bitmap pixels into HIMETRIC units.
517 NB y-axis gets flipped */
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);
526 hbmpOld = SelectObject(hdcBmp, This->desc.u.bmp.hbitmap);
528 StretchBlt(hdc, x, y, cx, cy, hdcBmp, xSrc, ySrc, cxSrc, cySrc, SRCCOPY);
530 SelectObject(hdcBmp, hbmpOld);
535 FIXME("Not quite correct implementation of rendering icons...\n");
536 DrawIcon(hdc,x,y,This->desc.u.icon.hicon);
539 case PICTYPE_METAFILE:
540 case PICTYPE_ENHMETAFILE:
542 FIXME("type %d not implemented\n", This->desc.picType);
548 /************************************************************************
549 * OLEPictureImpl_set_hPal
551 static HRESULT WINAPI OLEPictureImpl_set_hPal(IPicture *iface,
554 ICOM_THIS(OLEPictureImpl, iface);
555 FIXME("(%p)->(%08x): stub\n", This, hpal);
556 OLEPicture_SendNotify(This,DISPID_PICT_HPAL);
560 /************************************************************************
561 * OLEPictureImpl_get_CurDC
563 static HRESULT WINAPI OLEPictureImpl_get_CurDC(IPicture *iface,
566 ICOM_THIS(OLEPictureImpl, iface);
567 TRACE("(%p), returning %p\n", This, This->hDCCur);
568 if (phdc) *phdc = This->hDCCur;
572 /************************************************************************
573 * OLEPictureImpl_SelectPicture
575 static HRESULT WINAPI OLEPictureImpl_SelectPicture(IPicture *iface,
578 OLE_HANDLE *phbmpOut)
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);
586 *phdcOut = This->hDCCur;
587 This->hDCCur = hdcIn;
589 *phbmpOut = (OLE_HANDLE)This->desc.u.bmp.hbitmap;
592 FIXME("Don't know how to select picture type %d\n",This->desc.picType);
597 /************************************************************************
598 * OLEPictureImpl_get_KeepOriginalFormat
600 static HRESULT WINAPI OLEPictureImpl_get_KeepOriginalFormat(IPicture *iface,
603 ICOM_THIS(OLEPictureImpl, iface);
604 TRACE("(%p)->(%p)\n", This, pfKeep);
607 *pfKeep = This->keepOrigFormat;
611 /************************************************************************
612 * OLEPictureImpl_put_KeepOriginalFormat
614 static HRESULT WINAPI OLEPictureImpl_put_KeepOriginalFormat(IPicture *iface,
617 ICOM_THIS(OLEPictureImpl, iface);
618 TRACE("(%p)->(%d)\n", This, keep);
619 This->keepOrigFormat = keep;
620 /* FIXME: what DISPID notification here? */
624 /************************************************************************
625 * OLEPictureImpl_PictureChanged
627 static HRESULT WINAPI OLEPictureImpl_PictureChanged(IPicture *iface)
629 ICOM_THIS(OLEPictureImpl, iface);
630 TRACE("(%p)->()\n", This);
631 OLEPicture_SendNotify(This,DISPID_PICT_HANDLE);
635 /************************************************************************
636 * OLEPictureImpl_SaveAsFile
638 static HRESULT WINAPI OLEPictureImpl_SaveAsFile(IPicture *iface,
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);
648 /************************************************************************
649 * OLEPictureImpl_get_Attributes
651 static HRESULT WINAPI OLEPictureImpl_get_Attributes(IPicture *iface,
654 ICOM_THIS(OLEPictureImpl, iface);
655 TRACE("(%p)->(%p).\n", This, pdwAttr);
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;
667 /************************************************************************
668 * IConnectionPointContainer
671 static HRESULT WINAPI OLEPictureImpl_IConnectionPointContainer_QueryInterface(
672 IConnectionPointContainer* iface,
676 ICOM_THIS_From_IConnectionPointContainer(IPicture,iface);
678 return IPicture_QueryInterface(This,riid,ppvoid);
681 static ULONG WINAPI OLEPictureImpl_IConnectionPointContainer_AddRef(
682 IConnectionPointContainer* iface)
684 ICOM_THIS_From_IConnectionPointContainer(IPicture, iface);
686 return IPicture_AddRef(This);
689 static ULONG WINAPI OLEPictureImpl_IConnectionPointContainer_Release(
690 IConnectionPointContainer* iface)
692 ICOM_THIS_From_IConnectionPointContainer(IPicture, iface);
694 return IPicture_Release(This);
697 static HRESULT WINAPI OLEPictureImpl_EnumConnectionPoints(
698 IConnectionPointContainer* iface,
699 IEnumConnectionPoints** ppEnum
701 ICOM_THIS_From_IConnectionPointContainer(IPicture, iface);
703 FIXME("(%p,%p), stub!\n",This,ppEnum);
707 static HRESULT WINAPI OLEPictureImpl_FindConnectionPoint(
708 IConnectionPointContainer* iface,
710 IConnectionPoint **ppCP
712 ICOM_THIS_From_IConnectionPointContainer(OLEPictureImpl, iface);
713 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppCP);
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));
722 /************************************************************************
725 /************************************************************************
726 * OLEPictureImpl_IPersistStream_QueryInterface (IUnknown)
728 * See Windows documentation for more details on IUnknown methods.
730 static HRESULT WINAPI OLEPictureImpl_IPersistStream_QueryInterface(
731 IPersistStream* iface,
735 ICOM_THIS_From_IPersistStream(IPicture, iface);
737 return IPicture_QueryInterface(This, riid, ppvoid);
740 /************************************************************************
741 * OLEPictureImpl_IPersistStream_AddRef (IUnknown)
743 * See Windows documentation for more details on IUnknown methods.
745 static ULONG WINAPI OLEPictureImpl_IPersistStream_AddRef(
746 IPersistStream* iface)
748 ICOM_THIS_From_IPersistStream(IPicture, iface);
750 return IPicture_AddRef(This);
753 /************************************************************************
754 * OLEPictureImpl_IPersistStream_Release (IUnknown)
756 * See Windows documentation for more details on IUnknown methods.
758 static ULONG WINAPI OLEPictureImpl_IPersistStream_Release(
759 IPersistStream* iface)
761 ICOM_THIS_From_IPersistStream(IPicture, iface);
763 return IPicture_Release(This);
766 /************************************************************************
767 * OLEPictureImpl_IPersistStream_GetClassID
769 static HRESULT WINAPI OLEPictureImpl_GetClassID(
770 IPersistStream* iface,CLSID* pClassID)
772 ICOM_THIS_From_IPersistStream(IPicture, iface);
773 FIXME("(%p),stub!\n",This);
777 /************************************************************************
778 * OLEPictureImpl_IPersistStream_IsDirty
780 static HRESULT WINAPI OLEPictureImpl_IsDirty(
781 IPersistStream* iface)
783 ICOM_THIS_From_IPersistStream(IPicture, iface);
784 FIXME("(%p),stub!\n",This);
789 /* for the jpeg decompressor source manager. */
790 static void _jpeg_init_source(j_decompress_ptr cinfo) { }
792 static boolean _jpeg_fill_input_buffer(j_decompress_ptr cinfo) {
793 ERR("(), should not get here.\n");
797 static void _jpeg_skip_input_data(j_decompress_ptr cinfo,long num_bytes) {
798 ERR("(%ld), should not get here.\n",num_bytes);
801 static boolean _jpeg_resync_to_restart(j_decompress_ptr cinfo, int desired) {
802 ERR("(desired=%d), should not get here.\n",desired);
805 static void _jpeg_term_source(j_decompress_ptr cinfo) { }
806 #endif /* HAVE_LIBJPEG */
808 /************************************************************************
809 * OLEPictureImpl_IPersistStream_Load (IUnknown)
811 * Loads the binary data from the IStream. Starts at current position.
812 * There appears to be an 2 DWORD header:
816 * Currently implemented: BITMAP, ICON, JPEG.
818 static HRESULT WINAPI OLEPictureImpl_Load(IPersistStream* iface,IStream*pStm) {
824 ICOM_THIS_From_IPersistStream(OLEPictureImpl, iface);
826 TRACE("(%p,%p)\n",This,pStm);
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);
834 xbuf = This->data = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,header[1]);
835 This->datalen = header[1];
836 while (xread < header[1]) {
838 hr = IStream_Read(pStm,xbuf+xread,header[1]-xread,&nread);
843 if (xread != header[1])
844 FIXME("Could only read %ld of %ld bytes?\n",xread,header[1]);
846 magic = xbuf[0] + (xbuf[1]<<8);
848 case 0xd8ff: { /* JPEG */
850 struct jpeg_decompress_struct jd;
851 struct jpeg_error_mgr jerr;
855 BITMAPINFOHEADER bmi;
858 struct jpeg_source_mgr xjsm;
860 /* This is basically so we can use in-memory data for jpeg decompression.
861 * We need to have all the functions.
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;
871 jd.err = jpeg_std_error(&jerr);
872 jpeg_create_decompress(&jd);
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);
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);
886 FIXME("failed to read current scanline?\n");
889 memcpy( bits+jd.output_scanline*jd.output_width*jd.output_components,
891 jd.output_width*jd.output_components
894 bmi.biSize = sizeof(bmi);
895 bmi.biWidth = jd.output_width;
896 bmi.biHeight = -jd.output_height;
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;
904 bmi.biClrImportant = 0;
906 HeapFree(GetProcessHeap(),0,samprow);
907 jpeg_finish_decompress(&jd);
908 jpeg_destroy_decompress(&jd);
910 This->desc.u.bmp.hbitmap=CreateDIBitmap(
919 This->desc.picType = PICTYPE_BITMAP;
920 OLEPictureImpl_SetBitmap(This);
922 HeapFree(GetProcessHeap(),0,bits);
924 ERR("Trying to load JPEG picture, but JPEG supported not compiled in.\n");
929 case 0x4d42: { /* Bitmap */
930 BITMAPFILEHEADER *bfh = (BITMAPFILEHEADER*)xbuf;
931 BITMAPINFO *bi = (BITMAPINFO*)(bfh+1);
934 /* Does not matter whether this is a coreheader or not, we only use
935 * components which are in both
938 This->desc.u.bmp.hbitmap = CreateDIBitmap(
944 (bi->bmiHeader.biBitCount<=8)?DIB_PAL_COLORS:DIB_RGB_COLORS
947 This->desc.picType = PICTYPE_BITMAP;
948 OLEPictureImpl_SetBitmap(This);
952 case 0x0000: { /* ICON , first word is dwReserved */
954 CURSORICONFILEDIR *cifd = (CURSORICONFILEDIR*)xbuf;
958 FIXME("icon.idReserved=%d\n",cifd->idReserved);
959 FIXME("icon.idType=%d\n",cifd->idType);
960 FIXME("icon.idCount=%d\n",cifd->idCount);
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);
974 /* If we have more than one icon, try to find the best.
975 * this currently means '32 pixel wide'.
977 if (cifd->idCount!=1) {
978 for (i=0;i<cifd->idCount;i++) {
979 if (cifd->idEntries[i].bWidth == 32)
982 if (i==cifd->idCount) i=0;
985 hicon = CreateIconFromResourceEx(
986 xbuf+cifd->idEntries[i].dwDIBOffset,
987 cifd->idEntries[i].dwDIBSize,
990 cifd->idEntries[i].bWidth,
991 cifd->idEntries[i].bHeight,
995 FIXME("CreateIcon failed.\n");
998 This->desc.picType = PICTYPE_ICON;
999 This->desc.u.icon.hicon = hicon;
1005 FIXME("Unknown magic %04x\n",magic);
1010 /* FIXME: this notify is not really documented */
1012 OLEPicture_SendNotify(This,DISPID_PICT_TYPE);
1016 static HRESULT WINAPI OLEPictureImpl_Save(
1017 IPersistStream* iface,IStream*pStm,BOOL fClearDirty)
1019 ICOM_THIS_From_IPersistStream(IPicture, iface);
1020 FIXME("(%p,%p,%d),stub!\n",This,pStm,fClearDirty);
1024 static HRESULT WINAPI OLEPictureImpl_GetSizeMax(
1025 IPersistStream* iface,ULARGE_INTEGER*pcbSize)
1027 ICOM_THIS_From_IPersistStream(IPicture, iface);
1028 FIXME("(%p,%p),stub!\n",This,pcbSize);
1032 /************************************************************************
1035 /************************************************************************
1036 * OLEPictureImpl_IDispatch_QueryInterface (IUnknown)
1038 * See Windows documentation for more details on IUnknown methods.
1040 static HRESULT WINAPI OLEPictureImpl_IDispatch_QueryInterface(
1045 ICOM_THIS_From_IDispatch(IPicture, iface);
1047 return IPicture_QueryInterface(This, riid, ppvoid);
1050 /************************************************************************
1051 * OLEPictureImpl_IDispatch_AddRef (IUnknown)
1053 * See Windows documentation for more details on IUnknown methods.
1055 static ULONG WINAPI OLEPictureImpl_IDispatch_AddRef(
1058 ICOM_THIS_From_IDispatch(IPicture, iface);
1060 return IPicture_AddRef(This);
1063 /************************************************************************
1064 * OLEPictureImpl_IDispatch_Release (IUnknown)
1066 * See Windows documentation for more details on IUnknown methods.
1068 static ULONG WINAPI OLEPictureImpl_IDispatch_Release(
1071 ICOM_THIS_From_IDispatch(IPicture, iface);
1073 return IPicture_Release(This);
1076 /************************************************************************
1077 * OLEPictureImpl_GetTypeInfoCount (IDispatch)
1079 * See Windows documentation for more details on IDispatch methods.
1081 static HRESULT WINAPI OLEPictureImpl_GetTypeInfoCount(
1083 unsigned int* pctinfo)
1090 /************************************************************************
1091 * OLEPictureImpl_GetTypeInfo (IDispatch)
1093 * See Windows documentation for more details on IDispatch methods.
1095 static HRESULT WINAPI OLEPictureImpl_GetTypeInfo(
1099 ITypeInfo** ppTInfo)
1106 /************************************************************************
1107 * OLEPictureImpl_GetIDsOfNames (IDispatch)
1109 * See Windows documentation for more details on IDispatch methods.
1111 static HRESULT WINAPI OLEPictureImpl_GetIDsOfNames(
1114 LPOLESTR* rgszNames,
1124 /************************************************************************
1125 * OLEPictureImpl_Invoke (IDispatch)
1127 * See Windows documentation for more details on IDispatch methods.
1129 static HRESULT WINAPI OLEPictureImpl_Invoke(
1131 DISPID dispIdMember,
1135 DISPPARAMS* pDispParams,
1136 VARIANT* pVarResult,
1137 EXCEPINFO* pExepInfo,
1140 FIXME("(dispid: %ld):Stub\n",dispIdMember);
1142 VariantInit(pVarResult);
1143 V_VT(pVarResult) = VT_BOOL;
1144 V_UNION(pVarResult,boolVal) = FALSE;
1149 static ICOM_VTABLE(IPicture) OLEPictureImpl_VTable =
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
1171 static ICOM_VTABLE(IDispatch) OLEPictureImpl_IDispatch_VTable =
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
1183 static ICOM_VTABLE(IPersistStream) OLEPictureImpl_IPersistStream_VTable =
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
1196 static ICOM_VTABLE(IConnectionPointContainer) OLEPictureImpl_IConnectionPointContainer_VTable =
1198 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1199 OLEPictureImpl_IConnectionPointContainer_QueryInterface,
1200 OLEPictureImpl_IConnectionPointContainer_AddRef,
1201 OLEPictureImpl_IConnectionPointContainer_Release,
1202 OLEPictureImpl_EnumConnectionPoints,
1203 OLEPictureImpl_FindConnectionPoint
1206 /***********************************************************************
1207 * OleCreatePictureIndirect (OLEAUT32.419)
1209 HRESULT WINAPI OleCreatePictureIndirect(LPPICTDESC lpPictDesc, REFIID riid,
1210 BOOL fOwn, LPVOID *ppvObj )
1212 OLEPictureImpl* newPict = NULL;
1215 TRACE("(%p,%p,%d,%p)\n", lpPictDesc, riid, fOwn, ppvObj);
1226 * Try to construct a new instance of the class.
1228 newPict = OLEPictureImpl_Construct(lpPictDesc, fOwn);
1230 if (newPict == NULL)
1231 return E_OUTOFMEMORY;
1234 * Make sure it supports the interface required by the caller.
1236 hr = IPicture_QueryInterface((IPicture*)newPict, riid, ppvObj);
1239 * Release the reference obtained in the constructor. If
1240 * the QueryInterface was unsuccessful, it will free the class.
1242 IPicture_Release((IPicture*)newPict);
1248 /***********************************************************************
1249 * OleLoadPicture (OLEAUT32.418)
1251 HRESULT WINAPI OleLoadPicture( LPSTREAM lpstream, LONG lSize, BOOL fRunmode,
1252 REFIID riid, LPVOID *ppvObj )
1258 TRACE("(%p,%ld,%d,%s,%p), partially implemented.\n",
1259 lpstream, lSize, fRunmode, debugstr_guid(riid), ppvObj);
1261 hr = OleCreatePictureIndirect(NULL,riid,!fRunmode,(LPVOID*)&newpic);
1264 hr = IPicture_QueryInterface(newpic,&IID_IPersistStream, (LPVOID*)&ps);
1266 FIXME("Could not get IPersistStream iface from Ole Picture?\n");
1267 IPicture_Release(newpic);
1271 IPersistStream_Load(ps,lpstream);
1272 IPersistStream_Release(ps);
1273 hr = IPicture_QueryInterface(newpic,riid,ppvObj);
1275 FIXME("Failed to get interface %s from IPicture.\n",debugstr_guid(riid));
1276 IPicture_Release(newpic);
1280 /***********************************************************************
1281 * OleLoadPictureEx (OLEAUT32.401)
1283 HRESULT WINAPI OleLoadPictureEx( LPSTREAM lpstream, LONG lSize, BOOL fRunmode,
1284 REFIID riid, DWORD xsiz, DWORD ysiz, DWORD flags, LPVOID *ppvObj )
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);
1293 hr = OleCreatePictureIndirect(NULL,riid,!fRunmode,(LPVOID*)&newpic);
1296 hr = IPicture_QueryInterface(newpic,&IID_IPersistStream, (LPVOID*)&ps);
1298 FIXME("Could not get IPersistStream iface from Ole Picture?\n");
1299 IPicture_Release(newpic);
1303 IPersistStream_Load(ps,lpstream);
1304 IPersistStream_Release(ps);
1305 hr = IPicture_QueryInterface(newpic,riid,ppvObj);
1307 FIXME("Failed to get interface %s from IPicture.\n",debugstr_guid(riid));
1308 IPicture_Release(newpic);