Skip to content

Commit

Permalink
[COMCTL32] fix version number reading/writing image lists and countin…
Browse files Browse the repository at this point in the history
…g pointers for mixing image & mask
  • Loading branch information
Getequ committed Jun 22, 2018
1 parent e01f935 commit 1bbcd42
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions dll/win32/comctl32/imagelist.c
Expand Up @@ -80,9 +80,12 @@ struct _IMAGELIST
BOOL color_table_set;

LONG ref; /* reference count */

USHORT usVersion; /* hack for IL from stream. Keep version here */
};

#define IMAGELIST_MAGIC 0x53414D58
#define IMAGELIST_VERSION 0x101

/* Header used by ImageList_Read() and ImageList_Write() */
#include "pshpack2.h"
Expand Down Expand Up @@ -806,6 +809,7 @@ ImageList_Create (INT cx, INT cy, UINT flags,
himl->clrFg = CLR_DEFAULT;
himl->clrBk = CLR_NONE;
himl->color_table_set = FALSE;
himl->usVersion = 0;

/* initialize overlay mask indices */
for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
Expand Down Expand Up @@ -2375,7 +2379,9 @@ HIMAGELIST WINAPI ImageList_Read(IStream *pstm)
return NULL;
if (ilHead.usMagic != (('L' << 8) | 'I'))
return NULL;
if (ilHead.usVersion != 0x101) /* probably version? */
if (ilHead.usVersion != IMAGELIST_VERSION &&
ilHead.usVersion != 0x600 && /* XP/2003 version */
ilHead.usVersion != 0x620) /* Vista/7 version */
return NULL;

TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
Expand All @@ -2385,6 +2391,9 @@ HIMAGELIST WINAPI ImageList_Read(IStream *pstm)
if (!himl)
return NULL;

/* keep version from stream */
himl->usVersion = ilHead.usVersion;

if (!(image_bits = read_bitmap(pstm, image_info)))
{
WARN("failed to read bitmap from stream\n");
Expand All @@ -2404,23 +2413,25 @@ HIMAGELIST WINAPI ImageList_Read(IStream *pstm)
{
DWORD *ptr = image_bits;
BYTE *mask_ptr = mask_bits;
int stride = himl->cy * image_info->bmiHeader.biWidth;
int stride = himl->cy * (ilHead.usVersion != IMAGELIST_VERSION ? himl->cx : image_info->bmiHeader.biWidth);
int image_step = ilHead.usVersion != IMAGELIST_VERSION ? 1 : TILE_COUNT;
int mask_step = ilHead.usVersion != IMAGELIST_VERSION ? 4 : 8;

if (image_info->bmiHeader.biHeight > 0) /* bottom-up */
{
ptr += image_info->bmiHeader.biHeight * image_info->bmiHeader.biWidth - stride;
mask_ptr += (image_info->bmiHeader.biHeight * image_info->bmiHeader.biWidth - stride) / 8;
mask_ptr += (image_info->bmiHeader.biHeight * image_info->bmiHeader.biWidth - stride) / mask_step;
stride = -stride;
image_info->bmiHeader.biHeight = himl->cy;
}
else image_info->bmiHeader.biHeight = -himl->cy;

for (i = 0; i < ilHead.cCurImage; i += TILE_COUNT)
for (i = 0; i < ilHead.cCurImage; i += image_step)
{
add_dib_bits( himl, i, min( ilHead.cCurImage - i, TILE_COUNT ),
add_dib_bits( himl, i, min( ilHead.cCurImage - i, image_step ),
himl->cx, himl->cy, image_info, mask_info, ptr, mask_ptr );
ptr += stride;
mask_ptr += stride / 8;
mask_ptr += stride / mask_step;
}
}
else
Expand Down

0 comments on commit 1bbcd42

Please sign in to comment.