本文整理汇总了C++中SkData::writable_data方法的典型用法代码示例。如果您正苦于以下问题:C++ SkData::writable_data方法的具体用法?C++ SkData::writable_data怎么用?C++ SkData::writable_data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkData
的用法示例。
在下文中一共展示了SkData::writable_data方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: R
static SkData* make_3Dlut(int* cubeDimension, bool invR, bool invG, bool invB) {
int size = 4 << R(5);
SkData* data = SkData::NewUninitialized(sizeof(SkColor) * size * size * size);
SkColor* pixels = (SkColor*)(data->writable_data());
SkAutoTMalloc<uint8_t> lutMemory(size);
SkAutoTMalloc<uint8_t> invLutMemory(size);
uint8_t* lut = lutMemory.get();
uint8_t* invLut = invLutMemory.get();
const int maxIndex = size - 1;
for (int i = 0; i < size; i++) {
lut[i] = (i * 255) / maxIndex;
invLut[i] = ((maxIndex - i) * 255) / maxIndex;
}
for (int r = 0; r < size; ++r) {
for (int g = 0; g < size; ++g) {
for (int b = 0; b < size; ++b) {
pixels[(size * ((size * b) + g)) + r] = SkColorSetARGB(0xFF,
invR ? invLut[r] : lut[r],
invG ? invLut[g] : lut[g],
invB ? invLut[b] : lut[b]);
}
}
}
if (cubeDimension) {
*cubeDimension = size;
}
return data;
}
示例2: TypefaceStyle_test
static void TypefaceStyle_test(skiatest::Reporter* reporter,
uint16_t weight, uint16_t width, SkData* data)
{
sk_sp<SkData> dataCopy;
SkData* dataToUse = data;
if (!dataToUse->unique()) {
dataCopy = SkData::MakeWithCopy(data->data(), data->size());
dataToUse = dataCopy.get();
}
SkSFNTHeader* sfntHeader = static_cast<SkSFNTHeader*>(dataToUse->writable_data());
SkSFNTHeader::TableDirectoryEntry* tableEntry =
SkTAfter<SkSFNTHeader::TableDirectoryEntry>(sfntHeader);
SkSFNTHeader::TableDirectoryEntry* os2TableEntry = nullptr;
int numTables = SkEndian_SwapBE16(sfntHeader->numTables);
for (int tableEntryIndex = 0; tableEntryIndex < numTables; ++tableEntryIndex) {
if (SkOTTableOS2::TAG == tableEntry[tableEntryIndex].tag) {
os2TableEntry = tableEntry + tableEntryIndex;
break;
}
}
SkASSERT_RELEASE(os2TableEntry);
size_t os2TableOffset = SkEndian_SwapBE32(os2TableEntry->offset);
SkOTTableOS2_V0* os2Table = SkTAddOffset<SkOTTableOS2_V0>(sfntHeader, os2TableOffset);
os2Table->usWeightClass.value = SkEndian_SwapBE16(weight);
using WidthType = SkOTTableOS2_V0::WidthClass::Value;
os2Table->usWidthClass.value = static_cast<WidthType>(SkEndian_SwapBE16(width));
sk_sp<SkTypeface> newTypeface(SkTypeface::MakeFromStream(new SkMemoryStream(dataToUse)));
SkASSERT_RELEASE(newTypeface);
SkFontStyle newStyle = newTypeface->fontStyle();
//printf("%d, %f\n", weight, (newStyle.weight() - (float)0x7FFF) / (float)0x7FFF);
//printf("%d, %f\n", width , (newStyle.width() - (float)0x7F) / (float)0x7F);
//printf("%d, %d\n", weight, newStyle.weight());
//printf("%d, %d\n", width , newStyle.width());
// Some back-ends (CG, GDI, DW) support OS/2 version A which uses 0 - 10 (but all differently).
REPORTER_ASSERT(reporter,
newStyle.weight() == weight ||
(weight <= 10 && newStyle.weight() == 100 * weight) ||
(weight == 4 && newStyle.weight() == 350) || // GDI weirdness
(weight == 5 && newStyle.weight() == 400) || // GDI weirdness
(weight == 0 && newStyle.weight() == 1) || // DW weirdness
(weight == 1000 && newStyle.weight() == 999) // DW weirdness
);
// Some back-ends (GDI) don't support width, ensure these always report 'medium'.
REPORTER_ASSERT(reporter,
newStyle.width() == width ||
newStyle.width() == 5);
}
示例3: PrivateNewWithCopy
SkData* SkData::PrivateNewWithCopy(const void* srcOrNull, size_t length) {
if (0 == length) {
return SkData::NewEmpty();
}
char* storage = (char*)sk_malloc_throw(sizeof(SkData) + length);
SkData* data = new (storage) SkData(length);
if (srcOrNull) {
memcpy(data->writable_data(), srcOrNull, length);
}
return data;
}
示例4: newDrawableSnapshot
SkData* SkRecorder::newDrawableSnapshot(SkBBHFactory* factory, uint32_t recordFlags) {
const int count = fDrawableList.count();
if (0 == count) {
return NULL;
}
SkData* data = new_uninitialized_refcnt_ptrs(count);
SkPicture** pics = reinterpret_cast<SkPicture**>(data->writable_data());
for (int i = 0; i < count; ++i) {
pics[i] = fDrawableList[i]->newPictureSnapshot(factory, recordFlags);
}
return data;
}
示例5: CompressBitmapToFormat
SkData* CompressBitmapToFormat(const SkPixmap& pixmap, Format format) {
int compressedDataSize = GetCompressedDataSize(format, pixmap.width(), pixmap.height());
if (compressedDataSize < 0) {
return NULL;
}
const uint8_t* src = reinterpret_cast<const uint8_t*>(pixmap.addr());
SkData* dst = SkData::NewUninitialized(compressedDataSize);
if (!CompressBufferToFormat((uint8_t*)dst->writable_data(), src, pixmap.colorType(),
pixmap.width(), pixmap.height(), pixmap.rowBytes(), format)) {
dst->unref();
dst = NULL;
}
return dst;
}
示例6: makeCubeData
void makeCubeData() {
fCubeDimension = 32;
fCubeData = SkData::NewUninitialized(sizeof(SkColor) *
fCubeDimension * fCubeDimension * fCubeDimension);
SkColor* pixels = (SkColor*)(fCubeData->writable_data());
SkAutoTMalloc<uint8_t> lutMemory(fCubeDimension);
uint8_t* lut = lutMemory.get();
const int maxIndex = fCubeDimension - 1;
for (int i = 0; i < fCubeDimension; ++i) {
// Make an invert lut, but the content of
// the lut shouldn't affect performance.
lut[i] = ((maxIndex - i) * 255) / maxIndex;
}
for (int r = 0; r < fCubeDimension; ++r) {
for (int g = 0; g < fCubeDimension; ++g) {
for (int b = 0; b < fCubeDimension; ++b) {
pixels[(fCubeDimension * ((fCubeDimension * b) + g)) + r] =
SkColorSetARGB(0xFF, lut[r], lut[g], lut[b]);
}
}
}
}