| 2098 | | #ifdef notdef |
|---|
| 2099 | | /* -------------------------------------------------------------------- */ |
|---|
| 2100 | | /* Get the location table position from within the RPFHDR TRE */ |
|---|
| 2101 | | /* structure. */ |
|---|
| 2102 | | /* */ |
|---|
| 2103 | | /* This is the old approach, but since some RPFHDR segments are */ |
|---|
| 2104 | | /* written wrong, it is not very stable. See bug */ |
|---|
| 2105 | | /* http://bugzilla.remotesensing.org/show_bug.cgi?id=1313 */ |
|---|
| 2106 | | /* -------------------------------------------------------------------- */ |
|---|
| 2107 | | GUInt32 nLocTableOffset; |
|---|
| 2108 | | GUInt16 nLocCount; |
|---|
| 2109 | | int iLoc; |
|---|
| 2110 | | const char *pszTRE; |
|---|
| 2111 | | |
|---|
| 2112 | | pszTRE= NITFFindTRE( psFile->pachTRE, psFile->nTREBytes, "RPFHDR", NULL ); |
|---|
| 2113 | | if( pszTRE == NULL ) |
|---|
| 2114 | | return; |
|---|
| 2115 | | |
|---|
| 2116 | | memcpy( &nLocTableOffset, pszTRE + 44, 4 ); |
|---|
| 2117 | | nLocTableOffset = CPL_MSBWORD32( nLocTableOffset ); |
|---|
| 2118 | | |
|---|
| 2119 | | if( nLocTableOffset == 0 ) |
|---|
| 2120 | | return; |
|---|
| 2121 | | |
|---|
| 2122 | | /* -------------------------------------------------------------------- */ |
|---|
| 2123 | | /* Read the count of entries in the location table. */ |
|---|
| 2124 | | /* -------------------------------------------------------------------- */ |
|---|
| 2125 | | VSIFSeekL( psFile->fp, nLocTableOffset + 6, SEEK_SET ); |
|---|
| 2126 | | VSIFReadL( &nLocCount, 1, 2, psFile->fp ); |
|---|
| 2127 | | nLocCount = CPL_MSBWORD16( nLocCount ); |
|---|
| 2128 | | psFile->nLocCount = nLocCount; |
|---|
| 2129 | | |
|---|
| 2130 | | psFile->pasLocations = (NITFLocation *) |
|---|
| 2131 | | CPLCalloc(sizeof(NITFLocation), nLocCount); |
|---|
| 2132 | | #endif |
|---|
| 2133 | | |
|---|
| 2179 | | /* It seems that sometimes (at least for bug 1313) all the */ |
|---|
| 2180 | | /* locations in the location table are off by a fixed amount. */ |
|---|
| 2181 | | /* We can establish that amount by checking if the RPFHDR TRE */ |
|---|
| 2182 | | /* is at the location indicated in the location table. If not, */ |
|---|
| 2183 | | /* offset all locations by the difference. */ |
|---|
| | 2143 | /* It seems that sometimes (at least for bug #1313 and #1714) */ |
|---|
| | 2144 | /* the RPF headers are improperly placed. We check by looking */ |
|---|
| | 2145 | /* to see if the RPFHDR is where it should be. If not, we */ |
|---|
| | 2146 | /* disregard the location table. */ |
|---|
| | 2147 | /* */ |
|---|
| | 2148 | /* The NITF21_CGM_ANNO_Uncompressed_unmasked.ntf sample data */ |
|---|
| | 2149 | /* file (see gdal data downloads) is an example of this. */ |
|---|
| 2204 | | int nOffset = 0; |
|---|
| 2205 | | |
|---|
| 2206 | | for( i = 1; i < sizeof(achHeaderChunk)-6; i++ ) |
|---|
| 2207 | | { |
|---|
| 2208 | | if( EQUALN(achHeaderChunk+i,"RPFHDR",6) ) |
|---|
| 2209 | | { |
|---|
| 2210 | | nOffset = i; |
|---|
| 2211 | | break; |
|---|
| 2212 | | } |
|---|
| 2213 | | } |
|---|
| 2214 | | |
|---|
| 2215 | | if( nOffset != 0 ) |
|---|
| 2216 | | { |
|---|
| 2217 | | CPLDebug( "NITF", |
|---|
| 2218 | | "Location table offsets off by %d bytes, adjusting accordingly.", |
|---|
| 2219 | | nOffset ); |
|---|
| 2220 | | |
|---|
| 2221 | | for( i = 0; i < psImage->nLocCount; i++ ) |
|---|
| 2222 | | { |
|---|
| 2223 | | psImage->pasLocations[i].nLocOffset += nOffset; |
|---|
| 2224 | | } |
|---|
| 2225 | | } |
|---|
| | 2170 | CPLError( CE_Warning, CPLE_AppDefined, |
|---|
| | 2171 | "Ignoring NITF RPF Location table since it seems to be corrupt." ); |
|---|
| | 2172 | CPLFree( psImage->pasLocations ); |
|---|
| | 2173 | psImage->pasLocations = NULL; |
|---|
| | 2174 | psImage->nLocCount = 0; |
|---|