00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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);
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 }