diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h index 83919549d..d66158d02 100644 --- a/include/core/SkImageInfo.h +++ b/include/core/SkImageInfo.h @@ -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); } diff --git a/src/effects/SkAlphaThresholdFilter.cpp b/src/effects/SkAlphaThresholdFilter.cpp index 205e9a951..6fcd2b435 100644 --- a/src/effects/SkAlphaThresholdFilter.cpp +++ b/src/effects/SkAlphaThresholdFilter.cpp @@ -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; } diff --git a/src/effects/SkBicubicImageFilter.cpp b/src/effects/SkBicubicImageFilter.cpp index 8f78ff2bd..ea2d13e72 100644 --- a/src/effects/SkBicubicImageFilter.cpp +++ b/src/effects/SkBicubicImageFilter.cpp @@ -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; } diff --git a/src/effects/SkBlurImageFilter.cpp b/src/effects/SkBlurImageFilter.cpp index 00064d466..470dcac3c 100644 --- a/src/effects/SkBlurImageFilter.cpp +++ b/src/effects/SkBlurImageFilter.cpp @@ -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; } diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp index d0f134be4..a5519d1e9 100644 --- a/src/effects/SkDisplacementMapEffect.cpp +++ b/src/effects/SkDisplacementMapEffect.cpp @@ -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; } diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp index 24fdd0e9f..c0c605ca0 100644 --- a/src/effects/SkLightingImageFilter.cpp +++ b/src/effects/SkLightingImageFilter.cpp @@ -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; } diff --git a/src/effects/SkMagnifierImageFilter.cpp b/src/effects/SkMagnifierImageFilter.cpp index 509664016..99c0176a1 100644 --- a/src/effects/SkMagnifierImageFilter.cpp +++ b/src/effects/SkMagnifierImageFilter.cpp @@ -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; } diff --git a/src/effects/SkMatrixConvolutionImageFilter.cpp b/src/effects/SkMatrixConvolutionImageFilter.cpp index f6bc6a1f1..8ae837755 100644 --- a/src/effects/SkMatrixConvolutionImageFilter.cpp +++ b/src/effects/SkMatrixConvolutionImageFilter.cpp @@ -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) { diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp index 8803f8aae..19a9b68aa 100644 --- a/src/effects/SkMorphologyImageFilter.cpp +++ b/src/effects/SkMorphologyImageFilter.cpp @@ -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; } diff --git a/src/opts/SkBitmapProcState_opts_SSE2.cpp b/src/opts/SkBitmapProcState_opts_SSE2.cpp index 2279b9d14..1f3bbc1f8 100644 --- a/src/opts/SkBitmapProcState_opts_SSE2.cpp +++ b/src/opts/SkBitmapProcState_opts_SSE2.cpp @@ -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(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(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; diff --git a/src/opts/SkBitmapProcState_opts_SSSE3.cpp b/src/opts/SkBitmapProcState_opts_SSSE3.cpp index 4622937c7..5b97215cc 100644 --- a/src/opts/SkBitmapProcState_opts_SSSE3.cpp +++ b/src/opts/SkBitmapProcState_opts_SSSE3.cpp @@ -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 { diff --git a/src/opts/SkBitmapProcState_opts_arm.cpp b/src/opts/SkBitmapProcState_opts_arm.cpp index c2376d42a..ffa0ccfa8 100644 --- a/src/opts/SkBitmapProcState_opts_arm.cpp +++ b/src/opts/SkBitmapProcState_opts_arm.cpp @@ -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; diff --git a/src/opts/SkBlitMask_opts_arm.cpp b/src/opts/SkBlitMask_opts_arm.cpp index a8a92ccba..11e172c0d 100644 --- a/src/opts/SkBlitMask_opts_arm.cpp +++ b/src/opts/SkBlitMask_opts_arm.cpp @@ -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); } diff --git a/src/pdf/SkPDFImage.cpp b/src/pdf/SkPDFImage.cpp index f39dc5908..77fd84eff 100644 --- a/src/pdf/SkPDFImage.cpp +++ b/src/pdf/SkPDFImage.cpp @@ -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 zeroVal(new SkPDFInt(0)); SkAutoTUnref 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; diff --git a/src/utils/SkBitmapHasher.cpp b/src/utils/SkBitmapHasher.cpp index bd038ddaa..32ff1cb08 100644 --- a/src/utils/SkBitmapHasher.cpp +++ b/src/utils/SkBitmapHasher.cpp @@ -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(©Bitmap, kN32_SkColorType)) { return false; diff --git a/src/utils/SkBitmapHasher.h b/src/utils/SkBitmapHasher.h index d52a6d739..c8a5c0406 100644 --- a/src/utils/SkBitmapHasher.h +++ b/src/utils/SkBitmapHasher.h @@ -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. */ diff --git a/src/utils/SkPictureUtils.cpp b/src/utils/SkPictureUtils.cpp index 4dcb855a6..a2d6da131 100644 --- a/src/utils/SkPictureUtils.cpp +++ b/src/utils/SkPictureUtils.cpp @@ -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); } } diff --git a/src/utils/debugger/SkObjectParser.cpp b/src/utils/debugger/SkObjectParser.cpp index a3b208544..b932036a8 100644 --- a/src/utils/debugger/SkObjectParser.cpp +++ b/src/utils/debugger/SkObjectParser.cpp @@ -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"); diff --git a/src/utils/debugger/SkObjectParser.h b/src/utils/debugger/SkObjectParser.h index 911b77892..da842653f 100644 --- a/src/utils/debugger/SkObjectParser.h +++ b/src/utils/debugger/SkObjectParser.h @@ -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);