本文整理汇总了C++中SkIRect::width方法的典型用法代码示例。如果您正苦于以下问题:C++ SkIRect::width方法的具体用法?C++ SkIRect::width怎么用?C++ SkIRect::width使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkIRect
的用法示例。
在下文中一共展示了SkIRect::width方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getSampledSubsetDimensions
SkISize SkAndroidCodec::getSampledSubsetDimensions(int sampleSize, const SkIRect& subset) const {
if (!is_valid_sample_size(sampleSize)) {
return SkISize::Make(0, 0);
}
// We require that the input subset is a subset that is supported by SkAndroidCodec.
// We test this by calling getSupportedSubset() and verifying that no modifications
// are made to the subset.
SkIRect copySubset = subset;
if (!this->getSupportedSubset(©Subset) || copySubset != subset) {
return SkISize::Make(0, 0);
}
// If the subset is the entire image, for consistency, use getSampledDimensions().
if (fInfo.dimensions() == subset.size()) {
return this->getSampledDimensions(sampleSize);
}
// This should perhaps call a virtual function, but currently both of our subclasses
// want the same implementation.
return SkISize::Make(get_scaled_dimension(subset.width(), sampleSize),
get_scaled_dimension(subset.height(), sampleSize));
}
示例2: onFilterImageDeprecated
bool onFilterImageDeprecated(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* dst, SkIPoint* offset) const override {
SkBitmap source = src;
SkIPoint srcOffset = SkIPoint::Make(0, 0);
if (!this->filterInputDeprecated(0, proxy, src, ctx, &source, &srcOffset)) {
return false;
}
SkIRect bounds;
if (!this->applyCropRectDeprecated(ctx, proxy, source, &srcOffset, &bounds, &source)) {
return false;
}
SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds.height()));
SkCanvas canvas(device);
SkPaint paint;
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
canvas.drawBitmap(source, fDX - bounds.left(), fDY - bounds.top(), &paint);
*dst = device->accessBitmap(false);
offset->fX += bounds.left();
offset->fY += bounds.top();
return true;
}
示例3: draw_sprite
static void draw_sprite(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
SkPaint paint;
SkIRect bounds;
r.roundOut(&bounds);
SkBitmap bm;
bm.setConfig(SkBitmap::kARGB_8888_Config, bounds.width(), bounds.height());
bm.allocPixels();
bm.eraseColor(SK_ColorRED);
SkCanvas c(bm);
SkIRect cropRect = SkIRect::MakeXYWH(10, 10, 44, 44);
paint.setColor(SK_ColorGREEN);
c.drawRect(SkRect::Make(cropRect), paint);
paint.setImageFilter(imf);
SkPoint loc = { r.fLeft, r.fTop };
canvas->getTotalMatrix().mapPoints(&loc, 1);
canvas->drawSprite(bm,
SkScalarRoundToInt(loc.fX), SkScalarRoundToInt(loc.fY),
&paint);
}
示例4: while
static void SkARGB32_Blit32(const SkBitmap& device, const SkMask& mask,
const SkIRect& clip, SkPMColor srcColor) {
U8CPU alpha = SkGetPackedA32(srcColor);
unsigned flags = SkBlitRow::kSrcPixelAlpha_Flag32;
if (alpha != 255) {
flags |= SkBlitRow::kGlobalAlpha_Flag32;
}
SkBlitRow::Proc32 proc = SkBlitRow::Factory32(flags);
int x = clip.fLeft;
int y = clip.fTop;
int width = clip.width();
int height = clip.height();
SkPMColor* dstRow = device.getAddr32(x, y);
const SkPMColor* srcRow = reinterpret_cast<const SkPMColor*>(mask.getAddr8(x, y));
do {
proc(dstRow, srcRow, width, alpha);
dstRow = (SkPMColor*)((char*)dstRow + device.rowBytes());
srcRow = (const SkPMColor*)((const char*)srcRow + mask.fRowBytes);
} while (--height != 0);
}
示例5: onFilterImageDeprecated
bool SkPictureImageFilter::onFilterImageDeprecated(Proxy* proxy, const SkBitmap&,
const Context& ctx,
SkBitmap* result, SkIPoint* offset) const {
if (!fPicture) {
offset->fX = offset->fY = 0;
return true;
}
SkRect floatBounds;
ctx.ctm().mapRect(&floatBounds, fCropRect);
SkIRect bounds = floatBounds.roundOut();
if (!bounds.intersect(ctx.clipBounds())) {
return false;
}
if (bounds.isEmpty()) {
offset->fX = offset->fY = 0;
return true;
}
SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds.height()));
if (nullptr == device.get()) {
return false;
}
if (kDeviceSpace_PictureResolution == fPictureResolution ||
0 == (ctx.ctm().getType() & ~SkMatrix::kTranslate_Mask)) {
this->drawPictureAtDeviceResolution(device.get(), bounds, ctx);
} else {
this->drawPictureAtLocalResolution(proxy, device.get(), bounds, ctx);
}
*result = device.get()->accessBitmap(false);
offset->fX = bounds.fLeft;
offset->fY = bounds.fTop;
return true;
}
示例6:
void SkImageFilter::CropRect::applyTo(const SkIRect& imageBounds,
const SkMatrix& ctm,
bool embiggen,
SkIRect* cropped) const {
*cropped = imageBounds;
if (fFlags) {
SkRect devCropR;
ctm.mapRect(&devCropR, fRect);
SkIRect devICropR = devCropR.roundOut();
// Compute the left/top first, in case we need to modify the right/bottom for a missing edge
if (fFlags & kHasLeft_CropEdge) {
if (embiggen || devICropR.fLeft > cropped->fLeft) {
cropped->fLeft = devICropR.fLeft;
}
} else {
devICropR.fRight = cropped->fLeft + devICropR.width();
}
if (fFlags & kHasTop_CropEdge) {
if (embiggen || devICropR.fTop > cropped->fTop) {
cropped->fTop = devICropR.fTop;
}
} else {
devICropR.fBottom = cropped->fTop + devICropR.height();
}
if (fFlags & kHasWidth_CropEdge) {
if (embiggen || devICropR.fRight < cropped->fRight) {
cropped->fRight = devICropR.fRight;
}
}
if (fFlags & kHasHeight_CropEdge) {
if (embiggen || devICropR.fBottom < cropped->fBottom) {
cropped->fBottom = devICropR.fBottom;
}
}
}
}
示例7: SkASSERT
void SkARGB32_Black_Blitter::blitMask(const SkMask& mask, const SkIRect& clip) {
SkASSERT(mask.fBounds.contains(clip));
if (mask.fFormat == SkMask::kBW_Format) {
SkPMColor black = (SkPMColor)(SK_A32_MASK << SK_A32_SHIFT);
SkARGB32_BlitBW(fDevice, mask, clip, black);
} else if (SkMask::kARGB32_Format == mask.fFormat) {
SkARGB32_Blit32(fDevice, mask, clip, fPMColor);
} else if (SkMask::kLCD16_Format == mask.fFormat) {
blitmask_lcd16(fDevice, mask, clip, fPMColor);
} else if (SkMask::kLCD32_Format == mask.fFormat) {
blitmask_lcd32(fDevice, mask, clip, fPMColor);
} else {
unsigned width = clip.width();
unsigned height = clip.height();
SkASSERT((int)height > 0);
SkASSERT((int)width > 0);
uint32_t* device = fDevice.getAddr32(clip.fLeft, clip.fTop);
unsigned maskRB = mask.fRowBytes - width;
unsigned deviceRB = fDevice.rowBytes() - (width << 2);
const uint8_t* alpha = mask.getAddr(clip.fLeft, clip.fTop);
do {
unsigned w = width;
do {
unsigned aa = *alpha++;
*device = (aa << SK_A32_SHIFT) + SkAlphaMulQ(*device, SkAlpha255To256(255 - aa));
device += 1;
} while (--w != 0);
device = (uint32_t*)((char*)device + deviceRB);
alpha += maskRB;
} while (--height != 0);
}
}
示例8: GrIsImageInCache
bool GrIsImageInCache(const GrContext* ctx, uint32_t imageID, const SkIRect& subset,
GrTexture* nativeTexture, const GrTextureParams* params) {
SkGrStretch stretch;
get_stretch(ctx, subset.width(), subset.height(), params, &stretch);
// Handle the case where the bitmap/image is explicitly texture backed.
if (nativeTexture) {
if (SkGrStretch::kNone_Type == stretch.fType) {
return true;
}
const GrUniqueKey& key = nativeTexture->getUniqueKey();
if (!key.isValid()) {
return false;
}
GrUniqueKey stretchedKey;
GrMakeStretchedKey(key, stretch, &stretchedKey);
return ctx->textureProvider()->existsTextureWithUniqueKey(stretchedKey);
}
GrUniqueKey key, stretchedKey;
make_image_keys(imageID, subset, stretch, &key, &stretchedKey);
return ctx->textureProvider()->existsTextureWithUniqueKey(
(SkGrStretch::kNone_Type == stretch.fType) ? key : stretchedKey);
}
示例9: onFilterImageDeprecated
bool SkImageSource::onFilterImageDeprecated(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const {
SkRect dstRect;
ctx.ctm().mapRect(&dstRect, fDstRect);
SkRect bounds = SkRect::MakeIWH(fImage->width(), fImage->height());
if (fSrcRect == bounds && dstRect == bounds) {
// No regions cropped out or resized; return entire image.
offset->fX = offset->fY = 0;
return fImage->asLegacyBitmap(result, SkImage::kRO_LegacyBitmapMode);
}
const SkIRect dstIRect = dstRect.roundOut();
SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(dstIRect.width(), dstIRect.height()));
if (nullptr == device.get()) {
return false;
}
SkCanvas canvas(device.get());
SkPaint paint;
// Subtract off the integer component of the translation (will be applied in loc, below).
dstRect.offset(-SkIntToScalar(dstIRect.fLeft), -SkIntToScalar(dstIRect.fTop));
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
// FIXME: this probably shouldn't be necessary, but drawImageRect asserts
// None filtering when it's translate-only
paint.setFilterQuality(
fSrcRect.width() == dstRect.width() && fSrcRect.height() == dstRect.height() ?
kNone_SkFilterQuality : fFilterQuality);
canvas.drawImageRect(fImage, fSrcRect, dstRect, &paint, SkCanvas::kStrict_SrcRectConstraint);
*result = device.get()->accessBitmap(false);
offset->fX = dstIRect.fLeft;
offset->fY = dstIRect.fTop;
return true;
}
示例10: test_surface
// Exercise the public API of SkSpecialSurface (e.g., getCanvas, newImageSnapshot)
static void test_surface(const sk_sp<SkSpecialSurface>& surf,
skiatest::Reporter* reporter,
int offset) {
const SkIRect surfSubset = TestingSpecialSurfaceAccess::Subset(surf.get());
REPORTER_ASSERT(reporter, offset == surfSubset.fLeft);
REPORTER_ASSERT(reporter, offset == surfSubset.fTop);
REPORTER_ASSERT(reporter, kSmallerSize == surfSubset.width());
REPORTER_ASSERT(reporter, kSmallerSize == surfSubset.height());
SkCanvas* canvas = surf->getCanvas();
SkASSERT_RELEASE(canvas);
canvas->clear(SK_ColorRED);
sk_sp<SkSpecialImage> img(surf->makeImageSnapshot());
REPORTER_ASSERT(reporter, img);
const SkIRect imgSubset = img->subset();
REPORTER_ASSERT(reporter, surfSubset == imgSubset);
// the canvas was invalidated by the newImageSnapshot call
REPORTER_ASSERT(reporter, !surf->getCanvas());
}
示例11: canvas
PassOwnPtr<Vector<char>> PictureSnapshot::replay(unsigned fromStep, unsigned toStep, double scale) const
{
const SkIRect bounds = m_picture->cullRect().roundOut();
// TODO(fmalita): convert this to SkSurface/SkImage, drop the intermediate SkBitmap.
SkBitmap bitmap;
bitmap.allocPixels(SkImageInfo::MakeN32Premul(bounds.width(), bounds.height()));
bitmap.eraseARGB(0, 0, 0, 0);
{
ReplayingCanvas canvas(bitmap, fromStep, toStep);
// Disable LCD text preemptively, because the picture opacity is unknown.
// The canonical API involves SkSurface props, but since we're not SkSurface-based
// at this point (see TODO above) we (ab)use saveLayer for this purpose.
SkAutoCanvasRestore autoRestore(&canvas, false);
canvas.saveLayer(nullptr, nullptr);
canvas.scale(scale, scale);
canvas.resetStepCount();
m_picture->playback(&canvas, &canvas);
}
OwnPtr<Vector<char>> base64Data = adoptPtr(new Vector<char>());
Vector<char> encodedImage;
RefPtr<SkImage> image = adoptRef(SkImage::NewFromBitmap(bitmap));
if (!image)
return nullptr;
ImagePixelLocker pixelLocker(image, kUnpremul_SkAlphaType, kRGBA_8888_SkColorType);
ImageDataBuffer imageData(IntSize(image->width(), image->height()),
static_cast<const unsigned char*>(pixelLocker.pixels()));
if (!PNGImageEncoder::encode(imageData, reinterpret_cast<Vector<unsigned char>*>(&encodedImage)))
return nullptr;
base64Encode(encodedImage, *base64Data);
return base64Data.release();
}
示例12: drawStretchyPatch
static void drawStretchyPatch(SkCanvas* canvas, SkIRect& src, const SkRect& dst,
const SkBitmap& bitmap, const SkPaint& paint,
SkColor initColor, uint32_t colorHint,
bool hasXfer) {
if (colorHint != android::Res_png_9patch::NO_COLOR) {
((SkPaint*)&paint)->setColor(modAlpha(colorHint, paint.getAlpha()));
canvas->drawRect(dst, paint);
((SkPaint*)&paint)->setColor(initColor);
} else if (src.width() == 1 && src.height() == 1) {
SkColor c;
if (!getColor(bitmap, src.fLeft, src.fTop, &c)) {
goto SLOW_CASE;
}
if (0 != c || hasXfer) {
SkColor prev = paint.getColor();
((SkPaint*)&paint)->setColor(c);
canvas->drawRect(dst, paint);
((SkPaint*)&paint)->setColor(prev);
}
} else {
SLOW_CASE:
canvas->drawBitmapRect(bitmap, &src, dst, &paint);
}
}
示例13: onApplyFilter
SkImage* SkImage_Base::onApplyFilter(SkImageFilter* filter, SkIPoint* offsetResult,
bool forceResultToOriginalSize) const {
SkBitmap src;
if (!this->getROPixels(&src)) {
return nullptr;
}
const SkIRect srcBounds = SkIRect::MakeWH(this->width(), this->height());
if (forceResultToOriginalSize) {
const SkIRect clipBounds = srcBounds;
SkRasterImageFilterProxy proxy;
SkImageFilter::Context ctx(SkMatrix::I(), clipBounds, SkImageFilter::Cache::Get(),
SkImageFilter::kExact_SizeConstraint);
SkBitmap dst;
if (filter->filterImage(&proxy, src, ctx, &dst, offsetResult)) {
dst.setImmutable();
return SkImage::NewFromBitmap(dst);
}
} else {
const SkIRect dstR = compute_fast_ibounds(filter, srcBounds);
SkImageInfo info = SkImageInfo::MakeN32Premul(dstR.width(), dstR.height());
SkAutoTUnref<SkSurface> surface(this->onNewSurface(info));
SkPaint paint;
paint.setImageFilter(filter);
surface->getCanvas()->drawImage(this, SkIntToScalar(-dstR.x()), SkIntToScalar(-dstR.y()),
&paint);
offsetResult->set(dstR.x(), dstR.y());
return surface->newImageSnapshot();
}
return nullptr;
}
示例14:
bool SkImageFilter::CropRect::applyTo(const SkIRect& imageBounds, const Context& ctx,
SkIRect* cropped) const {
*cropped = imageBounds;
if (fFlags) {
SkRect devCropR;
ctx.ctm().mapRect(&devCropR, fRect);
const SkIRect devICropR = devCropR.roundOut();
// Compute the left/top first, in case we have to read them to compute right/bottom
if (fFlags & kHasLeft_CropEdge) {
cropped->fLeft = devICropR.fLeft;
}
if (fFlags & kHasTop_CropEdge) {
cropped->fTop = devICropR.fTop;
}
if (fFlags & kHasWidth_CropEdge) {
cropped->fRight = cropped->fLeft + devICropR.width();
}
if (fFlags & kHasHeight_CropEdge) {
cropped->fBottom = cropped->fTop + devICropR.height();
}
}
return cropped->intersect(ctx.clipBounds());
}
示例15: SkASSERT
SkNinePatchIter::SkNinePatchIter(int w, int h, const SkIRect& c, const SkRect& dst) {
SkASSERT(SkIRect::MakeWH(w, h).contains(c));
fSrcX[0] = 0;
fSrcX[1] = SkIntToScalar(c.fLeft);
fSrcX[2] = SkIntToScalar(c.fRight);
fSrcX[3] = SkIntToScalar(w);
fSrcY[0] = 0;
fSrcY[1] = SkIntToScalar(c.fTop);
fSrcY[2] = SkIntToScalar(c.fBottom);
fSrcY[3] = SkIntToScalar(h);
fDstX[0] = dst.fLeft;
fDstX[1] = dst.fLeft + SkIntToScalar(c.fLeft);
fDstX[2] = dst.fRight - SkIntToScalar(w - c.fRight);
fDstX[3] = dst.fRight;
fDstY[0] = dst.fTop;
fDstY[1] = dst.fTop + SkIntToScalar(c.fTop);
fDstY[2] = dst.fBottom - SkIntToScalar(h - c.fBottom);
fDstY[3] = dst.fBottom;
if (fDstX[1] > fDstX[2]) {
fDstX[1] = fDstX[0] + (fDstX[3] - fDstX[0]) * c.fLeft / (w - c.width());
fDstX[2] = fDstX[1];
}
if (fDstY[1] > fDstY[2]) {
fDstY[1] = fDstY[0] + (fDstY[3] - fDstY[0]) * c.fTop / (h - c.height());
fDstY[2] = fDstY[1];
}
fCurrX = fCurrY = 0;
fDone = false;
}