~mati75/spacefm/hand

« back to all changes in this revision

Viewing changes to src/vfs/vfs-thumbnail-loader.c

  • Committer: IgnorantGuru
  • Date: 2015-04-05 19:54:51 UTC
  • Revision ID: git-v1:61d701fed7fc467f5fbe4e2316be7083cd2d2908
[hand] create larger thumbnails; refresh view on icon size change #478

Show diffs side-by-side

added added

removed removed

Lines of Context:
318
318
}
319
319
 
320
320
static GdkPixbuf* _vfs_thumbnail_load( const char* file_path, const char* uri,
321
 
                                                                          int size, time_t mtime )
 
321
                                                    int size, time_t mtime )
322
322
{
323
323
#if GLIB_CHECK_VERSION(2, 16, 0)
324
324
    GChecksum *cs;
333
333
    int i, w, h;
334
334
    struct stat statbuf;
335
335
    GdkPixbuf* thumbnail, *result = NULL;
 
336
    int create_size = size > 128 ? 256 : 128;
336
337
 
337
338
    gboolean file_is_video = FALSE;
338
339
#ifdef HAVE_FFMPEG
345
346
    }
346
347
#endif
347
348
 
 
349
 
348
350
    if ( file_is_video == FALSE )
349
351
    {
350
352
        if ( !gdk_pixbuf_get_file_info( file_path, &w, &h ) )
351
353
            return NULL;   /* image format cannot be recognized */
352
354
 
353
355
        /* If the image itself is very small, we should load it directly */
354
 
        if ( w <= 128 && h <= 128 )
 
356
        if ( w <= create_size && h <= create_size )
355
357
        {
356
358
            if( w <= size && h <= size )
357
359
                return gdk_pixbuf_new_from_file( file_path, NULL );
386
388
 
387
389
    /* load existing thumbnail */
388
390
    thumbnail = gdk_pixbuf_new_from_file( thumbnail_file, NULL );
389
 
    if ( !thumbnail ||
390
 
            !( thumb_mtime = gdk_pixbuf_get_option( thumbnail, "tEXt::Thumb::MTime" ) ) ||
 
391
    if ( !thumbnail || !( thumb_mtime = gdk_pixbuf_get_option( thumbnail,
 
392
                                                "tEXt::Thumb::MTime" ) ) ||
391
393
            atol( thumb_mtime ) != mtime )
392
394
    {
393
395
        if( thumbnail )
395
397
        /* create new thumbnail */
396
398
        if ( file_is_video == FALSE )
397
399
        {
398
 
            thumbnail = gdk_pixbuf_new_from_file_at_size( file_path, 128, 128, NULL );
 
400
            thumbnail = gdk_pixbuf_new_from_file_at_size( file_path,
 
401
                                            create_size, create_size, NULL );
399
402
            if ( thumbnail )
400
403
            {
401
404
                thumbnail = gdk_pixbuf_apply_embedded_orientation( thumbnail );
402
405
                sprintf( mtime_str, "%lu", mtime );
403
406
                gdk_pixbuf_save( thumbnail, thumbnail_file, "png", NULL,
404
 
                                 "tEXt::Thumb::URI", uri, "tEXt::Thumb::MTime", mtime_str, NULL );
 
407
                                 "tEXt::Thumb::URI", uri, "tEXt::Thumb::MTime",
 
408
                                 mtime_str, NULL );
405
409
                chmod( thumbnail_file, 0600 );  /* only the owner can read it. */
406
410
            }
407
411
        }
413
417
            {
414
418
                video_thumb->seek_percentage = 25;
415
419
                video_thumb->overlay_film_strip = 1;
416
 
                video_thumbnailer_generate_thumbnail_to_file( video_thumb, file_path, thumbnail_file );
 
420
                video_thumb->thumbnail_size = create_size;
 
421
                video_thumbnailer_generate_thumbnail_to_file( video_thumb,
 
422
                                                file_path, thumbnail_file );
417
423
                video_thumbnailer_destroy( video_thumb );
418
424
 
419
425
                chmod( thumbnail_file, 0600 );  /* only the owner can read it. */