astile - demonstrates image tiling/cropping and tinting libAfterImage/tutorials/ASTile
Contents
Description
Actuall tiling is quite simple - just call tile_asimage and it will generate new ASImage containing tiled
and tinted image. For the sake of example we set quality to TOP, but normally GOOD quality is quite
sufficient, and is a default. Again, compression is set to 0 since we do not intend to store image for
long time. Even better we don't need to store it at all - all we need is XImage, so we can transfer it to
the server easily. That is why to_xim argument is set to ASA_XImage. As the result obtained ASImage will
not have any data in its buffers, but it will have ximage member set to point to valid XImage.
Subsequently we enjoy that convenience, by setting use_cached to True in call to asimage2pixmap(). That
ought to save us a lot of processing.
Tinting works in both directions - it can increase intensity of the color or decrease it. If any
particular channel of the tint_color is greater then 127 then intensity is increased, otherwise its
decreased.
Example
tinted_im = tile_asimage( asv, im, tile_x, tile_y,
tile_width, tile_height,
tint_color,
ASA_XImage, 0, ASIMAGE_QUALITY_TOP ); destroy_asimage( &im );
Name
astile - demonstrates image tiling/cropping and tinting libAfterImage/tutorials/ASTile
Nameastile
Notes
See Also
tile_asimage().
3rd Berkeley Distribution AfterStep v.2.2.12 astile(3x)
Source
#include "../afterbase.h" #include "../afterimage.h" #include "common.h"
void usage() {
printf( "Usage: astile [-h]|[[-g geometry][-t tint_color] image]\n");
printf( "Where: image - source image filename.\n");
printf( " geometry - width and height of the resulting image,\n");
printf( " and x, y of the origin of the tiling on "
"source image.\n");
printf( " tint_color - color to tint image with.( defaults to "
"current time :)\n"); }
int main(int argc, char* argv[]) {
Window w ;
Display *dpy = NULL;
ASVisual *asv ;
int screen = 0, depth = 0;
char *image_file = "rose512.jpg" ;
ARGB32 tint_color = time(NULL);
int tile_x, tile_y, geom_flags = 0;
unsigned int tile_width, tile_height ;
ASImage *im ;
/* see ASView.1 : */
set_application_name( argv[0] );
#ifndef X_DISPLAY_MISSING
/* parse_argb_color can only be used after display is open,
otherwise we are limited to colors defined as ARGB values : */
dpy = XOpenDisplay(NULL);
_XA_WM_DELETE_WINDOW = XInternAtom( dpy, "WM_DELETE_WINDOW", False);
screen = DefaultScreen(dpy);
depth = DefaultDepth( dpy, screen ); #endif
if( argc > 1 )
{
int i ;
if( strncmp( argv[1], "-h", 2 ) == 0 )
{
usage();
return 0;
}
for( i = 1 ; i < argc ; i++ )
{
if( argv[i][0] == '-' && i < argc-1 )
{
switch(argv[i][1])
{
case 't' : /* see ASTile.1 : */
if( parse_argb_color( argv[i+1], &tint_color ) ==
argv[i+1] )
show_warning( "unable to parse tint color - "
"default used: #%8.8lX",
(unsigned long)tint_color );
break ;
case 'g' : /* see ASTile.2 : */
geom_flags = XParseGeometry( argv[i+1],
&tile_x, &tile_y,
&tile_width,
&tile_height );
break ;
}
++i ;
}else
image_file = argv[i] ;
}
}else
{
show_warning( "no image file or tint color specified - "
"defaults used: \"%s\" #%8.8lX",
image_file, (unsigned long)tint_color );
usage();
}
/* see ASView.2 : */
im = file2ASImage( image_file, 0xFFFFFFFF, SCREEN_GAMMA, 0, getenv("IMAGE_PATH"), NULL );
/* Making sure tiling geometry is sane : */
if( !get_flags(geom_flags, XValue ) )
tile_x = im->width/2 ;
if( !get_flags(geom_flags, YValue ) )
tile_y = im->height/2 ;
if( !get_flags(geom_flags, WidthValue ) )
tile_width = im->width*2 ;
if( !get_flags(geom_flags, HeightValue ) )
tile_height = im->height*2;
printf( "%s: tiling image \"%s\" to "
"%dx%d%+d%+d tinting with #%8.8lX\n",
get_application_name(), image_file, tile_width, tile_height,
tile_x, tile_y, (unsigned long)tint_color );
if( im != NULL )
{
/* see ASView.3 : */
asv = create_asvisual( dpy, screen, depth, NULL );
w = None ; #ifndef X_DISPLAY_MISSING
/* see ASView.4 : */
w = create_top_level_window( asv, DefaultRootWindow(dpy), 32, 32,
tile_width, tile_height, 1, 0, NULL,
"ASTile", image_file );
if( w != None )
{
Pixmap p ;
ASImage *tinted_im ;
XMapRaised (dpy, w);
/* see ASTile.3 : */
tinted_im = tile_asimage( asv, im, tile_x, tile_y,
tile_width, tile_height,
tint_color, ASA_XImage, 0,
ASIMAGE_QUALITY_TOP );
destroy_asimage( &im );
/* see ASView.5 : */
p = asimage2pixmap( asv, DefaultRootWindow(dpy), tinted_im,
NULL, True );
destroy_asimage( &tinted_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; #else
{
ASImage *tinted_im ;
/* see ASTile.3 : */
tinted_im = tile_asimage( asv, im, tile_x, tile_y,
tile_width, tile_height,
tint_color, ASA_ASImage, 0,
ASIMAGE_QUALITY_TOP );
destroy_asimage( &im );
/* writing result into the file */
ASImage2file( tinted_im, NULL, "astile.jpg", ASIT_Jpeg, NULL );
destroy_asimage( &tinted_im );
} #endif
}
return 0 ; }
libAfterImage/tutorials/ASTile.1 [3.1]
Synopsis
Step 3. Actuall tiling of the image.
