Example #1
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);
            }
Example #2
0
        private int _GetSize()
        {
            int _size = 0;

            for (Tiff.Ifd _idf = this.ImageFileDirectory; _idf != null; _idf = _idf.NextIfd)
            {
                if (_idf.Offset + _idf.Size > _size)
                {
                    _size = _idf.Offset + _idf.Size;
                }

                Tiff.IfdEntry _stripOffsetsTag = null, _stripByteCountsTag = null;
                Tiff.IfdEntry _freeOffsets = null, _freeByteCounts = null;
                Tiff.IfdEntry _tileOffsets = null, _tileByteCounts = null;
                foreach (IfdEntry _entry in _idf)
                {
                    if (_entry.DataOffset + _entry.DataSize > _size)
                    {
                        _size = _entry.DataOffset + _entry.DataSize;
                    }
                    switch (_entry.Tag)
                    {
                    case TiffTags.STRIPOFFSETS:
                        _stripOffsetsTag = _entry;
                        break;

                    case TiffTags.STRIPBYTECOUNTS:
                        _stripByteCountsTag = _entry;
                        break;

                    case TiffTags.FREEOFFSETS:
                        _freeOffsets = _entry;
                        break;

                    case TiffTags.FREEBYTECOUNTS:
                        _freeByteCounts = _entry;
                        break;

                    case TiffTags.TILEOFFSETS:
                        _tileOffsets = _entry;
                        break;

                    case TiffTags.TILEBYTECOUNTS:
                        _tileByteCounts = _entry;
                        break;
                    }
                }
                foreach (IfdEntry[] _item in new Tiff.IfdEntry[][] { new[] { _stripOffsetsTag, _stripByteCountsTag }, new[] { _freeOffsets, _freeByteCounts }, new[] { _tileOffsets, _tileByteCounts } })
                {
                    if (_item[0] != null && _item[1] != null && _item[0].Length == _item[1].Length)
                    {
                        for (int i = 0; i < _item[0].Length; i++)
                        {
                            int _dataOffset = Convert.ToInt32(_item[0][i]);
                            int _dataSize   = Convert.ToInt32(_item[1][i]);
                            if (_dataOffset + _dataSize > _size)
                            {
                                _size = _dataOffset + _dataSize;
                            }
                        }
                    }
                }
            }
            return(_size);
        }