use colortype instead of config

clone of https://codereview.chromium.org/305133006/

TBR=

BUG=skia:

Author: reed@google.com

Review URL: https://codereview.chromium.org/301233011
This commit is contained in:
reed 2014-06-02 13:07:26 -07:00 коммит произвёл Commit bot
Родитель 80f709a0d7
Коммит c77392ed58
19 изменённых файлов: 67 добавлений и 76 удалений

Просмотреть файл

@ -189,6 +189,14 @@ struct SkImageInfo {
SkISize dimensions() const { return SkISize::Make(fWidth, fHeight); }
/**
* Return a new ImageInfo with the same colortype and alphatype as this info,
* but with the specified width and height.
*/
SkImageInfo makeWH(int newWidth, int newHeight) const {
return SkImageInfo::Make(newWidth, newHeight, fColorType, fAlphaType);
}
int bytesPerPixel() const {
return SkColorTypeBytesPerPixel(fColorType);
}

Просмотреть файл

@ -323,8 +323,7 @@ bool SkAlphaThresholdFilterImpl::onFilterImage(Proxy*, const SkBitmap& src,
return false;
}
dst->setConfig(src.config(), src.width(), src.height());
if (!dst->allocPixels()) {
if (!dst->allocPixels(src.info())) {
return false;
}

Просмотреть файл

@ -107,8 +107,7 @@ bool SkBicubicImageFilter::onFilterImage(Proxy* proxy,
if (dstIRect.isEmpty()) {
return false;
}
result->setConfig(src.config(), dstIRect.width(), dstIRect.height());
if (!result->allocPixels()) {
if (!result->allocPixels(src.info().makeWH(dstIRect.width(), dstIRect.height()))) {
return false;
}

Просмотреть файл

@ -163,11 +163,10 @@ bool SkBlurImageFilter::onFilterImage(Proxy* proxy,
return false;
}
dst->setConfig(src.config(), srcBounds.width(), srcBounds.height());
dst->getBounds(&dstBounds);
if (!dst->allocPixels()) {
if (!dst->allocPixels(src.info().makeWH(srcBounds.width(), srcBounds.height()))) {
return false;
}
dst->getBounds(&dstBounds);
SkVector sigma = SkVector::Make(fSigma.width(), fSigma.height());
ctx.ctm().mapVectors(&sigma, 1);
@ -191,8 +190,7 @@ bool SkBlurImageFilter::onFilterImage(Proxy* proxy,
}
SkBitmap temp;
temp.setConfig(dst->config(), dst->width(), dst->height());
if (!temp.allocPixels()) {
if (!temp.allocPixels(dst->info())) {
return false;
}

Просмотреть файл

@ -227,8 +227,7 @@ bool SkDisplacementMapEffect::onFilterImage(Proxy* proxy,
return false;
}
dst->setConfig(color.config(), bounds.width(), bounds.height());
if (!dst->allocPixels()) {
if (!dst->allocPixels(color.info().makeWH(bounds.width(), bounds.height()))) {
return false;
}

Просмотреть файл

@ -960,8 +960,7 @@ bool SkDiffuseLightingImageFilter::onFilterImage(Proxy* proxy,
return false;
}
dst->setConfig(src.config(), bounds.width(), bounds.height());
if (!dst->allocPixels()) {
if (!dst->allocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
return false;
}
@ -1052,9 +1051,7 @@ bool SkSpecularLightingImageFilter::onFilterImage(Proxy* proxy,
return false;
}
dst->setConfig(src.config(), bounds.width(), bounds.height());
dst->allocPixels();
if (!dst->getPixels()) {
if (!dst->allocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
return false;
}

Просмотреть файл

@ -298,9 +298,7 @@ bool SkMagnifierImageFilter::onFilterImage(Proxy*, const SkBitmap& src,
return false;
}
dst->setConfig(src.config(), src.width(), src.height());
dst->allocPixels();
if (!dst->getPixels()) {
if (!dst->allocPixels(src.info())) {
return false;
}

Просмотреть файл

@ -238,9 +238,7 @@ static SkBitmap unpremultiplyBitmap(const SkBitmap& src)
return SkBitmap();
}
SkBitmap result;
result.setConfig(src.config(), src.width(), src.height());
result.allocPixels();
if (!result.getPixels()) {
if (!result.allocPixels(src.info())) {
return SkBitmap();
}
for (int y = 0; y < src.height(); ++y) {

Просмотреть файл

@ -163,9 +163,7 @@ bool SkMorphologyImageFilter::filterImageGeneric(SkMorphologyImageFilter::Proc p
return false;
}
dst->setConfig(src.config(), bounds.width(), bounds.height());
dst->allocPixels();
if (!dst->getPixels()) {
if (!dst->allocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
return false;
}
@ -190,8 +188,7 @@ bool SkMorphologyImageFilter::filterImageGeneric(SkMorphologyImageFilter::Proc p
}
SkBitmap temp;
temp.setConfig(dst->config(), dst->width(), dst->height());
if (!temp.allocPixels()) {
if (!temp.allocPixels(dst->info())) {
return false;
}

Просмотреть файл

@ -16,7 +16,7 @@ void S32_opaque_D32_filter_DX_SSE2(const SkBitmapProcState& s,
int count, uint32_t* colors) {
SkASSERT(count > 0 && colors != NULL);
SkASSERT(s.fFilterLevel != SkPaint::kNone_FilterLevel);
SkASSERT(s.fBitmap->config() == SkBitmap::kARGB_8888_Config);
SkASSERT(kN32_SkColorType == s.fBitmap->colorType());
SkASSERT(s.fAlphaScale == 256);
const char* srcAddr = static_cast<const char*>(s.fBitmap->getPixels());
@ -122,7 +122,7 @@ void S32_alpha_D32_filter_DX_SSE2(const SkBitmapProcState& s,
int count, uint32_t* colors) {
SkASSERT(count > 0 && colors != NULL);
SkASSERT(s.fFilterLevel != SkPaint::kNone_FilterLevel);
SkASSERT(s.fBitmap->config() == SkBitmap::kARGB_8888_Config);
SkASSERT(kN32_SkColorType == s.fBitmap->colorType());
SkASSERT(s.fAlphaScale < 256);
const char* srcAddr = static_cast<const char*>(s.fBitmap->getPixels());
@ -642,7 +642,7 @@ void S32_D16_filter_DX_SSE2(const SkBitmapProcState& s,
int count, uint16_t* colors) {
SkASSERT(count > 0 && colors != NULL);
SkASSERT(s.fFilterLevel != SkPaint::kNone_FilterLevel);
SkASSERT(s.fBitmap->config() == SkBitmap::kARGB_8888_Config);
SkASSERT(kN32_SkColorType == s.fBitmap->colorType());
SkASSERT(s.fBitmap->isOpaque());
SkPMColor dstColor;

Просмотреть файл

@ -395,7 +395,7 @@ void S32_generic_D32_filter_DX_SSSE3(const SkBitmapProcState& s,
int count, uint32_t* colors) {
SkASSERT(count > 0 && colors != NULL);
SkASSERT(s.fFilterLevel != SkPaint::kNone_FilterLevel);
SkASSERT(s.fBitmap->config() == SkBitmap::kARGB_8888_Config);
SkASSERT(kN32_SkColorType == s.fBitmap->colorType());
if (has_alpha) {
SkASSERT(s.fAlphaScale < 256);
} else {
@ -587,7 +587,7 @@ void S32_generic_D32_filter_DXDY_SSSE3(const SkBitmapProcState& s,
int count, uint32_t* colors) {
SkASSERT(count > 0 && colors != NULL);
SkASSERT(s.fFilterLevel != SkPaint::kNone_FilterLevel);
SkASSERT(s.fBitmap->config() == SkBitmap::kARGB_8888_Config);
SkASSERT(kN32_SkColorType == s.fBitmap->colorType());
if (has_alpha) {
SkASSERT(s.fAlphaScale < 256);
} else {

Просмотреть файл

@ -202,8 +202,8 @@ void SkBitmapProcState::platformProcs() {
justDx = true;
}
switch (fBitmap->config()) {
case SkBitmap::kIndex8_Config:
switch (fBitmap->colorType()) {
case kIndex_8_SkColorType:
if (justDx && SkPaint::kNone_FilterLevel == fFilterLevel) {
#if 0 /* crashing on android device */
fSampleProc16 = SI8_D16_nofilter_DX_arm;

Просмотреть файл

@ -24,7 +24,7 @@ SkBlitMask::ColorProc SkBlitMask::PlatformColorProcs(SkColorType dstCT,
return NULL;
}
#endif
if ((SkBitmap::kARGB_8888_Config == dstConfig) &&
if ((kN32_SkColorType == dstCT) &&
(SkMask::kA8_Format == maskFormat)) {
return D32_A8_Factory_neon(color);
}

Просмотреть файл

@ -27,16 +27,17 @@ static bool skip_compression(SkPDFCatalog* catalog) {
static size_t get_uncompressed_size(const SkBitmap& bitmap,
const SkIRect& srcRect) {
switch (bitmap.config()) {
case SkBitmap::kIndex8_Config:
switch (bitmap.colorType()) {
case kIndex_8_SkColorType:
return srcRect.width() * srcRect.height();
case SkBitmap::kARGB_4444_Config:
case kARGB_4444_SkColorType:
return ((srcRect.width() * 3 + 1) / 2) * srcRect.height();
case SkBitmap::kRGB_565_Config:
case kRGB_565_SkColorType:
return srcRect.width() * 3 * srcRect.height();
case SkBitmap::kARGB_8888_Config:
case kRGBA_8888_SkColorType:
case kBGRA_8888_SkColorType:
return srcRect.width() * 3 * srcRect.height();
case SkBitmap::kA8_Config:
case kAlpha_8_SkColorType:
return 1;
default:
SkASSERT(false);
@ -208,9 +209,9 @@ static SkStream* create_black_image() {
static SkStream* extract_image_data(const SkBitmap& bitmap,
const SkIRect& srcRect,
bool extractAlpha, bool* isTransparent) {
SkBitmap::Config config = bitmap.config();
if (extractAlpha && (config == SkBitmap::kIndex8_Config ||
config == SkBitmap::kRGB_565_Config)) {
SkColorType colorType = bitmap.colorType();
if (extractAlpha && (kIndex_8_SkColorType == colorType ||
kRGB_565_SkColorType == colorType)) {
if (isTransparent != NULL) {
*isTransparent = false;
}
@ -221,26 +222,26 @@ static SkStream* extract_image_data(const SkBitmap& bitmap,
SkStream* stream = NULL;
bitmap.lockPixels();
switch (config) {
case SkBitmap::kIndex8_Config:
switch (colorType) {
case kIndex_8_SkColorType:
if (!extractAlpha) {
stream = extract_index8_image(bitmap, srcRect);
}
break;
case SkBitmap::kARGB_4444_Config:
case kARGB_4444_SkColorType:
stream = extract_argb4444_data(bitmap, srcRect, extractAlpha,
&isOpaque, &transparent);
break;
case SkBitmap::kRGB_565_Config:
case kRGB_565_SkColorType:
if (!extractAlpha) {
stream = extract_rgb565_image(bitmap, srcRect);
}
break;
case SkBitmap::kARGB_8888_Config:
case kN32_SkColorType:
stream = extract_argb8888_data(bitmap, srcRect, extractAlpha,
&isOpaque, &transparent);
break;
case SkBitmap::kA8_Config:
case kAlpha_8_SkColorType:
if (!extractAlpha) {
stream = create_black_image();
} else {
@ -373,14 +374,13 @@ static uint16_t get_argb4444_neighbor_avg_color(const SkBitmap& bitmap,
static SkBitmap unpremultiply_bitmap(const SkBitmap& bitmap,
const SkIRect& srcRect) {
SkBitmap outBitmap;
outBitmap.setConfig(bitmap.config(), srcRect.width(), srcRect.height());
outBitmap.allocPixels();
outBitmap.allocPixels(bitmap.info().makeWH(srcRect.width(), srcRect.height()));
int dstRow = 0;
outBitmap.lockPixels();
bitmap.lockPixels();
switch (bitmap.config()) {
case SkBitmap::kARGB_4444_Config: {
switch (bitmap.colorType()) {
case kARGB_4444_SkColorType: {
for (int y = srcRect.fTop; y < srcRect.fBottom; y++) {
uint16_t* dst = outBitmap.getAddr16(0, dstRow);
uint16_t* src = bitmap.getAddr16(0, y);
@ -408,7 +408,7 @@ static SkBitmap unpremultiply_bitmap(const SkBitmap& bitmap,
}
break;
}
case SkBitmap::kARGB_8888_Config: {
case kN32_SkColorType: {
for (int y = srcRect.fTop; y < srcRect.fBottom; y++) {
uint32_t* dst = outBitmap.getAddr32(0, dstRow);
uint32_t* src = bitmap.getAddr32(0, y);
@ -440,7 +440,7 @@ static SkBitmap unpremultiply_bitmap(const SkBitmap& bitmap,
SkPDFImage* SkPDFImage::CreateImage(const SkBitmap& bitmap,
const SkIRect& srcRect,
SkPicture::EncodeBitmap encoder) {
if (bitmap.config() == SkBitmap::kNo_Config) {
if (bitmap.colorType() == kUnknown_SkColorType) {
return NULL;
}
@ -459,9 +459,9 @@ SkPDFImage* SkPDFImage::CreateImage(const SkBitmap& bitmap,
}
SkPDFImage* image;
SkBitmap::Config config = bitmap.config();
if (alphaData.get() != NULL && (config == SkBitmap::kARGB_8888_Config ||
config == SkBitmap::kARGB_4444_Config)) {
SkColorType colorType = bitmap.colorType();
if (alphaData.get() != NULL && (kN32_SkColorType == colorType ||
kARGB_4444_SkColorType == colorType)) {
SkBitmap unpremulBitmap = unpremultiply_bitmap(bitmap, srcRect);
image = SkNEW_ARGS(SkPDFImage, (NULL, unpremulBitmap, false,
SkIRect::MakeWH(srcRect.width(), srcRect.height()),
@ -518,12 +518,12 @@ SkPDFImage::SkPDFImage(SkStream* stream,
fStreamValid = false;
}
SkBitmap::Config config = fBitmap.config();
SkColorType colorType = fBitmap.colorType();
insertName("Type", "XObject");
insertName("Subtype", "Image");
bool alphaOnly = (config == SkBitmap::kA8_Config);
bool alphaOnly = (kAlpha_8_SkColorType == colorType);
if (!isAlpha && alphaOnly) {
// For alpha only images, we stretch a single pixel of black for
@ -538,7 +538,7 @@ SkPDFImage::SkPDFImage(SkStream* stream,
if (isAlpha || alphaOnly) {
insertName("ColorSpace", "DeviceGray");
} else if (config == SkBitmap::kIndex8_Config) {
} else if (kIndex_8_SkColorType == colorType) {
SkAutoLockPixels alp(fBitmap);
insert("ColorSpace",
make_indexed_color_space(fBitmap.getColorTable()))->unref();
@ -547,12 +547,12 @@ SkPDFImage::SkPDFImage(SkStream* stream,
}
int bitsPerComp = 8;
if (config == SkBitmap::kARGB_4444_Config) {
if (kARGB_4444_SkColorType == colorType) {
bitsPerComp = 4;
}
insertInt("BitsPerComponent", bitsPerComp);
if (config == SkBitmap::kRGB_565_Config) {
if (kRGB_565_SkColorType == colorType) {
SkASSERT(!isAlpha);
SkAutoTUnref<SkPDFInt> zeroVal(new SkPDFInt(0));
SkAutoTUnref<SkPDFScalar> scale5Val(
@ -592,8 +592,6 @@ bool SkPDFImage::populate(SkPDFCatalog* catalog) {
SkBitmap subset;
// Extract subset
if (!fBitmap.extractSubset(&subset, fSrcRect)) {
// TODO(edisonn) It fails only for kA1_Config, if that is a
// major concern we will fix it later, so far it is NYI.
return false;
}
size_t pixelRefOffset = 0;

Просмотреть файл

@ -55,7 +55,7 @@ static inline uint64_t first_8_bytes_as_uint64(const uint8_t *bytearray) {
}
// Hmm, that didn't work. Maybe if we create a new
// kARGB_8888_Config version of the bitmap it will work better?
// version of the bitmap it will work better?
SkBitmap copyBitmap;
if (!bitmap.copyTo(&copyBitmap, kN32_SkColorType)) {
return false;

Просмотреть файл

@ -22,7 +22,7 @@ public:
* If this is unable to compute the hash for some reason,
* it returns false.
*
* Note: depending on the bitmap config, we may need to create an
* Note: depending on the bitmap colortype, we may need to create an
* intermediate SkBitmap and copy the pixels over to it... so in some
* cases, performance and memory usage can suffer.
*/

Просмотреть файл

@ -114,7 +114,7 @@ public:
virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
const SkMatrix&, const SkPaint& paint) SK_OVERRIDE {
this->addBitmap(bitmap);
if (SkBitmap::kA8_Config == bitmap.config()) {
if (kAlpha_8_SkColorType == bitmap.colorType()) {
this->addBitmapFromPaint(paint);
}
}
@ -123,7 +123,7 @@ public:
const SkPaint& paint,
SkCanvas::DrawBitmapRectFlags flags) SK_OVERRIDE {
this->addBitmap(bitmap);
if (SkBitmap::kA8_Config == bitmap.config()) {
if (kAlpha_8_SkColorType == bitmap.colorType()) {
this->addBitmapFromPaint(paint);
}
}

Просмотреть файл

@ -25,13 +25,13 @@ SkString* SkObjectParser::BitmapToString(const SkBitmap& bitmap) {
mBitmap->append(" H: ");
mBitmap->appendS32(bitmap.height());
const char* gConfigStrings[] = {
"None", "A8", "Index8", "RGB565", "ARGB4444", "ARGB8888"
const char* gColorTypeStrings[] = {
"None", "A8", "565", "4444", "RGBA", "BGRA", "Index8"
};
SkASSERT(SkBitmap::kConfigCount == SK_ARRAY_COUNT(gConfigStrings));
SkASSERT(kLastEnum_SkColorType + 1 == SK_ARRAY_COUNT(gColorTypeStrings));
mBitmap->append(" Config: ");
mBitmap->append(gConfigStrings[bitmap.config()]);
mBitmap->append(" ColorType: ");
mBitmap->append(gColorTypeStrings[bitmap.colorType()]);
if (bitmap.isOpaque()) {
mBitmap->append(" opaque");

Просмотреть файл

@ -20,7 +20,7 @@ class SkObjectParser {
public:
/**
Returns a string about a bitmaps bounds and config.
Returns a string about a bitmaps bounds and colortype.
@param bitmap SkBitmap
*/
static SkString* BitmapToString(const SkBitmap& bitmap);