remove alphatype from colortable
the owning bitmap is (already) responsible for knowing the alphatype BUG=skia: R=djsollen@google.com Author: reed@google.com Review URL: https://codereview.chromium.org/611093002
This commit is contained in:
parent
4572ae9221
commit
c5e15a1afa
@ -44,7 +44,7 @@ static void convertToIndex666(const SkBitmap& src, SkBitmap* dst, SkAlphaType aT
|
||||
}
|
||||
}
|
||||
}
|
||||
SkColorTable* ctable = new SkColorTable(storage, 216, aType);
|
||||
SkColorTable* ctable = new SkColorTable(storage, 216);
|
||||
dst->allocPixels(SkImageInfo::Make(src.width(), src.height(), kIndex_8_SkColorType, aType),
|
||||
NULL, ctable);
|
||||
ctable->unref();
|
||||
|
@ -63,7 +63,7 @@ static void convert_to_index666(const SkBitmap& src, SkBitmap* dst) {
|
||||
}
|
||||
}
|
||||
}
|
||||
SkColorTable* ctable = new SkColorTable(storage, 216, kOpaque_SkAlphaType);
|
||||
SkColorTable* ctable = new SkColorTable(storage, 216);
|
||||
dst->allocPixels(SkImageInfo::Make(src.width(), src.height(),
|
||||
kIndex_8_SkColorType, kOpaque_SkAlphaType),
|
||||
NULL, ctable);
|
||||
|
@ -26,16 +26,9 @@ public:
|
||||
/** Makes a deep copy of colors.
|
||||
*/
|
||||
SkColorTable(const SkColorTable& src);
|
||||
SkColorTable(const SkPMColor colors[], int count,
|
||||
SkAlphaType alphaType = kPremul_SkAlphaType);
|
||||
SkColorTable(const SkPMColor colors[], int count);
|
||||
virtual ~SkColorTable();
|
||||
|
||||
SkAlphaType alphaType() const { return (SkAlphaType)fAlphaType; }
|
||||
|
||||
bool isOpaque() const {
|
||||
return SkAlphaTypeIsOpaque(this->alphaType());
|
||||
}
|
||||
|
||||
/** Returns the number of colors in the table.
|
||||
*/
|
||||
int count() const { return fCount; }
|
||||
@ -44,7 +37,7 @@ public:
|
||||
the index is in range (0 <= index < count).
|
||||
*/
|
||||
SkPMColor operator[](int index) const {
|
||||
SkASSERT(fColors != NULL && (unsigned)index < fCount);
|
||||
SkASSERT(fColors != NULL && (unsigned)index < (unsigned)fCount);
|
||||
return fColors[index];
|
||||
}
|
||||
|
||||
@ -81,11 +74,12 @@ public:
|
||||
private:
|
||||
SkPMColor* fColors;
|
||||
uint16_t* f16BitCache;
|
||||
uint16_t fCount;
|
||||
uint8_t fAlphaType;
|
||||
int fCount;
|
||||
SkDEBUGCODE(int fColorLockCount;)
|
||||
SkDEBUGCODE(int f16BitCacheLockCount;)
|
||||
|
||||
void init(const SkPMColor* colors, int count);
|
||||
|
||||
void inval16BitCache();
|
||||
|
||||
typedef SkRefCnt INHERITED;
|
||||
|
@ -249,13 +249,14 @@ private:
|
||||
// V33: Serialize only public API of effects.
|
||||
// V34: Add SkTextBlob serialization.
|
||||
// V35: Store SkRect (rather then width & height) in header
|
||||
// V36: Remove (obsolete) alphatype from SkColorTable
|
||||
|
||||
// Note: If the picture version needs to be increased then please follow the
|
||||
// steps to generate new SKPs in (only accessible to Googlers): http://goo.gl/qATVcw
|
||||
|
||||
// Only SKPs within the min/current picture version range (inclusive) can be read.
|
||||
static const uint32_t MIN_PICTURE_VERSION = 19;
|
||||
static const uint32_t CURRENT_PICTURE_VERSION = 35;
|
||||
static const uint32_t CURRENT_PICTURE_VERSION = 36;
|
||||
|
||||
mutable uint32_t fUniqueID;
|
||||
|
||||
|
@ -57,11 +57,10 @@ static SkBitmap make_bitmap() {
|
||||
for (int i = 0; i < 256; i++) {
|
||||
c[i] = SkPackARGB32(0xFF, i, 0, 0);
|
||||
}
|
||||
SkColorTable* ctable = new SkColorTable(c, 256, kOpaque_SkAlphaType);
|
||||
SkColorTable* ctable = new SkColorTable(c, 256);
|
||||
|
||||
SkBitmap bm;
|
||||
bm.allocPixels(SkImageInfo::Make(256, 32, kIndex_8_SkColorType,
|
||||
kPremul_SkAlphaType),
|
||||
bm.allocPixels(SkImageInfo::Make(256, 32, kIndex_8_SkColorType, kPremul_SkAlphaType),
|
||||
NULL, ctable);
|
||||
ctable->unref();
|
||||
|
||||
|
@ -13,44 +13,36 @@
|
||||
#include "SkStream.h"
|
||||
#include "SkTemplates.h"
|
||||
|
||||
// As copy constructor is hidden in the class hierarchy, we need to call
|
||||
// default constructor explicitly to suppress a compiler warning.
|
||||
SkColorTable::SkColorTable(const SkColorTable& src) : INHERITED() {
|
||||
f16BitCache = NULL;
|
||||
fAlphaType = src.fAlphaType;
|
||||
int count = src.count();
|
||||
fCount = SkToU16(count);
|
||||
fColors = reinterpret_cast<SkPMColor*>(
|
||||
sk_malloc_throw(count * sizeof(SkPMColor)));
|
||||
memcpy(fColors, src.fColors, count * sizeof(SkPMColor));
|
||||
void SkColorTable::init(const SkPMColor colors[], int count) {
|
||||
SkASSERT((unsigned)count <= 256);
|
||||
|
||||
f16BitCache = NULL;
|
||||
fCount = count;
|
||||
fColors = reinterpret_cast<SkPMColor*>(sk_malloc_throw(count * sizeof(SkPMColor)));
|
||||
|
||||
memcpy(fColors, colors, count * sizeof(SkPMColor));
|
||||
|
||||
SkDEBUGCODE(fColorLockCount = 0;)
|
||||
SkDEBUGCODE(f16BitCacheLockCount = 0;)
|
||||
}
|
||||
|
||||
SkColorTable::SkColorTable(const SkPMColor colors[], int count, SkAlphaType at)
|
||||
: f16BitCache(NULL), fAlphaType(SkToU8(at))
|
||||
{
|
||||
SkASSERT(0 == count || colors);
|
||||
// As copy constructor is hidden in the class hierarchy, we need to call
|
||||
// default constructor explicitly to suppress a compiler warning.
|
||||
SkColorTable::SkColorTable(const SkColorTable& src) : INHERITED() {
|
||||
this->init(src.fColors, src.fCount);
|
||||
}
|
||||
|
||||
SkColorTable::SkColorTable(const SkPMColor colors[], int count) {
|
||||
SkASSERT(0 == count || colors);
|
||||
if (count < 0) {
|
||||
count = 0;
|
||||
} else if (count > 256) {
|
||||
count = 256;
|
||||
}
|
||||
|
||||
fCount = SkToU16(count);
|
||||
fColors = reinterpret_cast<SkPMColor*>(
|
||||
sk_malloc_throw(count * sizeof(SkPMColor)));
|
||||
|
||||
memcpy(fColors, colors, count * sizeof(SkPMColor));
|
||||
|
||||
SkDEBUGCODE(fColorLockCount = 0;)
|
||||
SkDEBUGCODE(f16BitCacheLockCount = 0;)
|
||||
this->init(colors, count);
|
||||
}
|
||||
|
||||
SkColorTable::~SkColorTable()
|
||||
{
|
||||
SkColorTable::~SkColorTable() {
|
||||
SkASSERT(fColorLockCount == 0);
|
||||
SkASSERT(f16BitCacheLockCount == 0);
|
||||
|
||||
@ -73,9 +65,6 @@ static inline void build_16bitcache(uint16_t dst[], const SkPMColor src[],
|
||||
}
|
||||
|
||||
const uint16_t* SkColorTable::lock16BitCache() {
|
||||
// Assert that we're opaque, since our 16-bit cache will be sort of useless
|
||||
// if there is alpha (which we're throwing away)
|
||||
SkASSERT(this->isOpaque());
|
||||
if (NULL == f16BitCache) {
|
||||
f16BitCache = (uint16_t*)sk_malloc_throw(fCount * sizeof(uint16_t));
|
||||
build_16bitcache(f16BitCache, fColors, fCount);
|
||||
@ -92,7 +81,10 @@ SkColorTable::SkColorTable(SkReadBuffer& buffer) {
|
||||
SkDEBUGCODE(fColorLockCount = 0;)
|
||||
SkDEBUGCODE(f16BitCacheLockCount = 0;)
|
||||
|
||||
fAlphaType = SkToU8(buffer.readUInt());
|
||||
if (buffer.isVersionLT(SkReadBuffer::kRemoveColorTableAlpha_Version)) {
|
||||
/*fAlphaType = */buffer.readUInt();
|
||||
}
|
||||
|
||||
fCount = buffer.getArrayCount();
|
||||
size_t allocSize = fCount * sizeof(SkPMColor);
|
||||
SkDEBUGCODE(bool success = false;)
|
||||
@ -110,6 +102,5 @@ SkColorTable::SkColorTable(SkReadBuffer& buffer) {
|
||||
}
|
||||
|
||||
void SkColorTable::writeToBuffer(SkWriteBuffer& buffer) const {
|
||||
buffer.writeUInt(fAlphaType);
|
||||
buffer.writeColorArray(fColors, fCount);
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ public:
|
||||
kImageFilterUniqueID_Version = 31,
|
||||
kRemoveAndroidPaintOpts_Version = 32,
|
||||
kFlattenCreateProc_Version = 33,
|
||||
kRemoveColorTableAlpha_Version = 36,
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -332,7 +332,6 @@ bool SkGIFImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* bm, Mode mode) {
|
||||
// Declare colorPtr here for scope.
|
||||
SkPMColor colorPtr[256]; // storage for worst-case
|
||||
const ColorMapObject* cmap = find_colormap(gif);
|
||||
SkAlphaType alphaType = kOpaque_SkAlphaType;
|
||||
if (cmap != NULL) {
|
||||
SkASSERT(cmap->ColorCount == (1 << (cmap->BitsPerPixel)));
|
||||
colorCount = cmap->ColorCount;
|
||||
@ -355,16 +354,13 @@ bool SkGIFImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* bm, Mode mode) {
|
||||
transpIndex = find_transpIndex(temp_save, colorCount);
|
||||
if (transpIndex >= 0) {
|
||||
colorPtr[transpIndex] = SK_ColorTRANSPARENT; // ram in a transparent SkPMColor
|
||||
alphaType = kPremul_SkAlphaType;
|
||||
fillIndex = transpIndex;
|
||||
} else if (fillIndex >= colorCount) {
|
||||
// gif->SBackGroundColor should be less than colorCount.
|
||||
fillIndex = 0; // If not, fix it.
|
||||
}
|
||||
|
||||
SkAutoTUnref<SkColorTable> ctable(SkNEW_ARGS(SkColorTable,
|
||||
(colorPtr, colorCount,
|
||||
alphaType)));
|
||||
SkAutoTUnref<SkColorTable> ctable(SkNEW_ARGS(SkColorTable, (colorPtr, colorCount)));
|
||||
if (!this->allocPixelRef(bm, ctable)) {
|
||||
return error_return(*bm, "allocPixelRef");
|
||||
}
|
||||
|
@ -709,17 +709,7 @@ bool SkPNGImageDecoder::decodePalette(png_structp png_ptr, png_infop info_ptr,
|
||||
*colorPtr = colorPtr[-1];
|
||||
}
|
||||
|
||||
SkAlphaType alphaType = kOpaque_SkAlphaType;
|
||||
if (reallyHasAlpha) {
|
||||
if (this->getRequireUnpremultipliedColors()) {
|
||||
alphaType = kUnpremul_SkAlphaType;
|
||||
} else {
|
||||
alphaType = kPremul_SkAlphaType;
|
||||
}
|
||||
}
|
||||
|
||||
*colorTablep = SkNEW_ARGS(SkColorTable,
|
||||
(colorStorage, colorCount, alphaType));
|
||||
*colorTablep = SkNEW_ARGS(SkColorTable, (colorStorage, colorCount));
|
||||
*reallyHasAlphap = reallyHasAlpha;
|
||||
return true;
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ bool SkWBMPImageDecoder::onDecode(SkStream* stream, SkBitmap* decodedBitmap,
|
||||
}
|
||||
|
||||
const SkPMColor colors[] = { SK_ColorBLACK, SK_ColorWHITE };
|
||||
SkColorTable* ct = SkNEW_ARGS(SkColorTable, (colors, 2, kOpaque_SkAlphaType));
|
||||
SkColorTable* ct = SkNEW_ARGS(SkColorTable, (colors, 2));
|
||||
SkAutoUnref aur(ct);
|
||||
|
||||
if (!this->allocPixelRef(decodedBitmap, ct)) {
|
||||
|
@ -61,11 +61,11 @@ static void init_src(const SkBitmap& bitmap) {
|
||||
}
|
||||
}
|
||||
|
||||
static SkColorTable* init_ctable(SkAlphaType alphaType) {
|
||||
static SkColorTable* init_ctable() {
|
||||
static const SkColor colors[] = {
|
||||
SK_ColorBLACK, SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE
|
||||
};
|
||||
return new SkColorTable(colors, SK_ARRAY_COUNT(colors), alphaType);
|
||||
return new SkColorTable(colors, SK_ARRAY_COUNT(colors));
|
||||
}
|
||||
|
||||
struct Pair {
|
||||
@ -196,19 +196,16 @@ static const int H = 33;
|
||||
|
||||
static void setup_src_bitmaps(SkBitmap* srcOpaque, SkBitmap* srcPremul,
|
||||
SkColorType ct) {
|
||||
SkColorTable* ctOpaque = NULL;
|
||||
SkColorTable* ctPremul = NULL;
|
||||
SkColorTable* ctable = NULL;
|
||||
if (kIndex_8_SkColorType == ct) {
|
||||
ctOpaque = init_ctable(kOpaque_SkAlphaType);
|
||||
ctPremul = init_ctable(kPremul_SkAlphaType);
|
||||
ctable = init_ctable();
|
||||
}
|
||||
|
||||
srcOpaque->allocPixels(SkImageInfo::Make(W, H, ct, kOpaque_SkAlphaType),
|
||||
NULL, ctOpaque);
|
||||
NULL, ctable);
|
||||
srcPremul->allocPixels(SkImageInfo::Make(W, H, ct, kPremul_SkAlphaType),
|
||||
NULL, ctPremul);
|
||||
SkSafeUnref(ctOpaque);
|
||||
SkSafeUnref(ctPremul);
|
||||
NULL, ctable);
|
||||
SkSafeUnref(ctable);
|
||||
init_src(*srcOpaque);
|
||||
init_src(*srcPremul);
|
||||
}
|
||||
@ -384,7 +381,7 @@ DEF_TEST(BitmapCopy, reporter) {
|
||||
SkBitmap src, subset;
|
||||
SkColorTable* ct = NULL;
|
||||
if (kIndex_8_SkColorType == src.colorType()) {
|
||||
ct = init_ctable(kPremul_SkAlphaType);
|
||||
ct = init_ctable();
|
||||
}
|
||||
|
||||
int localSubW;
|
||||
|
Loading…
Reference in New Issue
Block a user