Exemple #1
0
        public double CompassDirection()
        {
            if (GPSIFD == null)
            {
                return(0.0D);
            }

            InteroperabilityField field = GPSIFD.GetTag(Exif_GPS_Image_Direction);

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

            if (field.Count == 3)
            {
                double degrees = 0.0D;
                double minutes = 0.0D;
                double seconds = 0.0D;

                GPSTime(GPSIFD, Exif_GPS_Image_Direction, out degrees, out minutes, out seconds);

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

                if (return_value >= 360.0D)
                {
                    return_value = 0.0D;
                }

                return(return_value);
            }

            return(DecimalValue(GPSIFD, Exif_GPS_Image_Direction));
        }
Exemple #2
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);
        }
Exemple #3
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);
        }
Exemple #4
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);
        }
Exemple #5
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);
        }