/** * Set a file view. * Set a view of the ecw file in world coordinates, specifying the top left and bottom right extents. * @param nBands Number of bands * @param pBandList Pointer to a list of INT bands to view * @param nWidth The output view sampled width * @param nHeight The output view sampled height * @param dWorldTLX Top left X value in world coordinates * @param dWorldTLY Top left Y value in world coordinates * @param dWorldBRX Bottom right X value in world coordinates * @param dWorldBRY Bottom right Y value in world coordinates * @see SetView() * @return NCS_SUCCESS if successfull, or an NCSError value. */ NCSError CNCSFile::SetView ( INT32 nBands, INT32 *pBandList, INT32 nWidth, INT32 nHeight, IEEE8 dWorldTLX, IEEE8 dWorldTLY, IEEE8 dWorldBRX, IEEE8 dWorldBRY ) { INT32 nDatasetTLX, nDatasetTLY, nDatasetBRX, nDatasetBRY; NCSError nError; m_dSetViewWorldTLX = dWorldTLX; m_dSetViewWorldTLY = dWorldTLY; m_dSetViewWorldBRX = dWorldBRX; m_dSetViewWorldBRY = dWorldBRY; // We still need to correct dataset coords, so convert the world to datasets. ConvertWorldToDataset(m_dSetViewWorldTLX, m_dSetViewWorldTLY, &nDatasetTLX, &nDatasetTLY); ConvertWorldToDataset(m_dSetViewWorldBRX, m_dSetViewWorldBRY, &nDatasetBRX, &nDatasetBRY); // Do the set view with the adjusted extents nError = CNCSJP2FileView::SetView(nBands, (UINT32*)pBandList, nDatasetTLX, nDatasetTLY, nDatasetBRX, nDatasetBRY, nWidth, nHeight, m_dSetViewWorldTLX, m_dSetViewWorldTLY, m_dSetViewWorldBRX, m_dSetViewWorldBRY).GetErrorNumber(); if (nError == NCS_SUCCESS) { m_bHaveValidSetView = TRUE; } else if( nError == NCS_FILEIO_ERROR ) { m_bHaveValidSetView = FALSE; } else if( nError == NCS_CONNECTION_LOST ) { char buf[1024]; //[01] sprintf(buf, "SetView() Error - %s", NCSGetErrorText(nError)); //[01] NCSFormatErrorText(nError, buf); //[01] m_bHaveValidSetView = FALSE; } else { char buf[1024]; //[01] sprintf(buf, "SetView() Error - %s", NCSGetErrorText(nError)); //[01] nError = NCS_ECW_ERROR; //[01] NCSFormatErrorText(nError, buf); //[01] m_bHaveValidSetView = FALSE; } m_bSetViewModeIsWorld = TRUE; return (NCSError)nError; }
/** * Set a file view. * Set a view of the ecw file in dataset units, specifying the top left and bottom right extents. * @param nBands Number of bands * @param pBandList Pointer to a list of INT bands to view * @param nWidth The output view sampled width * @param nHeight The output view sampled height * @param dDatasetTLX Top left X value in dataset units * @param dDatasetTLY Top left Y value in dataset units * @param dDatasetBRX Bottom right X value in dataset units * @param dDatasetBRY Bottom right Y value in dataset units * @see SetView() * @return NCS_SUCCESS if successfull, or an NCSError value. */ NCSError CNCSFile::SetView ( INT32 nBands, INT32 *pBandList, INT32 nWidth, INT32 nHeight, INT32 dDatasetTLX, INT32 dDatasetTLY, INT32 dDatasetBRX, INT32 dDatasetBRY ) { NCSError nError; m_nSetViewDatasetTLX = dDatasetTLX; m_nSetViewDatasetTLY = dDatasetTLY; m_nSetViewDatasetBRX = dDatasetBRX; m_nSetViewDatasetBRY = dDatasetBRY; if ((m_nSetViewDatasetTLX < 0) || (m_nSetViewDatasetTLY < 0 ) || (m_nSetViewDatasetBRX > m_nWidth-1) || (m_nSetViewDatasetBRY > m_nHeight-1)) { // OK some or all of the view is outside the dataset, adjust accordingly /*#ifdef _DEBUG ::MessageBox(NULL, NCS_T("Problem with view"), NCS_T("DEBUG"), MB_OK); #endif*/ // clamp if (m_nSetViewDatasetTLX < 0) m_nSetViewDatasetTLX = 0; if (m_nSetViewDatasetTLY < 0 ) m_nSetViewDatasetTLY = 0; if (m_nSetViewDatasetBRX > m_nWidth-1) m_nSetViewDatasetBRX = m_nWidth-1; if (m_nSetViewDatasetBRY > m_nHeight-1) m_nSetViewDatasetBRY = m_nHeight-1; } // Do the set view with the adjusted extents nError = CNCSJP2FileView::SetView(nBands, (UINT32*)pBandList, m_nSetViewDatasetTLX, m_nSetViewDatasetTLY, m_nSetViewDatasetBRX, m_nSetViewDatasetBRY, nWidth, nHeight).GetErrorNumber(); if (nError == NCS_SUCCESS) { m_bHaveValidSetView = TRUE; } else if( nError == NCS_FILEIO_ERROR ) { m_bHaveValidSetView = FALSE; } else { char buf[1024]; //[01] sprintf(buf, "SetView() Error - %s", NCSGetErrorText(nError)); //[01] nError = NCS_ECW_ERROR; //[01] NCSFormatErrorText(nError, buf); //[01] m_bHaveValidSetView = FALSE; } m_bSetViewModeIsWorld = FALSE; return (NCSError)nError; }
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; }
int test_openview( char *szInputFilename, BOOLEAN bRandomReads, BOOLEAN bReportTime ) { NCSFileView *pNCSFileView; NCSFileViewFileInfo *pNCSFileInfo; NCSError eError = NCS_SUCCESS; UINT8 **p_p_output_line = NULL; UINT8 *p_output_buffer = NULL; UINT32 x_size, y_size, number_x, number_y; UINT32 start_x, start_y, end_x, end_y; UINT32 line; int regions; double total_pixels = 0.0; UINT32 band; UINT32 nBands; UINT32 *band_list = NULL; /* list of individual bands to read, may be subset of actual bands */ clock_t start_time, mark_time; printf("ECW READ EXAMPLE\n"); start_time = mark_time = clock(); /* ** Open the input NCSFileView */ eError = NCScbmOpenFileView(szInputFilename, &pNCSFileView, NULL); if (eError != NCS_SUCCESS) { printf("Could not open view for file:%s\n",szInputFilename); printf("Error = %s\n", NCSGetErrorText(eError)); return(1); } NCScbmGetViewFileInfo(pNCSFileView, &pNCSFileInfo); x_size = pNCSFileInfo->nSizeX; y_size = pNCSFileInfo->nSizeY; nBands = pNCSFileInfo->nBands; printf("Input file is [%ld x %ld by %d bands]\n", (long)x_size, (long)y_size, nBands); // Have to set up the band list. Compatible with ER Mapper's method. // In this example we always request all bands. band_list = (UINT32 *) malloc(sizeof(UINT32) * nBands); if( !band_list ) { printf("Error - unable to malloc band list\n"); NCScbmCloseFileView(pNCSFileView); return(1); } for( band = 0; band < nBands; band++ ) band_list[band] = band; // All of image start_x = 0; start_y = 0; end_x = x_size - 1; end_y = y_size - 1; number_x = x_size; number_y = y_size; // do many region reads as tests if( bRandomReads ) regions = 10; else regions = 100; // regions = 5000; while( regions -- ) { { // work out a random region to read number_x = number_y = 512; // define a random region and size start_x = (UINT32) (RAND() * x_size); end_x = (UINT32) (RAND() * (x_size - start_x)) + start_x; start_y = (UINT32) (RAND() * y_size); end_y = (UINT32) (RAND() * (y_size - start_y)) + start_y; // make a square view area if( (end_x - start_x) < MAX_WINDOW ) { end_x = start_x + MAX_WINDOW; if( end_x >= x_size ) { // [01] start_x = x_size - MAX_WINDOW; end_x = x_size-1; } } if( (end_y - start_y) < MAX_WINDOW ) { end_y = start_y + MAX_WINDOW; if( end_y >= y_size ) { // [01] start_y = y_size - MAX_WINDOW; end_y = y_size-1; } } if( (end_x - start_x) < (end_y - start_y) ) end_y = start_y + (end_x - start_x); else end_x = start_x + (end_y - start_y); number_x = number_y = MAX_WINDOW; } printf("Region %4d: [%d,%d] to [%d,%d] for [%d,%d]\n", regions, start_x, start_y, end_x, end_y, number_x, number_y); eError = NCScbmSetFileView(pNCSFileView, nBands, band_list, start_x, start_y, end_x, end_y, number_x, number_y); if( eError != NCS_SUCCESS) { printf("Error while setting file view to %d bands, TL[%d,%d] BR[%d,%d], Window size [%d,%d]\n", nBands, start_x, start_y, end_x, end_y, number_x, number_y); printf("Error = %s\n", NCSGetErrorText(eError)); NCScbmCloseFileView(pNCSFileView); free(band_list); return(1); } p_output_buffer = (UINT8 *) malloc( sizeof(UINT8) * number_x * nBands); p_p_output_line = (UINT8 **) malloc( sizeof(UINT8 *) * nBands); if( !p_p_output_line || !p_output_buffer) { printf("Malloc error for output buffers\n"); NCScbmCloseFileView(pNCSFileView); free(band_list); if( p_p_output_line ) free((char *) p_p_output_line); if( p_output_buffer ) free((char *) p_output_buffer); return(1); } for(band = 0; band < nBands; band++ ) p_p_output_line[band] = p_output_buffer + (band * number_x); /* ** Read each line of the compressed file */ for( line = 0; line < number_y; line++ ) { NCSEcwReadStatus eReadStatus; eReadStatus = NCScbmReadViewLineBIL( pNCSFileView, p_p_output_line); if (eReadStatus != NCSECW_READ_OK) { printf("Read line error at line %d\n",line); printf("Status code = %d\n", eReadStatus); NCScbmCloseFileView(pNCSFileView); free(band_list); free((char *) p_p_output_line); free((char *) p_output_buffer); return(1); } } free((char *) p_p_output_line); free((char *) p_output_buffer); if( bReportTime ) { double pixels, seconds, pixels_per_second, seconds_per_megapixel; // time for this run seconds = ((double) (clock() - mark_time)) / (double) CLOCKS_PER_SEC; if( seconds == 0 ) seconds = 0.01; pixels = (double) number_x * (double) number_y; pixels_per_second = pixels / seconds; seconds_per_megapixel = seconds / (pixels / 1000000.0); printf("Region time:%5.2lf sec.%5.2lf Mpixels/sec. %4.2lf secs/Mpixel (%6.2lf Mpixels)\n", seconds, pixels_per_second / 1000000, seconds_per_megapixel, (pixels/1000000)); // cumulative time mark_time = clock(); seconds = ((double) (mark_time - start_time)) / (double) CLOCKS_PER_SEC; if( seconds == 0 ) seconds = 0.001; total_pixels += pixels; pixels_per_second = total_pixels / seconds; seconds_per_megapixel = seconds / (total_pixels / 1000000.0); } } if( bReportTime ) { double seconds, pixels_per_second, seconds_per_megapixel; // cumulative time mark_time = clock(); seconds = ((double) (mark_time - start_time)) / (double) CLOCKS_PER_SEC; if( seconds == 0 ) seconds = 0.001; pixels_per_second = total_pixels / seconds; seconds_per_megapixel = seconds / (total_pixels / 1000000.0); printf("ALL time:%5.2lf sec.%5.2lf Mpixels/sec. %4.2lf secs/Mpixel (%6.2lf Mpixels)\n", seconds, pixels_per_second / 1000000, seconds_per_megapixel, total_pixels / 1000000); } // Make the second argument below TRUE if this is the last view of the file and you // want the file closed, otherwise it will be kept open in the cache. This can // sometimes be an problem when writing plugins. // NCScbmCloseFileViewEx(pNCSFileView, FALSE); free(band_list); return(0); }
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; }
int main(int argc, char **argv) { NCSEcwCompressClient *pClient; char *szInputFilename; char *szOutputFilename; NCSFileView *pNCSFileView; NCSFileViewFileInfo *pNCSFileInfo; UINT8 *pReadBuffer; UINT8 **ppInputBandBufferArray; NCSError eError; INT32 nBand; IEEE4 fTargetCompressionOverride = 0.0; // Check user has specified a file on command line if (argc < 3 || argc > 4) { ReportError( "Usage: %s InputFilename OutputFilename [Target Compression]", argv[0]); exit(1); } else { szInputFilename = argv[1]; szOutputFilename = argv[2]; if (argc == 4) { fTargetCompressionOverride = (float)atof(argv[3]); } } // Initialize the ECW JPEG 2000 SDK libraries NCSecwInit(); // Open the input file eError = NCScbmOpenFileView(szInputFilename, &pNCSFileView, NULL); if (eError != NCS_SUCCESS) { ReportError("Could not open view for file:%s, Error = %s", szInputFilename, NCSGetErrorText(eError)); exit(1); } // Get input file information eError = NCScbmGetViewFileInfo(pNCSFileView, &pNCSFileInfo); if (eError != NCS_SUCCESS) { ReportError("Could not get file information for file:%s, Error = %s", szInputFilename, NCSGetErrorText(eError)); exit(1); } // Set up the input band list and set the view { INT32 *pBandList; pBandList = (UINT32 *)malloc(sizeof(UINT32) * pNCSFileInfo->nBands); if (pBandList == NULL) { ReportError("Unable to malloc band list."); // NOTREACHED } for (nBand = 0; nBand < pNCSFileInfo->nBands; nBand++) { pBandList[nBand] = nBand; } // Set the view we want to read (the whole file) eError = NCScbmSetFileView( pNCSFileView, pNCSFileInfo->nBands, pBandList, 0, 0, pNCSFileInfo->nSizeX-1, pNCSFileInfo->nSizeY-1, pNCSFileInfo->nSizeX, pNCSFileInfo->nSizeY); if (eError != NCS_SUCCESS) { ReportError("Error setting file view: %s", NCSGetErrorText(eError)); exit(1); } } // The read function wants an array of band buffers to store // the data in. We allocate one block of memory and then point // set up the band points to point to different locations within // it. Alternatively, we could allocate a separate buffer for each // band. pReadBuffer = (UINT8 *)malloc(sizeof(UINT8) * pNCSFileInfo->nSizeX * pNCSFileInfo->nBands); if (pReadBuffer == NULL) { ReportError("Could not malloc read buffer"); exit(1); } ppInputBandBufferArray = (UINT8 **)malloc(sizeof(UINT8 *) * pNCSFileInfo->nBands); if (ppInputBandBufferArray == NULL) { ReportError("Could not malloc band buffer array"); exit(1); } for (nBand = 0; nBand < pNCSFileInfo->nBands; nBand++) { ppInputBandBufferArray[nBand] = pReadBuffer + (nBand * pNCSFileInfo->nSizeX * sizeof(UINT8)); } // Now set up the output side of the task. First we need to // allocate and set up a client structure for the compression if (pClient = NCSEcwCompressAllocClient()) { NCSError eError; ReadInfo CompressReadInfo; // output filename strcpy(pClient->szOutputFilename, szOutputFilename); // Set up the target compression if (fTargetCompressionOverride != 0.0) { // User has specified a compression pClient->fTargetCompression = fTargetCompressionOverride; } else { // Use the same compression it was originally compressed with pClient->fTargetCompression = (float)pNCSFileInfo->nCompressionRate; } // Set up the input dimensions pClient->nInOutSizeX = pNCSFileInfo->nSizeX; pClient->nInOutSizeY = pNCSFileInfo->nSizeY; pClient->nInputBands = pNCSFileInfo->nBands; // Currently there isn't a way to find out what type of file we have, // so we make a guess based on the # of input bands. if(pClient->nInputBands == 1) { pClient->eCompressFormat = COMPRESS_UINT8; } else if(pClient->nInputBands == 3) { pClient->eCompressFormat = COMPRESS_RGB; } else { pClient->eCompressFormat = COMPRESS_MULTI; } // Set up optional projection information pClient->fCellIncrementX = pNCSFileInfo->fCellIncrementX; pClient->fCellIncrementY = pNCSFileInfo->fCellIncrementY; pClient->fOriginX = pNCSFileInfo->fOriginX; pClient->fOriginY = pNCSFileInfo->fOriginY; pClient->eCellSizeUnits = pNCSFileInfo->eCellSizeUnits; strcpy(pClient->szDatum, pNCSFileInfo->szDatum); strcpy(pClient->szProjection, pNCSFileInfo->szProjection); // Specify the callbacks and client data ptr pClient->pReadCallback = ReadCallback; pClient->pStatusCallback = StatusCallback; pClient->pCancelCallback = CancelCallback; // Set up client data for read callback CompressReadInfo.pNCSFileView = pNCSFileView; CompressReadInfo.ppInputBandBufferArray = ppInputBandBufferArray; CompressReadInfo.nPercentComplete = 0; CompressReadInfo.pErrorBuffer[0] = '\0'; pClient->pClientData = (void *)&CompressReadInfo; // Open the compression eError = NCSEcwCompressOpen(pClient, FALSE); if (eError != NCS_SUCCESS) { ReportError("NCSCompressOpen failed: %s", NCSGetErrorText(eError)); } else { // Opened OK, now do the compression eError = NCSEcwCompress(pClient); if (eError == NCS_COULDNT_READ_INPUT_LINE) { ReportError("Compression error: %s (%s)", NCSGetErrorText(eError), CompressReadInfo.pErrorBuffer); } else if (eError != NCS_SUCCESS) { ReportError("Compression error: %s", NCSGetErrorText(eError)); } else { // Compressed ok // Close the compression eError = NCSEcwCompressClose(pClient); if (eError != NCS_SUCCESS) { ReportError("NCSEcwCompressClose failed: %s", NCSGetErrorText(eError)); } // output stats fprintf(stdout, "Target ratio: %.1lf\r\n" "Actual ratio: %.1lf\r\n" #ifdef WIN32 "Output size: %I64d bytes\r\n" #else "Output size: %lld bytes\r\n" #endif "Time taken: %.1lf seconds\r\n" "Data Rate: %.1lf MB/s\r\n", pClient->fTargetCompression, pClient->fActualCompression, pClient->nOutputSize, pClient->fCompressionSeconds, pClient->fCompressionMBSec); fflush(stdout); } } // Free client NCSEcwCompressFreeClient(pClient); } else { // Couldn't alloc client structure ReportError("NCSEcwCompressAllocClient() failed!"); } // Shutdown library resources NCSecwShutdown(); fprintf(stdout, "Hit Enter to exit"); fflush(stdout); fgetc(stdin); return(0); }
/* ** main() */ int main(int argc, char **argv) { NCSEcwCompressClient *pClient; if (argc != 2) { fprintf(stderr,"Usage: %s <output filename>\r\n", argv[0]); exit(1); } /* ** Initialize library resources */ NCSecwInit(); /* ** First we need to alloc a client structure */ if(pClient = NCSEcwCompressAllocClient()) { NCSError eError; ReadInfo RI = { 0 }; /* ** Set up the input dimensions */ pClient->nInputBands = TEST_NR_BANDS; pClient->nInOutSizeX = TEST_WIDTH; pClient->nInOutSizeY = TEST_HEIGHT; /* ** Set format and ratio based on # of input bands ** ** Format can be: ** COMPRESS_UINT8 (Grayscale) ** COMPRESS_RGB (RGB) ** COMPRESS_MULTI (Multi band grayscale) ** COMPRESS_YUV (YUV) */ if(pClient->nInputBands == 1) { pClient->eCompressFormat = COMPRESS_UINT8; pClient->fTargetCompression = 20.0f; } else if(pClient->nInputBands == 3) { pClient->eCompressFormat = COMPRESS_RGB; pClient->fTargetCompression = 10.0f; } else { pClient->eCompressFormat = COMPRESS_MULTI; pClient->fTargetCompression = 20.0f; } /* ** Give output filename */ strcpy(pClient->szOutputFilename, argv[1]); /* ** Specify the callbacks and client data ptr */ pClient->pReadCallback = ReadCallback; pClient->pStatusCallback = StatusCallback; pClient->pCancelCallback = CancelCallback; pClient->pClientData = (void*)&RI; /* ** Open the compression */ eError = NCSEcwCompressOpen(pClient, FALSE); if(eError == NCS_SUCCESS) { /* ** Opened OK, now do the compression */ eError = NCSEcwCompress(pClient); /* ** Close the compression */ NCSEcwCompressClose(pClient); } if(eError == NCS_SUCCESS) { /* ** Compressed OK, output stats */ fprintf(stdout, "Target ratio: %.1lf\r\n" "Actual ratio: %.1lf\r\n" #ifdef WIN32 "Output size: %I64d bytes\r\n" #else "Output size: %lld bytes\r\n" #endif "Time taken: %.1lf seconds\r\n" "Data Rate: %.1lf MB/s\r\n", pClient->fTargetCompression, pClient->fActualCompression, pClient->nOutputSize, pClient->fCompressionSeconds, pClient->fCompressionMBSec); fflush(stdout); } else { /* ** Got an error, dump to stderr */ fprintf(stderr, "Compression error: %s\r\n", NCSGetErrorText(eError)); fflush(stderr); } /* ** Free client */ NCSEcwCompressFreeClient(pClient); } else { /* ** Couldn't alloc client structure */ fprintf(stderr, "NCSEcwCompressAllocClient() failed!"); fflush(stderr); } NCSecwShutdown(); fprintf(stdout, "Hit Enter to exit"); fflush(stdout); fgetc(stdin); return(0); }