本文整理汇总了C++中SkBitmap::getColorTable方法的典型用法代码示例。如果您正苦于以下问题:C++ SkBitmap::getColorTable方法的具体用法?C++ SkBitmap::getColorTable怎么用?C++ SkBitmap::getColorTable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkBitmap
的用法示例。
在下文中一共展示了SkBitmap::getColorTable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onPreDraw
virtual void onPreDraw() {
SkBitmap bm;
if (SkBitmap::kIndex8_Config == fConfig) {
bm.setConfig(SkBitmap::kARGB_8888_Config, W, H);
} else {
bm.setConfig(fConfig, W, H);
}
bm.allocPixels();
bm.eraseColor(fIsOpaque ? SK_ColorBLACK : 0);
onDrawIntoBitmap(bm);
if (SkBitmap::kIndex8_Config == fConfig) {
convertToIndex666(bm, &fBitmap);
} else {
fBitmap = bm;
}
if (fBitmap.getColorTable()) {
fBitmap.getColorTable()->setIsOpaque(fIsOpaque);
}
fBitmap.setIsOpaque(fIsOpaque);
fBitmap.setIsVolatile(fIsVolatile);
}
示例2: encoded
DEF_TEST(DiscardablePixelRef_SecondLockColorTableCheck, r) {
SkString resourceDir = GetResourcePath();
SkString path = SkOSPath::Join(resourceDir.c_str(), "randPixels.gif");
if (!sk_exists(path.c_str())) {
return;
}
SkAutoDataUnref encoded(SkData::NewFromFileName(path.c_str()));
SkBitmap bitmap;
if (!SkInstallDiscardablePixelRef(
SkDecodingImageGenerator::Create(
encoded, SkDecodingImageGenerator::Options()), &bitmap)) {
#ifndef SK_BUILD_FOR_WIN
ERRORF(r, "SkInstallDiscardablePixelRef [randPixels.gif] failed.");
#endif
return;
}
if (kIndex_8_SkColorType != bitmap.colorType()) {
return;
}
{
SkAutoLockPixels alp(bitmap);
REPORTER_ASSERT(r, bitmap.getColorTable() && "first pass");
}
{
SkAutoLockPixels alp(bitmap);
REPORTER_ASSERT(r, bitmap.getColorTable() && "second pass");
}
}
示例3: BitmapBench
BitmapBench(void* param, bool isOpaque, SkBitmap::Config c,
bool forceUpdate = false, bool bitmapVolatile = false,
int tx = -1, int ty = -1)
: INHERITED(param), fIsOpaque(isOpaque), fForceUpdate(forceUpdate), fTileX(tx), fTileY(ty) {
const int w = 128;
const int h = 128;
SkBitmap bm;
if (SkBitmap::kIndex8_Config == c) {
bm.setConfig(SkBitmap::kARGB_8888_Config, w, h);
} else {
bm.setConfig(c, w, h);
}
bm.allocPixels();
bm.eraseColor(isOpaque ? SK_ColorBLACK : 0);
drawIntoBitmap(bm);
if (SkBitmap::kIndex8_Config == c) {
convertToIndex666(bm, &fBitmap);
} else {
fBitmap = bm;
}
if (fBitmap.getColorTable()) {
fBitmap.getColorTable()->setIsOpaque(isOpaque);
}
fBitmap.setIsOpaque(isOpaque);
fBitmap.setIsVolatile(bitmapVolatile);
}
示例4: bitmap
DEF_TEST(BitmapCopy_extractSubset, reporter) {
for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) {
SkBitmap srcOpaque, srcPremul;
setup_src_bitmaps(&srcOpaque, &srcPremul, gPairs[i].fColorType);
SkBitmap bitmap(srcOpaque);
SkBitmap subset;
SkIRect r;
// Extract a subset which has the same width as the original. This
// catches a bug where we cloned the genID incorrectly.
r.set(0, 1, W, 3);
bitmap.setIsVolatile(true);
// Relies on old behavior of extractSubset failing if colortype is unknown
if (kUnknown_SkColorType != bitmap.colorType() && bitmap.extractSubset(&subset, r)) {
REPORTER_ASSERT(reporter, subset.width() == W);
REPORTER_ASSERT(reporter, subset.height() == 2);
REPORTER_ASSERT(reporter, subset.alphaType() == bitmap.alphaType());
REPORTER_ASSERT(reporter, subset.isVolatile() == true);
// Test copying an extracted subset.
for (size_t j = 0; j < SK_ARRAY_COUNT(gPairs); j++) {
SkBitmap copy;
bool success = subset.copyTo(©, gPairs[j].fColorType);
if (!success) {
// Skip checking that success matches fValid, which is redundant
// with the code below.
REPORTER_ASSERT(reporter, gPairs[i].fColorType != gPairs[j].fColorType);
continue;
}
// When performing a copy of an extracted subset, the gen id should
// change.
REPORTER_ASSERT(reporter, copy.getGenerationID() != subset.getGenerationID());
REPORTER_ASSERT(reporter, copy.width() == W);
REPORTER_ASSERT(reporter, copy.height() == 2);
if (gPairs[i].fColorType == gPairs[j].fColorType) {
SkAutoLockPixels alp0(subset);
SkAutoLockPixels alp1(copy);
// they should both have, or both not-have, a colortable
bool hasCT = subset.getColorTable() != nullptr;
REPORTER_ASSERT(reporter, (copy.getColorTable() != nullptr) == hasCT);
}
}
}
bitmap = srcPremul;
bitmap.setIsVolatile(false);
if (bitmap.extractSubset(&subset, r)) {
REPORTER_ASSERT(reporter, subset.alphaType() == bitmap.alphaType());
REPORTER_ASSERT(reporter, subset.isVolatile() == false);
}
}
}
示例5: onGetPixels
virtual Result onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
const Options&,
SkPMColor ctableEntries[], int* ctableCount) override {
SkMemoryStream stream(fData->data(), fData->size(), false);
SkAutoTUnref<BareMemoryAllocator> allocator(SkNEW_ARGS(BareMemoryAllocator,
(info, pixels, rowBytes)));
fDecoder->setAllocator(allocator);
fDecoder->setRequireUnpremultipliedColors(kUnpremul_SkAlphaType == info.alphaType());
SkBitmap bm;
const SkImageDecoder::Result result = fDecoder->decode(&stream, &bm, info.colorType(),
SkImageDecoder::kDecodePixels_Mode);
if (SkImageDecoder::kFailure == result) {
return kInvalidInput;
}
SkASSERT(info.colorType() == bm.info().colorType());
if (kIndex_8_SkColorType == info.colorType()) {
SkASSERT(ctableEntries);
SkColorTable* ctable = bm.getColorTable();
if (NULL == ctable) {
return kInvalidConversion;
}
const int count = ctable->count();
memcpy(ctableEntries, ctable->readColors(), count * sizeof(SkPMColor));
*ctableCount = count;
}
if (SkImageDecoder::kPartialSuccess == result) {
return kIncompleteInput;
}
return kSuccess;
}
示例6: build_compressed_data
/* Fill out buffer with the compressed format Ganesh expects from a colortable
based bitmap. [palette (colortable) + indices].
At the moment Ganesh only supports 8bit version. If Ganesh allowed we others
we could detect that the colortable.count is <= 16, and then repack the
indices as nibbles to save RAM, but it would take more time (i.e. a lot
slower than memcpy), so skipping that for now.
Ganesh wants a full 256 palette entry, even though Skia's ctable is only as big
as the colortable.count says it is.
*/
static void build_compressed_data(void* buffer, const SkBitmap& bitmap) {
SkASSERT(SkBitmap::kIndex8_Config == bitmap.config());
SkAutoLockPixels apl(bitmap);
if (!bitmap.readyToDraw()) {
SkASSERT(!"bitmap not ready to draw!");
return;
}
SkColorTable* ctable = bitmap.getColorTable();
char* dst = (char*)buffer;
memcpy(dst, ctable->lockColors(), ctable->count() * sizeof(SkPMColor));
ctable->unlockColors(false);
// always skip a full 256 number of entries, even if we memcpy'd fewer
dst += kGrColorTableSize;
if (bitmap.width() == bitmap.rowBytes()) {
memcpy(dst, bitmap.getPixels(), bitmap.getSize());
} else {
// need to trim off the extra bytes per row
size_t width = bitmap.width();
size_t rowBytes = bitmap.rowBytes();
const char* src = (const char*)bitmap.getPixels();
for (int y = 0; y < bitmap.height(); y++) {
memcpy(dst, src, width);
src += rowBytes;
dst += width;
}
}
}
示例7: init_src
static void init_src(const SkBitmap& bitmap) {
SkAutoLockPixels lock(bitmap);
if (bitmap.getPixels()) {
if (bitmap.getColorTable()) {
sk_bzero(bitmap.getPixels(), bitmap.getSize());
} else {
bitmap.eraseColor(SK_ColorWHITE);
}
}
}
示例8: build_compressed_data
/* Fill out buffer with the compressed format GL expects from a colortable
based bitmap. [palette (colortable) + indices].
At the moment I always take the 8bit version, since that's what my data
is. I could detect that the colortable.count is <= 16, and then repack the
indices as nibbles to save RAM, but it would take more time (i.e. a lot
slower than memcpy), so I'm skipping that for now.
GL wants a full 256 palette entry, even though my ctable is only as big
as the colortable.count says it is. I presume it is OK to leave any
trailing entries uninitialized, since none of my indices should exceed
ctable->count().
*/
static void build_compressed_data(void* buffer, const SkBitmap& bitmap) {
SkASSERT(SkBitmap::kIndex8_Config == bitmap.config());
SkColorTable* ctable = bitmap.getColorTable();
uint8_t* dst = (uint8_t*)buffer;
memcpy(dst, ctable->lockColors(), ctable->count() * sizeof(SkPMColor));
ctable->unlockColors(false);
// always skip a full 256 number of entries, even if we memcpy'd fewer
dst += SK_GL_SIZE_OF_PALETTE;
memcpy(dst, bitmap.getPixels(), bitmap.getSize());
}
示例9: emit_image_xobject
static void emit_image_xobject(SkWStream* stream,
const SkImage* image,
bool alpha,
const sk_sp<SkPDFObject>& smask,
const SkPDFObjNumMap& objNumMap,
const SkPDFSubstituteMap& substitutes) {
SkBitmap bitmap;
image_get_ro_pixels(image, &bitmap); // TODO(halcanary): test
SkAutoLockPixels autoLockPixels(bitmap); // with malformed images.
// Write to a temporary buffer to get the compressed length.
SkDynamicMemoryWStream buffer;
SkDeflateWStream deflateWStream(&buffer);
if (alpha) {
bitmap_alpha_to_a8(bitmap, &deflateWStream);
} else {
bitmap_to_pdf_pixels(bitmap, &deflateWStream);
}
deflateWStream.finalize(); // call before detachAsStream().
std::unique_ptr<SkStreamAsset> asset(buffer.detachAsStream());
SkPDFDict pdfDict("XObject");
pdfDict.insertName("Subtype", "Image");
pdfDict.insertInt("Width", bitmap.width());
pdfDict.insertInt("Height", bitmap.height());
if (alpha) {
pdfDict.insertName("ColorSpace", "DeviceGray");
} else if (bitmap.colorType() == kIndex_8_SkColorType) {
SkASSERT(1 == pdf_color_component_count(bitmap.colorType()));
pdfDict.insertObject("ColorSpace",
make_indexed_color_space(bitmap.getColorTable(),
bitmap.alphaType()));
} else if (1 == pdf_color_component_count(bitmap.colorType())) {
pdfDict.insertName("ColorSpace", "DeviceGray");
} else {
pdfDict.insertName("ColorSpace", "DeviceRGB");
}
if (smask) {
pdfDict.insertObjRef("SMask", smask);
}
pdfDict.insertInt("BitsPerComponent", 8);
pdfDict.insertName("Filter", "FlateDecode");
pdfDict.insertInt("Length", asset->getLength());
pdfDict.emitObject(stream, objNumMap, substitutes);
pdf_stream_begin(stream);
stream->writeStream(asset.get(), asset->getLength());
pdf_stream_end(stream);
}
示例10: valid_for_drawing
static bool valid_for_drawing(const SkBitmap& bm) {
if (0 == bm.width() || 0 == bm.height()) {
return false; // nothing to draw
}
if (NULL == bm.pixelRef()) {
return false; // no pixels to read
}
if (SkBitmap::kIndex8_Config == bm.config()) {
// ugh, I have to lock-pixels to inspect the colortable
SkAutoLockPixels alp(bm);
if (!bm.getColorTable()) {
return false;
}
}
return true;
}
示例11: build_compressed_data
/* Fill out buffer with the compressed format Ganesh expects from a colortable
based bitmap. [palette (colortable) + indices].
At the moment Ganesh only supports 8bit version. If Ganesh allowed we others
we could detect that the colortable.count is <= 16, and then repack the
indices as nibbles to save RAM, but it would take more time (i.e. a lot
slower than memcpy), so skipping that for now.
Ganesh wants a full 256 palette entry, even though Skia's ctable is only as big
as the colortable.count says it is.
*/
static void build_compressed_data(void* buffer, const SkBitmap& bitmap) {
SkASSERT(SkBitmap::kIndex8_Config == bitmap.config());
SkAutoLockPixels alp(bitmap);
if (!bitmap.readyToDraw()) {
SkDEBUGFAIL("bitmap not ready to draw!");
return;
}
SkColorTable* ctable = bitmap.getColorTable();
char* dst = (char*)buffer;
const int count = ctable->count();
SkDstPixelInfo dstPI;
dstPI.fColorType = kRGBA_8888_SkColorType;
dstPI.fAlphaType = kPremul_SkAlphaType;
dstPI.fPixels = buffer;
dstPI.fRowBytes = count * sizeof(SkPMColor);
SkSrcPixelInfo srcPI;
srcPI.fColorType = kPMColor_SkColorType;
srcPI.fAlphaType = kPremul_SkAlphaType;
srcPI.fPixels = ctable->lockColors();
srcPI.fRowBytes = count * sizeof(SkPMColor);
srcPI.convertPixelsTo(&dstPI, count, 1);
ctable->unlockColors();
// always skip a full 256 number of entries, even if we memcpy'd fewer
dst += kGrColorTableSize;
if ((unsigned)bitmap.width() == bitmap.rowBytes()) {
memcpy(dst, bitmap.getPixels(), bitmap.getSize());
} else {
// need to trim off the extra bytes per row
size_t width = bitmap.width();
size_t rowBytes = bitmap.rowBytes();
const char* src = (const char*)bitmap.getPixels();
for (int y = 0; y < bitmap.height(); y++) {
memcpy(dst, src, width);
src += rowBytes;
dst += width;
}
}
}
示例12: ChooseToColorProc
// can return NULL
static ToColorProc ChooseToColorProc(const SkBitmap& src) {
switch (src.colorType()) {
case kN32_SkColorType:
switch (src.alphaType()) {
case kOpaque_SkAlphaType:
return ToColor_S32_Opaque;
case kPremul_SkAlphaType:
return ToColor_S32_Alpha;
case kUnpremul_SkAlphaType:
return ToColor_S32_Raw;
default:
return NULL;
}
case kARGB_4444_SkColorType:
switch (src.alphaType()) {
case kOpaque_SkAlphaType:
return ToColor_S4444_Opaque;
case kPremul_SkAlphaType:
return ToColor_S4444_Alpha;
case kUnpremul_SkAlphaType:
return ToColor_S4444_Raw;
default:
return NULL;
}
case kRGB_565_SkColorType:
return ToColor_S565;
case kIndex_8_SkColorType:
if (src.getColorTable() == NULL) {
return NULL;
}
switch (src.alphaType()) {
case kOpaque_SkAlphaType:
return ToColor_SI8_Opaque;
case kPremul_SkAlphaType:
return ToColor_SI8_Alpha;
case kUnpremul_SkAlphaType:
return ToColor_SI8_Raw;
default:
return NULL;
}
default:
break;
}
return NULL;
}
示例13: ChooseToColorProc
// can return NULL
static ToColorProc ChooseToColorProc(const SkBitmap& src) {
switch (src.config()) {
case SkBitmap::kARGB_8888_Config:
return src.isOpaque() ? ToColor_S32_Opaque : ToColor_S32_Alpha;
case SkBitmap::kARGB_4444_Config:
return src.isOpaque() ? ToColor_S4444_Opaque : ToColor_S4444_Alpha;
case SkBitmap::kRGB_565_Config:
return ToColor_S565;
case SkBitmap::kIndex8_Config:
if (src.getColorTable() == NULL) {
return NULL;
}
return src.isOpaque() ? ToColor_SI8_Opaque : ToColor_SI8_Alpha;
default:
break;
}
return NULL;
}
示例14: valid_for_drawing
static bool valid_for_drawing(const SkBitmap& bm) {
if (0 == bm.width() || 0 == bm.height()) {
return false; // nothing to draw
}
if (NULL == bm.pixelRef()) {
return false; // no pixels to read
}
if (bm.getTexture()) {
// we can handle texture (ugh) since lockPixels will perform a read-back
return true;
}
if (kIndex_8_SkColorType == bm.colorType()) {
SkAutoLockPixels alp(bm); // but we need to call it before getColorTable() is safe.
if (!bm.getColorTable()) {
return false;
}
}
return true;
}
示例15: ChooseToColorProc
// can return NULL
static ToColorProc ChooseToColorProc(const SkBitmap& src, bool isPremultiplied) {
switch (src.config()) {
case SkBitmap::kARGB_8888_Config:
if (src.isOpaque()) return ToColor_S32_Opaque;
return isPremultiplied ? ToColor_S32_Alpha : ToColor_S32_Raw;
case SkBitmap::kARGB_4444_Config:
if (src.isOpaque()) return ToColor_S4444_Opaque;
return isPremultiplied ? ToColor_S4444_Alpha : ToColor_S4444_Raw;
case SkBitmap::kRGB_565_Config:
return ToColor_S565;
case SkBitmap::kIndex8_Config:
if (src.getColorTable() == NULL) {
return NULL;
}
if (src.isOpaque()) return ToColor_SI8_Opaque;
return isPremultiplied ? ToColor_SI8_Raw : ToColor_SI8_Alpha;
default:
break;
}
return NULL;
}