/* Shared function between the single and buffer conversions */ static void gsicc_nocm_transform_general(gx_device *dev, gsicc_link_t *icclink, void *inputcolor, void *outputcolor, int num_bytes_in, int num_bytes_out) { /* Input data is either single byte or 2 byte color values. The color mapping procs work on frac values so we have to sandwich the transformation between to and from frac conversions. We are only doing at most 4 source colors here */ nocm_link_t *link = (nocm_link_t*) icclink->link_handle; byte num_in = link->num_in; byte num_out = link->num_out; frac frac_in[4]; frac frac_out[GX_DEVICE_COLOR_MAX_COMPONENTS]; int k; if (num_bytes_in == 2) { unsigned short *data = (unsigned short *) inputcolor; for (k = 0; k < num_in; k++) { frac_in[k] = ushort2frac(data[k]); } } else { byte *data = (byte *) inputcolor; for (k = 0; k < num_in; k++) { frac_in[k] = byte2frac(data[k]); } } /* Use the device procedure */ switch (num_in) { case 1: (link->cm_procs.map_gray)(dev, frac_in[0], frac_out); break; case 3: (link->cm_procs.map_rgb)(dev, link->pis, frac_in[0], frac_in[1], frac_in[2], frac_out); break; case 4: (link->cm_procs.map_cmyk)(dev, frac_in[0], frac_in[1], frac_in[2], frac_in[3], frac_out); break; default: break; } if (num_bytes_out == 2) { unsigned short *data = (unsigned short *) outputcolor; for (k = 0; k < num_out; k++) { data[k] = frac2ushort(frac_out[k]); } } else { byte *data = (byte *) outputcolor; for (k = 0; k < num_out; k++) { data[k] = frac2byte(frac_out[k]); } } return; }
/* Shared function between the single and buffer conversions. This is where we do the actual replacement. For now, we make the replacement a negative to show the effect of what using color replacement. We also use the device procs to map to the device value. */ static void gsicc_rcm_transform_general(gx_device *dev, gsicc_link_t *icclink, void *inputcolor, void *outputcolor, int num_bytes_in, int num_bytes_out) { /* Input data is either single byte or 2 byte color values. */ rcm_link_t *link = (rcm_link_t*) icclink->link_handle; byte num_in = link->num_in; byte num_out = link->num_out; frac frac_in[4]; frac frac_out[GX_DEVICE_COLOR_MAX_COMPONENTS]; int k; /* Make the negative for the demo.... */ if (num_bytes_in == 2) { unsigned short *data = (unsigned short *) inputcolor; for (k = 0; k < num_in; k++) { frac_in[k] = frac_1 - ushort2frac(data[k]); } } else { byte *data = (byte *) inputcolor; for (k = 0; k < num_in; k++) { frac_in[k] = frac_1 - byte2frac(data[k]); } } /* Use the device procedure */ switch (num_in) { case 1: (link->cm_procs.map_gray)(dev, frac_in[0], frac_out); break; case 3: (link->cm_procs.map_rgb)(dev, NULL, frac_in[0], frac_in[1], frac_in[2], frac_out); break; case 4: (link->cm_procs.map_cmyk)(dev, frac_in[0], frac_in[1], frac_in[2], frac_in[3], frac_out); break; default: break; } if (num_bytes_out == 2) { unsigned short *data = (unsigned short *) outputcolor; for (k = 0; k < num_out; k++) { data[k] = frac2ushort(frac_out[k]); } } else { byte *data = (byte *) outputcolor; for (k = 0; k < num_out; k++) { data[k] = frac2byte(frac_out[k]); } } return; }
/* * Copy from tmp to dst, taking into account PixelOut vs. PixelIn sizes * We do the conversion from PixelIn to PixelOut here (if needed) * since if the Y is scaled down we will convert less often. * This is simpler because we can treat all columns identically * without regard to the number of samples per pixel. */ static void idownscale_y(void /*PixelOut */ *dst, const void /* PixelIn */ *tmp, stream_ISpecialDownScale_state *const ss) { int kn = ss->params.WidthOut * ss->params.spp_interp; int kc; float scale = (float) ss->params.MaxValueOut/255.0; if_debug0('W', "[W]idownscale_y: "); if (ss->sizeofPixelOut == 1) { if (ss->sizeofPixelIn == 1) { const byte *pp = (byte *)tmp; for ( kc = 0; kc < kn; ++kc, pp++ ) { if_debug1('W', " %d", *pp); ((byte *)dst)[kc] = *pp; } } else { /* sizeofPixelIn == 2 */ const bits16 *pp = (bits16 *)tmp; for ( kc = 0; kc < kn; ++kc, pp++ ) { if_debug1('W', " %d", *pp); ((byte *)dst)[kc] = frac2byte(*pp); } } } else { /* sizeofPixelOut == 2 */ if (ss->sizeofPixelIn == 1) { const byte *pp = (byte *)tmp; for ( kc = 0; kc < kn; ++kc, pp++ ) { if_debug1('W', " %d", *pp); ((bits16 *)dst)[kc] = (bits16)((*pp)*scale); } } else { /* sizeofPixelIn == 2 */ const bits16 *pp = (bits16 *)tmp; for ( kc = 0; kc < kn; ++kc, pp++ ) { if_debug1('W', " %d", *pp); ((bits16 *)dst)[kc] = *pp; } } } if_debug0('W', "n"); }