| 2009 | | #ifdef notdef |
|---|
| 2010 | | /* -------------------------------------------------------------------- */ |
|---|
| 2011 | | /* Get the location table position from within the RPFHDR TRE */ |
|---|
| 2012 | | /* structure. */ |
|---|
| 2013 | | /* */ |
|---|
| 2014 | | /* This is the old approach, but since some RPFHDR segments are */ |
|---|
| 2015 | | /* written wrong, it is not very stable. See bug */ |
|---|
| 2016 | | /* http://bugzilla.remotesensing.org/show_bug.cgi?id=1313 */ |
|---|
| 2017 | | /* -------------------------------------------------------------------- */ |
|---|
| 2018 | | GUInt32 nLocTableOffset; |
|---|
| 2019 | | GUInt16 nLocCount; |
|---|
| 2020 | | int iLoc; |
|---|
| 2021 | | const char *pszTRE; |
|---|
| 2022 | | |
|---|
| 2023 | | pszTRE= NITFFindTRE( psFile->pachTRE, psFile->nTREBytes, "RPFHDR", NULL ); |
|---|
| 2024 | | if( pszTRE == NULL ) |
|---|
| 2025 | | return; |
|---|
| 2026 | | |
|---|
| 2027 | | memcpy( &nLocTableOffset, pszTRE + 44, 4 ); |
|---|
| 2028 | | nLocTableOffset = CPL_MSBWORD32( nLocTableOffset ); |
|---|
| 2029 | | |
|---|
| 2030 | | if( nLocTableOffset == 0 ) |
|---|
| 2031 | | return; |
|---|
| 2032 | | |
|---|
| 2033 | | /* -------------------------------------------------------------------- */ |
|---|
| 2034 | | /* Read the count of entries in the location table. */ |
|---|
| 2035 | | /* -------------------------------------------------------------------- */ |
|---|
| 2036 | | VSIFSeekL( psFile->fp, nLocTableOffset + 6, SEEK_SET ); |
|---|
| 2037 | | VSIFReadL( &nLocCount, 1, 2, psFile->fp ); |
|---|
| 2038 | | nLocCount = CPL_MSBWORD16( nLocCount ); |
|---|
| 2039 | | psFile->nLocCount = nLocCount; |
|---|
| 2040 | | |
|---|
| 2041 | | psFile->pasLocations = (NITFLocation *) |
|---|
| 2042 | | CPLCalloc(sizeof(NITFLocation), nLocCount); |
|---|
| 2043 | | #endif |
|---|
| 2044 | | |
|---|
| 2090 | | /* It seems that sometimes (at least for bug 1313) all the */ |
|---|
| 2091 | | /* locations in the location table are off by a fixed amount. */ |
|---|
| 2092 | | /* We can establish that amount by checking if the RPFHDR TRE */ |
|---|
| 2093 | | /* is at the location indicated in the location table. If not, */ |
|---|
| 2094 | | /* offset all locations by the difference. */ |
|---|
| | 2054 | /* It seems that sometimes (at least for bug #1313 and #1714) */ |
|---|
| | 2055 | /* the RPF headers are improperly placed. We check by looking */ |
|---|
| | 2056 | /* to see if the RPFHDR is where it should be. If not, we */ |
|---|
| | 2057 | /* disregard the location table. */ |
|---|
| | 2058 | /* */ |
|---|
| | 2059 | /* The NITF21_CGM_ANNO_Uncompressed_unmasked.ntf sample data */ |
|---|
| | 2060 | /* file (see gdal data downloads) is an example of this. */ |
|---|
| 2115 | | int nOffset = 0; |
|---|
| 2116 | | |
|---|
| 2117 | | for( i = 1; i < sizeof(achHeaderChunk)-6; i++ ) |
|---|
| 2118 | | { |
|---|
| 2119 | | if( EQUALN(achHeaderChunk+i,"RPFHDR",6) ) |
|---|
| 2120 | | { |
|---|
| 2121 | | nOffset = i; |
|---|
| 2122 | | break; |
|---|
| 2123 | | } |
|---|
| 2124 | | } |
|---|
| 2125 | | |
|---|
| 2126 | | if( nOffset != 0 ) |
|---|
| 2127 | | { |
|---|
| 2128 | | CPLDebug( "NITF", |
|---|
| 2129 | | "Location table offsets off by %d bytes, adjusting accordingly.", |
|---|
| 2130 | | nOffset ); |
|---|
| 2131 | | |
|---|
| 2132 | | for( i = 0; i < psImage->nLocCount; i++ ) |
|---|
| 2133 | | { |
|---|
| 2134 | | psImage->pasLocations[i].nLocOffset += nOffset; |
|---|
| 2135 | | } |
|---|
| 2136 | | } |
|---|
| | 2081 | CPLError( CE_Warning, CPLE_AppDefined, |
|---|
| | 2082 | "Ignoring NITF RPF Location table since it seems to be corrupt." ); |
|---|
| | 2083 | CPLFree( psImage->pasLocations ); |
|---|
| | 2084 | psImage->pasLocations = NULL; |
|---|
| | 2085 | psImage->nLocCount = 0; |
|---|