Ejemplo n.º 1
0
        private void ReadIfds(IIoStream stream, uint ifdOffset)
        {
            var ptr = ifdOffset;

            while (ptr > 0 && ptr < stream.Length)
            {
                try
                {
                    var ifd    = new ImageFileDirectory(ptr);
                    var buffer = new byte[12];
                    stream.Read(buffer, 2, ptr);
                    var offset = ptr + 2;
                    var size   = _bit.ToInt16(buffer, 0);
                    for (var i = 0; i < size; i++)
                    {
                        var currOffset = offset + i * 12;
                        stream.Read(buffer, 12, currOffset);
                        ifd.AddTag(buffer, _bit, stream);
                    }
                    stream.Read(buffer, 4, offset + size * 12);
                    ptr = _bit.ToUInt32(buffer, 0);
                    if (ifd.Tags.Any())
                    {
                        _ifds.Add(ifd);
                    }
                }
                catch (Exception)
                {
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        private void ReadHeader(IIoStream stream)
        {
            var header = new byte[16];

            stream.Read(header, header.Length, 0);
            if ((char)header[0] == 'I' && (char)header[1] == 'I')
            {
                _bit = new BitConvert(true);
            }
            else if ((char)header[0] == 'M' && (char)header[1] == 'M')
            {
                _bit = new BitConvert(false);
            }
            else
            {
                throw new ImageFormatInvalid();
            }
            if (_bit.ToInt16(header, 0x0002) != 0x002a)
            {
                throw new ImageFormatInvalid();
            }
            _tiffOffset = _bit.ToUInt32(header, 0x0004);
            if ((char)header[0x0008] != 'C' || (char)header[0x0009] != 'R')
            {
                throw new ImageFormatInvalid();
            }
            _cr2Version   = new Version(header[0x000a], header[0x000b]);
            _rawIFDOffset = _bit.ToUInt32(header, 0x000c);
        }
Ejemplo n.º 3
0
        public override bool Resolve(TagInfo info, IIoStream imageStream, BitConvert bit)
        {
            var buffer = new byte[8];

            imageStream.Read(buffer, buffer.Length, info.ValuePointer);
            Value = (decimal)bit.ToInt32(buffer, 0) / (decimal)bit.ToInt32(buffer, 4);
            return(true);
        }
Ejemplo n.º 4
0
        public override bool Resolve(TagInfo info, IIoStream imageStream, BitConvert bit)
        {
            var buffer = new byte[info.Count - 1];

            imageStream.Read(buffer, buffer.Length, info.ValuePointer);
            Value = Encoding.ASCII.GetString(buffer);
            return(true);
        }
Ejemplo n.º 5
0
        public override bool Resolve(TagInfo info, IIoStream imageStream, BitConvert bit)
        {
            var r      = new ushort[info.Count];
            var buffer = new byte[info.Count * 2];

            imageStream.Read(buffer, buffer.Length, info.ValuePointer);
            for (var i = 0; i < info.Count; i++)
            {
                r[i] = bit.ToUInt16(buffer, i * 2);
            }
            Value = r;
            return(true);
        }
Ejemplo n.º 6
0
        private void ReadIfds(IIoStream stream, uint ifdOffset)
        {
            var ptr = ifdOffset;

            while (ptr > 0)
            {
                var ifd = new ImageFileDirectory(ptr);
                _ifds.Add(ifd);
                var buffer = new byte[12];
                stream.Read(buffer, 2, ptr);
                var offset = ptr + 2;
                var size   = _bit.ToInt16(buffer, 0);
                for (var i = 0; i < size; i++)
                {
                    var currOffset = offset + i * 12;
                    stream.Read(buffer, 12, currOffset);
                    ifd.AddTag(buffer, _bit, stream);
                }
                stream.Read(buffer, 4, offset + size * 12);
                ptr = _bit.ToUInt32(buffer, 0);
            }
        }
Ejemplo n.º 7
0
        public override bool Resolve(TagInfo info, IIoStream imageStream, BitConvert bit)
        {
            var buffer = new byte[info.Count - 1];

            imageStream.Read(buffer, buffer.Length, info.ValuePointer);
            var      v = Encoding.ASCII.GetString(buffer);
            DateTime vd;

            if (DateTime.TryParseExact(v, DateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out vd))
            {
                Value = vd;
            }
            return(true);
        }
Ejemplo n.º 8
0
        private void ReadHeader(IIoStream stream)
        {
            var marker = new byte[2];

            stream.Read(marker, marker.Length, 0);
            if (!marker.SequenceEqual(HeaderMarker1))
            {
                throw new ImageFormatInvalid();
            }
            stream.Read(marker, marker.Length, 2);
            while (true)
            {
                if (marker.SequenceEqual(HeaderMarker2))
                {
                    break;
                }
                try
                {
                    stream.Read(marker, marker.Length);
                }
                catch (Exception)
                {
                    throw new ImageFormatInvalid();
                }
            }
            stream.Read(marker, marker.Length);
            var app0 = _bit.ToUInt16(marker, 0);

            var header = new byte[8];

            stream.Read(header, 6);
            var p = stream.Position;

            stream.Read(header, header.Length);
            if ((char)header[0] == 'I' && (char)header[1] == 'I')
            {
                _bit = new BitConvert(true);
            }
            else if ((char)header[0] == 'M' && (char)header[1] == 'M')
            {
                _bit = new BitConvert(false);
            }
            else
            {
                throw new ImageFormatInvalid();
            }
            if (_bit.ToInt16(header, 0x0002) != 0x002a)
            {
                throw new ImageFormatInvalid();
            }
            stream.StartOffset = p;
            _tiffOffset        = _bit.ToUInt32(header, 0x0004);
        }