[Lcms-user] passing Arrays of fixed sizes to cmsDoTransform
An ICC-based CMM for color management
                
                Brought to you by:
                
                    mm2
                    
                
            
            
        
        
        
    | 
      
      
      From: Roger B. <gr...@vi...> - 2016-07-08 19:03:34
      
     | 
| I am still having difficulty with calling cmsDoTransform with
variable-length arrays of bytes.
I always get MemoryAccessViolations errors.
Today's preliminary testing suggest I would have better luck using fixed
size arrays.
What will happen if I break down my bitmap image in fixed size chunks?
Suppose image size = 104 bytes 
Suppose I chose Fixed array size = 64 bytes
My new C# pinvoke function signature would look like this :
[DllImport(@lcms2Path, CallingConvention = CallingConvention.Winapi)]
static extern void cmsDoTransform(
            IntPtr xform,
            [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 64), In]
byte[] inputColors,
            [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 64), Out]
byte[] outputColors,
            uint Size);
Then, I will iterate cmsDoTransform 2x with 64 bytes each.
Upon return, it will be up to my code to throw away the remainder 2 x 64 =
128 - 104 -> 24 bytes.
I guess I will have to pad these extra 24 bytes with 00.
But, would this work?
At least, this approach has the merit of avoiding MemoryAccessViolations.
Best / Roger
 |