GDALAsyncReader* ECWDataset::BeginAsyncReader( int nXOff, int nYOff, int nXSize, int nYSize, void *pBuf, int nBufXSize, int nBufYSize, GDALDataType eBufType, int nBandCount, int* panBandMap, int nPixelSpace, int nLineSpace, int nBandSpace, char **papszOptions) { int i; /* -------------------------------------------------------------------- */ /* Provide default packing if needed. */ /* -------------------------------------------------------------------- */ if( nPixelSpace == 0 ) nPixelSpace = GDALGetDataTypeSize(eBufType) / 8; if( nLineSpace == 0 ) nLineSpace = nPixelSpace * nBufXSize; if( nBandSpace == 0 ) nBandSpace = nLineSpace * nBufYSize; /* -------------------------------------------------------------------- */ /* Do a bit of validation. */ /* -------------------------------------------------------------------- */ if( nXSize < 1 || nYSize < 1 || nBufXSize < 1 || nBufYSize < 1 ) { CPLDebug( "GDAL", "BeginAsyncReader() skipped for odd window or buffer size.\n" " Window = (%d,%d)x%dx%d\n" " Buffer = %dx%d\n", nXOff, nYOff, nXSize, nYSize, nBufXSize, nBufYSize ); return NULL; } if( nXOff < 0 || nXOff > INT_MAX - nXSize || nXOff + nXSize > nRasterXSize || nYOff < 0 || nYOff > INT_MAX - nYSize || nYOff + nYSize > nRasterYSize ) { ReportError( CE_Failure, CPLE_IllegalArg, "Access window out of range in RasterIO(). Requested\n" "(%d,%d) of size %dx%d on raster of %dx%d.", nXOff, nYOff, nXSize, nYSize, nRasterXSize, nRasterYSize ); return NULL; } if( nBandCount <= 0 || nBandCount > nBands ) { ReportError( CE_Failure, CPLE_IllegalArg, "Invalid band count" ); return NULL; } if( panBandMap != NULL ) { for( i = 0; i < nBandCount; i++ ) { if( panBandMap[i] < 1 || panBandMap[i] > nBands ) { ReportError( CE_Failure, CPLE_IllegalArg, "panBandMap[%d] = %d, this band does not exist on dataset.", i, panBandMap[i] ); return NULL; } } } /* -------------------------------------------------------------------- */ /* Create the corresponding async reader. */ /* -------------------------------------------------------------------- */ ECWAsyncReader *poReader = new ECWAsyncReader(); poReader->poDS = this; poReader->nXOff = nXOff; poReader->nYOff = nYOff; poReader->nXSize = nXSize; poReader->nYSize = nYSize; poReader->pBuf = pBuf; poReader->nBufXSize = nBufXSize; poReader->nBufYSize = nBufYSize; poReader->eBufType = eBufType; poReader->nBandCount = nBandCount; poReader->panBandMap = (int *) CPLCalloc(sizeof(int),nBandCount); if( panBandMap != NULL ) { memcpy( poReader->panBandMap, panBandMap, sizeof(int) * nBandCount ); } else { for( i = 0; i < nBandCount; i++ ) poReader->panBandMap[i] = i + 1; } poReader->nPixelSpace = nPixelSpace; poReader->nLineSpace = nLineSpace; poReader->nBandSpace = nBandSpace; /* -------------------------------------------------------------------- */ /* Create a new view for this request. */ /* -------------------------------------------------------------------- */ poReader->poFileView = OpenFileView( GetDescription(), true, poReader->bUsingCustomStream ); if( poReader->poFileView == NULL ) { delete poReader; return NULL; } poReader->poFileView->SetClientData( poReader ); poReader->poFileView->SetRefreshCallback( ECWAsyncReader::RefreshCB ); /* -------------------------------------------------------------------- */ /* Issue a corresponding SetView command. */ /* -------------------------------------------------------------------- */ std::vector<UINT32> anBandIndices; NCSError eNCSErr; CNCSError oErr; for( i = 0; i < nBandCount; i++ ) anBandIndices.push_back( panBandMap[i] - 1 ); oErr = poReader->poFileView->SetView( nBandCount, &(anBandIndices[0]), nXOff, nYOff, nXOff + nXSize - 1, nYOff + nYSize - 1, nBufXSize, nBufYSize ); eNCSErr = oErr.GetErrorNumber(); if( eNCSErr != NCS_SUCCESS ) { delete poReader; CPLError( CE_Failure, CPLE_AppDefined, "%s", NCSGetErrorText(eNCSErr) ); return NULL; } return poReader; }
GDALAsyncReader* ECWDataset::BeginAsyncReader( int nXOff, int nYOff, int nXSize, int nYSize, void *pBuf, int nBufXSize, int nBufYSize, GDALDataType eBufType, int nBandCount, int* panBandMap, int nPixelSpace, int nLineSpace, int nBandSpace, char **papszOptions) { /* -------------------------------------------------------------------- */ /* Provide default packing if needed. */ /* -------------------------------------------------------------------- */ if( nPixelSpace == 0 ) nPixelSpace = GDALGetDataTypeSize(eBufType) / 8; if( nLineSpace == 0 ) nLineSpace = nPixelSpace * nBufXSize; if( nBandSpace == 0 ) nBandSpace = nLineSpace * nBufYSize; /* -------------------------------------------------------------------- */ /* We should do a bit of validation first - perhaps add later. */ /* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */ /* Create the corresponding async reader. */ /* -------------------------------------------------------------------- */ ECWAsyncReader *poReader = new ECWAsyncReader(); poReader->poDS = this; poReader->nXOff = nXOff; poReader->nYOff = nYOff; poReader->nXSize = nXSize; poReader->nYSize = nYSize; poReader->pBuf = pBuf; poReader->nBufXSize = nBufXSize; poReader->nBufYSize = nBufYSize; poReader->eBufType = eBufType; poReader->nBandCount = nBandCount; poReader->panBandMap = (int *) CPLCalloc(sizeof(int),nBandCount); memcpy( poReader->panBandMap, panBandMap, sizeof(int) * nBandCount ); poReader->nPixelSpace = nPixelSpace; poReader->nLineSpace = nLineSpace; poReader->nBandSpace = nBandSpace; /* -------------------------------------------------------------------- */ /* Create a new view for this request. */ /* -------------------------------------------------------------------- */ poReader->poFileView = OpenFileView( GetDescription(), true, poReader->bUsingCustomStream ); if( poReader->poFileView == NULL ) { delete poReader; return NULL; } poReader->poFileView->SetClientData( poReader ); poReader->poFileView->SetRefreshCallback( ECWAsyncReader::RefreshCB ); /* -------------------------------------------------------------------- */ /* Issue a corresponding SetView command. */ /* -------------------------------------------------------------------- */ std::vector<UINT32> anBandIndices; int i; NCSError eNCSErr; CNCSError oErr; for( i = 0; i < nBandCount; i++ ) anBandIndices.push_back( panBandMap[i] - 1 ); oErr = poReader->poFileView->SetView( nBandCount, &(anBandIndices[0]), nXOff, nYOff, nXOff + nXSize - 1, nYOff + nYSize - 1, nBufXSize, nBufYSize ); eNCSErr = oErr.GetErrorNumber(); if( eNCSErr != NCS_SUCCESS ) { delete poReader; CPLError( CE_Failure, CPLE_AppDefined, "%s", NCSGetErrorText(eNCSErr) ); return NULL; } return poReader; }