Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Drawing / September 2003

Tip: Looking for answers? Try searching our database.

Transforming an image's color space

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
netnews.comcast.net - 20 Sep 2003 16:46 GMT
Hey guys,
I'm working on an image transformation project.  It takes a Canon raw file
(.CRW) file and converts it in to either a JPG or a Photoshop file.  The
Photoshop file is working pretty well, and since Photoshop can convert the
file in to the correct color space, it's not the issue.

However, the JPG output routine is currently writing out a linear output
file.  So, it looks pretty dark.  I have the ICC color profiles for the
source and the destination that I'm looking to make the file.

I'm not really sure how to do it.  I've looked in to the ImageAttribute
class and even tried to use it.  No luck there.  I did see an article on one
of the news groups that suggested that I might have to drop down in to GDI
and native code to do this.

Any suggestions, or better yet, any sample code?  I simply need to transform
a Bitmap from one color space to another one.

Thanks.
John Hornick [MSFT] - 20 Sep 2003 23:55 GMT
Hi,

Though it was written with unmanaged GDI+ in mind, the following
article may help:

HOW TO: Use GDI+ and Image Color Management to Adjust Image Colors
http://support.microsoft.com/?id=317825

Thanks,
- John
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
Visit http://www.microsoft.com/security for current information on security.

> I'm working on an image transformation project.  It takes a Canon raw file
> (.CRW) file and converts it in to either a JPG or a Photoshop file.  The
[quoted text clipped - 12 lines]
> Any suggestions, or better yet, any sample code?  I simply need to transform
> a Bitmap from one color space to another one.
netnews.comcast.net - 21 Sep 2003 02:45 GMT
Thanks John.
It looks like that should have all of the information that I need.

You wouldn't happen to have bit of sample code, though?

> Hi,
>
[quoted text clipped - 28 lines]
> transform
> > a Bitmap from one color space to another one.
John Hornick [MSFT] - 21 Sep 2003 17:58 GMT
Hi,

> It looks like that should have all of the information that I need.
>
> You wouldn't happen to have bit of sample code, though?

No, I don't.

Thanks,
- John
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
Visit http://www.microsoft.com/security for current information on security.
netnews.comcast.net - 21 Sep 2003 21:55 GMT
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.
james - 21 Sep 2003 00:27 GMT
I'm working on a similar project. But, have had to start over since I had a
hard drive failure.  (I have a much better backup system going now) It took
me a bit to convince Canon that I had completely lost the SDK and that I
needed to re-download it agian.  They finally said ok.
What I was wondering, is are you using the Canon SDK or are you doing
something else to do the conversion?  And what language are you using?  I am
using VB.NET (converting Canon's VB6 samples).
I had it where I could convert to jpg,,, but not all  the time.  And now,
I'm starting over.
I think I had a similar problem with my previous code , in that the
converted jpg tended to be on the dark side.  One idea would be to do
primary adjustments like, White Balance, Saturation, etc. while the image is
still in .CRW format and then convert that to jpg.  Have you tried that?
james

( I would be interested in exchanging ideas about this)
Here is my email address: jjames700REMOVEme@earthlink.net
(be sure to REMOVEme)

> Hey guys,
> I'm working on an image transformation project.  It takes a Canon raw file
[quoted text clipped - 15 lines]
>
> Thanks.
tom - 26 Sep 2003 12:30 GMT
james

I'm responding for bill...

In answer to your question whether we are using the Canon SDK the
answer is no.  We started mostly from scratch with only the dave
coffin crw converter.  Bill converted it to run under .net framework.
He's doing the interface and main program structure & I'm working on
the conversion code (interpolation, noise reduction, brightness,
blackpoint, etc.)

we are working in c#

tom
james - 27 Sep 2003 02:15 GMT
Thanks Tom, got your email.
james

> james
>
[quoted text clipped - 10 lines]
>
> tom

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.