本文整理汇总了C++中SkPixmap::height方法的典型用法代码示例。如果您正苦于以下问题:C++ SkPixmap::height方法的具体用法?C++ SkPixmap::height怎么用?C++ SkPixmap::height使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkPixmap
的用法示例。
在下文中一共展示了SkPixmap::height方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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);
}
示例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: 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;
}
示例5: erase
bool SkPixmap::erase(const SkColor4f& origColor, const SkIRect* subset) const {
SkPixmap pm;
if (subset) {
if (!this->extractSubset(&pm, *subset)) {
return false;
}
} else {
pm = *this;
}
const SkColor4f color = origColor.pin();
if (kRGBA_F16_SkColorType != pm.colorType()) {
Sk4f c4 = Sk4f::Load(color.vec());
SkColor c;
(c4 * Sk4f(255) + Sk4f(0.5f)).store(&c);
return pm.erase(c);
}
const uint64_t half4 = color.premul().toF16();
for (int y = 0; y < pm.height(); ++y) {
sk_memset64(pm.writable_addr64(0, y), half4, pm.width());
}
return true;
}
示例6: 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;
}
示例7: 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;
}
示例8:
SkLinearBitmapPipeline::SkLinearBitmapPipeline(
const SkMatrix& inverse,
SkFilterQuality filterQuality,
SkShader::TileMode xTile, SkShader::TileMode yTile,
const SkPixmap& srcPixmap) {
SkSize size = SkSize::Make(srcPixmap.width(), srcPixmap.height());
const SkImageInfo& srcImageInfo = srcPixmap.info();
// As the stages are built, the chooser function may skip a stage. For example, with the
// identity matrix, the matrix stage is skipped, and the tilerStage is the first stage.
auto placementStage = choose_pixel_placer(srcImageInfo.alphaType(), &fPixelStage);
auto samplerStage = choose_pixel_sampler(placementStage, srcPixmap, &fSampleStage);
auto tilerStage = choose_tiler(samplerStage, size, xTile, yTile, &fTileXOrBothStage,
&fTileYStage);
auto filterStage = choose_filter(tilerStage, filterQuality, &fFilterStage);
fFirstStage = choose_matrix(filterStage, inverse, &fMatrixStage);
}
示例9: scalePixels
bool SkImage::scalePixels(const SkPixmap& dst, SkFilterQuality quality, CachingHint chint) const {
if (this->width() == dst.width() && this->height() == dst.height()) {
return this->readPixels(dst, 0, 0, chint);
}
// Idea: If/when SkImageGenerator supports a native-scaling API (where the generator itself
// can scale more efficiently) we should take advantage of it here.
//
SkBitmap bm;
if (as_IB(this)->getROPixels(&bm, dst.info().colorSpace(), chint)) {
SkPixmap pmap;
// Note: By calling the pixmap scaler, we never cache the final result, so the chint
// is (currently) only being applied to the getROPixels. If we get a request to
// also attempt to cache the final (scaled) result, we would add that logic here.
//
return bm.peekPixels(&pmap) && pmap.scalePixels(dst, quality);
}
return false;
}
示例10: test_blender
static void test_blender(std::string resourceName, skiatest::Reporter* reporter) {
std::string fileName = resourceName + ".png";
sk_sp<SkImage> image = GetResourceAsImage(fileName.c_str());
if (image == nullptr) {
ERRORF(reporter, "image is NULL");
return;
}
SkBitmap bm;
if (!as_IB(image)->getROPixels(&bm)) {
ERRORF(reporter, "Could not read resource");
return;
}
SkPixmap pixmap;
bm.peekPixels(&pixmap);
SkASSERTF(pixmap.colorType() == kN32_SkColorType, "colorType: %d", pixmap.colorType());
SkASSERT(pixmap.alphaType() != kUnpremul_SkAlphaType);
const uint32_t* src = pixmap.addr32();
const int width = pixmap.rowBytesAsPixels();
SkASSERT(width > 0);
SkASSERT(width < 4000);
SkAutoTArray<uint32_t> correctDst(width);
SkAutoTArray<uint32_t> testDst(width);
for (int y = 0; y < pixmap.height(); y++) {
// TODO: zero is not the most interesting dst to test srcover...
sk_bzero(correctDst.get(), width * sizeof(uint32_t));
sk_bzero(testDst.get(), width * sizeof(uint32_t));
brute_force_srcover_srgb_srgb(correctDst.get(), src, width, width);
SkOpts:: srcover_srgb_srgb( testDst.get(), src, width, width);
for (int x = 0; x < width; x++) {
REPORTER_ASSERT_MESSAGE(
reporter, correctDst[x] == testDst[x],
mismatch_message(resourceName, x, y, src[x], correctDst[x], testDst[x]));
if (correctDst[x] != testDst[x]) break;
}
src += width;
}
}
示例11: generate_pixels
static bool generate_pixels(SkImageGenerator* gen, const SkPixmap& pmap, int originX, int originY,
SkTransferFunctionBehavior behavior) {
const int genW = gen->getInfo().width();
const int genH = gen->getInfo().height();
const SkIRect srcR = SkIRect::MakeWH(genW, genH);
const SkIRect dstR = SkIRect::MakeXYWH(originX, originY, pmap.width(), pmap.height());
if (!srcR.contains(dstR)) {
return false;
}
// If they are requesting a subset, we have to have a temp allocation for full image, and
// then copy the subset into their allocation
SkBitmap full;
SkPixmap fullPM;
const SkPixmap* dstPM = &pmap;
if (srcR != dstR) {
if (!full.tryAllocPixels(pmap.info().makeWH(genW, genH))) {
return false;
}
if (!full.peekPixels(&fullPM)) {
return false;
}
dstPM = &fullPM;
}
SkImageGenerator::Options opts;
opts.fBehavior = behavior;
if (!gen->getPixels(dstPM->info(), dstPM->writable_addr(), dstPM->rowBytes(), &opts)) {
return false;
}
if (srcR != dstR) {
if (!full.readPixels(pmap, originX, originY)) {
return false;
}
}
return true;
}
示例12: 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();
}
示例13: SkASSERT
static void pack4xHToLCD16(const SkPixmap& src, const SkMask& dst,
const SkMaskGamma::PreBlend& maskPreBlend) {
#define SAMPLES_PER_PIXEL 4
#define LCD_PER_PIXEL 3
SkASSERT(kAlpha_8_SkColorType == src.colorType());
SkASSERT(SkMask::kLCD16_Format == dst.fFormat);
const int sample_width = src.width();
const int height = src.height();
uint16_t* dstP = (uint16_t*)dst.fImage;
size_t dstRB = dst.fRowBytes;
// An N tap FIR is defined by
// out[n] = coeff[0]*x[n] + coeff[1]*x[n-1] + ... + coeff[N]*x[n-N]
// or
// out[n] = sum(i, 0, N, coeff[i]*x[n-i])
// The strategy is to use one FIR (different coefficients) for each of r, g, and b.
// This means using every 4th FIR output value of each FIR and discarding the rest.
// The FIRs are aligned, and the coefficients reach 5 samples to each side of their 'center'.
// (For r and b this is technically incorrect, but the coeffs outside round to zero anyway.)
// These are in some fixed point repesentation.
// Adding up to more than one simulates ink spread.
// For implementation reasons, these should never add up to more than two.
// Coefficients determined by a gausian where 5 samples = 3 std deviations (0x110 'contrast').
// Calculated using tools/generate_fir_coeff.py
// With this one almost no fringing is ever seen, but it is imperceptibly blurry.
// The lcd smoothed text is almost imperceptibly different from gray,
// but is still sharper on small stems and small rounded corners than gray.
// This also seems to be about as wide as one can get and only have a three pixel kernel.
// TODO: caculate these at runtime so parameters can be adjusted (esp contrast).
static const unsigned int coefficients[LCD_PER_PIXEL][SAMPLES_PER_PIXEL*3] = {
//The red subpixel is centered inside the first sample (at 1/6 pixel), and is shifted.
{ 0x03, 0x0b, 0x1c, 0x33, 0x40, 0x39, 0x24, 0x10, 0x05, 0x01, 0x00, 0x00, },
//The green subpixel is centered between two samples (at 1/2 pixel), so is symetric
{ 0x00, 0x02, 0x08, 0x16, 0x2b, 0x3d, 0x3d, 0x2b, 0x16, 0x08, 0x02, 0x00, },
//The blue subpixel is centered inside the last sample (at 5/6 pixel), and is shifted.
{ 0x00, 0x00, 0x01, 0x05, 0x10, 0x24, 0x39, 0x40, 0x33, 0x1c, 0x0b, 0x03, },
};
for (int y = 0; y < height; ++y) {
const uint8_t* srcP = src.addr8(0, y);
// TODO: this fir filter implementation is straight forward, but slow.
// It should be possible to make it much faster.
for (int sample_x = -4, pixel_x = 0; sample_x < sample_width + 4; sample_x += 4, ++pixel_x) {
int fir[LCD_PER_PIXEL] = { 0 };
for (int sample_index = SkMax32(0, sample_x - 4), coeff_index = sample_index - (sample_x - 4)
; sample_index < SkMin32(sample_x + 8, sample_width)
; ++sample_index, ++coeff_index)
{
int sample_value = srcP[sample_index];
for (int subpxl_index = 0; subpxl_index < LCD_PER_PIXEL; ++subpxl_index) {
fir[subpxl_index] += coefficients[subpxl_index][coeff_index] * sample_value;
}
}
for (int subpxl_index = 0; subpxl_index < LCD_PER_PIXEL; ++subpxl_index) {
fir[subpxl_index] /= 0x100;
fir[subpxl_index] = SkMin32(fir[subpxl_index], 255);
}
U8CPU r = sk_apply_lut_if<APPLY_PREBLEND>(fir[0], maskPreBlend.fR);
U8CPU g = sk_apply_lut_if<APPLY_PREBLEND>(fir[1], maskPreBlend.fG);
U8CPU b = sk_apply_lut_if<APPLY_PREBLEND>(fir[2], maskPreBlend.fB);
#if SK_SHOW_TEXT_BLIT_COVERAGE
r = SkMax32(r, 10); g = SkMax32(g, 10); b = SkMax32(b, 10);
#endif
dstP[pixel_x] = SkPack888ToRGB16(r, g, b);
}
dstP = (uint16_t*)((char*)dstP + dstRB);
}
}
示例14: valid_for_resize
static bool valid_for_resize(const SkPixmap& source, int dstW, int dstH) {
// TODO: Seems like we shouldn't care about the swizzle of source, just that it's 8888
return source.addr() && source.colorType() == kN32_SkColorType &&
source.width() >= 1 && source.height() >= 1 && dstW >= 1 && dstH >= 1;
}
示例15: Encode
bool SkJpegEncoder::Encode(SkWStream* dst, const SkPixmap& src, const Options& options) {
auto encoder = SkJpegEncoder::Make(dst, src, options);
return encoder.get() && encoder->encodeRows(src.height());
}