Esempio n. 1
0
/**
 * 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,
                     GimpImageType  *type,
                     gint           *num_layers,
                     GError        **error)
{
    GimpPlugInProcedure *file_proc;
    GimpProcedure       *procedure;

    g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
    g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
    g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
    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);

    if (! file_proc || ! file_proc->thumb_loader)
        return NULL;

    procedure = gimp_pdb_lookup_procedure (gimp->pdb, file_proc->thumb_loader);

    if (procedure && procedure->num_args >= 2 && procedure->num_values >= 1)
    {
        GimpPDBStatusType  status;
        GValueArray       *return_vals;
        gchar             *filename;
        GimpImage         *image = NULL;

        filename = file_utils_filename_from_uri (uri);

        if (! filename)
            filename = g_strdup (uri);

        return_vals =
            gimp_pdb_execute_procedure_by_name (gimp->pdb,
                                                context, progress, error,
                                                gimp_object_get_name (procedure),
                                                G_TYPE_STRING,   filename,
                                                GIMP_TYPE_INT32, size,
                                                G_TYPE_NONE);

        g_free (filename);

        status = g_value_get_enum (&return_vals->values[0]);

        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 &&
                    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)
            {
                file_open_sanitize_image (image, FALSE);

                *mime_type = file_proc->mime_type;

#ifdef GIMP_UNSTABLE
                g_printerr ("opened thumbnail at %d x %d\n",
                            gimp_image_get_width  (image),
                            gimp_image_get_height (image));
#endif
            }
        }

        g_value_array_free (return_vals);

        return image;
    }

    return NULL;
}
Esempio n. 2
0
/**
 * file_open_thumbnail:
 * @gimp:
 * @context:
 * @progress:
 * @file:         an 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
 * @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:
 *
 * 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,
                     GFile          *file,
                     gint            size,
                     const gchar   **mime_type,
                     gint           *image_width,
                     gint           *image_height,
                     const Babl    **format,
                     gint           *num_layers,
                     GError        **error)
{
  GimpPlugInProcedure *file_proc;
  GimpProcedure       *procedure;

  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
  g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
  g_return_val_if_fail (G_IS_FILE (file), NULL);
  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 (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;
  *format       = NULL;
  *num_layers   = -1;

  file_proc = file_procedure_find (gimp->plug_in_manager->load_procs, file,
                                   NULL);

  if (! file_proc || ! file_proc->thumb_loader)
    return NULL;

  procedure = gimp_pdb_lookup_procedure (gimp->pdb, file_proc->thumb_loader);

  if (procedure && procedure->num_args >= 2 && procedure->num_values >= 1)
    {
      GimpPDBStatusType  status;
      GimpValueArray    *return_vals;
      GimpImage         *image = NULL;
      gchar             *path  = NULL;

      if (! file_proc->handles_uri)
        path = g_file_get_path (file);

      if (! path)
        path = g_file_get_uri (file);

      return_vals =
        gimp_pdb_execute_procedure_by_name (gimp->pdb,
                                            context, progress, error,
                                            gimp_object_get_name (procedure),
                                            G_TYPE_STRING,   path,
                                            GIMP_TYPE_INT32, size,
                                            G_TYPE_NONE);

      g_free (path);

      status = g_value_get_enum (gimp_value_array_index (return_vals, 0));

      if (status == GIMP_PDB_SUCCESS &&
          GIMP_VALUE_HOLDS_IMAGE_ID (gimp_value_array_index (return_vals, 1)))
        {
          image = gimp_value_get_image (gimp_value_array_index (return_vals, 1),
                                        gimp);

          if (gimp_value_array_length (return_vals) >= 3 &&
              G_VALUE_HOLDS_INT (gimp_value_array_index (return_vals, 2)) &&
              G_VALUE_HOLDS_INT (gimp_value_array_index (return_vals, 3)))
            {
              *image_width =
                MAX (0, g_value_get_int (gimp_value_array_index (return_vals, 2)));

              *image_height =
                MAX (0, g_value_get_int (gimp_value_array_index (return_vals, 3)));

              if (gimp_value_array_length (return_vals) >= 5 &&
                  G_VALUE_HOLDS_INT (gimp_value_array_index (return_vals, 4)))
                {
                  gint value = g_value_get_int (gimp_value_array_index (return_vals, 4));

                  switch (value)
                    {
                    case GIMP_RGB_IMAGE:
                      *format = gimp_babl_format (GIMP_RGB,
                                                  GIMP_PRECISION_U8_GAMMA,
                                                  FALSE);
                      break;

                    case GIMP_RGBA_IMAGE:
                      *format = gimp_babl_format (GIMP_RGB,
                                                  GIMP_PRECISION_U8_GAMMA,
                                                  TRUE);
                      break;

                    case GIMP_GRAY_IMAGE:
                      *format = gimp_babl_format (GIMP_GRAY,
                                                  GIMP_PRECISION_U8_GAMMA,
                                                  FALSE);
                      break;

                    case GIMP_GRAYA_IMAGE:
                      *format = gimp_babl_format (GIMP_GRAY,
                                                  GIMP_PRECISION_U8_GAMMA,
                                                  TRUE);
                      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;
                    }
                }

              if (gimp_value_array_length (return_vals) >= 6 &&
                  G_VALUE_HOLDS_INT (gimp_value_array_index (return_vals, 5)))
                {
                  *num_layers =
                    MAX (0, g_value_get_int (gimp_value_array_index (return_vals, 5)));
                }
            }

          if (image)
            {
              file_open_sanitize_image (image, FALSE);

              *mime_type = file_proc->mime_type;

#ifdef GIMP_UNSTABLE
              g_printerr ("opened thumbnail at %d x %d\n",
                          gimp_image_get_width  (image),
                          gimp_image_get_height (image));
#endif
            }
        }

      gimp_value_array_unref (return_vals);

      return image;
    }

  return NULL;
}
Esempio n. 3
0
static GimpValueArray *
file_load_invoker (GimpProcedure         *procedure,
                   Gimp                  *gimp,
                   GimpContext           *context,
                   GimpProgress          *progress,
                   const GimpValueArray  *args,
                   GError               **error)
{
  GimpValueArray      *new_args;
  GimpValueArray      *return_vals;
  GimpPlugInProcedure *file_proc;
  GimpProcedure       *proc;
  gchar               *uri;
  gint                 i;

  uri = file_utils_filename_to_uri (gimp,
                                    g_value_get_string (gimp_value_array_index (args, 1)),
                                    error);

  if (! uri)
    return gimp_procedure_get_return_values (procedure, FALSE,
                                             error ? *error : NULL);

  file_proc =
    file_procedure_find (gimp->plug_in_manager->load_procs, uri, error);

  g_free (uri);

  if (! file_proc)
    return gimp_procedure_get_return_values (procedure, FALSE,
                                             error ? *error : NULL);

  proc = GIMP_PROCEDURE (file_proc);

  new_args = gimp_procedure_get_arguments (proc);

  for (i = 0; i < 3; i++)
    g_value_transform (gimp_value_array_index (args, i),
                       gimp_value_array_index (new_args, i));

  for (i = 3; i < proc->num_args; i++)
    if (G_IS_PARAM_SPEC_STRING (proc->args[i]))
      g_value_set_static_string (gimp_value_array_index (new_args, i), "");

  return_vals =
    gimp_pdb_execute_procedure_by_name_args (gimp->pdb,
                                             context, progress, error,
                                             gimp_object_get_name (proc),
                                             new_args);

  gimp_value_array_unref (new_args);

  if (g_value_get_enum (gimp_value_array_index (return_vals, 0)) ==
      GIMP_PDB_SUCCESS)
    {
      if (gimp_value_array_length (return_vals) > 1 &&
          GIMP_VALUE_HOLDS_IMAGE_ID (gimp_value_array_index (return_vals, 1)))
        {
          GimpImage *image =
            gimp_value_get_image (gimp_value_array_index (return_vals, 1),
                                  gimp);
          gimp_image_set_load_proc (image, file_proc);
        }
    }

  return return_vals;
}