Hi,

yes, I'd like to...could be good for mailing list to have all necessary information about the topic in the future... ;)

Ok, here we go. Let's assume you have read the *raw* Lab tiff image data into "buffer", and you know this is a 8-bit per pixel photometric 8 Lab TIFF. Then, you want to convert it to sRGB.

First you need to write the decoder. Just copy & paste this function:

// ---------------------------

unsigned char* UnrollTIFFLab8(register void* nfo, register WORD wIn[], register 
LPBYTE accum)
{
   _LPcmsTRANSFORM info = (_LPcmsTRANSFORM) nfo;

   wIn[0] = (accum[0]) << 8;
   wIn[1] = ((accum[1] > 127) ? (accum[1] - 128) : (accum[1] + 128)) << 8;
   wIn[2] = ((accum[2] > 127) ? (accum[2] - 128) : (accum[2] + 128)) << 8;
return accum + 3;
}
// ---------------

Right. Then you create a typical lcms color transform, from built-in Lab to 
sRGB:

cmsHPROFILE hLab    = cmsCreateLabProfile(NULL);
cmsHPROFILE hsRGB = cmsCreate_sRGBProfile();
cmsHTRANSFORM xform = cmsCreateTransform(hLab, TYPE_Lab_8, hsRGB, TYPE_RGB_8, 
INTERNT_PERCEPTUAL, 0);

And now comes the magic: You want the color transform to use the UnrollTIFFLab8 decoder instead of "normal" Lab, so:

cmsSetUserFormatters(xform, TYPE_Lab_8, UnrollTIFFLab8, 0, NULL); This works fine in 1.15, if you are using 1.14, you may need to save the old formatter:

cmsFORMATTER unroll,  pack;
DWORD  du, dp;

cmsGetUserFormatters(xform, &du, &unroll, &dp, &pack);
cmsSetUserFormatters(xform, TYPE_Lab_8, UnrollTIFFLab8, dp, pack);

That's all. You can now use cmsDoTransform() directly to
the "buffer". The CMM will decode the Lab values using UnrollTIFFLab8 and therefore understand the TIFF in the correct way. For writting TIFF is mostly same, but then using this encoder:

// ---------

unsigned char* PackTIFFLab8(register void* nfo, register WORD wOut[], register 
LPBYTE output)
{
   _LPcmsTRANSFORM info = (_LPcmsTRANSFORM) nfo;

 *output++ = (wOut[0] + 0x0080) >> 8;

 wOut[1] = (wOut[1] + 0x0080) >> 8;
 wOut[2] = (wOut[2] + 0x0080) >> 8;

 *output++ = (wOut[1] < 128) ? (wOut[1] + 128) : (wOut[1] - 128);
 *output++ = (wOut[2] < 128) ? (wOut[2] + 128) : (wOut[2] - 128);

   return output;
}

// ---------

Both functions are optimized for speed, so the operation should be reasonably fast. Please note that this is using the raw lcms API, and not tied with ImageMagick in any way. I don't know if there is any hook to implement that in IM code.

An alpha of 1.15 is available here:
http://www.littlecms.com/lcms-1.15.tar.gz

Hope this helps,
Regards
--
Marti Maria
The littlecms project.
www.littlecms.com




----- Original Message ----- From: "Michal Paczek" <[EMAIL PROTECTED]>
To: "Marti" <[EMAIL PROTECTED]>
Cc: <lcms-user@lists.sourceforge.net>
Sent: Friday, August 19, 2005 3:54 PM
Subject: Re: [Lcms-user] Littlecms with ImageMagick - howto?


Marti wrote:


Hi,
Not an expert at all, but I did some investigation time ago. Basically the encodings used by TIFF Lab and ICC are different on some photometric interpretations.

See the details here:

http://www.asmail.be/msg0055212264.html


so...that means we have to convert somehow our ICC profile...


By the way, in the CVS there is a new tifficc that would support some of these encodings. I can post
the piece of code that does the trick if wish so,  just let me know.


yes, I'd like to...could be good for mailing list to have all necessary information about the topic in the future... ;)



Best regards
Michal



--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.338 / Virus Database: 267.10.9/72 - Release Date: 14/08/2005




--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.338 / Virus Database: 267.10.9/72 - Release Date: 14/08/2005



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Lcms-user mailing list
Lcms-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lcms-user

Reply via email to