Basics

Basics — The basic set of the application API.

Functions

Types and Values

Includes

#include <abydos.h>

Description

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;
}

Functions

ABYDOS_INFO_HAS()

#define ABYDOS_INFO_HAS(p,f) (offsetof(abydos_info_t,f)<(p)->version)

abydos_info_callback_t ()

void
(*abydos_info_callback_t) (void *userdata,
                           abydos_t *ar);

abydos_update_callback_t ()

void
(*abydos_update_callback_t) (void *userdata,
                             abydos_t *ar,
                             cairo_rectangle_int_t *Param3);

abydos_create ()

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 .

Parameters

mime_type

MIME type

 

Returns

An abydos_t capable of handling mime_type . Or NULL if none is found. Call abydos_destroy() then you are done using it.


abydos_clone ()

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.

Parameters

src

An abydos_t to clone

 

Returns

A clone of src . Call abydos_destroy() then you are done using it.


abydos_reference ()

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.

Parameters

ar

an abydos_t

 

Returns

The same abydos_t. Call abydos_destroy() then you are done using it.


abydos_destroy ()

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.

Parameters

ar

an abydos_t

 

abydos_get_options ()

int
abydos_get_options (abydos_t *ar);

Gets the options currently in effect.

Parameters

ar

an abydos_t

 

Returns

Current effective options.


abydos_set_options ()

void
abydos_set_options (abydos_t *ar,
                    int options);

The options is a combination of the following (ored together):

and one of the following:

Parameters

ar

an abydos_t

 

options

Options

 

abydos_from_data ()

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.

Parameters

ar

an abydos_t

 

data

the data containing the image

 

len

length of the data

 

Returns

0 on success. Otherwise the operation has failed.


abydos_from_file ()

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.

Parameters

ar

an abydos_t

 

filename

file to load the image from

 

Returns

0 on success. Otherwise the operation has failed.


abydos_load_begin ()

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. info_func() will be called first and exactly once. update_func() will be called at least once. If abydos_load_feed() or abydos_load_end() fails info_func() and update_func() may or may not be called.

Parameters

ar

an abydos_t

 

info_func

a function to be called as soon as abydos_get_info() can be called, or NULL

 

update_func

a function to be called every time the image has been updated, or NULL

 

userdata

user data to be passed to info_func and update_func

 

abydos_load_end ()

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.

Parameters

ar

an abydos_t

 

Returns

0 on success. Otherwise the operation has failed.


abydos_load_feed ()

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.

Parameters

ar

an abydos_t

 

data

the data containing a part of the image

 

len

length of the data

 

Returns

0 on success. Otherwise the operation has failed.


abydos_get_info()

#define abydos_get_info(a,b) abydos_get_info_V(a,b,ABYDOS_INFO_VERSION)

abydos_get_size ()

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.

Parameters

ar

an abydos_t

 

height

where to store the width (or NULL)

 

width

where to store the height (or NULL)

 

abydos_get_max_size ()

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.

Parameters

ar

an abydos_t

 

width

where to store the width (or NULL)

 

height

where to store_the height (or NULL)

 

abydos_error ()

const char *
abydos_error (abydos_t *ar);

If an error has occured, this function can be used to get a description of the error.

Parameters

ar

an abydos_t

 

Returns

A string describing an error or NULL.


abydos_render ()

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.

Parameters

ar

an abydos_t

 

cr

a cairo context

 

abydos_get_image_surface ()

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.

Parameters

ar

an abydos_t

 

Returns

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.


abydos_get_image_surface_at_size_max ()

cairo_surface_t *
abydos_get_image_surface_at_size_max (abydos_t *ar,
                                      int width,
                                      int height);

abydos_get_image_surface_at_size_min ()

cairo_surface_t *
abydos_get_image_surface_at_size_min (abydos_t *ar,
                                      int width,
                                      int height);

abydos_mime_types ()

const char **
abydos_mime_types (void);

Returns an array with all MIME types supported with the currently installed plugins.

Returns

An array of strings. You should free the array but not the strings themselves.


abydos_unload_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().

Types and Values

ABYDOS_FEATURE_SQUARE_PIXELS

#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.


ABYDOS_FEATURE_SCALABLE_SIZE

#define ABYDOS_FEATURE_SCALABLE_SIZE (1<<1)

The image (or some aspect of it) can be scaled up. This is typical for vector images.


ABYDOS_FEATURE_SCALABLE_TIME

#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).


ABYDOS_PREFER_SHARE

#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.


ABYDOS_PREFER_COPY

#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.


ABYDOS_PREFER_TRANSFER

#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.


ABYDOS_IGNORE_ASPECT_RATIO

#define ABYDOS_IGNORE_ASPECT_RATIO    (1<<2)

Ignore the aspect ratio and get a pixel by pixel copy of the image.


ABYDOS_SHRINK_TO_ASPECT_RATIO

#define ABYDOS_SHRINK_TO_ASPECT_RATIO (2<<2)

Shrink the image to correct aspect ratio.


ABYDOS_GROW_TO_ASPECT_RATIO

#define ABYDOS_GROW_TO_ASPECT_RATIO   (3<<2)

Grow the image to correct aspect ratio.


abydos_t

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.


abydos_info_t

typedef struct {
    int version;
    int width;
    int height;
    int features;
    double pixel_ratio;
} abydos_info_t;

Information about an image.

Members

int version;

Version of this structure supported by the runtime version of abydos. You can use the macro ABYDOS_INFO_HAS() to check if a member of abydos_info_t is available at runtime.

 

int width;

Width of the image.

 

int height;

Height of the image.

 

int features;

A set of features supported by the image. They can be:

 

double pixel_ratio;

The aspect ratio of the pixels. The value is 1 is the pixels are perfectly square. If pixel_ratio if greater than one the pixels are wider than they are high.

 

ABYDOS_INFO_VERSION

#define ABYDOS_INFO_VERSION sizeof(abydos_info_t)