fBitmap = bm;
}
- fBitmap.setIsOpaque(fIsOpaque);
+ fBitmap.setAlphaType(fIsOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
fBitmap.setIsVolatile(fIsVolatile);
}
virtual void onPreDraw() SK_OVERRIDE {
fBitmap.allocPixels();
- fBitmap.setIsOpaque(true);
+ fBitmap.setAlphaType(kOpaque_SkAlphaType);
fBitmap.eraseColor(SK_ColorBLACK);
draw_into_bitmap(fBitmap);
}
virtual void onPreDraw() {
- fInputBitmap.setConfig(SkBitmap::kARGB_8888_Config, fInputSize, fInputSize);
+ fInputBitmap.setConfig(SkBitmap::kARGB_8888_Config,
+ fInputSize, fInputSize, 0, kOpaque_SkAlphaType);
fInputBitmap.allocPixels();
fInputBitmap.eraseColor(SK_ColorWHITE);
- fInputBitmap.setIsOpaque(true);
- fOutputBitmap.setConfig(SkBitmap::kARGB_8888_Config, fOutputSize, fOutputSize);
+ fOutputBitmap.setConfig(SkBitmap::kARGB_8888_Config,
+ fOutputSize, fOutputSize, 0, kOpaque_SkAlphaType);
fOutputBitmap.allocPixels();
- fOutputBitmap.setIsOpaque(true);
fMatrix.setScale( scale(), scale() );
}
virtual void onPreDraw() SK_OVERRIDE {
fBitmap.allocPixels();
fBitmap.eraseColor(fIsOpaque ? SK_ColorWHITE : 0);
- fBitmap.setIsOpaque(fIsOpaque);
+ fBitmap.setAlphaType(fIsOpaque ?
+ kOpaque_SkAlphaType : kPremul_SkAlphaType);
draw_into_bitmap(fBitmap);
, fDoScale(doScale) {
SkBitmap bm;
- bm.setConfig(SkBitmap::kARGB_8888_Config, kWidth, kHeight);
-
+ bm.setConfig(SkBitmap::kARGB_8888_Config, kWidth, kHeight, 0,
+ kOpaque_SkAlphaType);
bm.allocPixels();
bm.eraseColor(SK_ColorWHITE);
- bm.setIsOpaque(true);
create_gradient(&bm);
static void make_red_ringed_bitmap(SkBitmap* result, int width, int height) {
SkASSERT(0 == width % 2 && 0 == width % 2);
- result->setConfig(SkBitmap::kARGB_8888_Config, width, height);
+ result->setConfig(SkBitmap::kARGB_8888_Config, width, height, 0,
+ kOpaque_SkAlphaType);
result->allocPixels();
SkAutoLockPixels lock(*result);
for (int x = 0; x < width; ++x) {
scanline[x] = SK_ColorRED;
}
- result->setIsOpaque(true);
result->setImmutable();
}
}
virtual void onOnceBeforeDraw() SK_OVERRIDE {
- fBG.setConfig(SkBitmap::kARGB_4444_Config, 2, 2, 4);
+ fBG.setConfig(SkBitmap::kARGB_4444_Config, 2, 2, 4, kOpaque_SkAlphaType);
fBG.setPixels(gData);
- fBG.setIsOpaque(true);
make_bitmaps(W, H, &fSrcB, &fDstB);
}
SkPackARGB32(0xFF, 0x40, 0x40, 0x40)
};
SkBitmap bg;
- bg.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
+ bg.setConfig(SkBitmap::kARGB_8888_Config, 2, 2, 0, kOpaque_SkAlphaType);
bg.allocPixels();
SkAutoLockPixels bgAlp(bg);
memcpy(bg.getPixels(), kCheckData, sizeof(kCheckData));
- bg.setIsOpaque(true);
fBG.reset(SkShader::CreateBitmapShader(bg,
SkShader::kRepeat_TileMode,
SkPackARGB32(0xFF, 0x40, 0x40, 0x40)
};
SkBitmap bg;
- bg.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
+ bg.setConfig(SkBitmap::kARGB_8888_Config, 2, 2, 0, kOpaque_SkAlphaType);
bg.allocPixels();
SkAutoLockPixels bgAlp(bg);
memcpy(bg.getPixels(), kCheckData, sizeof(kCheckData));
- bg.setIsOpaque(true);
fBGShader.reset(SkShader::CreateBitmapShader(bg,
SkShader::kRepeat_TileMode,
#define SkBitmap_DEFINED
#include "Sk64.h"
+#include "SkAlpha.h"
#include "SkColor.h"
#include "SkColorTable.h"
#include "SkPoint.h"
*/
int rowBytesAsPixels() const { return fRowBytes >> (fBytesPerPixel >> 1); }
+ SkAlphaType alphaType() const { return (SkAlphaType)fAlphaType; }
+
+ /**
+ * Set the bitmap's alphaType, returning true on success. If false is
+ * returned, then the specified new alphaType is incompatible with the
+ * Config, and the current alphaType is unchanged.
+ */
+ bool setAlphaType(SkAlphaType);
+
/** Return the address of the pixels for this SkBitmap.
*/
void* getPixels() const { return fPixels; }
/** Returns true if the bitmap is opaque (has no translucent/transparent pixels).
*/
- bool isOpaque() const;
+ bool isOpaque() const {
+ return SkAlphaTypeIsOpaque(this->alphaType());
+ }
- /** Specify if this bitmap's pixels are all opaque or not. Is only meaningful for configs
- that support per-pixel alpha (RGB32, A1, A8).
- */
- void setIsOpaque(bool);
+ /**
+ * DEPRECATED: use setAlpahType() instead.
+ */
+ void setIsOpaque(bool opaque) {
+ this->setAlphaType(opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
+ }
/** Returns true if the bitmap is volatile (i.e. should not be cached by devices.)
*/
*/
static bool ComputeIsOpaque(const SkBitmap&);
- /**
- * Calls ComputeIsOpaque, and passes its result to setIsOpaque().
- */
- void computeAndSetOpaquePredicate() {
- this->setIsOpaque(ComputeIsOpaque(*this));
- }
-
/**
* Return the bitmap's bounds [0, 0, width, height] as an SkRect
*/
ComputeRowBytes() is called to compute the optimal value. This resets
any pixel/colortable ownership, just like reset().
*/
- void setConfig(Config, int width, int height, size_t rowBytes = 0);
+ bool setConfig(Config, int width, int height, size_t rowBytes, SkAlphaType);
+
+ bool setConfig(Config config, int width, int height, size_t rowBytes = 0) {
+ return this->setConfig(config, width, height, rowBytes,
+ kPremul_SkAlphaType);
+ }
+
+
/** Use this to assign a new pixel address for an existing bitmap. This
will automatically release any pixelref previously installed. Only call
this if you are handling ownership/lifetime of the pixel memory.
uint32_t fWidth;
uint32_t fHeight;
uint8_t fConfig;
+ uint8_t fAlphaType;
uint8_t fFlags;
uint8_t fBytesPerPixel; // based on config
static void setBitmapOpaque(SkBitmap* bm, bool isOpaque) {
SkAutoLockPixels alp(*bm); // needed for ctable
- bm->setIsOpaque(isOpaque);
+ bm->setAlphaType(isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
#if 0
SkColorTable* ctable = bm->getColorTable();
if (ctable) {
static void setBitmapOpaque(SkBitmap* bm, bool isOpaque) {
SkAutoLockPixels alp(*bm); // needed for ctable
- bm->setIsOpaque(isOpaque);
+ bm->setAlphaType(isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
#if 0
- // TODO - I think we just want to not allow this anymore
SkColorTable* ctable = bm->getColorTable();
if (ctable) {
ctable->setIsOpaque(isOpaque);
const static int W = 64;
const static int H = 64;
XfermodesBlurView() {
- fBG.setConfig(SkBitmap::kARGB_4444_Config, 2, 2, 4);
+ fBG.setConfig(SkBitmap::kARGB_4444_Config, 2, 2, 4, kOpaque_SkAlphaType);
fBG.setPixels(gBG);
- fBG.setIsOpaque(true);
}
protected:
SkTSwap(fWidth, other.fWidth);
SkTSwap(fHeight, other.fHeight);
SkTSwap(fConfig, other.fConfig);
+ SkTSwap(fAlphaType, other.fAlphaType);
SkTSwap(fFlags, other.fFlags);
SkTSwap(fBytesPerPixel, other.fBytesPerPixel);
///////////////////////////////////////////////////////////////////////////////
-void SkBitmap::setConfig(Config c, int width, int height, size_t rowBytes) {
- this->freePixels();
+static bool validate_alphaType(SkBitmap::Config config, SkAlphaType alphaType,
+ SkAlphaType* canonical) {
+ switch (config) {
+ case SkBitmap::kNo_Config:
+ alphaType = kIgnore_SkAlphaType;
+ break;
+ case SkBitmap::kA1_Config:
+ case SkBitmap::kA8_Config:
+ if (kUnpremul_SkAlphaType == alphaType) {
+ alphaType = kPremul_SkAlphaType;
+ }
+ // fall-through
+ case SkBitmap::kIndex8_Config:
+ case SkBitmap::kARGB_4444_Config:
+ case SkBitmap::kARGB_8888_Config:
+ if (kIgnore_SkAlphaType == alphaType) {
+ return false;
+ }
+ break;
+ case SkBitmap::kRGB_565_Config:
+ alphaType = kOpaque_SkAlphaType;
+ break;
+ }
+ if (canonical) {
+ *canonical = alphaType;
+ }
+ return true;
+}
+bool SkBitmap::setConfig(Config config, int width, int height, size_t rowBytes,
+ SkAlphaType alphaType) {
if ((width | height) < 0) {
- goto err;
+ goto ERROR;
}
-
if (rowBytes == 0) {
- rowBytes = SkBitmap::ComputeRowBytes(c, width);
- if (0 == rowBytes && kNo_Config != c) {
- goto err;
+ rowBytes = SkBitmap::ComputeRowBytes(config, width);
+ if (0 == rowBytes && kNo_Config != config) {
+ goto ERROR;
}
}
- fConfig = SkToU8(c);
+ if (!validate_alphaType(config, alphaType, &alphaType)) {
+ goto ERROR;
+ }
+
+ this->freePixels();
+
+ fConfig = SkToU8(config);
+ fAlphaType = SkToU8(alphaType);
fWidth = width;
fHeight = height;
fRowBytes = SkToU32(rowBytes);
- fBytesPerPixel = (uint8_t)ComputeBytesPerPixel(c);
+ fBytesPerPixel = (uint8_t)ComputeBytesPerPixel(config);
SkDEBUGCODE(this->validate();)
- return;
+ return true;
// if we got here, we had an error, so we reset the bitmap to empty
-err:
+ERROR:
this->reset();
+ return false;
+}
+
+bool SkBitmap::setAlphaType(SkAlphaType alphaType) {
+ if (!validate_alphaType(this->config(), alphaType, &alphaType)) {
+ return false;
+ }
+ fAlphaType = SkToU8(alphaType);
+ return true;
}
void SkBitmap::updatePixelsFromRef() const {
}
}
-bool SkBitmap::isOpaque() const {
- switch (fConfig) {
- case kNo_Config:
- return true;
-
- case kA1_Config:
- case kA8_Config:
- case kARGB_4444_Config:
- case kARGB_8888_Config:
- return (fFlags & kImageIsOpaque_Flag) != 0;
-
- case kIndex8_Config: {
- bool isOpaque;
-
- this->lockPixels();
- isOpaque = fColorTable && fColorTable->isOpaque();
- this->unlockPixels();
- return isOpaque;
- }
-
- case kRGB_565_Config:
- return true;
-
- default:
- SkDEBUGFAIL("unknown bitmap config pased to isOpaque");
- return false;
- }
-}
-
-void SkBitmap::setIsOpaque(bool isOpaque) {
- /* we record this regardless of fConfig, though it is ignored in
- isOpaque() for configs that can't support per-pixel alpha.
- */
- if (isOpaque) {
- fFlags |= kImageIsOpaque_Flag;
- } else {
- fFlags &= ~kImageIsOpaque_Flag;
- }
-}
-
bool SkBitmap::isVolatile() const {
return (fFlags & kImageIsVolatile_Flag) != 0;
}
SkPixelRef* pixelRef = fPixelRef->deepCopy(this->config(), &subset);
if (pixelRef != NULL) {
SkBitmap dst;
- dst.setConfig(this->config(), subset.width(), subset.height());
+ dst.setConfig(this->config(), subset.width(), subset.height(), 0,
+ this->alphaType());
dst.setIsVolatile(this->isVolatile());
- dst.setIsOpaque(this->isOpaque());
dst.setPixelRef(pixelRef)->unref();
SkDEBUGCODE(dst.validate());
result->swap(dst);
}
SkBitmap dst;
- dst.setConfig(this->config(), r.width(), r.height(), this->rowBytes());
+ dst.setConfig(this->config(), r.width(), r.height(), this->rowBytes(),
+ this->alphaType());
dst.setIsVolatile(this->isVolatile());
- dst.setIsOpaque(this->isOpaque());
if (fPixelRef) {
// share the pixelref with a custom offset
}
SkBitmap tmpDst;
- tmpDst.setConfig(dstConfig, src->width(), src->height());
+ tmpDst.setConfig(dstConfig, src->width(), src->height(), 0,
+ src->alphaType());
// allocate colortable if srcConfig == kIndex8_Config
SkColorTable* ctable = (dstConfig == kIndex8_Config) ?
canvas.drawBitmap(*src, 0, 0, &paint);
}
- tmpDst.setIsOpaque(src->isOpaque());
-
dst->swap(tmpDst);
return true;
}
buffer.writeInt(fHeight);
buffer.writeInt(fRowBytes);
buffer.writeInt(fConfig);
- buffer.writeBool(this->isOpaque());
+ buffer.writeInt(fAlphaType);
if (fPixelRef) {
if (fPixelRef->getFactory()) {
int height = buffer.readInt();
int rowBytes = buffer.readInt();
int config = buffer.readInt();
+ int alphaType = buffer.readInt();
- this->setConfig((Config)config, width, height, rowBytes);
- this->setIsOpaque(buffer.readBool());
+ this->setConfig((Config)config, width, height, rowBytes, (SkAlphaType)alphaType);
int reftype = buffer.readInt();
switch (reftype) {
}
SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, bool isOpaque) {
- fBitmap.setConfig(config, width, height);
+ fBitmap.setConfig(config, width, height, 0, isOpaque ?
+ kOpaque_SkAlphaType : kPremul_SkAlphaType);
fBitmap.allocPixels();
- fBitmap.setIsOpaque(isOpaque);
if (!isOpaque) {
fBitmap.eraseColor(SK_ColorTRANSPARENT);
}
const SkDeviceProperties& deviceProperties)
: SkBaseDevice(deviceProperties) {
- fBitmap.setConfig(config, width, height);
+ fBitmap.setConfig(config, width, height, 0, isOpaque ?
+ kOpaque_SkAlphaType : kPremul_SkAlphaType);
fBitmap.allocPixels();
- fBitmap.setIsOpaque(isOpaque);
if (!isOpaque) {
fBitmap.eraseColor(SK_ColorTRANSPARENT);
}
// Convolve into the result.
SkBitmap result;
result.setConfig(SkBitmap::kARGB_8888_Config,
- destSubset.width(), destSubset.height());
+ destSubset.width(), destSubset.height(), 0,
+ source.alphaType());
result.allocPixels(allocator, NULL);
if (!result.readyToDraw()) {
return false;
static_cast<unsigned char*>(result.getPixels()),
convolveProcs, true);
- // Preserve the "opaque" flag for use as an optimization later.
- result.setIsOpaque(source.isOpaque());
*resultPtr = result;
return true;
}
}
}
+/*
+ * GrRenderTarget does not know its opaqueness, only its config, so we have
+ * to make conservative guesses when we return an "equivalent" bitmap.
+ */
static SkBitmap make_bitmap(GrContext* context, GrRenderTarget* renderTarget) {
- GrPixelConfig config = renderTarget->config();
-
bool isOpaque;
+ SkBitmap::Config config = grConfig2skConfig(renderTarget->config(), &isOpaque);
+
SkBitmap bitmap;
- bitmap.setConfig(grConfig2skConfig(config, &isOpaque),
- renderTarget->width(), renderTarget->height());
- bitmap.setIsOpaque(isOpaque);
+ bitmap.setConfig(config, renderTarget->width(), renderTarget->height(), 0,
+ isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
return bitmap;
}
#include "SkCanvas.h"
#include "SkPicture.h"
-SkBitmap::Config SkImageInfoToBitmapConfig(const SkImage::Info& info,
- bool* isOpaque) {
+SkBitmap::Config SkImageInfoToBitmapConfig(const SkImage::Info& info) {
switch (info.fColorType) {
case SkImage::kAlpha_8_ColorType:
- switch (info.fAlphaType) {
- case kIgnore_SkAlphaType:
- // makes no sense
- return SkBitmap::kNo_Config;
-
- case kOpaque_SkAlphaType:
- *isOpaque = true;
- return SkBitmap::kA8_Config;
-
- case kPremul_SkAlphaType:
- case kUnpremul_SkAlphaType:
- *isOpaque = false;
- return SkBitmap::kA8_Config;
- }
- break;
+ return SkBitmap::kA8_Config;
case SkImage::kRGB_565_ColorType:
- // we ignore fAlpahType, though some would not make sense
- *isOpaque = true;
return SkBitmap::kRGB_565_Config;
case SkImage::kPMColor_ColorType:
- switch (info.fAlphaType) {
- case kIgnore_SkAlphaType:
- case kUnpremul_SkAlphaType:
- // not supported yet
- return SkBitmap::kNo_Config;
- case kOpaque_SkAlphaType:
- *isOpaque = true;
- return SkBitmap::kARGB_8888_Config;
- case kPremul_SkAlphaType:
- *isOpaque = false;
- return SkBitmap::kARGB_8888_Config;
- }
- break;
+ return SkBitmap::kARGB_8888_Config;
default:
// break for unsupported colortypes
class SkPicture;
-extern SkBitmap::Config SkImageInfoToBitmapConfig(const SkImage::Info&,
- bool* isOpaque);
+extern SkBitmap::Config SkImageInfoToBitmapConfig(const SkImage::Info&);
extern int SkImageBytesPerPixel(SkImage::ColorType);
return false;
}
- bool isOpaque;
- if (SkImageInfoToBitmapConfig(info, &isOpaque) == SkBitmap::kNo_Config) {
+ if (SkImageInfoToBitmapConfig(info) == SkBitmap::kNo_Config) {
return false;
}
SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes)
: INHERITED(info.fWidth, info.fHeight) {
- bool isOpaque;
- SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque);
+ SkBitmap::Config config = SkImageInfoToBitmapConfig(info);
- fBitmap.setConfig(config, info.fWidth, info.fHeight, rowBytes);
+ fBitmap.setConfig(config, info.fWidth, info.fHeight, rowBytes, info.fAlphaType);
fBitmap.setPixelRef(SkNEW_ARGS(SkDataPixelRef, (data)))->unref();
- fBitmap.setIsOpaque(isOpaque);
fBitmap.setImmutable();
}
SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, size_t rowBytes)
: INHERITED(info.fWidth, info.fHeight) {
- bool isOpaque;
- SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque);
+ SkBitmap::Config config = SkImageInfoToBitmapConfig(info);
- fBitmap.setConfig(config, info.fWidth, info.fHeight, rowBytes);
+ fBitmap.setConfig(config, info.fWidth, info.fHeight, rowBytes, info.fAlphaType);
fBitmap.setPixelRef(pr);
- fBitmap.setIsOpaque(isOpaque);
}
SkImage_Raster::~SkImage_Raster() {}
SkSurface_Gpu::SkSurface_Gpu(GrContext* ctx, const SkImage::Info& info,
int sampleCount)
: INHERITED(info.fWidth, info.fHeight) {
- bool isOpaque;
- SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque);
+ SkBitmap::Config config = SkImageInfoToBitmapConfig(info);
fDevice = SkNEW_ARGS(SkGpuDevice, (ctx, config, info.fWidth, info.fHeight, sampleCount));
- if (!isOpaque) {
+ if (!SkAlphaTypeIsOpaque(info.fAlphaType)) {
fDevice->clear(0x0);
}
}
return NULL;
}
- bool isOpaque;
- SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque);
+ SkBitmap::Config config = SkImageInfoToBitmapConfig(info);
GrTextureDesc desc;
desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFlagBit;
return SkNEW_ARGS(SkSurface_Gpu, (ctx, tex->asRenderTarget()));
}
+
bool SkSurface_Raster::Valid(const SkImage::Info& info, size_t rowBytes) {
static const size_t kMaxTotalSize = SK_MaxS32;
- bool isOpaque;
- SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque);
+ SkBitmap::Config config = SkImageInfoToBitmapConfig(info);
int shift = 0;
switch (config) {
SkSurface_Raster::SkSurface_Raster(const SkImage::Info& info, void* pixels, size_t rb)
: INHERITED(info.fWidth, info.fHeight) {
- bool isOpaque;
- SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque);
-
- fBitmap.setConfig(config, info.fWidth, info.fHeight, rb);
+ SkBitmap::Config config = SkImageInfoToBitmapConfig(info);
+ fBitmap.setConfig(config, info.fWidth, info.fHeight, rb, info.fAlphaType);
fBitmap.setPixels(pixels);
- fBitmap.setIsOpaque(isOpaque);
fWeOwnThePixels = false; // We are "Direct"
}
SkSurface_Raster::SkSurface_Raster(const SkImage::Info& info, SkPixelRef* pr, size_t rb)
: INHERITED(info.fWidth, info.fHeight) {
- bool isOpaque;
- SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque);
-
- fBitmap.setConfig(config, info.fWidth, info.fHeight, rb);
+ SkBitmap::Config config = SkImageInfoToBitmapConfig(info);
+ fBitmap.setConfig(config, info.fWidth, info.fHeight, rb, info.fAlphaType);
fBitmap.setPixelRef(pr);
- fBitmap.setIsOpaque(isOpaque);
fWeOwnThePixels = true;
- if (!isOpaque) {
+ if (!SkAlphaTypeIsOpaque(info.fAlphaType)) {
fBitmap.eraseColor(SK_ColorTRANSPARENT);
}
}
}
// if the destination has no pixels then we must allocate them.
if (dst->isNull()) {
- dst->setConfig(src->getConfig(), w, h);
- dst->setIsOpaque(src->isOpaque());
+ dst->setConfig(src->getConfig(), w, h, 0, src->alphaType());
if (!this->allocPixelRef(dst, NULL)) {
SkDEBUGF(("failed to allocate pixels needed to crop the bitmap"));
SkScaledBitmapSampler sampler(width, height, getSampleSize());
- bm->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight());
- bm->setIsOpaque(true);
+ bm->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight(), 0,
+ kOpaque_SkAlphaType);
if (justBounds) {
return true;
#endif
if (1 == sampleSize && SkImageDecoder::kDecodeBounds_Mode == mode) {
- bm->setConfig(config, cinfo.image_width, cinfo.image_height);
- bm->setIsOpaque(config != SkBitmap::kA8_Config);
- return true;
+ return bm->setConfig(config, cinfo.image_width, cinfo.image_height, 0,
+ SkBitmap::kA8_Config == config ?
+ kPremul_SkAlphaType : kOpaque_SkAlphaType);
}
/* image_width and image_height are the original dimensions, available
if (SkImageDecoder::kDecodeBounds_Mode == mode && valid_output_dimensions(cinfo)) {
SkScaledBitmapSampler smpl(cinfo.output_width, cinfo.output_height,
recompute_sampleSize(sampleSize, cinfo));
- bm->setConfig(config, smpl.scaledWidth(), smpl.scaledHeight());
- bm->setIsOpaque(config != SkBitmap::kA8_Config);
- return true;
+ return bm->setConfig(config, smpl.scaledWidth(), smpl.scaledHeight(),
+ 0, SkBitmap::kA8_Config == config ?
+ kPremul_SkAlphaType : kOpaque_SkAlphaType);
} else {
return return_false(cinfo, *bm, "start_decompress");
}
}
SkScaledBitmapSampler sampler(cinfo.output_width, cinfo.output_height, sampleSize);
- bm->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight());
- bm->setIsOpaque(config != SkBitmap::kA8_Config);
+ bm->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight(), 0,
+ SkBitmap::kA8_Config != config ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
if (SkImageDecoder::kDecodeBounds_Mode == mode) {
return true;
}
SkScaledBitmapSampler sampler(width, height, skiaSampleSize);
SkBitmap bitmap;
- bitmap.setConfig(config, sampler.scaledWidth(), sampler.scaledHeight());
- bitmap.setIsOpaque(true);
+ bitmap.setConfig(config, sampler.scaledWidth(), sampler.scaledHeight(), 0,
+ kOpaque_SkAlphaType);
// Check ahead of time if the swap(dest, src) is possible or not.
// If yes, then we will stick to AllocPixelRef since it's cheaper with the
if (SkBitmap::kA8_Config == decodedBitmap->config()) {
reallyHasAlpha = true;
}
- decodedBitmap->setIsOpaque(!reallyHasAlpha);
+
+ SkAlphaType alphaType = kOpaque_SkAlphaType;
+ if (reallyHasAlpha) {
+ if (this->getRequireUnpremultipliedColors()) {
+ alphaType = kUnpremul_SkAlphaType;
+ } else {
+ alphaType = kPremul_SkAlphaType;
+ }
+ }
+ decodedBitmap->setAlphaType(alphaType);
return true;
}
if (SkBitmap::kA8_Config == decodedBitmap.config()) {
reallyHasAlpha = true;
}
- decodedBitmap.setIsOpaque(!reallyHasAlpha);
+ SkAlphaType alphaType = kOpaque_SkAlphaType;
+ if (reallyHasAlpha) {
+ if (this->getRequireUnpremultipliedColors()) {
+ alphaType = kUnpremul_SkAlphaType;
+ } else {
+ alphaType = kPremul_SkAlphaType;
+ }
+ }
+ decodedBitmap.setAlphaType(alphaType);
if (swapOnly) {
bm->swap(decodedBitmap);
return false;
}
- decodedBitmap->setConfig(config, width, height, 0);
-
- decodedBitmap->setIsOpaque(!fHasAlpha);
-
- return true;
+ return decodedBitmap->setConfig(config, width, height, 0,
+ fHasAlpha ? kPremul_SkAlphaType : kOpaque_SkAlphaType);
}
bool SkWEBPImageDecoder::onBuildTileIndex(SkStreamRewindable* stream,
int width = head.fWidth;
int height = head.fHeight;
- decodedBitmap->setConfig(SkBitmap::kIndex8_Config, width, height);
- decodedBitmap->setIsOpaque(true);
+ decodedBitmap->setConfig(SkBitmap::kIndex8_Config, width, height, 0,
+ kOpaque_SkAlphaType);
if (SkImageDecoder::kDecodeBounds_Mode == mode) {
return true;
bool SkImageRef::isOpaque(SkBitmap* bitmap) {
if (bitmap && bitmap->pixelRef() == this) {
bitmap->lockPixels();
- bitmap->setIsOpaque(fBitmap.isOpaque());
+ // what about colortables??????
+ bitmap->setAlphaType(fBitmap.alphaType());
bitmap->unlockPixels();
return true;
}
return false;
}
- bool isOpaque = false;
- SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque);
+ SkBitmap::Config config = SkImageInfoToBitmapConfig(info);
Target target;
// FIMXE: There will be a problem if this rowbytes is calculated differently from
// in SkLazyPixelRef.
target.fRowBytes = SkImageMinRowBytes(info);
-
- dst->setConfig(config, info.fWidth, info.fHeight, target.fRowBytes);
- dst->setIsOpaque(isOpaque);
+ dst->setConfig(config, info.fWidth, info.fHeight, target.fRowBytes, info.fAlphaType);
// fImageCache and fCacheSelector are mutually exclusive.
SkASSERT(NULL == fImageCache || NULL == fCacheSelector);
static bool init_from_info(SkBitmap* bm, const SkImage::Info& info,
size_t rowBytes) {
- bool isOpaque;
- SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque);
+ SkBitmap::Config config = SkImageInfoToBitmapConfig(info);
if (SkBitmap::kNo_Config == config) {
return false;
}
- bm->setConfig(config, info.fWidth, info.fHeight, rowBytes);
- bm->setIsOpaque(isOpaque);
- return bm->allocPixels();
+ return bm->setConfig(config, info.fWidth, info.fHeight, rowBytes, info.fAlphaType)
+ &&
+ bm->allocPixels();
}
bool SkLazyPixelRef::onImplementsDecodeInto() {
case kCGImageAlphaNoneSkipLast:
case kCGImageAlphaNoneSkipFirst:
SkASSERT(SkBitmap::ComputeIsOpaque(*bm));
- bm->setIsOpaque(true);
+ bm->setAlphaType(kOpaque_SkAlphaType);
break;
default:
// we don't know if we're opaque or not, so compute it.
- bm->computeAndSetOpaquePredicate();
+ if (SkBitmap::ComputeIsOpaque(*bm)) {
+ bm->setAlphaType(kOpaque_SkAlphaType);
+ }
}
if (!bm->isOpaque() && this->getRequireUnpremultipliedColors()) {
// CGBitmapContext does not support unpremultiplied, so the image has been premultiplied.
*addr = unpremultiply_pmcolor(*addr);
}
}
+ bm->setAlphaType(kUnpremul_SkAlphaType);
}
bm->unlockPixels();
return true;
);
// Note: we don't need to premultiply here since we specified PBGRA
- bm->computeAndSetOpaquePredicate();
+ if (ComputeIsOpaque(*bm)) {
+ bm->setAlphaType(kOpaque_SkAlphaType);
+ }
}
return SUCCEEDED(hr);
if (width != fBitmap.width() || height != fBitmap.height() || config != fConfig)
{
fConfig = config;
- fBitmap.setConfig(config, width, height);
+ fBitmap.setConfig(config, width, height, 0, kOpaque_SkAlphaType);
fBitmap.allocPixels();
- fBitmap.setIsOpaque(true);
this->setSize(SkIntToScalar(width), SkIntToScalar(height));
this->inval(NULL);
{
bitmap.setConfig(configs[configIndex], kWidth, kHeight);
REPORTER_ASSERT(reporter, bitmap.allocPixels());
- bitmap.setIsOpaque(true);
+ bitmap.setAlphaType(kOpaque_SkAlphaType);
bitmap.eraseColor(SK_ColorBLUE);
// Change rows [0,1] from blue to [red,green].
SkCanvas canvas(bitmap);
SkColorTable* ctOpaque = NULL;
SkColorTable* ctPremul = NULL;
- srcOpaque.setConfig(gPairs[i].fConfig, W, H);
- srcPremul.setConfig(gPairs[i].fConfig, W, H);
+ srcOpaque.setConfig(gPairs[i].fConfig, W, H, 0, kOpaque_SkAlphaType);
+ srcPremul.setConfig(gPairs[i].fConfig, W, H, 0, kPremul_SkAlphaType);
if (SkBitmap::kIndex8_Config == gPairs[i].fConfig) {
ctOpaque = init_ctable(kOpaque_SkAlphaType);
ctPremul = init_ctable(kPremul_SkAlphaType);
srcPremul.allocPixels(ctPremul);
SkSafeUnref(ctOpaque);
SkSafeUnref(ctPremul);
-
- srcOpaque.setIsOpaque(true);
- srcPremul.setIsOpaque(false);
}
init_src(srcOpaque);
init_src(srcPremul);
REPORTER_ASSERT(reporter, subset.width() == 1);
REPORTER_ASSERT(reporter, subset.height() == 1);
REPORTER_ASSERT(reporter,
- subset.isOpaque() == bitmap.isOpaque());
+ subset.alphaType() == bitmap.alphaType());
REPORTER_ASSERT(reporter,
subset.isVolatile() == true);
REPORTER_ASSERT(reporter,
(copy.getColorTable() != NULL) == hasCT);
}
-
bitmap = srcPremul;
bitmap.setIsVolatile(false);
if (bitmap.extractSubset(&subset, r)) {
REPORTER_ASSERT(reporter,
- subset.isOpaque() == bitmap.isOpaque());
+ subset.alphaType() == bitmap.alphaType());
REPORTER_ASSERT(reporter,
subset.isVolatile() == false);
}
SkColor color) {
bitmap.setConfig(config, width, height);
REPORTER_ASSERT(fReporter, bitmap.allocPixels());
- bitmap.setIsOpaque(true);
+ bitmap.setAlphaType(kOpaque_SkAlphaType);
bitmap.eraseColor(color);
}
paint.setStyle(SkPaint::kFill_Style);
SkBitmap bmp;
create(&bmp, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
- bmp.setIsOpaque(true);
+ bmp.setAlphaType(kOpaque_SkAlphaType);
SkShader* shader = SkShader::CreateBitmapShader(bmp,
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
paint.setShader(shader)->unref();
paint.setStyle(SkPaint::kFill_Style);
SkBitmap bmp;
create(&bmp, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
- bmp.setIsOpaque(false);
+ bmp.setAlphaType(kPremul_SkAlphaType);
SkShader* shader = SkShader::CreateBitmapShader(bmp,
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
paint.setShader(shader)->unref();
shader->unref();
// test 3: explicitly opaque
- bmp.setIsOpaque(true);
+ bmp.setAlphaType(kOpaque_SkAlphaType);
shader = SkShader::CreateBitmapShader(bmp,
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
REPORTER_ASSERT(reporter, shader);
shader->unref();
// test 4: explicitly not opaque
- bmp.setIsOpaque(false);
+ bmp.setAlphaType(kPremul_SkAlphaType);
shader = SkShader::CreateBitmapShader(bmp,
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
REPORTER_ASSERT(reporter, shader);