private static Gdk.Pixbuf Rotate(Gdk.Pixbuf pixbuf, int angle) { Gdk.Pixbuf rotated = pixbuf; for (int i = 0; i < (angle / 90); i++) { pixbuf = rotated.RotateSimple(Gdk.PixbufRotation.Counterclockwise); rotated.Dispose(); rotated = pixbuf; } return(rotated); }
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 (var img = ImageFile.Create(selected_photos[p_index].DefaultVersion.Uri)) { Gdk.Pixbuf pixbuf; try { pixbuf = img.Load((int)mx, (int)my); Cms.Profile printer_profile; if (ColorManagement.Profiles.TryGetValue(Preferences.Get <string> (Preferences.COLOR_MANAGEMENT_OUTPUT_PROFILE), out printer_profile)) { ColorManagement.ApplyProfile(pixbuf, img.GetProfile(), printer_profile); } } catch (Exception e) { Log.Exception("Unable to load image " + selected_photos[p_index].DefaultVersion.Uri + "\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 void UpdatePreview() { thumb_image.Clear(); FileIsGood = false; int size = 200, margins = 30; if (System.IO.File.Exists(mFilename)) // Selected item is a file { origsize_label.Markup = ""; GLib.Timeout.Add(100, new GLib.TimeoutHandler(delegate { Gdk.Pixmap pm = null; Gdk.GC gc = null; Gdk.Pixbuf pb = null; try { pm = new Gdk.Pixmap(thumb_image.GdkWindow, size + margins, size + margins, -1); gc = new Gdk.GC(thumb_image.GdkWindow); pm.DrawRectangle(gc, true, new Gdk.Rectangle(0, 0, size + margins, size + margins)); RawDescriptionLoader rdl = RawDescriptionLoader.FromFile(mFilename); string idtext = ""; try { idtext += "Shot has been taken\n" + " on <b>" + rdl.TimeStamp.ToString("MMMM, d, yyyy") + "</b> at <b>" + rdl.TimeStamp.ToString("h:mm:ss tt") + "</b>,\n"; idtext += " with <b>" + rdl.CameraMaker + " " + rdl.CameraModel + "</b>\n\n"; idtext += "ISO speed: <b>" + rdl.ISOSpeed.ToString("0") + "</b>\n"; if (rdl.Shutter > 1) { idtext += "Shutter: <b>" + rdl.Shutter.ToString("0.0") + "</b> sec\n"; } else { idtext += "Shutter: <b>1/" + (1.0 / (rdl.Shutter + 0.000001)).ToString("0") + "</b> sec\n"; } idtext += "Aperture: <b>" + rdl.Aperture.ToString("0.0") + "</b>\n" + "Focal length: <b>" + rdl.FocalLength.ToString("0") + "</b> mm\n"; if (rdl.Artist != "") { idtext += "Artist: <b>" + rdl.Artist + "</b>\n"; } if (rdl.Description != "") { idtext += "Description: <b>" + rdl.Description + "</b>\n"; } Console.WriteLine(rdl.Flip); // Creating the thumbnail pixbuf pb = new Gdk.Pixbuf(rdl.ThumbnailData); } catch (Exception ex) { Console.WriteLine("Can't load the thumbnail: " + ex.Message); idtext += "\n<i>Can't load the thumbnail.</i>"; } identification_label.Markup = idtext; if (pb != null) { // Scaling the thumbnail Gdk.Pixbuf pbold = pb; int imgw = pb.Width, imgh = pb.Height; if (pb.Width > pb.Height) { pb = pb.ScaleSimple(size, (int)((double)pb.Height / pb.Width * size), Gdk.InterpType.Bilinear); } else { pb = pb.ScaleSimple((int)((double)pb.Width / pb.Height * size), size, Gdk.InterpType.Bilinear); } pbold.Dispose(); // Rotating the thumbnail if (rdl.Flip != RawDescriptionLoader.FlipValues.None) { pbold = pb; if (rdl.Flip == RawDescriptionLoader.FlipValues.UpsideDown) { pb = pb.RotateSimple(Gdk.PixbufRotation.Upsidedown); } else if (rdl.Flip == RawDescriptionLoader.FlipValues.Clockwise) { int t = imgw; imgw = imgh; imgh = t; pb = pb.RotateSimple(Gdk.PixbufRotation.Clockwise); } else if (rdl.Flip == RawDescriptionLoader.FlipValues.Counterclockwise) { int t = imgw; imgw = imgh; imgh = t; pb = pb.RotateSimple(Gdk.PixbufRotation.Counterclockwise); } pbold.Dispose(); } origsize_label.Markup = "Image size: <b>" + imgw + "</b> x <b>" + imgh + "</b>"; pm.DrawPixbuf(gc, pb, 0, 0, (size + margins) / 2 - pb.Width / 2, (size + margins) / 2 - pb.Height / 2, pb.Width, pb.Height, Gdk.RgbDither.Max, 0, 0); thumb_image.SetFromPixmap(pm, null); pb.Dispose(); } FileIsGood = true; } catch (Exception #if DEBUG ex #endif ) { #if DEBUG Console.WriteLine("Exception occured during the thumbnail loading process: " + ex.Message); #endif identification_label.Wrap = true; identification_label.Markup = "<i>Cannot decode the selected file. " + "Maybe it's corrupted or the user hasn't enough access rights to open it.</i>"; FileIsGood = false; } finally { if (gc != null) { gc.Dispose(); } if (pm != null) { pm.Dispose(); } } return(false); })); } }
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 (var img = ImageFile.Create (selected_photos[p_index].DefaultVersion.Uri)) { 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].DefaultVersion.Uri + "\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 (); } } } }
protected void UpdatePreview() { thumb_image.Clear(); FileIsGood = false; int size = 200, margins = 30; if (System.IO.File.Exists(mFilename)) // Selected item is a file { origsize_label.Markup = ""; GLib.Timeout.Add(100, new GLib.TimeoutHandler(delegate { Gdk.Pixmap pm = null; Gdk.GC gc = null; Gdk.Pixbuf pb = null; try { pm = new Gdk.Pixmap(thumb_image.GdkWindow, size + margins, size + margins, -1); gc = new Gdk.GC(thumb_image.GdkWindow); pm.DrawRectangle(gc, true, new Gdk.Rectangle(0, 0, size + margins, size + margins)); RawDescriptionLoader rdl = RawDescriptionLoader.FromFile(mFilename); string idtext = ""; try { idtext += "Shot has been taken\n" + " on <b>" + rdl.TimeStamp.ToString("MMMM, d, yyyy") + "</b> at <b>" + rdl.TimeStamp.ToString("h:mm:ss tt") + "</b>,\n"; idtext += " with <b>" + rdl.CameraMaker + " " + rdl.CameraModel + "</b>\n\n"; idtext += "ISO speed: <b>" + rdl.ISOSpeed.ToString("0") + "</b>\n"; if (rdl.Shutter > 1) idtext += "Shutter: <b>" + rdl.Shutter.ToString("0.0") + "</b> sec\n"; else idtext += "Shutter: <b>1/" + (1.0 / (rdl.Shutter + 0.000001)).ToString("0") + "</b> sec\n"; idtext += "Aperture: <b>" + rdl.Aperture.ToString("0.0") + "</b>\n" + "Focal length: <b>" + rdl.FocalLength.ToString("0") + "</b> mm\n"; if (rdl.Artist != "") idtext += "Artist: <b>" + rdl.Artist + "</b>\n"; if (rdl.Description != "") idtext += "Description: <b>" + rdl.Description + "</b>\n"; Console.WriteLine(rdl.Flip); // Creating the thumbnail pixbuf pb = new Gdk.Pixbuf(rdl.ThumbnailData); } catch (Exception ex) { Console.WriteLine("Can't load the thumbnail: " + ex.Message); idtext += "\n<i>Can't load the thumbnail.</i>"; } identification_label.Markup = idtext; if (pb != null) { // Scaling the thumbnail Gdk.Pixbuf pbold = pb; int imgw = pb.Width, imgh = pb.Height; if (pb.Width > pb.Height) pb = pb.ScaleSimple(size, (int)((double)pb.Height / pb.Width * size), Gdk.InterpType.Bilinear); else pb = pb.ScaleSimple((int)((double)pb.Width / pb.Height * size), size, Gdk.InterpType.Bilinear); pbold.Dispose(); // Rotating the thumbnail if (rdl.Flip != RawDescriptionLoader.FlipValues.None) { pbold = pb; if (rdl.Flip == RawDescriptionLoader.FlipValues.UpsideDown) pb = pb.RotateSimple(Gdk.PixbufRotation.Upsidedown); else if (rdl.Flip == RawDescriptionLoader.FlipValues.Clockwise) { int t = imgw; imgw = imgh; imgh = t; pb = pb.RotateSimple(Gdk.PixbufRotation.Clockwise); } else if (rdl.Flip == RawDescriptionLoader.FlipValues.Counterclockwise) { int t = imgw; imgw = imgh; imgh = t; pb = pb.RotateSimple(Gdk.PixbufRotation.Counterclockwise); } pbold.Dispose(); } origsize_label.Markup = "Image size: <b>" + imgw + "</b> x <b>" + imgh + "</b>"; pm.DrawPixbuf(gc, pb, 0, 0, (size + margins) / 2 - pb.Width / 2, (size + margins) / 2 - pb.Height / 2, pb.Width, pb.Height, Gdk.RgbDither.Max, 0, 0); thumb_image.SetFromPixmap(pm, null); pb.Dispose(); } FileIsGood = true; } catch (Exception #if DEBUG ex #endif ) { #if DEBUG Console.WriteLine("Exception occured during the thumbnail loading process: " + ex.Message); #endif identification_label.Wrap = true; identification_label.Markup = "<i>Cannot decode the selected file. "+ "Maybe it's corrupted or the user hasn't enough access rights to open it.</i>"; FileIsGood = false; } finally { if (gc != null) gc.Dispose(); if (pm != null) pm.Dispose(); } return false; })); } }
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(); } } } }