コード例 #1
0
ファイル: qgsgdalproviderbase.cpp プロジェクト: CS-SI/QGIS
CPLErr QgsGdalProviderBase::gdalRasterIO( GDALRasterBandH hBand, GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize, int nYSize, void *pData, int nBufXSize, int nBufYSize, GDALDataType eBufType, int nPixelSpace, int nLineSpace, QgsRasterBlockFeedback *feedback )
{
  GDALRasterIOExtraArg extra;
  INIT_RASTERIO_EXTRA_ARG( extra );
  if ( false && feedback )  // disabled!
  {
    // Currently the cancelation is disabled... When RasterIO call is canceled,
    // GDAL returns CE_Failure with error code = 0 (CPLE_None), however one would
    // expect to get CPLE_UserInterrupt to clearly identify that the failure was
    // caused by the cancelation and not that something dodgy is going on.
    // Are both error codes acceptable?
    extra.pfnProgress = _gdalProgressFnWithFeedback;
    extra.pProgressData = ( void * ) feedback;
  }
  CPLErr err = GDALRasterIOEx( hBand, eRWFlag, nXOff, nYOff, nXSize, nYSize, pData, nBufXSize, nBufYSize, eBufType, nPixelSpace, nLineSpace, &extra );

  return err;
}
コード例 #2
0
CPLErr GDALRescaledAlphaBand::IReadBlock( int nXBlockOff, int nYBlockOff,
                                         void * pImage )
{
    int nXSizeRequest = nBlockXSize;
    if (nXBlockOff * nBlockXSize + nBlockXSize > nRasterXSize)
        nXSizeRequest = nRasterXSize - nXBlockOff * nBlockXSize;
    int nYSizeRequest = nBlockYSize;
    if (nYBlockOff * nBlockYSize + nBlockYSize > nRasterYSize)
        nYSizeRequest = nRasterYSize - nYBlockOff * nBlockYSize;

    GDALRasterIOExtraArg sExtraArg;
    INIT_RASTERIO_EXTRA_ARG(sExtraArg);

    return IRasterIO(GF_Read, nXBlockOff * nBlockXSize, nYBlockOff * nBlockYSize,
                     nXSizeRequest, nYSizeRequest, pImage,
                     nXSizeRequest, nYSizeRequest, GDT_Byte,
                     1, nBlockXSize, &sExtraArg);
}
コード例 #3
0
ファイル: jp2lurarasterband.cpp プロジェクト: hdfeos/gdal
CPLErr JP2LuraRasterBand::IReadBlock(int nBlockXOff, int nBlockYOff,
                                     void * pImage)
{
    JP2LuraDataset *poGDS = reinterpret_cast<JP2LuraDataset *>(poDS);
#ifdef DEBUG_VERBOSE
    CPLDebug("JP2Lura", "IReadBlock(nBand=%d,nLevel=%d %d,%d)",
             nBand, poGDS->iLevel, nBlockXOff, nBlockYOff);
#endif
    int nXOff = nBlockXOff * nBlockXSize;
    int nYOff = nBlockYOff * nBlockYSize;
    int nXSize = nBlockXSize;
    int nYSize = nBlockYSize;
    if( nXOff + nXSize > nRasterXSize )
        nXSize = nRasterXSize - nXOff;
    if( nYOff + nYSize > nRasterYSize )
        nYSize = nRasterYSize - nYOff;
    GDALRasterIOExtraArg sExtraArgs;
    INIT_RASTERIO_EXTRA_ARG(sExtraArgs);
    const int nDTSizeBytes = GDALGetDataTypeSizeBytes(eDataType);
    CPLErr eErr = IRasterIO(GF_Read, nXOff, nYOff, nXSize, nYSize,
                            pImage, nXSize, nYSize,
                            eDataType,
                            nDTSizeBytes,
                            nDTSizeBytes * nXSize,
                            &sExtraArgs);

    // Unpack previously packed buffer if needed
    if( eErr == CE_None && nXSize < nBlockXSize )
    {
        GByte* pabyData = reinterpret_cast<GByte*>(pImage);
        for( int j = nYSize - 1; j >= 0; --j )
        {
            memmove( pabyData + j * nBlockXSize * nDTSizeBytes,
                     pabyData + j * nXSize * nDTSizeBytes,
                     nXSize * nDTSizeBytes );
        }
    }

    // Caching other bands while we have the cached buffer valid
    for( int iBand = 1;eErr == CE_None && iBand <= poGDS->nBands; iBand++ )
    {
        if( iBand == nBand )
            continue;
        JP2LuraRasterBand* poOtherBand =
            reinterpret_cast<JP2LuraRasterBand*>(poGDS->GetRasterBand(iBand));
        GDALRasterBlock* poBlock = poOtherBand->
                                TryGetLockedBlockRef(nBlockXOff,nBlockYOff);
        if (poBlock != nullptr)
        {
            poBlock->DropLock();
            continue;
        }

        poBlock = poOtherBand->
                            GetLockedBlockRef(nBlockXOff,nBlockYOff, TRUE);
        if (poBlock == nullptr)
        {
            continue;
        }

        GByte* pabyData = reinterpret_cast<GByte*>(poBlock->GetDataRef());
        eErr = poOtherBand->IRasterIO(GF_Read, nXOff, nYOff, nXSize, nYSize,
                        pabyData, nXSize, nYSize,
                        eDataType,
                        nDTSizeBytes,
                        nDTSizeBytes * nXSize,
                        &sExtraArgs);

        // Unpack previously packed buffer if needed
        if( eErr == CE_None && nXSize < nBlockXSize )
        {
            for( int j = nYSize - 1; j >= 0; --j )
            {
                memmove( pabyData + j * nBlockXSize * nDTSizeBytes,
                        pabyData + j * nXSize * nDTSizeBytes,
                        nXSize * nDTSizeBytes );
            }
        }

        poBlock->DropLock();
    }

    return eErr;
}