nsxiv7334bdf
Revert "Save rotated png-files with S-key"
This reverts commit 090ee5405b70d6dfa16a8ca3a691dbd556c41bdb.
+50 −81
6 files changed
- M Makefile +1 −1
- M image.c +4 −33
- M image.h +0 −3
- M main.c +40 −28
- M thumbs.c +4 −14
- M thumbs.h +1 −2
| @@ -1,6 +1,6 @@ | |||
| 1 | 1 | all: sxiv | |
| 2 | 2 | ||
| 3 | − | VERSION=git-20110227 | |
| 3 | + | VERSION=0.7 | |
| 4 | 4 | ||
| 5 | 5 | CC?=gcc | |
| 6 | 6 | PREFIX?=/usr/local | |
| @@ -16,7 +16,6 @@ | |||
| 16 | 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
| 17 | 17 | */ | |
| 18 | 18 | ||
| 19 | − | #include <string.h> | |
| 20 | 19 | #include <unistd.h> | |
| 21 | 20 | ||
| 22 | 21 | #include "config.h" | |
| @@ -29,9 +28,6 @@ int zl_cnt; | |||
| 29 | 28 | float zoom_min; | |
| 30 | 29 | float zoom_max; | |
| 31 | 30 | ||
| 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 | − | ||
| 35 | 31 | Imlib_Image *im_broken; | |
| 36 | 32 | ||
| 37 | 33 | void img_init(img_t *img, win_t *win) { | |
| @@ -94,8 +90,8 @@ int img_load(img_t *img, const char *filename) { | |||
| 94 | 90 | img->scalemode = SCALE_DOWN; | |
| 95 | 91 | } | |
| 96 | 92 | ||
| 97 | − | img->ori = img->o_ori = 1; | |
| 98 | − | img->re = img->checkpan = 0; | |
| 93 | + | img->re = 0; | |
| 94 | + | img->checkpan = 0; | |
| 99 | 95 | ||
| 100 | 96 | img->w = imlib_image_get_width(); | |
| 101 | 97 | img->h = imlib_image_get_height(); | |
| @@ -103,25 +99,6 @@ int img_load(img_t *img, const char *filename) { | |||
| 103 | 99 | return 1; | |
| 104 | 100 | } | |
| 105 | 101 | ||
| 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 | − | ||
| 125 | 102 | void img_close(img_t *img) { | |
| 126 | 103 | if (img && img->im) { | |
| 127 | 104 | imlib_context_set_image(img->im); | |
| @@ -364,17 +341,11 @@ void img_rotate(img_t *img, win_t *win, int d) { | |||
| 364 | 341 | } | |
| 365 | 342 | ||
| 366 | 343 | 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); | |
| 371 | 345 | } | |
| 372 | 346 | ||
| 373 | 347 | 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); | |
| 378 | 349 | } | |
| 379 | 350 | ||
| 380 | 351 | void img_toggle_antialias(img_t *img) { | |
| @@ -41,8 +41,6 @@ typedef struct img_s { | |||
| 41 | 41 | ||
| 42 | 42 | float zoom; | |
| 43 | 43 | scalemode_t scalemode; | |
| 44 | − | short ori; | |
| 45 | − | short o_ori; | |
| 46 | 44 | ||
| 47 | 45 | unsigned char re; | |
| 48 | 46 | unsigned char checkpan; | |
| @@ -59,7 +57,6 @@ void img_free(img_t*); | |||
| 59 | 57 | ||
| 60 | 58 | int img_check(const char*); | |
| 61 | 59 | int img_load(img_t*, const char*); | |
| 62 | − | int img_save(img_t*); | |
| 63 | 60 | void img_close(img_t*); | |
| 64 | 61 | ||
| 65 | 62 | void img_render(img_t*, win_t*); | |
| @@ -69,11 +69,10 @@ void cleanup() { | |||
| 69 | 69 | } | |
| 70 | 70 | } | |
| 71 | 71 | ||
| 72 | − | int load_image(int new) { | |
| 72 | + | int load_image() { | |
| 73 | 73 | struct stat fstats; | |
| 74 | 74 | ||
| 75 | 75 | img_close(&img); | |
| 76 | − | fileidx = new; | |
| 77 | 76 | ||
| 78 | 77 | if (!stat(filenames[fileidx], &fstats)) | |
| 79 | 78 | filesize = fstats.st_size; | |
| @@ -141,7 +140,7 @@ int main(int argc, char **argv) { | |||
| 141 | 140 | } else { | |
| 142 | 141 | mode = MODE_NORMAL; | |
| 143 | 142 | tns.thumbs = NULL; | |
| 144 | − | load_image(fileidx); | |
| 143 | + | load_image(); | |
| 145 | 144 | img_render(&img, &win); | |
| 146 | 145 | } | |
| 147 | 146 | ||
| @@ -308,29 +307,41 @@ void on_keypress(XKeyEvent *kev) { | |||
| 308 | 307 | /* navigate image list */ | |
| 309 | 308 | case XK_n: | |
| 310 | 309 | 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 | + | } | |
| 313 | 314 | break; | |
| 314 | 315 | case XK_p: | |
| 315 | 316 | case XK_BackSpace: | |
| 316 | − | if (fileidx > 0) | |
| 317 | − | changed = load_image(fileidx - 1); | |
| 317 | + | if (fileidx > 0) { | |
| 318 | + | --fileidx; | |
| 319 | + | changed = load_image(); | |
| 320 | + | } | |
| 318 | 321 | break; | |
| 319 | 322 | 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 | + | } | |
| 322 | 327 | break; | |
| 323 | 328 | 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 | + | } | |
| 326 | 333 | break; | |
| 327 | 334 | case XK_g: | |
| 328 | − | if (fileidx != 0) | |
| 329 | − | changed = load_image(0); | |
| 335 | + | if (fileidx != 0) { | |
| 336 | + | fileidx = 0; | |
| 337 | + | changed = load_image(); | |
| 338 | + | } | |
| 330 | 339 | break; | |
| 331 | 340 | 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 | + | } | |
| 334 | 345 | break; | |
| 335 | 346 | ||
| 336 | 347 | /* zooming */ | |
| @@ -407,11 +418,7 @@ void on_keypress(XKeyEvent *kev) { | |||
| 407 | 418 | changed = 1; | |
| 408 | 419 | break; | |
| 409 | 420 | 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(); | |
| 415 | 422 | break; | |
| 416 | 423 | } | |
| 417 | 424 | } else { | |
| @@ -419,7 +426,8 @@ void on_keypress(XKeyEvent *kev) { | |||
| 419 | 426 | switch (ksym) { | |
| 420 | 427 | /* open selected image */ | |
| 421 | 428 | case XK_Return: | |
| 422 | − | load_image(tns.sel); | |
| 429 | + | fileidx = tns.sel; | |
| 430 | + | load_image(); | |
| 423 | 431 | mode = MODE_NORMAL; | |
| 424 | 432 | win_set_cursor(&win, CURSOR_NONE); | |
| 425 | 433 | changed = 1; | |
| @@ -488,8 +496,10 @@ void on_buttonpress(XButtonEvent *bev) { | |||
| 488 | 496 | if (mode == MODE_NORMAL) { | |
| 489 | 497 | switch (bev->button) { | |
| 490 | 498 | 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 | + | } | |
| 493 | 503 | break; | |
| 494 | 504 | case Button2: | |
| 495 | 505 | mox = bev->x; | |
| @@ -499,8 +509,10 @@ void on_buttonpress(XButtonEvent *bev) { | |||
| 499 | 509 | drag = 1; | |
| 500 | 510 | break; | |
| 501 | 511 | case Button3: | |
| 502 | − | if (fileidx > 0) | |
| 503 | − | changed = load_image(fileidx - 1); | |
| 512 | + | if (fileidx > 0) { | |
| 513 | + | --fileidx; | |
| 514 | + | changed = load_image(); | |
| 515 | + | } | |
| 504 | 516 | break; | |
| 505 | 517 | case Button4: | |
| 506 | 518 | if (mask == ControlMask) | |
| @@ -531,7 +543,8 @@ void on_buttonpress(XButtonEvent *bev) { | |||
| 531 | 543 | case Button1: | |
| 532 | 544 | if ((sel = tns_translate(&tns, bev->x, bev->y)) >= 0) { | |
| 533 | 545 | if (sel == tns.sel) { | |
| 534 | − | load_image(tns.sel); | |
| 546 | + | fileidx = tns.sel; | |
| 547 | + | load_image(); | |
| 535 | 548 | mode = MODE_NORMAL; | |
| 536 | 549 | timo_cursor = TO_CURSOR_HIDE; | |
| 537 | 550 | } else { | |
| @@ -587,8 +600,7 @@ void run() { | |||
| 587 | 600 | gettimeofday(&t0, 0); | |
| 588 | 601 | ||
| 589 | 602 | 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]); | |
| 592 | 604 | gettimeofday(&t1, 0); | |
| 593 | 605 | if (TV_TO_DOUBLE(t1) - TV_TO_DOUBLE(t0) >= 0.25) | |
| 594 | 606 | break; | |
| @@ -35,7 +35,6 @@ void tns_init(tns_t *tns, int cnt) { | |||
| 35 | 35 | tns->cnt = tns->first = tns->sel = 0; | |
| 36 | 36 | tns->thumbs = (thumb_t*) s_malloc(cnt * sizeof(thumb_t)); | |
| 37 | 37 | memset(tns->thumbs, 0, cnt * sizeof(thumb_t)); | |
| 38 | − | tns->cap = cnt; | |
| 39 | 38 | tns->dirty = 0; | |
| 40 | 39 | } | |
| 41 | 40 | ||
| @@ -52,7 +51,7 @@ void tns_free(tns_t *tns, win_t *win) { | |||
| 52 | 51 | tns->thumbs = NULL; | |
| 53 | 52 | } | |
| 54 | 53 | ||
| 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) { | |
| 56 | 55 | int w, h; | |
| 57 | 56 | float z, zw, zh; | |
| 58 | 57 | thumb_t *t; | |
| @@ -61,17 +60,10 @@ void tns_load(tns_t *tns, win_t *win, int n, const char *filename) { | |||
| 61 | 60 | if (!tns || !win || !filename) | |
| 62 | 61 | return; | |
| 63 | 62 | ||
| 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))) | |
| 70 | 64 | imlib_context_set_image(im); | |
| 71 | − | imlib_image_set_changes_on_disk(); | |
| 72 | − | } else { | |
| 65 | + | else | |
| 73 | 66 | imlib_context_set_image(im_broken); | |
| 74 | − | } | |
| 75 | 67 | ||
| 76 | 68 | w = imlib_image_get_width(); | |
| 77 | 69 | h = imlib_image_get_height(); | |
| @@ -81,12 +73,10 @@ void tns_load(tns_t *tns, win_t *win, int n, const char *filename) { | |||
| 81 | 73 | if (!im && z > 1.0) | |
| 82 | 74 | z = 1.0; | |
| 83 | 75 | ||
| 84 | − | t = &tns->thumbs[n]; | |
| 76 | + | t = &tns->thumbs[tns->cnt++]; | |
| 85 | 77 | t->w = z * w; | |
| 86 | 78 | t->h = z * h; | |
| 87 | 79 | ||
| 88 | − | if (t->pm) | |
| 89 | − | win_free_pixmap(win, t->pm); | |
| 90 | 80 | t->pm = win_create_pixmap(win, t->w, t->h); | |
| 91 | 81 | imlib_context_set_drawable(t->pm); | |
| 92 | 82 | imlib_context_set_anti_alias(1); | |
| @@ -38,7 +38,6 @@ typedef struct thumb_s { | |||
| 38 | 38 | ||
| 39 | 39 | typedef struct tns_s { | |
| 40 | 40 | thumb_t *thumbs; | |
| 41 | − | int cap; | |
| 42 | 41 | int cnt; | |
| 43 | 42 | int x; | |
| 44 | 43 | int y; | |
| @@ -52,7 +51,7 @@ typedef struct tns_s { | |||
| 52 | 51 | void tns_init(tns_t*, int); | |
| 53 | 52 | void tns_free(tns_t*, win_t*); | |
| 54 | 53 | ||
| 55 | − | void tns_load(tns_t*, win_t*, int, const char*); | |
| 54 | + | void tns_load(tns_t*, win_t*, const char*); | |
| 56 | 55 | ||
| 57 | 56 | void tns_render(tns_t*, win_t*); | |
| 58 | 57 | void tns_highlight(tns_t*, win_t*, int, Bool); | |