asview(3x)
asview(3x) β AfterStep X11 window manager π
okay bestie, buckle up, we're reading the manual page for asview from the AfterStep X11 window manager corner of the universe. no cap.
β¨ NAME β¨
asview β demonstrates loading and displaying of images
libAfterImage/tutorials/ASView
π NAMEASView π
π¦ SYNOPSIS π¦
Simple image viewer based on libAfterImage.
π DESCRIPTION π
okay so literally all we want to do here is:
- grab the image filename off the command line,
- load that image,
- display it in a simple window,
- and then just⦠wait. politely. until the user closes our window. queen behavior.
that's the whole vibe. π«Ά
π SOURCE π
the full glow-up, verbatim, no edits, i do not make the rules:
#define DO_CLOCKING
#include "../afterbase.h" #include "../afterimage.h" #include
"common.h"
#ifdef DO_CLOCKING #if TIME_WITH_SYS_TIME # include <sys/time.h> #
include <time.h> #else # if HAVE_SYS_TIME_H # include <sys/time.h>
# else # include <time.h> # endif #endif #endif
void usage() {
printf( "Usage: asview [-h]|[image]\n");
printf( "Where: image - filename of the image to display.\n"); }
int main(int argc, char* argv[]) {
char *image_file = "rose512.jpg" ;
ASImage *im ;
ASVisual *asv ;
int screen = 0, depth = 24;
Display *dpy = NULL;
/* see ASView.1 : */
set_application_name( argv[0] ); #if (HAVE_AFTERBASE_FLAG==1)
set_output_threshold(OUTPUT_LEVEL_DEBUG); #ifdef DEBUG_ALLOCS
fprintf( stderr, "have DEBUG_ALLOCS\n"); #endif #ifdef
AFTERBASE_DEBUG_ALLOCS
fprintf( stderr, "have AFTERBASE_DEBUG_ALLOCS\n"); #endif #endif
if( argc > 1 )
{
if( strcmp( argv[1], "-h" ) == 0 )
{
usage();
return 0;
}
image_file = argv[1] ;
}else
{
show_warning( "Image filename was not specified. "
"Using default: \"%s\"", image_file );
usage();
} #ifndef X_DISPLAY_MISSING
dpy = XOpenDisplay(NULL);
XSynchronize (dpy, True);
_XA_WM_DELETE_WINDOW = XInternAtom( dpy, "WM_DELETE_WINDOW",
False);
screen = DefaultScreen(dpy);
depth = DefaultDepth( dpy, screen ); #endif
/* see ASView.3 : */
asv = create_asvisual( dpy, screen, depth, NULL );
/* asv = create_asvisual_for_id( dpy, screen, depth, 0x28, None,
NULL ); */
/* see ASView.2 : */
im = file2ASImage( image_file, 0xFFFFFFFF, SCREEN_GAMMA, 0,
getenv("IMAGE_PATH"), NULL );
/* The following could be used to dump JPEG version of the image
into
* stdout : */
/* ASImage2file( im, NULL, NULL, ASIT_Jpeg, NULL );
ASImage2file( im, NULL, "asview.png", ASIT_Png, NULL );
ASImage2file( im, NULL, "asview.gif", ASIT_Gif, NULL );
*/
if( im != NULL )
{ #ifndef X_DISPLAY_MISSING
Window w ; #if 0
/* test example for get_asimage_channel_rects() : */
XRectangle *rects ; unsigned int rects_count =0; int i ;
rects = get_asimage_channel_rects( im, IC_ALPHA, 10,
&rects_count );
fprintf( stderr, " %d rectangles generated : \n",
rects_count );
for( i = 0 ; i < rects_count ; ++i )
fprintf( stderr, "\trect[%d]=%dx%d%+d%+d;\n",
i, rects[i].width, rects[i].height,
rects[i].x, rects[i].y ); #endif
#if 0
/* test example for fill_asimage : */
fill_asimage(asv, im, 0, 0, 50, 50, 0xFFFF0000);
fill_asimage(asv, im, 50, 50, 100, 50, 0xFFFF0000);
fill_asimage(asv, im, 0, 100, 200, 50, 0xFFFF0000);
fill_asimage(asv, im, 150, 0, 50, 50, 0xFFFF0000); #endif
#if 0
/* test example for conversion to argb32 :*/
{
ASImage *tmp = tile_asimage( asv, im, 0, 0, im->width,
im->height, TINT_NONE, ASA_ARGB32,
0, ASIMAGE_QUALITY_DEFAULT
);
destroy_asimage( &im );
set_flags( tmp->flags,
ASIM_DATA_NOT_USEFUL|ASIM_XIMAGE_NOT_USEFUL );
im = tmp ;
} #endif
/* see ASView.4 : */
w = create_top_level_window( asv, DefaultRootWindow(dpy),
32, 32,
im->width, im->height, 1, 0,
NULL,
"ASView", image_file );
if( w != None )
{
Pixmap p ;
XMapRaised (dpy, w);
XSync(dpy,False);
/* see ASView.5 : */
p = create_visual_pixmap( asv, DefaultRootWindow(dpy),
im->width, im->height, 0 );
{
START_TIME(started);
/* for( int i = 0 ; i < 100 ; ++i ) To test
performance! */
asimage2drawable( asv, p, im, NULL, 0, 0, 0, 0,
im->width, im->height, False);
SHOW_TIME("", started);
}
/* print_storage(NULL); */
destroy_asimage( &im );
/* see common.c:set_window_background_and_free(): */
p = set_window_background_and_free( w, p );
}
/* see common.c: wait_closedown() : */
wait_closedown(w);
dpy = NULL;
/* no longer need this - lets clean it up :*/
destroy_asvisual( asv, False );
asv = NULL ;
#else
/* writing result into the file */
ASImage2file( im, NULL, "asview.png", ASIT_Png, NULL );
#endif
}
#ifdef DEBUG_ALLOCS
/* different cleanups of static memory pools : */
flush_ashash_memory_pool();
asxml_var_cleanup();
custom_color_cleanup();
build_xpm_colormap( NULL );
flush_default_asstorage();
/* requires libAfterBase */
print_unfreed_mem(); #endif
return 0 ; }
libAfterImage/tutorials/ASView.1 [1.1]
π SYNOPSIS π
Step 1. Initialization.
π DESCRIPTION π
libAfterImage only needs 2 global things set up, and honestly both of them are inherited from libAfterBase:
dpyβ pointer to an open X display. naturally that is something we cannot live without, it's giving oxygen.- application name β used in all the text output, like error and warning messages, and also debugging messages if such are enabled.
and the next two lines? that's genuinely all that's required to set up both of those global variables. iconic.
β¨ EXAMPLE β¨
set_application_name( argv[0] );
dpy = XOpenDisplay(NULL);
π NOTES π
First line is setting up the application name from the command line's program name. Second one opens up the X display specified in the DISPLAY env. variable. Naturally, based on application purpose, different parameters can be passed to these functions β such as some custom display string. you do you π
π«Ά SEE ALSO π«Ά
libAfterBase, set_application_name(), XOpenDisplay(), Display, libAfterImage/tutorials/ASView.2 [1.2]
libAfterImage/tutorials/ASView.2 [1.2]
π SYNOPSIS π
Step 2. Loading image file.
π DESCRIPTION π
At this point we are ready to load the image from the file into memory. Since libAfterImage does not use any X facilities to store the image, we don't have to create any window or anything else yet. even dpy is optional here β it will only be used to try and parse names of colors from .XPM images. lowkey freeing.
β¨ EXAMPLE β¨
im = file2ASImage( image_file, 0xFFFFFFFF, SCREEN_GAMMA, 0, NULL);
π NOTES π
We used compression set to 0, because we do not intend to store the image in memory for any considerable amount of time, and we want to avoid the additional processing overhead related to image compression. If the image was loaded successfully β which is indicated by the returned pointer being not NULL β we can proceed to creation of the window and displaying of the image. slay.
π«Ά SEE ALSO π«Ά
file2ASImage()
libAfterImage/tutorials/ASView.3 [1.3]
π SYNOPSIS π
Step 3. Preparation of the visual.
π DESCRIPTION π
At this point we have to obtain Visual information, because window creation is highly dependent on the Visual being used. In fact, when X creates a window it ties it to a particular Visual, and all its attributes β such as colormap, pixel values, pixmaps, etc. β must be associated with the same Visual. accordingly we need to acquire the ASVisual structure, which is our abstraction layer from them naughty X Visuals πΈ :
β¨ EXAMPLE β¨
asv = create_asvisual( dpy, screen, depth, NULL );
π NOTES π
If any Window or Pixmap is created based on a particular ASVisual, then this ASVisual structure must not be destroyed until all such Windows and Pixmaps are destroyed. do not free her early bestie, she is not done yet π
π«Ά SEE ALSO π«Ά
See create_asvisual() for details.
libAfterImage/tutorials/ASView.4 [1.4]
π SYNOPSIS π
Step 4. Preparation of the window.
π DESCRIPTION π
Creation of a top level window consists of several steps of its own:
a) create the window of desired size and placement b) set ICCCM hints on the window c) select appropriate events on the window c) map the window.
First two steps have been moved out into the create_top_level_window() function. (yes, there are two "c)"s, i am simply reporting the lore as written π)
β¨ EXAMPLE β¨
w = create_top_level_window( asv, DefaultRootWindow(dpy), 32, 32,
im->width, im->height, 1, 0, NULL,
"ASView" );
if( w != None )
{
XSelectInput (dpy, w, (StructureNotifyMask | ButtonPress));
XMapRaised (dpy, w);
}
π NOTES π
Map request should be made only for a window that has all its hints set up already, so that the Window Manager can read them right away. We want to map the window as soon as possible so that the User could see that something really is going on, even before the image is displayed. main character energy: show up first, deliver later β¨
π«Ά SEE ALSO π«Ά
ASImage, create_top_level_window()
libAfterImage/tutorials/ASView.5 [1.5]
π SYNOPSIS π
Step 5. Displaying the image.
π DESCRIPTION π
The simplest way to display an image in the window is to convert it into a Pixmap, then set the Window's background to this Pixmap, and, at last, clear the window, so that the background shows up. the reveal. the moment. π
β¨ EXAMPLE β¨
p = asimage2pixmap( asv, DefaultRootWindow(dpy), im, NULL, False );
destroy_asimage( &im );
π NOTES π
We no longer need ASImage after we transferred it onto the Pixmap, so we better destroy it to conserve resources. no hoarding, we're minimalists now π§
π«Ά SEE ALSO π«Ά
asimage2pixmap(), destroy_asimage(), set_window_background_and_free()
okay that's the whole page bestie, you ate it, you understood it, periodt ππ
and for the receipts at the bottom β this one's from the 3rd Berkeley Distribution, AfterStep v.2.2.12, dated asview(3x). go forth and view some images β¨π¦π
π¦ 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