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;
112 * Macros to retrieve pointer to IUnknown (IPicture) from the other VTables.
114 #define ICOM_THIS_From_IDispatch(impl, name) \
115 impl *This = (impl*)(((char*)name)-sizeof(void*));
116 #define ICOM_THIS_From_IPersistStream(impl, name) \
117 impl *This = (impl*)(((char*)name)-2*sizeof(void*));
118 #define ICOM_THIS_From_IConnectionPointContainer(impl, name) \
119 impl *This = (impl*)(((char*)name)-3*sizeof(void*));
122 * Predeclare VTables. They get initialized at the end.
124 static ICOM_VTABLE(IPicture) OLEPictureImpl_VTable;
125 static ICOM_VTABLE(IDispatch) OLEPictureImpl_IDispatch_VTable;
126 static ICOM_VTABLE(IPersistStream) OLEPictureImpl_IPersistStream_VTable;
127 static ICOM_VTABLE(IConnectionPointContainer) OLEPictureImpl_IConnectionPointContainer_VTable;
129 /***********************************************************************
130 * Implementation of the OLEPictureImpl class.
133 static void OLEPictureImpl_SetBitmap(OLEPictureImpl*This) {
137 TRACE("bitmap handle %08x\n", This->desc.u.bmp.hbitmap);
138 if(GetObjectA(This->desc.u.bmp.hbitmap, sizeof(bm), &bm) != sizeof(bm)) {
139 ERR("GetObject fails\n");
142 This->origWidth = bm.bmWidth;
143 This->origHeight = bm.bmHeight;
144 /* The width and height are stored in HIMETRIC units (0.01 mm),
145 so we take our pixel width divide by pixels per inch and
146 multiply by 25.4 * 100 */
147 /* Should we use GetBitmapDimension if available? */
148 hdcRef = CreateCompatibleDC(0);
149 This->himetricWidth =(bm.bmWidth *2540)/GetDeviceCaps(hdcRef, LOGPIXELSX);
150 This->himetricHeight=(bm.bmHeight*2540)/GetDeviceCaps(hdcRef, LOGPIXELSY);
154 /************************************************************************
155 * OLEPictureImpl_Construct
157 * This method will construct a new instance of the OLEPictureImpl
160 * The caller of this method must release the object when it's
163 static OLEPictureImpl* OLEPictureImpl_Construct(LPPICTDESC pictDesc, BOOL fOwn)
165 OLEPictureImpl* newObject = 0;
168 TRACE("(%p) type = %d\n", pictDesc, pictDesc->picType);
171 * Allocate space for the object.
173 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEPictureImpl));
179 * Initialize the virtual function table.
181 newObject->lpvtbl1 = &OLEPictureImpl_VTable;
182 newObject->lpvtbl2 = &OLEPictureImpl_IDispatch_VTable;
183 newObject->lpvtbl3 = &OLEPictureImpl_IPersistStream_VTable;
184 newObject->lpvtbl4 = &OLEPictureImpl_IConnectionPointContainer_VTable;
186 CreateConnectionPoint((IUnknown*)newObject,&IID_IPropertyNotifySink,&newObject->pCP);
189 * Start with one reference count. The caller of this function
190 * must release the interface pointer when it is done.
193 newObject->hDCCur = 0;
195 newObject->fOwn = fOwn;
197 /* dunno about original value */
198 newObject->keepOrigFormat = TRUE;
201 if(pictDesc->cbSizeofstruct != sizeof(PICTDESC)) {
202 FIXME("struct size = %d\n", pictDesc->cbSizeofstruct);
204 memcpy(&newObject->desc, pictDesc, sizeof(PICTDESC));
207 switch(pictDesc->picType) {
209 OLEPictureImpl_SetBitmap(newObject);
212 case PICTYPE_METAFILE:
213 TRACE("metafile handle %08x\n", pictDesc->u.wmf.hmeta);
214 newObject->himetricWidth = pictDesc->u.wmf.xExt;
215 newObject->himetricHeight = pictDesc->u.wmf.yExt;
219 case PICTYPE_ENHMETAFILE:
221 FIXME("Unsupported type %d\n", pictDesc->picType);
222 newObject->himetricWidth = newObject->himetricHeight = 0;
226 newObject->desc.picType = PICTYPE_UNINITIALIZED;
229 TRACE("returning %p\n", newObject);
233 /************************************************************************
234 * OLEPictureImpl_Destroy
236 * This method is called by the Release method when the reference
237 * count goes down to 0. It will free all resources used by
239 static void OLEPictureImpl_Destroy(OLEPictureImpl* Obj)
241 TRACE("(%p)\n", Obj);
243 if(Obj->fOwn) { /* We need to destroy the picture */
244 switch(Obj->desc.picType) {
246 DeleteObject(Obj->desc.u.bmp.hbitmap);
248 case PICTYPE_METAFILE:
249 DeleteMetaFile(Obj->desc.u.wmf.hmeta);
252 DestroyIcon(Obj->desc.u.icon.hicon);
254 case PICTYPE_ENHMETAFILE:
255 DeleteEnhMetaFile(Obj->desc.u.emf.hemf);
258 FIXME("Unsupported type %d - unable to delete\n", Obj->desc.picType);
262 HeapFree(GetProcessHeap(), 0, Obj);
265 static ULONG WINAPI OLEPictureImpl_AddRef(IPicture* iface);
267 /************************************************************************
268 * OLEPictureImpl_QueryInterface (IUnknown)
270 * See Windows documentation for more details on IUnknown methods.
272 static HRESULT WINAPI OLEPictureImpl_QueryInterface(
277 ICOM_THIS(OLEPictureImpl, iface);
278 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppvObject);
281 * Perform a sanity check on the parameters.
283 if ( (This==0) || (ppvObject==0) )
287 * Initialize the return parameter.
292 * Compare the riid with the interface IDs implemented by this object.
294 if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0)
296 *ppvObject = (IPicture*)This;
298 else if (memcmp(&IID_IPicture, riid, sizeof(IID_IPicture)) == 0)
300 *ppvObject = (IPicture*)This;
302 else if (memcmp(&IID_IDispatch, riid, sizeof(IID_IDispatch)) == 0)
304 *ppvObject = (IDispatch*)&(This->lpvtbl2);
306 else if (memcmp(&IID_IPictureDisp, riid, sizeof(IID_IPictureDisp)) == 0)
308 *ppvObject = (IDispatch*)&(This->lpvtbl2);
310 else if (memcmp(&IID_IPersistStream, riid, sizeof(IID_IPersistStream)) == 0)
312 *ppvObject = (IPersistStream*)&(This->lpvtbl3);
314 else if (memcmp(&IID_IConnectionPointContainer, riid, sizeof(IID_IConnectionPointContainer)) == 0)
316 *ppvObject = (IConnectionPointContainer*)&(This->lpvtbl4);
319 * Check that we obtained an interface.
323 FIXME("() : asking for un supported interface %s\n",debugstr_guid(riid));
324 return E_NOINTERFACE;
328 * Query Interface always increases the reference count by one when it is
331 OLEPictureImpl_AddRef((IPicture*)This);
335 /***********************************************************************
336 * OLEPicture_SendNotify (internal)
338 * Sends notification messages of changed properties to any interested
341 static void OLEPicture_SendNotify(OLEPictureImpl* this, DISPID dispID)
343 IEnumConnections *pEnum;
346 if (IConnectionPoint_EnumConnections(this->pCP, &pEnum))
348 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
349 IPropertyNotifySink *sink;
351 IUnknown_QueryInterface(CD.pUnk, &IID_IPropertyNotifySink, (LPVOID)&sink);
352 IPropertyNotifySink_OnChanged(sink, dispID);
353 IPropertyNotifySink_Release(sink);
354 IUnknown_Release(CD.pUnk);
356 IEnumConnections_Release(pEnum);
360 /************************************************************************
361 * OLEPictureImpl_AddRef (IUnknown)
363 * See Windows documentation for more details on IUnknown methods.
365 static ULONG WINAPI OLEPictureImpl_AddRef(
368 ICOM_THIS(OLEPictureImpl, iface);
369 TRACE("(%p)->(ref=%ld)\n", This, This->ref);
375 /************************************************************************
376 * OLEPictureImpl_Release (IUnknown)
378 * See Windows documentation for more details on IUnknown methods.
380 static ULONG WINAPI OLEPictureImpl_Release(
383 ICOM_THIS(OLEPictureImpl, iface);
384 TRACE("(%p)->(ref=%ld)\n", This, This->ref);
387 * Decrease the reference count on this object.
392 * If the reference count goes down to 0, perform suicide.
396 OLEPictureImpl_Destroy(This);
405 /************************************************************************
406 * OLEPictureImpl_get_Handle
408 static HRESULT WINAPI OLEPictureImpl_get_Handle(IPicture *iface,
411 ICOM_THIS(OLEPictureImpl, iface);
412 TRACE("(%p)->(%p)\n", This, phandle);
413 switch(This->desc.picType) {
415 *phandle = This->desc.u.bmp.hbitmap;
417 case PICTYPE_METAFILE:
418 *phandle = (OLE_HANDLE)This->desc.u.wmf.hmeta;
421 *phandle = This->desc.u.icon.hicon;
423 case PICTYPE_ENHMETAFILE:
424 *phandle = (OLE_HANDLE)This->desc.u.emf.hemf;
427 FIXME("Unimplemented type %d\n", This->desc.picType);
430 TRACE("returning handle %08x\n", *phandle);
434 /************************************************************************
435 * OLEPictureImpl_get_hPal
437 static HRESULT WINAPI OLEPictureImpl_get_hPal(IPicture *iface,
440 ICOM_THIS(OLEPictureImpl, iface);
441 FIXME("(%p)->(%p): stub\n", This, phandle);
445 /************************************************************************
446 * OLEPictureImpl_get_Type
448 static HRESULT WINAPI OLEPictureImpl_get_Type(IPicture *iface,
451 ICOM_THIS(OLEPictureImpl, iface);
452 TRACE("(%p)->(%p): type is %d\n", This, ptype, This->desc.picType);
453 *ptype = This->desc.picType;
457 /************************************************************************
458 * OLEPictureImpl_get_Width
460 static HRESULT WINAPI OLEPictureImpl_get_Width(IPicture *iface,
461 OLE_XSIZE_HIMETRIC *pwidth)
463 ICOM_THIS(OLEPictureImpl, iface);
464 TRACE("(%p)->(%p): width is %ld\n", This, pwidth, This->himetricWidth);
465 *pwidth = This->himetricWidth;
469 /************************************************************************
470 * OLEPictureImpl_get_Height
472 static HRESULT WINAPI OLEPictureImpl_get_Height(IPicture *iface,
473 OLE_YSIZE_HIMETRIC *pheight)
475 ICOM_THIS(OLEPictureImpl, iface);
476 TRACE("(%p)->(%p): height is %ld\n", This, pheight, This->himetricHeight);
477 *pheight = This->himetricHeight;
481 /************************************************************************
482 * OLEPictureImpl_Render
484 static HRESULT WINAPI OLEPictureImpl_Render(IPicture *iface, HDC hdc,
485 long x, long y, long cx, long cy,
486 OLE_XPOS_HIMETRIC xSrc,
487 OLE_YPOS_HIMETRIC ySrc,
488 OLE_XSIZE_HIMETRIC cxSrc,
489 OLE_YSIZE_HIMETRIC cySrc,
492 ICOM_THIS(OLEPictureImpl, iface);
493 TRACE("(%p)->(%08x, (%ld,%ld), (%ld,%ld) <- (%ld,%ld), (%ld,%ld), %p)\n",
494 This, hdc, x, y, cx, cy, xSrc, ySrc, cxSrc, cySrc, prcWBounds);
496 TRACE("prcWBounds (%d,%d) - (%d,%d)\n", prcWBounds->left, prcWBounds->top,
497 prcWBounds->right, prcWBounds->bottom);
500 * While the documentation suggests this to be here (or after rendering?)
501 * it does cause an endless recursion in my sample app. -MM 20010804
502 OLEPicture_SendNotify(This,DISPID_PICT_RENDER);
505 switch(This->desc.picType) {
511 /* Set a mapping mode that maps bitmap pixels into HIMETRIC units.
512 NB y-axis gets flipped */
514 hdcBmp = CreateCompatibleDC(0);
515 SetMapMode(hdcBmp, MM_ANISOTROPIC);
516 SetWindowOrgEx(hdcBmp, 0, 0, NULL);
517 SetWindowExtEx(hdcBmp, This->himetricWidth, This->himetricHeight, NULL);
518 SetViewportOrgEx(hdcBmp, 0, This->origHeight, NULL);
519 SetViewportExtEx(hdcBmp, This->origWidth, -This->origHeight, NULL);
521 hbmpOld = SelectObject(hdcBmp, This->desc.u.bmp.hbitmap);
523 StretchBlt(hdc, x, y, cx, cy, hdcBmp, xSrc, ySrc, cxSrc, cySrc, SRCCOPY);
525 SelectObject(hdcBmp, hbmpOld);
530 FIXME("Not quite correct implementation of rendering icons...\n");
531 DrawIcon(hdc,x,y,This->desc.u.icon.hicon);
534 case PICTYPE_METAFILE:
535 case PICTYPE_ENHMETAFILE:
537 FIXME("type %d not implemented\n", This->desc.picType);
543 /************************************************************************
544 * OLEPictureImpl_set_hPal
546 static HRESULT WINAPI OLEPictureImpl_set_hPal(IPicture *iface,
549 ICOM_THIS(OLEPictureImpl, iface);
550 FIXME("(%p)->(%08x): stub\n", This, hpal);
551 OLEPicture_SendNotify(This,DISPID_PICT_HPAL);
555 /************************************************************************
556 * OLEPictureImpl_get_CurDC
558 static HRESULT WINAPI OLEPictureImpl_get_CurDC(IPicture *iface,
561 ICOM_THIS(OLEPictureImpl, iface);
562 TRACE("(%p), returning %x\n", This, This->hDCCur);
563 if (phdc) *phdc = This->hDCCur;
567 /************************************************************************
568 * OLEPictureImpl_SelectPicture
570 static HRESULT WINAPI OLEPictureImpl_SelectPicture(IPicture *iface,
573 OLE_HANDLE *phbmpOut)
575 ICOM_THIS(OLEPictureImpl, iface);
576 TRACE("(%p)->(%08x, %p, %p)\n", This, hdcIn, phdcOut, phbmpOut);
577 if (This->desc.picType == PICTYPE_BITMAP) {
578 SelectObject(hdcIn,This->desc.u.bmp.hbitmap);
581 *phdcOut = This->hDCCur;
582 This->hDCCur = hdcIn;
584 *phbmpOut = This->desc.u.bmp.hbitmap;
587 FIXME("Don't know how to select picture type %d\n",This->desc.picType);
592 /************************************************************************
593 * OLEPictureImpl_get_KeepOriginalFormat
595 static HRESULT WINAPI OLEPictureImpl_get_KeepOriginalFormat(IPicture *iface,
598 ICOM_THIS(OLEPictureImpl, iface);
599 TRACE("(%p)->(%p)\n", This, pfKeep);
602 *pfKeep = This->keepOrigFormat;
606 /************************************************************************
607 * OLEPictureImpl_put_KeepOriginalFormat
609 static HRESULT WINAPI OLEPictureImpl_put_KeepOriginalFormat(IPicture *iface,
612 ICOM_THIS(OLEPictureImpl, iface);
613 TRACE("(%p)->(%d)\n", This, keep);
614 This->keepOrigFormat = keep;
615 /* FIXME: what DISPID notification here? */
619 /************************************************************************
620 * OLEPictureImpl_PictureChanged
622 static HRESULT WINAPI OLEPictureImpl_PictureChanged(IPicture *iface)
624 ICOM_THIS(OLEPictureImpl, iface);
625 TRACE("(%p)->()\n", This);
626 OLEPicture_SendNotify(This,DISPID_PICT_HANDLE);
630 /************************************************************************
631 * OLEPictureImpl_SaveAsFile
633 static HRESULT WINAPI OLEPictureImpl_SaveAsFile(IPicture *iface,
638 ICOM_THIS(OLEPictureImpl, iface);
639 FIXME("(%p)->(%p, %d, %p): stub\n", This, pstream, SaveMemCopy, pcbSize);
643 /************************************************************************
644 * OLEPictureImpl_get_Attributes
646 static HRESULT WINAPI OLEPictureImpl_get_Attributes(IPicture *iface,
649 ICOM_THIS(OLEPictureImpl, iface);
650 TRACE("(%p)->(%p).\n", This, pdwAttr);
652 switch (This->desc.picType) {
653 case PICTYPE_BITMAP: break; /* not 'truely' scalable, see MSDN. */
654 case PICTYPE_ICON: *pdwAttr = PICTURE_TRANSPARENT;break;
655 case PICTYPE_METAFILE: *pdwAttr = PICTURE_TRANSPARENT|PICTURE_SCALABLE;break;
656 default:FIXME("Unknown pictype %d\n",This->desc.picType);break;
662 /************************************************************************
663 * IConnectionPointContainer
666 static HRESULT WINAPI OLEPictureImpl_IConnectionPointContainer_QueryInterface(
667 IConnectionPointContainer* iface,
671 ICOM_THIS_From_IConnectionPointContainer(IPicture,iface);
673 return IPicture_QueryInterface(This,riid,ppvoid);
676 static ULONG WINAPI OLEPictureImpl_IConnectionPointContainer_AddRef(
677 IConnectionPointContainer* iface)
679 ICOM_THIS_From_IConnectionPointContainer(IPicture, iface);
681 return IPicture_AddRef(This);
684 static ULONG WINAPI OLEPictureImpl_IConnectionPointContainer_Release(
685 IConnectionPointContainer* iface)
687 ICOM_THIS_From_IConnectionPointContainer(IPicture, iface);
689 return IPicture_Release(This);
692 static HRESULT WINAPI OLEPictureImpl_EnumConnectionPoints(
693 IConnectionPointContainer* iface,
694 IEnumConnectionPoints** ppEnum
696 ICOM_THIS_From_IConnectionPointContainer(IPicture, iface);
698 FIXME("(%p,%p), stub!\n",This,ppEnum);
702 static HRESULT WINAPI OLEPictureImpl_FindConnectionPoint(
703 IConnectionPointContainer* iface,
705 IConnectionPoint **ppCP
707 ICOM_THIS_From_IConnectionPointContainer(OLEPictureImpl, iface);
708 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppCP);
712 if (IsEqualGUID(riid,&IID_IPropertyNotifySink))
713 return IConnectionPoint_QueryInterface(This->pCP,&IID_IConnectionPoint,(LPVOID)ppCP);
714 FIXME("tried to find connection point on %s?\n",debugstr_guid(riid));
717 /************************************************************************
720 /************************************************************************
721 * OLEPictureImpl_IPersistStream_QueryInterface (IUnknown)
723 * See Windows documentation for more details on IUnknown methods.
725 static HRESULT WINAPI OLEPictureImpl_IPersistStream_QueryInterface(
726 IPersistStream* iface,
730 ICOM_THIS_From_IPersistStream(IPicture, iface);
732 return IPicture_QueryInterface(This, riid, ppvoid);
735 /************************************************************************
736 * OLEPictureImpl_IPersistStream_AddRef (IUnknown)
738 * See Windows documentation for more details on IUnknown methods.
740 static ULONG WINAPI OLEPictureImpl_IPersistStream_AddRef(
741 IPersistStream* iface)
743 ICOM_THIS_From_IPersistStream(IPicture, iface);
745 return IPicture_AddRef(This);
748 /************************************************************************
749 * OLEPictureImpl_IPersistStream_Release (IUnknown)
751 * See Windows documentation for more details on IUnknown methods.
753 static ULONG WINAPI OLEPictureImpl_IPersistStream_Release(
754 IPersistStream* iface)
756 ICOM_THIS_From_IPersistStream(IPicture, iface);
758 return IPicture_Release(This);
761 /************************************************************************
762 * OLEPictureImpl_IPersistStream_GetClassID
764 static HRESULT WINAPI OLEPictureImpl_GetClassID(
765 IPersistStream* iface,CLSID* pClassID)
767 ICOM_THIS_From_IPersistStream(IPicture, iface);
768 FIXME("(%p),stub!\n",This);
772 /************************************************************************
773 * OLEPictureImpl_IPersistStream_IsDirty
775 static HRESULT WINAPI OLEPictureImpl_IsDirty(
776 IPersistStream* iface)
778 ICOM_THIS_From_IPersistStream(IPicture, iface);
779 FIXME("(%p),stub!\n",This);
784 /* for the jpeg decompressor source manager. */
785 static void _jpeg_init_source(j_decompress_ptr cinfo) { }
787 static boolean _jpeg_fill_input_buffer(j_decompress_ptr cinfo) {
788 ERR("(), should not get here.\n");
792 static void _jpeg_skip_input_data(j_decompress_ptr cinfo,long num_bytes) {
793 ERR("(%ld), should not get here.\n",num_bytes);
796 static boolean _jpeg_resync_to_restart(j_decompress_ptr cinfo, int desired) {
797 ERR("(desired=%d), should not get here.\n",desired);
800 static void _jpeg_term_source(j_decompress_ptr cinfo) { }
801 #endif /* HAVE_LIBJPEG */
803 /************************************************************************
804 * OLEPictureImpl_IPersistStream_Load (IUnknown)
806 * Loads the binary data from the IStream. Starts at current position.
807 * There appears to be an 2 DWORD header:
811 * Currently implemented: BITMAP, ICON, JPEG.
813 static HRESULT WINAPI OLEPictureImpl_Load(IPersistStream* iface,IStream*pStm) {
819 ICOM_THIS_From_IPersistStream(OLEPictureImpl, iface);
821 TRACE("(%p,%p)\n",This,pStm);
823 hr=IStream_Read(pStm,header,8,&xread);
824 if (hr || xread!=8) {
825 FIXME("Failure while reading picture header (hr is %lx, nread is %ld).\n",hr,xread);
829 xbuf = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,header[1]);
830 while (xread < header[1]) {
832 hr = IStream_Read(pStm,xbuf+xread,header[1]-xread,&nread);
837 if (xread != header[1])
838 FIXME("Could only read %ld of %ld bytes?\n",xread,header[1]);
840 magic = xbuf[0] + (xbuf[1]<<8);
842 case 0xd8ff: { /* JPEG */
844 struct jpeg_decompress_struct jd;
845 struct jpeg_error_mgr jerr;
849 BITMAPINFOHEADER bmi;
852 struct jpeg_source_mgr xjsm;
854 /* This is basically so we can use in-memory data for jpeg decompression.
855 * We need to have all the functions.
857 xjsm.next_input_byte = xbuf;
858 xjsm.bytes_in_buffer = xread;
859 xjsm.init_source = _jpeg_init_source;
860 xjsm.fill_input_buffer = _jpeg_fill_input_buffer;
861 xjsm.skip_input_data = _jpeg_skip_input_data;
862 xjsm.resync_to_restart = _jpeg_resync_to_restart;
863 xjsm.term_source = _jpeg_term_source;
865 jd.err = jpeg_std_error(&jerr);
866 jpeg_create_decompress(&jd);
868 ret=jpeg_read_header(&jd,TRUE);
869 jpeg_start_decompress(&jd);
870 if (ret != JPEG_HEADER_OK) {
871 ERR("Jpeg image in stream has bad format, read header returned %d.\n",ret);
872 HeapFree(GetProcessHeap(),0,xbuf);
875 bits = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(jd.output_height+1)*jd.output_width*jd.output_components);
876 samprow=HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,jd.output_width*jd.output_components);
877 while ( jd.output_scanline<jd.output_height ) {
878 x = jpeg_read_scanlines(&jd,&samprow,1);
880 FIXME("failed to read current scanline?\n");
883 memcpy( bits+jd.output_scanline*jd.output_width*jd.output_components,
885 jd.output_width*jd.output_components
888 bmi.biSize = sizeof(bmi);
889 bmi.biWidth = jd.output_width;
890 bmi.biHeight = -jd.output_height;
892 bmi.biBitCount = jd.output_components<<3;
893 bmi.biCompression = BI_RGB;
894 bmi.biSizeImage = jd.output_height*jd.output_width*jd.output_components;
895 bmi.biXPelsPerMeter = 0;
896 bmi.biYPelsPerMeter = 0;
898 bmi.biClrImportant = 0;
900 HeapFree(GetProcessHeap(),0,samprow);
901 jpeg_finish_decompress(&jd);
902 jpeg_destroy_decompress(&jd);
904 This->desc.u.bmp.hbitmap=CreateDIBitmap(
913 This->desc.picType = PICTYPE_BITMAP;
914 OLEPictureImpl_SetBitmap(This);
916 HeapFree(GetProcessHeap(),0,bits);
918 ERR("Trying to load JPEG picture, but JPEG supported not compiled in.\n");
923 case 0x4d42: { /* Bitmap */
924 BITMAPFILEHEADER *bfh = (BITMAPFILEHEADER*)xbuf;
925 BITMAPINFO *bi = (BITMAPINFO*)(bfh+1);
928 /* Does not matter whether this is a coreheader or not, we only use
929 * components which are in both
932 This->desc.u.bmp.hbitmap = CreateDIBitmap(
938 (bi->bmiHeader.biBitCount<=8)?DIB_PAL_COLORS:DIB_RGB_COLORS
941 This->desc.picType = PICTYPE_BITMAP;
942 OLEPictureImpl_SetBitmap(This);
946 case 0x0000: { /* ICON , first word is dwReserved */
948 CURSORICONFILEDIR *cifd = (CURSORICONFILEDIR*)xbuf;
952 FIXME("icon.idReserved=%d\n",cifd->idReserved);
953 FIXME("icon.idType=%d\n",cifd->idType);
954 FIXME("icon.idCount=%d\n",cifd->idCount);
956 for (i=0;i<cifd->idCount;i++) {
957 FIXME("[%d] width %d\n",i,cifd->idEntries[i].bWidth);
958 FIXME("[%d] height %d\n",i,cifd->idEntries[i].bHeight);
959 FIXME("[%d] bColorCount %d\n",i,cifd->idEntries[i].bColorCount);
960 FIXME("[%d] bReserved %d\n",i,cifd->idEntries[i].bReserved);
961 FIXME("[%d] xHotspot %d\n",i,cifd->idEntries[i].xHotspot);
962 FIXME("[%d] yHotspot %d\n",i,cifd->idEntries[i].yHotspot);
963 FIXME("[%d] dwDIBSize %d\n",i,cifd->idEntries[i].dwDIBSize);
964 FIXME("[%d] dwDIBOffset %d\n",i,cifd->idEntries[i].dwDIBOffset);
968 /* If we have more than one icon, try to find the best.
969 * this currently means '32 pixel wide'.
971 if (cifd->idCount!=1) {
972 for (i=0;i<cifd->idCount;i++) {
973 if (cifd->idEntries[i].bWidth == 32)
976 if (i==cifd->idCount) i=0;
979 hicon = CreateIconFromResourceEx(
980 xbuf+cifd->idEntries[i].dwDIBOffset,
981 cifd->idEntries[i].dwDIBSize,
984 cifd->idEntries[i].bWidth,
985 cifd->idEntries[i].bHeight,
989 FIXME("CreateIcon failed.\n");
992 This->desc.picType = PICTYPE_ICON;
993 This->desc.u.icon.hicon = hicon;
999 FIXME("Unknown magic %04x\n",magic);
1003 HeapFree(GetProcessHeap(),0,xbuf);
1005 /* FIXME: this notify is not really documented */
1007 OLEPicture_SendNotify(This,DISPID_PICT_TYPE);
1011 static HRESULT WINAPI OLEPictureImpl_Save(
1012 IPersistStream* iface,IStream*pStm,BOOL fClearDirty)
1014 ICOM_THIS_From_IPersistStream(IPicture, iface);
1015 FIXME("(%p,%p,%d),stub!\n",This,pStm,fClearDirty);
1019 static HRESULT WINAPI OLEPictureImpl_GetSizeMax(
1020 IPersistStream* iface,ULARGE_INTEGER*pcbSize)
1022 ICOM_THIS_From_IPersistStream(IPicture, iface);
1023 FIXME("(%p,%p),stub!\n",This,pcbSize);
1027 /************************************************************************
1030 /************************************************************************
1031 * OLEPictureImpl_IDispatch_QueryInterface (IUnknown)
1033 * See Windows documentation for more details on IUnknown methods.
1035 static HRESULT WINAPI OLEPictureImpl_IDispatch_QueryInterface(
1040 ICOM_THIS_From_IDispatch(IPicture, iface);
1042 return IPicture_QueryInterface(This, riid, ppvoid);
1045 /************************************************************************
1046 * OLEPictureImpl_IDispatch_AddRef (IUnknown)
1048 * See Windows documentation for more details on IUnknown methods.
1050 static ULONG WINAPI OLEPictureImpl_IDispatch_AddRef(
1053 ICOM_THIS_From_IDispatch(IPicture, iface);
1055 return IPicture_AddRef(This);
1058 /************************************************************************
1059 * OLEPictureImpl_IDispatch_Release (IUnknown)
1061 * See Windows documentation for more details on IUnknown methods.
1063 static ULONG WINAPI OLEPictureImpl_IDispatch_Release(
1066 ICOM_THIS_From_IDispatch(IPicture, iface);
1068 return IPicture_Release(This);
1071 /************************************************************************
1072 * OLEPictureImpl_GetTypeInfoCount (IDispatch)
1074 * See Windows documentation for more details on IDispatch methods.
1076 static HRESULT WINAPI OLEPictureImpl_GetTypeInfoCount(
1078 unsigned int* pctinfo)
1085 /************************************************************************
1086 * OLEPictureImpl_GetTypeInfo (IDispatch)
1088 * See Windows documentation for more details on IDispatch methods.
1090 static HRESULT WINAPI OLEPictureImpl_GetTypeInfo(
1094 ITypeInfo** ppTInfo)
1101 /************************************************************************
1102 * OLEPictureImpl_GetIDsOfNames (IDispatch)
1104 * See Windows documentation for more details on IDispatch methods.
1106 static HRESULT WINAPI OLEPictureImpl_GetIDsOfNames(
1109 LPOLESTR* rgszNames,
1119 /************************************************************************
1120 * OLEPictureImpl_Invoke (IDispatch)
1122 * See Windows documentation for more details on IDispatch methods.
1124 static HRESULT WINAPI OLEPictureImpl_Invoke(
1126 DISPID dispIdMember,
1130 DISPPARAMS* pDispParams,
1131 VARIANT* pVarResult,
1132 EXCEPINFO* pExepInfo,
1135 FIXME("(dispid: %ld):Stub\n",dispIdMember);
1137 VariantInit(pVarResult);
1138 V_VT(pVarResult) = VT_BOOL;
1139 V_UNION(pVarResult,boolVal) = FALSE;
1144 static ICOM_VTABLE(IPicture) OLEPictureImpl_VTable =
1146 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1147 OLEPictureImpl_QueryInterface,
1148 OLEPictureImpl_AddRef,
1149 OLEPictureImpl_Release,
1150 OLEPictureImpl_get_Handle,
1151 OLEPictureImpl_get_hPal,
1152 OLEPictureImpl_get_Type,
1153 OLEPictureImpl_get_Width,
1154 OLEPictureImpl_get_Height,
1155 OLEPictureImpl_Render,
1156 OLEPictureImpl_set_hPal,
1157 OLEPictureImpl_get_CurDC,
1158 OLEPictureImpl_SelectPicture,
1159 OLEPictureImpl_get_KeepOriginalFormat,
1160 OLEPictureImpl_put_KeepOriginalFormat,
1161 OLEPictureImpl_PictureChanged,
1162 OLEPictureImpl_SaveAsFile,
1163 OLEPictureImpl_get_Attributes
1166 static ICOM_VTABLE(IDispatch) OLEPictureImpl_IDispatch_VTable =
1168 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1169 OLEPictureImpl_IDispatch_QueryInterface,
1170 OLEPictureImpl_IDispatch_AddRef,
1171 OLEPictureImpl_IDispatch_Release,
1172 OLEPictureImpl_GetTypeInfoCount,
1173 OLEPictureImpl_GetTypeInfo,
1174 OLEPictureImpl_GetIDsOfNames,
1175 OLEPictureImpl_Invoke
1178 static ICOM_VTABLE(IPersistStream) OLEPictureImpl_IPersistStream_VTable =
1180 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1181 OLEPictureImpl_IPersistStream_QueryInterface,
1182 OLEPictureImpl_IPersistStream_AddRef,
1183 OLEPictureImpl_IPersistStream_Release,
1184 OLEPictureImpl_GetClassID,
1185 OLEPictureImpl_IsDirty,
1186 OLEPictureImpl_Load,
1187 OLEPictureImpl_Save,
1188 OLEPictureImpl_GetSizeMax
1191 static ICOM_VTABLE(IConnectionPointContainer) OLEPictureImpl_IConnectionPointContainer_VTable =
1193 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1194 OLEPictureImpl_IConnectionPointContainer_QueryInterface,
1195 OLEPictureImpl_IConnectionPointContainer_AddRef,
1196 OLEPictureImpl_IConnectionPointContainer_Release,
1197 OLEPictureImpl_EnumConnectionPoints,
1198 OLEPictureImpl_FindConnectionPoint
1201 /***********************************************************************
1202 * OleCreatePictureIndirect (OLEAUT32.419)
1204 HRESULT WINAPI OleCreatePictureIndirect(LPPICTDESC lpPictDesc, REFIID riid,
1205 BOOL fOwn, LPVOID *ppvObj )
1207 OLEPictureImpl* newPict = NULL;
1210 TRACE("(%p,%p,%d,%p)\n", lpPictDesc, riid, fOwn, ppvObj);
1221 * Try to construct a new instance of the class.
1223 newPict = OLEPictureImpl_Construct(lpPictDesc, fOwn);
1225 if (newPict == NULL)
1226 return E_OUTOFMEMORY;
1229 * Make sure it supports the interface required by the caller.
1231 hr = IPicture_QueryInterface((IPicture*)newPict, riid, ppvObj);
1234 * Release the reference obtained in the constructor. If
1235 * the QueryInterface was unsuccessful, it will free the class.
1237 IPicture_Release((IPicture*)newPict);
1243 /***********************************************************************
1244 * OleLoadPicture (OLEAUT32.418)
1246 HRESULT WINAPI OleLoadPicture( LPSTREAM lpstream, LONG lSize, BOOL fRunmode,
1247 REFIID riid, LPVOID *ppvObj )
1253 TRACE("(%p,%ld,%d,%s,%p), partially implemented.\n",
1254 lpstream, lSize, fRunmode, debugstr_guid(riid), ppvObj);
1256 hr = OleCreatePictureIndirect(NULL,riid,!fRunmode,(LPVOID*)&newpic);
1259 hr = IPicture_QueryInterface(newpic,&IID_IPersistStream, (LPVOID*)&ps);
1261 FIXME("Could not get IPersistStream iface from Ole Picture?\n");
1262 IPicture_Release(newpic);
1266 IPersistStream_Load(ps,lpstream);
1267 IPersistStream_Release(ps);
1268 hr = IPicture_QueryInterface(newpic,riid,ppvObj);
1270 FIXME("Failed to get interface %s from IPicture.\n",debugstr_guid(riid));
1271 IPicture_Release(newpic);
1275 /***********************************************************************
1276 * OleLoadPictureEx (OLEAUT32.401)
1278 HRESULT WINAPI OleLoadPictureEx( LPSTREAM lpstream, LONG lSize, BOOL fRunmode,
1279 REFIID reed, DWORD xsiz, DWORD ysiz, DWORD flags, LPVOID *ppvObj )
1281 FIXME("(%p,%ld,%d,%p,%lx,%lx,%lx,%p), not implemented\n",
1282 lpstream, lSize, fRunmode, reed, xsiz, ysiz, flags, ppvObj);