thanks for the quick answer.
Actually I used T_BYTES() as bytes per channel (hence I multiply
nNumOutputChannels * nNumBytes for the pixel size below).
The issue is that I do not know the output channel count - I need to
read that information directly from the output profile.
It could be anything from 3 to 8 channels.
Good point about the color models of the image vs the embedded profile.
I can work around that rather easily and check as you suggest if they match.
Not quite sure why the transformation does only affect 1/3 of the image
width and distorts the input image that way.
If I understand you correctly though - it may be the formatter?
I will give your suggestion a try now and see how that works.
> Hi Michael,
> I think you are assuming T_BYTES() returns the number of bytes per
> pixel when it really returns bytes per channel. Also, you are mixing
> cmsColorSpaceSignature with formatters.
> Just use this:
> nOutputFormatter = BYTES_SH(1) | CHANNELS_SH(nNumOutputChannels);
> This is enough. You can do an additional colorspace check by using
> nOutputFormatter |=
> Plese note the "_" at the begin of _cmsLCMScolorSpace, and that means
> you should not need this function in normal operation. If fact, the
> colorspace (color model to be more precise) of the image is not given
> by the profile but by the image itself. As an example, I can embed a
> RGB profile into a CMYK image. Using the algorithm above would not
> work. I would check both color models to validate the profile before
> proceeding to do the color transformation.
> Quoting Michael Zauner <psychotronic@...>:
>> I do love little CMS very much - nice, small and quick.
>> But I do have an issue with a bit of code and I cannot see what I am
>> doing wrong.
>> Maybe one of you guys could help me and tell if I do anything obvious
>> The basic idea is that I do have an image with an embedded profile and
>> an external profile file.
>> The external profile can differ and may have e.g. 6 channels.
>> I want to transform the image with the external profile and read the
>> pixel values of the output channels.
>> Here is an example code (leaving out only the input image specific
>> stuff), which is really a modified version of the basic example seen in
>> the tutorial:
>> cmsHPROFILE hInProfile, hOutProfile;
>> cmsHTRANSFORM hTransform;
>> //Width and height and pixel type are from the input image
>> int nInputPixelType = TYPE_BGRA_16;
>> int nWidth = xxx;
>> int nHeight = xxx;
>> //Loading the profiles
>> hInProfile = cmsOpenProfileFromMem(memoryPointer,size);
>> hOutProfile = cmsOpenProfileFromFile(szProfileFile, "r");
>> //Extracting information of the output profile
>> cmsColorSpaceSignature outputColorSpace = cmsGetColorSpace(hOutProfile);
>> int nNumOutputChannels = cmsChannelsOf(outputColorSpace); //This is 6 in
>> my example
>> //This formatter is used in the transformation
>> int nOutputFormatter = _cmsLCMScolorSpace(outputColorSpace);
>> int nNumBytes = T_BYTES(nOutputFormatter); //This is 4 in my example
>> //I change now the formatter to have 1 byte instead as I want to use
>> that instead of 4 byte precision
>> if(nNumBytes != 1)
>> //Clear the first 3 bits
>> nOutputFormatter &= ~7;
>> //Set it to 1 Bytes
>> nOutputFormatter |= 1;
>> //Retrieve the value again (making sure it is one byte)
>> nNumBytes = T_BYTES(nOutputFormatter);
>> //Create the transformation
>> hTransform = cmsCreateTransform(hInProfile, nInputPixelType,
>> hOutProfile, nOutputFormatter,
>> INTENT_RELATIVE_COLORIMETRIC, 0);
>> //Closing the profile
>> //Create a buffer to hold the transformed data
>> int nNewSizeInBytes = nNumOutputChannels * nHeight * nWidth * nNumBytes;
>> char* szData = new char[nNewSizeInBytes];
>> //Transform the data
>> int nRowLengthInBytes = nNumOutputChannels*nNumBytes*nWidth;
>> for(int i = 0; i < nHeight; ++i)
>> char* pixelBuffer = READ_BUFFER_FROM_IMAGE_FOR_ROW(i);
>> cmsDoTransform(hTransform, pixelBuffer,szData + i
>> *nRowLengthInBytes, nWidth);
>> The issue is that the transformation does work - I do get the data for
>> each channel. But the transformed image data is only 1/3 wide (the
>> height does match) - the other 2/3 of the image are untouched (e.g. when
>> I initialize szData with white instead of black, it remains white).
>> I must be doing something really stupid - but I cannot see what is
>> Any help or pointers are highly appriciated.
>> It would help me to know if the litte CMS code is ok but I have an issue
>> either in the input buffer or the output buffer?
>> Thank you very much in advance
>> Try New Relic Now & We'll Send You this Cool Shirt
>> New Relic is the only SaaS-based application performance monitoring
>> that delivers powerful full stack analytics. Optimize and monitor your
>> browser, app, & servers with just a few lines of code. Try New Relic
>> and get this awesome Nerd Life shirt!
>> Lcms-user mailing list