本文整理汇总了C++中SkBitmap::getAddr方法的典型用法代码示例。如果您正苦于以下问题:C++ SkBitmap::getAddr方法的具体用法?C++ SkBitmap::getAddr怎么用?C++ SkBitmap::getAddr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkBitmap
的用法示例。
在下文中一共展示了SkBitmap::getAddr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: equal
static bool equal(const SkBitmap& bm1, const SkBitmap& bm2) {
if (bm1.width() != bm2.width() ||
bm1.height() != bm2.height() ||
bm1.config() != bm2.config()) {
return false;
}
size_t pixelBytes = bm1.width() * bm1.bytesPerPixel();
for (int y = 0; y < bm1.height(); y++) {
if (memcmp(bm1.getAddr(0, y), bm2.getAddr(0, y), pixelBytes)) {
return false;
}
}
return true;
}
示例2: SetPixels
bool GraphicsJNI::SetPixels(JNIEnv* env, jintArray srcColors,
int srcOffset, int srcStride,
int x, int y, int width, int height,
const SkBitmap& dstBitmap) {
SkAutoLockPixels alp(dstBitmap);
void* dst = dstBitmap.getPixels();
FromColorProc proc = ChooseFromColorProc(dstBitmap.config());
if (NULL == dst || NULL == proc) {
return false;
}
const jint* array = env->GetIntArrayElements(srcColors, NULL);
const SkColor* src = (const SkColor*)array + srcOffset;
// reset to to actual choice from caller
dst = dstBitmap.getAddr(x, y);
// now copy/convert each scanline
for (int y = 0; y < height; y++) {
proc(dst, src, width, x, y);
src += srcStride;
dst = (char*)dst + dstBitmap.rowBytes();
}
dstBitmap.notifyPixelsChanged();
env->ReleaseIntArrayElements(srcColors, const_cast<jint*>(array),
JNI_ABORT);
return true;
}
示例3: lock
// Utility function to read the value of a given pixel in bm. All
// values converted to uint32_t for simplification of comparisons.
static uint32_t getPixel(int x, int y, const SkBitmap& bm) {
uint32_t val = 0;
uint16_t val16;
uint8_t val8;
SkAutoLockPixels lock(bm);
const void* rawAddr = bm.getAddr(x,y);
switch (bm.config()) {
case SkBitmap::kARGB_8888_Config:
memcpy(&val, rawAddr, sizeof(uint32_t));
break;
case SkBitmap::kARGB_4444_Config:
case SkBitmap::kRGB_565_Config:
memcpy(&val16, rawAddr, sizeof(uint16_t));
val = val16;
break;
case SkBitmap::kA8_Config:
case SkBitmap::kIndex8_Config:
memcpy(&val8, rawAddr, sizeof(uint8_t));
val = val8;
break;
default:
break;
}
return val;
}
示例4: setPixel
// Utility function to set value of any pixel in bm.
// bm.getConfig() specifies what format 'val' must be
// converted to, but at present uint32_t can handle all formats.
static void setPixel(int x, int y, uint32_t val, SkBitmap& bm) {
uint16_t val16;
uint8_t val8;
SkAutoLockPixels lock(bm);
void* rawAddr = bm.getAddr(x,y);
switch (bm.config()) {
case SkBitmap::kARGB_8888_Config:
memcpy(rawAddr, &val, sizeof(uint32_t));
break;
case SkBitmap::kARGB_4444_Config:
case SkBitmap::kRGB_565_Config:
val16 = val & 0xFFFF;
memcpy(rawAddr, &val16, sizeof(uint16_t));
break;
case SkBitmap::kA8_Config:
case SkBitmap::kIndex8_Config:
val8 = val & 0xFF;
memcpy(rawAddr, &val8, sizeof(uint8_t));
break;
default:
// Ignore.
break;
}
}
示例5: check
static void check(skiatest::Reporter* r,
const char path[],
SkISize size,
bool supportsScanlineDecoding) {
SkAutoTDelete<SkStream> stream(resource(path));
if (!stream) {
SkDebugf("Missing resource '%s'\n", path);
return;
}
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach()));
if (!codec) {
ERRORF(r, "Unable to decode '%s'", path);
return;
}
// This test is used primarily to verify rewinding works properly. Using kN32 allows
// us to test this without the added overhead of creating different bitmaps depending
// on the color type (ex: building a color table for kIndex8). DM is where we test
// decodes to all possible destination color types.
SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType);
REPORTER_ASSERT(r, info.dimensions() == size);
SkBitmap bm;
bm.allocPixels(info);
SkAutoLockPixels autoLockPixels(bm);
SkImageGenerator::Result result =
codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL);
REPORTER_ASSERT(r, result == SkImageGenerator::kSuccess);
SkMD5::Digest digest1, digest2;
md5(bm, &digest1);
bm.eraseColor(SK_ColorYELLOW);
result =
codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL);
REPORTER_ASSERT(r, result == SkImageGenerator::kSuccess);
// verify that re-decoding gives the same result.
md5(bm, &digest2);
REPORTER_ASSERT(r, digest1 == digest2);
SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(info);
if (supportsScanlineDecoding) {
bm.eraseColor(SK_ColorYELLOW);
REPORTER_ASSERT(r, scanlineDecoder);
for (int y = 0; y < info.height(); y++) {
result = scanlineDecoder->getScanlines(bm.getAddr(0, y), 1, 0);
REPORTER_ASSERT(r, result == SkImageGenerator::kSuccess);
}
// verify that scanline decoding gives the same result.
SkMD5::Digest digest3;
md5(bm, &digest3);
REPORTER_ASSERT(r, digest3 == digest1);
} else {
REPORTER_ASSERT(r, !scanlineDecoder);
}
}
示例6: autoLockPixels
static void md5(const SkBitmap& bm, SkMD5::Digest* digest) {
SkAutoLockPixels autoLockPixels(bm);
SkASSERT(bm.getPixels());
SkMD5 md5;
size_t rowLen = bm.info().bytesPerPixel() * bm.width();
for (int y = 0; y < bm.height(); ++y) {
md5.update(static_cast<uint8_t*>(bm.getAddr(0, y)), rowLen);
}
md5.finish(*digest);
}
示例7: bitmap_diff
static bool bitmap_diff(SkCanvas* canvas, const SkBitmap& orig,
SkBitmap* diff) {
const SkBitmap& src = canvas->getDevice()->accessBitmap(false);
SkAutoLockPixels alp0(src);
SkAutoLockPixels alp1(orig);
for (int y = 0; y < src.height(); y++) {
const void* srcP = src.getAddr(0, y);
const void* origP = orig.getAddr(0, y);
size_t bytes = src.width() * src.bytesPerPixel();
if (memcmp(srcP, origP, bytes)) {
SkDebugf("---------- difference on line %d\n", y);
return true;
}
}
return false;
}
示例8: check_color
static bool check_color(const SkBitmap& bm, SkPMColor expect32,
uint16_t expect16, uint8_t expect8,
skiatest::Reporter* reporter) {
uint32_t expect;
Proc proc = find_proc(bm, expect32, expect16, expect8, &expect);
for (int y = 0; y < bm.height(); y++) {
uint32_t bad;
int x = proc(bm.getAddr(0, y), bm.width(), expect, &bad);
if (x >= 0) {
SkString str;
str.printf("BlitRow config=%s [%d %d] expected %x got %x",
gConfigName[bm.config()], x, y, expect, bad);
reporter->reportFailed(str);
return false;
}
}
return true;
}
示例9: setPixel
// Utility function to set value of any pixel in bm.
// bm.getConfig() specifies what format 'val' must be
// converted to, but at present uint32_t can handle all formats.
static void setPixel(int x, int y, uint32_t val, SkBitmap& bm) {
uint16_t val16;
uint8_t val8;
SkAutoLockPixels lock(bm);
void* rawAddr = bm.getAddr(x,y);
switch (bm.bytesPerPixel()) {
case 4:
memcpy(rawAddr, &val, sizeof(uint32_t));
break;
case 2:
val16 = val & 0xFFFF;
memcpy(rawAddr, &val16, sizeof(uint16_t));
break;
case 1:
val8 = val & 0xFF;
memcpy(rawAddr, &val8, sizeof(uint8_t));
break;
default:
// Ignore.
break;
}
}
示例10: onDraw
void SubsetSingleBench::onDraw(const int n, SkCanvas* canvas) {
// When the color type is kIndex8, we will need to store the color table. If it is
// used, it will be initialized by the codec.
int colorCount;
SkPMColor colors[256];
if (fUseCodec) {
for (int count = 0; count < n; count++) {
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplicate()));
const SkImageInfo info = codec->getInfo().makeColorType(fColorType);
SkAutoTDeleteArray<uint8_t> row(SkNEW_ARRAY(uint8_t, info.minRowBytes()));
SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(
info, NULL, colors, &colorCount);
SkBitmap bitmap;
bitmap.allocPixels(info.makeWH(fSubsetWidth, fSubsetHeight));
scanlineDecoder->skipScanlines(fOffsetTop);
uint32_t bpp = info.bytesPerPixel();
for (uint32_t y = 0; y < fSubsetHeight; y++) {
scanlineDecoder->getScanlines(row.get(), 1, 0);
memcpy(bitmap.getAddr(0, y), row.get() + fOffsetLeft * bpp,
fSubsetWidth * bpp);
}
}
} else {
for (int count = 0; count < n; count++) {
SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStream));
int width, height;
decoder->buildTileIndex(fStream->duplicate(), &width, &height);
SkBitmap bitmap;
SkIRect rect = SkIRect::MakeXYWH(fOffsetLeft, fOffsetTop, fSubsetWidth,
fSubsetHeight);
decoder->decodeSubset(&bitmap, rect, fColorType);
}
}
}
示例11: lock
// Utility function to read the value of a given pixel in bm. All
// values converted to uint32_t for simplification of comparisons.
static uint32_t getPixel(int x, int y, const SkBitmap& bm) {
uint32_t val = 0;
uint16_t val16;
uint8_t val8;
SkAutoLockPixels lock(bm);
const void* rawAddr = bm.getAddr(x,y);
switch (bm.bytesPerPixel()) {
case 4:
memcpy(&val, rawAddr, sizeof(uint32_t));
break;
case 2:
memcpy(&val16, rawAddr, sizeof(uint16_t));
val = val16;
break;
case 1:
memcpy(&val8, rawAddr, sizeof(uint8_t));
val = val8;
break;
default:
break;
}
return val;
}
示例12: check
static void check(skiatest::Reporter* r,
const char path[],
SkISize size,
bool supportsScanlineDecoding,
bool supportsSubsetDecoding,
bool supportsIncomplete = true) {
SkAutoTDelete<SkStream> stream(resource(path));
if (!stream) {
SkDebugf("Missing resource '%s'\n", path);
return;
}
SkAutoTDelete<SkCodec> codec(nullptr);
bool isIncomplete = supportsIncomplete;
if (isIncomplete) {
size_t size = stream->getLength();
SkAutoTUnref<SkData> data((SkData::NewFromStream(stream, 2 * size / 3)));
codec.reset(SkCodec::NewFromData(data));
} else {
codec.reset(SkCodec::NewFromStream(stream.detach()));
}
if (!codec) {
ERRORF(r, "Unable to decode '%s'", path);
return;
}
// Test full image decodes with SkCodec
SkMD5::Digest codecDigest;
SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType);
SkBitmap bm;
SkCodec::Result expectedResult = isIncomplete ? SkCodec::kIncompleteInput : SkCodec::kSuccess;
test_codec(r, codec.get(), bm, info, size, expectedResult, &codecDigest, nullptr);
// Scanline decoding follows.
// Need to call startScanlineDecode() first.
REPORTER_ASSERT(r, codec->getScanlines(bm.getAddr(0, 0), 1, 0)
== 0);
REPORTER_ASSERT(r, codec->skipScanlines(1)
== 0);
const SkCodec::Result startResult = codec->startScanlineDecode(info);
if (supportsScanlineDecoding) {
bm.eraseColor(SK_ColorYELLOW);
REPORTER_ASSERT(r, startResult == SkCodec::kSuccess);
for (int y = 0; y < info.height(); y++) {
const int lines = codec->getScanlines(bm.getAddr(0, y), 1, 0);
if (!isIncomplete) {
REPORTER_ASSERT(r, 1 == lines);
}
}
// verify that scanline decoding gives the same result.
if (SkCodec::kTopDown_SkScanlineOrder == codec->getScanlineOrder()) {
compare_to_good_digest(r, codecDigest, bm);
}
// Cannot continue to decode scanlines beyond the end
REPORTER_ASSERT(r, codec->getScanlines(bm.getAddr(0, 0), 1, 0)
== 0);
// Interrupting a scanline decode with a full decode starts from
// scratch
REPORTER_ASSERT(r, codec->startScanlineDecode(info) == SkCodec::kSuccess);
const int lines = codec->getScanlines(bm.getAddr(0, 0), 1, 0);
if (!isIncomplete) {
REPORTER_ASSERT(r, lines == 1);
}
REPORTER_ASSERT(r, codec->getPixels(bm.info(), bm.getPixels(), bm.rowBytes())
== expectedResult);
REPORTER_ASSERT(r, codec->getScanlines(bm.getAddr(0, 0), 1, 0)
== 0);
REPORTER_ASSERT(r, codec->skipScanlines(1)
== 0);
// Test partial scanline decodes
if (supports_scaled_codec(path) && info.width() >= 3) {
SkCodec::Options options;
int width = info.width();
int height = info.height();
SkIRect subset = SkIRect::MakeXYWH(2 * (width / 3), 0, width / 3, height);
options.fSubset = ⊂
const SkCodec::Result partialStartResult = codec->startScanlineDecode(info, &options,
nullptr, nullptr);
REPORTER_ASSERT(r, partialStartResult == SkCodec::kSuccess);
for (int y = 0; y < height; y++) {
const int lines = codec->getScanlines(bm.getAddr(0, y), 1, 0);
if (!isIncomplete) {
REPORTER_ASSERT(r, 1 == lines);
}
}
}
} else {
REPORTER_ASSERT(r, startResult == SkCodec::kUnimplemented);
}
// The rest of this function tests decoding subsets, and will decode an arbitrary number of
//.........这里部分代码省略.........
示例13: srcLock
DEF_TEST(BitmapCopy, reporter) {
static const bool isExtracted[] = {
false, true
};
for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) {
SkBitmap srcOpaque, srcPremul;
setup_src_bitmaps(&srcOpaque, &srcPremul, gPairs[i].fColorType);
for (size_t j = 0; j < SK_ARRAY_COUNT(gPairs); j++) {
SkBitmap dst;
bool success = srcPremul.copyTo(&dst, gPairs[j].fColorType);
bool expected = gPairs[i].fValid[j] != '0';
if (success != expected) {
ERRORF(reporter, "SkBitmap::copyTo from %s to %s. expected %s "
"returned %s", gColorTypeName[i], gColorTypeName[j],
boolStr(expected), boolStr(success));
}
bool canSucceed = srcPremul.canCopyTo(gPairs[j].fColorType);
if (success != canSucceed) {
ERRORF(reporter, "SkBitmap::copyTo from %s to %s. returned %s "
"canCopyTo %s", gColorTypeName[i], gColorTypeName[j],
boolStr(success), boolStr(canSucceed));
}
if (success) {
REPORTER_ASSERT(reporter, srcPremul.width() == dst.width());
REPORTER_ASSERT(reporter, srcPremul.height() == dst.height());
REPORTER_ASSERT(reporter, dst.colorType() == gPairs[j].fColorType);
test_isOpaque(reporter, srcOpaque, srcPremul, dst.colorType());
if (srcPremul.colorType() == dst.colorType()) {
SkAutoLockPixels srcLock(srcPremul);
SkAutoLockPixels dstLock(dst);
REPORTER_ASSERT(reporter, srcPremul.readyToDraw());
REPORTER_ASSERT(reporter, dst.readyToDraw());
const char* srcP = (const char*)srcPremul.getAddr(0, 0);
const char* dstP = (const char*)dst.getAddr(0, 0);
REPORTER_ASSERT(reporter, srcP != dstP);
REPORTER_ASSERT(reporter, !memcmp(srcP, dstP,
srcPremul.getSize()));
REPORTER_ASSERT(reporter, srcPremul.getGenerationID() == dst.getGenerationID());
} else {
REPORTER_ASSERT(reporter, srcPremul.getGenerationID() != dst.getGenerationID());
}
} else {
// dst should be unchanged from its initial state
REPORTER_ASSERT(reporter, dst.colorType() == kUnknown_SkColorType);
REPORTER_ASSERT(reporter, dst.width() == 0);
REPORTER_ASSERT(reporter, dst.height() == 0);
}
} // for (size_t j = ...
// Tests for getSafeSize(), getSafeSize64(), copyPixelsTo(),
// copyPixelsFrom().
//
for (size_t copyCase = 0; copyCase < SK_ARRAY_COUNT(isExtracted);
++copyCase) {
// Test copying to/from external buffer.
// Note: the tests below have hard-coded values ---
// Please take care if modifying.
// Tests for getSafeSize64().
// Test with a very large configuration without pixel buffer
// attached.
SkBitmap tstSafeSize;
tstSafeSize.setInfo(SkImageInfo::Make(100000000U, 100000000U,
gPairs[i].fColorType, kPremul_SkAlphaType));
int64_t safeSize = tstSafeSize.computeSafeSize64();
if (safeSize < 0) {
ERRORF(reporter, "getSafeSize64() negative: %s",
gColorTypeName[tstSafeSize.colorType()]);
}
bool sizeFail = false;
// Compare against hand-computed values.
switch (gPairs[i].fColorType) {
case kUnknown_SkColorType:
break;
case kAlpha_8_SkColorType:
case kIndex_8_SkColorType:
if (safeSize != 0x2386F26FC10000LL) {
sizeFail = true;
}
break;
case kRGB_565_SkColorType:
case kARGB_4444_SkColorType:
if (safeSize != 0x470DE4DF820000LL) {
sizeFail = true;
}
break;
case kN32_SkColorType:
if (safeSize != 0x8E1BC9BF040000LL) {
sizeFail = true;
}
break;
//.........这里部分代码省略.........
示例14: onDraw
void SubsetZoomBench::onDraw(const int n, SkCanvas* canvas) {
// When the color type is kIndex8, we will need to store the color table. If it is
// used, it will be initialized by the codec.
int colorCount;
SkPMColor colors[256];
if (fUseCodec) {
for (int count = 0; count < n; count++) {
SkAutoTDelete<SkScanlineDecoder> scanlineDecoder(
SkScanlineDecoder::NewFromStream(fStream->duplicate()));
const SkImageInfo info = scanlineDecoder->getInfo().makeColorType(fColorType);
SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes()]);
scanlineDecoder->start(info, nullptr, colors, &colorCount);
const int centerX = info.width() / 2;
const int centerY = info.height() / 2;
int w = fSubsetWidth;
int h = fSubsetHeight;
do {
const int subsetStartX = SkTMax(0, centerX - w / 2);
const int subsetStartY = SkTMax(0, centerY - h / 2);
const int subsetWidth = SkTMin(w, info.width() - subsetStartX);
const int subsetHeight = SkTMin(h, info.height() - subsetStartY);
// Note that if we subsetted and scaled in a single step, we could use the
// same bitmap - as is often done in actual use cases.
SkBitmap bitmap;
SkImageInfo subsetInfo = info.makeWH(subsetWidth, subsetHeight);
alloc_pixels(&bitmap, subsetInfo, colors, colorCount);
uint32_t bpp = info.bytesPerPixel();
scanlineDecoder->skipScanlines(subsetStartY);
for (int y = 0; y < subsetHeight; y++) {
scanlineDecoder->getScanlines(row.get(), 1, 0);
memcpy(bitmap.getAddr(0, y), row.get() + subsetStartX * bpp,
subsetWidth * bpp);
}
w <<= 1;
h <<= 1;
} while (w < 2 * info.width() || h < 2 * info.height());
}
} else {
for (int count = 0; count < n; count++) {
int width, height;
SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStream));
decoder->buildTileIndex(fStream->duplicate(), &width, &height);
const int centerX = width / 2;
const int centerY = height / 2;
int w = fSubsetWidth;
int h = fSubsetHeight;
do {
const int subsetStartX = SkTMax(0, centerX - w / 2);
const int subsetStartY = SkTMax(0, centerY - h / 2);
const int subsetWidth = SkTMin(w, width - subsetStartX);
const int subsetHeight = SkTMin(h, height - subsetStartY);
SkBitmap bitmap;
SkIRect rect = SkIRect::MakeXYWH(subsetStartX, subsetStartY, subsetWidth,
subsetHeight);
decoder->decodeSubset(&bitmap, rect, fColorType);
w <<= 1;
h <<= 1;
} while (w < 2 * width || h < 2 * height);
}
}
}
示例15: MarkGMGood
const SkColor color = 0xbf400000;
auto grade = [&](int x, int y){
SkBitmap bm;
bm.allocPixels(SkImageInfo::Make(1,1,
kBGRA_8888_SkColorType,
kUnpremul_SkAlphaType,
SkColorSpace::MakeSRGB()));
if (!canvas->readPixels(bm, x,y)) {
// Picture-backed canvases, that sort of thing. Just assume they're good.
MarkGMGood(canvas, 140,40);
return;
}
SkColor pixel;
memcpy(&pixel, bm.getAddr(0,0), sizeof(pixel));
auto close = [](int x, int y) {
return x-y < 2
&& y-x < 2;
};
if (close(SkColorGetR(pixel), SkColorGetR(color)) &&
close(SkColorGetG(pixel), SkColorGetG(color)) &&
close(SkColorGetB(pixel), SkColorGetB(color)) &&
close(SkColorGetA(pixel), SkColorGetA(color))) {
MarkGMGood(canvas, 140,40);
} else {
MarkGMBad(canvas, 140,40);
}