If I could develop my application strictly in C, my problems accessing LittleCMS would be non-existent, but I need to develop in C# :(
I am seeking help with re-coding the cmsDoTransform declaration. Right now, I use this : [DllImport(@lcmsPath, CallingConvention = CallingConvention.Winapi)] static extern void cmsDoTransform( IntPtr xform, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2), In] double[] inputColors, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3), Out] double[] outputColors, uint Size); In code, I use this : double[] input = { 0.5, 0.5, 0.5, 0 }; double[] output = { 0, 0, 0, 0 }; cmsDoTransform(xform, input, output, 1); As you can see, I pass individual RGB values [in], recovering CMYK values [out]. The cmsCreateTransform looks like this : IntPtr xform = cmsCreateTransform(hSRGB, TYPE_RGB_DBL, hDestination, TYPE_CMYK_DBL, INTENT_RELATIVE_COLORIMETRIC, 0); Works perfect. But now, I need to pass 'pixels' (to convert bitmap images) values instead of individual device values. Obviously, I need to modify the pinvoke declaration to accommodate the difference in data type. I am no C# specialist (maybe someday?) but I read that I may not need very meticulous marshalling of data between my C# and lcms.dll. So I am looking for a way to rewrite the declaration to accommodate more than just 'double'. In C, the original cmsDoTransform function require a Handle to the Transform (another pointer), pointers to an input and output buffers, and the size of the buffer themselves : cmsDoTransform(cmsHTRANSFORM Transform, const void * InputBuffer, void * OutputBuffer, cmsUInt32Number Size); (Not sure what the 'const' keyword in front of the first void * statement does?) So my first awkward/intuitive shot at rewriting the function in C# call looks like this : [DllImport(lcms2Path, CallingConvention = CallingConvention.Winapi)] static extern void cmsDoTransform(IntPtr xform, IntPtr inputColors [in], IntPtr outputColors [out], uint Size); I have not tried running this code yet but I have been reading quite a bit about pointers and how they have a fixed size, no matter the type of data they point to. So my question becomes how do I pass pointers to the these buffers in my new declaration? I read somewhere about the need to use the keyword 'unsafe' but I am not sure. Also read about the need to use the attributes [in] and [out] in marshalling the data. (The Marshalling of data is a HUGE topic in itself as I found out through my hours of reading online) Ultimately, my goal is is to convert JPEG or TIFF images from one color space to another through LittleCMS. Thank you so much in advance for your kind help. / Roger Breton ------------------------------------------------------------------------------ Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San Francisco, CA to explore cutting-edge tech and listen to tech luminaries present their vision of the future. This family event has something for everyone, including kids. Get more information and register today. http://sdm.link/attshape _______________________________________________ Lcms-user mailing list Lcms-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lcms-user