f-spot r3954 - trunk/src/Cms



Author: sdelcroix
Date: Tue May 20 14:54:35 2008
New Revision: 3954
URL: http://svn.gnome.org/viewvc/f-spot?rev=3954&view=rev

Log:
fixing gendarme warning in Cms: 50 done

Modified:
   trunk/src/Cms/Cms.cs
   trunk/src/Cms/NativeMethods.cs

Modified: trunk/src/Cms/Cms.cs
==============================================================================
--- trunk/src/Cms/Cms.cs	(original)
+++ trunk/src/Cms/Cms.cs	Tue May 20 14:54:35 2008
@@ -7,6 +7,7 @@
 using System.Collections;
 using System.Runtime.InteropServices;
 using System.Reflection;
+using System.Runtime.Serialization;
 
 namespace Cms {
 	public enum Format : uint {
@@ -121,7 +122,7 @@
 
 		public static ColorCIExyY D50 {
 			get {
-				IntPtr ptr = NativeMethods.CmsD50_xyY ();
+				IntPtr ptr = NativeMethods.CmsD50xyY ();
 				return (ColorCIExyY) Marshal.PtrToStructure (ptr, typeof (ColorCIExyY));
 			}
 		}
@@ -172,7 +173,7 @@
 
 		public static ColorCIEXYZ D50 {
 			get {
-				IntPtr ptr = NativeMethods.CmsD50_XYZ ();
+				IntPtr ptr = NativeMethods.CmsD50XYZ ();
 				return (ColorCIEXYZ) Marshal.PtrToStructure (ptr, typeof (ColorCIEXYZ));
 			}
 		}
@@ -318,13 +319,13 @@
 
 		public int Count {
 			get {
-				return NativeMethods.f_cms_gamma_table_get_count (handle);
+				return NativeMethods.FCmsGammaTableGetCount (handle);
 			}
 		}
 
 		public IntPtr Values {
 			get {
-				return NativeMethods.f_cms_gamma_table_get_values (handle);
+				return NativeMethods.FCmsGammaTableGetValues (handle);
 			}
 		}
 
@@ -332,7 +333,7 @@
 			get {
 				unsafe {
 					if (handle.Handle == (IntPtr)0)
-						throw new ArgumentException ();
+						throw new Exception ();
 					
 					if (index < 0 || index >= Count)
 						throw new ArgumentOutOfRangeException (String.Format ("index {0} outside of count {1} for {2}", index, Count, handle.Handle));
@@ -344,7 +345,7 @@
 			set {
 				unsafe {
 					if (handle.Handle == (IntPtr)0)
-						throw new ArgumentException ();
+						throw new Exception ();
 					
 					if (index < 0 || index >= Count)
 						throw new ArgumentOutOfRangeException (String.Format ("index {0} outside of count {1} for handle {2}", index, Count, handle.Handle));
@@ -359,7 +360,7 @@
 		public GammaTable (ushort [] values, int start_offset, int length)
 		{
 #if true
-			handle = new HandleRef (this, NativeMethods.f_cms_gamma_table_new (values, start_offset, length));
+			handle = new HandleRef (this, NativeMethods.FCmsGammaTableNew (values, start_offset, length));
 			//System.Console.WriteLine ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXhandle = {0}", handle.Handle);
 #else
 			handle = new HandleRef (this, cmsAllocGamma (length));
@@ -444,7 +445,7 @@
 	}
 
 	public class Profile : IDisposable {
-		static Profile srgb = new Profile (cmsCreate_sRGBProfile());
+		static Profile srgb = new Profile (NativeMethods.CmsCreateSRGBProfile());
 
 		static Profile ()
 		{
@@ -458,17 +459,11 @@
 			}
 		}
 
-		[DllImport("liblcms-1.0.0.dll")]
-		static extern IntPtr _cmsCreateProfilePlaceholder ();
-		
-		private Profile () : this (_cmsCreateProfilePlaceholder ())
+		private Profile () : this (NativeMethods.CmsCreateProfilePlaceholder ())
 		{
 			
 		}
 
-		[DllImport("liblcms-1.0.0.dll")]
-		static extern IntPtr cmsCreate_sRGBProfile ();
-
 		public static Profile CreateSRgb () 
 		{
 			return CreateStandardRgb ();
@@ -497,40 +492,27 @@
 			return new Profile (wp, primaries, gamma);
 		}
 
-		[DllImport ("liblcms-1.0.0.dll")]
-		static extern IntPtr cmsCreateLabProfile (out ColorCIExyY WhitePoint);
-
 		public static Profile CreateLab (ColorCIExyY wp)
 		{
-			return new Profile (cmsCreateLabProfile (out wp));
+			return new Profile (NativeMethods.CmsCreateLabProfile (out wp));
 		}			
 
-		[DllImport ("liblcms-1.0.0.dll")]
-		static extern IntPtr cmsCreateLabProfile (IntPtr foo);
-
 		public static Profile CreateLab ()
 		{
-			return new Profile (cmsCreateLabProfile (IntPtr.Zero));
+			return new Profile (NativeMethods.CmsCreateLabProfile (IntPtr.Zero));
 		}			
 
-		[DllImport ("liblcms-1.0.0.dll")]
-		static extern IntPtr cmsCreateGrayProfile (ref ColorCIExyY white_point,
-							   HandleRef transfer_function);
-		
 		public static Profile CreateGray (ColorCIExyY white_point, GammaTable transfer)
 		{
 			if (transfer == null)
-				return new Profile (cmsCreateGrayProfile (ref white_point, new GammaTable (4096, 2.2).Handle));
+				return new Profile (NativeMethods.CmsCreateGrayProfile (ref white_point, new GammaTable (4096, 2.2).Handle));
 			else
-				return new Profile (cmsCreateGrayProfile (ref white_point, transfer.Handle));
+				return new Profile (NativeMethods.CmsCreateGrayProfile (ref white_point, transfer.Handle));
 		}
 
-		[DllImport ("libfspot")]
-		static extern IntPtr f_screen_get_profile (IntPtr screen);
-
 		public static Profile GetScreenProfile (Gdk.Screen screen)
 		{
-			IntPtr profile = f_screen_get_profile (screen.Handle);
+			IntPtr profile = NativeMethods.FScreenGetProfile (screen.Handle);
 			
 			if (profile == IntPtr.Zero)
 				return null;
@@ -539,26 +521,7 @@
 		}
 
 
-//		[DllImport("liblcms-1.0.0.dll")]
-//		static extern IntPtr cmsCreateBCHSWabstractProfile(int nLUTPoints,
-//								   double Bright, 
-//								   double Contrast,
-//								   double Hue,
-//								   double Saturation,
-//								   int TempSrc, 
-//								   int TempDest);
-
-		[DllImport("libfspot")]
-		static extern IntPtr f_cmsCreateBCHSWabstractProfile(int nLUTPoints,
-								     double Exposure,
-								     double Bright, 
-								     double Contrast,
-								     double Hue,
-								     double Saturation,
-								     ref ColorCIExyY src_wp, 
-								     ref ColorCIExyY dest_wp,
-								     HandleRef [] tables);
-		
+	
 		public static Profile CreateAbstract (int nLUTPoints,
 						      double Exposure,
 						      double Bright,
@@ -606,7 +569,7 @@
 			System.Console.WriteLine ("h {0}", Hue);
 			System.Console.WriteLine ("s {0} {1} {2}", Saturation, src_wp, dest_wp);
 			*/
-			return new Profile (f_cmsCreateBCHSWabstractProfile (nLUTPoints,
+			return new Profile (NativeMethods.FCmsCreateBCHSWabstractProfile (nLUTPoints,
 									     Exposure,
 									     0.0, //Bright,
 									     Contrast,
@@ -617,12 +580,9 @@
 									     CopyHandles (tables)));
 		}
 
-		[DllImport("liblcms-1.0.0.dll")]
-		static extern IntPtr cmsCreateLinearizationDeviceLink (IccColorSpace color_space, HandleRef [] tables);
-		
 		public Profile (IccColorSpace color_space, GammaTable [] gamma)
 		{
-			handle = new HandleRef (this, cmsCreateLinearizationDeviceLink (color_space, CopyHandles (gamma)));
+			handle = new HandleRef (this, NativeMethods.CmsCreateLinearizationDeviceLink (color_space, CopyHandles (gamma)));
 		}
 
 		private static HandleRef [] CopyHandles (GammaTable [] gamma)
@@ -637,42 +597,27 @@
 			return gamma_handles;
 		}
 
-		[DllImport("liblcms-1.0.0.dll")]
-		static extern IntPtr cmsCreateRGBProfile (out ColorCIExyY whitepoint, 
-						          out ColorCIExyYTriple primaries,
-							  HandleRef [] gamma_table);
-
 		public Profile (ColorCIExyY whitepoint, ColorCIExyYTriple primaries, GammaTable [] gamma)
 		{
-			handle = new HandleRef (this, cmsCreateRGBProfile (out whitepoint, out primaries, CopyHandles (gamma)));
+			handle = new HandleRef (this, NativeMethods.CmsCreateRGBProfile (out whitepoint, out primaries, CopyHandles (gamma)));
 		}
 
-		[DllImport("liblcms-1.0.0.dll")]
-		static extern int cmsCloseProfile (HandleRef hprofile);
-
-		[DllImport("liblcms-1.0.0.dll")]
-		static extern IntPtr cmsOpenProfileFromFile (string ICCProfile, string sAccess);
-
 		public Profile (string path) 
 		{
-			handle = new HandleRef (this, cmsOpenProfileFromFile (path, "r"));
+			handle = new HandleRef (this, NativeMethods.CmsOpenProfileFromFile (path, "r"));
 
 			if (handle.Handle == IntPtr.Zero)
 				throw new Exception ("Error opening ICC profile in file " + path);
 		}
 
-
-		[DllImport("liblcms-1.0.0.dll")]
-		static extern unsafe bool _cmsSaveProfileToMem (HandleRef profile, byte *mem, ref uint length);
-
 		public byte [] Save ()
 		{
 			unsafe {
 				uint length = 0;
-				if (_cmsSaveProfileToMem (this.Handle, null, ref length)) {
+				if (NativeMethods.CmsSaveProfileToMem (this.Handle, null, ref length)) {
 					byte [] data = new byte [length];
 					fixed (byte * data_p = &data [0]) {
-						if (_cmsSaveProfileToMem (this.Handle, data_p, ref length)) {
+						if (NativeMethods.CmsSaveProfileToMem (this.Handle, data_p, ref length)) {
 							return data;
 						}
 					}
@@ -681,9 +626,6 @@
 			throw new SaveException ("Error Saving Profile");
 		}
 
-		[DllImport("liblcms-1.0.0.dll")]
-		static extern unsafe IntPtr cmsOpenProfileFromMem (byte *data, uint length);
-
 		public Profile (byte [] data) : this (data, 0, data.Length) {}
 
 		public Profile (byte [] data, int start_offset, int length)
@@ -700,7 +642,7 @@
 			IntPtr profileh;
 			unsafe {
 				fixed (byte * start = & data [start_offset]) {
-					profileh = cmsOpenProfileFromMem (start, (uint)length);
+					profileh = NativeMethods.CmsOpenProfileFromMem (start, (uint)length);
 				}
 			}
 			
@@ -710,72 +652,55 @@
 				this.handle = new HandleRef (this, profileh);
 		}
 
-		[DllImport("liblcms-1.0.0.dll", EntryPoint = "cmsTakeMediaWhitePoint")]
-		extern static bool CmsTakeMediaWhitePoint (out ColorCIEXYZ wp, HandleRef handle);
-		
 		public ColorCIEXYZ MediaWhitePoint {
 			get {
 				ColorCIEXYZ wp;
-				if (!CmsTakeMediaWhitePoint (out wp, handle))
+				if (!NativeMethods.CmsTakeMediaWhitePoint (out wp, handle))
 					throw new ApplicationException ("unable to retrieve white point from profile");
 				return wp;
 			}
 		}
 
-		[DllImport("liblcms-1.0.0.dll", EntryPoint = "cmsTakeMediaBlackPoint")]
-		extern static bool CmsTakeMediaBlackPoint (out ColorCIEXYZ black, HandleRef handle);
-		
 		public ColorCIEXYZ MediaBlackPoint {
 			get {
 				ColorCIEXYZ black;
-				if (!CmsTakeMediaBlackPoint (out black, handle))
+				if (!NativeMethods.CmsTakeMediaBlackPoint (out black, handle))
 					throw new ApplicationException ("unable to retrieve white point from profile");
 				
 				return black;
 			}
 		}
 		
-		[DllImport("liblcms-1.0.0.dll", EntryPoint = "cmsTakeColorants")]
-		extern static bool CmsTakeColorants (out ColorCIEXYZTriple colors, HandleRef handle);
-
 		public ColorCIEXYZTriple Colorants {
 			get {
 				ColorCIEXYZTriple colors;
-				if (! CmsTakeColorants (out colors, handle))
+				if (!NativeMethods.CmsTakeColorants (out colors, handle))
 					throw new ApplicationException ("Unable to retrieve profile colorants");
 				
 				return colors;
 			}				
 		}
 		
-		[DllImport("liblcms-1.0.0.dll", EntryPoint = "cmsTakeModel")]
-		extern static IntPtr CmsTakeModel (HandleRef handle);
-		
 		public string Model {
 			get {
 				lock (srgb) {
-					return Marshal.PtrToStringAnsi (CmsTakeModel (handle));
+					return Marshal.PtrToStringAnsi (NativeMethods.CmsTakeModel (handle));
 				}
 			}
 		}
 
-		[DllImport("liblcms-1.0.0.dll", EntryPoint = "cmsTakeProductName")]
-		extern static IntPtr CmsTakeProductName (HandleRef handle);
-
 		public string ProductName {
 			get {
 				lock (srgb) {
-					return Marshal.PtrToStringAnsi (CmsTakeProductName (handle));
+					return Marshal.PtrToStringAnsi (NativeMethods.CmsTakeProductName (handle));
 				}
 			}
 		}
-		[DllImport("liblcms-1.0.0.dll")]
-		extern static IntPtr cmsTakeProductDesc (HandleRef handle);
 
 		public string ProductDescription {
 			get {
 				lock (srgb) {
-					return Marshal.PtrToStringAnsi (cmsTakeProductDesc (handle));
+					return Marshal.PtrToStringAnsi (NativeMethods.CmsTakeProductDesc (handle));
 				}
 			}
 		}
@@ -786,12 +711,9 @@
 			Ignore
 		}
 
-		[DllImport("liblcms-1.0.0.dll")]
-		static extern void cmsErrorAction (ErrorAction action);
-
 		private static void SetErrorAction (ErrorAction act)
 		{
-			cmsErrorAction (act);
+			NativeMethods.CmsErrorAction ((int) act);
 		}
 
 		public override string ToString ()
@@ -813,7 +735,7 @@
 
 		protected virtual void Cleanup ()
 		{
-			if (cmsCloseProfile (this.Handle) == 0)
+			if (NativeMethods.CmsCloseProfile (this.Handle) == 0)
 				throw new Exception ("Error closing Handle");
 
 		}
@@ -829,5 +751,17 @@
 		public SaveException (string message) : base (message)
 		{
 		}
+
+		protected SaveException (SerializationInfo info, StreamingContext context) : base (info, context)
+		{
+		}
+
+		public SaveException (string message, Exception innerException) : base (message, innerException)
+		{
+		}
+
+		public SaveException () : base ()
+		{
+		}
 	}
 }

Modified: trunk/src/Cms/NativeMethods.cs
==============================================================================
--- trunk/src/Cms/NativeMethods.cs	(original)
+++ trunk/src/Cms/NativeMethods.cs	Tue May 20 14:54:35 2008
@@ -12,7 +12,7 @@
 		public static extern void CmsxyY2XYZ (out ColorCIEXYZ dest, ref ColorCIExyY src);
 
 		[DllImport("liblcms-1.0.0.dll", EntryPoint = "cmsD50_xyY")]
-		public static extern IntPtr CmsD50_xyY();
+		public static extern IntPtr CmsD50xyY();
 
 		[DllImport("liblcms-1.0.0.dll", EntryPoint = "cmsXYZ2xyY")]
 		public static extern void CmsXYZ2xyY (out ColorCIExyY dest, ref ColorCIEXYZ source);
@@ -21,7 +21,7 @@
 		public static extern void CmsXYZ2Lab (ref ColorCIEXYZ wp, out ColorCIELab lab, ref ColorCIEXYZ xyz);
 
 		[DllImport("liblcms-1.0.0.dll", EntryPoint = "cmsD50_XYZ")]
-		public static extern IntPtr CmsD50_XYZ();
+		public static extern IntPtr CmsD50XYZ();
 
 		[DllImport("liblcms-1.0.0.dll", EntryPoint = "cmsLab2LCh")]
 		public static extern void CmsLab2LCh (out ColorCIELCh lch, ref ColorCIELab lab);
@@ -66,16 +66,93 @@
 		[DllImport("liblcms-1.0.0.dll", EntryPoint = "cmsDeleteTransform")]
 		public static extern void CmsDeleteTransform(HandleRef hTransform);
 		
+		[DllImport ("liblcms-1.0.0.dll", EntryPoint = "cmsCreateGrayProfile")]
+		public static extern IntPtr CmsCreateGrayProfile (ref ColorCIExyY white_point,
+							   HandleRef transfer_function);
+		
+		[DllImport ("liblcms-1.0.0.dll", EntryPoint = "cmsCreateLabProfile")]
+		public static extern IntPtr CmsCreateLabProfile (IntPtr foo);
 
-		[DllImport ("libfspot")]
-		public static extern IntPtr f_cms_gamma_table_new (ushort [] values, int start, int length);
+		[DllImport ("liblcms-1.0.0.dll", EntryPoint = "cmsCreateLabProfile")]
+		public static extern IntPtr CmsCreateLabProfile (out ColorCIExyY WhitePoint);
 
-		[DllImport ("libfspot")]
-		public static extern IntPtr f_cms_gamma_table_get_values (HandleRef table);
+		[DllImport("liblcms-1.0.0.dll", EntryPoint = "cmsCreate_sRGBProfile")]
+		public static extern IntPtr CmsCreateSRGBProfile ();
 
-		[DllImport ("libfspot")]
-		public static extern int f_cms_gamma_table_get_count (HandleRef table);
+		[DllImport("liblcms-1.0.0.dll", EntryPoint = "_cmsCreateProfilePlaceholder")]
+		public static extern IntPtr CmsCreateProfilePlaceholder ();
 
+//		[DllImport("liblcms-1.0.0.dll")]
+//		public static extern IntPtr cmsCreateBCHSWabstractProfile(int nLUTPoints,
+//								   double Bright, 
+//								   double Contrast,
+//								   double Hue,
+//								   double Saturation,
+//								   int TempSrc, 
+//								   int TempDest);
 	
+		[DllImport("liblcms-1.0.0.dll", EntryPoint = "cmsErrorAction")]
+		public static extern void CmsErrorAction (int action);
+
+		[DllImport("liblcms-1.0.0.dll", EntryPoint = "cmsTakeProductDesc")]
+		public extern static IntPtr CmsTakeProductDesc (HandleRef handle);
+
+		[DllImport("liblcms-1.0.0.dll", EntryPoint = "cmsTakeProductName")]
+		public extern static IntPtr CmsTakeProductName (HandleRef handle);
+
+		[DllImport("liblcms-1.0.0.dll", EntryPoint = "cmsTakeModel")]
+		public extern static IntPtr CmsTakeModel (HandleRef handle);
+		
+		[DllImport("liblcms-1.0.0.dll", EntryPoint = "cmsTakeColorants")]
+		public extern static bool CmsTakeColorants (out ColorCIEXYZTriple colors, HandleRef handle);
+
+		[DllImport("liblcms-1.0.0.dll", EntryPoint = "cmsTakeMediaBlackPoint")]
+		public extern static bool CmsTakeMediaBlackPoint (out ColorCIEXYZ black, HandleRef handle);
+		
+		[DllImport("liblcms-1.0.0.dll", EntryPoint = "cmsTakeMediaWhitePoint")]
+		public extern static bool CmsTakeMediaWhitePoint (out ColorCIEXYZ wp, HandleRef handle);
+		
+		[DllImport("liblcms-1.0.0.dll", EntryPoint = "cmsOpenProfileFromMem")]
+		public static extern unsafe IntPtr CmsOpenProfileFromMem (byte *data, uint length);
+
+		[DllImport("liblcms-1.0.0.dll", EntryPoint = "_cmsSaveProfileToMem")]
+		public static extern unsafe bool CmsSaveProfileToMem (HandleRef profile, byte *mem, ref uint length);
+
+		[DllImport("liblcms-1.0.0.dll", EntryPoint = "cmsOpenProfileFromFile")]
+		public static extern IntPtr CmsOpenProfileFromFile (string ICCProfile, string sAccess);
+
+		[DllImport("liblcms-1.0.0.dll", EntryPoint = "cmsCloseProfile")]
+		public static extern int CmsCloseProfile (HandleRef hprofile);
+
+		[DllImport("liblcms-1.0.0.dll", EntryPoint = "cmsCreateRGBProfile")]
+		public static extern IntPtr CmsCreateRGBProfile (out ColorCIExyY whitepoint, 
+						          out ColorCIExyYTriple primaries,
+							  HandleRef [] gamma_table);
+
+		[DllImport("liblcms-1.0.0.dll", EntryPoint = "cmsCreateLinearizationDeviceLink")]
+		public static extern IntPtr CmsCreateLinearizationDeviceLink (IccColorSpace color_space, HandleRef [] tables);
+		
+		[DllImport("libfspot", EntryPoint = "f_cmsCreateBCHSWabstractProfile")]
+		public static extern IntPtr FCmsCreateBCHSWabstractProfile(int nLUTPoints,
+								     double Exposure,
+								     double Bright, 
+								     double Contrast,
+								     double Hue,
+								     double Saturation,
+								     ref ColorCIExyY src_wp, 
+								     ref ColorCIExyY dest_wp,
+								     HandleRef [] tables);
+		
+		[DllImport ("libfspot", EntryPoint = "f_screen_get_profile")]
+		public static extern IntPtr FScreenGetProfile (IntPtr screen);
+
+		[DllImport ("libfspot", EntryPoint = "f_cms_gamma_table_new")]
+		public static extern IntPtr FCmsGammaTableNew (ushort [] values, int start, int length);
+
+		[DllImport ("libfspot", EntryPoint = "f_cms_gamma_table_get_values")]
+		public static extern IntPtr FCmsGammaTableGetValues (HandleRef table);
+
+		[DllImport ("libfspot", EntryPoint = "f_cms_gamma_table_get_count")]
+		public static extern int FCmsGammaTableGetCount (HandleRef table);	
 	}
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]