本文整理汇总了C++中GDALColorTable::GetColorEntryCount方法的典型用法代码示例。如果您正苦于以下问题:C++ GDALColorTable::GetColorEntryCount方法的具体用法?C++ GDALColorTable::GetColorEntryCount怎么用?C++ GDALColorTable::GetColorEntryCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GDALColorTable
的用法示例。
在下文中一共展示了GDALColorTable::GetColorEntryCount方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadLUT
void ReadLUT(GDALRasterBand* rasterBand, TeRasterParams& params)
{
GDALColorTable* colorTable = rasterBand->GetColorTable();
if(colorTable == 0)
return;
int ncolors = colorTable->GetColorEntryCount();
for(int i = 0; i < ncolors; ++i)
{
const GDALColorEntry* ce = colorTable->GetColorEntry(i);
if(ce == 0)
continue;
params.lutr_.push_back(ce->c1);
params.lutg_.push_back(ce->c2);
params.lutb_.push_back(ce->c3);
}
}
示例2: CALSWrapperSrcBand
CALSWrapperSrcBand(GDALDataset* poSrcDSIn)
{
this->poSrcDS = poSrcDSIn;
SetMetadataItem("NBITS", "1", "IMAGE_STRUCTURE");
poSrcDS->GetRasterBand(1)->GetBlockSize(&nBlockXSize, &nBlockYSize);
eDataType = GDT_Byte;
bInvertValues = TRUE;
GDALColorTable* poCT = poSrcDS->GetRasterBand(1)->GetColorTable();
if( poCT != NULL && poCT->GetColorEntryCount() >= 2 )
{
const GDALColorEntry* psEntry1 = poCT->GetColorEntry(0);
const GDALColorEntry* psEntry2 = poCT->GetColorEntry(1);
if( psEntry1->c1 == 255 && psEntry1->c2 == 255 && psEntry1->c3 == 255 &&
psEntry2->c1 == 0 && psEntry2->c2 == 0 && psEntry2->c3 == 0 )
{
bInvertValues = FALSE;
}
}
}
示例3: if
CMapRaster::CMapRaster(const QString& fn, CCanvas * parent)
: IMap(eRaster, "",parent)
, x(0)
, y(0)
, zoomlevel(1)
, zoomfactor(1.0)
, rasterBandCount(0)
{
filename = fn;
#ifdef WIN32
dataset = (GDALDataset*)GDALOpen(filename.toLocal8Bit(),GA_ReadOnly);
#else
dataset = (GDALDataset*)GDALOpen(filename.toUtf8(),GA_ReadOnly);
#endif
if(dataset == 0)
{
QMessageBox::warning(0, tr("Error..."), tr("Failed to load file: %1").arg(filename));
return;
}
rasterBandCount = dataset->GetRasterCount();
if(rasterBandCount == 1)
{
GDALRasterBand * pBand;
pBand = dataset->GetRasterBand(1);
if(pBand == 0)
{
delete dataset; dataset = 0;
QMessageBox::warning(0, tr("Error..."), tr("Failed to load file: %1").arg(filename));
return;
}
if(pBand->GetColorInterpretation() != GCI_PaletteIndex && pBand->GetColorInterpretation() != GCI_GrayIndex)
{
delete dataset; dataset = 0;
QMessageBox::warning(0, tr("Error..."), tr("File must be 8 bit palette or gray indexed."));
return;
}
if(pBand->GetColorInterpretation() == GCI_PaletteIndex )
{
GDALColorTable * pct = pBand->GetColorTable();
for(int i=0; i < pct->GetColorEntryCount(); ++i)
{
const GDALColorEntry& e = *pct->GetColorEntry(i);
colortable << qRgba(e.c1, e.c2, e.c3, e.c4);
}
}
else if(pBand->GetColorInterpretation() == GCI_GrayIndex )
{
for(int i=0; i < 256; ++i)
{
colortable << qRgba(i, i, i, 255);
}
}
else
{
delete dataset; dataset = 0;
QMessageBox::warning(0, tr("Error..."), tr("File must be 8 bit palette or gray indexed."));
return;
}
int success = 0;
double idx = pBand->GetNoDataValue(&success);
if(success)
{
QColor tmp(colortable[idx]);
tmp.setAlpha(0);
colortable[idx] = tmp.rgba();
}
}
maparea.setWidth(dataset->GetRasterXSize());
maparea.setHeight(dataset->GetRasterYSize());
}
示例4: CSLFetchBoolean
//.........这里部分代码省略.........
#endif
if( hGifFile == NULL )
{
VSIFCloseL( fp );
CPLError( CE_Failure, CPLE_OpenFailed,
"EGifOpenFilename(%s) failed. Does file already exist?",
pszFilename );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Prepare colortable. */
/* -------------------------------------------------------------------- */
GDALRasterBand *poBand = poSrcDS->GetRasterBand(1);
ColorMapObject *psGifCT;
int iColor;
if( poBand->GetColorTable() == NULL )
{
psGifCT = GifMakeMapObject( 256, NULL );
for( iColor = 0; iColor < 256; iColor++ )
{
psGifCT->Colors[iColor].Red = (GifByteType) iColor;
psGifCT->Colors[iColor].Green = (GifByteType) iColor;
psGifCT->Colors[iColor].Blue = (GifByteType) iColor;
}
}
else
{
GDALColorTable *poCT = poBand->GetColorTable();
int nFullCount = 1;
while( nFullCount < poCT->GetColorEntryCount() )
nFullCount = nFullCount * 2;
psGifCT = GifMakeMapObject( nFullCount, NULL );
for( iColor = 0; iColor < poCT->GetColorEntryCount(); iColor++ )
{
GDALColorEntry sEntry;
poCT->GetColorEntryAsRGB( iColor, &sEntry );
psGifCT->Colors[iColor].Red = (GifByteType) sEntry.c1;
psGifCT->Colors[iColor].Green = (GifByteType) sEntry.c2;
psGifCT->Colors[iColor].Blue = (GifByteType) sEntry.c3;
}
for( ; iColor < nFullCount; iColor++ )
{
psGifCT->Colors[iColor].Red = 0;
psGifCT->Colors[iColor].Green = 0;
psGifCT->Colors[iColor].Blue = 0;
}
}
/* -------------------------------------------------------------------- */
/* Setup parameters. */
/* -------------------------------------------------------------------- */
if (EGifPutScreenDesc(hGifFile, nXSize, nYSize,
psGifCT->ColorCount, 255, psGifCT) == GIF_ERROR)
{
GifFreeMapObject(psGifCT);
GDALPrintGifError(hGifFile, "Error writing gif file.");
GIFAbstractDataset::myEGifCloseFile(hGifFile);
VSIFCloseL( fp );
return NULL;
}
示例5: if
static GDALDataset *
BSBCreateCopy( const char * pszFilename, GDALDataset *poSrcDS,
int bStrict, char ** papszOptions,
GDALProgressFunc pfnProgress, void * pProgressData )
{
int nBands = poSrcDS->GetRasterCount();
int nXSize = poSrcDS->GetRasterXSize();
int nYSize = poSrcDS->GetRasterYSize();
/* -------------------------------------------------------------------- */
/* Some some rudimentary checks */
/* -------------------------------------------------------------------- */
if( nBands != 1 )
{
CPLError( CE_Failure, CPLE_NotSupported,
"BSB driver only supports one band images.\n" );
return NULL;
}
if( poSrcDS->GetRasterBand(1)->GetRasterDataType() != GDT_Byte
&& bStrict )
{
CPLError( CE_Failure, CPLE_NotSupported,
"BSB driver doesn't support data type %s. "
"Only eight bit bands supported.\n",
GDALGetDataTypeName(
poSrcDS->GetRasterBand(1)->GetRasterDataType()) );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Open the output file. */
/* -------------------------------------------------------------------- */
BSBInfo *psBSB;
psBSB = BSBCreate( pszFilename, 0, 200, nXSize, nYSize );
if( psBSB == NULL )
return NULL;
/* -------------------------------------------------------------------- */
/* Prepare initial color table.colortable. */
/* -------------------------------------------------------------------- */
GDALRasterBand *poBand = poSrcDS->GetRasterBand(1);
int iColor;
unsigned char abyPCT[771];
int nPCTSize;
int anRemap[256];
abyPCT[0] = 0;
abyPCT[1] = 0;
abyPCT[2] = 0;
if( poBand->GetColorTable() == NULL )
{
/* map greyscale down to 63 grey levels. */
for( iColor = 0; iColor < 256; iColor++ )
{
int nOutValue = (int) (iColor / 4.1) + 1;
anRemap[iColor] = nOutValue;
abyPCT[nOutValue*3 + 0] = (unsigned char) iColor;
abyPCT[nOutValue*3 + 1] = (unsigned char) iColor;
abyPCT[nOutValue*3 + 2] = (unsigned char) iColor;
}
nPCTSize = 64;
}
else
{
GDALColorTable *poCT = poBand->GetColorTable();
int nColorTableSize = poCT->GetColorEntryCount();
if (nColorTableSize > 255)
nColorTableSize = 255;
for( iColor = 0; iColor < nColorTableSize; iColor++ )
{
GDALColorEntry sEntry;
poCT->GetColorEntryAsRGB( iColor, &sEntry );
anRemap[iColor] = iColor + 1;
abyPCT[(iColor+1)*3 + 0] = (unsigned char) sEntry.c1;
abyPCT[(iColor+1)*3 + 1] = (unsigned char) sEntry.c2;
abyPCT[(iColor+1)*3 + 2] = (unsigned char) sEntry.c3;
}
nPCTSize = nColorTableSize + 1;
// Add entries for pixel values which apparently will not occur.
for( iColor = nPCTSize; iColor < 256; iColor++ )
anRemap[iColor] = 1;
}
/* -------------------------------------------------------------------- */
/* Boil out all duplicate entries. */
/* -------------------------------------------------------------------- */
int i;
//.........这里部分代码省略.........
示例6: loadFile
//.........这里部分代码省略.........
bool zRasterProcessed = false;
unsigned zInvalid = 0;
double zMinMax[2] = {0, 0};
for (int i=1; i<=rasterCount; ++i)
{
ccLog::Print( "Reading band #%i", i);
GDALRasterBand* poBand = poDataset->GetRasterBand(i);
GDALColorInterp colorInterp = poBand->GetColorInterpretation();
GDALDataType bandType = poBand->GetRasterDataType();
int nBlockXSize, nBlockYSize;
poBand->GetBlockSize( &nBlockXSize, &nBlockYSize );
ccLog::Print( "Block=%dx%d Type=%s, ColorInterp=%s", nBlockXSize, nBlockYSize, GDALGetDataTypeName(poBand->GetRasterDataType()), GDALGetColorInterpretationName(colorInterp) );
//fetching raster scan-line
int nXSize = poBand->GetXSize();
int nYSize = poBand->GetYSize();
assert(nXSize == rasterX);
assert(nYSize == rasterY);
int bGotMin, bGotMax;
double adfMinMax[2] = {0, 0};
adfMinMax[0] = poBand->GetMinimum( &bGotMin );
adfMinMax[1] = poBand->GetMaximum( &bGotMax );
if (!bGotMin || !bGotMax )
//DGM FIXME: if the file is corrupted (e.g. ASCII ArcGrid with missing rows) this method will enter in a infinite loop!
GDALComputeRasterMinMax((GDALRasterBandH)poBand, TRUE, adfMinMax);
ccLog::Print( "Min=%.3fd, Max=%.3f", adfMinMax[0], adfMinMax[1] );
GDALColorTable* colTable = poBand->GetColorTable();
if( colTable != NULL )
printf( "Band has a color table with %d entries", colTable->GetColorEntryCount() );
if( poBand->GetOverviewCount() > 0 )
printf( "Band has %d overviews", poBand->GetOverviewCount() );
if (colorInterp == GCI_Undefined && !zRasterProcessed/*&& !colTable*/) //probably heights?
{
zRasterProcessed = true;
zMinMax[0] = adfMinMax[0];
zMinMax[1] = adfMinMax[1];
double* scanline = (double*) CPLMalloc(sizeof(double)*nXSize);
//double* scanline = new double[nXSize];
memset(scanline,0,sizeof(double)*nXSize);
for (int j=0; j<nYSize; ++j)
{
if (poBand->RasterIO( GF_Read, /*xOffset=*/0, /*yOffset=*/j, /*xSize=*/nXSize, /*ySize=*/1, /*buffer=*/scanline, /*bufferSizeX=*/nXSize, /*bufferSizeY=*/1, /*bufferType=*/GDT_Float64, /*x_offset=*/0, /*y_offset=*/0 ) != CE_None)
{
delete pc;
CPLFree(scanline);
GDALClose(poDataset);
return CC_FERR_READING;
}
for (int k=0; k<nXSize; ++k)
{
double z = static_cast<double>(scanline[k]) + Pshift[2];
unsigned pointIndex = static_cast<unsigned>(k + j * rasterX);
if (pointIndex <= pc->size())
{
if (z < zMinMax[0] || z > zMinMax[1])
{
示例7: ReadBlockFromFile
CPLErr GDALWMSRasterBand::ReadBlockFromFile(int x, int y, const char *file_name, int to_buffer_band, void *buffer, int advise_read) {
CPLErr ret = CE_None;
GDALDataset *ds = 0;
GByte *color_table = NULL;
int i;
//CPLDebug("WMS", "ReadBlockFromFile: to_buffer_band=%d, (x,y)=(%d, %d)", to_buffer_band, x, y);
/* expected size */
const int esx = MIN(MAX(0, (x + 1) * nBlockXSize), nRasterXSize) - MIN(MAX(0, x * nBlockXSize), nRasterXSize);
const int esy = MIN(MAX(0, (y + 1) * nBlockYSize), nRasterYSize) - MIN(MAX(0, y * nBlockYSize), nRasterYSize);
ds = reinterpret_cast<GDALDataset*>(GDALOpen(file_name, GA_ReadOnly));
if (ds != NULL) {
int sx = ds->GetRasterXSize();
int sy = ds->GetRasterYSize();
bool accepted_as_no_alpha = false; // if the request is for 4 bands but the wms returns 3
/* Allow bigger than expected so pre-tiled constant size images work on corners */
if ((sx > nBlockXSize) || (sy > nBlockYSize) || (sx < esx) || (sy < esy)) {
CPLError(CE_Failure, CPLE_AppDefined, "GDALWMS: Incorrect size %d x %d of downloaded block, expected %d x %d, max %d x %d.",
sx, sy, esx, esy, nBlockXSize, nBlockYSize);
ret = CE_Failure;
}
if (ret == CE_None) {
int nDSRasterCount = ds->GetRasterCount();
if (nDSRasterCount != m_parent_dataset->nBands) {
/* Maybe its an image with color table */
bool accepted_as_ct = false;
if ((eDataType == GDT_Byte) && (ds->GetRasterCount() == 1)) {
GDALRasterBand *rb = ds->GetRasterBand(1);
if (rb->GetRasterDataType() == GDT_Byte) {
GDALColorTable *ct = rb->GetColorTable();
if (ct != NULL) {
accepted_as_ct = true;
if (!advise_read) {
color_table = new GByte[256 * 4];
const int count = MIN(256, ct->GetColorEntryCount());
for (i = 0; i < count; ++i) {
GDALColorEntry ce;
ct->GetColorEntryAsRGB(i, &ce);
color_table[i] = static_cast<GByte>(ce.c1);
color_table[i + 256] = static_cast<GByte>(ce.c2);
color_table[i + 512] = static_cast<GByte>(ce.c3);
color_table[i + 768] = static_cast<GByte>(ce.c4);
}
for (i = count; i < 256; ++i) {
color_table[i] = 0;
color_table[i + 256] = 0;
color_table[i + 512] = 0;
color_table[i + 768] = 0;
}
}
}
}
}
if (nDSRasterCount == 4 && m_parent_dataset->nBands == 3)
{
/* metacarta TMS service sometimes return a 4 band PNG instead of the expected 3 band... */
}
else if (!accepted_as_ct) {
if (ds->GetRasterCount()==3 && m_parent_dataset->nBands == 4 && (eDataType == GDT_Byte))
{ // WMS returned a file with no alpha so we will fill the alpha band with "opaque"
accepted_as_no_alpha = true;
}
else
{
CPLError(CE_Failure, CPLE_AppDefined, "GDALWMS: Incorrect bands count %d in downloaded block, expected %d.",
nDSRasterCount, m_parent_dataset->nBands);
ret = CE_Failure;
}
}
}
}
if (!advise_read) {
for (int ib = 1; ib <= m_parent_dataset->nBands; ++ib) {
if (ret == CE_None) {
void *p = NULL;
GDALRasterBlock *b = NULL;
if ((buffer != NULL) && (ib == to_buffer_band)) {
p = buffer;
} else {
GDALWMSRasterBand *band = static_cast<GDALWMSRasterBand *>(m_parent_dataset->GetRasterBand(ib));
if (m_overview >= 0) band = static_cast<GDALWMSRasterBand *>(band->GetOverview(m_overview));
if (!band->IsBlockInCache(x, y)) {
b = band->GetLockedBlockRef(x, y, true);
if (b != NULL) {
p = b->GetDataRef();
if (p == NULL) {
CPLError(CE_Failure, CPLE_AppDefined, "GDALWMS: GetDataRef returned NULL.");
ret = CE_Failure;
}
}
}
else
{
//CPLDebug("WMS", "Band %d, block (x,y)=(%d, %d) already in cache", band->GetBand(), x, y);
}
}
if (p != NULL) {
int pixel_space = GDALGetDataTypeSize(eDataType) / 8;
//.........这里部分代码省略.........
示例8: if
static GDALDataset *
XPMCreateCopy( const char * pszFilename, GDALDataset *poSrcDS,
int bStrict, char ** papszOptions,
GDALProgressFunc pfnProgress, void * pProgressData )
{
int nBands = poSrcDS->GetRasterCount();
int nXSize = poSrcDS->GetRasterXSize();
int nYSize = poSrcDS->GetRasterYSize();
GDALColorTable *poCT;
/* -------------------------------------------------------------------- */
/* Some some rudimentary checks */
/* -------------------------------------------------------------------- */
if( nBands != 1 )
{
CPLError( CE_Failure, CPLE_NotSupported,
"XPM driver only supports one band images.\n" );
return NULL;
}
if( poSrcDS->GetRasterBand(1)->GetRasterDataType() != GDT_Byte
&& bStrict )
{
CPLError( CE_Failure, CPLE_NotSupported,
"XPM driver doesn't support data type %s. "
"Only eight bit bands supported.\n",
GDALGetDataTypeName(
poSrcDS->GetRasterBand(1)->GetRasterDataType()) );
return NULL;
}
/* -------------------------------------------------------------------- */
/* If there is no colortable on the source image, create a */
/* greyscale one with 64 levels of grey. */
/* -------------------------------------------------------------------- */
GDALRasterBand *poBand = poSrcDS->GetRasterBand(1);
int i;
GDALColorTable oGreyTable;
poCT = poBand->GetColorTable();
if( poCT == NULL )
{
poCT = &oGreyTable;
for( i = 0; i < 256; i++ )
{
GDALColorEntry sColor;
sColor.c1 = (short) i;
sColor.c2 = (short) i;
sColor.c3 = (short) i;
sColor.c4 = 255;
poCT->SetColorEntry( i, &sColor );
}
}
/* -------------------------------------------------------------------- */
/* Build list of active colors, and the mapping from pixels to */
/* our active colormap. */
/* -------------------------------------------------------------------- */
const char *pszColorCodes = " [email protected]#$%^&*()-+=[]|:;,.<>?/";
int anPixelMapping[256];
GDALColorEntry asPixelColor[256];
int nActiveColors = MIN(poCT->GetColorEntryCount(),256);
// Setup initial colortable and pixel value mapping.
memset( anPixelMapping+0, 0, sizeof(int) * 256 );
for( i = 0; i < nActiveColors; i++ )
{
poCT->GetColorEntryAsRGB( i, asPixelColor + i );
anPixelMapping[i] = i;
}
/* ==================================================================== */
/* Iterate merging colors until we are under our limit (about 85). */
/* ==================================================================== */
while( nActiveColors > (int) strlen(pszColorCodes) )
{
int nClosestDistance = 768;
int iClose1 = -1, iClose2 = -1;
int iColor1, iColor2;
// Find the closest pair of colors.
for( iColor1 = 0; iColor1 < nActiveColors; iColor1++ )
{
for( iColor2 = iColor1+1; iColor2 < nActiveColors; iColor2++ )
{
int nDistance;
if( asPixelColor[iColor1].c4 < 128
&& asPixelColor[iColor2].c4 < 128 )
nDistance = 0;
else
nDistance =
ABS(asPixelColor[iColor1].c1-asPixelColor[iColor2].c1)
//.........这里部分代码省略.........
示例9: ProxyMain
//.........这里部分代码省略.........
poVDS->SetMetadata(papszMD, "RPC");
papszMD = ((GDALDataset*)hDataset)->GetMetadata("GEOLOCATION");
if (papszMD != NULL)
poVDS->SetMetadata(papszMD, "GEOLOCATION");
}
int nSrcBandCount = nBandCount;
if (nRGBExpand != 0)
{
GDALRasterBand *poSrcBand;
poSrcBand = ((GDALDataset*)
hDataset)->GetRasterBand(ABS(panBandList[0]));
if (panBandList[0] < 0)
poSrcBand = poSrcBand->GetMaskBand();
GDALColorTable *poColorTable = poSrcBand->GetColorTable();
if (poColorTable == NULL)
{
fprintf(stderr, "Error : band %d has no color table\n", ABS(panBandList[0]));
GDALClose(hDataset);
CPLFree(panBandList);
GDALDestroyDriverManager();
CSLDestroy(argv);
CSLDestroy(papszCreateOptions);
exit(1);
}
/* Check that the color table only contains gray levels */
/* when using -expand gray */
if (nRGBExpand == 1)
{
int nColorCount = poColorTable->GetColorEntryCount();
int nColor;
for (nColor = 0; nColor < nColorCount; nColor++)
{
const GDALColorEntry *poEntry = poColorTable->GetColorEntry(nColor);
if (poEntry->c1 != poEntry->c2 || poEntry->c1 != poEntry->c2)
{
fprintf(stderr, "Warning : color table contains non gray levels colors\n");
break;
}
}
}
if (nBandCount == 1)
nBandCount = nRGBExpand;
else if (nBandCount == 2 && (nRGBExpand == 3 || nRGBExpand == 4))
nBandCount = nRGBExpand;
else
{
fprintf(stderr, "Error : invalid use of -expand option.\n");
exit(1);
}
}
int bFilterOutStatsMetadata =
(bScale || bUnscale || !bSpatialArrangementPreserved || nRGBExpand != 0);
/* ==================================================================== */
/* Process all bands. */
/* ==================================================================== */
for (i = 0; i < nBandCount; i++)
{