[f-spot/taglib-metadata] More ImageFile sanitization.
- From: Ruben Vermeersch <rubenv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [f-spot/taglib-metadata] More ImageFile sanitization.
- Date: Mon, 5 Jul 2010 22:29:28 +0000 (UTC)
commit 7f81286636f955a1e585aa379cae60cf2d05ce96
Author: Ruben Vermeersch <ruben savanne be>
Date: Tue Jul 6 00:28:56 2010 +0200
More ImageFile sanitization.
src/Imaging/Ciff.cs | 12 +---------
src/Imaging/DCRawFile.cs | 2 +-
src/Imaging/ImageFile.cs | 50 +++++++++++++--------------------------------
src/Imaging/RafFile.cs | 20 ++---------------
src/Imaging/Tiff.cs | 12 +++++-----
5 files changed, 27 insertions(+), 69 deletions(-)
---
diff --git a/src/Imaging/Ciff.cs b/src/Imaging/Ciff.cs
index fd2022f..c688de1 100644
--- a/src/Imaging/Ciff.cs
+++ b/src/Imaging/Ciff.cs
@@ -299,7 +299,7 @@ namespace FSpot.Imaging.Ciff {
public ImageDirectory Root {
get {
if (root == null) {
- stream = Open ();
+ stream = PixbufStream ();
root = Load (stream);
}
@@ -379,15 +379,7 @@ namespace FSpot.Imaging.Ciff {
if (data != null)
return new System.IO.MemoryStream (data);
else
- return DCRawFile.RawPixbufStream (uri);
- }
-
- public override Gdk.Pixbuf Load (int width, int height)
- {
- Gdk.Pixbuf full = this.Load ();
- Gdk.Pixbuf scaled = PixbufUtils.ScaleToMaxSize (full, width, height);
- full.Dispose ();
- return scaled;
+ return DCRawFile.RawPixbufStream (Uri);
}
private byte [] GetEmbeddedJpeg ()
diff --git a/src/Imaging/DCRawFile.cs b/src/Imaging/DCRawFile.cs
index 971b3f1..f9d68b4 100644
--- a/src/Imaging/DCRawFile.cs
+++ b/src/Imaging/DCRawFile.cs
@@ -13,7 +13,7 @@ namespace FSpot.Imaging {
public override System.IO.Stream PixbufStream ()
{
- return RawPixbufStream (uri);
+ return RawPixbufStream (Uri);
}
internal static System.IO.Stream RawPixbufStream (SafeUri location)
diff --git a/src/Imaging/ImageFile.cs b/src/Imaging/ImageFile.cs
index 47fb40f..f49b8bc 100644
--- a/src/Imaging/ImageFile.cs
+++ b/src/Imaging/ImageFile.cs
@@ -167,40 +167,28 @@ namespace FSpot.Imaging {
}
public class BaseImageFile : IImageFile {
- ImageOrientation orientation = ImageOrientation.TopLeft;
+ public SafeUri Uri { get; private set; }
+ public ImageOrientation Orientation { get; private set; }
- protected SafeUri uri;
-
- public BaseImageFile (SafeUri uri)
- {
- this.uri = uri;
+ public BaseImageFile (SafeUri uri)
+ {
+ Uri = uri;
+ Orientation = ImageOrientation.TopLeft;
using (var metadata_file = Metadata.Parse (uri)) {
- orientation = metadata_file.ImageTag.Orientation;
+ Orientation = metadata_file.ImageTag.Orientation;
}
- }
+ }
~BaseImageFile ()
{
Dispose ();
}
- protected Stream Open ()
- {
- Log.DebugFormat ("open uri = {0}", uri.ToString ());
- return new GLib.GioStream (GLib.FileFactory.NewForUri (uri).Read (null));
- }
-
public virtual Stream PixbufStream ()
{
- return Open ();
- }
- public SafeUri Uri {
- get { return this.uri; }
- }
-
- public ImageOrientation Orientation {
- get { return orientation; }
+ Log.DebugFormat ("open uri = {0}", Uri.ToString ());
+ return new GLib.GioStream (GLib.FileFactory.NewForUri (Uri).Read (null));
}
protected Gdk.Pixbuf TransformAndDispose (Gdk.Pixbuf orig)
@@ -223,20 +211,12 @@ namespace FSpot.Imaging {
}
}
- public virtual Gdk.Pixbuf Load (int max_width, int max_height)
+ public Gdk.Pixbuf Load (int max_width, int max_height)
{
- System.IO.Stream stream = PixbufStream ();
- if (stream == null) {
- Gdk.Pixbuf orig = this.Load ();
- Gdk.Pixbuf scaled = PixbufUtils.ScaleToMaxSize (orig, max_width, max_height, false);
- orig.Dispose ();
- return scaled;
- }
-
- using (stream) {
- PixbufUtils.AspectLoader aspect = new PixbufUtils.AspectLoader (max_width, max_height);
- return aspect.Load (stream, Orientation);
- }
+ Gdk.Pixbuf full = this.Load ();
+ Gdk.Pixbuf scaled = PixbufUtils.ScaleToMaxSize (full, max_width, max_height);
+ full.Dispose ();
+ return scaled;
}
// FIXME this need to have an intent just like the loading stuff.
diff --git a/src/Imaging/RafFile.cs b/src/Imaging/RafFile.cs
index 837618e..500ca4b 100644
--- a/src/Imaging/RafFile.cs
+++ b/src/Imaging/RafFile.cs
@@ -29,7 +29,7 @@ namespace FSpot.Imaging.Raf {
public Exif.ExifData ExifData {
get {
if (exif_data == null)
- exif_data = new Exif.ExifData(uri.LocalPath);
+ exif_data = new Exif.ExifData(Uri.LocalPath);
Log.Debug ("loading exif data");
return exif_data;
}
@@ -42,21 +42,7 @@ namespace FSpot.Imaging.Raf {
if (data != null)
return new System.IO.MemoryStream (data);
else
- return DCRawFile.RawPixbufStream (uri);
- }
-
- public override Gdk.Pixbuf Load ()
- {
- return new Gdk.Pixbuf (PixbufStream ());
- }
-
- public override Gdk.Pixbuf Load (int width, int height)
- {
- Gdk.Pixbuf full = this.Load ();
- Gdk.Pixbuf rotated = FSpot.Utils.PixbufUtils.TransformOrientation (full, Orientation);
- Gdk.Pixbuf scaled = PixbufUtils.ScaleToMaxSize (rotated, width, height);
- full.Dispose ();
- return scaled;
+ return DCRawFile.RawPixbufStream (Uri);
}
public void Select (SemWeb.StatementSink sink)
@@ -65,7 +51,7 @@ namespace FSpot.Imaging.Raf {
private byte [] GetEmbeddedJpeg ()
{
- using (System.IO.Stream stream = Open ()) {
+ using (System.IO.Stream stream = base.PixbufStream ()) {
stream.Position = 0x54;
byte [] data = new byte [24];
stream.Read (data, 0, data.Length);
diff --git a/src/Imaging/Tiff.cs b/src/Imaging/Tiff.cs
index 2a4ae69..f6eafbe 100644
--- a/src/Imaging/Tiff.cs
+++ b/src/Imaging/Tiff.cs
@@ -1801,7 +1801,7 @@ namespace FSpot.Imaging.Tiff {
public TiffFile (SafeUri uri) : base (uri)
{
try {
- using (System.IO.Stream input = Open ()) {
+ using (System.IO.Stream input = PixbufStream ()) {
this.Header = new Header (input);
}
} catch (System.Exception e) {
@@ -1818,7 +1818,7 @@ namespace FSpot.Imaging.Tiff {
{
uint offset = directory.Lookup (TagId.JPEGInterchangeFormat).ValueAsLong [0];
- System.IO.Stream file = Open ();
+ System.IO.Stream file = PixbufStream ();
file.Position = offset;
return file;
}
@@ -1836,11 +1836,11 @@ namespace FSpot.Imaging.Tiff {
ImageDirectory directory = sub.Directory [sub.Directory.Length - 1];
uint offset = directory.Lookup (TagId.StripOffsets).ValueAsLong [0];
- System.IO.Stream file = Open ();
+ System.IO.Stream file = base.PixbufStream ();
file.Position = offset;
return file;
} catch {
- return DCRawFile.RawPixbufStream (uri);
+ return DCRawFile.RawPixbufStream (Uri);
}
}
@@ -1951,7 +1951,7 @@ namespace FSpot.Imaging.Tiff {
ImageDirectory jpeg_directory = sub.Directory [0];
return LookupJpegSubstream (jpeg_directory);
} catch (System.Exception) {
- return DCRawFile.RawPixbufStream (uri);
+ return DCRawFile.RawPixbufStream (Uri);
}
}
}
@@ -1965,7 +1965,7 @@ namespace FSpot.Imaging.Tiff {
public override System.IO.Stream PixbufStream ()
{
uint offset = Header.Directory.Lookup (TagId.StripOffsets).ValueAsLong [0];
- System.IO.Stream file = Open ();
+ System.IO.Stream file = base.PixbufStream ();
file.Position = offset;
return file;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]