示例#1
0
        public void AddNullTest()
        {
            Ifd   target = new Ifd();
            Field item   = null;

            Assert.Throws <ArgumentNullException>(() => target.Add(item));
        }
示例#2
0
        public void AddRangeNullTest()
        {
            Ifd target = new Ifd();
            IEnumerable <Field> items = null;

            Assert.Throws <ArgumentNullException>(() => target.AddRange(items));
        }
示例#3
0
        public void AddTest()
        {
            Ifd   target = new Ifd();
            Field item   = new Field();

            target.Add(item);
        }
示例#4
0
        public void AddRangeTest()
        {
            Ifd target = new Ifd();
            IEnumerable <Field> items = new List <Field> {
                new Field(), new Field(), new Field()
            };

            target.AddRange(items);
        }
示例#5
0
            public Exif(byte[] buf)
            {
                Length = buf.Length;

                byte[] header = new byte[8];
                Array.Copy(buf, 0, header, 0, 8);

                char c1 = Convert.ToChar(header[0]);
                char c2 = Convert.ToChar(header[1]);

                if (c1 == 'I' && c2 == 'I')
                {
                    LittleEndian = true;
                }
                else if (c1 == 'M' && c2 == 'M')
                {
                    LittleEndian = false;
                }
                else
                {
                    throw new Exception($"Poorly formed header, Unknown endian format: {c1} {c2}");
                }

                byte[] magicNumber = new byte[2] {
                    header[2],
                    header[3]
                };

                if (LittleEndian != BitConverter.IsLittleEndian)
                {
                    Array.Reverse(magicNumber);
                }

                TiffId = BitConverter.ToUInt16(magicNumber, 0);

                if (TiffId != 42)
                {
                    throw new Exception($"Poorly formed header, Invalid TIFF ID: {TiffId}");
                }

                byte[] offset = new byte[4]
                {
                    header[4],
                    header[5],
                    header[6],
                    header[7]
                };

                if (LittleEndian != BitConverter.IsLittleEndian)
                {
                    Array.Reverse(offset);
                }

                FirstIFDOffset = BitConverter.ToUInt32(offset, 0);

                ifd0 = new Ifd(buf, FirstIFDOffset, LittleEndian);
            }
示例#6
0
        public void SortTest()
        {
            var target = new Ifd
            {
                new Field(TagType.Artist, FieldType.Short, new short[] { }),
                new Field(TagType.BitsPerSample, FieldType.Short, new short[] { }),
                new Field(TagType.CellLength, FieldType.Short, new short[] { }),
            };

            target.Sort();
        }
示例#7
0
        private static Tiff FromPtr(IntPtr ptr)
        {
            Tiff _tiff = new Tiff {
                _header = (TiffHeader)Marshal.PtrToStructure(ptr, typeof(TiffHeader))
            };

            if (_tiff._header.magic == MagicValues.BigEndian)
            {
                throw new NotSupportedException();
            }
            _tiff._ifd = Ifd.FromPtr((IntPtr)(ptr.ToInt64() + _tiff._header.dirOffset), ptr);
            return(_tiff);
        }
示例#8
0
            private void Load(IntPtr ptr, IntPtr baseAddr)
            {
                ushort _count = (ushort)Marshal.PtrToStructure(ptr, typeof(ushort));
                IntPtr _ptr   = (IntPtr)(ptr.ToInt64() + sizeof(ushort));

                for (int i = 0, _size = Marshal.SizeOf(typeof(TiffDirEntry)); i < _count; i++, _ptr = (IntPtr)(_ptr.ToInt64() + _size))
                {
                    this.Add(Tiff.IfdEntry.FromPtr(_ptr, baseAddr));
                }
                int _nextIdfOffset = (int)Marshal.PtrToStructure(_ptr, typeof(int));

                if (_nextIdfOffset != 0)
                {
                    this.NextIfd = Ifd.FromPtr((IntPtr)(baseAddr.ToInt64() + _nextIdfOffset), baseAddr);
                }
                this.Offset = (int)(ptr.ToInt64() - baseAddr.ToInt64());
                this.Size   = 6 + Marshal.SizeOf(typeof(Tiff.TiffDirEntry)) * _count;
            }
示例#9
0
        public static string GetIfdNameExtended(Ifd ifd)
        {
            switch (ifd)
            {
            case Ifd.Zero:
                return(Catalog.GetString("Image Directory"));

            case Ifd.One:
                return(Catalog.GetString("Thumbnail Directory"));

            case Ifd.Exif:
                return(Catalog.GetString("Exif Directory"));

            case Ifd.Gps:
                return(Catalog.GetString("GPS Directory"));

            case Ifd.InterOperability:
                return(Catalog.GetString("InterOperability Directory"));

            default:
                return(Catalog.GetString("Unknown Directory"));
            }
        }
示例#10
0
		public static string GetIfdName (Ifd ifd)
		{			
			IntPtr raw_ret = exif_ifd_get_name (ifd);
			return Marshal.PtrToStringAnsi (raw_ret);
		}
示例#11
0
 static extern IntPtr exif_ifd_get_name(Ifd ifd);
示例#12
0
        public static string GetIfdName(Ifd ifd)
        {
            IntPtr raw_ret = exif_ifd_get_name(ifd);

            return(Marshal.PtrToStringAnsi(raw_ret));
        }
示例#13
0
        public ExifContent GetContents(Ifd ifd)
        {
            Assemble();

            return((ExifContent)ifds [(int)ifd]);
        }
示例#14
0
 public void FieldCollectionConstructorTest()
 {
     Ifd target = new Ifd();
 }
示例#15
0
		public ExifContent GetContents (Ifd ifd)
		{
			Assemble ();

			return (ExifContent) ifds [(int)ifd];
		}
示例#16
0
		public static string GetIfdNameExtended (Ifd ifd)
		{
			switch (ifd) {
			case Ifd.Zero:
				return Catalog.GetString ("Image Directory");
			case Ifd.One:
				return Catalog.GetString ("Thumbnail Directory");
			case Ifd.Exif:
				return Catalog.GetString ("Exif Directory");
			case Ifd.Gps:
				return Catalog.GetString ("GPS Directory");
			case Ifd.InterOperability:
				return Catalog.GetString ("InterOperability Directory");
			default:
				return Catalog.GetString ("Unknown Directory");
			}
		}
示例#17
0
        static void Main(string[] args)
        {
            string path = @"C:\Users\Greg\Pictures\file000325161223.jpg";

            //string path = @"E:\Development\vs2017\RotationGdiTest\Debug\D500\DSC_0001.JPG";

            if (args.Length > 0)
            {
                path = args[0];
            }

            using (FileStream fileStream = new FileStream(path, FileMode.Open))
            {
                byte[] buf2 = new byte[2];
                fileStream.Read(buf2, 0, 2);
                if (buf2[0] != 0xFF && buf2[1] != 0xD8)
                {
                    Console.WriteLine("File not a JPEG");
                    goto done;
                }

                fileStream.Read(buf2, 0, 2);
                while (!Jpeg.Definitions.SOS(buf2) && !Jpeg.Definitions.SOI(buf2))
                {
                    byte[] lenbuf = new byte[2];
                    fileStream.Read(lenbuf, 0, 2);
                    Array.Reverse(lenbuf);
                    ushort segmentLength = BitConverter.ToUInt16(lenbuf, 0);
                    int    len           = (int)segmentLength - 2;
                    Console.WriteLine($"Reading {len} {BitConverter.ToString(lenbuf)} {BitConverter.ToString(buf2)} ");
                    if (len <= 0)
                    {
                        goto done;
                    }


                    byte[] buf = new byte[len];
                    fileStream.Read(buf, 0, len);
                    try
                    {
                        if (Jpeg.Definitions.APP0(buf2))
                        {
                            IMarker app0 = App0.Parse(buf);
                            if (app0.GetMarkerType() == MarkerType.JFIF)
                            {
                                App0.Jfif jfif = (App0.Jfif)app0;
                                Console.WriteLine($"Jfif {jfif.GetVersion()}");
                                switch (jfif.DensityUnit)
                                {
                                case App0.Jfif.XYDensityUnit.AspectRatio:
                                    Console.WriteLine("XYDensityUnit AspectRatio");
                                    break;

                                case App0.Jfif.XYDensityUnit.DotsPerInch:
                                    Console.WriteLine("XYDensityUnit DotsPerInch");
                                    break;

                                case App0.Jfif.XYDensityUnit.DotsPerCm:
                                    Console.WriteLine("XYDensityUnit DOtsPerCm");
                                    break;
                                }

                                Console.WriteLine($"XDensity {jfif.XDensity}, YDensity {jfif.YDensity}");
                                Console.WriteLine($"Thumbnail X {jfif.XThumbnailCount}, Thumbnail Y {jfif.YThumbnailCount}");
                            }
                            else if (app0.GetMarkerType() == MarkerType.JFXX)
                            {
                                App0.Jfxx jfxx = (App0.Jfxx)app0;
                                Console.WriteLine("Jfxx");
                            }
                            else
                            {
                                Console.WriteLine("APP0");
                            }
                        }
                        else if (Jpeg.Definitions.APP1(buf2))
                        {
                            IMarker app = App1.Parse(buf);

                            if (app.GetMarkerType() == MarkerType.EXIF)
                            {
                                App1.Exif exif = (App1.Exif)app;
                                Console.WriteLine($"Exif {exif.TiffId} {exif.FirstIFDOffset} {exif.Length}");
                                Ifd ifd0 = exif.Ifd0;
                                Console.WriteLine($"IFD0 tag count {ifd0.FieldInteroperabiltyCount}");
                                Console.WriteLine($"Next IFD {ifd0.OffsetToNextIfd}");
                                for (int i = 0; i < ifd0.FieldInteroperabilties.Length; ++i)
                                {
                                    Console.WriteLine($"{ifd0.FieldInteroperabilties[i].TypeValue.TypeToString()} {ifd0.FieldInteroperabilties[i].Tag}");
                                    Console.WriteLine(ifd0.FieldInteroperabilties[i]);

                                    if (ifd0.FieldInteroperabilties[i].ExifIfd)
                                    {
                                        Ifd exifIfd = ifd0.FieldInteroperabilties[i].Exif;
                                        for (int j = 0; j < exifIfd.FieldInteroperabilties.Length; ++j)
                                        {
                                            Console.WriteLine($"{exifIfd.FieldInteroperabilties[j].TypeValue.TypeToString()} {exifIfd.FieldInteroperabilties[j].Tag}");
                                            Console.WriteLine(exifIfd.FieldInteroperabilties[j]);
                                        }
                                    }


                                    if (ifd0.FieldInteroperabilties[i].InteroperabilityIfd)
                                    {
                                        Ifd interoperabilityIfd = ifd0.FieldInteroperabilties[i].Interoperability;
                                        for (int j = 0; j < interoperabilityIfd.FieldInteroperabilties.Length; ++j)
                                        {
                                            Console.WriteLine($"{interoperabilityIfd.FieldInteroperabilties[j].TypeValue.TypeToString()} {interoperabilityIfd.FieldInteroperabilties[j].Tag}");
                                            Console.WriteLine(interoperabilityIfd.FieldInteroperabilties[j]);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                App1.XMP xmp = (App1.XMP)app;
                                Console.WriteLine("XMP");
                                Console.WriteLine(xmp.RawXml);
                            }
                        }
                        else if (Jpeg.Definitions.APPn(buf2))
                        {
                            Appn appn = new Appn(buf, buf2[1] & 0x0F);
                            Console.WriteLine($"Appn {appn.N}");
                        }
                        else if (Jpeg.Definitions.DQT(buf2))
                        {
                            Console.WriteLine($"DQT");
                        }
                        else if (Jpeg.Definitions.SOFn(buf2))
                        {
                            SOFn sofn = new SOFn(buf, buf2[1] & 0x0F);
                            Console.WriteLine($"SOFn {sofn.N}");
                        }
                        else if (Jpeg.Definitions.DRI(buf2))
                        {
                            Console.WriteLine("DRI");
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }


                    fileStream.Read(buf2, 0, 2);
                }
            }
done:
            if (Debugger.IsAttached)
            {
                Console.WriteLine("Complete. Press any key to continue.");
                Console.ReadKey();
            }
        }
示例#18
0
		static extern IntPtr exif_ifd_get_name (Ifd ifd);