本文整理汇总了C++中ColorBlock类的典型用法代码示例。如果您正苦于以下问题:C++ ColorBlock类的具体用法?C++ ColorBlock怎么用?C++ ColorBlock使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ColorBlock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetValue
virtual void SetValue( const String &value )
{
// search for <color> children, find the one with matching value
// and "select" it
ElementList colors;
ElementList::iterator it;
GetElementsByTagName( colors, "color" );
for( it = colors.begin(); it != colors.end(); ++it )
{
ColorBlock *cb = dynamic_cast<ColorBlock*>( *it );
if( cb && cb->getColor() == value )
{
selectColorBlock( cb );
break;
}
}
// FIXME: do i need to release the elements?
// TODO: if no block with matching color was found, find the
// custom colorblock and set its color to value and select it.
if( it == colors.end() )
{
// DEBUG
//Com_Printf( "ColorSelector searching for custom\n" );
for( it = colors.begin(); it != colors.end(); ++it )
{
ColorBlock *cb = dynamic_cast<ColorBlock*>( *it );
if( cb && cb->isCustom() )
{
cb->setColor( value );
selectColorBlock( cb );
// DEBUG
//Com_Printf( "ColorSelector FOUND custom\n" );
break;
}
}
// FIXME: what if we still have no block selected?
if( it == colors.end() )
{
// DEBUG
//Com_Printf( "ColorSelector DIDNT FIND custom\n" );
}
}
// this calls out onchange event i guess
SetAttribute("value", value);
}
示例2: color_block_to_vector_block
inline static void color_block_to_vector_block(const ColorBlock & rgba, Vector3 block[16])
{
for (int i = 0; i < 16; i++)
{
const Color32 c = rgba.color(i);
block[i] = Vector3(c.r, c.g, c.b);
}
}
示例3: compressBlock
void RgEtcCompressor::compressBlock(ColorBlock & rgba, AlphaMode alphaMode, const CompressionOptions::Private & compressionOptions, void * output)
{
rg_etc1::etc1_pack_params pack_params;
pack_params.m_quality = rg_etc1::cMediumQuality;
if (compressionOptions.quality == Quality_Fastest) pack_params.m_quality = rg_etc1::cLowQuality;
else if (compressionOptions.quality == Quality_Production) pack_params.m_quality = rg_etc1::cHighQuality;
else if (compressionOptions.quality == Quality_Highest) pack_params.m_quality = rg_etc1::cHighQuality;
else if (compressionOptions.quality == Quality_Normal) pack_params.m_quality = rg_etc1::cMediumQuality;
rgba.swizzle(2, 1, 0, 3);
rg_etc1::pack_etc1_block(output, (uint *)rgba.colors(), pack_params);
//Vector4 result[16];
//nv::decompress_etc(output, result);
}
示例4: GetValue
// FormControl methods
virtual String GetValue( void ) const
{
// search for <color> children, find the "selected" one
// and return its value
ElementList colors;
const_cast<ColorSelector*>( this )->GetElementsByTagName( colors, "color" );
for( ElementList::const_iterator it = colors.begin(); it != colors.end(); ++it )
{
ColorBlock *cb = dynamic_cast<ColorBlock*>( *it );
if( cb && cb->IsPseudoClassSet( "selected" ) )
return cb->getColor();
}
// FIXME: do i need to release the elements?
// FIXME: default value from THE CVAR??
return "";
}
示例5: colours
void CompressorDXT1::compressBlock(ColorBlock & rgba, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output)
{
nvsquish::WeightedClusterFit fit;
fit.SetMetric(compressionOptions.colorWeight.x, compressionOptions.colorWeight.y, compressionOptions.colorWeight.z);
if (rgba.isSingleColor())
{
BlockDXT1 * block = new(output) BlockDXT1;
OptimalCompress::compressDXT1(rgba.color(0), block);
}
else
{
nvsquish::ColourSet colours((uint8 *)rgba.colors(), 0);
fit.SetColourSet(&colours, nvsquish::kDxt1);
fit.Compress(output);
}
}
示例6: extractColorBlockRGB
inline static void extractColorBlockRGB(const ColorBlock & rgba, Vector3 block[16])
{
for (int i = 0; i < 16; i++)
{
const Color32 c = rgba.color(i);
block[i] = Vector3(c.r, c.g, c.b);
}
}
示例7: OnChildAdd
// Element method
virtual void OnChildAdd( Element* child )
{
Rocket::Controls::ElementFormControl::OnChildAdd( child );
ColorBlock *cb = dynamic_cast<ColorBlock*>( child );
if( cb )
{
cb->setSelector( this );
/*
// in preliminary stage, set :selected on the matched child?
// NEEDS A FIX AGAINST CUSTOM COLOR.. for now set the initial
// value with optionsform
if( cvar && cvar->string && cb->getColor() == cvar->string )
selectColorBlock( cb );
*/
}
}
示例8: min
void OptimalCompress::compressDXT5A(const ColorBlock & rgba, AlphaBlockDXT5 * dxtBlock)
{
uint8 mina = 255;
uint8 maxa = 0;
// Get min/max alpha.
for (uint i = 0; i < 16; i++)
{
uint8 alpha = rgba.color(i).a;
mina = min(mina, alpha);
maxa = max(maxa, alpha);
}
dxtBlock->alpha0 = maxa;
dxtBlock->alpha1 = mina;
if (maxa - mina > 8)
{
int besterror = computeAlphaError(rgba, dxtBlock);
int besta0 = maxa;
int besta1 = mina;
// Expand search space a bit.
const int alphaExpand = 8;
mina = (mina <= alphaExpand) ? 0 : mina - alphaExpand;
maxa = (maxa >= 255-alphaExpand) ? 255 : maxa + alphaExpand;
for (int a0 = mina+9; a0 < maxa; a0++)
{
for (int a1 = mina; a1 < a0-8; a1++)
{
nvDebugCheck(a0 - a1 > 8);
dxtBlock->alpha0 = a0;
dxtBlock->alpha1 = a1;
int error = computeAlphaError(rgba, dxtBlock, besterror);
if (error < besterror)
{
besterror = error;
besta0 = a0;
besta1 = a1;
}
}
}
dxtBlock->alpha0 = besta0;
dxtBlock->alpha1 = besta1;
}
computeAlphaIndices(rgba, dxtBlock);
}
示例9: CreateBlockCallback
void MainGameScene::CreateBlockCallback(float time)
{
// create block on a random location
ColorBlock* newBlock = ColorBlock::create("Assets/block.png");
// unattached blocks have 50% opacity
newBlock->setOpacity(127);
// randomize position
newBlock->setPositionX(rand() % 800);
//newBlock->setPositionX(300.0f);
// Y always in the botton
newBlock->setPositionY(-80.0f);
// add as a child to the batch
blocksBatch->addChild(newBlock);
newBlock->InitInWorld(box2DWorld);
// add to local list
blocksList.push_back(newBlock);
}
示例10: if
void AlphaBlock4x4::init(const ColorBlock & src, uint channel)
{
nvCheck(channel >= 0 && channel < 4);
// Colors are in BGRA format.
if (channel == 0) channel = 2;
else if (channel == 2) channel = 0;
for (int i = 0; i < 16; i++) {
alpha[i] = src.color(i).component[channel];
weights[i] = 1.0f;
}
}
示例11: extractColorBlockRGBA
inline static uint extractColorBlockRGBA(const ColorBlock & rgba, Vector3 block[16])
{
int num = 0;
for (int i = 0; i < 16; i++)
{
const Color32 c = rgba.color(i);
if (c.a > 127)
{
block[num++] = Vector3(c.r, c.g, c.b);
}
}
return num;
}
示例12:
void OptimalCompress::compressDXT3A(const ColorBlock & rgba, AlphaBlockDXT3 * dxtBlock)
{
dxtBlock->alpha0 = quantize4(rgba.color(0).a);
dxtBlock->alpha1 = quantize4(rgba.color(1).a);
dxtBlock->alpha2 = quantize4(rgba.color(2).a);
dxtBlock->alpha3 = quantize4(rgba.color(3).a);
dxtBlock->alpha4 = quantize4(rgba.color(4).a);
dxtBlock->alpha5 = quantize4(rgba.color(5).a);
dxtBlock->alpha6 = quantize4(rgba.color(6).a);
dxtBlock->alpha7 = quantize4(rgba.color(7).a);
dxtBlock->alpha8 = quantize4(rgba.color(8).a);
dxtBlock->alpha9 = quantize4(rgba.color(9).a);
dxtBlock->alphaA = quantize4(rgba.color(10).a);
dxtBlock->alphaB = quantize4(rgba.color(11).a);
dxtBlock->alphaC = quantize4(rgba.color(12).a);
dxtBlock->alphaD = quantize4(rgba.color(13).a);
dxtBlock->alphaE = quantize4(rgba.color(14).a);
dxtBlock->alphaF = quantize4(rgba.color(15).a);
}
示例13: new
void CompressorDXT5n::compressBlock(ColorBlock & rgba, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output)
{
BlockDXT5 * block = new(output) BlockDXT5;
// Compress Y.
if (compressionOptions.quality == Quality_Highest)
{
OptimalCompress::compressDXT1G(rgba, &block->color);
}
else
{
if (rgba.isSingleColor(Color32(0, 0xFF, 0, 0))) // Mask all but green channel.
{
OptimalCompress::compressDXT1G(rgba.color(0).g, &block->color);
}
else
{
ColorBlock tile = rgba;
tile.swizzle(4, 1, 5, 3); // leave alpha in alpha channel.
nvsquish::WeightedClusterFit fit;
fit.SetMetric(0, 1, 0);
int flags = 0;
if (alphaMode == nvtt::AlphaMode_Transparency) flags |= nvsquish::kWeightColourByAlpha;
nvsquish::ColourSet colours((uint8 *)tile.colors(), flags);
fit.SetColourSet(&colours, 0);
fit.Compress(&block->color);
}
}
rgba.swizzle(4, 1, 5, 0); // 1, G, 0, R
// Compress X.
if (compressionOptions.quality == Quality_Highest)
{
OptimalCompress::compressDXT5A(rgba, &block->alpha);
}
else
{
QuickCompress::compressDXT5A(rgba, &block->alpha);
}
}
示例14:
void StbCompressorDXT1::compressBlock(ColorBlock & rgba, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output)
{
rgba.swizzle(2, 1, 0, 3); // Swap R and B
stb_compress_dxt_block((unsigned char *)output, (unsigned char *)rgba.colors(), 0, 0);
}
示例15: nvDebugCheck
// Brute force green channel compressor
void OptimalCompress::compressDXT1G(const ColorBlock & rgba, BlockDXT1 * block)
{
nvDebugCheck(block != NULL);
uint8 ming = 63;
uint8 maxg = 0;
bool isSingleColor = true;
uint8 singleColor = rgba.color(0).g;
// Get min/max green.
for (uint i = 0; i < 16; i++)
{
uint8 green = (rgba.color(i).g + 1) >> 2;
ming = min(ming, green);
maxg = max(maxg, green);
if (rgba.color(i).g != singleColor) isSingleColor = false;
}
if (isSingleColor)
{
compressDXT1G(singleColor, block);
return;
}
block->col0.r = 31;
block->col1.r = 31;
block->col0.g = maxg;
block->col1.g = ming;
block->col0.b = 0;
block->col1.b = 0;
int bestError = computeGreenError(rgba, block);
int bestg0 = maxg;
int bestg1 = ming;
// Expand search space a bit.
const int greenExpand = 4;
ming = (ming <= greenExpand) ? 0 : ming - greenExpand;
maxg = (maxg >= 63-greenExpand) ? 63 : maxg + greenExpand;
for (int g0 = ming+1; g0 <= maxg; g0++)
{
for (int g1 = ming; g1 < g0; g1++)
{
block->col0.g = g0;
block->col1.g = g1;
int error = computeGreenError(rgba, block, bestError);
if (error < bestError)
{
bestError = error;
bestg0 = g0;
bestg1 = g1;
}
}
}
block->col0.g = bestg0;
block->col1.g = bestg1;
nvDebugCheck(bestg0 == bestg1 || block->isFourColorMode());
Color32 palette[4];
block->evaluatePalette(palette, false); // @@ Use target decoder.
block->indices = computeGreenIndices(rgba, palette);
}