Hi, The currenty python bindings does not support floating point RGB, you can convert values to 16 bits that is what is lcms doing internally. You will obtain same precission.
c = COLORW() c[0] = int(R * 65535.0 + 0.5) c[1] = int(G * 65535.0 + 0.5) c[2] = int(B * 65535.0 + 0.5) Regards Marti Guy K. Kloss wrote: > Hi, > > I'm having a bit trouble with the Python bindings of Lcms. I just can't > figure > out what type of object to create to pass as an argument 2 to the > cmsDoTransform(...) function. I want to use floatint point values (0.0 to > 1.0) for RGB tuples rather than byte values (0 to 255) to convert from sRGB > to Lab. Of course I could multiply the the floating point value by 255 and > convert to an int, but that would introduce unnecessary rounding errors if > performed often. > > To highlight the problem I've added a little script. I'm passing in a numpy > float array for the RGB tuple, and I want to convert that one to Lab (as > float). > > Any input on this? The Python examples in python/testbed were not > enlightening > here, and I could only find compatible structures called COLORB and COLORW, > which seem to be byte and some sort of int respectively, but not float. > > I've tried passing in a numpy array, the "data" member of the numpy array, a > Python list/tuple containing floats, but then all I'm getting is this: > > TypeError: in method 'cmsDoTransform', argument 2 of type 'LPVOID' > > It's probably simple, once you know, but for now I'm a bit lost ... :-/ > > Guy > > > import numpy > from lcms import lcms > > XFORM_SRGB2LAB = lcms.cmsCreateTransform(H_SRGB, lcms.TYPE_RGB_DBL, > H_LAB, lcms.TYPE_Lab_DBL, > lcms.INTENT_PERCEPTUAL, > lcms.cmsFLAGS_NOTPRECALC) > > def convert_sRGB2Lab(rgbColour): > """ > Converts sRGB to CIE L*a*b colour tuples. The sRGB colour tuple is tp be > given as floating point values (0.0 ... 1.0). > """ > > # I'm missing some magic here. What structure "colour" do I create > # here, that I can feed into cmsDoTransform(...) below > colour = ... > > lab = lcms.cmsCIELab() > lcms.cmsDoTransform(XFORM_SRGB2LAB, colour, lab, 1) > return numpy.array([lab.L, lab.a, lab.b]) > > > if __name__ == '__main__': > # Patch A01 of che GretagMacbeth ColorChecker > anRgbColour = numpy.array([116.0 / 255, > 81.0 / 255, > 67.0 / 255]) > lab = convert_sRGB2Lab(anRgbColour) > print lab > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! > Studies have shown that voting for your favorite open source project, > along with a healthy diet, reduces your potential for chronic lameness > and boredom. Vote Now at http://www.sourceforge.net/community/cca08 > ------------------------------------------------------------------------ > > _______________________________________________ > Lcms-user mailing list > Lcms-user@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/lcms-user > ------------------------------------------------------------------------- Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! Studies have shown that voting for your favorite open source project, along with a healthy diet, reduces your potential for chronic lameness and boredom. Vote Now at http://www.sourceforge.net/community/cca08 _______________________________________________ Lcms-user mailing list Lcms-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lcms-user