-
Notifications
You must be signed in to change notification settings - Fork 11
/
fbi.c
1518 lines (1343 loc) · 35.2 KB
/
fbi.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
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* image viewer, for framebuffer devices
*
* (c) 1998-2012 Gerd Hoffmann <gerd@kraxel.org>
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <math.h>
#include <signal.h>
#include <ctype.h>
#include <locale.h>
#include <wchar.h>
#include <setjmp.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <jpeglib.h>
#include <libexif/exif-data.h>
#include "readers.h"
#include "vt.h"
#include "kbd.h"
#include "fbtools.h"
#include "drmtools.h"
#include "fb-gui.h"
#include "filter.h"
#include "desktop.h"
#include "fbiconfig.h"
#include "logind.h"
#include "transupp.h" /* Support routines for jpegtran */
#include "jpegtools.h"
/* ---------------------------------------------------------------------- */
/* variables for read_image */
int32_t lut_red[256], lut_green[256], lut_blue[256];
int pcd_res = 3;
int v_steps = 50;
int h_steps = 50;
int textreading = 0, redraw = 0, statusline = 1;
int fitwidth;
/* file list */
struct flist {
/* file list */
int nr;
int tag;
char *name;
struct list_head list;
bool list_check;
/* image cache */
int seen;
int top;
int left;
int text_steps;
float scale;
struct ida_image *fimg;
struct ida_image *simg;
struct list_head lru;
};
static LIST_HEAD(flist);
static LIST_HEAD(flru);
static int fcount;
static struct flist *fcurrent;
static struct ida_image *img;
static const char *filelist;
static struct stat liststat;
/* accounting */
static int img_cnt, min_cnt = 2, max_cnt = 16;
static int img_mem, max_mem_mb;
/* graphics interface */
gfxstate *gfx;
/* framebuffer */
char *fbdev = NULL;
char *fbmode = NULL;
/* Command line options. */
int autodown;
int autoup;
int comments;
int transparency = 40;
int timeout;
int backup;
int preserve;
int read_ahead;
int editable;
int blend_msecs;
int perfmon = 0;
int interactive = 0;
/* font handling */
static char *fontname = NULL;
static cairo_font_extents_t *extents;
/* ---------------------------------------------------------------------- */
/* fwd declarations */
static struct ida_image *flist_img_get(struct flist *f);
static void flist_img_load(struct flist *f, int prefetch);
static void flist_img_free(struct flist *f);
/* ---------------------------------------------------------------------- */
static void
version(void)
{
fprintf(stdout,
"fbi version " VERSION ", compiled on %s\n"
"(c) 1998-2016 Gerd Hoffmann <gerd@kraxel.org>\n",
__DATE__ );
}
static void
usage(FILE *fp, char *name)
{
char *h;
if (NULL != (h = strrchr(name, '/')))
name = h+1;
fprintf(fp,
"\n"
"This program displays images using the Linux framebuffer device.\n"
"Supported formats: PhotoCD, jpeg, ppm, gif, tiff, xwd, bmp, png,\n"
"webp. It tries to use ImageMagick's convert for unknown file formats.\n"
"\n"
"usage: %s [ options ] file1 file2 ... fileN\n"
"\n",
name);
cfg_help_cmdline(fp,fbi_cmd,4,20,0);
cfg_help_cmdline(fp,fbi_cfg,4,20,40);
fprintf(fp,
"\n"
"Large images can be scrolled using the cursor keys. Zoom in/out\n"
"works with '+' and '-'. Use ESC or 'q' to quit. Space and PgDn\n"
"show the next, PgUp shows the previous image. Jumping to a image\n"
"works with <i>g. Return acts like Space but additionally prints\n"
"prints the filename of the currently displayed image to stdout.\n"
"\n");
}
/* ---------------------------------------------------------------------- */
static struct flist *flist_add(const char *filename)
{
struct flist *f;
f = malloc(sizeof(*f));
memset(f,0,sizeof(*f));
f->name = strdup(filename);
list_add_tail(&f->list,&flist);
INIT_LIST_HEAD(&f->lru);
return f;
}
static struct flist *flist_find(const char *filename)
{
struct list_head *item;
struct flist *f;
list_for_each(item,&flist) {
f = list_entry(item, struct flist, list);
if (strcmp(filename, f->name) == 0)
return f;
}
return NULL;
}
static int flist_add_list(const char *listfile)
{
char filename[256];
struct flist *f;
FILE *list;
list = fopen(listfile,"r");
if (NULL == list) {
fprintf(stderr,"open %s: %s\n",listfile,strerror(errno));
return -1;
}
fstat(fileno(list), &liststat);
while (NULL != fgets(filename,sizeof(filename)-1,list)) {
size_t off = strcspn(filename,"\r\n");
if (off)
filename[off] = 0;
f = flist_find(filename);
if (!f) {
f = flist_add(filename);
}
f->list_check = true;
}
fclose(list);
return 0;
}
static int flist_del(struct flist *f)
{
list_del(&f->list);
list_del(&f->lru);
free(f->name);
free(f);
return 0;
}
static void flist_renumber(void)
{
struct list_head *item;
struct flist *f;
int i = 0;
list_for_each(item,&flist) {
f = list_entry(item, struct flist, list);
f->nr = ++i;
}
fcount = i;
}
static int flist_check_reload_list(const char *listfile)
{
struct list_head *item, *safe;
struct flist *f;
struct stat st;
int ret;
ret = stat(listfile, &st);
if (ret < 0)
return ret;
if (st.st_mtime == liststat.st_mtime)
return 0;
list_for_each(item, &flist) {
f = list_entry(item, struct flist, list);
f->list_check = false;
}
ret = flist_add_list(listfile);
if (ret != 0)
return ret;
list_for_each_safe(item, safe, &flist) {
f = list_entry(item, struct flist, list);
if (!f->list_check) {
flist_img_free(f);
flist_del(f);
}
}
flist_renumber();
return 0;
}
static int flist_islast(struct flist *f)
{
return (&flist == f->list.next) ? 1 : 0;
}
static int flist_isfirst(struct flist *f)
{
return (&flist == f->list.prev) ? 1 : 0;
}
static struct flist* flist_first(void)
{
return list_entry(flist.next, struct flist, list);
}
static struct flist* flist_last(void)
{
return list_entry(flist.prev, struct flist, list);
}
static struct flist* flist_next(struct flist *f, int eof, int loop)
{
if (flist_islast(f)) {
if (eof)
return NULL;
if (loop)
return flist_first();
return f;
}
return list_entry(f->list.next, struct flist, list);
}
static struct flist* flist_prev(struct flist *f, int loop)
{
if (flist_isfirst(f)) {
if (loop)
return flist_last();
return f;
}
return list_entry(f->list.prev, struct flist, list);
}
static struct flist* flist_goto(int dest)
{
struct list_head *item;
struct flist *f;
list_for_each(item,&flist) {
f = list_entry(item, struct flist, list);
if (f->nr == dest)
return f;
}
return NULL;
}
static void flist_randomize(void)
{
struct flist *f;
int count;
srand((unsigned)time(NULL));
flist_renumber();
for (count = fcount; count > 0; count--) {
f = flist_goto((rand() % count)+1);
list_del(&f->list);
list_add_tail(&f->list,&flist);
flist_renumber();
}
}
static void flist_print_tagged(FILE *fp)
{
struct list_head *item;
struct flist *f;
list_for_each(item,&flist) {
f = list_entry(item, struct flist, list);
if (f->tag)
fprintf(fp,"%s\n",f->name);
}
}
/* ---------------------------------------------------------------------- */
static void
shadow_draw_image(struct ida_image *img, int xoff, int yoff,
unsigned int first, unsigned int last, int weight)
{
unsigned int xs, ys;
if (100 == weight)
shadow_clear_lines(first, last);
else
shadow_darkify(0, gfx->hdisplay-1, first, last, 100 - weight);
/* image < screen: center image */
xs = 0, ys = 0;
if (img->i.width < gfx->hdisplay)
xs += (gfx->hdisplay - img->i.width) / 2;
if (img->i.height < gfx->vdisplay)
ys += (gfx->vdisplay - img->i.height) / 2;
shadow_composite_image(img, xs - xoff, ys - yoff, weight);
}
static void status_prepare(void)
{
struct ida_image *img = flist_img_get(fcurrent);
int y1 = gfx->vdisplay - extents->height;
int y2 = gfx->vdisplay - 1;
if (img) {
shadow_draw_image(img, fcurrent->left, fcurrent->top, y1, y2, 100);
shadow_darkify(0, gfx->hdisplay-1, y1, y2, transparency);
} else {
shadow_clear_lines(y1, y2);
}
shadow_draw_line(0, gfx->hdisplay-1, y1-1, y1-1);
}
static void status_update(unsigned char *desc, char *info)
{
int yt = gfx->vdisplay - extents->height;
char str[128];
if (!statusline)
return;
status_prepare();
snprintf(str,ARRAY_SIZE(str),"%s",desc);
shadow_draw_string(0, yt, str, -1);
if (info) {
snprintf(str,ARRAY_SIZE(str), "[ %s ] H - Help", info);
} else {
snprintf(str,ARRAY_SIZE(str), "| H - Help");
}
shadow_draw_string(gfx->hdisplay, yt, str, 1);
shadow_render(gfx);
}
static void status_error(unsigned char *msg)
{
int yt = gfx->vdisplay - extents->height;
char str[128];
status_prepare();
snprintf(str,ARRAY_SIZE(str), "%s", msg);
shadow_draw_string(0, yt, str, -1);
shadow_render(gfx);
sleep(2);
}
static void show_exif(struct flist *f)
{
static unsigned int tags[] = {
0x010f, // Manufacturer
0x0110, // Model
0x0112, // Orientation
0x0132, // Date and Time
0x01e3, // White Point
0x829a, // Exposure Time
0x829d, // FNumber
0x9206, // Subject Distance
0xa40c, // Subject Distance Range
0xa405, // Focal Length In 35mm Film
0x9209, // Flash
0xa002, // Pixel X Dimension
0xa003, // Pixel Y Dimension
};
ExifData *ed;
ExifEntry *ee;
unsigned int tag,l1,l2,len,count,i;
const char *title[ARRAY_SIZE(tags)];
char *value[ARRAY_SIZE(tags)];
char *linebuffer[ARRAY_SIZE(tags)];
if (!console_visible)
return;
ed = exif_data_new_from_file(f->name);
if (NULL == ed) {
status_error("image has no EXIF data");
return;
}
/* pass one -- get data + calc size */
l1 = 0;
l2 = 0;
for (tag = 0; tag < ARRAY_SIZE(tags); tag++) {
ee = exif_content_get_entry (ed->ifd[EXIF_IFD_0], tags[tag]);
if (NULL == ee)
ee = exif_content_get_entry (ed->ifd[EXIF_IFD_EXIF], tags[tag]);
if (NULL == ee) {
title[tag] = NULL;
value[tag] = NULL;
continue;
}
title[tag] = exif_tag_get_title(tags[tag]);
value[tag] = malloc(128);
exif_entry_get_value(ee, value[tag], 128);
len = strlen(title[tag]);
if (l1 < len)
l1 = len;
len = strlen(value[tag]);
if (l2 < len)
l2 = len;
}
/* pass two -- print stuff */
count = 0;
for (tag = 0; tag < ARRAY_SIZE(tags); tag++) {
if (NULL == title[tag])
continue;
linebuffer[count] = malloc(sizeof(wchar_t)*(l1+l2+8));
snprintf(linebuffer[count], l1+l2+8,
"%-*.*s : %-*.*s",
l1, l1, title[tag],
l2, l2, value[tag]);
count++;
}
shadow_draw_text_box(24, 16, transparency,
linebuffer, count);
shadow_render(gfx);
/* pass three -- free data */
for (tag = 0; tag < ARRAY_SIZE(tags); tag++)
if (NULL != value[tag])
free(value[tag]);
exif_data_unref (ed);
for (i = 0; i < count; i++)
free(linebuffer[i]);
}
static void show_help(void)
{
static char *help[] = {
"keyboard commands",
"~~~~~~~~~~~~~~~~~",
" cursor keys - scroll image",
" PgUp, k - previous image",
" PgDn, SPACE, j - next image",
" <i>g - jump to image #i",
"",
" a - autozoom image",
" +/- - zoom in/out",
" <i>s - set zoom to <i>%",
"",
" ESC, q - quit",
" v - toggle statusline",
" h - show this help text",
" i - show EXIF info",
" p - pause slideshow",
"",
"available if started with --edit switch,",
"rotation works for jpeg images only:",
" D, Shift+d - delete image",
" r - rotate 90 degrees clockwise",
" l - rotate 90 degrees counter-clockwise",
" x - mirror image vertically (top / bottom)",
" y - mirror image horizontally (left to right)",
};
shadow_draw_text_box(24, 16, transparency,
help, ARRAY_SIZE(help));
shadow_render(gfx);
}
/* ---------------------------------------------------------------------- */
static void free_image(struct ida_image *img)
{
if (img) {
if (img->p) {
img_mem -= img->i.width * img->i.height * 3;
ida_image_free(img);
}
free(img);
}
}
static struct ida_image*
read_image(char *filename)
{
struct ida_loader *loader = NULL;
struct ida_image *img;
struct list_head *item;
char blk[512];
FILE *fp;
unsigned int y;
void *data;
/* open file */
if (NULL == (fp = fopen(filename, "r"))) {
fprintf(stderr,"open %s: %s\n",filename,strerror(errno));
return NULL;
}
memset(blk,0,sizeof(blk));
fread(blk,1,sizeof(blk),fp);
rewind(fp);
/* pick loader */
list_for_each(item,&loaders) {
loader = list_entry(item, struct ida_loader, list);
if (NULL == loader->magic)
break;
if (0 == memcmp(blk+loader->moff,loader->magic,loader->mlen))
break;
loader = NULL;
}
if (NULL == loader) {
/* no loader found, try to use ImageMagick's convert */
int p[2];
if (0 != pipe(p))
return NULL;
switch (fork()) {
case -1: /* error */
perror("fork");
close(p[0]);
close(p[1]);
return NULL;
case 0: /* child */
dup2(p[1], 1 /* stdout */);
close(p[0]);
close(p[1]);
execlp("convert", "convert", "-depth", "8", filename, "ppm:-", NULL);
exit(1);
default: /* parent */
close(p[1]);
fp = fdopen(p[0], "r");
if (NULL == fp)
return NULL;
loader = &ppm_loader;
}
}
/* load image */
img = malloc(sizeof(*img));
memset(img,0,sizeof(*img));
data = loader->init(fp,filename,0,&img->i,0);
if (NULL == data) {
fprintf(stderr,"loading %s [%s] FAILED\n",filename,loader->name);
free_image(img);
return NULL;
}
ida_image_alloc(img);
img_mem += img->i.width * img->i.height * 3;
for (y = 0; y < img->i.height; y++) {
check_console_switch();
loader->read(ida_image_scanline(img, y), y, data);
}
loader->done(data);
return img;
}
static struct ida_image*
scale_image(struct ida_image *src, float scale)
{
struct op_resize_parm p;
struct ida_rect rect;
struct ida_image *dest;
void *data;
unsigned int y;
dest = malloc(sizeof(*dest));
memset(dest,0,sizeof(*dest));
memset(&rect,0,sizeof(rect));
memset(&p,0,sizeof(p));
p.width = src->i.width * scale;
p.height = src->i.height * scale;
p.dpi = src->i.dpi;
if (0 == p.width)
p.width = 1;
if (0 == p.height)
p.height = 1;
data = desc_resize.init(src,&rect,&dest->i,&p);
ida_image_alloc(dest);
img_mem += dest->i.width * dest->i.height * 3;
for (y = 0; y < dest->i.height; y++) {
check_console_switch();
desc_resize.work(src, &rect, ida_image_scanline(dest, y), y, data);
}
desc_resize.done(data);
return dest;
}
static float auto_scale(struct ida_image *img)
{
float xs,ys,scale;
xs = (float)gfx->hdisplay / img->i.width;
if (fitwidth)
return xs;
ys = (float)gfx->vdisplay / img->i.height;
scale = (xs < ys) ? xs : ys;
return scale;
}
static int calculate_text_steps(int height, int yres)
{
int pages = ceil((float)height / yres);
int text_steps = ceil((float)height / pages);
return text_steps;
}
/* ---------------------------------------------------------------------- */
static void effect_blend(struct flist *f, struct flist *t)
{
struct timeval start, now;
int msecs, weight = 0;
char linebuffer[80];
int pos = 0;
int count = 0;
gettimeofday(&start, NULL);
do {
gettimeofday(&now, NULL);
msecs = (now.tv_sec - start.tv_sec) * 1000;
msecs += (now.tv_usec - start.tv_usec) / 1000;
weight = msecs * 100 / blend_msecs;
if (weight > 100)
weight = 100;
shadow_draw_image(flist_img_get(f), f->left, f->top,
0, gfx->vdisplay-1, 100);
shadow_draw_image(flist_img_get(t), t->left, t->top,
0, gfx->vdisplay-1, weight);
if (perfmon) {
pos += snprintf(linebuffer+pos, sizeof(linebuffer)-pos,
" %d%%", weight);
status_update(linebuffer, NULL);
count++;
}
shadow_render(gfx);
} while (weight < 100);
if (perfmon) {
gettimeofday(&now, NULL);
msecs = (now.tv_sec - start.tv_sec) * 1000;
msecs += (now.tv_usec - start.tv_usec) / 1000;
pos += snprintf(linebuffer+pos, sizeof(linebuffer)-pos,
" | %d/%d -> %d msec",
msecs, count, msecs/count);
status_update(linebuffer, NULL);
shadow_render(gfx);
sleep(2);
}
}
static int
svga_show(struct flist *f, struct flist *prev,
int timeout, char *desc, char *info, int *nr)
{
static int paused = 0, skip = -1;
struct ida_image *img = flist_img_get(f);
int exif = 0, help = 0;
int rc;
char key[16];
uint32_t keycode, keymod;
char linebuffer[80];
*nr = 0;
if (NULL == img)
return skip;
redraw = 1;
for (;;) {
if (redraw) {
redraw = 0;
if (img->i.height <= gfx->vdisplay) {
f->top = 0;
} else {
if (f->top < 0)
f->top = 0;
if (f->top + gfx->vdisplay > img->i.height)
f->top = img->i.height - gfx->vdisplay;
}
if (img->i.width <= gfx->hdisplay) {
f->left = 0;
} else {
if (f->left < 0)
f->left = 0;
if (f->left + gfx->hdisplay > img->i.width)
f->left = img->i.width - gfx->hdisplay;
}
if (blend_msecs && prev && prev != f &&
flist_img_get(prev) && flist_img_get(f)) {
effect_blend(prev, f);
prev = NULL;
} else {
shadow_draw_image(img, f->left, f->top, 0, gfx->vdisplay-1, 100);
}
status_update(desc, info);
shadow_render(gfx);
if (read_ahead) {
struct flist *f = flist_next(fcurrent,1,0);
if (f && !f->fimg)
flist_img_load(f,1);
status_update(desc, info);
shadow_render(gfx);
}
}
if (check_console_switch()) {
continue;
}
if (!interactive) {
sleep(timeout);
return -1;
}
rc = kbd_wait(paused ? 0 : timeout);
if (check_console_switch()) {
continue;
}
if (rc < 1)
return -1; /* timeout */
rc = kbd_read(key, sizeof(key), &keycode, &keymod);
if (rc < 0)
return XKB_KEY_Escape; /* EOF */
switch (keycode) {
case XKB_KEY_space:
if (textreading && f->top < (int)(img->i.height - gfx->vdisplay)) {
redraw = 1;
f->top += f->text_steps;
} else {
skip = XKB_KEY_space;
return XKB_KEY_space;
}
break;
case XKB_KEY_UP:
redraw = 1;
f->top -= v_steps;
break;
case XKB_KEY_DOWN:
redraw = 1;
f->top += v_steps;
break;
case XKB_KEY_Home:
redraw = 1;
f->top = 0;
break;
case XKB_KEY_End:
redraw = 1;
f->top = img->i.height - gfx->vdisplay;
break;
case XKB_KEY_Left:
redraw = 1;
f->left -= h_steps;
break;
case XKB_KEY_Right:
redraw = 1;
f->left += h_steps;
break;
case XKB_KEY_Page_Up:
case XKB_KEY_K:
if (textreading && f->top > 0) {
redraw = 1;
f->top -= f->text_steps;
} else {
skip = XKB_KEY_Page_Up;
return XKB_KEY_Page_Up;
}
break;
case XKB_KEY_Page_Down:
case XKB_KEY_J:
case XKB_KEY_N:
if (textreading && f->top < (int)(img->i.height - gfx->vdisplay)) {
redraw = 1;
f->top += f->text_steps;
} else {
skip = XKB_KEY_Page_Down;
return XKB_KEY_Page_Down;
}
break;
case XKB_KEY_P:
if (0 != timeout) {
paused = !paused;
status_update(paused ? "pause on " : "pause off", NULL);
}
break;
case XKB_KEY_H:
if (!help) {
show_help();
help = 1;
} else {
redraw = 1;
help = 0;
}
exif = 0;
break;
case XKB_KEY_I:
if (!exif) {
show_exif(fcurrent);
exif = 1;
} else {
redraw = 1;
exif = 0;
}
help = 0;
break;
case XKB_KEY_0:
case XKB_KEY_1:
case XKB_KEY_2:
case XKB_KEY_3:
case XKB_KEY_4:
case XKB_KEY_5:
case XKB_KEY_6:
case XKB_KEY_7:
case XKB_KEY_8:
case XKB_KEY_9:
*nr = *nr * 10;
if (keycode != XKB_KEY_0)
*nr += keycode - XKB_KEY_1 + 1;
snprintf(linebuffer, sizeof(linebuffer), "> %d",*nr);
status_update(linebuffer, NULL);
break;
case XKB_KEY_D:
/* need shift state for this one */
return XKB_KEY_D | (keymod << 16);
case XKB_KEY_VoidSymbol:
/* ignored event */
break;
default:
return keycode;
}
}
}
static void scale_fix_top_left(struct flist *f, float old, float new)
{
struct ida_image *img = flist_img_get(f);
unsigned int width, height;
float cx,cy;
cx = (float)(f->left + gfx->hdisplay/2) / (img->i.width * old);
cy = (float)(f->top + gfx->vdisplay/2) / (img->i.height * old);
width = img->i.width * new;
height = img->i.height * new;
f->left = cx * width - gfx->hdisplay/2;
f->top = cy * height - gfx->vdisplay/2;
if (textreading) {
f->text_steps = calculate_text_steps(height, gfx->vdisplay);
}
}
/* ---------------------------------------------------------------------- */
static char *my_basename(char *filename)
{
char *h;
h = strrchr(filename,'/');
if (h)
return h+1;
return filename;
}
static char *file_desktop(char *filename)
{
static char desc[128];
char *h;
strncpy(desc,filename,sizeof(desc)-1);
if (NULL != (h = strrchr(filename,'/'))) {
snprintf(desc,sizeof(desc),"%.*s/%s",
(int)(h - filename), filename,
".directory");
} else {
strcpy(desc,".directory");
}
return desc;
}
static char *make_desc(struct ida_image_info *img, char *filename)
{
static char linebuffer[128];
struct ida_extra *extra;
char *desc;
int len;
memset(linebuffer,0,sizeof(linebuffer));
strncpy(linebuffer,filename,sizeof(linebuffer)-1);
if (comments) {
extra = load_find_extra(img, EXTRA_COMMENT);
if (extra)
snprintf(linebuffer,sizeof(linebuffer),"%.*s",
extra->size,extra->data);
} else {
desc = file_desktop(filename);
len = desktop_read_entry(desc, "Comment=", linebuffer, sizeof(linebuffer));
if (0 != len)
snprintf(linebuffer+len,sizeof(linebuffer)-len,
" (%s)", my_basename(filename));
}
return linebuffer;
}
static char *make_info(struct ida_image *img, float scale)
{
static char linebuffer[128];
snprintf(linebuffer, sizeof(linebuffer),
"%s%.0f%% %ux%u %d/%d",
fcurrent->tag ? "* " : "",
scale*100,