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

Huw Davies huw at codeweavers.com
Thu Mar 29 06:03:19 CDT 2018


On Tue, Mar 27, 2018 at 11:39:59AM -0500, Sergio Gómez Del Real wrote:
> Signed-off-by: Sergio Gómez Del Real <sdelreal at codeweavers.com>
> ---
>  dlls/ole32/datacache.c | 62 +++++++++++++++++++++++++++++++++++---------------
>  1 file changed, 44 insertions(+), 18 deletions(-)
> 
> diff --git a/dlls/ole32/datacache.c b/dlls/ole32/datacache.c
> index e511eac23e..673f690934 100644
> --- a/dlls/ole32/datacache.c
> +++ b/dlls/ole32/datacache.c
> @@ -571,6 +571,18 @@ static HRESULT synthesize_emf( HMETAFILEPICT data, STGMEDIUM *med )
>      return hr;
>  }
>  
> +static HRESULT read_pres_header( IStream *stm, void *pres_hdr )
> +{

Having a void * here rings alarm bells.  You probably want something like

read_pres_header( IStream *, DWORD *clip_format, PresentationDataHeader *)


> +    ULONG read, pres_hdr_size;
> +    HRESULT hr;
> +
> +    pres_hdr_size = sizeof(PresentationDataHeader) + sizeof(DWORD) * 2;
> +    hr = IStream_Read( stm, pres_hdr, pres_hdr_size, &read );
> +    if (hr != S_OK || read != pres_hdr_size) return E_FAIL;
> +
> +    return S_OK;
> +}
> +
>  static HRESULT load_mf_pict( DataCacheEntry *cache_entry, IStream *stm )
>  {
>      HRESULT hr;
> @@ -650,32 +662,42 @@ static HRESULT load_dib( DataCacheEntry *cache_entry, IStream *stm )
>      void *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;
> -    }
> +    /* only standard clipformats */
> +    struct {
> +        DWORD cf[2];
> +        PresentationDataHeader pres;
> +    } pres_hdr;
> +    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_hdr)) return E_FAIL;
> +        hr = read_pres_header( stm, &pres_hdr );
> +        if (FAILED( hr )) return hr;
> +        stat.cbSize.QuadPart -= sizeof(pres_hdr);
> +    }
> +    else
> +    {
> +        if (stat.cbSize.QuadPart < sizeof(BITMAPFILEHEADER)) return E_FAIL;
> +        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;
>  
> +    /* read rest of BITMAPINFOHEADER */
>      hr = IStream_Read( stm, (char *)dib + sizeof(DWORD), bi_size - sizeof(DWORD), &read );
>      if (hr != S_OK || read != bi_size - sizeof(DWORD)) goto fail;
>  
> @@ -688,15 +710,19 @@ static HRESULT load_dib( DataCacheEntry *cache_entry, IStream *stm )
>      }
>      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)
>      {
> -        LARGE_INTEGER skip;
> +        if (file.bfOffBits)

There's not need for two if()s here just combine them with an &&.

As a bonus the indentation of the block won't change, so your patch
will be smaller.

> +        {
> +            LARGE_INTEGER skip;
>  
> -        skip.QuadPart = file.bfOffBits - sizeof(file) - info_size;
> -        if (stat.cbSize.QuadPart < skip.QuadPart) goto fail;
> -        hr = IStream_Seek( stm, skip, STREAM_SEEK_CUR, NULL );
> -        if (hr != S_OK) goto fail;
> -        stat.cbSize.QuadPart -= skip.QuadPart;
> +            skip.QuadPart = file.bfOffBits - sizeof(file) - info_size;
> +            if (stat.cbSize.QuadPart < skip.QuadPart) goto fail;
> +            hr = IStream_Seek( stm, skip, STREAM_SEEK_CUR, NULL );
> +            if (hr != S_OK) goto fail;
> +            stat.cbSize.QuadPart -= skip.QuadPart;
> +        }
>      }
>  
>      hr = IStream_Read( stm, (char *)dib + info_size, stat.cbSize.u.LowPart, &read );


This function is becoming hard to follow, let's see if those changes
help or whether we need to be more surgical.



More information about the wine-devel mailing list