~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/plug-in/plug-in-icc-profile.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GIMP - The GNU Image Manipulation Program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * plug-in-icc-profile.c
 
5
 * Copyright (C) 2006  Sven Neumann <sven@gimp.org>
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; either version 2 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program; if not, write to the Free Software
 
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
20
 */
 
21
 
 
22
#include "config.h"
 
23
 
 
24
#include <glib-object.h>
 
25
 
 
26
#include "core/core-types.h"
 
27
 
 
28
#include "core/gimp.h"
 
29
#include "core/gimpcontext.h"
 
30
#include "core/gimpimage.h"
 
31
#include "core/gimpparamspecs.h"
 
32
#include "core/gimpprogress.h"
 
33
 
 
34
#include "pdb/gimppdb.h"
 
35
#include "pdb/gimpprocedure.h"
 
36
 
 
37
#include "plug-in-icc-profile.h"
 
38
 
 
39
#include "gimp-intl.h"
 
40
 
 
41
 
 
42
#define ICC_PROFILE_APPLY_RGB_PROC  "plug-in-icc-profile-apply-rgb"
 
43
#define ICC_PROFILE_INFO_PROC       "plug-in-icc-profile-info"
 
44
#define ICC_PROFILE_FILE_INFO_PROC  "plug-in-icc-profile-file-info"
 
45
 
 
46
 
 
47
static void
 
48
plug_in_icc_profile_info_return (GValueArray  *return_vals,
 
49
                                 gchar       **name,
 
50
                                 gchar       **desc,
 
51
                                 gchar       **info);
 
52
 
 
53
 
 
54
gboolean
 
55
plug_in_icc_profile_apply_rgb (GimpImage     *image,
 
56
                               GimpContext   *context,
 
57
                               GimpProgress  *progress,
 
58
                               GimpRunMode    run_mode,
 
59
                               GError       **error)
 
60
{
 
61
  Gimp          *gimp = image->gimp;
 
62
  GimpProcedure *procedure;
 
63
 
 
64
  if (gimp_image_base_type (image) == GIMP_GRAY)
 
65
    return FALSE;
 
66
 
 
67
  procedure = gimp_pdb_lookup_procedure (gimp->pdb, ICC_PROFILE_APPLY_RGB_PROC);
 
68
 
 
69
  if (procedure &&
 
70
      procedure->num_args >= 2 &&
 
71
      GIMP_IS_PARAM_SPEC_INT32 (procedure->args[0]) &&
 
72
      GIMP_IS_PARAM_SPEC_IMAGE_ID (procedure->args[1]))
 
73
    {
 
74
      GValueArray            *return_vals;
 
75
      GimpPDBStatusType       status;
 
76
      GimpColorProfilePolicy  policy = GIMP_COLOR_PROFILE_POLICY_ASK;
 
77
      gboolean                success;
 
78
 
 
79
      return_vals =
 
80
        gimp_pdb_execute_procedure_by_name (gimp->pdb, context, progress,
 
81
                                            ICC_PROFILE_APPLY_RGB_PROC,
 
82
                                            GIMP_TYPE_INT32, run_mode,
 
83
                                            GIMP_TYPE_IMAGE_ID,
 
84
                                            gimp_image_get_ID (image),
 
85
                                            G_TYPE_NONE);
 
86
 
 
87
      status = g_value_get_enum (return_vals->values);
 
88
 
 
89
      switch (status)
 
90
        {
 
91
        case GIMP_PDB_SUCCESS:
 
92
          policy = GIMP_COLOR_PROFILE_POLICY_CONVERT;
 
93
          success = TRUE;
 
94
          break;
 
95
 
 
96
        case GIMP_PDB_CANCEL:
 
97
          policy = GIMP_COLOR_PROFILE_POLICY_KEEP;
 
98
          success = TRUE;
 
99
          break;
 
100
 
 
101
        default:
 
102
          g_set_error (error, 0, 0,
 
103
                       _("Error running '%s'"), ICC_PROFILE_APPLY_RGB_PROC);
 
104
          success = FALSE;
 
105
          break;
 
106
        }
 
107
 
 
108
      if (success && return_vals->n_values > 1)
 
109
        {
 
110
          GValue *value = g_value_array_get_nth (return_vals, 1);
 
111
 
 
112
          if (GIMP_VALUE_HOLDS_INT32 (value) && g_value_get_int (value))
 
113
            {
 
114
              g_object_set (G_OBJECT (gimp->config),
 
115
                            "color-profile-policy", policy,
 
116
                            NULL);
 
117
            }
 
118
        }
 
119
 
 
120
      g_value_array_free (return_vals);
 
121
 
 
122
      return success;
 
123
    }
 
124
 
 
125
  g_set_error (error, 0, 0,
 
126
               _("Plug-In missing (%s)"), ICC_PROFILE_APPLY_RGB_PROC);
 
127
 
 
128
  return FALSE;
 
129
}
 
130
 
 
131
gboolean
 
132
plug_in_icc_profile_info (GimpImage     *image,
 
133
                          GimpContext   *context,
 
134
                          GimpProgress  *progress,
 
135
                          gchar        **name,
 
136
                          gchar        **desc,
 
137
                          gchar        **info,
 
138
                          GError       **error)
 
139
{
 
140
  Gimp          *gimp = image->gimp;
 
141
  GimpProcedure *procedure;
 
142
 
 
143
  procedure = gimp_pdb_lookup_procedure (gimp->pdb, ICC_PROFILE_INFO_PROC);
 
144
 
 
145
  if (procedure &&
 
146
      procedure->num_args >= 1 &&
 
147
      GIMP_IS_PARAM_SPEC_IMAGE_ID (procedure->args[0]))
 
148
    {
 
149
      GValueArray       *return_vals;
 
150
      GimpPDBStatusType  status;
 
151
 
 
152
      return_vals =
 
153
        gimp_pdb_execute_procedure_by_name (gimp->pdb, context, progress,
 
154
                                            ICC_PROFILE_INFO_PROC,
 
155
                                            GIMP_TYPE_IMAGE_ID,
 
156
                                            gimp_image_get_ID (image),
 
157
                                            G_TYPE_NONE);
 
158
 
 
159
      status = g_value_get_enum (return_vals->values);
 
160
 
 
161
      switch (status)
 
162
        {
 
163
        case GIMP_PDB_SUCCESS:
 
164
          plug_in_icc_profile_info_return (return_vals, name, desc, info);
 
165
          break;
 
166
 
 
167
        default:
 
168
          g_set_error (error, 0, 0,
 
169
                       _("Error running '%s'"), ICC_PROFILE_INFO_PROC);
 
170
          break;
 
171
        }
 
172
 
 
173
      g_value_array_free (return_vals);
 
174
 
 
175
      return (status == GIMP_PDB_SUCCESS);
 
176
    }
 
177
 
 
178
  g_set_error (error, 0, 0,
 
179
               _("Plug-In missing (%s)"), ICC_PROFILE_INFO_PROC);
 
180
 
 
181
  return FALSE;
 
182
}
 
183
 
 
184
gboolean
 
185
plug_in_icc_profile_file_info (Gimp          *gimp,
 
186
                               GimpContext   *context,
 
187
                               GimpProgress  *progress,
 
188
                               const gchar   *filename,
 
189
                               gchar        **name,
 
190
                               gchar        **desc,
 
191
                               gchar        **info,
 
192
                               GError       **error)
 
193
{
 
194
  GimpProcedure *procedure;
 
195
 
 
196
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
 
197
  g_return_val_if_fail (filename != NULL, FALSE);
 
198
 
 
199
  procedure = gimp_pdb_lookup_procedure (gimp->pdb, ICC_PROFILE_FILE_INFO_PROC);
 
200
 
 
201
  if (procedure &&
 
202
      procedure->num_args >= 1 &&
 
203
      GIMP_IS_PARAM_SPEC_STRING (procedure->args[0]))
 
204
    {
 
205
      GValueArray       *return_vals;
 
206
      GimpPDBStatusType  status;
 
207
 
 
208
      return_vals =
 
209
        gimp_pdb_execute_procedure_by_name (gimp->pdb, context, progress,
 
210
                                            ICC_PROFILE_FILE_INFO_PROC,
 
211
                                            G_TYPE_STRING, filename,
 
212
                                            G_TYPE_NONE);
 
213
 
 
214
      status = g_value_get_enum (return_vals->values);
 
215
 
 
216
      switch (status)
 
217
        {
 
218
        case GIMP_PDB_SUCCESS:
 
219
          plug_in_icc_profile_info_return (return_vals, name, desc, info);
 
220
          break;
 
221
 
 
222
        default:
 
223
          g_set_error (error, 0, 0,
 
224
                       _("Error running '%s'"), ICC_PROFILE_FILE_INFO_PROC);
 
225
          break;
 
226
        }
 
227
 
 
228
      g_value_array_free (return_vals);
 
229
 
 
230
      return (status == GIMP_PDB_SUCCESS);
 
231
    }
 
232
 
 
233
  g_set_error (error, 0, 0,
 
234
               _("Plug-In missing (%s)"), ICC_PROFILE_FILE_INFO_PROC);
 
235
 
 
236
  return FALSE;
 
237
}
 
238
 
 
239
static void
 
240
plug_in_icc_profile_info_return (GValueArray  *return_vals,
 
241
                                 gchar       **name,
 
242
                                 gchar       **desc,
 
243
                                 gchar       **info)
 
244
{
 
245
  if (name)
 
246
    {
 
247
      GValue *value = g_value_array_get_nth (return_vals, 1);
 
248
 
 
249
      *name = G_VALUE_HOLDS_STRING (value) ? g_value_dup_string (value) : NULL;
 
250
    }
 
251
 
 
252
  if (desc)
 
253
    {
 
254
      GValue *value = g_value_array_get_nth (return_vals, 2);
 
255
 
 
256
      *desc = G_VALUE_HOLDS_STRING (value) ? g_value_dup_string (value) : NULL;
 
257
    }
 
258
 
 
259
  if (info)
 
260
    {
 
261
      GValue *value = g_value_array_get_nth (return_vals, 3);
 
262
 
 
263
      *info = G_VALUE_HOLDS_STRING (value) ? g_value_dup_string (value) : NULL;
 
264
    }
 
265
}