예제 #1
0
    public void WriteMetadataToImage()
    {
        string path = this.DefaultVersionUri.LocalPath;

        using (FSpot.ImageFile img = FSpot.ImageFile.Create(DefaultVersionUri)) {
            if (img is FSpot.JpegFile)
            {
                FSpot.JpegFile jimg = img as FSpot.JpegFile;

                jimg.SetDescription(this.Description);
                jimg.SetDateTimeOriginal(this.Time.ToLocalTime());
                jimg.SetXmp(UpdateXmp(this, jimg.Header.GetXmp()));

                jimg.SaveMetaData(path);
            }
            else if (img is FSpot.Png.PngFile)
            {
                FSpot.Png.PngFile png = img as FSpot.Png.PngFile;

                if (img.Description != this.Description)
                {
                    png.SetDescription(this.Description);
                }

                png.SetXmp(UpdateXmp(this, png.GetXmp()));

                png.Save(path);
            }
        }
    }
예제 #2
0
    public Photo Create(System.Uri new_uri, System.Uri orig_uri, uint roll_id, out Pixbuf thumbnail)
    {
        Photo photo;

        using (FSpot.ImageFile img = FSpot.ImageFile.Create(orig_uri)) {
            long   unix_time   = DbUtils.UnixTimeFromDateTime(img.Date);
            string description = img.Description != null?img.Description.Split('\0') [0] : String.Empty;

            string md5_sum = Photo.GenerateMD5(new_uri);

            uint id = (uint)Database.Execute(
                new DbCommand(
                    "INSERT INTO photos (time, uri, description, roll_id, default_version_id, rating, md5_sum) " +
                    "VALUES (:time, :uri, :description, :roll_id, :default_version_id, :rating, :md5_sum)",
                    "time", unix_time,
                    "uri", new_uri.OriginalString,
                    "description", description,
                    "roll_id", roll_id,
                    "default_version_id", Photo.OriginalVersionId,
                    "rating", "0",
                    "md5_sum", md5_sum
                    )
                );

            photo = new Photo(id, unix_time, new_uri, md5_sum);
            AddToCache(photo);
            photo.Loaded = true;

            thumbnail = GenerateThumbnail(new_uri, img);
            EmitAdded(photo);
        }
        return(photo);
    }
    public static string ChooseLocation(string path, Stack created_directories)
    {
        string   name = System.IO.Path.GetFileName(path);
        DateTime time;

        using (FSpot.ImageFile img = FSpot.ImageFile.Create(path)) {
            time = img.Date;
        }

        string dest_dir = String.Format("{0}{1}{2}{1}{3:D2}{1}{4:D2}",
                                        FSpot.Global.PhotoDirectory,
                                        System.IO.Path.DirectorySeparatorChar,
                                        time.Year,
                                        time.Month,
                                        time.Day);

        if (!System.IO.Directory.Exists(dest_dir))
        {
            System.IO.DirectoryInfo info;
            // Split dest_dir into constituent parts so we can clean up each individual directory in
            // event of a cancel.
            if (created_directories != null)
            {
                string [] parts    = dest_dir.Split(new char [] { System.IO.Path.DirectorySeparatorChar });
                string    nextPath = String.Empty;
                for (int i = 0; i < parts.Length; i++)
                {
                    if (i == 0)
                    {
                        nextPath += parts [i];
                    }
                    else
                    {
                        nextPath += System.IO.Path.DirectorySeparatorChar + parts [i];
                    }
                    if (nextPath.Length > 0)
                    {
                        info = new System.IO.DirectoryInfo(nextPath);
                        // only add the directory path if it didn't already exist and we haven't already added it.
                        if (!info.Exists && !created_directories.Contains(nextPath))
                        {
                            created_directories.Push(nextPath);
                        }
                    }
                }
            }

            info = System.IO.Directory.CreateDirectory(dest_dir);
        }

        // If the destination we'd like to use is the file itself return that
        if (Path.Combine(dest_dir, name) == path)
        {
            return(path);
        }

        string dest = UniqueName(dest_dir, name);

        return(dest);
    }
예제 #4
0
    public Photo Create(string newPath, string origPath, uint roll_id, out Pixbuf thumbnail)
    {
        Photo photo;

        using (FSpot.ImageFile img = FSpot.ImageFile.Create(origPath)) {
            long   unix_time   = DbUtils.UnixTimeFromDateTime(img.Date);
            string description = img.Description != null?img.Description.Split('\0') [0] : String.Empty;

            uint id = (uint)Database.Execute(new DbCommand("INSERT INTO photos (time, " +
                                                           "directory_path, name, description, roll_id, default_version_id) " +
                                                           "VALUES (:time, :directory_path, :name, :description, " +
                                                           ":roll_id, :default_version_id)",
                                                           "time", unix_time,
                                                           "directory_path", System.IO.Path.GetDirectoryName(newPath),
                                                           "name", System.IO.Path.GetFileName(newPath),
                                                           "description", description,
                                                           "roll_id", roll_id,
                                                           "default_version_id", Photo.OriginalVersionId));

            photo = new Photo(id, unix_time, newPath);
            AddToCache(photo);
            photo.Loaded = true;

            thumbnail = GenerateThumbnail(UriList.PathToFileUri(newPath), img);
            EmitAdded(photo);
        }
        return(photo);
    }
예제 #5
0
    // Private utility methods.

    protected virtual void ProcessRequest(RequestItem request)
    {
        Pixbuf orig_image;

        try {
            using (FSpot.ImageFile img = System.IO.File.Exists(request.path) ? FSpot.ImageFile.Create(request.path) : FSpot.ImageFile.Create(new Uri(request.path))) {
                if (request.width > 0)
                {
                    orig_image = img.Load(request.width, request.height);
                }
                else
                {
                    orig_image = img.Load();
                }
            }
        } catch (GLib.GException e) {
            System.Console.WriteLine(e.ToString());
            return;
        }

        if (orig_image == null)
        {
            return;
        }

        request.result = orig_image;
    }
예제 #6
0
        private static void RotateOrientation(string original_path, RotateDirection direction)
        {
            using (FSpot.ImageFile img = FSpot.ImageFile.Create(original_path)) {
                if (img is JpegFile)
                {
                    FSpot.JpegFile    jimg        = img as FSpot.JpegFile;
                    PixbufOrientation orientation = direction == RotateDirection.Clockwise
                                                ? PixbufUtils.Rotate90(img.Orientation)
                                                : PixbufUtils.Rotate270(img.Orientation);

                    jimg.SetOrientation(orientation);
                    jimg.SaveMetaData(original_path);
                }
                else if (img is PngFile)
                {
                    PngFile png       = img as PngFile;
                    bool    supported = false;

                    //FIXME there isn't much png specific here except the check
                    //the pixbuf is an accurate representation of the real file
                    //by checking the depth.  The check should be abstracted and
                    //this code made generic.
                    foreach (PngFile.Chunk c in png.Chunks)
                    {
                        PngFile.IhdrChunk ihdr = c as PngFile.IhdrChunk;

                        if (ihdr != null && ihdr.Depth == 8)
                        {
                            supported = true;
                        }
                    }

                    if (!supported)
                    {
                        throw new RotateException("Unable to rotate photo type", original_path);
                    }

                    string backup = ImageFile.TempPath(original_path);
                    using (Stream stream = File.Open(backup, FileMode.Truncate, FileAccess.Write)) {
                        using (Pixbuf pixbuf = img.Load()) {
                            PixbufOrientation fake = (direction == RotateDirection.Clockwise) ? PixbufOrientation.RightTop : PixbufOrientation.LeftBottom;
                            using (Pixbuf rotated = PixbufUtils.TransformOrientation(pixbuf, fake)) {
                                img.Save(rotated, stream);
                            }
                        }
                    }
                    File.Copy(backup, original_path, true);
                    File.Delete(backup);
                }
                else
                {
                    throw new RotateException("Unable to rotate photo type", original_path);
                }
            }
        }
예제 #7
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);
        }
예제 #8
0
        //FIXME: won't work on non file uris
        public uint SaveVersion(Gdk.Pixbuf buffer, bool create_version)
        {
            uint version = DefaultVersionId;

            using (var img = ImageFile.Create(DefaultVersion.Uri)) {
                // Always create a version if the source is not a jpeg for now.
                create_version = create_version || ImageFile.IsJpeg(DefaultVersion.Uri);

                if (buffer == null)
                {
                    throw new ApplicationException("invalid (null) image");
                }

                if (create_version)
                {
                    version = CreateDefaultModifiedVersion(DefaultVersionId, false);
                }

                try {
                    var versionUri = VersionUri(version);

                    PixbufUtils.CreateDerivedVersion(DefaultVersion.Uri, versionUri, 95, buffer);
                    GetVersion(version).ImportMD5 = HashUtils.GenerateMD5(VersionUri(version));
                    DefaultVersionId = version;
                } catch (System.Exception e) {
                    Log.Exception(e);
                    if (create_version)
                    {
                        DeleteVersion(version);
                    }

                    throw e;
                }
            }

            return(version);
        }
예제 #9
0
 private void CreateTagIconFromExternalPhoto()
 {
     try {
         using (FSpot.ImageFile img = FSpot.ImageFile.Create(new Uri(external_photo_chooser.Uri))) {
             using (Gdk.Pixbuf external_image = img.Load()) {
                 PreviewPixbuf = PixbufUtils.TagIconFromPixbuf(external_image);
                 PreviewPixbuf_WithoutProfile = PreviewPixbuf.Copy();
                 FSpot.ColorManagement.ApplyScreenProfile(PreviewPixbuf);
             }
         }
     } catch (Exception) {
         string caption = Catalog.GetString("Unable to load image");
         string message = String.Format(Catalog.GetString("Unable to load \"{0}\" as icon for the tag"),
                                        external_photo_chooser.Uri.ToString());
         HigMessageDialog md = new HigMessageDialog(this.Dialog,
                                                    DialogFlags.DestroyWithParent,
                                                    MessageType.Error,
                                                    ButtonsType.Close,
                                                    caption,
                                                    message);
         md.Run();
         md.Destroy();
     }
 }
예제 #10
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 (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 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 ();
					}
				}
			}

		}
예제 #12
0
        public static ImageFile Create(Uri uri)
        {
            System.Type t = GetLoaderType (uri);
            ImageFile img;

            if (t != null)
                img = (ImageFile) System.Activator.CreateInstance (t, new object[] { uri });
            else
                img = new ImageFile (uri);

            return img;
        }
예제 #13
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();
                    }
                }
            }
        }
 public static PixbufOrientation GetOrientation(string path)
 {
     using (FSpot.ImageFile img = FSpot.ImageFile.Create(path)) {
         return(img.Orientation);
     }
 }
예제 #15
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();
        }
    }
		private void FileLoad (ImageFile img)
		{
			pixbuf = img.Load ();
			done_reading = true;
			if (Done != null)
				Done (this, System.EventArgs.Empty);
		}
예제 #17
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 ();
                    }
                }
            }
        }
예제 #18
0
파일: InfoBox.cs 프로젝트: iainlane/f-spot
            public ImageInfo(ImageFile img)
            {
                // FIXME We use the memory store to hold the anonymous statements
                // as they are added so that we can query for them later to
                // resolve anonymous nodes.
                store = new MemoryStore ();

                if (img == null)
                    return;

                if (img is StatementSource) {
                    SemWeb.StatementSource source = (SemWeb.StatementSource)img;
                    source.Select (this);

                    // If we couldn't find the ISO speed because of the ordering
                    // search the memory store for the values
                    if (iso_speed == null && iso_anon != null) {
                        add = false;
                        store.Select (this);
                    }
                }

                if (img is JpegFile) {
                    int real_width;
                    int real_height;

                    JpegUtils.GetSize (img.Uri.LocalPath, out real_width, out real_height);
                    width = real_width.ToString ();
                    height = real_height.ToString ();
                }
                #if USE_EXIF_DATE
                date = img.Date;
                #endif
            }
예제 #19
0
        static int Main(string [] args)
        {
            args = FixArgs(args);

            ApplicationContext.ApplicationName = "F-Spot";
            ApplicationContext.TrySetProcessName(Defines.PACKAGE);

            Paths.ApplicationName = "f-spot";
            ThreadAssist.InitializeMainThread();
            ThreadAssist.ProxyToMainHandler = RunIdle;
            XdgThumbnailSpec.DefaultLoader  = (uri) => {
                using (var file = ImageFile.Create(uri))
                    return(file.Load());
            };

            // Options and Option parsing
            bool shutdown  = false;
            bool view      = false;
            bool slideshow = false;
            bool import    = false;

            GLib.GType.Init();
            Catalog.Init("f-spot", Defines.LOCALE_DIR);

            FSpot.Core.Global.PhotoUri = new SafeUri(Preferences.Get <string> (Preferences.STORAGE_PATH));

            ApplicationContext.CommandLine = new CommandLineParser(args, 0);

            if (ApplicationContext.CommandLine.ContainsStart("help"))
            {
                ShowHelp();
                return(0);
            }

            if (ApplicationContext.CommandLine.Contains("version"))
            {
                ShowVersion();
                return(0);
            }

            if (ApplicationContext.CommandLine.Contains("versions"))
            {
                ShowAssemblyVersions();
                return(0);
            }

            if (ApplicationContext.CommandLine.Contains("shutdown"))
            {
                Log.Information("Shutting down existing F-Spot server...");
                shutdown = true;
            }

            if (ApplicationContext.CommandLine.Contains("slideshow"))
            {
                Log.Information("Running F-Spot in slideshow mode.");
                slideshow = true;
            }

            if (ApplicationContext.CommandLine.Contains("basedir"))
            {
                string dir = ApplicationContext.CommandLine ["basedir"];

                if (!string.IsNullOrEmpty(dir))
                {
                    FSpot.Core.Global.BaseDirectory = dir;
                    Log.InformationFormat("BaseDirectory is now {0}", dir);
                }
                else
                {
                    Log.Error("f-spot: -basedir option takes one argument");
                    return(1);
                }
            }

            if (ApplicationContext.CommandLine.Contains("photodir"))
            {
                string dir = ApplicationContext.CommandLine ["photodir"];

                if (!string.IsNullOrEmpty(dir))
                {
                    FSpot.Core.Global.PhotoUri = new SafeUri(dir);
                    Log.InformationFormat("PhotoDirectory is now {0}", dir);
                }
                else
                {
                    Log.Error("f-spot: -photodir option takes one argument");
                    return(1);
                }
            }

            if (ApplicationContext.CommandLine.Contains("import"))
            {
                import = true;
            }

            if (ApplicationContext.CommandLine.Contains("view"))
            {
                view = true;
            }

            if (ApplicationContext.CommandLine.Contains("debug"))
            {
                Log.Debugging = true;
                // Debug GdkPixbuf critical warnings
                GLib.LogFunc logFunc = new GLib.LogFunc(GLib.Log.PrintTraceLogFunction);
                GLib.Log.SetLogHandler("GdkPixbuf", GLib.LogLevelFlags.Critical, logFunc);

                // Debug Gtk critical warnings
                GLib.Log.SetLogHandler("Gtk", GLib.LogLevelFlags.Critical, logFunc);

                // Debug GLib critical warnings
                GLib.Log.SetLogHandler("GLib", GLib.LogLevelFlags.Critical, logFunc);

                //Debug GLib-GObject critical warnings
                GLib.Log.SetLogHandler("GLib-GObject", GLib.LogLevelFlags.Critical, logFunc);

                GLib.Log.SetLogHandler("GLib-GIO", GLib.LogLevelFlags.Critical, logFunc);
            }

            // Validate command line options
            if ((import && (view || shutdown || slideshow)) ||
                (view && (shutdown || slideshow)) ||
                (shutdown && slideshow))
            {
                Log.Error("Can't mix -import, -view, -shutdown or -slideshow");
                return(1);
            }

            InitializeAddins();

            // Gtk initialization
            Gtk.Application.Init(Defines.PACKAGE, ref args);

            // init web proxy globally
            Platform.WebProxy.Init();

            if (File.Exists(Preferences.Get <string> (Preferences.GTK_RC)))
            {
                if (File.Exists(Path.Combine(FSpot.Core.Global.BaseDirectory, "gtkrc")))
                {
                    Gtk.Rc.AddDefaultFile(Path.Combine(FSpot.Core.Global.BaseDirectory, "gtkrc"));
                }

                FSpot.Core.Global.DefaultRcFiles = Gtk.Rc.DefaultFiles;
                Gtk.Rc.AddDefaultFile(Preferences.Get <string> (Preferences.GTK_RC));
                Gtk.Rc.ReparseAllForSettings(Gtk.Settings.Default, true);
            }

            try {
                Gtk.Window.DefaultIconList = new Gdk.Pixbuf [] {
                    GtkUtil.TryLoadIcon(FSpot.Core.Global.IconTheme, "f-spot", 16, (Gtk.IconLookupFlags) 0),
                    GtkUtil.TryLoadIcon(FSpot.Core.Global.IconTheme, "f-spot", 22, (Gtk.IconLookupFlags) 0),
                    GtkUtil.TryLoadIcon(FSpot.Core.Global.IconTheme, "f-spot", 32, (Gtk.IconLookupFlags) 0),
                    GtkUtil.TryLoadIcon(FSpot.Core.Global.IconTheme, "f-spot", 48, (Gtk.IconLookupFlags) 0)
                };
            } catch {}

            CleanRoomStartup.Startup(Startup);

            return(0);
        }
예제 #20
0
        private void Update()
        {
            Gtk.HTMLStream stream = this.Begin(null, "text/html; charset=utf-8", Gtk.HTMLBeginFlags.Scroll);

            string bg = Color(this.Style.Background(Gtk.StateType.Active));
            string fg = Color(this.Style.Foreground(Gtk.StateType.Active));
            string ig = Color(this.Style.Base(Gtk.StateType.Active));

            stream.Write("<table width=100% cellpadding=5 cellspacing=0>");
            bool empty   = true;
            bool missing = false;

            System.Exception error = null;

            if (exif_info != null)
            {
                foreach (Exif.ExifContent content in exif_info.GetContents())
                {
                    Exif.ExifEntry [] entries = content.GetEntries();
                    if (entries.Length > 0)
                    {
                        empty = false;
                        break;
                    }
                }

                if (exif_info.Data.Length > 0)
                {
                    stream.Write(String.Format("<tr><td colspan=2 align=\"center\" bgcolor=\"{0}\">" +
                                               "<img center src=\"exif:thumbnail\"></td></tr>", ig));
                }

                int i = 0;
                foreach (Exif.ExifContent content in exif_info.GetContents())
                {
                    Exif.ExifEntry [] entries = content.GetEntries();

                    i++;
                    if (entries.Length < 1)
                    {
                        continue;
                    }

                    stream.Write("<tr><th align=left bgcolor=\"" + ig + "\" colspan=2>"
                                 + Exif.ExifUtil.GetIfdNameExtended((Exif.Ifd)i - 1) + "</th><tr>");

                    foreach (Exif.ExifEntry entry in entries)
                    {
                        stream.Write("<tr><td valign=top align=right bgcolor=\"" + bg + "\"><small><font color=\"" + fg + "\">");
                        if (entry.Title != null)
                        {
                            stream.Write(entry.Title);
                        }
                        else
                        {
                            stream.Write("&lt;Unknown Tag ID=" + entry.Tag.ToString() + "&gt;");
                        }
                        stream.Write("</font></small></td><td>");
                        string s = entry.Value;
                        if (s != null && s != String.Empty)
                        {
                            stream.Write(s);
                        }
                        stream.Write("</td><tr>");
                    }
                }
            }

            if (photo != null)
            {
                MetadataStore store = new MetadataStore();
                try {
                    using (ImageFile img = ImageFile.Create(photo.DefaultVersionUri)) {
                        if (img is SemWeb.StatementSource)
                        {
                            StatementSource source = (StatementSource)img;
                            source.Select(store);
                        }
                    }
                } catch (System.IO.FileNotFoundException) {
                    missing = true;
                } catch (System.Exception e) {
                    // Sometimes we don't get the right exception, check for the file
                    if (!System.IO.File.Exists(photo.DefaultVersionUri.LocalPath))
                    {
                        missing = true;
                    }
                    else
                    {
                        // if the file is there but we still got an exception display it.
                        error = e;
                    }
                }

                if (store.StatementCount > 0)
                {
#if false
                    using (System.IO.Stream xmpstream = System.IO.File.OpenWrite("tmp.xmp")) {
                        xmpstream.Length = 0;
                        FSpot.Xmp.XmpFile file;

                        file = new FSpot.Xmp.XmpFile();
                        store.Select(file);
                        file.Save(xmpstream);
                    }
#endif
                    empty = false;
                    stream.Write("<tr><th align=left bgcolor=\"" + ig + "\" colspan=2>"
                                 + Catalog.GetString("Extended Metadata") + "</th></tr>");

                    foreach (Statement stmt in store)
                    {
                        // Skip anonymous subjects because they are
                        // probably part of a collection
                        if (stmt.Subject.Uri == null && store.SelectSubjects(null, stmt.Subject).Length > 0)
                        {
                            continue;
                        }

                        string title;
                        string value;

                        Description.GetDescription(store, stmt, out title, out value);

                        stream.Write("<tr><td valign=top align=right bgcolor=\"" + bg + "\"><small><font color=\"" + fg + "\">");
                        stream.Write(title);
                        stream.Write("</font></small></td><td width=100%>");

                        if (value != null)
                        {
                            value = Escape(value);
                        }
                        else
                        {
                            MemoryStore substore = store.Select(new Statement((Entity)stmt.Object, null, null, null)).Load();
                            WriteCollection(substore, stream);
                        }

                        if (value != null && value != String.Empty)
                        {
                            stream.Write(value);
                        }

                        stream.Write("</td></tr>");
                    }
                }

                if (Core.Database != null && photo is Photo)
                {
                    stream.Write("<tr><th align=left bgcolor=\"" + ig + "\" colspan=2>" + Catalog.GetString("Exported Locations") + "</th></tr>");

                    Photo p = photo as Photo;
                    foreach (ExportItem export in Core.Database.Exports.GetByImageId(p.Id, p.DefaultVersionId))
                    {
                        string url   = GetExportUrl(export);
                        string label = GetExportLabel(export);
                        if (url == null || label == null)
                        {
                            continue;
                        }

                        stream.Write("<tr colspan=2><td width=100%>");
                        stream.Write(String.Format("<a href=\"{0}\">{1}</a>", url, label));
                        stream.Write("</font></small></td></tr>");
                    }
                }
            }

            if (empty)
            {
                string msg;
                if (photo == null)
                {
                    // FIXME we should pass the full selection to the info display and let it
                    // handle multiple items however it wants.
                    msg = String.Format("<tr><td valign=top align=center bgcolor=\"{0}\">"
                                        + "<b>{1}</b></td></tr>", ig,
                                        Catalog.GetString("No active photo"));
                }
                else if (missing)
                {
                    string text = String.Format(Catalog.GetString("The photo \"{0}\" does not exist"), photo.DefaultVersionUri);
                    msg = String.Format("<tr><td valign=top align=center bgcolor=\"{0}\">"
                                        + "<b>{1}</b></td></tr>", ig, text);
                }
                else
                {
                    msg = String.Format("<tr><td valign=top align=center bgcolor=\"{0}\">"
                                        + "<b>{1}</b></td></tr>", ig,
                                        Catalog.GetString("No metadata available"));

                    if (error != null)
                    {
                        String.Format("<pre>{0}</pre>", error);
                    }
                }
                stream.Write(msg);
            }

            stream.Write("</table>");
            End(stream, Gtk.HTMLStreamStatus.Ok);
        }
        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();
                }
            }
        }
		private void HandleThumbnailIconViewButtonPressEvent (object sender, Gtk.ButtonPressEventArgs args)
		{
			int old_item = current_item;
			current_item = thumbnail_iconview.CellAtPosition ((int) args.Event.X, (int) args.Event.Y, false);

			if (current_item < 0 || current_item >=  items.Length) {                                current_item = old_item;
				return;
                        }

			captions [old_item] = caption_textview.Buffer.Text;

			string caption = captions [current_item];
			if (caption == null)
				captions [current_item] = caption = "";
			caption_textview.Buffer.Text = caption;

			tag_treeview.Model = new TagStore (account.Facebook, tags [current_item], friends);

			IBrowsableItem item = items [current_item];
			string thumbnail_path = ThumbnailGenerator.ThumbnailPath (item.DefaultVersionUri);

			if (tag_image_eventbox.Children.Length > 0) {
				tag_image_eventbox.Remove (tag_image);
				tag_image.Destroy ();
			}

			using (ImageFile image = new ImageFile (thumbnail_path)) {
				Gdk.Pixbuf data = image.Load ();
				data = PixbufUtils.ScaleToMaxSize (data, 400, 400);
				tag_image_height = data.Height;
				tag_image_width = data.Width;
				tag_image = new Gtk.Image (data);
				tag_image_eventbox.Add (tag_image);
				tag_image_eventbox.ShowAll ();
			}
		}
예제 #23
0
		public static ImageFile Create (Uri uri)
		{
			string path = uri.AbsolutePath;
			string extension = System.IO.Path.GetExtension (path).ToLower ();
			System.Type t = (System.Type) name_table [extension];
			ImageFile img;

			if (t != null)
				img = (ImageFile) System.Activator.CreateInstance (t, new object[] { uri });
			else 
				img = new ImageFile (uri);

			return img;
		}
예제 #24
0
    //
    // Generates the thumbnail, returns the Pixbuf, and also stores it as a side effect
    //

    public static Pixbuf GenerateThumbnail(Uri uri)
    {
        using (FSpot.ImageFile img = FSpot.ImageFile.Create(uri)) {
            return(GenerateThumbnail(uri, img));
        }
    }