Exemplo n.º 1
0
        /// <summary>
        /// Calculates the floating point value of this IFD.
        /// </summary>
        /// <returns>The value of this IFD as a float.</returns>
        public double AsDecimal()
        {
            int numerator   = TIFFHeader.ToInt32(Buffer, OffsetToValue, IsLittleEndian);
            int denominator = TIFFHeader.ToInt32(Buffer, OffsetToValue + 4, IsLittleEndian);

            return(Exif.Rational(numerator, denominator));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns the number of times the shutter has opened on the camera.
        /// </summary>
        /// <returns>The number of times the camera's shutter has opened.</returns>
        public int ShutterCount()
        {
            // See if we can pull the data from a makernote.

            string make = Make().ToLowerInvariant();

            if (make.Contains("nikon") == true && ExifIFD != null)
            {
                // Find the maker note...

                var maker_note_field = ExifIFD.GetTag(MakerNote);

                if (maker_note_field != null)
                {
                    byte[] maker_note_buffer = new byte[maker_note_field.Count - 10];

                    Array.Copy(TIFFData, maker_note_field.OffsetToValue + 10, maker_note_buffer, 0, maker_note_field.Count - 10);

                    var tiff_header = new TIFFHeader();

                    if (tiff_header.FromBytes(maker_note_buffer, 0) == true)
                    {
                        var maker_note = new ImageFileDirectory();

                        if (maker_note.FromBytes(maker_note_buffer, tiff_header.OffsetToZerothIFD, tiff_header.LittleEndian) == true)
                        {
                            return(IntegerValue(maker_note, Exif_MakerNote_Nikon3_ShutterCount));
                        }
                    }
                }
            }

            return(0);
        }
Exemplo n.º 3
0
 /// <summary>
 /// The default constructor.
 /// </summary>
 public Exif()
 {
     Header = new TIFFHeader();
     IFD0   = new ImageFileDirectory();
     IFD0.InitializeIFD0TagNames();
     ExifIFD  = null;
     GPSIFD   = null;
     TIFFData = null;
 }
Exemplo n.º 4
0
        public string SerialNumber()
        {
            string return_value = StringValue(Exif_Photo_BodySerialNumber);

            if (string.IsNullOrEmpty(return_value) == false)
            {
                return(return_value);
            }

            // See if we can pull the data from a makernote.

            string make = Make().ToLowerInvariant();

            if (make.Contains("nikon") == true && ExifIFD != null)
            {
                // Find the maker note...

                InteroperabilityField maker_note_field = ExifIFD.GetTag(MakerNote);

                if (maker_note_field != null)
                {
                    byte[] maker_note_buffer = new byte[maker_note_field.Count - 10];

                    Array.Copy(TIFFData, maker_note_field.OffsetToValue + 10, maker_note_buffer, 0, maker_note_field.Count - 10);

                    TIFFHeader th = new TIFFHeader();

                    if (th.FromBytes(maker_note_buffer, 0) == true)
                    {
                        ImageFileDirectory maker_note = new ImageFileDirectory();

                        if (maker_note.FromBytes(maker_note_buffer, th.OffsetToZerothIFD, th.LittleEndian) == true)
                        {
                            // Now read from the Maker Note Buffer!

                            return_value = StringValue(maker_note, Exif_MakerNote_Nikon3_SerialNumber, maker_note_buffer);

                            if (string.IsNullOrEmpty(return_value) == true)
                            {
                                return_value = StringValue(maker_note, Exif_MakerNote_Nikon3_SerialNO, maker_note_buffer);

                                if (return_value.StartsWith("NO=") == true)
                                {
                                    return(return_value.Substring(3, return_value.Length - 3).Trim());
                                }
                            }
                        }
                    }

                    return(return_value);
                }
            }

            return(string.Empty);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Parses the bytes specified as an InteroperabilityField.
        /// </summary>
        /// <param name="buffer">The buffer containing the data.</param>
        /// <param name="offset">The offset into the buffer to begin parsing.</param>
        /// <param name="little_endian">When true, integers are in little endian format, when false integers are in big endian format.</param>
        /// <returns>An InteroperabilityField object.</returns>
        public static InteroperabilityField FromBytes(byte[] buffer, int offset, bool little_endian)
        {
            var return_value = new InteroperabilityField();

            return_value.IsLittleEndian = little_endian;
            return_value.Tag            = TIFFHeader.ToUInt16(buffer, offset, little_endian);
            return_value.Type           = TIFFHeader.ToUInt16(buffer, offset + 2, little_endian);
            return_value.Count          = TIFFHeader.ToInt32(buffer, offset + 4, little_endian);
            return_value.OffsetToValue  = TIFFHeader.ToInt32(buffer, offset + 8, little_endian);

            return_value.Byte0 = buffer[offset + 8];
            return_value.Byte1 = buffer[offset + 9];
            return_value.Byte2 = buffer[offset + 10];
            return_value.Byte3 = buffer[offset + 11];

            return_value.Buffer = buffer;

            return(return_value);
        }
Exemplo n.º 6
0
        public double DecimalValue(ImageFileDirectory ifd, int tag, byte[] buffer)
        {
            if (buffer == null || ifd == null)
            {
                return(0.0D);
            }

            var field = ifd.GetTag(tag);

            if (field == null || field.Type != 5)
            {
                return(0.0D);
            }

            int numerator   = TIFFHeader.ToInt32(buffer, field.OffsetToValue, Header.LittleEndian);
            int denominator = TIFFHeader.ToInt32(buffer, field.OffsetToValue + 4, Header.LittleEndian);

            double return_value = Rational(numerator, denominator);

            return(return_value);
        }
Exemplo n.º 7
0
        public bool GPSTime(ImageFileDirectory ifd, int tag, out double hours, out double minutes, out double seconds)
        {
            hours   = 0.0D;
            minutes = 0.0D;
            seconds = 0.0D;

            if (TIFFData == null || ifd == null)
            {
                return(false);
            }

            var field = ifd.GetTag(tag);

            if (field == null || field.Type != 5)
            {
                return(false);
            }

            if (field.Count < 3)
            {
                return(false);
            }

            int[] integer_array = new int[field.Count * 2]; // Rationals are two integers each

            int array_index = 0;

            while (array_index < integer_array.Length)
            {
                integer_array[array_index] = TIFFHeader.ToInt32(TIFFData, field.OffsetToValue + (array_index * 4), Header.LittleEndian);
                array_index++;
            }

            hours   = Rational(integer_array[0], integer_array[1]);
            minutes = Rational(integer_array[2], integer_array[3]);
            seconds = Rational(integer_array[4], integer_array[5]);

            return(true);
        }
Exemplo n.º 8
0
        public bool FromBytes(byte[] buffer, int offset, bool little_endian)
        {
            Empty();

            if (buffer == null || offset < 0 || buffer.Length < 6)
            {
                return(false);
            }

            int number_of_entries = TIFFHeader.ToUInt16(buffer, offset, little_endian);

            if (number_of_entries > 5460) // 5461 entries in 64KB buffer
            {
                return(false);
            }

            Fields = new InteroperabilityField[number_of_entries];

            string tag_name = string.Empty;

            int entry_index = 0;

            while (entry_index < number_of_entries)
            {
                Fields[entry_index] = InteroperabilityField.FromBytes(buffer, offset + 2 + (entry_index * 12), little_endian);

                if (TagNames != null && TagNames.TryGetValue(Fields[entry_index].Tag, out tag_name) == true)
                {
                    Fields[entry_index].TagName = tag_name;
                }

                entry_index++;
            }

            NextOffset = TIFFHeader.ToInt32(buffer, offset + 2 + (number_of_entries * 12), little_endian);

            return(true);
        }
Exemplo n.º 9
0
        public double DegreesValue(ImageFileDirectory ifd, int tag)
        {
            if (TIFFData == null || ifd == null)
            {
                return(0.0D);
            }

            InteroperabilityField field = ifd.GetTag(tag);

            if (field == null || (field.Type != 5 && field.Type != 10))
            {
                return(0.0D);
            }

            if (field.Count < 3)
            {
                return(0.0D);
            }

            int[] integer_array = new int[field.Count * 2]; // Rationals are two integers each

            int array_index = 0;

            while (array_index < integer_array.Length)
            {
                integer_array[array_index] = TIFFHeader.ToInt32(TIFFData, field.OffsetToValue + (array_index * 4), Header.LittleEndian);
                array_index++;
            }

            double degrees = Rational(integer_array[0], integer_array[1]);
            double minutes = Rational(integer_array[2], integer_array[3]);
            double seconds = Rational(integer_array[4], integer_array[5]);

            double return_value = ConvertDegreesMinutesSecondsCoordinateToDecimalDegrees(degrees, minutes, seconds);

            return(return_value);
        }