Hi,

I'm trying to do a direct transform of XYZ values from my colorimeter into RGB values from a printer profile, but I'm getting very odd results...

The program I'm using is included below, and the profile can be found at
http://www.blackfiveservices.co.uk/R300_Tesco_20050929.icm (generated using Argyll)

When I sample a black square from the target used to generate the printer profile, I get:
XYZ: X: 0.0231488, Y: 0.0225699, Z: 0.0167407
RGB: R: 95, G: 143, B: 133

A magenta square comes out as:
XYZ: X: 0.289546, Y: 0.142001, Z: 0.0952269
RGB: R: 131, G: 227, B: 159

If I use sRGB instead of my printer profile I get reasonable values, and the printer profile works fine for sRGB->Printer use, so I'm totally baffled as to why this is happening...

Can anyone shed any light on this?

(I'm using LCMS-1.14 BTW)

All the best,
--
Alastair M. Robinson
#include <iostream>

#include <stdlib.h>

#include "CSCMTLib.h"

#define PACKAGE_NAME
#include <lcms.h>

using namespace std;

#ifdef WIN32
#define sleep _sleep
#endif

void DumpModes()
{
	MeasMode modes;
	CSDGetSupportedModes(&modes);
	cout << "Currently attached ColorMouse supports:" << endl;
	if(modes&CMReflectionMode)
		cout << "  Reflective" << endl;
	if(modes&CMTransmissionMode)
		cout << "  Transmissive" << endl;
	if(modes&CMIncidentMode)
		cout << "  Incident" << endl;
	if(modes&CMMonitorMode)
		cout << "  Monitor" << endl;
}


bool InitCM()
{
	cout << "Initialising" <<  endl;
	CSDOpen();
	if (CSDInit (FALSE, 1) != CSCMNoErr)
	{
		CSDClose();
		CSDOpen();
		if (CSDInit (FALSE, 2) != CSCMNoErr)
		{
			CSDClose();
			throw "Cannot find ColorMouse on COM1 or COM2.";
		}
	}
	cout << "Done - setting capture modes" << endl;
	CSDPlaySound (TRUE);
	if (CSDSetMesData (CMXYZMode) != CSCMNoErr)
	{
		if (CSDSetMesData (CMSpecMode) != CSCMNoErr)
		{
			CSDClose();
			throw "Only CM2S and CM2C are supported by this program.";
		}
	}
	else
		CSDSetWhitePoint (cIllumD50 | cObs2deg);
	cout << "Done" << endl;
}


bool PollButton()
{
	Boolean pressed;
	sleep(10);
	CSDButtonPressed(&pressed);

	return(pressed);
}


void WaitButton()
{
	while(!PollButton());
}


void GetMeasurement(double *vals)
{
	MeasData meas;
	int err=CSDMeasure(&meas);
	if(err != CSCMNoErr)
	{
		if (err!=-1)
			cerr << "Measurement error" << endl;
		return;
	}
	vals[0]=meas.data.xyz.cieX;
	vals[1]=meas.data.xyz.cieY;
	vals[2]=meas.data.xyz.cieZ;
}


int main(int argc,char **argv)
{
	InitCM();
	DumpModes();

	cmsHPROFILE xyz=cmsCreateXYZProfile();
	cmsHPROFILE rgb=cmsOpenProfileFromFile("R300_Tesco_20050929.icm","r");

	cmsHTRANSFORM trans=cmsCreateTransform(xyz,TYPE_XYZ_DBL,rgb,TYPE_RGB_8,INTENT_ABSOLUTE_COLORIMETRIC,0);

	cout << "Begin measuring..." << endl;
	while(1)
	{
		double src[3];
		double lab[3];
		unsigned char dst[3];
		unsigned char chk[3];
		WaitButton();
		GetMeasurement(src);

		cout << "XYZ: X: " << src[0] << ", Y: " << src[1] << ", Z: " << src[2] << endl;

		cmsDoTransform(trans,src,dst,1);

		cout << "RGB: R: " << int(dst[0]) << ", G: " << int(dst[1]) << ", B: " << int(dst[2]) << endl;
	}
	return(0);
}

Reply via email to