本文整理汇总了C++中SkBitmap::getSize方法的典型用法代码示例。如果您正苦于以下问题:C++ SkBitmap::getSize方法的具体用法?C++ SkBitmap::getSize怎么用?C++ SkBitmap::getSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkBitmap
的用法示例。
在下文中一共展示了SkBitmap::getSize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Run
static void Run(const Task& task) {
SkString name = task.src->name();
SkString log;
if (!FLAGS_dryRun) {
SkBitmap bitmap;
SkDynamicMemoryWStream stream;
start(task.sink.tag.c_str(), task.src.tag.c_str(),
task.src.options.c_str(), name.c_str());
Error err = task.sink->draw(*task.src, &bitmap, &stream, &log);
if (!log.isEmpty()) {
info("%s %s %s %s:\n%s\n", task.sink.tag.c_str()
, task.src.tag.c_str()
, task.src.options.c_str()
, name.c_str()
, log.c_str());
}
if (!err.isEmpty()) {
if (err.isFatal()) {
fail(SkStringPrintf("%s %s %s %s: %s",
task.sink.tag.c_str(),
task.src.tag.c_str(),
task.src.options.c_str(),
name.c_str(),
err.c_str()));
} else {
done(task.sink.tag.c_str(), task.src.tag.c_str(),
task.src.options.c_str(), name.c_str());
return;
}
}
// We're likely switching threads here, so we must capture by value, [=] or [foo,bar].
SkStreamAsset* data = stream.detachAsStream();
gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{
SkAutoTDelete<SkStreamAsset> ownedData(data);
// Why doesn't the copy constructor do this when we have pre-locked pixels?
bitmap.lockPixels();
SkString md5;
if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
SkMD5 hash;
if (data->getLength()) {
hash.writeStream(data, data->getLength());
data->rewind();
} else {
// If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android).
// This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org.
// (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.)
// We might consider promoting 565 to RGBA too.
if (bitmap.colorType() == kBGRA_8888_SkColorType) {
SkBitmap swizzle;
SkAssertResult(bitmap.copyTo(&swizzle, kRGBA_8888_SkColorType));
hash.write(swizzle.getPixels(), swizzle.getSize());
} else {
hash.write(bitmap.getPixels(), bitmap.getSize());
}
}
SkMD5::Digest digest;
hash.finish(digest);
for (int i = 0; i < 16; i++) {
md5.appendf("%02x", digest.data[i]);
}
}
if (!FLAGS_readPath.isEmpty() &&
!gGold.contains(Gold(task.sink.tag, task.src.tag,
task.src.options, name, md5))) {
fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
md5.c_str(),
task.sink.tag.c_str(),
task.src.tag.c_str(),
task.src.options.c_str(),
name.c_str(),
FLAGS_readPath[0]));
}
if (!FLAGS_writePath.isEmpty()) {
const char* ext = task.sink->fileExtension();
if (data->getLength()) {
WriteToDisk(task, md5, ext, data, data->getLength(), nullptr);
SkASSERT(bitmap.drawsNothing());
} else if (!bitmap.drawsNothing()) {
WriteToDisk(task, md5, ext, nullptr, 0, &bitmap);
}
}
});
}
done(task.sink.tag.c_str(), task.src.tag.c_str(), task.src.options.c_str(), name.c_str());
}
示例2: runSimpleRendering
void runSimpleRendering( string renderingFileName, string resourceDir, RenderingInfo* info) {
SkColor defaultMapColor = SK_ColorLTGRAY;
if (info->width > 10000 || info->height > 10000) {
osmand_log_print(LOG_ERROR, "We don't rendering images more than 10000x10000 ");
return;
}
osmand_log_print(LOG_INFO, "Rendering info bounds(%d, %d, %d, %d) zoom(%d), width/height(%d/%d) tilewidth/tileheight(%d/%d) fileName(%s)",
info->left, info->top, info->right, info->bottom, info->zoom, info->width, info->height, info->tileWX, info->tileHY, info->tileFileName.c_str());
RenderingRulesStorage* st = new RenderingRulesStorage(renderingFileName.c_str());
st->parseRulesFromXmlInputStream(renderingFileName.c_str(), NULL);
RenderingRuleSearchRequest* searchRequest = new RenderingRuleSearchRequest(st);
ResultPublisher* publisher = new ResultPublisher();
SearchQuery q(floor(info->left), floor(info->right), ceil(info->top), ceil(info->bottom), searchRequest, publisher);
q.zoom = info->zoom;
ResultPublisher* res = searchObjectsForRendering(&q, true, "Nothing found");
osmand_log_print(LOG_INFO, "Found %d objects", res->result.size());
SkBitmap* bitmap = new SkBitmap();
bitmap->setConfig(SkBitmap::kRGB_565_Config, info->width, info->height);
size_t bitmapDataSize = bitmap->getSize();
void* bitmapData = malloc(bitmapDataSize);
bitmap->setPixels(bitmapData);
osmand_log_print(LOG_INFO, "Initializing rendering style and rendering context");
ElapsedTimer initObjects;
initObjects.start();
RenderingContext rc;
rc.setDefaultIconsDir(resourceDir);
searchRequest->clearState();
searchRequest->setIntFilter(st->PROPS.R_MINZOOM, info->zoom);
if (searchRequest->searchRenderingAttribute(A_DEFAULT_COLOR)) {
defaultMapColor = searchRequest->getIntPropertyValue(searchRequest->props()->R_ATTR_COLOR_VALUE);
}
searchRequest->clearState();
searchRequest->setIntFilter(st->PROPS.R_MINZOOM, info->zoom);
if (searchRequest->searchRenderingAttribute(A_SHADOW_RENDERING)) {
rc.setShadowRenderingMode(searchRequest->getIntPropertyValue(searchRequest->props()->R_ATTR_INT_VALUE));
//rc.setShadowRenderingColor(searchRequest->getIntPropertyValue(searchRequest->props()->R_SHADOW_COLOR));
}
rc.setLocation(
((double)info->left)/getPowZoom(31-info->zoom),
((double)info->top)/getPowZoom(31-info->zoom)
);
rc.setDimension(info->width, info->height);
rc.setZoom(info->zoom);
rc.setRotate(0);
rc.setDensityScale(1);
osmand_log_print(LOG_INFO, "Rendering image");
initObjects.pause();
SkCanvas* canvas = new SkCanvas(*bitmap);
canvas->drawColor(defaultMapColor);
doRendering(res->result, canvas, searchRequest, &rc);
osmand_log_print(LOG_INFO, "End Rendering image");
osmand_log_print(LOG_INFO, "Native ok (init %d, rendering %d) ", initObjects.getElapsedTime(),
rc.nativeOperations.getElapsedTime());
SkImageEncoder* enc = SkImageEncoder::Create(SkImageEncoder::kPNG_Type);
if (enc != NULL && !enc->encodeFile(info->tileFileName.c_str(), *bitmap, 100)) {
osmand_log_print(LOG_ERROR, "FAIL to save tile to %s", info->tileFileName.c_str());
} else {
osmand_log_print(LOG_INFO, "Tile successfully saved to %s", info->tileFileName.c_str());
}
delete enc;
delete publisher;
delete searchRequest;
delete st;
delete canvas;
delete bitmap;
free(bitmapData);
return;
}
示例3: Run
static void Run(Task* task) {
SkString name = task->src->name();
// We'll skip drawing this Src/Sink pair if:
// - the Src vetoes the Sink;
// - this Src / Sink combination is on the blacklist;
// - it's a dry run.
SkString note(task->src->veto(task->sink->flags()) ? " (veto)" : "");
SkString whyBlacklisted = is_blacklisted(task->sink.tag, task->src.tag,
task->src.options, name.c_str());
if (!whyBlacklisted.isEmpty()) {
note.appendf(" (--blacklist %s)", whyBlacklisted.c_str());
}
SkString log;
WallTimer timer;
timer.start();
if (!FLAGS_dryRun && note.isEmpty()) {
SkBitmap bitmap;
SkDynamicMemoryWStream stream;
if (FLAGS_pre_log) {
SkDebugf("\nRunning %s->%s", name.c_str(), task->sink.tag);
}
start(task->sink.tag, task->src.tag, task->src.options, name.c_str());
Error err = task->sink->draw(*task->src, &bitmap, &stream, &log);
if (!err.isEmpty()) {
timer.end();
if (err.isFatal()) {
fail(SkStringPrintf("%s %s %s %s: %s",
task->sink.tag,
task->src.tag,
task->src.options,
name.c_str(),
err.c_str()));
} else {
note.appendf(" (skipped: %s)", err.c_str());
}
done(timer.fWall, task->sink.tag, task->src.tag, task->src.options,
name, note, log);
return;
}
SkAutoTDelete<SkStreamAsset> data(stream.detachAsStream());
SkString md5;
if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
SkMD5 hash;
if (data->getLength()) {
hash.writeStream(data, data->getLength());
data->rewind();
} else {
// If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android).
// This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org.
// (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.)
// We might consider promoting 565 to RGBA too.
if (bitmap.colorType() == kBGRA_8888_SkColorType) {
SkBitmap swizzle;
SkAssertResult(bitmap.copyTo(&swizzle, kRGBA_8888_SkColorType));
hash.write(swizzle.getPixels(), swizzle.getSize());
} else {
hash.write(bitmap.getPixels(), bitmap.getSize());
}
}
SkMD5::Digest digest;
hash.finish(digest);
for (int i = 0; i < 16; i++) {
md5.appendf("%02x", digest.data[i]);
}
}
if (!FLAGS_readPath.isEmpty() &&
!gGold.contains(Gold(task->sink.tag, task->src.tag,
task->src.options, name, md5))) {
fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
md5.c_str(),
task->sink.tag,
task->src.tag,
task->src.options,
name.c_str(),
FLAGS_readPath[0]));
}
if (!FLAGS_writePath.isEmpty()) {
const char* ext = task->sink->fileExtension();
if (data->getLength()) {
WriteToDisk(*task, md5, ext, data, data->getLength(), NULL);
SkASSERT(bitmap.drawsNothing());
} else if (!bitmap.drawsNothing()) {
WriteToDisk(*task, md5, ext, NULL, 0, &bitmap);
}
}
}
timer.end();
done(timer.fWall, task->sink.tag, task->src.tag, task->src.options, name, note, log);
}
示例4: Run
static void Run(Task* task) {
SkString name = task->src->name();
SkString note;
SkString whyBlacklisted = is_blacklisted(task->sink.tag, task->src.tag,
task->src.options, name.c_str());
if (!whyBlacklisted.isEmpty()) {
note.appendf(" (--blacklist %s)", whyBlacklisted.c_str());
}
SkString log;
WallTimer timer;
timer.start();
if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) {
SkBitmap bitmap;
SkDynamicMemoryWStream stream;
start(task->sink.tag, task->src.tag, task->src.options, name.c_str());
Error err = task->sink->draw(*task->src, &bitmap, &stream, &log);
if (!err.isEmpty()) {
timer.end();
if (err.isFatal()) {
fail(SkStringPrintf("%s %s %s %s: %s",
task->sink.tag,
task->src.tag,
task->src.options,
name.c_str(),
err.c_str()));
} else {
note.appendf(" (skipped: %s)", err.c_str());
}
done(timer.fWall, task->sink.tag, task->src.tag, task->src.options,
name, note, log);
return;
}
SkAutoTDelete<SkStreamAsset> data(stream.detachAsStream());
SkString md5;
if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
SkMD5 hash;
if (data->getLength()) {
hash.writeStream(data, data->getLength());
data->rewind();
} else {
hash.write(bitmap.getPixels(), bitmap.getSize());
}
SkMD5::Digest digest;
hash.finish(digest);
for (int i = 0; i < 16; i++) {
md5.appendf("%02x", digest.data[i]);
}
}
if (!FLAGS_readPath.isEmpty() &&
!gGold.contains(Gold(task->sink.tag, task->src.tag,
task->src.options, name, md5))) {
fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
md5.c_str(),
task->sink.tag,
task->src.tag,
task->src.options,
name.c_str(),
FLAGS_readPath[0]));
}
if (!FLAGS_writePath.isEmpty()) {
const char* ext = task->sink->fileExtension();
if (data->getLength()) {
WriteToDisk(*task, md5, ext, data, data->getLength(), NULL);
SkASSERT(bitmap.drawsNothing());
} else if (!bitmap.drawsNothing()) {
WriteToDisk(*task, md5, ext, NULL, 0, &bitmap);
}
}
}
timer.end();
done(timer.fWall, task->sink.tag, task->src.tag, task->src.options, name, note, log);
}
示例5: Bitmap_createFromParcel
static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) {
if (parcel == NULL) {
SkDebugf("-------- unparcel parcel is NULL\n");
return NULL;
}
android::Parcel* p = android::parcelForJavaObject(env, parcel);
const bool isMutable = p->readInt32() != 0;
const SkColorType colorType = (SkColorType)p->readInt32();
const SkAlphaType alphaType = (SkAlphaType)p->readInt32();
const int width = p->readInt32();
const int height = p->readInt32();
const int rowBytes = p->readInt32();
const int density = p->readInt32();
if (kN32_SkColorType != colorType &&
kRGB_565_SkColorType != colorType &&
kARGB_4444_SkColorType != colorType &&
kIndex_8_SkColorType != colorType &&
kAlpha_8_SkColorType != colorType) {
SkDebugf("Bitmap_createFromParcel unknown colortype: %d\n", colorType);
return NULL;
}
SkBitmap* bitmap = new SkBitmap;
bitmap->setInfo(SkImageInfo::Make(width, height, colorType, alphaType), rowBytes);
SkColorTable* ctable = NULL;
if (colorType == kIndex_8_SkColorType) {
int count = p->readInt32();
if (count > 0) {
size_t size = count * sizeof(SkPMColor);
const SkPMColor* src = (const SkPMColor*)p->readInplace(size);
ctable = new SkColorTable(src, count);
}
}
jbyteArray buffer = GraphicsJNI::allocateJavaPixelRef(env, bitmap, ctable);
if (NULL == buffer) {
SkSafeUnref(ctable);
delete bitmap;
return NULL;
}
SkSafeUnref(ctable);
size_t size = bitmap->getSize();
android::Parcel::ReadableBlob blob;
android::status_t status = p->readBlob(size, &blob);
if (status) {
doThrowRE(env, "Could not read bitmap from parcel blob.");
delete bitmap;
return NULL;
}
bitmap->lockPixels();
memcpy(bitmap->getPixels(), blob.data(), size);
bitmap->unlockPixels();
blob.release();
return GraphicsJNI::createBitmap(env, bitmap, buffer, getPremulBitmapCreateFlags(isMutable),
NULL, NULL, density);
}
示例6: should_use_ashmem
static bool should_use_ashmem(const SkBitmap& bm) {
return bm.getSize() >= MIN_ASHMEM_ALLOC_SIZE;
}