[Gimp-developer] CMYK palette info from Photoshop
Hal V. Engel
hvengel at astound.net
Sun Apr 1 09:32:51 PDT 2007
On Saturday 31 March 2007 23:01, David Gowers wrote:
> On 4/1/07, Chris Mohler <cr33dog at gmail.com> wrote:
> > On 3/31/07, Hal V. Engel <hvengel at astound.net> wrote:
> > > You might consider using a color transform using ICC profiles. For
> >
> > example
> >
> > > you could use sRGB as your generic destination color space and perhaps
> > > a
> >
> > SWAP
> >
> > > profile for the CMYK side. Once you have selected your two profiles
> >
> > doing
> >
> > > the conversion is almost trivial using calls to lcms.
> >
> > Hal,
> >
> > Could you point me to an example? I see some functions in
> > plug-ins/lcms, but have not figured out how to use them. Most seem to
> > operate on drawables - I want to push CMYK number values into RGB.
>
> Chris,
> The lcms plugin is a different thing from the lcms library; GIMP's lcms
> plugin just provides an interface to the lcms library (
> http://www.littlecms.com/)
> Try looking in the plugin to see how the plugin accesses LCMS, not to find
> out what functions the plugin provides.
> IIRC it basically just needs to know the input and output profiles, and be
> provided pointers to source and destination buffers.
From my own application. This code does an RGB transform from a floating
point format image to an 8bit/channel QImage. But the same thing could be
done to go from CMYK to RGB. In addition to just do one color (rather than
an image) you can eliminate the nested loops and make a single call to
cmsDoTransform(...) and there is likely no reason for you to be doing the
normalization either:
// A ICC profile transform on whole image
void ImageItem::TransformImage(const QString OutputProfile,
const QString InputProfile,
vigra::DRGBImage& p,
QImage& pout)
{
struct dblColor
{
double r, g, b;
};
struct uint8Color
{
char r, g, b;
};
dblColor *RGB;
uint8Color *rgb;
double divisor;
RGB = (dblColor*) malloc(sizeof(dblColor));
rgb = (uint8Color*) malloc(sizeof(uint8Color));
cmsHTRANSFORM xform;
cmsHPROFILE hIn, hOut;
hIn = cmsOpenProfileFromFile(InputProfile.local8Bit(), "r");
hOut = cmsOpenProfileFromFile(OutputProfile.local8Bit(), "r");
xform = cmsCreateTransform(hIn, TYPE_RGB_DBL, hOut, TYPE_RGB_8,
/*INTENT_PERCEPTUAL*/ intent,
cmsFLAGS_WHITEBLACKCOMPENSATION);
vigra::DRGBImage::Iterator point=p.upperLeft();
if (uint8) divisor = 255.0;
else if (int16) divisor = 65536.0;
else if (int32) divisor = 4294967296.0;
for (int i=0; i < p.height(); i++)
for (int j=0; j < p.width(); j++)
{
if (uint8 | int16 | int32)
{
// scale RGB values to max = 1.0
// since this is what is expected for
// floating point images
RGB->r = point(j, i).red()/divisor;
RGB->g = point(j, i).green()/divisor;
RGB->b = point(j, i).blue()/divisor;
}
else // Floating point image
// no rescaling of RGB values needed
{
RGB->r = point(j, i).red();
RGB->g = point(j, i).green();
RGB->b = point(j, i).blue();
}
cmsDoTransform(xform, RGB, rgb, 1);
pout.setPixel(j,i, qRgba ( rgb->r, rgb->g, rgb->b, 0xff));
}
cmsDeleteTransform(xform);
cmsCloseProfile(hIn);
cmsCloseProfile(hOut);
free(RGB);
free(rgb);
}
More information about the Gimp-developer
mailing list