Commit 84fd11ad authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

allow to specify the amount of black pullout. Documented the function.

2003-09-02  Sven Neumann  <sven@gimp.org>

	* libgimpcolor/gimpcolorspace.c (gimp_rgb_to_cmyk_int): allow to
	specify the amount of black pullout. Documented the function.

	* plug-ins/common/newsprint.c: use the RGB to CMYK routine from
	libgimpcolor.
parent 138bab29
2003-09-02 Sven Neumann <sven@gimp.org>
* libgimpcolor/gimpcolorspace.c (gimp_rgb_to_cmyk_int): allow to
specify the amount of black pullout. Documented the function.
* plug-ins/common/newsprint.c: use the RGB to CMYK routine from
libgimpcolor.
2003-09-02 Sven Neumann <sven@gimp.org> 2003-09-02 Sven Neumann <sven@gimp.org>
* app/tools/gimpdrawtool.[ch]: added new function * app/tools/gimpdrawtool.[ch]: added new function
...@@ -706,27 +706,51 @@ gimp_hls_to_rgb_int (gint *hue, ...@@ -706,27 +706,51 @@ gimp_hls_to_rgb_int (gint *hue,
} }
} }
/**
* gimp_rgb_to_cmyk_int:
* @red: the red channel; returns the cyan value (0-255)
* @green: the green channel; returns the magenta value (0-255)
* @blue: the blue channel; returns the yellow value (0-255)
* @pullout: the maximum amount of black to pull out; returns
* the black value (0-255)
*
* Does a naive conversion from RGB to CMYK colorspace. A simple
* formula that doesn't take any color-profiles into account is used.
* The amount of black pullout how can be controlled via the @pullout
* parameter. A @pullout value of 0 makes this a conversion to CMY.
* For most cases, @pullout should be choosen as 255.
**/
void void
gimp_rgb_to_cmyk_int (gint *red, gimp_rgb_to_cmyk_int (gint *red,
gint *green, gint *green,
gint *blue, gint *blue,
gint *black) gint *pullout)
{ {
gint c, m, y, k; gint c, m, y;
c = 255 - *red; c = 255 - *red;
m = 255 - *green; m = 255 - *green;
y = 255 - *blue; y = 255 - *blue;
k = 255; if (*pullout == 0)
if (c < k) k = c; {
if (m < k) k = m; *red = c;
if (y < k) k = y; *green = m;
*blue = y;
}
else
{
gint k = CLAMP (*pullout, 0, 255);
if (c < k) k = c;
if (m < k) k = m;
if (y < k) k = y;
*red = ((c - k) << 8) / (256 - k); *red = ((c - k) << 8) / (256 - k);
*green = ((m - k) << 8) / (256 - k); *green = ((m - k) << 8) / (256 - k);
*blue = ((y - k) << 8) / (256 - k); *blue = ((y - k) << 8) / (256 - k);
*black = k; *pullout = k;
}
} }
void void
......
...@@ -207,7 +207,7 @@ static spot_info_t spotfn_list[] = ...@@ -207,7 +207,7 @@ static spot_info_t spotfn_list[] =
#define VALID_SPOTFN(x) ((x) >= 0 && (x) < NUM_SPOTFN) #define VALID_SPOTFN(x) ((x) >= 0 && (x) < NUM_SPOTFN)
#define THRESH(x,y) (thresh[(y)*width + (x)]) #define THRESH(x,y) (thresh[(y)*width + (x)])
#define THRESHn(n,x,y) ((thresh[n])[(y)*width + (x)]) #define THRESHn(n,x,y) ((thresh[n])[(y)*width + (x)])
/* Arguments to filter */ /* Arguments to filter */
...@@ -290,7 +290,7 @@ typedef struct ...@@ -290,7 +290,7 @@ typedef struct
GtkObject *input_spi; GtkObject *input_spi;
GtkObject *output_lpi; GtkObject *output_lpi;
GtkObject *cellsize; GtkObject *cellsize;
GtkWidget *vbox; /* container for screen info */ GtkWidget *vbox; /* container for screen info */
/* Notebook for the channels (one per colorspace) */ /* Notebook for the channels (one per colorspace) */
GtkWidget *channel_notebook[NUM_CS]; GtkWidget *channel_notebook[NUM_CS];
...@@ -726,7 +726,7 @@ new_preview (gint *sfn) ...@@ -726,7 +726,7 @@ new_preview (gint *sfn)
} }
/* the popup menu "st" has changed, so the previews associated with it /* the popup menu "st" has changed, so the previews associated with it
* need re-calculation */ * need re-calculation */
static void static void
preview_update (channel_st *st) preview_update (channel_st *st)
...@@ -1016,7 +1016,7 @@ new_channel (const chan_tmpl *ct) ...@@ -1016,7 +1016,7 @@ new_channel (const chan_tmpl *ct)
GtkWidget *menu; GtkWidget *menu;
spot_info_t *sf; spot_info_t *sf;
channel_st *chst; channel_st *chst;
gint i; gint i;
/* create the channel state record */ /* create the channel state record */
chst = new_preview (ct->spotfn); chst = new_preview (ct->spotfn);
...@@ -1046,7 +1046,7 @@ new_channel (const chan_tmpl *ct) ...@@ -1046,7 +1046,7 @@ new_channel (const chan_tmpl *ct)
hbox = gtk_hbox_new (FALSE, 6); hbox = gtk_hbox_new (FALSE, 6);
gtk_box_pack_start (GTK_BOX (chst->vbox), hbox, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (chst->vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox); gtk_widget_show (hbox);
abox = gtk_alignment_new (0.5, 0.0, 0.0, 0.0); abox = gtk_alignment_new (0.5, 0.0, 0.0, 0.0);
gtk_box_pack_start (GTK_BOX (hbox), abox, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), abox, FALSE, FALSE, 0);
gtk_widget_show (abox); gtk_widget_show (abox);
...@@ -1071,7 +1071,7 @@ new_channel (const chan_tmpl *ct) ...@@ -1071,7 +1071,7 @@ new_channel (const chan_tmpl *ct)
while (sf->name) while (sf->name)
{ {
chst->menuitem[i] = gtk_menu_item_new_with_label( gettext(sf->name)); chst->menuitem[i] = gtk_menu_item_new_with_label( gettext(sf->name));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), gtk_menu_shell_append (GTK_MENU_SHELL (menu),
GTK_WIDGET (chst->menuitem[i])); GTK_WIDGET (chst->menuitem[i]));
gtk_widget_show (chst->menuitem[i]); gtk_widget_show (chst->menuitem[i]);
...@@ -1197,7 +1197,7 @@ newsprint_dialog (GimpDrawable *drawable) ...@@ -1197,7 +1197,7 @@ newsprint_dialog (GimpDrawable *drawable)
for(i=0; i<NUM_CS; i++) for(i=0; i<NUM_CS; i++)
st.chst[i][0] = NULL; st.chst[i][0] = NULL;
/* need to know the bpp, so we can tell if we're doing /* need to know the bpp, so we can tell if we're doing
* RGB/CMYK or grey style of dialog box */ * RGB/CMYK or grey style of dialog box */
bpp = gimp_drawable_bpp (drawable->drawable_id); bpp = gimp_drawable_bpp (drawable->drawable_id);
if (gimp_drawable_has_alpha (drawable->drawable_id)) if (gimp_drawable_has_alpha (drawable->drawable_id))
...@@ -1759,7 +1759,7 @@ newsprint (GimpDrawable *drawable) ...@@ -1759,7 +1759,7 @@ newsprint (GimpDrawable *drawable)
gdouble r; gdouble r;
gdouble theta; gdouble theta;
gdouble rot[4]; gdouble rot[4];
gdouble k_pullout; gint k_pullout;
gint bpp, colour_bpp; gint bpp, colour_bpp;
gint has_alpha; gint has_alpha;
gint b; gint b;
...@@ -1777,7 +1777,7 @@ newsprint (GimpDrawable *drawable) ...@@ -1777,7 +1777,7 @@ newsprint (GimpDrawable *drawable)
#ifdef TIMINGS #ifdef TIMINGS
GTimer *timer = g_timer_new (); GTimer *timer = g_timer_new ();
#endif #endif
width = pvals.cell_width; width = pvals.cell_width;
...@@ -1787,7 +1787,7 @@ newsprint (GimpDrawable *drawable) ...@@ -1787,7 +1787,7 @@ newsprint (GimpDrawable *drawable)
width = 1; width = 1;
oversample = pvals.oversample; oversample = pvals.oversample;
k_pullout = ((gdouble) pvals.k_pullout) / 100.0; k_pullout = (255 * pvals.k_pullout) / 100;
width *= oversample; width *= oversample;
...@@ -1832,7 +1832,7 @@ do { \ ...@@ -1832,7 +1832,7 @@ do { \
/* calculate the RGB / CMYK rotations and threshold matrices */ /* calculate the RGB / CMYK rotations and threshold matrices */
if (colour_bpp == 1 || colourspace == CS_INTENSITY) if (colour_bpp == 1 || colourspace == CS_INTENSITY)
{ {
rot[0] = DEG2RAD (pvals.gry_ang); rot[0] = DEG2RAD (pvals.gry_ang);
thresh[0] = spot2thresh (pvals.gry_spotfn, width); thresh[0] = spot2thresh (pvals.gry_spotfn, width);
} }
else else
...@@ -1868,7 +1868,7 @@ do { \ ...@@ -1868,7 +1868,7 @@ do { \
gf = pvals.gry_spotfn; gf = pvals.gry_spotfn;
ASRT (gf); ASRT (gf);
if (!spotfn_list[gf].thresh) if (!spotfn_list[gf].thresh)
spotfn_list[gf].thresh = spot2thresh (gf, width); spotfn_list[gf].thresh = spot2thresh (gf, width);
thresh[3] = spotfn_list[gf].thresh; thresh[3] = spotfn_list[gf].thresh;
} }
} }
...@@ -1925,20 +1925,21 @@ do { \ ...@@ -1925,20 +1925,21 @@ do { \
switch (colourspace) switch (colourspace)
{ {
case CS_CMYK: case CS_CMYK:
data[3] = 0xff; {
gint r,g,b,k;
data[0] = 0xff - data[0]; r = data[0];
data[3] = MIN (data[3], data[0]); g = data[1];
data[1] = 0xff - data[1]; b = data[2];
data[3] = MIN (data[3], data[1]); k = k_pullout;
data[2] = 0xff - data[2];
data[3] = MIN (data[3], data[2]);
data[3] = ((gdouble)data[3]) * k_pullout; gimp_rgb_to_cmyk_int (&r, &g, &b, &k);
data[0] -= data[3]; data[0] = r;
data[1] -= data[3]; data[1] = g;
data[2] -= data[3]; data[2] = b;
data[3] = k;
}
break; break;
case CS_INTENSITY: case CS_INTENSITY:
...@@ -1949,7 +1950,7 @@ do { \ ...@@ -1949,7 +1950,7 @@ do { \
default: default:
break; break;
} }
for (b = 0; b < cspace_nchans[colourspace]; b++) for (b = 0; b < cspace_nchans[colourspace]; b++)
{ {
rx = RINT (r * cos (theta + rot[b])); rx = RINT (r * cos (theta + rot[b]));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment