display-filter-proof.c 11.2 KB
Newer Older
1
/* GIMP - The GNU Image Manipulation Program
2 3
 * Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7 8 9 10 11 12 13 14
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 17 18 19
 */

#include "config.h"

20
#include <gegl.h>
21 22
#include <gtk/gtk.h>

23
#include "libgimpbase/gimpbase.h"
24
#include "libgimpcolor/gimpcolor.h"
25 26
#include "libgimpconfig/gimpconfig.h"
#include "libgimpmath/gimpmath.h"
27 28 29 30 31
#include "libgimpmodule/gimpmodule.h"
#include "libgimpwidgets/gimpwidgets.h"

#include "libgimp/libgimp-intl.h"

32
#define CDISPLAY_TYPE_PROOF            (cdisplay_proof_get_type ())
33 34 35 36 37 38
#define CDISPLAY_PROOF(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), CDISPLAY_TYPE_PROOF, CdisplayProof))
#define CDISPLAY_PROOF_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), CDISPLAY_TYPE_PROOF, CdisplayProofClass))
#define CDISPLAY_IS_PROOF(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CDISPLAY_TYPE_PROOF))
#define CDISPLAY_IS_PROOF_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CDISPLAY_TYPE_PROOF))


39
typedef struct _CdisplayProof      CdisplayProof;
40 41 42 43
typedef struct _CdisplayProofClass CdisplayProofClass;

struct _CdisplayProof
{
44
  GimpColorDisplay    parent_instance;
45

46 47 48
  gint                intent;
  gboolean            bpc;
  gchar              *profile;
49

50
  GimpColorTransform *transform;
51 52 53 54 55 56 57 58
};

struct _CdisplayProofClass
{
  GimpColorDisplayClass parent_instance;
};


59 60 61 62 63 64 65 66 67
enum
{
  PROP_0,
  PROP_INTENT,
  PROP_BPC,
  PROP_PROFILE
};


68
static GType       cdisplay_proof_get_type        (void);
69

70 71 72 73 74 75 76 77 78
static void        cdisplay_proof_finalize        (GObject          *object);
static void        cdisplay_proof_get_property    (GObject          *object,
                                                   guint             property_id,
                                                   GValue           *value,
                                                   GParamSpec       *pspec);
static void        cdisplay_proof_set_property    (GObject          *object,
                                                   guint             property_id,
                                                   const GValue     *value,
                                                   GParamSpec       *pspec);
79

80

81 82 83
static void        cdisplay_proof_convert_buffer  (GimpColorDisplay *display,
                                                   GeglBuffer       *buffer,
                                                   GeglRectangle    *area);
84 85
static GtkWidget * cdisplay_proof_configure       (GimpColorDisplay *display);
static void        cdisplay_proof_changed         (GimpColorDisplay *display);
86 87 88 89 90 91 92 93 94 95 96 97


static const GimpModuleInfo cdisplay_proof_info =
{
  GIMP_MODULE_ABI_VERSION,
  N_("Color proof filter using ICC color profile"),
  "Banlu Kemiyatorn <id@project-ile.net>",
  "v0.1",
  "(c) 2002-2003, released under the GPL",
  "November 14, 2003"
};

98

99 100
G_DEFINE_DYNAMIC_TYPE (CdisplayProof, cdisplay_proof,
                       GIMP_TYPE_COLOR_DISPLAY)
101

102

103 104 105 106 107 108 109 110 111
G_MODULE_EXPORT const GimpModuleInfo *
gimp_module_query (GTypeModule *module)
{
  return &cdisplay_proof_info;
}

G_MODULE_EXPORT gboolean
gimp_module_register (GTypeModule *module)
{
112
  cdisplay_proof_register_type (module);
113 114 115 116 117 118 119

  return TRUE;
}

static void
cdisplay_proof_class_init (CdisplayProofClass *klass)
{
120 121
  GObjectClass          *object_class  = G_OBJECT_CLASS (klass);
  GimpColorDisplayClass *display_class = GIMP_COLOR_DISPLAY_CLASS (klass);
122

123 124 125
  object_class->finalize         = cdisplay_proof_finalize;
  object_class->get_property     = cdisplay_proof_get_property;
  object_class->set_property     = cdisplay_proof_set_property;
126

127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
  GIMP_CONFIG_PROP_ENUM (object_class, PROP_INTENT,
                         "intent",
                         _("Intent"),
                         NULL,
                         GIMP_TYPE_COLOR_RENDERING_INTENT,
                         GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL,
                         0);

  GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_BPC,
                            "black-point-compensation",
                            _("Black point compensation"),
                            NULL,
                            FALSE,
                            0);

  GIMP_CONFIG_PROP_PATH (object_class, PROP_PROFILE,
                         "profile",
                         _("Profile"),
                         NULL,
                         GIMP_CONFIG_PATH_FILE, NULL,
                         0);
148

149 150
  display_class->name            = _("Color Proof");
  display_class->help_id         = "gimp-colordisplay-proof";
151
  display_class->icon_name       = GIMP_STOCK_DISPLAY_FILTER_PROOF;
152

153
  display_class->convert_buffer  = cdisplay_proof_convert_buffer;
154 155
  display_class->configure       = cdisplay_proof_configure;
  display_class->changed         = cdisplay_proof_changed;
156 157
}

158 159 160 161 162
static void
cdisplay_proof_class_finalize (CdisplayProofClass *klass)
{
}

163 164 165 166
static void
cdisplay_proof_init (CdisplayProof *proof)
{
  proof->transform = NULL;
167
  proof->profile   = NULL;
168 169 170 171 172 173 174
}

static void
cdisplay_proof_finalize (GObject *object)
{
  CdisplayProof *proof = CDISPLAY_PROOF (object);

175
  if (proof->profile)
176
    {
177 178
      g_free (proof->profile);
      proof->profile = NULL;
179
    }
180

181 182
  if (proof->transform)
    {
183
      g_object_unref (proof->transform);
184 185 186
      proof->transform = NULL;
    }

187
  G_OBJECT_CLASS (cdisplay_proof_parent_class)->finalize (object);
188 189
}

190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
static void
cdisplay_proof_get_property (GObject    *object,
                             guint       property_id,
                             GValue     *value,
                             GParamSpec *pspec)
{
  CdisplayProof *proof = CDISPLAY_PROOF (object);

  switch (property_id)
    {
    case PROP_INTENT:
      g_value_set_enum (value, proof->intent);
      break;
    case PROP_BPC:
      g_value_set_boolean (value, proof->bpc);
      break;
    case PROP_PROFILE:
      g_value_set_string (value, proof->profile);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
}

static void
cdisplay_proof_set_property (GObject      *object,
                             guint         property_id,
                             const GValue *value,
                             GParamSpec   *pspec)
{
  CdisplayProof *proof = CDISPLAY_PROOF (object);

  switch (property_id)
    {
    case PROP_INTENT:
      proof->intent = g_value_get_enum (value);
      break;
    case PROP_BPC:
      proof->bpc = g_value_get_boolean (value);
      break;
    case PROP_PROFILE:
      g_free (proof->profile);
      proof->profile = g_value_dup_string (value);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }

  gimp_color_display_changed (GIMP_COLOR_DISPLAY (proof));
}

243
static void
244 245 246
cdisplay_proof_convert_buffer (GimpColorDisplay *display,
                               GeglBuffer       *buffer,
                               GeglRectangle    *area)
247
{
248
  CdisplayProof *proof = CDISPLAY_PROOF (display);
249

250 251 252 253
  if (proof->transform)
    gimp_color_transform_process_buffer (proof->transform,
                                         buffer, area,
                                         buffer, area);
254 255
}

256 257 258 259
static void
cdisplay_proof_profile_changed (GtkWidget     *combo,
                                CdisplayProof *proof)
{
260 261
  GFile *file;
  gchar *path = NULL;
262

263 264 265 266
  file = gimp_color_profile_combo_box_get_active_file (GIMP_COLOR_PROFILE_COMBO_BOX (combo));

  if (file)
    {
267
      path = gimp_file_get_config_path (file, NULL);
268 269
      g_object_unref (file);
    }
270 271

  g_object_set (proof,
272
                "profile", path,
273 274
                NULL);

275
  g_free (path);
276 277
}

278 279 280
static GtkWidget *
cdisplay_proof_configure (GimpColorDisplay *display)
{
281
  CdisplayProof *proof = CDISPLAY_PROOF (display);
282
  GtkWidget     *table;
283 284
  GtkWidget     *combo;
  GtkWidget     *toggle;
285 286
  GtkWidget     *dialog;
  gchar         *history;
287

288 289 290
  table = gtk_table_new (3, 2, FALSE);
  gtk_table_set_col_spacings (GTK_TABLE (table), 6);
  gtk_table_set_row_spacings (GTK_TABLE (table), 6);
291

292 293 294
  dialog = gimp_color_profile_chooser_dialog_new (_("Choose an ICC Color Profile"),
                                                  NULL,
                                                  GTK_FILE_CHOOSER_ACTION_OPEN);
295 296 297 298 299 300 301 302 303 304

  history = gimp_personal_rc_file ("profilerc");
  combo = gimp_color_profile_combo_box_new (dialog, history);
  g_free (history);

  g_signal_connect (combo, "changed",
                    G_CALLBACK (cdisplay_proof_profile_changed),
                    proof);

  if (proof->profile)
305
    {
306
      GFile *file = gimp_file_new_for_config_path (proof->profile, NULL);
307 308 309

      gimp_color_profile_combo_box_set_active_file (GIMP_COLOR_PROFILE_COMBO_BOX (combo),
                                                    file, NULL);
310 311 312

      if (file)
        g_object_unref (file);
313
    }
314

315
  gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
316
                             _("_Profile:"), 0.0, 0.5,
317
                             combo, 1, FALSE);
318

319 320
  combo = gimp_prop_enum_combo_box_new (G_OBJECT (proof), "intent", 0, 0);

321
  gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
322 323
                             _("_Intent:"), 0.0, 0.5,
                             combo, 1, FALSE);
324

325 326 327
  toggle = gimp_prop_check_button_new (G_OBJECT (proof),
                                       "black-point-compensation",
                                       _("_Black Point Compensation"));
328
  gtk_table_attach_defaults (GTK_TABLE (table), toggle, 1, 2, 2, 3);
329
  gtk_widget_show (toggle);
330

331
  return table;
332 333 334 335 336
}

static void
cdisplay_proof_changed (GimpColorDisplay *display)
{
337 338
  CdisplayProof    *proof         = CDISPLAY_PROOF (display);
  GimpColorProfile *proof_profile = NULL;
339
  GimpColorProfile *rgb_profile;
340
  GFile            *file;
341 342 343

  if (proof->transform)
    {
344
      g_object_unref (proof->transform);
345 346 347
      proof->transform = NULL;
    }

348
  if (! proof->profile)
349 350
    return;

351
  rgb_profile = gimp_color_profile_new_rgb_srgb ();
352

353 354 355 356 357 358 359
  file = gimp_file_new_for_config_path (proof->profile, NULL);

  if (file)
    {
      proof_profile = gimp_color_profile_new_from_file (file, NULL);
      g_object_unref (file);
    }
360

361
  if (proof_profile)
362
    {
363
      GimpColorTransformFlags flags = 0;
364

365
      if (proof->bpc)
366 367 368 369 370 371 372 373 374 375 376
        flags |= GIMP_COLOR_TRANSFORM_FLAGS_BLACK_POINT_COMPENSATION;

      proof->transform =
        gimp_color_transform_new_proofing (rgb_profile,
                                           babl_format ("R'G'B'A float"),
                                           rgb_profile,
                                           babl_format ("R'G'B'A float"),
                                           proof_profile,
                                           proof->intent,
                                           proof->intent,
                                           flags);
377

378
      g_object_unref (proof_profile);
379 380
    }

381
  g_object_unref (rgb_profile);
382
}