Krolyxon
Commit 7334bdf

Branches

Refs →

nsxiv7334bdf

Revert "Save rotated png-files with S-key"

This reverts commit 090ee5405b70d6dfa16a8ca3a691dbd556c41bdb.
Author
Bert
Date
2011-02-27 13:03 +0100
Parent
090ee54
Commit
7334bdfa51778d143958811bd38d4719fcbf72f0

+50 −81

6 files changed

  1. M Makefile +1 −1
  2. M image.c +4 −33
  3. M image.h +0 −3
  4. M main.c +40 −28
  5. M thumbs.c +4 −14
  6. M thumbs.h +1 −2
M Makefile View
@@ -1,6 +1,6 @@
11 all: sxiv
22
3−VERSION=git-20110227
3+VERSION=0.7
44
55 CC?=gcc
66 PREFIX?=/usr/local
M image.c View
@@ -16,7 +16,6 @@
1616 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1717 */
1818
19−#include <string.h>
2019 #include <unistd.h>
2120
2221 #include "config.h"
@@ -29,9 +28,6 @@ int zl_cnt;
2928 float zoom_min;
3029 float zoom_max;
3130
32−const short ori_left[8] = { 8, 7, 6, 5, 2, 1, 4, 3 };
33−const short ori_right[8] = { 6, 5, 8, 7, 4, 3, 2, 1 };
34−
3531 Imlib_Image *im_broken;
3632
3733 void img_init(img_t *img, win_t *win) {
@@ -94,8 +90,8 @@ int img_load(img_t *img, const char *filename) {
9490 img->scalemode = SCALE_DOWN;
9591 }
9692
97− img->ori = img->o_ori = 1;
98− img->re = img->checkpan = 0;
93+ img->re = 0;
94+ img->checkpan = 0;
9995
10096 img->w = imlib_image_get_width();
10197 img->h = imlib_image_get_height();
@@ -103,25 +99,6 @@ int img_load(img_t *img, const char *filename) {
10399 return 1;
104100 }
105101
106−int img_save(img_t *img) {
107− const char *fmt;
108−
109− if (!img || !img->im)
110− return 0;
111−
112− imlib_context_set_image(img->im);
113−
114− if (img->ori != img->o_ori) {
115− fmt = imlib_image_format();
116− if (strcmp(fmt, "png") == 0) {
117− imlib_save_image(imlib_image_get_filename());
118− return 1;
119− }
120− }
121−
122− return 0;
123−}
124−
125102 void img_close(img_t *img) {
126103 if (img && img->im) {
127104 imlib_context_set_image(img->im);
@@ -364,17 +341,11 @@ void img_rotate(img_t *img, win_t *win, int d) {
364341 }
365342
366343 void img_rotate_left(img_t *img, win_t *win) {
367− if (img) {
368− img_rotate(img, win, 3);
369− img->ori = ori_left[img->ori];
370− }
344+ img_rotate(img, win, 3);
371345 }
372346
373347 void img_rotate_right(img_t *img, win_t *win) {
374− if (img) {
375− img_rotate(img, win, 1);
376− img->ori = ori_right[img->ori];
377− }
348+ img_rotate(img, win, 1);
378349 }
379350
380351 void img_toggle_antialias(img_t *img) {
M image.h View
@@ -41,8 +41,6 @@ typedef struct img_s {
4141
4242 float zoom;
4343 scalemode_t scalemode;
44− short ori;
45− short o_ori;
4644
4745 unsigned char re;
4846 unsigned char checkpan;
@@ -59,7 +57,6 @@ void img_free(img_t*);
5957
6058 int img_check(const char*);
6159 int img_load(img_t*, const char*);
62−int img_save(img_t*);
6360 void img_close(img_t*);
6461
6562 void img_render(img_t*, win_t*);
M main.c View
@@ -69,11 +69,10 @@ void cleanup() {
6969 }
7070 }
7171
72−int load_image(int new) {
72+int load_image() {
7373 struct stat fstats;
7474
7575 img_close(&img);
76− fileidx = new;
7776
7877 if (!stat(filenames[fileidx], &fstats))
7978 filesize = fstats.st_size;
@@ -141,7 +140,7 @@ int main(int argc, char **argv) {
141140 } else {
142141 mode = MODE_NORMAL;
143142 tns.thumbs = NULL;
144− load_image(fileidx);
143+ load_image();
145144 img_render(&img, &win);
146145 }
147146
@@ -308,29 +307,41 @@ void on_keypress(XKeyEvent *kev) {
308307 /* navigate image list */
309308 case XK_n:
310309 case XK_space:
311− if (fileidx + 1 < filecnt)
312− changed = load_image(fileidx + 1);
310+ if (fileidx + 1 < filecnt) {
311+ ++fileidx;
312+ changed = load_image();
313+ }
313314 break;
314315 case XK_p:
315316 case XK_BackSpace:
316− if (fileidx > 0)
317− changed = load_image(fileidx - 1);
317+ if (fileidx > 0) {
318+ --fileidx;
319+ changed = load_image();
320+ }
318321 break;
319322 case XK_bracketleft:
320− if (fileidx != 0)
321− changed = load_image(MAX(0, fileidx - 10));
323+ if (fileidx != 0) {
324+ fileidx = MAX(0, fileidx - 10);
325+ changed = load_image();
326+ }
322327 break;
323328 case XK_bracketright:
324− if (fileidx != filecnt - 1)
325− changed = load_image(MIN(fileidx + 10, filecnt - 1));
329+ if (fileidx != filecnt - 1) {
330+ fileidx = MIN(fileidx + 10, filecnt - 1);
331+ changed = load_image();
332+ }
326333 break;
327334 case XK_g:
328− if (fileidx != 0)
329− changed = load_image(0);
335+ if (fileidx != 0) {
336+ fileidx = 0;
337+ changed = load_image();
338+ }
330339 break;
331340 case XK_G:
332− if (fileidx != filecnt - 1)
333− changed = load_image(filecnt - 1);
341+ if (fileidx != filecnt - 1) {
342+ fileidx = filecnt - 1;
343+ changed = load_image();
344+ }
334345 break;
335346
336347 /* zooming */
@@ -407,11 +418,7 @@ void on_keypress(XKeyEvent *kev) {
407418 changed = 1;
408419 break;
409420 case XK_r:
410− changed = load_image(fileidx);
411− break;
412− case XK_S:
413− if (img_save(&img))
414− tns_load(&tns, &win, fileidx, filenames[fileidx]);
421+ changed = load_image();
415422 break;
416423 }
417424 } else {
@@ -419,7 +426,8 @@ void on_keypress(XKeyEvent *kev) {
419426 switch (ksym) {
420427 /* open selected image */
421428 case XK_Return:
422− load_image(tns.sel);
429+ fileidx = tns.sel;
430+ load_image();
423431 mode = MODE_NORMAL;
424432 win_set_cursor(&win, CURSOR_NONE);
425433 changed = 1;
@@ -488,8 +496,10 @@ void on_buttonpress(XButtonEvent *bev) {
488496 if (mode == MODE_NORMAL) {
489497 switch (bev->button) {
490498 case Button1:
491− if (fileidx + 1 < filecnt)
492− changed = load_image(fileidx + 1);
499+ if (fileidx + 1 < filecnt) {
500+ ++fileidx;
501+ changed = load_image();
502+ }
493503 break;
494504 case Button2:
495505 mox = bev->x;
@@ -499,8 +509,10 @@ void on_buttonpress(XButtonEvent *bev) {
499509 drag = 1;
500510 break;
501511 case Button3:
502− if (fileidx > 0)
503− changed = load_image(fileidx - 1);
512+ if (fileidx > 0) {
513+ --fileidx;
514+ changed = load_image();
515+ }
504516 break;
505517 case Button4:
506518 if (mask == ControlMask)
@@ -531,7 +543,8 @@ void on_buttonpress(XButtonEvent *bev) {
531543 case Button1:
532544 if ((sel = tns_translate(&tns, bev->x, bev->y)) >= 0) {
533545 if (sel == tns.sel) {
534− load_image(tns.sel);
546+ fileidx = tns.sel;
547+ load_image();
535548 mode = MODE_NORMAL;
536549 timo_cursor = TO_CURSOR_HIDE;
537550 } else {
@@ -587,8 +600,7 @@ void run() {
587600 gettimeofday(&t0, 0);
588601
589602 while (!XPending(win.env.dpy) && tns.cnt < filecnt) {
590− /* tns.cnt is increased inside tns_load */
591− tns_load(&tns, &win, tns.cnt, filenames[tns.cnt]);
603+ tns_load(&tns, &win, filenames[tns.cnt]);
592604 gettimeofday(&t1, 0);
593605 if (TV_TO_DOUBLE(t1) - TV_TO_DOUBLE(t0) >= 0.25)
594606 break;
M thumbs.c View
@@ -35,7 +35,6 @@ void tns_init(tns_t *tns, int cnt) {
3535 tns->cnt = tns->first = tns->sel = 0;
3636 tns->thumbs = (thumb_t*) s_malloc(cnt * sizeof(thumb_t));
3737 memset(tns->thumbs, 0, cnt * sizeof(thumb_t));
38− tns->cap = cnt;
3938 tns->dirty = 0;
4039 }
4140
@@ -52,7 +51,7 @@ void tns_free(tns_t *tns, win_t *win) {
5251 tns->thumbs = NULL;
5352 }
5453
55−void tns_load(tns_t *tns, win_t *win, int n, const char *filename) {
54+void tns_load(tns_t *tns, win_t *win, const char *filename) {
5655 int w, h;
5756 float z, zw, zh;
5857 thumb_t *t;
@@ -61,17 +60,10 @@ void tns_load(tns_t *tns, win_t *win, int n, const char *filename) {
6160 if (!tns || !win || !filename)
6261 return;
6362
64− if (n >= tns->cap)
65− return;
66− else if (n >= tns->cnt)
67− tns->cnt = n + 1;
68−
69− if ((im = imlib_load_image(filename))) {
63+ if ((im = imlib_load_image(filename)))
7064 imlib_context_set_image(im);
71− imlib_image_set_changes_on_disk();
72− } else {
65+ else
7366 imlib_context_set_image(im_broken);
74− }
7567
7668 w = imlib_image_get_width();
7769 h = imlib_image_get_height();
@@ -81,12 +73,10 @@ void tns_load(tns_t *tns, win_t *win, int n, const char *filename) {
8173 if (!im && z > 1.0)
8274 z = 1.0;
8375
84− t = &tns->thumbs[n];
76+ t = &tns->thumbs[tns->cnt++];
8577 t->w = z * w;
8678 t->h = z * h;
8779
88− if (t->pm)
89− win_free_pixmap(win, t->pm);
9080 t->pm = win_create_pixmap(win, t->w, t->h);
9181 imlib_context_set_drawable(t->pm);
9282 imlib_context_set_anti_alias(1);
M thumbs.h View
@@ -38,7 +38,6 @@ typedef struct thumb_s {
3838
3939 typedef struct tns_s {
4040 thumb_t *thumbs;
41− int cap;
4241 int cnt;
4342 int x;
4443 int y;
@@ -52,7 +51,7 @@ typedef struct tns_s {
5251 void tns_init(tns_t*, int);
5352 void tns_free(tns_t*, win_t*);
5453
55−void tns_load(tns_t*, win_t*, int, const char*);
54+void tns_load(tns_t*, win_t*, const char*);
5655
5756 void tns_render(tns_t*, win_t*);
5857 void tns_highlight(tns_t*, win_t*, int, Bool);