예제 #1
0
        public override ITag ReadTag()
        {
            if (this._position != -1)
            {
                this.Context.Reader.BaseStream.Seek(this._position, SeekOrigin.Begin);
            }
            if (this.Context.TagCountLeft == 0)
            {
                this._position = -1;
                this.Context.NextImageFileDirectory = Helper.Read <uint>(this.Context.Reader.BaseStream);
                this.FireEvent(TagState.ToNextIfd);
                return(null);
            }
            this.Context.ValueCountLeft = (int)(this.Context.CurrentTag = Helper.Read <TiffDirEntry>(this.Context.Reader.BaseStream)).count;
            this.Context.TagCountLeft--;

            this._position = this.Context.Reader.BaseStream.Position;
            int _itemSize = TiffDataTypeHelper.Sizeof(this.Context.CurrentTag.type);

            if (_itemSize * this.Context.CurrentTag.count > 4)
            {
                // Массив значений
                this.Context.Reader.BaseStream.Seek(this.Context.CurrentTag.offset, SeekOrigin.Begin);
            }
            else
            {
                // Массив, вписанный в поле offset
                this.Context.Reader.BaseStream.Seek(Marshal.OffsetOf(typeof(TiffDirEntry), "offset").ToInt64() - Marshal.SizeOf(typeof(TiffDirEntry)), SeekOrigin.Current);
            }

            this.FireEvent(TagState.ToValue);
            return(this.Context.CurrentTag);
        }
예제 #2
0
            public static Tiff.IfdEntry FromPtr(IntPtr ptr, IntPtr baseAddr)
            {
                TiffDirEntry _entry = (TiffDirEntry)Marshal.PtrToStructure(ptr, typeof(TiffDirEntry));

                Tiff.IfdEntry _ifdEntry = new Tiff.IfdEntry {
                    Tag      = _entry.tag,
                    DataType = _entry.type,
                    _data    = Array.CreateInstance(TiffDataTypeHelper.Typeof(_entry.type), _entry.count <= int.MaxValue?_entry.count:0)
                };

                IntPtr _dataPtr = (IntPtr)(((_ifdEntry.DataSize = (int)(TiffDataTypeHelper.Sizeof(_entry.type) * _ifdEntry._data.Length)) > 4)?baseAddr.ToInt64() + _entry.offset:ptr.ToInt64() + 8);

                _ifdEntry.DataOffset = (int)(_dataPtr.ToInt64() - baseAddr.ToInt64());
                for (int i = 0, _size = TiffDataTypeHelper.Sizeof(_entry.type); i < _ifdEntry._data.Length; i++)
                {
                    _ifdEntry._data.SetValue(Marshal.PtrToStructure((IntPtr)(_dataPtr.ToInt64() + _size * i), TiffDataTypeHelper.Typeof(_entry.type)), i);
                }

                return(_ifdEntry);
            }