return info;
}
+ static SkImageInfo MakeUnknown(int width, int height) {
+ SkImageInfo info = {
+ width, height, kUnknown_SkColorType, kIgnore_SkAlphaType
+ };
+ return info;
+ }
+
int width() const { return fWidth; }
int height() const { return fHeight; }
SkColorType colorType() const { return fColorType; }
return false;
}
- // TODO: consider supporting other configs (e.g. 565, A8)
- if (fBitmap->config() != SkBitmap::kARGB_8888_Config) {
+ // TODO: consider supporting other colortypes (e.g. 565, A8)
+ if (fBitmap->colorType() != kPMColor_SkColorType) {
return false;
}
#endif
bool SkBitmapProcShader::CanDo(const SkBitmap& bm, TileMode tx, TileMode ty) {
- switch (bm.config()) {
- case SkBitmap::kA8_Config:
- case SkBitmap::kRGB_565_Config:
- case SkBitmap::kIndex8_Config:
- case SkBitmap::kARGB_8888_Config:
+ switch (bm.colorType()) {
+ case kAlpha_8_SkColorType:
+ case kRGB_565_SkColorType:
+ case kIndex_8_SkColorType:
+ case kPMColor_SkColorType:
// if (tx == ty && (kClamp_TileMode == tx || kRepeat_TileMode == tx))
return true;
default:
if (NULL == bm.pixelRef()) {
return false; // no pixels to read
}
- if (SkBitmap::kIndex8_Config == bm.config()) {
+ if (kIndex_8_SkColorType == bm.colorType()) {
// ugh, I have to lock-pixels to inspect the colortable
SkAutoLockPixels alp(bm);
if (!bm.getColorTable()) {
flags |= kOpaqueAlpha_Flag;
}
- switch (bitmap.config()) {
- case SkBitmap::kRGB_565_Config:
+ switch (bitmap.colorType()) {
+ case kRGB_565_SkColorType:
flags |= (kHasSpan16_Flag | kIntrinsicly16_Flag);
break;
- case SkBitmap::kIndex8_Config:
- case SkBitmap::kARGB_8888_Config:
+ case kIndex_8_SkColorType:
+ case kPMColor_SkColorType:
if (bitmapIsOpaque) {
flags |= kHasSpan16_Flag;
}
break;
- case SkBitmap::kA8_Config:
+ case kAlpha_8_SkColorType:
break; // never set kHasSpan16_Flag
default:
break;
}
- if (paint.isDither() && bitmap.config() != SkBitmap::kRGB_565_Config) {
+ if (paint.isDither() && bitmap.colorType() != kRGB_565_SkColorType) {
// gradients can auto-dither in their 16bit sampler, but we don't so
// we clear the flag here.
flags &= ~kHasSpan16_Flag;
return false;
}
- switch (bm.config()) {
- case SkBitmap::kARGB_8888_Config:
+ switch (bm.colorType()) {
+ case kPMColor_SkColorType:
*color = SkUnPreMultiply::PMColorToColor(*bm.getAddr32(0, 0));
return true;
- case SkBitmap::kRGB_565_Config:
+ case kRGB_565_SkColorType:
*color = SkPixel16ToColor(*bm.getAddr16(0, 0));
return true;
- case SkBitmap::kIndex8_Config:
+ case kIndex_8_SkColorType:
*color = SkUnPreMultiply::PMColorToColor(bm.getIndex8Color(0, 0));
return true;
default: // just skip the other configs for now
SkAutoLockPixels locker(source);
if (!source.readyToDraw() ||
- source.config() != SkBitmap::kARGB_8888_Config) {
+ source.colorType() != kPMColor_SkColorType) {
return false;
}
// Convolve into the result.
SkBitmap result;
- result.setConfig(SkBitmap::kARGB_8888_Config,
- destSubset.width(), destSubset.height(), 0,
- source.alphaType());
+ result.setConfig(SkImageInfo::MakeN32(destSubset.width(),
+ destSubset.height(),
+ source.alphaType()));
result.allocPixels(allocator, NULL);
if (!result.readyToDraw()) {
return false;
bool SkBitmap::scrollRect(const SkIRect* subset, int dx, int dy,
SkRegion* inval) const
{
- if (this->isImmutable()) {
+ if (this->isImmutable() || kUnknown_SkColorType == this->colorType()) {
return false;
}
tmp.scrollRect(NULL, dx, dy, inval);
}
- int shift;
-
- switch (this->config()) {
- case kIndex8_Config:
- case kA8_Config:
- shift = 0;
- break;
- case kARGB_4444_Config:
- case kRGB_565_Config:
- shift = 1;
- break;
- case kARGB_8888_Config:
- shift = 2;
- break;
- default:
- // can't scroll this config
- return false;
- }
-
+ int shift = this->bytesPerPixel() >> 1;
int width = this->width();
int height = this->height();
};
static XferInterp interpret_xfermode(const SkPaint& paint, SkXfermode* xfer,
- SkBitmap::Config deviceConfig) {
+ SkColorType deviceCT) {
SkXfermode::Mode mode;
if (SkXfermode::AsMode(xfer, &mode)) {
case SkXfermode::kSrcOver_Mode:
return kSrcOver_XferInterp;
case SkXfermode::kDstOver_Mode:
- if (SkBitmap::kRGB_565_Config == deviceConfig) {
+ if (kRGB_565_SkColorType == deviceCT) {
return kSkipDrawing_XferInterp;
}
break;
case SkXfermode::kSrcIn_Mode:
- if (SkBitmap::kRGB_565_Config == deviceConfig &&
+ if (kRGB_565_SkColorType == deviceCT &&
just_solid_color(paint)) {
return kSrcOver_XferInterp;
}
// which check, in case we're being called by a client with a dummy device
// (e.g. they have a bounder that always aborts the draw)
- if (SkBitmap::kNo_Config == device.config() ||
- (drawCoverage && (SkBitmap::kA8_Config != device.config()))) {
+ if (kUnknown_SkColorType == device.colorType() ||
+ (drawCoverage && (kAlpha_8_SkColorType != device.colorType()))) {
SK_PLACEMENT_NEW(blitter, SkNullBlitter, storage, storageSize);
return blitter;
}
}
if (NULL != mode) {
- switch (interpret_xfermode(*paint, mode, device.config())) {
+ switch (interpret_xfermode(*paint, mode, device.colorType())) {
case kSrcOver_XferInterp:
mode = NULL;
paint.writable()->setXfermode(NULL);
}
- switch (device.config()) {
- case SkBitmap::kA8_Config:
+ switch (device.colorType()) {
+ case kAlpha_8_SkColorType:
if (drawCoverage) {
SkASSERT(NULL == shader);
SkASSERT(NULL == paint->getXfermode());
}
break;
- case SkBitmap::kRGB_565_Config:
+ case kRGB_565_SkColorType:
blitter = SkBlitter_ChooseD565(device, *paint, storage, storageSize);
break;
- case SkBitmap::kARGB_8888_Config:
+ case kPMColor_SkColorType:
if (shader) {
SK_PLACEMENT_NEW_ARGS(blitter, SkARGB32_Shader_Blitter,
storage, storageSize, (device, *paint));
SkSpriteBlitter* blitter;
- switch (device.config()) {
- case SkBitmap::kRGB_565_Config:
+ switch (device.colorType()) {
+ case kRGB_565_SkColorType:
blitter = SkSpriteBlitter::ChooseD16(source, paint, storage,
storageSize);
break;
- case SkBitmap::kARGB_8888_Config:
+ case kPMColor_SkColorType:
blitter = SkSpriteBlitter::ChooseD32(source, paint, storage,
storageSize);
break;
inc_canvas();
SkBitmap bitmap;
- bitmap.setConfig(SkBitmap::kNo_Config, width, height);
+ bitmap.setConfig(SkImageInfo::MakeUnknown(width, height));
this->init(SkNEW_ARGS(SkBitmapDevice, (bitmap)))->unref();
}
if (dev) {
return dev->imageInfo();
} else {
- // TODO: need a real unknown for alphatype it seems.
- SkAlphaType unknownAlphaType = kIgnore_SkAlphaType;
- return SkImageInfo::Make(0, 0, kUnknown_SkColorType, unknownAlphaType);
+ return SkImageInfo::MakeUnknown(0, 0);
}
}
// TODO: should make this guy pure-virtual.
SkImageInfo SkBaseDevice::imageInfo() const {
- return SkImageInfo::Make(this->width(), this->height(),
- kUnknown_SkColorType, kIgnore_SkAlphaType);
+ return SkImageInfo::MakeUnknown(this->width(), this->height());
}
const SkBitmap& SkBaseDevice::accessBitmap(bool changePixels) {
should I worry about dithering for the lower depths?
*/
SkPMColor pmc = SkPreMultiplyColor(color);
- switch (bitmap.config()) {
- case SkBitmap::kARGB_8888_Config:
+ switch (bitmap.colorType()) {
+ case kPMColor_SkColorType:
if (data) {
*data = pmc;
}
// SkDebugf("--- D32_Src_BitmapXferProc\n");
return D32_Src_BitmapXferProc;
- case SkBitmap::kRGB_565_Config:
+ case kRGB_565_SkColorType:
if (data) {
*data = SkPixel32ToPixel16(pmc);
}
// SkDebugf("--- D16_Src_BitmapXferProc\n");
return D16_Src_BitmapXferProc;
- case SkBitmap::kA8_Config:
+ case kAlpha_8_SkColorType:
if (data) {
*data = SkGetPackedA32(pmc);
}
static void CallBitmapXferProc(const SkBitmap& bitmap, const SkIRect& rect,
BitmapXferProc proc, uint32_t procData) {
int shiftPerPixel;
- switch (bitmap.config()) {
- case SkBitmap::kARGB_8888_Config:
+ switch (bitmap.colorType()) {
+ case kPMColor_SkColorType:
shiftPerPixel = 2;
break;
- case SkBitmap::kRGB_565_Config:
+ case kRGB_565_SkColorType:
shiftPerPixel = 1;
break;
- case SkBitmap::kA8_Config:
+ case kAlpha_8_SkColorType:
shiftPerPixel = 0;
break;
default:
if (SkCanvas::kPoints_PointMode == fMode && fClip->isRect()) {
uint32_t value;
const SkBitmap* bm = blitter->justAnOpaqueColor(&value);
- if (bm && SkBitmap::kRGB_565_Config == bm->config()) {
+ if (bm && kRGB_565_SkColorType == bm->colorType()) {
proc = bw_pt_rect_16_hair_proc;
- } else if (bm && SkBitmap::kARGB_8888_Config == bm->config()) {
+ } else if (bm && kPMColor_SkColorType == bm->colorType()) {
proc = bw_pt_rect_32_hair_proc;
} else {
proc = bw_pt_rect_hair_proc;
void SkDraw::drawBitmapAsMask(const SkBitmap& bitmap,
const SkPaint& paint) const {
- SkASSERT(bitmap.config() == SkBitmap::kA8_Config);
+ SkASSERT(bitmap.colorType() == kAlpha_8_SkColorType);
if (just_translate(*fMatrix, bitmap)) {
int ix = SkScalarRoundToInt(fMatrix->getTranslateX());
// nothing to draw
if (fRC->isEmpty() ||
bitmap.width() == 0 || bitmap.height() == 0 ||
- bitmap.config() == SkBitmap::kNo_Config) {
+ bitmap.colorType() == kUnknown_SkColorType) {
return;
}
}
}
- if (bitmap.config() != SkBitmap::kA8_Config &&
+ if (bitmap.colorType() != kAlpha_8_SkColorType &&
just_translate(matrix, bitmap)) {
//
// It is safe to call lock pixels now, since we know the matrix is
SkDraw draw(*this);
draw.fMatrix = &matrix;
- if (bitmap.config() == SkBitmap::kA8_Config) {
+ if (bitmap.colorType() == kAlpha_8_SkColorType) {
draw.drawBitmapAsMask(bitmap, paint);
} else {
SkAutoBitmapShaderInstall install(bitmap, paint);
// nothing to draw
if (fRC->isEmpty() ||
bitmap.width() == 0 || bitmap.height() == 0 ||
- bitmap.config() == SkBitmap::kNo_Config) {
+ bitmap.colorType() == kUnknown_SkColorType) {
return;
}
return false;
}
- // can relax when we have bitmap::asImageInfo
- if (SkBitmap::kARGB_8888_Config != bitmap->config()) {
+ // can we relax this?
+ if (kPMColor_SkColorType != bitmap->colorType()) {
return false;
}
- SkImageInfo info = SkImageInfo::MakeN32(bitmap->width(), bitmap->height(),
- bitmap->alphaType());
+ SkImageInfo info = bitmap->info();
bitmap->setPixelRef(SkNEW_ARGS(SkOneShotDiscardablePixelRef,
(info, dm, bitmap->rowBytes())))->unref();
bitmap->lockPixels();
const SkMaskGamma::PreBlend& maskPreBlend) {
#define SAMPLES_PER_PIXEL 4
#define LCD_PER_PIXEL 3
- SkASSERT(SkBitmap::kA8_Config == src.config());
+ SkASSERT(kAlpha_8_SkColorType == src.colorType());
SkASSERT(SkMask::kLCD16_Format == dst.fFormat);
const int sample_width = src.width();
template<bool APPLY_PREBLEND>
static void pack4xHToLCD32(const SkBitmap& src, const SkMask& dst,
const SkMaskGamma::PreBlend& maskPreBlend) {
- SkASSERT(SkBitmap::kA8_Config == src.config());
+ SkASSERT(kAlpha_8_SkColorType == src.colorType());
SkASSERT(SkMask::kLCD32_Format == dst.fFormat);
const int width = dst.fBounds.width();
class Sprite_D32_S32 : public SkSpriteBlitter {
public:
Sprite_D32_S32(const SkBitmap& src, U8CPU alpha) : INHERITED(src) {
- SkASSERT(src.config() == SkBitmap::kARGB_8888_Config);
+ SkASSERT(src.colorType() == kPMColor_SkColorType);
unsigned flags32 = 0;
if (255 != alpha) {
SkColorFilter* filter = paint.getColorFilter();
SkSpriteBlitter* blitter = NULL;
- switch (source.config()) {
- case SkBitmap::kARGB_4444_Config:
+ switch (source.colorType()) {
+ case kARGB_4444_SkColorType:
if (alpha != 0xFF) {
return NULL; // we only have opaque sprites
}
storage, storageSize, (source));
}
break;
- case SkBitmap::kARGB_8888_Config:
+ case kPMColor_SkColorType:
if (xfermode || filter) {
if (255 == alpha) {
// this can handle xfermode or filter, but not alpha
SkSpriteBlitter* blitter = NULL;
unsigned alpha = paint.getAlpha();
- switch (source.config()) {
- case SkBitmap::kARGB_8888_Config:
+ switch (source.colorType()) {
+ case kPMColor_SkColorType:
SK_PLACEMENT_NEW_ARGS(blitter, Sprite_D16_S32_BlitRowProc,
storage, storageSize, (source));
break;
- case SkBitmap::kARGB_4444_Config:
+ case kARGB_4444_SkColorType:
if (255 == alpha) {
SK_PLACEMENT_NEW_ARGS(blitter, Sprite_D16_S4444_Opaque,
storage, storageSize, (source));
storage, storageSize, (source, alpha >> 4));
}
break;
- case SkBitmap::kRGB_565_Config:
+ case kRGB_565_SkColorType:
if (255 == alpha) {
SK_PLACEMENT_NEW_ARGS(blitter, Sprite_D16_S16_Opaque,
storage, storageSize, (source));
storage, storageSize, (source, alpha));
}
break;
- case SkBitmap::kIndex8_Config:
+ case kIndex_8_SkColorType:
if (paint.isDither()) {
// we don't support dither yet in these special cases
break;
static SkBitmap make_fake_bitmap(int width, int height) {
SkBitmap bitmap;
- bitmap.setConfig(SkBitmap::kNo_Config, width, height);
+ bitmap.setConfig(SkImageInfo::MakeUnknown(width, height));
return bitmap;
}
+// TODO: should inherit from SkBaseDevice instead of SkBitmapDevice...
SkXPSDevice::SkXPSDevice()
: SkBitmapDevice(make_fake_bitmap(10000, 10000))
, fCurrentPage(0) {
|| (!dst->setConfig(info, 0))) {
return false;
}
- SkASSERT(dst->config() != SkBitmap::kNo_Config);
+ SkASSERT(dst->colorType() != kUnknown_SkColorType);
if (dst->empty()) { // Use a normal pixelref.
return dst->allocPixels();
}
static inline SkBitmap makeContentBitmap(const SkISize& contentSize,
const SkMatrix* initialTransform) {
- SkBitmap bitmap;
+ SkImageInfo info;
if (initialTransform) {
// Compute the size of the drawing area.
SkVector drawingSize;
}
inverse.mapVectors(&drawingSize, 1);
SkISize size = SkSize::Make(drawingSize.fX, drawingSize.fY).toRound();
- bitmap.setConfig(SkBitmap::kNo_Config, abs(size.fWidth),
- abs(size.fHeight));
+ info = SkImageInfo::MakeUnknown(abs(size.fWidth), abs(size.fHeight));
} else {
- bitmap.setConfig(SkBitmap::kNo_Config, abs(contentSize.fWidth),
- abs(contentSize.fHeight));
+ info = SkImageInfo::MakeUnknown(abs(contentSize.fWidth),
+ abs(contentSize.fHeight));
}
+ SkBitmap bitmap;
+ bitmap.setConfig(info);
return bitmap;
}
// TODO(vandebo) change pageSize to SkSize.
+// TODO: inherit from SkBaseDevice instead of SkBitmapDevice
SkPDFDevice::SkPDFDevice(const SkISize& pageSize, const SkISize& contentSize,
const SkMatrix& initialTransform)
: SkBitmapDevice(makeContentBitmap(contentSize, &initialTransform)),
GatherPixelRefDevice(int width, int height, PixelRefSet* prset) {
fSize.set(width, height);
- fEmptyBitmap.setConfig(SkBitmap::kNo_Config, width, height);
+ fEmptyBitmap.setConfig(SkImageInfo::MakeUnknown(width, height));
fPRSet = prset;
}