asimage(3x)

✨ asimage ✨

okay bestie, sit down, hydrate, grab your boba πŸ§‹ β€” because today's lesson is asimage, straight outta the AfterStep X11 window manager manual, section 3x. This is the libAfterImage lore and it is so much, in the best way πŸ’…


🌸 NAME 🌸

asimage β€” internal structures and methods used for image manipulation in libAfterImage libAfterImage/asimage.h πŸ‘‘

🌈 NAMEasimage 🌈

asimage defines main structures and function for image manipulation. she's here twice because she's iconic, periodt πŸ’–


πŸŽ€ DESCRIPTION πŸŽ€

libAfterImage provides powerful functionality to load, store and transform images β€” literally doing the most, no cap. And the way she keeps memory small? By utilizing run-length encoding of the image data. 🌸

There could be different levels of compression selected, which allows you to choose the best speed/memory ratio. so you can pick your own adventure: fast πŸƒβ€β™€οΈ or smol 🐜, your call.


πŸ¦‹ SEE ALSO πŸ¦‹

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

πŸ’œ AUTHOR πŸ’œ

Sasha Vasko <sasha at aftercode dot net> 🫢


πŸ’– libAfterImage/ASAltImFormats πŸ’–

🌸 NAMEASAltImFormats 🌸

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. iykyk πŸ‘‘

πŸŽ€ SOURCE πŸŽ€

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 πŸ’…

✨ NAMEASImage ✨

is the main structure to hold image data. the main character, honestly πŸ‘‘

🌈 DESCRIPTION 🌈

Images are stored internally split into ARGB channels, each split into scanline. Actual data is stored using the ASStorage container. Inside the ASImage data structure we only store IDs pointing to data in ASStorage β€” very demure, very mindful πŸŽ€

And ASStorage implements reference counting, data compression, automatic memory defragmentation and other nice things. she does it all, fr fr πŸ’…

πŸ¦‹ SEE ALSO πŸ¦‹

  • asimage_init()
  • asimage_start()
  • create_asimage()
  • destroy_asimage()

πŸ’œ SOURCE πŸ’œ

bestie, fair warning: the struct below got kinda mangled by the original page's line wrapping, so the comments are re-flowed to be readable β€” every token, number and #define is exactly as it was πŸ’–
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 🧚

πŸ’– NAMEASImageManager πŸ’–

structure to be used to maintain list of loaded images for given set of search paths and gamma. Images are named and reference counted β€” a whole little library of her own, obsessed 🌸

⭐ SOURCE ⭐

typedef struct ASImageManager {
    ASHashTable  *image_hash ;
    /* misc stuff that may come handy : */
    char         *search_path[MAX_SEARCH_PATHS+1];
    double        gamma ; }ASImageManager;

πŸ“ libAfterImage/LIMITS πŸ“

πŸŽ€ NAMEMAX_IMPORT_IMAGE_SIZE πŸŽ€

  • MAX_IMPORT_IMAGE_SIZE β€” 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.

πŸ¦‹ SOURCE πŸ¦‹

#define MAX_IMPORT_IMAGE_SIZE   8000
#define MAX_BEVEL_OUTLINE       100
#define MAX_SEARCH_PATHS        8      /* prudently limiting ourselfs */

🌈 libAfterImage/ASVectorPalette 🌈

✨ NAMEASVectorPalette ✨

contains palette allowing us to map double values in vector image data into actuall ARGB values. translating the vibes into colors, truly her gift πŸ’…

πŸ’œ SOURCE πŸ’œ

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 πŸ‘‘

🌸 NAMEASImageLayer 🌸

specifies parameters of the image superimposition. πŸ’…

πŸŽ€ DESCRIPTION πŸŽ€

libAfterImage allows for simultaneous superimposition (overlaying) of arbitrary number of images β€” the more the merrier, bestie. 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 β€” they don't all have to match, they just have to vibe.

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. fifteen!! she ate πŸ”₯

⭐ NOTES ⭐

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. πŸ›‘

πŸ¦‹ SEE ALSO πŸ¦‹

  • merge_layers() blender.h

πŸ“‚ SOURCE

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


βš™οΈ FUNCTION

Stack these flags together and you're literally choosing the vibe of how a gradient gets rendered. It's giving arts-and-crafts but make it bitwise. πŸ’…

🏷️ NAME

GRADIENT_TYPE_DIAG

bestie, set this and the gradient's direction gets rotated by 45 degrees ✨

GRADIENT_TYPE_ORIENTATION will rotate the gradient direction by 90 degrees. And when you combine it with GRADIENT_TYPE_DIAG? Now we're rotating the gradient direction by 135 degrees. Math is serving angles, periodt. πŸ’–

πŸ“‚ SOURCE

#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


βš™οΈ FUNCTION

These are the named little combos of the flags from up top, so you don't have to hand-stack bits like a menace. They define the type of gradient. Pick your fighter. πŸŽ€

🏷️ NAME

GRADIENT_Left2Right

the normal left-to-right gradient. The classic. The blueprint. πŸ‘‘

GRADIENT_TopLeft2BottomRight

diagonal, top-left to bottom-right. Slay. πŸ¦‹

GRADIENT_Top2Bottom

vertical, top to bottom gradient.

GRADIENT_BottomLeft2TopRight

diagonal, bottom-left to top-right. So symmetrical of it. ✨

πŸ“‚ SOURCE

#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


🏷️ NAME

ASGradient

okay so this one describes how a gradient is actually to be drawn. πŸ‘‘

πŸ’¬ DESCRIPTION

libAfterImage is lowkey stacked β€” it can draw multipoint gradients in 4 different directions: left->right, top->bottom, and the two diagonals, lefttop->rightbottom and bottomleft->topright. Obsessed.

Every gradient is described by:

  • its type,
  • the number of colors (aka anchor points),
  • the ARGB values for each color,
  • and the offsets of each point from the beginning of the gradient, expressed as fractions of the entire length.

House rules, no exceptions: there have to be at least 2 anchor points, the very first point should have an offset of 0., and the last point should have an offset of 1. πŸ’…

Gradients get drawn in ARGB colorspace, which means yes bestie β€” you can absolutely have semitransparent gradients. Main character energy. ✨

πŸ‘€ SEE ALSO

make_gradient()

πŸ“‚ SOURCE

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


βš™οΈ FUNCTION

These are the flags that define the rotation angle. Rotating is just a vibe check for your pixels. πŸŒ€

🏷️ NAME

FLIP_VERTICAL

defines rotation of 90 degrees counterclockwise.

FLIP_UPSIDEDOWN

defines rotation of 180 degrees counterclockwise.

And when you combine them together? Boom β€” that defines rotation of 270 degrees counterclockwise. Stacking flags is the moment. πŸ’…

πŸ“‚ SOURCE

#define FLIP_VERTICAL       (0x01<<0)
#define FLIP_UPSIDEDOWN     (0x01<<1)
#define FLIP_MASK           (FLIP_UPSIDEDOWN|FLIP_VERTICAL)

libAfterImage/asimage/flip_gradient()


🏷️ NAME

flip_gradient()

rotates a gradient in 90 degree increments. Iconic behavior honestly.

πŸ“œ SYNOPSIS

ASGradient *flip_gradient( ASGradient *orig, int flip );

πŸ“₯ INPUTS

  • orig β€” pointer to the original ASGradient structure that's gonna get rotated.
  • flip β€” the value defining the desired rotation.

πŸ“€ RETURN VALUE

Same as the original gradient if flip is 0. A new gradient structure in any other case. 🫢

πŸ’¬ DESCRIPTION

Rotates (flips) gradient data in 90 degree increments. And when it needs to, the order of points gets reversed. Simple as that, bestie. Reversal is just a glow-up in a different direction. ✨

libAfterImage/asimage/tint


βš™οΈ FUNCTION

So we use 32 bit ARGB values to define how tinting should be done. Here's the formula for tinting a particular channel's data:

tinted_data = (image_data * tint)/128

Let's break it down, because this is actually so important:

  • If the tint channel value is greater than 127 β€” that same channel will be brighter in the destination image. ✨
  • If it's lower than 127 β€” that same channel will be darker in the destination image.
  • A tint channel value of 127 (or 0x7F hex) changes nothing. Neutral king. πŸ‘‘

The alpha channel gets tinted as well, which allows for the creation of semitransparent images. Yes bestie, transparency is on the menu. πŸ˜­πŸ’–

Calculations are performed in 24.8 format β€” with 8 bit precision. The result is saturated to avoid overflow, and the leftover precision is carried over to the next pixel (that's called error diffusion), when converting 24.8 to 8 bit format. Details matter and we stay detail-oriented. πŸ’…

🏷️ NAME

TINT_NONE

special value that disables tinting. Zero tint, zero drama.

TINT_LEAVE_SAME

also disables tinting. Same energy, different constant. πŸ™ˆ

πŸ“‚ SOURCE

#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


βš™οΈ FUNCTION

Defines the level of compression to attempt on ASImage scanlines. Squish at your own discretion. πŸ—œοΈ

🏷️ NAME

ASIM_COMPRESSION_NONE

defined as 0 β€” disables compression. Nothing gets squished.

ASIM_COMPRESSION_FULL

defined as 100 β€” the highest compression level. Maximum squish. πŸ”₯

Anything in between 0 and 100 will cause only part of the scanline to be compressed. And okay, tea time: this is obsolete. Now all images are compressed if possible. So don't come to this option expecting modern behavior, bestie. πŸ’€

libAfterImage/asimage/asimage_init()


🏷️ NAME

asimage_init()

frees datamembers of the supplied ASImage structure, and initializes it to all 0. Reset era. 🌸

πŸ“œ SYNOPSIS

void asimage_init (ASImage * im, Bool free_resources);

πŸ“₯ INPUTS

  • im β€” pointer to a valid ASImage structure.
  • free_resources β€” if True, will make the function attempt to free all non-NULL pointers.

libAfterImage/asimage/flush_asimage_cache()


🏷️ NAME

flush_asimage_cache()

destroys XImage and mask XImage kept from previous conversions to/from X Pixmap. Clearing the cache, clearing the clutter. 🧹

πŸ“œ SYNOPSIS

void flush_asimage_cache (ASImage * im );

πŸ“₯ INPUTS

  • im β€” pointer to a valid ASImage structure.

libAfterImage/asimage/asimage_start()


🏷️ NAME

asimage_start()

Allocates the memory needed to store a scanline of the image of the supplied size. Assigns all the data members valid values. Makes sure that the ASImage structure is ready to store image data. Getting the whole thing prepped and cute. πŸŽ€

πŸ“œ SYNOPSIS

void asimage_start (ASImage * im, unsigned int width,
                                  unsigned int height,
                                  unsigned int compression);

πŸ“₯ INPUTS

  • im β€” pointer to a valid ASImage structure.
  • width β€” width of the image.
  • height β€” height of the image.
  • compression β€” level of compression to perform on image data. compression has to be in the range of 0-100, with 100 signifying the highest level of compression.

πŸ“ NOTES

Heads up bestie: in order to resize an ASImage structure after asimage_start() has been called, you must invoke asimage_init() first to free all the memory, and then call asimage_start() with the new dimensions. No shortcuts, no skipping steps. πŸ’…

libAfterImage/asimage/create_asimage()


🏷️ NAME

create_asimage()

Performs memory allocation for the new ASImage structure, plus initialization of that freshly allocated structure based on the supplied parameters. Born ready. ✨

πŸ“œ SYNOPSIS

ASImage *create_asimage( unsigned int width,
                         unsigned int height,
                         unsigned int compression);

πŸ“₯ INPUTS

  • width β€” desired image width.
  • height β€” desired image height.
  • compression β€” compression level in the new ASImage (see asimage_start() for more).

πŸ“€ RETURN VALUE

Pointer to the newly allocated and initialized ASImage structure on Success. NULL in case of any kind of error β€” which, and I quote, should never happen. 😭

libAfterImage/asimage/clone_asimage()


🏷️ NAME

clone_asimage()

πŸ“œ SYNOPSIS

ASImage *clone_asimage(ASImage *src, ASFlagType filter );

πŸ“₯ INPUTS

  • src β€” the original ASImage.
  • filter β€” bitmask of channels to be copied from one image to another.

πŸ“€ RETURN VALUE

A new ASImage, as a copy of the original image. 🫢

πŸ’¬ DESCRIPTION

Creates an exact clone of the original ASImage, with the same compression, back_color and the rest of the attributes. Only ASImage data will be carried over. Any attached alternative forms of images (XImages, etc.) will not be copied. And any channel with an unset bit in filter will not be copied either β€” you're literally choosing what comes along for the ride.

Important: Image name, ASImageManager and ref_count will not be copied β€” use store_asimage() afterwards, and make sure you use a different name, to avoid clashes with the original image. No identity theft in this house. πŸ’€

libAfterImage/asimage/destroy_asimage()


🏷️ NAME

destroy_asimage()

frees all the memory allocated for the specified ASImage. Cleanup era, we love to see it. 🌸

πŸ“œ SYNOPSIS

void destroy_asimage( ASImage **im );

πŸ“₯ INPUTS

  • im β€” pointer to a valid ASImage structure.

πŸ“ NOTES

If there was an XImage attached to it β€” that gets deallocated as well. No stragglers, no leftovers. ✨

πŸ“ EXAMPLE

asview.c: ASView.5

libAfterImage/asimage/asimage_replace()


🏷️ NAME

asimage_replace()

will replace ASImage's data using data from another ASImage. Glow-up via swap. πŸ”„

πŸ“œ SYNOPSIS

Bool asimage_replace (ASImage *im, ASImage *from);

πŸ“₯ INPUTS

  • im β€” pointer to a valid ASImage structure.
  • from β€” pointer to the ASImage from which to take the data.

πŸ“ NOTES

This function updates the image without reallocating the structure itself, which means all pointers to it will still be valid. Bestie, that's the whole point. πŸ‘‘

But listen: if that function succeeds β€” the from ASImage will become unusable and should be deallocated using a free() call. It gave everything it had. 🫢

libAfterImage/asimage/set_asimage_vector()


🏷️ NAME

set_asimage_vector()

This function replaces contents of the vector member of the ASImage structure with new double precision data. New data, who dis. ✨

πŸ“œ SYNOPSIS

set_asimage_vector( ASImage *im, register double *vector );
  • im β€” pointer to a valid ASImage structure, bestie. like, an actual one, not a vibe πŸ’…
  • vector β€” the scientific data you're attaching to the image. yes, actual numbers. slay πŸ”₯

✨ NOTES ✨

okay so listen β€” the data has to have size of width*height, where width and height are the size of the ASImage. no shortcuts, no "close enough". the math has to math. 🌸

libAfterImage/asimage/vectorize_asimage()


πŸ“› NAME β€” vectorize_asimage() πŸ’«

this one replaces the contents of the vector member of the ASImage structure with brand new double precision data, generated from native ARGB32 image contents. and the color palette? generated by indexing color values using the max_colors, dither and opaque_threshold parameters. iconic behavior honestly πŸ‘‘

πŸ¦‹ SYNOPSIS πŸ¦‹

ASVectorPalette* vectorize_asimage( ASImage *im,
                                    unsigned int max_colors,
                                    unsigned int dither,
                                    int opaque_threshold );

πŸ’– INPUTS πŸ’–

  • im β€” pointer to valid ASImage structure. 🫢
  • max_colors β€” maximum size of the colormap.
  • dither β€” number of bits to strip off the color data ( 0...7 ). yes that's the range. don't be weird about it.
  • opaque_threshold β€” alpha channel threshold at which pixel should be treated as opaque

🌈 RETURN VALUE 🌈

pointer to the ASVectorPalette structure that could be used for reverse conversion from double values to ARGB32. it's giving utility. it's giving round trip. ✨

πŸŽ€ NOTES πŸŽ€

the alt.vector member of the supplied ASImage will be replaced, and will contain WIDTHxHEIGHT double values representing generated scientific data. so like, heads up β€” your old data is gone gone. πŸ’€

libAfterImage/asimage/create_image_manager()


πŸ“› NAME β€” create_image_manager() πŸ‘‘

create ASImage management and reference counting object. it's literally the adult supervision of your images. 🧚

πŸ¦‹ SYNOPSIS πŸ¦‹

ASImageManager *create_image_manager( ASImageManager *reusable_memory,
                                      double gamma, ... );

πŸ’– INPUTS πŸ’–

  • reusable_memory β€” optional pointer to a block of memory to be used to store ASImageManager object.
  • double gamma β€” value of gamma correction to be used while loading images from files.
  • ... β€” NULL terminated list of up to 8 PATH strings to list locations at which images could be found. up to 8, bestie. not 9. do not.

🌸 DESCRIPTION 🌸

Creates the ASImageManager object in memory and initializes it with the requested gamma value and PATH list. This object will contain a hash table referencing all the loaded images. When such an 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. fr fr consistent.

File name will be used as the image name, and if the same file is attempted to be loaded again β€” instead the reference will be incremented, and the previously loaded image will be returned. no double loading, no wasted memory, main character efficiency. πŸ’…

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. so like, respect the chain of command ok 😀

libAfterImage/asimage/destroy_image_manager()


πŸ“› NAME β€” destroy_image_manager() πŸ’€

destroy management object. (the source says "obejct", but the vibe is destruction either way.)

πŸ¦‹ SYNOPSIS πŸ¦‹

void destroy_image_manager( struct ASImageManager *imman,
                            Bool reusable );

πŸ’– INPUTS πŸ’–

  • imman β€” pointer to ASImageManager object to be deallocated
  • reusable β€” if True, then memory that holds object itself will not be deallocated. Useful when object is created on stack. 🫢

🌸 DESCRIPTION 🌸

Destroys all the referenced images, PATH values, and if reusable is False, also deallocates object's memory. full cleanout. no survivors. ✨

libAfterImage/asimage/store_asimage()


πŸ“› NAME β€” store_asimage() πŸŽ€

add ASImage to the reference. put it in the group chat, essentially.

πŸ¦‹ SYNOPSIS πŸ¦‹

Bool store_asimage( ASImageManager* imageman, ASImage *im,
                    const char *name );

πŸ’– INPUTS πŸ’–

  • imageman β€” pointer to valid ASImageManager object.
  • im β€” pointer to the image to be stored.
  • name β€” unique name of the image. unique, okay? that's the whole point. πŸ™ˆ

🌸 DESCRIPTION 🌸

Adds the specified image to the ASImageManager's list of referenced images. A stored ASImage could be deallocated only by release_asimage(), or when the ASImageManager object itself is destroyed. those are the rules. periodt. πŸ’…

libAfterImage/asimage/relocate_asimage()


πŸ“› NAME β€” relocate_asimage() πŸ¦‹

relocate ASImage into a different image manager. moving day, but for pointers. πŸ“¦

πŸ¦‹ SYNOPSIS πŸ¦‹

void     relocate_asimage( ASImageManager* to_imageman, ASImage *im );

πŸ’– INPUTS πŸ’–

  • to_imageman β€” pointer to valid ASImageManager object. (this is the destination, the new home 🏑)
  • im β€” pointer to the image to be stored.

🌸 DESCRIPTION 🌸

Moves image from one ASImageManager's list of referenced images into another ASImageManager. Reference count will be kept the same. no drama, no recount, it just slides over. 😌

libAfterImage/asimage/fetch_asimage()


πŸ“› NAME β€” fetch_asimage(), query_asimage() 🌟

πŸ¦‹ SYNOPSIS πŸ¦‹

ASImage *fetch_asimage( ASImageManager* imageman, const char *name );
ASImage *query_asimage( ASImageManager* imageman, const char *name );

πŸ’– INPUTS πŸ’–

  • imageman β€” pointer to valid ASImageManager object.
  • name β€” unique name of the image.

🌸 DESCRIPTION 🌸

Looks for image with the name in ASImageManager's list and if found, returns pointer to it. here's the crucial difference bestie: query_asimage() does not increment the reference count, while fetch_asimage() does. Therefore if fetch_asimage() is used β€” release_asimage() should be called, when image is no longer in use. the way that forgetting this leaks memory 😭

libAfterImage/asimage/dup_asimage()


πŸ“› NAME β€” dup_asimage() πŸ’–

increment reference count of stored ASImage. it's giving "me too, me too!"

πŸ¦‹ SYNOPSIS πŸ¦‹

ASImage *dup_asimage( ASImage* im );

πŸ’– INPUTS πŸ’–

  • im β€” pointer to already referenced image.

libAfterImage/asimage/release_asimage()


πŸ“› NAME β€” release_asimage() πŸ’…

decrement reference count for given ASImage. and release_asimage_by_name() decrements reference count for ASImage identified by its name. two icons, one entry.

πŸ¦‹ SYNOPSIS πŸ¦‹

int release_asimage( ASImage *im );
int release_asimage_by_name( ASImageManager *imman, char *name );

πŸ’– INPUTS πŸ’–

  • im β€” pointer to already referenced image.
  • imageman β€” pointer to valid ASImageManager object.
  • name β€” unique name of the image.

🌸 DESCRIPTION 🌸

Decrements reference count on the ASImage object and destroys it if reference count is below zero. that's it. that's the whole job. clean, simple, slay. ✨

libAfterImage/asimage/forget_asimage()


πŸ“› NAME β€” forget_asimage() πŸ«₯

remove ASImage from ASImageManager's hash by pointer. and forget_asimage_name() removes ASImage from ASImageManager's hash by its name. two ways to be forgotten, bestie πŸ’”

πŸ¦‹ SYNOPSIS πŸ¦‹

void     forget_asimage( ASImage *im );
void  forget_asimage_name( ASImageManager *imman, const char *name );

πŸ’– INPUTS πŸ’–

  • im β€” pointer to already referenced image.
  • imageman β€” pointer to valid ASImageManager object.
  • name β€” unique name of the image.

libAfterImage/safe_asimage_destroy()


πŸ“› NAME β€” safe_asimage_destroy() πŸ›‘οΈ

either release or destroy the asimage, checking if it is attached to an ASImageManager. it's the "look before you leap" of destructors. ngl kind of the responsible friend of the group. 🫢

πŸ¦‹ SYNOPSIS πŸ¦‹

int      safe_asimage_destroy( ASImage *im );

πŸ’– INPUTS πŸ’–

  • im β€” pointer to an ASImage structure.

libAfterImage/print_asimage_manager()


πŸ“› NAME β€” print_asimage_manager() πŸ–¨οΈ

prints list of images referenced in given ASImageManager structure. a little roster. a little attendance sheet. attendance is mandatory btw. πŸ“‹

libAfterImage/asimage/destroy_asgradient()


πŸ“› NAME β€” destroy_asgradient() 🌈

  • destroy ASGradient structure, deallocating all associated memory. gradient's over, babe. it served its lewk and now it's gone. πŸ’«

libAfterImage/asimage/init_image_layers()


πŸ“› NAME β€” init_image_layers() 🧁

  • initialize set of ASImageLayer structures.

πŸ¦‹ SYNOPSIS πŸ¦‹

void init_image_layers( register ASImageLayer *l, int count );

πŸ’– INPUTS πŸ’–

  • l β€” pointer to valid ASImageLayer structure.
  • count β€” number of elements to initialize.

🌸 DESCRIPTION 🌸

Initializes an array of ASImageLayer structures to sensible defaults. Basically β€” all zeros and merge_scanlines == alphablend_scanlines. like a fresh notepad. blank slate energy. ✨

libAfterImage/asimage/create_image_layers()


πŸ“› NAME β€” create_image_layers() πŸ‘‘

  • allocate and initialize set of ASImageLayer's.

πŸ¦‹ SYNOPSIS πŸ¦‹

ASImageLayer *create_image_layers( int count );

πŸ’– INPUTS πŸ’–

  • count β€” number of ASImageLayer structures in allocated array.

🌈 RETURN VALUE 🌈

Pointer to newly allocated and initialized array of ASImageLayer structures on Success. NULL in case of any kind of error β€” that should never happen. (should never happen is doing a lot of heavy lifting in that sentence ngl πŸ’€)

🌸 DESCRIPTION 🌸

Performs memory allocation for the new array of ASImageLayer structures, as well as initialization of the allocated structure to sensible defaults β€” merge_func will be set to alphablend_scanlines. yes it pre-sets that for you. she's thoughtful like that. πŸŽ€

libAfterImage/asimage/destroy_image_layers()


πŸ“› NAME β€” destroy_image_layers() πŸ’₯

  • destroy set of ASImageLayer structures.

πŸ¦‹ SYNOPSIS πŸ¦‹

void destroy_image_layers( register ASImageLayer *l,
                           int count,
                           Bool reusable );

πŸ’– INPUTS πŸ’–

  • l β€” pointer to pointer to valid array of ASImageLayer structures.
  • count β€” number of structures in array.
  • reusable β€” if True β€” then array itself will not be deallocated β€” which is usable when it was allocated on stack. 🫢

🌸 DESCRIPTION 🌸

frees all the memory allocated for the specified array of ASImageLayers. If there was an ASImage and/or ASImageBevel attached to it β€” it will be deallocated as well. yes, they come down with the ship. collateral cleanup. πŸ’…

libAfterImage/asimage/asimage_add_line()


πŸ“› NAME β€” asimage_add_line() ⭐

πŸ¦‹ SYNOPSIS πŸ¦‹

size_t asimage_add_line ( ASImage * im, ColorPart color,
                          CARD32 * data, unsigned int y);

πŸ’– INPUTS πŸ’–

  • im β€” pointer to valid ASImage structure
  • color β€” color channel's number
  • data β€” raw channel data of 32 bits per pixel β€” only lowest 8 bits gets encoded. only the bottom 8. the rest get ignored, like your ex's texts. πŸ™ˆ
  • y β€” image row starting with 0

🌈 RETURN VALUE 🌈

asimage_add_line() returns size of the encoded channel scanline in bytes. On failure it will return 0. zero. nada. red flag check. 🚩

🌸 DESCRIPTION 🌸

Encodes raw data of the single channel into an ASImage channel scanline. Based on the compression level selected for this ASImage, all or part of the scanline will be RLE encoded. compression said "I'll take some of it" and honestly? valid. πŸ”₯

libAfterImage/asimage/asimage_add_line_mono()


πŸ“› NAME β€” asimage_add_line_mono() πŸŽ€

πŸ¦‹ SYNOPSIS πŸ¦‹

size_t asimage_add_line_mono ( ASImage * im, ColorPart color,
                               CARD8 value, unsigned int y);

πŸ’– INPUTS πŸ’–

  • im β€” pointer to valid ASImage structure
  • color β€” color channel's number
  • value β€” value for the channel
  • y β€” image row starting with 0

🌈 RETURN VALUE 🌈

asimage_add_line_mono() returns size of the encoded channel scanline in bytes. On failure it will return 0.

🌸 DESCRIPTION 🌸

encodes ASImage channel scanline to have the same color components value in every pixel. Useful for vertical gradients for example. yes, every single pixel. uniformity. consistency. a little bit of monotony, but in a chic way. πŸ’…

libAfterImage/asimage/get_asimage_chanmask()


πŸ“› NAME β€” get_asimage_chanmask() πŸ”

πŸ¦‹ SYNOPSIS πŸ¦‹

ASFlagType get_asimage_chanmask( ASImage *im);

πŸ’– INPUTS πŸ’–

  • im β€” valid ASImage object.

🌸 DESCRIPTION 🌸

goes through all the scanlines of the ASImage and toggles bits representing those components that have at least some data. it's basically doing a vibe check on each channel β€” do you have data or not, bestie? πŸ’–

libAfterImage/asimage/move_asimage_channel()


πŸ“› NAME β€” move_asimage_channel() πŸ¦‹

πŸ¦‹ SYNOPSIS πŸ¦‹

void move_asimage_channel( ASImage *dst, int channel_dst,
                           ASImage *src, int channel_src );

πŸ’– INPUTS πŸ’–

  • dst β€” ASImage which will have its channel substituted;
  • channel_dst β€” what channel to move data to;
  • src β€” ASImage which will donate its channel to dst;
  • channel_src β€” what source image channel to move data from.

🌸 DESCRIPTION 🌸

MOves channel data from one ASImage to another, while discarding what was already in destination's channel. so the destination's old data? gone. no merge, no blend, no compromise. out with the old, in with the donated. πŸ’«

🌸 NOTES 🌸

okay so bestie, listen β€” these are the receipts you need before you touch any of this πŸ’…

The source image (aka the donor, the one giving the gift 🎁) is gonna lose all its channel data, because that data is getting moved into the destination ASImage. It's not a copy, it's a relocation. The donor walks away with nothing. RIP to it fr 😭

Also there's a whole condition here: both images must be the same width. If they're not? The function just… returns. Does nothing. No error, no drama, just vibes and silence πŸ™ˆ

But if the heights differ? No problem β€” the minimum of the two gets used. Slay, adaptive ✨

libAfterImage/asimage/copy_asimage_channel()


πŸ’– NAME πŸ’–

copy_asimage_channel()

✨ SYNOPSIS ✨

void copy_asimage_channel( ASImage *dst, int channel_dst,
                           ASImage *src, int channel_src );

πŸŽ€ INPUTS πŸŽ€

  • dst β€” the ASImage that's about to get one of its channels swapped out, main character energy πŸ‘‘
  • channel_dst β€” which channel we're copying the data to
  • src β€” the ASImage donating its channel to dst, so generous 🫢
  • channel_src β€” which channel on the source image we're copying the data from

πŸ¦‹ DESCRIPTION πŸ¦‹

Same as move_asimage_channel(), except β€” and this is the whole plot twist β€” it makes an actual copy of the channel's data instead of just yeeting it from one image to the other. Original stays. Iconic, non-destructive behavior πŸ’œ

libAfterImage/asimage/copy_asimage_lines()


πŸ’– NAME πŸ’–

copy_asimage_lines()

✨ SYNOPSIS ✨

void copy_asimage_lines( ASImage *dst, unsigned int offset_dst,
                         ASImage *src, unsigned int offset_src,
                         unsigned int nlines, ASFlagType filter );

πŸŽ€ INPUTS πŸŽ€

  • dst β€” the ASImage getting its channel substituted
  • offset_dst β€” the scanline in the destination image you're copying to
  • src β€” the ASImage donating its channel to dst
  • offset_src β€” the scanline in the source image you're copying data from
  • nlines β€” how many scanlines are getting copied
  • filter β€” tells us which channels should actually be copied, gatekeeping as it should πŸ’…

πŸ¦‹ DESCRIPTION πŸ¦‹

It copies scanline data for a continuous set of scanlines, and it only touches the channels that are marked in filter. Selective queen ✨

NOTE: the images must be the same width. No negotiation.

libAfterImage/asimage/verbosity


🌈 FUNCTION 🌈

These are the flags that decide what asimage_print_line() actually prints out:

  • VRB_LINE_SUMMARY β€” just the summary for each scanline, no oversharing πŸ™ˆ
  • VRB_LINE_CONTENT β€” the summary and the data for each scanline
  • VRB_CTRL_EXPLAIN β€” the summary, the data, and the control codes for each scanline. Full transparency, we love to see it πŸ’–

πŸ“ SOURCE πŸ“

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


πŸ’– NAME πŸ’–

asimage_print_line()

✨ SYNOPSIS ✨

unsigned int asimage_print_line ( ASImage * im, ColorPart color,
                                  unsigned int y,
                                  unsigned long verbosity);

πŸŽ€ INPUTS πŸŽ€

  • im β€” pointer to a valid ASImage structure
  • color β€” the color channel's number
  • y β€” image row, and it starts counting at 0 (zero-indexed girlies rise up πŸ™Œ)
  • verbosity β€” the verbosity level; any combination of flags is allowed, mix and match bestie

πŸ”₯ RETURN VALUE πŸ”₯

The amount of memory used by this particular channel of the specified scanline. Numbers, but make it fashion πŸ’…

πŸ¦‹ DESCRIPTION πŸ¦‹

asimage_print_line() prints the data stored in the channel of the specified image scanline. That can include a simple summary of how much memory is used, the actual visible data, and/or RLE control codes. Basically it helps you see how effectively the data is encoded. Vibe check on your compression πŸ”

Mostly useful for debugging purposes. She's a dev tool, not a spotlight girlie πŸŽ€

libAfterImage/asimage/get_asimage_channel_rects()


πŸ’– NAME πŸ’–

get_asimage_channel_rects() β€” translate image into a list of rectangles.

✨ SYNOPSIS ✨

XRectangle*
    get_asimage_channel_rects( ASImage *src, int channel,
                               unsigned int threshold,
                               unsigned int *rects_count_ret );

πŸŽ€ INPUTS πŸŽ€

  • src β€” ASImage which will donate its channel to dst
  • channel β€” what source image channel to copy data from
  • threshold β€” the threshold that channel values get compared against
  • rects_count_ret β€” returns the count of generated rectangles

πŸ¦‹ DESCRIPTION πŸ¦‹

This one translates the contents of a selected channel (usually alpha, the shy one) into a whole list of rectangles, encompassing the regions where values are above the threshold. Super useful for generating the shape of a window to use with the X Shape extension. Window shaped like a butterfly? Possible. πŸ¦‹βœ¨


aaaaand that's the whole page bestie, you made it to the end, so proud of you fr fr πŸ₯ΉπŸ’– This was AfterStep v.2.2.12, from the 3rd Berkeley Distribution, and asimage(3x) says hi and hopes you slayed πŸŒˆπŸ‘‘

periodt. πŸ’…

πŸ“¦ where this page comes from