本文整理汇总了C++中GDALSwapWords函数的典型用法代码示例。如果您正苦于以下问题:C++ GDALSwapWords函数的具体用法?C++ GDALSwapWords怎么用?C++ GDALSwapWords使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GDALSwapWords函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: VSIFSeekL
CPLErr GFFRasterBand::IReadBlock( int /* nBlockXOff */ ,
int nBlockYOff,
void *pImage )
{
GFFDataset *poGDS = (GFFDataset *)poDS;
long nOffset = poGDS->nLength;
VSIFSeekL(poGDS->fp, nOffset + (poGDS->GetRasterXSize() * nBlockYOff * (nSampleSize)),SEEK_SET);
/* Ingest entire range line */
if (VSIFReadL(pImage,nRasterBandMemory,1,poGDS->fp) != 1)
return CE_Failure;
#if defined(CPL_MSB)
if( GDALDataTypeIsComplex( eDataType ) )
{
int nWordSize = GDALGetDataTypeSize(eDataType)/16;
GDALSwapWords( pImage, nWordSize, nBlockXSize, 2*nWordSize );
GDALSwapWords( ((GByte *) pImage)+nWordSize,
nWordSize, nBlockXSize, 2*nWordSize );
}
#endif
return CE_None;
}
示例2: VSIFSeekL
CPLErr NGSGEOIDRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
{
NGSGEOIDDataset *poGDS = (NGSGEOIDDataset *) poDS;
/* First values in the file corresponds to the south-most line of the imagery */
VSIFSeekL(poGDS->fp,
HEADER_SIZE + (nRasterYSize - 1 - nBlockYOff) * nRasterXSize * 4,
SEEK_SET);
if ((int)VSIFReadL(pImage, 4, nRasterXSize, poGDS->fp) != nRasterXSize)
return CE_Failure;
if (poGDS->bIsLittleEndian)
{
#ifdef CPL_MSB
GDALSwapWords( pImage, 4, nRasterXSize, 4 );
#endif
}
else
{
#ifdef CPL_LSB
GDALSwapWords( pImage, 4, nRasterXSize, 4 );
#endif
}
return CE_None;
}
示例3: VSIFSeekL
CPLErr PALSARJaxaRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void *pImage )
{
int nNumBytes = 0;
if (nFileType == level_11) {
nNumBytes = 8;
}
else {
nNumBytes = 2;
}
int nOffset = IMAGE_OPT_DESC_LENGTH + ((nBlockYOff - 1) * nRecordSize) +
(nFileType == level_11 ? SIG_DAT_REC_OFFSET : PROC_DAT_REC_OFFSET);
VSIFSeekL( fp, nOffset, SEEK_SET );
VSIFReadL( pImage, nNumBytes, nRasterXSize, fp );
#ifdef CPL_LSB
if (nFileType == level_11)
GDALSwapWords( pImage, 4, nBlockXSize * 2, 4 );
else
GDALSwapWords( pImage, 2, nBlockXSize, 2 );
#endif
return CE_None;
}
示例4: LoadBlockBuf
CPLErr IntergraphRasterBand::IReadBlock( int nBlockXOff,
int nBlockYOff,
void *pImage )
{
// --------------------------------------------------------------------
// Load Block Buffer
// --------------------------------------------------------------------
if (HandleUninstantiatedTile( nBlockXOff, nBlockYOff, pImage ))
return CE_None;
uint32 nBytesRead = LoadBlockBuf( nBlockXOff, nBlockYOff, nBlockBufSize, pabyBlockBuf );
if( nBytesRead == 0 )
{
memset( pImage, 0, nBlockXSize * nBlockYSize *
GDALGetDataTypeSize( eDataType ) / 8 );
CPLError( CE_Failure, CPLE_FileIO,
"Can't read (%s) tile with X offset %d and Y offset %d.\n",
((IntergraphDataset*)poDS)->pszFilename, nBlockXOff, nBlockYOff );
return CE_Failure;
}
// --------------------------------------------------------------------
// Reshape blocks if needed
// --------------------------------------------------------------------
if( nBlockXOff == nFullBlocksX ||
nBlockYOff == nFullBlocksY )
{
ReshapeBlock( nBlockXOff, nBlockYOff, nBlockBufSize, pabyBlockBuf );
}
// --------------------------------------------------------------------
// Copy block buffer to image
// --------------------------------------------------------------------
memcpy( pImage, pabyBlockBuf, nBlockXSize * nBlockYSize *
GDALGetDataTypeSize( eDataType ) / 8 );
#ifdef CPL_MSB
if( eDataType == GDT_Int16 || eDataType == GDT_UInt16)
GDALSwapWords( pImage, 2, nBlockXSize * nBlockYSize, 2 );
else if( eDataType == GDT_Int32 || eDataType == GDT_UInt32 || eDataType == GDT_Float32 )
GDALSwapWords( pImage, 4, nBlockXSize * nBlockYSize, 4 );
else if (eDataType == GDT_Float64 )
GDALSwapWords( pImage, 8, nBlockXSize * nBlockYSize, 8 );
#endif
return CE_None;
}
示例5: memset
CPLErr RawRasterBand::AccessBlock( vsi_l_offset nBlockOff, int nBlockSize,
void * pData )
{
int nBytesActuallyRead;
/* -------------------------------------------------------------------- */
/* Seek to the right block. */
/* -------------------------------------------------------------------- */
if( Seek( nBlockOff, SEEK_SET ) == -1 )
{
memset( pData, 0, nBlockSize );
return CE_None;
}
/* -------------------------------------------------------------------- */
/* Read the block. */
/* -------------------------------------------------------------------- */
nBytesActuallyRead = Read( pData, 1, nBlockSize );
if( nBytesActuallyRead < nBlockSize )
{
memset( ((GByte *) pData) + nBytesActuallyRead,
0, nBlockSize - nBytesActuallyRead );
return CE_None;
}
/* -------------------------------------------------------------------- */
/* Byte swap the interesting data, if required. */
/* -------------------------------------------------------------------- */
if( !bNativeOrder && eDataType != GDT_Byte )
{
if( GDALDataTypeIsComplex( eDataType ) )
{
int nWordSize;
nWordSize = GDALGetDataTypeSize(eDataType)/16;
GDALSwapWords( pData, nWordSize, nBlockSize / nPixelOffset,
nPixelOffset );
GDALSwapWords( ((GByte *) pData) + nWordSize,
nWordSize, nBlockSize / nPixelOffset, nPixelOffset );
}
else
GDALSwapWords( pData, GDALGetDataTypeSize(eDataType) / 8,
nBlockSize / nPixelOffset, nPixelOffset );
}
return CE_None;
}
示例6: CPLAssert
CPLErr BTRasterBand::IReadBlock( int nBlockXOff,
CPL_UNUSED int nBlockYOff,
void * pImage )
{
CPLAssert( nBlockYOff == 0 );
const int nDataSize = GDALGetDataTypeSizeBytes( eDataType );
/* -------------------------------------------------------------------- */
/* Seek to profile. */
/* -------------------------------------------------------------------- */
if( VSIFSeekL( fpImage,
256 + nBlockXOff * nDataSize *
static_cast<vsi_l_offset>( nRasterYSize ),
SEEK_SET ) != 0 )
{
CPLError( CE_Failure, CPLE_FileIO,
".bt Seek failed:%s", VSIStrerror( errno ) );
return CE_Failure;
}
/* -------------------------------------------------------------------- */
/* Read the profile. */
/* -------------------------------------------------------------------- */
if( VSIFReadL( pImage, nDataSize, nRasterYSize, fpImage ) !=
static_cast<size_t>( nRasterYSize ) )
{
CPLError( CE_Failure, CPLE_FileIO,
".bt Read failed:%s", VSIStrerror( errno ) );
return CE_Failure;
}
/* -------------------------------------------------------------------- */
/* Swap on MSB platforms. */
/* -------------------------------------------------------------------- */
#ifdef CPL_MSB
GDALSwapWords( pImage, nDataSize, nRasterYSize, nDataSize );
#endif
/* -------------------------------------------------------------------- */
/* Vertical flip, since GDAL expects values from top to bottom, */
/* but in .bt they are bottom to top. */
/* -------------------------------------------------------------------- */
for( int i = 0; i < nRasterYSize / 2; i++ )
{
GByte abyWrk[8] = { 0 };
memcpy( abyWrk, reinterpret_cast<GByte *>(pImage) + i * nDataSize,
nDataSize );
memcpy( reinterpret_cast<GByte *>(pImage) + i * nDataSize,
reinterpret_cast<GByte *>(pImage) + (nRasterYSize - i - 1) *
nDataSize,
nDataSize );
memcpy( reinterpret_cast<GByte *>(pImage) + (nRasterYSize - i - 1) *
nDataSize,
abyWrk, nDataSize );
}
return CE_None;
}
示例7: GDALGetDataTypeSizeBytes
CPLErr SRTMHGTRasterBand::IWriteBlock(int /*nBlockXOff*/, int nBlockYOff, void* pImage)
{
SRTMHGTDataset* poGDS = reinterpret_cast<SRTMHGTDataset *>( poDS );
if( poGDS->eAccess != GA_Update )
return CE_Failure;
const int nDTSize = GDALGetDataTypeSizeBytes(eDataType);
VSIFSeekL(poGDS->fpImage, nBlockYOff*nBlockXSize*nDTSize, SEEK_SET);
#ifdef CPL_LSB
if( nDTSize > 1 )
{
memcpy(poGDS->panBuffer, pImage, nBlockXSize*nDTSize);
GDALSwapWords(poGDS->panBuffer, nDTSize, nBlockXSize, nDTSize);
VSIFWriteL( reinterpret_cast<unsigned char *>( poGDS->panBuffer ),
nBlockXSize, nDTSize, poGDS->fpImage );
}
else
#endif
{
VSIFWriteL( reinterpret_cast<unsigned char *>( pImage ),
nBlockXSize, nDTSize, poGDS->fpImage );
}
return CE_None;
}
示例8: CPLAssert
CPLErr SRTMHGTRasterBand::IWriteBlock(int nBlockXOff, int nBlockYOff, void* pImage)
{
SRTMHGTDataset* poGDS = (SRTMHGTDataset*) poDS;
CPLAssert(nBlockXOff == 0);
if(nBlockXOff != 0)
{
CPLError(CE_Failure, CPLE_NotSupported, "unhandled nBlockXOff value : %d", nBlockXOff);
return CE_Failure;
}
if((poGDS == NULL) || (poGDS->fpImage == NULL) || (poGDS->eAccess != GA_Update))
return CE_Failure;
VSIFSeekL(poGDS->fpImage, nBlockYOff*nBlockXSize*2, SEEK_SET);
#ifdef CPL_LSB
memcpy(poGDS->panBuffer, pImage, nBlockXSize*sizeof(GInt16));
GDALSwapWords(poGDS->panBuffer, 2, nBlockXSize, 2);
VSIFWriteL((unsigned char*)poGDS->panBuffer, nBlockXSize, 2, poGDS->fpImage);
#else
VSIFWriteL((unsigned char*)pImage, nBlockXSize, 2, poGDS->fpImage);
#endif
return CE_None;
}
示例9: VSIFSeek
CPLErr COSARRasterBand::IReadBlock(CPL_UNUSED int nBlockXOff, int nBlockYOff,
void *pImage) {
unsigned long nRSFV = 0;
unsigned long nRSLV = 0;
COSARDataset *pCDS = (COSARDataset *) poDS;
/* Find the line we want to be at */
/* To explain some magic numbers:
* 4 bytes for an entire sample (2 I, 2 Q)
* nBlockYOff + 4 = Y offset + 4 annotation lines at beginning
* of file
*/
VSIFSeek(pCDS->fp,(this->nRTNB * (nBlockYOff + 4)), SEEK_SET);
/* Read RSFV and RSLV (TX-GS-DD-3307) */
VSIFRead(&nRSFV,1,4,pCDS->fp);
VSIFRead(&nRSLV,1,4,pCDS->fp);
#ifdef CPL_LSB
nRSFV = CPL_SWAP32(nRSFV);
nRSLV = CPL_SWAP32(nRSLV);
#endif
if (nRSLV < nRSFV || nRSFV == 0
|| nRSFV - 1 >= ((unsigned long) nBlockXSize)
|| nRSLV - nRSFV > ((unsigned long) nBlockXSize)
|| nRSFV >= this->nRTNB || nRSLV > this->nRTNB)
{
/* throw an error */
CPLError(CE_Failure, CPLE_AppDefined,
"RSLV/RSFV values are not sane... oh dear.\n");
return CE_Failure;
}
/* zero out the range line */
for (int i = 0; i < this->nRasterXSize; i++)
{
((GUInt32 *)pImage)[i] = 0;
}
/* properly account for validity mask */
if (nRSFV > 1)
{
VSIFSeek(pCDS->fp,(this->nRTNB*(nBlockYOff+4)+(nRSFV+1)*4), SEEK_SET);
}
/* Read the valid samples: */
VSIFRead(((char *)pImage)+((nRSFV - 1)*4),1,((nRSLV-1)*4)-((nRSFV-1)*4),pCDS->fp);
#ifdef CPL_LSB
// GDALSwapWords( pImage, 4, nBlockXSize * nBlockYSize, 4 );
GDALSwapWords( pImage, 2, nBlockXSize * nBlockYSize * 2, 2 );
#endif
return CE_None;
}
示例10: CPLError
CPLErr ISISTiledBand::IReadBlock( int nXBlock, int nYBlock, void *pImage )
{
GIntBig nOffset = nFirstTileOffset +
nXBlock * nXTileOffset + nYBlock * nYTileOffset;
size_t nBlockSize =
(GDALGetDataTypeSize(eDataType)/8) * nBlockXSize * nBlockYSize;
if( VSIFSeekL( fpVSIL, nOffset, SEEK_SET ) != 0 )
{
CPLError( CE_Failure, CPLE_FileIO,
"Failed to seek to offset %d to read tile %d,%d.",
(int) nOffset, nXBlock, nYBlock );
return CE_Failure;
}
if( VSIFReadL( pImage, 1, nBlockSize, fpVSIL ) != nBlockSize )
{
CPLError( CE_Failure, CPLE_FileIO,
"Failed to read %d bytes for tile %d,%d.",
(int) nBlockSize, nXBlock, nYBlock );
return CE_Failure;
}
if( !bNativeOrder )
GDALSwapWords( pImage, GDALGetDataTypeSize(eDataType)/8,
nBlockXSize*nBlockYSize,
GDALGetDataTypeSize(eDataType)/8 );
return CE_None;
}
示例11: CPLError
CPLErr COASPRasterBand::IReadBlock( CPL_UNUSED int nBlockXOff,
int nBlockYOff,
void *pImage )
{
if (this->fp == NULL) {
CPLError(CE_Fatal, CPLE_AppDefined, "file pointer freed unexpectedly\n");
return CE_Fatal;
}
/* 8 bytes per pixel: 4 bytes I, 4 bytes Q */
unsigned long nByteNum = poDS->GetRasterXSize() * 8 * nBlockYOff;
VSIFSeekL(this->fp, nByteNum, SEEK_SET);
int nReadSize = (GDALGetDataTypeSize(eDataType)/8) * poDS->GetRasterXSize();
VSIFReadL((char *)pImage, 1, nReadSize,
this->fp);
#ifdef CPL_LSB
GDALSwapWords( pImage, 4, nBlockXSize * 2, 4 );
#endif
return CE_None;
}
示例12: CPLAssert
CPLErr TerragenRasterBand::IWriteBlock
(
int nBlockXOff,
int nBlockYOff,
void* pImage
)
{
CPLAssert( nBlockXOff == 0 );
CPLAssert( pImage != NULL );
CPLAssert( m_pvLine != NULL );
#define sgn(_n) ((_n) < 0 ? -1 : ((_n) > 0 ? 1 : 0) )
#define sround(_f) \
(int)((_f) + (0.5 * sgn(_f)))
const size_t pixelsize = sizeof(GInt16);
TerragenDataset& ds = *(TerragenDataset*)poDS;
if(m_bFirstTime)
{
m_bFirstTime = false;
ds.write_header();
ds.m_nDataOffset = VSIFTellL(ds.m_fp);
}
const size_t rowbytes = nBlockXSize * pixelsize;
GInt16* pLine = (GInt16*)m_pvLine;
if(0 == VSIFSeekL(
ds.m_fp,
ds.m_nDataOffset +
// Terragen is Y inverted.
(ds.GetRasterYSize()-1-nBlockYOff) * rowbytes,
SEEK_SET))
{
// Convert each float32 to int16.
float* pfImage = (float*)pImage;
for(size_t x = 0; x < (size_t)nBlockXSize; x++)
{
double f = pfImage[x];
f *= ds.m_dMetersPerElevUnit;
f /= ds.m_dSCAL;
GInt16 hv =
(GInt16)((f - ds.m_nBaseHeight) *
65536.0 / ds.m_nHeightScale /*+ ds.m_nShift*/);
pLine[x] = hv;
}
#ifdef CPL_MSB
GDALSwapWords( m_pvLine, pixelsize, nBlockXSize, pixelsize );
#endif
if(1 == VSIFWriteL(m_pvLine, rowbytes, 1, ds.m_fp))
return CE_None;
}
return CE_Failure;
}
示例13: CPLAssert
CPLErr TerragenRasterBand::IWriteBlock
(
CPL_UNUSED int nBlockXOff,
int nBlockYOff,
void* pImage
)
{
CPLAssert( nBlockXOff == 0 );
CPLAssert( pImage != NULL );
CPLAssert( m_pvLine != NULL );
const size_t pixelsize = sizeof(GInt16);
TerragenDataset& ds = *reinterpret_cast<TerragenDataset *>(poDS );
if( m_bFirstTime )
{
m_bFirstTime = false;
ds.write_header();
ds.m_nDataOffset = VSIFTellL(ds.m_fp);
}
const size_t rowbytes = nBlockXSize * pixelsize;
GInt16* pLine = reinterpret_cast<GInt16 *>( m_pvLine );
if(0 == VSIFSeekL(
ds.m_fp,
ds.m_nDataOffset +
// Terragen is Y inverted.
(ds.GetRasterYSize()-1-nBlockYOff) * rowbytes,
SEEK_SET))
{
// Convert each float32 to int16.
float* pfImage = reinterpret_cast<float *>( pImage );
for( size_t x = 0; x < static_cast<size_t>( nBlockXSize ); x++ )
{
const double f = pfImage[x] * ds.m_dMetersPerElevUnit / ds.m_dSCAL;
const GInt16 hv = static_cast<GInt16>(
( f - ds.m_nBaseHeight ) * 65536.0 / ds.m_nHeightScale
/*+ ds.m_nShift*/ );
pLine[x] = hv;
}
#ifdef CPL_MSB
GDALSwapWords( m_pvLine, pixelsize, nBlockXSize, pixelsize );
#endif
if(1 == VSIFWriteL(m_pvLine, rowbytes, 1, ds.m_fp))
return CE_None;
}
return CE_Failure;
}
示例14: GDALSwapWords
// Test that GDALSwapWords() with unaligned buffers
template<> template<> void object::test<10>()
{
GByte abyBuffer[ 8 * 2 + 1 ] = { 0, 1, 2, 3, 4, 5, 6, 7, 255, 7, 6, 5, 4, 3, 2, 1, 0 };
GDALSwapWords(abyBuffer, 4, 2, 9 );
ensure( abyBuffer[0] == 3 );
ensure( abyBuffer[1] == 2 );
ensure( abyBuffer[2] == 1 );
ensure( abyBuffer[3] == 0 );
ensure( abyBuffer[9] == 4 );
ensure( abyBuffer[10] == 5 );
ensure( abyBuffer[11] == 6 );
ensure( abyBuffer[12] == 7 );
GDALSwapWords(abyBuffer, 4, 2, 9 );
GDALSwapWords(abyBuffer, 8, 2, 9 );
ensure( abyBuffer[0] == 7 );
ensure( abyBuffer[1] == 6 );
ensure( abyBuffer[2] == 5 );
ensure( abyBuffer[3] == 4 );
ensure( abyBuffer[4] == 3 );
ensure( abyBuffer[5] == 2 );
ensure( abyBuffer[6] == 1 );
ensure( abyBuffer[7] == 0 );
ensure( abyBuffer[9] == 0 );
ensure( abyBuffer[10] == 1 );
ensure( abyBuffer[11] == 2 );
ensure( abyBuffer[12] == 3 );
ensure( abyBuffer[13] == 4 );
ensure( abyBuffer[14] == 5 );
ensure( abyBuffer[15] == 6 );
ensure( abyBuffer[16] == 7 );
GDALSwapWords(abyBuffer, 4, 2, 9 );
}
示例15: CPLAssert
CPLErr LevellerRasterBand::IWriteBlock
(
int nBlockXOff,
int nBlockYOff,
void* pImage
)
{
CPLAssert( nBlockXOff == 0 );
CPLAssert( pImage != NULL );
CPLAssert( m_pLine != NULL );
/* #define sgn(_n) ((_n) < 0 ? -1 : ((_n) > 0 ? 1 : 0) )
#define sround(_f) \
(int)((_f) + (0.5 * sgn(_f)))
*/
const size_t pixelsize = sizeof(float);
LevellerDataset& ds = *(LevellerDataset*)poDS;
if(m_bFirstTime)
{
m_bFirstTime = false;
if(!ds.write_header())
return CE_Failure;
ds.m_nDataOffset = VSIFTellL(ds.m_fp);
}
const size_t rowbytes = nBlockXSize * pixelsize;
const float* pfImage = (float*)pImage;
if(0 == VSIFSeekL(
ds.m_fp, ds.m_nDataOffset + nBlockYOff * rowbytes,
SEEK_SET))
{
for(size_t x = 0; x < (size_t)nBlockXSize; x++)
{
// Convert logical elevations to physical.
m_pLine[x] = (float)
((pfImage[x] - ds.m_dElevBase) / ds.m_dElevScale);
}
#ifdef CPL_MSB
GDALSwapWords( m_pLine, pixelsize, nBlockXSize, pixelsize );
#endif
if(1 == VSIFWriteL(m_pLine, rowbytes, 1, ds.m_fp))
return CE_None;
}
return CE_Failure;
}