~ubuntu-branches/debian/sid/gdal/sid

« back to all changes in this revision

Viewing changes to frmts/nitf/rpftocfile.cpp

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2012-05-07 15:04:42 UTC
  • mfrom: (5.5.16 experimental)
  • Revision ID: package-import@ubuntu.com-20120507150442-2eks97loeh6rq005
Tags: 1.9.0-1
* Ready for sid, starting transition.
* All symfiles updated to latest builds.
* Added dh_numpy call in debian/rules to depend on numpy ABI.
* Policy bumped to 3.9.3, no changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/******************************************************************************
2
 
 * $Id: rpftocfile.cpp 17617 2009-09-07 19:14:46Z rouault $
 
2
 * $Id: rpftocfile.cpp 20996 2010-10-28 18:38:15Z rouault $
3
3
 *
4
4
 * Project:  RPF A.TOC read Library
5
5
 * Purpose:  Module responsible for opening a RPF TOC file, populating RPFToc
49
49
#include "cpl_conv.h"
50
50
#include "cpl_string.h"
51
51
 
52
 
CPL_CVSID("$Id: rpftocfile.cpp 17617 2009-09-07 19:14:46Z rouault $");
 
52
CPL_CVSID("$Id: rpftocfile.cpp 20996 2010-10-28 18:38:15Z rouault $");
53
53
 
54
54
/************************************************************************/
55
55
/*                        RPFTOCTrim()                                    */
86
86
 
87
87
RPFToc* RPFTOCRead(const char* pszFilename, NITFFile* psFile)
88
88
{
89
 
    int TRESize;
 
89
    int nTRESize;
90
90
    const char* pachTRE = NITFFindTRE( psFile->pachTRE, psFile->nTREBytes, 
91
 
                           "RPFHDR", &TRESize );
 
91
                           "RPFHDR", &nTRESize );
92
92
    if (pachTRE == NULL)
93
93
    {
94
94
        CPLError( CE_Failure, CPLE_NotSupported, 
96
96
        return NULL;
97
97
    }
98
98
 
99
 
    if (TRESize < 48)
 
99
    if (nTRESize != 48)
100
100
    {
101
101
        CPLError( CE_Failure, CPLE_NotSupported, 
102
 
                  "Not enough bytes in RPFHDR." );
103
 
        return NULL;
104
 
    }
105
 
 
106
 
    int nRemainingBytes = psFile->nTREBytes - (pachTRE - psFile->pachTRE);
107
 
    if (nRemainingBytes < 48)
108
 
    {
109
 
        CPLError(CE_Failure, CPLE_AppDefined,
110
 
                "Cannot read RPFHDR TRE. Not enough bytes");
 
102
                  "RPFHDR TRE wrong size." );
111
103
        return NULL;
112
104
    }
113
105
 
117
109
 
118
110
/* This function is directly inspired by function parse_toc coming from ogdi/driver/rpf/utils.c */
119
111
 
120
 
RPFToc* RPFTOCReadFromBuffer(const char* pszFilename, FILE* fp, const char* tocHeader)
 
112
RPFToc* RPFTOCReadFromBuffer(const char* pszFilename, VSILFILE* fp, const char* tocHeader)
121
113
{
122
114
    int i, j;
123
115
    unsigned int locationSectionPhysicalLocation;
124
116
    
125
 
    unsigned short nSections;
126
 
    unsigned int boundaryRectangleSectionSubHeaderPhysIndex = 0, boundaryRectangleSectionSubHeaderLength = 0;
127
 
    unsigned int boundaryRectangleTablePhysIndex = 0, boundaryRectangleTableLength = 0;
128
 
    unsigned int frameFileIndexSectionSubHeaderPhysIndex = 0, frameFileIndexSectionSubHeaderLength = 0;
129
 
    unsigned int frameFileIndexSubsectionPhysIndex = 0, frameFileIndexSubsectionLength = 0;
 
117
    int nSections;
 
118
    unsigned int boundaryRectangleSectionSubHeaderPhysIndex = 0;
 
119
    unsigned int boundaryRectangleTablePhysIndex = 0;
 
120
    unsigned int frameFileIndexSectionSubHeaderPhysIndex = 0;
 
121
    unsigned int frameFileIndexSubsectionPhysIndex = 0;
130
122
    
131
123
    unsigned int boundaryRectangleTableOffset;
132
124
    unsigned short boundaryRectangleCount;
161
153
        return NULL;
162
154
    }
163
155
    
164
 
    /* Skip location section length (4) and component location table offset (2)*/
165
 
    VSIFSeekL( fp, 4 + 2, SEEK_CUR);
166
 
    
167
 
    /* How many sections: # of section location records */
168
 
    VSIFReadL( &nSections, 1, sizeof(nSections), fp);
169
 
    CPL_MSBPTR16( &nSections );
170
 
    
171
 
    /* Skip location record length(2) + component aggregate length(4) */
172
 
    VSIFSeekL( fp, 2 + 4, SEEK_CUR);
 
156
    NITFLocation* pasLocations = NITFReadRPFLocationTable(fp, &nSections);
173
157
    
174
158
    for (i = 0; i < nSections; i++)
175
159
    {
176
 
        unsigned short id;
177
 
        unsigned int sectionLength, physIndex;
178
 
        VSIFReadL( &id, 1, sizeof(id), fp);
179
 
        CPL_MSBPTR16( &id );
180
 
        
181
 
        VSIFReadL( &sectionLength, 1, sizeof(sectionLength), fp);
182
 
        CPL_MSBPTR32( &sectionLength );
183
 
        
184
 
        VSIFReadL( &physIndex, 1, sizeof(physIndex), fp);
185
 
        CPL_MSBPTR32( &physIndex );
186
 
        
187
 
        if (id == LID_BoundaryRectangleSectionSubheader)
188
 
        {
189
 
            boundaryRectangleSectionSubHeaderPhysIndex = physIndex;
190
 
            boundaryRectangleSectionSubHeaderLength = sectionLength;
191
 
        }
192
 
        else if (id == LID_BoundaryRectangleTable)
193
 
        {
194
 
            boundaryRectangleTablePhysIndex = physIndex;
195
 
            boundaryRectangleTableLength = sectionLength;
196
 
        }
197
 
        else if (id == LID_FrameFileIndexSectionSubHeader)
198
 
        {
199
 
            frameFileIndexSectionSubHeaderPhysIndex = physIndex;
200
 
            frameFileIndexSectionSubHeaderLength = sectionLength;
201
 
        }
202
 
        else if (id == LID_FrameFileIndexSubsection)
203
 
        {
204
 
            frameFileIndexSubsectionPhysIndex = physIndex;
205
 
            frameFileIndexSubsectionLength = sectionLength;
 
160
        if (pasLocations[i].nLocId == LID_BoundaryRectangleSectionSubheader)
 
161
        {
 
162
            boundaryRectangleSectionSubHeaderPhysIndex = pasLocations[i].nLocOffset;
 
163
        }
 
164
        else if (pasLocations[i].nLocId == LID_BoundaryRectangleTable)
 
165
        {
 
166
            boundaryRectangleTablePhysIndex = pasLocations[i].nLocOffset;
 
167
        }
 
168
        else if (pasLocations[i].nLocId == LID_FrameFileIndexSectionSubHeader)
 
169
        {
 
170
            frameFileIndexSectionSubHeaderPhysIndex = pasLocations[i].nLocOffset;
 
171
        }
 
172
        else if (pasLocations[i].nLocId == LID_FrameFileIndexSubsection)
 
173
        {
 
174
            frameFileIndexSubsectionPhysIndex = pasLocations[i].nLocOffset;
206
175
        }
207
176
    }
 
177
 
 
178
    CPLFree(pasLocations);
208
179
    
209
180
    if (boundaryRectangleSectionSubHeaderPhysIndex == 0)
210
181
    {
451
422
 
452
423
        if (frameEntry->exists)
453
424
        {
454
 
            CPLError( CE_Failure, CPLE_NotSupported, 
455
 
                      "Invalid TOC file. Frame entry(%d,%d) for frame file index %d is a duplicate.",
 
425
            CPLError( CE_Warning, CPLE_AppDefined, 
 
426
                      "Frame entry(%d,%d) for frame file index %d was already found.",
456
427
                      frameRow, frameCol, i);
457
 
            RPFTOCFree(toc);
458
 
            return NULL;
 
428
            CPLFree(frameEntry->directory);
 
429
            frameEntry->directory = NULL;
 
430
            CPLFree(frameEntry->fullFilePath);
 
431
            frameEntry->fullFilePath = NULL;
 
432
            frameEntry->exists = 0;
459
433
        }
460
434
        
461
435
        VSIFReadL( &offsetFrameFilePathName, 1, sizeof(offsetFrameFilePathName), fp);