// Currently, the raster imagefilters can only handle certain imageinfos. Call this to know if // a given info is supported. staticbool valid_for_imagefilters(const SkImageInfo& info) { // no support for other swizzles/depths yet return info.colorType() == kN32_SkColorType;
}
// TODO(skbug.com/12784): Once bitmap images work with SkImageShader::MakeSubset(), this does not // need to be virtual anymore.
sk_sp<SkShader> SkSpecialImage::asShader(SkTileMode tileMode, const SkSamplingOptions& sampling, const SkMatrix& lm, bool strict) const { // The special image's logical (0,0) is at its subset's topLeft() so we need to account for // that in the local matrix used when sampling.
SkMatrix subsetOrigin = SkMatrix::Translate(-this->subset().topLeft());
subsetOrigin.postConcat(lm);
if (strict) { // However, we don't need to modify the subset itself since that is defined with respect // to the base image, and the local matrix is applied before any tiling/clamping. const SkRect subset = SkRect::Make(this->subset());
// asImage() w/o a subset makes no copy; create the SkImageShader directly to remember // the subset used to access the image. return SkImageShader::MakeSubset(
this->asImage(), subset, tileMode, tileMode, sampling, &subsetOrigin);
} else { // Ignore 'subset' other than its origin translation applied to the local matrix. return this->asImage()->makeShader(tileMode, tileMode, sampling, subsetOrigin);
}
}
class SkSpecialImage_Raster final : public SkSpecialImage { public:
SkSpecialImage_Raster(const SkIRect& subset, const SkBitmap& bm, const SkSurfaceProps& props)
: SkSpecialImage(subset, bm.getGenerationID(), bm.info().colorInfo(), props)
, fBitmap(bm) {
SkASSERT(bm.pixelRef());
SkASSERT(fBitmap.getPixels());
}
sk_sp<SkSpecialImage> onMakeBackingStoreSubset(const SkIRect& subset) const override { // No need to extract subset, onGetROPixels handles that when needed return SkSpecialImages::MakeFromRaster(subset, fBitmap, this->props());
}
sk_sp<SkShader> asShader(SkTileMode tileMode, const SkSamplingOptions& sampling, const SkMatrix& lm, bool strict) const override { if (strict) { // TODO(skbug.com/12784): SkImage::makeShader() doesn't support a subset yet, but // SkBitmap supports subset views so create the shader from the subset bitmap instead of // fBitmap.
SkBitmap subsetBM; if (!this->getROPixels(&subsetBM)) { return nullptr;
} return subsetBM.makeShader(tileMode, tileMode, sampling, lm);
} else { // The special image's logical (0,0) is at its subset's topLeft() so we need to // account for that in the local matrix used when sampling.
SkMatrix subsetOrigin = SkMatrix::Translate(-this->subset().topLeft());
subsetOrigin.postConcat(lm); return fBitmap.makeShader(tileMode, tileMode, sampling, subsetOrigin);
}
}
const SkBitmap* srcBM = &bm;
SkBitmap tmp; // ImageFilters only handle N32 at the moment, so force our src to be that if (!valid_for_imagefilters(bm.info())) { if (!tmp.tryAllocPixels(bm.info().makeColorType(kN32_SkColorType)) ||
!bm.readPixels(tmp.info(), tmp.getPixels(), tmp.rowBytes(), 0, 0))
{ return nullptr;
}
srcBM = &tmp;
} return sk_make_sp<SkSpecialImage_Raster>(subset, *srcBM, props);
}
SkBitmap tmp;
SkImageInfo info = bm.info().makeDimensions(subset.size()); // As in MakeFromRaster, must force src to N32 for ImageFilters if (!valid_for_imagefilters(bm.info())) {
info = info.makeColorType(kN32_SkColorType);
} if (!tmp.tryAllocPixels(info)) { return nullptr;
} if (!bm.readPixels(tmp.info(), tmp.getPixels(), tmp.rowBytes(), subset.x(), subset.y())) { return nullptr;
}
// Since we're making a copy of the raster, the resulting special image is the exact size // of the requested subset of the original and no longer needs to be offset by subset's left // and top, since those were relative to the original's buffer. return sk_make_sp<SkSpecialImage_Raster>(
SkIRect::MakeWH(subset.width(), subset.height()), tmp, props);
}
// This will not work if the image is uploaded to a GPU render target.
SkBitmap bm; if (as_IB(image)->getROPixels(nullptr, &bm)) { return MakeFromRaster(subset, bm, props);
} return nullptr;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.