represents the
information common to all kinds of messages. Given a
pointer to a , the message kind can
be accessed as <"p->m_any.tag">. */
/* ddjvu_message_tag_t ---
This enumerated type identifies each kind of
message delivered by the DDJVU API. */
typedef enum {
DDJVU_ERROR,
DDJVU_INFO,
DDJVU_NEWSTREAM,
DDJVU_DOCINFO,
DDJVU_PAGEINFO,
DDJVU_RELAYOUT,
DDJVU_REDISPLAY,
DDJVU_CHUNK,
DDJVU_THUMBNAIL,
DDJVU_PROGRESS,
} ddjvu_message_tag_t;
/* ddjvu_message_t::m_any ---
This structure is a member of the union .
It represents the information common to all kinds of
messages. Member indicates the kind of message.
Members , , , and indicate
the origin of the message. These fields contain null
pointers when they are not relevant.
These fields are also cleared when the corresponding
object is released with .
If the message has not yet been passed to the user
with , it is silently
removed from the message queue. */
typedef struct ddjvu_message_any_s {
ddjvu_message_tag_t tag;
ddjvu_context_t *context;
ddjvu_document_t *document;
ddjvu_page_t *page;
ddjvu_job_t *job;
} ddjvu_message_any_t;
/* ddjvu_message_t::m_error ---
Error messages are generated whenever the decoder or the
DDJVU API encounters an error condition. All errors are
reported as error messages because they can occur
asynchronously. Member is the error message.
Members , and
indicates the place where the error was detected. */
struct ddjvu_message_error_s { /* ddjvu_message_t::m_error */
ddjvu_message_any_t any;
const char *message;
const char *function;
const char *filename;
int lineno;
};
/* ddjvu_message_t::m_info ---
This messages provides informational text indicating
the progress of the decoding process. This might
be displayed in the browser status bar. */
struct ddjvu_message_info_s { /* ddjvu_message_t::m_info */
ddjvu_message_any_t any;
const char *message;
};
/* -------------------------------------------------- */
/* DDJVU_DOCUMENT_T */
/* -------------------------------------------------- */
/* ddjvu_document_create ---
Creates a decoder for a DjVu document and starts
decoding. This function returns immediately. The
decoding job then generates messages to request the raw
data and to indicate the state of the decoding process.
Argument specifies an optional URL for the document.
The URL follows the usual syntax (<"protocol://machine/path">).
It should not end with a slash. It only serves two purposes:
- The URL is used as a key for the cache of decoded pages.
- The URL is used to document messages.
Setting argument to indicates that decoded pages
should be cached when possible. This only works when
argument is not the null pointer.
It is important to understand that the URL is not used to
access the data. The document generates
messages to indicate which data is needed. The caller must
then provide the raw data using
and .
Localized characters in argument should be in
urlencoded UTF-8 (like "%2A"). What is happening for non
ascii characters is unclear (probably UTF-8). */
DDJVUAPI ddjvu_document_t *
ddjvu_document_create(ddjvu_context_t *context,
const char *url,
int cache);
/* ddjvu_document_create_by_filename ---
Creates a document for a DjVu document stored in a file.
The document will directly access the specified DjVu file
or related files without generating messages.
The standard function expects the filename in locale encoding.
The utf8 variant expects an utf8 encoded filename. */
DDJVUAPI ddjvu_document_t *
ddjvu_document_create_by_filename(ddjvu_context_t *context,
const char *filename,
int cache);
DDJVUAPI ddjvu_document_t *
ddjvu_document_create_by_filename_utf8(ddjvu_context_t *context,
const char *filename,
int cache);
/* ddjvu_document_job ---
Access the job object in charge of decoding the document header.
In fact is a subclass of
and this function is a type cast. */
DDJVUAPI ddjvu_job_t *
ddjvu_document_job(ddjvu_document_t *document);
/* ddjvu_document_release ---
Release a reference to a object.
The calling program should no longer reference this object.
The object itself will be destroyed as soon as no other object
or thread needs it. */
#define ddjvu_document_release(document) \
ddjvu_job_release(ddjvu_document_job(document))
/* ddjvu_document_set_user_data ---
ddjvu_document_get_user_data ---
Each object can store an arbitray pointer
that callers can use for any purpose. These two functions
provide for accessing or setting this pointer. */
#define ddjvu_document_set_user_data(document,userdata) \
ddjvu_job_set_user_data(ddjvu_document_job(document),userdata)
#define ddjvu_document_get_user_data(document) \
ddjvu_job_get_user_data(ddjvu_document_job(document))
/* ddjvu_document_decoding_status ---
ddjvu_document_decoding_done, ddjvu_document_decoding_error ---
This function returns the status of the document header decoding job */
#define ddjvu_document_decoding_status(document) \
ddjvu_job_status(ddjvu_document_job(document))
#define ddjvu_document_decoding_done(document) \
(ddjvu_document_decoding_status(document) >= DDJVU_JOB_OK)
#define ddjvu_document_decoding_error(document) \
(ddjvu_document_decoding_status(document) >= DDJVU_JOB_FAILED)
/* ------- STREAMS ------- */
/* ddjvu_message_t::m_newstream ---
Newstream messages are generated whenever the decoder
needs to access raw DjVu data. The caller must then
provide the requested data using
and .
In the case of indirect documents, a single decoder
might simultaneously request several streams of data.
Each stream is identified by a small integer .
The first message always has member
set to zero and member set to the null
pointer. It indicates that the decoder needs to access
the data in the main DjVu file. In fact, data can be
written to stream <0> as soon as the
object is created.
Further messages are generated to access
the auxiliary files of indirect or indexed DjVu
documents. Member then provides the basename of
the auxiliary file.
Member is set according to the url argument
provided to function . The first
newstream message always contain the url passed to
. Subsequent newstream messages
contain the url of the auxiliary files for indirect or
indexed DjVu documents. */
struct ddjvu_message_newstream_s { /* ddjvu_message_t::m_newstream */
ddjvu_message_any_t any;
int streamid;
const char *name;
const char *url;
};
/* ddjvu_stream_write ---
Provide raw data to the DjVu decoder.
This function should be called as soon as the data is available,
for instance when receiving DjVu data from a network connection.
*/
DDJVUAPI void
ddjvu_stream_write(ddjvu_document_t *document,
int streamid,
const char *data,
unsigned long datalen );
/* ddjvu_stream_close ---
Indicates that no more data will be provided on a
particular stream. Argument most likely should be
set to . Setting argument to
indicates that the user has interrupted the data transfer
(for instance by pressing the stop button of a browser)
and that the decoding threads should be stopped as
soon as feasible. */
DDJVUAPI void
ddjvu_stream_close(ddjvu_document_t *document,
int streamid,
int stop );
/* ------- QUERIES ------- */
/* ddjvu_message_t::m_docinfo ---
The message indicates that basic information
about the document has been obtained and decoded.
Not much can be done before this happens.
Call to determine
whether the operation was successful. */
struct ddjvu_message_docinfo_s {
ddjvu_message_any_t any;
};
/* ddjvu_document_get_type ---
Returns the type of a DjVu document.
This function might return
when called before receiving a message. */
typedef enum {
DDJVU_DOCTYPE_UNKNOWN=0,
DDJVU_DOCTYPE_SINGLEPAGE,
DDJVU_DOCTYPE_BUNDLED,
DDJVU_DOCTYPE_INDIRECT,
DDJVU_DOCTYPE_OLD_BUNDLED, /* obsolete */
DDJVU_DOCTYPE_OLD_INDEXED, /* obsolete */
} ddjvu_document_type_t;
DDJVUAPI ddjvu_document_type_t
ddjvu_document_get_type(ddjvu_document_t *document);
/* ddjvu_document_get_pagenum ---
Returns the number of pages in a DjVu document.
This function might return 1 when called
before receiving a message */
DDJVUAPI int
ddjvu_document_get_pagenum(ddjvu_document_t *document);
/* ------- ADVANCED ------- */
/* ddjvu_document_get_filenum --
Returns the number of component files.
This function might return 0 when called
before receiving a message */
DDJVUAPI int
ddjvu_document_get_filenum(ddjvu_document_t *document);
/* ddjvu_document_get_fileinfo --
Returns information about component file .
This function might return when
called before receiving a message.
String pointers in the returned data structure
might be null. Strings are UTF8 encoded and remain
allocated as long as the ddjvu_document_t object exists.
Changes for ddjvuapi=18
- Redefined as a macro passing the structure size.
*/
typedef struct ddjvu_fileinfo_s {
char type; /* [P]age, [T]humbnails, [I]nclude. */
int pageno; /* Negative when not applicable. */
int size; /* Negative when unknown. */
const char *id; /* File identifier. */
const char *name; /* Name for indirect documents. */
const char *title; /* Page title. */
} ddjvu_fileinfo_t;
#define ddjvu_document_get_fileinfo(d,f,i) \
ddjvu_document_get_fileinfo_imp(d,f,i,sizeof(ddjvu_fileinfo_t))
DDJVUAPI ddjvu_status_t
ddjvu_document_get_fileinfo_imp(ddjvu_document_t *document, int fileno,
ddjvu_fileinfo_t *info, unsigned int infosz);
/* ddjvu_document_search_pageno --- DEPRECATED. */
DDJVUAPI int ddjvu_document_search_pageno(ddjvu_document_t*, const char*);
/* ddjvu_document_check_pagedata ---
Returns a non zero result if the data for page
is already in memory. When this is the case, functions
and
return the information immediately.
This function causes the emission of messages
with zero in the field whenever a new file
is completely downloaded. */
DDJVUAPI int
ddjvu_document_check_pagedata(ddjvu_document_t *document, int pageno);
/* ddjvu_document_get_pageinfo ---
Attempts to obtain information about page
without decoding the page. If the information is available,
the function returns and fills the structure.
Otherwise it starts fetching page data and returns .
This function causes the emission of messages
with zero in the field.
Typical synchronous usage:
ddjvu_status_t r;
ddjvu_pageinfo_t info;
while ((r=ddjvu_document_get_pageinfo(doc,pageno,&info))=DDJVU_JOB_FAILED)
signal_error();
Changes for ddjvuapi=18
- Redefined as a macro passing the structure size.
- Added fields 'rotation' and 'version'.
*/
typedef struct ddjvu_pageinfo_s {
int width; /* page width (in pixels) */
int height; /* page height (in pixels) */
int dpi; /* page resolution (in dots per inche) */
int rotation; /* initial page orientation */
int version; /* page version */
} ddjvu_pageinfo_t;
#define ddjvu_document_get_pageinfo(d,p,i) \
ddjvu_document_get_pageinfo_imp(d,p,i,sizeof(ddjvu_pageinfo_t))
DDJVUAPI ddjvu_status_t
ddjvu_document_get_pageinfo_imp(ddjvu_document_t *document, int pageno,
ddjvu_pageinfo_t *info, unsigned int infosz );
/* ddjvu_document_get_pagedump --
This function returns a UTF8 encoded text describing the contents
of page using the same format as command .
The returned string must be deallocated using .
It returns <0> when the information is not yet available.
It may then cause then the emission of
messages with null .
*/
DDJVUAPI char *
ddjvu_document_get_pagedump(ddjvu_document_t *document, int pageno);
/* ddjvu_document_get_filedump --
This function returns a UTF8 encoded text describing the contents
of file using the same format as command .
The returned string must be deallocated using .
It returns <0> when the information is not yet available.
It may then cause then the emission of
messages with null .
*/
DDJVUAPI char *
ddjvu_document_get_filedump(ddjvu_document_t *document, int fileno);
/* -------------------------------------------------- */
/* DJVU_PAGE_T */
/* -------------------------------------------------- */
/* ddjvu_page_create_by_pageno ---
Each page of a document can be accessed by creating a
object with this function. Argument
indicates the page number, starting with page
<0> to . This function may return NULL
when called before receiving the message.
Calling this function also initiates the data transfer
and the decoding threads for the specified page.
Various messages will document the progress of these
operations. Error messages will be generated if
the page does not exists. */
DDJVUAPI ddjvu_page_t *
ddjvu_page_create_by_pageno(ddjvu_document_t *document,
int pageno);
/* ddjvu_page_create_by_pageid ---
This function is similar to
but identifies the desired page by name instead of page
number. */
DDJVUAPI ddjvu_page_t *
ddjvu_page_create_by_pageid(ddjvu_document_t *document,
const char *pageid);
/* ddjvu_page_job ---
Access the job object in charge of decoding the document header.
In fact is a subclass of
and this function is a type cast. */
DDJVUAPI ddjvu_job_t *
ddjvu_page_job(ddjvu_page_t *page);
/* ddjvu_page_release ---
Release a reference to a object.
The calling program should no longer reference this object.
The object itself will be destroyed as soon as no other object
or thread needs it. */
#define ddjvu_page_release(page) \
ddjvu_job_release(ddjvu_page_job(page))
/* ddjvu_page_set_user_data ---
ddjvu_page_get_user_data ---
Each object can store an arbitray pointer
that callers can use for any purpose. These two functions
provide for accessing or setting this pointer. */
#define ddjvu_page_set_user_data(page,userdata) \
ddjvu_job_set_user_data(ddjvu_page_job(page),userdata)
#define ddjvu_page_get_user_data(page) \
ddjvu_job_get_user_data(ddjvu_page_job(page))
/* ddjvu_page_decoding_status ---
ddjvu_page_decoding_done ---
ddjvu_page_decoding_error ---
These calls return the status of the page decoding job. */
#define ddjvu_page_decoding_status(page) \
ddjvu_job_status(ddjvu_page_job(page))
#define ddjvu_page_decoding_done(page) \
(ddjvu_page_decoding_status(page) >= DDJVU_JOB_OK)
#define ddjvu_page_decoding_error(page) \
(ddjvu_page_decoding_status(page) >= DDJVU_JOB_FAILED)
/* ------- MESSAGES ------- */
/* ddjvu_message_t::m_pageinfo ---
The page decoding process generates this message
- when basic page information is available and
before any or message,
- when the page decoding thread terminates.
You can distinguish both cases using
function ddjvu_page_decoding_status().
Messages are also generated as a consequence of
functions such as .
The field of such message is null.
*/
struct ddjvu_message_pageinfo_s { /* ddjvu_message_t::m_pageinfo */
ddjvu_message_any_t any;
};
/* ddjvu_message_t::m_relayout ---
This message is generated when a DjVu viewer
should recompute the layout of the page viewer
because the page size and resolution information has
been updated. */
struct ddjvu_message_relayout_s { /* ddjvu_message_t::m_relayout */
ddjvu_message_any_t any;
};
/* ddjvu_message_t::m_redisplay ---
This message is generated when a DjVu viewer
should call and redisplay
the page. This happens, for instance, when newly
decoded DjVu data provides a better image. */
struct ddjvu_message_redisplay_s { /* ddjvu_message_t::m_redisplay */
ddjvu_message_any_t any;
};
/* ddjvu_message_t::m_chunk ---
This message indicates that an additional chunk
of DjVu data has been decoded. Member
indicates the type of the DjVu chunk. */
struct ddjvu_message_chunk_s { /* ddjvu_message_t::m_chunk */
ddjvu_message_any_t any;
const char *chunkid;
};
/* About page messages --
Both the and messages are derived from the
message. They are intended for driving a djvu image viewer.
When receiving , the viewer should get the image size, decide
zoom factors, and place the image area, scrollbars, toolbars, and other gui
objects. When receiving , the viewer should invalidate the
image area so that the gui toolkit calls the repaint event handler. This
handler should call ddjvu_page_render() and paint the part of the
image that needs repainting. */
/* ------- QUERIES ------- */
/* ddjvu_page_get_width ---
Returns the page width in pixels. Calling this function
before receiving a message always yields <0>. */
DDJVUAPI int
ddjvu_page_get_width(ddjvu_page_t *page);
/* ddjvu_page_get_height---
Returns the page height in pixels. Calling this function
before receiving a message always yields <0>. */
DDJVUAPI int
ddjvu_page_get_height(ddjvu_page_t *page);
/* ddjvu_page_get_resolution ---
Returns the page resolution in pixels per inch (dpi).
Calling this function before receiving a
message yields a meaningless but plausible value. */
DDJVUAPI int
ddjvu_page_get_resolution(ddjvu_page_t *page);
/* ddjvu_page_get_gamma ---
Returns the gamma of the display for which this page was designed.
Calling this function before receiving a
message yields a meaningless but plausible value. */
DDJVUAPI double
ddjvu_page_get_gamma(ddjvu_page_t *page);
/* ddjvu_page_get_version ---
Returns the version of the djvu file format.
Calling this function before receiving a
message yields a meaningless but plausible value. */
DDJVUAPI int
ddjvu_page_get_version(ddjvu_page_t *page);
/* ddjvu_code_get_version ---
Returns the version of the djvu file format
implemented by this library. More or less graceful
degradation might arise if this is smaller than
the number returned by . */
DDJVUAPI int
ddjvu_code_get_version(void);
/* ddjvu_page_get_type ---
Returns the type of the page data.
Calling this function before the termination of the
decoding process might returns . */
typedef enum {
DDJVU_PAGETYPE_UNKNOWN,
DDJVU_PAGETYPE_BITONAL,
DDJVU_PAGETYPE_PHOTO,
DDJVU_PAGETYPE_COMPOUND,
} ddjvu_page_type_t;
DDJVUAPI ddjvu_page_type_t
ddjvu_page_get_type(ddjvu_page_t *page);
/* ddjvu_page_get_{short,long}_description --- DEPRECATED */
DDJVUAPI char *ddjvu_page_get_short_description(ddjvu_page_t *);
DDJVUAPI char *ddjvu_page_get_long_description(ddjvu_page_t *);
/* ddjvu_page_set_rotation ---
Changes the counter-clockwise rotation angle for a DjVu page.
Calling this function before receiving a
message has no good effect. */
typedef enum {
DDJVU_ROTATE_0 = 0,
DDJVU_ROTATE_90 = 1,
DDJVU_ROTATE_180 = 2,
DDJVU_ROTATE_270 = 3,
} ddjvu_page_rotation_t;
DDJVUAPI void
ddjvu_page_set_rotation(ddjvu_page_t *page,
ddjvu_page_rotation_t rot);
/* ddjvu_page_get_rotation ---
Returns the counter-clockwise rotation angle for the DjVu page.
The rotation is automatically taken into account
by ,
and . */
DDJVUAPI ddjvu_page_rotation_t
ddjvu_page_get_rotation(ddjvu_page_t *page);
/* ddjvu_page_get_initial_rotation ---
Returns the page rotation specified by the
orientation flags in the DjVu file.
[brain damage warning] This is useful because
maparea coordinates in the annotation chunks
are expressed relative to the rotated coordinates
whereas text coordinates in the hidden text data
are expressed relative to the unrotated coordinates. */
DDJVUAPI ddjvu_page_rotation_t
ddjvu_page_get_initial_rotation(ddjvu_page_t *page);
/* ------- RENDER ------- */
/* ddjvu_render_mode_t ---
Various ways to render a page. */
typedef enum {
DDJVU_RENDER_COLOR = 0, /* color page or stencil */
DDJVU_RENDER_BLACK, /* stencil or color page */
DDJVU_RENDER_COLORONLY, /* color page or fail */
DDJVU_RENDER_MASKONLY, /* stencil or fail */
DDJVU_RENDER_BACKGROUND, /* color background layer */
DDJVU_RENDER_FOREGROUND, /* color foreground layer */
} ddjvu_render_mode_t;
/* ddjvu_rect_t ---
This structure specifies the location of a rectangle.
Coordinates are usually expressed in pixels relative to
the BOTTOM LEFT CORNER (but see ddjvu_format_set_y_direction).
Members and indicate the position of the bottom left
corner of the rectangle Members and indicate the
width and height of the rectangle. */
struct ddjvu_rect_s {
int x, y;
unsigned int w, h;
};
/* ddjvu_page_render --
Renders a segment of a page with arbitrary scale.
Argument indicates what image layers
should be rendered.
Conceptually this function renders the full page
into a rectangle and copies the
pixels specified by rectangle
into the buffer starting at position .
The actual code is much more efficient than that.
The final image is written into buffer .
Argument specifies the expected pixel format.
Argument specifies the number of BYTES from
one row to the next in the buffer. The buffer must be
large enough to accomodate the desired image.
This function makes a best effort to compute an image
that reflects the most recently decoded data. It might
return to indicate that no image could be
computed at this point, and that nothing was written into
the buffer. */
DDJVUAPI int
ddjvu_page_render(ddjvu_page_t *page,
const ddjvu_render_mode_t mode,
const ddjvu_rect_t *pagerect,
const ddjvu_rect_t *renderrect,
const ddjvu_format_t *pixelformat,
unsigned long rowsize,
char *imagebuffer );
/* -------------------------------------------------- */
/* COORDINATE TRANSFORMS */
/* -------------------------------------------------- */
/* ddjvu_rectmapper_create --
Creates a data structure
representing an affine coordinate transformation that
maps points from rectangle to rectangle