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

This commit is contained in:
Alexandre Julliard 2008-05-13 20:26:57 +02:00
parent 12de7d7591
commit 520d1bc5e4
1 changed files with 13 additions and 6 deletions

View File

@ -201,8 +201,8 @@ static BOOL SaveIconResAsPNG(const BITMAPINFO *pIcon, const char *png_filename,
png_infop info_ptr; png_infop info_ptr;
png_text comment; png_text comment;
int nXORWidthBytes, nANDWidthBytes, color_type = 0, i, j; int nXORWidthBytes, nANDWidthBytes, color_type = 0, i, j;
BYTE *pXOR, *row; BYTE *row, *copy = NULL;
const BYTE *pAND = NULL; const BYTE *pXOR, *pAND = NULL;
int nWidth = pIcon->bmiHeader.biWidth; int nWidth = pIcon->bmiHeader.biWidth;
int nHeight = pIcon->bmiHeader.biHeight; int nHeight = pIcon->bmiHeader.biHeight;
int nBpp = pIcon->bmiHeader.biBitCount; 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); nXORWidthBytes = 4 * ((nWidth * nBpp + 31) / 32);
nANDWidthBytes = 4 * ((nWidth + 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) if (nHeight > nWidth)
{ {
nHeight /= 2; nHeight /= 2;
pAND = pXOR + nHeight * nXORWidthBytes; pAND = pXOR + nHeight * nXORWidthBytes;
} }
/* image and mask are upside down reversed */
row = pXOR + (nHeight - 1) * nXORWidthBytes;
/* Apply mask if present */ /* Apply mask if present */
if (pAND) if (pAND)
{ {
RGBQUAD bgColor; 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 */ /* top left corner */
bgColor.rgbRed = row[0]; bgColor.rgbRed = row[0];
bgColor.rgbGreen = row[1]; 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); ppng_destroy_write_struct(&png_ptr, &info_ptr);
if (png_ptr) ppng_destroy_write_struct(&png_ptr, NULL); if (png_ptr) ppng_destroy_write_struct(&png_ptr, NULL);
fclose(fp); fclose(fp);
HeapFree(GetProcessHeap(), 0, copy);
HeapFree(GetProcessHeap(), 0, comment.text); HeapFree(GetProcessHeap(), 0, comment.text);
return TRUE; 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); if (png_ptr) ppng_destroy_write_struct(&png_ptr, NULL);
fclose(fp); fclose(fp);
unlink(png_filename); unlink(png_filename);
HeapFree(GetProcessHeap(), 0, copy);
HeapFree(GetProcessHeap(), 0, comment.text); HeapFree(GetProcessHeap(), 0, comment.text);
return FALSE; return FALSE;
} }