asimage(3x) | AfterStep X11 window manager | asimage(3x) |
asimage - internal structures and methods used for image manipulation in libAfterImage libAfterImage/asimage.h
defines main structures and function for image manipulation.
libAfterImage provides powerful functionality to load, store and
transform images. It allows for smaller memory utilization by utilizing
run-length encoding of the image data. There could be different levels of
compression selected, allowing to choose best speed/memory ratio.
Structures :
ASImage
ASImageManager
ASImageBevel
ASImageDecoder
ASImageOutput
ASImageLayer
ASGradient
Functions :
asimage_init(), asimage_start(), create_asimage(),
clone_asimage(), destroy_asimage()
ImageManager Reference counting and managing :
create_image_manager(), destroy_image_manager(),
store_asimage(), fetch_asimage(), query_asimage(),
dup_asimage(), release_asimage(),
release_asimage_by_name(), forget_asimage(),
safe_asimage_destroy()
Gradients helper functions :
flip_gradient(), destroy_asgradient()
Layers helper functions :
init_image_layers(), create_image_layers(),
destroy_image_layers()
Encoding :
asimage_add_line(), asimage_add_line_mono(),
asimage_print_line(), get_asimage_chanmask(),
move_asimage_channel(), copy_asimage_channel(),
copy_asimage_lines()
Decoding
start_image_decoding(), stop_image_decoding(),
asimage_decode_line (), set_decoder_shift(),
set_decoder_back_color()
Output :
start_image_output(), set_image_output_back_color(),
toggle_image_output_direction(), stop_image_output()
Other libAfterImage modules :
ascmap.h asfont.h asimage.h asvisual.h blender.h export.h
import.h transform.h ximage.h
Sasha Vasko <sasha at aftercode dot net>
libAfterImage/ASAltImFormats
identifies what output format should be used for storing the transformation result. Also identifies what data is currently stored in alt member of ASImage structure.
typedef enum {
ASA_ASImage = 0,
ASA_XImage,
ASA_MaskXImage,
/* temporary XImages to be allocated from static pool of memory :*/
ASA_ScratchXImage,
ASA_ScratchMaskXImage,
ASA_ScratchXImageAndAlpha,
ASA_ARGB32,
ASA_Vector, /* This cannot be used for transformation's result
* format */
ASA_Formats }ASAltImFormats;
libAfterImage/ASImage
is the main structure to hold image data.
Images are stored internally split into ARGB channels, each split
into scanline. Actuall data is stored using ASStorage container. Inside
ASImage data structure we only store IDs pointing to data in ASStorage
ASStorage implements reference counting, data compression, automatic memory
defragmentation and other nice things.
asimage_init()
asimage_start()
create_asimage()
destroy_asimage()
struct ASImageAlternative; struct ASImageManager;
/* magic number identifying ASFont data structure */ #define MAGIC_ASIMAGE 0xA3A314AE
typedef struct ASImage {
unsigned long magic ;
unsigned int width, height; /* size of the image in pixels */
/* arrays of storage ids of stored scanlines of particular channel: */
ASStorageID *alpha,
*red,
*green,
*blue;
ASStorageID *channels[IC_NUM_CHANNELS];
/* merely a shortcut so we can
* somewhat simplify code in loops */
ARGB32 back_color ; /* background color of the image, so
* we could discard everything that
* matches it, and then restore it
* back. */
struct ASImageAlternative
{ /* alternative forms of ASImage storage : */
XImage *ximage ; /* pointer to XImage created as the
* result of transformations whenever
* we request it to output into
* XImage ( see to_xim parameter ) */
XImage *mask_ximage ; /* XImage of depth 1 that could be
* used to store mask of the image */
ARGB32 *argb32 ; /* array of widthxheight ARGB32
* values */
double *vector ; /* scientific data that should be used
* in conjunction with
* ASScientificPalette to produce
* actuall ARGB data */
}alt;
struct ASImageManager *imageman; /* if not null - then image could be
* referenced by some other code */
int ref_count ;/* this will tell us what us how many
* times */
char *name ; /* readonly copy of image name
* this name is a hash value used to
* store image in the image-man's hash,
* and gets freed automagically on image
* removal from hash */
#define ASIM_DATA_NOT_USEFUL (0x01<<0) #define
ASIM_VECTOR_TOP2BOTTOM (0x01<<1) #define ASIM_XIMAGE_8BIT_MASK
(0x01<<2) #define ASIM_NO_COMPRESSION (0x01<<3) /* Do not use
compression to
* save some computation time
*/ #define ASIM_ALPHA_IS_BITMAP (0x01<<4) #define ASIM_RGB_IS_BITMAP
(0x01<<5) #define ASIM_XIMAGE_NOT_USEFUL (0x01<<6) #define
ASIM_NAME_IS_FILENAME (0x01<<7)
ASFlagType flags ; /* combination of the above flags */
} ASImage;
libAfterImage/ASImageManager
structure to be used to maintain list of loaded images for given set of search paths and gamma. Images are named and reference counted.
typedef struct ASImageManager {
ASHashTable *image_hash ;
/* misc stuff that may come handy : */
char *search_path[MAX_SEARCH_PATHS+1];
double gamma ; }ASImageManager;
libAfterImage/LIMITS
effectively limits size of the allowed images to be loaded from files. That is needed to be able to filter out corrupt files. MAX_BEVEL_OUTLINE Limit on bevel outline to be drawn around the image. MAX_SEARCH_PATHS Number of search paths to be used while loading images from files.
#define MAX_IMPORT_IMAGE_SIZE 8000 #define MAX_BEVEL_OUTLINE 100 #define
MAX_SEARCH_PATHS 8 /* prudently limiting ourselfs */
libAfterImage/ASVectorPalette
contains palette allowing us to map double values in vector image data into actuall ARGB values.
typedef struct ASVectorPalette {
unsigned int npoints ;
double *points ;
CARD16 *channels[IC_NUM_CHANNELS] ; /* ARGB data for key points. */
ARGB32 default_color; }ASVectorPalette;
libAfterImage/asimage/ASImageLayer
specifies parameters of the image superimposition.
libAfterImage allows for simultaneous superimposition (overlaying)
of arbitrary number of images. To facilitate this ASImageLayer structure has
been created in order to specify parameters of each image participating in
overlaying operation. Images need not to be exact same size. For each image
its position on destination is specified via dst_x and dst_y data members.
Each image maybe tiled and clipped to fit into rectangle specified by
clip_x, clip_y, clip_width, clip_height ( in image coordinates - not
destination ). If image is missing, then area specified by dst_x, dst_y,
clip_width, clip_height will be filled with solid_color. Entire image will
be tinted using tint parameter prior to overlaying. Bevel specified by bevel
member will be drawn over image prior to overlaying. Specific overlay method
has to be specified. merge_scanlines method is pointer to a function, that
accepts 2 ASScanlines as arguments and performs overlaying of first one with
the second one. There are 15 different merge_scanline methods implemented in
libAfterImage, including alpha-blending, tinting, averaging, HSV and HSL
colorspace operations, etc.
ASImageLayer s could be organized into chains using next pointers.
Since there could be a need to rearrange layers and maybe bypass some layers
- we need to provide for flexibility, while at the same time allowing for
simplicity of arrays. As the result next pointers could be used to link
together continuous arrays of layer, like so : array1:
[layer1(next==NULL)][layer2(next!=NULL)]
____________________________|
V array2: [layer3(next==NULL)][layer4(next==NULL)][layer5(next!=NULL)]
________________________________________________|
V array3: [layer6(next==NULL)][layer7(next==layer7)]
^______|
While iterating through such a list we check for two conditions -
exceeding count of layers and layer pointing to self. When any of that is
met - we stopping iteration.
merge_layers() blender.h
typedef struct ASImageLayer {
ASImage *im;
ARGB32 solid_color ; /* If im == NULL, then fill
* the area with this color. */
int dst_x, dst_y; /* placement in overall
* composition */
/* clip area could be partially outside of the image -
* image gets tiled in it */
int clip_x, clip_y;
unsigned int clip_width, clip_height;
ARGB32 tint ; /* if 0 - no tint */
struct ASImageBevel *bevel ; /* border to wrap layer with
* (for buttons, etc.)*/
/* if image is clipped then we need to specify offsets of bevel as
* related to clipped rectangle. Normally it should be :
* 0, 0, im->width, im->height. And if width/height left 0 - it will
* default to this values. Note that clipped image MUST be entirely
* inside the bevel rectangle. !!!*/
int bevel_x, bevel_y;
unsigned int bevel_width, bevel_height;
int merge_mode ; /* reserved for future use */
merge_scanlines_func merge_scanlines ; /* overlay method */
struct ASImageLayer *next; /* optional pointer to next
* layer. If it points to
* itself - then end of the
* chain.*/
void *data; /* hook to hung data on */ }ASImageLayer;
libAfterImage/asimage/GRADIENT_TYPE_flags
Combination of this flags defines the way gradient is rendered.
when set it will cause gradient's direction to be rotated by 45 degrees GRADIENT_TYPE_ORIENTATION will cause gradient direction to be rotated by 90 degrees. When combined with GRADIENT_TYPE_DIAG - rotates gradient direction by 135 degrees.
#define GRADIENT_TYPE_DIAG (0x01<<0) #define GRADIENT_TYPE_ORIENTATION
(0x01<<1) #define GRADIENT_TYPE_MASK (GRADIENT_TYPE_ORIENTATION| \
GRADIENT_TYPE_DIAG)
libAfterImage/asimage/GRADIENT_TYPE
This are named combinations of above flags to define type of
gradient.
normal left-to-right gradient. GRADIENT_TopLeft2BottomRight diagonal top-left to bottom-right. GRADIENT_Top2Bottom vertical top to bottom gradient. GRADIENT_BottomLeft2TopRight diagonal bottom-left to top-right.
#define GRADIENT_Left2Right 0 #define GRADIENT_TopLeft2BottomRight
GRADIENT_TYPE_DIAG #define GRADIENT_Top2Bottom GRADIENT_TYPE_ORIENTATION
#define GRADIENT_BottomLeft2TopRight (GRADIENT_TYPE_DIAG| \
GRADIENT_TYPE_ORIENTATION)
libAfterImage/ASGradient
describes how gradient is to be drawn.
libAfterImage includes functionality to draw multipoint gradients
in 4 different directions left->right, top->bottom and diagonal
lefttop->rightbottom and bottomleft->topright. Each gradient described
by type, number of colors (or anchor points), ARGB values for each color and
offsets of each point from the beginning of gradient in fractions of entire
length. There should be at least 2 anchor points. very first point should
have offset of 0. and last point should have offset of 1. Gradients are
drawn in ARGB colorspace, so it is possible to have semitransparent
gradients.
make_gradient()
typedef struct ASGradient {
int type; /* see GRADIENT_TYPE above */
int npoints; /* number of anchor points */
ARGB32 *color; /* ARGB color values for each anchor point*/
double *offset; /* offset of each point from the beginning in
* fractions of entire length */ }ASGradient;
libAfterImage/asimage/flip
This are flags that define rotation angle.
defines rotation of 90 degrees counterclockwise. FLIP_UPSIDEDOWN defines rotation of 180 degrees counterclockwise. combined they define rotation of 270 degrees counterclockwise.
#define FLIP_VERTICAL (0x01<<0) #define FLIP_UPSIDEDOWN (0x01<<1)
#define FLIP_MASK (FLIP_UPSIDEDOWN|FLIP_VERTICAL)
libAfterImage/asimage/flip_gradient()
- rotates gradient in 90 degree increments.
ASGradient *flip_gradient( ASGradient *orig, int flip );
Same as original gradient if flip is 0. New gradient structure in
any other case.
Rotates ( flips ) gradient data in 90 degree increments. When
needed order of points is reversed.
libAfterImage/asimage/tint
We use 32 bit ARGB values to define how tinting should be done.
The formula for tinting particular channel data goes like that: tinted_data
= (image_data * tint)/128 So if tint channel value is greater then 127 -
same channel will be brighter in destination image; if it is lower then 127
- same channel will be darker in destination image. Tint channel value of
127 ( or 0x7F hex ) does not change anything. Alpha channel is tinted as
well, allowing for creation of semitransparent images. Calculations are
performed in 24.8 format - with 8 bit precision. Result is saturated to
avoid overflow, and precision is carried over to next pixel ( error
diffusion ), when con verting 24.8 to 8 bit format.
special value that disables tinting TINT_LEAVE_SAME also disables tinting.
#define TINT_NONE 0 #define TINT_LEAVE_SAME (0x7F7F7F7F) #define
TINT_HALF_DARKER (0x3F3F3F3F) #define TINT_HALF_BRIGHTER (0xCFCFCFCF)
#define TINT_RED (0x7F7F0000) #define TINT_GREEN (0x7F007F00) #define
TINT_BLUE (0x7F00007F)
libAfterImage/asimage/compression
Defines the level of compression to attempt on ASImage scanlines.
defined as 0 - disables compression. ASIM_COMPRESSION_FULL defined as 100 - highest compression level. Anything in between 0 and 100 will cause only part of the scanline to be compressed. This is obsolete. Now all images are compressed if possible. libAfterImage/asimage/asimage_init()
frees datamembers of the supplied ASImage structure, and initializes it to all 0.
void asimage_init (ASImage * im, Bool free_resources);
destroys XImage and mask XImage kept from previous conversions to/from X Pixmap.
void flush_asimage_cache (ASImage * im );
Allocates memory needed to store scanline of the image of supplied size. Assigns all the data members valid values. Makes sure that ASImage structure is ready to store image data.
void asimage_start (ASImage * im, unsigned int width,
unsigned int height,
unsigned int compression);
In order to resize ASImage structure after asimage_start() has
been called, asimage_init() must be invoked to free all the memory, and then
asimage_start() has to be called with new dimensions.
libAfterImage/asimage/create_asimage()
Performs memory allocation for the new ASImage structure, as well as initialization of allocated structure based on supplied parameters.
ASImage *create_asimage( unsigned int width,
unsigned int height,
unsigned int compression);
Pointer to newly allocated and initialized ASImage structure on
Success. NULL in case of any kind of error - that should never happen.
libAfterImage/asimage/clone_asimage()
ASImage *clone_asimage(ASImage *src, ASFlagType filter );
New ASImage, as a copy of original image.
Creates exact clone of the original ASImage, with same
compression, back_color and rest of the attributes. Only ASImage data will
be carried over. Any attached alternative forms of images (XImages, etc.)
will not be copied. Any channel with unset bit in filter will not be copied.
Image name, ASImageManager and ref_count will not be copied - use
store_asimage() afterwards and make sure you use different name, to avoid
clashes with original image.
libAfterImage/asimage/destroy_asimage()
frees all the memory allocated for specified ASImage.
void destroy_asimage( ASImage **im );
If there was XImage attached to it - it will be deallocated as
well.
asview.c: ASView.5
libAfterImage/asimage/asimage_replace()
will replace ASImage's data using data from another ASImage
Bool asimage_replace (ASImage *im, ASImage *from);
this function updates image without reallocating structure itself,
which means that all pointers to it will still be valid. If that function
succeeds - [from] ASImage will become unusable and should be deallocated
using free() call.
libAfterImage/asimage/set_asimage_vector()
This function replaces contents of the vector member of ASImage structure with new double precision data.
set_asimage_vector( ASImage *im, register double *vector );
Data must have size of width*height ahere width and height are
size of the ASImage.
libAfterImage/asimage/vectorize_asimage()
This function replaces contents of the vector member of ASImage structure with new double precision data, generated from native ARGB32 image contents. Color palette is generated by indexing color values using max_colors, dither and opaque_threshold parameters.
ASVectorPalette* vectorize_asimage( ASImage *im,
unsigned int max_colors,
unsigned int dither,
int opaque_threshold );
pointer to the ASVectorPalette structure that could be used for
reverse conversion from double values to ARGB32.
alt.vector member of the supplied ASImage will be replaced and
will contain WIDTHxHEIGHT double values representing generated scientific
data.
libAfterImage/asimage/create_image_manager()
create ASImage management and reference counting object.
ASImageManager *create_image_manager( ASImageManager
*reusable_memory,
double gamma, ... );
Creates ASImageManager object in memory and initializes it with
requested gamma value and PATH list. This Object will contain a hash table
referencing all the loaded images. When such object is used while loading
images from the file - gamma and PATH values will be used, so that all the
loaded and referenced images will have same parameters. File name will be
used as the image name, and if same file is attempted to be loaded again -
instead reference will be incremented, and previously loaded image will be
retyrned. All the images stored in ASImageManager's table will contain a
back pointer to it, and they must be deallocated only by calling
release_asimage(). destroy_asimage() will refuse to deallocate such an
image.
libAfterImage/asimage/destroy_image_manager()
destroy management obejct.
void destroy_image_manager( struct ASImageManager *imman,
Bool reusable );
Destroys all the referenced images, PATH values and if reusable is
False, also deallocates object's memory.
libAfterImage/asimage/store_asimage()
add ASImage to the reference.
Bool store_asimage( ASImageManager* imageman, ASImage *im,
const char *name );
Adds specifyed image to the ASImageManager's list of referenced
images. Stored ASImage could be deallocated only by release_asimage(), or
when ASImageManager object itself is destroyed.
libAfterImage/asimage/relocate_asimage()
relocate ASImage into a different image manager.
void relocate_asimage( ASImageManager* to_imageman, ASImage *im );
Moves image from one ASImageManager's list of referenced images
into another ASImageManager. Reference count will be kept the same.
libAfterImage/asimage/fetch_asimage()
query_asimage()
ASImage *fetch_asimage( ASImageManager* imageman, const char *name
); ASImage *query_asimage( ASImageManager* imageman, const char *name );
Looks for image with the name in ASImageManager's list and if
found, returns pointer to it. Note that query_asimage() does not increment
reference count, while fetch_asimage() does. Therefore if fetch_asimage() is
used - release_asimage() should be called , when image is no longer in use.
libAfterImage/asimage/dup_asimage()
increment reference count of stored ASImage.
ASImage *dup_asimage( ASImage* im );
decrement reference count for given ASImage. release_asimage_by_name() decrement reference count for ASImage identifyed by its name.
int release_asimage( ASImage *im ); int release_asimage_by_name(
ASImageManager *imman, char *name );
Decrements reference count on the ASImage object and destroys it
if reference count is below zero.
libAfterImage/asimage/forget_asimage()
remove ASImage from ASImageManager's hash by pointer. forget_asimage_name() remove ASImage from ASImageManager's hash by its name.
void forget_asimage( ASImage *im ); void forget_asimage_name(
ASImageManager *imman, const char *name );
either release or destroy asimage, checking if it is attached to ASImageManager.
int safe_asimage_destroy( ASImage *im );
prints list of images referenced in given ASImageManager structure. libAfterImage/asimage/destroy_asgradient()
- destroy ASGradient structure, deallocating all associated memory libAfterImage/asimage/init_image_layers()
- initialize set of ASImageLayer structures.
void init_image_layers( register ASImageLayer *l, int count );
Initializes array on ASImageLayer structures to sensible defaults.
Basically - all zeros and merge_scanlines == alphablend_scanlines.
libAfterImage/asimage/create_image_layers()
- allocate and initialize set of ASImageLayer's.
ASImageLayer *create_image_layers( int count );
Pointer to newly allocated and initialized array of ASImageLayer
structures on Success. NULL in case of any kind of error - that should never
happen.
Performs memory allocation for the new array of ASImageLayer
structures, as well as initialization of allocated structure to sensible
defaults - merge_func will be set to alphablend_scanlines.
libAfterImage/asimage/destroy_image_layers()
- destroy set of ASImageLayer structures.
void destroy_image_layers( register ASImageLayer *l,
int count,
Bool reusable );
frees all the memory allocated for specified array of ASImageLayer
s. If there was ASImage and/or ASImageBevel attached to it - it will be
deallocated as well.
libAfterImage/asimage/asimage_add_line()
size_t asimage_add_line ( ASImage * im, ColorPart color,
CARD32 * data, unsigned int y);
asimage_add_line() return size of the encoded channel scanline in
bytes. On failure it will return 0.
Encodes raw data of the single channel into ASImage channel
scanline. based on compression level selected for this ASImage all or part
of the scanline will be RLE encoded.
libAfterImage/asimage/asimage_add_line_mono()
size_t asimage_add_line_mono ( ASImage * im, ColorPart color,
CARD8 value, unsigned int y);
asimage_add_line_mono() return size of the encoded channel
scanline in bytes. On failure it will return 0.
encodes ASImage channel scanline to have same color components
value in every pixel. Useful for vertical gradients for example.
libAfterImage/asimage/get_asimage_chanmask()
ASFlagType get_asimage_chanmask( ASImage *im);
goes throu all the scanlines of the ASImage and toggles bits
representing those components that have at least some data.
libAfterImage/asimage/move_asimage_channel()
void move_asimage_channel( ASImage *dst, int channel_dst,
ASImage *src, int channel_src );
MOves channel data from one ASImage to another, while discarding
what was already in destination's channel.
Source image (donor) will loose its channel data, as it will be
moved to destination ASImage. Also there is a condition that both images
must be of the same width - otherwise function returns without doing
anything. If height is different - the minimum of two will be used.
libAfterImage/asimage/copy_asimage_channel()
void copy_asimage_channel( ASImage *dst, int channel_dst,
ASImage *src, int channel_src );
Same as move_asimage_channel() but makes copy of channel's data
instead of simply moving it from one image to another.
libAfterImage/asimage/copy_asimage_lines()
void copy_asimage_lines( ASImage *dst, unsigned int offset_dst,
ASImage *src, unsigned int offset_src,
unsigned int nlines, ASFlagType filter );
Makes copy of scanline data for continuos set of scanlines,
affecting only those channels marked in filter. NOTE Images must be of the
same width.
libAfterImage/asimage/verbosity
This are flags that define what should be printed by
asimage_print_line():
VRB_LINE_SUMMARY - print only summary for each scanline
VRB_LINE_CONTENT - print summary and data for each scanline
VRB_CTRL_EXPLAIN - print summary, data and control codes for each
scanline
#define VRB_LINE_SUMMARY (0x01<<0) #define VRB_LINE_CONTENT
(0x01<<1) #define VRB_CTRL_EXPLAIN (0x01<<2) #define
VRB_EVERYTHING (VRB_LINE_SUMMARY|VRB_CTRL_EXPLAIN| \
VRB_LINE_CONTENT)
libAfterImage/asimage/asimage_print_line()
unsigned int asimage_print_line ( ASImage * im, ColorPart color,
unsigned int y,
unsigned long verbosity);
amount of memory used by this particular channel of specified
scanline.
asimage_print_line() prints data stored in specified image scanline channel. That may include simple summary of how much memory is used, actual visible data, and/or RLE control codes. That helps one to see how effectively data is encoded.
Useful mostly for debugging purposes.
libAfterImage/asimage/get_asimage_channel_rects()
- translate image into a list of rectangles.
XRectangle*
get_asimage_channel_rects( ASImage *src, int channel,
unsigned int threshold,
unsigned int *rects_count_ret );
This function will translate contents of selected channel (usually
alpha) into a list of rectangles, ecompasing regions with values above the
threshold. This is useful to generate shape of the window to be used with X
Shape extension.
AfterStep v.2.2.12 | 3rd Berkeley Distribution |