示例#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();
            }
        }
示例#2
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);
            }
        }
示例#3
0
        TiffIFD(ref FileMap f, UInt32 offset, UInt32 _depth)
        {
            TIFF_DEPTH(_depth);
            mFile = f;
            ushort[] entries;

            entries = *(ushort*)f.getData(offset, 2);    // Directory entries in this IFD

            for (UInt32 i = 0; i < entries; i++)
            {
                int entry_offset = (int)(offset + 2 + i * 12);

                // If the space for the entry is no longer valid stop reading any more as
                // the file is broken or truncated
                if (!mFile.isValid(entry_offset, 12))
                    break;

                TiffEntry t = null;
                try
                {
                    t = new TiffEntry(f, entry_offset, offset);
                }
                catch (IOException)
                { // Ignore unparsable entry
                    continue;
                }

                switch (t.tag)
                {
                    case DNGPRIVATEDATA:
                        {
                            try
                            {
                                TiffIFD* maker_ifd = parseDngPrivateData(t);
                                mSubIFD.push_back(maker_ifd);
                                delete(t);
                            }
                            catch (TiffParserException)
                            { // Unparsable private data are added as entries
                                mEntry[t.tag] = t;
                            }
                            catch (IOException)
                            { // Unparsable private data are added as entries
                                mEntry[t.tag] = t;
                            }
                        }
                        break;
                    case MAKERNOTE:
                    case MAKERNOTE_ALT:
                        {
                            try
                            {
                                mSubIFD.push_back(parseMakerNote(f, t.getDataOffset(), endian));
                                delete(t);
                            }
                            catch (TiffParserException)
                            { // Unparsable makernotes are added as entries
                                mEntry[t.tag] = t;
                            }
                            catch (IOException)
                            { // Unparsable makernotes are added as entries
                                mEntry[t.tag] = t;
                            }
                        }
                        break;

                    case FUJI_RAW_IFD:
                        if (t.type == 0xd) // FUJI - correct type
                            t.type = TIFF_LONG;
                    case SUBIFDS:
                    case EXIFIFDPOINTER:
                        try
                        {
                            for (UInt32 j = 0; j < t.count; j++)
                            {
                                mSubIFD.push_back(new TiffIFD(f, t.getInt(j), depth));
                            }
                            delete(t);
                        }
                        catch (TiffParserException)
                        { // Unparsable subifds are added as entries
                            mEntry[t.tag] = t;
                        }
                        catch (IOException)
                        { // Unparsable subifds are added as entries
                            mEntry[t.tag] = t;
                        }

                        break;
                    default:
                        mEntry[t.tag] = t;
                }
            }
            nextIFD = *(align1_int*)f.getData(offset + 2 + entries * 12, 4);
        }