[f-spot/taglib-metadata] Simplify Ciff and RafFile.



commit ba206bdcad57ab32569e945bca626240f415671f
Author: Ruben Vermeersch <ruben savanne be>
Date:   Tue Jul 6 23:21:03 2010 +0200

    Simplify Ciff and RafFile.

 src/Imaging/Ciff.cs    |  235 +----------------------------------------------
 src/Imaging/RafFile.cs |   12 +---
 2 files changed, 6 insertions(+), 241 deletions(-)
---
diff --git a/src/Imaging/Ciff.cs b/src/Imaging/Ciff.cs
index c688de1..d60c7d3 100644
--- a/src/Imaging/Ciff.cs
+++ b/src/Imaging/Ciff.cs
@@ -4,166 +4,8 @@ using Hyena;
 using TagLib.Image;
 
 namespace FSpot.Imaging.Ciff {
-	public enum Tag {
-		// Byte valuesad
-		NullRecord = 0x0000,
-		FreeBytes = 0x0001,
-		CanonColorInfo1 = 0x0032,
-
-		// ASCII strings
-		CanonFileDescription = 0x0805,
-		UserComment = 0x0805, // FIXME this is the same as above, is it correct?
-		CanonRawMakeModel = 0x080a, 
-		CanonFirmwareVersion = 0x080b,
-		ComponentVersion = 0x08c,
-		ROMOperationMode = 0x08d,
-		OwnerName = 0x0810,
-		CanonImageType = 0x0815,
-		OriginalFileName = 0x0816,
-		ThumbnailFileName = 0x0817,
-		
-		// Short values
-		TargetImageType = 0x100a,
-		ShutterReleaseMethod = 0x1010,
-		ShutterReleaseTiming = 0x1011,
-		ReleaseSetting = 0x1016,
-		BaseISO = 0x101c,
-
-		Uknown2 = 0x1028,
-
-		FocalLength = 0x1029,
-		CanonShotInfo = 0x102a,
-		CanonColorInfo2 = 0x102c,
-		CanonCameraSettings = 0x102d,
-		WhiteSample = 0x1030,
-		SensorInfo = 0x1031,
-		CanonCustomFunctions = 0x1033,
-		CanonPictureInfo = 0x1038,
-
-		Unknown3 = 0x1039,
-		Unknown4 = 0x1093,
-		Unknown5 = 0x10a8,
-		
-		WhiteBalanceTable = 0x10a9,
-		
-		Unknown6 = 0x10aa,
-
-		ColorTemperature = 0x10ae,
-		ColorSapce = 0x10b4,
-		
-		Unknown7 = 0x10b5,
-		unknown8 = 0x10c0,
-		Unknown9 = 0x10c1,
-
-		ImageFormat = 0x1803,
-		RecordID = 0x1804,
-		SelfTimerTime = 0x1806,
-		TargetDistanceSetting = 0x1807,
-		SerialNumber = 0x180b,
-		TimeStamp = 0x180e,
-		ImageSpec = 0x1810,
-		FlashInfo = 0x1813,
-		MeasuredEV = 0x1814,
-		FileNumber = 0x1817,
-		ExposureInfo = 0x1818,
-		
-		Unknown10 = 0x1834,
-
-		DecoderTable = 0x1835,
-		
-		Unknown11 = 0x183b,
-
-		// Image Data
-		RawData = 0x2005,
+	internal enum Tag {
 		JpgFromRaw = 0x2007,
-		ThumbnailImage = 0x2008,
-
-		// Directories
-		ImageDescrption = 0x2804,
-		CameraObject = 0x2807,
-		ShootingRecord = 0x3002,
-		MeasuredInfo = 0x3003,
-		CameraSpecification = 0x3004,
-		ImageProps = 0x300a,
-		ExifInformation = 0x300b
-	}
-
-	
-
-	internal struct ImageSpec {
-		public uint ImageWidth;  // Number of horizontal pixels
-		public uint ImageHeight; // Number of vertical pixels
-		public float PixelAspectRatio;
-		public uint ComponentBitDepth; // bits per component
-		public uint ColorBitDepth; // bits per component * channels
-		public uint ColorBW; //  byte wise:  0 gray - 1 color ; byte 2 use aspect ratio ; 3 and 4 reserved
-
-		public ImageSpec (byte [] data, bool little)
-		{
-			ImageWidth = BitConverter.ToUInt32 (data, 0, little);
-			ImageHeight = BitConverter.ToUInt32 (data, 4, little);
-
-			PixelAspectRatio = BitConverter.ToSingle (data, 8, little);
-			ComponentBitDepth = BitConverter.ToUInt32 (data, 16, little);
-			ColorBitDepth = BitConverter.ToUInt32 (data, 20, little);
-			ColorBW = BitConverter.ToUInt32 (data, 24, little);
-			Log.DebugFormat ("0x{0}", ColorBW.ToString ("x"));
-		}
-
-		public bool IsColor {
-			get {
-				return (ColorBW & 1) > 0;
-
-			}
-		}
-
-		public bool HasSquarePixels {
-			get {
-				return (ColorBW & 1 << 1) == 0;
-			}
-		}
-	}
-
-	public struct CaptureTime {
-		uint seconds;
-		int tz_offset;
-		uint tz_data;
-
-		public CaptureTime (byte [] data, bool little)
-		{
-			seconds = BitConverter.ToUInt32 (data, 0, little);
-			tz_offset = BitConverter.ToInt32 (data, 4, little);
-			tz_data = BitConverter.ToUInt32 (data, 8, little);
-		}
-
-		public System.DateTime LocalTime {
-			get {
-				return new System.DateTime (1970, 1, 1).AddSeconds (seconds);
-			}
-		}
-
-		public bool HasTimezone {
-			get {
-				return ((1 << 31 & tz_data) > 0);
-			}
-		}
-
-		public override string ToString ()
-		{
-			string tz = String.Empty;
-			
-			if (HasTimezone)
-				if (tz_offset != 0)
-					tz = System.String.Format ("{0}{1}:{2}", 
-								   seconds > 0 ? "+" : "-", 
-								   tz_offset / 3600, 
-								   tz_offset / 60 % 60);
-				else 
-					tz = "Z";
-
-		       
-			return System.String.Format ("{0}{1}", LocalTime.ToString ("yyyy-MM-ddThh:mm:ss"), tz);
-		}
 	}
 
 	public enum EntryType : ushort {
@@ -177,9 +19,7 @@ namespace FSpot.Imaging.Ciff {
 	}
 	
 	public enum Mask {
-		StorageFormat = 0xc000,
 		Type = 0x3800,
-		ID = 0x07ff,
 	}
 
 	/* See http://www.sno.phy.queensu.ca/~phil/exiftool/canon_raw.html */
@@ -194,27 +34,9 @@ namespace FSpot.Imaging.Ciff {
 			Size = BitConverter.ToUInt32 (data, pos + 2, little);
 			Offset = BitConverter.ToUInt32 (data, pos + 6, little);
 		}	
-		
-		public EntryType Type {
-			get {
-				return GetType (Tag);
-			}
-		}
-
-		public static EntryType GetType (Tag tag) 
-		{
-			EntryType type = (EntryType) ((ushort)tag & (ushort)Mask.Type);
-			return type;
-		}
-
-		public static bool IsDirectory (Tag tag)
-		{
-			EntryType type = GetType (tag);
-			return (type == EntryType.Directory1 || type == EntryType.Directory2);
-		}
 	}
 
-	public class ImageDirectory {
+	class ImageDirectory {
 		System.Collections.ArrayList entry_list;
 		uint Count;
 		bool little;
@@ -286,17 +108,12 @@ namespace FSpot.Imaging.Ciff {
 		}
 	}
 	
-	public class CiffFile : BaseImageFile , SemWeb.StatementSource {
-		public ImageDirectory root;
+	public class CiffFile : BaseImageFile {
+		ImageDirectory root;
 		bool little;
 		System.IO.Stream stream;
-
-                // False seems a safe default
-                public bool Distinct {
-                        get { return false; }
-                }
 		
-		public ImageDirectory Root {
+		ImageDirectory Root {
 			get {
 				if (root == null) {
 					stream = PixbufStream ();
@@ -311,48 +128,6 @@ namespace FSpot.Imaging.Ciff {
 		{
 		}
 
-		public void Select (SemWeb.StatementSink sink)
-		{
-			byte [] data = null;
-			ImageDirectory props = Root.ReadDirectory (Tag.ImageProps);
-			ImageDirectory camera = props.ReadDirectory (Tag.CameraObject);
-
-			data = props.ReadEntry (Tag.TimeStamp);
-			if (data != null)
-				MetadataStore.AddLiteral (sink, "xmp:CreateDate", new CaptureTime (data, little).ToString ());
-
-			data = props.ReadEntry (Tag.ImageSpec);
-			if (data != null) {
-				ImageSpec spec = new ImageSpec (data, little);
-				MetadataStore.AddLiteral (sink, "tiff:ImageWidth", spec.ImageWidth.ToString ());
-				MetadataStore.AddLiteral (sink, "tiff:ImageLength", spec.ImageHeight.ToString ());
-				string comp = spec.ComponentBitDepth.ToString ();
-
-				if (spec.IsColor) {
-					MetadataStore.Add (sink, "tiff:BitsPerSample", "rdf:Seq", new string [] { comp, comp, comp });
-				} else {
-					MetadataStore.Add (sink, "tiff:BitsPerSample", "rdf:Seq", new string [] { comp });
-				}					
-				
-				if (!spec.HasSquarePixels) {
-					MetadataStore.AddLiteral (sink, "tiff:XResolution", 
-								  (1000000 * spec.PixelAspectRatio).ToString ());
-					MetadataStore.AddLiteral (sink, "tiff:YResolution", 
-								  (1000000 * (1 / spec.PixelAspectRatio)).ToString ());
-				}
-					
-			}
-			
-			data = camera.ReadEntry (Tag.CanonRawMakeModel);
-			if (data != null) {
-				string make_model = System.Text.Encoding.ASCII.GetString (data, 0, data.Length - 1);
-				string [] vals = make_model.Split (new char [] {'\0'});
-				MetadataStore.AddLiteral (sink, "tiff:Make", vals [0]); 
-				MetadataStore.AddLiteral (sink, "tiff:Model", vals [1]); 
-			}
-		}
-
-
 		private ImageDirectory Load (System.IO.Stream stream)
 		{
 			byte [] header = new byte [26];  // the spec reserves the first 26 bytes as the header block
diff --git a/src/Imaging/RafFile.cs b/src/Imaging/RafFile.cs
index b4974ec..ee6f315 100644
--- a/src/Imaging/RafFile.cs
+++ b/src/Imaging/RafFile.cs
@@ -14,12 +14,7 @@ namespace FSpot.Imaging.Raf {
 
 	// ALL the sample files I have begin with "FUJIFILMCCD-RAW "
 	
-	public class RafFile : BaseImageFile, SemWeb.StatementSource {
-
-                // false seems a safe default
-                public bool Distinct {
-                        get { return false; }
-                }
+	public class RafFile : BaseImageFile {
 
 		public RafFile (SafeUri uri) : base (uri)
 		{
@@ -35,10 +30,6 @@ namespace FSpot.Imaging.Raf {
 				return DCRawFile.RawPixbufStream (Uri);
 		}
 
-		public void Select (SemWeb.StatementSink sink)
-		{
-		}
-
 		private byte [] GetEmbeddedJpeg ()
 		{
 			using (System.IO.Stream stream = base.PixbufStream ()) {
@@ -61,7 +52,6 @@ namespace FSpot.Imaging.Raf {
 				stream.Read (image, 0, image.Length);
 				return image;
 			}
-
 		}
 	}
 }



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