File: xslideshow.c

package info (click to toggle)
xslideshow 3.1-7
  • links: PTS
  • area: non-free
  • in suites: sarge
  • size: 792 kB
  • ctags: 1,375
  • sloc: ansic: 14,006; makefile: 897; sh: 1
file content (374 lines) | stat: -rw-r--r-- 8,552 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
/*
   xslideshow.c - displays pictures on the X11 window

   Author:   Susumu Shiohara (shiohara@tpp.epson.co.jp)

          Copyright 1993-1997 by Susumu Shiohara

                   All Rights Reserved

*/

#include "xslideshow.h"
#include "animate.h"

#if defined(__STDC__) || defined(__cplusplus)
# define P_(s) s
#else
# define P_(s) ()
#endif

extern ErrStatus checkFileType P_((char *));
extern ErrStatus gif2gimage P_((char *));
extern ErrStatus jpg2gimage P_((char *));
extern ErrStatus CreateXImage P_(());
extern void replaceBiffWindow P_(());
extern void replaceClockWindow P_(());
extern void lg3zoom P_((unsigned int, unsigned int));
extern void zoom24 P_((unsigned int, unsigned int));
extern void zoom P_((unsigned int, unsigned int));
extern void FreeXImage P_(());
extern void makeAppreciationCursor P_(());
extern void makePauseCursor P_(());
extern void makeWaitCursor P_(());

extern ActionStatus xgifanim P_((char *));
extern void postxgifanim P_((char *));

int  doPostAnimate=False;
int originalImageWidth, originalImageHeight;
char currentAnimate[256];
char postAnimate[256];

#if defined(__STDC__) || defined(__cplusplus)
static void fitIt(Widget topWidget, char *fname)
#else
static void fitIt(topWidget, fname)
Widget topWidget;
char *fname;
#endif
{
Arg args[5];
int ac;
int d_h,f_a,f_d;
XCharStruct overall;
int ww, wh, dw, dh, xzoom, yzoom;
double dzoom;


	/* Set the window size */
	if(!app_data.root && !app_data.full && !app_data.resize){

		/* Change the window size according to StructureNotify Event */
		if( windowWidth != newWindowWidth
			|| windowHeight != newWindowHeight){

			windowWidth = newWindowWidth;
			windowHeight = newWindowHeight;

			replaceBiffWindow();
			replaceClockWindow();
		}

	} else if(!app_data.root && !app_data.full && app_data.resize){

		/* Change the window size to the picture size */
		windowWidth = gim.subImageList->width;
		windowHeight = gim.subImageList->height;

		if( app_data.showFileName || app_data.clock ){
			/* Get text and font information */
			XTextExtents(
				app_data.font,
				fname,strlen(fname),
				&d_h,&f_a,&f_d,&overall
				);

			/* Expand window size to show file name and clock */
			windowHeight = windowHeight + (overall.descent + overall.ascent) * 2;
		}

		/* Set and change window size */
		ac = 0;
		XtSetArg(args[ac],XtNwidth,windowWidth);ac++;
		XtSetArg(args[ac],XtNheight,windowHeight);ac++;
		XtSetValues(topWidget,args,ac);

		replaceBiffWindow();
		replaceClockWindow();
	}


	/* Check if it is need to zoom an image */
	if(!app_data.resize && (app_data.fit || app_data.maxfit)){

		if(!strcmp(app_data.animate,"float24")){
			ww = app_data.floatImageSize;
			wh = app_data.floatImageSize;
		}
		else {
			ww = windowWidth;
			wh = windowHeight;

			if( app_data.showFileName || app_data.clock ){
				/* Get the text and font information */
				XTextExtents(app_data.font,fname,strlen(fname),
					&d_h,&f_a,&f_d,&overall);

				/* Make space for showing the file name and the clock */
				wh = wh - (overall.descent + overall.ascent)*2;
			}
		}


		/* Calculate zoom size */
		if(ww < gim.subImageList->width && wh < gim.subImageList->height) {

			dw = gim.subImageList->width - ww;
			dh = gim.subImageList->height - wh;

			if(dw > dh){
				xzoom = (int)((double)ww * 100 / gim.subImageList->width);
				if((gim.subImageList->height * xzoom) > (wh * 100)){
					dzoom = (double)wh * 100 / (gim.subImageList->height * xzoom);
					yzoom = (int)((double)xzoom * dzoom);
					xzoom = yzoom;
				}
				else{
					yzoom = xzoom;
				}
			}
			else {
				yzoom = (int)((double)wh * 100 / gim.subImageList->height);
				xzoom = yzoom;
			}

		}
		else if(ww < gim.subImageList->width && wh >= gim.subImageList->height) {

			xzoom = (int)((double)ww * 100 / gim.subImageList->width);
			yzoom = xzoom;

		}
		else if(ww >= gim.subImageList->width && wh < gim.subImageList->height) {

			yzoom = (int)((double)wh * 100 / gim.subImageList->height);
			xzoom = yzoom;

		}
		else if(ww >= gim.subImageList->width && wh >= gim.subImageList->height) {

			if( app_data.maxfit){
				yzoom = (int)((double)wh * 100 / gim.subImageList->height);
				xzoom = yzoom;
			}
			else{
				xzoom = yzoom = 100;
			}

		}

		if(xzoom < 100 || xzoom > 100) {
			if(!strcmp(app_data.zoom,"fast")){
				if(gim.subImageList->bits_per_pixel == 24)
					zoom24(xzoom, yzoom);
				else
					zoom(xzoom, yzoom);
			}
			else{
				lg3zoom(xzoom, yzoom);
			}
		}
	}
}

#if defined(__STDC__) || defined(__cplusplus)
ErrStatus animateShow(Widget topWidget,char *fname,int *hasImage, int *action)
#else
ErrStatus animateShow(topWidget,fname,hasImage,action)
Widget topWidget;
char *fname;
int *hasImage;
int *action;
#endif
{
ErrStatus errf=ERR_NO_ERR;
SUBGIMAGE *prev,*cur,*next;

	*hasImage = True;

	strcpy(currentAnimate,app_data.animate);

	if(!app_data.root)
		makeWaitCursor();

	/* Check file type (GIF or JPEG or .. ) */
	if((errf = checkFileType(fname)) != ERR_NO_ERR) {

		if(!app_data.root)
			makeAppreciationCursor();

		*hasImage = False;
		return(errf);
	}


	if(fileType == IS_GIF){

		/* Convert GIF file to General Image Format (GIMAGE) */
		if((errf = gif2gimage(fname)) != ERR_NO_ERR) {
			if(gim.subImageList->image != (byte *)NULL) {
				XtFree((char *)(gim.subImageList->image));
				gim.subImageList->image = (byte *)NULL;
			}
			if(!app_data.root)
				makeAppreciationCursor();

			*hasImage = False;
			return(errf);
		}

	}
	else if(fileType == IS_JPG){

		/* Convert JPEG file to General Image Format (GIMAGE) */
		if((errf = jpg2gimage(fname)) != ERR_NO_ERR) {
			if(gim.subImageList->image != (byte *)NULL) {
				XtFree((char *)(gim.subImageList->image));
				gim.subImageList->image = (byte *)NULL;
			}
			if(!app_data.root)
				makeAppreciationCursor();

			*hasImage = False;
			return(errf);
		}

	}
	else {
		if(!app_data.root)
			makeAppreciationCursor();

		*hasImage = False;
		return(ERR_NO_ERR);
	}


	/* Check if there are valid subimages */
	prev = gim.subImageList;
	do {
		cur = prev->next;
		if(cur == (SUBGIMAGE *)NULL)
			break;
		if(cur->image == (byte *)NULL
				|| cur->width == 0
				|| cur->height == 0){
			if(cur->image != (byte *)NULL){
				XtFree((char *)cur->image);
				cur->image = (byte *)NULL;
			}
			next = cur->next;
			XtFree((char *)cur);
			prev->next = next;
			prev = next;
		}
		else {
			prev = cur;
		}
	} while (prev != (SUBGIMAGE *)NULL);


	/* Check if there is a valid image */
	if(gim.subImageList->image == (byte *)NULL
			|| gim.subImageList->width == 0
			|| gim.subImageList->height == 0){

		if(gim.subImageList->image != (byte *)NULL){
			XtFree((char *)gim.subImageList->image);
			gim.subImageList->image = (byte *)NULL;
		}
		/* Image was not created */
		if(!app_data.root)
			makeAppreciationCursor();

		*hasImage = False;
		return(ERR_NO_ERR);
	}

	/* Let's do animate ! */
  	if(gim.subImageList->next != (SUBGIMAGE *)NULL)
		strcpy(currentAnimate,"gifanim");

	gotSomeAction = False;

	do {

		originalImageWidth = gim.subImageList->width;
		originalImageHeight = gim.subImageList->height;

		/* Resize if need */
		fitIt(topWidget, fname);

		/*
		The CreateXImage routine frees its pixels,
		so must do postAnimateFunc before calling CreateXImage
		*/
		if(doPostAnimate) {
			(void)postAnimateFunc[animate_strtoenum(postAnimate)](fname);
		}

		/* Create the XImage */
		if((errf = CreateXImage()) != ERR_NO_ERR) {  
			/* Some error happend */
			if(gim.subImageList->image != (byte *)NULL) {
				XtFree((char *)(gim.subImageList->image));
				gim.subImageList->image = (byte *)NULL;
			}
			if(!app_data.root)
				makeAppreciationCursor();

			*hasImage = False;
			return(errf);
		}

		if(!app_data.root)
			makeAppreciationCursor();

		*action = animateFunc[animate_strtoenum(currentAnimate)](fname);

		strcpy(postAnimate,currentAnimate);
		doPostAnimate = True;

		FreeXImage();

		if(gotSomeAction){
			while(gim.subImageList->next != (SUBGIMAGE *)NULL){
				cur = gim.subImageList;
				gim.subImageList = gim.subImageList->next;
				if(cur->image != (byte *)NULL){
					XtFree((char *)cur->image);
				}
				XtFree((char *)cur);
			} 
			if(gim.subImageList->image != (byte *)NULL){
				XtFree((char *)gim.subImageList->image);
				gim.subImageList->image = (byte *)NULL;
			}
			break;
		}

		if(gim.subImageList->next == (SUBGIMAGE *)NULL){
			break;
		}
		else { /* link next subimage */
			cur = gim.subImageList;
			gim.subImageList = gim.subImageList->next;
			XtFree((char *)cur);
		}

	} while(True);

	/* End displaying all images */
	return(errf);
}