本文整理汇总了C++中SkData类的典型用法代码示例。如果您正苦于以下问题:C++ SkData类的具体用法?C++ SkData怎么用?C++ SkData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SkData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: flatten
static bool SK_WARN_UNUSED_RESULT flatten(const SkImage& image, Json::Value* target,
bool sendBinaries) {
if (sendBinaries) {
SkData* encoded = image.encode(SkImageEncoder::kPNG_Type, 100);
if (encoded == nullptr) {
// PNG encode doesn't necessarily support all color formats, convert to a different
// format
size_t rowBytes = 4 * image.width();
void* buffer = sk_malloc_throw(rowBytes * image.height());
SkImageInfo dstInfo = SkImageInfo::Make(image.width(), image.height(),
kN32_SkColorType, kPremul_SkAlphaType);
if (!image.readPixels(dstInfo, buffer, rowBytes, 0, 0)) {
SkDebugf("readPixels failed\n");
return false;
}
SkImage* converted = SkImage::NewRasterCopy(dstInfo, buffer, rowBytes);
encoded = converted->encode(SkImageEncoder::kPNG_Type, 100);
if (encoded == nullptr) {
SkDebugf("image encode failed\n");
return false;
}
free(converted);
free(buffer);
}
Json::Value bytes;
encode_data(encoded->data(), encoded->size(), &bytes);
(*target)[SKJSONCANVAS_ATTRIBUTE_BYTES] = bytes;
encoded->unref();
}
else {
SkString description = SkStringPrintf("%dx%d pixel image", image.width(), image.height());
(*target)[SKJSONCANVAS_ATTRIBUTE_DESCRIPTION] = Json::Value(description.c_str());
}
return true;
}
示例2: TestDataRef
void TestDataRef(skiatest::Reporter* reporter) {
const char* str = "We the people, in order to form a more perfect union.";
const int N = 10;
SkData* r0 = SkData::NewEmpty();
SkData* r1 = SkData::NewWithCopy(str, strlen(str));
SkData* r2 = SkData::NewWithProc(new int[N], N*sizeof(int),
delete_int_proc, gGlobal);
SkData* r3 = SkData::NewSubset(r1, 7, 6);
SkAutoUnref aur0(r0);
SkAutoUnref aur1(r1);
SkAutoUnref aur2(r2);
SkAutoUnref aur3(r3);
assert_len(reporter, r0, 0);
assert_len(reporter, r1, strlen(str));
assert_len(reporter, r2, N * sizeof(int));
assert_len(reporter, r3, 6);
assert_data(reporter, r1, str, strlen(str));
assert_data(reporter, r3, "people", 6);
SkData* tmp = SkData::NewSubset(r1, strlen(str), 10);
assert_len(reporter, tmp, 0);
tmp->unref();
tmp = SkData::NewSubset(r1, 0, 0);
assert_len(reporter, tmp, 0);
tmp->unref();
}
示例3: DEF_TEST
DEF_TEST(Data, reporter) {
const char* str = "We the people, in order to form a more perfect union.";
const int N = 10;
SkAutoTUnref<SkData> r0(SkData::NewEmpty());
SkAutoTUnref<SkData> r1(SkData::NewWithCopy(str, strlen(str)));
SkAutoTUnref<SkData> r2(SkData::NewWithProc(new int[N], N*sizeof(int),
delete_int_proc, gGlobal));
SkAutoTUnref<SkData> r3(SkData::NewSubset(r1, 7, 6));
assert_len(reporter, r0, 0);
assert_len(reporter, r1, strlen(str));
assert_len(reporter, r2, N * sizeof(int));
assert_len(reporter, r3, 6);
assert_data(reporter, r1, str, strlen(str));
assert_data(reporter, r3, "people", 6);
SkData* tmp = SkData::NewSubset(r1, strlen(str), 10);
assert_len(reporter, tmp, 0);
tmp->unref();
tmp = SkData::NewSubset(r1, 0, 0);
assert_len(reporter, tmp, 0);
tmp->unref();
test_cstring(reporter);
test_files(reporter);
}
示例4: tool_main
int tool_main(int argc, char** argv) {
SkAutoGraphics ag;
SkLua L;
for (int i = 1; i < argc; ++i) {
SkData* data = nullptr;
const void* ptr;
size_t len;
if (!strcmp(argv[i], "--lua") && i < argc-1) {
ptr = argv[i + 1];
len = strlen(argv[i + 1]);
i += 1;
} else {
data = read_into_data(argv[i]);
ptr = data->data();
len = data->size();
}
if (!L.runCode(ptr, len)) {
SkDebugf("failed to load %s\n", argv[i]);
exit(-1);
}
SkSafeUnref(data);
}
return 0;
}
示例5: TestWStream
static void TestWStream(skiatest::Reporter* reporter) {
SkDynamicMemoryWStream ds;
const char s[] = "abcdefghijklmnopqrstuvwxyz";
int i;
for (i = 0; i < 100; i++) {
REPORTER_ASSERT(reporter, ds.write(s, 26));
}
REPORTER_ASSERT(reporter, ds.getOffset() == 100 * 26);
char* dst = new char[100 * 26 + 1];
dst[100*26] = '*';
ds.copyTo(dst);
REPORTER_ASSERT(reporter, dst[100*26] == '*');
// char* p = dst;
for (i = 0; i < 100; i++) {
REPORTER_ASSERT(reporter, memcmp(&dst[i * 26], s, 26) == 0);
}
{
SkData* data = ds.copyToData();
REPORTER_ASSERT(reporter, 100 * 26 == data->size());
REPORTER_ASSERT(reporter, memcmp(dst, data->data(), data->size()) == 0);
data->unref();
}
delete[] dst;
}
示例6: make_3Dlut
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;
}
示例7: decodeThreadWithRefEncodedMain
static void decodeThreadWithRefEncodedMain(ImageFrameGenerator* generator)
{
// Image must be complete - refEncodedData otherwise returns null.
char buffer[100 * 100 * 4];
SkData* data = generator->refEncodedData();
generator->decodeAndScale(0, imageInfo(), buffer, 100 * 4);
data->unref();
}
示例8: test_dataset_subset
// asserts that inner is a subset of outer
static void test_dataset_subset(skiatest::Reporter* reporter,
const SkDataSet& outer, const SkDataSet& inner) {
SkDataSet::Iter iter(inner);
for (; !iter.done(); iter.next()) {
SkData* outerData = outer.find(iter.key());
REPORTER_ASSERT(reporter, outerData);
REPORTER_ASSERT(reporter, outerData->equals(iter.value()));
}
}
示例9: 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);
}
示例10: new
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;
}
示例11: DEF_TEST
DEF_TEST(ImageDataRef, reporter) {
SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
size_t rowBytes = info.minRowBytes();
size_t size = info.getSafeSize(rowBytes);
SkData* data = SkData::NewUninitialized(size);
REPORTER_ASSERT(reporter, data->unique());
SkImage* image = SkImage::NewRasterData(info, data, rowBytes);
REPORTER_ASSERT(reporter, !data->unique());
image->unref();
REPORTER_ASSERT(reporter, data->unique());
data->unref();
}
示例12: new_uninitialized_refcnt_ptrs
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;
}
示例13: send_picture
static void send_picture(int socket, const PictureHeader& header, const SkData& skp) {
// Vectored IO lets us send header and skp contiguously without first
// copying them to a contiguous buffer.
struct nn_iovec iov[] = {
create_iov(&header, sizeof(header)),
create_iov(skp.data(), skp.size()),
};
struct nn_msghdr msg;
sk_bzero(&msg, sizeof(msg));
msg.msg_iov = iov;
msg.msg_iovlen = SK_ARRAY_COUNT(iov);
nn_sendmsg(socket, &msg, 0/*flags*/);
}
示例14: 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;
}
示例15: ensureLua
lua_State* ensureLua() {
if (NULL == fLua) {
fLua = SkNEW(SkLua);
SkString str = GetResourcePath(LUA_FILENAME);
SkData* data = SkData::NewFromFileName(str.c_str());
if (data) {
fLua->runCode(data->data(), data->size());
data->unref();
this->setImageFilename(fLua->get());
} else {
fLua->runCode(gMissingCode);
}
}
return fLua->get();
}