本文整理汇总了C++中SkISize::width方法的典型用法代码示例。如果您正苦于以下问题:C++ SkISize::width方法的具体用法?C++ SkISize::width怎么用?C++ SkISize::width使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkISize
的用法示例。
在下文中一共展示了SkISize::width方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: scaling_supported
// check if scaling to dstInfo size from srcInfo size using sampleSize is possible
static bool scaling_supported(const SkISize& dstDim, const SkISize& srcDim,
int* sampleX, int* sampleY) {
SkScaledCodec::ComputeSampleSize(dstDim, srcDim, sampleX, sampleY);
const int dstWidth = dstDim.width();
const int dstHeight = dstDim.height();
const int srcWidth = srcDim.width();
const int srcHeight = srcDim.height();
// only support down sampling, not up sampling
if (dstWidth > srcWidth || dstHeight > srcHeight) {
return false;
}
// check that srcWidth is scaled down by an integer value
if (get_scaled_dimension(srcWidth, *sampleX) != dstWidth) {
return false;
}
// check that src height is scaled down by an integer value
if (get_scaled_dimension(srcHeight, *sampleY) != dstHeight) {
return false;
}
// sampleX and sampleY should be equal unless the original sampleSize requested was larger
// than srcWidth or srcHeight. If so, the result of this is dstWidth or dstHeight = 1.
// This functionality allows for tall thin images to still be scaled down by scaling factors.
if (*sampleX != *sampleY){
if (1 != dstWidth && 1 != dstHeight) {
return false;
}
}
return true;
}
示例2: onDraw
void onDraw(int loops, SkCanvas* canvas) override {
canvas->clear(SK_ColorBLACK);
SkISize size = canvas->getDeviceSize();
int offX = (size.width() - kWindowSize) / kNumStepsX;
int offY = (size.height() - kWindowSize) / kNumStepsY;
SkPaint paint;
paint.setColor(SK_ColorBLUE);
canvas->drawCircle(SkIntToScalar(size.width()/2),
SkIntToScalar(size.height()/2),
SkIntToScalar(size.width()/2),
paint);
SkBitmap bitmap;
bitmap.setInfo(SkImageInfo::MakeN32Premul(kWindowSize, kWindowSize));
for (int i = 0; i < loops; i++) {
for (int x = 0; x < kNumStepsX; ++x) {
for (int y = 0; y < kNumStepsY; ++y) {
canvas->readPixels(&bitmap, x * offX, y * offY);
}
}
}
}
示例3: onDrawContent
void GMSampleView::onDrawContent(SkCanvas* canvas) {
SkPictureRecorder recorder;
SkCanvas* origCanvas = canvas;
if (false) {
SkISize size = fGM->getISize();
canvas = recorder.beginRecording(SkRect::MakeIWH(size.width(), size.height()));
}
{
SkAutoCanvasRestore acr(canvas, fShowSize);
fGM->drawContent(canvas);
}
if (origCanvas != canvas) {
sk_sp<SkPicture> pic = recorder.finishRecordingAsPicture();
if (false) {
pic = round_trip_serialize(pic.get());
}
origCanvas->drawPicture(pic);
canvas = origCanvas;
}
if (fShowSize) {
SkISize size = fGM->getISize();
SkRect r = SkRect::MakeWH(SkIntToScalar(size.width()),
SkIntToScalar(size.height()));
SkPaint paint;
paint.setColor(0x40FF8833);
canvas->drawRect(r, paint);
}
}
示例4: extractScaledImageFragment
// This function is used to scale an image and extract a scaled fragment.
//
// ALGORITHM
//
// Because the scaled image size has to be integers, we approximate the real
// scale with the following formula (only X direction is shown):
//
// scaledImageWidth = round(scaleX * imageRect.width())
// approximateScaleX = scaledImageWidth / imageRect.width()
//
// With this method we maintain a constant scale factor among fragments in
// the scaled image. This allows fragments to stitch together to form the
// full scaled image. The downside is there will be a small difference
// between |scaleX| and |approximateScaleX|.
//
// A scaled image fragment is identified by:
//
// - Scaled image size
// - Scaled image fragment rectangle (IntRect)
//
// Scaled image size has been determined and the next step is to compute the
// rectangle for the scaled image fragment which needs to be an IntRect.
//
// scaledSrcRect = srcRect * (approximateScaleX, approximateScaleY)
// enclosingScaledSrcRect = enclosingIntRect(scaledSrcRect)
//
// Finally we extract the scaled image fragment using
// (scaledImageSize, enclosingScaledSrcRect).
//
SkBitmap NativeImageSkia::extractScaledImageFragment(const SkRect& srcRect, float scaleX, float scaleY, SkRect* scaledSrcRect) const
{
SkISize imageSize = SkISize::Make(bitmap().width(), bitmap().height());
SkISize scaledImageSize = SkISize::Make(clampToInteger(roundf(imageSize.width() * scaleX)),
clampToInteger(roundf(imageSize.height() * scaleY)));
SkRect imageRect = SkRect::MakeWH(imageSize.width(), imageSize.height());
SkRect scaledImageRect = SkRect::MakeWH(scaledImageSize.width(), scaledImageSize.height());
SkMatrix scaleTransform;
scaleTransform.setRectToRect(imageRect, scaledImageRect, SkMatrix::kFill_ScaleToFit);
scaleTransform.mapRect(scaledSrcRect, srcRect);
bool ok = scaledSrcRect->intersect(scaledImageRect);
ASSERT_UNUSED(ok, ok);
SkIRect enclosingScaledSrcRect = enclosingIntRect(*scaledSrcRect);
// |enclosingScaledSrcRect| can be larger than |scaledImageSize| because
// of float inaccuracy so clip to get inside.
ok = enclosingScaledSrcRect.intersect(SkIRect::MakeSize(scaledImageSize));
ASSERT_UNUSED(ok, ok);
// scaledSrcRect is relative to the pixel snapped fragment we're extracting.
scaledSrcRect->offset(-enclosingScaledSrcRect.x(), -enclosingScaledSrcRect.y());
return resizedBitmap(scaledImageSize, enclosingScaledSrcRect);
}
示例5: best_scaled_dimensions
static SkISize best_scaled_dimensions(const SkISize& origDims, const SkISize& nativeDims,
const SkISize& scaledCodecDims, float desiredScale) {
if (nativeDims == scaledCodecDims) {
// does not matter which to return if equal. Return here to skip below calculations
return nativeDims;
}
float idealWidth = origDims.width() * desiredScale;
float idealHeight = origDims.height() * desiredScale;
// calculate difference between native dimensions and ideal dimensions
float nativeWDiff = SkTAbs(idealWidth - nativeDims.width());
float nativeHDiff = SkTAbs(idealHeight - nativeDims.height());
float nativeDiff = nativeWDiff + nativeHDiff;
// Native scaling is preferred to sampling. If we can scale natively to
// within one of the ideal value, we should choose to scale natively.
if (nativeWDiff < 1.0f && nativeHDiff < 1.0f) {
return nativeDims;
}
// calculate difference between scaledCodec dimensions and ideal dimensions
float scaledCodecWDiff = SkTAbs(idealWidth - scaledCodecDims.width());
float scaledCodecHDiff = SkTAbs(idealHeight - scaledCodecDims.height());
float scaledCodecDiff = scaledCodecWDiff + scaledCodecHDiff;
// return dimensions closest to ideal dimensions.
// If the differences are equal, return nativeDims, as native scaling is more efficient.
return nativeDiff > scaledCodecDiff ? scaledCodecDims : nativeDims;
}
示例6: test_dimensions
static void test_dimensions(skiatest::Reporter* r, const char path[]) {
// Create the codec from the resource file
SkAutoTDelete<SkStream> stream(resource(path));
if (!stream) {
SkDebugf("Missing resource '%s'\n", path);
return;
}
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach()));
if (!codec) {
ERRORF(r, "Unable to create codec '%s'", path);
return;
}
// Check that the decode is successful for a variety of scales
for (float scale = -0.05f; scale < 2.0f; scale += 0.05f) {
// Scale the output dimensions
SkISize scaledDims = codec->getScaledDimensions(scale);
SkImageInfo scaledInfo = codec->getInfo().makeWH(scaledDims.width(), scaledDims.height());
// Set up for the decode
size_t rowBytes = scaledDims.width() * sizeof(SkPMColor);
size_t totalBytes = scaledInfo.getSafeSize(rowBytes);
SkAutoTMalloc<SkPMColor> pixels(totalBytes);
SkImageGenerator::Result result =
codec->getPixels(scaledInfo, pixels.get(), rowBytes, NULL, NULL, NULL);
REPORTER_ASSERT(r, SkImageGenerator::kSuccess == result);
}
}
示例7: test_dimensions
static void test_dimensions(skiatest::Reporter* r, const char path[]) {
// Create the codec from the resource file
SkAutoTDelete<SkStream> stream(resource(path));
if (!stream) {
SkDebugf("Missing resource '%s'\n", path);
return;
}
SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromStream(stream.detach()));
if (!codec) {
ERRORF(r, "Unable to create codec '%s'", path);
return;
}
// Check that the decode is successful for a variety of scales
for (int sampleSize = 1; sampleSize < 32; sampleSize++) {
// Scale the output dimensions
SkISize scaledDims = codec->getSampledDimensions(sampleSize);
SkImageInfo scaledInfo = codec->getInfo()
.makeWH(scaledDims.width(), scaledDims.height())
.makeColorType(kN32_SkColorType);
// Set up for the decode
size_t rowBytes = scaledDims.width() * sizeof(SkPMColor);
size_t totalBytes = scaledInfo.getSafeSize(rowBytes);
SkAutoTMalloc<SkPMColor> pixels(totalBytes);
SkAndroidCodec::AndroidOptions options;
options.fSampleSize = sampleSize;
SkCodec::Result result =
codec->getAndroidPixels(scaledInfo, pixels.get(), rowBytes, &options);
REPORTER_ASSERT(r, SkCodec::kSuccess == result);
}
}
示例8: setupCurrentSlide
void Viewer::setupCurrentSlide(int previousSlide) {
if (fCurrentSlide == previousSlide) {
return; // no change; do nothing
}
fGesture.reset();
fDefaultMatrix.reset();
fDefaultMatrixInv.reset();
if (fWindow->supportsContentRect() && fWindow->scaleContentToFit()) {
const SkRect contentRect = fWindow->getContentRect();
const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions();
const SkRect slideBounds = SkRect::MakeIWH(slideSize.width(), slideSize.height());
if (contentRect.width() > 0 && contentRect.height() > 0) {
fDefaultMatrix.setRectToRect(slideBounds, contentRect, SkMatrix::kStart_ScaleToFit);
SkAssertResult(fDefaultMatrix.invert(&fDefaultMatrixInv));
}
}
if (fWindow->supportsContentRect()) {
const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions();
SkRect windowRect = fWindow->getContentRect();
fDefaultMatrixInv.mapRect(&windowRect);
fGesture.setTransLimit(SkRect::MakeWH(slideSize.width(), slideSize.height()), windowRect);
}
this->updateTitle();
this->updateUIState();
fSlides[fCurrentSlide]->load();
if (previousSlide >= 0) {
fSlides[previousSlide]->unload();
}
fWindow->inval();
}
示例9: drawClippedRect
void drawClippedRect(SkCanvas* canvas, int x, int y, const SkPaint& paint) {
canvas->save();
canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y),
SkIntToScalar(fSize.width()), SkIntToScalar(fSize.height())));
SkRect r = SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y),
SkIntToScalar(fSize.width()),
SkIntToScalar(fSize.height()));
canvas->drawRect(r, paint);
canvas->restore();
}
示例10: make_bitmap
void make_bitmap() {
fBitmap.allocN32Pixels(fSize.width(), fSize.height());
SkCanvas canvas(fBitmap);
canvas.clear(0x00000000);
SkPaint paint;
paint.setAntiAlias(true);
SkShader* shader = MakeLinear(fSize);
paint.setShader(shader);
SkRect r = { 0, 0, SkIntToScalar(fSize.width()), SkIntToScalar(fSize.height()) };
canvas.drawRect(r, paint);
shader->unref();
}
示例11: 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;
}
示例12: INHERITED
GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(sk_sp<GrTextureProxy> proxy,
const SkIRect& bounds,
const SkISize& kernelSize,
const SkScalar* kernel,
SkScalar gain,
SkScalar bias,
const SkIPoint& kernelOffset,
GrTextureDomain::Mode tileMode,
bool convolveAlpha)
// To advertise either the modulation or opaqueness optimizations we'd have to examine the
// parameters.
: INHERITED(kGrMatrixConvolutionEffect_ClassID, kNone_OptimizationFlags)
, fCoordTransform(proxy.get())
, fDomain(proxy.get(), GrTextureDomain::MakeTexelDomainForMode(bounds, tileMode), tileMode)
, fTextureSampler(std::move(proxy))
, fKernelSize(kernelSize)
, fGain(SkScalarToFloat(gain))
, fBias(SkScalarToFloat(bias) / 255.0f)
, fConvolveAlpha(convolveAlpha) {
this->addCoordTransform(&fCoordTransform);
this->addTextureSampler(&fTextureSampler);
for (int i = 0; i < kernelSize.width() * kernelSize.height(); i++) {
fKernel[i] = SkScalarToFloat(kernel[i]);
}
fKernelOffset[0] = static_cast<float>(kernelOffset.x());
fKernelOffset[1] = static_cast<float>(kernelOffset.y());
}
示例13: Make
std::unique_ptr<GrFragmentProcessor> GrMatrixConvolutionEffect::TestCreate(GrProcessorTestData* d) {
int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
: GrProcessorUnitTest::kAlphaTextureIdx;
sk_sp<GrTextureProxy> proxy = d->textureProxy(texIdx);
int width = d->fRandom->nextRangeU(1, MAX_KERNEL_SIZE);
int height = d->fRandom->nextRangeU(1, MAX_KERNEL_SIZE / width);
SkISize kernelSize = SkISize::Make(width, height);
std::unique_ptr<SkScalar[]> kernel(new SkScalar[width * height]);
for (int i = 0; i < width * height; i++) {
kernel.get()[i] = d->fRandom->nextSScalar1();
}
SkScalar gain = d->fRandom->nextSScalar1();
SkScalar bias = d->fRandom->nextSScalar1();
SkIPoint kernelOffset = SkIPoint::Make(d->fRandom->nextRangeU(0, kernelSize.width()),
d->fRandom->nextRangeU(0, kernelSize.height()));
SkIRect bounds = SkIRect::MakeXYWH(d->fRandom->nextRangeU(0, proxy->width()),
d->fRandom->nextRangeU(0, proxy->height()),
d->fRandom->nextRangeU(0, proxy->width()),
d->fRandom->nextRangeU(0, proxy->height()));
GrTextureDomain::Mode tileMode =
static_cast<GrTextureDomain::Mode>(d->fRandom->nextRangeU(0, 2));
bool convolveAlpha = d->fRandom->nextBool();
return GrMatrixConvolutionEffect::Make(std::move(proxy),
bounds,
kernelSize,
kernel.get(),
gain,
bias,
kernelOffset,
tileMode,
convolveAlpha);
}
示例14: op
bool SkRasterClip::op(const SkPath& path, const SkISize& size, SkRegion::Op op, bool doAA) {
// base is used to limit the size (and therefore memory allocation) of the
// region that results from scan converting devPath.
SkRegion base;
if (SkRegion::kIntersect_Op == op) {
// since we are intersect, we can do better (tighter) with currRgn's
// bounds, than just using the device. However, if currRgn is complex,
// our region blitter may hork, so we do that case in two steps.
if (this->isRect()) {
// FIXME: we should also be able to do this when this->isBW(),
// but relaxing the test above triggers GM asserts in
// SkRgnBuilder::blitH(). We need to investigate what's going on.
return this->setPath(path, this->bwRgn(), doAA);
} else {
base.setRect(this->getBounds());
SkRasterClip clip;
clip.setPath(path, base, doAA);
return this->op(clip, op);
}
} else {
base.setRect(0, 0, size.width(), size.height());
if (SkRegion::kReplace_Op == op) {
return this->setPath(path, base, doAA);
} else {
SkRasterClip clip;
clip.setPath(path, base, doAA);
return this->op(clip, op);
}
}
}
示例15: createComplete
PassOwnPtr<ScaledImageFragment> createCompleteImage(const SkISize& size)
{
SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height());
bitmap.allocPixels();
return ScaledImageFragment::createComplete(size, 0, bitmap);
}