This post is related to one simple task – decode ICO file format from C++ manually (I needed this for one of my projects where i wanted to display fav icons related to web sites and decoder has to be part of my cross-platform framework). As a result you can download small c++ code below (ico.cpp). The description of ICO format you can find here – http://www.daubnet.com/en/file-format-ico. Image data is stored uncompressed so we don’t need to implement some smart decompression algorithms – just read some headers, get data and apply bit mask to fill alpha channel.
As solution i wanted a function like this:
bool IcoDecoder::decode(unsigned char* buffer,///< input buffer data
int size,///< size of buffer
unsigned int& width,///< output – width
unsigned int& height,///< output – height
std::vector<unsigned char>&image///< output – image data
and this function should extract the largest possible image from multiresolution icon.