FIXME: this can be rather slow and blocks until the size is known
authorColin Clark <colin.clark@cclark.uk>
Thu, 8 Dec 2022 15:59:27 +0000 (15:59 +0000)
committerColin Clark <colin.clark@cclark.uk>
Thu, 8 Dec 2022 15:59:27 +0000 (15:59 +0000)
Instead of using image_loader() use gdk_pixbuf_get_file_info() to get
image size - this function reads only a small part of the file.

src/image-load.cc

index fd75cc8..8516ef2 100644 (file)
@@ -1438,32 +1438,27 @@ const gchar *image_loader_get_error(ImageLoader *il)
        return ret;
 }
 
-
-/**
- *  @FIXME this can be rather slow and blocks until the size is known
- */
 gboolean image_load_dimensions(FileData *fd, gint *width, gint *height)
 {
-       ImageLoader *il;
        gboolean success;
+       gint width_file = 0;
+       gint height_file = 0;
 
-       il = image_loader_new(fd);
+       gdk_pixbuf_get_file_info(fd->path, &width_file, &height_file);
 
-       success = image_loader_start_idle(il);
-
-       if (success && il->pixbuf)
+       if (width_file && height_file)
                {
-               if (width) *width = gdk_pixbuf_get_width(il->pixbuf);
-               if (height) *height = gdk_pixbuf_get_height(il->pixbuf);;
+               *width = width_file;
+               *height = height_file;
+               success = TRUE;
                }
        else
                {
-               if (width) *width = -1;
-               if (height) *height = -1;
+               *width = -1;
+               *height = -1;
+               success = FALSE;
                }
 
-       image_loader_free(il);
-
        return success;
 }
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */