The main purposes of the img module are
In both these cases the image which is to be displayed by Opera will be decoded and cached by the img module.
Some implementation details are described in the mainpage of the API documentation.
The core functionality of the image module is the decode images and cache them.
The image object in the img module contains an ImageRep. The ImageRep contains the actual data and can be shared between multiple Image object. It is the ImageRep which is stored in the image cache.
The ImageRep contains a content provider, image loader, meta data, some flags and most importently an image content. The image content can be of several different types. A null image content means the size is not yet known. There is only one null image content. An empty image content means the size is known but the image is not yet decoded. A static image content is used for images with a single frame, regardless if it is animated or not. An animated image content is used for animated images.
The decoding of images is done through image decoders. The image decoders factories, which can be used to create decoders are registered in the image manager and can then be used by the image module to decode images. You can register any number of image decoders. Most of the decoder factories are included in the img module.
The image decoder factories are designed to be able to given a data stream detect if the data stream could be a supported image. This is used to determine which image decoder to use. If a factory detects a supported format it will probably be asked to create an image decoder later on.
The image decoder factories are also able to check the size of an image without creating a decoder and decoding it. This is needed to check the size of image which are not visible without spending much time on it.
The actual image decoders created by the factories must handle decoding of data without having the entire data stream. The image module will call DecodeData repeatedly with chunks of data. If the decode cannot handle all of it it must report how much data to resend.
The image cache in the image module caches ImageReps. The current cache strategy is to cache images on a MRU basis, but images which are visible in a document are always kept in the cache. This means that the cache can exceed the cache limit.
The image cache consists of three different lists. One list for free images, one list for decoded images which are not visible and one list for decoded images which are visible. When an image is marked as visible or not visible it is moved between the lists.