1asview(1)                AfterStep X11 window manager                asview(1)
2
3
4

NAME

6       asview -  demonstrates  loading  and  displaying  of images libAfterIm‐
7       age/tutorials/ASView
8

NAMEASView

SYNOPSIS

11       Simple image viewer based on libAfterImage.
12

DESCRIPTION

14       All we want to do here is to get image filename from the command line,
15       then load this image, and display it in simple window.
16       After that we would want to wait, until user closes our window.
17

SOURCE

19       Source :
20       #define DO_CLOCKING
21
22       #include "../afterbase.h"
23       #include "../afterimage.h"
24       #include "common.h"
25
26       #ifdef DO_CLOCKING
27       #if TIME_WITH_SYS_TIME
28       # include <sys/time.h>
29       # include <time.h>
30       #else
31       # if HAVE_SYS_TIME_H
32       #  include <sys/time.h>
33       # else
34       #  include <time.h>
35       # endif
36       #endif
37       #endif
38
39
40       void usage()
41       {
42           printf( "Usage: asview [-h]|[image]0);
43           printf( "Where: image - filename of the image to display.0);
44       }
45
46
47       int main(int argc, char* argv[])
48       {
49           char *image_file = "rose512.jpg" ;
50           ASImage *im ;
51           ASVisual *asv ;
52           int screen, depth ;
53
54           /* see ASView.1 : */
55           set_application_name( argv[0] );
56       #if (HAVE_AFTERBASE_FLAG==1)
57           set_output_threshold(OUTPUT_LEVEL_DEBUG);
58       #ifdef DEBUG_ALLOCS
59           fprintf( stderr, "have DEBUG_ALLOCS0);
60       #endif
61       #ifdef AFTERBASE_DEBUG_ALLOCS
62           fprintf( stderr, "have AFTERBASE_DEBUG_ALLOCS0);
63       #endif
64       #endif
65
66           if( argc > 1 )
67           {
68               if( strcmp( argv[1], "-h" ) == 0 )
69               {
70                   usage();
71                   return 0;
72               }
73               image_file = argv[1] ;
74           }else
75           {
76               show_warning(   "Image filename was not specified. "
77                               "Using default:
78               usage();
79           }
80       #ifndef X_DISPLAY_MISSING
81           dpy = XOpenDisplay(NULL);
82           XSynchronize (dpy, True);
83           _XA_WM_DELETE_WINDOW = XInternAtom( dpy, "WM_DELETE_WINDOW",
84                                               False);
85           screen = DefaultScreen(dpy);
86           depth = DefaultDepth( dpy, screen );
87           /* see ASView.3 : */
88           asv = create_asvisual( dpy, screen, depth, NULL );
89           /* asv = create_asvisual_for_id( dpy, screen, depth, 0x28, None, NULL ); */
90       #endif
91           /* see ASView.2 : */
92           im = file2ASImage( image_file, 0xFFFFFFFF, SCREEN_GAMMA, 0, getenv("IMAGE_PATH"), NULL );
93
94           /* The following could be used to dump JPEG version of the image into
95            * stdout : */
96           /* ASImage2file( im, NULL, NULL, ASIT_Jpeg, NULL ); */
97
98
99           if( im != NULL )
100           {
101       #ifndef X_DISPLAY_MISSING
102               Window w ;
103       #if 0
104               /* test example for get_asimage_channel_rects() : */
105               XRectangle *rects ; unsigned int rects_count =0; int i ;
106               rects = get_asimage_channel_rects( im, IC_ALPHA, 10,
107                                                   &rects_count );
108               fprintf( stderr, " %d rectangles generated : 0, rects_count );
109               for( i = 0 ; i < rects_count ; ++i )
110                   fprintf( stderr, "rect[%d]=%dx%d%+d%+d;0,
111                            i, rects[i].width, rects[i].height,
112                            rects[i].x, rects[i].y );
113       #endif
114
115
116       #if 0
117               /* test example for fill_asimage : */
118               fill_asimage(asv, im, 0, 0, 50, 50, 0xFFFF0000);
119               fill_asimage(asv, im, 50, 50, 100, 50, 0xFFFF0000);
120               fill_asimage(asv, im, 0, 100, 200, 50, 0xFFFF0000);
121               fill_asimage(asv, im, 150, 0, 50, 50, 0xFFFF0000);
122       #endif
123       #if 0
124               /* test example for conversion to argb32 :*/
125               {
126                   ASImage *tmp = tile_asimage( asv, im, 0, 0, im->width, im->height, TINT_NONE, ASA_ARGB32,
127                                                 0, ASIMAGE_QUALITY_DEFAULT );
128                   destroy_asimage( &im );
129                   set_flags( tmp->flags, ASIM_DATA_NOT_USEFUL|ASIM_XIMAGE_NOT_USEFUL );
130                   im = tmp ;
131               }
132       #endif
133               /* see ASView.4 : */
134               w = create_top_level_window( asv, DefaultRootWindow(dpy), 32, 32,
135                                            im->width, im->height, 1, 0, NULL,
136                                            "ASView", image_file );
137               if( w != None )
138               {
139                   Pixmap p ;
140
141                   XMapRaised   (dpy, w);
142                   XSync(dpy,False);
143                   /* see ASView.5 : */
144                   p = create_visual_pixmap( asv, DefaultRootWindow(dpy), im->width, im->height, 0 );
145
146                   {
147                       /*int i ;*/
148                       START_TIME(started);
149                       /* for( i = 0 ; i < 100 ; ++i )  To test performance! */
150                       asimage2drawable( asv, p, im, NULL, 0, 0, 0, 0, im->width, im->height, False);
151                       SHOW_TIME("", started);
152                   }
153                   /* print_storage(NULL); */
154                   destroy_asimage( &im );
155                   /* see common.c:set_window_background_and_free(): */
156                   p = set_window_background_and_free( w, p );
157               }
158               /* no longer need this - lets clean it up :*/
159               destroy_asvisual( asv, False );
160               asv = NULL ;
161
162               /* see common.c: wait_closedown() : */
163               wait_closedown(w);
164       #else
165               /* writing result into the file */
166               ASImage2file( im, NULL, "asview.jpg", ASIT_Jpeg, NULL );
167       #endif
168           }
169
170       #ifdef DEBUG_ALLOCS
171           /* different cleanups of static memory pools : */
172           flush_ashash_memory_pool();
173           asxml_var_cleanup();
174           custom_color_cleanup();
175           build_xpm_colormap( NULL );
176           flush_default_asstorage();
177           /* requires libAfterBase */
178           print_unfreed_mem();
179       #endif
180
181           return 0 ;
182       }
183

SYNOPSIS

185       Step 1. Initialization.
186

DESCRIPTION

188       libAfterImage requires only 2 global things to be setup, and both of
189       those are inherited from libAfterBase: dpy - pointer to open X display-
190       naturally that is something we cannot live without; application name -
191       used in all the text output, such as error and warning messages and
192       also debugging messages if such are enabled.
193       The following two line are about all that is required to setup both
194       of this global variables :
195

EXAMPLE

197           set_application_name( argv[0] );
198           dpy = XOpenDisplay(NULL);
199

NOTES

201       First line is setting up application name from command line's
202       program name. Second opens up X display specified in DISPLAY env.
203       variable. Naturally based on application purpose different parameters
204       can be passed to these functions, such as some custom display string.
205

SEE ALSO

207       libAfterBase, set_application_name(), XOpenDisplay(), Display,
208

SYNOPSIS

210       Step 2. Loading image file.
211

DESCRIPTION

213       At this point we are ready to load image from file into memory. Since
214       libAfterImage does not use any X facilities to store image - we don't
215       have to create any window or anything else yet. Even dpy is optional
216       here - it will only be used to try and parse names of colors from
217

EXAMPLE

219           im = file2ASImage( image_file, 0xFFFFFFFF, SCREEN_GAMMA, 0, NULL);
220

NOTES

222       We used compression set to 0, as we do not intend to store
223       image in memory for any considerable amount of time, and we want to
224       avoid additional processing overhead related to image compression.
225       If image was loaded successfully, which is indicated by returned
226       pointer being not NULL, we can proceed to creation of the window and
227       displaying of the image.
228

SEE ALSO

230       file2ASImage()
231

SYNOPSIS

233       Step 3. Preparation of the visual.
234

DESCRIPTION

236       At this point we have to obtain Visual information, as window
237       creation is highly dependant on Visual being used. In fact when X
238       creates a window it ties it to a particular Visual, and all its
239       attributes, such as colormap, pixel values, pixmaps, etc. must be
240       associated with the same Visual. Accordingly we need to acquire
241       ASVisual structure, which is our abstraction layer from them naughty
242       X Visuals. :
243

EXAMPLE

245           asv = create_asvisual( dpy, screen, depth, NULL );
246

NOTES

248       If any Window or Pixmap is created based on particular ASVisual, then
249       this ASVisual structure must not be destroyed untill all such
250       Windows and Pixmaps are destroyed.
251

SEE ALSO

253       See create_asvisual() for details.
254

SYNOPSIS

256       Step 4. Preparation of the window.
257

DESCRIPTION

259       Creation of top level window consists of several steps of its own:
260       a) create the window of desired size and placement
261       b) set ICCCM hints on the window
262       c) select appropriate events on the window
263       c) map the window.
264       First two steps has been moved out into create_top_level_window()
265       function.
266

EXAMPLE

268           w = create_top_level_window( asv, DefaultRootWindow(dpy), 32, 32,
269                                        im->width, im->height, 1, 0, NULL,
270                                        "ASView" );
271           if( w != None )
272           {
273               XSelectInput (dpy, w, (StructureNotifyMask | ButtonPress));
274               XMapRaised   (dpy, w);
275           }
276

NOTES

278       Map request should be made only for window that has all its hints set
279       up already, so that Window Manager can read them right away.
280       We want to map window as soon as possible so that User could see that
281       something really is going on, even before image is displayed.
282

SEE ALSO

284       ASImage, create_top_level_window()
285

SYNOPSIS

287       Step 5. Displaying the image.
288

DESCRIPTION

290       The simplest way to display image in the window is to convert it
291       into Pixmap, then set Window's background to this Pixmap, and,
292       at last, clear the window, so that background shows up.
293

EXAMPLE

295        p = asimage2pixmap( asv, DefaultRootWindow(dpy), im, NULL, False );
296        destroy_asimage( &im );
297

NOTES

299       We no longer need ASImage after we transfered it onto the Pixmap, so
300       we better destroy it to conserve resources.
301

SEE ALSO

303       asimage2pixmap(), destroy_asimage(), set_window_background_and_free()
304
305
306
3073rd Berkeley Distribution      AfterStep v.2.2.6                     asview(1)
Impressum