本文整理汇总了C++中SkPixmap::rowBytes方法的典型用法代码示例。如果您正苦于以下问题:C++ SkPixmap::rowBytes方法的具体用法?C++ SkPixmap::rowBytes怎么用?C++ SkPixmap::rowBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkPixmap
的用法示例。
在下文中一共展示了SkPixmap::rowBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Resize
bool SkBitmapScaler::Resize(const SkPixmap& result, const SkPixmap& source, ResizeMethod method) {
if (!valid_for_resize(source, result.width(), result.height())) {
return false;
}
if (!result.addr() || result.colorType() != source.colorType()) {
return false;
}
SkConvolutionProcs convolveProcs= { 0, nullptr, nullptr, nullptr, nullptr };
PlatformConvolutionProcs(&convolveProcs);
SkRect destSubset = SkRect::MakeIWH(result.width(), result.height());
SkResizeFilter filter(method, source.width(), source.height(),
result.width(), result.height(), destSubset, convolveProcs);
// Get a subset encompassing this touched area. We construct the
// offsets and row strides such that it looks like a new bitmap, while
// referring to the old data.
const uint8_t* sourceSubset = reinterpret_cast<const uint8_t*>(source.addr());
return BGRAConvolve2D(sourceSubset, static_cast<int>(source.rowBytes()),
!source.isOpaque(), filter.xFilter(), filter.yFilter(),
static_cast<int>(result.rowBytes()),
static_cast<unsigned char*>(result.writable_addr()),
convolveProcs, true);
}
示例2: SkASSERT
SkLinearBitmapPipeline::SkLinearBitmapPipeline(
const SkLinearBitmapPipeline& pipeline,
const SkPixmap& srcPixmap,
SkXfermode::Mode mode,
const SkImageInfo& dstInfo)
{
SkASSERT(mode == SkXfermode::kSrc_Mode || mode == SkXfermode::kSrcOver_Mode);
SkASSERT(srcPixmap.info().colorType() == dstInfo.colorType()
&& srcPixmap.info().colorType() == kRGBA_8888_SkColorType);
if (mode == SkXfermode::kSrc_Mode) {
fSampleStage.initSink<RGBA8888UnitRepeatSrc>(
srcPixmap.writable_addr32(0, 0), srcPixmap.rowBytes() / 4);
fLastStage = fSampleStage.getInterface<DestinationInterface, RGBA8888UnitRepeatSrc>();
} else {
fSampleStage.initSink<RGBA8888UnitRepeatSrcOver>(
srcPixmap.writable_addr32(0, 0), srcPixmap.rowBytes() / 4);
fLastStage = fSampleStage.getInterface<DestinationInterface, RGBA8888UnitRepeatSrcOver>();
}
auto sampleStage = fSampleStage.get();
auto tilerStage = pipeline.fTileStage.cloneStageTo(sampleStage, &fTileStage);
tilerStage = (tilerStage != nullptr) ? tilerStage : sampleStage;
auto matrixStage = pipeline.fMatrixStage.cloneStageTo(tilerStage, &fMatrixStage);
matrixStage = (matrixStage != nullptr) ? matrixStage : tilerStage;
fFirstStage = matrixStage;
}
示例3: paintEvent
void SkDrawCommandGeometryWidget::paintEvent(QPaintEvent* event) {
this->QFrame::paintEvent(event);
if (!fSurface) {
return;
}
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
SkPixmap pixmap;
if (fSurface->peekPixels(&pixmap)) {
SkASSERT(pixmap.width() > 0);
SkASSERT(pixmap.height() > 0);
QRectF resultRect;
if (this->width() < this->height()) {
float ratio = this->width() / pixmap.width();
resultRect = QRectF(0, 0, this->width(), ratio * pixmap.height());
} else {
float ratio = this->height() / pixmap.height();
resultRect = QRectF(0, 0, ratio * pixmap.width(), this->height());
}
resultRect.moveCenter(this->contentsRect().center());
QImage image(reinterpret_cast<const uchar*>(pixmap.addr()),
pixmap.width(),
pixmap.height(),
pixmap.rowBytes(),
QImage::Format_ARGB32_Premultiplied);
painter.drawImage(resultRect, image);
}
}
示例4: 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;
}
示例5: 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;
}
示例6: INHERITED
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);
}
示例7: test_newraster
static void test_newraster(skiatest::Reporter* reporter) {
SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10);
const size_t minRowBytes = info.minRowBytes();
const size_t size = info.getSafeSize(minRowBytes);
SkAutoTMalloc<SkPMColor> storage(size);
SkPMColor* baseAddr = storage.get();
sk_bzero(baseAddr, size);
std::unique_ptr<SkCanvas> canvas = SkCanvas::MakeRasterDirect(info, baseAddr, minRowBytes);
REPORTER_ASSERT(reporter, canvas);
SkPixmap pmap;
const SkPMColor* addr = canvas->peekPixels(&pmap) ? pmap.addr32() : nullptr;
REPORTER_ASSERT(reporter, addr);
REPORTER_ASSERT(reporter, info == pmap.info());
REPORTER_ASSERT(reporter, minRowBytes == pmap.rowBytes());
for (int y = 0; y < info.height(); ++y) {
for (int x = 0; x < info.width(); ++x) {
REPORTER_ASSERT(reporter, 0 == addr[x]);
}
addr = (const SkPMColor*)((const char*)addr + pmap.rowBytes());
}
// now try a deliberately bad info
info = info.makeWH(-1, info.height());
REPORTER_ASSERT(reporter, nullptr == SkCanvas::MakeRasterDirect(info, baseAddr, minRowBytes));
// too big
info = info.makeWH(1 << 30, 1 << 30);
REPORTER_ASSERT(reporter, nullptr == SkCanvas::MakeRasterDirect(info, baseAddr, minRowBytes));
// not a valid pixel type
info = SkImageInfo::Make(10, 10, kUnknown_SkColorType, info.alphaType());
REPORTER_ASSERT(reporter, nullptr == SkCanvas::MakeRasterDirect(info, baseAddr, minRowBytes));
// We should succeed with a zero-sized valid info
info = SkImageInfo::MakeN32Premul(0, 0);
canvas = SkCanvas::MakeRasterDirect(info, baseAddr, minRowBytes);
REPORTER_ASSERT(reporter, canvas);
}
示例8: 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;
}
示例9: getSize
size_t getSize() const override {
#if SK_SUPPORT_GPU
if (GrTexture* texture = as_IB(fImage.get())->peekTexture()) {
return texture->gpuMemorySize();
} else
#endif
{
SkPixmap pm;
if (fImage->peekPixels(&pm)) {
return pm.height() * pm.rowBytes();
}
}
return 0;
}
示例10: Resize
bool SkBitmapScaler::Resize(SkBitmap* resultPtr, const SkPixmap& source, ResizeMethod method,
int destWidth, int destHeight, SkBitmap::Allocator* allocator) {
if (nullptr == source.addr() || source.colorType() != kN32_SkColorType ||
source.width() < 1 || source.height() < 1)
{
return false;
}
if (destWidth < 1 || destHeight < 1) {
return false;
}
SkConvolutionProcs convolveProcs= { 0, nullptr, nullptr, nullptr, nullptr };
PlatformConvolutionProcs(&convolveProcs);
SkRect destSubset = SkRect::MakeIWH(destWidth, destHeight);
SkResizeFilter filter(method, source.width(), source.height(),
destWidth, destHeight, destSubset, convolveProcs);
// Get a subset encompassing this touched area. We construct the
// offsets and row strides such that it looks like a new bitmap, while
// referring to the old data.
const uint8_t* sourceSubset = reinterpret_cast<const uint8_t*>(source.addr());
// Convolve into the result.
SkBitmap result;
result.setInfo(SkImageInfo::MakeN32(SkScalarCeilToInt(destSubset.width()),
SkScalarCeilToInt(destSubset.height()),
source.alphaType()));
result.allocPixels(allocator, nullptr);
if (!result.readyToDraw()) {
return false;
}
if (!BGRAConvolve2D(sourceSubset, static_cast<int>(source.rowBytes()),
!source.isOpaque(), filter.xFilter(), filter.yFilter(),
static_cast<int>(result.rowBytes()),
static_cast<unsigned char*>(result.getPixels()),
convolveProcs, true)) {
return false;
}
*resultPtr = result;
resultPtr->lockPixels();
SkASSERT(resultPtr->getPixels());
return true;
}
示例11: getROPixels
bool SkImage_Gpu::getROPixels(SkBitmap* dst, SkColorSpace* dstColorSpace, CachingHint chint) const {
const auto desc = SkBitmapCacheDesc::Make(this);
if (SkBitmapCache::Find(desc, dst)) {
SkASSERT(dst->getGenerationID() == this->uniqueID());
SkASSERT(dst->isImmutable());
SkASSERT(dst->getPixels());
return true;
}
SkImageInfo ii = make_info(this->width(), this->height(), this->alphaType(),
sk_ref_sp(dstColorSpace));
SkBitmapCache::RecPtr rec = nullptr;
SkPixmap pmap;
if (kAllow_CachingHint == chint) {
rec = SkBitmapCache::Alloc(desc, ii, &pmap);
if (!rec) {
return false;
}
} else {
if (!dst->tryAllocPixels(ii)) {
return false;
}
}
sk_sp<GrSurfaceContext> sContext = fContext->contextPriv().makeWrappedSurfaceContext(
fProxy,
fColorSpace);
if (!sContext) {
return false;
}
if (!sContext->readPixels(pmap.info(), pmap.writable_addr(), pmap.rowBytes(), 0, 0)) {
return false;
}
if (rec) {
SkBitmapCache::Add(std::move(rec), dst);
fAddedRasterVersionToCache.store(true);
}
return true;
}
示例12: IntSize
bool
SourceSurfaceSkia::InitFromImage(sk_sp<SkImage> aImage,
SurfaceFormat aFormat,
DrawTargetSkia* aOwner)
{
if (!aImage) {
return false;
}
mSize = IntSize(aImage->width(), aImage->height());
// For the raster image case, we want to use the format and stride
// information that the underlying raster image is using, which is
// reliable.
// For the GPU case (for which peekPixels is false), we can't easily
// figure this information out. It is better to report the originally
// intended format and stride that we will convert to if this GPU
// image is ever read back into a raster image.
SkPixmap pixmap;
if (aImage->peekPixels(&pixmap)) {
mFormat =
aFormat != SurfaceFormat::UNKNOWN ?
aFormat :
SkiaColorTypeToGfxFormat(pixmap.colorType(), pixmap.alphaType());
mStride = pixmap.rowBytes();
} else if (aFormat != SurfaceFormat::UNKNOWN) {
mFormat = aFormat;
SkImageInfo info = MakeSkiaImageInfo(mSize, mFormat);
mStride = SkAlign4(info.minRowBytes());
} else {
return false;
}
mImage = aImage;
if (aOwner) {
mDrawTarget = aOwner;
}
return true;
}
示例13: proc
static void SkARGB32_Blit32(const SkPixmap& device, const SkMask& mask,
const SkIRect& clip, SkPMColor srcColor) {
U8CPU alpha = SkGetPackedA32(srcColor);
unsigned flags = SkBlitRow::kSrcPixelAlpha_Flag32;
if (alpha != 255) {
flags |= SkBlitRow::kGlobalAlpha_Flag32;
}
SkBlitRow::Proc32 proc = SkBlitRow::Factory32(flags);
int x = clip.fLeft;
int y = clip.fTop;
int width = clip.width();
int height = clip.height();
SkPMColor* dstRow = device.writable_addr32(x, y);
const SkPMColor* srcRow = reinterpret_cast<const SkPMColor*>(mask.getAddr8(x, y));
do {
proc(dstRow, srcRow, width, alpha);
dstRow = (SkPMColor*)((char*)dstRow + device.rowBytes());
srcRow = (const SkPMColor*)((const char*)srcRow + mask.fRowBytes);
} while (--height != 0);
}
示例14: test_peekpixels
static void test_peekpixels(skiatest::Reporter* reporter) {
const SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10);
SkPixmap pmap;
SkBitmap bm;
// empty should return false
REPORTER_ASSERT(reporter, !bm.peekPixels(nullptr));
REPORTER_ASSERT(reporter, !bm.peekPixels(&pmap));
// no pixels should return false
bm.setInfo(SkImageInfo::MakeN32Premul(10, 10));
REPORTER_ASSERT(reporter, !bm.peekPixels(nullptr));
REPORTER_ASSERT(reporter, !bm.peekPixels(&pmap));
// real pixels should return true
bm.allocPixels(info);
REPORTER_ASSERT(reporter, bm.peekPixels(nullptr));
REPORTER_ASSERT(reporter, bm.peekPixels(&pmap));
REPORTER_ASSERT(reporter, pmap.info() == bm.info());
REPORTER_ASSERT(reporter, pmap.addr() == bm.getPixels());
REPORTER_ASSERT(reporter, pmap.rowBytes() == bm.rowBytes());
}
示例15: CaptureCanvasState
SkCanvasState* SkCanvasStateUtils::CaptureCanvasState(SkCanvas* canvas) {
SkASSERT(canvas);
// Check the clip can be decomposed into rectangles (i.e. no soft clips).
ClipValidator validator;
canvas->replayClips(&validator);
if (validator.failed()) {
SkErrorInternals::SetError(kInvalidOperation_SkError,
"CaptureCanvasState does not support canvases with antialiased clips.\n");
return nullptr;
}
SkAutoTDelete<SkCanvasState_v1> canvasState(new SkCanvasState_v1(canvas));
// decompose the total matrix and clip
setup_MC_state(&canvasState->mcState, canvas->getTotalMatrix(),
canvas->internal_private_getTotalClip());
/*
* decompose the layers
*
* storage is allocated on the stack for the first 3 layers. It is common in
* some view systems (e.g. Android) that a few non-clipped layers are present
* and we will not need to malloc any additional memory in those cases.
*/
SkSWriter32<3*sizeof(SkCanvasLayerState)> layerWriter;
int layerCount = 0;
for (SkCanvas::LayerIter layer(canvas); !layer.done(); layer.next()) {
// we currently only work for bitmap backed devices
SkPixmap pmap;
if (!layer.device()->accessPixels(&pmap) || 0 == pmap.width() || 0 == pmap.height()) {
return nullptr;
}
SkCanvasLayerState* layerState =
(SkCanvasLayerState*) layerWriter.reserve(sizeof(SkCanvasLayerState));
layerState->type = kRaster_CanvasBackend;
layerState->x = layer.x();
layerState->y = layer.y();
layerState->width = pmap.width();
layerState->height = pmap.height();
switch (pmap.colorType()) {
case kN32_SkColorType:
layerState->raster.config = kARGB_8888_RasterConfig;
break;
case kRGB_565_SkColorType:
layerState->raster.config = kRGB_565_RasterConfig;
break;
default:
return nullptr;
}
layerState->raster.rowBytes = pmap.rowBytes();
layerState->raster.pixels = pmap.writable_addr();
setup_MC_state(&layerState->mcState, layer.matrix(), layer.clip().bwRgn());
layerCount++;
}
// allocate memory for the layers and then and copy them to the struct
SkASSERT(layerWriter.bytesWritten() == layerCount * sizeof(SkCanvasLayerState));
canvasState->layerCount = layerCount;
canvasState->layers = (SkCanvasLayerState*) sk_malloc_throw(layerWriter.bytesWritten());
layerWriter.flatten(canvasState->layers);
return canvasState.release();
}