~ubuntu-branches/debian/sid/feh/sid

« back to all changes in this revision

Viewing changes to src/thumbnail.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Tille
  • Date: 2010-06-01 11:37:21 UTC
  • mfrom: (1.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100601113721-fraf4g038q7jdpcw
Tags: 1.6-1
* New upstream version
  Closes: #430218
* debian/control: Build-Depends: perl-modules, libtest-command-perl
  to enable testing

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
        int index_image_width, index_image_height;
72
72
        int x_offset_name = 0, x_offset_dim = 0, x_offset_size = 0;
73
73
        char *s;
 
74
        unsigned int thumb_counter = 0;
74
75
 
75
76
        /* initialize thumbnail mode data */
76
77
        td.im_main = NULL;
172
173
 
173
174
        /* make sure we have an ~/.thumbnails/normal directory for storing
174
175
           permanent thumbnails */
175
 
        td.cache_thumbnails = feh_thumbnail_setup_thumbnail_dir();
176
176
        td.cache_thumbnails = opt.cache_thumbnails;
177
177
 
 
178
        if (td.cache_thumbnails) {
 
179
                if (opt.thumb_w > opt.thumb_h)
 
180
                        td.cache_dim = opt.thumb_w;
 
181
                else
 
182
                        td.cache_dim = opt.thumb_h;
 
183
 
 
184
                if (td.cache_dim > 256) {
 
185
                        /* No caching as specified by standard. Sort of. */
 
186
                        td.cache_thumbnails = 0;
 
187
                } else if (td.cache_dim > 128) {
 
188
                        td.cache_dim = 256;
 
189
                        td.cache_dir = estrdup("large");
 
190
                } else {
 
191
                        td.cache_dim = 128;
 
192
                        td.cache_dir = estrdup("normal");
 
193
                }
 
194
                feh_thumbnail_setup_thumbnail_dir();
 
195
        }
 
196
 
178
197
        for (l = filelist; l; l = l->next) {
179
198
                file = FEH_FILE(l->data);
180
199
                if (last) {
278
297
                                        break;
279
298
                        }
280
299
 
281
 
                        if (opt.aspect) {
282
 
                                xxx = x + ((opt.thumb_w - www) / 2);
283
 
                                yyy = y + ((opt.thumb_h - hhh) / 2);
284
 
                        } else {
285
 
                                /* Ignore the aspect ratio and squash the image in */
286
 
                                xxx = x;
287
 
                                yyy = y;
288
 
                        }
 
300
                        /* center image relative to the text below it (if any) */
 
301
                        xxx = x + ((td.text_area_w - www) / 2);
 
302
                        yyy = y;
 
303
 
 
304
                        if (opt.aspect)
 
305
                                yyy += (opt.thumb_h - hhh) / 2;
289
306
 
290
307
                        /* Draw now */
291
308
                        gib_imlib_blend_image_onto_image(td.im_main,
334
351
                        last = l;
335
352
                }
336
353
                if (opt.display) {
337
 
                        winwidget_render_image(winwid, 0, 0);
 
354
                        /* thumb_counter is unsigned, so no need to catch overflows */
 
355
                        if (++thumb_counter == opt.thumb_redraw) {
 
356
                                winwidget_render_image(winwid, 0, 0);
 
357
                                thumb_counter = 0;
 
358
                        }
338
359
                        if (!feh_main_iteration(0))
339
360
                                exit(0);
340
361
                }
341
362
        }
 
363
 
 
364
        if (thumb_counter != 0)
 
365
                winwidget_render_image(winwid, 0, 0);
 
366
 
342
367
        if (opt.verbose)
343
368
                fprintf(stdout, "\n");
344
369
 
719
744
                if (!status)
720
745
                        status = feh_thumbnail_generate(image, file, thumb_file, uri);
721
746
 
722
 
                printf("uri is %s, thumb_file is %s\n", uri, thumb_file);
 
747
                D(1, ("uri is %s, thumb_file is %s\n", uri, thumb_file));
723
748
                free(uri);
724
749
                free(thumb_file);
725
750
        } else
738
763
 
739
764
        home = getenv("HOME");
740
765
        if (home) {
741
 
                thumb_file = estrjoin("/", home, ".thumbnails/normal", md5_name, NULL);
 
766
                thumb_file = estrjoin("/", home, ".thumbnails", td.cache_dir, md5_name, NULL);
742
767
        }
743
768
 
744
769
        free(md5_name);
750
775
{
751
776
        char *cwd, *uri = NULL;
752
777
 
753
 
        /* FIXME: what happends with http, https, and ftp? MTime etc */
 
778
        /* FIXME: what happens with http, https, and ftp? MTime etc */
754
779
        if ((strncmp(name, "http://", 7) != 0) &&
755
780
            (strncmp(name, "https://", 8) != 0) && (strncmp(name, "ftp://", 6) != 0)
756
781
            && (strncmp(name, "file://", 7) != 0)) {
803
828
        if (feh_load_image(&im_temp, file) != 0) {
804
829
                w = gib_imlib_image_get_width(im_temp);
805
830
                h = gib_imlib_image_get_height(im_temp);
806
 
                thumb_w = 128;
807
 
                thumb_h = 128;
 
831
                thumb_w = td.cache_dim;
 
832
                thumb_h = td.cache_dim;
808
833
 
809
 
                if ((w > 128) || (h > 128)) {
 
834
                if ((w > td.cache_dim) || (h > td.cache_dim)) {
810
835
                        double ratio = (double) w / h;
811
836
                        if (ratio > 1.0)
812
 
                                thumb_h = 128 / ratio;
 
837
                                thumb_h = td.cache_dim / ratio;
813
838
                        else if (ratio != 1.0)
814
 
                                thumb_w = 128 * ratio;
 
839
                                thumb_w = td.cache_dim * ratio;
815
840
                }
816
841
 
817
842
                *image = gib_imlib_create_cropped_scaled_image(im_temp, 0, 0, w, h,
867
892
 
868
893
        home = getenv("HOME");
869
894
        if (home != NULL) {
870
 
                dir = estrjoin("/", home, ".thumbnails/normal", NULL);
 
895
                dir = estrjoin("/", home, ".thumbnails", td.cache_dir, NULL);
871
896
 
872
897
                if (!stat(dir, &sb)) {
873
898
                        if (S_ISDIR(sb.st_mode))