forked from akkana/pho
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpho.c
795 lines (685 loc) · 25.7 KB
/
pho.c
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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* pho.c: core routines for pho, an image viewer.
*
* Copyright 2004 by Akkana Peck.
* You are free to use or modify this code under the Gnu Public License.
*/
#include "pho.h"
#include "dialogs.h"
#include "exif/phoexif.h"
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h> /* for unlink() */
#include <fcntl.h> /* for symbols like O_RDONLY */
/* ************* Definition of globals ************ */
PhoImage* gFirstImage = 0;
PhoImage* gCurImage = 0;
/* Monitor resolution */
int gMonitorWidth = 0;
int gMonitorHeight = 0;
/* Effective resolution, e.g. if we'll be sending to a projector */
int gPresentationWidth = 0;
int gPresentationHeight = 0;
/* We only have one image at a time, so make it global. */
GdkPixbuf* gImage = 0;
int gDebug = 0; /* debugging messages */
int gScaleMode = PHO_SCALE_NORMAL;
double gScaleRatio = 1.0;
int gDisplayMode = PHO_DISPLAY_NORMAL;
/* Slideshow delay is zero by default -- no slideshow. */
int gDelayMillis = 0;
int gPendingTimeout = 0;
/* Loop back to the first image after showing the last one */
int gRepeat = 0;
static int RotateImage(PhoImage* img, int degrees); /* forward */
static gint DelayTimer(gpointer data)
{
if (gDelayMillis == 0) /* slideshow mode was cancelled */
return FALSE;
if (gDebug) printf("-- Timer fired\n");
gPendingTimeout = 0;
NextImage();
return FALSE; /* cancel the timer */
}
int ShowImage()
{
ScaleAndRotate(gCurImage, 0);
/* Keywords dialog will be updated if necessary from DrawImage */
if (gDelayMillis > 0 && gPendingTimeout == 0
&& (gCurImage->next != 0 || gCurImage->next != gFirstImage)) {
if (gDebug) printf("Adding timeout for %d msec\n", gDelayMillis);
gPendingTimeout = g_timeout_add (gDelayMillis, DelayTimer, 0);
}
return 0;
}
static int LoadImageFromFile(PhoImage* img)
{
GError* err = NULL;
int rot;
if (img == 0)
return -1;
if (gDebug)
printf("LoadImageFromFile(%s)\n", img->filename);
/* Free the current image */
if (gImage) {
g_object_unref(gImage);
gImage = 0;
}
gImage = gdk_pixbuf_new_from_file(img->filename, &err);
if (!gImage)
{
gImage = 0;
fprintf(stderr, "Can't open %s: %s\n", img->filename, err->message);
return -1;
}
ReadCaption(img);
img->curWidth = gdk_pixbuf_get_width(gImage);
img->curHeight = gdk_pixbuf_get_height(gImage);
/* The first time an image is loaded, it should be rotated
* to its appropriate EXIF rotation. Subsequently, though,
* it should be rotated to curRot.
*/
if (img->trueWidth == 0 || img->trueHeight == 0) {
/* Read the EXIF rotation if we haven't already rotated this image */
ExifReadInfo(img->filename);
if (HasExif() && (rot = ExifGetInt(ExifOrientation)) != 0)
img->exifRot = rot;
else
img->exifRot = 0;
}
/* trueWidth and Height used to be set inside EXIF clause,
* but that doesn't make sense -- we need it not just the first
* time, but also ever time the image is reloaded.
*/
img->trueWidth = img->curWidth;
img->trueHeight = img->curHeight;
return 0;
}
static int LoadImageAndRotate(PhoImage* img)
{
int e;
int rot = (img ? img->curRot : 0);
int firsttime = (img && (img->trueWidth == 0));
if (!img) return -1;
img->trueWidth = img->trueHeight = img->curRot = 0;
e = LoadImageFromFile(img);
if (e) return e;
/* If it's not the first time we've loaded this image,
* default its rotation to the EXIF rotation if any.
* Otherwise rotate to the saved img->curRot.
*/
if (firsttime && img->exifRot != 0)
ScaleAndRotate(gCurImage, img->exifRot);
else
ScaleAndRotate(gCurImage, rot);
return 0;
}
/* ThisImage() is called when gCurImage has changed and needs to
* be reloaded.
*/
int ThisImage()
{
if (LoadImageAndRotate(gCurImage) != 0)
return NextImage();
ShowImage();
return 0;
}
int NextImage()
{
int retval = 0;
int looping = 0;
if (gDebug)
printf("\n================= NextImage ====================\n");
/* Loop, since images may fail to load
* and may need to be deleted from the list
*/
while (1)
{
if (gFirstImage == 0)
/* There's no list! How can we go to the next item? */
return -1;
if (gCurImage == 0) { /* no image loaded yet, first call */
if (gDebug)
printf("NextImage: going to first image\n");
gCurImage = gFirstImage;
}
else if (looping && gCurImage->next == gFirstImage)
/* We're to the end of the list, after deleting something bogus */
return -1;
else if (!gCurImage->next || (gCurImage->next == gFirstImage))
/* We're at the end of the list, can't go farther.
* However, we may have gotten here by trying to go to
* the next image and failing, in which case we no longer
* have a pixmap loaded. So we still need to LoadImage,
* but we'll want to return -1 to indicate we didn't progress.
*/
if (gRepeat)
gCurImage = gFirstImage;
else
retval = -1;
/* We only want to go to ->next the first time;
* if we're looping because of an error, gCurImage is already set.
*/
else if (!looping)
gCurImage = gCurImage->next;
if (LoadImageAndRotate(gCurImage) == 0) { /* Success! */
ShowImage();
return retval;
}
/* The image didn't load. Remove it from the list.
* That means we're going to loop around and try again,
* so keep gCurImage where it is (but change gCurImage->next).
*/
if (gDebug)
printf("Skipping '%s' (didn't load)\n", gCurImage->filename);
DeleteItem(gCurImage);
looping = 1;
}
/* NOTREACHED */
return 0;
}
int PrevImage()
{
if (gDebug)
printf("\n================= PrevImage ====================\n");
do {
if (gCurImage == 0) { /* no image loaded yet, first call */
gCurImage = gFirstImage;
if (gCurImage->prev)
gCurImage = gCurImage->prev;
}
else {
if (gCurImage == gFirstImage)
return -1; /* end of list */
gCurImage = gCurImage->prev;
}
} while (LoadImageAndRotate(gCurImage) != 0);
ShowImage();
return 0;
}
/* Limit new_width and new_height so that they're no bigger than
* max_width and max_height. This doesn't actually scale, just
* calculates dimensions and returns them in *width and *height.
*/
static void ScaleToFit(int *width, int *height,
int max_width, int max_height,
int scaleMode, double scaleRatio)
{
int new_w, new_h;
if (scaleMode == PHO_SCALE_SCREEN_RATIO) {
/* Which dimension needs to be scaled down more? */
double xratio = (double)(*width) / max_width;
double yratio = (double)(*height) / max_height;
if (xratio > 1. || yratio > 1.) { /* need some scaling */
if (xratio > yratio) { /* X needs more scaling down */
new_w = *width / xratio;
new_h = *height / xratio;
} else { /* Y needs more scaling down */
new_w = *width / yratio;
new_h = *height / yratio;
}
}
}
else {
double xratio, yratio;
if (scaleMode == PHO_SCALE_FIXED) {
/* Special case: scaleRatio isn't actually a ratio,
* it's the max size we want the image's long dimension to be.
*/
if (*width > *height) {
new_w = scaleRatio;
new_h = scaleRatio * *height / *width;
}
else {
new_w = scaleRatio * *width / *height;
new_h = scaleRatio;
}
/* Reset scaleRatio so it can now be used for (no) scaling */
scaleRatio = 1.0;
}
else {
new_w = *width;
new_h = *height;
}
new_w *= scaleRatio;
new_h *= scaleRatio;
xratio = (double)new_w / (double)max_width;
yratio = (double)new_h / (double)max_height;
if (xratio > 1. || yratio > 1.) {
if (xratio > yratio) {
new_w /= xratio;
new_h /= xratio;
} else {
new_w /= yratio;
new_h /= yratio;
}
}
}
*width = new_w * scaleRatio;
*height = new_h * scaleRatio;
}
#define SWAP(a, b) { int temp = a; a = b; b = temp; }
/*#define SWAP(a, b) {a ^= b; b ^= a; a ^= b;}*/
/* Rotate the image according to the current scale mode, scaling as needed,
* then redisplay.
*
* This will read the image from disk if necessary,
* and it will rotate the image at the appropriate time
* (when the image is at its smallest).
*
* This is the routine that should be called by external callers:
* callers should never need to call RotateImage.
*
* degrees is the increment from the current rotation (curRot).
*/
int ScaleAndRotate(PhoImage* img, int degrees)
{
#define true_width img->trueWidth
#define true_height img->trueHeight
int new_width;
int new_height;
if (gDebug)
printf("ScaleAndRotate(%d (cur = %d))\n", degrees, img->curRot);
/* degrees should be between 0 and 360 */
degrees = (degrees + 360) % 360;
/* First, load the image if we haven't already, to get true w/h */
if (true_width == 0 || true_height == 0) {
if (gDebug) printf("Loading, first time, from ScaleAndRotate!\n");
LoadImageFromFile(img);
}
/*
* Calculate new_width and new_height, the size to which the image
* should be scaled before or after rotation,
* based on the current scale mode.
* That means that if the aspect ratio is changing,
* new_width will be the image's height after rotation.
*/
/* Fullsize: display always at real resolution,
* even if it's too big to fit on the screen.
*/
if (gScaleMode == PHO_SCALE_FULLSIZE) {
new_width = true_width * gScaleRatio;
new_height = true_height * gScaleRatio;
if (gDebug) printf("Now fullsize, %dx%d\n", new_width, new_height);
}
/* Normal: display at full size unless it won't fit the screen,
* in which case scale it down.
*/
#define NORMAL_SCALE_SLOP 5
else if (gScaleMode == PHO_SCALE_NORMAL
|| gScaleMode == PHO_SCALE_SCREEN_RATIO
|| gScaleMode == PHO_SCALE_FIXED)
{
int max_width, max_height;
int aspect_changing; /* Is the aspect ratio changing? */
new_width = true_width;
new_height = true_height;
aspect_changing = ((degrees % 180) != 0);
if (aspect_changing) {
max_width = gMonitorHeight;
max_height = gMonitorWidth;
if (gDebug)
printf("Aspect ratio is changing\n");
} else {
max_width = gMonitorWidth;
max_height = gMonitorHeight;
}
/* If we're in fixed mode, make sure we've set the "scale ratio"
* to the screen size:
*/
if (gScaleMode == PHO_SCALE_FIXED && gScaleRatio == 0.0)
gScaleRatio = FracOfScreenSize();
if (new_width > max_width || new_height > max_height) {
ScaleToFit(&new_width, &new_height, max_width, max_height,
gScaleMode, gScaleRatio);
}
#if 0
/* Special case: if in PHO_SCALE_SCREEN_RATIO, we don't need to
* scale verticals (assuming a landscape screen) down -- it's
* better to keep the max dimension of each image the same.
*/
if (new_width <= max_height && new_height <= max_width) {
double r =
} else {
new_width *= gScaleRatio;
new_height *= gScaleRatio;
}
#endif
/* See if new_width and new_height are close enough already
* that it might not be worth doing the work of scaling:
*/
if (abs(img->curWidth - new_width) + abs(img->curHeight - new_height)
< NORMAL_SCALE_SLOP) {
new_width = img->curWidth;
new_height = img->curHeight;
}
}
else if (gScaleMode == PHO_SCALE_IMG_RATIO) {
new_width = true_width * gScaleRatio;
new_height = true_height * gScaleRatio;
/* See if we're close */
if (abs(img->curWidth - new_width) + abs(img->curHeight - new_height)
< NORMAL_SCALE_SLOP) {
new_width = img->curWidth;
new_height = img->curHeight;
}
}
/* Fullscreen: Scale either up or down if necessary to make
* the largest dimension match the screen size.
*/
#define FULLSCREEN_SCALE_SLOP 20
else if (gScaleMode == PHO_SCALE_FULLSCREEN) {
/* If we're in presentation mode, then we need to scale
* to the current size of the window, not the monitor,
* because in xinerama gdk_window_fullscreen() will fullscreen
* onto only one monitor, but gdk_screen_width() gives the
* width of the full xinerama setup.
*/
int diffx = abs(img->curWidth - gMonitorWidth);
int diffy = abs(img->curHeight - gMonitorHeight);
double xratio, yratio;
gint screenwidth, screenheight;
if (gDisplayMode == PHO_DISPLAY_PRESENTATION)
gtk_window_get_size(GTK_WINDOW(gWin), &screenwidth, &screenheight);
else {
screenwidth = gMonitorWidth;
screenheight = gMonitorHeight;
}
if (diffx < FULLSCREEN_SCALE_SLOP || diffy < FULLSCREEN_SCALE_SLOP) {
new_width = img->curWidth;
new_height = img->curHeight;
}
else {
xratio = (double)screenwidth / true_width;
yratio = (double)screenheight / true_height;
/* Use xratio for the more extreme of the two */
if (xratio > yratio) xratio = yratio;
new_width = xratio * true_width;
new_height = xratio * true_height;
}
}
else {
/* Shouldn't ever happen, means gScaleMode is bogus */
printf("Internal error: Unknown scale mode %d\n", gScaleMode);
new_width = img->curWidth;
new_height = img->curHeight;
}
/*
* Finally, we're done with the scaling modes.
* Time to do the scaling and rotation,
* reloading the image if needed.
*/
/* First figure out if we're getting bigger and hence need to reload. */
if ((new_width > img->curWidth || new_height > img->curHeight)
&& (img->curWidth < true_width && img->curHeight < true_height)) {
if (gDebug)
printf("Getting bigger, from %dx%d to %dx%d -- need to reload\n",
img->curWidth, img->curHeight, new_width, new_height);
/* Because curRot is going back to zero, that means we
* might need to swap new_width and new_height, in case
* the aspect ratio is changing.
if (degrees % 180 != 0) {
if ((img->curRot + degrees) % 180 != 0) {
* new_width and new_height have already taken into account
* the desired rotation (degrees); the important thing is
* whether the current rotation is 90 degrees off.
*/
if (img->curRot % 180 != 0) {
SWAP(new_width, new_height);
if (gDebug)
printf("Swapping new width/height: %dx%d\n",
new_width, new_height);
}
/* image->curRot is going to be set back to zero when we load
* from file, so adjust current planned rotation accordingly.
*/
degrees = (degrees + img->curRot + 360) % 360;
/* Now it's the absolute end rot desired */
img->curRot = 0;
LoadImageFromFile(img);
}
#if 0
else if (degrees % 180 != 0) {
SWAP(new_width, new_height);
printf("Not reloading, but swapped new width/height, now %dx%d\n",
new_width, new_height);
}
/* new_* are the sizes we want after rotation. But we need
* to compare them now to the sizes before rotation. So we
* need to compensate for rotation.
*/
/* If we're going to scale up, then do the rotation first,
* before scaling. Otherwise, scale down first then rotate.
*/
if (degrees != 0 &&
(new_width > img->curWidth || new_height > img->curHeight)) {
if (gDebug) printf("Rotating before scaling up\n");
RotateImage(img, degrees);
degrees = 0; /* finished with rotation */
}
#endif
/* Do the scaling (thought we'd never get there!) */
if (new_width != img->curWidth || new_height != img->curHeight)
{
GdkPixbuf* newimage = gdk_pixbuf_scale_simple(gImage,
new_width,
new_height,
GDK_INTERP_BILINEAR);
/* If that's too slow use GDK_INTERP_NEAREST */
/* scale_simple apparently has no error return; if it fails,
* it still returns a pixbuf but width and height are -1.
* Hope this undocumented behavior doesn't change!
* Later: now it's documented. Whew.
*/
if (!newimage || gdk_pixbuf_get_width(newimage) < 1) {
if (newimage)
g_object_unref(newimage);
printf("\007Error scaling from %d x %d to %d x %d: probably out of memory\n",
img->curWidth, img->curHeight, new_width, new_height);
Prompt("Couldn't scale up: probably out of memory", "Bummer", 0,
"\n ", "");
return -1;
}
if (gDebug)
printf("Scale from %dx%d = %dx%d to %dx%d = %dx%d\n",
img->curWidth, img->curHeight,
gdk_pixbuf_get_width(gImage), gdk_pixbuf_get_height(gImage),
new_width, new_height,
gdk_pixbuf_get_width(newimage),
gdk_pixbuf_get_height(newimage));
if (gImage)
g_object_unref(gImage);
gImage = newimage;
img->curWidth = gdk_pixbuf_get_width(gImage);
img->curHeight = gdk_pixbuf_get_height(gImage);
}
/* If we didn't rotate before, do it now. */
if (degrees != 0)
RotateImage(img, degrees);
/* We've finished making our changes. Now we may need to make
* changes in the window size or position.
*/
PrepareWindow();
return 0;
}
PhoImage* NewPhoImage(char* fnam)
{
PhoImage* newimg = calloc(1, sizeof (PhoImage));
if (newimg == 0) return 0;
newimg->filename = fnam; /* no copy, we don't own the memory */
return newimg;
}
void ReallyDelete(PhoImage* delImg)
{
/* Make sure the keywords dialog doesn't save a pointer to this image */
NoCurrentKeywords();
if (unlink(delImg->filename) < 0)
{
printf("OOPS! Can't delete %s\n", delImg->filename);
return;
}
DeleteItem(delImg);
/* If we just deleted the last image, all we can do is quit */
if (!gFirstImage)
EndSession();
ThisImage();
}
void DeleteImage(PhoImage* delImg)
{
char buf[512];
if (delImg->filename == 0)
return;
sprintf(buf, "Delete file %s?", delImg->filename);
if (Prompt(buf, "Delete", 0, "dD\n", "nN") > 0)
ReallyDelete(delImg);
}
/* RotateImage just rotates an existing image, no scaling or reloading.
* It's typically called from ScaleAndRotate either just
* before or just after scaling.
* No one except ScaleAndRotate should call it.
* Degrees is the amount of rotation relative to current.
*/
static int RotateImage(PhoImage* img, int degrees)
{
guchar *oldpixels, *newpixels;
int x, y;
int oldrowstride, newrowstride, nchannels, bitsper, alpha;
int newWidth, newHeight, newTrueWidth, newTrueHeight;
GdkPixbuf* newImage;
if (!gImage) return 1; /* sanity check */
if (gDebug)
printf("RotateImage(%d), initially %d x %d, true %dx%d\n",
degrees, img->curWidth, img->curHeight,
img->trueWidth, img->trueHeight);
/* Make sure degrees is between 0 and 360 even if it's -90 */
degrees = (degrees + 360) % 360;
/* degrees might be zero now, since we might be rotating back to zero. */
if (degrees == 0) {
return 0;
}
/* Swap X and Y if appropriate */
if (degrees == 90 || degrees == 270)
{
newWidth = img->curHeight;
newHeight = img->curWidth;
newTrueWidth = img->trueHeight;
newTrueHeight = img->trueWidth;
}
else
{
newWidth = img->curWidth;
newHeight = img->curHeight;
newTrueWidth = img->trueWidth;
newTrueHeight = img->trueHeight;
}
oldrowstride = gdk_pixbuf_get_rowstride(gImage);
/* Sometimes rowstride is slightly different from width*nchannels:
* gdk_pixbuf optimizes by aligning to 32-bit boundaries.
* But apparently it works even if rowstride is not aligned,
* just might not be as fast.
* XXX check newrowstride alignment
*/
bitsper = gdk_pixbuf_get_bits_per_sample(gImage);
nchannels = gdk_pixbuf_get_n_channels(gImage);
alpha = gdk_pixbuf_get_has_alpha(gImage);
oldpixels = gdk_pixbuf_get_pixels(gImage);
newImage = gdk_pixbuf_new(GDK_COLORSPACE_RGB, alpha, bitsper,
newWidth, newHeight);
if (!newImage) return 1;
newpixels = gdk_pixbuf_get_pixels(newImage);
newrowstride = gdk_pixbuf_get_rowstride(newImage);
for (x = 0; x < img->curWidth; ++x)
{
for (y = 0; y < img->curHeight; ++y)
{
int newx, newy;
int i;
switch (degrees)
{
case 90:
newx = img->curHeight - y - 1;
newy = x;
break;
case 270:
newx = y;
newy = img->curWidth - x - 1;
break;
case 180:
newx = img->curWidth - x - 1;
newy = img->curHeight - y - 1;
break;
default:
printf("Illegal rotation value!\n");
return 1;
}
for (i=0; i<nchannels; ++i)
newpixels[newy*newrowstride + newx*nchannels + i]
= oldpixels[y*oldrowstride + x*nchannels + i];
}
}
img->curWidth = newWidth;
img->curHeight = newHeight;
img->trueWidth = newTrueWidth;
img->trueHeight = newTrueHeight;
img->curRot = (img->curRot + degrees + 360) % 360;
g_object_unref(gImage);
gImage = newImage;
return 0;
}
void Usage()
{
printf("pho version %s. Copyright 2002-2009 Akkana Peck [email protected].\n", VERSION);
printf("Usage: pho [-dhnp] image [image ...]\n");
printf("\t-p: Presentation mode (full screen, centered)\n");
printf("\t-p[resolution]: Projector mode:\n\tlike presentation mode but in upper left corner\n");
printf("\t-P: No presentation mode (separate window) -- default\n");
printf("\t-k: Keywords mode (show a Keywords dialog for each image)\n");
printf("\t-n: Replace each image window with a new window (helpful for some window managers)\n");
printf("\t-sN: Slideshow mode, where N is the timeout in seconds\n");
printf("\t-r: Repeat: loop back to the first image after showing the last\n");
printf("\t-cpattern: Caption/Comment file pattern, format string for reworking filename\n");
printf("\t--: Assume no more flags will follow\n");
printf("\t-d: Debug messages\n");
printf("\t-h: Help: Print this summary\n");
printf("\t-v: Verbose help: Print a summary of key bindings\n");
exit(1);
}
void VerboseHelp()
{
printf("pho version %s. Copyright 2002,2003,2004,2007 Akkana Peck [email protected].\n", VERSION);
printf("Type pho -h for commandline arguments.\n");
printf("\npho Key Bindings:\n\n");
printf("<space>, <Page Down>\n\tNext image (or cancel slideshow mode)\n");
printf("<backspace>, <Page Up>\n\tPrevious image\n");
printf("<home>\tFirst image\n");
printf("f\tToggle full-size mode (even if bigger than screen)\n");
printf("F\tToggle fullscreen mode (scale even small images up to fullscreen)\n");
printf("k\tTurn on keywords mode: show the keywords dialog\n");
printf("p\tToggle presentation mode (take up the whole screen, centering the image)\n");
printf("d\tDelete current image (from disk, after confirming with another d)\n");
printf("0-9\tRemember image in note list 0 through 9 (to be printed at exit)\n");
printf("\t(In keywords dialog, alt + 0-9 adds 10, e.g. alt-4 triggers flag 14.\n");
printf("t, r, <Right>\n\tRotate right 90 degrees\n");
printf("T, R, l, L, <Left>]n\tRotate left 90 degrees\n");
printf("<up>\tRotate 180 degrees\n");
printf("+, =\tDouble size\n");
printf("/, -\tHalf size\n");
printf("i\tShow/hide info dialog\n");
printf("o\tChange the working file set (add files or make a new list)\n");
printf("g\tRun gimp on the current image\n");
printf("\t(or set PHO_CMD to an alternate command)\n");
printf("q\tQuit\n");
printf("<esc>\tQuit (or hide a dialog, if one is showing)\n");
printf("\n");
printf("Pho mouse bindings:\n");
printf("In presentation mode: drag with middlemouse to pan/move.\n");
printf("\n");
printf("Pho environment variables:\n");
printf("PHO_ARGS: default arguments (e.g. -p)\n");
printf("PHO_CMD : command to run when pressing g (default: gimp).\n");
printf(" Use an empty string if you don't want any command.\n");
exit(0);
}