本文整理汇总了C++中SkImageInfo::computeMinByteSize方法的典型用法代码示例。如果您正苦于以下问题:C++ SkImageInfo::computeMinByteSize方法的具体用法?C++ SkImageInfo::computeMinByteSize怎么用?C++ SkImageInfo::computeMinByteSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkImageInfo
的用法示例。
在下文中一共展示了SkImageInfo::computeMinByteSize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: draw
void draw(SkCanvas* canvas) {
SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2);
const size_t size = info.computeMinByteSize();
SkAutoTMalloc<SkPMColor> storage(size);
SkPMColor* pixels = storage.get();
SkBitmap bitmap;
bitmap.setInfo(info);
bitmap.setPixels(pixels);
bitmap.eraseColor(SK_ColorRED);
canvas->scale(50, 50);
canvas->rotate(8);
canvas->drawBitmap(bitmap, 2, 0);
}
示例2: draw
void draw(SkCanvas* ) {
SkImageInfo info = SkImageInfo::MakeN32Premul(3, 3);
const size_t size = info.computeMinByteSize();
SkAutoTMalloc<SkPMColor> storage(size);
SkPMColor* pixels = storage.get();
sk_sp<SkSurface> surface(SkSurface::MakeRasterDirect(info, pixels, info.minRowBytes()));
SkCanvas* canvas = surface->getCanvas();
canvas->clear(SK_ColorWHITE);
SkPMColor pmWhite = pixels[0];
SkPaint paint;
canvas->drawPoint(1, 1, paint);
canvas->flush(); // ensure that point was drawn
for (int y = 0; y < info.height(); ++y) {
for (int x = 0; x < info.width(); ++x) {
SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x');
}
SkDebugf("\n");
}
}
示例3: dirEntryBuffer
//.........这里部分代码省略.........
// Save the vital fields
directoryEntries[i].offset = offset;
directoryEntries[i].size = size;
}
// Default Result, if no valid embedded codecs are found.
*result = kInvalidInput;
// It is "customary" that the embedded images will be stored in order of
// increasing offset. However, the specification does not indicate that
// they must be stored in this order, so we will not trust that this is the
// case. Here we sort the embedded images by increasing offset.
struct EntryLessThan {
bool operator() (Entry a, Entry b) const {
return a.offset < b.offset;
}
};
EntryLessThan lessThan;
SkTQSort(directoryEntries, &directoryEntries[numImages - 1], lessThan);
// Now will construct a candidate codec for each of the embedded images
uint32_t bytesRead = kIcoDirectoryBytes + numImages * kIcoDirEntryBytes;
std::unique_ptr<SkTArray<std::unique_ptr<SkCodec>, true>> codecs(
new SkTArray<std::unique_ptr<SkCodec>, true>(numImages));
for (uint32_t i = 0; i < numImages; i++) {
uint32_t offset = directoryEntries[i].offset;
uint32_t size = directoryEntries[i].size;
// Ensure that the offset is valid
if (offset < bytesRead) {
SkCodecPrintf("Warning: invalid ico offset.\n");
continue;
}
// If we cannot skip, assume we have reached the end of the stream and
// stop trying to make codecs
if (stream->skip(offset - bytesRead) != offset - bytesRead) {
SkCodecPrintf("Warning: could not skip to ico offset.\n");
break;
}
bytesRead = offset;
// Create a new stream for the embedded codec
SkAutoFree buffer(sk_malloc_canfail(size));
if (!buffer) {
SkCodecPrintf("Warning: OOM trying to create embedded stream.\n");
break;
}
if (stream->read(buffer.get(), size) != size) {
SkCodecPrintf("Warning: could not create embedded stream.\n");
*result = kIncompleteInput;
break;
}
sk_sp<SkData> data(SkData::MakeFromMalloc(buffer.release(), size));
auto embeddedStream = SkMemoryStream::Make(data);
bytesRead += size;
// Check if the embedded codec is bmp or png and create the codec
std::unique_ptr<SkCodec> codec;
Result dummyResult;
if (SkPngCodec::IsPng((const char*) data->bytes(), data->size())) {
codec = SkPngCodec::MakeFromStream(std::move(embeddedStream), &dummyResult);
} else {
codec = SkBmpCodec::MakeFromIco(std::move(embeddedStream), &dummyResult);
}
// Save a valid codec
if (nullptr != codec) {
codecs->push_back().reset(codec.release());
}
}
// Recognize if there are no valid codecs
if (0 == codecs->count()) {
SkCodecPrintf("Error: could not find any valid embedded ico codecs.\n");
return nullptr;
}
// Use the largest codec as a "suggestion" for image info
size_t maxSize = 0;
int maxIndex = 0;
for (int i = 0; i < codecs->count(); i++) {
SkImageInfo info = codecs->operator[](i)->getInfo();
size_t size = info.computeMinByteSize();
if (size > maxSize) {
maxSize = size;
maxIndex = i;
}
}
auto maxInfo = codecs->operator[](maxIndex)->getEncodedInfo().copy();
*result = kSuccess;
// The original stream is no longer needed, because the embedded codecs own their
// own streams.
return std::unique_ptr<SkCodec>(new SkIcoCodec(std::move(maxInfo), codecs.release()));
}