Пример #1
0
        private Texture CreateTexture()
        {
            if (glx == null || GdkWindow == null)
            {
                return(null);
            }

            glx.MakeCurrent(GdkWindow);

            Texture tex;

            try {
                using (ImageFile img = ImageFile.Create(item.Current.DefaultVersionUri)) {
                    using (Gdk.Pixbuf pixbuf = img.Load()) {
                        FSpot.ColorManagement.ApplyScreenProfile(pixbuf, img.GetProfile());
                        tex = new Texture(pixbuf);
                    }
                }
            } catch (Exception) {
                tex = new Texture(PixbufUtils.ErrorPixbuf);
            }
            return(tex);
        }
        public void Load(Uri uri)
        {
            this.uri = uri;

            delay.Stop();

            if (!done_reading)
            {
                Close();
            }

            done_reading  = false;
            area_prepared = false;
            damage        = Gdk.Rectangle.Zero;

            using (ImageFile img = ImageFile.Create(uri)) {
                orientation = Accelerometer.GetViewOrientation(img.Orientation);

                try {
                    PixbufOrientation thumb_orientation = Accelerometer.GetViewOrientation(PixbufOrientation.TopLeft);
                    thumb = new Gdk.Pixbuf(ThumbnailGenerator.ThumbnailPath(uri));
                    thumb = PixbufUtils.TransformOrientation(thumb, thumb_orientation);

                    if (FSpot.ColorManagement.IsEnabled && !thumb.HasAlpha)
                    {
                        if (img.GetProfile() == null)
                        {
                            FSpot.ColorManagement.PhotoImageView.Transform = FSpot.ColorManagement.StandartTransform();
                        }
                        else
                        {
                            FSpot.ColorManagement.PhotoImageView.Transform = FSpot.ColorManagement.CreateTransform(thumb, img.GetProfile());
                        }
                    }
                    else
                    {
                        FSpot.ColorManagement.PhotoImageView.Transform = null;
                    }
                } catch (System.Exception e) {
                    //FSpot.ThumbnailGenerator.Default.Request (uri.ToString (), 0, 256, 256);
                    if (!(e is GLib.GException))
                    {
                        System.Console.WriteLine(e.ToString());
                    }
                }

                System.IO.Stream nstream = img.PixbufStream();
                if (nstream == null)
                {
                    FileLoad(img);
                    return;
                }
                else
                {
                    stream = new StreamWrapper(nstream);
                }

                loader = new Gdk.PixbufLoader();
                loader.AreaPrepared += ap;
                loader.AreaUpdated  += au;
                loader.Closed       += ev;

                if (AreaPrepared != null && thumb != null)
                {
                    pixbuf = thumb;
                    AreaPrepared(this, new AreaPreparedArgs(true));
                }

                ThumbnailGenerator.Default.PushBlock();
                //AsyncIORead (null);
                if (nstream is IOChannel)
                {
                    ((IOChannel)nstream).DataReady += IOChannelRead;
                }
                else
                {
                    delay.Start();
                }
            }
        }
Пример #3
0
        protected override void OnDrawPage(Gtk.PrintContext context, int page_nr)
        {
            base.OnDrawPage (context, page_nr);
            Context cr = context.CairoContext;

            int ppx, ppy;
            switch (photos_per_page) {
            default:
            case 1: ppx = ppy =1; break;
            case 2: ppx = 1; ppy = 2; break;
            case 4: ppx = ppy = 2; break;
            case 9: ppx = ppy = 3; break;
            case 12: ppx = 3; ppy = 4; break;
            case 20: ppx = 4; ppy = 5; break;
            case 30: ppx = 5; ppy = 6; break;
            }

            //FIXME: if paper is landscape, swap ppx with ppy

            double w = context.Width / ppx;
            double h = context.Height / ppy;

            // compute picture size using 4800DPI
            double mx=(w / 25.4) * 4800, my=(h / 25.4) * 4800;

            for (int x = 0; x <= ppx; x++) {
                for (int y = 0; y <= ppy; y++) {
                    int p_index = repeat ? page_nr : page_nr * photos_per_page + y * ppx + x;
                    if (crop_marks)
                        DrawCropMarks (cr, x*w, y*h, w*.1);
                    if (x == ppx || y == ppy || p_index >= selected_photos.Length)
                        continue;
                    using (ImageFile img = new ImageFile (selected_photos[p_index].DefaultVersionUri))
                    {
                        Gdk.Pixbuf pixbuf;
                        try {
                            pixbuf = img.Load ((int) mx, (int) my);
                            Cms.Profile printer_profile;
                            if (FSpot.ColorManagement.Profiles.TryGetValue (Preferences.Get<string> (Preferences.COLOR_MANAGEMENT_OUTPUT_PROFILE), out printer_profile))
                                FSpot.ColorManagement.ApplyProfile (pixbuf, img.GetProfile (), printer_profile);
                        } catch (Exception e) {
                            Log.Exception ("Unable to load image " + selected_photos[p_index].DefaultVersionUri + "\n", e);
                            // If the image is not found load error pixbuf
                            pixbuf = new Gdk.Pixbuf (PixbufUtils.ErrorPixbuf, 0, 0,
                                              PixbufUtils.ErrorPixbuf.Width,
                                              PixbufUtils.ErrorPixbuf.Height);
                        }
                        //Gdk.Pixbuf pixbuf = img.Load (100, 100);
                        bool rotated = false;
                        if (Math.Sign ((double)pixbuf.Width/pixbuf.Height - 1.0) != Math.Sign (w/h - 1.0)) {
                            Gdk.Pixbuf d_pixbuf = pixbuf.RotateSimple (Gdk.PixbufRotation.Counterclockwise);
                            pixbuf.Dispose ();
                            pixbuf = d_pixbuf;
                            rotated = true;
                        }

                        DrawImage (cr, pixbuf, x * w, y * h, w, h);

                        string tag_string = "";
                        foreach (Tag t in selected_photos[p_index].Tags)
                            tag_string = String.Concat (tag_string, t.Name);

                        string label = String.Format (print_label_format,
                                          comment,
                                          selected_photos[p_index].Name,
                                          selected_photos[p_index].Time.ToLocalTime ().ToShortDateString (),
                                          selected_photos[p_index].Time.ToLocalTime ().ToShortTimeString (),
                                          tag_string,
                                          selected_photos[p_index].Description);

                        DrawComment (context, (x + 1) * w, (rotated ? y : y + 1) * h, (rotated ? w : h) * .025, label, rotated);

                        pixbuf.Dispose ();
                    }
                }
            }
        }
		protected override void OnDrawPage (Gtk.PrintContext context, int page_nr)
		{
			base.OnDrawPage (context, page_nr);
			Context cr = context.CairoContext;	

			int ppx, ppy;
			switch (photos_per_page) {
			default:
			case 1: ppx = ppy =1; break;
			case 2: ppx = 1; ppy = 2; break;
			case 4: ppx = ppy = 2; break;
			case 9: ppx = ppy = 3; break;
			}

			//FIXME: if paper is landscape, swap ppx with ppy

			double w = context.Width / ppx;
			double h = context.Height / ppy;

			for (int x = 0; x <= ppx; x++) {
				for (int y = 0; y <= ppy; y++) {
					int p_index = repeat ? page_nr : page_nr * photos_per_page + y * ppx + x;
					if (crop_marks)
						DrawCropMarks (cr, x*w, y*h, w*.1);
					if (x == ppx || y == ppy || p_index >= selected_photos.Length)
						continue;
					using (ImageFile img = new ImageFile (selected_photos[p_index].DefaultVersionUri))
					{
						Gdk.Pixbuf pixbuf;
						try {
							pixbuf = img.Load ();
							FSpot.ColorManagement.ApplyPrinterProfile (pixbuf, img.GetProfile ());
						} catch (Exception e) {
							Log.Exception ("Unable to load image " + selected_photos[p_index].DefaultVersionUri + "\n", e);
							// If the image is not found load error pixbuf
							pixbuf = new Gdk.Pixbuf (PixbufUtils.ErrorPixbuf, 0, 0, 
										      PixbufUtils.ErrorPixbuf.Width, 
										      PixbufUtils.ErrorPixbuf.Height);
						}
						//Gdk.Pixbuf pixbuf = img.Load (100, 100);
						bool rotated = false;
						if (Math.Sign ((double)pixbuf.Width/pixbuf.Height - 1.0) != Math.Sign (w/h - 1.0)) {
							Gdk.Pixbuf d_pixbuf = pixbuf.RotateSimple (Gdk.PixbufRotation.Counterclockwise);
							pixbuf.Dispose ();
							pixbuf = d_pixbuf;
							rotated = true;
						}

						DrawImage (cr, pixbuf, x * w, y * h, w, h);
						DrawComment (context, (x + 1) * w, (rotated ? y : y + 1) * h, (rotated ? w : h) * .025, comment, rotated);
						pixbuf.Dispose ();
					}
				}
			}

		}
Пример #5
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();
        }
    }
Пример #6
0
        protected override void OnDrawPage(Gtk.PrintContext context, int page_nr)
        {
            base.OnDrawPage(context, page_nr);
            Context cr = context.CairoContext;

            int ppx, ppy;

            switch (photos_per_page)
            {
            default:
            case 1: ppx = ppy = 1; break;

            case 2: ppx = 1; ppy = 2; break;

            case 4: ppx = ppy = 2; break;

            case 9: ppx = ppy = 3; break;
            }

            //FIXME: if paper is landscape, swap ppx with ppy

            double w = context.Width / ppx;
            double h = context.Height / ppy;

            for (int x = 0; x <= ppx; x++)
            {
                for (int y = 0; y <= ppy; y++)
                {
                    int p_index = repeat ? page_nr : page_nr * photos_per_page + y * ppx + x;
                    if (crop_marks)
                    {
                        DrawCropMarks(cr, x * w, y * h, w * .1);
                    }
                    if (x == ppx || y == ppy || p_index >= selected_photos.Length)
                    {
                        continue;
                    }
                    using (ImageFile img = new ImageFile(selected_photos[p_index].DefaultVersionUri))
                    {
                        Gdk.Pixbuf pixbuf;
                        try {
                            pixbuf = img.Load();
                            FSpot.ColorManagement.ApplyPrinterProfile(pixbuf, img.GetProfile());
                        } catch (Exception e) {
                            Log.Exception("Unable to load image " + selected_photos[p_index].DefaultVersionUri + "\n", e);
                            // If the image is not found load error pixbuf
                            pixbuf = new Gdk.Pixbuf(PixbufUtils.ErrorPixbuf, 0, 0,
                                                    PixbufUtils.ErrorPixbuf.Width,
                                                    PixbufUtils.ErrorPixbuf.Height);
                        }
                        //Gdk.Pixbuf pixbuf = img.Load (100, 100);
                        bool rotated = false;
                        if (Math.Sign((double)pixbuf.Width / pixbuf.Height - 1.0) != Math.Sign(w / h - 1.0))
                        {
                            Gdk.Pixbuf d_pixbuf = pixbuf.RotateSimple(Gdk.PixbufRotation.Counterclockwise);
                            pixbuf.Dispose();
                            pixbuf  = d_pixbuf;
                            rotated = true;
                        }

                        DrawImage(cr, pixbuf, x * w, y * h, w, h);
                        DrawComment(context, (x + 1) * w, (rotated ? y : y + 1) * h, (rotated ? w : h) * .025, comment, rotated);
                        pixbuf.Dispose();
                    }
                }
            }
        }