gimp r27595 - in trunk: . app/core app/file



Author: neo
Date: Mon Nov 10 08:21:36 2008
New Revision: 27595
URL: http://svn.gnome.org/viewvc/gimp?rev=27595&view=rev

Log:
2008-11-10  Sven Neumann  <sven gimp org>

	Bug 559725 â Allow to set image-type and image-num-layers for
	thumbnail

	* app/file/file-open.[ch] (file_open_thumbnail): added 
parameters
	for image-type and number of layers. Try to get these from the
	procedure return values. Changes based on a patch from "tks".

	* app/core/gimpimagefile.c (gimp_imagefile_create_thumbnail)
	(gimp_thumbnail_set_info): set image-type and number of layers 
if
	specified.



Modified:
   trunk/ChangeLog
   trunk/app/core/gimpimagefile.c
   trunk/app/file/file-open.c
   trunk/app/file/file-open.h

Modified: trunk/app/core/gimpimagefile.c
==============================================================================
--- trunk/app/core/gimpimagefile.c	(original)
+++ trunk/app/core/gimpimagefile.c	Mon Nov 10 08:21:36 2008
@@ -87,7 +87,9 @@
 static void     gimp_thumbnail_set_info            (GimpThumbnail  *thumbnail,
                                                     const gchar    *mime_type,
                                                     gint            width,
-                                                    gint            height);
+                                                    gint            height,
+                                                    GimpImageType   type,
+                                                    gint            num_layers);
 
 
 G_DEFINE_TYPE (GimpImagefile, gimp_imagefile, GIMP_TYPE_VIEWABLE)
@@ -248,23 +250,27 @@
   if (image_state == GIMP_THUMB_STATE_REMOTE ||
       image_state >= GIMP_THUMB_STATE_EXISTS)
     {
-      GimpImage    *image;
-      gboolean      success;
-      gint          width     = 0;
-      gint          height    = 0;
-      const gchar  *mime_type = NULL;
-      GError       *error     = NULL;
+      GimpImage     *image;
+      gboolean       success;
+      gint           width      = 0;
+      gint           height     = 0;
+      const gchar   *mime_type  = NULL;
+      GError        *error      = NULL;
+      GimpImageType  type       = -1;
+      gint           num_layers = -1;
 
       g_object_ref (imagefile);
 
       image = file_open_thumbnail (imagefile->gimp, context, progress,
                                    thumbnail->image_uri, size,
-                                   &mime_type, &width, &height, NULL);
+                                   &mime_type, &width, &height,
+                                   &type, &num_layers, NULL);
 
       if (image)
         {
           gimp_thumbnail_set_info (imagefile->thumbnail,
-                                   mime_type, width, height);
+                                   mime_type, width, height,
+                                   type, num_layers);
         }
       else
         {
@@ -823,20 +829,52 @@
                 NULL);
 }
 
+/**
+ * gimp_thumbnail_set_info:
+ * @thumbnail: #GimpThumbnail object
+ * @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)
+ * @num_layers: number of layers in the image
+ *              (or -1 if the number of layers is not known)
+ *
+ * Set information about the image associated with the @thumbnail object.
+ */
 static void
 gimp_thumbnail_set_info (GimpThumbnail *thumbnail,
                          const gchar   *mime_type,
                          gint           width,
-                         gint           height)
+                         gint           height,
+                         GimpImageType  type,
+                         gint           num_layers)
 {
   /*  peek the thumbnail to make sure that mtime and filesize are set  */
   gimp_thumbnail_peek_image (thumbnail);
 
   g_object_set (thumbnail,
-                "image-mimetype",   mime_type,
-                "image-width",      width,
-                "image-height",     height,
-                "image-type",       NULL,
-                "image-num-layers", NULL,
+                "image-mimetype", mime_type,
+                "image-width",    width,
+                "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 (num_layers != -1)
+    {
+      g_object_set (thumbnail,
+                    "image-num-layers", num_layers,
+                    NULL);
+    }
 }

Modified: trunk/app/file/file-open.c
==============================================================================
--- trunk/app/file/file-open.c	(original)
+++ trunk/app/file/file-open.c	Mon Nov 10 08:21:36 2008
@@ -41,6 +41,7 @@
 #define R_OK 4
 #endif
 
+#include "libgimpbase/gimpbase.h"
 #include "libgimpconfig/gimpconfig.h"
 
 #include "core/core-types.h"
@@ -205,17 +206,37 @@
   return image;
 }
 
-/*  Attempts to load a thumbnail by using a registered thumbnail loader.  */
+/**
+ * file_open_thumbnail:
+ * @gimp:
+ * @context:
+ * @progress:
+ * @uri:          the URI of the image file
+ * @size:         requested size of the thumbnail
+ * @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)
+ * @num_layers:   return location for number of layers
+ *                (set to -1 if the number of layers is not known)
+ * @error:
+ *
+ * Attempts to load a thumbnail by using a registered thumbnail loader.
+ *
+ * Return value: the thumbnail image
+ */
 GimpImage *
-file_open_thumbnail (Gimp          *gimp,
-                     GimpContext   *context,
-                     GimpProgress  *progress,
-                     const gchar   *uri,
-                     gint           size,
-                     const gchar  **mime_type,
-                     gint          *image_width,
-                     gint          *image_height,
-                     GError       **error)
+file_open_thumbnail (Gimp           *gimp,
+                     GimpContext    *context,
+                     GimpProgress   *progress,
+                     const gchar    *uri,
+                     gint            size,
+                     const gchar   **mime_type,
+                     gint           *image_width,
+                     gint           *image_height,
+                     GimpImageType  *type,
+                     gint           *num_layers,
+                     GError        **error)
 {
   GimpPlugInProcedure *file_proc;
   GimpProcedure       *procedure;
@@ -226,10 +247,14 @@
   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 (num_layers != NULL, NULL);
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
   *image_width  = 0;
   *image_height = 0;
+  *type         = -1;
+  *num_layers   = -1;
 
   file_proc = file_procedure_find (gimp->plug_in_manager->load_procs, uri,
                                    NULL);
@@ -263,16 +288,38 @@
 
       status = g_value_get_enum (&return_vals->values[0]);
 
-      if (status == GIMP_PDB_SUCCESS)
+      if (status == GIMP_PDB_SUCCESS &&
+          GIMP_VALUE_HOLDS_IMAGE_ID (&return_vals->values[1]))
         {
           image = gimp_value_get_image (&return_vals->values[1], gimp);
 
-          if (return_vals->n_values >= 3)
+          if (return_vals->n_values >= 3 &&
+              G_VALUE_HOLDS_INT (&return_vals->values[2]) &&
+              G_VALUE_HOLDS_INT (&return_vals->values[3]))
             {
               *image_width  = MAX (0,
                                    g_value_get_int (&return_vals->values[2]));
               *image_height = MAX (0,
                                    g_value_get_int (&return_vals->values[3]));
+
+              if (return_vals->n_values >= 5 &&
+                  G_VALUE_HOLDS_INT (&return_vals->values[4]))
+                {
+                  gint value = g_value_get_int (&return_vals->values[4]);
+
+                  if (gimp_enum_get_value (GIMP_TYPE_IMAGE_TYPE, value,
+                                           NULL, NULL, NULL, NULL))
+                    {
+                      *type = value;
+                    }
+                }
+
+              if (return_vals->n_values >= 6 &&
+                  G_VALUE_HOLDS_INT (&return_vals->values[5]))
+                {
+                  *num_layers = MAX (0,
+                                     g_value_get_int (&return_vals->values[5]));
+                }
             }
 
           if (image)

Modified: trunk/app/file/file-open.h
==============================================================================
--- trunk/app/file/file-open.h	(original)
+++ trunk/app/file/file-open.h	Mon Nov 10 08:21:36 2008
@@ -42,6 +42,8 @@
                                              const gchar        **mime_type,
                                              gint                *image_width,
                                              gint                *image_height,
+                                             GimpImageType       *type,
+                                             gint                *num_layers,
                                              GError             **error);
 GimpImage * file_open_with_display          (Gimp                *gimp,
                                              GimpContext         *context,



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