[gimp/goat-invasion] app: return a format, not image type from file_open_thumbnail()



commit e12d5c98de74fe579433a93d1325101800629cdd
Author: Michael Natterer <mitch gimp org>
Date:   Wed Apr 11 21:54:23 2012 +0200

    app: return a format, not image type from file_open_thumbnail()
    
    create a dummy indexed format if neccessary, which can only be used
    for checking with babl_format_is_palette(). Port the rest of
    GimpImageFile from GimpImageType to Babl*.

 app/core/gimpimagefile.c  |   36 ++++++++++++----------------------
 app/file/file-open.c      |   46 ++++++++++++++++++++++++++++++++++++++------
 app/file/file-open.h      |    2 +-
 app/gui/gimpdbusservice.c |    1 +
 4 files changed, 54 insertions(+), 31 deletions(-)
---
diff --git a/app/core/gimpimagefile.c b/app/core/gimpimagefile.c
index 536921f..bb60713 100644
--- a/app/core/gimpimagefile.c
+++ b/app/core/gimpimagefile.c
@@ -114,7 +114,7 @@ static void     gimp_thumbnail_set_info            (GimpThumbnail  *thumbnail,
                                                     const gchar    *mime_type,
                                                     gint            width,
                                                     gint            height,
-                                                    GimpImageType   type,
+                                                    const Babl     *format,
                                                     gint            num_layers);
 
 
@@ -353,7 +353,7 @@ gimp_imagefile_create_thumbnail (GimpImagefile *imagefile,
       gint           height     = 0;
       const gchar   *mime_type  = NULL;
       GError        *error      = NULL;
-      GimpImageType  type       = -1;
+      const Babl    *format     = NULL;
       gint           num_layers = -1;
 
       g_object_ref (imagefile);
@@ -361,13 +361,13 @@ gimp_imagefile_create_thumbnail (GimpImagefile *imagefile,
       image = file_open_thumbnail (private->gimp, context, progress,
                                    thumbnail->image_uri, size,
                                    &mime_type, &width, &height,
-                                   &type, &num_layers, NULL);
+                                   &format, &num_layers, NULL);
 
       if (image)
         {
           gimp_thumbnail_set_info (private->thumbnail,
                                    mime_type, width, height,
-                                   type, num_layers);
+                                   format, num_layers);
         }
       else
         {
@@ -997,7 +997,7 @@ gimp_thumbnail_set_info_from_image (GimpThumbnail *thumbnail,
  * @mime_type:  MIME type of the image associated with this thumbnail
  * @width:      width of the image associated with this thumbnail
  * @height:     height of the image associated with this thumbnail
- * @type:       type of the image (or -1 if the type is not known)
+ * @format:     format of the image (or NULL if the type is not known)
  * @num_layers: number of layers in the image
  *              (or -1 if the number of layers is not known)
  *
@@ -1008,7 +1008,7 @@ gimp_thumbnail_set_info (GimpThumbnail *thumbnail,
                          const gchar   *mime_type,
                          gint           width,
                          gint           height,
-                         GimpImageType  type,
+                         const Babl    *format,
                          gint           num_layers)
 {
   /*  peek the thumbnail to make sure that mtime and filesize are set  */
@@ -1020,23 +1020,13 @@ gimp_thumbnail_set_info (GimpThumbnail *thumbnail,
                 "image-height",   height,
                 NULL);
 
-  if (type != -1)
-    {
-      GimpEnumDesc *desc;
-
-      desc = gimp_enum_get_desc (g_type_class_peek (GIMP_TYPE_IMAGE_TYPE),
-                                 type);
-
-      if (desc)
-        g_object_set (thumbnail,
-                      "image-type", desc->value_desc,
-                      NULL);
-    }
+  if (format)
+    g_object_set (thumbnail,
+                  "image-type", gimp_babl_get_description (format),
+                  NULL);
 
   if (num_layers != -1)
-    {
-      g_object_set (thumbnail,
-                    "image-num-layers", num_layers,
-                    NULL);
-    }
+    g_object_set (thumbnail,
+                  "image-num-layers", num_layers,
+                  NULL);
 }
diff --git a/app/file/file-open.c b/app/file/file-open.c
index c192777..37d042d 100644
--- a/app/file/file-open.c
+++ b/app/file/file-open.c
@@ -229,7 +229,7 @@ file_open_image (Gimp                *gimp,
  * @mime_type:    return location for image MIME type
  * @image_width:  return location for image width
  * @image_height: return location for image height
- * @type:         return location for image type (set to -1 if unknown)
+ * @format:       return location for image format (set to NULL if unknown)
  * @num_layers:   return location for number of layers
  *                (set to -1 if the number of layers is not known)
  * @error:
@@ -247,7 +247,7 @@ file_open_thumbnail (Gimp           *gimp,
                      const gchar   **mime_type,
                      gint           *image_width,
                      gint           *image_height,
-                     GimpImageType  *type,
+                     const Babl    **format,
                      gint           *num_layers,
                      GError        **error)
 {
@@ -260,13 +260,13 @@ file_open_thumbnail (Gimp           *gimp,
   g_return_val_if_fail (mime_type != NULL, NULL);
   g_return_val_if_fail (image_width != NULL, NULL);
   g_return_val_if_fail (image_height != NULL, NULL);
-  g_return_val_if_fail (type != NULL, NULL);
+  g_return_val_if_fail (format != NULL, NULL);
   g_return_val_if_fail (num_layers != NULL, NULL);
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
   *image_width  = 0;
   *image_height = 0;
-  *type         = -1;
+  *format       = NULL;
   *num_layers   = -1;
 
   file_proc = file_procedure_find (gimp->plug_in_manager->load_procs, uri,
@@ -320,10 +320,42 @@ file_open_thumbnail (Gimp           *gimp,
                 {
                   gint value = g_value_get_int (&return_vals->values[4]);
 
-                  if (gimp_enum_get_value (GIMP_TYPE_IMAGE_TYPE, value,
-                                           NULL, NULL, NULL, NULL))
+                  switch (value)
                     {
-                      *type = value;
+                    case GIMP_RGB_IMAGE:
+                      *format = babl_format ("R'G'B' u8");
+                      break;
+
+                    case GIMP_RGBA_IMAGE:
+                      *format = babl_format ("R'G'B'A u8");
+                      break;
+
+                    case GIMP_GRAY_IMAGE:
+                      *format = babl_format ("Y' u8");
+                      break;
+
+                    case GIMP_GRAYA_IMAGE:
+                      *format = babl_format ("Y'A u8");
+                      break;
+
+                    case GIMP_INDEXED_IMAGE:
+                    case GIMP_INDEXEDA_IMAGE:
+                      {
+                        const Babl *rgb;
+                        const Babl *rgba;
+
+                        babl_new_palette ("-gimp-indexed-format-dummy",
+                                          &rgb, &rgba);
+
+                        if (value == GIMP_INDEXED_IMAGE)
+                          *format = rgb;
+                        else
+                          *format = rgba;
+                      }
+                      break;
+
+                    default:
+                      break;
                     }
                 }
 
diff --git a/app/file/file-open.h b/app/file/file-open.h
index fe54d2e..d6651ba 100644
--- a/app/file/file-open.h
+++ b/app/file/file-open.h
@@ -41,7 +41,7 @@ GimpImage * file_open_thumbnail             (Gimp                *gimp,
                                              const gchar        **mime_type,
                                              gint                *image_width,
                                              gint                *image_height,
-                                             GimpImageType       *type,
+                                             const Babl         **format,
                                              gint                *num_layers,
                                              GError             **error);
 GimpImage * file_open_with_display          (Gimp                *gimp,
diff --git a/app/gui/gimpdbusservice.c b/app/gui/gimpdbusservice.c
index 67bf6f9..771664d 100644
--- a/app/gui/gimpdbusservice.c
+++ b/app/gui/gimpdbusservice.c
@@ -22,6 +22,7 @@
 
 #if HAVE_DBUS_GLIB
 
+#include <gegl.h>
 #include <gtk/gtk.h>
 #include <dbus/dbus-glib.h>
 



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