[PATCH v3 2/5] ole32: Add support for loading dibs from presentation streams to data cache.

Huw Davies huw at codeweavers.com
Thu Apr 5 13:57:44 CDT 2018


> On 5 Apr 2018, at 14:05, Sergio Gómez Del Real <sdelreal at codeweavers.com> wrote:
> 
> Signed-off-by: Sergio Gómez Del Real <sdelreal at codeweavers.com>
> ---
> dlls/ole32/datacache.c | 43 ++++++++++++++++++++++++++-----------------
> 1 file changed, 26 insertions(+), 17 deletions(-)
> 
> diff --git a/dlls/ole32/datacache.c b/dlls/ole32/datacache.c
> index 3d97473c10..2678c3ff06 100644
> --- a/dlls/ole32/datacache.c
> +++ b/dlls/ole32/datacache.c
> @@ -686,48 +686,57 @@ static HRESULT load_dib( DataCacheEntry *cache_entry, IStream *stm )
> {
>     HRESULT hr;
>     STATSTG stat;
> -    void *dib;
> +    BYTE *dib;
>     HGLOBAL hglobal;
>     ULONG read, info_size, bi_size;
> -    BITMAPFILEHEADER file;
>     BITMAPINFOHEADER *info;
> -
> -    if (cache_entry->load_stream_num != STREAM_NUMBER_CONTENTS)
> -    {
> -        FIXME( "Unimplemented for presentation stream\n" );
> -        return E_FAIL;
> -    }
> +    CLIPFORMAT cf[4];

Why cf[4]? There’s only one clip format.


> +    PresentationDataHeader pres;
> +    BITMAPFILEHEADER file;
> 
>     hr = IStream_Stat( stm, &stat, STATFLAG_NONAME );
>     if (FAILED( hr )) return hr;
> 
> -    if (stat.cbSize.QuadPart < sizeof(file) + sizeof(DWORD)) return E_FAIL;
> -    hr = IStream_Read( stm, &file, sizeof(file), &read );
> -    if (hr != S_OK || read != sizeof(file)) return E_FAIL;
> -    stat.cbSize.QuadPart -= sizeof(file);
> +    if (cache_entry->load_stream_num != STREAM_NUMBER_CONTENTS)
> +    {
> +        if (stat.cbSize.QuadPart < sizeof(pres) + sizeof(cf)) return E_FAIL;

You could remove this size check (it’s not right anyway) and rely on
read_clipformat() failing or the following Read() to return fewer than
sizeof(pres) bytes to indicate a small stream.  You would then call
Seek() to return the current pos and subtract that from stat.cbSize.
See how it’s done in load_mfpict().

> +        hr = read_clipformat( stm, cf );
> +        if (FAILED( hr )) return hr;
> +        hr = IStream_Read( stm, &pres, sizeof(pres), &read );
> +        stat.cbSize.QuadPart -= sizeof(pres) + sizeof(cf);
> +    }
> +    else
> +    {
> +        if (stat.cbSize.QuadPart < sizeof(BITMAPFILEHEADER)) return E_FAIL;

Similarly this could go and check read == sizeof(BITMAPFILEHEADER).

> +        hr = IStream_Read( stm, &file, sizeof(BITMAPFILEHEADER), &read );
> +        stat.cbSize.QuadPart -= sizeof(BITMAPFILEHEADER);
> +    }
> 
>     hglobal = GlobalAlloc( GMEM_MOVEABLE, stat.cbSize.u.LowPart );
>     if (!hglobal) return E_OUTOFMEMORY;
>     dib = GlobalLock( hglobal );
> 
> +    /* read first DWORD of BITMAPINFOHEADER */
>     hr = IStream_Read( stm, dib, sizeof(DWORD), &read );
>     if (hr != S_OK || read != sizeof(DWORD)) goto fail;
>     bi_size = *(DWORD *)dib;
>     if (stat.cbSize.QuadPart < bi_size) goto fail;
> 
> -    hr = IStream_Read( stm, (char *)dib + sizeof(DWORD), bi_size - sizeof(DWORD), &read );
> +    /* read rest of BITMAPINFOHEADER */
> +    hr = IStream_Read( stm, dib + sizeof(DWORD), bi_size - sizeof(DWORD), &read );
>     if (hr != S_OK || read != bi_size - sizeof(DWORD)) goto fail;
> 
> -    info_size = bitmap_info_size( dib, DIB_RGB_COLORS );
> +    info_size = bitmap_info_size( (BITMAPINFO *)dib, DIB_RGB_COLORS );
>     if (stat.cbSize.QuadPart < info_size) goto fail;
>     if (info_size > bi_size)
>     {
> -        hr = IStream_Read( stm, (char *)dib + bi_size, info_size - bi_size, &read );
> +        hr = IStream_Read( stm, dib + bi_size, info_size - bi_size, &read );
>         if (hr != S_OK || read != info_size - bi_size) goto fail;
>     }
>     stat.cbSize.QuadPart -= info_size;
> 
> -    if (file.bfOffBits)
> +    /* set Stream pointer to beginning of bitmap bits */
> +    if (cache_entry->load_stream_num == STREAM_NUMBER_CONTENTS && file.bfOffBits)
>     {
>         LARGE_INTEGER skip;
> 
> @@ -738,7 +747,7 @@ static HRESULT load_dib( DataCacheEntry *cache_entry, IStream *stm )
>         stat.cbSize.QuadPart -= skip.QuadPart;
>     }
> 
> -    hr = IStream_Read( stm, (char *)dib + info_size, stat.cbSize.u.LowPart, &read );
> +    hr = IStream_Read( stm, dib + info_size, stat.cbSize.u.LowPart, &read );
>     if (hr != S_OK || read != stat.cbSize.QuadPart) goto fail;
> 
>     if (bi_size >= sizeof(*info))
> -- 
> 2.14.1
> 
> 
> 




More information about the wine-devel mailing list