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 $
4
4
* Project: RPF A.TOC read Library
5
5
* Purpose: Module responsible for opening a RPF TOC file, populating RPFToc
101
101
CPLError( CE_Failure, CPLE_NotSupported,
102
"Not enough bytes in RPFHDR." );
106
int nRemainingBytes = psFile->nTREBytes - (pachTRE - psFile->pachTRE);
107
if (nRemainingBytes < 48)
109
CPLError(CE_Failure, CPLE_AppDefined,
110
"Cannot read RPFHDR TRE. Not enough bytes");
102
"RPFHDR TRE wrong size." );
118
110
/* This function is directly inspired by function parse_toc coming from ogdi/driver/rpf/utils.c */
120
RPFToc* RPFTOCReadFromBuffer(const char* pszFilename, FILE* fp, const char* tocHeader)
112
RPFToc* RPFTOCReadFromBuffer(const char* pszFilename, VSILFILE* fp, const char* tocHeader)
123
115
unsigned int locationSectionPhysicalLocation;
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;
118
unsigned int boundaryRectangleSectionSubHeaderPhysIndex = 0;
119
unsigned int boundaryRectangleTablePhysIndex = 0;
120
unsigned int frameFileIndexSectionSubHeaderPhysIndex = 0;
121
unsigned int frameFileIndexSubsectionPhysIndex = 0;
131
123
unsigned int boundaryRectangleTableOffset;
132
124
unsigned short boundaryRectangleCount;
164
/* Skip location section length (4) and component location table offset (2)*/
165
VSIFSeekL( fp, 4 + 2, SEEK_CUR);
167
/* How many sections: # of section location records */
168
VSIFReadL( &nSections, 1, sizeof(nSections), fp);
169
CPL_MSBPTR16( &nSections );
171
/* Skip location record length(2) + component aggregate length(4) */
172
VSIFSeekL( fp, 2 + 4, SEEK_CUR);
156
NITFLocation* pasLocations = NITFReadRPFLocationTable(fp, &nSections);
174
158
for (i = 0; i < nSections; i++)
177
unsigned int sectionLength, physIndex;
178
VSIFReadL( &id, 1, sizeof(id), fp);
181
VSIFReadL( §ionLength, 1, sizeof(sectionLength), fp);
182
CPL_MSBPTR32( §ionLength );
184
VSIFReadL( &physIndex, 1, sizeof(physIndex), fp);
185
CPL_MSBPTR32( &physIndex );
187
if (id == LID_BoundaryRectangleSectionSubheader)
189
boundaryRectangleSectionSubHeaderPhysIndex = physIndex;
190
boundaryRectangleSectionSubHeaderLength = sectionLength;
192
else if (id == LID_BoundaryRectangleTable)
194
boundaryRectangleTablePhysIndex = physIndex;
195
boundaryRectangleTableLength = sectionLength;
197
else if (id == LID_FrameFileIndexSectionSubHeader)
199
frameFileIndexSectionSubHeaderPhysIndex = physIndex;
200
frameFileIndexSectionSubHeaderLength = sectionLength;
202
else if (id == LID_FrameFileIndexSubsection)
204
frameFileIndexSubsectionPhysIndex = physIndex;
205
frameFileIndexSubsectionLength = sectionLength;
160
if (pasLocations[i].nLocId == LID_BoundaryRectangleSectionSubheader)
162
boundaryRectangleSectionSubHeaderPhysIndex = pasLocations[i].nLocOffset;
164
else if (pasLocations[i].nLocId == LID_BoundaryRectangleTable)
166
boundaryRectangleTablePhysIndex = pasLocations[i].nLocOffset;
168
else if (pasLocations[i].nLocId == LID_FrameFileIndexSectionSubHeader)
170
frameFileIndexSectionSubHeaderPhysIndex = pasLocations[i].nLocOffset;
172
else if (pasLocations[i].nLocId == LID_FrameFileIndexSubsection)
174
frameFileIndexSubsectionPhysIndex = pasLocations[i].nLocOffset;
178
CPLFree(pasLocations);
209
180
if (boundaryRectangleSectionSubHeaderPhysIndex == 0)
452
423
if (frameEntry->exists)
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);
428
CPLFree(frameEntry->directory);
429
frameEntry->directory = NULL;
430
CPLFree(frameEntry->fullFilePath);
431
frameEntry->fullFilePath = NULL;
432
frameEntry->exists = 0;
461
435
VSIFReadL( &offsetFrameFilePathName, 1, sizeof(offsetFrameFilePathName), fp);