public static unsafe void ColorAdjust(Pixbuf src, Pixbuf dest,
                                          double brightness, double contrast,
                                          double hue, double saturation,
                                          int src_color, int dest_color)
    {
        if (src.Width != dest.Width || src.Height != dest.Height)
        {
            throw new Exception("Invalid Dimensions");
        }

        //Cms.Profile eos10d = new Cms.Profile ("/home/lewing/ICCProfiles/EOS-10D-True-Color-Non-Linear.icm");
        Cms.Profile srgb = Cms.Profile.CreateStandardRgb();

        Cms.Profile bchsw = Cms.Profile.CreateAbstract(256,
                                                       0.0,
                                                       brightness, contrast,
                                                       hue, saturation, src_color,
                                                       dest_color);

        Cms.Profile [] list  = new Cms.Profile [] { srgb, bchsw, srgb };
        Cms.Transform  trans = new Cms.Transform(list,
                                                 PixbufCmsFormat(src),
                                                 PixbufCmsFormat(dest),
                                                 Cms.Intent.Perceptual, 0x0100);

        ColorAdjust(src, dest, trans);

        trans.Dispose();
        srgb.Dispose();
        bchsw.Dispose();
    }
Пример #2
0
		public Transform (Profile input, Format input_format,
				  Profile output, Format output_format,
				  Intent intent, uint flags)
		{
			this.handle = new HandleRef (this, NativeMethods.CmsCreateTransform (input.Handle, input_format,
									       output.Handle, output_format,
									       (int)intent, flags));
		}
Пример #3
0
        private void Adjust()
        {
            if (brightness_scale == null)
            {
                return;
            }

            if (AdjustedPixbuf == null)
            {
                return;
            }

            Cms.Profile    display_profile = Cms.Profile.GetScreenProfile(view.Screen);
            Cms.Profile [] list;

            if (display_profile == null)
            {
                display_profile = Cms.Profile.CreateStandardRgb();
            }

            if (!Changed || AdjustedPixbuf.HasAlpha)
            {
                if (AdjustedPixbuf.HasAlpha)
                {
                    System.Console.WriteLine("Cannot currently adjust images with an alpha channel");
                }

                list = new Cms.Profile [] { image_profile, display_profile };

                next_transform = new Cms.Transform(list,
                                                   PixbufUtils.PixbufCmsFormat(AdjustedPixbuf),
                                                   PixbufUtils.PixbufCmsFormat(AdjustedPixbuf),
                                                   Cms.Intent.Perceptual, 0x0000);
            }
            else
            {
                using (adjustment_profile = AdjustmentProfile()) {
                    list = new Cms.Profile [] { image_profile, adjustment_profile, display_profile };

                    next_transform = new Cms.Transform(list,
                                                       PixbufUtils.PixbufCmsFormat(AdjustedPixbuf),
                                                       PixbufUtils.PixbufCmsFormat(AdjustedPixbuf),
                                                       Cms.Intent.Perceptual, 0x0000);
                }
            }

            lock (AdjustedPixbuf) {
                PixbufUtils.ColorAdjust(ScaledPixbuf,
                                        AdjustedPixbuf,
                                        next_transform);
#if USE_THREAD
                expose_timeout.Start();
#else
                this.QueueDraw();
#endif
            }
        }
		public void Adjust ()
		{
			bool create_version = photo.DefaultVersionId == Photo.OriginalVersionId;
			using (ImageFile img = ImageFile.Create (photo.DefaultVersionUri)) {
				if (image == null)
					image = img.Load ();
			
				if (image_profile == null)
					image_profile = img.GetProfile ();
			}

			if (image_profile == null)
				image_profile = Cms.Profile.CreateStandardRgb ();

			if (destination_profile == null)
				destination_profile = image_profile;

			Gdk.Pixbuf final = new Gdk.Pixbuf (Gdk.Colorspace.Rgb,
							   false, 8,
							   image.Width, 
							   image.Height);
			
			Cms.Profile adjustment_profile = GenerateProfile ();
			Cms.Profile [] list;
			if (adjustment_profile != null)
				list = new Cms.Profile [] { image_profile, adjustment_profile, destination_profile };
			else
				list = new Cms.Profile [] { image_profile, destination_profile };
			
			if (image.HasAlpha) {
				Pixbuf alpha = PixbufUtils.Flatten (image);
				Transform transform = new Transform (list,
								     PixbufUtils.PixbufCmsFormat (alpha),
								     PixbufUtils.PixbufCmsFormat (final),
								     intent, 0x0000);
				PixbufUtils.ColorAdjust (alpha, final, transform);
				PixbufUtils.ReplaceColor (final, image);
				alpha.Dispose ();
				final.Dispose ();
				final = image;
			} else {
				Cms.Transform transform = new Cms.Transform (list,
									     PixbufUtils.PixbufCmsFormat (image),
									     PixbufUtils.PixbufCmsFormat (final),
									     intent, 0x0000);
				
				PixbufUtils.ColorAdjust (image, final, transform);
				image.Dispose ();
			}
				
			photo.SaveVersion (final, create_version);
			final.Dispose ();
		}
Пример #5
0
        public Transform(Profile input, Format input_format,
				  Profile output, Format output_format,
				  Intent intent, uint flags)
        {
            if (input == null)
                throw new ArgumentNullException ("input");
            if (output == null)
                throw new ArgumentNullException ("output");

            this.handle = new HandleRef (this, NativeMethods.CmsCreateTransform (input.Handle, input_format,
                                           output.Handle, output_format,
                                           (int)intent, flags));
        }
Пример #6
0
 public FullColorAdjustment(Pixbuf input, Cms.Profile input_profile,
                            double exposure, double brightness, double contrast,
                            double hue, double saturation,
                            Cms.ColorCIEXYZ src_wp, Cms.ColorCIEXYZ dest_wp)
     : base(input, input_profile)
 {
     this.exposure   = exposure;
     this.brightness = brightness;
     this.contrast   = contrast;
     this.hue        = hue;
     this.saturation = saturation;
     this.src_wp     = src_wp;
     this.dest_wp    = dest_wp;
 }
Пример #7
0
		public Transform (Profile [] profiles,
				  Format input_format,
				  Format output_format,
				  Intent intent, uint flags)
		{
			HandleRef [] handles = new HandleRef [profiles.Length];
			for (int i = 0; i < profiles.Length; i++) {
				handles [i] = profiles [i].Handle;
			}
			
			this.handle = new HandleRef (this, NativeMethods.CmsCreateMultiprofileTransform (handles, handles.Length, 
											   input_format,
											   output_format, 
											   (int)intent, flags));
		}
		private void Adjust ()
		{

			if (brightness_scale == null)
				return;
			
			if (AdjustedPixbuf == null)
				return;

			Cms.Profile display_profile = Cms.Profile.GetScreenProfile (view.Screen);
			Cms.Profile [] list;
			
			if (display_profile == null)
				display_profile = Cms.Profile.CreateStandardRgb ();
			
			if (!Changed || AdjustedPixbuf.HasAlpha) {
				if (AdjustedPixbuf.HasAlpha)
					System.Console.WriteLine ("Cannot currently adjust images with an alpha channel");

				list = new Cms.Profile [] { image_profile, display_profile };

				next_transform = new Cms.Transform (list, 
								    PixbufUtils.PixbufCmsFormat (AdjustedPixbuf),
								    PixbufUtils.PixbufCmsFormat (AdjustedPixbuf),
								    Cms.Intent.Perceptual, 0x0000);
			} else {
					
				using (adjustment_profile = AdjustmentProfile ()) {
					list = new Cms.Profile [] { image_profile, adjustment_profile, display_profile };
					
					next_transform = new Cms.Transform (list, 
									    PixbufUtils.PixbufCmsFormat (AdjustedPixbuf),
									    PixbufUtils.PixbufCmsFormat (AdjustedPixbuf),
									    Cms.Intent.Perceptual, 0x0000);
				}
			}
			
			lock (AdjustedPixbuf) {
				PixbufUtils.ColorAdjust (ScaledPixbuf,
							 AdjustedPixbuf,
							 next_transform);
#if USE_THREAD
				expose_timeout.Start ();
#else
				this.QueueDraw ();
#endif
			}
		}
Пример #9
0
        public Transform(Profile [] profiles,
				  Format input_format,
				  Format output_format,
				  Intent intent, uint flags)
        {
            if (profiles == null)
                throw new ArgumentNullException ("profiles");

            HandleRef [] handles = new HandleRef [profiles.Length];
            for (int i = 0; i < profiles.Length; i++) {
                handles [i] = profiles [i].Handle;
            }

            this.handle = new HandleRef (this, NativeMethods.CmsCreateMultiprofileTransform (handles, handles.Length,
                                               input_format,
                                               output_format,
                                               (int)intent, flags));
        }
Пример #10
0
        private void HandlePhotoChanged(PhotoImageView view)
        {
            try {
                if (!view.Item.IsValid)
                {
                    throw new Exception("Invalid Image");
                }

                using (FSpot.ImageFile img = FSpot.ImageFile.Create(((Photo)view.Item.Current).DefaultVersionUri)) {
                    try {
                        image_profile = img.GetProfile();
                    } catch (System.Exception e) {
                        image_profile = null;
                        System.Console.WriteLine(e);
                    }

                    // FIXME fall back to rgb for now
                    if (image_profile == null)
                    {
                        image_profile = Cms.Profile.CreateStandardRgb();
                    }

                    AdjustedPixbuf = img.Load(256, 256);
                    ScaledPixbuf   = AdjustedPixbuf.Copy();
                }

                if (AdjustedPixbuf.HasAlpha)
                {
                    throw new Exception("Unsupported Alpha Channel");
                }

                control_vbox.Sensitive = true;
                ok_button.Sensitive    = true;

                RangeChanged(null, null);
            } catch (System.Exception) {
                control_vbox.Sensitive = false;
                ok_button.Sensitive    = false;
                AdjustedPixbuf         = null;
                ScaledPixbuf           = null;
                image_profile          = null;
            }
        }
Пример #11
0
			public void LoadSave ()
			{
				Profile srgb = CreateStandardRgb ();
				byte [] data = srgb.Save ();
				Assert.IsNotNull (data);
				Profile result = new Profile (data);
				Assert.AreEqual (result.ProductName, srgb.ProductName);
				Assert.AreEqual (result.ProductDescription, srgb.ProductDescription);
				Assert.AreEqual (result.Model, srgb.Model);
			}
Пример #12
0
        public void Save()
        {
            if (!Changed)
            {
                this.Dialog.Destroy();
                return;
            }

            if (!view.Item.IsValid)
            {
                return;
            }

            Console.WriteLine("Saving....");

            Photo photo = (Photo)view.Item.Current;

            try {
                bool create_version = photo.DefaultVersionId == Photo.OriginalVersionId;

                Gdk.Pixbuf orig  = view.CompletePixbuf();
                Gdk.Pixbuf final = new Gdk.Pixbuf(Gdk.Colorspace.Rgb,
                                                  false, 8,
                                                  orig.Width,
                                                  orig.Height);

                Cms.Profile abs = AdjustmentProfile();

                // FIXME this shouldn't use the screen as the destination profile.
                Cms.Profile destination = Cms.Profile.GetScreenProfile(view.Screen);
                if (destination == null)
                {
                    destination = Cms.Profile.CreateStandardRgb();
                }

                Cms.Profile [] list      = new Cms.Profile [] { image_profile, abs, destination };
                Cms.Transform  transform = new Cms.Transform(list,
                                                             PixbufUtils.PixbufCmsFormat(orig),
                                                             PixbufUtils.PixbufCmsFormat(final),
                                                             Cms.Intent.Perceptual, 0x0000);

                PixbufUtils.ColorAdjust(orig,
                                        final,
                                        transform);

                photo.SaveVersion(final, create_version);
                ((PhotoQuery)view.Query).Commit(view.Item.Index);
                final.Dispose();
            } catch (System.Exception e) {
                string msg  = Catalog.GetString("Error saving adjusted photo");
                string desc = String.Format(Catalog.GetString("Received exception \"{0}\". Unable to save photo {1}"),
                                            e.Message, photo.Name);

                HigMessageDialog md = new HigMessageDialog((Gtk.Window)Dialog.Toplevel,
                                                           DialogFlags.DestroyWithParent,
                                                           Gtk.MessageType.Error, ButtonsType.Ok,
                                                           msg,
                                                           desc);
                md.Run();
                md.Destroy();
            }

            this.Dialog.Sensitive = false;
            this.Dialog.Destroy();
        }
Пример #13
0
		private void HandlePhotoChanged (PhotoImageView view)
		{
			try {
				if (!view.Item.IsValid)
 					throw new Exception ("Invalid Image");
				
				using (FSpot.ImageFile img = FSpot.ImageFile.Create (((Photo)view.Item.Current).DefaultVersionUri)) {
 					try {
 						image_profile = img.GetProfile ();
 					} catch (System.Exception e) {
 						image_profile = null;
 						System.Console.WriteLine (e);
 					}

					// FIXME fall back to rgb for now
					if (image_profile == null)
						image_profile = Cms.Profile.CreateStandardRgb ();
				
					AdjustedPixbuf = img.Load (256, 256);
					ScaledPixbuf = AdjustedPixbuf.Copy ();			
				}

				if (AdjustedPixbuf.HasAlpha)
					throw new Exception ("Unsupported Alpha Channel");

 				control_vbox.Sensitive = true;
 				ok_button.Sensitive = true;

  				RangeChanged (null, null);
  			} catch (System.Exception) {
 				control_vbox.Sensitive = false;
 				ok_button.Sensitive = false;
 				AdjustedPixbuf = null;
 				ScaledPixbuf = null;
  				image_profile = null;
  			}	
		}
Пример #14
0
		public void Save ()
		{
			if (!Changed) {
				this.Dialog.Destroy ();
				return;
			}

			if (!view.Item.IsValid)
				return;

			Console.WriteLine ("Saving....");

			Photo photo = (Photo)view.Item.Current;
			try {
				bool create_version = photo.DefaultVersionId == Photo.OriginalVersionId;
				
				Gdk.Pixbuf orig = view.CompletePixbuf ();
				Gdk.Pixbuf final = new Gdk.Pixbuf (Gdk.Colorspace.Rgb,
								   false, 8,
								   orig.Width, 
								   orig.Height);
				
				Cms.Profile abs = AdjustmentProfile ();
				
				// FIXME this shouldn't use the screen as the destination profile.
				Cms.Profile destination = Cms.Profile.GetScreenProfile (view.Screen);
				if (destination == null)
					destination = Cms.Profile.CreateStandardRgb ();
				
				Cms.Profile [] list = new Cms.Profile [] { image_profile, abs, destination };
				Cms.Transform transform = new Cms.Transform (list,
									     PixbufUtils.PixbufCmsFormat (orig),
									     PixbufUtils.PixbufCmsFormat (final),
									     Cms.Intent.Perceptual, 0x0000);
				
				PixbufUtils.ColorAdjust (orig,
							 final,
							 transform);
				
				photo.SaveVersion (final, create_version);
				((PhotoQuery)view.Query).Commit (view.Item.Index);
				final.Dispose ();
			} catch (System.Exception e) {
				string msg = Catalog.GetString ("Error saving adjusted photo");
				string desc = String.Format (Catalog.GetString ("Received exception \"{0}\". Unable to save photo {1}"),
							     e.Message, photo.Name);
				
				HigMessageDialog md = new HigMessageDialog ((Gtk.Window)Dialog.Toplevel,
									    DialogFlags.DestroyWithParent, 
									    Gtk.MessageType.Error, ButtonsType.Ok, 
									    msg,
									    desc);
				md.Run ();
				md.Destroy ();
			}

			this.Dialog.Sensitive = false;
			this.Dialog.Destroy ();
		}
Пример #15
0
 public Adjustment(Pixbuf input, Profile inputProfile)
 {
     Input = input;
     InputProfile = inputProfile;
 }
Пример #16
0
 public SepiaTone(Pixbuf input, Cms.Profile input_profile) : base(input, input_profile)
 {
 }
Пример #17
0
 public Adjustment(Pixbuf input, Cms.Profile input_profile)
 {
     Input        = input;
     InputProfile = input_profile;
 }
Пример #18
0
        public void Adjust()
        {
            bool create_version = photo.DefaultVersionId == Photo.OriginalVersionId;

            using (ImageFile img = ImageFile.Create(photo.DefaultVersionUri)) {
                if (image == null)
                {
                    image = img.Load();
                }

                if (image_profile == null)
                {
                    image_profile = img.GetProfile();
                }
            }

            if (image_profile == null)
            {
                image_profile = Cms.Profile.CreateStandardRgb();
            }

            if (destination_profile == null)
            {
                destination_profile = image_profile;
            }

            Gdk.Pixbuf final = new Gdk.Pixbuf(Gdk.Colorspace.Rgb,
                                              false, 8,
                                              image.Width,
                                              image.Height);

            Cms.Profile    adjustment_profile = GenerateProfile();
            Cms.Profile [] list;
            if (adjustment_profile != null)
            {
                list = new Cms.Profile [] { image_profile, adjustment_profile, destination_profile }
            }
            ;
            else
            {
                list = new Cms.Profile [] { image_profile, destination_profile }
            };

            if (image.HasAlpha)
            {
                Pixbuf    alpha     = PixbufUtils.Flatten(image);
                Transform transform = new Transform(list,
                                                    PixbufUtils.PixbufCmsFormat(alpha),
                                                    PixbufUtils.PixbufCmsFormat(final),
                                                    intent, 0x0000);
                PixbufUtils.ColorAdjust(alpha, final, transform);
                PixbufUtils.ReplaceColor(final, image);
                alpha.Dispose();
                final.Dispose();
                final = image;
            }
            else
            {
                Cms.Transform transform = new Cms.Transform(list,
                                                            PixbufUtils.PixbufCmsFormat(image),
                                                            PixbufUtils.PixbufCmsFormat(final),
                                                            intent, 0x0000);

                PixbufUtils.ColorAdjust(image, final, transform);
                image.Dispose();
            }

            photo.SaveVersion(final, create_version);
            final.Dispose();
        }
    }
Пример #19
0
 protected override Adjustment CreateAdjustment(Pixbuf input, Cms.Profile input_profile)
 {
     return(new FSpot.ColorAdjustment.AutoStretch(input, input_profile));
 }
Пример #20
0
 public Desaturate(Pixbuf input, Cms.Profile input_profile) : base(input, input_profile)
 {
 }
Пример #21
0
		protected virtual Profile [] Prepare (Gdk.Pixbuf image)
		{
			Profile [] list;

			if (link != null)
				list = new Profile [] { link };
			else if (adjustment != null)
				list = new Profile [] { profile, adjustment, destination };
			else
				list = new Profile [] { profile, destination };

			return list;
		}
Пример #22
0
		public ColorFilter (Profile adjustment)
		{
			this.adjustment = adjustment;
		}
Пример #23
0
 public AutoStretch(Pixbuf input, Profile input_profile)
     : base(input, input_profile)
 {
 }
Пример #24
0
 public void SetDestination(Cms.Profile profile)
 {
     destination_profile = profile;
 }
Пример #25
0
		public bool Convert (FilterRequest req)
		{
			Uri source = req.Current;
			using (ImageFile img = ImageFile.Create (source)) {
				pixbuf = img.Load ();
				profile = img.GetProfile ();
	
				// If the image doesn't have an embedded profile assume it is sRGB
				if (profile == null)
					profile = Profile.CreateStandardRgb ();
	
				if (destination == null)
					destination = profile;
	
				Gdk.Pixbuf final = new Gdk.Pixbuf (Gdk.Colorspace.Rgb,
								   false, 8,
								   pixbuf.Width, 
								   pixbuf.Height);
	
				Profile [] list = Prepare (pixbuf);
	
				if (pixbuf.HasAlpha) {
					Gdk.Pixbuf alpha = PixbufUtils.Flatten (pixbuf);
					Transform transform = new Transform (list,
									     PixbufUtils.PixbufCmsFormat (alpha),
									     PixbufUtils.PixbufCmsFormat (final),
									     rendering_intent, 0x0000);
					PixbufUtils.ColorAdjust (alpha, final, transform);
					PixbufUtils.ReplaceColor (final, pixbuf);
					alpha.Dispose ();
					final.Dispose ();
					final = pixbuf;
				} else {
					Transform transform = new Transform (list,
									     PixbufUtils.PixbufCmsFormat (pixbuf),
									     PixbufUtils.PixbufCmsFormat (final),
									     rendering_intent, 0x0000);
					PixbufUtils.ColorAdjust (pixbuf, final, transform);
					pixbuf.Dispose ();
				}
				
				Uri dest_uri = req.TempUri (Path.GetExtension (source.LocalPath));
				using (Stream output = File.OpenWrite (dest_uri.LocalPath)) {
					img.Save (final, output);
				}
				final.Dispose ();
				req.Current = dest_uri;
				
				return true;
			}
		}
		public void SetDestination (Cms.Profile profile)
		{
			destination_profile = profile;
		}
Пример #27
0
			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);
					}
				}

			}
Пример #28
0
			public void Process (string name, Profile profile)
			{
				string path = CreateFile (name, 120);
				using (FilterRequest req = new FilterRequest (path)) {
					IFilter filter = new ColorFilter (profile);
					Assert.IsTrue (filter.Convert (req), "Filter failed to operate");
					Assert.IsTrue (System.IO.File.Exists (req.Current.LocalPath),
						       "Error: Did not create " + req.Current.LocalPath);
					Assert.IsTrue (new FileInfo (req.Current.LocalPath).Length > 0,
						       "Error: " + req.Current.LocalPath + "is Zero length");
				}
			}
Пример #29
0
 public AutoStretch(Pixbuf input, Cms.Profile input_profile) : base(input, input_profile)
 {
 }
Пример #30
0
 protected abstract Adjustment CreateAdjustment(Pixbuf input, Cms.Profile input_profile);