Beispiel #1
0
        public TiffEntry(ref FileMap f, UInt32 offset, UInt32 up_offset)
        {
            parent_offset = up_offset;
            own_data      = null;
            empty_data    = 0;
            file          = f;
            type          = TiffDataType.TIFF_UNDEFINED; // We set type to undefined to avoid debug assertion errors.

            byte[] temp_data = f.getData(offset, 8);
            tag   = (TiffTag)Common.get4LEget2LE(temp_data, 0);
            type  = (TiffDataType)Common.get4LEget2LE(temp_data, 2);
            count = Common.get4LE(temp_data, 4);

            bytesize = (UInt64)count << (int)Data.datashifts[(int)type];
            if (bytesize > UInt32.MaxValue)
            {
                TiffParserException.ThrowTPE("TIFF entry is supposedly " + bytesize + " bytes");
            }

            if (bytesize == 0) // Better return empty than null-dereference later
            {
                data = (byte8 *)&empty_data;
            }
            else if (bytesize <= 4)
            {
                data = fgetDataWrt(offset + 8, bytesize);
            }
            else
            { // offset
                data_offset = get4LE(f.getData(offset + 8, 4), 0);
                fetchData();
            }
        }
Beispiel #2
0
 void TIFF_DEPTH(uint _depth)
 {
     depth = _depth + 1;
     if ((depth) > 10)
     {
         TiffParserException.ThrowTPE("TIFF: sub-micron matryoshka dolls are ignored");
     }
 }
Beispiel #3
0
 bool isTiffSameAsHost(ref UInt16[] tifftag)
 {
     Endianness host = Common.getHostEndianness();
     if (tifftag[0] == 0x4949)
         return Endianness.little == host;
     if (tifftag[0] == 0x4d4d)
         return Endianness.big == host;
     TiffParserException.ThrowTPE("Unknown Tiff Byteorder :" + tifftag[0]);
     return false;
 }
Beispiel #4
0
        float getFloat(UInt32 num)
        {
            if (!isFloat())
            {
                TiffParserException.ThrowTPE("TIFF, getFloat: Wrong type " + type + " encountered. Expected Float or something convertible on " + tag);
            }

            if (type == TiffDataType.TIFF_DOUBLE)
            {
                if (num * 8 + 7 >= bytesize)
                {
                    TiffParserException.ThrowTPE("TIFF, getFloat: Trying to read out of bounds");
                }
                return((float)get8LE(data, num * 8));
            }
            else if (type == TiffDataType.TIFF_FLOAT)
            {
                if (num * 4 + 3 >= bytesize)
                {
                    TiffParserException.ThrowTPE("TIFF, getFloat: Trying to read out of bounds");
                }
                return((float)get4LE(data, num * 4));
            }
            else if (type == TiffDataType.TIFF_LONG || type == TiffDataType.TIFF_SHORT)
            {
                return((float)getInt(num));
            }
            else if (type == TiffDataType.TIFF_SLONG || type == TiffDataType.TIFF_SSHORT)
            {
                return((float)getSInt(num));
            }
            else if (type == TiffDataType.TIFF_RATIONAL)
            {
                UInt32 a = getInt(num * 2);
                UInt32 b = getInt(num * 2 + 1);
                if (b != 0)
                {
                    return((float)a / b);
                }
            }
            else if (type == TiffDataType.TIFF_SRATIONAL)
            {
                int a = (int)getInt(num * 2);
                int b = (int)getInt(num * 2 + 1);
                if (b != 0)
                {
                    return((float)a / b);
                }
            }
            return(0.0f);
        }
Beispiel #5
0
        Int16 getSShort(UInt32 num)
        {
            if (type != TiffDataType.TIFF_SSHORT && type != TiffDataType.TIFF_UNDEFINED)
            {
                TiffParserException.ThrowTPE("TIFF, getSShort: Wrong type " + type + " encountered. Expected Short or Undefined on " + tag);
            }

            if (num * 2 + 1 >= bytesize)
            {
                TiffParserException.ThrowTPE("TIFF, getSShort: Trying to read out of bounds");
            }

            return((Int16)get2LE(data, num * 2));
        }
Beispiel #6
0
        byte getByte(UInt32 num)
        {
            if (type != TiffDataType.TIFF_BYTE)
            {
                TiffParserException.ThrowTPE("TIFF, getByte: Wrong type " + type + " encountered. Expected Byte on " + tag);
            }

            if (num >= bytesize)
            {
                TiffParserException.ThrowTPE("TIFF, getByte: Trying to read out of bounds");
            }

            return(data[num]);
        }
Beispiel #7
0
        unsafe void setData(void *in_data, UInt32 byte_count)
        {
            UInt32 bytesize = count << (int)Data.datashifts[(int)type];

            if (byte_count > bytesize)
            {
                TiffParserException.ThrowTPE("TIFF, data set larger than entry size given");
            }

            if (own_data == null)
            {
                own_data = new byte[bytesize];
                memcpy(own_data, data, bytesize);
            }
            memcpy(own_data, in_data, byte_count);
        }
Beispiel #8
0
        Int32 getSInt(UInt32 num)
        {
            if (type == TiffDataType.TIFF_SSHORT)
            {
                return(getSShort(num));
            }
            if (!(type == TiffDataType.TIFF_SLONG || type == TiffDataType.TIFF_UNDEFINED))
            {
                TiffParserException.ThrowTPE("TIFF, getSInt: Wrong type " + type + " encountered. Expected SLong or Undefined on " + tag);
            }

            if (num * 4 + 3 >= bytesize)
            {
                TiffParserException.ThrowTPE("TIFF, getSInt: Trying to read out of bounds");
            }

            return(get4LE(data, num * 4));
        }
Beispiel #9
0
        UInt32 getInt(UInt32 num)
        {
            if (type == TiffDataType.TIFF_SHORT)
            {
                return(getShort(num));
            }
            if (!(type == TiffDataType.TIFF_LONG || type == TiffDataType.TIFF_OFFSET || type == TiffDataType.TIFF_BYTE || type == TiffDataType.TIFF_UNDEFINED ||
                  type == TiffDataType.TIFF_RATIONAL || type == TiffDataType.TIFF_SRATIONAL))
            {
                TiffParserException.ThrowTPE("TIFF, getInt: Wrong type " + type + " encountered. Expected Long, Offset, Rational or Undefined on " + tag);
            }

            if (num * 4 + 3 >= bytesize)
            {
                TiffParserException.ThrowTPE("TIFF, getInt: Trying to read out of bounds");
            }

            return(get4LE(data, num * 4));
        }
Beispiel #10
0
        unsafe string getString()
        {
            if (type != TiffDataType.TIFF_ASCII && type != TiffDataType.TIFF_BYTE)
            {
                TiffParserException.ThrowTPE("TIFF, getString: Wrong type " + type + " encountered. Expected Ascii or Byte");
            }

            if (count == 0)
            {
                return("");
            }

            if (own_data == null)
            {
                own_data = new byte[count];
                memcpy(own_data, data, count);
                own_data[count - 1] = 0;  // Ensure string is not larger than count defines
            }
            return(new String((char *)own_data[0]));
        }
Beispiel #11
0
        TiffEntryBE(ref FileMap f, UInt32 offset, UInt32 up_offset)
        {
            parent_offset = up_offset;
            own_data      = null;
            empty_data    = 0;
            file          = f;
            type          = TiffDataType.TIFF_UNDEFINED; // We set type to undefined to avoid debug assertion errors.

            byte[] temp_data = f.getData(offset, 8);
            tag   = (TiffTag)get2BE(temp_data, 0);
            type  = (TiffDataType)get2BE(temp_data, 2);
            count = get4BE(temp_data, 4);

            if ((int)type > 13)
            {
                TiffParserException.ThrowTPE("Error reading TIFF structure. Unknown Type " + type + " encountered.");
            }

            bytesize = (UInt64)count << (int)Data.datashifts[(int)type];
            if (bytesize > UInt32.MaxValue)
            {
                TiffParserException.ThrowTPE("TIFF entry is supposedly " + bytesize + " bytes");
            }

            if (bytesize == 0) // Better return empty than null-dereference later
            {
                data = empty_data;
            }
            else if (bytesize <= 4)
            {
                data = f.getDataWrt(offset + 8, bytesize);
            }
            else
            { // offset
                data_offset = get4BE(f.getData(offset + 8, 4), 0);
                data        = f.getDataWrt(data_offset, bytesize);
            }
        }