本文整理汇总了C++中SkBitmap::allocN32Pixels方法的典型用法代码示例。如果您正苦于以下问题:C++ SkBitmap::allocN32Pixels方法的具体用法?C++ SkBitmap::allocN32Pixels怎么用?C++ SkBitmap::allocN32Pixels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkBitmap
的用法示例。
在下文中一共展示了SkBitmap::allocN32Pixels方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dev
// Tests that SkNewImageFromBitmap obeys pixelref origin.
DEF_TEST(SkImageFromBitmap_extractSubset, reporter) {
SkAutoTUnref<SkImage> image;
{
SkBitmap srcBitmap;
srcBitmap.allocN32Pixels(gWidth, gHeight);
srcBitmap.eraseColor(SK_ColorRED);
SkBitmapDevice dev(srcBitmap);
SkCanvas canvas(&dev);
SkIRect r = SkIRect::MakeXYWH(5, 5, gWidth - 5, gWidth - 5);
SkPaint p;
p.setColor(SK_ColorGREEN);
canvas.drawIRect(r, p);
SkBitmap dstBitmap;
srcBitmap.extractSubset(&dstBitmap, r);
image.reset(SkNewImageFromBitmap(dstBitmap, true, NULL));
}
SkBitmap tgt;
tgt.allocN32Pixels(gWidth, gHeight);
SkBitmapDevice dev(tgt);
SkCanvas canvas(&dev);
canvas.clear(SK_ColorTRANSPARENT);
canvas.drawImage(image, 0, 0, NULL);
uint32_t pixel = 0;
SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
canvas.readPixels(info, &pixel, 4, 0, 0);
REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
canvas.readPixels(info, &pixel, 4, gWidth - 6, gWidth - 6);
REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
canvas.readPixels(info, &pixel, 4, gWidth - 5, gWidth - 5);
REPORTER_ASSERT(reporter, pixel == SK_ColorTRANSPARENT);
}
示例2: lock
TEST(DragImageTest, InterpolationNone)
{
SkBitmap expectedBitmap;
expectedBitmap.allocN32Pixels(4, 4);
{
SkAutoLockPixels lock(expectedBitmap);
expectedBitmap.eraseArea(SkIRect::MakeXYWH(0, 0, 2, 2), 0xFFFFFFFF);
expectedBitmap.eraseArea(SkIRect::MakeXYWH(0, 2, 2, 2), 0xFF000000);
expectedBitmap.eraseArea(SkIRect::MakeXYWH(2, 0, 2, 2), 0xFF000000);
expectedBitmap.eraseArea(SkIRect::MakeXYWH(2, 2, 2, 2), 0xFFFFFFFF);
}
SkBitmap testBitmap;
testBitmap.allocN32Pixels(2, 2);
{
SkAutoLockPixels lock(testBitmap);
testBitmap.eraseArea(SkIRect::MakeXYWH(0, 0, 1, 1), 0xFFFFFFFF);
testBitmap.eraseArea(SkIRect::MakeXYWH(0, 1, 1, 1), 0xFF000000);
testBitmap.eraseArea(SkIRect::MakeXYWH(1, 0, 1, 1), 0xFF000000);
testBitmap.eraseArea(SkIRect::MakeXYWH(1, 1, 1, 1), 0xFFFFFFFF);
}
RefPtr<TestImage> testImage = TestImage::create(adoptRef(SkImage::NewFromBitmap(testBitmap)));
OwnPtr<DragImage> dragImage = DragImage::create(testImage.get(), DoNotRespectImageOrientation, 1, InterpolationNone);
ASSERT_TRUE(dragImage);
dragImage->scale(2, 2);
const SkBitmap& dragBitmap = dragImage->bitmap();
{
SkAutoLockPixels lock1(dragBitmap);
SkAutoLockPixels lock2(expectedBitmap);
for (int x = 0; x < dragBitmap.width(); ++x)
for (int y = 0; y < dragBitmap.height(); ++y)
EXPECT_EQ(expectedBitmap.getColor(x, y), dragBitmap.getColor(x, y));
}
}
示例3: test_drawBitmap
static void test_drawBitmap(skiatest::Reporter* reporter) {
SkBitmap src;
src.allocN32Pixels(10, 10);
src.eraseColor(SK_ColorWHITE);
SkBitmap dst;
dst.allocN32Pixels(10, 10);
dst.eraseColor(SK_ColorTRANSPARENT);
SkCanvas canvas(dst);
SkPaint paint;
// we are initially transparent
REPORTER_ASSERT(reporter, 0 == *dst.getAddr32(5, 5));
// we see the bitmap drawn
canvas.drawBitmap(src, 0, 0, &paint);
REPORTER_ASSERT(reporter, 0xFFFFFFFF == *dst.getAddr32(5, 5));
// reverify we are clear again
dst.eraseColor(SK_ColorTRANSPARENT);
REPORTER_ASSERT(reporter, 0 == *dst.getAddr32(5, 5));
// if the bitmap is clipped out, we don't draw it
canvas.drawBitmap(src, SkIntToScalar(-10), 0, &paint);
REPORTER_ASSERT(reporter, 0 == *dst.getAddr32(5, 5));
// now install our looper, which will draw, since it internally translates
// to the left. The test is to ensure that canvas' quickReject machinary
// allows us through, even though sans-looper we would look like we should
// be clipped out.
paint.setLooper(sk_make_sp<TestLooper>());
canvas.drawBitmap(src, SkIntToScalar(-10), 0, &paint);
REPORTER_ASSERT(reporter, 0xFFFFFFFF == *dst.getAddr32(5, 5));
}
示例4: canvas
DEF_TEST(Image_NewFromGenerator, r) {
TestImageGenerator::TestType testTypes[] = {
TestImageGenerator::kFailGetPixels_TestType,
TestImageGenerator::kSucceedGetPixels_TestType,
};
for (size_t i = 0; i < SK_ARRAY_COUNT(testTypes); ++i) {
TestImageGenerator::TestType test = testTypes[i];
SkImageGenerator* gen = SkNEW_ARGS(TestImageGenerator, (test, r));
SkAutoTUnref<SkImage> image(SkImage::NewFromGenerator(gen));
if (NULL == image.get()) {
ERRORF(r, "SkImage::NewFromGenerator unexpecedly failed ["
SK_SIZE_T_SPECIFIER "]", i);
continue;
}
REPORTER_ASSERT(r, TestImageGenerator::Width() == image->width());
REPORTER_ASSERT(r, TestImageGenerator::Height() == image->height());
SkBitmap bitmap;
bitmap.allocN32Pixels(TestImageGenerator::Width(), TestImageGenerator::Height());
SkCanvas canvas(bitmap);
const SkColor kDefaultColor = 0xffabcdef;
canvas.clear(kDefaultColor);
canvas.drawImage(image, 0, 0, NULL);
if (TestImageGenerator::kSucceedGetPixels_TestType == test) {
REPORTER_ASSERT(
r, TestImageGenerator::Color() == *bitmap.getAddr32(0, 0));
} else {
REPORTER_ASSERT(r, kDefaultColor == bitmap.getColor(0,0));
}
}
}
示例5: canvas
DEF_TEST(FlatData, reporter) {
// Test flattening SkShader
SkPoint points[2];
points[0].set(0, 0);
points[1].set(SkIntToScalar(20), SkIntToScalar(20));
SkColor colors[2];
colors[0] = SK_ColorRED;
colors[1] = SK_ColorBLUE;
SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(points, colors, NULL, 2,
SkShader::kRepeat_TileMode));
testCreate<SkFlattenableTraits>(reporter, *shader);
// Test SkBitmap
{
SkBitmap bm;
bm.allocN32Pixels(50, 50);
SkCanvas canvas(bm);
SkPaint paint;
paint.setShader(shader);
canvas.drawPaint(paint);
testCreate<SkBitmapTraits>(reporter, bm);
}
// Test SkColorFilter
SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateLightingFilter(SK_ColorBLUE, SK_ColorRED));
testCreate<SkFlattenableTraits>(reporter, *cf);
// Test SkXfermode
SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(SkXfermode::kDstOver_Mode));
testCreate<SkFlattenableTraits>(reporter, *xfer);
}
示例6: ConstXTileBench
ConstXTileBench(SkShader::TileMode xTile,
SkShader::TileMode yTile,
bool doFilter,
bool doTrans,
bool doScale)
: fDoFilter(doFilter)
, fDoTrans(doTrans)
, fDoScale(doScale) {
SkBitmap bm;
bm.allocN32Pixels(kWidth, kHeight, true);
bm.eraseColor(SK_ColorWHITE);
create_gradient(&bm);
fPaint.setShader(SkShader::MakeBitmapShader(bm, xTile, yTile));
fName.printf("constXTile_");
static const char* gTileModeStr[SkShader::kTileModeCount] = { "C", "R", "M" };
fName.append(gTileModeStr[xTile]);
fName.append(gTileModeStr[yTile]);
if (doFilter) {
fName.append("_filter");
}
if (doTrans) {
fName.append("_trans");
}
if (doScale) {
fName.append("_scale");
}
}
示例7: canvas
DEF_TEST(CanvasState_test_saveLayer_clip, reporter) {
const int WIDTH = 100;
const int HEIGHT = 100;
const int LAYER_WIDTH = 50;
const int LAYER_HEIGHT = 50;
SkBitmap bitmap;
bitmap.allocN32Pixels(WIDTH, HEIGHT);
SkCanvas canvas(bitmap);
SkRect bounds = SkRect::MakeWH(SkIntToScalar(LAYER_WIDTH), SkIntToScalar(LAYER_HEIGHT));
canvas.clipRect(SkRect::MakeWH(SkIntToScalar(WIDTH), SkIntToScalar(HEIGHT)));
// Check that saveLayer without the kClipToLayer_SaveFlag leaves the
// clip stack unchanged.
canvas.saveLayer(&bounds, NULL, SkCanvas::kARGB_NoClipLayer_SaveFlag);
SkRect clipStackBounds;
SkClipStack::BoundsType boundsType;
canvas.getClipStack()->getBounds(&clipStackBounds, &boundsType);
REPORTER_ASSERT(reporter, clipStackBounds.width() == WIDTH);
REPORTER_ASSERT(reporter, clipStackBounds.height() == HEIGHT);
canvas.restore();
// Check that saveLayer with the kClipToLayer_SaveFlag sets the clip
// stack to the layer bounds.
canvas.saveLayer(&bounds, NULL, SkCanvas::kARGB_ClipLayer_SaveFlag);
canvas.getClipStack()->getBounds(&clipStackBounds, &boundsType);
REPORTER_ASSERT(reporter, clipStackBounds.width() == LAYER_WIDTH);
REPORTER_ASSERT(reporter, clipStackBounds.height() == LAYER_HEIGHT);
canvas.restore();
}
示例8: drawMask
void drawMask(SkCanvas* canvas, const SkRect& r) {
SkPaint paint;
paint.setAntiAlias(true);
if (true) {
SkBitmap mask;
int w = SkScalarRoundToInt(r.width());
int h = SkScalarRoundToInt(r.height());
mask.allocN32Pixels(w, h);
mask.eraseColor(SK_ColorTRANSPARENT);
SkCanvas c(mask);
SkRect bounds = r;
bounds.offset(-bounds.fLeft, -bounds.fTop);
c.drawOval(bounds, paint);
paint.setBlendMode(SkBlendMode::kDstIn);
canvas->drawBitmap(mask, r.fLeft, r.fTop, &paint);
} else {
SkPath p;
p.addOval(r);
p.setFillType(SkPath::kInverseWinding_FillType);
paint.setBlendMode(SkBlendMode::kDstOut);
canvas->drawPath(p, paint);
}
}
示例9: autoLock
TEST_F(DeferredImageDecoderTest, decodeOnOtherThread)
{
m_lazyDecoder->setData(*m_data, true);
RefPtr<SkImage> image = m_lazyDecoder->createFrameAtIndex(0);
ASSERT_TRUE(image);
EXPECT_EQ(1, image->width());
EXPECT_EQ(1, image->height());
SkPictureRecorder recorder;
SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0);
tempCanvas->drawImage(image.get(), 0, 0);
RefPtr<SkPicture> picture = adoptRef(recorder.endRecording());
EXPECT_EQ(0, m_decodeRequestCount);
// Create a thread to rasterize SkPicture.
OwnPtr<WebThread> thread = adoptPtr(Platform::current()->createThread("RasterThread"));
thread->taskRunner()->postTask(BLINK_FROM_HERE, new Task(threadSafeBind(&rasterizeMain, AllowCrossThreadAccess(m_surface->getCanvas()), AllowCrossThreadAccess(picture.get()))));
thread.clear();
EXPECT_EQ(0, m_decodeRequestCount);
SkBitmap canvasBitmap;
canvasBitmap.allocN32Pixels(100, 100);
ASSERT_TRUE(m_surface->getCanvas()->readPixels(&canvasBitmap, 0, 0));
SkAutoLockPixels autoLock(canvasBitmap);
EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0));
}
示例10: TestConstantGradient
// Ensure that repeated color gradients behave like drawing a single color
static void TestConstantGradient(skiatest::Reporter*) {
const SkPoint pts[] = {
{ 0, 0 },
{ SkIntToScalar(10), 0 }
};
SkColor colors[] = { SK_ColorBLUE, SK_ColorBLUE };
const SkScalar pos[] = { 0, SK_Scalar1 };
SkAutoTUnref<SkShader> s(SkGradientShader::CreateLinear(pts,
colors,
pos,
2,
SkShader::kClamp_TileMode));
SkBitmap outBitmap;
outBitmap.allocN32Pixels(10, 1);
SkPaint paint;
paint.setShader(s.get());
SkCanvas canvas(outBitmap);
canvas.drawPaint(paint);
SkAutoLockPixels alp(outBitmap);
for (int i = 0; i < 10; i++) {
// The following is commented out because it currently fails
// Related bug: https://code.google.com/p/skia/issues/detail?id=1098
// REPORTER_ASSERT(reporter, SK_ColorBLUE == outBitmap.getColor(i, 0));
}
}
示例11: main
int main(int argc, char** argv) {
SkAutoGraphics ag;
SkCommandLineFlags::Parse(argc, argv);
if (FLAGS_stop) {
stop(FLAGS_control[0]);
}
if (!FLAGS_skp.isEmpty()) {
client(FLAGS_skp[0], FLAGS_data[0]);
}
if (!FLAGS_png.isEmpty()) {
SkBitmap bitmap;
bitmap.allocN32Pixels(1000, 1000);
SkCanvas canvas(bitmap);
canvas.clear(0xFFFFFFFF);
server(FLAGS_data[0], FLAGS_control[0], &canvas);
canvas.flush();
SkImageEncoder::EncodeFile(FLAGS_png[0], bitmap, SkImageEncoder::kPNG_Type, 100);
SkDebugf("Wrote %s.\n", FLAGS_png[0]);
}
return 0;
}
示例12: TestBitmapSerialization
static void TestBitmapSerialization(const SkBitmap& validBitmap,
const SkBitmap& invalidBitmap,
bool shouldSucceed,
skiatest::Reporter* reporter) {
sk_sp<SkImage> validImage(SkImage::MakeFromBitmap(validBitmap));
sk_sp<SkImageFilter> validBitmapSource(SkImageSource::Make(std::move(validImage)));
sk_sp<SkImage> invalidImage(SkImage::MakeFromBitmap(invalidBitmap));
sk_sp<SkImageFilter> invalidBitmapSource(SkImageSource::Make(std::move(invalidImage)));
sk_sp<SkImageFilter> xfermodeImageFilter(
SkXfermodeImageFilter::Make(SkBlendMode::kSrcOver,
std::move(invalidBitmapSource),
std::move(validBitmapSource), nullptr));
sk_sp<SkImageFilter> deserializedFilter(
TestFlattenableSerialization<SkImageFilter>(
xfermodeImageFilter.get(), shouldSucceed, reporter));
// Try to render a small bitmap using the invalid deserialized filter
// to make sure we don't crash while trying to render it
if (shouldSucceed) {
SkBitmap bitmap;
bitmap.allocN32Pixels(24, 24);
SkCanvas canvas(bitmap);
canvas.clear(0x00000000);
SkPaint paint;
paint.setImageFilter(deserializedFilter);
canvas.clipRect(SkRect::MakeXYWH(0, 0, SkIntToScalar(24), SkIntToScalar(24)));
canvas.drawBitmap(bitmap, 0, 0, &paint);
}
}
示例13: autoLock
TEST_F(DeferredImageDecoderTest, decodeOnOtherThread)
{
m_lazyDecoder->setData(*m_data, true);
RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewNativeImage();
EXPECT_EQ(1, image->bitmap().width());
EXPECT_EQ(1, image->bitmap().height());
EXPECT_FALSE(image->bitmap().isNull());
EXPECT_TRUE(image->bitmap().isImmutable());
SkPictureRecorder recorder;
SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0);
tempCanvas->drawBitmap(image->bitmap(), 0, 0);
RefPtr<SkPicture> picture = adoptRef(recorder.endRecording());
EXPECT_EQ(0, m_frameBufferRequestCount);
// Create a thread to rasterize SkPicture.
OwnPtr<WebThread> thread = adoptPtr(Platform::current()->createThread("RasterThread"));
thread->postTask(new Task(WTF::bind(&rasterizeMain, m_surface->getCanvas(), picture.get())));
thread.clear();
EXPECT_EQ(0, m_frameBufferRequestCount);
SkBitmap canvasBitmap;
canvasBitmap.allocN32Pixels(100, 100);
ASSERT_TRUE(m_surface->getCanvas()->readPixels(&canvasBitmap, 0, 0));
SkAutoLockPixels autoLock(canvasBitmap);
EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0));
}
示例14: canvas
DEF_TEST(Canvas_EmptyBitmap, r) {
SkBitmap dst;
dst.allocN32Pixels(10, 10);
SkCanvas canvas(dst);
test_draw_bitmaps(&canvas);
}
示例15: canvas
static void test_cubic2() {
const char* str = "M2242 -590088L-377758 9.94099e+07L-377758 9.94099e+07L2242 -590088Z";
SkPath path;
SkParsePath::FromSVGString(str, &path);
{
#ifdef SK_BUILD_FOR_WIN
// windows doesn't have strtof
float x = (float)strtod("9.94099e+07", NULL);
#else
float x = strtof("9.94099e+07", NULL);
#endif
int ix = (int)x;
int fx = (int)(x * 65536);
int ffx = SkScalarToFixed(x);
SkDebugf("%g %x %x %x\n", x, ix, fx, ffx);
SkRect r = path.getBounds();
SkIRect ir;
r.round(&ir);
SkDebugf("[%g %g %g %g] [%x %x %x %x]\n",
SkScalarToDouble(r.fLeft), SkScalarToDouble(r.fTop),
SkScalarToDouble(r.fRight), SkScalarToDouble(r.fBottom),
ir.fLeft, ir.fTop, ir.fRight, ir.fBottom);
}
SkBitmap bitmap;
bitmap.allocN32Pixels(300, 200);
SkCanvas canvas(bitmap);
SkPaint paint;
paint.setAntiAlias(true);
canvas.drawPath(path, paint);
}