ColorAdjust() public static method

public static ColorAdjust ( Pixbuf src, double brightness, double contrast, double hue, double saturation, int src_color, int dest_color ) : Pixbuf
src Pixbuf
brightness double
contrast double
hue double
saturation double
src_color int
dest_color int
return Pixbuf
Esempio n. 1
0
        public Pixbuf Adjust()
        {
            Gdk.Pixbuf final = new Gdk.Pixbuf(Gdk.Colorspace.Rgb,
                                              false, 8,
                                              Input.Width,
                                              Input.Height);
            Cms.Profile [] list = GenerateAdjustments().ToArray();

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

                PixbufUtils.ColorAdjust(Input, final, transform);
            }

            return(final);
        }
Esempio n. 2
0
        public Pixbuf Adjust()
        {
            var final = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, false, 8, Input.Width, Input.Height);

            Profile[] list = GenerateAdjustments().ToArray();

            if (Input.HasAlpha)
            {
                var inputCopy = (Gdk.Pixbuf)Input.Clone();
                var alpha     = PixbufUtils.Flatten(Input);
                var transform = new Transform(list, PixbufUtils.PixbufCmsFormat(alpha), PixbufUtils.PixbufCmsFormat(final), intent, 0x0000);
                PixbufUtils.ColorAdjust(alpha, final, transform);
                PixbufUtils.ReplaceColor(final, inputCopy);
                alpha.Dispose();
                final.Dispose();
                final = inputCopy;
            }
            else
            {
                var transform = new Transform(list, PixbufUtils.PixbufCmsFormat(Input), PixbufUtils.PixbufCmsFormat(final), intent, 0x0000);

                PixbufUtils.ColorAdjust(Input, final, transform);
            }

            return(final);
        }
Esempio n. 3
0
 //the main apply color profile method. it use the _standart_ image profile and current display profile
 public static void ApplyScreenProfile(Gdk.Pixbuf pixbuf)
 {
     if (IsEnabled && pixbuf != null && !pixbuf.HasAlpha)
     {
         PixbufUtils.ColorAdjust(pixbuf, pixbuf, standart_transform);
     }
 }
        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 static unsafe Pixbuf ColorAdjust(Pixbuf src, double brightness, double contrast,
                                            double hue, double saturation, int src_color, int dest_color)
    {
        Pixbuf adjusted = new Pixbuf(Colorspace.Rgb, src.HasAlpha, 8, src.Width, src.Height);

        PixbufUtils.ColorAdjust(src, adjusted, brightness, contrast, hue, saturation, src_color, dest_color);
        return(adjusted);
    }
Esempio n. 6
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
            }
        }
Esempio n. 7
0
        public static void ApplyProfile(Gdk.Pixbuf pixbuf, Profile imageProfile, Profile destinationProfile)
        {
            if (pixbuf == null || pixbuf.HasAlpha)
            {
                return;
            }

            imageProfile = imageProfile ?? Profile.CreateStandardRgb();

            Profile[] list      = { imageProfile, destinationProfile };
            var       transform = new Transform(list, PixbufUtils.PixbufCmsFormat(pixbuf), PixbufUtils.PixbufCmsFormat(pixbuf),
                                                Intent.Perceptual, 0x0000);

            PixbufUtils.ColorAdjust(pixbuf, pixbuf, transform);
        }
Esempio n. 8
0
//		public static void ApplyScreenProfile (Gdk.Pixbuf src, Gdk.Pixbuf dest)
//		{
//			PixbufUtils.ColorAdjust (src, dest, standart_transform);
//		}

        public static void ApplyPrinterProfile(Gdk.Pixbuf pixbuf, Cms.Profile image_profile)
        {
            if (IsEnabled && pixbuf != null && !pixbuf.HasAlpha)
            {
                if (image_profile == null)
                {
                    image_profile = Cms.Profile.CreateStandardRgb();
                }

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

                Cms.Transform transform = new Cms.Transform(list,
                                                            PixbufUtils.PixbufCmsFormat(pixbuf),
                                                            PixbufUtils.PixbufCmsFormat(pixbuf),
                                                            Cms.Intent.Perceptual, 0x0000);
                PixbufUtils.ColorAdjust(pixbuf, pixbuf, transform);
            }
        }
Esempio n. 9
0
 //it works also but it uses the image_profile too
 public static void ApplyScreenProfile(Gdk.Pixbuf pixbuf, Cms.Profile image_profile)
 {
     if (IsEnabled && pixbuf != null && !pixbuf.HasAlpha)
     {
         if (image_profile == null)
         {
             ApplyScreenProfile(pixbuf);
         }
         else
         {
             Cms.Profile [] list      = new Cms.Profile [] { image_profile, display_profile };
             Cms.Transform  transform = new Cms.Transform(list,
                                                          PixbufUtils.PixbufCmsFormat(pixbuf),
                                                          PixbufUtils.PixbufCmsFormat(pixbuf),
                                                          Cms.Intent.Perceptual, 0x0000);
             PixbufUtils.ColorAdjust(pixbuf, pixbuf, transform);
         }
     }
 }
Esempio n. 10
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();
        }
    }
Esempio n. 11
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();
        }