public static Profile CreateAbstract(int nLUTPoints, double Exposure, double Bright, double Contrast, double Hue, double Saturation, ToneCurve [] tables, ColorCIExyY srcWp, ColorCIExyY destWp) { if (tables == null) { ToneCurve gamma = new ToneCurve(Math.Pow(10, -Bright / 100)); ToneCurve line = new ToneCurve(1.0); tables = new ToneCurve [] { gamma, line, line }; } /* * System.Console.WriteLine ("e {0}", Exposure); * System.Console.WriteLine ("b {0}", Bright); * System.Console.WriteLine ("c {0}", Contrast); * System.Console.WriteLine ("h {0}", Hue); * System.Console.WriteLine ("s {0} {1} {2}", Saturation, srcWp, destWp); */ return(new Profile(NativeMethods.FCmsCreateBCHSWabstractProfile(nLUTPoints, Exposure, 0.0, //Bright, Contrast, Hue, Saturation, ref srcWp, ref destWp, CopyHandles(tables)))); }
public static ColorCIExyY WhitePointFromTemperatureResource(int temp, string name) { ColorCIExyY wp; //const int line_size = 0x1e; using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name)) { string line = string.Empty; using (var reader = new StreamReader(stream, System.Text.Encoding.ASCII)) { for (int i = 0; i <= temp - 1000; i++) { line = reader.ReadLine(); } } //System.Console.WriteLine (line); string [] subs = line.Split('\t'); int ptemp = int.Parse(subs [0]); if (ptemp != temp) { throw new CmsException($"{ptemp} != {temp}"); } double x = double.Parse(subs [1]); double y = double.Parse(subs [2]); wp = new ColorCIExyY(x, y, 1.0); return(wp); } }
public static Profile CreateGray(ColorCIExyY whitePoint, ToneCurve transfer) { if (transfer == null) { return(new Profile(NativeMethods.CmsCreateGrayProfile(ref whitePoint, new ToneCurve(2.2).Handle))); } return(new Profile(NativeMethods.CmsCreateGrayProfile(ref whitePoint, transfer.Handle))); }
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 [] curves);
public static Profile CreateAlternateRgb() { // FIXME I'm basing this off the values set in the camera // exif data when the adobe profile is selected. They could // easily be off var wp = new ColorCIExyY(.3127, .329, 1.0); var primaries = new ColorCIExyYTriple( new ColorCIExyY(.64, .33, 1.0), new ColorCIExyY(.21, .71, 1.0), new ColorCIExyY(.15, .06, 1.0)); var tc = new ToneCurve(2.2); var tcs = new ToneCurve [] { tc, tc, tc, tc }; return(new Profile(wp, primaries, tcs)); }
public static Profile CreateAbstract(int nLUTPoints, double Exposure, double Bright, double Contrast, double Hue, double Saturation, int TempSrc, int TempDest) { #if true var gamma = new ToneCurve(Math.Pow(10, -Bright / 100)); var line = new ToneCurve(1.0); var tables = new ToneCurve [] { gamma, line, line }; return(CreateAbstract(nLUTPoints, Exposure, 0.0, Contrast, Hue, Saturation, tables, ColorCIExyY.WhitePointFromTemperature(TempSrc), ColorCIExyY.WhitePointFromTemperature(TempDest))); #else GammaTable [] tables = null; return(CreateAbstract(nLUTPoints, Exposure, Bright, Contrast, Hue, Saturation, tables, ColorCIExyY.WhitePointFromTemperature(TempSrc), ColorCIExyY.WhitePointFromTemperature(TempDest))); #endif }
public ColorCIExyYTriple(ColorCIExyY red, ColorCIExyY green, ColorCIExyY blue) { Red = red; Green = green; Blue = blue; }
public static extern void CmsxyY2XYZ(out ColorCIEXYZ dest, ref ColorCIExyY src);
public ColorCIELab ToLab(ColorCIExyY wp) { return(ToXYZ().ToLab(wp)); }
public static Profile CreateAlternateRgb() { // FIXME I'm basing this off the values set in the camera // exif data when the adobe profile is selected. They could // easily be off ColorCIExyY wp = new ColorCIExyY (.3127, .329, 1.0); ColorCIExyYTriple primaries = new ColorCIExyYTriple ( new ColorCIExyY (.64, .33, 1.0), new ColorCIExyY (.21, .71, 1.0), new ColorCIExyY (.15, .06, 1.0)); ToneCurve tc = new ToneCurve (2.2); ToneCurve [] tcs = new ToneCurve [] { tc, tc, tc, tc}; return new Profile (wp, primaries, tcs); }
public static extern IntPtr CmsCreateRGBProfile(out ColorCIExyY whitepoint, out ColorCIExyYTriple primaries, HandleRef [] transfer_function);
public ColorCIELab ToLab(ColorCIExyY wp) { return ToXYZ ().ToLab (wp); }
public static ColorCIExyY WhitePointFromTemperatureResource(int temp, string name) { ColorCIExyY wp; //const int line_size = 0x1e; using (Stream stream = Assembly.GetExecutingAssembly ().GetManifestResourceStream (name)) { var reader = new StreamReader (stream, System.Text.Encoding.ASCII); string line = null; for (int i = 0; i <= temp - 1000; i++) { line = reader.ReadLine (); } //System.Console.WriteLine (line); string [] subs = line.Split ('\t'); int ptemp = int.Parse (subs [0]); if (ptemp != temp) throw new CmsException (String.Format ("{0} != {1}", ptemp, temp)); double x = double.Parse (subs [1]); double y = double.Parse (subs [2]); wp = new ColorCIExyY (x, y, 1.0); return wp; } }
public static extern IntPtr CmsCreateLabProfile(out ColorCIExyY WhitePoint);
public static extern IntPtr CmsCreateGrayProfile(ref ColorCIExyY white_point, HandleRef transfer_function);
public static extern void CmsXYZ2xyY(out ColorCIExyY dest, ref ColorCIEXYZ source);
public static extern bool CmsWhitePointFromTemp(int TempSrc, out ColorCIExyY white_point);
public static Profile CreateLab(ColorCIExyY wp) { return new Profile (NativeMethods.CmsCreateLabProfile (out wp)); }
public Cms.Profile GetProfile () { Cms.ColorCIExyY whitepoint = new Cms.ColorCIExyY (0, 0, 0); Cms.ColorCIExyYTriple primaries = new Cms.ColorCIExyYTriple (whitepoint, whitepoint, whitepoint); Cms.GammaTable [] transfer = null; int bits_per_sample = 8; double gamma = 2.2; foreach (DirectoryEntry e in entries) { switch (e.Id) { case TagId.InterColorProfile: try { return new Cms.Profile (e.RawData); } catch (System.Exception ex) { System.Console.WriteLine (ex); } break; case TagId.ColorSpace: switch ((ColorSpace)e.ValueAsLong [0]) { case ColorSpace.StandardRGB: return Cms.Profile.CreateStandardRgb (); case ColorSpace.AdobeRGB: return Cms.Profile.CreateAlternateRgb (); case ColorSpace.Uncalibrated: System.Console.WriteLine ("Uncalibrated colorspace"); break; } break; case TagId.WhitePoint: Rational [] white = e.RationalValue; whitepoint.x = white [0].Value; whitepoint.y = white [1].Value; whitepoint.Y = 1.0; break; case TagId.PrimaryChromaticities: Rational [] colors = e.RationalValue; primaries.Red.x = colors [0].Value; primaries.Red.y = colors [1].Value; primaries.Red.Y = 1.0; primaries.Green.x = colors [2].Value; primaries.Green.y = colors [3].Value; primaries.Green.Y = 1.0; primaries.Blue.x = colors [4].Value; primaries.Blue.y = colors [5].Value; primaries.Blue.Y = 1.0; break; case TagId.TransferFunction: ushort [] trns = e.ShortValue; ushort gamma_count = (ushort) (1 << bits_per_sample); Cms.GammaTable [] tables = new Cms.GammaTable [3]; System.Console.WriteLine ("Parsing transfer function: count = {0}", trns.Length); // FIXME we should use the TransferRange here // FIXME we should use bits per sample here for (int c = 0; c < 3; c++) { tables [c] = new Cms.GammaTable (trns, c * gamma_count, gamma_count); } transfer = tables; break; case TagId.ExifIfdPointer: SubdirectoryEntry exif = (SubdirectoryEntry) e; DirectoryEntry ee = exif.Directory [0].Lookup ((int)TagId.Gamma); if (ee == null) break; Rational rgamma = ee.RationalValue [0]; gamma = rgamma.Value; break; } } if (transfer == null) { Cms.GammaTable basic = new Cms.GammaTable (1 << bits_per_sample, gamma); transfer = new Cms.GammaTable [] { basic, basic, basic }; } // if we didn't get a white point or primaries, give up if (whitepoint.Y != 1.0 || primaries.Red.Y != 1.0) return null; return new Cms.Profile (whitepoint, primaries, transfer); }
public static Profile CreateAbstract(int nLUTPoints, double Exposure, double Bright, double Contrast, double Hue, double Saturation, ToneCurve [] tables, ColorCIExyY srcWp, ColorCIExyY destWp) { if (tables == null) { ToneCurve gamma = new ToneCurve (Math.Pow (10, -Bright/100)); ToneCurve line = new ToneCurve (1.0); tables = new ToneCurve [] { gamma, line, line }; } /* System.Console.WriteLine ("e {0}", Exposure); System.Console.WriteLine ("b {0}", Bright); System.Console.WriteLine ("c {0}", Contrast); System.Console.WriteLine ("h {0}", Hue); System.Console.WriteLine ("s {0} {1} {2}", Saturation, srcWp, destWp); */ return new Profile (NativeMethods.FCmsCreateBCHSWabstractProfile (nLUTPoints, Exposure, 0.0, //Bright, Contrast, Hue, Saturation, ref srcWp, ref destWp, CopyHandles (tables))); }
public static Profile CreateLab(ColorCIExyY wp) { return(new Profile(NativeMethods.CmsCreateLabProfile(out wp))); }
public static Profile CreateGray(ColorCIExyY whitePoint, ToneCurve transfer) { if (transfer == null) return new Profile (NativeMethods.CmsCreateGrayProfile (ref whitePoint, new ToneCurve (2.2).Handle)); return new Profile (NativeMethods.CmsCreateGrayProfile (ref whitePoint, transfer.Handle)); }
public Profile(ColorCIExyY whitepoint, ColorCIExyYTriple primaries, ToneCurve [] gamma) { Handle = new HandleRef (this, NativeMethods.CmsCreateRGBProfile (out whitepoint, out primaries, CopyHandles (gamma))); }
public Profile(ColorCIExyY whitepoint, ColorCIExyYTriple primaries, ToneCurve[] gamma) { Handle = new HandleRef(this, NativeMethods.CmsCreateRGBProfile(out whitepoint, out primaries, CopyHandles(gamma))); }