~ubuntu-branches/ubuntu/hoary/gimp/hoary

« back to all changes in this revision

Viewing changes to libgimpcolor/gimpcmyk.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2005-04-04 14:51:23 UTC
  • Revision ID: james.westby@ubuntu.com-20050404145123-9py049eeelfymur8
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* LIBGIMP - The GIMP Library
 
2
 * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Lesser General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2 of the License, or (at your option) any later version.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * Library General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Lesser General Public
 
15
 * License along with this library; if not, write to the
 
16
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
 * Boston, MA 02111-1307, USA.
 
18
 */
 
19
 
 
20
#include "config.h"
 
21
 
 
22
#include <glib.h>
 
23
 
 
24
#include "libgimpmath/gimpmath.h"
 
25
 
 
26
#include "gimpcolortypes.h"
 
27
 
 
28
#include "gimpcmyk.h"
 
29
 
 
30
 
 
31
/*  CMYK functions  */
 
32
 
 
33
/**
 
34
 * gimp_cmyk_set:
 
35
 * @cmyk:    A #GimpCMYK structure which will hold the specified CMYK value.
 
36
 * @cyan:    The Cyan channel of the CMYK value
 
37
 * @magenta: The Magenta channel
 
38
 * @yellow:  The Yellow channel
 
39
 * @black:   The blacK channel
 
40
 *
 
41
 * Very basic initialiser for the internal #GimpCMYK structure. Channel
 
42
 * values are doubles in the range 0 to 1.
 
43
 **/
 
44
void
 
45
gimp_cmyk_set (GimpCMYK *cmyk,
 
46
               gdouble   cyan,
 
47
               gdouble   magenta,
 
48
               gdouble   yellow,
 
49
               gdouble   black)
 
50
{
 
51
  g_return_if_fail (cmyk != NULL);
 
52
 
 
53
  cmyk->c = cyan;
 
54
  cmyk->m = magenta;
 
55
  cmyk->y = yellow;
 
56
  cmyk->k = black;
 
57
}
 
58
 
 
59
/**
 
60
 * gimp_cmyk_set_uchar:
 
61
 * @cmyk:    A #GimpCMYK structure which will hold the specified CMYK value.
 
62
 * @cyan:    The Cyan channel of the CMYK value
 
63
 * @magenta: The Magenta channel
 
64
 * @yellow:  The Yellow channel
 
65
 * @black:   The blacK channel
 
66
 *
 
67
 * The same as gimp_cmyk_set(), except that channel values are
 
68
 * unsigned chars in the range 0 to 255.
 
69
 **/
 
70
void
 
71
gimp_cmyk_set_uchar (GimpCMYK *cmyk,
 
72
                     guchar    cyan,
 
73
                     guchar    magenta,
 
74
                     guchar    yellow,
 
75
                     guchar    black)
 
76
{
 
77
  g_return_if_fail (cmyk != NULL);
 
78
 
 
79
  cmyk->c = (gdouble) cyan    / 255.0;
 
80
  cmyk->m = (gdouble) magenta / 255.0;
 
81
  cmyk->y = (gdouble) yellow  / 255.0;
 
82
  cmyk->k = (gdouble) black   / 255.0;
 
83
}
 
84
 
 
85
/**
 
86
 * gimp_cmyk_get_uchar:
 
87
 * @cmyk:    A #GimpCMYK structure which will hold the specified CMYK value.
 
88
 * @cyan:    The Cyan channel of the CMYK value
 
89
 * @magenta: The Magenta channel
 
90
 * @yellow:  The Yellow channel
 
91
 * @black:   The blacK channel
 
92
 *
 
93
 * Retrieve individual channel values from a #GimpCMYK structure. Channel
 
94
 * values are pointers to unsigned chars in the range 0 to 255.
 
95
 **/
 
96
void
 
97
gimp_cmyk_get_uchar (const GimpCMYK *cmyk,
 
98
                     guchar         *cyan,
 
99
                     guchar         *magenta,
 
100
                     guchar         *yellow,
 
101
                     guchar         *black)
 
102
{
 
103
  g_return_if_fail (cmyk != NULL);
 
104
 
 
105
  if (cyan)    *cyan    = ROUND (CLAMP (cmyk->c, 0.0, 1.0) * 255.0);
 
106
  if (magenta) *magenta = ROUND (CLAMP (cmyk->m, 0.0, 1.0) * 255.0);
 
107
  if (yellow)  *yellow  = ROUND (CLAMP (cmyk->y, 0.0, 1.0) * 255.0);
 
108
  if (black)   *black   = ROUND (CLAMP (cmyk->k, 0.0, 1.0) * 255.0);
 
109
}
 
110
 
 
111
 
 
112
/*  CMYKA functions  */
 
113
 
 
114
/**
 
115
 * gimp_cmyka_set:
 
116
 * @cmyka:   A #GimpCMYK structure which will hold the specified CMYKA value.
 
117
 * @cyan:    The Cyan channel of the CMYK value
 
118
 * @magenta: The Magenta channel
 
119
 * @yellow:  The Yellow channel
 
120
 * @black:   The blacK channel
 
121
 * @alpha:   The Alpha channel
 
122
 *
 
123
 * Initialiser for the internal #GimpCMYK structure. Channel values are
 
124
 * doubles in the range 0 to 1.
 
125
 **/
 
126
void
 
127
gimp_cmyka_set (GimpCMYK *cmyka,
 
128
                gdouble   cyan,
 
129
                gdouble   magenta,
 
130
                gdouble   yellow,
 
131
                gdouble   black,
 
132
                gdouble   alpha)
 
133
{
 
134
  g_return_if_fail (cmyka != NULL);
 
135
 
 
136
  cmyka->c = cyan;
 
137
  cmyka->m = magenta;
 
138
  cmyka->y = yellow;
 
139
  cmyka->k = black;
 
140
  cmyka->a = alpha;
 
141
}
 
142
 
 
143
/**
 
144
 * gimp_cmyka_set_uchar:
 
145
 * @cmyka:   A #GimpCMYK structure which will hold the specified CMYKA value.
 
146
 * @cyan:    The Cyan channel of the CMYK value
 
147
 * @magenta: The Magenta channel
 
148
 * @yellow:  The Yellow channel
 
149
 * @black:   The blacK channel
 
150
 * @alpha:   The Alpha channel
 
151
 *
 
152
 * The same as gimp_cmyka_set(), except that channel values are
 
153
 * unsigned chars in the range 0 to 255.
 
154
 **/
 
155
void
 
156
gimp_cmyka_set_uchar (GimpCMYK *cmyka,
 
157
                      guchar    cyan,
 
158
                      guchar    magenta,
 
159
                      guchar    yellow,
 
160
                      guchar    black,
 
161
                      guchar    alpha)
 
162
{
 
163
  g_return_if_fail (cmyka != NULL);
 
164
 
 
165
  cmyka->c = (gdouble) cyan    / 255.0;
 
166
  cmyka->m = (gdouble) magenta / 255.0;
 
167
  cmyka->y = (gdouble) yellow  / 255.0;
 
168
  cmyka->k = (gdouble) black   / 255.0;
 
169
  cmyka->a = (gdouble) alpha   / 255.0;
 
170
}
 
171
/**
 
172
 * gimp_cmyka_get_uchar:
 
173
 * @cmyka:   A #GimpCMYK structure which will hold the specified CMYKA value.
 
174
 * @cyan:    The Cyan channel of the CMYK value
 
175
 * @magenta: The Magenta channel
 
176
 * @yellow:  The Yellow channel
 
177
 * @black:   The blacK channel
 
178
 * @alpha:   The Alpha channel
 
179
 *
 
180
 * Retrieve individual channel values from a #GimpCMYK structure.
 
181
 * Channel values are pointers to unsigned chars in the range 0 to 255.
 
182
 **/
 
183
void
 
184
gimp_cmyka_get_uchar (const GimpCMYK *cmyka,
 
185
                      guchar         *cyan,
 
186
                      guchar         *magenta,
 
187
                      guchar         *yellow,
 
188
                      guchar         *black,
 
189
                      guchar         *alpha)
 
190
{
 
191
  g_return_if_fail (cmyka != NULL);
 
192
 
 
193
  if (cyan)    *cyan    = ROUND (CLAMP (cmyka->c, 0.0, 1.0) * 255.0);
 
194
  if (magenta) *magenta = ROUND (CLAMP (cmyka->m, 0.0, 1.0) * 255.0);
 
195
  if (yellow)  *yellow  = ROUND (CLAMP (cmyka->y, 0.0, 1.0) * 255.0);
 
196
  if (black)   *black   = ROUND (CLAMP (cmyka->k, 0.0, 1.0) * 255.0);
 
197
  if (alpha)   *alpha   = ROUND (CLAMP (cmyka->a, 0.0, 1.0) * 255.0);
 
198
}