[gthumb] Support all image/x-dcraw sub-types using libraw, and drop dcraw



commit 8ba7652a3bab4765f0e3f2e85aefeef5ec6762ec
Author: Michael J. Chudobiak <mjc avtechpulse com>
Date:   Mon Dec 21 16:20:07 2015 -0500

    Support all image/x-dcraw sub-types using libraw, and drop dcraw

 README                                           |   13 +-
 configure.ac                                     |    7 +-
 extensions/image_viewer/gth-image-viewer-page.c  |   17 +--
 extensions/raw_files/gth-metadata-provider-raw.c |   18 +--
 extensions/raw_files/main.c                      |  251 +++-------------------
 extensions/raw_files/main.h                      |    2 -
 gthumb/glib-utils.c                              |   15 +-
 gthumb/glib-utils.h                              |    1 +
 8 files changed, 51 insertions(+), 273 deletions(-)
---
diff --git a/README b/README
index 0c39e99..4af7c91 100644
--- a/README
+++ b/README
@@ -71,8 +71,8 @@ Compiling
   version 2 or greater, with the development tools installed properly.
   The following is the detailed list of libraries you need:
 
-       * glib                  version >= 2.16.0
-       * gtk                   version >= 2.18.0
+       * glib                  version >= 2.36.0
+       * gtk                   version >= 3.13.2
        * gthread
        * gmodule
        * gio-unix
@@ -84,10 +84,10 @@ Compiling
   While not mandatory, these libraries greatly increase gThumb's
   basic usefulness:
 
-       * exiv2                 version >= 0.18
+       * exiv2                 version >= 0.21
          (embedded metadata support)
 
-       * gstreamer             version >= 0.10
+       * gstreamer             version >= 1.0.0
          (video support)
 
        * libjpeg
@@ -101,13 +101,10 @@ Compiling
        * clutter-gtk           version >= 0.10.0
           (These libraries provide enhanced slideshow effects.)
 
-       * libopenraw            version >= 0.0.8
+       * libraw
           (This adds some support for RAW photos)
 
 
-  If dcraw is present (and is in your executable search path), 
-  gthumb can view full RAW photos.
-
 
 Extensions
 ==========
diff --git a/configure.ac b/configure.ac
index 451f405..9182843 100644
--- a/configure.ac
+++ b/configure.ac
@@ -476,7 +476,7 @@ dnl ===========================================================================
 
 AC_MSG_CHECKING(libraw)
 AC_ARG_ENABLE([libraw],
-             [AS_HELP_STRING([--disable-libraw],[do not use libraw to read raw files (will use dcraw 
directly)])],,
+             [AS_HELP_STRING([--disable-libraw],[do not use libraw - disables raw photo file support])],,
              [enable_libraw=yes])
 
 if test x$enable_libraw = xyes ; then
@@ -485,11 +485,12 @@ if test x$enable_libraw = xyes ; then
                          [enable_libraw=yes],
                          [enable_libraw=no])
        if test "x$enable_libraw" = "xyes"; then
-               AC_DEFINE(HAVE_LIBRAW, 1, [Define to 1 if libraw is used to read raw files instead of dcraw])
+               AC_DEFINE(HAVE_LIBRAW, 1, [Define to 1 if libraw is used to provide raw photo file support])
+
        fi
 fi
 if test x$enable_libraw = xno ; then
-       enable_libraw='no (uses dcraw)'
+       enable_libraw='no'
 fi
 AC_SUBST(LIBRAW_LIBS)
 AC_SUBST(LIBRAW_CFLAGS)
diff --git a/extensions/image_viewer/gth-image-viewer-page.c b/extensions/image_viewer/gth-image-viewer-page.c
index 9618a27..3fdb238 100644
--- a/extensions/image_viewer/gth-image-viewer-page.c
+++ b/extensions/image_viewer/gth-image-viewer-page.c
@@ -265,25 +265,16 @@ _g_mime_type_can_load_different_quality (const char *mime_type)
        static const char *supported[] = {
                "image/jpeg",
                "image/x-portable-pixmap"
-
-               /* RAW formats: to keep in sync with raw_mime_types in extensions/raw_files/main.c */
-
-               "image/x-adobe-dng",
-               "image/x-canon-cr2",
-               "image/x-canon-crw",
-               "image/x-epson-erf",
-               "image/x-minolta-mrw",
-               "image/x-nikon-nef",
-               "image/x-olympus-orf",
-               "image/x-pentax-pef",
-               "image/x-sony-arw"
        };
-       int i;
 
+       int i;
        for (i = 0; i < G_N_ELEMENTS (supported); i++)
                if (g_strcmp0 (mime_type, supported[i]) == 0)
                        return TRUE;
 
+       if (_g_mime_type_is_raw (mime_type))
+               return TRUE;
+
        return FALSE;
 }
 
diff --git a/extensions/raw_files/gth-metadata-provider-raw.c 
b/extensions/raw_files/gth-metadata-provider-raw.c
index c05b58c..77870ba 100644
--- a/extensions/raw_files/gth-metadata-provider-raw.c
+++ b/extensions/raw_files/gth-metadata-provider-raw.c
@@ -44,22 +44,6 @@ gth_metadata_provider_raw_can_read (GthMetadataProvider  *self,
 }
 
 
-static gboolean
-supported_mime_type (GthFileData *file_data)
-{
-       const char *mime_type;
-       int         i;
-
-       mime_type = gth_file_data_get_mime_type (file_data);
-       for (i = 0; raw_mime_types[i] != NULL; i++) {
-               if (g_strcmp0 (raw_mime_types[i], mime_type) == 0)
-                       return TRUE;
-       }
-
-       return FALSE;
-}
-
-
 static void
 gth_metadata_provider_raw_read (GthMetadataProvider *self,
                                GthFileData         *file_data,
@@ -74,7 +58,7 @@ gth_metadata_provider_raw_read (GthMetadataProvider *self,
        char          *size;
        guint          width, height;
 
-       if (! supported_mime_type (file_data))
+       if (!_g_mime_type_is_raw (gth_file_data_get_mime_type (file_data)))
                return;
 
        raw_data = libraw_init (LIBRAW_OPIONS_NO_MEMERR_CALLBACK | LIBRAW_OPIONS_NO_DATAERR_CALLBACK);
diff --git a/extensions/raw_files/main.c b/extensions/raw_files/main.c
index a8713d3..3c1bea4 100644
--- a/extensions/raw_files/main.c
+++ b/extensions/raw_files/main.c
@@ -22,36 +22,19 @@
 
 #include <config.h>
 #include <glib.h>
+#include <gthumb.h>
 #include "main.h"
 
 
-const char *raw_mime_types[] = {
-       "image/x-adobe-dng",
-       "image/x-canon-cr2",
-       "image/x-canon-crw",
-       "image/x-epson-erf",
-       "image/x-minolta-mrw",
-       "image/x-nikon-nef",
-       "image/x-olympus-orf",
-       "image/x-pentax-pef",
-       "image/x-sony-arw",
-       "image/x-fuji-raf",
-       NULL };
-
-
 #ifdef HAVE_LIBRAW
 
 
 #include <cairo.h>
 #include <gtk/gtk.h>
-#include <gthumb.h>
 #include <libraw.h>
 #include "gth-metadata-provider-raw.h"
 
 
-#define RAW_USE_EMBEDDED_THUMBNAIL 1
-
-
 typedef enum {
        RAW_OUTPUT_COLOR_RAW = 0,
        RAW_OUTPUT_COLOR_SRGB = 1,
@@ -184,9 +167,6 @@ _libraw_read_bitmap_data (int     width,
 }
 
 
-#ifdef RAW_USE_EMBEDDED_THUMBNAIL
-
-
 static GthTransform
 _libraw_get_tranform (libraw_data_t *raw_data)
 {
@@ -211,9 +191,6 @@ _libraw_get_tranform (libraw_data_t *raw_data)
 }
 
 
-#endif
-
-
 static int
 _libraw_progress_cb (void                 *callback_data,
                     enum LibRaw_progress  stage,
@@ -267,9 +244,6 @@ _cairo_image_surface_create_from_raw (GInputStream  *istream,
                goto fatal_error;
        }
 
-       /*  */
-
-#if RAW_USE_EMBEDDED_THUMBNAIL
 
        if (requested_size > 0) {
 
@@ -345,12 +319,7 @@ _cairo_image_surface_create_from_raw (GInputStream  *istream,
                        *original_width = raw_data->sizes.iwidth;
                        *original_height = raw_data->sizes.iheight;
                }
-       }
-       else
-
-#endif
-
-       {
+       } else {
                /* read the image */
 
                libraw_processed_image_t *processed_image;
@@ -423,211 +392,49 @@ _cairo_image_surface_create_from_raw (GInputStream  *istream,
 G_MODULE_EXPORT void
 gthumb_extension_activate (void)
 {
-       gth_main_register_metadata_provider (GTH_TYPE_METADATA_PROVIDER_RAW);
-       gth_main_register_image_loader_func_v (_cairo_image_surface_create_from_raw,
-                                              GTH_IMAGE_FORMAT_CAIRO_SURFACE,
-                                              raw_mime_types);
-}
-
-
-#else /* ! HAVE_LIBRAW */
-
-
-#define GDK_PIXBUF_ENABLE_BACKEND
-#include <gtk/gtk.h>
-#include <gthumb.h>
-
-
-static char *
-get_cache_full_path (const char *filename,
-                    const char *extension)
-{
-       char  *name;
-       GFile *file;
-       char  *cache_filename;
-
-       if (extension == NULL)
-               name = g_strdup (filename);
-       else
-               name = g_strconcat (filename, ".", extension, NULL);
-       file = gth_user_dir_get_file_for_write (GTH_DIR_CACHE, GTHUMB_DIR, name, NULL);
-       cache_filename = g_file_get_path (file);
-
-       g_object_unref (file);
-       g_free (name);
-
-       return cache_filename;
-}
-
-
-static time_t
-get_file_mtime (const char *path)
-{
-       GFile  *file;
-       time_t  t;
-
-       file = g_file_new_for_path (path);
-       t = _g_file_get_mtime (file);
-       g_object_unref (file);
-
-       return t;
-}
-
-
-static GthImage *
-dcraw_pixbuf_animation_new_from_file (GInputStream  *istream,
-                                       GthFileData   *file_data,
-                                       int            requested_size,
-                                       int           *original_width,
-                                       int           *original_height,
-                                       gboolean      *loaded_original,
-                                       gpointer       user_data,
-                                       GCancellable  *cancellable,
-                                       GError       **error)
-{
-       GthImage    *image = NULL;
-       GdkPixbuf   *pixbuf;
-       gboolean     is_thumbnail;
-       char        *local_file;
-       char         *local_file_md5;
-       char         *cache_file;
-       char         *cache_file_esc;
-       char         *local_file_esc;
-       char         *command = NULL;
-
-       if (file_data == NULL) {
-               if (error != NULL)
-                       *error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_INVALID_FILENAME, "Could not 
load file");
-               return NULL;
-       }
-
-       is_thumbnail = requested_size > 0;
-
-       /* The output filename, and its persistence, depend on the input file
-        * type, and whether or not a thumbnail has been requested. */
-
-       local_file = g_file_get_path (file_data->file);
-       local_file_md5 = gnome_desktop_thumbnail_md5 (local_file);
-
-       if (!is_thumbnail)
-               /* Full-sized converted RAW file */
-               cache_file = get_cache_full_path (local_file_md5, "conv.pnm");
-       else
-               /* RAW: thumbnails generated in pnm format. The converted file is later removed. */
-               cache_file = get_cache_full_path (local_file_md5, "conv-thumb.pnm");
-
-       g_free (local_file_md5);
-
-       if (cache_file == NULL) {
-               g_free (local_file);
-               return NULL;
-       }
-
-       local_file_esc = g_shell_quote (local_file);
-       cache_file_esc = g_shell_quote (cache_file);
-
-       /* Do nothing if an up-to-date converted file is already in the cache */
-       if (! g_file_test (cache_file, G_FILE_TEST_EXISTS)
-           || (gth_file_data_get_mtime (file_data) > get_file_mtime (cache_file)))
-       {
-               {
-                       if (is_thumbnail) {
-                               char *first_part;
-                               char *jpg_thumbnail;
-                               char *tiff_thumbnail;
-                               char *ppm_thumbnail;
-                               char *thumb_command;
-
-                               thumb_command = g_strdup_printf ("dcraw -e %s", local_file_esc);
-                               g_spawn_command_line_sync (thumb_command, NULL, NULL, NULL, NULL);
-                               g_free (thumb_command);
-
-                               first_part = _g_uri_remove_extension (local_file);
-                               jpg_thumbnail = g_strdup_printf ("%s.thumb.jpg", first_part);
-                               tiff_thumbnail = g_strdup_printf ("%s.thumb.tiff", first_part);
-                               ppm_thumbnail = g_strdup_printf ("%s.thumb.ppm", first_part);
-
-                               if (g_file_test (jpg_thumbnail, G_FILE_TEST_EXISTS)) {
-                                       g_free (cache_file);
-                                       cache_file = g_strdup (jpg_thumbnail);
-                               }
-                               else if (g_file_test (tiff_thumbnail, G_FILE_TEST_EXISTS)) {
-                                       g_free (cache_file);
-                                       cache_file = g_strdup (tiff_thumbnail);
-                               }
-                               else if (g_file_test (ppm_thumbnail, G_FILE_TEST_EXISTS)) {
-                                       g_free (cache_file);
-                                       cache_file = g_strdup (ppm_thumbnail);
-                               }
-                               else {
-                                       /* No embedded thumbnail. Read the whole file. */
-                                       /* Add -h option to speed up thumbnail generation. */
-                                       command = g_strdup_printf ("dcraw -w -c -h %s > %s",
-                                                                  local_file_esc,
-                                                                  cache_file_esc);
-                               }
-
-                               g_free (first_part);
-                               g_free (jpg_thumbnail);
-                               g_free (tiff_thumbnail);
-                               g_free (ppm_thumbnail);
-                       }
-                       else {
-                               /* -w option = camera-specified white balance */
-                               command = g_strdup_printf ("dcraw -w -c %s > %s",
-                                                          local_file_esc,
-                                                          cache_file_esc);
-                       }
-               }
-
-               if (command != NULL) {
-                       if (system (command) == -1) {
-                               g_free (command);
-                               g_free (cache_file_esc);
-                               g_free (local_file_esc);
-                               g_free (cache_file);
-                               g_free (local_file);
-
-                               return NULL;
-                       }
-                       g_free (command);
+       GList *mime_types;
+       mime_types = g_content_types_get_registered ();
+
+       GList *l = mime_types;
+       while (l != NULL) {
+               GList *next = l->next;
+               if (!_g_mime_type_is_raw (l->data)) {
+                       g_free (l->data);
+                       mime_types = g_list_delete_link (mime_types, l);
                }
+               l = next;
        }
 
-       pixbuf = gdk_pixbuf_new_from_file (cache_file, NULL);
+       int count_of_raw_types, i;
+       count_of_raw_types = g_list_length (mime_types);
 
-       /* Thumbnail files are already cached, so delete the conversion cache copies */
-       if (is_thumbnail) {
-               GFile *file;
+       gchar *raw_mime_types[count_of_raw_types];
 
-               file = g_file_new_for_path (cache_file);
-               g_file_delete (file, NULL, NULL);
-               g_object_unref (file);
+       i = 0;
+       l = mime_types;
+       while (l != NULL) {
+               GList *next = l->next;
+               raw_mime_types[i] = (gchar *) l->data;
+               i++;
+               l = next;
        }
 
-       if (pixbuf != NULL) {
-               image = gth_image_new_for_pixbuf (pixbuf);
-               g_object_unref (pixbuf);
-       }
-
-       g_free (cache_file_esc);
-       g_free (local_file_esc);
-       g_free (cache_file);
-       g_free (local_file);
+       gth_main_register_metadata_provider (GTH_TYPE_METADATA_PROVIDER_RAW);
+       gth_main_register_image_loader_func_v (_cairo_image_surface_create_from_raw,
+                                              GTH_IMAGE_FORMAT_CAIRO_SURFACE,
+                                              (const gchar **) raw_mime_types);
 
-       return image;
+       g_list_free_full (mime_types, g_free);
 }
 
 
+#else
+
 G_MODULE_EXPORT void
 gthumb_extension_activate (void)
 {
-       gth_main_register_image_loader_func_v (dcraw_pixbuf_animation_new_from_file,
-                                              GTH_IMAGE_FORMAT_GDK_PIXBUF,
-                                              raw_mime_types);
 }
 
-
 #endif
 
 
diff --git a/extensions/raw_files/main.h b/extensions/raw_files/main.h
index a2a39a7..08eb0cd 100644
--- a/extensions/raw_files/main.h
+++ b/extensions/raw_files/main.h
@@ -25,6 +25,4 @@
 
 #include <config.h>
 
-extern const char *raw_mime_types[];
-
 #endif /* GTH_RAW_FILES_MAIN_H */
diff --git a/gthumb/glib-utils.c b/gthumb/glib-utils.c
index cf63930..daf3fb5 100644
--- a/gthumb/glib-utils.c
+++ b/gthumb/glib-utils.c
@@ -3078,16 +3078,15 @@ gboolean
 _g_mime_type_is_image (const char *mime_type)
 {
        g_return_val_if_fail (mime_type != NULL, FALSE);
+       return (g_content_type_is_a (mime_type, "image/*"));
+}
 
-       /* Valid image mime types:
-               1. All *image* types,
-               2. application/x-crw
-                       This is a RAW photo file, which for some reason
-                       uses an "application" prefix instead of "image".
-       */
 
-       return (g_content_type_is_a (mime_type, "image/*")
-               || (strcmp (mime_type, "application/x-crw") == 0));
+gboolean
+_g_mime_type_is_raw (const char *mime_type)
+{
+        g_return_val_if_fail (mime_type != NULL, FALSE);
+        return (g_content_type_is_a (mime_type, "image/x-dcraw"));
 }
 
 
diff --git a/gthumb/glib-utils.h b/gthumb/glib-utils.h
index 763ca26..484df17 100644
--- a/gthumb/glib-utils.h
+++ b/gthumb/glib-utils.h
@@ -331,6 +331,7 @@ const char *    _g_content_type_get_from_stream  (GInputStream  *istream,
                                                  GCancellable  *cancellable,
                                                  GError       **error);
 gboolean        _g_mime_type_is_image            (const char *mime_type);
+gboolean        _g_mime_type_is_raw              (const char *mime_type);
 gboolean        _g_mime_type_is_video            (const char *mime_type);
 gboolean        _g_mime_type_is_audio            (const char *mime_type);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]