本文整理汇总了C++中SkPaint::getAlpha方法的典型用法代码示例。如果您正苦于以下问题:C++ SkPaint::getAlpha方法的具体用法?C++ SkPaint::getAlpha怎么用?C++ SkPaint::getAlpha使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkPaint
的用法示例。
在下文中一共展示了SkPaint::getAlpha方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setContext
bool SkColorShader::setContext(const SkBitmap& device, const SkPaint& paint,
const SkMatrix& matrix) {
if (!this->INHERITED::setContext(device, paint, matrix)) {
return false;
}
SkColor c;
unsigned a;
if (fInheritColor) {
c = paint.getColor();
a = SkColorGetA(c);
} else {
c = fColor;
a = SkAlphaMul(SkColorGetA(c), SkAlpha255To256(paint.getAlpha()));
}
unsigned r = SkColorGetR(c);
unsigned g = SkColorGetG(c);
unsigned b = SkColorGetB(c);
// we want this before we apply any alpha
fColor16 = SkPack888ToRGB16(r, g, b);
if (a != 255) {
a = SkAlpha255To256(a);
r = SkAlphaMul(r, a);
g = SkAlphaMul(g, a);
b = SkAlphaMul(b, a);
}
fPMColor = SkPackARGB32(a, r, g, b);
return true;
}
示例2: Supports
static bool Supports(const SkPixmap& dst, const SkPixmap& src, const SkPaint& paint) {
if (dst.colorType() != src.colorType()) {
return false;
}
if (dst.info().gammaCloseToSRGB() != src.info().gammaCloseToSRGB()) {
return false;
}
if (paint.getMaskFilter() || paint.getColorFilter() || paint.getImageFilter()) {
return false;
}
if (0xFF != paint.getAlpha()) {
return false;
}
SkBlendMode mode = paint.getBlendMode();
if (SkBlendMode::kSrc == mode) {
return true;
}
if (SkBlendMode::kSrcOver == mode && src.isOpaque()) {
return true;
}
// At this point memcpy can't be used. The following check for using SrcOver.
if (dst.colorType() != kN32_SkColorType || !dst.info().gammaCloseToSRGB()) {
return false;
}
return SkBlendMode::kSrcOver == mode;
}
示例3: drawImageLattice
void SkBaseDevice::drawImageLattice(const SkImage* image,
const SkCanvas::Lattice& lattice, const SkRect& dst,
const SkPaint& paint) {
SkLatticeIter iter(lattice, dst);
SkRect srcR, dstR;
SkColor c;
bool isFixedColor = false;
const SkImageInfo info = SkImageInfo::Make(1, 1, kBGRA_8888_SkColorType, kUnpremul_SkAlphaType);
while (iter.next(&srcR, &dstR, &isFixedColor, &c)) {
if (isFixedColor || (srcR.width() <= 1.0f && srcR.height() <= 1.0f &&
image->readPixels(info, &c, 4, srcR.fLeft, srcR.fTop))) {
// Fast draw with drawRect, if this is a patch containing a single color
// or if this is a patch containing a single pixel.
if (0 != c || !paint.isSrcOver()) {
SkPaint paintCopy(paint);
int alpha = SkAlphaMul(SkColorGetA(c), SkAlpha255To256(paint.getAlpha()));
paintCopy.setColor(SkColorSetA(c, alpha));
this->drawRect(dstR, paintCopy);
}
} else {
this->drawImageRect(image, &srcR, dstR, paint, SkCanvas::kStrict_SrcRectConstraint);
}
}
}
示例4: asFragmentProcessor
bool DCShader::asFragmentProcessor(GrContext*, const SkPaint& paint, const SkMatrix& viewM,
const SkMatrix* localMatrix, GrColor* color,
GrFragmentProcessor** fp) const {
*fp = SkNEW_ARGS(DCFP, (fDeviceMatrix));
*color = GrColorPackA4(paint.getAlpha());
return true;
}
示例5: onDraw
virtual void onDraw(int loops, SkCanvas* canvas) {
const SkIPoint dim = this->getSize();
SkRandom rand;
SkPaint paint(fPaint);
this->setupPaint(&paint);
// explicitly need these
paint.setAlpha(fPaint.getAlpha());
paint.setAntiAlias(kBW != fFQ);
paint.setLCDRenderText(kLCD == fFQ);
const SkScalar x0 = SkIntToScalar(-10);
const SkScalar y0 = SkIntToScalar(-10);
paint.setTextSize(SkIntToScalar(12));
for (int i = 0; i < loops; i++) {
SkScalar x = x0 + rand.nextUScalar1() * dim.fX;
SkScalar y = y0 + rand.nextUScalar1() * dim.fY;
canvas->drawString(fText, x, y, paint);
}
paint.setTextSize(SkIntToScalar(48));
for (int i = 0; i < loops / 4 ; i++) {
SkScalar x = x0 + rand.nextUScalar1() * dim.fX;
SkScalar y = y0 + rand.nextUScalar1() * dim.fY;
canvas->drawString(fText, x, y, paint);
}
}
示例6: SetPaint
void SkGL::SetPaint(const SkPaint& paint, bool isPremul, bool justAlpha) {
if (justAlpha) {
SkGL::SetAlpha(paint.getAlpha());
} else {
SkGL::SetColor(paint.getColor());
}
GLenum sm = GL_ONE;
GLenum dm = GL_ONE_MINUS_SRC_ALPHA;
SkXfermode* mode = paint.getXfermode();
SkXfermode::Coeff sc, dc;
if (mode && mode->asCoeff(&sc, &dc)) {
sm = gXfermodeCoeff2Blend[sc];
dm = gXfermodeCoeff2Blend[dc];
}
// hack for text, which is not-premul (afaik)
if (!isPremul) {
if (GL_ONE == sm) {
sm = GL_SRC_ALPHA;
}
}
glEnable(GL_BLEND);
glBlendFunc(sm, dm);
if (paint.isDither()) {
glEnable(GL_DITHER);
} else {
glDisable(GL_DITHER);
}
}
示例7: draw
/**
* Draw a single path element of the clip stack into the accumulation bitmap
*/
void GrSWMaskHelper::draw(const SkPath& path, const SkStrokeRec& stroke, SkRegion::Op op,
bool antiAlias, uint8_t alpha) {
SkPaint paint;
if (stroke.isHairlineStyle()) {
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(SK_Scalar1);
} else {
if (stroke.isFillStyle()) {
paint.setStyle(SkPaint::kFill_Style);
} else {
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeJoin(stroke.getJoin());
paint.setStrokeCap(stroke.getCap());
paint.setStrokeWidth(stroke.getWidth());
}
}
paint.setAntiAlias(antiAlias);
if (SkRegion::kReplace_Op == op && 0xFF == alpha) {
SkASSERT(0xFF == paint.getAlpha());
fDraw.drawPathCoverage(path, paint);
} else {
paint.setXfermodeMode(op_to_mode(op));
paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha));
fDraw.drawPath(path, paint);
}
}
示例8: draw
bool draw(SkCanvas* canvas, const SkString& newText, SkScalar x, SkScalar y, SkPaint& paint)
{
SkScalar scale;
if (fInterp.timeToValues(SkTime::GetMSecs(), &scale) == SkInterpolator::kFreezeEnd_Result)
{
canvas->drawText(newText.c_str(), newText.size(), x, y, paint);
return false;
}
else
{
U8 alpha = paint.getAlpha();
SkScalar above, below;
(void)paint.measureText(nil, 0, &above, &below);
SkScalar height = below - above;
SkScalar dy = SkScalarMul(height, scale);
if (scale < 0)
height = -height;
// draw the old
paint.setAlpha((U8)SkScalarMul(alpha, SK_Scalar1 - SkScalarAbs(scale)));
canvas->drawText(fOldText.c_str(), fOldText.size(), x, y - dy, paint);
// draw the new
paint.setAlpha((U8)SkScalarMul(alpha, SkScalarAbs(scale)));
canvas->drawText(newText.c_str(), newText.size(), x, y + height - dy, paint);
// restore the paint
paint.setAlpha(alpha);
return true;
}
}
示例9: Supports
static bool Supports(const SkPixmap& dst, const SkPixmap& src, const SkPaint& paint) {
if (dst.colorType() != src.colorType()) {
return false;
}
if (dst.info().profileType() != src.info().profileType()) {
return false;
}
if (paint.getMaskFilter() || paint.getColorFilter() || paint.getImageFilter()) {
return false;
}
if (0xFF != paint.getAlpha()) {
return false;
}
SkXfermode::Mode mode;
if (!SkXfermode::AsMode(paint.getXfermode(), &mode)) {
return false;
}
if (SkXfermode::kSrc_Mode == mode) {
return true;
}
if (SkXfermode::kSrcOver_Mode == mode && src.isOpaque()) {
return true;
}
return false;
}
示例10: fStrokeWidth
SkPDFGraphicState::SkPDFGraphicState(const SkPaint& p)
: fStrokeWidth(p.getStrokeWidth())
, fStrokeMiter(p.getStrokeMiter())
, fAlpha(p.getAlpha())
, fStrokeCap(SkToU8(p.getStrokeCap()))
, fStrokeJoin(SkToU8(p.getStrokeJoin()))
, fMode(SkToU8(mode_for_pdf(p.getXfermode()))) {}
示例11: setContext
bool SkTransparentShader::setContext(const SkBitmap& device,
const SkPaint& paint,
const SkMatrix& matrix) {
fDevice = &device;
fAlpha = paint.getAlpha();
return this->INHERITED::setContext(device, paint, matrix);
}
示例12: onDraw
void onDraw(SkCanvas* canvas) override {
const struct {
SkISize size;
SkScalar scaleX, scaleY;
SkScalar opacity;
} configs[] = {
{ SkISize::Make(200, 100), 1, 1, 1 },
{ SkISize::Make(200, 200), 1, 1, 1 },
{ SkISize::Make(200, 200), 1, 2, 1 },
{ SkISize::Make(400, 200), 2, 2, 1 },
{ SkISize::Make(200, 100), 1, 1, 0.9f },
{ SkISize::Make(200, 200), 1, 1, 0.75f },
{ SkISize::Make(200, 200), 1, 2, 0.5f },
{ SkISize::Make(400, 200), 2, 2, 0.25f },
{ SkISize::Make(200, 200), 0.5f, 1, 1 },
{ SkISize::Make(200, 200), 1, 0.5f, 1 },
{ SkISize::Make(200, 200), 0.5f, 0.5f, 1 },
{ SkISize::Make(200, 200), 2, 2, 1 },
{ SkISize::Make(200, 100), -1, 1, 1 },
{ SkISize::Make(200, 100), 1, -1, 1 },
{ SkISize::Make(200, 100), -1, -1, 1 },
{ SkISize::Make(200, 100), -1, -1, 0.5f },
};
const unsigned kDrawsPerRow = 4;
const SkScalar kDrawSize = 250;
for (size_t i = 0; i < SK_ARRAY_COUNT(configs); ++i) {
SkPaint p;
p.setAlpha(SkScalarRoundToInt(255 * configs[i].opacity));
SkMatrix m = SkMatrix::MakeScale(configs[i].scaleX, configs[i].scaleY);
if (configs[i].scaleX < 0) {
m.postTranslate(SkIntToScalar(configs[i].size.width()), 0);
}
if (configs[i].scaleY < 0) {
m.postTranslate(0, SkIntToScalar(configs[i].size.height()));
}
SkAutoTDelete<SkImageGenerator> gen(
SkImageGenerator::NewFromPicture(configs[i].size, fPicture.get(), &m,
p.getAlpha() != 255 ? &p : nullptr));
SkBitmap bm;
gen->generateBitmap(&bm);
const SkScalar x = kDrawSize * (i % kDrawsPerRow);
const SkScalar y = kDrawSize * (i / kDrawsPerRow);
p.setColor(0xfff0f0f0);
p.setAlpha(255);
canvas->drawRect(SkRect::MakeXYWH(x, y,
SkIntToScalar(bm.width()),
SkIntToScalar(bm.height())), p);
canvas->drawBitmap(bm, x, y);
}
}
示例13: asNewEffect
bool SkColorShader::asNewEffect(GrContext* context, const SkPaint& paint,
const SkMatrix* localMatrix, GrColor* grColor,
GrEffectRef** grEffect) const {
*grEffect = NULL;
SkColor skColor = fColor;
U8CPU newA = SkMulDiv255Round(SkColorGetA(fColor), paint.getAlpha());
*grColor = SkColor2GrColor(SkColorSetA(skColor, newA));
return true;
}
示例14: SkSpriteBlitter
Sprite_D32_XferFilter(const SkBitmap& source, const SkPaint& paint)
: SkSpriteBlitter(source) {
fColorFilter = paint.getColorFilter();
SkSafeRef(fColorFilter);
fXfermode = paint.getXfermode();
SkSafeRef(fXfermode);
fBufferSize = 0;
fBuffer = NULL;
unsigned flags32 = 0;
if (255 != paint.getAlpha()) {
flags32 |= SkBlitRow::kGlobalAlpha_Flag32;
}
if (!source.isOpaque()) {
flags32 |= SkBlitRow::kSrcPixelAlpha_Flag32;
}
fProc32 = SkBlitRow::Factory32(flags32);
fAlpha = paint.getAlpha();
}
示例15: onGetName
virtual const char* onGetName() {
fName.printf("text_%g", SkScalarToFloat(fPaint.getTextSize()));
if (fDoPos) {
fName.append("_pos");
}
fName.appendf("_%s", fontQualityName(fPaint));
if (SK_ColorBLACK != fPaint.getColor()) {
fName.appendf("_%02X", fPaint.getAlpha());
} else {
fName.append("_BK");
}
return fName.c_str();
}