PlanetDjVu Products
JRA Software, Publisher
JRMD Library 1.0
INTRODUCTION:
JRMD Library 1.0 allows your application to store and retrieval metadata in DjVu files. The information can be stored at both the Document and at the Page levels.
libjrmd.dll was originally developed to extract and modify embedded metadata: hence the suffix md = metadata. Later one extra method has been added to allow page-by-page decoding.
This ZIP file for the JRMD Library contains the following components:
libjrmd.dll - The DLL itself
libjrmd.h - Header file for instant integration of the DLL with C/C++ applications
libjrmd.lib - LIB file for easy linking of C/C++ applications with the DLL
jrmd.cpp - Example application for testing libjrmd.dll
readme.doc - The documentation
RAW IMAGE FORMAT DESCRIPTION:
jrmdDecodePage() method of libjrmd.dll can produce raster image in either of the two formats:
Bitonal format
Each pixel is represented by one byte: 0xff representing black, 0x00 - white. Coordinate system has its reference point in the lower-left angle of the image with Y axis pointing up. Pixels are stored in memory continuously with possible gaps between adjacent rows made for alignment purposes.
Bitonal raster images will be produced by DjVu pages containing Sjbz chunks only. If a page contains other image chunks, such as FGbz, FG44 or BG44, decoded image will be in color format (see below)
Color format
Each pixel is represented by three bytes (BGR). First byte is the Blue component: 0x00 corresponding to the minimum intensity, 0xff - maximum intensity. Second byte is a Green, and the last one is a Red component. Desired gamma value can be passed to jrmdDecodePage() for automatic gamma correction. Gamma 2.2 is recommended as a good default.
Coordinate system has its reference point in the lower left angle of the image with Y axis pointing up. Pixels are stored in memory continuously with possible gaps between adjacent rows made for alignment purposes.
WORKFLOW:
Before any page can be decoded, the DjVu document must be created, initialized and loaded. This is accomplished by the following calls
(Note that detailed information on every function is available in libjrmd.h):
static void
reportErrorAndDie(void * doc)
{
char buffer[1024];
jrmdGetLastError(doc, buffer, sizeof(buffer));
fprintf(stderr, "%s\n", buffer);
exit(1);
}
…
// Create and initialize JRMD document
void * doc=jrmdInitDoc();
// Load DjVu document specified in the command line
if (jrmdLoad(doc, argv[1]))
reportErrorAndDie(doc);
Note that the “doc” handle obtained from jrmdInitDoc() must be passed to every other function dealing with this document.
After the document is initialized, the number of pages can be obtained as follows:
// Retrieve the number of pages
int pages_num=jrmdGetPagesNum(doc);
if (pages_num<0)
reportErrorAndDie(doc);
Knowing the total number of pages it's now possible to decode each and every page in the following manner:
const unsigned char * data;
unsigned int width, height;
unsigned int bytes_per_pixel;
unsigned int bytes_per_row;
if (jrmdDecodePage(doc, page_num, 2.2, &data, &width,
&height, &bytes_per_row, &bytes_per_pixel))
reportErrorAndDie(doc);
Note that you may neither modify nor deallocate memory referenced by the “data” pointer. The data will be valid until the next call to jrmdDecodePage() or until the document is destroyed by jrmdDestroyDoc(doc)
After all pages have been decoded, jrmdDestroyDoc(doc) must be called to release memory and close all open handles:
// Destroy document
jrmdDestroyDoc(doc);
Note that it's imperative that all open documents are closed before unloading libjrmd.dll
|