本文整理汇总了C++中SkBitmap::getColor方法的典型用法代码示例。如果您正苦于以下问题:C++ SkBitmap::getColor方法的具体用法?C++ SkBitmap::getColor怎么用?C++ SkBitmap::getColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkBitmap
的用法示例。
在下文中一共展示了SkBitmap::getColor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
// At the time of writing, SkBitmap::erase() works when the color is zero for all formats,
// but some formats failed when the color is non-zero!
DEF_TEST(Bitmap_erase, r) {
SkColorType colorTypes[] = {
kRGB_565_SkColorType,
kARGB_4444_SkColorType,
kRGB_888x_SkColorType,
kRGBA_8888_SkColorType,
kBGRA_8888_SkColorType,
kRGB_101010x_SkColorType,
kRGBA_1010102_SkColorType,
};
for (SkColorType ct : colorTypes) {
SkImageInfo info = SkImageInfo::Make(1,1, (SkColorType)ct, kPremul_SkAlphaType);
SkBitmap bm;
bm.allocPixels(info);
bm.eraseColor(0x00000000);
if (SkColorTypeIsAlwaysOpaque(ct)) {
REPORTER_ASSERT(r, bm.getColor(0,0) == 0xff000000);
} else {
REPORTER_ASSERT(r, bm.getColor(0,0) == 0x00000000);
}
bm.eraseColor(0xaabbccdd);
REPORTER_ASSERT(r, bm.getColor(0,0) != 0xff000000);
REPORTER_ASSERT(r, bm.getColor(0,0) != 0x00000000);
}
}
示例2: compare
/** Assumes that the ref draw was completely inside ref canvas --
implies that everything outside is "bgColor".
Checks that all overlap is the same and that all non-overlap on the
ref is "bgColor".
*/
static bool compare(const SkBitmap& ref, const SkIRect& iref,
const SkBitmap& test, const SkIRect& itest)
{
const int xOff = itest.fLeft - iref.fLeft;
const int yOff = itest.fTop - iref.fTop;
SkAutoLockPixels alpRef(ref);
SkAutoLockPixels alpTest(test);
for (int y = 0; y < test.height(); ++y) {
for (int x = 0; x < test.width(); ++x) {
SkColor testColor = test.getColor(x, y);
int refX = x + xOff;
int refY = y + yOff;
SkColor refColor;
if (refX >= 0 && refX < ref.width() &&
refY >= 0 && refY < ref.height())
{
refColor = ref.getColor(refX, refY);
} else {
refColor = bgColor;
}
if (refColor != testColor) {
return false;
}
}
}
return true;
}
示例3: test_interlaced_gif_data
static void test_interlaced_gif_data(skiatest::Reporter* r,
void* data,
size_t size) {
SkBitmap bm;
bool imageDecodeSuccess = decode_memory(data, size, &bm);
REPORTER_ASSERT(r, imageDecodeSuccess);
REPORTER_ASSERT(r, bm.width() == 9);
REPORTER_ASSERT(r, bm.height() == 9);
REPORTER_ASSERT(r, !(bm.empty()));
if (!(bm.empty())) {
REPORTER_ASSERT(r, bm.getColor(0, 0) == 0xffff0000);
REPORTER_ASSERT(r, bm.getColor(1, 0) == 0xffffff00);
REPORTER_ASSERT(r, bm.getColor(2, 0) == 0xff00ffff);
REPORTER_ASSERT(r, bm.getColor(0, 2) == 0xffffffff);
REPORTER_ASSERT(r, bm.getColor(1, 2) == 0xffff00ff);
REPORTER_ASSERT(r, bm.getColor(2, 2) == 0xff0000ff);
REPORTER_ASSERT(r, bm.getColor(0, 4) == 0xff808080);
REPORTER_ASSERT(r, bm.getColor(1, 4) == 0xff000000);
REPORTER_ASSERT(r, bm.getColor(2, 4) == 0xff00ff00);
REPORTER_ASSERT(r, bm.getColor(0, 6) == 0xffff0000);
REPORTER_ASSERT(r, bm.getColor(1, 6) == 0xffffff00);
REPORTER_ASSERT(r, bm.getColor(2, 6) == 0xff00ffff);
REPORTER_ASSERT(r, bm.getColor(0, 8) == 0xffffffff);
REPORTER_ASSERT(r, bm.getColor(1, 8) == 0xffff00ff);
REPORTER_ASSERT(r, bm.getColor(2, 8) == 0xff0000ff);
}
}
示例4: test_erasecolor_premul
static void test_erasecolor_premul(skiatest::Reporter* reporter, SkColorType ct, SkColor input,
SkColor expected) {
SkBitmap bm;
bm.allocPixels(SkImageInfo::Make(1, 1, ct, kPremul_SkAlphaType));
bm.eraseColor(input);
INFOF(reporter, "expected: %x actual: %x\n", expected, bm.getColor(0, 0));
REPORTER_ASSERT(reporter, bm.getColor(0, 0) == expected);
}
示例5: TestDeferredCanvasFlush
static void TestDeferredCanvasFlush(skiatest::Reporter* reporter) {
SkBitmap store;
create(&store, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
SkDevice device(store);
SkDeferredCanvas canvas(&device);
canvas.clear(0x00000000);
SkAutoLockPixels alp(store);
REPORTER_ASSERT(reporter, store.getColor(0,0) == 0xFFFFFFFF); //verify that clear was deferred
canvas.flush();
REPORTER_ASSERT(reporter, store.getColor(0,0) == 0x00000000); //verify that clear was executed
}
示例6: TestDeferredCanvasBitmapAccess
static void TestDeferredCanvasBitmapAccess(skiatest::Reporter* reporter) {
SkBitmap store;
create(&store, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
SkDevice device(store);
SkDeferredCanvas canvas(&device);
canvas.clear(0x00000000);
SkAutoLockPixels alp(store);
REPORTER_ASSERT(reporter, store.getColor(0,0) == 0xFFFFFFFF); //verify that clear was deferred
SkBitmap accessed = canvas.getDevice()->accessBitmap(false);
REPORTER_ASSERT(reporter, store.getColor(0,0) == 0x00000000); //verify that clear was executed
REPORTER_ASSERT(reporter, accessed.pixelRef() == store.pixelRef());
}
示例7: autoLock
TEST_F(DeferredImageDecoderTest, drawIntoSkPictureProgressive)
{
RefPtr<SharedBuffer> partialData = SharedBuffer::create(m_data->data(), m_data->size() - 10);
// Received only half the file.
m_lazyDecoder->setData(*partialData, false);
RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewNativeImage();
SkPictureRecorder recorder;
SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0);
tempCanvas->drawBitmap(image->bitmap(), 0, 0);
RefPtr<SkPicture> picture = adoptRef(recorder.endRecording());
m_surface->getCanvas()->drawPicture(picture.get());
// Fully received the file and draw the SkPicture again.
m_lazyDecoder->setData(*m_data, true);
image = m_lazyDecoder->frameBufferAtIndex(0)->asNewNativeImage();
tempCanvas = recorder.beginRecording(100, 100, 0, 0);
tempCanvas->drawBitmap(image->bitmap(), 0, 0);
picture = adoptRef(recorder.endRecording());
m_surface->getCanvas()->drawPicture(picture.get());
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));
}
示例8: 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));
}
示例9: 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));
}
}
}
示例10: write_bitmap
static bool write_bitmap(const char outName[], const SkBitmap& bm) {
SkISize size = opaqueSize(bm);
SkBitmap dst;
setup_bitmap(&dst, size.width(), size.height());
for (int y = 0 ; y < dst.height(); y++) {
for (int x = 0 ; x < dst.width(); x++) {
SkColor color = bm.getColor(x, y);
if (SkColorGetA(color) != 0xff) {
int a = SkColorGetA(color);
int r = SkColorGetR(color);
int g = SkColorGetG(color);
int b = SkColorGetB(color);
if (a == 0) {
r = g = b = 0;
} else {
r = (r * a) / 255;
g = (g * a) / 255;
b = (b * a) / 255;
a = 255;
}
color = SkColorSetARGB((U8CPU)a, (U8CPU)r, (U8CPU)g, (U8CPU)b);
}
*dst.getAddr32(x, y) = color;
}
}
return SkImageEncoder::EncodeFile(outName, dst, SkImageEncoder::kPNG_Type, 100);
}
示例11: autoLock
TEST_F(DeferredImageDecoderTest, drawIntoSkPicture)
{
m_lazyDecoder->setData(*m_data, true);
SkBitmap bitmap;
EXPECT_TRUE(m_lazyDecoder->createFrameAtIndex(0, &bitmap));
EXPECT_EQ(1, bitmap.width());
EXPECT_EQ(1, bitmap.height());
EXPECT_FALSE(bitmap.isNull());
EXPECT_TRUE(bitmap.isImmutable());
SkPictureRecorder recorder;
SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0);
tempCanvas->drawBitmap(bitmap, 0, 0);
RefPtr<SkPicture> picture = adoptRef(recorder.endRecording());
EXPECT_EQ(0, m_decodeRequestCount);
m_surface->getCanvas()->drawPicture(picture.get());
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));
}
示例12: 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));
}
}
示例13: ERRORF
/**
* This test checks that getColor works for both swizzles.
*/
DEF_TEST(Bitmap_getColor_Swizzle, r) {
SkBitmap source;
source.allocN32Pixels(1,1);
source.eraseColor(SK_ColorRED);
SkColorType colorTypes[] = {
kRGBA_8888_SkColorType,
kBGRA_8888_SkColorType,
};
for (SkColorType ct : colorTypes) {
SkBitmap copy;
if (!sk_tool_utils::copy_to(©, ct, source)) {
ERRORF(r, "SkBitmap::copy failed %d", (int)ct);
continue;
}
REPORTER_ASSERT(r, source.getColor(0, 0) == copy.getColor(0, 0));
}
}
示例14: encoded
DEF_TEST(WebP, reporter) {
const unsigned char encodedWebP[] = {
0x52, 0x49, 0x46, 0x46, 0x2c, 0x01, 0x00, 0x00, 0x57, 0x45, 0x42, 0x50,
0x56, 0x50, 0x38, 0x4c, 0x20, 0x01, 0x00, 0x00, 0x2f, 0x07, 0xc0, 0x01,
0x00, 0xff, 0x01, 0x45, 0x03, 0x00, 0xe2, 0xd5, 0xae, 0x60, 0x2b, 0xad,
0xd9, 0x68, 0x76, 0xb6, 0x8d, 0x6a, 0x1d, 0xc0, 0xe6, 0x19, 0xd6, 0x16,
0xb7, 0xb4, 0xef, 0xcf, 0xc3, 0x15, 0x6c, 0xb3, 0xbd, 0x77, 0x0d, 0x85,
0x6d, 0x1b, 0xa9, 0xb1, 0x2b, 0xdc, 0x3d, 0x83, 0xdb, 0x00, 0x00, 0xc8,
0x26, 0xe5, 0x01, 0x99, 0x8a, 0xd5, 0xdd, 0xfc, 0x82, 0xcd, 0xcd, 0x9a,
0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53, 0xa2, 0x05, 0x8c, 0x2f, 0xcd, 0xa8,
0xa7, 0xf3, 0xa3, 0xbd, 0x83, 0x8b, 0x2a, 0xc8, 0x58, 0xf5, 0xac, 0x80,
0xe3, 0xfe, 0x66, 0xa4, 0x7c, 0x1b, 0x6c, 0xd1, 0xa9, 0xd8, 0x14, 0xd0,
0xc5, 0xb5, 0x39, 0x71, 0x97, 0x19, 0x19, 0x1b
};
SkAutoDataUnref encoded(SkData::NewWithCopy(encodedWebP,
sizeof(encodedWebP)));
SkBitmap bm;
bool success = SkInstallDiscardablePixelRef(
SkDecodingImageGenerator::Create(encoded,
SkDecodingImageGenerator::Options()), &bm);
REPORTER_ASSERT(reporter, success);
if (!success) {
return;
}
SkAutoLockPixels alp(bm);
bool rightSize = ((kExpectedWidth == bm.width())
&& (kExpectedHeight == bm.height()));
REPORTER_ASSERT(reporter, rightSize);
if (rightSize) {
bool error = false;
const SkColor* correctPixel = kExpectedPixels;
for (int y = 0; y < bm.height(); ++y) {
for (int x = 0; x < bm.width(); ++x) {
error |= (*correctPixel != bm.getColor(x, y));
++correctPixel;
}
}
REPORTER_ASSERT(reporter, !error);
}
}
示例15: compare_bitmaps
static void compare_bitmaps(skiatest::Reporter* reporter,
const SkBitmap& b1, const SkBitmap& b2) {
REPORTER_ASSERT(reporter, b1.width() == b2.width());
REPORTER_ASSERT(reporter, b1.height() == b2.height());
if ((b1.width() != b2.width()) ||
(b1.height() != b2.height())) {
return;
}
int pixelErrors = 0;
for (int y = 0; y < b2.height(); ++y) {
for (int x = 0; x < b2.width(); ++x) {
if (b1.getColor(x, y) != b2.getColor(x, y))
++pixelErrors;
}
}
REPORTER_ASSERT(reporter, 0 == pixelErrors);
}