1asflip(1) AfterStep X11 window manager asflip(1)
2
3
4
6 asflip - demonstrates flipping image in 90 degree increments libAfter‐
7 Image/tutorials/ASFlip
8
11 libAfterImage application for image rotation.
12
14 New steps described in this tutorial are :
15 ASFlip.1. Flip value.
16 ASFlip.2. Rotating ASImage.
17
19 Tutorial 1: ASView - explanation of basic steps needed to use
20 libAfterImage and some other simple things.
21 Tutorial 2: ASScale - image scaling basics.
22 Tutorial 3: ASTile - image tiling and tinting.
23 Tutorial 4: ASMerge - scaling and blending of arbitrary number of
24 images.
25 Tutorial 5: ASGrad - drawing multipoint linear gradients.
26
28 Source :
29 #include "../afterbase.h"
30 #include "../afterimage.h"
31 #include "common.h"
32
33 void usage()
34 {
35 printf( "Usage: asflip [-h]|[[-f flip]|[-m vertical] "
36 "[-g geom] image]");
37 printf( "0here: image - is image filename0);
38 printf( " flip - rotation angle in degrees. "
39 "90, 180 and 270 degrees supported0);
40 printf( " geom - source image is tiled using this geometry, "
41 "prior to rotation0);
42 printf( " vertical - 1 - mirror image in vertical direction, "
43 "0 - horizontal0);
44 }
45
46 int main(int argc, char* argv[])
47 {
48 ASVisual *asv ;
49 int screen = 0 , depth = 0 ;
50 char *image_file = "rose512.jpg" ;
51 int flip = FLIP_VERTICAL;
52 Bool vertical = False, mirror = False ;
53 int tile_x, tile_y, geom_flags = 0;
54 unsigned int tile_width, tile_height ;
55 ASImage *im = NULL;
56 ASImage *flipped_im = NULL ;
57
58 /* see ASView.1 : */
59 set_application_name( argv[0] );
60
61 if( argc > 1 )
62 {
63 int i = 1 ;
64 if( strcmp( argv[1], "-h" ) == 0 )
65 {
66 usage();
67 return 0;
68 }
69 for( i = 1 ; i < argc ; i++ )
70 {
71 if( argv[i][0] == '-' && i < argc-1 )
72 {
73 switch(argv[i][1])
74 {
75 case 'm' :
76 mirror = True;
77 vertical = atoi(argv[i+1]) ;
78 break ;
79 case 'f' : /* see ASFlip.1 */
80 mirror = False;
81 flip = atoi(argv[i+1])/90 ;
82 break ;
83 case 'g' : /* see ASTile.2 : */
84 geom_flags = XParseGeometry( argv[i+1],
85 &tile_x, &tile_y,
86 &tile_width,
87 &tile_height );
88 break ;
89 }
90 ++i ;
91 }else
92 image_file = argv[i] ;
93 }
94 }else
95 usage();
96
97 #ifndef X_DISPLAY_MISSING
98 dpy = XOpenDisplay(NULL);
99 _XA_WM_DELETE_WINDOW = XInternAtom( dpy, "WM_DELETE_WINDOW", False);
100 screen = DefaultScreen(dpy);
101 depth = DefaultDepth( dpy, screen );
102 #endif
103 /* see ASView.2 : */
104 im = file2ASImage( image_file, 0xFFFFFFFF, SCREEN_GAMMA, 0, getenv("IMAGE_PATH"), NULL );
105 if( im == NULL )
106 return 1;
107
108 /* Making sure tiling geometry is sane : */
109 if( !get_flags(geom_flags, XValue ) )
110 tile_x = 0 ;
111 if( !get_flags(geom_flags, YValue ) )
112 tile_y = 0 ;
113 if( !get_flags(geom_flags, WidthValue ) )
114 {
115 if( !mirror )
116 tile_width = (get_flags(flip,FLIP_VERTICAL))?
117 im->height:im->width ;
118 else
119 tile_width = im->width ;
120 }
121 if( !get_flags(geom_flags, HeightValue ) )
122 {
123 if( !mirror )
124 tile_height = (get_flags(flip,FLIP_VERTICAL))?
125 im->width:im->height;
126 else
127 tile_height = im->height ;
128 }
129 printf( "%s: tiling image
130 "flipping it by %d degrees0,
131 get_application_name(), image_file,
132 tile_width, tile_height,tile_x, tile_y, flip*90 );
133
134 /* see ASView.3 : */
135 asv = create_asvisual( dpy, screen, depth, NULL );
136
137 /* see ASFlip.2 : */
138 if( !mirror )
139 flipped_im = flip_asimage( asv, im,
140 tile_x, tile_y,
141 tile_width, tile_height,
142 flip,
143 ASA_ASImage, 0,
144 ASIMAGE_QUALITY_DEFAULT );
145 else
146 flipped_im = mirror_asimage(asv, im,
147 tile_x, tile_y,
148 tile_width, tile_height,
149 vertical,
150 ASA_ASImage, 0,
151 ASIMAGE_QUALITY_DEFAULT );
152 destroy_asimage( &im );
153
154 if( flipped_im )
155 {
156 #ifndef X_DISPLAY_MISSING
157 /* see ASView.4 : */
158 Window w = create_top_level_window( asv, DefaultRootWindow(dpy),
159 32, 32,
160 tile_width, tile_height,
161 1, 0, NULL,
162 "ASFlip", image_file );
163 if( w != None )
164 {
165 Pixmap p ;
166
167 XMapRaised (dpy, w);
168 /* see ASView.5 : */
169 p = asimage2pixmap( asv, DefaultRootWindow(dpy), flipped_im,
170 NULL, True );
171 destroy_asimage( &flipped_im );
172 /* see common.c: set_window_background_and_free() : */
173 p = set_window_background_and_free( w, p );
174 /* see common.c: wait_closedown() : */
175 wait_closedown(w);
176 }
177 if( dpy )
178 XCloseDisplay (dpy);
179 #else
180 /* writing result into the file */
181 ASImage2file( flipped_im, NULL, "asflip.jpg", ASIT_Jpeg, NULL );
182 destroy_asimage( &flipped_im );
183 #endif
184 }
185 return 0 ;
186 }
187
189 Step 1. Flip value.
190
192 libAfterImage provides facility for rotating images in 90 degree
193 increments - flipping essentially. Accordingly flip parameter could
194 have 4 values - 0, -90, -180, -270 degrees.
195
197 flip = atoi(argv[2])/90;
198
200 flip
201
203 Step 2. Flipping ASImage.
204
206 Flipping can actually be combined with offset and tiling. Original
207 image gets tiled to suplied rectangle, and then gets rotated to
208 requested degree.
209
211 flipped_im = flip_asimage(asv, im,
212 tile_x, tile_y,
213 tile_width, tile_height,
214 flip,
215 ASA_XImage,0,
216 ASIMAGE_QUALITY_DEFAULT );
217 destroy_asimage( &im );
218
220 As far as we need to render rotated image right away - we set to_xim
221 parameter to True, so that image will be rotated into XImage. Right
222 after rotation is done - we can destroy original image.
223
225 flip_asimage()
226
227
228
2293rd Berkeley Distribution AfterStep v.2.2.6 asflip(1)