本文整理汇总了C++中SkSize::width方法的典型用法代码示例。如果您正苦于以下问题:C++ SkSize::width方法的具体用法?C++ SkSize::width怎么用?C++ SkSize::width使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkSize
的用法示例。
在下文中一共展示了SkSize::width方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: drawHere
void drawHere(SkCanvas* canvas, SkFilterQuality filter, SkScalar dx, SkScalar dy) {
SkCanvas* origCanvas = canvas;
SkAutoCanvasRestore acr(canvas, true);
SkISize size = SkISize::Make(fImage->width(), fImage->height());
SkAutoTUnref<SkSurface> surface;
if (fShowFatBits) {
// scale up so we don't clip rotations
SkImageInfo info = SkImageInfo::MakeN32(fImage->width() * 2, fImage->height() * 2,
kOpaque_SkAlphaType);
surface.reset(make_surface(canvas, info));
canvas = surface->getCanvas();
canvas->drawColor(SK_ColorWHITE);
size.set(info.width(), info.height());
} else {
canvas->translate(SkScalarHalf(fCell.width() - fImage->width()),
SkScalarHalf(fCell.height() - fImage->height()));
}
this->drawTheImage(canvas, size, filter, dx, dy);
if (surface) {
SkAutoTUnref<SkImage> orig(surface->newImageSnapshot());
SkAutoTUnref<SkImage> zoomed(zoom_up(orig));
origCanvas->drawImage(zoomed,
SkScalarHalf(fCell.width() - zoomed->width()),
SkScalarHalf(fCell.height() - zoomed->height()));
}
}
示例2: checkOval
int checkOval(int* flatCount, int* buldgeCount) {
int flatc = 0;
int buldgec = 0;
const SkScalar rad = SkScalarHalf(fSize.width());
SkScalar cx = SkScalarHalf(fSize.width());
SkScalar cy = SkScalarHalf(fSize.height());
for (int y = 0; y < kILimit; y++) {
for (int x = 0; x < kILimit; x++) {
// measure from pixel centers
SkScalar px = SkIntToScalar(x) + SK_ScalarHalf;
SkScalar py = SkIntToScalar(y) + SK_ScalarHalf;
SkPMColor* ptr = fBitmap.getAddr32(x, y);
SkScalar dist = SkPoint::Length(px - cx, py - cy);
if (dist <= rad && !*ptr) {
flatc++;
*ptr = fInsideColor;
} else if (dist > rad && *ptr) {
buldgec++;
*ptr = fOutsideColor;
}
}
}
if (flatCount) *flatCount = flatc;
if (buldgeCount) *buldgeCount = buldgec;
return flatc + buldgec;
}
示例3: refBitmapShader
SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix, const SkMatrix* localM) const {
SkASSERT(fPicture && fPicture->width() > 0 && fPicture->height() > 0);
SkMatrix m;
m.setConcat(matrix, this->getLocalMatrix());
if (localM) {
m.preConcat(*localM);
}
// Use a rotation-invariant scale
SkPoint scale;
if (!SkDecomposeUpper2x2(m, NULL, &scale, NULL)) {
// Decomposition failed, use an approximation.
scale.set(SkScalarSqrt(m.getScaleX() * m.getScaleX() + m.getSkewX() * m.getSkewX()),
SkScalarSqrt(m.getScaleY() * m.getScaleY() + m.getSkewY() * m.getSkewY()));
}
SkSize scaledSize = SkSize::Make(scale.x() * fPicture->width(), scale.y() * fPicture->height());
SkISize tileSize = scaledSize.toRound();
if (tileSize.isEmpty()) {
return NULL;
}
// The actual scale, compensating for rounding.
SkSize tileScale = SkSize::Make(SkIntToScalar(tileSize.width()) / fPicture->width(),
SkIntToScalar(tileSize.height()) / fPicture->height());
SkAutoMutexAcquire ama(fCachedBitmapShaderMutex);
if (!fCachedBitmapShader || tileScale != fCachedTileScale) {
SkBitmap bm;
if (!bm.allocN32Pixels(tileSize.width(), tileSize.height())) {
return NULL;
}
bm.eraseColor(SK_ColorTRANSPARENT);
SkCanvas canvas(bm);
canvas.scale(tileScale.width(), tileScale.height());
canvas.drawPicture(fPicture);
fCachedTileScale = tileScale;
SkMatrix shaderMatrix = this->getLocalMatrix();
shaderMatrix.preScale(1 / tileScale.width(), 1 / tileScale.height());
fCachedBitmapShader.reset(CreateBitmapShader(bm, fTmx, fTmy, &shaderMatrix));
}
// Increment the ref counter inside the mutex to ensure the returned pointer is still valid.
// Otherwise, the pointer may have been overwritten on a different thread before the object's
// ref count was incremented.
fCachedBitmapShader.get()->ref();
return fCachedBitmapShader;
}
示例4: processMediumRequest
/*
* Modulo internal errors, this should always succeed *if* the matrix is downscaling
* (in this case, we have the inverse, so it succeeds if fInvMatrix is upscaling)
*/
bool SkDefaultBitmapControllerState::processMediumRequest(const SkBitmapProvider& provider) {
SkASSERT(fQuality <= kMedium_SkFilterQuality);
if (fQuality != kMedium_SkFilterQuality) {
return false;
}
// Our default return state is to downgrade the request to Low, w/ or w/o setting fBitmap
// to a valid bitmap.
fQuality = kLow_SkFilterQuality;
SkSize invScaleSize;
if (!fInvMatrix.decomposeScale(&invScaleSize, nullptr)) {
return false;
}
// Use the largest (non-inverse) scale, to ensure anisotropic consistency.
SkASSERT(invScaleSize.width() >= 0 && invScaleSize.height() >= 0);
const SkScalar invScale = SkTMin(invScaleSize.width(), invScaleSize.height());
if (invScale > SK_Scalar1) {
fCurrMip.reset(SkMipMapCache::FindAndRef(provider.makeCacheDesc()));
if (nullptr == fCurrMip.get()) {
SkBitmap orig;
if (!provider.asBitmap(&orig)) {
return false;
}
fCurrMip.reset(SkMipMapCache::AddAndRef(orig));
if (nullptr == fCurrMip.get()) {
return false;
}
}
// diagnostic for a crasher...
if (nullptr == fCurrMip->data()) {
sk_throw();
}
SkScalar levelScale = SkScalarInvert(invScale);
SkMipMap::Level level;
if (fCurrMip->extractLevel(levelScale, &level)) {
const SkSize& invScaleFixup = level.fScale;
fInvMatrix.postScale(invScaleFixup.width(), invScaleFixup.height());
// todo: if we could wrap the fCurrMip in a pixelref, then we could just install
// that here, and not need to explicitly track it ourselves.
return fResultBitmap.installPixels(level.fPixmap);
} else {
// failed to extract, so release the mipmap
fCurrMip.reset(nullptr);
}
}
return false;
}
示例5: check_decompScale
static bool check_decompScale(const SkMatrix& matrix) {
SkSize scale;
SkMatrix remaining;
if (!matrix.decomposeScale(&scale, &remaining)) {
return false;
}
if (scale.width() <= 0 || scale.height() <= 0) {
return false;
}
remaining.preScale(scale.width(), scale.height());
return nearly_equal(matrix, remaining);
}
示例6: processMediumRequest
/*
* Modulo internal errors, this should always succeed *if* the matrix is downscaling
* (in this case, we have the inverse, so it succeeds if fInvMatrix is upscaling)
*/
bool SkDefaultBitmapControllerState::processMediumRequest(const SkBitmapProvider& provider) {
SkASSERT(fQuality <= kMedium_SkFilterQuality);
if (fQuality != kMedium_SkFilterQuality) {
return false;
}
// Our default return state is to downgrade the request to Low, w/ or w/o setting fBitmap
// to a valid bitmap.
fQuality = kLow_SkFilterQuality;
SkSize invScaleSize;
if (!fInvMatrix.decomposeScale(&invScaleSize, nullptr)) {
return false;
}
SkDestinationSurfaceColorMode colorMode = provider.dstColorSpace()
? SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware
: SkDestinationSurfaceColorMode::kLegacy;
if (invScaleSize.width() > SK_Scalar1 || invScaleSize.height() > SK_Scalar1) {
fCurrMip.reset(SkMipMapCache::FindAndRef(provider.makeCacheDesc(), colorMode));
if (nullptr == fCurrMip.get()) {
SkBitmap orig;
if (!provider.asBitmap(&orig)) {
return false;
}
fCurrMip.reset(SkMipMapCache::AddAndRef(orig, colorMode));
if (nullptr == fCurrMip.get()) {
return false;
}
}
// diagnostic for a crasher...
SkASSERT_RELEASE(fCurrMip->data());
const SkSize scale = SkSize::Make(SkScalarInvert(invScaleSize.width()),
SkScalarInvert(invScaleSize.height()));
SkMipMap::Level level;
if (fCurrMip->extractLevel(scale, &level)) {
const SkSize& invScaleFixup = level.fScale;
fInvMatrix.postScale(invScaleFixup.width(), invScaleFixup.height());
// todo: if we could wrap the fCurrMip in a pixelref, then we could just install
// that here, and not need to explicitly track it ourselves.
return fResultBitmap.installPixels(level.fPixmap);
} else {
// failed to extract, so release the mipmap
fCurrMip.reset(nullptr);
}
}
return false;
}
示例7: draw
void draw(SkCanvas* canvas,
const SkRect& rect,
const SkSize& deviceSize,
SkPaint::FilterLevel filterLevel,
SkImageFilter* input = NULL) {
SkRect dstRect;
canvas->getTotalMatrix().mapRect(&dstRect, rect);
canvas->save();
SkScalar deviceScaleX = SkScalarDiv(deviceSize.width(), dstRect.width());
SkScalar deviceScaleY = SkScalarDiv(deviceSize.height(), dstRect.height());
canvas->translate(rect.x(), rect.y());
canvas->scale(deviceScaleX, deviceScaleY);
canvas->translate(-rect.x(), -rect.y());
SkMatrix matrix;
matrix.setScale(SkScalarInvert(deviceScaleX),
SkScalarInvert(deviceScaleY));
SkAutoTUnref<SkImageFilter> imageFilter(
SkMatrixImageFilter::Create(matrix, filterLevel, input));
SkPaint filteredPaint;
filteredPaint.setImageFilter(imageFilter.get());
canvas->saveLayer(&rect, &filteredPaint);
SkPaint paint;
paint.setColor(0xFF00FF00);
SkRect ovalRect = rect;
ovalRect.inset(SkIntToScalar(4), SkIntToScalar(4));
canvas->drawOval(ovalRect, paint);
canvas->restore(); // for saveLayer
canvas->restore();
}
示例8: map_sigma
static SkVector map_sigma(const SkSize& localSigma, const SkMatrix& ctm) {
SkVector sigma = SkVector::Make(localSigma.width(), localSigma.height());
ctm.mapVectors(&sigma, 1);
sigma.fX = SkMinScalar(SkScalarAbs(sigma.fX), MAX_SIGMA);
sigma.fY = SkMinScalar(SkScalarAbs(sigma.fY), MAX_SIGMA);
return sigma;
}
示例9: SkScalarAbs
bool SkBitmapController::State::processHighRequest(const SkBitmapProvider& provider) {
if (fQuality != kHigh_SkFilterQuality) {
return false;
}
fQuality = kMedium_SkFilterQuality;
SkScalar invScaleX = fInvMatrix.getScaleX();
SkScalar invScaleY = fInvMatrix.getScaleY();
if (fInvMatrix.getType() & SkMatrix::kAffine_Mask) {
SkSize scale;
if (!fInvMatrix.decomposeScale(&scale)) {
return false;
}
invScaleX = scale.width();
invScaleY = scale.height();
}
invScaleX = SkScalarAbs(invScaleX);
invScaleY = SkScalarAbs(invScaleY);
if (invScaleX >= 1 - SK_ScalarNearlyZero || invScaleY >= 1 - SK_ScalarNearlyZero) {
// we're down-scaling so abort HQ
return false;
}
// Confirmed that we can use HQ (w/ rasterpipeline)
fQuality = kHigh_SkFilterQuality;
(void)provider.asBitmap(&fResultBitmap);
return true;
}
示例10: processHQRequest
/*
* High quality is implemented by performing up-right scale-only filtering and then
* using bilerp for any remaining transformations.
*/
bool SkDefaultBitmapControllerState::processHQRequest(const SkBitmap& origBitmap) {
if (fQuality != kHigh_SkFilterQuality) {
return false;
}
// Our default return state is to downgrade the request to Medium, w/ or w/o setting fBitmap
// to a valid bitmap. If we succeed, we will set this to Low instead.
fQuality = kMedium_SkFilterQuality;
if (kN32_SkColorType != origBitmap.colorType() || !cache_size_okay(origBitmap, fInvMatrix) ||
fInvMatrix.hasPerspective())
{
return false; // can't handle the reqeust
}
SkScalar invScaleX = fInvMatrix.getScaleX();
SkScalar invScaleY = fInvMatrix.getScaleY();
if (fInvMatrix.getType() & SkMatrix::kAffine_Mask) {
SkSize scale;
if (!fInvMatrix.decomposeScale(&scale)) {
return false;
}
invScaleX = scale.width();
invScaleY = scale.height();
}
if (SkScalarNearlyEqual(invScaleX, 1) && SkScalarNearlyEqual(invScaleY, 1)) {
return false; // no need for HQ
}
SkScalar trueDestWidth = origBitmap.width() / invScaleX;
SkScalar trueDestHeight = origBitmap.height() / invScaleY;
SkScalar roundedDestWidth = SkScalarRoundToScalar(trueDestWidth);
SkScalar roundedDestHeight = SkScalarRoundToScalar(trueDestHeight);
if (!SkBitmapCache::Find(origBitmap, roundedDestWidth, roundedDestHeight, &fResultBitmap)) {
SkAutoPixmapUnlock src;
if (!origBitmap.requestLock(&src)) {
return false;
}
if (!SkBitmapScaler::Resize(&fResultBitmap, src.pixmap(), SkBitmapScaler::RESIZE_BEST,
roundedDestWidth, roundedDestHeight,
SkResourceCache::GetAllocator())) {
return false; // we failed to create fScaledBitmap
}
SkASSERT(fResultBitmap.getPixels());
fResultBitmap.setImmutable();
SkBitmapCache::Add(origBitmap, roundedDestWidth, roundedDestHeight, fResultBitmap);
}
SkASSERT(fResultBitmap.getPixels());
fInvMatrix.postScale(roundedDestWidth / origBitmap.width(),
roundedDestHeight / origBitmap.height());
fQuality = kLow_SkFilterQuality;
return true;
}
示例11: extractLevel
bool SkMipMap::extractLevel(const SkSize& scaleSize, Level* levelPtr) const {
if (nullptr == fLevels) {
return false;
}
SkASSERT(scaleSize.width() >= 0 && scaleSize.height() >= 0);
#ifndef SK_SUPPORT_LEGACY_ANISOTROPIC_MIPMAP_SCALE
// Use the smallest scale to match the GPU impl.
const SkScalar scale = SkTMin(scaleSize.width(), scaleSize.height());
#else
// Ideally we'd pick the smaller scale, to match Ganesh. But ignoring one of the
// scales can produce some atrocious results, so for now we use the geometric mean.
// (https://bugs.chromium.org/p/skia/issues/detail?id=4863)
const SkScalar scale = SkScalarSqrt(scaleSize.width() * scaleSize.height());
#endif
if (scale >= SK_Scalar1 || scale <= 0 || !SkScalarIsFinite(scale)) {
return false;
}
SkScalar L = -SkScalarLog2(scale);
if (!SkScalarIsFinite(L)) {
return false;
}
SkASSERT(L >= 0);
int level = SkScalarFloorToInt(L);
SkASSERT(level >= 0);
if (level <= 0) {
return false;
}
if (level > fCount) {
level = fCount;
}
if (levelPtr) {
*levelPtr = fLevels[level - 1];
// need to augment with our colorspace
levelPtr->fPixmap.setColorSpace(fCS);
}
return true;
}
示例12: drawBorders
void drawBorders(SkCanvas* canvas) {
SkPaint p;
p.setStyle(SkPaint::kStroke_Style);
p.setColor(SK_ColorBLUE);
SkRect r = SkRect::MakeWH(fCell.width() * 2, fCell.height() * 2);
r.inset(SK_ScalarHalf, SK_ScalarHalf);
canvas->drawRect(r, p);
canvas->drawLine(r.left(), r.centerY(), r.right(), r.centerY(), p);
canvas->drawLine(r.centerX(), r.top(), r.centerX(), r.bottom(), p);
}
示例13: onDrawContent
void onDrawContent(SkCanvas* canvas) override {
fCell.set(this->height() / 2, this->height() / 2);
SkScalar trans[2];
fTrans.timeToValues(fCurrTime, trans);
for (int y = 0; y < 2; ++y) {
for (int x = 0; x < 2; ++x) {
int index = y * 2 + x;
SkAutoCanvasRestore acr(canvas, true);
canvas->translate(fCell.width() * x, fCell.height() * y);
SkRect r = SkRect::MakeWH(fCell.width(), fCell.height());
r.inset(4, 4);
canvas->clipRect(r);
this->drawHere(canvas, SkFilterQuality(index), trans[0], trans[1]);
}
}
this->drawBorders(canvas);
const SkScalar textX = fCell.width() * 2 + 30;
SkPaint paint;
paint.setAntiAlias(true);
paint.setTextSize(36);
SkString str;
str.appendScalar(fScale);
canvas->drawText(str.c_str(), str.size(), textX, 100, paint);
str.reset(); str.appendScalar(fAngle);
canvas->drawText(str.c_str(), str.size(), textX, 150, paint);
str.reset(); str.appendScalar(trans[0]);
canvas->drawText(str.c_str(), str.size(), textX, 200, paint);
str.reset(); str.appendScalar(trans[1]);
canvas->drawText(str.c_str(), str.size(), textX, 250, paint);
}
示例14: processMediumRequest
/*
* Modulo internal errors, this should always succeed *if* the matrix is downscaling
* (in this case, we have the inverse, so it succeeds if fInvMatrix is upscaling)
*/
bool SkDefaultBitmapControllerState::processMediumRequest(const SkBitmap& origBitmap) {
SkASSERT(fQuality <= kMedium_SkFilterQuality);
if (fQuality != kMedium_SkFilterQuality) {
return false;
}
// Our default return state is to downgrade the request to Low, w/ or w/o setting fBitmap
// to a valid bitmap.
fQuality = kLow_SkFilterQuality;
SkSize invScaleSize;
if (!fInvMatrix.decomposeScale(&invScaleSize, NULL)) {
return false;
}
SkScalar invScale = SkScalarSqrt(invScaleSize.width() * invScaleSize.height());
if (invScale > SK_Scalar1) {
fCurrMip.reset(SkMipMapCache::FindAndRef(origBitmap));
if (NULL == fCurrMip.get()) {
fCurrMip.reset(SkMipMapCache::AddAndRef(origBitmap));
if (NULL == fCurrMip.get()) {
return false;
}
}
// diagnostic for a crasher...
if (NULL == fCurrMip->data()) {
sk_throw();
}
SkScalar levelScale = SkScalarInvert(invScale);
SkMipMap::Level level;
if (fCurrMip->extractLevel(levelScale, &level)) {
SkScalar invScaleFixup = level.fScale;
fInvMatrix.postScale(invScaleFixup, invScaleFixup);
const SkImageInfo info = origBitmap.info().makeWH(level.fWidth, level.fHeight);
// todo: if we could wrap the fCurrMip in a pixelref, then we could just install
// that here, and not need to explicitly track it ourselves.
return fResultBitmap.installPixels(info, level.fPixels, level.fRowBytes);
} else {
// failed to extract, so release the mipmap
fCurrMip.reset(NULL);
}
}
return false;
}
示例15: WritePDF
// Here is an example of using Skia’s PDF backend (SkPDF) via the SkDocument
// and SkCanvas APIs.
void WritePDF(SkWStream* outputStream,
const char* documentTitle,
void (*writePage)(SkCanvas*, int page),
int numberOfPages,
SkSize pageSize) {
SkPDF::Metadata metadata;
metadata.fTitle = documentTitle;
metadata.fCreator = "Example WritePDF() Function";
metadata.fCreation = {0, 2019, 1, 4, 31, 12, 34, 56};
metadata.fModified = {0, 2019, 1, 4, 31, 12, 34, 56};
auto pdfDocument = SkPDF::MakeDocument(outputStream, metadata);
SkASSERT(pdfDocument);
for (int page = 0; page < numberOfPages; ++page) {
SkCanvas* pageCanvas = pdfDocument->beginPage(pageSize.width(),
pageSize.height());
writePage(pageCanvas, page);
pdfDocument->endPage();
}
pdfDocument->close();
}