> It looks like that should have all of the information that I need.
>
> You wouldn't happen to have bit of sample code, though?
Well, using this article - http://groups.google.com/groups?q=opencolorprofile&hl=en&lr=&ie=UTF-8&oe=UTF-8&s
elmr9e8c9a.0111081307.3f7d6f81%40posting.google.com&rnum=5 , as a guide, I've got something that seems to work. Obviously, I could clean up the code quite a bit (rename the class for gdisnot, add a whole lot of enums, etc.)
But, I did want to post the code so anyone else could find it. Here are the two classes. One to wrap the GDI interop--gdisnot, and the main class to test the functions. It seems to work fine. (And, I can't get the tabs to show up here, so it's not the prettiest code. :)
using System;
using System.Runtime.InteropServices;
namespace managedtest
{
[StructLayout( LayoutKind.Sequential, CharSet=CharSet.Ansi )]
public struct tagPROFILE
{
public uint dwType;
public string pProfileData;
public uint cbDataSize;
}
public delegate bool ICMProgressProcCallback( uint ulMax, uint ulCurrent, int ulCallbackData );
public enum BMFORMAT
{
//
// 16bpp - 5 bits per channel. The most significant bit is ignored.
//
BM_x555RGB = 0x0000,
BM_x555XYZ = 0x0101,
BM_x555Yxy,
BM_x555Lab,
BM_x555G3CH,
//
// Packed 8 bits per channel => 8bpp for GRAY and
// 24bpp for the 3 channel colors, more for hifi channels
//
BM_RGBTRIPLETS = 0x0002,
BM_BGRTRIPLETS = 0x0004,
BM_XYZTRIPLETS = 0x0201,
BM_YxyTRIPLETS,
BM_LabTRIPLETS,
BM_G3CHTRIPLETS,
BM_5CHANNEL,
BM_6CHANNEL,
BM_7CHANNEL,
BM_8CHANNEL,
BM_GRAY,
//
// 32bpp - 8 bits per channel. The most significant byte is ignored
// for the 3 channel colors.
//
BM_xRGBQUADS = 0x0008,
BM_xBGRQUADS = 0x0010,
BM_xG3CHQUADS = 0x0304,
BM_KYMCQUADS,
BM_CMYKQUADS = 0x0020,
//
// 32bpp - 10 bits per channel. The 2 most significant bits are ignored.
//
BM_10b_RGB = 0x0009,
BM_10b_XYZ = 0x0401,
BM_10b_Yxy,
BM_10b_Lab,
BM_10b_G3CH,
//
// 32bpp - named color indices (1-based)
//
BM_NAMED_INDEX,
//
// Packed 16 bits per channel => 16bpp for GRAY and
// 48bpp for the 3 channel colors.
//
BM_16b_RGB = 0x000A,
BM_16b_XYZ = 0x0501,
BM_16b_Yxy,
BM_16b_Lab,
BM_16b_G3CH,
BM_16b_GRAY,
//
// 16 bpp - 5 bits for Red & Blue, 6 bits for Green
//
BM_565RGB = 0x0001,
};
/// <summary>
/// Summary description for gdisnot.
/// </summary>
public class gdisnot
{
[DllImport("mscms.dll", SetLastError=true)]
public static extern IntPtr OpenColorProfileA(ref tagPROFILE pProfile, uint AccessMode, uint ShareMode, uint CreateMode);
[DllImport("mscms.dll", SetLastError=true)]
public static extern IntPtr CreateMultiProfileTransform(IntPtr [] profiles , uint numOfProfiles, ref uint [] intents, uint numOfIntents, uint flags, uint indexPreferredCMM );
[DllImport("mscms.dll", SetLastError=true)]
public static extern bool TranslateBitmapBits(IntPtr pTransform, IntPtr inBuffer, BMFORMAT inFormat,
uint width, uint height, uint stride,
IntPtr outBuffer, BMFORMAT outFormat, uint outStride, ICMProgressProcCallback pfCallback, int CallBackParam);
[DllImport("mscms.dll", SetLastError=true)]
public static extern bool CloseColorProfile(IntPtr profile);
[DllImport("mscms.dll", SetLastError=true)]
public static extern bool DeleteColorTransform(IntPtr transform);
}
}
using System;
using System.Drawing.Imaging;
using System.Drawing;
using System.Runtime.InteropServices;
namespace managedtest
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
IntPtr [] profiles = new IntPtr[2];
tagPROFILE x = new tagPROFILE();
x.dwType = 1;
x.pProfileData = @"C:\Program Files\Common Files\Adobe\Color\Profiles\D60-linear-aboutdigicam.com.icm";
x.cbDataSize = (uint)x.pProfileData.Length+1;
profiles[0] = gdisnot.OpenColorProfileA( ref x, (uint)1, (uint)1, (uint)3 );
int q = Marshal.GetLastWin32Error();
x.pProfileData = @"C:\Program Files\Common Files\Adobe\Color\Profiles\Recommended\sRGB Color Space Profile.icm";
x.cbDataSize = (uint)x.pProfileData.Length+1;
profiles[1] = gdisnot.OpenColorProfileA( ref x, (uint)1, (uint)1, (uint)3 );
Console.WriteLine( "Got D60 profile {0}", profiles[0] );
Console.WriteLine( "Got RGB profile {0}", profiles[1] );
Console.ReadLine();
uint [] intents = new uint[2];
intents[0] = 0;
intents[1] = 0;
IntPtr pTransforms = gdisnot.CreateMultiProfileTransform( profiles, 2, ref intents, 2, 3, 0 );
q = Marshal.GetLastWin32Error();
Bitmap bmpTemp = (Bitmap)Bitmap.FromFile( @"F:\Share\Photos\08_14\BobProcessed\CRW_2705.Jpg", false );
BitmapData bd = bmpTemp.LockBits(new Rectangle(0, 0, bmpTemp.Width, bmpTemp.Height ), ImageLockMode.ReadWrite, bmpTemp.PixelFormat);
bool success = gdisnot.TranslateBitmapBits( pTransforms, bd.Scan0, BMFORMAT.BM_RGBTRIPLETS, (uint)bd.Width, (uint)bd.Height,
(uint)bd.Stride, bd.Scan0, BMFORMAT.BM_RGBTRIPLETS, (uint)bd.Stride, null, 0 );
bmpTemp.UnlockBits( bd );
bmpTemp.Save( @"F:\Share\Photos\08_14\BobProcessed\CRW_2705_1.Jpg", System.Drawing.Imaging.ImageFormat.Jpeg );
gdisnot.CloseColorProfile( profiles[0] );
gdisnot.CloseColorProfile( profiles[1] );
gdisnot.DeleteColorTransform( pTransforms );
}
}
}
> Hi,
>
[quoted text clipped - 9 lines]
> This posting is provided "AS IS" with no warranties, and confers no rights.
> Visit http://www.microsoft.com/security for current information on security.