CPatch: New memory management
[TortoiseGit.git] / src / Utils / IconExtractor.h
blob588d071b002f43623b6a66bac2c8d132c50e099c
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2010, 2014 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #pragma once
21 // The following structures are taken from iconpro sdk example
22 #pragma pack(push)
23 #pragma pack(2)
24 typedef struct
26 BYTE bWidth; // Width of the image
27 BYTE bHeight; // Height of the image (times 2)
28 BYTE bColorCount; // Number of colors in image (0 if >=8bpp)
29 BYTE bReserved; // Reserved
30 WORD wPlanes; // Color Planes
31 WORD wBitCount; // Bits per pixel
32 DWORD dwBytesInRes; // how many bytes in this resource?
33 WORD nID; // the ID
34 } MEMICONDIRENTRY, *LPMEMICONDIRENTRY;
35 typedef struct
37 WORD idReserved; // Reserved
38 WORD idType; // resource type (1 for icons)
39 WORD idCount; // how many images?
40 MEMICONDIRENTRY idEntries[1]; // the entries for each image
41 } MEMICONDIR, *LPMEMICONDIR;
42 #pragma pack(pop)
44 typedef struct
46 UINT Width, Height, Colors; // Width, Height and bpp
47 LPBYTE lpBits; // ptr to DIB bits
48 DWORD dwNumBytes; // how many bytes?
49 LPBITMAPINFO lpbi; // ptr to header
50 LPBYTE lpXOR; // ptr to XOR image bits
51 LPBYTE lpAND; // ptr to AND image bits
52 } ICONIMAGE, *LPICONIMAGE;
53 typedef struct
55 BOOL bHasChanged; // Has image changed?
56 UINT nNumImages; // How many images?
57 ICONIMAGE IconImages[1]; // Image entries
58 } ICONRESOURCE, *LPICONRESOURCE;
61 // These next two structs represent how the icon information is stored
62 // in an ICO file.
63 typedef struct
65 BYTE bWidth; // Width of the image
66 BYTE bHeight; // Height of the image (times 2)
67 BYTE bColorCount; // Number of colors in image (0 if >=8bpp)
68 BYTE bReserved; // Reserved
69 WORD wPlanes; // Color Planes
70 WORD wBitCount; // Bits per pixel
71 DWORD dwBytesInRes; // how many bytes in this resource?
72 DWORD dwImageOffset; // where in the file is this image
73 } ICONDIRENTRY, *LPICONDIRENTRY;
74 typedef struct
76 WORD idReserved; // Reserved
77 WORD idType; // resource type (1 for icons)
78 WORD idCount; // how many images?
79 ICONDIRENTRY idEntries[1]; // the entries for each image
80 } ICONDIR, *LPICONDIR;
83 class CIconExtractor
85 public:
86 CIconExtractor();
88 DWORD ExtractIcon(HINSTANCE hResource, LPCTSTR id, LPCTSTR TargetICON);
90 private:
91 DWORD WriteIconToICOFile(LPICONRESOURCE lpIR, LPCTSTR szFileName);
92 BOOL AdjustIconImagePointers(LPICONIMAGE lpImage);
94 LPSTR FindDIBBits(LPSTR lpbi);
95 WORD DIBNumColors(LPSTR lpbi) const;
96 WORD PaletteSize(LPSTR lpbi);
97 DWORD BytesPerLine(LPBITMAPINFOHEADER lpBMIH) const;
98 DWORD WriteICOHeader(HANDLE hFile, UINT nNumEntries) const;
99 DWORD CalculateImageOffset(LPICONRESOURCE lpIR, UINT nIndex) const;