gimpcmyk.c 6.54 KB
Newer Older
1 2 3
/* LIBGIMP - The GIMP Library
 * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
 *
4
 * This library is free software: you can redistribute it and/or
5 6
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
7
 * version 3 of the License, or (at your option) any later version.
8 9 10 11 12 13 14
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
15
 * License along with this library.  If not, see
16
 * <https://www.gnu.org/licenses/>.
17 18 19 20
 */

#include "config.h"

21
#include <glib-object.h>
22 23 24 25 26 27 28 29

#include "libgimpmath/gimpmath.h"

#include "gimpcolortypes.h"

#include "gimpcmyk.h"


30
/**
31
 * SECTION: gimpcmyk
32 33 34 35 36 37 38
 * @title: GimpCMYK
 * @short_description: Definitions and Functions relating to CMYK colors.
 *
 * Definitions and Functions relating to CMYK colors.
 **/


39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
/*
 * GIMP_TYPE_CMYK
 */

static GimpCMYK * gimp_cmyk_copy (const GimpCMYK *cmyk);


GType
gimp_cmyk_get_type (void)
{
  static GType cmyk_type = 0;

  if (!cmyk_type)
    cmyk_type = g_boxed_type_register_static ("GimpCMYK",
                                              (GBoxedCopyFunc) gimp_cmyk_copy,
                                              (GBoxedFreeFunc) g_free);

  return cmyk_type;
}

static GimpCMYK *
gimp_cmyk_copy (const GimpCMYK *cmyk)
{
  return g_memdup (cmyk, sizeof (GimpCMYK));
}


66 67
/*  CMYK functions  */

Dave Neary's avatar
Dave Neary committed
68 69
/**
 * gimp_cmyk_set:
70 71 72 73 74
 * @cmyk:    A #GimpCMYK structure which will hold the specified CMYK value.
 * @cyan:    The Cyan channel of the CMYK value
 * @magenta: The Magenta channel
 * @yellow:  The Yellow channel
 * @black:   The blacK channel
Dave Neary's avatar
Dave Neary committed
75
 *
76
 * Very basic initialiser for the internal #GimpCMYK structure. Channel
Dave Neary's avatar
Dave Neary committed
77 78
 * values are doubles in the range 0 to 1.
 **/
79 80
void
gimp_cmyk_set (GimpCMYK *cmyk,
81 82 83 84
               gdouble   cyan,
               gdouble   magenta,
               gdouble   yellow,
               gdouble   black)
85 86 87
{
  g_return_if_fail (cmyk != NULL);

88 89 90 91
  cmyk->c = cyan;
  cmyk->m = magenta;
  cmyk->y = yellow;
  cmyk->k = black;
92 93
}

Dave Neary's avatar
Dave Neary committed
94 95
/**
 * gimp_cmyk_set_uchar:
96 97 98 99 100
 * @cmyk:    A #GimpCMYK structure which will hold the specified CMYK value.
 * @cyan:    The Cyan channel of the CMYK value
 * @magenta: The Magenta channel
 * @yellow:  The Yellow channel
 * @black:   The blacK channel
Dave Neary's avatar
Dave Neary committed
101
 *
102 103
 * The same as gimp_cmyk_set(), except that channel values are
 * unsigned chars in the range 0 to 255.
Dave Neary's avatar
Dave Neary committed
104
 **/
105 106
void
gimp_cmyk_set_uchar (GimpCMYK *cmyk,
107 108 109 110
                     guchar    cyan,
                     guchar    magenta,
                     guchar    yellow,
                     guchar    black)
111 112 113
{
  g_return_if_fail (cmyk != NULL);

114 115 116 117
  cmyk->c = (gdouble) cyan    / 255.0;
  cmyk->m = (gdouble) magenta / 255.0;
  cmyk->y = (gdouble) yellow  / 255.0;
  cmyk->k = (gdouble) black   / 255.0;
118 119
}

Dave Neary's avatar
Dave Neary committed
120 121
/**
 * gimp_cmyk_get_uchar:
122 123 124 125 126
 * @cmyk:    A #GimpCMYK structure which will hold the specified CMYK value.
 * @cyan:    The Cyan channel of the CMYK value
 * @magenta: The Magenta channel
 * @yellow:  The Yellow channel
 * @black:   The blacK channel
Dave Neary's avatar
Dave Neary committed
127
 *
128
 * Retrieve individual channel values from a #GimpCMYK structure. Channel
Dave Neary's avatar
Dave Neary committed
129 130
 * values are pointers to unsigned chars in the range 0 to 255.
 **/
131 132
void
gimp_cmyk_get_uchar (const GimpCMYK *cmyk,
133 134 135 136
                     guchar         *cyan,
                     guchar         *magenta,
                     guchar         *yellow,
                     guchar         *black)
137 138 139
{
  g_return_if_fail (cmyk != NULL);

140 141 142 143
  if (cyan)    *cyan    = ROUND (CLAMP (cmyk->c, 0.0, 1.0) * 255.0);
  if (magenta) *magenta = ROUND (CLAMP (cmyk->m, 0.0, 1.0) * 255.0);
  if (yellow)  *yellow  = ROUND (CLAMP (cmyk->y, 0.0, 1.0) * 255.0);
  if (black)   *black   = ROUND (CLAMP (cmyk->k, 0.0, 1.0) * 255.0);
144 145 146 147 148
}


/*  CMYKA functions  */

Dave Neary's avatar
Dave Neary committed
149 150
/**
 * gimp_cmyka_set:
151 152 153 154 155 156
 * @cmyka:   A #GimpCMYK structure which will hold the specified CMYKA value.
 * @cyan:    The Cyan channel of the CMYK value
 * @magenta: The Magenta channel
 * @yellow:  The Yellow channel
 * @black:   The blacK channel
 * @alpha:   The Alpha channel
Dave Neary's avatar
Dave Neary committed
157
 *
158
 * Initialiser for the internal #GimpCMYK structure. Channel values are
Dave Neary's avatar
Dave Neary committed
159 160
 * doubles in the range 0 to 1.
 **/
161 162
void
gimp_cmyka_set (GimpCMYK *cmyka,
163 164 165 166 167
                gdouble   cyan,
                gdouble   magenta,
                gdouble   yellow,
                gdouble   black,
                gdouble   alpha)
168 169 170
{
  g_return_if_fail (cmyka != NULL);

171 172 173 174 175
  cmyka->c = cyan;
  cmyka->m = magenta;
  cmyka->y = yellow;
  cmyka->k = black;
  cmyka->a = alpha;
176 177
}

Dave Neary's avatar
Dave Neary committed
178 179
/**
 * gimp_cmyka_set_uchar:
180 181 182 183 184 185
 * @cmyka:   A #GimpCMYK structure which will hold the specified CMYKA value.
 * @cyan:    The Cyan channel of the CMYK value
 * @magenta: The Magenta channel
 * @yellow:  The Yellow channel
 * @black:   The blacK channel
 * @alpha:   The Alpha channel
Dave Neary's avatar
Dave Neary committed
186
 *
187 188
 * The same as gimp_cmyka_set(), except that channel values are
 * unsigned chars in the range 0 to 255.
Dave Neary's avatar
Dave Neary committed
189
 **/
190 191
void
gimp_cmyka_set_uchar (GimpCMYK *cmyka,
192 193 194 195 196
                      guchar    cyan,
                      guchar    magenta,
                      guchar    yellow,
                      guchar    black,
                      guchar    alpha)
197 198 199
{
  g_return_if_fail (cmyka != NULL);

200 201 202 203 204
  cmyka->c = (gdouble) cyan    / 255.0;
  cmyka->m = (gdouble) magenta / 255.0;
  cmyka->y = (gdouble) yellow  / 255.0;
  cmyka->k = (gdouble) black   / 255.0;
  cmyka->a = (gdouble) alpha   / 255.0;
205
}
Dave Neary's avatar
Dave Neary committed
206 207
/**
 * gimp_cmyka_get_uchar:
208 209 210 211 212 213
 * @cmyka:   A #GimpCMYK structure which will hold the specified CMYKA value.
 * @cyan:    The Cyan channel of the CMYK value
 * @magenta: The Magenta channel
 * @yellow:  The Yellow channel
 * @black:   The blacK channel
 * @alpha:   The Alpha channel
Dave Neary's avatar
Dave Neary committed
214
 *
215 216
 * Retrieve individual channel values from a #GimpCMYK structure.
 * Channel values are pointers to unsigned chars in the range 0 to 255.
Dave Neary's avatar
Dave Neary committed
217
 **/
218 219
void
gimp_cmyka_get_uchar (const GimpCMYK *cmyka,
220 221 222 223 224
                      guchar         *cyan,
                      guchar         *magenta,
                      guchar         *yellow,
                      guchar         *black,
                      guchar         *alpha)
225 226 227
{
  g_return_if_fail (cmyka != NULL);

228 229 230 231 232
  if (cyan)    *cyan    = ROUND (CLAMP (cmyka->c, 0.0, 1.0) * 255.0);
  if (magenta) *magenta = ROUND (CLAMP (cmyka->m, 0.0, 1.0) * 255.0);
  if (yellow)  *yellow  = ROUND (CLAMP (cmyka->y, 0.0, 1.0) * 255.0);
  if (black)   *black   = ROUND (CLAMP (cmyka->k, 0.0, 1.0) * 255.0);
  if (alpha)   *alpha   = ROUND (CLAMP (cmyka->a, 0.0, 1.0) * 255.0);
233
}