Class DjVuImage provides a simple interface for processing DjVu content. The complete documentation is found in section DjVuImage.h. You may also consult the source code of program djvutopnm.The DjVu Reference Library uses a two stage decoding model.
- The first stage, called decoding, consists of analyzing a DjVu or IW44 file and constructing a partially decoded representation of the image in memory. This partially decoded representation requires much less memory (typically 1-2 MBytes) than the raw image (typically 20-30 MBytes).
- The second stage, called rendering, consists of using this representation to recreate the pixels for any part of the image at any resolution. You should render on-the-fly the part of the image that you actually wish to display. This strategy minimizes both the memory and the computational requirements.
The sample decoding code below may be called once when you receive the DjVu data. The function decode processes the data stream represented by class ByteStream and updates the DjVuImage object.
DjVuImage img; ByteStream &bs = my_incoming_data_stream(); img.decode(bs);The sample rendering code below may be called whenever you need to redisplay part of a window showing DjVu image. Class GRect is used to represent two rectangles of interest. Rectangle full represents the range of pixels that would be occupied by the full DjVu image. This rectangle may be much larger than your computer screen. The ratio between the size of this rectangle and the size of the image implicitly defines the resolution of the displayed image. Rectangle part represents the range of pixel that you actually want to compute. This rectangle always corresponds to a visible portion of your screen. The functions get_pixmap and get_bitmap return a "smart" GP pointer to either a GPixmap or GBitmap containing the requested pixels.GRect part = my_rectangle_to_redisplay(); GRect full = my_rectangle_for_the_full_image(); // Try rendering in color GP<GPixmap> pm = img->get_pixmap(part, full); if (pm) { my_display_in_color(pm); return; } // Try rendering in gray GP<GBitmap> bm = img->get_bitmap(part, full); if (bm) { my_display_in_grays(bm); return ; }Progressive display can be implemented using multi-threading. The browser starts a decoding thread as soon as it starts receiving data. The decoding progress can be monitored using class DjVuInterface. The main thread can call the rendering functions at any time while the decoding is in progress. These function render the image as early as possible, using only the already decoded data.
Section GThreads.h discusses the multi-threading capabilities of the DjVu Reference Library. These features must be enabled at compile-time using the adequate option of the configuration script.
Alphabetic index Hierarchy of classes