Image
Image is the final group in the console library. It provides wide range of capabilities, but it is built on the device independent bitmap (DIB). Open source conversion routines from other image types are available for use, and these are implemented in the Image library "Image.dll". There are more details about this library here. The main supported image formats are BMP/DIB (Windows Bitmap), RLE (Windows Run Length Encoded), JPEG (Joint Pictures Expert Group), PNG (Portable Network Graphics) and GIF (Graphic Interchange Format).
The image group has the capability to read, write and manipulate ICO (Windows Icon) and CUR (Windows Cursor) multiple image formats. The icon capability supports all the latest Windows Vista formats including the large alpha transparent icons and PNG compressed icons.
All image formats including icons and cursors support direct save, and serialisation.
Any non native image format is loaded and immediately converted to the DIB format for ease of manipulation. Since the DIB is contained by, for example, a VPNGDib container, when the DIB is saved it appears on the disk as a PNG. Assuming one wanted to convert between PNG and JPEG one would load a VPNGDib, transfer the DIB from the VPNGDib into a VJPEGDib, and then save VJPEGDib. If the image palette and transparency of the source image are supported by the destination format, then it's that simple. Intelligent resampling is available, and easily used. A basic DIB image may be anything from 2 colours (1bit) through to 16M colors (24 bit) with an alpha channel. In addition we extend the DIB format internally such that the windows monochrome mask/invert format is supported as MaskedDib.
Windows does not really provide any useful capability for the resampling and optimisation of image colour tables. A group of classes is provided for the purpose of changing the colour depth of an image. The capability may use a standard equal separation palette, or use a median cut algorithm to reduce the colour depth of an existing image. This scheme is extensible, and other optimisation algorithms could easily be added. Once the colour depth is reduced, one may use a nearest colour, or an error diffusion algorithm to resample the image. Again resampling is easily extensible to include other algorithms. The conversion capability is well integrated and it is easily possible to convert between any two image types and depths, in just a couple of lines of code.
Dealing with image formats that use transparent colours is particularly interesting. The resampling module has the capacity to threshold the alpha channel, and select an unused colour for transparency. This is a useful (if not perfect) solution for converting form Alpha transparent PNG's to GIF's with a transparent palette entry. GIF files with transparency convert well into the MaskedDib format. All conversions are possible, and produce visually intelligible results. Some of the conversions are better than others, and some of the large compressions really do strain tastefulness with some types of image content! Nevertheless "pictures" (faces and scenery), are usually fairly good right through to monochrome thanks to the error diffusion algorithm. If animation becomes necessary an ordered dither will almost certainly be required.
No image sizing functionality is provided in this image group, but windows itself provides a nice fast bilinear stretch capability. The VDib base class provides a variable window convolve facility which operates on a _cdecl callback function. Some simple antialiasing callback functions are provided. These too are reasonably fast, and work well with stretch in visually sensitive situations.
Although any VDib can be set directly to/from a device context, the main object from which rendering normally takes place is VBitmap. Typically this object is loaded from a DIB. The VBitmap object has the capability to understand image swatches, transparent background colours, masks and alpha. Swatches and masks are particularly useful in conjunction with the resource compiler. VBitmap is easily capable of getting any common image onto the screen. To further this goal the VBitmap object can create icons (single handle type) and imagelists as they are used by most standard windows controls.
Being multiple image types, icons (file icons), do not naturally map to a single DIB. Icons are read from file into a DIB list container called VMultiIcon. From these lists of DIB's it is possible to extract them and load them into a VBitmap, from where one can do pretty much anything. Equally, an icon or cursor can be built by loading DIBs into the VMultiIcon container and saving them to disk. |