本文整理汇总了C++中SkBitmap::getAddr32方法的典型用法代码示例。如果您正苦于以下问题:C++ SkBitmap::getAddr32方法的具体用法?C++ SkBitmap::getAddr32怎么用?C++ SkBitmap::getAddr32使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkBitmap
的用法示例。
在下文中一共展示了SkBitmap::getAddr32方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onFilterImage
bool SkBicubicImageFilter::onFilterImage(Proxy* proxy,
const SkBitmap& source,
const SkMatrix& matrix,
SkBitmap* result,
SkIPoint* loc) {
SkBitmap src = source;
if (getInput(0) && !getInput(0)->filterImage(proxy, source, matrix, &src, loc)) {
return false;
}
if (src.config() != SkBitmap::kARGB_8888_Config) {
return false;
}
SkAutoLockPixels alp(src);
if (!src.getPixels()) {
return false;
}
SkRect dstRect = SkRect::MakeWH(SkScalarMul(SkIntToScalar(src.width()), fScale.fWidth),
SkScalarMul(SkIntToScalar(src.height()), fScale.fHeight));
SkIRect dstIRect;
dstRect.roundOut(&dstIRect);
result->setConfig(src.config(), dstIRect.width(), dstIRect.height());
result->allocPixels();
if (!result->getPixels()) {
return false;
}
SkRect srcRect;
src.getBounds(&srcRect);
SkMatrix inverse;
inverse.setRectToRect(dstRect, srcRect, SkMatrix::kFill_ScaleToFit);
inverse.postTranslate(SkFloatToScalar(-0.5f), SkFloatToScalar(-0.5f));
for (int y = dstIRect.fTop; y < dstIRect.fBottom; ++y) {
SkPMColor* dptr = result->getAddr32(dstIRect.fLeft, y);
for (int x = dstIRect.fLeft; x < dstIRect.fRight; ++x) {
SkPoint srcPt, dstPt = SkPoint::Make(SkIntToScalar(x), SkIntToScalar(y));
inverse.mapPoints(&srcPt, &dstPt, 1);
SkScalar fractx = srcPt.fX - SkScalarFloorToScalar(srcPt.fX);
SkScalar fracty = srcPt.fY - SkScalarFloorToScalar(srcPt.fY);
int sx = SkScalarFloorToInt(srcPt.fX);
int sy = SkScalarFloorToInt(srcPt.fY);
int x0 = SkClampMax(sx - 1, src.width() - 1);
int x1 = SkClampMax(sx , src.width() - 1);
int x2 = SkClampMax(sx + 1, src.width() - 1);
int x3 = SkClampMax(sx + 2, src.width() - 1);
int y0 = SkClampMax(sy - 1, src.height() - 1);
int y1 = SkClampMax(sy , src.height() - 1);
int y2 = SkClampMax(sy + 1, src.height() - 1);
int y3 = SkClampMax(sy + 2, src.height() - 1);
SkPMColor s00 = *src.getAddr32(x0, y0);
SkPMColor s10 = *src.getAddr32(x1, y0);
SkPMColor s20 = *src.getAddr32(x2, y0);
SkPMColor s30 = *src.getAddr32(x3, y0);
SkPMColor s0 = cubicBlend(fCoefficients, fractx, s00, s10, s20, s30);
SkPMColor s01 = *src.getAddr32(x0, y1);
SkPMColor s11 = *src.getAddr32(x1, y1);
SkPMColor s21 = *src.getAddr32(x2, y1);
SkPMColor s31 = *src.getAddr32(x3, y1);
SkPMColor s1 = cubicBlend(fCoefficients, fractx, s01, s11, s21, s31);
SkPMColor s02 = *src.getAddr32(x0, y2);
SkPMColor s12 = *src.getAddr32(x1, y2);
SkPMColor s22 = *src.getAddr32(x2, y2);
SkPMColor s32 = *src.getAddr32(x3, y2);
SkPMColor s2 = cubicBlend(fCoefficients, fractx, s02, s12, s22, s32);
SkPMColor s03 = *src.getAddr32(x0, y3);
SkPMColor s13 = *src.getAddr32(x1, y3);
SkPMColor s23 = *src.getAddr32(x2, y3);
SkPMColor s33 = *src.getAddr32(x3, y3);
SkPMColor s3 = cubicBlend(fCoefficients, fractx, s03, s13, s23, s33);
*dptr++ = cubicBlend(fCoefficients, fracty, s0, s1, s2, s3);
}
}
return true;
}
示例2: fetch
static inline SkPMColor fetch(const SkBitmap& src, int x, int y) {
return *src.getAddr32(x, y);
}
示例3: onFilterImageDeprecated
bool SkBlurImageFilter::onFilterImageDeprecated(Proxy* proxy,
const SkBitmap& source, const Context& ctx,
SkBitmap* dst, SkIPoint* offset) const {
SkBitmap src = source;
SkIPoint srcOffset = SkIPoint::Make(0, 0);
if (!this->filterInputDeprecated(0, proxy, source, ctx, &src, &srcOffset)) {
return false;
}
if (src.colorType() != kN32_SkColorType) {
return false;
}
SkIRect srcBounds = src.bounds();
srcBounds.offset(srcOffset);
SkIRect dstBounds;
if (!this->applyCropRect(this->mapContext(ctx), srcBounds, &dstBounds)) {
return false;
}
if (!srcBounds.intersect(dstBounds)) {
return false;
}
SkVector sigma = map_sigma(fSigma, ctx.ctm());
int kernelSizeX, kernelSizeX3, lowOffsetX, highOffsetX;
int kernelSizeY, kernelSizeY3, lowOffsetY, highOffsetY;
getBox3Params(sigma.x(), &kernelSizeX, &kernelSizeX3, &lowOffsetX, &highOffsetX);
getBox3Params(sigma.y(), &kernelSizeY, &kernelSizeY3, &lowOffsetY, &highOffsetY);
if (kernelSizeX < 0 || kernelSizeY < 0) {
return false;
}
if (kernelSizeX == 0 && kernelSizeY == 0) {
src.extractSubset(dst, srcBounds);
offset->fX = srcBounds.x();
offset->fY = srcBounds.y();
return true;
}
SkAutoLockPixels alp(src);
if (!src.getPixels()) {
return false;
}
SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(dstBounds.width(), dstBounds.height()));
if (!device) {
return false;
}
*dst = device->accessBitmap(false);
SkAutoLockPixels alp_dst(*dst);
SkAutoTUnref<SkBaseDevice> tempDevice(proxy->createDevice(dst->width(), dst->height()));
if (!tempDevice) {
return false;
}
SkBitmap temp = tempDevice->accessBitmap(false);
SkAutoLockPixels alpTemp(temp);
offset->fX = dstBounds.fLeft;
offset->fY = dstBounds.fTop;
SkPMColor* t = temp.getAddr32(0, 0);
SkPMColor* d = dst->getAddr32(0, 0);
int w = dstBounds.width(), h = dstBounds.height();
const SkPMColor* s = src.getAddr32(srcBounds.x() - srcOffset.x(), srcBounds.y() - srcOffset.y());
srcBounds.offset(-dstBounds.x(), -dstBounds.y());
dstBounds.offset(-dstBounds.x(), -dstBounds.y());
SkIRect srcBoundsT = SkIRect::MakeLTRB(srcBounds.top(), srcBounds.left(), srcBounds.bottom(), srcBounds.right());
SkIRect dstBoundsT = SkIRect::MakeWH(dstBounds.height(), dstBounds.width());
int sw = src.rowBytesAsPixels();
/**
*
* In order to make memory accesses cache-friendly, we reorder the passes to
* use contiguous memory reads wherever possible.
*
* For example, the 6 passes of the X-and-Y blur case are rewritten as
* follows. Instead of 3 passes in X and 3 passes in Y, we perform
* 2 passes in X, 1 pass in X transposed to Y on write, 2 passes in X,
* then 1 pass in X transposed to Y on write.
*
* +----+ +----+ +----+ +---+ +---+ +---+ +----+
* + AB + ----> | AB | ----> | AB | -----> | A | ----> | A | ----> | A | -----> | AB |
* +----+ blurX +----+ blurX +----+ blurXY | B | blurX | B | blurX | B | blurXY +----+
* +---+ +---+ +---+
*
* In this way, two of the y-blurs become x-blurs applied to transposed
* images, and all memory reads are contiguous.
*/
if (kernelSizeX > 0 && kernelSizeY > 0) {
SkOpts::box_blur_xx(s, sw, srcBounds, t, kernelSizeX, lowOffsetX, highOffsetX, w, h);
SkOpts::box_blur_xx(t, w, dstBounds, d, kernelSizeX, highOffsetX, lowOffsetX, w, h);
SkOpts::box_blur_xy(d, w, dstBounds, t, kernelSizeX3, highOffsetX, highOffsetX, w, h);
SkOpts::box_blur_xx(t, h, dstBoundsT, d, kernelSizeY, lowOffsetY, highOffsetY, h, w);
SkOpts::box_blur_xx(d, h, dstBoundsT, t, kernelSizeY, highOffsetY, lowOffsetY, h, w);
SkOpts::box_blur_xy(t, h, dstBoundsT, d, kernelSizeY3, highOffsetY, highOffsetY, h, w);
} else if (kernelSizeX > 0) {
SkOpts::box_blur_xx(s, sw, srcBounds, d, kernelSizeX, lowOffsetX, highOffsetX, w, h);
SkOpts::box_blur_xx(d, w, dstBounds, t, kernelSizeX, highOffsetX, lowOffsetX, w, h);
//.........这里部分代码省略.........
示例4: 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,
//.........这里部分代码省略.........
示例5: render_picture
/**
* Render the SKP file(s) within inputPath, writing their bitmap images into outputDir.
*
* @param inputPath path to an individual SKP file, or a directory of SKP files
* @param outputDir if not NULL, write the image(s) generated into this directory
* @param renderer PictureRenderer to use to render the SKPs
* @param jsonSummaryPtr if not NULL, add the image(s) generated to this summary
*/
static bool render_picture(const SkString& inputPath, const SkString* outputDir,
sk_tools::PictureRenderer& renderer,
sk_tools::ImageResultsSummary *jsonSummaryPtr) {
int diffs[256] = {0};
SkBitmap* bitmap = NULL;
renderer.setJsonSummaryPtr(jsonSummaryPtr);
bool success = render_picture_internal(inputPath,
FLAGS_writeWholeImage ? NULL : outputDir,
renderer,
FLAGS_validate || FLAGS_writeWholeImage ? &bitmap : NULL);
if (!success || ((FLAGS_validate || FLAGS_writeWholeImage) && bitmap == NULL)) {
SkDebugf("Failed to draw the picture.\n");
SkDELETE(bitmap);
return false;
}
if (FLAGS_validate) {
SkBitmap* referenceBitmap = NULL;
sk_tools::PictureRenderer* referenceRenderer;
// If the renderer uses a BBoxHierarchy, then the reference renderer
// will be the same renderer, without the bbh.
AutoRestoreBbhType arbbh;
if (sk_tools::PictureRenderer::kNone_BBoxHierarchyType !=
renderer.getBBoxHierarchyType()) {
referenceRenderer = &renderer;
referenceRenderer->ref(); // to match auto unref below
arbbh.set(referenceRenderer, sk_tools::PictureRenderer::kNone_BBoxHierarchyType);
} else {
referenceRenderer = SkNEW(sk_tools::SimplePictureRenderer);
}
SkAutoTUnref<sk_tools::PictureRenderer> aurReferenceRenderer(referenceRenderer);
success = render_picture_internal(inputPath, NULL, *referenceRenderer,
&referenceBitmap);
if (!success || NULL == referenceBitmap || NULL == referenceBitmap->getPixels()) {
SkDebugf("Failed to draw the reference picture.\n");
SkDELETE(bitmap);
SkDELETE(referenceBitmap);
return false;
}
if (success && (bitmap->width() != referenceBitmap->width())) {
SkDebugf("Expected image width: %i, actual image width %i.\n",
referenceBitmap->width(), bitmap->width());
SkDELETE(bitmap);
SkDELETE(referenceBitmap);
return false;
}
if (success && (bitmap->height() != referenceBitmap->height())) {
SkDebugf("Expected image height: %i, actual image height %i",
referenceBitmap->height(), bitmap->height());
SkDELETE(bitmap);
SkDELETE(referenceBitmap);
return false;
}
for (int y = 0; success && y < bitmap->height(); y++) {
for (int x = 0; success && x < bitmap->width(); x++) {
int diff = MaxByteDiff(*referenceBitmap->getAddr32(x, y),
*bitmap->getAddr32(x, y));
SkASSERT(diff >= 0 && diff <= 255);
diffs[diff]++;
if (diff > FLAGS_maxComponentDiff) {
SkDebugf("Expected pixel at (%i %i) exceedds maximum "
"component diff of %i: 0x%x, actual 0x%x\n",
x, y, FLAGS_maxComponentDiff,
*referenceBitmap->getAddr32(x, y),
*bitmap->getAddr32(x, y));
SkDELETE(bitmap);
SkDELETE(referenceBitmap);
return false;
}
}
}
SkDELETE(referenceBitmap);
for (int i = 1; i <= 255; ++i) {
if(diffs[i] > 0) {
SkDebugf("Number of pixels with max diff of %i is %i\n", i, diffs[i]);
}
}
}
if (FLAGS_writeWholeImage) {
sk_tools::force_all_opaque(*bitmap);
SkString inputFilename, outputPath;
sk_tools::get_basename(&inputFilename, inputPath);
sk_tools::make_filepath(&outputPath, *outputDir, inputFilename);
//.........这里部分代码省略.........
示例6: onFilterImage
bool SkMagnifierImageFilter::onFilterImage(Proxy*, const SkBitmap& src,
const Context&, SkBitmap* dst,
SkIPoint* offset) const {
if ((src.colorType() != kN32_SkColorType) ||
(fSrcRect.width() >= src.width()) ||
(fSrcRect.height() >= src.height())) {
return false;
}
SkAutoLockPixels alp(src);
SkASSERT(src.getPixels());
if (!src.getPixels() || src.width() <= 0 || src.height() <= 0) {
return false;
}
if (!dst->tryAllocPixels(src.info())) {
return false;
}
SkScalar inv_inset = fInset > 0 ? SkScalarInvert(fInset) : SK_Scalar1;
SkScalar inv_x_zoom = fSrcRect.width() / src.width();
SkScalar inv_y_zoom = fSrcRect.height() / src.height();
SkColor* sptr = src.getAddr32(0, 0);
SkColor* dptr = dst->getAddr32(0, 0);
int width = src.width(), height = src.height();
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
SkScalar x_dist = SkMin32(x, width - x - 1) * inv_inset;
SkScalar y_dist = SkMin32(y, height - y - 1) * inv_inset;
SkScalar weight = 0;
static const SkScalar kScalar2 = SkScalar(2);
// To create a smooth curve at the corners, we need to work on
// a square twice the size of the inset.
if (x_dist < kScalar2 && y_dist < kScalar2) {
x_dist = kScalar2 - x_dist;
y_dist = kScalar2 - y_dist;
SkScalar dist = SkScalarSqrt(SkScalarSquare(x_dist) +
SkScalarSquare(y_dist));
dist = SkMaxScalar(kScalar2 - dist, 0);
weight = SkMinScalar(SkScalarSquare(dist), SK_Scalar1);
} else {
SkScalar sqDist = SkMinScalar(SkScalarSquare(x_dist),
SkScalarSquare(y_dist));
weight = SkMinScalar(sqDist, SK_Scalar1);
}
SkScalar x_interp = SkScalarMul(weight, (fSrcRect.x() + x * inv_x_zoom)) +
(SK_Scalar1 - weight) * x;
SkScalar y_interp = SkScalarMul(weight, (fSrcRect.y() + y * inv_y_zoom)) +
(SK_Scalar1 - weight) * y;
int x_val = SkPin32(SkScalarFloorToInt(x_interp), 0, width - 1);
int y_val = SkPin32(SkScalarFloorToInt(y_interp), 0, height - 1);
*dptr = sptr[y_val * width + x_val];
dptr++;
}
}
return true;
}
示例7: putImageData
void putImageData(ByteArray*& source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint,
SkDevice* dstDevice, const IntSize& size)
{
ASSERT(sourceRect.width() > 0);
ASSERT(sourceRect.height() > 0);
int originX = sourceRect.x();
int destX = destPoint.x() + sourceRect.x();
ASSERT(destX >= 0);
ASSERT(destX < size.width());
ASSERT(originX >= 0);
ASSERT(originX < sourceRect.maxX());
int endX = destPoint.x() + sourceRect.maxX();
ASSERT(endX <= size.width());
int numColumns = endX - destX;
int originY = sourceRect.y();
int destY = destPoint.y() + sourceRect.y();
ASSERT(destY >= 0);
ASSERT(destY < size.height());
ASSERT(originY >= 0);
ASSERT(originY < sourceRect.maxY());
int endY = destPoint.y() + sourceRect.maxY();
ASSERT(endY <= size.height());
int numRows = endY - destY;
unsigned srcBytesPerRow = 4 * sourceSize.width();
SkBitmap deviceBitmap = dstDevice->accessBitmap(true);
SkAutoLockPixels deviceAutoLock(deviceBitmap);
// If the device's bitmap doesn't have pixels we will make a temp and call writePixels on the device.
bool temporaryBitmap = !deviceBitmap.getPixels();
SkBitmap destBitmap;
if (temporaryBitmap) {
destBitmap.setConfig(SkBitmap::kARGB_8888_Config, numColumns, numRows, srcBytesPerRow);
if (!destBitmap.allocPixels())
CRASH();
} else
deviceBitmap.extractSubset(&destBitmap, SkIRect::MakeXYWH(destX, destY, numColumns, numRows));
// Whether we made a temporary or not destBitmap is always configured to be written at 0,0
SkAutoLockPixels destAutoLock(destBitmap);
const unsigned char* srcRow = source->data() + originY * srcBytesPerRow + originX * 4;
for (int y = 0; y < numRows; ++y) {
SkPMColor* destRow = destBitmap.getAddr32(0, y);
for (int x = 0; x < numColumns; ++x) {
const unsigned char* srcPixel = &srcRow[x * 4];
if (multiplied == Unmultiplied) {
unsigned char alpha = srcPixel[3];
unsigned char r = SkMulDiv255Ceiling(srcPixel[0], alpha);
unsigned char g = SkMulDiv255Ceiling(srcPixel[1], alpha);
unsigned char b = SkMulDiv255Ceiling(srcPixel[2], alpha);
destRow[x] = SkPackARGB32(alpha, r, g, b);
} else
destRow[x] = SkPackARGB32(srcPixel[3], srcPixel[0], srcPixel[1], srcPixel[2]);
}
srcRow += srcBytesPerRow;
}
// If we used a temporary then write it to the device
if (temporaryBitmap)
dstDevice->writePixels(destBitmap, destX, destY);
}
示例8: DrawWithFP
sk_sp<SkSpecialImage> SkMagnifierImageFilter::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;
}
const SkIRect inputBounds = SkIRect::MakeXYWH(inputOffset.x(), inputOffset.y(),
input->width(), input->height());
SkIRect bounds;
if (!this->applyCropRect(ctx, inputBounds, &bounds)) {
return nullptr;
}
SkScalar invInset = fInset > 0 ? SkScalarInvert(fInset) : SK_Scalar1;
SkScalar invXZoom = fSrcRect.width() / bounds.width();
SkScalar invYZoom = fSrcRect.height() / bounds.height();
#if SK_SUPPORT_GPU
if (source->isTextureBacked()) {
GrContext* context = source->getContext();
sk_sp<GrTexture> inputTexture(input->asTextureRef(context));
SkASSERT(inputTexture);
offset->fX = bounds.left();
offset->fY = bounds.top();
bounds.offset(-inputOffset);
SkScalar yOffset = inputTexture->origin() == kTopLeft_GrSurfaceOrigin
? fSrcRect.y()
: inputTexture->height() -
fSrcRect.height() * inputTexture->height() / bounds.height() - fSrcRect.y();
int boundsY = inputTexture->origin() == kTopLeft_GrSurfaceOrigin
? bounds.y()
: inputTexture->height() - bounds.height();
SkRect effectBounds = SkRect::MakeXYWH(
SkIntToScalar(bounds.x()) / inputTexture->width(),
SkIntToScalar(boundsY) / inputTexture->height(),
SkIntToScalar(inputTexture->width()) / bounds.width(),
SkIntToScalar(inputTexture->height()) / bounds.height());
// SRGBTODO: Handle sRGB here
sk_sp<GrFragmentProcessor> fp(GrMagnifierEffect::Create(
inputTexture.get(),
effectBounds,
fSrcRect.x() / inputTexture->width(),
yOffset / inputTexture->height(),
invXZoom,
invYZoom,
bounds.width() * invInset,
bounds.height() * invInset));
if (!fp) {
return nullptr;
}
return DrawWithFP(context, std::move(fp), bounds);
}
#endif
SkBitmap inputBM;
if (!input->getROPixels(&inputBM)) {
return nullptr;
}
if ((inputBM.colorType() != kN32_SkColorType) ||
(fSrcRect.width() >= inputBM.width()) || (fSrcRect.height() >= inputBM.height())) {
return nullptr;
}
SkAutoLockPixels alp(inputBM);
SkASSERT(inputBM.getPixels());
if (!inputBM.getPixels() || inputBM.width() <= 0 || inputBM.height() <= 0) {
return nullptr;
}
const SkImageInfo info = SkImageInfo::MakeN32Premul(bounds.width(), bounds.height());
SkBitmap dst;
if (!dst.tryAllocPixels(info)) {
return nullptr;
}
SkAutoLockPixels dstLock(dst);
SkColor* dptr = dst.getAddr32(0, 0);
int dstWidth = dst.width(), dstHeight = dst.height();
for (int y = 0; y < dstHeight; ++y) {
for (int x = 0; x < dstWidth; ++x) {
SkScalar x_dist = SkMin32(x, dstWidth - x - 1) * invInset;
SkScalar y_dist = SkMin32(y, dstHeight - y - 1) * invInset;
SkScalar weight = 0;
static const SkScalar kScalar2 = SkScalar(2);
//.........这里部分代码省略.........
示例9: dstLock
sk_sp<SkSpecialImage> SkMorphologyImageFilter::filterImageGeneric(bool dilate,
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->applyCropRect(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 (input->peekTexture() && input->peekTexture()->getContext()) {
auto type = dilate ? GrMorphologyEffect::kDilate_MorphologyType
: GrMorphologyEffect::kErode_MorphologyType;
sk_sp<SkSpecialImage> result(apply_morphology(input.get(), srcBounds, type,
SkISize::Make(width, height)));
if (result) {
offset->fX = bounds.left();
offset->fY = bounds.top();
}
return result;
}
#endif
SkPixmap inputPixmap;
if (!input->peekPixels(&inputPixmap)) {
return nullptr;
}
if (inputPixmap.colorType() != kN32_SkColorType) {
return nullptr;
}
SkImageInfo info = SkImageInfo::Make(bounds.width(), bounds.height(),
inputPixmap.colorType(), inputPixmap.alphaType());
SkBitmap dst;
if (!dst.tryAllocPixels(info)) {
return nullptr;
}
SkAutoLockPixels dstLock(dst);
SkMorphologyImageFilter::Proc procX, procY;
if (dilate) {
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;
}
SkAutoLockPixels tmpLock(tmp);
call_proc_X(procX, inputPixmap, &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, inputPixmap, &dst, width, srcBounds);
} else if (height > 0) {
call_proc_Y(procY,
inputPixmap.addr32(srcBounds.left(), srcBounds.top()),
inputPixmap.rowBytesAsPixels(),
&dst, height, srcBounds);
}
//.........这里部分代码省略.........
示例10: getImageData
PassRefPtr<ByteArray> getImageData(const IntRect& rect, SkDevice& srcDevice,
const IntSize& size)
{
RefPtr<ByteArray> result = ByteArray::create(rect.width() * rect.height() * 4);
SkBitmap::Config srcConfig = srcDevice.accessBitmap(false).config();
if (srcConfig == SkBitmap::kNo_Config) {
// This is an empty SkBitmap that could not be configured.
ASSERT(!size.width() || !size.height());
return result.release();
}
unsigned char* data = result->data();
if (rect.x() < 0
|| rect.y() < 0
|| rect.maxX() > size.width()
|| rect.maxY() > size.height())
memset(data, 0, result->length());
int originX = rect.x();
int destX = 0;
if (originX < 0) {
destX = -originX;
originX = 0;
}
int endX = rect.maxX();
if (endX > size.width())
endX = size.width();
int numColumns = endX - originX;
if (numColumns <= 0)
return result.release();
int originY = rect.y();
int destY = 0;
if (originY < 0) {
destY = -originY;
originY = 0;
}
int endY = rect.maxY();
if (endY > size.height())
endY = size.height();
int numRows = endY - originY;
if (numRows <= 0)
return result.release();
ASSERT(srcConfig == SkBitmap::kARGB_8888_Config);
unsigned destBytesPerRow = 4 * rect.width();
SkBitmap srcBitmap;
srcDevice.readPixels(SkIRect::MakeXYWH(originX, originY, numColumns, numRows), &srcBitmap);
unsigned char* destRow = data + destY * destBytesPerRow + destX * 4;
// Do conversion of byte order and alpha divide (if necessary)
for (int y = 0; y < numRows; ++y) {
SkPMColor* srcBitmapRow = srcBitmap.getAddr32(0, y);
for (int x = 0; x < numColumns; ++x) {
SkPMColor srcPMColor = srcBitmapRow[x];
unsigned char* destPixel = &destRow[x * 4];
if (multiplied == Unmultiplied) {
unsigned char a = SkGetPackedA32(srcPMColor);
destPixel[0] = a ? SkGetPackedR32(srcPMColor) * 255 / a : 0;
destPixel[1] = a ? SkGetPackedG32(srcPMColor) * 255 / a : 0;
destPixel[2] = a ? SkGetPackedB32(srcPMColor) * 255 / a : 0;
destPixel[3] = a;
} else {
// Input and output are both pre-multiplied, we just need to re-arrange the
// bytes from the bitmap format to RGBA.
destPixel[0] = SkGetPackedR32(srcPMColor);
destPixel[1] = SkGetPackedG32(srcPMColor);
destPixel[2] = SkGetPackedB32(srcPMColor);
destPixel[3] = SkGetPackedA32(srcPMColor);
}
}
destRow += destBytesPerRow;
}
return result.release();
}
示例11: bitmapLock
PassRefPtr<ImageData> getImageData(const IntRect& rect, const SkBitmap& bitmap,
const IntSize& size)
{
RefPtr<ImageData> result = ImageData::create(rect.width(), rect.height());
if (bitmap.config() == SkBitmap::kNo_Config) {
// This is an empty SkBitmap that could not be configured.
ASSERT(!size.width() || !size.height());
return result;
}
unsigned char* data = result->data()->data()->data();
if (rect.x() < 0 || rect.y() < 0 ||
(rect.x() + rect.width()) > size.width() ||
(rect.y() + rect.height()) > size.height())
memset(data, 0, result->data()->length());
int originX = rect.x();
int destX = 0;
if (originX < 0) {
destX = -originX;
originX = 0;
}
int endX = rect.x() + rect.width();
if (endX > size.width())
endX = size.width();
int numColumns = endX - originX;
int originY = rect.y();
int destY = 0;
if (originY < 0) {
destY = -originY;
originY = 0;
}
int endY = rect.y() + rect.height();
if (endY > size.height())
endY = size.height();
int numRows = endY - originY;
ASSERT(bitmap.config() == SkBitmap::kARGB_8888_Config);
SkAutoLockPixels bitmapLock(bitmap);
unsigned destBytesPerRow = 4 * rect.width();
unsigned char* destRow = data + destY * destBytesPerRow + destX * 4;
for (int y = 0; y < numRows; ++y) {
uint32_t* srcRow = bitmap.getAddr32(originX, originY + y);
for (int x = 0; x < numColumns; ++x) {
unsigned char* destPixel = &destRow[x * 4];
if (multiplied == Unmultiplied) {
SkColor color = srcRow[x];
unsigned a = SkColorGetA(color);
destPixel[0] = a ? SkColorGetR(color) * 255 / a : 0;
destPixel[1] = a ? SkColorGetG(color) * 255 / a : 0;
destPixel[2] = a ? SkColorGetB(color) * 255 / a : 0;
destPixel[3] = a;
} else {
// Input and output are both pre-multiplied, we just need to re-arrange the
// bytes from the bitmap format to RGBA.
destPixel[0] = SkGetPackedR32(srcRow[x]);
destPixel[1] = SkGetPackedG32(srcRow[x]);
destPixel[2] = SkGetPackedB32(srcRow[x]);
destPixel[3] = SkGetPackedA32(srcRow[x]);
}
}
destRow += destBytesPerRow;
}
return result;
}
示例12: fetch
static inline SkPMColor fetch(const SkBitmap& src, int x, int y, const SkIRect& bounds) {
x = SkTPin(x, bounds.fLeft, bounds.fRight - 1);
y = SkTPin(y, bounds.fTop, bounds.fBottom - 1);
return *src.getAddr32(x, y);
}
示例13: pathsDrawTheSame
static int pathsDrawTheSame(const SkPath& one, const SkPath& two,
SkBitmap& bits, SkPath& scaledOne, SkPath& scaledTwo, int& error2x2) {
const int bitWidth = 64;
const int bitHeight = 64;
if (bits.width() == 0) {
bits.setConfig(SkBitmap::kARGB_8888_Config, bitWidth * 2, bitHeight);
bits.allocPixels();
}
SkRect larger = one.getBounds();
larger.join(two.getBounds());
SkScalar largerWidth = larger.width();
if (largerWidth < 4) {
largerWidth = 4;
}
SkScalar largerHeight = larger.height();
if (largerHeight < 4) {
largerHeight = 4;
}
SkScalar hScale = (bitWidth - 2) / largerWidth;
SkScalar vScale = (bitHeight - 2) / largerHeight;
SkMatrix scale;
scale.reset();
scale.preScale(hScale, vScale);
one.transform(scale, &scaledOne);
two.transform(scale, &scaledTwo);
const SkRect& bounds1 = scaledOne.getBounds();
SkCanvas canvas(bits);
canvas.drawColor(SK_ColorWHITE);
SkPaint paint;
canvas.save();
canvas.translate(-bounds1.fLeft + 1, -bounds1.fTop + 1);
canvas.drawPath(scaledOne, paint);
canvas.restore();
canvas.save();
canvas.translate(-bounds1.fLeft + 1 + bitWidth, -bounds1.fTop + 1);
canvas.drawPath(scaledTwo, paint);
canvas.restore();
int errors2 = 0;
int errors = 0;
for (int y = 0; y < bitHeight - 1; ++y) {
uint32_t* addr1 = bits.getAddr32(0, y);
uint32_t* addr2 = bits.getAddr32(0, y + 1);
uint32_t* addr3 = bits.getAddr32(bitWidth, y);
uint32_t* addr4 = bits.getAddr32(bitWidth, y + 1);
for (int x = 0; x < bitWidth - 1; ++x) {
// count 2x2 blocks
bool err = addr1[x] != addr3[x];
if (err) {
errors2 += addr1[x + 1] != addr3[x + 1]
&& addr2[x] != addr4[x] && addr2[x + 1] != addr4[x + 1];
errors++;
}
}
}
if (errors2 >= 6 || errors > 160) {
SkDebugf("%s errors2=%d errors=%d\n", __FUNCTION__, errors2, errors);
}
error2x2 = errors2;
return errors;
}
示例14: callProcY
static void callProcY(SkMorphologyImageFilter::Proc procY, const SkBitmap& src, SkBitmap* dst, int radiusY, const SkIRect& bounds)
{
procY(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0),
radiusY, bounds.height(), bounds.width(),
src.rowBytesAsPixels(), dst->rowBytesAsPixels());
}
示例15: render_picture
/**
* Render the SKP file(s) within inputPath.
*
* @param inputPath path to an individual SKP file, or a directory of SKP files
* @param writePath if not NULL, write all image(s) generated into this directory
* @param mismatchPath if not NULL, write any image(s) not matching expectations into this directory
* @param renderer PictureRenderer to use to render the SKPs
* @param jsonSummaryPtr if not NULL, add the image(s) generated to this summary
*/
static bool render_picture(const SkString& inputPath, const SkString* writePath,
const SkString* mismatchPath, sk_tools::PictureRenderer& renderer,
sk_tools::ImageResultsAndExpectations *jsonSummaryPtr) {
int diffs[256] = {0};
SkBitmap* bitmap = NULL;
renderer.setJsonSummaryPtr(jsonSummaryPtr);
bool success = render_picture_internal(inputPath,
FLAGS_writeWholeImage ? NULL : writePath,
FLAGS_writeWholeImage ? NULL : mismatchPath,
renderer,
FLAGS_validate || FLAGS_writeWholeImage ? &bitmap : NULL);
if (!success || ((FLAGS_validate || FLAGS_writeWholeImage) && bitmap == NULL)) {
SkDebugf("Failed to draw the picture.\n");
delete bitmap;
return false;
}
if (FLAGS_validate) {
SkBitmap* referenceBitmap = NULL;
sk_tools::PictureRenderer* referenceRenderer;
// If the renderer uses a BBoxHierarchy, then the reference renderer
// will be the same renderer, without the bbh.
AutoRestoreBbhType arbbh;
if (sk_tools::PictureRenderer::kNone_BBoxHierarchyType !=
renderer.getBBoxHierarchyType()) {
referenceRenderer = &renderer;
referenceRenderer->ref(); // to match auto unref below
arbbh.set(referenceRenderer, sk_tools::PictureRenderer::kNone_BBoxHierarchyType);
} else {
#if SK_SUPPORT_GPU
referenceRenderer = new sk_tools::SimplePictureRenderer(renderer.getGrContextOptions());
#else
referenceRenderer = new sk_tools::SimplePictureRenderer;
#endif
}
SkAutoTUnref<sk_tools::PictureRenderer> aurReferenceRenderer(referenceRenderer);
success = render_picture_internal(inputPath, NULL, NULL, *referenceRenderer,
&referenceBitmap);
if (!success || NULL == referenceBitmap || NULL == referenceBitmap->getPixels()) {
SkDebugf("Failed to draw the reference picture.\n");
delete bitmap;
delete referenceBitmap;
return false;
}
if (success && (bitmap->width() != referenceBitmap->width())) {
SkDebugf("Expected image width: %i, actual image width %i.\n",
referenceBitmap->width(), bitmap->width());
delete bitmap;
delete referenceBitmap;
return false;
}
if (success && (bitmap->height() != referenceBitmap->height())) {
SkDebugf("Expected image height: %i, actual image height %i",
referenceBitmap->height(), bitmap->height());
delete bitmap;
delete referenceBitmap;
return false;
}
for (int y = 0; success && y < bitmap->height(); y++) {
for (int x = 0; success && x < bitmap->width(); x++) {
int diff = MaxByteDiff(*referenceBitmap->getAddr32(x, y),
*bitmap->getAddr32(x, y));
SkASSERT(diff >= 0 && diff <= 255);
diffs[diff]++;
if (diff > FLAGS_maxComponentDiff) {
SkDebugf("Expected pixel at (%i %i) exceedds maximum "
"component diff of %i: 0x%x, actual 0x%x\n",
x, y, FLAGS_maxComponentDiff,
*referenceBitmap->getAddr32(x, y),
*bitmap->getAddr32(x, y));
delete bitmap;
delete referenceBitmap;
return false;
}
}
}
delete referenceBitmap;
for (int i = 1; i <= 255; ++i) {
if(diffs[i] > 0) {
SkDebugf("Number of pixels with max diff of %i is %i\n", i, diffs[i]);
}
}
}
//.........这里部分代码省略.........