Exemple #1
0
        protected override void PullImageProperties()
        {
            DirectoryEntry e;
            Header         header = new Header(Stream);

            e = header.Directory.Lookup(TagId.ExifIfdPointer);
            if (e != null)
            {
                ImageDirectory exif = ((SubdirectoryEntry)e).Directory [0];
                AddTiffDirectoryProperties(this, exif);
            }

            e = header.Directory.Lookup(TagId.SubIFDs);
            if (e != null)
            {
                ImageDirectory [] dirs = ((SubdirectoryEntry)e).Directory;

                foreach (ImageDirectory subdir in dirs)
                {
                    AddTiffDirectoryProperties(this, subdir);
                }
            }

            // we filter ifd0 last so that we pick up the
            // width and height from the full resolution
            // version if it exists

            AddTiffDirectoryProperties(this, header.Directory);
        }
Exemple #2
0
        private ImageSource ReadFromDisk(IFileSystemObject fileSystemObject)
        {
            ImageSource bitmap = null;
            //lock (locker)
            {
#if DISPLAY_DEBUG
                System.Diagnostics.Debug.WriteLine("Cache read from disk " + fileSystemObject.Name);
#endif
                if (fileSystemObject is IDirectoryObject)
                {
                    bitmap = _Converter.GetImage(fileSystemObject.FullName);
                }
                else if (ImageDirectory.IsImage(fileSystemObject as IFileObject))
                {
                    using (var stream = (fileSystemObject as IFileObject).OpenRead())
                    {
                        bitmap = GetBitmap(stream);
                    }
                }
                else
                {
                    bitmap = _Converter.GetImage(fileSystemObject.FullName);
                }
                bitmap.Freeze();
            }
            return(bitmap);
        }
Exemple #3
0
        public void TestImageDirectoryWithValidUrl()
        {
            var imageDirectory = new ImageDirectory(Mock.Of <IConfiguration>(c => c["CatsUrl"] == "https://latelier.co/data/cats.json"));
            var images         = imageDirectory.Images;

            Assert.IsNotEmpty(images);
        }
        //=========== LOADING ============
        #region Loading

        /**<summary>Returns a palette loaded from the specified stream.</summary>*/
        public static Palette FromStream(Stream stream)
        {
            BinaryReader   reader         = new BinaryReader(stream);
            ImageDirectory imageDirectory = new ImageDirectory();
            GraphicsData   graphicsData   = new GraphicsData(imageDirectory);

            imageDirectory.Read(reader);
            graphicsData.Read(reader);
            return(graphicsData.GetPalette(0));
        }
Exemple #5
0
 public ImageDirectory ReadDirectory(Tag tag)
 {
     foreach (var e in entry_list)
     {
         if (e.Tag == tag)
         {
             uint subdir_start = start + e.Offset;
             var  subdir       = new ImageDirectory(stream, subdir_start, subdir_start + e.Size, little);
             return(subdir);
         }
     }
     return(null);
 }
        //=========== READING ============
        #region Reading

        /**<summary>Saves the palette image to the specified file path.</summary>*/
        public void Save(string path)
        {
            BinaryWriter   writer         = new BinaryWriter(new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write));
            ImageDirectory imageDirectory = new ImageDirectory();
            GraphicsData   graphicsData   = new GraphicsData(imageDirectory);

            graphicsData.Add(this);

            long imageDirectoryPosition = writer.BaseStream.Position;

            imageDirectory.Write(writer);
            graphicsData.Write(writer);
            writer.BaseStream.Position = imageDirectoryPosition;
            imageDirectory.Write(writer);

            writer.Close();
        }
Exemple #7
0
        protected internal async Task <ImageDto> CreateImageAsync(IBrowserFile file, ImageDirectory imageDirectory)
        {
            CheckIfFileIsNull(file);

            CheckIfSizeLessThan500KiloByte(file);

            var extension = Path.GetExtension(file.Name).ToLower();

            CheckIfExtensionIsSupported(extension);

            var image = BuildImage(extension);

            image.ImageDirectory = imageDirectory;
            image.ByteImage      = await ConvertStreamToByteArray(file);

            // here you can upload to the server
            return(image);
        }
        //============ SAVING ============
        #region Saving

        /**<summary>Saves the palette to the specified stream.</summary>*/
        public void Save(Stream stream)
        {
            BinaryWriter   writer         = new BinaryWriter(stream);
            ImageDirectory imageDirectory = new ImageDirectory();
            GraphicsData   graphicsData   = new GraphicsData(imageDirectory);

            graphicsData.Add(this);

            long imageDirectoryPosition = writer.BaseStream.Position;

            imageDirectory.Write(writer);
            graphicsData.Write(writer);

            long endPosition = stream.Position;

            writer.BaseStream.Position = imageDirectoryPosition;
            imageDirectory.Write(writer);

            stream.Position = endPosition;
        }
		private void CompareDirectories (ImageDirectory olddir, ImageDirectory newdir)
		{
			Assert.AreEqual (olddir.Entries.Count, newdir.Entries.Count);
			for (int i = 0; i < olddir.Entries.Count; i++) {
				Assert.AreEqual (olddir.Entries [i].Id, newdir.Entries [i].Id);
				Assert.AreEqual (olddir.Entries [i].Type, newdir.Entries [i].Type);
				Assert.AreEqual (olddir.Entries [i].Count, newdir.Entries [i].Count);
				Assert.AreEqual (olddir.Entries [i].Length, newdir.Entries [i].Length);
				if (olddir.Entries [i] is SubdirectoryEntry) {
					SubdirectoryEntry oldsub = olddir.Entries [i] as SubdirectoryEntry;
					SubdirectoryEntry newsub = newdir.Entries [i] as SubdirectoryEntry;
					
					for (int j = 0; j < oldsub.Directory.Length; j++)
						CompareDirectories (oldsub.Directory [j], newsub.Directory [j]);
				}
			}
		}
		public Gdk.Pixbuf LoadJpegInterchangeFormat (ImageDirectory directory)
		{
			uint offset = directory.Lookup (TagId.JPEGInterchangeFormat).ValueAsLong [0];
			uint length = directory.Lookup (TagId.JPEGInterchangeFormatLength).ValueAsLong [0];
			   
			using (System.IO.Stream file = Open ()) {
				file.Position = offset;
				
				byte [] data = new byte [32768];
				int read;

				Gdk.PixbufLoader loader = new Gdk.PixbufLoader ();
				
				while (length > 0) {
					read = file.Read (data, 0, (int)System.Math.Min ((int)data.Length, length));
					if (read <= 0)
						break;

					loader.Write (data, (ulong)read);
					length -= (uint) read;
				}
				Gdk.Pixbuf result = loader.Pixbuf;
				loader.Close ();
				return result; 
			}
		}
		public System.IO.Stream LookupJpegSubstream (ImageDirectory directory)
		{
			uint offset = directory.Lookup (TagId.JPEGInterchangeFormat).ValueAsLong [0];
			
			System.IO.Stream file = Open ();
			file.Position = offset;
			return file;
		}
Exemple #12
0
        internal static void AddTiffDirectoryProperties(FilterTiff filter, ImageDirectory directory)
        {
            foreach (DirectoryEntry e in directory.Entries)
            {
                switch (e.Id)
                {
                case TagId.ImageDescription:
                    filter.AddProperty(Beagle.Property.New("exif:ImageDescription", e.ValueAsString [0]));
                    break;

                case TagId.Model:
                    filter.AddProperty(Beagle.Property.New("exif:Model", e.ValueAsString [0]));
                    break;

                case TagId.UserComment:
                    filter.AddProperty(Beagle.Property.New("exif:UserComment", e.ValueAsString [0]));
                    break;

                case TagId.DateTimeOriginal:
                    AddDateProperty(filter, "exif:DateTimeOriginal", e.ValueAsString [0]);
                    break;

                case TagId.DateTimeDigitized:
                    AddDateProperty(filter, "exif:DateTimeDigitized", e.ValueAsString [0]);
                    break;

                case TagId.DateTime:
                    AddDateProperty(filter, "exif:DateTime", e.ValueAsString [0]);
                    break;

                case TagId.PixelXDimension:
                    filter.Width = (int)e.ValueAsLong [0];
                    //filter.AddProperty (Beagle.Property.NewUnsearched ("exif:PixelXDimension", e.ValueAsString [0]));
                    break;

                case TagId.PixelYDimension:
                    filter.Height = (int)e.ValueAsLong [0];
                    //filter.AddProperty (Beagle.Property.NewUnsearched ("exif:PixelYDimension", e.ValueAsString [0]));
                    break;

                case TagId.ImageWidth:
                    uint wval = e.ValueAsLong [0];
                    if (filter.Width < wval)
                    {
                        filter.Width = (int)wval;
                    }
                    break;

                case TagId.ImageLength:
                    uint hval = e.ValueAsLong [0];
                    if (filter.Height < hval)
                    {
                        filter.Height = (int)hval;
                    }
                    break;

                case TagId.ExposureTime:
                    filter.AddProperty(Beagle.Property.NewUnsearched("exif:ExposureTime", e.ValueAsString [0]));
                    break;

                case TagId.ISOSpeedRatings:
                    filter.AddProperty(Beagle.Property.NewUnsearched("exif:ISOSpeedRatings", e.ValueAsString [0]));
                    break;

                case TagId.FNumber:
                    filter.AddProperty(Beagle.Property.NewUnsearched("exif:FNumber", Math.Round((e.RationalValue [0]).Value, 1)));
                    break;

                case TagId.FocalLength:
                    filter.AddProperty(Beagle.Property.NewUnsearched("exif:FocalLength", e.ValueAsString [0]));
                    break;

                case TagId.Flash:
                    ushort flash_val = e.ShortValue [0];
                    filter.AddProperty(Beagle.Property.NewBool("exif:Flash", (flash_val & 0x1) == 0x1));
                    break;

                case TagId.XMP:
                    XmpFile xmp = new XmpFile(new System.IO.MemoryStream(e.RawData));
                    filter.AddXmpProperties(xmp);
                    break;
                }
            }
        }
Exemple #13
0
 public string CreateMainDirectory(ImageDirectory imageDirectory)
 {
     return(CreateDirectory(imageDirectory.ToString()));
 }