Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding thumbnails of CR3 files #824

Open
Tehgg opened this issue Jan 1, 2025 · 0 comments
Open

Adding thumbnails of CR3 files #824

Tehgg opened this issue Jan 1, 2025 · 0 comments

Comments

@Tehgg
Copy link

Tehgg commented Jan 1, 2025

By default, only the video files or the image files that are recognized by GdkPixbuf can have a thumbnail. I added thumbnails for CR3 files to my local version of spacefm, using exiv2. Here I share my ugly hacks, maybe someone will find it useful or have some comments.

The relevant parts are:

  • In src/vfs/vfs-thumbnail-loader.c, the function _vfs_thumbnail_load (line 354).
  • The files src/desktop/desktop-window.c and src/ptk/ptk-file-list.c.

The idea is very lazy: when we want to create a thumbnail for a CR3 file, we extract the jpg with exiv2, and we hijack the existing code to create a thumbnail for this file instead. The diff of src/vfs/vfs-thumbnail-loader.c can be found below. You need to create a folder ~/.thumbnails/cr3. My CR3 files always have 2 embedded jpeg files, a small one and a larger one. I hardcoded below the extraction the second jpeg, which is the largest.

@@ -387,8 +387,9 @@
     }
 #endif
 
+    int cr3_file = !strcmp( vfs_mime_type_get_type( mimetype ), "image/x-canon-cr3" );
 
-    if ( file_is_video == FALSE )
+    if ( file_is_video == FALSE && !cr3_file )
     {
         if ( !gdk_pixbuf_get_file_info( file_path, &w, &h ) )
             return NULL;   /* image format cannot be recognized */
@@ -441,6 +442,12 @@
         w = gdk_pixbuf_get_width( thumbnail );
         h = gdk_pixbuf_get_height( thumbnail );
     }
+    else if ( cr3_file )
+    {
+      w = -1;
+      h = -1;
+    }
+
     if ( !thumbnail || ( w < size && h < size ) ||
                 !( thumb_mtime = gdk_pixbuf_get_option( thumbnail,
                                                 "tEXt::Thumb::MTime" ) ) ||
@@ -449,10 +456,21 @@
         if( thumbnail )
             g_object_unref( thumbnail );
         /* create new thumbnail */
+
+        if ( cr3_file )
+        {
+          symlink(file_path, "/home/user/.thumbnails/cr3/temp.CR3");
+          system("exiv2 -f -e p2 /home/user/.thumbnails/cr3/temp.CR3");
+          unlink("/home/user/.thumbnails/cr3/temp.CR3");
+          file_path = "/home/user/.thumbnails/cr3/temp-preview2.jpg";
+        }
+
         if ( file_is_video == FALSE )
         {
             thumbnail = gdk_pixbuf_new_from_file_at_size( file_path,
                                             create_size, create_size, NULL );
+            if ( cr3_file )
+                system("rm /home/user/.thumbnails/cr3/temp-preview2.jpg");
             if ( thumbnail )
             {
                 // Note: gdk_pixbuf_apply_embedded_orientation returns a new

The problem is that the size of CR3 files often exceeds the hard limit of 32768 KB for thumbnails to show. There are two options. The easiest one is to increase that limit in the file data/ui/prefdlg2.ui. The second option is to modify the files src/desktop/desktop-window.c and src/ptk/ptk-file-list.c to bypass the size limit when the file is a CR3 file. This is not a problem, since exiv2 just extracts a small jpeg from the potentially huge CR3 file. There is a lot of code duplication and I'm too lazy to refactor, so for each call of vfs_file_info_is_video in these files, I added another condition to test if the file is a CR3 file. For instance,

#ifdef HAVE_FFMPEG
         ( vfs_file_info_is_video( item->fi ) &&
           time( NULL ) - *vfs_file_info_get_mtime( item->fi ) > 5 ) ||
#endif
             ( item->fi->size < app_settings.max_thumb_size
                                && vfs_file_info_is_image( item->fi ) ) ) )

becomes

#ifdef HAVE_FFMPEG
         ( vfs_file_info_is_video( item->fi ) &&
           time( NULL ) - *vfs_file_info_get_mtime( item->fi ) > 5 ) ||
#endif
             ( item->fi->size < app_settings.max_thumb_size
                                && vfs_file_info_is_image( item->fi ) ) ||
             !strcmp( "image/x-canon-cr3", vfs_mime_type_get_type( item->fi->mime_type ) ) // NEW CONDITION
         ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant