本文整理汇总了C++中SkColorTable::unlockColors方法的典型用法代码示例。如果您正苦于以下问题:C++ SkColorTable::unlockColors方法的具体用法?C++ SkColorTable::unlockColors怎么用?C++ SkColorTable::unlockColors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkColorTable
的用法示例。
在下文中一共展示了SkColorTable::unlockColors方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
}
}
示例2: alps
static void convertToIndex666(const SkBitmap& src, SkBitmap* dst) {
SkColorTable* ctable = new SkColorTable(216);
SkPMColor* colors = ctable->lockColors();
// rrr ggg bbb
for (int r = 0; r < 6; r++) {
int rr = conv6ToByte(r);
for (int g = 0; g < 6; g++) {
int gg = conv6ToByte(g);
for (int b = 0; b < 6; b++) {
int bb = conv6ToByte(b);
*colors++ = SkPreMultiplyARGB(0xFF, rr, gg, bb);
}
}
}
ctable->unlockColors(true);
dst->setConfig(SkBitmap::kIndex8_Config, src.width(), src.height());
dst->allocPixels(ctable);
ctable->unref();
SkAutoLockPixels alps(src);
SkAutoLockPixels alpd(*dst);
for (int y = 0; y < src.height(); y++) {
const SkPMColor* srcP = src.getAddr32(0, y);
uint8_t* dstP = dst->getAddr8(0, y);
for (int x = src.width() - 1; x >= 0; --x) {
*dstP++ = compute666Index(*srcP++);
}
}
}
示例3: make_bitmap
static SkBitmap make_bitmap() {
SkBitmap bm;
SkColorTable* ctable = new SkColorTable(256);
SkPMColor* c = ctable->lockColors();
for (int i = 0; i < 256; i++) {
c[i] = SkPackARGB32(255 - i, 0, 0, 0);
}
ctable->unlockColors(true);
bm.setConfig(SkBitmap::kIndex8_Config, 256, 256);
bm.allocPixels(ctable);
ctable->unref();
bm.lockPixels();
const float cx = bm.width() * 0.5f;
const float cy = bm.height() * 0.5f;
for (int y = 0; y < bm.height(); y++) {
float dy = y - cy;
dy *= dy;
uint8_t* p = bm.getAddr8(0, y);
for (int x = 0; x < 256; x++) {
float dx = x - cx;
dx *= dx;
float d = (dx + dy) / (cx/2);
int id = (int)d;
if (id > 255) {
id = 255;
}
p[x] = id;
}
}
bm.unlockPixels();
return bm;
}
示例4: make_bitmap
static SkBitmap make_bitmap()
{
SkBitmap bm;
SkColorTable* ctable = new SkColorTable(256);
SkPMColor* c = ctable->lockColors();
for (int i = 0; i < 256; i++)
{
c[i] = SkPackARGB32(0xFF, i, 0, 0);
}
ctable->unlockColors(true);
bm.setConfig(SkBitmap::kIndex8_Config, 256, 32);
bm.allocPixels(ctable);
ctable->unref();
bm.lockPixels();
for (int y = 0; y < bm.height(); y++)
{
uint8_t* p = bm.getAddr8(0, y);
for (int x = 0; x < 256; x++)
{
p[x] = x;
}
}
bm.unlockPixels();
return bm;
}
示例5: Bitmap_writeToParcel
static jboolean Bitmap_writeToParcel(JNIEnv* env, jobject,
jlong bitmapHandle,
jboolean isMutable, jint density,
jobject parcel) {
const SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
if (parcel == NULL) {
SkDebugf("------- writeToParcel null parcel\n");
return JNI_FALSE;
}
android::Parcel* p = android::parcelForJavaObject(env, parcel);
p->writeInt32(isMutable);
p->writeInt32(bitmap->colorType());
p->writeInt32(bitmap->alphaType());
p->writeInt32(bitmap->width());
p->writeInt32(bitmap->height());
p->writeInt32(bitmap->rowBytes());
p->writeInt32(density);
if (bitmap->colorType() == kIndex_8_SkColorType) {
SkColorTable* ctable = bitmap->getColorTable();
if (ctable != NULL) {
int count = ctable->count();
p->writeInt32(count);
memcpy(p->writeInplace(count * sizeof(SkPMColor)),
ctable->lockColors(), count * sizeof(SkPMColor));
ctable->unlockColors();
} else {
p->writeInt32(0); // indicate no ctable
}
}
size_t size = bitmap->getSize();
android::Parcel::WritableBlob blob;
android::status_t status = p->writeBlob(size, &blob);
if (status) {
doThrowRE(env, "Could not write bitmap to parcel blob.");
return JNI_FALSE;
}
bitmap->lockPixels();
const void* pSrc = bitmap->getPixels();
if (pSrc == NULL) {
memset(blob.data(), 0, size);
} else {
memcpy(blob.data(), pSrc, size);
}
bitmap->unlockPixels();
blob.release();
return JNI_TRUE;
}
示例6: 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());
}
示例7: 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;
}
}
}
示例8: make_bitmap
static SkBitmap make_bitmap() {
SkBitmap bm;
SkColorTable* ctable = new SkColorTable(1);
SkPMColor* c = ctable->lockColors();
c[0] = SkPackARGB32(0x80, 0x80, 0, 0);
ctable->unlockColors(true);
bm.setConfig(SkBitmap::kIndex8_Config, 1, 1);
bm.allocPixels(ctable);
ctable->unref();
bm.lockPixels();
*bm.getAddr8(0, 0) = 0;
bm.unlockPixels();
return bm;
}
示例9: make_bitmap
static SkBitmap make_bitmap() {
SkBitmap bm;
const int N = 1;
SkColorTable* ctable = new SkColorTable(N);
SkPMColor* c = ctable->lockColors();
for (int i = 0; i < N; i++) {
c[i] = SkPackARGB32(0x80, 0x80, 0, 0);
}
ctable->unlockColors(true);
bm.setConfig(SkBitmap::kIndex8_Config, 1, 1);
bm.allocPixels(ctable);
ctable->unref();
bm.lockPixels();
for (int y = 0; y < bm.height(); y++) {
uint8_t* p = bm.getAddr8(0, y);
for (int x = 0; x < bm.width(); x++) {
p[x] = 0;
}
}
bm.unlockPixels();
return bm;
}
示例10: 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;
uint32_t* colorTableDst = reinterpret_cast<uint32_t*>(dst);
const uint32_t* colorTableSrc = reinterpret_cast<const uint32_t*>(ctable->lockColors());
SkConvertConfig8888Pixels(colorTableDst, 0, SkCanvas::kRGBA_Premul_Config8888,
colorTableSrc, 0, SkCanvas::kNative_Premul_Config8888,
ctable->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;
}
}
}
示例11: onDecode
//.........这里部分代码省略.........
SkPMColor* colorPtr = colorTable->lockColors();
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, NULL);
hasAlpha = (num_trans > 0);
} else {
num_trans = 0;
colorTable->setFlags(colorTable->getFlags() | SkColorTable::kColorsAreOpaque_Flag);
}
// check for bad images that might make us crash
if (num_trans > num_palette) {
num_trans = num_palette;
}
int index = 0;
int transLessThanFF = 0;
for (; index < num_trans; index++) {
transLessThanFF |= (int)*trans - 0xFF;
*colorPtr++ = SkPreMultiplyARGB(*trans++, palette->red, palette->green, palette->blue);
palette++;
}
reallyHasAlpha |= (transLessThanFF < 0);
for (; index < num_palette; index++) {
*colorPtr++ = SkPackARGB32(0xFF, palette->red, palette->green, palette->blue);
palette++;
}
// see BUGGY IMAGE WORKAROUND comment above
if (num_palette < 256) {
*colorPtr = colorPtr[-1];
}
colorTable->unlockColors(true);
}
SkAutoUnref aur(colorTable);
if (!this->allocPixelRef(decodedBitmap, colorTable)) {
delete colorTable;
return false;
}
SkAutoLockPixels alp(*decodedBitmap);
/* swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */
// if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
// ; // png_set_swap_alpha(png_ptr);
/* swap bytes of 16 bit files to least significant byte first */
// png_set_swap(png_ptr);
/* Add filler (or alpha) byte (before/after each RGB triplet) */
if (color_type == PNG_COLOR_TYPE_RGB || color_type == PNG_COLOR_TYPE_GRAY) {
png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
}
/* Turn on interlace handling. REQUIRED if you are not using
* png_read_image(). To see how to handle interlacing passes,
* see the png_read_row() method below:
*/
const int number_passes = interlace_type != PNG_INTERLACE_NONE ?
png_set_interlace_handling(png_ptr) : 1;
/* Optional call to gamma correct and add the background to the palette
* and update info structure. REQUIRED if you are expecting libpng to