Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals  

src/main/color-cmyk.c

Go to the documentation of this file.
00001 /*
00002  * "$Id: print-color.c,v 1.106.2.31 2004/03/25 01:01:05 rlk Exp $"
00003  *
00004  *   Gimp-Print color management module - traditional Gimp-Print algorithm.
00005  *
00006  *   Copyright 1997-2000 Michael Sweet (mike@easysw.com) and
00007  *      Robert Krawitz (rlk@alum.mit.edu)
00008  *
00009  *   This program is free software; you can redistribute it and/or modify it
00010  *   under the terms of the GNU General Public License as published by the Free
00011  *   Software Foundation; either version 2 of the License, or (at your option)
00012  *   any later version.
00013  *
00014  *   This program is distributed in the hope that it will be useful, but
00015  *   WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00016  *   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00017  *   for more details.
00018  *
00019  *   You should have received a copy of the GNU General Public License
00020  *   along with this program; if not, write to the Free Software
00021  *   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00022  */
00023 
00024 /*
00025  * This file must include only standard C header files.  The core code must
00026  * compile on generic platforms that don't support glib, gimp, gtk, etc.
00027  */
00028 
00029 #ifdef HAVE_CONFIG_H
00030 #include <config.h>
00031 #endif
00032 #include <gimp-print/gimp-print.h>
00033 #include "gimp-print-internal.h"
00034 #include <gimp-print/gimp-print-intl-internal.h>
00035 #include <math.h>
00036 #ifdef HAVE_LIMITS_H
00037 #include <limits.h>
00038 #endif
00039 #include <string.h>
00040 #include "lut.h"
00041 
00042 #ifdef __GNUC__
00043 #define inline __inline__
00044 #endif
00045 
00046 static inline int
00047 mem_eq(const unsigned short *i1, const unsigned short *i2, int count)
00048 {
00049   int i;
00050   for (i = 0; i < count; i++)
00051     if (i1[i] != i2[i])
00052       return 0;
00053   return 1;
00054 }
00055 
00056 static unsigned
00057 generic_cmy_to_kcmy(stp_const_vars_t vars, const unsigned short *in,
00058                     unsigned short *out)
00059 {
00060   lut_t *lut = (lut_t *)(stpi_get_component_data(vars, "Color"));
00061   int width = lut->image_width;
00062   int step = 65535 / (lut->steps - 1); /* 1 or 257 */
00063 
00064   const unsigned short *gcr_lookup;
00065   const unsigned short *black_lookup;
00066   int i;
00067   int j;
00068   unsigned short nz[4];
00069   unsigned retval = 0;
00070   const unsigned short *input_cache = NULL;
00071   const unsigned short *output_cache = NULL;
00072 
00073   gcr_lookup = cache_get_ushort_data(&(lut->gcr_curve));
00074   stp_curve_resample(cache_get_curve(&(lut->channel_curves[CHANNEL_K])),
00075                      lut->steps);
00076   black_lookup = cache_get_ushort_data(&(lut->channel_curves[CHANNEL_K]));
00077   memset(nz, 0, sizeof(nz));
00078 
00079   for (i = 0; i < width; i++, out += 4, in += 3)
00080     {
00081       if (input_cache && mem_eq(input_cache, in, 3))
00082         {
00083           for (j = 0; j < 4; j++)
00084             out[j] = output_cache[j];
00085         }
00086       else
00087         {
00088           int c = in[0];
00089           int m = in[1];
00090           int y = in[2];
00091           int k = FMIN(c, FMIN(m, y));
00092           input_cache = in;
00093           out[0] = 0;
00094           for (j = 0; j < 3; j++)
00095             out[j + 1] = in[j];
00096           if (k > 0)
00097             {
00098               int where, resid;
00099               int kk;
00100               if (lut->steps == 65536)
00101                 kk = gcr_lookup[k];
00102               else
00103                 {
00104                   where = k / step;
00105                   resid = k % step;
00106                   kk = gcr_lookup[where];
00107                   if (resid > 0)
00108                     kk += (gcr_lookup[where + 1] - gcr_lookup[where]) * resid /
00109                       step;
00110                 }
00111               if (kk > k)
00112                 kk = k;
00113               if (kk > 0)
00114                 {
00115                   if (lut->steps == 65536)
00116                     out[0] = black_lookup[kk];
00117                   else
00118                     {
00119                       int k_out;
00120                       where = kk / step;
00121                       resid = kk % step;
00122                       k_out = black_lookup[where];
00123                       if (resid > 0)
00124                         k_out +=
00125                           (black_lookup[where + 1] - black_lookup[where]) * resid /
00126                           step;
00127                       out[0] = k_out;
00128                     }
00129                   out[1] -= kk;
00130                   out[2] -= kk;
00131                   out[3] -= kk;
00132                 }
00133             }
00134           output_cache = out;
00135           for (j = 0; j < 4; j++)
00136             if (out[j])
00137               nz[j] = 1;
00138         }
00139     }
00140   for (j = 0; j < 4; j++)
00141     if (nz[j] == 0)
00142       retval |= (1 << j);
00143   return retval;
00144 }
00145 
00146 static unsigned
00147 raw_cmy_to_kcmy(stp_const_vars_t vars, const unsigned short *in,
00148                 unsigned short *out)
00149 {
00150   lut_t *lut = (lut_t *)(stpi_get_component_data(vars, "Color"));
00151   int width = lut->image_width;
00152 
00153   int i;
00154   int j;
00155   unsigned short nz[4];
00156   unsigned retval = 0;
00157   const unsigned short *input_cache = NULL;
00158   const unsigned short *output_cache = NULL;
00159 
00160   memset(nz, 0, sizeof(nz));
00161 
00162   for (i = 0; i < width; i++, out += 4, in += 3)
00163     {
00164       if (input_cache && mem_eq(input_cache, in, 3))
00165         {
00166           for (j = 0; j < 4; j++)
00167             out[j] = output_cache[j];
00168         }
00169       else
00170         {
00171           int c = in[0];
00172           int m = in[1];
00173           int y = in[2];
00174           int k = FMIN(c, FMIN(m, y));
00175           input_cache = in;
00176           out[0] = 0;
00177           for (j = 0; j < 3; j++)
00178             out[j + 1] = in[j];
00179           if (k > 0)
00180             {
00181               out[0] = k;
00182               out[1] -= k;
00183               out[2] -= k;
00184               out[3] -= k;
00185             }
00186           output_cache = out;
00187           for (j = 0; j < 4; j++)
00188             if (out[j])
00189               nz[j] = 1;
00190         }
00191     }
00192   for (j = 0; j < 4; j++)
00193     if (nz[j] == 0)
00194       retval |= (1 << j);
00195   return retval;
00196 }

Generated on Wed May 12 20:21:27 2004 for libgimpprint API Reference by doxygen1.2.17