File: decode.html

package info (click to toggle)
minidjvu 0.8.svn.2010.05.06+dfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 2,372 kB
  • ctags: 1,082
  • sloc: sh: 9,230; ansic: 5,788; cpp: 2,400; makefile: 259; python: 42
file content (92 lines) | stat: -rw-r--r-- 2,834 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<HTML>
<H1>minidjvu: how to decode a DjVu page</H1>

This file describes minidjvu 0.3 library;
this is also fully applicable to 0.33 version.
<P>
The library interface is <B>unstable</B>.
<P>
See also: <a href="encode.html">how to compress a DjVu file</a>
<HR>
<H3>Step 0: get things working</H3>
Add this include line to you source files that use minidjvu:
<PRE>
    #include &lt;minidjvu.h&gt;
</PRE>
I'll assume that your compiler can find the minidjvu headers
and your linker can link against the library. If not, try to read INSTALL
or README, or try to add the parent release directory into the header search path.
<P>
This examples also require
<PRE>
    #include &lt;assert.h&gt;
    #include &lt;stdio.h&gt;
    #include &lt;stdlib.h&gt;
</PRE>
<HR>
<H3>Step 1: load the image</H3>
You can load DjVu pages with <I>mdjvu_load_djvu_page()</I>.
That's an example of doing full error handling:
<PRE>
    const char *input = "your_input_file_name_here.djvu";
    mdjvu_error_t error;
    mdjvu_image_t image = mdjvu_load_djvu_page(input, &amp;error);
    if (!image)
    {
        fprintf(stderr, "%s: %s\n", input, mdjvu_get_error_message(error));
        exit(1);
    }
</PRE>
<HR>
<H3>Step 2: render into a bitmap</H3>
An image is not yet a bitmap. It's a sequence of commands like
"put (a bitmap) at point x = (an integer), y = (an integer)".
These commands need to be interpreted. Function <I>mdjvu_render()</I>
does this:
<PRE>
    mdjvu_bitmap_t bitmap = mdjvu_render(image);
    assert(bitmap);
</PRE>
<HR>
<H3>Step 3: save the bitmap</H3>
You can save your bitmap into one of bitmap formats supported by minidjvu:
PBM and Windows BMP. In any case, an output file will be rewritten if it
exists. That's how to save a PBM:
<PRE>
    const char *output = "your_output_file_name_here.pbm";
    mdjvu_error_t error;
    if (!mdjvu_save_pbm(bitmap, output, &amp;error))
    {
        fprintf(stderr, "%s: %s\n", output, mdjvu_get_error_message(error));
        exit(1);
    }
</PRE>
Doing it with BMPs is pretty similar:
<PRE>
    const char *output = "your_output_file_name_here.bmp";
    mdjvu_error_t error;
    if (!mdjvu_save_bmp(bitmap, output, &amp;error))
    {
        fprintf(stderr, "%s: %s\n", output, mdjvu_get_error_message(error));
        exit(1);
    }
</PRE>
With TIFF, you can just call <I>mdjvu_save_tiff()</I>, but it's a good idea
to check first whether TIFF support is compiled into minidjvu by calling
<PRE>
    int have_tiff = mdjvu_have_tiff_support();
</PRE>
<P>
For the sake of completeness, there's a second declaration of <I>error</I>
in this examples. Obviously, you should remove it if you plan to compile this.
<HR>

<H3>Step 4: clean up</H3>

If you no longer need the image and the bitmap, destroy them:
<PRE>
    mdjvu_image_destroy(image);
    mdjvu_bitmap_destroy(bitmap);
</PRE>

</HTML>