[4/5] winemenubuilder: use windowscodecs for all ICO to PNG conversion

Damjan Jovanovic damjan.jov at gmail.com
Sat May 22 10:59:30 CDT 2010


Changelog:
* winemenubuilder: use windowscodecs for all ICO to PNG conversion

Damjan Jovanovic
-------------- next part --------------
--- a/programs/winemenubuilder/winemenubuilder.c	2010-05-22 16:19:56.247779022 +0200
+++ b/programs/winemenubuilder/winemenubuilder.c	2010-05-22 17:19:34.472734923 +0200
@@ -750,6 +750,64 @@
     return FALSE;
 }
 
+static BOOL reassemble_and_save_to_png(GRPICONDIRENTRY *grpIconDirEntry, BITMAPINFO *pIcon,
+    const char *pngFileName, LPCWSTR commentW)
+{
+    SIZE_T size;
+    HGLOBAL hGlobal = NULL;
+    IStream *stream = NULL;
+    char *p;
+    ICONDIR *pIconDir;
+    ICONDIRENTRY *pIconDirEntry;
+    HRESULT hr = E_FAIL;
+    
+    size = sizeof(ICONDIR) + sizeof(ICONDIRENTRY) + grpIconDirEntry->dwBytesInRes;
+    hGlobal = GlobalAlloc(GMEM_MOVEABLE, size);
+    if (hGlobal == NULL)
+    {
+        WINE_ERR("out of memory allocating icon\n");
+        goto end;
+    }
+    
+    p = GlobalLock(hGlobal);
+    pIconDir = (ICONDIR*)p;
+    pIconDir->idReserved = 0;
+    pIconDir->idType = 1;
+    pIconDir->idCount = 1;
+    p += sizeof(ICONDIR);
+    pIconDirEntry = (ICONDIRENTRY*)p;
+    pIconDirEntry->bWidth = grpIconDirEntry->bWidth;
+    pIconDirEntry->bHeight = grpIconDirEntry->bHeight;
+    pIconDirEntry->bColorCount = grpIconDirEntry->bColorCount;
+    pIconDirEntry->bReserved = grpIconDirEntry->bReserved;
+    pIconDirEntry->wPlanes = grpIconDirEntry->wPlanes;
+    pIconDirEntry->wBitCount = grpIconDirEntry->wBitCount;
+    pIconDirEntry->dwBytesInRes = grpIconDirEntry->dwBytesInRes;
+    pIconDirEntry->dwImageOffset = sizeof(ICONDIR) + sizeof(ICONDIRENTRY);
+    p += sizeof(ICONDIRENTRY);
+    memcpy(p, pIcon, grpIconDirEntry->dwBytesInRes);
+    GlobalUnlock(hGlobal);
+    
+    hr = CreateStreamOnHGlobal(hGlobal, FALSE, &stream);
+    if (FAILED(hr))
+    {
+        WINE_ERR("could not create stream on icon hglobal, error 0x%08X\n", hr);
+        goto end;
+    }
+    
+    if (SaveIconStreamAsPNG(stream, 0, pngFileName, commentW))
+        hr = S_OK;
+    else
+        hr = E_FAIL;
+    
+end:
+    if (hGlobal)
+        GlobalFree(hGlobal);
+    if (stream)
+        IStream_Release(stream);
+    return SUCCEEDED(hr);
+}
+
 static BOOL CALLBACK EnumResNameProc(HMODULE hModule, LPCWSTR lpszType, LPWSTR lpszName, LONG_PTR lParam)
 {
     ENUMRESSTRUCT *sEnumRes = (ENUMRESSTRUCT *) lParam;
@@ -774,6 +832,7 @@
     ENUMRESSTRUCT sEnumRes;
     int nMax = 0;
     int nMaxBits = 0;
+    GRPICONDIRENTRY iconDirEntry = {0};
     int i;
     BOOL ret = FALSE;
 
@@ -819,6 +878,7 @@
 			    lpName = MAKEINTRESOURCEW(pIconDir->idEntries[i].nID);
 			    nMax = pIconDir->idEntries[i].bHeight * pIconDir->idEntries[i].bWidth;
 			    nMaxBits = pIconDir->idEntries[i].wBitCount;
+			    iconDirEntry = pIconDir->idEntries[i];
 			}
 		    }		    
                 }
@@ -840,11 +900,9 @@
         {
             if ((pIcon = LockResource(hResData)))
             {
-#ifdef SONAME_LIBPNG
-                if (SaveIconResAsPNG(pIcon, szXPMFileName, szFileName))
+                if (reassemble_and_save_to_png(&iconDirEntry, pIcon, szXPMFileName, szFileName))
                     ret = TRUE;
                 else
-#endif
                 {
                     memcpy(szXPMFileName + strlen(szXPMFileName) - 3, "xpm", 3);
                     if (SaveIconResAsXPM(pIcon, szXPMFileName, szFileName))


More information about the wine-patches mailing list