2000-07-15 16:59:11 +02:00
|
|
|
/*
|
|
|
|
* OLE Picture object
|
|
|
|
*
|
|
|
|
* Implementation of OLE IPicture and related interfaces
|
|
|
|
*
|
|
|
|
* Copyright 2000 Huw D M Davies for CodeWeavers.
|
2001-08-06 20:52:14 +02:00
|
|
|
* Copyright 2001 Marcus Meissner
|
2008-10-04 01:24:37 +02:00
|
|
|
* Copyright 2008 Kirill K. Smirnov
|
2000-07-15 16:59:11 +02:00
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-07-15 16:59:11 +02:00
|
|
|
*
|
|
|
|
* BUGS
|
|
|
|
*
|
2008-04-11 01:24:54 +02:00
|
|
|
* Support PICTYPE_BITMAP and PICTYPE_ICON, although only bitmaps very well..
|
2001-08-06 20:52:14 +02:00
|
|
|
* Lots of methods are just stubs.
|
2000-07-15 16:59:11 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* NOTES (or things that msdn doesn't tell you)
|
|
|
|
*
|
|
|
|
* The width and height properties are returned in HIMETRIC units (0.01mm)
|
|
|
|
* IPicture::Render also uses these to select a region of the src picture.
|
|
|
|
* A bitmap's size is converted into these units by using the screen resolution
|
|
|
|
* thus an 8x8 bitmap on a 96dpi screen has a size of 212x212 (8/96 * 2540).
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2001-08-09 23:35:59 +02:00
|
|
|
#include "config.h"
|
2004-08-04 21:10:26 +02:00
|
|
|
#include "wine/port.h"
|
2001-08-09 23:35:59 +02:00
|
|
|
|
2002-08-17 02:43:16 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2001-08-06 20:52:14 +02:00
|
|
|
#include <stdio.h>
|
2001-01-26 21:43:40 +01:00
|
|
|
#include <string.h>
|
2003-01-07 21:36:20 +01:00
|
|
|
|
2008-07-03 12:39:28 +02:00
|
|
|
#ifdef SONAME_LIBJPEG
|
|
|
|
/* This is a hack, so jpeglib.h does not redefine INT32 and the like*/
|
|
|
|
#define XMD_H
|
|
|
|
#define UINT8 JPEG_UINT8
|
|
|
|
#define UINT16 JPEG_UINT16
|
|
|
|
#define boolean jpeg_boolean
|
|
|
|
# include <jpeglib.h>
|
|
|
|
#undef UINT8
|
|
|
|
#undef UINT16
|
|
|
|
#undef boolean
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_PNG_H
|
|
|
|
#include <png.h>
|
|
|
|
#endif
|
|
|
|
|
2003-01-09 07:04:33 +01:00
|
|
|
/* Must be before wine includes, the header has things conflicting with
|
|
|
|
* WINE headers.
|
|
|
|
*/
|
2004-10-07 05:06:48 +02:00
|
|
|
#define COBJMACROS
|
2003-01-07 21:36:20 +01:00
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
2004-10-07 05:06:48 +02:00
|
|
|
|
2000-07-15 16:59:11 +02:00
|
|
|
#include "winerror.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2000-11-30 02:31:28 +01:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "ole2.h"
|
2000-07-15 16:59:11 +02:00
|
|
|
#include "olectl.h"
|
2001-08-06 20:52:14 +02:00
|
|
|
#include "oleauto.h"
|
|
|
|
#include "connpt.h"
|
2005-03-04 13:30:26 +01:00
|
|
|
#include "urlmon.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2005-03-04 13:30:26 +01:00
|
|
|
#include "wine/unicode.h"
|
2009-04-01 18:20:21 +02:00
|
|
|
#include "wine/library.h"
|
2001-08-06 20:52:14 +02:00
|
|
|
|
2006-09-08 05:27:15 +02:00
|
|
|
#include "ungif.h"
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
2000-07-15 16:59:11 +02:00
|
|
|
|
2005-07-20 12:31:37 +02:00
|
|
|
#include "pshpack1.h"
|
|
|
|
|
2007-10-04 01:56:53 +02:00
|
|
|
/* Header for Aldus Placable Metafiles - a standard metafile follows */
|
|
|
|
typedef struct _APM_HEADER
|
|
|
|
{
|
|
|
|
DWORD key;
|
|
|
|
WORD handle;
|
|
|
|
SHORT left;
|
|
|
|
SHORT top;
|
|
|
|
SHORT right;
|
|
|
|
SHORT bottom;
|
|
|
|
WORD inch;
|
|
|
|
DWORD reserved;
|
|
|
|
WORD checksum;
|
|
|
|
} APM_HEADER;
|
|
|
|
|
2005-07-20 12:31:37 +02:00
|
|
|
typedef struct {
|
|
|
|
BYTE bWidth;
|
|
|
|
BYTE bHeight;
|
|
|
|
BYTE bColorCount;
|
|
|
|
BYTE bReserved;
|
|
|
|
WORD xHotspot;
|
|
|
|
WORD yHotspot;
|
|
|
|
DWORD dwDIBSize;
|
|
|
|
DWORD dwDIBOffset;
|
|
|
|
} CURSORICONFILEDIRENTRY;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
WORD idReserved;
|
|
|
|
WORD idType;
|
|
|
|
WORD idCount;
|
|
|
|
CURSORICONFILEDIRENTRY idEntries[1];
|
|
|
|
} CURSORICONFILEDIR;
|
|
|
|
|
|
|
|
#include "poppack.h"
|
|
|
|
|
2000-07-15 16:59:11 +02:00
|
|
|
/*************************************************************************
|
|
|
|
* Declaration of implementation class
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct OLEPictureImpl {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IPicture handles IUnknown
|
|
|
|
*/
|
|
|
|
|
2005-07-27 17:14:18 +02:00
|
|
|
const IPictureVtbl *lpVtbl;
|
|
|
|
const IDispatchVtbl *lpvtblIDispatch;
|
|
|
|
const IPersistStreamVtbl *lpvtblIPersistStream;
|
|
|
|
const IConnectionPointContainerVtbl *lpvtblIConnectionPointContainer;
|
2000-07-15 16:59:11 +02:00
|
|
|
|
2005-02-25 15:07:56 +01:00
|
|
|
/* Object reference count */
|
2005-07-11 12:25:19 +02:00
|
|
|
LONG ref;
|
2000-07-15 16:59:11 +02:00
|
|
|
|
|
|
|
/* We own the object and must destroy it ourselves */
|
|
|
|
BOOL fOwn;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-15 16:59:11 +02:00
|
|
|
/* Picture description */
|
|
|
|
PICTDESC desc;
|
|
|
|
|
|
|
|
/* These are the pixel size of a bitmap */
|
|
|
|
DWORD origWidth;
|
|
|
|
DWORD origHeight;
|
|
|
|
|
|
|
|
/* And these are the size of the picture converted into HIMETRIC units */
|
|
|
|
OLE_XSIZE_HIMETRIC himetricWidth;
|
|
|
|
OLE_YSIZE_HIMETRIC himetricHeight;
|
|
|
|
|
2001-08-06 20:52:14 +02:00
|
|
|
IConnectionPoint *pCP;
|
|
|
|
|
|
|
|
BOOL keepOrigFormat;
|
|
|
|
HDC hDCCur;
|
2002-11-11 20:54:22 +01:00
|
|
|
|
2004-05-04 04:53:48 +02:00
|
|
|
/* Bitmap transparency mask */
|
|
|
|
HBITMAP hbmMask;
|
2005-04-22 21:05:05 +02:00
|
|
|
HBITMAP hbmXor;
|
2004-05-04 04:53:48 +02:00
|
|
|
COLORREF rgbTrans;
|
|
|
|
|
2002-11-11 20:54:22 +01:00
|
|
|
/* data */
|
|
|
|
void* data;
|
|
|
|
int datalen;
|
2004-09-22 06:04:03 +02:00
|
|
|
BOOL bIsDirty; /* Set to TRUE if picture has changed */
|
|
|
|
unsigned int loadtime_magic; /* If a length header was found, saves value */
|
|
|
|
unsigned int loadtime_format; /* for PICTYPE_BITMAP only, keeps track of image format (GIF/BMP/JPEG) */
|
2000-07-15 16:59:11 +02:00
|
|
|
} OLEPictureImpl;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Macros to retrieve pointer to IUnknown (IPicture) from the other VTables.
|
|
|
|
*/
|
2005-07-27 17:14:18 +02:00
|
|
|
|
|
|
|
static inline OLEPictureImpl *impl_from_IDispatch( IDispatch *iface )
|
|
|
|
{
|
|
|
|
return (OLEPictureImpl *)((char*)iface - FIELD_OFFSET(OLEPictureImpl, lpvtblIDispatch));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline OLEPictureImpl *impl_from_IPersistStream( IPersistStream *iface )
|
|
|
|
{
|
|
|
|
return (OLEPictureImpl *)((char*)iface - FIELD_OFFSET(OLEPictureImpl, lpvtblIPersistStream));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline OLEPictureImpl *impl_from_IConnectionPointContainer( IConnectionPointContainer *iface )
|
|
|
|
{
|
|
|
|
return (OLEPictureImpl *)((char*)iface - FIELD_OFFSET(OLEPictureImpl, lpvtblIConnectionPointContainer));
|
|
|
|
}
|
2000-07-15 16:59:11 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Predeclare VTables. They get initialized at the end.
|
|
|
|
*/
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IPictureVtbl OLEPictureImpl_VTable;
|
|
|
|
static const IDispatchVtbl OLEPictureImpl_IDispatch_VTable;
|
|
|
|
static const IPersistStreamVtbl OLEPictureImpl_IPersistStream_VTable;
|
|
|
|
static const IConnectionPointContainerVtbl OLEPictureImpl_IConnectionPointContainer_VTable;
|
2000-07-15 16:59:11 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Implementation of the OLEPictureImpl class.
|
|
|
|
*/
|
|
|
|
|
2001-08-06 20:52:14 +02:00
|
|
|
static void OLEPictureImpl_SetBitmap(OLEPictureImpl*This) {
|
|
|
|
BITMAP bm;
|
|
|
|
HDC hdcRef;
|
|
|
|
|
2002-10-25 05:12:50 +02:00
|
|
|
TRACE("bitmap handle %p\n", This->desc.u.bmp.hbitmap);
|
2001-08-06 20:52:14 +02:00
|
|
|
if(GetObjectA(This->desc.u.bmp.hbitmap, sizeof(bm), &bm) != sizeof(bm)) {
|
|
|
|
ERR("GetObject fails\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
This->origWidth = bm.bmWidth;
|
|
|
|
This->origHeight = bm.bmHeight;
|
|
|
|
/* The width and height are stored in HIMETRIC units (0.01 mm),
|
|
|
|
so we take our pixel width divide by pixels per inch and
|
|
|
|
multiply by 25.4 * 100 */
|
|
|
|
/* Should we use GetBitmapDimension if available? */
|
|
|
|
hdcRef = CreateCompatibleDC(0);
|
|
|
|
This->himetricWidth =(bm.bmWidth *2540)/GetDeviceCaps(hdcRef, LOGPIXELSX);
|
|
|
|
This->himetricHeight=(bm.bmHeight*2540)/GetDeviceCaps(hdcRef, LOGPIXELSY);
|
|
|
|
DeleteDC(hdcRef);
|
|
|
|
}
|
|
|
|
|
2005-03-30 12:21:30 +02:00
|
|
|
static void OLEPictureImpl_SetIcon(OLEPictureImpl * This)
|
|
|
|
{
|
|
|
|
ICONINFO infoIcon;
|
|
|
|
|
|
|
|
TRACE("icon handle %p\n", This->desc.u.icon.hicon);
|
|
|
|
if (GetIconInfo(This->desc.u.icon.hicon, &infoIcon)) {
|
|
|
|
HDC hdcRef;
|
|
|
|
BITMAP bm;
|
|
|
|
|
|
|
|
TRACE("bitmap handle for icon is %p\n", infoIcon.hbmColor);
|
|
|
|
if(GetObjectA(infoIcon.hbmColor ? infoIcon.hbmColor : infoIcon.hbmMask, sizeof(bm), &bm) != sizeof(bm)) {
|
|
|
|
ERR("GetObject fails on icon bitmap\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
This->origWidth = bm.bmWidth;
|
|
|
|
This->origHeight = infoIcon.hbmColor ? bm.bmHeight : bm.bmHeight / 2;
|
|
|
|
/* see comment on HIMETRIC on OLEPictureImpl_SetBitmap() */
|
|
|
|
hdcRef = GetDC(0);
|
|
|
|
This->himetricWidth = (This->origWidth *2540)/GetDeviceCaps(hdcRef, LOGPIXELSX);
|
|
|
|
This->himetricHeight= (This->origHeight *2540)/GetDeviceCaps(hdcRef, LOGPIXELSY);
|
|
|
|
ReleaseDC(0, hdcRef);
|
|
|
|
|
|
|
|
DeleteObject(infoIcon.hbmMask);
|
|
|
|
if (infoIcon.hbmColor) DeleteObject(infoIcon.hbmColor);
|
|
|
|
} else {
|
|
|
|
ERR("GetIconInfo() fails on icon %p\n", This->desc.u.icon.hicon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-15 16:59:11 +02:00
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_Construct
|
|
|
|
*
|
|
|
|
* This method will construct a new instance of the OLEPictureImpl
|
|
|
|
* class.
|
|
|
|
*
|
|
|
|
* The caller of this method must release the object when it's
|
|
|
|
* done with it.
|
|
|
|
*/
|
|
|
|
static OLEPictureImpl* OLEPictureImpl_Construct(LPPICTDESC pictDesc, BOOL fOwn)
|
|
|
|
{
|
|
|
|
OLEPictureImpl* newObject = 0;
|
2001-08-06 20:52:14 +02:00
|
|
|
|
|
|
|
if (pictDesc)
|
|
|
|
TRACE("(%p) type = %d\n", pictDesc, pictDesc->picType);
|
2000-07-15 16:59:11 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate space for the object.
|
|
|
|
*/
|
2002-11-11 20:54:22 +01:00
|
|
|
newObject = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(OLEPictureImpl));
|
2000-07-15 16:59:11 +02:00
|
|
|
|
|
|
|
if (newObject==0)
|
|
|
|
return newObject;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-15 16:59:11 +02:00
|
|
|
/*
|
|
|
|
* Initialize the virtual function table.
|
|
|
|
*/
|
2005-07-27 17:14:18 +02:00
|
|
|
newObject->lpVtbl = &OLEPictureImpl_VTable;
|
|
|
|
newObject->lpvtblIDispatch = &OLEPictureImpl_IDispatch_VTable;
|
|
|
|
newObject->lpvtblIPersistStream = &OLEPictureImpl_IPersistStream_VTable;
|
|
|
|
newObject->lpvtblIConnectionPointContainer = &OLEPictureImpl_IConnectionPointContainer_VTable;
|
2001-08-06 20:52:14 +02:00
|
|
|
|
2006-02-14 11:34:00 +01:00
|
|
|
newObject->pCP = NULL;
|
2001-08-06 20:52:14 +02:00
|
|
|
CreateConnectionPoint((IUnknown*)newObject,&IID_IPropertyNotifySink,&newObject->pCP);
|
2006-02-14 11:34:00 +01:00
|
|
|
if (!newObject->pCP)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, newObject);
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-08-06 20:52:14 +02:00
|
|
|
|
2000-07-15 16:59:11 +02:00
|
|
|
/*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Start with one reference count. The caller of this function
|
2000-07-15 16:59:11 +02:00
|
|
|
* must release the interface pointer when it is done.
|
|
|
|
*/
|
2001-08-06 20:52:14 +02:00
|
|
|
newObject->ref = 1;
|
|
|
|
newObject->hDCCur = 0;
|
2000-07-15 16:59:11 +02:00
|
|
|
|
2001-08-06 20:52:14 +02:00
|
|
|
newObject->fOwn = fOwn;
|
2000-07-15 16:59:11 +02:00
|
|
|
|
2001-08-06 20:52:14 +02:00
|
|
|
/* dunno about original value */
|
|
|
|
newObject->keepOrigFormat = TRUE;
|
2000-07-15 16:59:11 +02:00
|
|
|
|
2004-05-04 04:53:48 +02:00
|
|
|
newObject->hbmMask = NULL;
|
2005-04-22 21:05:05 +02:00
|
|
|
newObject->hbmXor = NULL;
|
2004-09-22 06:04:03 +02:00
|
|
|
newObject->loadtime_magic = 0xdeadbeef;
|
|
|
|
newObject->loadtime_format = 0;
|
|
|
|
newObject->bIsDirty = FALSE;
|
2004-05-04 04:53:48 +02:00
|
|
|
|
2001-08-06 20:52:14 +02:00
|
|
|
if (pictDesc) {
|
2008-03-11 21:55:17 +01:00
|
|
|
newObject->desc = *pictDesc;
|
2000-07-15 16:59:11 +02:00
|
|
|
|
2001-08-06 20:52:14 +02:00
|
|
|
switch(pictDesc->picType) {
|
|
|
|
case PICTYPE_BITMAP:
|
|
|
|
OLEPictureImpl_SetBitmap(newObject);
|
|
|
|
break;
|
2000-07-15 16:59:11 +02:00
|
|
|
|
2001-08-06 20:52:14 +02:00
|
|
|
case PICTYPE_METAFILE:
|
2002-10-25 05:12:50 +02:00
|
|
|
TRACE("metafile handle %p\n", pictDesc->u.wmf.hmeta);
|
2001-08-06 20:52:14 +02:00
|
|
|
newObject->himetricWidth = pictDesc->u.wmf.xExt;
|
|
|
|
newObject->himetricHeight = pictDesc->u.wmf.yExt;
|
|
|
|
break;
|
2000-07-15 16:59:11 +02:00
|
|
|
|
2003-01-02 18:54:57 +01:00
|
|
|
case PICTYPE_NONE:
|
|
|
|
/* not sure what to do here */
|
|
|
|
newObject->himetricWidth = newObject->himetricHeight = 0;
|
|
|
|
break;
|
|
|
|
|
2001-08-06 20:52:14 +02:00
|
|
|
case PICTYPE_ICON:
|
2005-03-30 12:21:30 +02:00
|
|
|
OLEPictureImpl_SetIcon(newObject);
|
|
|
|
break;
|
2001-08-06 20:52:14 +02:00
|
|
|
case PICTYPE_ENHMETAFILE:
|
|
|
|
default:
|
|
|
|
FIXME("Unsupported type %d\n", pictDesc->picType);
|
|
|
|
newObject->himetricWidth = newObject->himetricHeight = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
newObject->desc.picType = PICTYPE_UNINITIALIZED;
|
2000-07-15 16:59:11 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-15 16:59:11 +02:00
|
|
|
TRACE("returning %p\n", newObject);
|
|
|
|
return newObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_Destroy
|
|
|
|
*
|
|
|
|
* This method is called by the Release method when the reference
|
2000-07-16 17:44:22 +02:00
|
|
|
* count goes down to 0. It will free all resources used by
|
2000-07-15 16:59:11 +02:00
|
|
|
* this object. */
|
|
|
|
static void OLEPictureImpl_Destroy(OLEPictureImpl* Obj)
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
2000-07-15 16:59:11 +02:00
|
|
|
TRACE("(%p)\n", Obj);
|
|
|
|
|
2006-02-14 11:34:00 +01:00
|
|
|
if (Obj->pCP)
|
|
|
|
IConnectionPoint_Release(Obj->pCP);
|
|
|
|
|
2000-07-15 16:59:11 +02:00
|
|
|
if(Obj->fOwn) { /* We need to destroy the picture */
|
|
|
|
switch(Obj->desc.picType) {
|
|
|
|
case PICTYPE_BITMAP:
|
|
|
|
DeleteObject(Obj->desc.u.bmp.hbitmap);
|
2005-04-22 21:05:05 +02:00
|
|
|
if (Obj->hbmMask != NULL) DeleteObject(Obj->hbmMask);
|
|
|
|
if (Obj->hbmXor != NULL) DeleteObject(Obj->hbmXor);
|
2000-07-15 16:59:11 +02:00
|
|
|
break;
|
|
|
|
case PICTYPE_METAFILE:
|
|
|
|
DeleteMetaFile(Obj->desc.u.wmf.hmeta);
|
|
|
|
break;
|
|
|
|
case PICTYPE_ICON:
|
|
|
|
DestroyIcon(Obj->desc.u.icon.hicon);
|
|
|
|
break;
|
|
|
|
case PICTYPE_ENHMETAFILE:
|
|
|
|
DeleteEnhMetaFile(Obj->desc.u.emf.hemf);
|
|
|
|
break;
|
2005-06-06 12:03:58 +02:00
|
|
|
case PICTYPE_NONE:
|
2007-06-05 11:33:24 +02:00
|
|
|
case PICTYPE_UNINITIALIZED:
|
2005-06-06 12:03:58 +02:00
|
|
|
/* Nothing to do */
|
|
|
|
break;
|
2000-07-15 16:59:11 +02:00
|
|
|
default:
|
|
|
|
FIXME("Unsupported type %d - unable to delete\n", Obj->desc.picType);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, Obj->data);
|
2000-07-15 16:59:11 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, Obj);
|
|
|
|
}
|
|
|
|
|
2006-03-08 12:54:36 +01:00
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_AddRef (IUnknown)
|
|
|
|
*
|
|
|
|
* See Windows documentation for more details on IUnknown methods.
|
|
|
|
*/
|
|
|
|
static ULONG WINAPI OLEPictureImpl_AddRef(
|
|
|
|
IPicture* iface)
|
|
|
|
{
|
|
|
|
OLEPictureImpl *This = (OLEPictureImpl *)iface;
|
|
|
|
ULONG refCount = InterlockedIncrement(&This->ref);
|
|
|
|
|
2006-10-12 20:57:10 +02:00
|
|
|
TRACE("(%p)->(ref before=%d)\n", This, refCount - 1);
|
2006-03-08 12:54:36 +01:00
|
|
|
|
|
|
|
return refCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_Release (IUnknown)
|
|
|
|
*
|
|
|
|
* See Windows documentation for more details on IUnknown methods.
|
|
|
|
*/
|
|
|
|
static ULONG WINAPI OLEPictureImpl_Release(
|
|
|
|
IPicture* iface)
|
|
|
|
{
|
|
|
|
OLEPictureImpl *This = (OLEPictureImpl *)iface;
|
|
|
|
ULONG refCount = InterlockedDecrement(&This->ref);
|
|
|
|
|
2006-10-12 20:57:10 +02:00
|
|
|
TRACE("(%p)->(ref before=%d)\n", This, refCount + 1);
|
2006-03-08 12:54:36 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the reference count goes down to 0, perform suicide.
|
|
|
|
*/
|
|
|
|
if (!refCount) OLEPictureImpl_Destroy(This);
|
|
|
|
|
|
|
|
return refCount;
|
|
|
|
}
|
2000-07-15 16:59:11 +02:00
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_QueryInterface (IUnknown)
|
|
|
|
*
|
|
|
|
* See Windows documentation for more details on IUnknown methods.
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI OLEPictureImpl_QueryInterface(
|
|
|
|
IPicture* iface,
|
|
|
|
REFIID riid,
|
|
|
|
void** ppvObject)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
OLEPictureImpl *This = (OLEPictureImpl *)iface;
|
2000-07-15 16:59:11 +02:00
|
|
|
TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppvObject);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform a sanity check on the parameters.
|
|
|
|
*/
|
|
|
|
if ( (This==0) || (ppvObject==0) )
|
|
|
|
return E_INVALIDARG;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-15 16:59:11 +02:00
|
|
|
/*
|
|
|
|
* Initialize the return parameter.
|
|
|
|
*/
|
|
|
|
*ppvObject = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-15 16:59:11 +02:00
|
|
|
/*
|
|
|
|
* Compare the riid with the interface IDs implemented by this object.
|
|
|
|
*/
|
2006-03-29 19:41:01 +02:00
|
|
|
if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IPicture, riid))
|
2009-02-09 09:45:52 +01:00
|
|
|
*ppvObject = This;
|
2006-03-29 19:41:01 +02:00
|
|
|
else if (IsEqualIID(&IID_IDispatch, riid))
|
2009-02-09 09:45:52 +01:00
|
|
|
*ppvObject = &This->lpvtblIDispatch;
|
2006-03-29 19:41:01 +02:00
|
|
|
else if (IsEqualIID(&IID_IPictureDisp, riid))
|
2009-02-09 09:45:52 +01:00
|
|
|
*ppvObject = &This->lpvtblIDispatch;
|
2006-03-29 19:41:24 +02:00
|
|
|
else if (IsEqualIID(&IID_IPersist, riid) || IsEqualIID(&IID_IPersistStream, riid))
|
2009-02-09 09:45:52 +01:00
|
|
|
*ppvObject = &This->lpvtblIPersistStream;
|
2006-03-29 19:41:01 +02:00
|
|
|
else if (IsEqualIID(&IID_IConnectionPointContainer, riid))
|
2009-02-09 09:45:52 +01:00
|
|
|
*ppvObject = &This->lpvtblIConnectionPointContainer;
|
2006-03-29 19:41:01 +02:00
|
|
|
|
2000-07-15 16:59:11 +02:00
|
|
|
/*
|
|
|
|
* Check that we obtained an interface.
|
|
|
|
*/
|
|
|
|
if ((*ppvObject)==0)
|
|
|
|
{
|
|
|
|
FIXME("() : asking for un supported interface %s\n",debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-15 16:59:11 +02:00
|
|
|
/*
|
|
|
|
* Query Interface always increases the reference count by one when it is
|
|
|
|
* successful
|
|
|
|
*/
|
|
|
|
OLEPictureImpl_AddRef((IPicture*)This);
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
return S_OK;
|
2000-07-15 16:59:11 +02:00
|
|
|
}
|
2006-03-08 12:54:36 +01:00
|
|
|
|
2001-08-06 20:52:14 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* OLEPicture_SendNotify (internal)
|
|
|
|
*
|
|
|
|
* Sends notification messages of changed properties to any interested
|
|
|
|
* connections.
|
|
|
|
*/
|
|
|
|
static void OLEPicture_SendNotify(OLEPictureImpl* this, DISPID dispID)
|
|
|
|
{
|
|
|
|
IEnumConnections *pEnum;
|
|
|
|
CONNECTDATA CD;
|
|
|
|
|
|
|
|
if (IConnectionPoint_EnumConnections(this->pCP, &pEnum))
|
|
|
|
return;
|
|
|
|
while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
|
|
|
|
IPropertyNotifySink *sink;
|
|
|
|
|
|
|
|
IUnknown_QueryInterface(CD.pUnk, &IID_IPropertyNotifySink, (LPVOID)&sink);
|
|
|
|
IPropertyNotifySink_OnChanged(sink, dispID);
|
|
|
|
IPropertyNotifySink_Release(sink);
|
|
|
|
IUnknown_Release(CD.pUnk);
|
|
|
|
}
|
|
|
|
IEnumConnections_Release(pEnum);
|
|
|
|
}
|
|
|
|
|
2000-07-15 16:59:11 +02:00
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_get_Handle
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
2000-07-15 16:59:11 +02:00
|
|
|
static HRESULT WINAPI OLEPictureImpl_get_Handle(IPicture *iface,
|
|
|
|
OLE_HANDLE *phandle)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
OLEPictureImpl *This = (OLEPictureImpl *)iface;
|
2000-07-15 16:59:11 +02:00
|
|
|
TRACE("(%p)->(%p)\n", This, phandle);
|
2009-01-07 07:07:06 +01:00
|
|
|
|
|
|
|
if(!phandle)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2000-07-15 16:59:11 +02:00
|
|
|
switch(This->desc.picType) {
|
2005-06-06 12:03:58 +02:00
|
|
|
case PICTYPE_NONE:
|
2007-06-05 11:33:24 +02:00
|
|
|
case PICTYPE_UNINITIALIZED:
|
2005-06-06 12:03:58 +02:00
|
|
|
*phandle = 0;
|
|
|
|
break;
|
2000-07-15 16:59:11 +02:00
|
|
|
case PICTYPE_BITMAP:
|
2009-01-08 17:27:14 +01:00
|
|
|
*phandle = HandleToUlong(This->desc.u.bmp.hbitmap);
|
2000-07-15 16:59:11 +02:00
|
|
|
break;
|
|
|
|
case PICTYPE_METAFILE:
|
2009-01-08 17:27:14 +01:00
|
|
|
*phandle = HandleToUlong(This->desc.u.wmf.hmeta);
|
2000-07-15 16:59:11 +02:00
|
|
|
break;
|
|
|
|
case PICTYPE_ICON:
|
2009-01-08 17:27:14 +01:00
|
|
|
*phandle = HandleToUlong(This->desc.u.icon.hicon);
|
2000-07-15 16:59:11 +02:00
|
|
|
break;
|
|
|
|
case PICTYPE_ENHMETAFILE:
|
2009-01-08 17:27:14 +01:00
|
|
|
*phandle = HandleToUlong(This->desc.u.emf.hemf);
|
2000-07-15 16:59:11 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Unimplemented type %d\n", This->desc.picType);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
TRACE("returning handle %08x\n", *phandle);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_get_hPal
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
2000-07-15 16:59:11 +02:00
|
|
|
static HRESULT WINAPI OLEPictureImpl_get_hPal(IPicture *iface,
|
|
|
|
OLE_HANDLE *phandle)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
OLEPictureImpl *This = (OLEPictureImpl *)iface;
|
2005-08-24 11:44:25 +02:00
|
|
|
HRESULT hres;
|
|
|
|
TRACE("(%p)->(%p)\n", This, phandle);
|
2005-06-06 12:03:58 +02:00
|
|
|
|
2005-08-24 11:44:25 +02:00
|
|
|
if (!phandle)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
switch (This->desc.picType) {
|
2007-08-03 00:48:13 +02:00
|
|
|
case (UINT)PICTYPE_UNINITIALIZED:
|
2005-08-24 11:44:25 +02:00
|
|
|
case PICTYPE_NONE:
|
|
|
|
*phandle = 0;
|
|
|
|
hres = S_FALSE;
|
|
|
|
break;
|
|
|
|
case PICTYPE_BITMAP:
|
2009-01-08 17:27:14 +01:00
|
|
|
*phandle = HandleToUlong(This->desc.u.bmp.hpal);
|
2005-08-24 11:44:25 +02:00
|
|
|
hres = S_OK;
|
|
|
|
break;
|
|
|
|
case PICTYPE_METAFILE:
|
2007-10-04 01:56:53 +02:00
|
|
|
hres = E_FAIL;
|
|
|
|
break;
|
|
|
|
case PICTYPE_ICON:
|
2005-08-24 11:44:25 +02:00
|
|
|
case PICTYPE_ENHMETAFILE:
|
|
|
|
default:
|
|
|
|
FIXME("unimplemented for type %d. Returning 0 palette.\n",
|
|
|
|
This->desc.picType);
|
|
|
|
*phandle = 0;
|
|
|
|
hres = S_OK;
|
|
|
|
}
|
|
|
|
|
2006-10-12 20:57:10 +02:00
|
|
|
TRACE("returning 0x%08x, palette handle %08x\n", hres, *phandle);
|
2005-08-24 11:44:25 +02:00
|
|
|
return hres;
|
2000-07-15 16:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_get_Type
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
2000-07-15 16:59:11 +02:00
|
|
|
static HRESULT WINAPI OLEPictureImpl_get_Type(IPicture *iface,
|
|
|
|
short *ptype)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
OLEPictureImpl *This = (OLEPictureImpl *)iface;
|
2000-07-15 16:59:11 +02:00
|
|
|
TRACE("(%p)->(%p): type is %d\n", This, ptype, This->desc.picType);
|
2009-01-07 07:31:00 +01:00
|
|
|
|
|
|
|
if(!ptype)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2000-07-15 16:59:11 +02:00
|
|
|
*ptype = This->desc.picType;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_get_Width
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
2000-07-15 16:59:11 +02:00
|
|
|
static HRESULT WINAPI OLEPictureImpl_get_Width(IPicture *iface,
|
|
|
|
OLE_XSIZE_HIMETRIC *pwidth)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
OLEPictureImpl *This = (OLEPictureImpl *)iface;
|
2006-10-12 20:57:10 +02:00
|
|
|
TRACE("(%p)->(%p): width is %d\n", This, pwidth, This->himetricWidth);
|
2000-07-15 16:59:11 +02:00
|
|
|
*pwidth = This->himetricWidth;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_get_Height
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
2000-07-15 16:59:11 +02:00
|
|
|
static HRESULT WINAPI OLEPictureImpl_get_Height(IPicture *iface,
|
|
|
|
OLE_YSIZE_HIMETRIC *pheight)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
OLEPictureImpl *This = (OLEPictureImpl *)iface;
|
2006-10-12 20:57:10 +02:00
|
|
|
TRACE("(%p)->(%p): height is %d\n", This, pheight, This->himetricHeight);
|
2000-07-15 16:59:11 +02:00
|
|
|
*pheight = This->himetricHeight;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_Render
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
2000-07-15 16:59:11 +02:00
|
|
|
static HRESULT WINAPI OLEPictureImpl_Render(IPicture *iface, HDC hdc,
|
2004-10-19 00:39:21 +02:00
|
|
|
LONG x, LONG y, LONG cx, LONG cy,
|
2000-07-15 16:59:11 +02:00
|
|
|
OLE_XPOS_HIMETRIC xSrc,
|
|
|
|
OLE_YPOS_HIMETRIC ySrc,
|
|
|
|
OLE_XSIZE_HIMETRIC cxSrc,
|
|
|
|
OLE_YSIZE_HIMETRIC cySrc,
|
|
|
|
LPCRECT prcWBounds)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
OLEPictureImpl *This = (OLEPictureImpl *)iface;
|
2006-10-12 20:57:10 +02:00
|
|
|
TRACE("(%p)->(%p, (%d,%d), (%d,%d) <- (%d,%d), (%d,%d), %p)\n",
|
2000-07-15 16:59:11 +02:00
|
|
|
This, hdc, x, y, cx, cy, xSrc, ySrc, cxSrc, cySrc, prcWBounds);
|
|
|
|
if(prcWBounds)
|
2006-10-12 20:57:10 +02:00
|
|
|
TRACE("prcWBounds (%d,%d) - (%d,%d)\n", prcWBounds->left, prcWBounds->top,
|
2000-07-15 16:59:11 +02:00
|
|
|
prcWBounds->right, prcWBounds->bottom);
|
|
|
|
|
2008-12-10 13:08:47 +01:00
|
|
|
if(cx == 0 || cy == 0 || cxSrc == 0 || cySrc == 0){
|
|
|
|
return CTL_E_INVALIDPROPERTYVALUE;
|
|
|
|
}
|
|
|
|
|
2001-08-06 20:52:14 +02:00
|
|
|
/*
|
|
|
|
* While the documentation suggests this to be here (or after rendering?)
|
|
|
|
* it does cause an endless recursion in my sample app. -MM 20010804
|
|
|
|
OLEPicture_SendNotify(This,DISPID_PICT_RENDER);
|
|
|
|
*/
|
|
|
|
|
2000-07-15 16:59:11 +02:00
|
|
|
switch(This->desc.picType) {
|
2008-12-10 13:08:47 +01:00
|
|
|
case PICTYPE_UNINITIALIZED:
|
|
|
|
case PICTYPE_NONE:
|
|
|
|
/* nothing to do */
|
|
|
|
return S_OK;
|
2000-07-15 16:59:11 +02:00
|
|
|
case PICTYPE_BITMAP:
|
|
|
|
{
|
|
|
|
HBITMAP hbmpOld;
|
|
|
|
HDC hdcBmp;
|
|
|
|
|
|
|
|
/* Set a mapping mode that maps bitmap pixels into HIMETRIC units.
|
|
|
|
NB y-axis gets flipped */
|
|
|
|
|
|
|
|
hdcBmp = CreateCompatibleDC(0);
|
|
|
|
SetMapMode(hdcBmp, MM_ANISOTROPIC);
|
|
|
|
SetWindowOrgEx(hdcBmp, 0, 0, NULL);
|
|
|
|
SetWindowExtEx(hdcBmp, This->himetricWidth, This->himetricHeight, NULL);
|
|
|
|
SetViewportOrgEx(hdcBmp, 0, This->origHeight, NULL);
|
|
|
|
SetViewportExtEx(hdcBmp, This->origWidth, -This->origHeight, NULL);
|
|
|
|
|
2004-05-04 04:53:48 +02:00
|
|
|
if (This->hbmMask) {
|
|
|
|
HDC hdcMask = CreateCompatibleDC(0);
|
|
|
|
HBITMAP hOldbm = SelectObject(hdcMask, This->hbmMask);
|
|
|
|
|
2005-04-22 21:05:05 +02:00
|
|
|
hbmpOld = SelectObject(hdcBmp, This->hbmXor);
|
|
|
|
|
2004-05-04 04:53:48 +02:00
|
|
|
SetMapMode(hdcMask, MM_ANISOTROPIC);
|
|
|
|
SetWindowOrgEx(hdcMask, 0, 0, NULL);
|
|
|
|
SetWindowExtEx(hdcMask, This->himetricWidth, This->himetricHeight, NULL);
|
|
|
|
SetViewportOrgEx(hdcMask, 0, This->origHeight, NULL);
|
|
|
|
SetViewportExtEx(hdcMask, This->origWidth, -This->origHeight, NULL);
|
|
|
|
|
|
|
|
SetBkColor(hdc, RGB(255, 255, 255));
|
|
|
|
SetTextColor(hdc, RGB(0, 0, 0));
|
|
|
|
StretchBlt(hdc, x, y, cx, cy, hdcMask, xSrc, ySrc, cxSrc, cySrc, SRCAND);
|
|
|
|
StretchBlt(hdc, x, y, cx, cy, hdcBmp, xSrc, ySrc, cxSrc, cySrc, SRCPAINT);
|
|
|
|
|
|
|
|
SelectObject(hdcMask, hOldbm);
|
|
|
|
DeleteDC(hdcMask);
|
2005-04-22 21:05:05 +02:00
|
|
|
} else {
|
|
|
|
hbmpOld = SelectObject(hdcBmp, This->desc.u.bmp.hbitmap);
|
2004-05-04 04:53:48 +02:00
|
|
|
StretchBlt(hdc, x, y, cx, cy, hdcBmp, xSrc, ySrc, cxSrc, cySrc, SRCCOPY);
|
2005-04-22 21:05:05 +02:00
|
|
|
}
|
2000-07-15 16:59:11 +02:00
|
|
|
|
|
|
|
SelectObject(hdcBmp, hbmpOld);
|
|
|
|
DeleteDC(hdcBmp);
|
|
|
|
}
|
|
|
|
break;
|
2001-08-06 20:52:14 +02:00
|
|
|
case PICTYPE_ICON:
|
|
|
|
FIXME("Not quite correct implementation of rendering icons...\n");
|
|
|
|
DrawIcon(hdc,x,y,This->desc.u.icon.hicon);
|
|
|
|
break;
|
2000-07-15 16:59:11 +02:00
|
|
|
|
|
|
|
case PICTYPE_METAFILE:
|
2007-10-04 02:26:56 +02:00
|
|
|
{
|
2009-01-20 03:50:03 +01:00
|
|
|
POINT prevOrg, prevWndOrg;
|
|
|
|
SIZE prevExt, prevWndExt;
|
2007-10-04 02:26:56 +02:00
|
|
|
int oldmode;
|
|
|
|
|
2009-01-20 03:50:03 +01:00
|
|
|
/* Render the WMF to the appropriate location by setting the
|
|
|
|
appropriate ratio between "device units" and "logical units" */
|
2007-10-04 02:26:56 +02:00
|
|
|
oldmode = SetMapMode(hdc, MM_ANISOTROPIC);
|
2009-01-20 03:50:03 +01:00
|
|
|
/* For the "source rectangle" the y-axis must be inverted */
|
|
|
|
SetWindowOrgEx(hdc, xSrc, This->himetricHeight-ySrc, &prevWndOrg);
|
|
|
|
SetWindowExtEx(hdc, cxSrc, -cySrc, &prevWndExt);
|
|
|
|
/* For the "destination rectangle" no inversion is necessary */
|
2007-10-04 02:26:56 +02:00
|
|
|
SetViewportOrgEx(hdc, x, y, &prevOrg);
|
|
|
|
SetViewportExtEx(hdc, cx, cy, &prevExt);
|
|
|
|
|
|
|
|
if (!PlayMetaFile(hdc, This->desc.u.wmf.hmeta))
|
|
|
|
ERR("PlayMetaFile failed!\n");
|
|
|
|
|
2009-01-20 03:50:03 +01:00
|
|
|
/* We're done, restore the DC to the previous settings for converting
|
|
|
|
logical units to device units */
|
|
|
|
SetWindowExtEx(hdc, prevWndExt.cx, prevWndExt.cy, NULL);
|
|
|
|
SetWindowOrgEx(hdc, prevWndOrg.x, prevWndOrg.y, NULL);
|
2007-10-04 02:26:56 +02:00
|
|
|
SetViewportExtEx(hdc, prevExt.cx, prevExt.cy, NULL);
|
|
|
|
SetViewportOrgEx(hdc, prevOrg.x, prevOrg.y, NULL);
|
|
|
|
SetMapMode(hdc, oldmode);
|
2007-05-28 09:22:46 +02:00
|
|
|
break;
|
2007-10-04 02:26:56 +02:00
|
|
|
}
|
2007-05-28 09:22:46 +02:00
|
|
|
|
2000-07-15 16:59:11 +02:00
|
|
|
case PICTYPE_ENHMETAFILE:
|
2007-05-28 09:22:46 +02:00
|
|
|
{
|
2007-08-02 02:55:27 +02:00
|
|
|
RECT rc = { x, y, x + cx, y + cy };
|
2007-05-28 09:22:46 +02:00
|
|
|
PlayEnhMetaFile(hdc, This->desc.u.emf.hemf, &rc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-07-15 16:59:11 +02:00
|
|
|
default:
|
|
|
|
FIXME("type %d not implemented\n", This->desc.picType);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_set_hPal
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
2000-07-15 16:59:11 +02:00
|
|
|
static HRESULT WINAPI OLEPictureImpl_set_hPal(IPicture *iface,
|
|
|
|
OLE_HANDLE hpal)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
OLEPictureImpl *This = (OLEPictureImpl *)iface;
|
2000-07-15 16:59:11 +02:00
|
|
|
FIXME("(%p)->(%08x): stub\n", This, hpal);
|
2001-08-06 20:52:14 +02:00
|
|
|
OLEPicture_SendNotify(This,DISPID_PICT_HPAL);
|
2000-07-15 16:59:11 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_get_CurDC
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
2000-07-15 16:59:11 +02:00
|
|
|
static HRESULT WINAPI OLEPictureImpl_get_CurDC(IPicture *iface,
|
|
|
|
HDC *phdc)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
OLEPictureImpl *This = (OLEPictureImpl *)iface;
|
2002-10-25 05:12:50 +02:00
|
|
|
TRACE("(%p), returning %p\n", This, This->hDCCur);
|
2001-08-06 20:52:14 +02:00
|
|
|
if (phdc) *phdc = This->hDCCur;
|
|
|
|
return S_OK;
|
2000-07-15 16:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_SelectPicture
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
2000-07-15 16:59:11 +02:00
|
|
|
static HRESULT WINAPI OLEPictureImpl_SelectPicture(IPicture *iface,
|
|
|
|
HDC hdcIn,
|
|
|
|
HDC *phdcOut,
|
|
|
|
OLE_HANDLE *phbmpOut)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
OLEPictureImpl *This = (OLEPictureImpl *)iface;
|
2002-10-25 05:12:50 +02:00
|
|
|
TRACE("(%p)->(%p, %p, %p)\n", This, hdcIn, phdcOut, phbmpOut);
|
2001-08-06 20:52:14 +02:00
|
|
|
if (This->desc.picType == PICTYPE_BITMAP) {
|
|
|
|
SelectObject(hdcIn,This->desc.u.bmp.hbitmap);
|
|
|
|
|
|
|
|
if (phdcOut)
|
|
|
|
*phdcOut = This->hDCCur;
|
|
|
|
This->hDCCur = hdcIn;
|
|
|
|
if (phbmpOut)
|
2009-01-08 17:27:14 +01:00
|
|
|
*phbmpOut = HandleToUlong(This->desc.u.bmp.hbitmap);
|
2001-08-06 20:52:14 +02:00
|
|
|
return S_OK;
|
|
|
|
} else {
|
|
|
|
FIXME("Don't know how to select picture type %d\n",This->desc.picType);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2000-07-15 16:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_get_KeepOriginalFormat
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
2000-07-15 16:59:11 +02:00
|
|
|
static HRESULT WINAPI OLEPictureImpl_get_KeepOriginalFormat(IPicture *iface,
|
|
|
|
BOOL *pfKeep)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
OLEPictureImpl *This = (OLEPictureImpl *)iface;
|
2001-08-06 20:52:14 +02:00
|
|
|
TRACE("(%p)->(%p)\n", This, pfKeep);
|
|
|
|
if (!pfKeep)
|
|
|
|
return E_POINTER;
|
|
|
|
*pfKeep = This->keepOrigFormat;
|
|
|
|
return S_OK;
|
2000-07-15 16:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_put_KeepOriginalFormat
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
2000-07-15 16:59:11 +02:00
|
|
|
static HRESULT WINAPI OLEPictureImpl_put_KeepOriginalFormat(IPicture *iface,
|
|
|
|
BOOL keep)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
OLEPictureImpl *This = (OLEPictureImpl *)iface;
|
2001-08-06 20:52:14 +02:00
|
|
|
TRACE("(%p)->(%d)\n", This, keep);
|
|
|
|
This->keepOrigFormat = keep;
|
|
|
|
/* FIXME: what DISPID notification here? */
|
|
|
|
return S_OK;
|
2000-07-15 16:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_PictureChanged
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
2000-07-15 16:59:11 +02:00
|
|
|
static HRESULT WINAPI OLEPictureImpl_PictureChanged(IPicture *iface)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
OLEPictureImpl *This = (OLEPictureImpl *)iface;
|
2001-08-06 20:52:14 +02:00
|
|
|
TRACE("(%p)->()\n", This);
|
|
|
|
OLEPicture_SendNotify(This,DISPID_PICT_HANDLE);
|
2004-09-22 06:04:03 +02:00
|
|
|
This->bIsDirty = TRUE;
|
2001-08-06 20:52:14 +02:00
|
|
|
return S_OK;
|
2000-07-15 16:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_SaveAsFile
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
2000-07-15 16:59:11 +02:00
|
|
|
static HRESULT WINAPI OLEPictureImpl_SaveAsFile(IPicture *iface,
|
|
|
|
IStream *pstream,
|
|
|
|
BOOL SaveMemCopy,
|
|
|
|
LONG *pcbSize)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
OLEPictureImpl *This = (OLEPictureImpl *)iface;
|
2002-11-11 20:54:22 +01:00
|
|
|
FIXME("(%p)->(%p, %d, %p), hacked stub.\n", This, pstream, SaveMemCopy, pcbSize);
|
|
|
|
return IStream_Write(pstream,This->data,This->datalen,(ULONG*)pcbSize);
|
2000-07-15 16:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_get_Attributes
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
2000-07-15 16:59:11 +02:00
|
|
|
static HRESULT WINAPI OLEPictureImpl_get_Attributes(IPicture *iface,
|
|
|
|
DWORD *pdwAttr)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
OLEPictureImpl *This = (OLEPictureImpl *)iface;
|
2001-08-06 20:52:14 +02:00
|
|
|
TRACE("(%p)->(%p).\n", This, pdwAttr);
|
2009-01-05 22:40:07 +01:00
|
|
|
|
|
|
|
if(!pdwAttr)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2001-08-06 20:52:14 +02:00
|
|
|
*pdwAttr = 0;
|
|
|
|
switch (This->desc.picType) {
|
2009-01-05 22:25:43 +01:00
|
|
|
case PICTYPE_UNINITIALIZED:
|
|
|
|
case PICTYPE_NONE: break;
|
2005-04-22 21:05:05 +02:00
|
|
|
case PICTYPE_BITMAP: if (This->hbmMask) *pdwAttr = PICTURE_TRANSPARENT; break; /* not 'truly' scalable, see MSDN. */
|
2001-08-06 20:52:14 +02:00
|
|
|
case PICTYPE_ICON: *pdwAttr = PICTURE_TRANSPARENT;break;
|
2007-05-28 09:22:46 +02:00
|
|
|
case PICTYPE_ENHMETAFILE: /* fall through */
|
2001-08-06 20:52:14 +02:00
|
|
|
case PICTYPE_METAFILE: *pdwAttr = PICTURE_TRANSPARENT|PICTURE_SCALABLE;break;
|
|
|
|
default:FIXME("Unknown pictype %d\n",This->desc.picType);break;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* IConnectionPointContainer
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI OLEPictureImpl_IConnectionPointContainer_QueryInterface(
|
|
|
|
IConnectionPointContainer* iface,
|
|
|
|
REFIID riid,
|
2005-07-27 17:14:18 +02:00
|
|
|
VOID** ppvoid)
|
|
|
|
{
|
|
|
|
OLEPictureImpl *This = impl_from_IConnectionPointContainer(iface);
|
2001-08-06 20:52:14 +02:00
|
|
|
|
2005-07-27 17:14:18 +02:00
|
|
|
return IPicture_QueryInterface((IPicture *)This,riid,ppvoid);
|
2001-08-06 20:52:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI OLEPictureImpl_IConnectionPointContainer_AddRef(
|
|
|
|
IConnectionPointContainer* iface)
|
|
|
|
{
|
2005-07-27 17:14:18 +02:00
|
|
|
OLEPictureImpl *This = impl_from_IConnectionPointContainer(iface);
|
2001-08-06 20:52:14 +02:00
|
|
|
|
2005-07-27 17:14:18 +02:00
|
|
|
return IPicture_AddRef((IPicture *)This);
|
2001-08-06 20:52:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI OLEPictureImpl_IConnectionPointContainer_Release(
|
|
|
|
IConnectionPointContainer* iface)
|
|
|
|
{
|
2005-07-27 17:14:18 +02:00
|
|
|
OLEPictureImpl *This = impl_from_IConnectionPointContainer(iface);
|
2001-08-06 20:52:14 +02:00
|
|
|
|
2005-07-27 17:14:18 +02:00
|
|
|
return IPicture_Release((IPicture *)This);
|
2001-08-06 20:52:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI OLEPictureImpl_EnumConnectionPoints(
|
|
|
|
IConnectionPointContainer* iface,
|
2005-07-27 17:14:18 +02:00
|
|
|
IEnumConnectionPoints** ppEnum)
|
|
|
|
{
|
|
|
|
OLEPictureImpl *This = impl_from_IConnectionPointContainer(iface);
|
2001-08-06 20:52:14 +02:00
|
|
|
|
|
|
|
FIXME("(%p,%p), stub!\n",This,ppEnum);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI OLEPictureImpl_FindConnectionPoint(
|
|
|
|
IConnectionPointContainer* iface,
|
|
|
|
REFIID riid,
|
2005-07-27 17:14:18 +02:00
|
|
|
IConnectionPoint **ppCP)
|
|
|
|
{
|
|
|
|
OLEPictureImpl *This = impl_from_IConnectionPointContainer(iface);
|
2001-08-06 20:52:14 +02:00
|
|
|
TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppCP);
|
2002-06-01 01:06:46 +02:00
|
|
|
if (!ppCP)
|
2001-08-06 20:52:14 +02:00
|
|
|
return E_POINTER;
|
|
|
|
*ppCP = NULL;
|
|
|
|
if (IsEqualGUID(riid,&IID_IPropertyNotifySink))
|
|
|
|
return IConnectionPoint_QueryInterface(This->pCP,&IID_IConnectionPoint,(LPVOID)ppCP);
|
2006-02-10 14:51:30 +01:00
|
|
|
FIXME("no connection point for %s\n",debugstr_guid(riid));
|
|
|
|
return CONNECT_E_NOCONNECTION;
|
2001-08-06 20:52:14 +02:00
|
|
|
}
|
2006-03-08 12:54:36 +01:00
|
|
|
|
|
|
|
|
2001-08-06 20:52:14 +02:00
|
|
|
/************************************************************************
|
|
|
|
* IPersistStream
|
|
|
|
*/
|
2006-03-08 12:54:36 +01:00
|
|
|
|
2001-08-06 20:52:14 +02:00
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_IPersistStream_QueryInterface (IUnknown)
|
|
|
|
*
|
|
|
|
* See Windows documentation for more details on IUnknown methods.
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI OLEPictureImpl_IPersistStream_QueryInterface(
|
|
|
|
IPersistStream* iface,
|
|
|
|
REFIID riid,
|
|
|
|
VOID** ppvoid)
|
|
|
|
{
|
2005-07-27 17:14:18 +02:00
|
|
|
OLEPictureImpl *This = impl_from_IPersistStream(iface);
|
2001-08-06 20:52:14 +02:00
|
|
|
|
2005-07-27 17:14:18 +02:00
|
|
|
return IPicture_QueryInterface((IPicture *)This, riid, ppvoid);
|
2001-08-06 20:52:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_IPersistStream_AddRef (IUnknown)
|
|
|
|
*
|
|
|
|
* See Windows documentation for more details on IUnknown methods.
|
|
|
|
*/
|
|
|
|
static ULONG WINAPI OLEPictureImpl_IPersistStream_AddRef(
|
|
|
|
IPersistStream* iface)
|
|
|
|
{
|
2005-07-27 17:14:18 +02:00
|
|
|
OLEPictureImpl *This = impl_from_IPersistStream(iface);
|
2001-08-06 20:52:14 +02:00
|
|
|
|
2005-07-27 17:14:18 +02:00
|
|
|
return IPicture_AddRef((IPicture *)This);
|
2001-08-06 20:52:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_IPersistStream_Release (IUnknown)
|
|
|
|
*
|
|
|
|
* See Windows documentation for more details on IUnknown methods.
|
|
|
|
*/
|
|
|
|
static ULONG WINAPI OLEPictureImpl_IPersistStream_Release(
|
|
|
|
IPersistStream* iface)
|
|
|
|
{
|
2005-07-27 17:14:18 +02:00
|
|
|
OLEPictureImpl *This = impl_from_IPersistStream(iface);
|
2001-08-06 20:52:14 +02:00
|
|
|
|
2005-07-27 17:14:18 +02:00
|
|
|
return IPicture_Release((IPicture *)This);
|
2001-08-06 20:52:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_IPersistStream_GetClassID
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI OLEPictureImpl_GetClassID(
|
|
|
|
IPersistStream* iface,CLSID* pClassID)
|
|
|
|
{
|
2006-07-14 01:02:36 +02:00
|
|
|
TRACE("(%p)\n", pClassID);
|
2008-03-11 21:55:17 +01:00
|
|
|
*pClassID = CLSID_StdPicture;
|
2006-07-14 01:02:36 +02:00
|
|
|
return S_OK;
|
2000-07-15 16:59:11 +02:00
|
|
|
}
|
|
|
|
|
2001-08-06 20:52:14 +02:00
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_IPersistStream_IsDirty
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI OLEPictureImpl_IsDirty(
|
|
|
|
IPersistStream* iface)
|
|
|
|
{
|
2005-07-27 17:14:18 +02:00
|
|
|
OLEPictureImpl *This = impl_from_IPersistStream(iface);
|
2001-08-06 20:52:14 +02:00
|
|
|
FIXME("(%p),stub!\n",This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2000-07-15 16:59:11 +02:00
|
|
|
|
2007-07-02 19:53:14 +02:00
|
|
|
#ifdef SONAME_LIBJPEG
|
2004-08-04 21:10:26 +02:00
|
|
|
|
|
|
|
static void *libjpeg_handle;
|
|
|
|
#define MAKE_FUNCPTR(f) static typeof(f) * p##f
|
|
|
|
MAKE_FUNCPTR(jpeg_std_error);
|
|
|
|
MAKE_FUNCPTR(jpeg_CreateDecompress);
|
|
|
|
MAKE_FUNCPTR(jpeg_read_header);
|
|
|
|
MAKE_FUNCPTR(jpeg_start_decompress);
|
|
|
|
MAKE_FUNCPTR(jpeg_read_scanlines);
|
|
|
|
MAKE_FUNCPTR(jpeg_finish_decompress);
|
|
|
|
MAKE_FUNCPTR(jpeg_destroy_decompress);
|
|
|
|
#undef MAKE_FUNCPTR
|
|
|
|
|
|
|
|
static void *load_libjpeg(void)
|
|
|
|
{
|
|
|
|
if((libjpeg_handle = wine_dlopen(SONAME_LIBJPEG, RTLD_NOW, NULL, 0)) != NULL) {
|
|
|
|
|
|
|
|
#define LOAD_FUNCPTR(f) \
|
|
|
|
if((p##f = wine_dlsym(libjpeg_handle, #f, NULL, 0)) == NULL) { \
|
|
|
|
libjpeg_handle = NULL; \
|
|
|
|
return NULL; \
|
|
|
|
}
|
|
|
|
|
|
|
|
LOAD_FUNCPTR(jpeg_std_error);
|
|
|
|
LOAD_FUNCPTR(jpeg_CreateDecompress);
|
|
|
|
LOAD_FUNCPTR(jpeg_read_header);
|
|
|
|
LOAD_FUNCPTR(jpeg_start_decompress);
|
|
|
|
LOAD_FUNCPTR(jpeg_read_scanlines);
|
|
|
|
LOAD_FUNCPTR(jpeg_finish_decompress);
|
|
|
|
LOAD_FUNCPTR(jpeg_destroy_decompress);
|
|
|
|
#undef LOAD_FUNCPTR
|
|
|
|
}
|
|
|
|
return libjpeg_handle;
|
|
|
|
}
|
|
|
|
|
2001-08-06 20:52:14 +02:00
|
|
|
/* for the jpeg decompressor source manager. */
|
|
|
|
static void _jpeg_init_source(j_decompress_ptr cinfo) { }
|
|
|
|
|
2008-07-03 12:39:28 +02:00
|
|
|
static jpeg_boolean _jpeg_fill_input_buffer(j_decompress_ptr cinfo) {
|
2001-08-06 20:52:14 +02:00
|
|
|
ERR("(), should not get here.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _jpeg_skip_input_data(j_decompress_ptr cinfo,long num_bytes) {
|
2003-08-18 21:53:23 +02:00
|
|
|
TRACE("Skipping %ld bytes...\n", num_bytes);
|
|
|
|
cinfo->src->next_input_byte += num_bytes;
|
|
|
|
cinfo->src->bytes_in_buffer -= num_bytes;
|
2001-08-06 20:52:14 +02:00
|
|
|
}
|
|
|
|
|
2008-07-03 12:39:28 +02:00
|
|
|
static jpeg_boolean _jpeg_resync_to_restart(j_decompress_ptr cinfo, int desired) {
|
2001-08-06 20:52:14 +02:00
|
|
|
ERR("(desired=%d), should not get here.\n",desired);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
static void _jpeg_term_source(j_decompress_ptr cinfo) { }
|
2007-07-02 19:53:14 +02:00
|
|
|
#endif /* SONAME_LIBJPEG */
|
2004-08-04 21:10:26 +02:00
|
|
|
|
2003-01-09 07:04:33 +01:00
|
|
|
struct gifdata {
|
|
|
|
unsigned char *data;
|
|
|
|
unsigned int curoff;
|
|
|
|
unsigned int len;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int _gif_inputfunc(GifFileType *gif, GifByteType *data, int len) {
|
2009-02-09 09:45:52 +01:00
|
|
|
struct gifdata *gd = gif->UserData;
|
2003-01-09 07:04:33 +01:00
|
|
|
|
|
|
|
if (len+gd->curoff > gd->len) {
|
2008-10-16 11:20:45 +02:00
|
|
|
ERR("Trying to read %d bytes, but only %d available.\n",len, gd->len-gd->curoff);
|
2003-01-09 07:04:33 +01:00
|
|
|
len = gd->len - gd->curoff;
|
|
|
|
}
|
|
|
|
memcpy(data, gd->data+gd->curoff, len);
|
|
|
|
gd->curoff += len;
|
|
|
|
return len;
|
|
|
|
}
|
2004-08-04 21:10:26 +02:00
|
|
|
|
2005-06-06 12:03:58 +02:00
|
|
|
|
2006-03-05 14:34:31 +01:00
|
|
|
static HRESULT OLEPictureImpl_LoadGif(OLEPictureImpl *This, BYTE *xbuf, ULONG xread)
|
|
|
|
{
|
2003-01-09 07:04:33 +01:00
|
|
|
struct gifdata gd;
|
|
|
|
GifFileType *gif;
|
|
|
|
BITMAPINFO *bmi;
|
|
|
|
HDC hdcref;
|
|
|
|
LPBYTE bytes;
|
|
|
|
int i,j,ret;
|
|
|
|
GifImageDesc *gid;
|
|
|
|
SavedImage *si;
|
|
|
|
ColorMapObject *cm;
|
2004-05-04 04:53:48 +02:00
|
|
|
int transparent = -1;
|
|
|
|
ExtensionBlock *eb;
|
2004-05-10 21:56:34 +02:00
|
|
|
int padding;
|
|
|
|
|
2003-01-09 07:04:33 +01:00
|
|
|
gd.data = xbuf;
|
|
|
|
gd.curoff = 0;
|
|
|
|
gd.len = xread;
|
2006-09-08 05:27:15 +02:00
|
|
|
gif = DGifOpen((void*)&gd, _gif_inputfunc);
|
|
|
|
ret = DGifSlurp(gif);
|
2003-01-09 07:04:33 +01:00
|
|
|
if (ret == GIF_ERROR) {
|
2008-10-16 11:20:45 +02:00
|
|
|
ERR("Failed reading GIF using libgif.\n");
|
2003-01-09 07:04:33 +01:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
TRACE("screen height %d, width %d\n", gif->SWidth, gif->SHeight);
|
|
|
|
TRACE("color res %d, backgcolor %d\n", gif->SColorResolution, gif->SBackGroundColor);
|
|
|
|
TRACE("imgcnt %d\n", gif->ImageCount);
|
|
|
|
if (gif->ImageCount<1) {
|
2008-10-16 11:20:45 +02:00
|
|
|
ERR("GIF stream does not have images inside?\n");
|
2003-01-09 07:04:33 +01:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
TRACE("curimage: %d x %d, on %dx%d, interlace %d\n",
|
|
|
|
gif->Image.Width, gif->Image.Height,
|
|
|
|
gif->Image.Left, gif->Image.Top,
|
|
|
|
gif->Image.Interlace
|
|
|
|
);
|
|
|
|
/* */
|
2004-05-10 21:56:34 +02:00
|
|
|
padding = (gif->SWidth+3) & ~3;
|
2003-01-09 07:04:33 +01:00
|
|
|
si = gif->SavedImages+0;
|
|
|
|
gid = &(si->ImageDesc);
|
|
|
|
cm = gid->ColorMap;
|
|
|
|
if (!cm) cm = gif->SColorMap;
|
2005-07-19 13:38:25 +02:00
|
|
|
bmi = HeapAlloc(GetProcessHeap(),0,sizeof(BITMAPINFOHEADER)+(cm->ColorCount)*sizeof(RGBQUAD));
|
|
|
|
bytes= HeapAlloc(GetProcessHeap(),0,padding*gif->SHeight);
|
2004-05-04 04:53:48 +02:00
|
|
|
|
|
|
|
/* look for the transparent color extension */
|
|
|
|
for (i = 0; i < si->ExtensionBlockCount; ++i) {
|
|
|
|
eb = si->ExtensionBlocks + i;
|
|
|
|
if (eb->Function == 0xF9 && eb->ByteCount == 4) {
|
|
|
|
if ((eb->Bytes[0] & 1) == 1) {
|
2005-03-29 20:57:15 +02:00
|
|
|
transparent = (unsigned char)eb->Bytes[3];
|
2004-05-04 04:53:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-19 13:38:25 +02:00
|
|
|
for (i = 0; i < cm->ColorCount; i++) {
|
2003-01-09 07:04:33 +01:00
|
|
|
bmi->bmiColors[i].rgbRed = cm->Colors[i].Red;
|
|
|
|
bmi->bmiColors[i].rgbGreen = cm->Colors[i].Green;
|
|
|
|
bmi->bmiColors[i].rgbBlue = cm->Colors[i].Blue;
|
2004-05-04 04:53:48 +02:00
|
|
|
if (i == transparent) {
|
|
|
|
This->rgbTrans = RGB(bmi->bmiColors[i].rgbRed,
|
|
|
|
bmi->bmiColors[i].rgbGreen,
|
|
|
|
bmi->bmiColors[i].rgbBlue);
|
|
|
|
}
|
2003-01-09 07:04:33 +01:00
|
|
|
}
|
2004-05-04 04:53:48 +02:00
|
|
|
|
2004-09-16 21:07:42 +02:00
|
|
|
/* Map to in picture coordinates */
|
|
|
|
for (i = 0, j = 0; i < gid->Height; i++) {
|
|
|
|
if (gif->Image.Interlace) {
|
|
|
|
memcpy(
|
|
|
|
bytes + (gid->Top + j) * padding + gid->Left,
|
|
|
|
si->RasterBits + i * gid->Width,
|
|
|
|
gid->Width);
|
|
|
|
|
|
|
|
/* Lower bits of interlaced counter encode current interlace */
|
|
|
|
if (j & 1) j += 2; /* Currently filling odd rows */
|
|
|
|
else if (j & 2) j += 4; /* Currently filling even rows not multiples of 4 */
|
|
|
|
else j += 8; /* Currently filling every 8th row or 4th row in-between */
|
|
|
|
|
|
|
|
if (j >= gid->Height && i < gid->Height && (j & 1) == 0) {
|
|
|
|
/* End of current interlace, go to next interlace */
|
|
|
|
if (j & 2) j = 1; /* Next iteration fills odd rows */
|
|
|
|
else if (j & 4) j = 2; /* Next iteration fills even rows not mod 4 and not mod 8 */
|
|
|
|
else j = 4; /* Next iteration fills rows in-between rows mod 6 */
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
memcpy(
|
|
|
|
bytes + (gid->Top + i) * padding + gid->Left,
|
|
|
|
si->RasterBits + i * gid->Width,
|
|
|
|
gid->Width);
|
|
|
|
}
|
|
|
|
}
|
2004-05-10 21:56:34 +02:00
|
|
|
|
2003-01-09 07:04:33 +01:00
|
|
|
bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
|
|
bmi->bmiHeader.biWidth = gif->SWidth;
|
2004-05-10 21:56:34 +02:00
|
|
|
bmi->bmiHeader.biHeight = -gif->SHeight;
|
2003-01-09 07:04:33 +01:00
|
|
|
bmi->bmiHeader.biPlanes = 1;
|
|
|
|
bmi->bmiHeader.biBitCount = 8;
|
|
|
|
bmi->bmiHeader.biCompression = BI_RGB;
|
2004-05-10 21:56:34 +02:00
|
|
|
bmi->bmiHeader.biSizeImage = padding*gif->SHeight;
|
2003-01-09 07:04:33 +01:00
|
|
|
bmi->bmiHeader.biXPelsPerMeter = 0;
|
|
|
|
bmi->bmiHeader.biYPelsPerMeter = 0;
|
2005-07-19 13:38:25 +02:00
|
|
|
bmi->bmiHeader.biClrUsed = cm->ColorCount;
|
2003-01-09 07:04:33 +01:00
|
|
|
bmi->bmiHeader.biClrImportant = 0;
|
|
|
|
|
|
|
|
hdcref = GetDC(0);
|
|
|
|
This->desc.u.bmp.hbitmap=CreateDIBitmap(
|
|
|
|
hdcref,
|
|
|
|
&bmi->bmiHeader,
|
|
|
|
CBM_INIT,
|
|
|
|
bytes,
|
|
|
|
bmi,
|
2004-05-04 04:53:48 +02:00
|
|
|
DIB_RGB_COLORS
|
2003-01-09 07:04:33 +01:00
|
|
|
);
|
2004-05-04 04:53:48 +02:00
|
|
|
|
|
|
|
if (transparent > -1) {
|
|
|
|
/* Create the Mask */
|
|
|
|
HDC hdc = CreateCompatibleDC(0);
|
|
|
|
HDC hdcMask = CreateCompatibleDC(0);
|
|
|
|
HBITMAP hOldbitmap;
|
|
|
|
HBITMAP hOldbitmapmask;
|
|
|
|
|
2005-04-22 21:05:05 +02:00
|
|
|
unsigned int monopadding = (((unsigned)(gif->SWidth + 31)) >> 5) << 2;
|
|
|
|
HBITMAP hTempMask;
|
|
|
|
|
|
|
|
This->hbmXor = CreateDIBitmap(
|
|
|
|
hdcref,
|
|
|
|
&bmi->bmiHeader,
|
|
|
|
CBM_INIT,
|
|
|
|
bytes,
|
|
|
|
bmi,
|
|
|
|
DIB_RGB_COLORS
|
|
|
|
);
|
|
|
|
|
|
|
|
bmi->bmiColors[0].rgbRed = 0;
|
|
|
|
bmi->bmiColors[0].rgbGreen = 0;
|
|
|
|
bmi->bmiColors[0].rgbBlue = 0;
|
|
|
|
bmi->bmiColors[1].rgbRed = 255;
|
|
|
|
bmi->bmiColors[1].rgbGreen = 255;
|
|
|
|
bmi->bmiColors[1].rgbBlue = 255;
|
|
|
|
|
|
|
|
bmi->bmiHeader.biBitCount = 1;
|
|
|
|
bmi->bmiHeader.biSizeImage = monopadding*gif->SHeight;
|
|
|
|
bmi->bmiHeader.biClrUsed = 2;
|
|
|
|
|
|
|
|
for (i = 0; i < gif->SHeight; i++) {
|
|
|
|
unsigned char * colorPointer = bytes + padding * i;
|
|
|
|
unsigned char * monoPointer = bytes + monopadding * i;
|
|
|
|
for (j = 0; j < gif->SWidth; j++) {
|
|
|
|
unsigned char pixel = colorPointer[j];
|
|
|
|
if ((j & 7) == 0) monoPointer[j >> 3] = 0;
|
|
|
|
if (pixel == (transparent & 0x000000FFU)) monoPointer[j >> 3] |= 1 << (7 - (j & 7));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hdcref = GetDC(0);
|
|
|
|
hTempMask = CreateDIBitmap(
|
|
|
|
hdcref,
|
|
|
|
&bmi->bmiHeader,
|
|
|
|
CBM_INIT,
|
|
|
|
bytes,
|
|
|
|
bmi,
|
|
|
|
DIB_RGB_COLORS
|
|
|
|
);
|
|
|
|
DeleteDC(hdcref);
|
|
|
|
|
|
|
|
bmi->bmiHeader.biHeight = -bmi->bmiHeader.biHeight;
|
|
|
|
This->hbmMask = CreateBitmap(bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight, 1, 1, NULL);
|
|
|
|
hOldbitmap = SelectObject(hdc, hTempMask);
|
2004-05-04 04:53:48 +02:00
|
|
|
hOldbitmapmask = SelectObject(hdcMask, This->hbmMask);
|
2005-04-22 21:05:05 +02:00
|
|
|
|
|
|
|
SetBkColor(hdc, RGB(255, 255, 255));
|
2004-05-04 04:53:48 +02:00
|
|
|
BitBlt(hdcMask, 0, 0, bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight, hdc, 0, 0, SRCCOPY);
|
|
|
|
|
|
|
|
/* We no longer need the original bitmap, so we apply the first
|
|
|
|
transformation with the mask to speed up the rendering */
|
2005-04-22 21:05:05 +02:00
|
|
|
SelectObject(hdc, This->hbmXor);
|
2004-05-04 04:53:48 +02:00
|
|
|
SetBkColor(hdc, RGB(0,0,0));
|
|
|
|
SetTextColor(hdc, RGB(255,255,255));
|
|
|
|
BitBlt(hdc, 0, 0, bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight,
|
|
|
|
hdcMask, 0, 0, SRCAND);
|
|
|
|
|
|
|
|
SelectObject(hdc, hOldbitmap);
|
|
|
|
SelectObject(hdcMask, hOldbitmapmask);
|
|
|
|
DeleteDC(hdcMask);
|
|
|
|
DeleteDC(hdc);
|
2005-04-22 21:05:05 +02:00
|
|
|
DeleteObject(hTempMask);
|
2004-05-04 04:53:48 +02:00
|
|
|
}
|
|
|
|
|
2003-01-09 07:04:33 +01:00
|
|
|
DeleteDC(hdcref);
|
|
|
|
This->desc.picType = PICTYPE_BITMAP;
|
|
|
|
OLEPictureImpl_SetBitmap(This);
|
2006-09-08 05:27:15 +02:00
|
|
|
DGifCloseFile(gif);
|
2008-01-31 15:45:29 +01:00
|
|
|
HeapFree(GetProcessHeap(),0,bmi);
|
2003-01-09 07:04:33 +01:00
|
|
|
HeapFree(GetProcessHeap(),0,bytes);
|
|
|
|
return S_OK;
|
2006-03-05 14:34:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT OLEPictureImpl_LoadJpeg(OLEPictureImpl *This, BYTE *xbuf, ULONG xread)
|
|
|
|
{
|
2007-07-02 19:53:14 +02:00
|
|
|
#ifdef SONAME_LIBJPEG
|
2001-08-06 20:52:14 +02:00
|
|
|
struct jpeg_decompress_struct jd;
|
|
|
|
struct jpeg_error_mgr jerr;
|
|
|
|
int ret;
|
|
|
|
JDIMENSION x;
|
2003-05-08 19:35:12 +02:00
|
|
|
JSAMPROW samprow,oldsamprow;
|
2001-08-06 20:52:14 +02:00
|
|
|
BITMAPINFOHEADER bmi;
|
|
|
|
LPBYTE bits;
|
|
|
|
HDC hdcref;
|
|
|
|
struct jpeg_source_mgr xjsm;
|
2003-05-08 19:35:12 +02:00
|
|
|
LPBYTE oldbits;
|
2004-09-22 04:46:38 +02:00
|
|
|
unsigned int i;
|
2001-08-06 20:52:14 +02:00
|
|
|
|
2004-08-04 21:10:26 +02:00
|
|
|
if(!libjpeg_handle) {
|
|
|
|
if(!load_libjpeg()) {
|
2008-10-16 11:20:45 +02:00
|
|
|
ERR("Failed reading JPEG because unable to find %s\n", SONAME_LIBJPEG);
|
2004-08-04 21:10:26 +02:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-06 20:52:14 +02:00
|
|
|
/* This is basically so we can use in-memory data for jpeg decompression.
|
|
|
|
* We need to have all the functions.
|
|
|
|
*/
|
|
|
|
xjsm.next_input_byte = xbuf;
|
|
|
|
xjsm.bytes_in_buffer = xread;
|
|
|
|
xjsm.init_source = _jpeg_init_source;
|
|
|
|
xjsm.fill_input_buffer = _jpeg_fill_input_buffer;
|
|
|
|
xjsm.skip_input_data = _jpeg_skip_input_data;
|
|
|
|
xjsm.resync_to_restart = _jpeg_resync_to_restart;
|
|
|
|
xjsm.term_source = _jpeg_term_source;
|
|
|
|
|
2004-08-04 21:10:26 +02:00
|
|
|
jd.err = pjpeg_std_error(&jerr);
|
|
|
|
/* jpeg_create_decompress is a macro that expands to jpeg_CreateDecompress - see jpeglib.h
|
|
|
|
* jpeg_create_decompress(&jd); */
|
2008-01-15 22:49:14 +01:00
|
|
|
pjpeg_CreateDecompress(&jd, JPEG_LIB_VERSION, sizeof(struct jpeg_decompress_struct));
|
2001-08-06 20:52:14 +02:00
|
|
|
jd.src = &xjsm;
|
2004-08-04 21:10:26 +02:00
|
|
|
ret=pjpeg_read_header(&jd,TRUE);
|
2003-05-08 19:35:12 +02:00
|
|
|
jd.out_color_space = JCS_RGB;
|
2004-08-04 21:10:26 +02:00
|
|
|
pjpeg_start_decompress(&jd);
|
2001-08-06 20:52:14 +02:00
|
|
|
if (ret != JPEG_HEADER_OK) {
|
|
|
|
ERR("Jpeg image in stream has bad format, read header returned %d.\n",ret);
|
|
|
|
HeapFree(GetProcessHeap(),0,xbuf);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2003-05-08 19:35:12 +02:00
|
|
|
|
|
|
|
bits = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
|
|
|
|
(jd.output_height+1) * ((jd.output_width*jd.output_components + 3) & ~3) );
|
2001-08-06 20:52:14 +02:00
|
|
|
samprow=HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,jd.output_width*jd.output_components);
|
2003-05-08 19:35:12 +02:00
|
|
|
|
|
|
|
oldbits = bits;
|
|
|
|
oldsamprow = samprow;
|
2001-08-06 20:52:14 +02:00
|
|
|
while ( jd.output_scanline<jd.output_height ) {
|
2004-08-04 21:10:26 +02:00
|
|
|
x = pjpeg_read_scanlines(&jd,&samprow,1);
|
2001-08-06 20:52:14 +02:00
|
|
|
if (x != 1) {
|
2008-10-16 11:20:45 +02:00
|
|
|
ERR("failed to read current scanline?\n");
|
2001-08-06 20:52:14 +02:00
|
|
|
break;
|
|
|
|
}
|
2003-05-08 19:35:12 +02:00
|
|
|
/* We have to convert from RGB to BGR, see MSDN/ BITMAPINFOHEADER */
|
|
|
|
for(i=0;i<jd.output_width;i++,samprow+=jd.output_components) {
|
|
|
|
*(bits++) = *(samprow+2);
|
|
|
|
*(bits++) = *(samprow+1);
|
|
|
|
*(bits++) = *(samprow);
|
|
|
|
}
|
|
|
|
bits = (LPBYTE)(((UINT_PTR)bits + 3) & ~3);
|
|
|
|
samprow = oldsamprow;
|
2001-08-06 20:52:14 +02:00
|
|
|
}
|
2003-05-08 19:35:12 +02:00
|
|
|
bits = oldbits;
|
|
|
|
|
2001-08-06 20:52:14 +02:00
|
|
|
bmi.biSize = sizeof(bmi);
|
|
|
|
bmi.biWidth = jd.output_width;
|
|
|
|
bmi.biHeight = -jd.output_height;
|
|
|
|
bmi.biPlanes = 1;
|
|
|
|
bmi.biBitCount = jd.output_components<<3;
|
|
|
|
bmi.biCompression = BI_RGB;
|
|
|
|
bmi.biSizeImage = jd.output_height*jd.output_width*jd.output_components;
|
|
|
|
bmi.biXPelsPerMeter = 0;
|
|
|
|
bmi.biYPelsPerMeter = 0;
|
|
|
|
bmi.biClrUsed = 0;
|
|
|
|
bmi.biClrImportant = 0;
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(),0,samprow);
|
2004-08-04 21:10:26 +02:00
|
|
|
pjpeg_finish_decompress(&jd);
|
|
|
|
pjpeg_destroy_decompress(&jd);
|
2001-08-20 20:00:10 +02:00
|
|
|
hdcref = GetDC(0);
|
2001-08-06 20:52:14 +02:00
|
|
|
This->desc.u.bmp.hbitmap=CreateDIBitmap(
|
|
|
|
hdcref,
|
|
|
|
&bmi,
|
|
|
|
CBM_INIT,
|
|
|
|
bits,
|
|
|
|
(BITMAPINFO*)&bmi,
|
|
|
|
DIB_RGB_COLORS
|
|
|
|
);
|
|
|
|
DeleteDC(hdcref);
|
|
|
|
This->desc.picType = PICTYPE_BITMAP;
|
|
|
|
OLEPictureImpl_SetBitmap(This);
|
|
|
|
HeapFree(GetProcessHeap(),0,bits);
|
2006-03-05 14:34:31 +01:00
|
|
|
return S_OK;
|
2001-08-06 20:52:14 +02:00
|
|
|
#else
|
|
|
|
ERR("Trying to load JPEG picture, but JPEG supported not compiled in.\n");
|
2006-03-05 14:34:31 +01:00
|
|
|
return E_FAIL;
|
2001-08-06 20:52:14 +02:00
|
|
|
#endif
|
2006-03-05 14:34:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT OLEPictureImpl_LoadDIB(OLEPictureImpl *This, BYTE *xbuf, ULONG xread)
|
|
|
|
{
|
2001-08-06 20:52:14 +02:00
|
|
|
BITMAPFILEHEADER *bfh = (BITMAPFILEHEADER*)xbuf;
|
|
|
|
BITMAPINFO *bi = (BITMAPINFO*)(bfh+1);
|
|
|
|
HDC hdcref;
|
|
|
|
|
|
|
|
/* Does not matter whether this is a coreheader or not, we only use
|
|
|
|
* components which are in both
|
|
|
|
*/
|
2001-08-20 20:00:10 +02:00
|
|
|
hdcref = GetDC(0);
|
2001-08-06 20:52:14 +02:00
|
|
|
This->desc.u.bmp.hbitmap = CreateDIBitmap(
|
|
|
|
hdcref,
|
|
|
|
&(bi->bmiHeader),
|
|
|
|
CBM_INIT,
|
|
|
|
xbuf+bfh->bfOffBits,
|
|
|
|
bi,
|
2004-11-09 21:02:25 +01:00
|
|
|
DIB_RGB_COLORS
|
2001-08-06 20:52:14 +02:00
|
|
|
);
|
|
|
|
DeleteDC(hdcref);
|
2008-07-19 00:25:31 +02:00
|
|
|
if (This->desc.u.bmp.hbitmap == 0)
|
|
|
|
return E_FAIL;
|
2001-08-06 20:52:14 +02:00
|
|
|
This->desc.picType = PICTYPE_BITMAP;
|
|
|
|
OLEPictureImpl_SetBitmap(This);
|
2006-03-05 14:34:31 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2007-06-19 22:12:57 +02:00
|
|
|
/*****************************************************
|
|
|
|
* start of PNG-specific code
|
|
|
|
* currently only supports colortype PNG_COLOR_TYPE_RGB
|
|
|
|
*/
|
|
|
|
#ifdef SONAME_LIBPNG
|
|
|
|
typedef struct{
|
|
|
|
ULONG position;
|
|
|
|
ULONG size;
|
|
|
|
BYTE * buff;
|
|
|
|
} png_io;
|
|
|
|
|
|
|
|
static void png_stream_read_data(png_structp png_ptr, png_bytep data,
|
|
|
|
png_size_t length)
|
|
|
|
{
|
|
|
|
png_io * io_ptr = png_ptr->io_ptr;
|
|
|
|
|
|
|
|
if(length + io_ptr->position > io_ptr->size){
|
|
|
|
length = io_ptr->size - io_ptr->position;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(data, io_ptr->buff + io_ptr->position, length);
|
|
|
|
|
|
|
|
io_ptr->position += length;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *libpng_handle;
|
|
|
|
#define MAKE_FUNCPTR(f) static typeof(f) * p##f
|
|
|
|
MAKE_FUNCPTR(png_create_read_struct);
|
|
|
|
MAKE_FUNCPTR(png_create_info_struct);
|
|
|
|
MAKE_FUNCPTR(png_set_read_fn);
|
|
|
|
MAKE_FUNCPTR(png_read_info);
|
|
|
|
MAKE_FUNCPTR(png_read_image);
|
|
|
|
MAKE_FUNCPTR(png_get_rowbytes);
|
|
|
|
MAKE_FUNCPTR(png_set_bgr);
|
|
|
|
MAKE_FUNCPTR(png_destroy_read_struct);
|
|
|
|
MAKE_FUNCPTR(png_set_palette_to_rgb);
|
|
|
|
MAKE_FUNCPTR(png_read_update_info);
|
2007-08-09 04:42:33 +02:00
|
|
|
MAKE_FUNCPTR(png_get_tRNS);
|
|
|
|
MAKE_FUNCPTR(png_get_PLTE);
|
|
|
|
MAKE_FUNCPTR(png_set_expand);
|
2007-06-19 22:12:57 +02:00
|
|
|
#undef MAKE_FUNCPTR
|
|
|
|
|
|
|
|
static void *load_libpng(void)
|
|
|
|
{
|
|
|
|
if((libpng_handle = wine_dlopen(SONAME_LIBPNG, RTLD_NOW, NULL, 0)) != NULL) {
|
|
|
|
|
|
|
|
#define LOAD_FUNCPTR(f) \
|
|
|
|
if((p##f = wine_dlsym(libpng_handle, #f, NULL, 0)) == NULL) { \
|
|
|
|
libpng_handle = NULL; \
|
|
|
|
return NULL; \
|
|
|
|
}
|
|
|
|
LOAD_FUNCPTR(png_create_read_struct);
|
|
|
|
LOAD_FUNCPTR(png_create_info_struct);
|
|
|
|
LOAD_FUNCPTR(png_set_read_fn);
|
|
|
|
LOAD_FUNCPTR(png_read_info);
|
|
|
|
LOAD_FUNCPTR(png_read_image);
|
|
|
|
LOAD_FUNCPTR(png_get_rowbytes);
|
|
|
|
LOAD_FUNCPTR(png_set_bgr);
|
|
|
|
LOAD_FUNCPTR(png_destroy_read_struct);
|
|
|
|
LOAD_FUNCPTR(png_set_palette_to_rgb);
|
|
|
|
LOAD_FUNCPTR(png_read_update_info);
|
2007-08-09 04:42:33 +02:00
|
|
|
LOAD_FUNCPTR(png_get_tRNS);
|
|
|
|
LOAD_FUNCPTR(png_get_PLTE);
|
|
|
|
LOAD_FUNCPTR(png_set_expand);
|
2007-06-19 22:12:57 +02:00
|
|
|
|
|
|
|
#undef LOAD_FUNCPTR
|
|
|
|
}
|
|
|
|
return libpng_handle;
|
|
|
|
}
|
|
|
|
#endif /* SONAME_LIBPNG */
|
|
|
|
|
|
|
|
static HRESULT OLEPictureImpl_LoadPNG(OLEPictureImpl *This, BYTE *xbuf, ULONG xread)
|
|
|
|
{
|
|
|
|
#ifdef SONAME_LIBPNG
|
|
|
|
png_io io;
|
|
|
|
png_structp png_ptr = NULL;
|
|
|
|
png_infop info_ptr = NULL;
|
2007-08-09 04:42:33 +02:00
|
|
|
INT row, rowsize, height, width, num_trans, i, j;
|
2007-06-19 22:12:57 +02:00
|
|
|
png_bytep* row_pointers = NULL;
|
|
|
|
png_bytep pngdata = NULL;
|
|
|
|
BITMAPINFOHEADER bmi;
|
2007-08-09 04:42:33 +02:00
|
|
|
HDC hdcref = NULL, hdcXor, hdcMask;
|
2007-06-19 22:12:57 +02:00
|
|
|
HRESULT ret;
|
2007-08-09 04:42:33 +02:00
|
|
|
BOOL transparency;
|
|
|
|
png_bytep trans;
|
|
|
|
png_color_16p trans_values;
|
|
|
|
COLORREF white = RGB(255, 255, 255), black = RGB(0, 0, 0);
|
|
|
|
HBITMAP hbmoldXor, hbmoldMask, temp;
|
2007-06-19 22:12:57 +02:00
|
|
|
|
|
|
|
if(!libpng_handle) {
|
|
|
|
if(!load_libpng()) {
|
|
|
|
ERR("Failed reading PNG because unable to find %s\n",SONAME_LIBPNG);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
io.size = xread;
|
|
|
|
io.position = 0;
|
|
|
|
io.buff = xbuf;
|
|
|
|
|
|
|
|
png_ptr = ppng_create_read_struct(PNG_LIBPNG_VER_STRING,
|
|
|
|
NULL, NULL, NULL);
|
|
|
|
|
|
|
|
if(setjmp(png_jmpbuf(png_ptr))){
|
|
|
|
TRACE("Error in libpng\n");
|
|
|
|
ret = E_FAIL;
|
2007-08-09 04:42:33 +02:00
|
|
|
goto end;
|
2007-06-19 22:12:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
info_ptr = ppng_create_info_struct(png_ptr);
|
|
|
|
ppng_set_read_fn(png_ptr, &io, png_stream_read_data);
|
|
|
|
ppng_read_info(png_ptr, info_ptr);
|
|
|
|
|
|
|
|
if(!(png_ptr->color_type == PNG_COLOR_TYPE_RGB ||
|
2007-08-04 02:30:11 +02:00
|
|
|
png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
|
|
|
|
png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)){
|
2007-06-19 22:12:57 +02:00
|
|
|
FIXME("Unsupported .PNG type: %d\n", png_ptr->color_type);
|
|
|
|
ret = E_FAIL;
|
2007-08-09 04:42:33 +02:00
|
|
|
goto end;
|
2007-06-19 22:12:57 +02:00
|
|
|
}
|
|
|
|
|
2007-08-09 04:42:33 +02:00
|
|
|
transparency = (ppng_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, &trans_values)
|
|
|
|
== PNG_INFO_tRNS);
|
2007-06-19 22:12:57 +02:00
|
|
|
|
2007-08-09 04:42:33 +02:00
|
|
|
/* sets format from anything to RGBA */
|
|
|
|
ppng_set_expand(png_ptr);
|
|
|
|
/* sets format to BGRA */
|
|
|
|
ppng_set_bgr(png_ptr);
|
2007-06-19 22:12:57 +02:00
|
|
|
|
|
|
|
ppng_read_update_info(png_ptr, info_ptr);
|
|
|
|
|
|
|
|
rowsize = ppng_get_rowbytes(png_ptr, info_ptr);
|
|
|
|
/* align rowsize to 4-byte boundary */
|
|
|
|
rowsize = (rowsize + 3) & ~3;
|
|
|
|
height = info_ptr->height;
|
|
|
|
width = info_ptr->width;
|
|
|
|
|
|
|
|
pngdata = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, height * rowsize);
|
|
|
|
row_pointers = HeapAlloc(GetProcessHeap(), 0, height * (sizeof(VOID *)));
|
|
|
|
|
|
|
|
if(!pngdata || !row_pointers){
|
|
|
|
ret = E_FAIL;
|
2007-08-09 04:42:33 +02:00
|
|
|
goto end;
|
2007-06-19 22:12:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (row = 0; row < height; row++){
|
|
|
|
row_pointers[row] = pngdata + row * rowsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
ppng_read_image(png_ptr, row_pointers);
|
|
|
|
|
|
|
|
bmi.biSize = sizeof(bmi);
|
|
|
|
bmi.biWidth = width;
|
|
|
|
bmi.biHeight = -height;
|
|
|
|
bmi.biPlanes = 1;
|
|
|
|
bmi.biBitCount = info_ptr->channels * 8;
|
|
|
|
bmi.biCompression = BI_RGB;
|
|
|
|
bmi.biSizeImage = height * rowsize;
|
|
|
|
bmi.biXPelsPerMeter = 0;
|
|
|
|
bmi.biYPelsPerMeter = 0;
|
|
|
|
bmi.biClrUsed = 0;
|
|
|
|
bmi.biClrImportant = 0;
|
|
|
|
|
|
|
|
hdcref = GetDC(0);
|
|
|
|
This->desc.u.bmp.hbitmap = CreateDIBitmap(
|
|
|
|
hdcref,
|
|
|
|
&bmi,
|
|
|
|
CBM_INIT,
|
|
|
|
pngdata,
|
|
|
|
(BITMAPINFO*)&bmi,
|
|
|
|
DIB_RGB_COLORS
|
|
|
|
);
|
2007-08-09 04:42:33 +02:00
|
|
|
|
|
|
|
/* only fully-transparent alpha is handled */
|
|
|
|
if((info_ptr->channels != 4) || !transparency){
|
|
|
|
ReleaseDC(0, hdcref);
|
|
|
|
goto succ;
|
|
|
|
}
|
|
|
|
|
|
|
|
This->hbmXor = CreateDIBitmap(
|
|
|
|
hdcref,
|
|
|
|
&bmi,
|
|
|
|
CBM_INIT,
|
|
|
|
pngdata,
|
|
|
|
(BITMAPINFO*)&bmi,
|
|
|
|
DIB_RGB_COLORS
|
|
|
|
);
|
|
|
|
|
|
|
|
/* set transparent pixels to black, all others to white */
|
|
|
|
for(i = 0; i < height; i++){
|
|
|
|
for(j = 3; j < rowsize; j += 4){
|
|
|
|
if(row_pointers[i][j] == 0)
|
|
|
|
*((DWORD*)(&row_pointers[i][j - 3])) = black;
|
|
|
|
else
|
|
|
|
*((DWORD*)(&row_pointers[i][j - 3])) = white;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
temp = CreateDIBitmap(
|
|
|
|
hdcref,
|
|
|
|
&bmi,
|
|
|
|
CBM_INIT,
|
|
|
|
pngdata,
|
|
|
|
(BITMAPINFO*)&bmi,
|
|
|
|
DIB_RGB_COLORS
|
|
|
|
);
|
|
|
|
|
2007-06-19 22:12:57 +02:00
|
|
|
ReleaseDC(0, hdcref);
|
2007-08-09 04:42:33 +02:00
|
|
|
|
|
|
|
This->hbmMask = CreateBitmap(width,-height,1,1,NULL);
|
|
|
|
hdcXor = CreateCompatibleDC(NULL);
|
|
|
|
hdcMask = CreateCompatibleDC(NULL);
|
|
|
|
|
|
|
|
hbmoldXor = SelectObject(hdcXor,temp);
|
|
|
|
hbmoldMask = SelectObject(hdcMask,This->hbmMask);
|
|
|
|
SetBkColor(hdcXor,black);
|
|
|
|
BitBlt(hdcMask,0,0,width,height,hdcXor,0,0,SRCCOPY);
|
|
|
|
|
|
|
|
SelectObject(hdcXor,This->hbmXor);
|
|
|
|
DeleteObject(temp);
|
|
|
|
|
|
|
|
SetTextColor(hdcXor,white);
|
|
|
|
SetBkColor(hdcXor,black);
|
|
|
|
BitBlt(hdcXor,0,0,width,height,hdcMask,0,0,SRCAND);
|
|
|
|
|
|
|
|
SelectObject(hdcXor,hbmoldXor);
|
|
|
|
SelectObject(hdcMask,hbmoldMask);
|
|
|
|
|
|
|
|
DeleteDC(hdcXor);
|
|
|
|
DeleteDC(hdcMask);
|
|
|
|
|
|
|
|
succ:
|
2007-06-19 22:12:57 +02:00
|
|
|
This->desc.picType = PICTYPE_BITMAP;
|
|
|
|
OLEPictureImpl_SetBitmap(This);
|
|
|
|
ret = S_OK;
|
|
|
|
|
2007-08-09 04:42:33 +02:00
|
|
|
end:
|
2007-06-19 22:12:57 +02:00
|
|
|
if(png_ptr)
|
2008-11-02 00:21:15 +01:00
|
|
|
ppng_destroy_read_struct(&png_ptr, info_ptr ? &info_ptr : NULL, NULL);
|
2007-06-19 22:12:57 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, row_pointers);
|
|
|
|
HeapFree(GetProcessHeap(), 0, pngdata);
|
|
|
|
return ret;
|
|
|
|
#else /* SONAME_LIBPNG */
|
|
|
|
ERR("Trying to load PNG picture, but PNG supported not compiled in.\n");
|
|
|
|
return E_FAIL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************
|
|
|
|
* start of Icon-specific code
|
|
|
|
*/
|
|
|
|
|
2006-03-05 14:34:31 +01:00
|
|
|
static HRESULT OLEPictureImpl_LoadIcon(OLEPictureImpl *This, BYTE *xbuf, ULONG xread)
|
|
|
|
{
|
2001-08-06 20:52:14 +02:00
|
|
|
HICON hicon;
|
|
|
|
CURSORICONFILEDIR *cifd = (CURSORICONFILEDIR*)xbuf;
|
2004-08-18 02:26:44 +02:00
|
|
|
HDC hdcRef;
|
2001-08-06 20:52:14 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
FIXME("icon.idReserved=%d\n",cifd->idReserved);
|
|
|
|
FIXME("icon.idType=%d\n",cifd->idType);
|
|
|
|
FIXME("icon.idCount=%d\n",cifd->idCount);
|
|
|
|
|
|
|
|
for (i=0;i<cifd->idCount;i++) {
|
|
|
|
FIXME("[%d] width %d\n",i,cifd->idEntries[i].bWidth);
|
|
|
|
FIXME("[%d] height %d\n",i,cifd->idEntries[i].bHeight);
|
|
|
|
FIXME("[%d] bColorCount %d\n",i,cifd->idEntries[i].bColorCount);
|
|
|
|
FIXME("[%d] bReserved %d\n",i,cifd->idEntries[i].bReserved);
|
|
|
|
FIXME("[%d] xHotspot %d\n",i,cifd->idEntries[i].xHotspot);
|
|
|
|
FIXME("[%d] yHotspot %d\n",i,cifd->idEntries[i].yHotspot);
|
|
|
|
FIXME("[%d] dwDIBSize %d\n",i,cifd->idEntries[i].dwDIBSize);
|
|
|
|
FIXME("[%d] dwDIBOffset %d\n",i,cifd->idEntries[i].dwDIBOffset);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
i=0;
|
|
|
|
/* If we have more than one icon, try to find the best.
|
|
|
|
* this currently means '32 pixel wide'.
|
|
|
|
*/
|
|
|
|
if (cifd->idCount!=1) {
|
|
|
|
for (i=0;i<cifd->idCount;i++) {
|
|
|
|
if (cifd->idEntries[i].bWidth == 32)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i==cifd->idCount) i=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
hicon = CreateIconFromResourceEx(
|
|
|
|
xbuf+cifd->idEntries[i].dwDIBOffset,
|
|
|
|
cifd->idEntries[i].dwDIBSize,
|
|
|
|
TRUE, /* is icon */
|
|
|
|
0x00030000,
|
|
|
|
cifd->idEntries[i].bWidth,
|
|
|
|
cifd->idEntries[i].bHeight,
|
|
|
|
0
|
|
|
|
);
|
|
|
|
if (!hicon) {
|
2008-10-16 11:20:45 +02:00
|
|
|
ERR("CreateIcon failed.\n");
|
2006-03-05 14:34:31 +01:00
|
|
|
return E_FAIL;
|
2001-08-06 20:52:14 +02:00
|
|
|
} else {
|
|
|
|
This->desc.picType = PICTYPE_ICON;
|
|
|
|
This->desc.u.icon.hicon = hicon;
|
2004-08-18 02:26:44 +02:00
|
|
|
This->origWidth = cifd->idEntries[i].bWidth;
|
|
|
|
This->origHeight = cifd->idEntries[i].bHeight;
|
|
|
|
hdcRef = CreateCompatibleDC(0);
|
|
|
|
This->himetricWidth =(cifd->idEntries[i].bWidth *2540)/GetDeviceCaps(hdcRef, LOGPIXELSX);
|
|
|
|
This->himetricHeight=(cifd->idEntries[i].bHeight*2540)/GetDeviceCaps(hdcRef, LOGPIXELSY);
|
|
|
|
DeleteDC(hdcRef);
|
2006-03-05 14:34:31 +01:00
|
|
|
return S_OK;
|
2001-08-06 20:52:14 +02:00
|
|
|
}
|
2006-03-05 14:34:31 +01:00
|
|
|
}
|
|
|
|
|
2008-10-04 01:24:37 +02:00
|
|
|
static HRESULT OLEPictureImpl_LoadEnhMetafile(OLEPictureImpl *This,
|
|
|
|
const BYTE *data, ULONG size)
|
2007-05-28 09:22:46 +02:00
|
|
|
{
|
|
|
|
HENHMETAFILE hemf;
|
2008-10-04 01:24:37 +02:00
|
|
|
ENHMETAHEADER hdr;
|
2007-05-28 09:22:46 +02:00
|
|
|
|
|
|
|
hemf = SetEnhMetaFileBits(size, data);
|
|
|
|
if (!hemf) return E_FAIL;
|
|
|
|
|
2008-10-04 01:24:37 +02:00
|
|
|
GetEnhMetaFileHeader(hemf, sizeof(hdr), &hdr);
|
|
|
|
|
2007-05-28 09:22:46 +02:00
|
|
|
This->desc.picType = PICTYPE_ENHMETAFILE;
|
|
|
|
This->desc.u.emf.hemf = hemf;
|
|
|
|
|
|
|
|
This->origWidth = 0;
|
|
|
|
This->origHeight = 0;
|
2008-10-04 01:24:37 +02:00
|
|
|
This->himetricWidth = hdr.rclFrame.right - hdr.rclFrame.left;
|
|
|
|
This->himetricHeight = hdr.rclFrame.bottom - hdr.rclFrame.top;
|
2007-05-28 09:22:46 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2007-10-04 01:56:53 +02:00
|
|
|
static HRESULT OLEPictureImpl_LoadAPM(OLEPictureImpl *This,
|
|
|
|
const BYTE *data, ULONG size)
|
|
|
|
{
|
|
|
|
APM_HEADER *header = (APM_HEADER *)data;
|
2008-10-04 01:24:37 +02:00
|
|
|
HMETAFILE hmf;
|
2007-10-04 01:56:53 +02:00
|
|
|
|
|
|
|
if (size < sizeof(APM_HEADER))
|
|
|
|
return E_FAIL;
|
|
|
|
if (header->key != 0x9ac6cdd7)
|
|
|
|
return E_FAIL;
|
|
|
|
|
2008-10-04 01:24:37 +02:00
|
|
|
/* SetMetaFileBitsEx performs data check on its own */
|
|
|
|
hmf = SetMetaFileBitsEx(size - sizeof(*header), data + sizeof(*header));
|
|
|
|
if (!hmf) return E_FAIL;
|
2007-10-04 01:56:53 +02:00
|
|
|
|
2008-10-04 01:24:37 +02:00
|
|
|
This->desc.picType = PICTYPE_METAFILE;
|
|
|
|
This->desc.u.wmf.hmeta = hmf;
|
|
|
|
This->desc.u.wmf.xExt = 0;
|
|
|
|
This->desc.u.wmf.yExt = 0;
|
|
|
|
|
|
|
|
This->origWidth = 0;
|
|
|
|
This->origHeight = 0;
|
2007-10-04 01:56:53 +02:00
|
|
|
This->himetricWidth = MulDiv((INT)header->right - header->left, 2540, header->inch);
|
|
|
|
This->himetricHeight = MulDiv((INT)header->bottom - header->top, 2540, header->inch);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-03-06 09:16:55 +01:00
|
|
|
/************************************************************************
|
|
|
|
* BITMAP FORMAT FLAGS -
|
|
|
|
* Flags that differentiate between different types of bitmaps.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define BITMAP_FORMAT_BMP 0x4d42 /* "BM" */
|
|
|
|
#define BITMAP_FORMAT_JPEG 0xd8ff
|
|
|
|
#define BITMAP_FORMAT_GIF 0x4947
|
|
|
|
#define BITMAP_FORMAT_PNG 0x5089
|
|
|
|
#define BITMAP_FORMAT_APM 0xcdd7
|
|
|
|
|
2006-03-05 14:34:31 +01:00
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_IPersistStream_Load (IUnknown)
|
|
|
|
*
|
|
|
|
* Loads the binary data from the IStream. Starts at current position.
|
|
|
|
* There appears to be an 2 DWORD header:
|
|
|
|
* DWORD magic;
|
|
|
|
* DWORD len;
|
|
|
|
*
|
2007-05-28 09:22:46 +02:00
|
|
|
* Currently implemented: BITMAP, ICON, JPEG, GIF, WMF, EMF
|
2006-03-05 14:34:31 +01:00
|
|
|
*/
|
|
|
|
static HRESULT WINAPI OLEPictureImpl_Load(IPersistStream* iface,IStream*pStm) {
|
|
|
|
HRESULT hr = E_FAIL;
|
|
|
|
BOOL headerisdata = FALSE;
|
|
|
|
BOOL statfailed = FALSE;
|
|
|
|
ULONG xread, toread;
|
2006-11-06 22:47:25 +01:00
|
|
|
ULONG headerread;
|
2006-03-05 14:34:31 +01:00
|
|
|
BYTE *xbuf;
|
|
|
|
DWORD header[2];
|
|
|
|
WORD magic;
|
|
|
|
STATSTG statstg;
|
|
|
|
OLEPictureImpl *This = impl_from_IPersistStream(iface);
|
|
|
|
|
|
|
|
TRACE("(%p,%p)\n",This,pStm);
|
|
|
|
|
|
|
|
/****************************************************************************************
|
|
|
|
* Part 1: Load the data
|
|
|
|
*/
|
|
|
|
/* Sometimes we have a header, sometimes we don't. Apply some guesses to find
|
|
|
|
* out whether we do.
|
|
|
|
*
|
|
|
|
* UPDATE: the IStream can be mapped to a plain file instead of a stream in a
|
|
|
|
* compound file. This may explain most, if not all, of the cases of "no
|
|
|
|
* header", and the header validation should take this into account.
|
|
|
|
* At least in Visual Basic 6, resource streams, valid headers are
|
|
|
|
* header[0] == "lt\0\0",
|
|
|
|
* header[1] == length_of_stream.
|
|
|
|
*
|
|
|
|
* Also handle streams where we do not have a working "Stat" method by
|
|
|
|
* reading all data until the end of the stream.
|
|
|
|
*/
|
|
|
|
hr=IStream_Stat(pStm,&statstg,STATFLAG_NONAME);
|
|
|
|
if (hr) {
|
2006-10-12 20:57:10 +02:00
|
|
|
TRACE("stat failed with hres %x, proceeding to read all data.\n",hr);
|
2006-03-05 14:34:31 +01:00
|
|
|
statfailed = TRUE;
|
|
|
|
/* we will read at least 8 byte ... just right below */
|
|
|
|
statstg.cbSize.QuadPart = 8;
|
|
|
|
}
|
|
|
|
|
2006-11-06 22:47:25 +01:00
|
|
|
toread = 0;
|
|
|
|
headerread = 0;
|
2006-03-05 14:34:31 +01:00
|
|
|
headerisdata = FALSE;
|
2006-11-06 22:47:25 +01:00
|
|
|
do {
|
|
|
|
hr=IStream_Read(pStm,header,8,&xread);
|
|
|
|
if (hr || xread!=8) {
|
2008-10-16 11:20:45 +02:00
|
|
|
ERR("Failure while reading picture header (hr is %x, nread is %d).\n",hr,xread);
|
2008-10-16 11:20:54 +02:00
|
|
|
return (hr?hr:E_FAIL);
|
2006-11-06 22:47:25 +01:00
|
|
|
}
|
|
|
|
headerread += xread;
|
|
|
|
xread = 0;
|
|
|
|
|
|
|
|
if (!memcmp(&(header[0]),"lt\0\0", 4) && (statfailed || (header[1] + headerread <= statstg.cbSize.QuadPart))) {
|
|
|
|
if (toread != 0 && toread != header[1])
|
|
|
|
FIXME("varying lengths of image data (prev=%u curr=%u), only last one will be used\n",
|
|
|
|
toread, header[1]);
|
2006-03-05 14:34:31 +01:00
|
|
|
toread = header[1];
|
2006-11-06 22:47:25 +01:00
|
|
|
if (toread == 0) break;
|
|
|
|
} else {
|
|
|
|
if (!memcmp(&(header[0]), "GIF8", 4) || /* GIF header */
|
|
|
|
!memcmp(&(header[0]), "BM", 2) || /* BMP header */
|
|
|
|
!memcmp(&(header[0]), "\xff\xd8", 2) || /* JPEG header */
|
2007-07-31 04:09:33 +02:00
|
|
|
(header[0] == EMR_HEADER) || /* EMF header */
|
2006-11-06 22:47:25 +01:00
|
|
|
(header[1] > statstg.cbSize.QuadPart)|| /* invalid size */
|
|
|
|
(header[1]==0)
|
|
|
|
) {/* Found start of bitmap data */
|
|
|
|
headerisdata = TRUE;
|
|
|
|
if (toread == 0)
|
|
|
|
toread = statstg.cbSize.QuadPart-8;
|
|
|
|
else toread -= 8;
|
|
|
|
xread = 8;
|
|
|
|
} else {
|
|
|
|
FIXME("Unknown stream header magic: %08x\n", header[0]);
|
|
|
|
toread = header[1];
|
|
|
|
}
|
2006-03-05 14:34:31 +01:00
|
|
|
}
|
2006-11-06 22:47:25 +01:00
|
|
|
} while (!headerisdata);
|
2006-03-05 14:34:31 +01:00
|
|
|
|
|
|
|
if (statfailed) { /* we don't know the size ... read all we get */
|
|
|
|
int sizeinc = 4096;
|
|
|
|
int origsize = sizeinc;
|
|
|
|
ULONG nread = 42;
|
|
|
|
|
|
|
|
TRACE("Reading all data from stream.\n");
|
|
|
|
xbuf = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, origsize);
|
|
|
|
if (headerisdata)
|
2008-07-11 11:41:47 +02:00
|
|
|
memcpy (xbuf, header, 8);
|
2006-03-05 14:34:31 +01:00
|
|
|
while (1) {
|
|
|
|
while (xread < origsize) {
|
|
|
|
hr = IStream_Read(pStm,xbuf+xread,origsize-xread,&nread);
|
|
|
|
xread+=nread;
|
|
|
|
if (hr || !nread)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!nread || hr) /* done, or error */
|
|
|
|
break;
|
|
|
|
if (xread == origsize) {
|
|
|
|
origsize += sizeinc;
|
|
|
|
sizeinc = 2*sizeinc; /* exponential increase */
|
|
|
|
xbuf = HeapReAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, xbuf, origsize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hr)
|
2006-10-12 20:57:10 +02:00
|
|
|
TRACE("hr in no-stat loader case is %08x\n", hr);
|
|
|
|
TRACE("loaded %d bytes.\n", xread);
|
2006-03-05 14:34:31 +01:00
|
|
|
This->datalen = xread;
|
|
|
|
This->data = xbuf;
|
|
|
|
} else {
|
|
|
|
This->datalen = toread+(headerisdata?8:0);
|
|
|
|
xbuf = This->data = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, This->datalen);
|
2008-07-19 00:25:31 +02:00
|
|
|
if (!xbuf)
|
|
|
|
return E_OUTOFMEMORY;
|
2006-03-05 14:34:31 +01:00
|
|
|
|
|
|
|
if (headerisdata)
|
2008-07-11 11:41:47 +02:00
|
|
|
memcpy (xbuf, header, 8);
|
2006-03-05 14:34:31 +01:00
|
|
|
|
|
|
|
while (xread < This->datalen) {
|
|
|
|
ULONG nread;
|
|
|
|
hr = IStream_Read(pStm,xbuf+xread,This->datalen-xread,&nread);
|
|
|
|
xread+=nread;
|
|
|
|
if (hr || !nread)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (xread != This->datalen)
|
2008-10-16 11:20:45 +02:00
|
|
|
ERR("Could only read %d of %d bytes out of stream?\n",xread,This->datalen);
|
2006-03-05 14:34:31 +01:00
|
|
|
}
|
|
|
|
if (This->datalen == 0) { /* Marks the "NONE" picture */
|
|
|
|
This->desc.picType = PICTYPE_NONE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************************
|
|
|
|
* Part 2: Process the loaded data
|
|
|
|
*/
|
|
|
|
|
|
|
|
magic = xbuf[0] + (xbuf[1]<<8);
|
2007-06-19 22:15:46 +02:00
|
|
|
This->loadtime_format = magic;
|
|
|
|
|
2006-03-05 14:34:31 +01:00
|
|
|
switch (magic) {
|
2008-03-06 09:16:55 +01:00
|
|
|
case BITMAP_FORMAT_GIF: /* GIF */
|
2006-03-05 14:34:31 +01:00
|
|
|
hr = OLEPictureImpl_LoadGif(This, xbuf, xread);
|
|
|
|
break;
|
2008-03-06 09:16:55 +01:00
|
|
|
case BITMAP_FORMAT_JPEG: /* JPEG */
|
2006-03-05 14:34:31 +01:00
|
|
|
hr = OLEPictureImpl_LoadJpeg(This, xbuf, xread);
|
|
|
|
break;
|
2008-03-06 09:16:55 +01:00
|
|
|
case BITMAP_FORMAT_BMP: /* Bitmap */
|
2006-03-05 14:34:31 +01:00
|
|
|
hr = OLEPictureImpl_LoadDIB(This, xbuf, xread);
|
|
|
|
break;
|
2008-03-06 09:16:55 +01:00
|
|
|
case BITMAP_FORMAT_PNG: /* PNG */
|
2007-06-19 22:12:57 +02:00
|
|
|
hr = OLEPictureImpl_LoadPNG(This, xbuf, xread);
|
|
|
|
break;
|
2008-03-06 09:16:55 +01:00
|
|
|
case BITMAP_FORMAT_APM: /* APM */
|
2007-10-04 01:56:53 +02:00
|
|
|
hr = OLEPictureImpl_LoadAPM(This, xbuf, xread);
|
|
|
|
break;
|
2006-03-05 14:34:31 +01:00
|
|
|
case 0x0000: { /* ICON , first word is dwReserved */
|
|
|
|
hr = OLEPictureImpl_LoadIcon(This, xbuf, xread);
|
2001-08-06 20:52:14 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2003-01-09 07:04:33 +01:00
|
|
|
{
|
2004-09-22 04:46:38 +02:00
|
|
|
unsigned int i;
|
2007-05-28 09:22:46 +02:00
|
|
|
|
2008-10-04 01:24:37 +02:00
|
|
|
/* let's see if it's a EMF */
|
|
|
|
hr = OLEPictureImpl_LoadEnhMetafile(This, xbuf, xread);
|
2007-05-28 09:22:46 +02:00
|
|
|
if (hr == S_OK) break;
|
|
|
|
|
2006-10-12 20:57:10 +02:00
|
|
|
FIXME("Unknown magic %04x, %d read bytes:\n",magic,xread);
|
2001-08-06 20:52:14 +02:00
|
|
|
hr=E_FAIL;
|
2003-01-09 07:04:33 +01:00
|
|
|
for (i=0;i<xread+8;i++) {
|
2008-07-11 11:41:47 +02:00
|
|
|
if (i<8) MESSAGE("%02x ",((unsigned char*)header)[i]);
|
2003-01-09 07:04:33 +01:00
|
|
|
else MESSAGE("%02x ",xbuf[i-8]);
|
|
|
|
if (i % 10 == 9) MESSAGE("\n");
|
|
|
|
}
|
|
|
|
MESSAGE("\n");
|
2001-08-06 20:52:14 +02:00
|
|
|
break;
|
|
|
|
}
|
2003-01-09 07:04:33 +01:00
|
|
|
}
|
2004-09-22 06:04:03 +02:00
|
|
|
This->bIsDirty = FALSE;
|
2001-08-06 20:52:14 +02:00
|
|
|
|
|
|
|
/* FIXME: this notify is not really documented */
|
|
|
|
if (hr==S_OK)
|
|
|
|
OLEPicture_SendNotify(This,DISPID_PICT_TYPE);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2004-09-22 06:04:03 +02:00
|
|
|
static int serializeBMP(HBITMAP hBitmap, void ** ppBuffer, unsigned int * pLength)
|
|
|
|
{
|
|
|
|
int iSuccess = 0;
|
|
|
|
HDC hDC;
|
|
|
|
BITMAPINFO * pInfoBitmap;
|
|
|
|
int iNumPaletteEntries;
|
|
|
|
unsigned char * pPixelData;
|
|
|
|
BITMAPFILEHEADER * pFileHeader;
|
|
|
|
BITMAPINFO * pInfoHeader;
|
|
|
|
|
2005-03-24 22:01:35 +01:00
|
|
|
pInfoBitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
2004-09-22 06:04:03 +02:00
|
|
|
sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
|
|
|
|
|
|
|
|
/* Find out bitmap size and padded length */
|
|
|
|
hDC = GetDC(0);
|
|
|
|
pInfoBitmap->bmiHeader.biSize = sizeof(pInfoBitmap->bmiHeader);
|
|
|
|
GetDIBits(hDC, hBitmap, 0, 0, NULL, pInfoBitmap, DIB_RGB_COLORS);
|
|
|
|
|
|
|
|
/* Fetch bitmap palette & pixel data */
|
|
|
|
|
2005-03-24 22:01:35 +01:00
|
|
|
pPixelData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, pInfoBitmap->bmiHeader.biSizeImage);
|
2004-09-22 06:04:03 +02:00
|
|
|
GetDIBits(hDC, hBitmap, 0, pInfoBitmap->bmiHeader.biHeight, pPixelData, pInfoBitmap, DIB_RGB_COLORS);
|
|
|
|
|
|
|
|
/* Calculate the total length required for the BMP data */
|
2005-02-14 12:08:22 +01:00
|
|
|
if (pInfoBitmap->bmiHeader.biClrUsed != 0) {
|
|
|
|
iNumPaletteEntries = pInfoBitmap->bmiHeader.biClrUsed;
|
|
|
|
if (iNumPaletteEntries > 256) iNumPaletteEntries = 256;
|
|
|
|
} else {
|
|
|
|
if (pInfoBitmap->bmiHeader.biBitCount <= 8)
|
|
|
|
iNumPaletteEntries = 1 << pInfoBitmap->bmiHeader.biBitCount;
|
|
|
|
else
|
|
|
|
iNumPaletteEntries = 0;
|
|
|
|
}
|
2004-09-22 06:04:03 +02:00
|
|
|
*pLength =
|
|
|
|
sizeof(BITMAPFILEHEADER) +
|
|
|
|
sizeof(BITMAPINFOHEADER) +
|
|
|
|
iNumPaletteEntries * sizeof(RGBQUAD) +
|
|
|
|
pInfoBitmap->bmiHeader.biSizeImage;
|
2005-03-24 22:01:35 +01:00
|
|
|
*ppBuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *pLength);
|
2004-09-22 06:04:03 +02:00
|
|
|
|
|
|
|
/* Fill the BITMAPFILEHEADER */
|
2009-02-09 09:45:52 +01:00
|
|
|
pFileHeader = *ppBuffer;
|
2008-03-06 09:16:55 +01:00
|
|
|
pFileHeader->bfType = BITMAP_FORMAT_BMP;
|
2004-09-22 06:04:03 +02:00
|
|
|
pFileHeader->bfSize = *pLength;
|
|
|
|
pFileHeader->bfOffBits =
|
|
|
|
sizeof(BITMAPFILEHEADER) +
|
|
|
|
sizeof(BITMAPINFOHEADER) +
|
|
|
|
iNumPaletteEntries * sizeof(RGBQUAD);
|
|
|
|
|
|
|
|
/* Fill the BITMAPINFOHEADER and the palette data */
|
|
|
|
pInfoHeader = (BITMAPINFO *)((unsigned char *)(*ppBuffer) + sizeof(BITMAPFILEHEADER));
|
|
|
|
memcpy(pInfoHeader, pInfoBitmap, sizeof(BITMAPINFOHEADER) + iNumPaletteEntries * sizeof(RGBQUAD));
|
|
|
|
memcpy(
|
|
|
|
(unsigned char *)(*ppBuffer) +
|
|
|
|
sizeof(BITMAPFILEHEADER) +
|
|
|
|
sizeof(BITMAPINFOHEADER) +
|
|
|
|
iNumPaletteEntries * sizeof(RGBQUAD),
|
|
|
|
pPixelData, pInfoBitmap->bmiHeader.biSizeImage);
|
|
|
|
iSuccess = 1;
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, pPixelData);
|
|
|
|
HeapFree(GetProcessHeap(), 0, pInfoBitmap);
|
|
|
|
return iSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int serializeIcon(HICON hIcon, void ** ppBuffer, unsigned int * pLength)
|
|
|
|
{
|
|
|
|
ICONINFO infoIcon;
|
|
|
|
int iSuccess = 0;
|
|
|
|
|
|
|
|
*ppBuffer = NULL; *pLength = 0;
|
|
|
|
if (GetIconInfo(hIcon, &infoIcon)) {
|
|
|
|
HDC hDC;
|
|
|
|
BITMAPINFO * pInfoBitmap;
|
|
|
|
unsigned char * pIconData = NULL;
|
|
|
|
unsigned int iDataSize = 0;
|
|
|
|
|
2005-03-24 22:01:35 +01:00
|
|
|
pInfoBitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
|
2004-09-22 06:04:03 +02:00
|
|
|
|
|
|
|
/* Find out icon size */
|
|
|
|
hDC = GetDC(0);
|
|
|
|
pInfoBitmap->bmiHeader.biSize = sizeof(pInfoBitmap->bmiHeader);
|
|
|
|
GetDIBits(hDC, infoIcon.hbmColor, 0, 0, NULL, pInfoBitmap, DIB_RGB_COLORS);
|
|
|
|
if (1) {
|
|
|
|
/* Auxiliary pointers */
|
|
|
|
CURSORICONFILEDIR * pIconDir;
|
|
|
|
CURSORICONFILEDIRENTRY * pIconEntry;
|
|
|
|
BITMAPINFOHEADER * pIconBitmapHeader;
|
|
|
|
unsigned int iOffsetPalette;
|
|
|
|
unsigned int iOffsetColorData;
|
|
|
|
unsigned int iOffsetMaskData;
|
|
|
|
|
|
|
|
unsigned int iLengthScanLineColor;
|
|
|
|
unsigned int iLengthScanLineMask;
|
|
|
|
unsigned int iNumEntriesPalette;
|
|
|
|
|
|
|
|
iLengthScanLineMask = ((pInfoBitmap->bmiHeader.biWidth + 31) >> 5) << 2;
|
|
|
|
iLengthScanLineColor = ((pInfoBitmap->bmiHeader.biWidth * pInfoBitmap->bmiHeader.biBitCount + 31) >> 5) << 2;
|
|
|
|
/*
|
|
|
|
FIXME("DEBUG: bitmap size is %d x %d\n",
|
|
|
|
pInfoBitmap->bmiHeader.biWidth,
|
|
|
|
pInfoBitmap->bmiHeader.biHeight);
|
|
|
|
FIXME("DEBUG: bitmap bpp is %d\n",
|
|
|
|
pInfoBitmap->bmiHeader.biBitCount);
|
|
|
|
FIXME("DEBUG: bitmap nplanes is %d\n",
|
|
|
|
pInfoBitmap->bmiHeader.biPlanes);
|
2006-10-12 20:57:10 +02:00
|
|
|
FIXME("DEBUG: bitmap biSizeImage is %u\n",
|
2004-09-22 06:04:03 +02:00
|
|
|
pInfoBitmap->bmiHeader.biSizeImage);
|
|
|
|
*/
|
|
|
|
/* Let's start with one CURSORICONFILEDIR and one CURSORICONFILEDIRENTRY */
|
|
|
|
iDataSize += 3 * sizeof(WORD) + sizeof(CURSORICONFILEDIRENTRY) + sizeof(BITMAPINFOHEADER);
|
2005-03-24 22:01:35 +01:00
|
|
|
pIconData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, iDataSize);
|
2004-09-22 06:04:03 +02:00
|
|
|
|
|
|
|
/* Fill out the CURSORICONFILEDIR */
|
|
|
|
pIconDir = (CURSORICONFILEDIR *)pIconData;
|
|
|
|
pIconDir->idType = 1;
|
|
|
|
pIconDir->idCount = 1;
|
|
|
|
|
|
|
|
/* Fill out the CURSORICONFILEDIRENTRY */
|
|
|
|
pIconEntry = (CURSORICONFILEDIRENTRY *)(pIconData + 3 * sizeof(WORD));
|
|
|
|
pIconEntry->bWidth = (unsigned char)pInfoBitmap->bmiHeader.biWidth;
|
|
|
|
pIconEntry->bHeight = (unsigned char)pInfoBitmap->bmiHeader.biHeight;
|
|
|
|
pIconEntry->bColorCount =
|
|
|
|
(pInfoBitmap->bmiHeader.biBitCount < 8)
|
|
|
|
? 1 << pInfoBitmap->bmiHeader.biBitCount
|
|
|
|
: 0;
|
|
|
|
pIconEntry->xHotspot = pInfoBitmap->bmiHeader.biPlanes;
|
|
|
|
pIconEntry->yHotspot = pInfoBitmap->bmiHeader.biBitCount;
|
|
|
|
pIconEntry->dwDIBSize = 0;
|
|
|
|
pIconEntry->dwDIBOffset = 3 * sizeof(WORD) + sizeof(CURSORICONFILEDIRENTRY);
|
|
|
|
|
|
|
|
/* Fill out the BITMAPINFOHEADER */
|
|
|
|
pIconBitmapHeader = (BITMAPINFOHEADER *)(pIconData + 3 * sizeof(WORD) + sizeof(CURSORICONFILEDIRENTRY));
|
2008-03-11 21:55:17 +01:00
|
|
|
*pIconBitmapHeader = pInfoBitmap->bmiHeader;
|
2004-09-22 06:04:03 +02:00
|
|
|
|
|
|
|
/* Find out whether a palette exists for the bitmap */
|
|
|
|
if ( (pInfoBitmap->bmiHeader.biBitCount == 16 && pInfoBitmap->bmiHeader.biCompression == BI_RGB)
|
|
|
|
|| (pInfoBitmap->bmiHeader.biBitCount == 24)
|
|
|
|
|| (pInfoBitmap->bmiHeader.biBitCount == 32 && pInfoBitmap->bmiHeader.biCompression == BI_RGB)) {
|
|
|
|
iNumEntriesPalette = pInfoBitmap->bmiHeader.biClrUsed;
|
2005-02-14 12:08:22 +01:00
|
|
|
if (iNumEntriesPalette > 256) iNumEntriesPalette = 256;
|
2004-09-22 06:04:03 +02:00
|
|
|
} else if ((pInfoBitmap->bmiHeader.biBitCount == 16 || pInfoBitmap->bmiHeader.biBitCount == 32)
|
|
|
|
&& pInfoBitmap->bmiHeader.biCompression == BI_BITFIELDS) {
|
|
|
|
iNumEntriesPalette = 3;
|
|
|
|
} else if (pInfoBitmap->bmiHeader.biBitCount <= 8) {
|
|
|
|
iNumEntriesPalette = 1 << pInfoBitmap->bmiHeader.biBitCount;
|
|
|
|
} else {
|
|
|
|
iNumEntriesPalette = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add bitmap size and header size to icon data size. */
|
|
|
|
iOffsetPalette = iDataSize;
|
|
|
|
iDataSize += iNumEntriesPalette * sizeof(DWORD);
|
|
|
|
iOffsetColorData = iDataSize;
|
|
|
|
iDataSize += pIconBitmapHeader->biSizeImage;
|
|
|
|
iOffsetMaskData = iDataSize;
|
|
|
|
iDataSize += pIconBitmapHeader->biHeight * iLengthScanLineMask;
|
|
|
|
pIconBitmapHeader->biSizeImage += pIconBitmapHeader->biHeight * iLengthScanLineMask;
|
|
|
|
pIconBitmapHeader->biHeight *= 2;
|
2005-03-24 22:01:35 +01:00
|
|
|
pIconData = HeapReAlloc(GetProcessHeap(), 0, pIconData, iDataSize);
|
2004-09-22 06:04:03 +02:00
|
|
|
pIconEntry = (CURSORICONFILEDIRENTRY *)(pIconData + 3 * sizeof(WORD));
|
|
|
|
pIconBitmapHeader = (BITMAPINFOHEADER *)(pIconData + 3 * sizeof(WORD) + sizeof(CURSORICONFILEDIRENTRY));
|
|
|
|
pIconEntry->dwDIBSize = iDataSize - (3 * sizeof(WORD) + sizeof(CURSORICONFILEDIRENTRY));
|
|
|
|
|
|
|
|
/* Get the actual bitmap data from the icon bitmap */
|
|
|
|
GetDIBits(hDC, infoIcon.hbmColor, 0, pInfoBitmap->bmiHeader.biHeight,
|
|
|
|
pIconData + iOffsetColorData, pInfoBitmap, DIB_RGB_COLORS);
|
|
|
|
if (iNumEntriesPalette > 0) {
|
|
|
|
memcpy(pIconData + iOffsetPalette, pInfoBitmap->bmiColors,
|
|
|
|
iNumEntriesPalette * sizeof(RGBQUAD));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset all values so that GetDIBits call succeeds */
|
|
|
|
memset(pIconData + iOffsetMaskData, 0, iDataSize - iOffsetMaskData);
|
|
|
|
memset(pInfoBitmap, 0, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
|
|
|
|
pInfoBitmap->bmiHeader.biSize = sizeof(pInfoBitmap->bmiHeader);
|
|
|
|
/*
|
|
|
|
if (!(GetDIBits(hDC, infoIcon.hbmMask, 0, 0, NULL, pInfoBitmap, DIB_RGB_COLORS)
|
|
|
|
&& GetDIBits(hDC, infoIcon.hbmMask, 0, pIconEntry->bHeight,
|
|
|
|
pIconData + iOffsetMaskData, pInfoBitmap, DIB_RGB_COLORS))) {
|
|
|
|
|
2006-10-12 20:57:10 +02:00
|
|
|
printf("ERROR: unable to get bitmap mask (error %u)\n",
|
2004-09-22 06:04:03 +02:00
|
|
|
GetLastError());
|
|
|
|
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
GetDIBits(hDC, infoIcon.hbmMask, 0, 0, NULL, pInfoBitmap, DIB_RGB_COLORS);
|
|
|
|
GetDIBits(hDC, infoIcon.hbmMask, 0, pIconEntry->bHeight, pIconData + iOffsetMaskData, pInfoBitmap, DIB_RGB_COLORS);
|
|
|
|
|
|
|
|
/* Write out everything produced so far to the stream */
|
|
|
|
*ppBuffer = pIconData; *pLength = iDataSize;
|
|
|
|
iSuccess = 1;
|
|
|
|
} else {
|
|
|
|
/*
|
2006-10-12 20:57:10 +02:00
|
|
|
printf("ERROR: unable to get bitmap information via GetDIBits() (error %u)\n",
|
2004-09-22 06:04:03 +02:00
|
|
|
GetLastError());
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
Remarks (from MSDN entry on GetIconInfo):
|
|
|
|
|
|
|
|
GetIconInfo creates bitmaps for the hbmMask and hbmColor
|
|
|
|
members of ICONINFO. The calling application must manage
|
|
|
|
these bitmaps and delete them when they are no longer
|
|
|
|
necessary.
|
|
|
|
*/
|
|
|
|
if (hDC) ReleaseDC(0, hDC);
|
|
|
|
DeleteObject(infoIcon.hbmMask);
|
|
|
|
if (infoIcon.hbmColor) DeleteObject(infoIcon.hbmColor);
|
|
|
|
HeapFree(GetProcessHeap(), 0, pInfoBitmap);
|
|
|
|
} else {
|
2006-10-12 20:57:10 +02:00
|
|
|
printf("ERROR: Unable to get icon information (error %u)\n",
|
2004-09-22 06:04:03 +02:00
|
|
|
GetLastError());
|
|
|
|
}
|
|
|
|
return iSuccess;
|
2001-08-06 20:52:14 +02:00
|
|
|
}
|
|
|
|
|
2006-03-08 12:54:36 +01:00
|
|
|
static HRESULT WINAPI OLEPictureImpl_Save(
|
|
|
|
IPersistStream* iface,IStream*pStm,BOOL fClearDirty)
|
|
|
|
{
|
|
|
|
HRESULT hResult = E_NOTIMPL;
|
|
|
|
void * pIconData;
|
|
|
|
unsigned int iDataSize;
|
|
|
|
ULONG dummy;
|
|
|
|
int iSerializeResult = 0;
|
2006-08-14 07:07:30 +02:00
|
|
|
OLEPictureImpl *This = impl_from_IPersistStream(iface);
|
2006-03-08 12:54:36 +01:00
|
|
|
|
2006-08-14 07:07:30 +02:00
|
|
|
TRACE("%p %p %d\n", This, pStm, fClearDirty);
|
2006-03-08 12:54:36 +01:00
|
|
|
|
|
|
|
switch (This->desc.picType) {
|
|
|
|
case PICTYPE_ICON:
|
2006-08-14 07:07:30 +02:00
|
|
|
if (This->bIsDirty || !This->data) {
|
|
|
|
if (!serializeIcon(This->desc.u.icon.hicon, &pIconData, &iDataSize)) {
|
|
|
|
ERR("(%p,%p,%d), serializeIcon() failed\n", This, pStm, fClearDirty);
|
2006-03-08 12:54:36 +01:00
|
|
|
hResult = E_FAIL;
|
2006-08-14 07:07:30 +02:00
|
|
|
break;
|
2006-03-08 12:54:36 +01:00
|
|
|
}
|
2006-08-14 14:02:28 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->data);
|
2006-08-14 07:07:30 +02:00
|
|
|
This->data = pIconData;
|
|
|
|
This->datalen = iDataSize;
|
|
|
|
}
|
|
|
|
if (This->loadtime_magic != 0xdeadbeef) {
|
|
|
|
DWORD header[2];
|
2006-03-08 12:54:36 +01:00
|
|
|
|
2006-08-14 07:07:30 +02:00
|
|
|
header[0] = This->loadtime_magic;
|
|
|
|
header[1] = This->datalen;
|
|
|
|
IStream_Write(pStm, header, 2 * sizeof(DWORD), &dummy);
|
2006-03-08 12:54:36 +01:00
|
|
|
}
|
2006-08-14 07:07:30 +02:00
|
|
|
IStream_Write(pStm, This->data, This->datalen, &dummy);
|
|
|
|
|
|
|
|
hResult = S_OK;
|
2006-03-08 12:54:36 +01:00
|
|
|
break;
|
|
|
|
case PICTYPE_BITMAP:
|
|
|
|
if (This->bIsDirty) {
|
2008-03-06 09:16:55 +01:00
|
|
|
switch (This->keepOrigFormat ? This->loadtime_format : BITMAP_FORMAT_BMP) {
|
|
|
|
case BITMAP_FORMAT_BMP:
|
2006-03-08 12:54:36 +01:00
|
|
|
iSerializeResult = serializeBMP(This->desc.u.bmp.hbitmap, &pIconData, &iDataSize);
|
|
|
|
break;
|
2008-03-06 09:16:55 +01:00
|
|
|
case BITMAP_FORMAT_JPEG:
|
2006-03-08 12:54:36 +01:00
|
|
|
FIXME("(%p,%p,%d), PICTYPE_BITMAP (format JPEG) not implemented!\n",This,pStm,fClearDirty);
|
|
|
|
break;
|
2008-03-06 09:16:55 +01:00
|
|
|
case BITMAP_FORMAT_GIF:
|
2006-03-08 12:54:36 +01:00
|
|
|
FIXME("(%p,%p,%d), PICTYPE_BITMAP (format GIF) not implemented!\n",This,pStm,fClearDirty);
|
|
|
|
break;
|
2008-03-06 09:16:55 +01:00
|
|
|
case BITMAP_FORMAT_PNG:
|
2007-06-19 22:12:57 +02:00
|
|
|
FIXME("(%p,%p,%d), PICTYPE_BITMAP (format PNG) not implemented!\n",This,pStm,fClearDirty);
|
|
|
|
break;
|
2006-03-08 12:54:36 +01:00
|
|
|
default:
|
|
|
|
FIXME("(%p,%p,%d), PICTYPE_BITMAP (format UNKNOWN, using BMP?) not implemented!\n",This,pStm,fClearDirty);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (iSerializeResult) {
|
|
|
|
/*
|
|
|
|
if (This->loadtime_magic != 0xdeadbeef) {
|
|
|
|
*/
|
|
|
|
if (1) {
|
|
|
|
DWORD header[2];
|
|
|
|
|
|
|
|
header[0] = (This->loadtime_magic != 0xdeadbeef) ? This->loadtime_magic : 0x0000746c;
|
|
|
|
header[1] = iDataSize;
|
|
|
|
IStream_Write(pStm, header, 2 * sizeof(DWORD), &dummy);
|
|
|
|
}
|
|
|
|
IStream_Write(pStm, pIconData, iDataSize, &dummy);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->data);
|
|
|
|
This->data = pIconData;
|
|
|
|
This->datalen = iDataSize;
|
|
|
|
hResult = S_OK;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
if (This->loadtime_magic != 0xdeadbeef) {
|
|
|
|
*/
|
|
|
|
if (1) {
|
|
|
|
DWORD header[2];
|
|
|
|
|
|
|
|
header[0] = (This->loadtime_magic != 0xdeadbeef) ? This->loadtime_magic : 0x0000746c;
|
|
|
|
header[1] = This->datalen;
|
|
|
|
IStream_Write(pStm, header, 2 * sizeof(DWORD), &dummy);
|
|
|
|
}
|
|
|
|
IStream_Write(pStm, This->data, This->datalen, &dummy);
|
|
|
|
hResult = S_OK;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PICTYPE_METAFILE:
|
|
|
|
FIXME("(%p,%p,%d), PICTYPE_METAFILE not implemented!\n",This,pStm,fClearDirty);
|
|
|
|
break;
|
|
|
|
case PICTYPE_ENHMETAFILE:
|
|
|
|
FIXME("(%p,%p,%d),PICTYPE_ENHMETAFILE not implemented!\n",This,pStm,fClearDirty);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("(%p,%p,%d), [unknown type] not implemented!\n",This,pStm,fClearDirty);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (hResult == S_OK && fClearDirty) This->bIsDirty = FALSE;
|
|
|
|
return hResult;
|
|
|
|
}
|
|
|
|
|
2001-08-06 20:52:14 +02:00
|
|
|
static HRESULT WINAPI OLEPictureImpl_GetSizeMax(
|
|
|
|
IPersistStream* iface,ULARGE_INTEGER*pcbSize)
|
|
|
|
{
|
2005-07-27 17:14:18 +02:00
|
|
|
OLEPictureImpl *This = impl_from_IPersistStream(iface);
|
2001-08-06 20:52:14 +02:00
|
|
|
FIXME("(%p,%p),stub!\n",This,pcbSize);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2000-07-15 16:59:11 +02:00
|
|
|
|
2006-03-08 12:54:36 +01:00
|
|
|
|
2000-07-15 16:59:11 +02:00
|
|
|
/************************************************************************
|
|
|
|
* IDispatch
|
|
|
|
*/
|
2006-03-08 12:54:36 +01:00
|
|
|
|
2000-07-15 16:59:11 +02:00
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_IDispatch_QueryInterface (IUnknown)
|
|
|
|
*
|
|
|
|
* See Windows documentation for more details on IUnknown methods.
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI OLEPictureImpl_IDispatch_QueryInterface(
|
|
|
|
IDispatch* iface,
|
|
|
|
REFIID riid,
|
|
|
|
VOID** ppvoid)
|
|
|
|
{
|
2005-07-27 17:14:18 +02:00
|
|
|
OLEPictureImpl *This = impl_from_IDispatch(iface);
|
2000-07-15 16:59:11 +02:00
|
|
|
|
2005-07-27 17:14:18 +02:00
|
|
|
return IPicture_QueryInterface((IPicture *)This, riid, ppvoid);
|
2000-07-15 16:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_IDispatch_AddRef (IUnknown)
|
|
|
|
*
|
|
|
|
* See Windows documentation for more details on IUnknown methods.
|
|
|
|
*/
|
|
|
|
static ULONG WINAPI OLEPictureImpl_IDispatch_AddRef(
|
|
|
|
IDispatch* iface)
|
|
|
|
{
|
2005-07-27 17:14:18 +02:00
|
|
|
OLEPictureImpl *This = impl_from_IDispatch(iface);
|
2000-07-15 16:59:11 +02:00
|
|
|
|
2005-07-27 17:14:18 +02:00
|
|
|
return IPicture_AddRef((IPicture *)This);
|
2000-07-15 16:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_IDispatch_Release (IUnknown)
|
|
|
|
*
|
|
|
|
* See Windows documentation for more details on IUnknown methods.
|
|
|
|
*/
|
|
|
|
static ULONG WINAPI OLEPictureImpl_IDispatch_Release(
|
|
|
|
IDispatch* iface)
|
|
|
|
{
|
2005-07-27 17:14:18 +02:00
|
|
|
OLEPictureImpl *This = impl_from_IDispatch(iface);
|
2000-07-15 16:59:11 +02:00
|
|
|
|
2005-07-27 17:14:18 +02:00
|
|
|
return IPicture_Release((IPicture *)This);
|
2000-07-15 16:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_GetTypeInfoCount (IDispatch)
|
|
|
|
*
|
|
|
|
* See Windows documentation for more details on IDispatch methods.
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI OLEPictureImpl_GetTypeInfoCount(
|
2002-06-01 01:06:46 +02:00
|
|
|
IDispatch* iface,
|
2000-07-15 16:59:11 +02:00
|
|
|
unsigned int* pctinfo)
|
|
|
|
{
|
2006-10-05 11:11:03 +02:00
|
|
|
TRACE("(%p)\n", pctinfo);
|
2000-07-15 16:59:11 +02:00
|
|
|
|
2006-07-28 02:26:13 +02:00
|
|
|
*pctinfo = 1;
|
|
|
|
|
|
|
|
return S_OK;
|
2000-07-15 16:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_GetTypeInfo (IDispatch)
|
|
|
|
*
|
|
|
|
* See Windows documentation for more details on IDispatch methods.
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI OLEPictureImpl_GetTypeInfo(
|
2002-06-01 01:06:46 +02:00
|
|
|
IDispatch* iface,
|
2000-07-15 16:59:11 +02:00
|
|
|
UINT iTInfo,
|
2002-06-01 01:06:46 +02:00
|
|
|
LCID lcid,
|
2000-07-15 16:59:11 +02:00
|
|
|
ITypeInfo** ppTInfo)
|
|
|
|
{
|
2006-07-28 02:26:13 +02:00
|
|
|
static const WCHAR stdole2tlb[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
|
|
|
|
ITypeLib *tl;
|
|
|
|
HRESULT hres;
|
2000-07-15 16:59:11 +02:00
|
|
|
|
2006-07-28 02:26:13 +02:00
|
|
|
TRACE("(iTInfo=%d, lcid=%04x, %p)\n", iTInfo, (int)lcid, ppTInfo);
|
|
|
|
|
|
|
|
if (iTInfo != 0)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
hres = LoadTypeLib(stdole2tlb, &tl);
|
|
|
|
if (FAILED(hres))
|
|
|
|
{
|
|
|
|
ERR("Could not load stdole2.tlb\n");
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = ITypeLib_GetTypeInfoOfGuid(tl, &IID_IPictureDisp, ppTInfo);
|
|
|
|
if (FAILED(hres))
|
2006-10-12 20:57:10 +02:00
|
|
|
ERR("Did not get IPictureDisp typeinfo from typelib, hres %x\n", hres);
|
2006-07-28 02:26:13 +02:00
|
|
|
|
|
|
|
return hres;
|
2000-07-15 16:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_GetIDsOfNames (IDispatch)
|
|
|
|
*
|
|
|
|
* See Windows documentation for more details on IDispatch methods.
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI OLEPictureImpl_GetIDsOfNames(
|
|
|
|
IDispatch* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
REFIID riid,
|
|
|
|
LPOLESTR* rgszNames,
|
|
|
|
UINT cNames,
|
2000-07-15 16:59:11 +02:00
|
|
|
LCID lcid,
|
|
|
|
DISPID* rgDispId)
|
|
|
|
{
|
2007-11-30 19:02:47 +01:00
|
|
|
ITypeInfo * pTInfo;
|
|
|
|
HRESULT hres;
|
2000-07-15 16:59:11 +02:00
|
|
|
|
2007-11-30 19:02:47 +01:00
|
|
|
TRACE("(%p,%s,%p,cNames=%d,lcid=%04x,%p)\n", iface, debugstr_guid(riid),
|
|
|
|
rgszNames, cNames, (int)lcid, rgDispId);
|
|
|
|
|
|
|
|
if (cNames == 0)
|
|
|
|
{
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* retrieve type information */
|
|
|
|
hres = OLEPictureImpl_GetTypeInfo(iface, 0, lcid, &pTInfo);
|
|
|
|
|
|
|
|
if (FAILED(hres))
|
|
|
|
{
|
|
|
|
ERR("GetTypeInfo failed.\n");
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* convert names to DISPIDs */
|
|
|
|
hres = DispGetIDsOfNames (pTInfo, rgszNames, cNames, rgDispId);
|
|
|
|
ITypeInfo_Release(pTInfo);
|
|
|
|
|
|
|
|
return hres;
|
|
|
|
}
|
2000-07-15 16:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* OLEPictureImpl_Invoke (IDispatch)
|
|
|
|
*
|
|
|
|
* See Windows documentation for more details on IDispatch methods.
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI OLEPictureImpl_Invoke(
|
|
|
|
IDispatch* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
DISPID dispIdMember,
|
|
|
|
REFIID riid,
|
|
|
|
LCID lcid,
|
2000-07-15 16:59:11 +02:00
|
|
|
WORD wFlags,
|
|
|
|
DISPPARAMS* pDispParams,
|
2002-06-01 01:06:46 +02:00
|
|
|
VARIANT* pVarResult,
|
2000-07-15 16:59:11 +02:00
|
|
|
EXCEPINFO* pExepInfo,
|
|
|
|
UINT* puArgErr)
|
|
|
|
{
|
2006-02-10 14:51:03 +01:00
|
|
|
OLEPictureImpl *This = impl_from_IDispatch(iface);
|
2006-07-28 02:22:02 +02:00
|
|
|
|
|
|
|
/* validate parameters */
|
|
|
|
|
|
|
|
if (!IsEqualIID(riid, &IID_NULL))
|
|
|
|
{
|
|
|
|
ERR("riid was %s instead of IID_NULL\n", debugstr_guid(riid));
|
|
|
|
return DISP_E_UNKNOWNNAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pDispParams)
|
|
|
|
{
|
|
|
|
ERR("null pDispParams not allowed\n");
|
|
|
|
return DISP_E_PARAMNOTOPTIONAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wFlags & DISPATCH_PROPERTYGET)
|
|
|
|
{
|
2006-07-28 02:24:10 +02:00
|
|
|
if (pDispParams->cArgs != 0)
|
|
|
|
{
|
|
|
|
ERR("param count for DISPATCH_PROPERTYGET was %d instead of 0\n", pDispParams->cArgs);
|
|
|
|
return DISP_E_BADPARAMCOUNT;
|
|
|
|
}
|
2006-07-28 02:22:02 +02:00
|
|
|
if (!pVarResult)
|
|
|
|
{
|
|
|
|
ERR("null pVarResult not allowed when DISPATCH_PROPERTYGET specified\n");
|
|
|
|
return DISP_E_PARAMNOTOPTIONAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (wFlags & DISPATCH_PROPERTYPUT)
|
|
|
|
{
|
|
|
|
if (pDispParams->cArgs != 1)
|
|
|
|
{
|
|
|
|
ERR("param count for DISPATCH_PROPERTYPUT was %d instead of 1\n", pDispParams->cArgs);
|
|
|
|
return DISP_E_BADPARAMCOUNT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-28 02:24:10 +02:00
|
|
|
switch (dispIdMember)
|
2006-02-10 14:51:03 +01:00
|
|
|
{
|
2006-07-28 02:24:10 +02:00
|
|
|
case DISPID_PICT_HANDLE:
|
|
|
|
if (wFlags & DISPATCH_PROPERTYGET)
|
2006-02-10 14:51:03 +01:00
|
|
|
{
|
2006-07-28 02:24:10 +02:00
|
|
|
TRACE("DISPID_PICT_HANDLE\n");
|
|
|
|
V_VT(pVarResult) = VT_I4;
|
|
|
|
return IPicture_get_Handle((IPicture *)&This->lpVtbl, &V_UINT(pVarResult));
|
2006-02-10 14:51:03 +01:00
|
|
|
}
|
2006-07-28 02:24:10 +02:00
|
|
|
break;
|
|
|
|
case DISPID_PICT_HPAL:
|
|
|
|
if (wFlags & DISPATCH_PROPERTYGET)
|
|
|
|
{
|
|
|
|
TRACE("DISPID_PICT_HPAL\n");
|
|
|
|
V_VT(pVarResult) = VT_I4;
|
|
|
|
return IPicture_get_hPal((IPicture *)&This->lpVtbl, &V_UINT(pVarResult));
|
|
|
|
}
|
2006-07-28 02:25:23 +02:00
|
|
|
else if (wFlags & DISPATCH_PROPERTYPUT)
|
|
|
|
{
|
|
|
|
VARIANTARG vararg;
|
|
|
|
HRESULT hr;
|
|
|
|
TRACE("DISPID_PICT_HPAL\n");
|
|
|
|
|
|
|
|
VariantInit(&vararg);
|
|
|
|
hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_I4);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = IPicture_set_hPal((IPicture *)&This->lpVtbl, V_I4(&vararg));
|
|
|
|
|
|
|
|
VariantClear(&vararg);
|
|
|
|
return hr;
|
|
|
|
}
|
2006-07-28 02:24:10 +02:00
|
|
|
break;
|
|
|
|
case DISPID_PICT_TYPE:
|
|
|
|
if (wFlags & DISPATCH_PROPERTYGET)
|
|
|
|
{
|
|
|
|
TRACE("DISPID_PICT_TYPE\n");
|
|
|
|
V_VT(pVarResult) = VT_I2;
|
|
|
|
return OLEPictureImpl_get_Type((IPicture *)&This->lpVtbl, &V_I2(pVarResult));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DISPID_PICT_WIDTH:
|
|
|
|
if (wFlags & DISPATCH_PROPERTYGET)
|
|
|
|
{
|
|
|
|
TRACE("DISPID_PICT_WIDTH\n");
|
|
|
|
V_VT(pVarResult) = VT_I4;
|
|
|
|
return IPicture_get_Width((IPicture *)&This->lpVtbl, &V_I4(pVarResult));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DISPID_PICT_HEIGHT:
|
|
|
|
if (wFlags & DISPATCH_PROPERTYGET)
|
|
|
|
{
|
|
|
|
TRACE("DISPID_PICT_HEIGHT\n");
|
|
|
|
V_VT(pVarResult) = VT_I4;
|
|
|
|
return IPicture_get_Height((IPicture *)&This->lpVtbl, &V_I4(pVarResult));
|
|
|
|
}
|
|
|
|
break;
|
2006-02-10 14:51:03 +01:00
|
|
|
}
|
2000-07-15 16:59:11 +02:00
|
|
|
|
2006-10-12 20:57:10 +02:00
|
|
|
ERR("invalid dispid 0x%x or wFlags 0x%x\n", dispIdMember, wFlags);
|
2006-07-28 02:24:10 +02:00
|
|
|
return DISP_E_MEMBERNOTFOUND;
|
2000-07-15 16:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IPictureVtbl OLEPictureImpl_VTable =
|
2000-07-15 16:59:11 +02:00
|
|
|
{
|
|
|
|
OLEPictureImpl_QueryInterface,
|
|
|
|
OLEPictureImpl_AddRef,
|
|
|
|
OLEPictureImpl_Release,
|
|
|
|
OLEPictureImpl_get_Handle,
|
|
|
|
OLEPictureImpl_get_hPal,
|
|
|
|
OLEPictureImpl_get_Type,
|
|
|
|
OLEPictureImpl_get_Width,
|
|
|
|
OLEPictureImpl_get_Height,
|
|
|
|
OLEPictureImpl_Render,
|
|
|
|
OLEPictureImpl_set_hPal,
|
|
|
|
OLEPictureImpl_get_CurDC,
|
|
|
|
OLEPictureImpl_SelectPicture,
|
|
|
|
OLEPictureImpl_get_KeepOriginalFormat,
|
|
|
|
OLEPictureImpl_put_KeepOriginalFormat,
|
|
|
|
OLEPictureImpl_PictureChanged,
|
|
|
|
OLEPictureImpl_SaveAsFile,
|
|
|
|
OLEPictureImpl_get_Attributes
|
|
|
|
};
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IDispatchVtbl OLEPictureImpl_IDispatch_VTable =
|
2000-07-15 16:59:11 +02:00
|
|
|
{
|
|
|
|
OLEPictureImpl_IDispatch_QueryInterface,
|
|
|
|
OLEPictureImpl_IDispatch_AddRef,
|
|
|
|
OLEPictureImpl_IDispatch_Release,
|
|
|
|
OLEPictureImpl_GetTypeInfoCount,
|
|
|
|
OLEPictureImpl_GetTypeInfo,
|
|
|
|
OLEPictureImpl_GetIDsOfNames,
|
|
|
|
OLEPictureImpl_Invoke
|
|
|
|
};
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IPersistStreamVtbl OLEPictureImpl_IPersistStream_VTable =
|
2001-08-06 20:52:14 +02:00
|
|
|
{
|
|
|
|
OLEPictureImpl_IPersistStream_QueryInterface,
|
|
|
|
OLEPictureImpl_IPersistStream_AddRef,
|
|
|
|
OLEPictureImpl_IPersistStream_Release,
|
|
|
|
OLEPictureImpl_GetClassID,
|
|
|
|
OLEPictureImpl_IsDirty,
|
|
|
|
OLEPictureImpl_Load,
|
|
|
|
OLEPictureImpl_Save,
|
|
|
|
OLEPictureImpl_GetSizeMax
|
|
|
|
};
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IConnectionPointContainerVtbl OLEPictureImpl_IConnectionPointContainer_VTable =
|
2001-08-06 20:52:14 +02:00
|
|
|
{
|
|
|
|
OLEPictureImpl_IConnectionPointContainer_QueryInterface,
|
|
|
|
OLEPictureImpl_IConnectionPointContainer_AddRef,
|
|
|
|
OLEPictureImpl_IConnectionPointContainer_Release,
|
|
|
|
OLEPictureImpl_EnumConnectionPoints,
|
|
|
|
OLEPictureImpl_FindConnectionPoint
|
|
|
|
};
|
|
|
|
|
2000-07-15 16:59:11 +02:00
|
|
|
/***********************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* OleCreatePictureIndirect (OLEAUT32.419)
|
2000-07-15 16:59:11 +02:00
|
|
|
*/
|
|
|
|
HRESULT WINAPI OleCreatePictureIndirect(LPPICTDESC lpPictDesc, REFIID riid,
|
|
|
|
BOOL fOwn, LPVOID *ppvObj )
|
|
|
|
{
|
|
|
|
OLEPictureImpl* newPict = NULL;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
2006-08-14 07:07:14 +02:00
|
|
|
TRACE("(%p,%s,%d,%p)\n", lpPictDesc, debugstr_guid(riid), fOwn, ppvObj);
|
2000-07-15 16:59:11 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Sanity check
|
|
|
|
*/
|
|
|
|
if (ppvObj==0)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*ppvObj = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to construct a new instance of the class.
|
|
|
|
*/
|
|
|
|
newPict = OLEPictureImpl_Construct(lpPictDesc, fOwn);
|
|
|
|
|
|
|
|
if (newPict == NULL)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure it supports the interface required by the caller.
|
|
|
|
*/
|
|
|
|
hr = IPicture_QueryInterface((IPicture*)newPict, riid, ppvObj);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Release the reference obtained in the constructor. If
|
|
|
|
* the QueryInterface was unsuccessful, it will free the class.
|
|
|
|
*/
|
|
|
|
IPicture_Release((IPicture*)newPict);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* OleLoadPicture (OLEAUT32.418)
|
2000-07-15 16:59:11 +02:00
|
|
|
*/
|
|
|
|
HRESULT WINAPI OleLoadPicture( LPSTREAM lpstream, LONG lSize, BOOL fRunmode,
|
2001-08-06 20:52:14 +02:00
|
|
|
REFIID riid, LPVOID *ppvObj )
|
2000-07-15 16:59:11 +02:00
|
|
|
{
|
2001-08-06 20:52:14 +02:00
|
|
|
LPPERSISTSTREAM ps;
|
|
|
|
IPicture *newpic;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2006-10-12 20:57:10 +02:00
|
|
|
TRACE("(%p,%d,%d,%s,%p), partially implemented.\n",
|
2001-08-06 20:52:14 +02:00
|
|
|
lpstream, lSize, fRunmode, debugstr_guid(riid), ppvObj);
|
|
|
|
|
|
|
|
hr = OleCreatePictureIndirect(NULL,riid,!fRunmode,(LPVOID*)&newpic);
|
|
|
|
if (hr)
|
|
|
|
return hr;
|
|
|
|
hr = IPicture_QueryInterface(newpic,&IID_IPersistStream, (LPVOID*)&ps);
|
|
|
|
if (hr) {
|
2008-10-16 11:20:45 +02:00
|
|
|
ERR("Could not get IPersistStream iface from Ole Picture?\n");
|
2001-08-06 20:52:14 +02:00
|
|
|
IPicture_Release(newpic);
|
|
|
|
*ppvObj = NULL;
|
|
|
|
return hr;
|
|
|
|
}
|
2008-07-19 00:25:31 +02:00
|
|
|
hr = IPersistStream_Load(ps,lpstream);
|
2001-08-06 20:52:14 +02:00
|
|
|
IPersistStream_Release(ps);
|
2008-07-19 00:25:31 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ERR("IPersistStream_Load failed\n");
|
|
|
|
IPicture_Release(newpic);
|
|
|
|
*ppvObj = NULL;
|
|
|
|
return hr;
|
|
|
|
}
|
2001-08-06 20:52:14 +02:00
|
|
|
hr = IPicture_QueryInterface(newpic,riid,ppvObj);
|
|
|
|
if (hr)
|
2008-10-16 11:20:45 +02:00
|
|
|
ERR("Failed to get interface %s from IPicture.\n",debugstr_guid(riid));
|
2001-08-06 20:52:14 +02:00
|
|
|
IPicture_Release(newpic);
|
|
|
|
return hr;
|
2000-07-15 16:59:11 +02:00
|
|
|
}
|
2001-04-10 23:17:04 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
2002-07-19 02:30:16 +02:00
|
|
|
* OleLoadPictureEx (OLEAUT32.401)
|
2001-04-10 23:17:04 +02:00
|
|
|
*/
|
|
|
|
HRESULT WINAPI OleLoadPictureEx( LPSTREAM lpstream, LONG lSize, BOOL fRunmode,
|
2002-11-11 20:54:22 +01:00
|
|
|
REFIID riid, DWORD xsiz, DWORD ysiz, DWORD flags, LPVOID *ppvObj )
|
2001-04-10 23:17:04 +02:00
|
|
|
{
|
2002-11-11 20:54:22 +01:00
|
|
|
LPPERSISTSTREAM ps;
|
|
|
|
IPicture *newpic;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2006-10-12 20:57:10 +02:00
|
|
|
FIXME("(%p,%d,%d,%s,x=%d,y=%d,f=%x,%p), partially implemented.\n",
|
2002-11-11 20:54:22 +01:00
|
|
|
lpstream, lSize, fRunmode, debugstr_guid(riid), xsiz, ysiz, flags, ppvObj);
|
|
|
|
|
|
|
|
hr = OleCreatePictureIndirect(NULL,riid,!fRunmode,(LPVOID*)&newpic);
|
|
|
|
if (hr)
|
|
|
|
return hr;
|
|
|
|
hr = IPicture_QueryInterface(newpic,&IID_IPersistStream, (LPVOID*)&ps);
|
|
|
|
if (hr) {
|
2008-10-16 11:20:45 +02:00
|
|
|
ERR("Could not get IPersistStream iface from Ole Picture?\n");
|
2002-11-11 20:54:22 +01:00
|
|
|
IPicture_Release(newpic);
|
|
|
|
*ppvObj = NULL;
|
|
|
|
return hr;
|
|
|
|
}
|
2008-10-04 01:24:37 +02:00
|
|
|
hr = IPersistStream_Load(ps,lpstream);
|
2002-11-11 20:54:22 +01:00
|
|
|
IPersistStream_Release(ps);
|
2008-10-04 01:24:37 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ERR("IPersistStream_Load failed\n");
|
|
|
|
IPicture_Release(newpic);
|
|
|
|
*ppvObj = NULL;
|
|
|
|
return hr;
|
|
|
|
}
|
2002-11-11 20:54:22 +01:00
|
|
|
hr = IPicture_QueryInterface(newpic,riid,ppvObj);
|
|
|
|
if (hr)
|
2008-10-16 11:20:45 +02:00
|
|
|
ERR("Failed to get interface %s from IPicture.\n",debugstr_guid(riid));
|
2002-11-11 20:54:22 +01:00
|
|
|
IPicture_Release(newpic);
|
|
|
|
return hr;
|
2001-04-10 23:17:04 +02:00
|
|
|
}
|
2003-01-02 18:54:57 +01:00
|
|
|
|
2005-02-21 19:36:06 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* OleLoadPicturePath (OLEAUT32.424)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI OleLoadPicturePath( LPOLESTR szURLorPath, LPUNKNOWN punkCaller,
|
|
|
|
DWORD dwReserved, OLE_COLOR clrReserved, REFIID riid,
|
|
|
|
LPVOID *ppvRet )
|
|
|
|
{
|
2005-03-04 13:30:26 +01:00
|
|
|
static const WCHAR file[] = { 'f','i','l','e',':','/','/',0 };
|
|
|
|
IPicture *ipicture;
|
|
|
|
HANDLE hFile;
|
|
|
|
DWORD dwFileSize;
|
|
|
|
HGLOBAL hGlobal = NULL;
|
|
|
|
DWORD dwBytesRead = 0;
|
|
|
|
IStream *stream;
|
|
|
|
BOOL bRead;
|
|
|
|
IPersistStream *pStream;
|
|
|
|
HRESULT hRes;
|
|
|
|
|
2006-10-12 20:57:10 +02:00
|
|
|
TRACE("(%s,%p,%d,%08x,%s,%p): stub\n",
|
2005-02-21 19:36:06 +01:00
|
|
|
debugstr_w(szURLorPath), punkCaller, dwReserved, clrReserved,
|
|
|
|
debugstr_guid(riid), ppvRet);
|
|
|
|
|
2005-03-04 13:30:26 +01:00
|
|
|
if (!ppvRet) return E_POINTER;
|
|
|
|
|
|
|
|
if (strncmpW(szURLorPath, file, 7) == 0) {
|
|
|
|
szURLorPath += 7;
|
|
|
|
|
|
|
|
hFile = CreateFileW(szURLorPath, GENERIC_READ, 0, NULL, OPEN_EXISTING,
|
|
|
|
0, NULL);
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
|
|
|
dwFileSize = GetFileSize(hFile, NULL);
|
|
|
|
if (dwFileSize != INVALID_FILE_SIZE )
|
|
|
|
{
|
|
|
|
hGlobal = GlobalAlloc(GMEM_FIXED,dwFileSize);
|
|
|
|
if ( hGlobal)
|
|
|
|
{
|
|
|
|
bRead = ReadFile(hFile, hGlobal, dwFileSize, &dwBytesRead, NULL);
|
|
|
|
if (!bRead)
|
|
|
|
{
|
|
|
|
GlobalFree(hGlobal);
|
|
|
|
hGlobal = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CloseHandle(hFile);
|
|
|
|
|
|
|
|
if (!hGlobal)
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
|
|
|
hRes = CreateStreamOnHGlobal(hGlobal, TRUE, &stream);
|
|
|
|
if (FAILED(hRes))
|
|
|
|
{
|
|
|
|
GlobalFree(hGlobal);
|
|
|
|
return hRes;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
IMoniker *pmnk;
|
|
|
|
IBindCtx *pbc;
|
|
|
|
|
|
|
|
hRes = CreateBindCtx(0, &pbc);
|
|
|
|
if (SUCCEEDED(hRes))
|
|
|
|
{
|
|
|
|
hRes = CreateURLMoniker(NULL, szURLorPath, &pmnk);
|
|
|
|
if (SUCCEEDED(hRes))
|
|
|
|
{
|
|
|
|
hRes = IMoniker_BindToStorage(pmnk, pbc, NULL, &IID_IStream, (LPVOID*)&stream);
|
|
|
|
IMoniker_Release(pmnk);
|
|
|
|
}
|
|
|
|
IBindCtx_Release(pbc);
|
|
|
|
}
|
|
|
|
if (FAILED(hRes))
|
|
|
|
return hRes;
|
|
|
|
}
|
|
|
|
|
|
|
|
hRes = CoCreateInstance(&CLSID_StdPicture, punkCaller, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IPicture, (LPVOID*)&ipicture);
|
|
|
|
if (hRes != S_OK) {
|
|
|
|
IStream_Release(stream);
|
|
|
|
return hRes;
|
|
|
|
}
|
|
|
|
|
|
|
|
hRes = IPicture_QueryInterface(ipicture, &IID_IPersistStream, (LPVOID*)&pStream);
|
|
|
|
if (hRes) {
|
|
|
|
IStream_Release(stream);
|
|
|
|
IPicture_Release(ipicture);
|
|
|
|
return hRes;
|
|
|
|
}
|
|
|
|
|
|
|
|
hRes = IPersistStream_Load(pStream, stream);
|
|
|
|
IPersistStream_Release(pStream);
|
|
|
|
IStream_Release(stream);
|
|
|
|
|
|
|
|
if (hRes) {
|
|
|
|
IPicture_Release(ipicture);
|
|
|
|
return hRes;
|
|
|
|
}
|
|
|
|
|
|
|
|
hRes = IPicture_QueryInterface(ipicture,riid,ppvRet);
|
|
|
|
if (hRes)
|
2008-10-16 11:20:45 +02:00
|
|
|
ERR("Failed to get interface %s from IPicture.\n",debugstr_guid(riid));
|
2005-03-04 13:30:26 +01:00
|
|
|
|
|
|
|
IPicture_Release(ipicture);
|
|
|
|
return hRes;
|
2005-02-21 19:36:06 +01:00
|
|
|
}
|
|
|
|
|
2003-01-02 18:54:57 +01:00
|
|
|
/*******************************************************************************
|
|
|
|
* StdPic ClassFactory
|
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
/* IUnknown fields */
|
2005-06-06 21:50:35 +02:00
|
|
|
const IClassFactoryVtbl *lpVtbl;
|
2005-07-11 12:25:19 +02:00
|
|
|
LONG ref;
|
2003-01-02 18:54:57 +01:00
|
|
|
} IClassFactoryImpl;
|
|
|
|
|
|
|
|
static HRESULT WINAPI
|
|
|
|
SPCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
|
2004-09-09 23:03:58 +02:00
|
|
|
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
|
2003-01-02 18:54:57 +01:00
|
|
|
|
|
|
|
FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI
|
|
|
|
SPCF_AddRef(LPCLASSFACTORY iface) {
|
2004-09-09 23:03:58 +02:00
|
|
|
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
|
2004-09-21 02:25:03 +02:00
|
|
|
return InterlockedIncrement(&This->ref);
|
2003-01-02 18:54:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI SPCF_Release(LPCLASSFACTORY iface) {
|
2004-09-09 23:03:58 +02:00
|
|
|
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
|
2003-01-02 18:54:57 +01:00
|
|
|
/* static class, won't be freed */
|
2004-09-21 02:25:03 +02:00
|
|
|
return InterlockedDecrement(&This->ref);
|
2003-01-02 18:54:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI SPCF_CreateInstance(
|
|
|
|
LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
|
|
|
|
) {
|
2005-03-04 13:30:26 +01:00
|
|
|
/* Creates an uninitialized picture */
|
|
|
|
return OleCreatePictureIndirect(NULL,riid,TRUE,ppobj);
|
2003-01-02 18:54:57 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI SPCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
|
2004-09-09 23:03:58 +02:00
|
|
|
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
|
2003-01-02 18:54:57 +01:00
|
|
|
FIXME("(%p)->(%d),stub!\n",This,dolock);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IClassFactoryVtbl SPCF_Vtbl = {
|
2003-01-02 18:54:57 +01:00
|
|
|
SPCF_QueryInterface,
|
|
|
|
SPCF_AddRef,
|
|
|
|
SPCF_Release,
|
|
|
|
SPCF_CreateInstance,
|
|
|
|
SPCF_LockServer
|
|
|
|
};
|
|
|
|
static IClassFactoryImpl STDPIC_CF = {&SPCF_Vtbl, 1 };
|
|
|
|
|
2009-02-09 09:45:52 +01:00
|
|
|
void _get_STDPIC_CF(LPVOID *ppv) { *ppv = &STDPIC_CF; }
|