Top |
#define | ABYDOS_INFO_HAS() |
void | (*abydos_info_callback_t) () |
void | (*abydos_update_callback_t) () |
abydos_t * | abydos_create () |
abydos_t * | abydos_clone () |
abydos_t * | abydos_reference () |
void | abydos_destroy () |
int | abydos_get_options () |
void | abydos_set_options () |
int | abydos_from_data () |
int | abydos_from_file () |
void | abydos_load_begin () |
int | abydos_load_end () |
int | abydos_load_feed () |
#define | abydos_get_info() |
void | abydos_get_size () |
void | abydos_get_max_size () |
const char * | abydos_error () |
void | abydos_render () |
cairo_surface_t * | abydos_get_image_surface () |
cairo_surface_t * | abydos_get_image_surface_at_size_max () |
cairo_surface_t * | abydos_get_image_surface_at_size_min () |
const char ** | abydos_mime_types () |
void | abydos_unload_plugins () |
#define | ABYDOS_FEATURE_SQUARE_PIXELS |
#define | ABYDOS_FEATURE_SCALABLE_SIZE |
#define | ABYDOS_FEATURE_SCALABLE_TIME |
#define | ABYDOS_PREFER_SHARE |
#define | ABYDOS_PREFER_COPY |
#define | ABYDOS_PREFER_TRANSFER |
#define | ABYDOS_IGNORE_ASPECT_RATIO |
#define | ABYDOS_SHRINK_TO_ASPECT_RATIO |
#define | ABYDOS_GROW_TO_ASPECT_RATIO |
abydos_t | |
abydos_info_t | |
#define | ABYDOS_INFO_VERSION |
There are three steps for using abydos. The first step is to create an
abydos_t for a specific MIME type using abydos_create()
. Then you are
done using it you should destroy it using abydos_destroy()
. Determining
the correct MIME type for your data is outside the scope of abydos. Read
more about image format detection.
The second step is to load the data. There are three different methods
to choose from for doing this. You can load it from a file using
abydos_from_file()
. Or you can load it from memory using
abydos_from_data()
. Or you can use abydos_load_begin()
,
abydos_load_feed()
and abydos_load_end()
to progressively load the image.
With the last option you may get the opertunity to display a partially
decoded image. But this is not always possible since some images store
crucial information at the end of the file.
The third step is to get the image data. There are two different ways to
do this. Either you can render it to a cairo_t using abydos_render()
.
This is the recommended approch if you intend to display the image since
vector graphics will always be rendered in full quality intependant of
scale. Or you can get a cairo image surface with
abydos_get_image_surface()
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#include <abydos.h> #include <cairo.h> int main (int argc, char **argv) { abydos_t *ar; cairo_surface_t *surface; ar = abydos_create ("image/x-ilbm"); if (!ar) return 1; if (abydos_from_file (ar, "example.ilbm") < 0) return 1; surface = abydos_get_image_surface (ar); abydos_destroy (ar); cairo_surface_write_to_png (surface, "example.png"); cairo_surface_destroy (surface); return 0; } |
void (*abydos_update_callback_t) (void *userdata
,abydos_t *ar
,cairo_rectangle_int_t *Param3
);
abydos_t *
abydos_create (const char *mime_type
);
Creates a new abydos_t object to load an image of the type specified by mime_type
.
An abydos_t capable of handling mime_type
. Or NULL if none is
found. Call abydos_destroy()
then you are done using it.
abydos_t *
abydos_clone (abydos_t *src
);
Make a clone of src
, which is cheap and effectively only copies the
internal state. This is useful for maintaining multiple states at once.
Such as rendering several pages of a multi page image in parallell.
abydos_t *
abydos_reference (abydos_t *ar
);
Increases the reference count on ar
by one. This prevents ar from being
destroyed until a matching call to abydos_destroy()
is made.
void
abydos_destroy (abydos_t *ar
);
Decreases the reference count on ar
by one. If the result is zero, then
ar
and all associated resources are freed.
void abydos_set_options (abydos_t *ar
,int options
);
The options
is a combination of the following (ored together):
zero for the default
and one of the following:
zero for the default
int abydos_from_data (abydos_t *ar
,const char *data
,size_t len
);
Create the image from a single chunk of data. If you prefer to feed the
data a little at a time, use progressive interface abydos_load_begin()
,
abydos_load_feed()
and abydos_load_end()
. If the operation fails you can
call abydos_error()
to get an error message. Apart fram that nothing more
can be done with ar
and it must be destroyed.
int abydos_from_file (abydos_t *ar
,const char *filename
);
Create the image from a file. You may want to use the convenience
function abydos_create_from_file()
, which is identical to calling
abydos_create()
followed by abydos_from_file()
. If the operation fails
you can call abydos_error()
to get an error message. Apart fram that
nothing more can be done with ar
and it must be destroyed.
void abydos_load_begin (abydos_t *ar
,abydos_info_callback_t info_func
,abydos_update_callback_t update_func
,void *userdata
);
Begin progressive loading of an image. If you pass info_func
and
update_func
they are guaranteed to be called before abydos_load_end()
returns successfully.
will be called first and exactly once.
info_func()
will be called at least once. If update_func()
abydos_load_feed()
or
abydos_load_end()
fails
and info_func()
may or may not be
called.update_func()
ar |
an abydos_t |
|
info_func |
a function to be called as soon as |
|
update_func |
a function to be called every time the image has been updated, or NULL |
|
userdata |
user data to be passed to |
int
abydos_load_end (abydos_t *ar
);
End progressive loading of an image. If the operation fails you can call
abydos_error()
to get an error message. Apart fram that nothing more can
be done with ar
and it must be destroyed.
int abydos_load_feed (abydos_t *ar
,const char *data
,size_t len
);
Feed bytes of the image. If the operation fails you can call
abydos_error()
to get an error message. Apart from that nothing more can
be done with ar
and it must be destroyed.
void abydos_get_size (abydos_t *ar
,int *width
,int *height
);
Get the size of a loaded image. Note that this is the size of the image
as rendered and may be affected by the currently set options
(see abydos_set_options()
) in the case pixels are not square.
ar |
an abydos_t |
|
height |
where to store the width (or NULL) |
|
width |
where to store the height (or NULL) |
void abydos_get_max_size (abydos_t *ar
,int *width
,int *height
);
Get the maximum size of a loaded image, a size large enough to hold any variant of any page.
ar |
an abydos_t |
|
width |
where to store the width (or NULL) |
|
height |
where to store_the height (or NULL) |
const char *
abydos_error (abydos_t *ar
);
If an error has occured, this function can be used to get a description of the error.
void abydos_render (abydos_t *ar
,cairo_t *cr
);
Render the image to a cairo_t. Use ordinary cairo trasformations to
scale the image. The result may also be affected by the currently set
options (see abydos_set_options()
) in the pixels are not square.
cairo_surface_t *
abydos_get_image_surface (abydos_t *ar
);
Get a cairo_surface_t containing the image. This may or may not be a
reference to an internally cached image surface. If you don't intend to
modify it or if you intend to get it and modify it only once, then this
is no problem. But you intend to get several copies and modify them you
need to pass one of the flags ABYDOS_PREFER_COPY
or
ABYDOS_PREFER_TRANSFER
. The flags
may also affect the size of the image
if it has non square pixels. Valid flags are one of:
and one of:
The default is ABYDOS_PREFER_SHARE
and ABYDOS_GROW_TO_ASPECT_RATIO
, but
it may change in the future.
For the common simple cases you might want to use the convinience
function abydos_load()
to quickly get an image surface from a file.
If the image loading has suceeded a valid cairo_surface_t
will
be returned. Call cairo_surface_destroy()
then you are done
using it. If the image loading hasn't succeeded the return value
is undefined.
cairo_surface_t * abydos_get_image_surface_at_size_max (abydos_t *ar
,int width
,int height
);
cairo_surface_t * abydos_get_image_surface_at_size_min (abydos_t *ar
,int width
,int height
);
const char **
abydos_mime_types (void
);
Returns an array with all MIME types supported with the currently installed plugins.
void
abydos_unload_plugins (void
);
Unloads all plugins and frees up all global memory used by abydos.
This isn't something you normally need to do. But It might be useful for
memory debugging. And it can also be used to force abydos to pick up
changes in the configuration file or plugins that have been updated or
added. Plugins that are in use will not be affected but kept around as
long as they remain in use. Keep in mind that this function isn't
completely thread safe. It must not be called at the same time as
abydos_create()
or abydos_mime_types()
.
#define ABYDOS_FEATURE_SQUARE_PIXELS (1<<0)
The image has perfectly square pixels. Meaning that it doesn't need to be scaled in order to be displayed with correct aspect ratio.
#define ABYDOS_FEATURE_SCALABLE_SIZE (1<<1)
The image (or some aspect of it) can be scaled up. This is typical for vector images.
#define ABYDOS_FEATURE_SCALABLE_TIME (1<<2)
The image format has the ability to (at least potentially) create images between the defined frames. It is also set if the resulting image may differ depending on other variables (such as the current clock time).
#define ABYDOS_PREFER_SHARE (1<<0)
Prefer to get a shared object reference. This is always fastest but alterations to the object may or may not also affect the next reference you request. If you intend to alter the object and want to be sure you can request more references to (unaltered) objects later, use ABYDOS_PREFER_COPY or ABYDOS_PREFER_TRANSFER instad.
#define ABYDOS_PREFER_COPY (2<<0)
Prefer to get a copy of the object. This is always safe then the object needs to be altered. But it may also be slowest if a copy doesn't actually need to be made. Consider using ABYDOS_PREFER_TRANSFER instead if you consider it unlikely you will need more references to the (unaltered) object later.
#define ABYDOS_PREFER_TRANSFER (3<<0)
Prefer to take over the ownership of the object. This is always safe then the object needs to be alteter. But it may also be slowest if you need another copy later and it has to be recreated. Consider using ABYDOS_PREFER_COPY instead if you consider it likely you will need more references to the (unaltered) object.
#define ABYDOS_IGNORE_ASPECT_RATIO (1<<2)
Ignore the aspect ratio and get a pixel by pixel copy of the image.
#define ABYDOS_SHRINK_TO_ASPECT_RATIO (2<<2)
Shrink the image to correct aspect ratio.
#define ABYDOS_GROW_TO_ASPECT_RATIO (3<<2)
Grow the image to correct aspect ratio.
typedef struct _abydos_t abydos_t;
An abydos_t is an opaque type representing an image. It is both used for
loading the image then for rendering it. It has also an internal state
and can be used as an iterator in several ways. If you need several
independant iterators you can use abydos_clone()
, which is cheap and
effectively only makes a copy of the state.
typedef struct { int version; int width; int height; int features; double pixel_ratio; } abydos_info_t;
Information about an image.
Version of this structure supported by the runtime version of
abydos. You can use the macro |
||
Width of the image. |
||
Height of the image. |
||
A set of features supported by the image. They can be: |
||
The aspect ratio of the pixels. The value is 1 is the
pixels are perfectly square. If |