[f-spot] Make sure we always parse the sidecar as well.
- From: Ruben Vermeersch <rubenv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [f-spot] Make sure we always parse the sidecar as well.
- Date: Thu, 8 Jul 2010 16:52:28 +0000 (UTC)
commit d418122097ec932e1d7bb66d3b34f05ba6b617b6
Author: Ruben Vermeersch <ruben savanne be>
Date: Fri Jul 2 20:58:23 2010 +0200
Make sure we always parse the sidecar as well.
src/Core/FileBrowsableItem.cs | 3 +--
src/Imaging/ImageFile.cs | 6 +-----
src/Import/FileImportSource.cs | 3 +--
src/Import/MetadataImporter.cs | 16 +---------------
src/Jobs/SyncMetadataJob.cs | 5 +----
src/PixbufUtils.cs | 39 ++-------------------------------------
src/RotateCommand.cs | 3 +--
src/Utils/Makefile.am | 1 +
src/Utils/Metadata.cs | 24 ++++++++++++++++++++++++
9 files changed, 33 insertions(+), 67 deletions(-)
---
diff --git a/src/Core/FileBrowsableItem.cs b/src/Core/FileBrowsableItem.cs
index 708f0fe..e0caebd 100644
--- a/src/Core/FileBrowsableItem.cs
+++ b/src/Core/FileBrowsableItem.cs
@@ -36,8 +36,7 @@ namespace FSpot {
if (metadata_parsed)
return;
- var res = new GIOTagLibFileAbstraction () { Uri = DefaultVersion.Uri };
- using (var metadata = TagLib.File.Create (res) as TagLib.Image.File) {
+ using (var metadata = Metadata.Parse (DefaultVersion.Uri)) {
var date = metadata.ImageTag.DateTime;
time = date.HasValue ? date.Value : CreateDate;
description = metadata.ImageTag.Comment;
diff --git a/src/Imaging/ImageFile.cs b/src/Imaging/ImageFile.cs
index 7c606f9..137f65d 100644
--- a/src/Imaging/ImageFile.cs
+++ b/src/Imaging/ImageFile.cs
@@ -245,15 +245,11 @@ namespace FSpot.Imaging {
}
public class TagLibFile : ImageFile {
- public TagLib.Image.File Metadata {
- get { return metadata_file; }
- }
-
private TagLib.Image.File metadata_file;
public TagLibFile (SafeUri uri) : base (uri)
{
- metadata_file = TagLib.File.Create (new GIOTagLibFileAbstraction () { Uri = uri }) as TagLib.Image.File;
+ metadata_file = Metadata.Parse (uri);
}
~TagLibFile () {
diff --git a/src/Import/FileImportSource.cs b/src/Import/FileImportSource.cs
index 1030a9a..a6bd603 100644
--- a/src/Import/FileImportSource.cs
+++ b/src/Import/FileImportSource.cs
@@ -156,8 +156,7 @@ namespace FSpot.Import
if (metadata_parsed)
return;
- var res = new GIOTagLibFileAbstraction () { Uri = DefaultVersion.Uri };
- using (var metadata = TagLib.File.Create (res) as TagLib.Image.File) {
+ using (var metadata = Metadata.Parse (DefaultVersion.Uri)) {
var date = metadata.ImageTag.DateTime;
time = date.HasValue ? date.Value : CreateDate;
description = metadata.ImageTag.Comment;
diff --git a/src/Import/MetadataImporter.cs b/src/Import/MetadataImporter.cs
index a974bb4..fa71560 100644
--- a/src/Import/MetadataImporter.cs
+++ b/src/Import/MetadataImporter.cs
@@ -84,21 +84,7 @@ namespace FSpot.Import {
public bool Import (Photo photo, IBrowsableItem importing_from)
{
- var res = new GIOTagLibFileAbstraction () {
- Uri = importing_from.DefaultVersion.Uri
- };
-
- var sidecar_uri = importing_from.DefaultVersion.Uri.ReplaceExtension (".xmp");
- var sidecar_res = new GIOTagLibFileAbstraction () {
- Uri = sidecar_uri
- };
-
- using (var metadata = TagLib.File.Create (res) as TagLib.Image.File) {
- var file = GLib.FileFactory.NewForUri (sidecar_uri);
- if (file.Exists) {
- metadata.ParseXmpSidecar (sidecar_res);
- }
-
+ using (var metadata = Metadata.Parse (importing_from.DefaultVersion.Uri)) {
// Copy Rating
var rating = metadata.ImageTag.Rating;
if (rating.HasValue) {
diff --git a/src/Jobs/SyncMetadataJob.cs b/src/Jobs/SyncMetadataJob.cs
index 9e05804..1e781bb 100644
--- a/src/Jobs/SyncMetadataJob.cs
+++ b/src/Jobs/SyncMetadataJob.cs
@@ -46,16 +46,13 @@ namespace FSpot.Jobs {
void WriteMetadataToImage (Photo photo)
{
- string path = photo.DefaultVersion.Uri.LocalPath;
-
Tag [] tags = photo.Tags;
string [] names = new string [tags.Length];
for (int i = 0; i < tags.Length; i++)
names [i] = tags [i].Name;
- var res = new GIOTagLibFileAbstraction () { Uri = photo.DefaultVersion.Uri };
- using (var metadata = TagLib.File.Create (res) as TagLib.Image.File) {
+ using (var metadata = Metadata.Parse (photo.DefaultVersion.Uri)) {
metadata.GetTag (TagLib.TagTypes.XMP, true);
var tag = metadata.ImageTag;
diff --git a/src/PixbufUtils.cs b/src/PixbufUtils.cs
index b460a41..d056758 100644
--- a/src/PixbufUtils.cs
+++ b/src/PixbufUtils.cs
@@ -427,39 +427,6 @@ public static class PixbufUtils {
}
}
- public static Gdk.Pixbuf GetThumbnail (ExifData data)
- {
- byte [] thumb_data = data.Data;
- if (thumb_data.Length > 0) {
- ImageOrientation orientation = GetOrientation (data);
-
- using (MemoryStream mem = new MemoryStream (thumb_data)) {
- Gdk.Pixbuf thumb = new Gdk.Pixbuf (mem);
- Gdk.Pixbuf rotated;
-
- using (thumb)
- rotated = FSpot.Utils.PixbufUtils.TransformOrientation (thumb, orientation);
-
- return rotated;
- }
- }
- return null;
- }
-
- public static ImageOrientation GetOrientation (ExifData data)
- {
- ImageOrientation orientation = ImageOrientation.TopLeft;
-
- FSpot.Imaging.Exif.ExifEntry e = data.GetContents (FSpot.Imaging.Exif.Ifd.Zero).Lookup (FSpot.Imaging.Exif.Tag.Orientation);
-
- if (e != null) {
- ushort [] value = e.GetDataUShort ();
- orientation = (ImageOrientation) value [0];
- }
-
- return orientation;
- }
-
public static ImageOrientation GetOrientation (SafeUri uri)
{
using (ImageFile img = ImageFile.Create (uri)) {
@@ -514,10 +481,8 @@ public static class PixbufUtils {
{
SaveToSuitableFormat (destination, pixbuf, jpeg_quality);
- var res_from = new GIOTagLibFileAbstraction () { Uri = source };
- var res_to = new GIOTagLibFileAbstraction () { Uri = destination };
- using (var metadata_from = TagLib.File.Create (res_from) as TagLib.Image.File) {
- using (var metadata_to = TagLib.File.Create (res_to) as TagLib.Image.File) {
+ using (var metadata_from = Metadata.Parse (source)) {
+ using (var metadata_to = Metadata.Parse (destination)) {
metadata_to.CopyFrom (metadata_from);
metadata_to.Save ();
}
diff --git a/src/RotateCommand.cs b/src/RotateCommand.cs
index f11a2d8..f4628fd 100644
--- a/src/RotateCommand.cs
+++ b/src/RotateCommand.cs
@@ -60,8 +60,7 @@ namespace FSpot {
private static void RotateOrientation (string original_path, RotateDirection direction)
{
try {
- var res = new GIOTagLibFileAbstraction () { Uri = new SafeUri (original_path) };
- using (var metadata = TagLib.File.Create (res) as TagLib.Image.File) {
+ using (var metadata = Metadata.Parse (new SafeUri (original_path))) {
var tag = metadata.ImageTag;
var orientation = direction == RotateDirection.Clockwise
? FSpot.Utils.PixbufUtils.Rotate90 (tag.Orientation)
diff --git a/src/Utils/Makefile.am b/src/Utils/Makefile.am
index 9557dbf..191d979 100644
--- a/src/Utils/Makefile.am
+++ b/src/Utils/Makefile.am
@@ -11,6 +11,7 @@ SOURCES = \
GIOTagLibFileAbstraction.cs \
GtkUtil.cs \
HashUtils.cs \
+ Metadata.cs \
PixbufUtils.cs \
RecursiveFileEnumerator.cs \
SafeUri.cs \
diff --git a/src/Utils/Metadata.cs b/src/Utils/Metadata.cs
new file mode 100644
index 0000000..2ab9471
--- /dev/null
+++ b/src/Utils/Metadata.cs
@@ -0,0 +1,24 @@
+using Hyena;
+using TagLib;
+using System;
+
+namespace FSpot.Utils
+{
+ public static class Metadata
+ {
+ public static TagLib.Image.File Parse (SafeUri uri)
+ {
+ var res = new GIOTagLibFileAbstraction () { Uri = uri };
+ var sidecar_uri = uri.ReplaceExtension (".xmp");
+ var sidecar_res = new GIOTagLibFileAbstraction () { Uri = sidecar_uri };
+ var file = File.Create (res) as TagLib.Image.File;
+
+ var sidecar_file = GLib.FileFactory.NewForUri (sidecar_uri);
+ if (sidecar_file.Exists) {
+ file.ParseXmpSidecar (sidecar_res);
+ }
+
+ return file;
+ }
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]