| 1 |
<HTML> |
| 2 |
<H1>minidjvu: how to decode a DjVu page</H1> |
| 3 |
|
| 4 |
This file describes minidjvu 0.3 library; |
| 5 |
this is also fully applicable to 0.33 version. |
| 6 |
<P> |
| 7 |
The library interface is <B>unstable</B>. |
| 8 |
<P> |
| 9 |
See also: <a href="encode.html">how to compress a DjVu file</a> |
| 10 |
<HR> |
| 11 |
<H3>Step 0: get things working</H3> |
| 12 |
Add this include line to you source files that use minidjvu: |
| 13 |
<PRE> |
| 14 |
#include <minidjvu.h> |
| 15 |
</PRE> |
| 16 |
I'll assume that your compiler can find the minidjvu headers |
| 17 |
and your linker can link against the library. If not, try to read INSTALL |
| 18 |
or README, or try to add the parent release directory into the header search path. |
| 19 |
<P> |
| 20 |
This examples also require |
| 21 |
<PRE> |
| 22 |
#include <assert.h> |
| 23 |
#include <stdio.h> |
| 24 |
#include <stdlib.h> |
| 25 |
</PRE> |
| 26 |
<HR> |
| 27 |
<H3>Step 1: load the image</H3> |
| 28 |
You can load DjVu pages with <I>mdjvu_load_djvu_page()</I>. |
| 29 |
That's an example of doing full error handling: |
| 30 |
<PRE> |
| 31 |
const char *input = "your_input_file_name_here.djvu"; |
| 32 |
mdjvu_error_t error; |
| 33 |
mdjvu_image_t image = mdjvu_load_djvu_page(input, &error); |
| 34 |
if (!image) |
| 35 |
{ |
| 36 |
fprintf(stderr, "%s: %s\n", input, mdjvu_get_error_message(error)); |
| 37 |
exit(1); |
| 38 |
} |
| 39 |
</PRE> |
| 40 |
<HR> |
| 41 |
<H3>Step 2: render into a bitmap</H3> |
| 42 |
An image is not yet a bitmap. It's a sequence of commands like |
| 43 |
"put (a bitmap) at point x = (an integer), y = (an integer)". |
| 44 |
These commands need to be interpreted. Function <I>mdjvu_render()</I> |
| 45 |
does this: |
| 46 |
<PRE> |
| 47 |
mdjvu_bitmap_t bitmap = mdjvu_render(image); |
| 48 |
assert(bitmap); |
| 49 |
</PRE> |
| 50 |
<HR> |
| 51 |
<H3>Step 3: save the bitmap</H3> |
| 52 |
You can save your bitmap into one of bitmap formats supported by minidjvu: |
| 53 |
PBM and Windows BMP. In any case, an output file will be rewritten if it |
| 54 |
exists. That's how to save a PBM: |
| 55 |
<PRE> |
| 56 |
const char *output = "your_output_file_name_here.pbm"; |
| 57 |
mdjvu_error_t error; |
| 58 |
if (!mdjvu_save_pbm(bitmap, output, &error)) |
| 59 |
{ |
| 60 |
fprintf(stderr, "%s: %s\n", output, mdjvu_get_error_message(error)); |
| 61 |
exit(1); |
| 62 |
} |
| 63 |
</PRE> |
| 64 |
Doing it with BMPs is pretty similar: |
| 65 |
<PRE> |
| 66 |
const char *output = "your_output_file_name_here.bmp"; |
| 67 |
mdjvu_error_t error; |
| 68 |
if (!mdjvu_save_bmp(bitmap, output, &error)) |
| 69 |
{ |
| 70 |
fprintf(stderr, "%s: %s\n", output, mdjvu_get_error_message(error)); |
| 71 |
exit(1); |
| 72 |
} |
| 73 |
</PRE> |
| 74 |
With TIFF, you can just call <I>mdjvu_save_tiff()</I>, but it's a good idea |
| 75 |
to check first whether TIFF support is compiled into minidjvu by calling |
| 76 |
<PRE> |
| 77 |
int have_tiff = mdjvu_have_tiff_support(); |
| 78 |
</PRE> |
| 79 |
<P> |
| 80 |
For the sake of completeness, there's a second declaration of <I>error</I> |
| 81 |
in this examples. Obviously, you should remove it if you plan to compile this. |
| 82 |
<HR> |
| 83 |
|
| 84 |
<H3>Step 4: clean up</H3> |
| 85 |
|
| 86 |
If you no longer need the image and the bitmap, destroy them: |
| 87 |
<PRE> |
| 88 |
mdjvu_image_destroy(image); |
| 89 |
mdjvu_bitmap_destroy(bitmap); |
| 90 |
</PRE> |
| 91 |
|
| 92 |
</HTML> |