---
name: "asflip"
section: "3x"
platform: "linux"
package: "libafterimage-dev"
version: "2.2.12-18"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/asflip"
---

# asflip(3x)

demonstrates flipping image in 90 degree increments libAfterImage/tutorials/ASFlip

## NAME

**asflip** - demonstrates flipping image in 90 degree increments libAfterImage/tutorials/ASFlip

## NAMEASFlip

## SYNOPSIS

libAfterImage application for image rotation.

## DESCRIPTION

New steps described in this tutorial are : ASFlip.1. Flip value. ASFlip.2. Rotating ASImage.

## SEE ALSO

Tutorial 1: ASView  - explanation of basic steps needed to use\
                       libAfterImage and some other simple things. Tutorial 2: ASScale - image scaling basics. Tutorial 3: ASTile  - image tiling and tinting. Tutorial 4: ASMerge - scaling and blending of arbitrary number of\
                       images. Tutorial 5: ASGrad  - drawing multipoint linear gradients.

## SOURCE

\#include "../afterbase.h" #include "../afterimage.h" #include "common.h"

void usage() {\
     printf( "Usage: asflip \[-h\]\|\[\[-f flip\]\|\[-m vertical\] "\
             "\[-g geom\] image\]");\
     printf( "\\nWhere: image - is image filename\\n");\
     printf( "       flip  - rotation angle in degrees. "\
             "90, 180 and 270 degrees supported\\n");\
     printf( "       geom  - source image is tiled using this geometry, "\
             "prior to rotation\\n");\
     printf( "       vertical - 1 - mirror image in vertical direction, "\
             "0 - horizontal\\n"); }

int main(int argc, char\* argv\[\]) {\
     Display \*dpy = NULL;\
     ASVisual \*asv ;\
     int screen = 0 , depth = 0 ;\
     char \*image\_file = "rose512.jpg" ;\
     int flip = FLIP\_VERTICAL;\
     Bool vertical = False, mirror = False ;\
     int tile\_x, tile\_y, geom\_flags = 0;\
     unsigned int tile\_width, tile\_height ;\
     ASImage \*im = NULL;\
     ASImage \*flipped\_im = NULL ;

    /\* see ASView.1 : \*/\
     set\_application\_name( argv\[0\] );

    if( argc \> 1 )\
     {\
         int i = 1 ;\
         if( strcmp( argv\[1\], "-h" ) == 0 )\
         {\
             usage();\
             return 0;\
         }\
         for( i = 1 ; i \< argc ; i++ )\
         {\
             if( argv\[i\]\[0\] == '-' && i \< argc-1 )\
             {\
                 switch(argv\[i\]\[1\])\
                 {\
                     case 'm' :\
                         mirror = True;\
                         vertical = atoi(argv\[i+1\]) ;\
                         break ;\
                     case 'f' :          /\* see ASFlip.1 \*/\
                         mirror = False;\
                         flip = atoi(argv\[i+1\])/90 ;\
                         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\
         usage();

\#ifndef X\_DISPLAY\_MISSING\
     dpy = XOpenDisplay(NULL);\
     \_XA\_WM\_DELETE\_WINDOW = XInternAtom( dpy, "WM\_DELETE\_WINDOW", False);\
     screen = DefaultScreen(dpy);\
     depth = DefaultDepth( dpy, screen ); #endif\
     /\* see ASView.2 : \*/\
     im = file2ASImage( image\_file, 0xFFFFFFFF, SCREEN\_GAMMA, 0, getenv("IMAGE\_PATH"), NULL );\
     if( im == NULL )\
         return 1;

    /\* Making sure tiling geometry is sane : \*/\
     if( !get\_flags(geom\_flags, XValue ) )\
         tile\_x = 0 ;\
     if( !get\_flags(geom\_flags, YValue ) )\
         tile\_y = 0 ;\
     if( !get\_flags(geom\_flags, WidthValue ) )\
     {\
         if( !mirror )\
             tile\_width = (get\_flags(flip,FLIP\_VERTICAL))?\
                             im-\>height:im-\>width ;\
         else\
             tile\_width = im-\>width ;\
     }\
     if( !get\_flags(geom\_flags, HeightValue ) )\
     {\
         if( !mirror )\
             tile\_height = (get\_flags(flip,FLIP\_VERTICAL))?\
                             im-\>width:im-\>height;\
         else\
             tile\_height = im-\>height ;\
     }\
     printf( "%s: tiling image \\"%s\\" to %dx%d%+d%+d and then "\
             "flipping it by %d degrees\\n",\
             get\_application\_name(), image\_file,\
             tile\_width, tile\_height,tile\_x, tile\_y, flip\*90 );

    /\* see ASView.3 : \*/\
     asv = create\_asvisual( dpy, screen, depth, NULL );

    /\* see ASFlip.2 : \*/\
     if( !mirror )\
         flipped\_im = flip\_asimage(  asv, im,\
                                     tile\_x, tile\_y,\
                                     tile\_width, tile\_height,\
                                     flip,\
                                     ASA\_ASImage, 0, \
                                     ASIMAGE\_QUALITY\_DEFAULT );\
     else\
         flipped\_im = mirror\_asimage(asv, im,\
                                     tile\_x, tile\_y,\
                                     tile\_width, tile\_height,\
                                     vertical,\
                                     ASA\_ASImage, 0, \
                                     ASIMAGE\_QUALITY\_DEFAULT );\
     destroy\_asimage( &im );

    if( flipped\_im )\
     { #ifndef X\_DISPLAY\_MISSING\
         /\* see ASView.4 : \*/\
         Window w = create\_top\_level\_window( asv, DefaultRootWindow(dpy), \
                                             32, 32,\
                                             tile\_width, tile\_height, \
                                             1, 0, NULL,\
                                             "ASFlip", image\_file );\
         if( w != None )\
         {\
             Pixmap p ;

            XMapRaised   (dpy, w);\
             /\* see ASView.5 : \*/\
             p = asimage2pixmap( asv, DefaultRootWindow(dpy), flipped\_im,\
                                 NULL, True );\
             destroy\_asimage( &flipped\_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\
         /\* writing result into the file \*/\
         ASImage2file( flipped\_im, NULL, "asflip.jpg", ASIT\_Jpeg, NULL );\
         destroy\_asimage( &flipped\_im ); #endif\
     }\
     return 0 ; }

libAfterImage/tutorials/ASFlip.1 \[6.1\]

## SYNOPSIS

Step 1. Flip value.

## DESCRIPTION

libAfterImage provides facility for rotating images in 90 degree increments - flipping essentially. Accordingly flip parameter could have 4 values - 0, -90, -180, -270 degrees.

## EXAMPLE

    flip = atoi(argv\[2\])/90;

## SEE ALSO

flip libAfterImage/tutorials/ASFlip.2 \[6.2\]

## SYNOPSIS

Step 2. Flipping ASImage.

## DESCRIPTION

Flipping can actually be combined with offset and tiling. Original image gets tiled to supplied rectangle, and then gets rotated to requested degree.

## EXAMPLE

    flipped\_im = flip\_asimage(asv, im,\
                                   tile\_x, tile\_y,\
                                   tile\_width, tile\_height,\
                                   flip,\
                                   ASA\_XImage,0, \
                                   ASIMAGE\_QUALITY\_DEFAULT );\
         destroy\_asimage( &im );

## NOTES

As far as we need to render rotated image right away - we set to\_xim parameter to True, so that image will be rotated into XImage. Right after rotation is done - we can destroy original image.

## SEE ALSO

flip\_asimage()
