本文整理汇总了C++中SkColorTable::setFlags方法的典型用法代码示例。如果您正苦于以下问题:C++ SkColorTable::setFlags方法的具体用法?C++ SkColorTable::setFlags怎么用?C++ SkColorTable::setFlags使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkColorTable
的用法示例。
在下文中一共展示了SkColorTable::setFlags方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_isOpaque
// copyTo() should preserve isOpaque when it makes sense
static void test_isOpaque(skiatest::Reporter* reporter, const SkBitmap& src,
SkBitmap::Config dstConfig) {
SkBitmap bitmap(src);
SkBitmap dst;
// we need the lock so that we get a valid colorTable (when available)
SkAutoLockPixels alp(bitmap);
SkColorTable* ctable = bitmap.getColorTable();
unsigned ctableFlags = ctable ? ctable->getFlags() : 0;
if (canHaveAlpha(bitmap.config()) && canHaveAlpha(dstConfig)) {
bitmap.setIsOpaque(false);
if (ctable) {
ctable->setFlags(ctableFlags & ~SkColorTable::kColorsAreOpaque_Flag);
}
REPORTER_ASSERT(reporter, bitmap.copyTo(&dst, dstConfig));
REPORTER_ASSERT(reporter, dst.config() == dstConfig);
if (bitmap.isOpaque() != dst.isOpaque()) {
report_opaqueness(reporter, bitmap, dst);
}
}
bitmap.setIsOpaque(true);
if (ctable) {
ctable->setFlags(ctableFlags | SkColorTable::kColorsAreOpaque_Flag);
}
REPORTER_ASSERT(reporter, bitmap.copyTo(&dst, dstConfig));
REPORTER_ASSERT(reporter, dst.config() == dstConfig);
if (bitmap.isOpaque() != dst.isOpaque()) {
report_opaqueness(reporter, bitmap, dst);
}
if (ctable) {
ctable->setFlags(ctableFlags);
}
}
示例2: drawBG
void drawBG(SkCanvas* canvas)
{
canvas->drawColor(0xFFDDDDDD);
return;
#if 0
SkColorTable ct;
SkPMColor colors[] = { SK_ColorRED, SK_ColorBLUE };
ct.setColors(colors, 2);
ct.setFlags(ct.getFlags() | SkColorTable::kColorsAreOpaque_Flag);
SkBitmap bm;
bm.setConfig(SkBitmap::kIndex8_Config, 20, 20, 21);
bm.setColorTable(&ct);
bm.allocPixels();
sk_memset16((uint16_t*)bm.getAddr8(0, 0), 0x0001, bm.rowBytes() * bm.height() / 2);
#endif
#if 0
SkBitmap bm;
bm.setConfig(SkBitmap::kRGB_565_Config, 20, 20, 42);
bm.allocPixels();
sk_memset32((uint32_t*)bm.getAddr16(0, 0), 0x0000FFFF, bm.rowBytes() * bm.height() / 4);
#endif
#if 1
SkBitmap bm;
bm.setConfig(SkBitmap::kARGB_8888_Config, 20, 20);
bm.allocPixels();
sk_memset32((uint32_t*)bm.getAddr32(0, 0), 0xFFDDDDDD, bm.rowBytes() * bm.height() / 4);
#endif
SkPaint paint;
// SkShader* shader = SkShader::CreateBitmapShader(bm, false, SkPaint::kBilinear_FilterType, SkShader::kRepeat_TileMode);
SkPoint pts[] = { 0, 0, SkIntToScalar(100), SkIntToScalar(0) };
SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE };
SkShader* shader = SkGradientShader::CreateLinear(pts, colors, NULL, 2, SkShader::kMirror_TileMode);
paint.setShader(shader)->unref();
canvas->drawPaint(paint);
}
示例3: onDecode
//.........这里部分代码省略.........
}
// we track if we actually see a non-opaque pixels, since sometimes a PNG sets its colortype
// to |= PNG_COLOR_MASK_ALPHA, but all of its pixels are in fact opaque. We care, since we
// draw lots faster if we can flag the bitmap has being opaque
bool reallyHasAlpha = false;
SkColorTable* colorTable = NULL;
if (color_type == PNG_COLOR_TYPE_PALETTE) {
int num_palette;
png_colorp palette;
png_bytep trans;
int num_trans;
png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
/* BUGGY IMAGE WORKAROUND
We hit some images (e.g. fruit_.png) who contain bytes that are == colortable_count
which is a problem since we use the byte as an index. To work around this we grow
the colortable by 1 (if its < 256) and duplicate the last color into that slot.
*/
int colorCount = num_palette + (num_palette < 256);
colorTable = SkNEW_ARGS(SkColorTable, (colorCount));
SkPMColor* colorPtr = colorTable->lockColors();
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, NULL);
hasAlpha = (num_trans > 0);
} else {
num_trans = 0;
colorTable->setFlags(colorTable->getFlags() | SkColorTable::kColorsAreOpaque_Flag);
}
// check for bad images that might make us crash
if (num_trans > num_palette) {
num_trans = num_palette;
}
int index = 0;
int transLessThanFF = 0;
for (; index < num_trans; index++) {
transLessThanFF |= (int)*trans - 0xFF;
*colorPtr++ = SkPreMultiplyARGB(*trans++, palette->red, palette->green, palette->blue);
palette++;
}
reallyHasAlpha |= (transLessThanFF < 0);
for (; index < num_palette; index++) {
*colorPtr++ = SkPackARGB32(0xFF, palette->red, palette->green, palette->blue);
palette++;
}
// see BUGGY IMAGE WORKAROUND comment above
if (num_palette < 256) {
*colorPtr = colorPtr[-1];
}
colorTable->unlockColors(true);
}
SkAutoUnref aur(colorTable);
if (!this->allocPixelRef(decodedBitmap, colorTable)) {
delete colorTable;