本文整理汇总了C++中SkISize类的典型用法代码示例。如果您正苦于以下问题:C++ SkISize类的具体用法?C++ SkISize怎么用?C++ SkISize使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SkISize类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ASSERT
// Creates an SkImage that is backed by SkDiscardablePixelRef.
PassRefPtr<SkImage> DeferredImageDecoder::createImage(size_t index, bool knownToBeOpaque) const
{
SkISize decodedSize = m_frameGenerator->getFullSize();
ASSERT(decodedSize.width() > 0);
ASSERT(decodedSize.height() > 0);
const SkImageInfo info = SkImageInfo::MakeN32(decodedSize.width(), decodedSize.height(),
knownToBeOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
DecodingImageGenerator* generator = new DecodingImageGenerator(m_frameGenerator, info, index);
RefPtr<SkImage> image = adoptRef(SkImage::NewFromGenerator(generator));
if (!image)
return nullptr;
generator->setGenerationId(image->uniqueID());
return image.release();
}
示例2: fWriter
SkSVGDevice::SkSVGDevice(const SkISize& size, SkXMLWriter* writer)
: fWriter(writer)
, fResourceBucket(SkNEW(ResourceBucket)) {
SkASSERT(writer);
fLegacyBitmap.setInfo(SkImageInfo::MakeUnknown(size.width(), size.height()));
fWriter->writeHeader();
// The root <svg> tag gets closed by the destructor.
fRootElement.reset(SkNEW_ARGS(AutoElement, ("svg", fWriter)));
fRootElement->addAttribute("xmlns", "http://www.w3.org/2000/svg");
fRootElement->addAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
fRootElement->addAttribute("width", size.width());
fRootElement->addAttribute("height", size.height());
}
示例3: INHERITED
SkSVGDevice::SkSVGDevice(const SkISize& size, SkXMLWriter* writer)
: INHERITED(SkImageInfo::MakeUnknown(size.fWidth, size.fHeight),
SkSurfaceProps(0, kUnknown_SkPixelGeometry))
, fWriter(writer)
, fResourceBucket(new ResourceBucket)
{
SkASSERT(writer);
fWriter->writeHeader();
// The root <svg> tag gets closed by the destructor.
fRootElement.reset(new AutoElement("svg", fWriter));
fRootElement->addAttribute("xmlns", "http://www.w3.org/2000/svg");
fRootElement->addAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
fRootElement->addAttribute("width", size.width());
fRootElement->addAttribute("height", size.height());
}
示例4: drawJpeg
static void drawJpeg(SkCanvas* canvas, const SkISize& size) {
// TODO: Make this draw a file that is checked in, so it can
// be exercised on machines other than mike's. Will require a
// rebaseline.
SkAutoDataUnref data(SkData::NewFromFileName("/Users/mike/Downloads/skia.google.jpeg"));
if (NULL == data.get()) {
return;
}
SkImage* image = SkImage::NewFromGenerator(
SkDecodingImageGenerator::Create(data, SkDecodingImageGenerator::Options()));
if (image) {
SkAutoCanvasRestore acr(canvas, true);
canvas->scale(size.width() * 1.0f / image->width(),
size.height() * 1.0f / image->height());
canvas->drawImage(image, 0, 0, NULL);
image->unref();
}
}
示例5: GrMatrixConvolutionEffect
// Static function to create a 2D convolution
std::unique_ptr<GrFragmentProcessor> GrMatrixConvolutionEffect::MakeGaussian(
sk_sp<GrTextureProxy> proxy,
const SkIRect& bounds,
const SkISize& kernelSize,
SkScalar gain,
SkScalar bias,
const SkIPoint& kernelOffset,
GrTextureDomain::Mode tileMode,
bool convolveAlpha,
SkScalar sigmaX,
SkScalar sigmaY) {
float kernel[MAX_KERNEL_SIZE];
fill_in_2D_gaussian_kernel(kernel, kernelSize.width(), kernelSize.height(), sigmaX, sigmaY);
return std::unique_ptr<GrFragmentProcessor>(
new GrMatrixConvolutionEffect(std::move(proxy), bounds, kernelSize, kernel, gain, bias,
kernelOffset, tileMode, convolveAlpha));
}
示例6: draw
void TileGridTask::draw() {
const SkTileGridPicture::TileGridInfo info = {
fTileSize,
SkISize::Make(0,0), // Overlap between adjacent tiles.
SkIPoint::Make(0,0), // Offset.
};
const SkISize size = fGM->getISize();
SkTileGridPicture recorded(size.width(), size.height(), info);
RecordPicture(fGM.get(), &recorded, SkPicture::kUsePathBoundsForClip_RecordingFlag);
SkBitmap full;
SetupBitmap(fReference.colorType(), fGM.get(), &full);
SkCanvas fullCanvas(full);
SkBitmap tile;
tile.allocPixels(SkImageInfo::Make(fTileSize.width(), fTileSize.height(),
fReference.colorType(), kPremul_SkAlphaType));
SkCanvas tileCanvas(tile);
SkPaint paint;
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
for (int y = 0; y < tiles_needed(full.height(), tile.height()); y++) {
for (int x = 0; x < tiles_needed(full.width(), tile.width()); x++) {
SkAutoCanvasRestore ar(&tileCanvas, true/*also save now*/);
const SkScalar xOffset = SkIntToScalar(x * tile.width()),
yOffset = SkIntToScalar(y * tile.height());
SkMatrix matrix = tileCanvas.getTotalMatrix();
matrix.postTranslate(-xOffset, -yOffset);
tileCanvas.setMatrix(matrix);
recorded.draw(&tileCanvas);
tileCanvas.flush();
fullCanvas.drawBitmap(tile, xOffset, yOffset, &paint);
}
}
if (!BitmapsEqual(full, fReference)) {
this->fail();
this->spawnChild(SkNEW_ARGS(WriteTask, (*this, full)));
}
}
示例7: ComputeSampleSize
// calculates sampleSize in x and y direction
void SkScaledCodec::ComputeSampleSize(const SkISize& dstDim, const SkISize& srcDim,
int* sampleXPtr, int* sampleYPtr) {
int srcWidth = srcDim.width();
int dstWidth = dstDim.width();
int srcHeight = srcDim.height();
int dstHeight = dstDim.height();
int sampleX = srcWidth / dstWidth;
int sampleY = srcHeight / dstHeight;
// only support down sampling, not up sampling
SkASSERT(dstWidth <= srcWidth);
SkASSERT(dstHeight <= srcHeight);
// 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) {
// rounding during onGetScaledDimensions can cause different sampleSizes
// Ex: srcWidth = 79, srcHeight = 20, sampleSize = 10
// dstWidth = 7, dstHeight = 2, sampleX = 79/7 = 11, sampleY = 20/2 = 10
// correct for this rounding by comparing width to sampleY and height to sampleX
if (get_scaled_dimension(srcWidth, sampleY) == dstWidth) {
sampleX = sampleY;
} else if (get_scaled_dimension(srcHeight, sampleX) == dstHeight) {
sampleY = sampleX;
}
}
}
if (sampleXPtr) {
*sampleXPtr = sampleX;
}
if (sampleYPtr) {
*sampleYPtr = sampleY;
}
}
示例8: blobs
/*
If you execute skp_parser with one argument, it spits out a json representation
of the skp, but that's incomplete since it's missing many binary blobs (these
could represent images or typefaces or just anything that doesn't currently
have a json representation). Each unique blob is labeled with a string in the
form "data/%d". So for example:
tools/git-sync-deps
bin/gn gen out/debug
ninja -C out/debug dm skp_parser
out/debug/dm -m grayscale -w /tmp/dm --config skp
out/debug/skp_parser /tmp/dm/skp/gm/grayscalejpg.skp | less
out/debug/skp_parser /tmp/dm/skp/gm/grayscalejpg.skp | grep data
out/debug/skp_parser /tmp/dm/skp/gm/grayscalejpg.skp data/0 | file -
out/debug/skp_parser /tmp/dm/skp/gm/grayscalejpg.skp data/0 > /tmp/data0.png
"data/0" is an image that the SKP serializer has encoded as PNG.
*/
int main(int argc, char** argv) {
if (argc < 2) {
SkDebugf("Usage:\n %s SKP_FILE [DATA_URL]\n", argv[0]);
return 1;
}
SkFILEStream input(argv[1]);
if (!input.isValid()) {
SkDebugf("Bad file: '%s'\n", argv[1]);
return 2;
}
sk_sp<SkPicture> pic = SkPicture::MakeFromStream(&input);
if (!pic) {
SkDebugf("Bad skp: '%s'\n", argv[1]);
return 3;
}
SkISize size = pic->cullRect().roundOut().size();
SkDebugCanvas debugCanvas(size.width(), size.height());
pic->playback(&debugCanvas);
std::unique_ptr<SkCanvas> nullCanvas = SkMakeNullCanvas();
UrlDataManager dataManager(SkString("data"));
Json::Value json = debugCanvas.toJSON(
dataManager, debugCanvas.getSize(), nullCanvas.get());
if (argc > 2) {
if (UrlDataManager::UrlData* data =
dataManager.getDataFromUrl(SkString(argv[2]))) {
SkData* skdata = data->fData.get();
SkASSERT(skdata);
#ifdef SK_BUILD_FOR_WIN
fflush(stdout);
(void)_setmode(_fileno(stdout), _O_BINARY);
#endif
fwrite(skdata->data(), skdata->size(), 1, stdout);
} else {
SkDebugf("Bad data url.\n");
return 4;
}
} else {
Json::StyledStreamWriter(" ").write(std::cout, json);
}
return 0;
}
示例9: createBitmap
// Creates a SkBitmap that is backed by SkDiscardablePixelRef.
SkBitmap DeferredImageDecoder::createBitmap(size_t index)
{
SkISize decodedSize = m_frameGenerator->getFullSize();
ASSERT(decodedSize.width() > 0);
ASSERT(decodedSize.height() > 0);
#if SK_B32_SHIFT // Little-endian RGBA pixels. (Android)
const SkColorType colorType = kRGBA_8888_SkColorType;
#else
const SkColorType colorType = kBGRA_8888_SkColorType;
#endif
const SkImageInfo info = SkImageInfo::Make(decodedSize.width(), decodedSize.height(), colorType, kPremul_SkAlphaType);
SkBitmap bitmap;
DecodingImageGenerator* generator = new DecodingImageGenerator(m_frameGenerator, info, index);
bool installed = SkInstallDiscardablePixelRef(generator, &bitmap);
ASSERT_UNUSED(installed, installed);
bitmap.pixelRef()->setURI(labelDiscardable);
generator->setGenerationId(bitmap.getGenerationID());
return bitmap;
}
示例10: drawTheImage
void drawTheImage(SkCanvas* canvas, const SkISize& size, SkFilterQuality filter,
SkScalar dx, SkScalar dy) {
SkPaint paint;
paint.setAntiAlias(true);
paint.setFilterQuality(filter);
SkAutoCanvasRestore acr(canvas, true);
canvas->translate(dx, dy);
canvas->translate(SkScalarHalf(size.width()), SkScalarHalf(size.height()));
canvas->scale(fScale, fScale);
canvas->rotate(fAngle);
canvas->drawImage(fImage, -SkScalarHalf(fImage->width()), -SkScalarHalf(fImage->height()),
&paint);
if (false) {
acr.restore();
draw_box_frame(canvas, size.width(), size.height());
}
}
示例11: SkAssertResult
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();
}
示例12: 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);
}
}
}
}
示例13: 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;
}
示例14: acr
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);
}
}
示例15: INHERITED
GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(GrTexture* texture,
const SkIRect& bounds,
const SkISize& kernelSize,
const SkScalar* kernel,
SkScalar gain,
SkScalar bias,
const SkIPoint& kernelOffset,
GrTextureDomain::Mode tileMode,
bool convolveAlpha)
: INHERITED(texture, GrCoordTransform::MakeDivByTextureWHMatrix(texture)),
fKernelSize(kernelSize),
fGain(SkScalarToFloat(gain)),
fBias(SkScalarToFloat(bias) / 255.0f),
fConvolveAlpha(convolveAlpha),
fDomain(GrTextureDomain::MakeTexelDomainForMode(texture, bounds, tileMode), tileMode) {
this->initClassID<GrMatrixConvolutionEffect>();
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());
}