Example #1
0
 public void TestAlloc()
 {
     ushort [] values = new ushort [] { 0, 0x00ff, 0xffff };
     GammaTable t = new GammaTable (values);
     for (int i = 0; i < values.Length; i++) {
         Assert.AreEqual (t[i], values [i]);
     }
 }
Example #2
0
        protected override List <Cms.Profile> GenerateAdjustments()
        {
            List <Cms.Profile> profiles = new List <Cms.Profile> ();
            Histogram          hist     = new Histogram(Input);

            tables = new GammaTable [3];

            for (int channel = 0; channel < tables.Length; channel++)
            {
                int high, low;
                hist.GetHighLow(channel, out high, out low);
                System.Console.WriteLine("high = {0}, low = {1}", high, low);
                tables [channel] = StretchChannel(255, low / 255.0, high / 255.0);
            }
            profiles.Add(new Cms.Profile(IccColorSpace.Rgb, tables));
            return(profiles);
        }
            public void Linearize(string name)
            {
                GammaTable table = new GammaTable(new ushort [] { 0x0000, 0x0000, 0x0000, 0x0000 });
                Profile    link  = new Profile(IccColorSpace.Rgb, new GammaTable [] { table, table, table });

                string path = CreateFile(name, 32);

                using (FilterRequest req = new FilterRequest(path)) {
                    ColorFilter filter = new ColorFilter();
                    filter.DeviceLink = link;
                    Assert.IsTrue(filter.Convert(req), "Filter failed to operate");
                    req.Preserve(req.Current);
                    Assert.IsTrue(System.IO.File.Exists(req.Current.LocalPath),
                                  "Error: Did not create " + req.Current);
                    Assert.IsTrue(new FileInfo(req.Current.LocalPath).Length > 0,
                                  "Error: " + req.Current + "is Zero length");
                    using (ImageFile img = ImageFile.Create(req.Current)) {
                        Pixbuf pixbuf = img.Load();
                        Assert.IsNotNull(pixbuf);
                        // We linearized to all black so this should pass the gray test
                        Assert.IsTrue(PixbufUtils.IsGray(pixbuf, 1), "failed to linearize" + req.Current);
                    }
                }
            }
Example #4
0
		public override Cms.Profile GetProfile ()
		{
			ColorChunk color = null;
			IccpChunk icc = null;
			GammaChunk gamma = null;
			StandardRgbChunk srgb = null;
			double gamma_value = 2.2;
			ColorCIExyY red = new ColorCIExyY (0.64, 0.33, 1.0);
			ColorCIExyY green = new ColorCIExyY (0.3, 0.6, 1.0);
			ColorCIExyY blue = new ColorCIExyY (0.15, 0.06, 1.0);
			ColorCIExyY whitepoint = new ColorCIExyY (0.3127, 0.329, 1.0);
			ColorCIExyYTriple chroma = new ColorCIExyYTriple (red, green, blue);

			//System.Console.WriteLine ("Trying to get profile");

			foreach (Chunk chunk in Chunks) {
				if (color == null) 
					color = chunk as ColorChunk;
				if (icc == null)
					icc = chunk as IccpChunk;
				if (srgb == null)
					srgb = chunk as StandardRgbChunk;
				if (gamma == null)
					gamma = chunk as GammaChunk;
			}
			
			//System.Console.WriteLine ("color: {0} icc: {1} srgb: {2} gamma: {3}", color, icc, srgb, gamma);

			if (icc != null) {
				try {
					return new Profile (icc.Profile);
				} catch (System.Exception ex) {
					//System.Console.WriteLine ("Error trying to decode embedded profile" + ex.ToString ());
				}
			}

			if (srgb != null)
				return Profile.CreateStandardRgb ();

			if (gamma != null)
				gamma_value = 1 / gamma.Gamma;
			
			if (color != null) {
				whitepoint = new ColorCIExyY (color.WhiteX.Value, color.WhiteY.Value, 1.0);
				red = new ColorCIExyY (color.RedX.Value, color.RedY.Value, 1.0);
				green = new ColorCIExyY (color.GreenX.Value, color.GreenY.Value, 1.0);
				blue = new ColorCIExyY (color.BlueX.Value, color.BlueY.Value, 1.0);
				chroma = new ColorCIExyYTriple (red, green, blue);
			}

			if (color != null || gamma != null) {
				GammaTable table = new GammaTable (1024, gamma_value);
				return new Profile (whitepoint, chroma, new GammaTable [] {table, table, table});
			}
			
			return null;
		}