本文整理汇总了C++中SkPixmap类的典型用法代码示例。如果您正苦于以下问题:C++ SkPixmap类的具体用法?C++ SkPixmap怎么用?C++ SkPixmap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SkPixmap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MakeSkiaImageInfo
uint8_t*
SourceSurfaceSkia::GetData()
{
#ifdef USE_SKIA_GPU
if (mImage->isTextureBacked()) {
sk_sp<SkImage> raster;
if (sk_sp<SkData> data = MakeSkData(nullptr, mSize, mStride)) {
SkImageInfo info = MakeSkiaImageInfo(mSize, mFormat);
if (mImage->readPixels(info, data->writable_data(), mStride, 0, 0, SkImage::kDisallow_CachingHint)) {
raster = SkImage::MakeRasterData(info, data, mStride);
}
}
if (raster) {
mImage = raster;
} else {
gfxCriticalError() << "Failed making Skia raster image for GPU surface";
}
}
#endif
SkPixmap pixmap;
if (!mImage->peekPixels(&pixmap)) {
gfxCriticalError() << "Failed accessing pixels for Skia raster image";
}
return reinterpret_cast<uint8_t*>(pixmap.writable_addr());
}
示例2: onGetROPixels
bool onGetROPixels(SkBitmap* dst) const override {
const auto desc = SkBitmapCacheDesc::Make(this->uniqueID(), this->width(), this->height());
if (SkBitmapCache::Find(desc, dst)) {
SkASSERT(dst->getGenerationID() == this->uniqueID());
SkASSERT(dst->isImmutable());
SkASSERT(dst->getPixels());
return true;
}
SkPixmap pmap;
SkImageInfo info = SkImageInfo::MakeN32(this->width(), this->height(),
this->alphaType(), fColorSpace);
auto rec = SkBitmapCache::Alloc(desc, info, &pmap);
if (!rec) {
return false;
}
sk_sp<SkColorSpace> colorSpace;
if (GrPixelConfigIsSRGB(fTextureProxy->config())) {
colorSpace = SkColorSpace::MakeSRGB();
}
sk_sp<GrSurfaceContext> sContext = fContext->contextPriv().makeWrappedSurfaceContext(
fTextureProxy, std::move(colorSpace));
if (!sContext) {
return false;
}
if (!sContext->readPixels(info, pmap.writable_addr(), pmap.rowBytes(), 0, 0)) {
return false;
}
SkBitmapCache::Add(std::move(rec), dst);
fAddedRasterVersionToCache.store(true);
return true;
}
示例3: SkPngEncoder
std::unique_ptr<SkEncoder> SkPngEncoder::Make(SkWStream* dst, const SkPixmap& src,
const Options& options) {
if (!SkPixmapIsValid(src)) {
return nullptr;
}
std::unique_ptr<SkPngEncoderMgr> encoderMgr = SkPngEncoderMgr::Make(dst);
if (!encoderMgr) {
return nullptr;
}
if (!encoderMgr->setHeader(src.info(), options)) {
return nullptr;
}
if (!encoderMgr->setColorSpace(src.info())) {
return nullptr;
}
if (!encoderMgr->writeInfo(src.info())) {
return nullptr;
}
encoderMgr->chooseProc(src.info());
return std::unique_ptr<SkPngEncoder>(new SkPngEncoder(std::move(encoderMgr), src));
}
示例4: just_trans_clamp
/**
* For the purposes of drawing bitmaps, if a matrix is "almost" translate
* go ahead and treat it as if it were, so that subsequent code can go fast.
*/
static bool just_trans_clamp(const SkMatrix& matrix, const SkPixmap& pixmap) {
SkASSERT(matrix_only_scale_translate(matrix));
if (matrix.getType() & SkMatrix::kScale_Mask) {
SkRect dst;
SkRect src = SkRect::Make(pixmap.bounds());
// Can't call mapRect(), since that will fix up inverted rectangles,
// e.g. when scale is negative, and we don't want to return true for
// those.
matrix.mapPoints(SkTCast<SkPoint*>(&dst),
SkTCast<const SkPoint*>(&src),
2);
// Now round all 4 edges to device space, and then compare the device
// width/height to the original. Note: we must map all 4 and subtract
// rather than map the "width" and compare, since we care about the
// phase (in pixel space) that any translate in the matrix might impart.
SkIRect idst;
dst.round(&idst);
return idst.width() == pixmap.width() && idst.height() == pixmap.height();
}
// if we got here, we're either kTranslate_Mask or identity
return true;
}
示例5:
void SkLinearGradient::
LinearGradient4fContext::D32_BlitBW(BlitState* state, int x, int y, const SkPixmap& dst,
int count) {
// FIXME: ignoring coverage for now
const LinearGradient4fContext* ctx =
static_cast<const LinearGradient4fContext*>(state->fCtx);
if (!dst.info().gammaCloseToSRGB()) {
if (ctx->fColorsArePremul) {
ctx->shadePremulSpan<DstType::L32, ApplyPremul::False>(
x, y, dst.writable_addr32(x, y), count);
} else {
ctx->shadePremulSpan<DstType::L32, ApplyPremul::True>(
x, y, dst.writable_addr32(x, y), count);
}
} else {
if (ctx->fColorsArePremul) {
ctx->shadePremulSpan<DstType::S32, ApplyPremul::False>(
x, y, dst.writable_addr32(x, y), count);
} else {
ctx->shadePremulSpan<DstType::S32, ApplyPremul::True>(
x, y, dst.writable_addr32(x, y), count);
}
}
}
示例6:
void SkLinearGradient::
LinearGradient4fContext::D32_BlitBW(BlitState* state, int x, int y, const SkPixmap& dst,
int count) {
// FIXME: ignoring coverage for now
const LinearGradient4fContext* ctx =
static_cast<const LinearGradient4fContext*>(state->fCtx);
if (dst.info().isLinear()) {
if (ctx->fColorsArePremul) {
ctx->shadePremulSpan<SkPMColor, kLinear_SkColorProfileType, ApplyPremul::False>(
x, y, dst.writable_addr32(x, y), count);
} else {
ctx->shadePremulSpan<SkPMColor, kLinear_SkColorProfileType, ApplyPremul::True>(
x, y, dst.writable_addr32(x, y), count);
}
} else {
if (ctx->fColorsArePremul) {
ctx->shadePremulSpan<SkPMColor, kSRGB_SkColorProfileType, ApplyPremul::False>(
x, y, dst.writable_addr32(x, y), count);
} else {
ctx->shadePremulSpan<SkPMColor, kSRGB_SkColorProfileType, ApplyPremul::True>(
x, y, dst.writable_addr32(x, y), count);
}
}
}
示例7: copy_to
bool copy_to(SkBitmap* dst, SkColorType dstColorType, const SkBitmap& src) {
SkPixmap srcPM;
if (!src.peekPixels(&srcPM)) {
return false;
}
SkBitmap tmpDst;
SkImageInfo dstInfo = srcPM.info().makeColorType(dstColorType);
if (!tmpDst.setInfo(dstInfo)) {
return false;
}
if (!tmpDst.tryAllocPixels()) {
return false;
}
SkPixmap dstPM;
if (!tmpDst.peekPixels(&dstPM)) {
return false;
}
if (!srcPM.readPixels(dstPM)) {
return false;
}
dst->swap(tmpDst);
return true;
}
示例8: memcpy
std::unique_ptr<SkEncoder> SkJpegEncoder::Make(SkWStream* dst, const SkPixmap& src,
const Options& options) {
if (!SkPixmapIsValid(src, options.fBlendBehavior)) {
return nullptr;
}
std::unique_ptr<SkJpegEncoderMgr> encoderMgr = SkJpegEncoderMgr::Make(dst);
if (setjmp(encoderMgr->jmpBuf())) {
return nullptr;
}
if (!encoderMgr->setParams(src.info(), options)) {
return nullptr;
}
jpeg_set_quality(encoderMgr->cinfo(), options.fQuality, TRUE);
jpeg_start_compress(encoderMgr->cinfo(), TRUE);
sk_sp<SkData> icc = icc_from_color_space(src.info());
if (icc) {
// Create a contiguous block of memory with the icc signature followed by the profile.
sk_sp<SkData> markerData =
SkData::MakeUninitialized(kICCMarkerHeaderSize + icc->size());
uint8_t* ptr = (uint8_t*) markerData->writable_data();
memcpy(ptr, kICCSig, sizeof(kICCSig));
ptr += sizeof(kICCSig);
*ptr++ = 1; // This is the first marker.
*ptr++ = 1; // Out of one total markers.
memcpy(ptr, icc->data(), icc->size());
jpeg_write_marker(encoderMgr->cinfo(), kICCMarker, markerData->bytes(), markerData->size());
}
return std::unique_ptr<SkJpegEncoder>(new SkJpegEncoder(std::move(encoderMgr), src));
}
示例9: call_proc_X
static void call_proc_X(SkMorphologyImageFilter::Proc procX,
const SkPixmap& src, SkBitmap* dst,
int radiusX, const SkIRect& bounds) {
procX(src.addr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0),
radiusX, bounds.width(), bounds.height(),
src.rowBytesAsPixels(), dst->rowBytesAsPixels());
}
示例10: Supports
static bool Supports(const SkPixmap& dst, const SkPixmap& src, const SkPaint& paint) {
if (dst.colorType() != src.colorType()) {
return false;
}
if (dst.info().profileType() != src.info().profileType()) {
return false;
}
if (paint.getMaskFilter() || paint.getColorFilter() || paint.getImageFilter()) {
return false;
}
if (0xFF != paint.getAlpha()) {
return false;
}
SkXfermode::Mode mode;
if (!SkXfermode::AsMode(paint.getXfermode(), &mode)) {
return false;
}
if (SkXfermode::kSrc_Mode == mode) {
return true;
}
if (SkXfermode::kSrcOver_Mode == mode && src.isOpaque()) {
return true;
}
return false;
}
示例11: ClonePipelineForBlitting
bool SkLinearBitmapPipeline::ClonePipelineForBlitting(
SkEmbeddableLinearPipeline* pipelineStorage,
const SkLinearBitmapPipeline& pipeline,
SkMatrix::TypeMask matrixMask,
SkShader::TileMode xTileMode,
SkShader::TileMode yTileMode,
SkFilterQuality filterQuality,
const SkPixmap& srcPixmap,
float finalAlpha,
SkXfermode::Mode xferMode,
const SkImageInfo& dstInfo)
{
if (xferMode == SkXfermode::kSrcOver_Mode
&& srcPixmap.info().alphaType() == kOpaque_SkAlphaType) {
xferMode = SkXfermode::kSrc_Mode;
}
if (matrixMask & ~SkMatrix::kTranslate_Mask ) { return false; }
if (filterQuality != SkFilterQuality::kNone_SkFilterQuality) { return false; }
if (finalAlpha != 1.0f) { return false; }
if (srcPixmap.info().colorType() != kRGBA_8888_SkColorType
|| dstInfo.colorType() != kRGBA_8888_SkColorType) { return false; }
if (!srcPixmap.info().gammaCloseToSRGB() || !dstInfo.gammaCloseToSRGB()) {
return false;
}
if (xferMode != SkXfermode::kSrc_Mode && xferMode != SkXfermode::kSrcOver_Mode) {
return false;
}
pipelineStorage->init(pipeline, srcPixmap, xferMode, dstInfo);
return true;
}
示例12: SkSpecialImage_Raster
SkSpecialImage_Raster(const SkIRect& subset,
const SkPixmap& pixmap,
RasterReleaseProc releaseProc,
ReleaseContext context,
const SkSurfaceProps* props)
: INHERITED(subset, kNeedNewImageUniqueID_SpecialImage, props) {
fBitmap.installPixels(pixmap.info(), pixmap.writable_addr(),
pixmap.rowBytes(), pixmap.ctable(),
releaseProc, context);
}
示例13: scalePixels
bool SkPixmap::scalePixels(const SkPixmap& dst, SkFilterQuality quality) const {
// Can't do anthing with empty src or dst
if (this->width() <= 0 || this->height() <= 0 || dst.width() <= 0 || dst.height() <= 0) {
return false;
}
// no scaling involved?
if (dst.width() == this->width() && dst.height() == this->height()) {
return this->readPixels(dst);
}
SkBitmap bitmap;
if (!bitmap.installPixels(*this)) {
return false;
}
bitmap.setIsVolatile(true); // so we don't try to cache it
SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterDirect(dst.info(), dst.writable_addr(),
dst.rowBytes()));
if (!surface) {
return false;
}
SkPaint paint;
paint.setFilterQuality(quality);
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
surface->getCanvas()->drawBitmapRect(bitmap, SkRect::MakeIWH(dst.width(), dst.height()),
&paint);
return true;
}
示例14: draw
void draw(SkCanvas* canvas) {
std::vector<int32_t> pixels;
pixels.resize(image->height() * image->width() * 4);
SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
image->readPixels(pixmap, 0, 0);
SkDebugf("pixels address: 0x%llx\n", pixmap.addr());
SkPixmap inset;
if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) {
SkDebugf("inset address: 0x%llx\n", inset.addr());
}
}
示例15: peekPixels
const void* SkSurface::peekPixels(SkImageInfo* info, size_t* rowBytes) {
SkPixmap pm;
if (this->peekPixels(&pm)) {
if (info) {
*info = pm.info();
}
if (rowBytes) {
*rowBytes = pm.rowBytes();
}
return pm.addr();
}
return nullptr;
}