imencdec(3x)
π imencdec(3x) π
okay so bestie, this is the imencdec(3x) page from the AfterStep X11 window manager era, and it's giving major libAfterImage energy. We're decoding and encoding ASImage data like it's nobody's business. π
β¨ NAME β¨
imencdecβ encoding/decodingASImagedata from/to usable data structureslibAfterImage/imencdec.h
π«Ά NAMEimencdec π«Ά
defines main structures and function for image storing, extraction and conversion to/from usable formats.
πΈ DESCRIPTION πΈ
this header defines structures and functions to be used by outside applications for reading and writing into ASImages. ASImage pixel data maybe stored in several different formats, and should not be accessed directly, but only through encoder/decoder facility.
π SEE ALSO π
Structures :
ASImageBevelASImageDecoderASImageOutput
Functions :
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.hasfont.hasimage.hasvisual.hblender.hexport.himport.htransform.hximage.h
π AUTHOR π
Sasha Vasko <sasha at aftercode dot net>
libAfterImage/ASImageBevel
π NAMEASImageBevel π
describes bevel to be drawn around the image.
π¦ DESCRIPTION π¦
Bevel is used to create 3D effect while drawing buttons, or any other image that needs to be framed. Bevel is drawn using 2 primary colors: one for top and left sides - hi color, and another for bottom and right sides - low color. There are additionally 3 auxiliary colors: hihi is used for the edge of top-left corner, hilo is used for the edge of top-right and bottom-left corners, and lolo is used for the edge of bottom-right corner. Colors are specified as ARGB and contain alpha component, thus allowing for semitransparent bevels.
Bevel consists of outline and inline. Outline is drawn outside of the image boundaries and its size adds to image size as the result. Alpha component of the outline is constant. Inline is drawn on top of the image and its alpha component is fading towards the center of the image, thus creating illusion of smooth disappearing edge.
π¦ SOURCE π¦
typedef struct ASImageBevel { #define BEVEL_SOLID_INLINE (0x01<<0)
ASFlagType type ; /* reserved for future use */
/* primary bevel colors */
ARGB32 hi_color ; /* top and left side color */
ARGB32 lo_color ; /* bottom and right side color */
/* these will be placed in the corners */
ARGB32 hihi_color ; /* color of the top-left corner */
ARGB32 hilo_color ; /* color of the top-right and
* bottom-left corners */
ARGB32 lolo_color ; /* color of the bottom-right corner */
/* outlines define size of the line drawn around the image */
unsigned short left_outline ;
unsigned short top_outline ;
unsigned short right_outline ;
unsigned short bottom_outline ;
/* inlines define size of the semitransparent line drawn
* inside the image */
unsigned short left_inline ;
unsigned short top_inline ;
unsigned short right_inline ;
unsigned short bottom_inline ; }ASImageBevel;
libAfterImage/ASImageDecoder
π NAMEASImageDecoder π
describes the status of reading any particular ASImage, as well as providing detail on how it should be done.
π DESCRIPTION π
ASImageDecoder works as an abstraction layer and as the way to automate several operations. Most of the transformations in libAfterImage are performed as operations on ASScanline data structure, that holds all or some of the channels of single image scanline. In order to automate data extraction from ASImage into ASScanline ASImageDecoder has been designed.
It has following features :
- All missing scanlines, or channels of scanlines will be filled with supplied
back_color - It is possible to leave out some channels of the image, extracting only subset of channels. It is done by setting only needed flags in
filtermember. - It is possible to extract sub-image of the image by setting
offset_xandoffset_yto top-left corner of sub-image,out_width- to width of the sub-image and callingdecode_image_scanlinemethod as many times as height of the sub-image. - It is possible to apply bevel to extracted sub-image, by setting
bevelmember to specificASImageBevelstructure.
Extracted Scanlines will be stored in buffer and it will be updated after each call to decode_image_scanline().
π¦ SOURCE π¦
/* low level driver (what data to use - native, XImage or ARGB): */
typedef void (*decode_asscanline_func)( struct ASImageDecoder
*imdec,
unsigned int skip, int y );
/* high level driver (bevel or not bevel): */ typedef void
(*decode_image_scanline_func)
(struct ASImageDecoder *imdec);
typedef struct ASImageDecoder {
struct ASVisual *asv;
struct ASImage *im ;
ASFlagType filter; /* flags that mask set of
* channels to be extracted
* from the image */
ARGB32 back_color; /* we fill missing scanlines
* with this default - black*/
unsigned int offset_x, /* left margin on source image
* before which we skip everything
*/
out_width; /* actual length of the output
* scanline */
unsigned int offset_y, /* top margin */
out_height;
ASImageBevel *bevel; /* bevel to wrap everything
* around with */
/* offsets of the drawn bevel baseline on resulting image : */
int bevel_left, bevel_top,
bevel_right, bevel_bottom ;
/* scanline buffer containing current scanline */
struct ASScanline buffer; /* matches the out_width */
/* internal data : */
unsigned short bevel_h_addon, bevel_v_addon ;
int next_line ;
struct ASScanline *xim_buffer; /* matches the size of the
* original XImage */
decode_asscanline_func decode_asscanline ;
decode_image_scanline_func decode_image_scanline ;
}ASImageDecoder;
libAfterImage/asimage/quality
π₯ FUNCTION π₯
Defines level of output quality/speed ratio
β NAMEASIMAGE_QUALITY_POOR β
ASIMAGE_QUALITY_POORβ there will be no dithering and interpolation used while transformingASIMAGE_QUALITY_FASTβ there will be no dithering and used while transforming but interpolation will be used.ASIMAGE_QUALITY_GOODβ simplified dithering is performed in addition to interpolation.ASIMAGE_QUALITY_TOPβ full dithering and interpolation.ASIMAGE_QUALITY_DEFAULTβ requests current default setting - typically same asASIMAGE_QUALITY_GOOD.MAX_GRADIENT_DITHER_LINESβ defines number of lines to use for dithering, while rendering gradients, in order to create smooth effect. Higher number will slow things down, but will create better gradients.
π¦ SOURCE π¦
#define ASIMAGE_QUALITY_POOR 0 #define ASIMAGE_QUALITY_FAST 1
#define ASIMAGE_QUALITY_GOOD 2 #define ASIMAGE_QUALITY_TOP 3
#define ASIMAGE_QUALITY_DEFAULT -1
#define MAX_GRADIENT_DITHER_LINES ASIMAGE_QUALITY_TOP+1
libAfterImage/asimage/ASImageOutput
π NAMEASImageOutput π
describes the output state of the transformation result. It is used to transparently write results into ASImage or XImage with different levels of quality.
πΈ DESCRIPTION πΈ
libAfterImage allows for transformation result to be stored in both ASImage ( useful for long term storage and subsequent processing ) and XImage ( useful for transfer of the result onto the X Server). At the same time there are 4 different quality levels of output implemented. They differ in the way special technics, like error diffusion and interpolation are applied, and allow for fine grained selection of quality/speed ratio. ASIMAGE_QUALITY_GOOD should be good enough for most applications. The following additional output features are implemented :
- Filling of the missing channels with supplied values.
- Error diffusion to improve quality while converting from internal
24.8format to8bit format. - Tiling of the output. If
tiling_stepis greater then0, then each scanlines will be copied into lines foundtiling_stepone from another, up to the edge of the image. - Reverse order of output. Output image will be mirrored along y axis if
bottom_to_topis set toTrue.
π§ NOTES π§
The output_image_scanline method should be called for each scanline to be stored. Convenience functions listed below should be used to safely alter state of the output instead of direct manipulation of the data members. (makes you pity you don't write in C++ doesn't it ?)
Also There is a trick in the way how output_image_scanline handles empty scanlines while writing ASImage. If back_color of empty scanline matches back_color of ASImageOutput - then particular line is erased! If back_colors are same - then particular line of ASImage gets filled with the back_color of ASScanline. First approach is useful when resulting image will be used in subsequent call to merge_layers - in such case knowing back_color of image is good enough and we don't need to store lines with the same color. In case where ASImage will be converted into Pixmap/XImage - second approach is preferable, since that conversion does not take into consideration image's back color - we may want to change it in the future.
π SEE ALSO π
start_image_output()set_image_output_back_color()toggle_image_output_direction()stop_image_output()
π SOURCE π
bestie. this is the actual source for ASImageOutput β the typedefs and the struct, copied character-for-character because we do not paraphrase code in this house π«Ά
typedef void (*encode_image_scanline_func)( struct ASImageOutput *imout,
struct ASScanline *to_store );
typedef void (*output_image_scanline_func)( struct ASImageOutput *,
struct ASScanline *, int );
typedef struct ASImageOutput {
struct ASVisual *asv;
struct ASImage *im ;
ASAltImFormats out_format ;
CARD32 chan_fill[4];
int buffer_shift; /* -1 means - buffer is empty,
* 0 - no shift,
* 8 - use 8 bit precision */
int next_line ; /* next scanline to be written */
unsigned int tiling_step; /* each line written will be
* repeated with this step until
* we exceed image size */
unsigned int tiling_range; /* Limits region in which we need
* to tile. If set to 0 then image
* height is used */
int bottom_to_top; /* -1 if we should output in
* bottom to top order,
* +1 otherwise*/
int quality ; /* see above */
output_image_scanline_func
output_image_scanline ; /* high level interface - division,
* error diffusion as well
* as encoding */
encode_image_scanline_func
encode_image_scanline ; /* low level interface -
* encoding only */
/* internal data members : */
struct ASScanline buffer[2], *used, *available;
}ASImageOutput;
and then, like, the actual page for libAfterImage/asimage/start_image_decoding(), slay β¨
π¦ NAMEstart_image_decoding() π¦
start_image_decoding() β allocates and initializes the decoder structure.
πΈ SYNOPSIS πΈ
ASImageDecoder *start_image_decoding( ASVisual *asv,ASImage *im,
ASFlagType filter,
int offset_x, int offset_y,
unsigned int out_width,
unsigned int out_height,
ASImageBevel *bevel );
β¨ INPUTS β¨
asvβ pointer to a validASVisualstructure (it mostly needs this so it knows whether we're in BGR mode or not π).imβ theASImagewe are going to decode.filterβ a bitmask where the set bits mark the channels that have to be decoded.offset_xβ the left margin insideim, from which we should start reading pixel data; effectively clips the source image.offset_yβ the top margin insideim, from which we should start reading scanlines; effectively clips the source image. Note that when the edge of the image is reached, subsequent requests for scanlines will wrap around to the top of the image, and notoffset_y.out_widthβ width of the scanline needed. If it's larger than the source image β then image data will be tiled in it. If it's smaller β then image data will be clipped.out_heightβ height of the output drawable.-1means that same as image height. Ifout_heightis greater then image height, then image will be tiled.bevelβNULLor pointer to a validASImageBevelstructure if decoded data should be overlayed with bevel at the time of decoding.
π RETURN VALUE π
start_image_decoding() returns a pointer to a newly allocated ASImageDecoder structure on success, and NULL on failure. no in-between, it's giving all or nothing π
π DESCRIPTION π
the normal process of reading image data from an ASImage is literally just 3 steps:
- start decoding by calling
start_image_decoding. - call the
decode_image_scanline()method of the returned structure, for each scanline up to the desired height of the target image. Decoded data will be returned in thebuffermember of theASImageDecoderstructure. - finish decoding and deallocate all the used memory by calling
stop_image_decoding().
periodt. that's the whole ritual π―οΈ
π§ libAfterImage/asimage/set_decoder_bevel_geom() π§
π NAMEset_decoder_bevel_geom() π
set_decoder_bevel_geom() β changes the default placement of the bevel on the decoded image.
β SYNOPSIS β
void set_decoder_bevel_geom( ASImageDecoder *imdec, int x, int y,
unsigned int width, unsigned int height );
π INPUTS π
imdecβ pointer to a pointer to a structure previously created bystart_image_decoding.x,yβ the left top position of the inner border of the Bevel outline as related to the origin of the subimage being decoded.width,heightβ the widtha and height of the inner border of the bevel outline. (yes,widthaβ that's the original spelling, we don't gatekeep typos here π )
π«Ά DESCRIPTION π«Ά
for example, if you only need to render a small part of the button that is being rendered from a transparency image. π
NOTE This call modifiesbevel_h_addonandbevel_v_addonof theASImageDecoderstructure.
π libAfterImage/asimage/set_decoder_shift() π
π« NAMEset_decoder_shift() π«
set_decoder_shift() β changes the shift value of the decoder to 8 or 0.
πΈ SYNOPSIS πΈ
void set_decoder_shift( ASImageDecoder *imdec, int shift );
β¨ INPUTS β¨
imdecβ pointer to a pointer to a structure previously created bystart_image_decoding.shiftβ the new value to be used as the shift while decoding the image. valid values are8and0.
π¦ DESCRIPTION π¦
you should use this function instead of directly modifying the value of the shift member of the ASImageDecoder structure. fr fr, use the function π
π libAfterImage/asimage/set_decoder_back_color() π
π₯ NAMEset_decoder_back_color() π₯
set_decoder_back_color() β changes the back color to be used while decoding the image.
π SYNOPSIS π
void set_decoder_back_color( ASImageDecoder *imdec, ARGB32 back_color );
β INPUTS β
imdecβ pointer to a pointer to a structure previously created bystart_image_decoding.back_colorβARGB32color value to be used as the background color to fill empty spaces in the decodedASImage.
π DESCRIPTION π
this function should be used instead of directly modifying the value of the back_color member of the ASImageDecoder structure. same energy as above, bestie β hands off the struct, use the API π«Ά
πΈ libAfterImage/asimage/stop_image_decoding() πΈ
π NAMEstop_image_decoding() π
stop_image_decoding() β finishes decoding, frees all allocated memory.
β¨ SYNOPSIS β¨
void stop_image_decoding( ASImageDecoder **pimdec );
π INPUTS π
pimdecβ pointer to a pointer to a structure previously created bystart_image_decoding.
π¦ RETURN VALUE π¦
pimdecβ pointer toASImageDecoderwill be reset toNULL.
π SEE ALSO π
start_image_decoding()
π« libAfterImage/asimage/start_image_output() π«
π NAMEstart_image_output() π
start_image_output() β initializes the output structure.
π SYNOPSIS π
ASImageOutput *start_image_output ( struct ASVisual *asv,
ASImage *im,
ASAltImFormats format,
int shift, int quality );
πΈ INPUTS πΈ
asvβ pointer to a validASVisualstructure.imβ destinationASImage.formatβ indicates that output should be written into an alternative format, such as a suppliedXImage,ARGB32array, etc.shiftβ precision of scanline data. Supported values are0β no precision, and8β 24.8 precision. The value of that argument defines by how much scanline data is shifted rightwards.qualityβ what algorithms should be used while writing data out, i.e. full error diffusion, fast error diffusion, no error diffusion.
β¨ DESCRIPTION β¨
start_image_output() creates and initializes a new ASImageOutput structure based on the supplied parameters. The created structure can subsequently be used to write scanlines into the destination image. It is effectively hiding the differences between XImage and ASImage and other available output formats. π
the outpt_image_scanline() method of the structure can be used to write out a single scanline. Each written scanline moves the internal pointer to the next image line, and possibly writes several scanlines at once if the tiling_step member is not 0. it's giving multitasking, honestly π
π libAfterImage/asimage/set_image_output_back_color() π
π NAMEset_image_output_back_color() π
set_image_output_back_color() β changes the background color of the output.
β SYNOPSIS β
void set_image_output_back_color ( ASImageOutput *imout,
ARGB32 back_color );
π INPUTS π
imoutβASImageOutputstructure, previously created withstart_image_output().back_colorβ new background color value inARGBformat. This color will be used to fill empty parts of outgoing scanlines.
π¦ libAfterImage/asimage/toggle_image_output_direction() π¦
π NAMEtoggle_image_output_direction() π
toggle_image_output_direction() β reverses the vertical direction of output.
π« SYNOPSIS π«
void toggle_image_output_direction( ASImageOutput *imout );
π INPUTS π
imoutβASImageOutputstructure, previously created withstart_image_output().
β¨ DESCRIPTION β¨
reverses vertical direction of output. If previously scanlines has been written from top to bottom, for example, after this function is called they will be written in the opposite direction. Current line does not change, unless it points to the very first or the very last image line. In this last case it will be moved to the opposing end of the image. π
π libAfterImage/asimage/stop_image_output() π
π NAMEstop_image_output() π
stop_image_output() β finishes output, frees all the allocated memory.
πΈ SYNOPSIS πΈ
void stop_image_output( ASImageOutput **pimout );
π§ INPUTS π§
pimoutβ pointer to a pointer to anASImageOutputstructure, previously created with a call tostart_image_output().
β RETURN VALUE β
pimoutβ pointer toASImageOutputwill be reset toNULL.
π DESCRIPTION π
completes the image output process. Flushes all the internal buffers. Deallocates all the allocated memory. Resets the pointer to NULL to avoid dereferencing invalid pointers. she cleans up after herself, as she should π
β¨
aaaand that's the whole page, bestie!! thanks for sticking around for part 2 β this one came to you from the 3rd Berkeley Distribution, AfterStep v.2.2.12, filed under imencdec(3x). go forth and decode responsibly π«ΆππΈ
π¦ where this page comes from
- ubuntu resolute: libafterimage-dev 2.2.12-19 Β· GPL-2.0-or-later
- ubuntu stonking: libafterimage-dev 2.2.12-19 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms