Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/FreeImage/PluginICO.cpp view on Meta::CPAN
#pragma pack()
#endif
// ==========================================================
// Static helpers
// ==========================================================
/** How wide, in bytes, would this many bits be, DWORD aligned ?
*/
static int
WidthBytes(int bits) {
return ((((bits) + 31)>>5)<<2);
}
/** Calculates the size of a single icon image
@return Returns the size for that image
*/
static DWORD
CalculateImageSize(FIBITMAP* icon_dib) {
DWORD dwNumBytes = 0;
unsigned colors = FreeImage_GetColorsUsed(icon_dib);
unsigned width = FreeImage_GetWidth(icon_dib);
unsigned height = FreeImage_GetHeight(icon_dib);
unsigned pitch = FreeImage_GetPitch(icon_dib);
dwNumBytes = sizeof( BITMAPINFOHEADER ); // header
dwNumBytes += colors * sizeof(RGBQUAD); // palette
dwNumBytes += height * pitch; // XOR mask
dwNumBytes += height * WidthBytes(width); // AND mask
return dwNumBytes;
}
/** Calculates the file offset for an icon image
@return Returns the file offset for that image
*/
static DWORD
CalculateImageOffset(std::vector<FIBITMAP*>& vPages, int nIndex ) {
DWORD dwSize;
// calculate the ICO header size
dwSize = sizeof(ICONHEADER);
// add the ICONDIRENTRY's
dwSize += (DWORD)( vPages.size() * sizeof(ICONDIRENTRY) );
// add the sizes of the previous images
for(int k = 0; k < nIndex; k++) {
FIBITMAP *icon_dib = (FIBITMAP*)vPages[k];
dwSize += CalculateImageSize(icon_dib);
}
return dwSize;
}
/**
Vista icon support
@return Returns TRUE if the bitmap data is stored in PNG format
*/
static BOOL
IsPNG(FreeImageIO *io, fi_handle handle) {
BYTE png_signature[8] = { 137, 80, 78, 71, 13, 10, 26, 10 };
BYTE signature[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
long tell = io->tell_proc(handle);
io->read_proc(&signature, 1, 8, handle);
BOOL bIsPNG = (memcmp(png_signature, signature, 8) == 0);
io->seek_proc(handle, tell, SEEK_SET);
return bIsPNG;
}
#ifdef FREEIMAGE_BIGENDIAN
static void
SwapInfoHeader(BITMAPINFOHEADER *header) {
SwapLong(&header->biSize);
SwapLong((DWORD *)&header->biWidth);
SwapLong((DWORD *)&header->biHeight);
SwapShort(&header->biPlanes);
SwapShort(&header->biBitCount);
SwapLong(&header->biCompression);
SwapLong(&header->biSizeImage);
SwapLong((DWORD *)&header->biXPelsPerMeter);
SwapLong((DWORD *)&header->biYPelsPerMeter);
SwapLong(&header->biClrUsed);
SwapLong(&header->biClrImportant);
}
static void
SwapIconHeader(ICONHEADER *header) {
SwapShort(&header->idReserved);
SwapShort(&header->idType);
SwapShort(&header->idCount);
}
static void
SwapIconDirEntries(ICONDIRENTRY *ent, int num) {
while(num) {
SwapShort(&ent->wPlanes);
SwapShort(&ent->wBitCount);
SwapLong(&ent->dwBytesInRes);
SwapLong(&ent->dwImageOffset);
num--;
ent++;
}
}
#endif
// ==========================================================
// Plugin Interface
// ==========================================================
static int s_format_id;
// ==========================================================
// Plugin Implementation
// ==========================================================
static const char * DLL_CALLCONV
Format() {
return "ICO";
}
static const char * DLL_CALLCONV
Description() {
return "Windows Icon";
}
( run in 0.656 second using v1.01-cache-2.11-cpan-df04353d9ac )