本文整理汇总了C++中BMP::TellNumberOfColors方法的典型用法代码示例。如果您正苦于以下问题:C++ BMP::TellNumberOfColors方法的具体用法?C++ BMP::TellNumberOfColors怎么用?C++ BMP::TellNumberOfColors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BMP
的用法示例。
在下文中一共展示了BMP::TellNumberOfColors方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runtime_error
std::vector<gimg::colorRGB24> ImportPaletteFromBMP( const std::string & filepath )
{
std::vector<gimg::colorRGB24> outpal;
BMP input;
input.ReadFromFile( filepath.c_str() );
const unsigned int nbColors = static_cast<unsigned int>( ( input.TellNumberOfColors() > 0 )? input.TellNumberOfColors() : 0 );
if( nbColors == 0 )
throw runtime_error("ERROR: BMP image being imported has an invalid palette!");
outpal.resize( nbColors );
for( unsigned int i = 0; i < nbColors; ++i )
{
RGBApixel acolor = input.GetColor(i);
outpal[i].red = acolor.Red;
outpal[i].green = acolor.Green;
outpal[i].blue = acolor.Blue;
//Alpha is ignored
}
return std::move(outpal);
}
示例2: ImportBMP
bool ImportBMP( _TImg_t & out_timg,
const std::string & filepath,
unsigned int forcedwidth,
unsigned int forcedheight,
bool erroronwrongres )
{
//The max nb of colors possible with that bitdepth!
static const unsigned int NB_Colors_Support = utils::do_exponent_of_2_<_TImg_t::pixel_t::mypixeltrait_t::BITS_PER_PIXEL>::value;
bool hasWarnedOORPixel = false; //Whether we warned about out of range pixels at least once during the pixel loop! If applicable..
bool isWrongResolution = false;
BMP input;
auto & outpal = out_timg.getPalette();
input.ReadFromFile( filepath.c_str() );
if( input.TellBitDepth() != _TImg_t::pixel_t::GetBitsPerPixel() )
{
//We don't support anything with a different bitdepth!
//Mention the palette length mismatch
cerr <<"\n<!>-ERROR: The file : " <<filepath <<", is not a " <<_TImg_t::pixel_t::GetBitsPerPixel()
<<"bpp indexed bmp ! Its in fact " <<input.TellBitDepth() <<"bpp!\n"
<<"Make sure the bmp file is saved as " <<_TImg_t::pixel_t::GetBitsPerPixel() <<"bpp, "
<<NB_Colors_Support << " colors!\n";
return false;
}
//Only force resolution when we were asked to!
if( forcedwidth != 0 && forcedheight != 0 )
isWrongResolution = input.TellWidth() != forcedwidth || input.TellHeight() != forcedheight;
if( erroronwrongres && isWrongResolution )
{
cerr <<"\n<!>-ERROR: The file : " <<filepath <<" has an unexpected resolution!\n"
<<" Expected :" <<forcedwidth <<"x" <<forcedheight <<", and got " <<input.TellWidth() <<"x" <<input.TellHeight()
<<"! Skipping!\n";
return false;
}
if( utils::LibraryWide::getInstance().Data().isVerboseOn() && input.TellNumberOfColors() <= NB_Colors_Support )
{
//Mention the palette length mismatch
cerr <<"\n<!>-Warning: " <<filepath <<" has a different palette length than expected!\n"
<<"Fixing and continuing happily..\n";
}
out_timg.setNbColors( NB_Colors_Support );
//Build palette
const unsigned int nbColors = static_cast<unsigned int>( ( input.TellNumberOfColors() > 0 )? input.TellNumberOfColors() : 0 );
if( nbColors == 0 )
throw runtime_error("ERROR: BMP image being imported has an invalid palette!");
for( unsigned int i = 0; i < nbColors; ++i )
{
RGBApixel acolor = input.GetColor(i);
outpal[i].red = acolor.Red;
outpal[i].green = acolor.Green;
outpal[i].blue = acolor.Blue;
//Alpha is ignored
}
//Image Resolution
int tiledwidth = (forcedwidth != 0)? forcedwidth : input.TellWidth();
int tiledheight = (forcedheight != 0)? forcedheight : input.TellHeight();
//Make sure the height and width are divisible by the size of the tiles!
if( tiledwidth % _TImg_t::tile_t::WIDTH )
tiledwidth = CalcClosestHighestDenominator( tiledwidth, _TImg_t::tile_t::WIDTH );
if( tiledheight % _TImg_t::tile_t::HEIGHT )
tiledheight = CalcClosestHighestDenominator( tiledheight, _TImg_t::tile_t::HEIGHT );
//Resize target image
out_timg.setPixelResolution( tiledwidth, tiledheight );
//If the image we read is not divisible by the dimension of our tiles,
// we have to ensure that we won't got out of bound while copying!
int maxCopyWidth = out_timg.getNbPixelWidth();
int maxCopyHeight = out_timg.getNbPixelHeight();
if( maxCopyWidth != input.TellWidth() || maxCopyHeight != input.TellHeight() )
{
//Take the smallest resolution, so we don't go out of bound!
maxCopyWidth = std::min( input.TellWidth(), maxCopyWidth );
maxCopyHeight = std::min( input.TellHeight(), maxCopyHeight );
}
//Copy pixels over
for( int i = 0; i < maxCopyWidth; ++i )
{
for( int j = 0; j < maxCopyHeight; ++j )
{
RGBApixel apixel = input.GetPixel(i,j);
//First we need to find out what index the color is..
gimg::colorRGB24::colordata_t colorindex = FindIndexForColor( apixel, outpal );
if( !hasWarnedOORPixel && colorindex == -1 )
{
//We got a problem
//.........这里部分代码省略.........