Exemplo n.º 1
0
        public virtual void Populate(JpegInfo info, ExifIFD ifd)
        {
            if (ifd == ExifIFD.Exif)
            {
                switch ((ExifId)this.Tag)
                {
                case ExifId.ImageWidth: info.Width = GetInt(0); break;

                case ExifId.ImageHeight: info.Height = GetInt(0); break;

                case ExifId.Orientation: info.Orientation = (ExifOrientation)GetInt(0); break;

                case ExifId.XResolution: info.XResolution = GetNumericValue(0); break;

                case ExifId.YResolution: info.YResolution = GetNumericValue(0); break;

                case ExifId.ResolutionUnit: info.ResolutionUnit = (ExifUnit)GetInt(0); break;

                case ExifId.DateTime: info.DateTime = GetStringValue(); break;

                case ExifId.DateTimeOriginal: info.DateTimeOriginal = GetStringValue(); break;

                case ExifId.Description: info.Description = GetStringValue(); break;

                case ExifId.Make: info.Make = GetStringValue(); break;

                case ExifId.Model: info.Model = GetStringValue(); break;

                case ExifId.Software: info.Software = GetStringValue(); break;

                case ExifId.Artist: info.Artist = GetStringValue(); break;

                case ExifId.ThumbnailOffset: info.ThumbnailOffset = GetInt(0); break;

                case ExifId.ThumbnailLength: info.ThumbnailSize = GetInt(0); break;

                case ExifId.Copyright: info.Copyright = GetStringValue(); break;

                case ExifId.UserComment: info.UserComment = GetStringValue(); break;

                case ExifId.ExposureTime: info.ExposureTime = GetNumericValue(0); break;

                case ExifId.FNumber: info.FNumber = GetNumericValue(0); break;

                case ExifId.FlashUsed: info.Flash = (ExifFlash)GetInt(0); break;

                default: break;
                }
            }
            else if (ifd == ExifIFD.Gps)
            {
                switch ((ExifGps)this.Tag)
                {
                case ExifGps.LatitudeRef:
                {
                    if (GetStringValue() == "N")
                    {
                        info.GpsLatitudeRef = ExifGpsLatitudeRef.North;
                    }
                    else if (GetStringValue() == "S")
                    {
                        info.GpsLatitudeRef = ExifGpsLatitudeRef.South;
                    }
                } break;

                case ExifGps.LongitudeRef:
                {
                    if (GetStringValue() == "E")
                    {
                        info.GpsLongitudeRef = ExifGpsLongitudeRef.East;
                    }
                    else if (GetStringValue() == "W")
                    {
                        info.GpsLongitudeRef = ExifGpsLongitudeRef.West;
                    }
                } break;

                case ExifGps.Latitude:
                {
                    if (Components == 3)
                    {
                        info.GpsLatitude[0] = GetNumericValue(0);
                        info.GpsLatitude[1] = GetNumericValue(1);
                        info.GpsLatitude[2] = GetNumericValue(2);
                    }
                } break;

                case ExifGps.Longitude:
                {
                    if (Components == 3)
                    {
                        info.GpsLongitude[0] = GetNumericValue(0);
                        info.GpsLongitude[1] = GetNumericValue(1);
                        info.GpsLongitude[2] = GetNumericValue(2);
                    }
                } break;
                }
            }
        }
Exemplo n.º 2
0
        private void ProcessExifDir(byte[] section, int offsetDir, int offsetBase, int length, int depth, ExifIFD ifd)
        {
            if (depth > 4)
            {
                // corrupted Exif header...
                return;
            }

            ushort numEntries = ExifIO.ReadUShort(section, offsetDir, littleEndian);
            if (offsetDir + 2 + 12 * numEntries >= offsetDir + length)
            {
                // too long
                return;
            }

            int offset = 0;

            for (int de = 0; de < numEntries; ++de)
            {
                offset = DirOffset(offsetDir, de);
                ExifTag exifTag = new ExifTag(section, offset, offsetBase, length, littleEndian);

                if (!exifTag.IsValid)
                    continue;

                switch (exifTag.Tag)
                {
                    case (int)ExifIFD.Exif:
                        {
                            int dirStart = offsetBase + exifTag.GetInt(0);
                            if (dirStart <= offsetBase + length)
                            {
                                ProcessExifDir(section, dirStart, offsetBase, length, depth + 1, ExifIFD.Exif);
                            }
                        } break;
                    case (int)ExifIFD.Gps:
                        {
                            int dirStart = offsetBase + exifTag.GetInt(0);
                            if (dirStart <= offsetBase + length)
                            {
                                ProcessExifDir(section, dirStart, offsetBase, length, depth + 1, ExifIFD.Gps);
                            }
                        } break;
                    default:
                        {
                            exifTag.Populate(info, ifd);
                        } break;
                }
            }

            // final link defined?
            offset = DirOffset(offsetDir, numEntries) + 4;
            if (offset <= offsetBase + length)
            {
                offset = ExifIO.ReadInt(section, offsetDir + 2 + 12 * numEntries, littleEndian);
                if (offset > 0)
                {
                    int subDirStart = offsetBase + offset;
                    if (subDirStart <= offsetBase + length && subDirStart >= offsetBase)
                    {
                        ProcessExifDir(section, subDirStart, offsetBase, length, depth + 1, ifd);
                    }
                }
            }

            if (info.ThumbnailData == null && info.ThumbnailOffset > 0 && info.ThumbnailSize > 0)
            {
                // store it.
                info.ThumbnailData = new byte[info.ThumbnailSize];
                Array.Copy(section, offsetBase + info.ThumbnailOffset, info.ThumbnailData, 0, info.ThumbnailSize);
            }
        }
Exemplo n.º 3
0
        private void ProcessExifDir(byte[] section, int offsetDir, int offsetBase, int length, int depth, ExifIFD ifd)
        {
            if (depth > 4)
            {
                // corrupted Exif header...
                return;
            }

            ushort numEntries = ExifIO.ReadUShort(section, offsetDir, littleEndian);

            if (offsetDir + 2 + 12 * numEntries >= offsetDir + length)
            {
                // too long
                return;
            }

            int offset = 0;

            for (int de = 0; de < numEntries; ++de)
            {
                offset = DirOffset(offsetDir, de);
                ExifTag exifTag = new ExifTag(section, offset, offsetBase, length, littleEndian);

                if (!exifTag.IsValid)
                {
                    continue;
                }

                switch (exifTag.Tag)
                {
                case (int)ExifIFD.Exif:
                {
                    int dirStart = offsetBase + exifTag.GetInt(0);
                    if (dirStart <= offsetBase + length)
                    {
                        ProcessExifDir(section, dirStart, offsetBase, length, depth + 1, ExifIFD.Exif);
                    }
                } break;

                case (int)ExifIFD.Gps:
                {
                    int dirStart = offsetBase + exifTag.GetInt(0);
                    if (dirStart <= offsetBase + length)
                    {
                        ProcessExifDir(section, dirStart, offsetBase, length, depth + 1, ExifIFD.Gps);
                    }
                } break;

                default:
                {
                    exifTag.Populate(info, ifd);
                } break;
                }
            }

            // final link defined?
            offset = DirOffset(offsetDir, numEntries) + 4;
            if (offset <= offsetBase + length)
            {
                offset = ExifIO.ReadInt(section, offsetDir + 2 + 12 * numEntries, littleEndian);
                if (offset > 0)
                {
                    int subDirStart = offsetBase + offset;
                    if (subDirStart <= offsetBase + length && subDirStart >= offsetBase)
                    {
                        ProcessExifDir(section, subDirStart, offsetBase, length, depth + 1, ifd);
                    }
                }
            }

            if (info.ThumbnailData == null && info.ThumbnailOffset > 0 && info.ThumbnailSize > 0)
            {
                // store it.
                info.ThumbnailData = new byte[info.ThumbnailSize];
                Array.Copy(section, offsetBase + info.ThumbnailOffset, info.ThumbnailData, 0, info.ThumbnailSize);
            }
        }
Exemplo n.º 4
0
 public virtual void Populate(JpegInfo info, ExifIFD ifd)
 {
     if (ifd == ExifIFD.Exif)
     {
         switch ((ExifId)this.Tag)
         {
             case ExifId.ImageWidth: info.Width = GetInt(0); break;
             case ExifId.ImageHeight: info.Height = GetInt(0); break;
             case ExifId.Orientation: info.Orientation = (ExifOrientation)GetInt(0); break;
             case ExifId.XResolution: info.XResolution = GetNumericValue(0); break;
             case ExifId.YResolution: info.YResolution = GetNumericValue(0); break;
             case ExifId.ResolutionUnit: info.ResolutionUnit = (ExifUnit)GetInt(0); break;
             case ExifId.DateTime: info.DateTime = GetStringValue(); break;
             case ExifId.DateTimeOriginal: info.DateTimeOriginal = GetStringValue(); break;
             case ExifId.Description: info.Description = GetStringValue(); break;
             case ExifId.Make: info.Make = GetStringValue(); break;
             case ExifId.Model: info.Model = GetStringValue(); break;
             case ExifId.Software: info.Software = GetStringValue(); break;
             case ExifId.Artist: info.Artist = GetStringValue(); break;
             case ExifId.ThumbnailOffset: info.ThumbnailOffset = GetInt(0); break;
             case ExifId.ThumbnailLength: info.ThumbnailSize = GetInt(0); break;
             case ExifId.Copyright: info.Copyright = GetStringValue(); break;
             case ExifId.UserComment: info.UserComment = GetStringValue(); break;
             case ExifId.ExposureTime: info.ExposureTime = GetNumericValue(0); break;
             case ExifId.FNumber: info.FNumber = GetNumericValue(0); break;
             case ExifId.FlashUsed: info.Flash = (ExifFlash)GetInt(0); break;
             default: break;
         }
     }
     else if (ifd == ExifIFD.Gps)
     {
         switch ((ExifGps)this.Tag)
         {
             case ExifGps.LatitudeRef:
                 {
                     if (GetStringValue() == "N") info.GpsLatitudeRef = ExifGpsLatitudeRef.North;
                     else if (GetStringValue() == "S") info.GpsLatitudeRef = ExifGpsLatitudeRef.South;
                 } break;
             case ExifGps.LongitudeRef:
                 {
                     if (GetStringValue() == "E") info.GpsLongitudeRef = ExifGpsLongitudeRef.East;
                     else if (GetStringValue() == "W") info.GpsLongitudeRef = ExifGpsLongitudeRef.West;
                 } break;
             case ExifGps.Latitude:
                 {
                     if (Components == 3)
                     {
                         info.GpsLatitude[0] = GetNumericValue(0);
                         info.GpsLatitude[1] = GetNumericValue(1);
                         info.GpsLatitude[2] = GetNumericValue(2);
                     }
                 } break;
             case ExifGps.Longitude:
                 {
                     if (Components == 3)
                     {
                         info.GpsLongitude[0] = GetNumericValue(0);
                         info.GpsLongitude[1] = GetNumericValue(1);
                         info.GpsLongitude[2] = GetNumericValue(2);
                     }
                 } break;
         }
     }
 }
Exemplo n.º 5
0
        public virtual void Populate(JpegInfo info, ExifIFD ifd, long sectionStart)
        {
            if (ifd == ExifIFD.Exif)
            {
                switch ((ExifId)this.Tag)
                {
                case ExifId.FlashUsed:
                    info.Flash = (ExifFlash)this.GetInt(0);
                    break;

                case ExifId.UserComment:
                    info.UserComment = this.GetStringValue();
                    break;

                case ExifId.ExposureTime:
                    info.ExposureTime = this.GetNumericValue(0);
                    break;

                case ExifId.FNumber:
                    info.FNumber = this.GetNumericValue(0);
                    break;

                case ExifId.ThumbnailLength:
                    info.ThumbnailSize = this.GetInt(0);
                    break;

                case ExifId.Copyright:
                    info.Copyright = this.GetStringValue();
                    break;

                case ExifId.Artist:
                    info.Artist = this.GetStringValue();
                    break;

                case ExifId.ThumbnailOffset:
                    info.ThumbnailOffset = this.GetInt(0);
                    break;

                case ExifId.Software:
                    info.Software = this.GetStringValue();
                    break;

                case ExifId.DateTime:
                    info.DateTime = this.GetStringValue();
                    break;

                case ExifId.YResolution:
                    info.YResolution = this.GetNumericValue(0);
                    break;

                case ExifId.ResolutionUnit:
                    info.ResolutionUnit = (ExifUnit)this.GetInt(0);
                    break;

                case ExifId.Description:
                    info.Description = this.GetStringValue();
                    break;

                case ExifId.Make:
                    info.Make = this.GetStringValue();
                    break;

                case ExifId.Model:
                    info.Model = this.GetStringValue();
                    break;

                case ExifId.Orientation:
                    info.OrientationOffset = sectionStart + this.ValueOffset;
                    info.Orientation       = (ExifOrientation)this.GetInt(0);
                    break;

                case ExifId.XResolution:
                    info.XResolution = this.GetNumericValue(0);
                    break;

                case ExifId.ImageWidth:
                    info.Width = this.GetInt(0);
                    break;

                case ExifId.ImageHeight:
                    info.Height = this.GetInt(0);
                    break;
                }
            }
            else
            {
                if (ifd != ExifIFD.Gps)
                {
                    return;
                }
                switch (this.Tag)
                {
                case 1:
                    if (this.GetStringValue() == "N")
                    {
                        info.GpsLatitudeRef = ExifGpsLatitudeRef.North;
                        break;
                    }
                    if (!(this.GetStringValue() == "S"))
                    {
                        break;
                    }
                    info.GpsLatitudeRef = ExifGpsLatitudeRef.South;
                    break;

                case 2:
                    if (this.Components != 3)
                    {
                        break;
                    }
                    info.GpsLatitude[0] = this.GetNumericValue(0);
                    info.GpsLatitude[1] = this.GetNumericValue(1);
                    info.GpsLatitude[2] = this.GetNumericValue(2);
                    break;

                case 3:
                    if (this.GetStringValue() == "E")
                    {
                        info.GpsLongitudeRef = ExifGpsLongitudeRef.East;
                        break;
                    }
                    if (!(this.GetStringValue() == "W"))
                    {
                        break;
                    }
                    info.GpsLongitudeRef = ExifGpsLongitudeRef.West;
                    break;

                case 4:
                    if (this.Components != 3)
                    {
                        break;
                    }
                    info.GpsLongitude[0] = this.GetNumericValue(0);
                    info.GpsLongitude[1] = this.GetNumericValue(1);
                    info.GpsLongitude[2] = this.GetNumericValue(2);
                    break;
                }
            }
        }
Exemplo n.º 6
0
        private void ProcessExifDir(byte[] section, int offsetDir, int offsetBase, int length, int depth, ExifIFD ifd, long sectionStart)
        {
            if (depth > 4)
            {
                return;
            }
            ushort num1 = ExifIO.ReadUShort(section, offsetDir, this.littleEndian);

            if (offsetDir + 2 + 12 * (int)num1 >= offsetDir + length)
            {
                return;
            }
            for (int num2 = 0; num2 < (int)num1; ++num2)
            {
                int     sectionOffset = this.DirOffset(offsetDir, num2);
                ExifTag exifTag       = new ExifTag(section, sectionOffset, offsetBase, length, this.littleEndian);
                if (exifTag.IsValid)
                {
                    switch (exifTag.Tag)
                    {
                    case 34665:
                        int offsetDir1 = offsetBase + exifTag.GetInt(0);
                        if (offsetDir1 <= offsetBase + length)
                        {
                            this.ProcessExifDir(section, offsetDir1, offsetBase, length, depth + 1, ExifIFD.Exif, sectionStart);
                            continue;
                        }
                        continue;

                    case 34853:
                        int offsetDir2 = offsetBase + exifTag.GetInt(0);
                        if (offsetDir2 <= offsetBase + length)
                        {
                            this.ProcessExifDir(section, offsetDir2, offsetBase, length, depth + 1, ExifIFD.Gps, sectionStart);
                            continue;
                        }
                        continue;

                    default:
                        exifTag.Populate(this.info, ifd, sectionStart);
                        continue;
                    }
                }
            }
            if (this.DirOffset(offsetDir, (int)num1) + 4 <= offsetBase + length)
            {
                int num2 = ExifIO.ReadInt(section, offsetDir + 2 + 12 * (int)num1, this.littleEndian);
                if (num2 > 0)
                {
                    int offsetDir1 = offsetBase + num2;
                    if (offsetDir1 <= offsetBase + length && offsetDir1 >= offsetBase)
                    {
                        this.ProcessExifDir(section, offsetDir1, offsetBase, length, depth + 1, ifd, sectionStart);
                    }
                }
            }
            if (this.info.ThumbnailData != null || this.info.ThumbnailOffset <= 0 || this.info.ThumbnailSize <= 0)
            {
                return;
            }
            this.info.ThumbnailData = new byte[this.info.ThumbnailSize];
            Array.Copy((Array)section, offsetBase + this.info.ThumbnailOffset, (Array)this.info.ThumbnailData, 0, this.info.ThumbnailSize);
        }
Exemplo n.º 7
0
        private void ProcessExifDir(byte[] section, int offsetDir, int offsetBase, int length, int depth, ExifIFD ifd)
        {
            if (depth > 4)
            {
                return;
            }

            ushort num1 = ExifIo.ReadUShort(section, offsetDir, _isLittleEndian);

            if (offsetDir + 2 + 12 * num1 >= offsetDir + length)
            {
                return;
            }

            for (int num2 = 0; num2 < (int)num1; ++num2)
            {
                int     sectionOffset = DirOffset(offsetDir, num2);
                ExifTag exifTag       = new ExifTag(section, sectionOffset, offsetBase, length, _isLittleEndian);
                if (exifTag.IsValid)
                {
                    switch (exifTag.Tag)
                    {
                    case 34665:
                        int offsetDir1 = offsetBase + exifTag.GetInt(0);
                        if (offsetDir1 <= offsetBase + length)
                        {
                            ProcessExifDir(section, offsetDir1, offsetBase, length, depth + 1, ExifIFD.Exif);
                        }
                        continue;

                    case 34853:
                        int offsetDir2 = offsetBase + exifTag.GetInt(0);
                        if (offsetDir2 <= offsetBase + length)
                        {
                            ProcessExifDir(section, offsetDir2, offsetBase, length, depth + 1, ExifIFD.Gps);
                        }
                        continue;

                    default:
                        exifTag.Populate(Info, ifd);
                        continue;
                    }
                }
            }
            if (DirOffset(offsetDir, num1) + 4 <= offsetBase + length)
            {
                int num2 = ExifIo.ReadInt(section, offsetDir + 2 + 12 * num1, _isLittleEndian);
                if (num2 > 0)
                {
                    int offsetDir1 = offsetBase + num2;
                    if (offsetDir1 <= offsetBase + length && offsetDir1 >= offsetBase)
                    {
                        ProcessExifDir(section, offsetDir1, offsetBase, length, depth + 1, ifd);
                    }
                }
            }
            if (Info.ThumbnailData != null || Info.ThumbnailOffset <= 0 || Info.ThumbnailSize <= 0)
            {
                return;
            }

            Info.ThumbnailData = new byte[Info.ThumbnailSize];
            Array.Copy(section, offsetBase + Info.ThumbnailOffset, Info.ThumbnailData, 0, Info.ThumbnailSize);
        }