本文整理汇总了C++中SkIRect::offset方法的典型用法代码示例。如果您正苦于以下问题:C++ SkIRect::offset方法的具体用法?C++ SkIRect::offset怎么用?C++ SkIRect::offset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkIRect
的用法示例。
在下文中一共展示了SkIRect::offset方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: build_base_rgn
void build_base_rgn(SkRegion* rgn) {
rgn->setRect(fBase);
SkIRect r = fBase;
r.offset(75, 20);
rgn->op(r, SkRegion::kUnion_Op);
}
示例2: MakeFromRaster
sk_sp<SkSpecialImage> SkMorphologyImageFilter::onFilterImage(SkSpecialImage* source,
const Context& ctx,
SkIPoint* offset) const {
SkIPoint inputOffset = SkIPoint::Make(0, 0);
sk_sp<SkSpecialImage> input(this->filterInput(0, source, ctx, &inputOffset));
if (!input) {
return nullptr;
}
SkIRect bounds;
input = this->applyCropRectAndPad(this->mapContext(ctx), input.get(), &inputOffset, &bounds);
if (!input) {
return nullptr;
}
SkVector radius = SkVector::Make(SkIntToScalar(this->radius().width()),
SkIntToScalar(this->radius().height()));
ctx.ctm().mapVectors(&radius, 1);
int width = SkScalarFloorToInt(radius.fX);
int height = SkScalarFloorToInt(radius.fY);
if (width < 0 || height < 0) {
return nullptr;
}
SkIRect srcBounds = bounds;
srcBounds.offset(-inputOffset);
if (0 == width && 0 == height) {
offset->fX = bounds.left();
offset->fY = bounds.top();
return input->makeSubset(srcBounds);
}
#if SK_SUPPORT_GPU
if (source->isTextureBacked()) {
GrContext* context = source->getContext();
// Ensure the input is in the destination color space. Typically applyCropRect will have
// called pad_image to account for our dilation of bounds, so the result will already be
// moved to the destination color space. If a filter DAG avoids that, then we use this
// fall-back, which saves us from having to do the xform during the filter itself.
input = ImageToColorSpace(input.get(), ctx.outputProperties());
auto type = (kDilate_Op == this->op()) ? GrMorphologyEffect::Type::kDilate
: GrMorphologyEffect::Type::kErode;
sk_sp<SkSpecialImage> result(apply_morphology(context, input.get(), srcBounds, type,
SkISize::Make(width, height),
ctx.outputProperties()));
if (result) {
offset->fX = bounds.left();
offset->fY = bounds.top();
}
return result;
}
#endif
SkBitmap inputBM;
if (!input->getROPixels(&inputBM)) {
return nullptr;
}
if (inputBM.colorType() != kN32_SkColorType) {
return nullptr;
}
SkImageInfo info = SkImageInfo::Make(bounds.width(), bounds.height(),
inputBM.colorType(), inputBM.alphaType());
SkBitmap dst;
if (!dst.tryAllocPixels(info)) {
return nullptr;
}
SkMorphologyImageFilter::Proc procX, procY;
if (kDilate_Op == this->op()) {
procX = SkOpts::dilate_x;
procY = SkOpts::dilate_y;
} else {
procX = SkOpts::erode_x;
procY = SkOpts::erode_y;
}
if (width > 0 && height > 0) {
SkBitmap tmp;
if (!tmp.tryAllocPixels(info)) {
return nullptr;
}
call_proc_X(procX, inputBM, &tmp, width, srcBounds);
SkIRect tmpBounds = SkIRect::MakeWH(srcBounds.width(), srcBounds.height());
call_proc_Y(procY,
tmp.getAddr32(tmpBounds.left(), tmpBounds.top()), tmp.rowBytesAsPixels(),
&dst, height, tmpBounds);
} else if (width > 0) {
call_proc_X(procX, inputBM, &dst, width, srcBounds);
} else if (height > 0) {
call_proc_Y(procY,
//.........这里部分代码省略.........
示例3: filterImageGeneric
bool SkMorphologyImageFilter::filterImageGeneric(SkMorphologyImageFilter::Proc procX,
SkMorphologyImageFilter::Proc procY,
Proxy* proxy,
const SkBitmap& source,
const Context& ctx,
SkBitmap* dst,
SkIPoint* offset) const {
SkBitmap src = source;
SkIPoint srcOffset = SkIPoint::Make(0, 0);
if (!this->filterInput(0, proxy, source, ctx, &src, &srcOffset)) {
return false;
}
if (src.colorType() != kN32_SkColorType) {
return false;
}
SkIRect bounds;
if (!this->applyCropRect(this->mapContext(ctx), proxy, src, &srcOffset, &bounds, &src)) {
return false;
}
SkAutoLockPixels alp(src);
if (!src.getPixels()) {
return false;
}
SkVector radius = SkVector::Make(SkIntToScalar(this->radius().width()),
SkIntToScalar(this->radius().height()));
ctx.ctm().mapVectors(&radius, 1);
int width = SkScalarFloorToInt(radius.fX);
int height = SkScalarFloorToInt(radius.fY);
if (width < 0 || height < 0) {
return false;
}
SkIRect srcBounds = bounds;
srcBounds.offset(-srcOffset);
if (width == 0 && height == 0) {
src.extractSubset(dst, srcBounds);
offset->fX = bounds.left();
offset->fY = bounds.top();
return true;
}
SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds.height()));
if (!device) {
return false;
}
*dst = device->accessBitmap(false);
SkAutoLockPixels alp_dst(*dst);
if (width > 0 && height > 0) {
SkAutoTUnref<SkBaseDevice> tempDevice(proxy->createDevice(dst->width(), dst->height()));
if (!tempDevice) {
return false;
}
SkBitmap temp = tempDevice->accessBitmap(false);
SkAutoLockPixels alp_temp(temp);
callProcX(procX, src, &temp, width, srcBounds);
SkIRect tmpBounds = SkIRect::MakeWH(srcBounds.width(), srcBounds.height());
callProcY(procY, temp, dst, height, tmpBounds);
} else if (width > 0) {
callProcX(procX, src, dst, width, srcBounds);
} else if (height > 0) {
callProcY(procY, src, dst, height, srcBounds);
}
offset->fX = bounds.left();
offset->fY = bounds.top();
return true;
}
示例4: filterImageGPU
bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const {
SkBitmap colorBM = src;
SkIPoint colorOffset = SkIPoint::Make(0, 0);
if (!this->filterInputGPU(1, proxy, src, ctx, &colorBM, &colorOffset)) {
return false;
}
SkBitmap displacementBM = src;
SkIPoint displacementOffset = SkIPoint::Make(0, 0);
if (!this->filterInputGPU(0, proxy, src, ctx, &displacementBM, &displacementOffset)) {
return false;
}
SkIRect bounds;
// Since GrDisplacementMapEffect does bounds checking on color pixel access, we don't need to
// pad the color bitmap to bounds here.
if (!this->applyCropRect(ctx, colorBM, colorOffset, &bounds)) {
return false;
}
SkIRect displBounds;
if (!this->applyCropRect(ctx, proxy, displacementBM,
&displacementOffset, &displBounds, &displacementBM)) {
return false;
}
if (!bounds.intersect(displBounds)) {
return false;
}
GrTexture* color = colorBM.getTexture();
GrTexture* displacement = displacementBM.getTexture();
GrContext* context = color->getContext();
GrSurfaceDesc desc;
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fWidth = bounds.width();
desc.fHeight = bounds.height();
desc.fConfig = kSkia8888_GrPixelConfig;
SkAutoTUnref<GrTexture> dst(context->textureProvider()->createApproxTexture(desc));
if (!dst) {
return false;
}
SkVector scale = SkVector::Make(fScale, fScale);
ctx.ctm().mapVectors(&scale, 1);
GrPaint paint;
SkMatrix offsetMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(displacement);
offsetMatrix.preTranslate(SkIntToScalar(colorOffset.fX - displacementOffset.fX),
SkIntToScalar(colorOffset.fY - displacementOffset.fY));
paint.addColorFragmentProcessor(
GrDisplacementMapEffect::Create(fXChannelSelector,
fYChannelSelector,
scale,
displacement,
offsetMatrix,
color,
colorBM.dimensions()))->unref();
paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
SkIRect colorBounds = bounds;
colorBounds.offset(-colorOffset);
SkMatrix matrix;
matrix.setTranslate(-SkIntToScalar(colorBounds.x()),
-SkIntToScalar(colorBounds.y()));
SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(dst->asRenderTarget()));
if (!drawContext) {
return false;
}
drawContext->drawRect(GrClip::WideOpen(), paint, matrix, SkRect::Make(colorBounds));
offset->fX = bounds.left();
offset->fY = bounds.top();
GrWrapTextureInBitmap(dst, bounds.width(), bounds.height(), false, result);
return true;
}