Commit 520d1bc5 authored by Alexandre Julliard's avatar Alexandre Julliard

winemenubuilder: Copy the icon data before modifying it, resources are read-only.

parent 12de7d75
......@@ -201,8 +201,8 @@ static BOOL SaveIconResAsPNG(const BITMAPINFO *pIcon, const char *png_filename,
png_infop info_ptr;
png_text comment;
int nXORWidthBytes, nANDWidthBytes, color_type = 0, i, j;
BYTE *pXOR, *row;
const BYTE *pAND = NULL;
BYTE *row, *copy = NULL;
const BYTE *pXOR, *pAND = NULL;
int nWidth = pIcon->bmiHeader.biWidth;
int nHeight = pIcon->bmiHeader.biHeight;
int nBpp = pIcon->bmiHeader.biBitCount;
......@@ -233,21 +233,26 @@ static BOOL SaveIconResAsPNG(const BITMAPINFO *pIcon, const char *png_filename,
nXORWidthBytes = 4 * ((nWidth * nBpp + 31) / 32);
nANDWidthBytes = 4 * ((nWidth + 31 ) / 32);
pXOR = (BYTE*) pIcon + sizeof(BITMAPINFOHEADER) + pIcon->bmiHeader.biClrUsed * sizeof(RGBQUAD);
pXOR = (const BYTE*) pIcon + sizeof(BITMAPINFOHEADER) + pIcon->bmiHeader.biClrUsed * sizeof(RGBQUAD);
if (nHeight > nWidth)
{
nHeight /= 2;
pAND = pXOR + nHeight * nXORWidthBytes;
}
/* image and mask are upside down reversed */
row = pXOR + (nHeight - 1) * nXORWidthBytes;
/* Apply mask if present */
if (pAND)
{
RGBQUAD bgColor;
/* copy bytes before modifying them */
copy = HeapAlloc( GetProcessHeap(), 0, nHeight * nXORWidthBytes );
memcpy( copy, pXOR, nHeight * nXORWidthBytes );
pXOR = copy;
/* image and mask are upside down reversed */
row = copy + (nHeight - 1) * nXORWidthBytes;
/* top left corner */
bgColor.rgbRed = row[0];
bgColor.rgbGreen = row[1];
......@@ -306,6 +311,7 @@ static BOOL SaveIconResAsPNG(const BITMAPINFO *pIcon, const char *png_filename,
ppng_destroy_write_struct(&png_ptr, &info_ptr);
if (png_ptr) ppng_destroy_write_struct(&png_ptr, NULL);
fclose(fp);
HeapFree(GetProcessHeap(), 0, copy);
HeapFree(GetProcessHeap(), 0, comment.text);
return TRUE;
......@@ -313,6 +319,7 @@ static BOOL SaveIconResAsPNG(const BITMAPINFO *pIcon, const char *png_filename,
if (png_ptr) ppng_destroy_write_struct(&png_ptr, NULL);
fclose(fp);
unlink(png_filename);
HeapFree(GetProcessHeap(), 0, copy);
HeapFree(GetProcessHeap(), 0, comment.text);
return FALSE;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment