sk_bzero(this, sizeof(*this));
}
-#ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG
-SkBitmap::Config SkBitmap::config() const {
- return SkColorTypeToBitmapConfig(fInfo.colorType());
-}
-#endif
-
void SkBitmap::getBounds(SkRect* bounds) const {
SkASSERT(bounds);
bounds->set(0, 0,
- SkIntToScalar(fInfo.fWidth), SkIntToScalar(fInfo.fHeight));
+ SkIntToScalar(fInfo.width()), SkIntToScalar(fInfo.height()));
}
void SkBitmap::getBounds(SkIRect* bounds) const {
SkASSERT(bounds);
- bounds->set(0, 0, fInfo.fWidth, fInfo.fHeight);
+ bounds->set(0, 0, fInfo.width(), fInfo.height());
}
///////////////////////////////////////////////////////////////////////////////
-bool SkBitmap::setInfo(const SkImageInfo& origInfo, size_t rowBytes) {
- SkImageInfo info = origInfo;
-
- if (!SkColorTypeValidateAlphaType(info.fColorType, info.fAlphaType,
- &info.fAlphaType)) {
+bool SkBitmap::setInfo(const SkImageInfo& info, size_t rowBytes) {
+ SkAlphaType newAT = info.alphaType();
+ if (!SkColorTypeValidateAlphaType(info.colorType(), info.alphaType(), &newAT)) {
return reset_return_false(this);
}
+ // don't look at info.alphaType(), since newAT is the real value...
// require that rowBytes fit in 31bits
int64_t mrb = info.minRowBytes64();
this->freePixels();
- fInfo = info;
+ fInfo = info.makeAlphaType(newAT);
fRowBytes = SkToU32(rowBytes);
return true;
}
-bool SkBitmap::setAlphaType(SkAlphaType alphaType) {
- if (!SkColorTypeValidateAlphaType(fInfo.fColorType, alphaType, &alphaType)) {
+bool SkBitmap::setAlphaType(SkAlphaType newAlphaType) {
+ if (!SkColorTypeValidateAlphaType(fInfo.colorType(), newAlphaType, &newAlphaType)) {
return false;
}
- if (fInfo.fAlphaType != alphaType) {
- fInfo.fAlphaType = alphaType;
+ if (fInfo.alphaType() != newAlphaType) {
+ fInfo = fInfo.makeAlphaType(newAlphaType);
if (fPixelRef) {
- fPixelRef->changeAlphaType(alphaType);
+ fPixelRef->changeAlphaType(newAlphaType);
}
}
return true;
}
void SkBitmap::updatePixelsFromRef() const {
- if (NULL != fPixelRef) {
+ if (fPixelRef) {
if (fPixelLockCount > 0) {
SkASSERT(fPixelRef->isLocked());
void* p = fPixelRef->pixels();
- if (NULL != p) {
+ if (p) {
p = (char*)p
+ fPixelRefOrigin.fY * fRowBytes
+ fPixelRefOrigin.fX * fInfo.bytesPerPixel();
if (pr) {
if (kUnknown_SkColorType != fInfo.colorType()) {
const SkImageInfo& prInfo = pr->info();
- SkASSERT(fInfo.fWidth <= prInfo.fWidth);
- SkASSERT(fInfo.fHeight <= prInfo.fHeight);
- SkASSERT(fInfo.fColorType == prInfo.fColorType);
- switch (prInfo.fAlphaType) {
+ SkASSERT(fInfo.width() <= prInfo.width());
+ SkASSERT(fInfo.height() <= prInfo.height());
+ SkASSERT(fInfo.colorType() == prInfo.colorType());
+ switch (prInfo.alphaType()) {
case kIgnore_SkAlphaType:
- SkASSERT(fInfo.fAlphaType == kIgnore_SkAlphaType);
+ SkASSERT(fInfo.alphaType() == kIgnore_SkAlphaType);
break;
case kOpaque_SkAlphaType:
case kPremul_SkAlphaType:
- SkASSERT(fInfo.fAlphaType == kOpaque_SkAlphaType ||
- fInfo.fAlphaType == kPremul_SkAlphaType);
+ SkASSERT(fInfo.alphaType() == kOpaque_SkAlphaType ||
+ fInfo.alphaType() == kPremul_SkAlphaType);
break;
case kUnpremul_SkAlphaType:
- SkASSERT(fInfo.fAlphaType == kOpaque_SkAlphaType ||
- fInfo.fAlphaType == kUnpremul_SkAlphaType);
+ SkASSERT(fInfo.alphaType() == kOpaque_SkAlphaType ||
+ fInfo.alphaType() == kUnpremul_SkAlphaType);
break;
}
}
if (pr) {
const SkImageInfo& info = pr->info();
- fPixelRefOrigin.set(SkPin32(dx, 0, info.fWidth),
- SkPin32(dy, 0, info.fHeight));
+ fPixelRefOrigin.set(SkPin32(dx, 0, info.width()), SkPin32(dy, 0, info.height()));
} else {
// ignore dx,dy if there is no pixelref
fPixelRefOrigin.setZero();
}
void SkBitmap::lockPixels() const {
- if (NULL != fPixelRef && 0 == sk_atomic_inc(&fPixelLockCount)) {
+ if (fPixelRef && 0 == sk_atomic_inc(&fPixelLockCount)) {
fPixelRef->lockPixels();
this->updatePixelsFromRef();
}
void SkBitmap::unlockPixels() const {
SkASSERT(NULL == fPixelRef || fPixelLockCount > 0);
- if (NULL != fPixelRef && 1 == sk_atomic_dec(&fPixelLockCount)) {
+ if (fPixelRef && 1 == sk_atomic_dec(&fPixelLockCount)) {
fPixelRef->unlockPixels();
this->updatePixelsFromRef();
}
SkDEBUGCODE(this->validate();)
}
-bool SkBitmap::allocPixels(Allocator* allocator, SkColorTable* ctable) {
+bool SkBitmap::tryAllocPixels(Allocator* allocator, SkColorTable* ctable) {
HeapAllocator stdalloc;
if (NULL == allocator) {
///////////////////////////////////////////////////////////////////////////////
-bool SkBitmap::allocPixels(const SkImageInfo& requestedInfo, size_t rowBytes) {
+bool SkBitmap::tryAllocPixels(const SkImageInfo& requestedInfo, size_t rowBytes) {
if (kIndex_8_SkColorType == requestedInfo.colorType()) {
return reset_return_false(this);
}
return true;
}
-bool SkBitmap::allocPixels(const SkImageInfo& requestedInfo, SkPixelRefFactory* factory,
- SkColorTable* ctable) {
- if (kIndex_8_SkColorType == requestedInfo.fColorType && NULL == ctable) {
+bool SkBitmap::tryAllocPixels(const SkImageInfo& requestedInfo, SkPixelRefFactory* factory,
+ SkColorTable* ctable) {
+ if (kIndex_8_SkColorType == requestedInfo.colorType() && NULL == ctable) {
return reset_return_false(this);
}
if (!this->setInfo(requestedInfo)) {
///////////////////////////////////////////////////////////////////////////////
void SkBitmap::freePixels() {
- if (NULL != fPixelRef) {
+ if (fPixelRef) {
if (fPixelLockCount > 0) {
fPixelRef->unlockPixels();
}
SkAutoLockPixels lock(*this);
const uint8_t* srcP = reinterpret_cast<const uint8_t*>(getPixels());
uint8_t* dstP = reinterpret_cast<uint8_t*>(dst);
- for (int row = 0; row < fInfo.fHeight;
- row++, srcP += fRowBytes, dstP += dstRowBytes) {
+ for (int row = 0; row < fInfo.height(); row++, srcP += fRowBytes, dstP += dstRowBytes) {
memcpy(dstP, srcP, rowBytes);
}
return false;
}
- SkImageInfo dstInfo = requestedDstInfo;
// the intersect may have shrunk info's logical size
- dstInfo.fWidth = srcR.width();
- dstInfo.fHeight = srcR.height();
+ const SkImageInfo dstInfo = requestedDstInfo.makeWH(srcR.width(), srcR.height());
// if x or y are negative, then we have to adjust pixels
if (x > 0) {
return false;
}
- SkImageInfo srcInfo = this->info();
- srcInfo.fWidth = dstInfo.width();
- srcInfo.fHeight = dstInfo.height();
+ const SkImageInfo srcInfo = this->info().makeWH(dstInfo.width(), dstInfo.height());
const void* srcPixels = this->getAddr(srcR.x(), srcR.y());
return SkPixelInfo::CopyPixels(dstInfo, dstPixels, dstRB, srcInfo, srcPixels, this->rowBytes(),
// The only way to be readyToDraw is if fPixelRef is non NULL.
SkASSERT(fPixelRef != NULL);
- SkImageInfo dstInfo = src->info();
- dstInfo.fColorType = dstColorType;
+ const SkImageInfo dstInfo = src->info().makeColorType(dstColorType);
SkBitmap tmpDst;
if (!tmpDst.setInfo(dstInfo)) {
// TODO: can we just ref() the src colortable? Is it reentrant-safe?
ctable.reset(SkNEW_ARGS(SkColorTable, (*src->getColorTable())));
}
- if (!tmpDst.allocPixels(alloc, ctable)) {
+ if (!tmpDst.tryAllocPixels(alloc, ctable)) {
return false;
}
rowBytes = 0;
}
- SkImageInfo info = fInfo;
- info.fColorType = dstCT;
+ const SkImageInfo info = fInfo.makeColorType(dstCT);
if (!dst->setInfo(info, rowBytes)) {
return false;
}
SkMaskFilter* filter = paint ? paint->getMaskFilter() : NULL;
// compute our (larger?) dst bounds if we have a filter
- if (NULL != filter) {
+ if (filter) {
identity.reset();
srcM.fImage = NULL;
if (!filter->filterMask(&dstM, srcM, identity, NULL)) {
} else {
NO_FILTER_CASE:
tmpBitmap.setInfo(SkImageInfo::MakeA8(this->width(), this->height()), srcM.fRowBytes);
- if (!tmpBitmap.allocPixels(allocator, NULL)) {
+ if (!tmpBitmap.tryAllocPixels(allocator, NULL)) {
// Allocation of pixels for alpha bitmap failed.
SkDebugf("extractAlpha failed to allocate (%d,%d) alpha bitmap\n",
tmpBitmap.width(), tmpBitmap.height());
tmpBitmap.setInfo(SkImageInfo::MakeA8(dstM.fBounds.width(), dstM.fBounds.height()),
dstM.fRowBytes);
- if (!tmpBitmap.allocPixels(allocator, NULL)) {
+ if (!tmpBitmap.tryAllocPixels(allocator, NULL)) {
// Allocation of pixels for alpha bitmap failed.
SkDebugf("extractAlpha failed to allocate (%d,%d) alpha bitmap\n",
tmpBitmap.width(), tmpBitmap.height());
return false;
}
- char* dst = (char*)sk_malloc_throw(ramSize);
+ SkAutoDataUnref data(SkData::NewUninitialized(ramSize));
+ char* dst = (char*)data->writable_data();
buffer->readByteArray(dst, snugSize);
- SkAutoDataUnref data(SkData::NewFromMalloc(dst, ramSize));
if (snugSize != ramSize) {
const char* srcRow = dst + snugRB * (height - 1);
SkASSERT(fPixelRefOrigin.fX >= 0);
SkASSERT(fPixelRefOrigin.fY >= 0);
SkASSERT(fPixelRef->info().width() >= (int)this->width() + fPixelRefOrigin.fX);
- SkASSERT(fPixelRef->info().fHeight >= (int)this->height() + fPixelRefOrigin.fY);
+ SkASSERT(fPixelRef->info().height() >= (int)this->height() + fPixelRefOrigin.fY);
SkASSERT(fPixelRef->rowBytes() >= fInfo.minRowBytes());
} else {
SkASSERT(NULL == fColorTable);
str->appendf(" pixels:%p", this->getPixels());
} else {
const char* uri = pr->getURI();
- if (NULL != uri) {
+ if (uri) {
str->appendf(" uri:\"%s\"", uri);
} else {
str->appendf(" pixelref:%p", pr);