int main( int argc, char ** argv ) { /* Check that we are running against at least GDAL 1.4 (probably older in fact !) */ /* Note to developers : if we use newer API, please change the requirement */ if (atoi(GDALVersionInfo("VERSION_NUM")) < 1400) { fprintf(stderr, "At least, GDAL >= 1.4.0 is required for this version of %s, " "which was compiled against GDAL %s\n", argv[0], GDAL_RELEASE_NAME); exit(1); } /* -------------------------------------------------------------------- */ /* Generic arg processing. */ /* -------------------------------------------------------------------- */ GDALAllRegister(); GDALSetCacheMax( 100000000 ); argc = GDALGeneralCmdLineProcessor( argc, &argv, 0 ); if( argc < 1 ) exit( -argc ); /* -------------------------------------------------------------------- */ /* Parse arguments. */ /* -------------------------------------------------------------------- */ int i; const char *pszOutFile = NULL; const char *pszInFile = NULL; int nMaxNonBlack = 2; int nNearDist = 15; int bNearWhite = FALSE; int bSetAlpha = FALSE; int bSetMask = FALSE; const char* pszDriverName = "HFA"; int bFormatExplicitelySet = FALSE; char** papszCreationOptions = NULL; int bQuiet = FALSE; Colors oColors; for( i = 1; i < argc; i++ ) { if( EQUAL(argv[i], "--utility_version") ) { printf("%s was compiled against GDAL %s and is running against GDAL %s\n", argv[0], GDAL_RELEASE_NAME, GDALVersionInfo("RELEASE_NAME")); return 0; } else if( EQUAL(argv[i], "-o") && i < argc-1 ) pszOutFile = argv[++i]; else if( EQUAL(argv[i], "-of") && i < argc-1 ) { pszDriverName = argv[++i]; bFormatExplicitelySet = TRUE; } else if( EQUAL(argv[i], "-white") ) { bNearWhite = TRUE; } /***** -color c1,c2,c3...cn *****/ else if( EQUAL(argv[i], "-color") && i < argc-1 ) { Color oColor; /***** tokenize the arg on , *****/ char **papszTokens; papszTokens = CSLTokenizeString2( argv[++i], ",", 0 ); /***** loop over the tokens *****/ int iToken; for( iToken = 0; papszTokens && papszTokens[iToken]; iToken++ ) { /***** ensure the token is an int and add it to the color *****/ if ( IsInt( papszTokens[iToken] ) ) oColor.push_back( atoi( papszTokens[iToken] ) ); else { CPLError(CE_Failure, CPLE_AppDefined, "Colors must be valid integers." ); CSLDestroy( papszTokens ); exit(1); } } CSLDestroy( papszTokens ); /***** check if the number of bands is consistant *****/ if ( oColors.size() > 0 && oColors.front().size() != oColor.size() ) { CPLError(CE_Failure, CPLE_AppDefined, "ERROR: all -color args must have the same number of values.\n" ); exit(1); } /***** add the color to the colors *****/ oColors.push_back( oColor ); } else if( EQUAL(argv[i], "-nb") && i < argc-1 ) nMaxNonBlack = atoi(argv[++i]); else if( EQUAL(argv[i], "-near") && i < argc-1 ) nNearDist = atoi(argv[++i]); else if( EQUAL(argv[i], "-setalpha") ) bSetAlpha = TRUE; else if( EQUAL(argv[i], "-setmask") ) bSetMask = TRUE; else if( EQUAL(argv[i], "-q") || EQUAL(argv[i], "-quiet") ) bQuiet = TRUE; else if( EQUAL(argv[i], "-co") && i < argc-1 ) papszCreationOptions = CSLAddString(papszCreationOptions, argv[++i]); else if( argv[i][0] == '-' ) Usage(); else if( pszInFile == NULL ) pszInFile = argv[i]; else Usage(); } if( pszInFile == NULL ) Usage(); if( pszOutFile == NULL ) pszOutFile = pszInFile; /* -------------------------------------------------------------------- */ /* Open input file. */ /* -------------------------------------------------------------------- */ GDALDatasetH hInDS, hOutDS = NULL; int nXSize, nYSize, nBands; if( pszOutFile == pszInFile ) hInDS = hOutDS = GDALOpen( pszInFile, GA_Update ); else hInDS = GDALOpen( pszInFile, GA_ReadOnly ); if( hInDS == NULL ) exit( 1 ); nXSize = GDALGetRasterXSize( hInDS ); nYSize = GDALGetRasterYSize( hInDS ); nBands = GDALGetRasterCount( hInDS ); int nDstBands = nBands; if( hOutDS != NULL && papszCreationOptions != NULL) { CPLError(CE_Warning, CPLE_AppDefined, "Warning: creation options are ignored when writing to an existing file."); } /* -------------------------------------------------------------------- */ /* Do we need to create output file? */ /* -------------------------------------------------------------------- */ if( hOutDS == NULL ) { GDALDriverH hDriver = GDALGetDriverByName( pszDriverName ); if (hDriver == NULL) exit(1); if (!bQuiet && !bFormatExplicitelySet) CheckExtensionConsistency(pszOutFile, pszDriverName); if (bSetAlpha) { /***** fixme there should be a way to preserve alpha band data not in the collar *****/ if (nBands == 4) nBands --; else nDstBands ++; } if (bSetMask) { if (nBands == 4) nDstBands = nBands = 3; } hOutDS = GDALCreate( hDriver, pszOutFile, nXSize, nYSize, nDstBands, GDT_Byte, papszCreationOptions ); if( hOutDS == NULL ) exit( 1 ); double adfGeoTransform[6]; if( GDALGetGeoTransform( hInDS, adfGeoTransform ) == CE_None ) { GDALSetGeoTransform( hOutDS, adfGeoTransform ); GDALSetProjection( hOutDS, GDALGetProjectionRef( hInDS ) ); } } else { if (bSetAlpha) { if (nBands != 4 && (nBands < 2 || GDALGetRasterColorInterpretation(GDALGetRasterBand(hOutDS, nBands)) != GCI_AlphaBand)) { CPLError(CE_Failure, CPLE_AppDefined, "Last band is not an alpha band."); exit(1); } nBands --; } if (bSetMask) { if (nBands == 4) nDstBands = nBands = 3; } } /***** set a color if there are no colors set? *****/ if ( oColors.size() == 0) { Color oColor; /***** loop over the bands to get the right number of values *****/ int iBand; for (iBand = 0; iBand < nBands ; iBand++) { /***** black or white? *****/ if (bNearWhite) oColor.push_back(255); else oColor.push_back(0); } /***** add the color to the colors *****/ oColors.push_back(oColor); } /***** does the number of bands match the number of color values? *****/ if ( (int)oColors.front().size() != nBands ) { CPLError( CE_Failure, CPLE_AppDefined, "-color args must have the same number of values as the non alpha input band count.\n" ); exit(1); } /***** check the input and output datasets are the same size *****/ if (GDALGetRasterXSize(hOutDS) != nXSize || GDALGetRasterYSize(hOutDS) != nYSize) { CPLError(CE_Failure, CPLE_AppDefined, "The dimensions of the output dataset don't match " "the dimensions of the input dataset."); exit(1); } int iBand; for( iBand = 0; iBand < nBands; iBand++ ) { GDALRasterBandH hBand = GDALGetRasterBand(hInDS, iBand+1); if (GDALGetRasterDataType(hBand) != GDT_Byte) { CPLError(CE_Warning, CPLE_AppDefined, "Band %d is not of type GDT_Byte. It can lead to unexpected results.", iBand+1); } if (GDALGetRasterColorTable(hBand) != NULL) { CPLError(CE_Warning, CPLE_AppDefined, "Band %d has a color table, which is ignored by nearblack. " "It can lead to unexpected results.", iBand+1); } } GDALRasterBandH hMaskBand = NULL; if (bSetMask) { /***** if there isn't already a mask band on the output file create one *****/ if ( GMF_PER_DATASET != GDALGetMaskFlags( GDALGetRasterBand(hOutDS, 1) ) ) { if ( CE_None != GDALCreateDatasetMaskBand(hOutDS, GMF_PER_DATASET) ) { CPLError(CE_Failure, CPLE_AppDefined, "Failed to create mask band on output DS"); bSetMask = FALSE; } } if (bSetMask) { hMaskBand = GDALGetMaskBand(GDALGetRasterBand(hOutDS, 1)); } } /* -------------------------------------------------------------------- */ /* Allocate a line buffer. */ /* -------------------------------------------------------------------- */ GByte *pabyLine; GByte *pabyMask=NULL; int *panLastLineCounts; pabyLine = (GByte *) CPLMalloc(nXSize * nDstBands); if (bSetMask) pabyMask = (GByte *) CPLMalloc(nXSize); panLastLineCounts = (int *) CPLCalloc(sizeof(int),nXSize); /* -------------------------------------------------------------------- */ /* Processing data one line at a time. */ /* -------------------------------------------------------------------- */ int iLine; for( iLine = 0; iLine < nYSize; iLine++ ) { CPLErr eErr; eErr = GDALDatasetRasterIO( hInDS, GF_Read, 0, iLine, nXSize, 1, pabyLine, nXSize, 1, GDT_Byte, nBands, NULL, nDstBands, nXSize * nDstBands, 1 ); if( eErr != CE_None ) break; if (bSetAlpha) { int iCol; for(iCol = 0; iCol < nXSize; iCol ++) { pabyLine[iCol * nDstBands + nDstBands - 1] = 255; } } if (bSetMask) { int iCol; for(iCol = 0; iCol < nXSize; iCol ++) { pabyMask[iCol] = 255; } } ProcessLine( pabyLine, pabyMask, 0, nXSize-1, nBands, nDstBands, nNearDist, nMaxNonBlack, bNearWhite, &oColors, panLastLineCounts, TRUE, // bDoHorizontalCheck TRUE, // bDoVerticalCheck FALSE // bBottomUp ); ProcessLine( pabyLine, pabyMask, nXSize-1, 0, nBands, nDstBands, nNearDist, nMaxNonBlack, bNearWhite, &oColors, panLastLineCounts, TRUE, // bDoHorizontalCheck FALSE, // bDoVerticalCheck FALSE // bBottomUp ); eErr = GDALDatasetRasterIO( hOutDS, GF_Write, 0, iLine, nXSize, 1, pabyLine, nXSize, 1, GDT_Byte, nDstBands, NULL, nDstBands, nXSize * nDstBands, 1 ); if( eErr != CE_None ) break; /***** write out the mask band line *****/ if (bSetMask) { eErr = GDALRasterIO ( hMaskBand, GF_Write, 0, iLine, nXSize, 1, pabyMask, nXSize, 1, GDT_Byte, 0, 0 ); if( eErr != CE_None ) { CPLError(CE_Warning, CPLE_AppDefined, "ERROR writeing out line to mask band."); break; } } if (!bQuiet) GDALTermProgress( 0.5 * ((iLine+1) / (double) nYSize), NULL, NULL ); } /* -------------------------------------------------------------------- */ /* Now process from the bottom back up .*/ /* -------------------------------------------------------------------- */ memset( panLastLineCounts, 0, sizeof(int) * nXSize); for( iLine = nYSize-1; iLine >= 0; iLine-- ) { CPLErr eErr; eErr = GDALDatasetRasterIO( hOutDS, GF_Read, 0, iLine, nXSize, 1, pabyLine, nXSize, 1, GDT_Byte, nDstBands, NULL, nDstBands, nXSize * nDstBands, 1 ); if( eErr != CE_None ) break; /***** read the mask band line back in *****/ if (bSetMask) { eErr = GDALRasterIO ( hMaskBand, GF_Read, 0, iLine, nXSize, 1, pabyMask, nXSize, 1, GDT_Byte, 0, 0 ); if( eErr != CE_None ) break; } ProcessLine( pabyLine, pabyMask, 0, nXSize-1, nBands, nDstBands, nNearDist, nMaxNonBlack, bNearWhite, &oColors, panLastLineCounts, TRUE, // bDoHorizontalCheck TRUE, // bDoVerticalCheck TRUE // bBottomUp ); ProcessLine( pabyLine, pabyMask, nXSize-1, 0, nBands, nDstBands, nNearDist, nMaxNonBlack, bNearWhite, &oColors, panLastLineCounts, TRUE, // bDoHorizontalCheck FALSE, // bDoVerticalCheck TRUE // bBottomUp ); eErr = GDALDatasetRasterIO( hOutDS, GF_Write, 0, iLine, nXSize, 1, pabyLine, nXSize, 1, GDT_Byte, nDstBands, NULL, nDstBands, nXSize * nDstBands, 1 ); if( eErr != CE_None ) break; /***** write out the mask band line *****/ if (bSetMask) { eErr = GDALRasterIO ( hMaskBand, GF_Write, 0, iLine, nXSize, 1, pabyMask, nXSize, 1, GDT_Byte, 0, 0 ); if( eErr != CE_None ) break; } if (!bQuiet) GDALTermProgress( 0.5 + 0.5 * (nYSize-iLine) / (double) nYSize, NULL, NULL ); } CPLFree(pabyLine); if (bSetMask) CPLFree(pabyMask); CPLFree( panLastLineCounts ); GDALClose( hOutDS ); if( hInDS != hOutDS ) GDALClose( hInDS ); GDALDumpOpenDatasets( stderr ); CSLDestroy( argv ); CSLDestroy( papszCreationOptions ); GDALDestroyDriverManager(); return 0; }
int main( int argc, char ** argv ) { /* Check that we are running against at least GDAL 1.4 (probably older in fact !) */ /* Note to developers : if we use newer API, please change the requirement */ if (atoi(GDALVersionInfo("VERSION_NUM")) < 1400) { fprintf(stderr, "At least, GDAL >= 1.4.0 is required for this version of %s, " "which was compiled against GDAL %s\n", argv[0], GDAL_RELEASE_NAME); exit(1); } /* -------------------------------------------------------------------- */ /* Generic arg processing. */ /* -------------------------------------------------------------------- */ GDALAllRegister(); GDALSetCacheMax( 100000000 ); argc = GDALGeneralCmdLineProcessor( argc, &argv, 0 ); if( argc < 1 ) exit( -argc ); /* -------------------------------------------------------------------- */ /* Parse arguments. */ /* -------------------------------------------------------------------- */ int i; const char *pszOutFile = NULL; const char *pszInFile = NULL; int nMaxNonBlack = 2; int nNearDist = 15; int bNearWhite = FALSE; for( i = 1; i < argc; i++ ) { if( EQUAL(argv[i], "--utility_version") ) { printf("%s was compiled against GDAL %s and is running against GDAL %s\n", argv[0], GDAL_RELEASE_NAME, GDALVersionInfo("RELEASE_NAME")); return 0; } else if( EQUAL(argv[i], "-o") && i < argc-1 ) pszOutFile = argv[++i]; else if( EQUAL(argv[i], "-white") ) bNearWhite = TRUE; else if( EQUAL(argv[i], "-nb") && i < argc-1 ) nMaxNonBlack = atoi(argv[++i]); else if( EQUAL(argv[i], "-near") && i < argc-1 ) nNearDist = atoi(argv[++i]); else if( argv[i][0] == '-' ) Usage(); else if( pszInFile == NULL ) pszInFile = argv[i]; else Usage(); } if( pszInFile == NULL ) Usage(); if( pszOutFile == NULL ) pszOutFile = pszInFile; /* -------------------------------------------------------------------- */ /* Open input file. */ /* -------------------------------------------------------------------- */ GDALDatasetH hInDS, hOutDS = NULL; int nXSize, nYSize, nBands; if( pszOutFile == pszInFile ) hInDS = hOutDS = GDALOpen( pszInFile, GA_Update ); else hInDS = GDALOpen( pszInFile, GA_ReadOnly ); if( hInDS == NULL ) exit( 1 ); nXSize = GDALGetRasterXSize( hInDS ); nYSize = GDALGetRasterYSize( hInDS ); nBands = GDALGetRasterCount( hInDS ); /* -------------------------------------------------------------------- */ /* Do we need to create output file? */ /* -------------------------------------------------------------------- */ if( hOutDS == NULL ) { GDALDriverH hDriver = GDALGetDriverByName( "HFA" ); hOutDS = GDALCreate( hDriver, pszOutFile, nXSize, nYSize, nBands, GDT_Byte, NULL ); if( hOutDS == NULL ) exit( 1 ); double adfGeoTransform[6]; if( GDALGetGeoTransform( hInDS, adfGeoTransform ) == CE_None ) { GDALSetGeoTransform( hOutDS, adfGeoTransform ); GDALSetProjection( hOutDS, GDALGetProjectionRef( hInDS ) ); } } int iBand; for( iBand = 0; iBand < nBands; iBand++ ) { GDALRasterBandH hBand = GDALGetRasterBand(hInDS, iBand+1); if (GDALGetRasterDataType(hBand) != GDT_Byte) { CPLError(CE_Warning, CPLE_AppDefined, "Band %d is not of type GDT_Byte. It can lead to unexpected results.", iBand+1); } if (GDALGetRasterColorTable(hBand) != NULL) { CPLError(CE_Warning, CPLE_AppDefined, "Band %d has a color table, which is ignored by nearblack. " "It can lead to unexpected results.", iBand+1); } } /* -------------------------------------------------------------------- */ /* Allocate a line buffer. */ /* -------------------------------------------------------------------- */ GByte *pabyLine; int *panLastLineCounts; pabyLine = (GByte *) CPLMalloc(nXSize * nBands); panLastLineCounts = (int *) CPLCalloc(sizeof(int),nXSize); /* -------------------------------------------------------------------- */ /* Processing data one line at a time. */ /* -------------------------------------------------------------------- */ int iLine; for( iLine = 0; iLine < nYSize; iLine++ ) { CPLErr eErr; eErr = GDALDatasetRasterIO( hInDS, GF_Read, 0, iLine, nXSize, 1, pabyLine, nXSize, 1, GDT_Byte, nBands, NULL, nBands, nXSize * nBands, 1 ); if( eErr != CE_None ) break; ProcessLine( pabyLine, 0, nXSize-1, nBands, nNearDist, nMaxNonBlack, bNearWhite, panLastLineCounts, TRUE, TRUE ); ProcessLine( pabyLine, nXSize-1, 0, nBands, nNearDist, nMaxNonBlack, bNearWhite, NULL, TRUE, FALSE ); eErr = GDALDatasetRasterIO( hOutDS, GF_Write, 0, iLine, nXSize, 1, pabyLine, nXSize, 1, GDT_Byte, nBands, NULL, nBands, nXSize * nBands, 1 ); if( eErr != CE_None ) break; GDALTermProgress( 0.5 * ((iLine+1) / (double) nYSize), NULL, NULL ); } /* -------------------------------------------------------------------- */ /* Now process from the bottom back up, doing only the vertical pass.*/ /* -------------------------------------------------------------------- */ memset( panLastLineCounts, 0, sizeof(int) * nXSize); for( iLine = nYSize-1; iLine >= 0; iLine-- ) { CPLErr eErr; eErr = GDALDatasetRasterIO( hOutDS, GF_Read, 0, iLine, nXSize, 1, pabyLine, nXSize, 1, GDT_Byte, nBands, NULL, nBands, nXSize * nBands, 1 ); if( eErr != CE_None ) break; ProcessLine( pabyLine, 0, nXSize-1, nBands, nNearDist, nMaxNonBlack, bNearWhite, panLastLineCounts, FALSE, TRUE ); eErr = GDALDatasetRasterIO( hOutDS, GF_Write, 0, iLine, nXSize, 1, pabyLine, nXSize, 1, GDT_Byte, nBands, NULL, nBands, nXSize * nBands, 1 ); if( eErr != CE_None ) break; GDALTermProgress( 0.5 + 0.5 * (nYSize-iLine) / (double) nYSize, NULL, NULL ); } CPLFree(pabyLine); CPLFree( panLastLineCounts ); GDALClose( hOutDS ); if( hInDS != hOutDS ) GDALClose( hInDS ); GDALDumpOpenDatasets( stderr ); GDALDestroyDriverManager(); return 0; }
// // Compute histogram of a GDAL image // int main(int argc, char* argv[]) { GDALSetCacheMax(512*1024*1024); GDALAllRegister(); int format = 3; // most compressed. format 4 is Mark Aubin's format int merge = 0; int verbose = 0; char output[1024] = "histogram.txt"; char input[1024] = {0}; char *filelist = NULL; // parse command line 'option arguments' int cursor; for (cursor = 1; cursor < argc && argv[cursor][0] == '-'; cursor++) { if (strcmp(argv[cursor], "-filelist") == 0) { filelist = argv[++cursor]; } else if (strcmp(argv[cursor], "--filelist") == 0) { filelist = argv[++cursor]; } else if (strcmp(argv[cursor], "-f") == 0) { if (sscanf(argv[cursor], "-f%d", &format) != 1) sscanf(argv[++cursor], "%d", &format); } else if (strcmp(argv[cursor], "-i") == 0) { if (sscanf(argv[cursor], "-i%s", input) != 1) sscanf(argv[++cursor], "%s", input); } else if (strcmp(argv[cursor], "-o") == 0) { if (sscanf(argv[cursor], "-o%s", output) != 1) sscanf(argv[++cursor], "%s", output); } else if (strcmp(argv[cursor], "-i") == 0) { if (sscanf(argv[cursor], "-i%s", input) != 1) sscanf(argv[++cursor], "%s", input); } else if (strcmp(argv[cursor], "-m") == 0) { merge = 1; } else if (strcmp(argv[cursor], "-v") == 0) { verbose = 1; } else if (strcmp(argv[cursor], "-i") == 0) { if (sscanf(argv[cursor], "-i%s", input) != 1) sscanf(argv[++cursor], "%s", input); } else { printf("error: unknown option '%s'\n", argv[cursor]); return 1; } } // process remaining argument, if any if (cursor < argc && input[0] == '\0') strcpy(input, argv[cursor++]); // validate configuration if ((filelist == NULL || filelist[0] == '\0') && input[0] == '\0') { printf("usage: histogram [-f format][-i input][-o output][-m][-filelist name] [input]\n"); printf(" default format is 3 (most compressed representation)\n"); printf(" default output file name is 'histogram.txt'\n"); return 2; } if (filelist != 0) { // open file list FILE *fp; if ((fp = fopen(filelist, "r")) == NULL) { printf("error: unable to open filelist '%s'\n", filelist); exit(2); } // process each file in list if (merge == 0) { char nextName[2048]; while (fscanf(fp, "%s", nextName) == 1) { if (verbose) printf("%s\n", nextName); // compute histogram KHistogram h; if (h.histogramGDAL(nextName)) { printf("error: unable to compute histogram from file '%s'\n", nextName); return 1; } char *dot = strrchr(nextName, '.'); if (dot != NULL) { *dot = '\0'; } sprintf(output, "%s.his", nextName); // write histogram if (h.write(output, format)) { printf("error: unable to write histogram to file '%s'\n", output); return 2; } } } else { char nextName[2048]; KHistogram m; while (fscanf(fp, "%s", nextName) == 1) { KHistogram h; if (verbose) printf("%s\n", nextName); // histogram or file? char *dot = strrchr(nextName, '.'); if (dot != NULL && strncmp(dot, ".his", 4) == 0) { if (h.read(nextName) == 0) m.accumulate(h); else printf("warning: unable to load histogram from file '%s'\n", nextName); } else { if (h.histogramGDAL(nextName) == 0) m.accumulate(h); else printf("warning: unable to compute histogram from file '%s'\n", nextName); } } // write histogram if (m.write(output, format)) { printf("error: unable to write histogram to file '%s'\n", output); return 2; } } // close file list fclose(fp); } else { if (merge == 0) { // compute histogram KHistogram h; if (h.histogramGDAL(input)) { printf("error: unable to compute histogram from file '%s'\n", input); return 1; } // write histogram if (h.write(output, format)) { printf("error: unable to write histogram to file '%s'\n", output); return 2; } } else { KHistogram m; for (--cursor; cursor < argc; cursor++) { KHistogram h; if (verbose) printf("%s\n", argv[cursor]); // histogram or file? char *dot = strrchr(argv[cursor], '.'); if (dot != NULL && strncmp(dot, ".his", 4) == 0) { if (h.read(argv[cursor]) == 0) m.accumulate(h); else printf("warning: unable to load histogram from file '%s'\n", argv[cursor]); } else { if (h.histogramGDAL(argv[cursor]) == 0) m.accumulate(h); else printf("warning: unable to compute histogram from file '%s'\n", argv[cursor]); } } // write histogram if (m.write(output, format)) { printf("error: unable to write histogram to file '%s'\n", output); return 2; } } } // normal termination return 0; }
int main(int /* argc*/ , char* /* argv */[]) { int nOvrLevel; int nBandNum; GDALDatasetH hDS; GDALDatasetH hSrcDS; FILE* f; const char* pszGDAL_SKIP = CPLGetConfigOption("GDAL_SKIP", NULL); if( pszGDAL_SKIP == NULL ) CPLSetConfigOption("GDAL_SKIP", "GIF"); else CPLSetConfigOption("GDAL_SKIP", CPLSPrintf("%s GIF", pszGDAL_SKIP)); GDALAllRegister(); hDS = GDALOpen("../gcore/data/byte.tif", GA_ReadOnly); if (hDS) GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0, GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS)); hDS = GDALOpen("../gcore/data/byte.vrt", GA_ReadOnly); if (hDS) GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0, GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS)); hDS = GDALOpen("../gdrivers/data/rgb_warp.vrt", GA_ReadOnly); if (hDS) GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0, GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS)); hDS = GDALOpen("../gdrivers/data/A.TOC", GA_ReadOnly); hDS = GDALOpen("NITF_TOC_ENTRY:CADRG_ONC_1,000,000_2_0:../gdrivers/data/A.TOC", GA_ReadOnly); if (hDS) GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0, GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS)); hDS = GDALOpen("../gdrivers/data/testtil.til", GA_ReadOnly); if (hDS) GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0, GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS)); hDS = GDALOpen("../gdrivers/data/product.xml", GA_ReadOnly); if (hDS) GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0, GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS)); hDS = GDALOpen("../gdrivers/data/METADATA.DIM", GA_ReadOnly); if (hDS) GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0, GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS)); hDS = GDALOpen("../gdrivers/tmp/cache/file9_j2c.ntf", GA_ReadOnly); if (hDS) GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0, GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS)); hDS = GDALOpen("../gdrivers/data/bug407.gif", GA_ReadOnly); if (hDS) { GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0, GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS)); GDALSetCacheMax(0); GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0, GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS)); } /* Create external overviews */ hSrcDS = GDALOpen("../gcore/data/byte.tif", GA_ReadOnly); hDS = GDALCreateCopy(GDALGetDriverByName("GTiff"), "byte.tif", hSrcDS, 0, NULL, NULL, NULL); GDALClose(hSrcDS); hSrcDS = NULL; hDS = GDALOpen("byte.tif", GA_ReadOnly); nOvrLevel = 2; nBandNum = 1; GDALBuildOverviews( hDS, "NEAR", 1, &nOvrLevel, 1, &nBandNum, NULL, NULL); GDALClose(hDS); hDS = GDALOpen("byte.tif", GA_ReadOnly); GDALGetOverviewCount(GDALGetRasterBand(hDS, 1)); /* Create internal overviews */ hSrcDS = GDALOpen("../gcore/data/byte.tif", GA_ReadOnly); hDS = GDALCreateCopy(GDALGetDriverByName("GTiff"), "byte2.tif", hSrcDS, 0, NULL, NULL, NULL); GDALClose(hSrcDS); hSrcDS = NULL; hDS = GDALOpen("byte2.tif", GA_Update); nOvrLevel = 2; nBandNum = 1; GDALBuildOverviews( hDS, "NEAR", 1, &nOvrLevel, 1, &nBandNum, NULL, NULL); GDALClose(hDS); hDS = GDALOpen("byte2.tif", GA_ReadOnly); GDALGetOverviewCount(GDALGetRasterBand(hDS, 1)); /* Create external mask */ hSrcDS = GDALOpen("../gcore/data/byte.tif", GA_ReadOnly); hDS = GDALCreateCopy(GDALGetDriverByName("GTiff"), "byte3.tif", hSrcDS, 0, NULL, NULL, NULL); GDALClose(hSrcDS); hSrcDS = NULL; hDS = GDALOpen("byte3.tif", GA_ReadOnly); GDALCreateDatasetMaskBand(hDS, GMF_PER_DATASET); GDALClose(hDS); hDS = GDALOpen("byte3.tif", GA_ReadOnly); GDALGetMaskFlags(GDALGetRasterBand(hDS, 1)); f = fopen("byte.vrt", "wb"); fprintf(f, "%s", "<VRTDataset rasterXSize=\"20\" rasterYSize=\"20\">" "<VRTRasterBand dataType=\"Byte\" band=\"1\">" "<SimpleSource>" "<SourceFilename relativeToVRT=\"1\">../gcore/data/byte.tif</SourceFilename>" "<SourceBand>1</SourceBand>" "<SourceProperties RasterXSize=\"20\" RasterYSize=\"20\" DataType=\"Byte\" BlockXSize=\"20\" BlockYSize=\"20\" />" "<SrcRect xOff=\"0\" yOff=\"0\" xSize=\"20\" ySize=\"20\"/>" "<DstRect xOff=\"0\" yOff=\"0\" xSize=\"20\" ySize=\"20\"/>" "</SimpleSource>" "</VRTRasterBand>" "</VRTDataset>"); fclose(f); hDS = GDALOpen("byte.vrt", GA_ReadOnly); nOvrLevel = 2; nBandNum = 1; GDALBuildOverviews( hDS, "NEAR", 1, &nOvrLevel, 1, &nBandNum, NULL, NULL); GDALClose(hDS); hDS = GDALOpen("byte.vrt", GA_ReadOnly); GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0, GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS)); GDALGetOverviewCount(GDALGetRasterBand(hDS, 1)); hDS = GDALOpen("<VRTDataset rasterXSize=\"20\" rasterYSize=\"20\">" "<VRTRasterBand dataType=\"Byte\" band=\"1\">" "<SimpleSource>" "<SourceFilename relativeToVRT=\"1\">byte.vrt</SourceFilename>" "<SourceBand>1</SourceBand>" "<SourceProperties RasterXSize=\"20\" RasterYSize=\"20\" DataType=\"Byte\" BlockXSize=\"20\" BlockYSize=\"20\" />" "<SrcRect xOff=\"0\" yOff=\"0\" xSize=\"20\" ySize=\"20\"/>" "<DstRect xOff=\"0\" yOff=\"0\" xSize=\"20\" ySize=\"20\"/>" "</SimpleSource>" "</VRTRasterBand>" "</VRTDataset>", GA_ReadOnly); GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0, GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS)); hDS = GDALOpenShared("../gcore/data/byte.tif", GA_ReadOnly); hDS = GDALOpenShared("../gcore/data/byte.tif", GA_ReadOnly); hDS = GDALOpenShared("../gdrivers/data/mercator.sid", GA_ReadOnly); hDS = GDALOpen("RASTERLITE:../gdrivers/data/rasterlite_pyramids.sqlite,table=test", GA_ReadOnly); hDS = GDALOpen("RASTERLITE:../gdrivers/data/rasterlite_pyramids.sqlite,table=test,level=1", GA_ReadOnly); OpenJPEG2000("../gdrivers/data/rgbwcmyk01_YeGeo_kakadu.jp2"); hDS = GDALOpen("../gdrivers/tmp/cache/Europe 2001_OZF.map", GA_ReadOnly); CPLDebug("TEST","Call GDALDestroyDriverManager()"); GDALDestroyDriverManager(); unlink("byte.tif"); unlink("byte.tif.ovr"); unlink("byte2.tif"); unlink("byte3.tif"); unlink("byte3.tif.msk"); unlink("byte.vrt"); return 0; }