[f-spot] First Imaging type killed: JpegFile is now fully generic.



commit 2cfe8bd543b64110305b13bfdd3e600583fa4fb9
Author: Ruben Vermeersch <ruben savanne be>
Date:   Fri Jul 2 11:24:14 2010 +0200

    First Imaging type killed: JpegFile is now fully generic.

 extensions/Tools/DevelopInUFraw/DevelopInUFRaw.cs |    2 +-
 extensions/Tools/RawPlusJpeg/RawPlusJpeg.cs       |    6 +-
 lib/libfspot/f-jpeg-utils.c                       |  130 ---------------------
 lib/libfspot/f-jpeg-utils.h                       |    5 -
 src/Core/Photo.cs                                 |    2 +-
 src/Imaging/ImageFile.cs                          |   53 ++++++++-
 src/Imaging/JpegFile.cs                           |   66 -----------
 src/Imaging/JpegUtils.cs                          |    8 --
 src/Imaging/Tiff.cs                               |   18 +---
 src/Makefile.am                                   |    1 -
 src/Widgets/InfoBox.cs                            |    9 --
 11 files changed, 54 insertions(+), 246 deletions(-)
---
diff --git a/extensions/Tools/DevelopInUFraw/DevelopInUFRaw.cs b/extensions/Tools/DevelopInUFraw/DevelopInUFRaw.cs
index e9ecb39..e477ad0 100644
--- a/extensions/Tools/DevelopInUFraw/DevelopInUFRaw.cs
+++ b/extensions/Tools/DevelopInUFraw/DevelopInUFRaw.cs
@@ -93,7 +93,7 @@ namespace DevelopInUFRawExtension
 			LoadPreference (UFRAW_BATCH_ARGUMENTS_KEY);
 
 			PhotoVersion raw = p.GetVersion (Photo.OriginalVersionId) as PhotoVersion;
-			if (!ImageFile.IsRaw (raw.Uri.AbsolutePath)) {
+			if (!ImageFile.IsRaw (raw.Uri)) {
 				Log.Warning ("The original version of this image is not a (supported) RAW file");
 				return;
 			}
diff --git a/extensions/Tools/RawPlusJpeg/RawPlusJpeg.cs b/extensions/Tools/RawPlusJpeg/RawPlusJpeg.cs
index d33c90a..ea208ee 100644
--- a/extensions/Tools/RawPlusJpeg/RawPlusJpeg.cs
+++ b/extensions/Tools/RawPlusJpeg/RawPlusJpeg.cs
@@ -48,12 +48,12 @@ namespace RawPlusJpegExtension
 			for (int i = 0; i < photos.Length; i++) {
 				Photo p = photos [i];
 
-				if (!ImageFile.IsRaw (p.Name) && !ImageFile.IsJpeg (p.Name))
+				if (!ImageFile.IsRaw (p.DefaultVersion.Uri) && !ImageFile.IsJpeg (p.DefaultVersion.Uri))
 					continue;
 
-				if (ImageFile.IsJpeg (p.Name))
+				if (ImageFile.IsJpeg (p.DefaultVersion.Uri))
 					jpeg = p;
-				if (ImageFile.IsRaw (p.Name))
+				if (ImageFile.IsRaw (p.DefaultVersion.Uri))
 					raw = p;
 
 				if (raw != null && jpeg != null && SamePlaceAndName (raw, jpeg))
diff --git a/lib/libfspot/f-jpeg-utils.c b/lib/libfspot/f-jpeg-utils.c
index b83848a..7f94f14 100644
--- a/lib/libfspot/f-jpeg-utils.c
+++ b/lib/libfspot/f-jpeg-utils.c
@@ -185,136 +185,6 @@ free_buffer (guchar *pixels, gpointer data)
 	g_free (pixels);
 }
 
-
-static GdkPixbuf *
-do_load_internal (const char *path,
-		  int target_width, int target_height,
-		  int *original_width_return, int *original_height_return)
-{
-	struct jpeg_decompress_struct cinfo;
-	ErrorHandlerData jerr;
-	unsigned char *lines[1];
-	guchar * volatile buffer;
-	guchar * volatile pixels;
-	guchar *ptr;
-	GFile *uri;
-	GFileInputStream *input_stream;
-	GError *err = NULL;
-	unsigned int i;
-
-	g_return_val_if_fail (g_path_is_absolute (path), NULL);
-
-	if (original_width_return != NULL)
-		*original_width_return = 0;
-	if (original_height_return != NULL)
-		*original_height_return = 0;
-
-	uri = g_file_new_for_path (path);
-	input_stream = g_file_read (uri, NULL, &err);
-	g_object_unref (uri);
-
-	if (err != NULL)
-		return NULL;
-	
-	cinfo.err = jpeg_std_error (&jerr.pub);
-	jerr.pub.error_exit = fatal_error_handler;
-	jerr.pub.output_message = output_message_handler;
-
-	buffer = NULL;
-	pixels = NULL;
-	if (setjmp (jerr.setjmp_buffer)) {
-		/* Handle a JPEG error. */
-		jpeg_destroy_decompress (&cinfo);
-		g_input_stream_close (G_INPUT_STREAM (input_stream), NULL, NULL);
-		g_free (buffer);
-		g_free (pixels);
-		return NULL;
-	}
-
-	jpeg_create_decompress (&cinfo);
-
-	gio_src (&cinfo, G_INPUT_STREAM (input_stream));
-	jpeg_read_header (&cinfo, TRUE);
-
-	if (target_width != 0 && target_height != 0) {
-		cinfo.scale_num = 1;
-		cinfo.scale_denom = calculate_divisor (cinfo.image_width,
-						       cinfo.image_height,
-						       target_width,
-						       target_height);
-		cinfo.dct_method = JDCT_FASTEST;
-		cinfo.do_fancy_upsampling = FALSE;
-	
-		jpeg_start_decompress (&cinfo);
-
-		pixels = g_malloc (cinfo.output_width *	cinfo.output_height * 3);
-
-		ptr = pixels;
-		if (cinfo.num_components == 1) {
-			/* Allocate extra buffer for grayscale data */
-			buffer = g_malloc (cinfo.output_width);
-			lines[0] = buffer;
-		} else {
-			lines[0] = pixels;
-		}
-	
-		while (cinfo.output_scanline < cinfo.output_height) {
-			jpeg_read_scanlines (&cinfo, lines, 1);
-		
-			if (cinfo.num_components == 1) {
-				/* Convert grayscale to rgb */
-				for (i = 0; i < cinfo.output_width; i++) {
-					ptr[i*3] = buffer[i];
-					ptr[i*3+1] = buffer[i];
-					ptr[i*3+2] = buffer[i];
-				}
-				ptr += cinfo.output_width * 3;
-			} else {
-				lines[0] += cinfo.output_width * 3;
-			}
-		}
-
-		g_free (buffer);
-		buffer = NULL;
-
-		jpeg_finish_decompress (&cinfo);
-	}
-
-	jpeg_destroy_decompress (&cinfo);
-
-	gio_src_free (&cinfo);
-	
-	g_input_stream_close (G_INPUT_STREAM (input_stream), NULL, NULL);
-
-	if (original_width_return != NULL)
-		*original_width_return = cinfo.image_width;
-	if (original_height_return != NULL)
-		*original_height_return = cinfo.image_height;
-
-	if (target_width == 0 || target_height == 0)
-		return NULL;
-
-	return gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, FALSE, 8,
-					 cinfo.output_width,
-					 cinfo.output_height,
-					 cinfo.output_width * 3,
-					 free_buffer, NULL);
-}
-
-
-/* Public API.  */
-
-
-/* FIXME: Error reporting in this function sucks...  */
-void
-f_get_jpeg_size  (const char *path,
-		  int *width_return,
-		  int *height_return)
-{
-	do_load_internal (path, 0, 0, width_return, height_return);
-}
-
-
 /* Implementation of non-lossy JPEG file transformations, based on GThumb code
    by Paolo Bacchilega.  */
 
diff --git a/lib/libfspot/f-jpeg-utils.h b/lib/libfspot/f-jpeg-utils.h
index 74fef89..c587686 100644
--- a/lib/libfspot/f-jpeg-utils.h
+++ b/lib/libfspot/f-jpeg-utils.h
@@ -31,11 +31,6 @@
 
 #include <gdk-pixbuf/gdk-pixbuf.h>
 
-void  f_get_jpeg_size  (const char *path,
-			int        *width_return,
-			int        *height_return);
-
-
 enum _FJpegTransform {
 	F_JPEG_TRANSFORM_ROTATE_90,
 	F_JPEG_TRANSFORM_ROTATE_180,
diff --git a/src/Core/Photo.cs b/src/Core/Photo.cs
index 23a2b35..104615c 100644
--- a/src/Core/Photo.cs
+++ b/src/Core/Photo.cs
@@ -220,7 +220,7 @@ namespace FSpot
 			uint version = DefaultVersionId;
 			using (ImageFile img = ImageFile.Create (DefaultVersion.Uri)) {
 				// Always create a version if the source is not a jpeg for now.
-				create_version = create_version || !(img is FSpot.Imaging.JpegFile);
+				create_version = create_version || ImageFile.IsJpeg (DefaultVersion.Uri);
 	
 				if (buffer == null)
 					throw new ApplicationException ("invalid (null) image");
diff --git a/src/Imaging/ImageFile.cs b/src/Imaging/ImageFile.cs
index bffa1a2..89bf12d 100644
--- a/src/Imaging/ImageFile.cs
+++ b/src/Imaging/ImageFile.cs
@@ -56,8 +56,8 @@ namespace FSpot.Imaging {
 			name_table [".gif"] = typeof (ImageFile);
 			name_table [".bmp"] = typeof (ImageFile);
 			name_table [".pcx"] = typeof (ImageFile);
-			name_table [".jpeg"] = typeof (JpegFile);
-			name_table [".jpg"] = typeof (JpegFile);
+			name_table [".jpeg"] = typeof (TagLibFile);
+			name_table [".jpg"] = typeof (TagLibFile);
 			name_table [".png"] = typeof (FSpot.Imaging.Png.PngFile);
 			name_table [".cr2"] = typeof (FSpot.Imaging.Tiff.Cr2File);
 			name_table [".nef"] = typeof (FSpot.Imaging.Tiff.NefFile);
@@ -228,7 +228,7 @@ namespace FSpot.Imaging {
 		{
 		}
 
-		public static bool IsRaw (string name)
+		public static bool IsRaw (SafeUri uri)
 		{
 			string [] raw_extensions = {
 				".arw",
@@ -243,19 +243,60 @@ namespace FSpot.Imaging {
 				".raf",
 				".rw2",
 			};
+			var extension = uri.GetExtension ().ToLower ();
 			foreach (string ext in raw_extensions)
-				if (ext == System.IO.Path.GetExtension (name).ToLower ())
+				if (ext == extension)
 					return true;
 			return false;
 		}
 
-		public static bool IsJpeg (string name)
+		public static bool IsJpeg (SafeUri uri)
 		{
 			string [] jpg_extensions = {".jpg", ".jpeg"};
+			var extension = uri.GetExtension ().ToLower ();
 			foreach (string ext in jpg_extensions)
-				if (ext == System.IO.Path.GetExtension (name).ToLower ())
+				if (ext == extension)
 					return true;
 			return false;
 		}
 	} 
+
+    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;
+        }
+
+        ~TagLibFile () {
+            metadata_file.Dispose ();
+        }
+
+        public override Cms.Profile GetProfile ()
+        {
+            return null;
+        }
+
+        public override ImageOrientation GetOrientation ()
+        {
+            var orientation = metadata_file.ImageTag.Orientation;
+            return orientation;
+        }
+
+        public void SetOrientation (ImageOrientation orientation)
+        {
+            metadata_file.ImageTag.Orientation = orientation;
+        }
+
+        public void SetDateTimeOriginal (DateTime time)
+        {
+            metadata_file.ImageTag.DateTime = time;
+        }
+
+    }
 }
diff --git a/src/Imaging/JpegUtils.cs b/src/Imaging/JpegUtils.cs
index 2596b75..12c7162 100644
--- a/src/Imaging/JpegUtils.cs
+++ b/src/Imaging/JpegUtils.cs
@@ -5,14 +5,6 @@ using Gdk;
 namespace FSpot.Imaging {
 public class JpegUtils {
 
-	[DllImport ("libfspot")]
-	static extern void f_get_jpeg_size (string path, out int width_return, out int height_return);
-
-	public static void GetSize (string path, out int width_return, out int height_return)
-	{
-		f_get_jpeg_size (path, out width_return, out height_return);
-	}
-
 	public enum TransformType {
 		Rotate90,
 		Rotate180,
diff --git a/src/Imaging/Tiff.cs b/src/Imaging/Tiff.cs
index fcebca1..cda5e80 100644
--- a/src/Imaging/Tiff.cs
+++ b/src/Imaging/Tiff.cs
@@ -1981,7 +1981,7 @@ namespace FSpot.Imaging.Tiff {
 		}
 	}	
 	
-	public class NefFile : TiffFile, IThumbnailContainer {
+	public class NefFile : TiffFile {
 		public NefFile (SafeUri uri) : base (uri)
 		{
 		}
@@ -2021,13 +2021,6 @@ namespace FSpot.Imaging.Tiff {
 			} while (i < sub.Directory.Length);
 		}
 
-		public Gdk.Pixbuf GetEmbeddedThumbnail ()
-		{
-			using (System.IO.Stream stream = Open ()) {
-				return TransformAndDispose (new Gdk.Pixbuf (stream));
-			}
-		}
-
 		public override System.IO.Stream PixbufStream ()
 		{
 			try {
@@ -2041,18 +2034,11 @@ namespace FSpot.Imaging.Tiff {
 	}
 		
 
-	public class Cr2File : TiffFile, IThumbnailContainer {
+	public class Cr2File : TiffFile {
 		public Cr2File (SafeUri uri) : base (uri)
 		{
 		}
 
-		public Gdk.Pixbuf GetEmbeddedThumbnail ()
-		{
-			ImageDirectory directory;
-			directory = Header.Directory.NextDirectory;
-			return TransformAndDispose (LoadJpegInterchangeFormat (directory));
-		}
-
 		public override System.IO.Stream PixbufStream ()
 		{
 			uint offset = Header.Directory.Lookup (TagId.StripOffsets).ValueAsLong [0];
diff --git a/src/Makefile.am b/src/Makefile.am
index 38ae9d8..fe5f0c6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -91,7 +91,6 @@ SOURCES = \
 	Imaging/InternalProcess.cs \
 	Imaging/IptcFile.cs \
 	Imaging/IOChannel.cs \
-	Imaging/JpegFile.cs \
 	Imaging/JpegUtils.cs \
 	Imaging/MrwFile.cs \
 	Imaging/OrderedWriter.cs \
diff --git a/src/Widgets/InfoBox.cs b/src/Widgets/InfoBox.cs
index 9c2043a..a01bc23 100644
--- a/src/Widgets/InfoBox.cs
+++ b/src/Widgets/InfoBox.cs
@@ -327,15 +327,6 @@ namespace FSpot.Widgets
 						store.Select (this);
 					}
 				}
-	
-				if (img is Imaging.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 ();
-				}
 			}
 	
 			public bool Add (SemWeb.Statement stmt)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]