Flatten() public static method

public static Flatten ( Pixbuf pixbuf ) : Pixbuf
pixbuf Pixbuf
return Pixbuf
        public void SaveLoad()
        {
            using (Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(null, "f-spot-32.png")) {
                Gdk.Pixbuf source = pixbuf;
                if (pixbuf.HasAlpha)
                {
                    source = PixbufUtils.Flatten(pixbuf);
                }

                string  path = ImageFile.TempPath("test.ppm");
                PnmFile pnm  = new PnmFile(path);
                using (Stream stream = File.OpenWrite(path)) {
                    pnm.Save(source, stream);
                }

                pnm = new PnmFile(path);

                using (Gdk.Pixbuf saved = pnm.Load()) {
                    Assert.IsNotNull(saved);
                    Assert.AreEqual(saved.Width, source.Width);
                    Assert.AreEqual(saved.Height, source.Height);
                }

                if (source != pixbuf)
                {
                    source.Dispose();
                }

                File.Delete(path);
            }
        }
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
        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);
        }
        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);
            }
        }
Esempio n. 5
0
        private void Render()
        {
            double page_width, page_height;

            print_job.GetPageSize(out page_width, out page_height);
            Gnome.PrintContext ctx = print_job.Context;

            ArrayList exceptions = new ArrayList();

            foreach (Photo photo in photos)
            {
                Gdk.Pixbuf image = null;
                try {
                    image = FSpot.PhotoLoader.Load(photo);

                    if (image == null)
                    {
                        throw new System.Exception("Error loading picture");
                    }
                } catch (Exception e) {
                    exceptions.Add(e);
                    continue;
                }

                Gdk.Pixbuf flat = PixbufUtils.Flatten(image);
                if (flat != null)
                {
                    image.Dispose();
                    image = flat;
                }

                Gnome.Print.Beginpage(ctx, "F-Spot" + photo.DefaultVersionUri.ToString());

                bool   rotate = false;
                double width  = page_width;
                double height = page_height;
                if (image.Width > image.Height)
                {
                    rotate = true;
                    width  = page_height;
                    height = page_width;
                }

                double scale = System.Math.Min(width / image.Width,
                                               height / image.Height);

                Gnome.Print.Gsave(ctx);

                if (rotate)
                {
                    Gnome.Print.Rotate(ctx, 90);
                    Gnome.Print.Translate(ctx, 0, -page_width);
                }

                Gnome.Print.Translate(ctx,
                                      (width - image.Width * scale) / 2.0,
                                      (height - image.Height * scale) / 2.0);

                Gnome.Print.Scale(ctx, image.Width * scale, image.Height * scale);
                Gnome.Print.Pixbuf(ctx, image);
                Gnome.Print.Grestore(ctx);

                Gnome.Print.Showpage(ctx);
                image.Dispose();
            }

            print_job.Close();

            if (exceptions.Count != 0)
            {
                //FIXME string freeze the message here is not
                //really appropriate to the problem.
                Dialog md = new EditExceptionDialog(print_dialog,
                                                    (Exception [])exceptions.ToArray(typeof(Exception)));
                md.Run();
                md.Destroy();
            }
        }
Esempio n. 6
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();
        }
    }