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

« back to all changes in this revision

Viewing changes to plug-ins/common/decompose.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
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * Decompose plug-in (C) 1997 Peter Kirchgessner
30
30
 
31
31
#include "config.h"
32
32
 
33
 
#include <stdio.h>
34
 
#include <stdlib.h>
35
33
#include <string.h>
36
34
 
37
35
#include <libgimp/gimp.h>
38
36
#include <libgimp/gimpui.h>
39
 
#include <libgimpmath/gimpmath.h>
40
37
 
41
38
#include "libgimp/stdplugins-intl.h"
42
39
 
45
42
#define cbrt(x) (pow(x, 1.0/3.0))
46
43
#endif
47
44
 
 
45
 
 
46
#define PLUG_IN_PROC      "plug-in-decompose"
 
47
#define PLUG_IN_PROC_REG  "plug-in-decompose-registered"
 
48
#define PLUG_IN_BINARY    "decompose"
 
49
 
 
50
 
48
51
/* Declare local functions
49
52
 */
50
53
static void    query            (void);
56
59
 
57
60
static gint32  decompose        (gint32              image_id,
58
61
                                 gint32              drawable_ID,
59
 
                                 gchar              *extract_type,
60
 
                                 gint32             *drawable_ID_dst);
 
62
                                 const gchar        *extract_type,
 
63
                                 gint32             *image_ID_dst,
 
64
                                 gint32             *num_layers,
 
65
                                 gint32             *layer_ID_dst);
61
66
static gint32  create_new_image (const gchar        *filename,
62
67
                                 const gchar        *layername,
63
68
                                 guint               width,
69
74
                                 GimpDrawable      **drawable,
70
75
                                 GimpPixelRgn       *pixel_rgn);
71
76
static gint32  create_new_layer (gint32              image_ID,
 
77
                                 gint                position,
72
78
                                 const gchar        *layername,
73
79
                                 guint               width,
74
80
                                 guint               height,
76
82
                                 GimpDrawable      **drawable,
77
83
                                 GimpPixelRgn       *pixel_rgn);
78
84
 
 
85
static void transfer_registration_color (const guchar *src,
 
86
                                         gint bpp, gint numpix, guchar **dst,
 
87
                                         gint num_channels);
79
88
 
80
 
static void extract_rgb      (guchar *src, gint bpp, gint numpix, guchar **dst);
81
 
static void extract_red      (guchar *src, gint bpp, gint numpix, guchar **dst);
82
 
static void extract_green    (guchar *src, gint bpp, gint numpix, guchar **dst);
83
 
static void extract_blue     (guchar *src, gint bpp, gint numpix, guchar **dst);
84
 
static void extract_rgba     (guchar *src, gint bpp, gint numpix, guchar **dst);
85
 
static void extract_alpha    (guchar *src, gint bpp, gint numpix, guchar **dst);
86
 
static void extract_hsv      (guchar *src, gint bpp, gint numpix, guchar **dst);
87
 
static void extract_hue      (guchar *src, gint bpp, gint numpix, guchar **dst);
88
 
static void extract_sat      (guchar *src, gint bpp, gint numpix, guchar **dst);
89
 
static void extract_val      (guchar *src, gint bpp, gint numpix, guchar **dst);
90
 
static void extract_cmy      (guchar *src, gint bpp, gint numpix, guchar **dst);
91
 
static void extract_cyan     (guchar *src, gint bpp, gint numpix, guchar **dst);
92
 
static void extract_magenta  (guchar *src, gint bpp, gint numpix, guchar **dst);
93
 
static void extract_yellow   (guchar *src, gint bpp, gint numpix, guchar **dst);
94
 
static void extract_cmyk     (guchar *src, gint bpp, gint numpix, guchar **dst);
95
 
static void extract_cyank    (guchar *src, gint bpp, gint numpix, guchar **dst);
96
 
static void extract_magentak (guchar *src, gint bpp, gint numpix, guchar **dst);
97
 
static void extract_yellowk  (guchar *src, gint bpp, gint numpix, guchar **dst);
98
 
static void extract_lab      (guchar *src, gint bpp, gint numpix, guchar **dst);
99
 
static void extract_ycbcr470 (guchar *src, gint bpp, gint numpix, guchar **dst);
100
 
static void extract_ycbcr709 (guchar *src, gint bpp, gint numpix, guchar **dst);
101
 
static void extract_ycbcr470f(guchar *src, gint bpp, gint numpix, guchar **dst);
102
 
static void extract_ycbcr709f(guchar *src, gint bpp, gint numpix, guchar **dst);
 
89
static void extract_rgb      (const guchar *src,
 
90
                              gint bpp, gint numpix, guchar **dst);
 
91
static void extract_red      (const guchar *src,
 
92
                              gint bpp, gint numpix, guchar **dst);
 
93
static void extract_green    (const guchar *src,
 
94
                              gint bpp, gint numpix, guchar **dst);
 
95
static void extract_blue     (const guchar *src,
 
96
                              gint bpp, gint numpix, guchar **dst);
 
97
static void extract_rgba     (const guchar *src,
 
98
                              gint bpp, gint numpix, guchar **dst);
 
99
static void extract_alpha    (const guchar *src,
 
100
                              gint bpp, gint numpix, guchar **dst);
 
101
static void extract_hsv      (const guchar *src,
 
102
                              gint bpp, gint numpix, guchar **dst);
 
103
static void extract_hsl      (const guchar *src,
 
104
                              gint bpp, gint numpix, guchar **dst);
 
105
static void extract_hue      (const guchar *src,
 
106
                              gint bpp, gint numpix, guchar **dst);
 
107
static void extract_sat      (const guchar *src,
 
108
                              gint bpp, gint numpix, guchar **dst);
 
109
static void extract_val      (const guchar *src,
 
110
                              gint bpp, gint numpix, guchar **dst);
 
111
static void extract_huel     (const guchar *src,
 
112
                              gint bpp, gint numpix, guchar **dst);
 
113
static void extract_satl     (const guchar *src,
 
114
                              gint bpp, gint numpix, guchar **dst);
 
115
static void extract_lightness     (const guchar *src,
 
116
                              gint bpp, gint numpix, guchar **dst);
 
117
static void extract_cmy      (const guchar *src,
 
118
                              gint bpp, gint numpix, guchar **dst);
 
119
static void extract_cyan     (const guchar *src,
 
120
                              gint bpp, gint numpix, guchar **dst);
 
121
static void extract_magenta  (const guchar *src,
 
122
                              gint bpp, gint numpix, guchar **dst);
 
123
static void extract_yellow   (const guchar *src,
 
124
                              gint bpp, gint numpix, guchar **dst);
 
125
static void extract_cmyk     (const guchar *src,
 
126
                              gint bpp, gint numpix, guchar **dst);
 
127
static void extract_cyank    (const guchar *src,
 
128
                              gint bpp, gint numpix, guchar **dst);
 
129
static void extract_magentak (const guchar *src,
 
130
                              gint bpp, gint numpix, guchar **dst);
 
131
static void extract_yellowk  (const guchar *src,
 
132
                              gint bpp, gint numpix, guchar **dst);
 
133
static void extract_lab      (const guchar *src,
 
134
                              gint bpp, gint numpix, guchar **dst);
 
135
static void extract_ycbcr470 (const guchar *src,
 
136
                              gint bpp, gint numpix, guchar **dst);
 
137
static void extract_ycbcr709 (const guchar *src,
 
138
                              gint bpp, gint numpix, guchar **dst);
 
139
static void extract_ycbcr470f(const guchar *src,
 
140
                              gint bpp, gint numpix, guchar **dst);
 
141
static void extract_ycbcr709f(const guchar *src,
 
142
                              gint bpp, gint numpix, guchar **dst);
103
143
 
104
144
static gboolean  decompose_dialog (void);
105
145
 
106
146
 
107
 
/* LAB colorspace constants */
108
 
static const gdouble Xn = 0.951;
109
 
static const gdouble Yn = 1.0;
110
 
static const gdouble Zn = 1.089;
111
 
 
112
 
 
113
 
/* Maximum number of new images generated by an extraction */
 
147
/* Maximum number of images/layers generated by an extraction */
114
148
#define MAX_EXTRACT_IMAGES 4
115
149
 
116
150
/* Description of an extraction */
117
151
typedef struct
118
152
{
119
 
  gchar *type;            /* What to extract */
120
 
  gint   dialog;          /* Dialog-Flag. Set it to 1 if you want to appear */
121
 
                          /* this extract function within the dialog */
122
 
  gint   num_images;      /* Number of images to create */
123
 
  gchar *channel_name[MAX_EXTRACT_IMAGES];   /* Names of channels to extract */
124
 
                          /* Function that performs the extraction */
125
 
  void (*extract_fun) (guchar *src, int bpp, gint numpix, guchar **dst);
 
153
  const gchar *type;        /* What to extract */
 
154
  gboolean     dialog;      /* Dialog-Flag. Set it to TRUE if you want to appear
 
155
                             * this extract function within the dialog */
 
156
  gint         num_images;  /* Number of images to create */
 
157
 
 
158
  /* Names of channels to extract */
 
159
  const gchar *channel_name[MAX_EXTRACT_IMAGES];
 
160
 
 
161
  /* Function that performs the extraction */
 
162
  void   (* extract_fun) (const guchar  *src,
 
163
                          int            bpp,
 
164
                          gint           numpix,
 
165
                          guchar       **dst);
126
166
} EXTRACT;
127
167
 
128
168
static EXTRACT extract[] =
129
169
{
130
170
  { N_("RGB"),        TRUE,  3, { N_("red"),
131
 
                                  N_("green"),
132
 
                                  N_("blue") }, extract_rgb },
133
 
  { N_("Red"),        FALSE, 1, { N_("red") }, extract_red },
 
171
                                  N_("green"),
 
172
                                  N_("blue") }, extract_rgb },
 
173
 
 
174
  { N_("Red"),        FALSE, 1, { N_("red")   }, extract_red },
134
175
  { N_("Green"),      FALSE, 1, { N_("green") }, extract_green },
 
176
  { N_("Blue"),       FALSE, 1, { N_("blue")  }, extract_blue },
 
177
 
135
178
  { N_("RGBA"),       TRUE,  4, { N_("red"),
136
 
                                  N_("green"),
137
 
                                  N_("blue"),
138
 
                                  N_("alpha") }, extract_rgba },
139
 
  { N_("Blue"),       FALSE, 1, { N_("blue") }, extract_blue },
 
179
                                  N_("green"),
 
180
                                  N_("blue"),
 
181
                                  N_("alpha") }, extract_rgba },
 
182
 
 
183
 
140
184
  { N_("HSV"),        TRUE,  3, { N_("hue"),
141
 
                                  N_("saturation"),
142
 
                                  N_("value") }, extract_hsv },
143
 
  { N_("Hue"),        FALSE, 1, { N_("hue") }, extract_hue },
 
185
                                  N_("saturation"),
 
186
                                  N_("value")    }, extract_hsv },
 
187
 
 
188
  { N_("Hue"),        FALSE, 1, { N_("hue")      }, extract_hue },
144
189
  { N_("Saturation"), FALSE, 1, { N_("saturation") }, extract_sat },
145
 
  { N_("Value"),      FALSE, 1, { N_("value") }, extract_val },
 
190
  { N_("Value"),      FALSE, 1, { N_("value")    }, extract_val },
 
191
 
 
192
 
 
193
  { N_("HSL"),        TRUE,  3, { N_("hue_l"),
 
194
                                  N_("saturation_l"),
 
195
                                  N_("lightness")    }, extract_hsl },
 
196
 
 
197
  { N_("Hue (HSL)"),  FALSE, 1, { N_("hue_l")   }, extract_huel },
 
198
  { N_("Saturation (HSL)"), FALSE, 1, { N_("saturation_l") }, extract_satl },
 
199
  { N_("Lightness"),  FALSE, 1, { N_("lightness")}, extract_lightness },
 
200
 
 
201
 
146
202
  { N_("CMY"),        TRUE,  3, { N_("cyan"),
147
 
                                  N_("magenta"),
148
 
                                  N_("yellow") }, extract_cmy },
149
 
  { N_("Cyan"),       FALSE, 1, { N_("cyan") }, extract_cyan },
 
203
                                  N_("magenta"),
 
204
                                  N_("yellow")  }, extract_cmy },
 
205
 
 
206
  { N_("Cyan"),       FALSE, 1, { N_("cyan")    }, extract_cyan },
150
207
  { N_("Magenta"),    FALSE, 1, { N_("magenta") }, extract_magenta },
151
 
  { N_("Yellow"),     FALSE, 1, { N_("yellow") }, extract_yellow },
152
 
  { N_("CMYK"),       TRUE,  4, { N_("cyan_k"),
153
 
                                  N_("magenta_k"),
154
 
                                  N_("yellow_k"),
155
 
                                  N_("black") }, extract_cmyk },
156
 
  { N_("Cyan_K"),     FALSE, 1, { N_("cyan_k") }, extract_cyank },
157
 
  { N_("Magenta_K"),  FALSE, 1, { N_("magenta_k") }, extract_magentak },
158
 
  { N_("Yellow_K"),   FALSE, 1, { N_("yellow_k") }, extract_yellowk },
 
208
  { N_("Yellow"),     FALSE, 1, { N_("yellow")  }, extract_yellow },
 
209
 
 
210
 
 
211
  { N_("CMYK"),       TRUE,  4, { N_("cyan-k"),
 
212
                                  N_("magenta-k"),
 
213
                                  N_("yellow-k"),
 
214
                                  N_("black")     }, extract_cmyk },
 
215
 
 
216
  { N_("Cyan_K"),     FALSE, 1, { N_("cyan-k")    }, extract_cyank },
 
217
  { N_("Magenta_K"),  FALSE, 1, { N_("magenta-k") }, extract_magentak },
 
218
  { N_("Yellow_K"),   FALSE, 1, { N_("yellow-k")  }, extract_yellowk },
 
219
 
 
220
 
159
221
  { N_("Alpha"),      TRUE,  1, { N_("alpha") }, extract_alpha },
160
222
 
 
223
 
161
224
  { N_("LAB"),        TRUE,  3, { "L",
162
225
                                  "A",
163
226
                                  "B" }, extract_lab },
164
227
 
165
 
  { "YCbCr_ITU_R470",
166
 
                      TRUE,  3, { N_("luma_y470"),
167
 
                                  N_("blueness_cb470"),
168
 
                                  N_("redness_cr470") }, extract_ycbcr470 },
169
 
  { "YCbCr_ITU_R709",
170
 
                      TRUE,  3, { N_("luma_y709"),
171
 
                                  N_("blueness_cb709"),
172
 
                                  N_("redness_cr709") }, extract_ycbcr709 },
173
 
  { "YCbCr_ITU_R470_256",
174
 
                      TRUE,  3, { N_("luma_y470f"),
175
 
                                  N_("blueness_cb470f"),
176
 
                                  N_("redness_cr470f") }, extract_ycbcr470f },
177
 
  { "YCbCr_ITU_R709_256",
178
 
                      TRUE,  3, { N_("luma_y709f"),
179
 
                                  N_("blueness_cb709f"),
180
 
                                  N_("redness_cr709f") }, extract_ycbcr709f },
 
228
 
 
229
  { "YCbCr_ITU_R470",     TRUE, 3, { N_("luma-y470"),
 
230
                                     N_("blueness-cb470"),
 
231
                                     N_("redness-cr470") }, extract_ycbcr470 },
 
232
 
 
233
  { "YCbCr_ITU_R709",     TRUE, 3, { N_("luma-y709"),
 
234
                                     N_("blueness-cb709"),
 
235
                                     N_("redness-cr709") }, extract_ycbcr709 },
 
236
 
 
237
  { "YCbCr ITU R470 256", TRUE, 3, { N_("luma-y470f"),
 
238
                                     N_("blueness-cb470f"),
 
239
                                     N_("redness-cr470f") }, extract_ycbcr470f },
 
240
 
 
241
  { "YCbCr ITU R709 256", TRUE, 3, { N_("luma-y709f"),
 
242
                                     N_("blueness-cb709f"),
 
243
                                     N_("redness-cr709f") }, extract_ycbcr709f }
181
244
};
182
245
 
183
246
 
185
248
{
186
249
  gchar     extract_type[32];
187
250
  gboolean  as_layers;
 
251
  gboolean  use_registration;
188
252
} DecoVals;
189
253
 
190
 
typedef struct
191
 
{
192
 
  gint extract_flag[G_N_ELEMENTS (extract)];
193
 
} DecoInterface;
194
 
 
195
 
GimpPlugInInfo PLUG_IN_INFO =
 
254
const GimpPlugInInfo PLUG_IN_INFO =
196
255
{
197
256
  NULL,  /* init_proc  */
198
257
  NULL,  /* quit_proc  */
203
262
static DecoVals decovals =
204
263
{
205
264
  "rgb",    /* Decompose type      */
206
 
  TRUE      /* Decompose to Layers */
207
 
};
208
 
 
209
 
static DecoInterface decoint =
210
 
{
211
 
  { 0 }  /*  extract flags */
 
265
  TRUE,     /* Decompose to Layers */
 
266
  FALSE     /* use registration color */
212
267
};
213
268
 
214
269
static GimpRunMode run_mode;
219
274
static void
220
275
query (void)
221
276
{
222
 
  static GimpParamDef args[] =
 
277
  static const GimpParamDef args[] =
223
278
  {
224
 
    { GIMP_PDB_INT32, "run_mode",        "Interactive, non-interactive" },
225
 
    { GIMP_PDB_IMAGE, "image",           "Input image (unused)" },
226
 
    { GIMP_PDB_DRAWABLE, "drawable",     "Input drawable" },
227
 
    { GIMP_PDB_STRING, "decompose_type", "What to decompose: RGB, Red, Green, Blue, RGBA, Red, Green, Blue, Alpha, HSV, Hue, Saturation, Value, CMY, Cyan, Magenta, Yellow, CMYK, Cyan_K, Magenta_K, Yellow_K, Alpha, LAB" },
228
 
    { GIMP_PDB_INT32, "layers_mode",     "Create channels as layers in a single image" }
 
279
    { GIMP_PDB_INT32,    "run-mode",       "Interactive, non-interactive" },
 
280
    { GIMP_PDB_IMAGE,    "image",          "Input image (unused)"         },
 
281
    { GIMP_PDB_DRAWABLE, "drawable",       "Input drawable"               },
 
282
    { GIMP_PDB_STRING,   "decompose-type", "What to decompose: RGB, Red, Green, Blue, RGBA, Red, Green, Blue, Alpha, HSV, Hue, Saturation, Value, CMY, Cyan, Magenta, Yellow, CMYK, Cyan_K, Magenta_K, Yellow_K, Alpha, LAB" },
 
283
    { GIMP_PDB_INT32,    "layers-mode",    "Create channels as layers in a single image" }
229
284
  };
230
 
  static GimpParamDef return_vals[] =
 
285
  static const GimpParamDef return_vals[] =
231
286
  {
232
 
    { GIMP_PDB_IMAGE, "new_image", "Output gray image" },
233
 
    { GIMP_PDB_IMAGE, "new_image", "Output gray image (N/A for single channel extract)" },
234
 
    { GIMP_PDB_IMAGE, "new_image", "Output gray image (N/A for single channel extract)" },
235
 
    { GIMP_PDB_IMAGE, "new_image", "Output gray image (N/A for single channel extract)" }
 
287
    { GIMP_PDB_IMAGE, "new-image", "Output gray image" },
 
288
    { GIMP_PDB_IMAGE, "new-image", "Output gray image (N/A for single channel extract)" },
 
289
    { GIMP_PDB_IMAGE, "new-image", "Output gray image (N/A for single channel extract)" },
 
290
    { GIMP_PDB_IMAGE, "new-image", "Output gray image (N/A for single channel extract)" }
236
291
  };
237
292
 
238
 
  gimp_install_procedure ("plug_in_decompose",
239
 
                          "Decompose an image into different types of channels",
 
293
  gimp_install_procedure (PLUG_IN_PROC,
 
294
                          N_("Decompose an image into separate colorspace components"),
240
295
                          "This function creates new gray images with "
241
296
                          "different channel information in each of them",
242
297
                          "Peter Kirchgessner",
243
 
                          "Peter Kirchgessner (peter@kirchgessner.net)",
244
 
                          "1997",
245
 
                          N_("_Decompose..."),
246
 
                          "RGB*",
247
 
                          GIMP_PLUGIN,
248
 
                          G_N_ELEMENTS (args),
249
 
                          G_N_ELEMENTS (return_vals),
250
 
                          args, return_vals);
251
 
 
252
 
  gimp_plugin_menu_register ("plug_in_decompose", "<Image>/Filters/Colors");
253
 
  gimp_plugin_menu_register ("plug_in_decompose", "<Image>/Image/Mode");
 
298
                          "Peter Kirchgessner",
 
299
                          "1997",
 
300
                          N_("_Decompose..."),
 
301
                          "RGB*",
 
302
                          GIMP_PLUGIN,
 
303
                          G_N_ELEMENTS (args),
 
304
                          G_N_ELEMENTS (return_vals),
 
305
                          args, return_vals);
 
306
 
 
307
  gimp_install_procedure (PLUG_IN_PROC_REG,
 
308
                          N_("Decompose an image into separate colorspace components"),
 
309
                          "This function creates new gray images with "
 
310
                          "different channel information in each of them. "
 
311
                          "Pixels in the foreground color will appear black "
 
312
                          "in all output images.  This can be used for "
 
313
                          "things like crop marks that have to show up on "
 
314
                          "all channels.",
 
315
                          "Peter Kirchgessner",
 
316
                          "Peter Kirchgessner, Clarence Risher",
 
317
                          "1997",
 
318
                          N_("_Decompose..."),
 
319
                          "RGB*",
 
320
                          GIMP_PLUGIN,
 
321
                          G_N_ELEMENTS (args),
 
322
                          G_N_ELEMENTS (return_vals),
 
323
                          args, return_vals);
 
324
 
 
325
  gimp_plugin_menu_register (PLUG_IN_PROC_REG, "<Image>/Colors/Components");
254
326
}
255
327
 
256
328
static void
260
332
     gint             *nreturn_vals,
261
333
     GimpParam       **return_vals)
262
334
{
263
 
  static GimpParam  values[MAX_EXTRACT_IMAGES+1];
 
335
  static GimpParam  values[MAX_EXTRACT_IMAGES + 1];
264
336
  GimpPDBStatusType status = GIMP_PDB_SUCCESS;
265
 
  GimpImageType     drawable_type;
266
337
  gint32            num_images;
267
338
  gint32            image_ID_extract[MAX_EXTRACT_IMAGES];
 
339
  gint32            layer_ID_extract[MAX_EXTRACT_IMAGES];
268
340
  gint              j;
 
341
  gint32            layer;
 
342
  gint32            num_layers;
 
343
  gint32            image_ID;
269
344
 
270
345
  INIT_I18N ();
271
346
 
272
347
  run_mode = param[0].data.d_int32;
 
348
  image_ID = param[1].data.d_image;
 
349
  layer    = param[2].data.d_drawable;
273
350
 
274
351
  *nreturn_vals = MAX_EXTRACT_IMAGES+1;
275
352
  *return_vals  = values;
276
353
 
277
354
  values[0].type          = GIMP_PDB_STATUS;
278
355
  values[0].data.d_status = status;
 
356
 
279
357
  for (j = 0; j < MAX_EXTRACT_IMAGES; j++)
280
358
    {
281
359
      values[j+1].type         = GIMP_PDB_IMAGE;
286
364
    {
287
365
    case GIMP_RUN_INTERACTIVE:
288
366
      /*  Possibly retrieve data  */
289
 
      gimp_get_data ("plug_in_decompose", &decovals);
 
367
      gimp_get_data (PLUG_IN_PROC, &decovals);
290
368
 
291
369
      /*  First acquire information with a dialog  */
292
370
      if (! decompose_dialog ())
295
373
 
296
374
    case GIMP_RUN_NONINTERACTIVE:
297
375
      /*  Make sure all the arguments are there!  */
298
 
      if (nparams != 4 && nparams != 5)
 
376
      if (nparams != 4 && nparams != 5 && nparams != 6)
299
377
        {
300
378
          status = GIMP_PDB_CALLING_ERROR;
301
379
        }
306
384
          decovals.extract_type[sizeof (decovals.extract_type)-1] = '\0';
307
385
 
308
386
          decovals.as_layers = nparams > 4 ? param[4].data.d_int32 : FALSE;
 
387
          decovals.use_registration = (strcmp (name, PLUG_IN_PROC_REG) == 0);
309
388
        }
310
389
      break;
311
390
 
312
391
    case GIMP_RUN_WITH_LAST_VALS:
313
392
      /*  Possibly retrieve data  */
314
 
      gimp_get_data ("plug_in_decompose", &decovals);
 
393
      gimp_get_data (PLUG_IN_PROC, &decovals);
315
394
      break;
316
395
 
317
396
    default:
319
398
    }
320
399
 
321
400
  /*  Make sure that the drawable is RGB color  */
322
 
  drawable_type = gimp_drawable_type (param[2].data.d_drawable);
323
 
  if ((drawable_type != GIMP_RGB_IMAGE) && (drawable_type != GIMP_RGBA_IMAGE))
 
401
  if (gimp_drawable_type_with_alpha (layer) != GIMP_RGBA_IMAGE)
324
402
    {
325
403
      g_message ("Can only work on RGB images.");
326
404
      status = GIMP_PDB_CALLING_ERROR;
327
405
    }
 
406
 
328
407
  if (status == GIMP_PDB_SUCCESS)
329
408
    {
330
 
      gimp_progress_init (_("Decomposing..."));
 
409
      gimp_progress_init (_("Decomposing"));
331
410
 
332
 
      num_images = decompose (param[1].data.d_image, param[2].data.d_drawable,
333
 
                              decovals.extract_type, image_ID_extract);
 
411
      num_images = decompose (image_ID, layer,
 
412
                              decovals.extract_type,
 
413
                              image_ID_extract,
 
414
                              &num_layers,
 
415
                              layer_ID_extract);
334
416
 
335
417
      if (num_images <= 0)
336
418
        {
338
420
        }
339
421
      else
340
422
        {
 
423
          /* create decompose-data parasite */
 
424
          GString *data = g_string_new ("");
 
425
 
 
426
          g_string_printf (data, "source=%d type=%s ",
 
427
                           layer, decovals.extract_type);
 
428
 
 
429
          for (j = 0; j < num_layers; j++)
 
430
            g_string_append_printf (data, "%d ", layer_ID_extract[j]);
 
431
 
341
432
          for (j = 0; j < num_images; j++)
342
433
            {
343
434
              values[j+1].data.d_int32 = image_ID_extract[j];
 
435
 
344
436
              gimp_image_undo_enable (image_ID_extract[j]);
345
437
              gimp_image_clean_all (image_ID_extract[j]);
 
438
 
 
439
              gimp_image_attach_new_parasite (image_ID_extract[j],
 
440
                                              "decompose-data",
 
441
                                              0, data->len + 1, data->str);
 
442
 
346
443
              if (run_mode != GIMP_RUN_NONINTERACTIVE)
347
444
                gimp_display_new (image_ID_extract[j]);
348
445
            }
349
446
 
350
447
          /*  Store data  */
351
448
          if (run_mode == GIMP_RUN_INTERACTIVE)
352
 
            gimp_set_data ("plug_in_decompose", &decovals, sizeof (DecoVals));
 
449
            gimp_set_data (PLUG_IN_PROC, &decovals, sizeof (DecoVals));
353
450
        }
354
451
    }
355
452
 
362
459
   On failure, -1 is returned.
363
460
*/
364
461
static gint32
365
 
decompose (gint32  image_ID,
366
 
           gint32  drawable_ID,
367
 
           char   *extract_type,
368
 
           gint32 *image_ID_dst)
 
462
decompose (gint32       image_ID,
 
463
           gint32       drawable_ID,
 
464
           const gchar *extract_type,
 
465
           gint32      *image_ID_dst,
 
466
           gint32      *nlayers,
 
467
           gint32      *layer_ID_dst)
369
468
{
370
 
  const gchar *layername;
371
 
  gint    i, j, extract_idx, scan_lines;
372
 
  gint    height, width, tile_height, num_images;
373
 
  gchar  *filename;
374
 
  guchar *src;
375
 
  guchar *dst[MAX_EXTRACT_IMAGES];
376
 
  gint32  layer_ID_dst[MAX_EXTRACT_IMAGES];
377
 
  GimpDrawable *drawable_src, *drawable_dst[MAX_EXTRACT_IMAGES];
378
 
  GimpPixelRgn pixel_rgn_src, pixel_rgn_dst[MAX_EXTRACT_IMAGES];
 
469
  const gchar  *layername;
 
470
  gint          i, j, extract_idx, scan_lines;
 
471
  gint          height, width, tile_height, num_layers;
 
472
  gchar        *filename;
 
473
  guchar       *src;
 
474
  guchar       *dst[MAX_EXTRACT_IMAGES];
 
475
  GimpDrawable *drawable_src;
 
476
  GimpDrawable *drawable_dst[MAX_EXTRACT_IMAGES];
 
477
  GimpPixelRgn  pixel_rgn_src;
 
478
  GimpPixelRgn  pixel_rgn_dst[MAX_EXTRACT_IMAGES];
379
479
 
380
480
  extract_idx = -1;   /* Search extract type */
381
481
  for (j = 0; j < G_N_ELEMENTS (extract); j++)
404
504
      return -1;
405
505
    }
406
506
 
407
 
  width = drawable_src->width;
 
507
  width  = drawable_src->width;
408
508
  height = drawable_src->height;
409
509
 
410
510
  tile_height = gimp_tile_height ();
415
515
  src = g_new (guchar, tile_height * width * drawable_src->bpp);
416
516
 
417
517
  /* Create all new gray images */
418
 
  num_images = extract[extract_idx].num_images;
419
 
  if (num_images > MAX_EXTRACT_IMAGES)
420
 
    num_images = MAX_EXTRACT_IMAGES;
 
518
  num_layers = extract[extract_idx].num_images;
 
519
  if (num_layers > MAX_EXTRACT_IMAGES)
 
520
    num_layers = MAX_EXTRACT_IMAGES;
421
521
 
422
 
  for (j = 0; j < num_images; j++)
 
522
  for (j = 0; j < num_layers; j++)
423
523
    {
424
524
      /* Build a filename like <imagename>-<channel>.<extension> */
425
525
      gchar   *fname;
479
579
                                                drawable_dst + j,
480
580
                                                pixel_rgn_dst + j);
481
581
          else
482
 
            layer_ID_dst[j] = create_new_layer (image_ID_dst[0], layername,
 
582
            layer_ID_dst[j] = create_new_layer (image_ID_dst[0], j, layername,
483
583
                                                width, height, GIMP_GRAY,
484
584
                                                drawable_dst + j,
485
585
                                                pixel_rgn_dst + j);
510
610
      extract[extract_idx].extract_fun (src, drawable_src->bpp, scan_lines*width,
511
611
                                        dst);
512
612
 
 
613
      /* Transfer the registration color */
 
614
      if (decovals.use_registration)
 
615
        transfer_registration_color (src, drawable_src->bpp, scan_lines*width,
 
616
                                     dst, extract[extract_idx].num_images);
 
617
 
513
618
      /* Set destination pixel regions */
514
 
      for (j = 0; j < num_images; j++)
 
619
      for (j = 0; j < num_layers; j++)
515
620
        gimp_pixel_rgn_set_rect (&(pixel_rgn_dst[j]), dst[j], 0, i, width,
516
621
                                 scan_lines);
517
622
      i += scan_lines;
521
626
 
522
627
  g_free (src);
523
628
 
524
 
  for (j = 0; j < num_images; j++)
 
629
  for (j = 0; j < num_layers; j++)
525
630
    {
526
631
      gimp_drawable_detach (drawable_dst[j]);
527
632
      gimp_drawable_update (layer_ID_dst[j], 0, 0,
533
638
 
534
639
  gimp_drawable_detach (drawable_src);
535
640
 
536
 
  return (decovals.as_layers ? 1 : num_images);
 
641
  *nlayers = num_layers;
 
642
 
 
643
  return (decovals.as_layers ? 1 : num_layers);
537
644
}
538
645
 
539
646
 
558
665
  gimp_image_set_filename (image_ID, filename);
559
666
  gimp_image_set_resolution (image_ID, xres, yres);
560
667
 
561
 
  *layer_ID = create_new_layer (image_ID,
 
668
  *layer_ID = create_new_layer (image_ID, 0,
562
669
                                layername, width, height, type,
563
670
                                drawable, pixel_rgn);
564
671
 
568
675
 
569
676
static gint32
570
677
create_new_layer (gint32              image_ID,
 
678
                  gint                position,
571
679
                  const gchar        *layername,
572
680
                  guint               width,
573
681
                  guint               height,
596
704
 
597
705
  layer_ID = gimp_layer_new (image_ID, layername, width, height,
598
706
                             gdtype, 100, GIMP_NORMAL_MODE);
599
 
  gimp_image_add_layer (image_ID, layer_ID, 0);
 
707
  gimp_image_add_layer (image_ID, layer_ID, position);
600
708
 
601
709
  *drawable = gimp_drawable_get (layer_ID);
602
710
  gimp_pixel_rgn_init (pixel_rgn, *drawable, 0, 0, (*drawable)->width,
605
713
  return layer_ID;
606
714
}
607
715
 
 
716
/* Registration Color function */
 
717
 
 
718
static void
 
719
transfer_registration_color (const guchar  *src,
 
720
                             gint           bpp,
 
721
                             gint           numpix,
 
722
                             guchar       **dst,
 
723
                             gint           num_channels)
 
724
{
 
725
  register const guchar *rgb_src = src;
 
726
  guchar *dsts[4];
 
727
  register gint count = numpix;
 
728
  gint channel;
 
729
  GimpRGB color;
 
730
  guchar red, green, blue;
 
731
 
 
732
  gimp_context_get_foreground (&color);
 
733
  gimp_rgb_get_uchar (&color, &red, &green, &blue);
 
734
 
 
735
  for (channel = 0; channel < num_channels; channel++)
 
736
    dsts[channel] = dst[channel];
 
737
 
 
738
  while (count-- > 0)
 
739
    {
 
740
      if (rgb_src[0] == red && rgb_src[1] == green && rgb_src[2] == blue)
 
741
        for (channel = 0; channel < num_channels; channel++)
 
742
          *(dsts[channel]++) = 255;
 
743
      else
 
744
        for (channel = 0; channel < num_channels; channel++)
 
745
          dsts[channel]++;
 
746
 
 
747
      rgb_src += bpp;
 
748
    }
 
749
}
 
750
 
608
751
 
609
752
/* Extract functions */
610
753
 
611
754
static void
612
 
extract_rgb (guchar  *src,
613
 
             gint     bpp,
614
 
             gint     numpix,
615
 
             guchar **dst)
 
755
extract_rgb (const guchar  *src,
 
756
             gint           bpp,
 
757
             gint           numpix,
 
758
             guchar       **dst)
616
759
{
617
 
  register guchar *rgb_src = src;
 
760
  register const guchar *rgb_src = src;
618
761
  register guchar *red_dst = dst[0];
619
762
  register guchar *green_dst = dst[1];
620
763
  register guchar *blue_dst = dst[2];
630
773
}
631
774
 
632
775
static void
633
 
extract_rgba (guchar  *src,
634
 
              gint     bpp,
635
 
              gint     numpix,
636
 
              guchar **dst)
 
776
extract_rgba (const guchar  *src,
 
777
              gint           bpp,
 
778
              gint           numpix,
 
779
              guchar       **dst)
637
780
{
638
 
  register guchar *rgba_src = src;
 
781
  register const guchar *rgba_src = src;
639
782
  register guchar *red_dst = dst[0];
640
783
  register guchar *green_dst = dst[1];
641
784
  register guchar *blue_dst = dst[2];
653
796
}
654
797
 
655
798
static void
656
 
extract_red (guchar  *src,
657
 
             gint     bpp,
658
 
             gint     numpix,
659
 
             guchar **dst)
 
799
extract_red (const guchar  *src,
 
800
             gint           bpp,
 
801
             gint           numpix,
 
802
             guchar       **dst)
660
803
{
661
 
  register guchar *rgb_src = src;
 
804
  register const guchar *rgb_src = src;
662
805
  register guchar *red_dst = dst[0];
663
806
  register gint count = numpix, offset = bpp;
664
807
 
671
814
 
672
815
 
673
816
static void
674
 
extract_green (guchar  *src,
675
 
               gint     bpp,
676
 
               gint     numpix,
677
 
               guchar **dst)
 
817
extract_green (const guchar  *src,
 
818
               gint           bpp,
 
819
               gint           numpix,
 
820
               guchar       **dst)
678
821
{
679
 
  register guchar *rgb_src = src+1;
 
822
  register const guchar *rgb_src = src+1;
680
823
  register guchar *green_dst = dst[0];
681
824
  register gint count = numpix, offset = bpp;
682
825
 
689
832
 
690
833
 
691
834
static void
692
 
extract_blue (guchar  *src,
693
 
              gint     bpp,
694
 
              gint     numpix,
695
 
              guchar **dst)
 
835
extract_blue (const guchar  *src,
 
836
              gint           bpp,
 
837
              gint           numpix,
 
838
              guchar       **dst)
696
839
{
697
 
  register guchar *rgb_src = src+2;
 
840
  register const guchar *rgb_src = src+2;
698
841
  register guchar *blue_dst = dst[0];
699
842
  register gint count = numpix, offset = bpp;
700
843
 
707
850
 
708
851
 
709
852
static void
710
 
extract_alpha (guchar  *src,
711
 
               gint     bpp,
712
 
               gint     numpix,
713
 
               guchar **dst)
 
853
extract_alpha (const guchar  *src,
 
854
               gint           bpp,
 
855
               gint           numpix,
 
856
               guchar       **dst)
714
857
{
715
 
  register guchar *rgb_src = src+3;
 
858
  register const guchar *rgb_src = src+3;
716
859
  register guchar *alpha_dst = dst[0];
717
860
  register gint count = numpix, offset = bpp;
718
861
 
725
868
 
726
869
 
727
870
static void
728
 
extract_cmy (guchar  *src,
729
 
             gint     bpp,
730
 
             gint     numpix,
731
 
             guchar **dst)
 
871
extract_cmy (const guchar  *src,
 
872
             gint           bpp,
 
873
             gint           numpix,
 
874
             guchar       **dst)
732
875
{
733
 
  register guchar *rgb_src = src;
 
876
  register const guchar *rgb_src = src;
734
877
  register guchar *cyan_dst = dst[0];
735
878
  register guchar *magenta_dst = dst[1];
736
879
  register guchar *yellow_dst = dst[2];
747
890
 
748
891
 
749
892
static void
750
 
extract_hsv (guchar  *src,
751
 
             gint     bpp,
752
 
             gint     numpix,
753
 
             guchar **dst)
 
893
extract_hsv (const guchar  *src,
 
894
             gint           bpp,
 
895
             gint           numpix,
 
896
             guchar       **dst)
754
897
{
755
 
  register guchar *rgb_src = src;
 
898
  register const guchar *rgb_src = src;
756
899
  register guchar *hue_dst = dst[0];
757
900
  register guchar *sat_dst = dst[1];
758
901
  register guchar *val_dst = dst[2];
771
914
 
772
915
 
773
916
static void
774
 
extract_hue (guchar  *src,
775
 
             gint     bpp,
776
 
             gint     numpix,
777
 
             guchar **dst)
 
917
extract_hue (const guchar  *src,
 
918
             gint           bpp,
 
919
             gint           numpix,
 
920
             guchar       **dst)
778
921
{
779
 
  register guchar *rgb_src = src;
 
922
  register const guchar *rgb_src = src;
780
923
  register guchar *hue_dst = dst[0];
781
924
  register gint count = numpix, offset = bpp;
782
925
  gdouble hue, dummy;
791
934
 
792
935
 
793
936
static void
794
 
extract_sat (guchar  *src,
795
 
             gint     bpp,
796
 
             gint     numpix,
797
 
             guchar **dst)
 
937
extract_sat (const guchar  *src,
 
938
             gint           bpp,
 
939
             gint           numpix,
 
940
             guchar       **dst)
798
941
{
799
 
  register guchar *rgb_src = src;
 
942
  register const guchar *rgb_src = src;
800
943
  register guchar *sat_dst = dst[0];
801
944
  register gint count = numpix, offset = bpp;
802
945
  gdouble sat, dummy;
811
954
 
812
955
 
813
956
static void
814
 
extract_val (guchar  *src,
815
 
             gint     bpp,
816
 
             gint     numpix,
817
 
             guchar **dst)
 
957
extract_val (const guchar  *src,
 
958
             gint           bpp,
 
959
             gint           numpix,
 
960
             guchar       **dst)
818
961
{
819
 
  register guchar *rgb_src = src;
 
962
  register const guchar *rgb_src = src;
820
963
  register guchar *val_dst = dst[0];
821
964
  register gint count = numpix, offset = bpp;
822
965
  gdouble val, dummy;
831
974
 
832
975
 
833
976
static void
834
 
extract_cyan (guchar  *src,
835
 
              gint     bpp,
836
 
              gint     numpix,
837
 
              guchar **dst)
838
 
{
839
 
  register guchar *rgb_src = src;
 
977
extract_hsl (const guchar  *src,
 
978
             gint           bpp,
 
979
             gint           numpix,
 
980
             guchar       **dst)
 
981
{
 
982
  register const guchar *rgb_src = src;
 
983
  register guchar *hue_dst = dst[0];
 
984
  register guchar *sat_dst = dst[1];
 
985
  register guchar *lum_dst = dst[2];
 
986
  register gint count = numpix, offset = bpp;
 
987
 
 
988
  while (count-- > 0)
 
989
    {
 
990
      GimpRGB rgb;
 
991
      GimpHSL hsl;
 
992
 
 
993
      gimp_rgb_set_uchar (&rgb, rgb_src[0], rgb_src[1], rgb_src[2]);
 
994
      gimp_rgb_to_hsl (&rgb, &hsl);
 
995
 
 
996
      *hue_dst++ = (guchar) (hsl.h * 255.999);
 
997
      *sat_dst++ = (guchar) (hsl.s * 255.999);
 
998
      *lum_dst++ = (guchar) (hsl.l * 255.999);
 
999
 
 
1000
      rgb_src += offset;
 
1001
    }
 
1002
}
 
1003
 
 
1004
 
 
1005
static void
 
1006
extract_huel (const guchar  *src,
 
1007
             gint           bpp,
 
1008
             gint           numpix,
 
1009
             guchar       **dst)
 
1010
{
 
1011
  register const guchar *rgb_src = src;
 
1012
  register guchar *hue_dst = dst[0];
 
1013
  register gint count = numpix, offset = bpp;
 
1014
 
 
1015
  while (count-- > 0)
 
1016
    {
 
1017
      GimpRGB rgb;
 
1018
      GimpHSL hsl;
 
1019
 
 
1020
      gimp_rgb_set_uchar (&rgb, rgb_src[0], rgb_src[1], rgb_src[2]);
 
1021
      gimp_rgb_to_hsl (&rgb, &hsl);
 
1022
 
 
1023
      *hue_dst++ = (guchar) (hsl.h * 255.999);
 
1024
      rgb_src += offset;
 
1025
    }
 
1026
}
 
1027
 
 
1028
 
 
1029
static void
 
1030
extract_satl (const guchar  *src,
 
1031
             gint           bpp,
 
1032
             gint           numpix,
 
1033
             guchar       **dst)
 
1034
{
 
1035
  register const guchar *rgb_src = src;
 
1036
  register guchar *sat_dst = dst[0];
 
1037
  register gint count = numpix, offset = bpp;
 
1038
 
 
1039
  while (count-- > 0)
 
1040
    {
 
1041
      GimpRGB rgb;
 
1042
      GimpHSL hsl;
 
1043
 
 
1044
      gimp_rgb_set_uchar (&rgb, rgb_src[0], rgb_src[1], rgb_src[2]);
 
1045
      gimp_rgb_to_hsl (&rgb, &hsl);
 
1046
 
 
1047
      *sat_dst++ = (guchar) (hsl.s * 255.999);
 
1048
      rgb_src += offset;
 
1049
    }
 
1050
}
 
1051
 
 
1052
 
 
1053
static void
 
1054
extract_lightness (const guchar  *src,
 
1055
                   gint           bpp,
 
1056
                   gint           numpix,
 
1057
                   guchar       **dst)
 
1058
{
 
1059
  register const guchar *rgb_src = src;
 
1060
  register guchar *lum_dst = dst[0];
 
1061
  register gint count = numpix, offset = bpp;
 
1062
 
 
1063
  while (count-- > 0)
 
1064
    {
 
1065
      GimpRGB rgb;
 
1066
      GimpHSL hsl;
 
1067
 
 
1068
      gimp_rgb_set_uchar (&rgb, rgb_src[0], rgb_src[1], rgb_src[2]);
 
1069
      gimp_rgb_to_hsl (&rgb, &hsl);
 
1070
      *lum_dst++ = (guchar) (hsl.l * 255.999);
 
1071
      rgb_src += offset;
 
1072
    }
 
1073
}
 
1074
 
 
1075
 
 
1076
static void
 
1077
extract_cyan (const guchar  *src,
 
1078
              gint           bpp,
 
1079
              gint           numpix,
 
1080
              guchar       **dst)
 
1081
{
 
1082
  register const guchar *rgb_src = src;
840
1083
  register guchar *cyan_dst = dst[0];
841
1084
  register gint count = numpix, offset = bpp-1;
842
1085
 
849
1092
 
850
1093
 
851
1094
static void
852
 
extract_magenta (guchar  *src,
853
 
                 gint     bpp,
854
 
                 gint     numpix,
855
 
                 guchar **dst)
 
1095
extract_magenta (const guchar  *src,
 
1096
                 gint           bpp,
 
1097
                 gint           numpix,
 
1098
                 guchar       **dst)
856
1099
{
857
 
  register guchar *rgb_src = src+1;
 
1100
  register const guchar *rgb_src = src+1;
858
1101
  register guchar *magenta_dst = dst[0];
859
1102
  register gint count = numpix, offset = bpp-1;
860
1103
 
867
1110
 
868
1111
 
869
1112
static void
870
 
extract_yellow (guchar  *src,
871
 
                gint     bpp,
872
 
                gint     numpix,
873
 
                guchar **dst)
 
1113
extract_yellow (const guchar  *src,
 
1114
                gint           bpp,
 
1115
                gint           numpix,
 
1116
                guchar       **dst)
874
1117
{
875
 
  register guchar *rgb_src = src+2;
 
1118
  register const guchar *rgb_src = src+2;
876
1119
  register guchar *yellow_dst = dst[0];
877
1120
  register gint count = numpix, offset = bpp-1;
878
1121
 
885
1128
 
886
1129
 
887
1130
static void
888
 
extract_cmyk (guchar  *src,
889
 
              gint     bpp,
890
 
              gint     numpix,
891
 
              guchar **dst)
 
1131
extract_cmyk (const guchar  *src,
 
1132
              gint           bpp,
 
1133
              gint           numpix,
 
1134
              guchar       **dst)
892
1135
 
893
1136
{
894
 
  register guchar *rgb_src = src;
 
1137
  register const guchar *rgb_src = src;
895
1138
  register guchar *cyan_dst = dst[0];
896
1139
  register guchar *magenta_dst = dst[1];
897
1140
  register guchar *yellow_dst = dst[2];
925
1168
 
926
1169
 
927
1170
static void
928
 
extract_cyank (guchar  *src,
929
 
               gint     bpp,
930
 
               gint     numpix,
931
 
               guchar **dst)
 
1171
extract_cyank (const guchar  *src,
 
1172
               gint           bpp,
 
1173
               gint           numpix,
 
1174
               guchar       **dst)
932
1175
{
933
 
  register guchar *rgb_src = src;
 
1176
  register const guchar *rgb_src = src;
934
1177
  register guchar *cyan_dst = dst[0];
935
1178
  register guchar s, k;
936
1179
  register gint count = numpix, offset = bpp-3;
951
1194
 
952
1195
 
953
1196
static void
954
 
extract_magentak (guchar  *src,
955
 
                  gint     bpp,
956
 
                  gint     numpix,
957
 
                  guchar **dst)
 
1197
extract_magentak (const guchar  *src,
 
1198
                  gint           bpp,
 
1199
                  gint           numpix,
 
1200
                  guchar       **dst)
958
1201
{
959
 
  register guchar *rgb_src = src;
 
1202
  register const guchar *rgb_src = src;
960
1203
  register guchar *magenta_dst = dst[0];
961
1204
  register guchar s, k;
962
1205
  register gint count = numpix, offset = bpp-3;
980
1223
 
981
1224
 
982
1225
static void
983
 
extract_yellowk (guchar  *src,
984
 
                 gint     bpp,
985
 
                 gint     numpix,
986
 
                 guchar **dst)
 
1226
extract_yellowk (const guchar  *src,
 
1227
                 gint           bpp,
 
1228
                 gint           numpix,
 
1229
                 guchar       **dst)
987
1230
 
988
1231
{
989
 
  register guchar *rgb_src = src;
 
1232
  register const guchar *rgb_src = src;
990
1233
  register guchar *yellow_dst = dst[0];
991
1234
  register guchar s, k;
992
1235
  register gint count = numpix, offset = bpp-3;
1008
1251
}
1009
1252
 
1010
1253
static void
1011
 
extract_lab (guchar  *src,
1012
 
             gint     bpp,
1013
 
             gint     numpix,
1014
 
             guchar **dst)
 
1254
extract_lab (const guchar  *src,
 
1255
             gint           bpp,
 
1256
             gint           numpix,
 
1257
             guchar       **dst)
1015
1258
{
1016
 
  register guchar *rgb_src = src;
 
1259
  register const guchar *rgb_src = src;
1017
1260
  register guchar *l_dst = dst[0];
1018
1261
  register guchar *a_dst = dst[1];
1019
1262
  register guchar *b_dst = dst[2];
1027
1270
 
1028
1271
  gdouble sixteenth = 16.0 / 116.0;
1029
1272
 
 
1273
  /* LAB colorspace constants */
 
1274
#define LAB_Xn 0.951
 
1275
#define LAB_Yn 1.0
 
1276
#define LAB_Zn 1.089
1030
1277
 
1031
1278
  while (count-- > 0)
1032
1279
    {
1038
1285
      y = 0.222 * red + 0.707 * green + 0.071 * blue;
1039
1286
      z = 0.020 * red + 0.130 * green + 0.939 * blue;
1040
1287
 
1041
 
      if (( ty = y/Yn ) > 0.008856)
 
1288
      if ((ty = y / LAB_Yn) > 0.008856)
1042
1289
        {
1043
 
          l   = 116.0 * cbrt( ty ) - 16.0;
1044
 
          fty = cbrt( ty );
 
1290
          l   = 116.0 * cbrt (ty) - 16.0;
 
1291
          fty = cbrt (ty);
1045
1292
        }
1046
1293
      else
1047
1294
        {
1048
 
          l   = 903.3 * ty;
1049
 
          fty = 7.78*ty + sixteenth;
 
1295
          l   = 903.3  * ty;
 
1296
          fty =   7.78 * ty + sixteenth;
1050
1297
        }
1051
1298
 
1052
 
      ftx = ((tx = x/Xn) > 0.008856) ? cbrt (tx) : 7.78 * tx + sixteenth;
1053
 
      ftz = ((tz = z/Zn) > 0.008856) ? cbrt (tz) : 7.78 * tz + sixteenth;
 
1299
      ftx = ((tx = x / LAB_Xn) > 0.008856) ? cbrt (tx) : 7.78 * tx + sixteenth;
 
1300
      ftz = ((tz = z / LAB_Zn) > 0.008856) ? cbrt (tz) : 7.78 * tz + sixteenth;
1054
1301
 
1055
1302
      *l_dst++ = (guchar) CLAMP (l * 2.5599, 0., 256.);
1056
1303
      *a_dst++ = (guchar) CLAMP (128.0 + (ftx - fty) * 635, 0., 256.);
1068
1315
#define FIXC(a) ((int)((a)*256.0*256.0*224.0/255.0 + 0.5))
1069
1316
 
1070
1317
static void
1071
 
extract_ycbcr470 (guchar  *src,
1072
 
                  gint     bpp,
1073
 
                  gint     numpix,
1074
 
                  guchar **dst)
 
1318
extract_ycbcr470 (const guchar  *src,
 
1319
                  gint           bpp,
 
1320
                  gint           numpix,
 
1321
                  guchar       **dst)
1075
1322
{
1076
 
  register guchar *rgb_src = src;
 
1323
  register const guchar *rgb_src = src;
1077
1324
  register guchar *y_dst  = dst[0];
1078
1325
  register guchar *cb_dst = dst[1];
1079
1326
  register guchar *cr_dst = dst[2];
1095
1342
 
1096
1343
 
1097
1344
static void
1098
 
extract_ycbcr709 (guchar  *src,
1099
 
                  gint     bpp,
1100
 
                  gint     numpix,
1101
 
                  guchar **dst)
 
1345
extract_ycbcr709 (const guchar  *src,
 
1346
                  gint           bpp,
 
1347
                  gint           numpix,
 
1348
                  guchar       **dst)
1102
1349
{
1103
 
  register guchar *rgb_src = src;
 
1350
  register const guchar *rgb_src = src;
1104
1351
  register guchar *y_dst  = dst[0];
1105
1352
  register guchar *cb_dst = dst[1];
1106
1353
  register guchar *cr_dst = dst[2];
1122
1369
 
1123
1370
 
1124
1371
static void
1125
 
extract_ycbcr470f (guchar  *src,
1126
 
                   gint     bpp,
1127
 
                   gint     numpix,
1128
 
                   guchar **dst)
 
1372
extract_ycbcr470f (const guchar  *src,
 
1373
                   gint           bpp,
 
1374
                   gint           numpix,
 
1375
                   guchar       **dst)
1129
1376
{
1130
 
  register guchar *rgb_src = src;
 
1377
  register const guchar *rgb_src = src;
1131
1378
  register guchar *y_dst  = dst[0];
1132
1379
  register guchar *cb_dst = dst[1];
1133
1380
  register guchar *cr_dst = dst[2];
1152
1399
 
1153
1400
 
1154
1401
static void
1155
 
extract_ycbcr709f (guchar  *src,
1156
 
             gint     bpp,
1157
 
             gint     numpix,
1158
 
             guchar **dst)
 
1402
extract_ycbcr709f (const guchar  *src,
 
1403
                   gint           bpp,
 
1404
                   gint           numpix,
 
1405
                   guchar       **dst)
1159
1406
{
1160
 
  register guchar *rgb_src = src;
 
1407
  register const guchar *rgb_src = src;
1161
1408
  register guchar *y_dst  = dst[0];
1162
1409
  register guchar *cb_dst = dst[1];
1163
1410
  register guchar *cr_dst = dst[2];
1185
1432
static gboolean
1186
1433
decompose_dialog (void)
1187
1434
{
1188
 
  GtkWidget *dlg;
 
1435
  GtkWidget *dialog;
1189
1436
  GtkWidget *main_vbox;
1190
 
  GtkWidget *toggle;
1191
1437
  GtkWidget *frame;
1192
1438
  GtkWidget *vbox;
1193
 
  GSList    *group;
 
1439
  GtkWidget *hbox;
 
1440
  GtkWidget *label;
 
1441
  GtkWidget *combo;
 
1442
  GtkWidget *toggle;
1194
1443
  gint       j;
 
1444
  gint       extract_idx;
1195
1445
  gboolean   run;
1196
1446
 
1197
 
  gimp_ui_init ("decompose", FALSE);
1198
 
 
1199
 
  dlg = gimp_dialog_new (_("Decompose"), "decompose",
1200
 
                         NULL, 0,
1201
 
                         gimp_standard_help_func, "plug-in-decompose",
1202
 
 
1203
 
                         GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1204
 
                         GTK_STOCK_OK,     GTK_RESPONSE_OK,
1205
 
 
1206
 
                         NULL);
 
1447
  extract_idx = 0;
 
1448
  for (j = 0; j < G_N_ELEMENTS (extract); j++)
 
1449
    {
 
1450
      if (extract[j].dialog &&
 
1451
          g_ascii_strcasecmp (decovals.extract_type, extract[j].type) == 0)
 
1452
        {
 
1453
          extract_idx = j;
 
1454
          break;
 
1455
        }
 
1456
    }
 
1457
 
 
1458
  gimp_ui_init (PLUG_IN_BINARY, FALSE);
 
1459
 
 
1460
  dialog = gimp_dialog_new (_("Decompose"), PLUG_IN_BINARY,
 
1461
                            NULL, 0,
 
1462
                            gimp_standard_help_func, PLUG_IN_PROC,
 
1463
 
 
1464
                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 
1465
                            GTK_STOCK_OK,     GTK_RESPONSE_OK,
 
1466
 
 
1467
                            NULL);
 
1468
 
 
1469
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
 
1470
                                           GTK_RESPONSE_OK,
 
1471
                                           GTK_RESPONSE_CANCEL,
 
1472
                                           -1);
 
1473
 
 
1474
  gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
 
1475
  gimp_window_set_transient (GTK_WINDOW (dialog));
1207
1476
 
1208
1477
  main_vbox = gtk_vbox_new (FALSE, 12);
1209
1478
  gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
1210
 
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), main_vbox,
 
1479
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), main_vbox,
1211
1480
                      TRUE, TRUE, 0);
1212
1481
  gtk_widget_show (main_vbox);
1213
1482
 
1214
 
  /*  parameter settings  */
1215
1483
  frame = gimp_frame_new (_("Extract Channels"));
1216
1484
  gtk_box_pack_start (GTK_BOX (main_vbox), frame, TRUE, TRUE, 0);
 
1485
  gtk_widget_show (frame);
1217
1486
 
1218
 
  vbox = gtk_vbox_new (FALSE, 2);
 
1487
  vbox = gtk_vbox_new (FALSE, 6);
1219
1488
  gtk_container_add (GTK_CONTAINER (frame), vbox);
1220
 
 
1221
 
  group = NULL;
 
1489
  gtk_widget_show (vbox);
 
1490
 
 
1491
  hbox = gtk_hbox_new (FALSE, 6);
 
1492
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
 
1493
  gtk_widget_show (hbox);
 
1494
 
 
1495
  label = gtk_label_new_with_mnemonic (_("Color _model:"));
 
1496
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
 
1497
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
 
1498
  gtk_widget_show (label);
 
1499
 
 
1500
  combo = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
1222
1501
  for (j = 0; j < G_N_ELEMENTS (extract); j++)
1223
1502
    {
1224
 
      if (!extract[j].dialog)
1225
 
        continue;
1226
 
 
1227
 
      toggle = gtk_radio_button_new_with_label (group,
1228
 
                                                gettext (extract[j].type));
1229
 
      group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (toggle));
1230
 
      gtk_box_pack_start (GTK_BOX (vbox), toggle, TRUE, TRUE, 0);
1231
 
      decoint.extract_flag[j] =
1232
 
        (g_ascii_strcasecmp (decovals.extract_type, extract[j].type) == 0);
1233
 
      gtk_widget_show (toggle);
1234
 
 
1235
 
      g_signal_connect (toggle, "toggled",
1236
 
                        G_CALLBACK (gimp_toggle_button_update),
1237
 
                        &(decoint.extract_flag[j]));
1238
 
 
1239
 
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
1240
 
                                    decoint.extract_flag[j]);
 
1503
      if (extract[j].dialog)
 
1504
        {
 
1505
          gchar *label = g_strdup (gettext (extract[j].type));
 
1506
          gchar *l;
 
1507
 
 
1508
          for (l = label; *l; l++)
 
1509
            if (*l == '-' || *l == '_')
 
1510
              *l = ' ';
 
1511
 
 
1512
          gimp_int_combo_box_append (GIMP_INT_COMBO_BOX (combo),
 
1513
                                     GIMP_INT_STORE_LABEL, label,
 
1514
                                     GIMP_INT_STORE_VALUE, j,
 
1515
                                     -1);
 
1516
          g_free (label);
 
1517
        }
1241
1518
    }
1242
1519
 
1243
 
  toggle = gtk_check_button_new_with_mnemonic (_("Decompose to _layers"));
 
1520
  gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
 
1521
  gtk_widget_show (combo);
 
1522
 
 
1523
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
 
1524
 
 
1525
  gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
 
1526
                              extract_idx,
 
1527
                              G_CALLBACK (gimp_int_combo_box_get_active),
 
1528
                              &extract_idx);
 
1529
 
 
1530
  toggle = gtk_check_button_new_with_mnemonic (_("_Decompose to layers"));
 
1531
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
 
1532
                                decovals.as_layers);
1244
1533
  gtk_box_pack_start (GTK_BOX (main_vbox), toggle, FALSE, FALSE, 0);
 
1534
  gtk_widget_show (toggle);
 
1535
 
1245
1536
  g_signal_connect (toggle, "toggled",
1246
1537
                    G_CALLBACK (gimp_toggle_button_update),
1247
1538
                    &decovals.as_layers);
 
1539
 
 
1540
  toggle =
 
1541
    gtk_check_button_new_with_mnemonic (_("_Foreground as registration color"));
 
1542
  gimp_help_set_help_data (toggle, _("Pixels in the foreground color will "
 
1543
                                     "appear black in all output images.  "
 
1544
                                     "This can be used for things like crop "
 
1545
                                     "marks that have to show up on all "
 
1546
                                     "channels."), PLUG_IN_PROC);
1248
1547
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
1249
 
                                decovals.as_layers);
 
1548
                                decovals.use_registration);
 
1549
  gtk_box_pack_start (GTK_BOX (main_vbox), toggle, FALSE, FALSE, 0);
1250
1550
  gtk_widget_show (toggle);
1251
1551
 
1252
 
  gtk_widget_show (vbox);
1253
 
  gtk_widget_show (frame);
1254
 
  gtk_widget_show (dlg);
1255
 
 
1256
 
  run = (gimp_dialog_run (GIMP_DIALOG (dlg)) == GTK_RESPONSE_OK);
1257
 
 
1258
 
  gtk_widget_destroy (dlg);
 
1552
  g_signal_connect (toggle, "toggled",
 
1553
                    G_CALLBACK (gimp_toggle_button_update),
 
1554
                    &decovals.use_registration);
 
1555
 
 
1556
  gtk_widget_show (dialog);
 
1557
 
 
1558
  run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
 
1559
 
 
1560
  gtk_widget_destroy (dialog);
1259
1561
 
1260
1562
  if (run)
1261
 
    {
1262
 
      gint j;
1263
 
 
1264
 
      for (j = 0; j < G_N_ELEMENTS (extract); j++)
1265
 
        {
1266
 
          if (decoint.extract_flag[j])
1267
 
            {
1268
 
              strcpy (decovals.extract_type, extract[j].type);
1269
 
              break;
1270
 
            }
1271
 
        }
1272
 
    }
 
1563
    strcpy (decovals.extract_type, extract[extract_idx].type);
1273
1564
 
1274
1565
  return run;
1275
1566
}