| Index: src/images/SkDecodingImageGenerator.cpp
|
| diff --git a/src/images/SkDecodingImageGenerator.cpp b/src/images/SkDecodingImageGenerator.cpp
|
| index 1e2813660329ad29821704cadf79916df0aab153..63bb72f74377226c43fd33d5aea46e01657cc5e2 100644
|
| --- a/src/images/SkDecodingImageGenerator.cpp
|
| +++ b/src/images/SkDecodingImageGenerator.cpp
|
| @@ -25,30 +25,29 @@ public:
|
| size_t rowBytes,
|
| int width,
|
| int height,
|
| - SkBitmap::Config config)
|
| + SkColorType colorType)
|
| : fTarget(target)
|
| , fRowBytes(rowBytes)
|
| , fWidth(width)
|
| , fHeight(height)
|
| - , fConfig(config) { }
|
| + , fColorType(colorType) { }
|
|
|
| bool isReady() { return (fTarget != NULL); }
|
|
|
| virtual bool allocPixelRef(SkBitmap* bm, SkColorTable* ct) {
|
| if ((NULL == fTarget)
|
| - || (fConfig != bm->config())
|
| + || (fColorType != bm->colorType())
|
| || (fWidth != bm->width())
|
| || (fHeight != bm->height())
|
| || (ct != NULL)) {
|
| // Call default allocator.
|
| return bm->allocPixels(NULL, ct);
|
| }
|
| +
|
| + SkImageInfo info = SkImageInfo::Make(fWidth, fHeight, fColorType,
|
| + bm->alphaType());
|
| // make sure fRowBytes is correct.
|
| - bm->setConfig(fConfig, fWidth, fHeight, fRowBytes, bm->alphaType());
|
| - // TODO(halcanary): verify that all callers of this function
|
| - // will respect new RowBytes. Will be moot once rowbytes belongs
|
| - // to PixelRef.
|
| - bm->setPixels(fTarget, NULL);
|
| + bm->installPixels(info, fTarget, fRowBytes, NULL, NULL);
|
| fTarget = NULL; // never alloc same pixels twice!
|
| return true;
|
| }
|
| @@ -67,7 +66,7 @@ private:
|
| // the correct info using this allocator, so the
|
| // default allocator will be used instead of
|
| // fTarget.
|
| - SkBitmap::Config fConfig;
|
| + SkColorType fColorType;
|
| typedef SkBitmap::Allocator INHERITED;
|
| };
|
|
|
| @@ -89,19 +88,19 @@ inline bool check_alpha(SkAlphaType reported, SkAlphaType actual) {
|
| } // namespace
|
| ////////////////////////////////////////////////////////////////////////////////
|
|
|
| -SkDecodingImageGenerator::SkDecodingImageGenerator(
|
| - SkData* data,
|
| - SkStreamRewindable* stream,
|
| - const SkImageInfo& info,
|
| - int sampleSize,
|
| - bool ditherImage,
|
| - SkBitmap::Config requestedConfig)
|
| +SkDecodingImageGenerator::SkDecodingImageGenerator(SkData* data,
|
| + SkStreamRewindable* stream,
|
| + const SkImageInfo& info,
|
| + int sampleSize,
|
| + bool ditherImage,
|
| + SkColorType requestedColorType)
|
| : fData(data)
|
| , fStream(stream)
|
| , fInfo(info)
|
| , fSampleSize(sampleSize)
|
| , fDitherImage(ditherImage)
|
| - , fRequestedConfig(requestedConfig) {
|
| + , fRequestedColorType(requestedColorType)
|
| +{
|
| SkASSERT(stream != NULL);
|
| SkSafeRef(fData); // may be NULL.
|
| }
|
| @@ -151,7 +150,7 @@ bool SkDecodingImageGenerator::getPixels(const SkImageInfo& info,
|
| // to change the settings.
|
| return false;
|
| }
|
| - int bpp = SkBitmap::ComputeBytesPerPixel(fRequestedConfig);
|
| + int bpp = SkColorTypeBytesPerPixel(fRequestedColorType);
|
| if (static_cast<size_t>(bpp * info.fWidth) > rowBytes) {
|
| // The caller has specified a bad rowBytes.
|
| return false;
|
| @@ -167,18 +166,20 @@ bool SkDecodingImageGenerator::getPixels(const SkImageInfo& info,
|
|
|
| SkBitmap bitmap;
|
| TargetAllocator allocator(pixels, rowBytes, info.fWidth,
|
| - info.fHeight, fRequestedConfig);
|
| + info.fHeight, fRequestedColorType);
|
| decoder->setAllocator(&allocator);
|
| - bool success = decoder->decode(fStream, &bitmap, fRequestedConfig,
|
| + bool success = decoder->decode(fStream, &bitmap, fRequestedColorType,
|
| SkImageDecoder::kDecodePixels_Mode);
|
| decoder->setAllocator(NULL);
|
| if (!success) {
|
| return false;
|
| }
|
| if (allocator.isReady()) { // Did not use pixels!
|
| + // HACK: need access to colortype versions of these calls
|
| + SkBitmap::Config config = SkColorTypeToBitmapConfig(fRequestedColorType);
|
| SkBitmap bm;
|
| - SkASSERT(bitmap.canCopyTo(fRequestedConfig));
|
| - if (!bitmap.copyTo(&bm, fRequestedConfig, &allocator)
|
| + SkASSERT(bitmap.canCopyTo(config));
|
| + if (!bitmap.copyTo(&bm, config, &allocator)
|
| || allocator.isReady()) {
|
| SkDEBUGFAIL("bitmap.copyTo(requestedConfig) failed.");
|
| // Earlier we checked canCopyto(); we expect consistency.
|
| @@ -237,7 +238,7 @@ SkImageGenerator* SkDecodingImageGenerator::Create(
|
| }
|
| SkBitmap bitmap;
|
| decoder->setSampleSize(opts.fSampleSize);
|
| - if (!decoder->decode(stream, &bitmap,
|
| + if (!decoder->decode(stream, &bitmap, kUnknown_SkColorType,
|
| SkImageDecoder::kDecodeBounds_Mode)) {
|
| return NULL;
|
| }
|
| @@ -246,29 +247,30 @@ SkImageGenerator* SkDecodingImageGenerator::Create(
|
| }
|
|
|
| SkImageInfo info;
|
| - SkBitmap::Config config;
|
| + SkColorType requestedColorType;
|
|
|
| if (!opts.fUseRequestedColorType) {
|
| // Use default config.
|
| - if (SkBitmap::kIndex8_Config == bitmap.config()) {
|
| + if (kIndex_8_SkColorType == bitmap.colorType()) {
|
| // We don't support kIndex8 because we don't support
|
| // colortables in this workflow.
|
| - config = SkBitmap::kARGB_8888_Config;
|
| + requestedColorType = kPMColor_SkColorType;
|
| +
|
| info.fWidth = bitmap.width();
|
| info.fHeight = bitmap.height();
|
| - info.fColorType = kPMColor_SkColorType;
|
| + info.fColorType = requestedColorType;
|
| info.fAlphaType = bitmap.alphaType();
|
| } else {
|
| - config = bitmap.config(); // Save for later!
|
| + requestedColorType = bitmap.colorType(); // Save for later!
|
| if (!bitmap.asImageInfo(&info)) {
|
| SkDEBUGFAIL("Getting SkImageInfo from bitmap failed.");
|
| return NULL;
|
| }
|
| }
|
| } else {
|
| - config = SkColorTypeToBitmapConfig(opts.fRequestedColorType);
|
| - if (!bitmap.canCopyTo(config)) {
|
| - SkASSERT(bitmap.config() != config);
|
| + requestedColorType = opts.fRequestedColorType;
|
| + if (!bitmap.canCopyTo(requestedColorType)) {
|
| + SkASSERT(bitmap.colorType() != requestedColorType);
|
| return NULL; // Can not translate to needed config.
|
| }
|
| info.fWidth = bitmap.width();
|
| @@ -278,5 +280,5 @@ SkImageGenerator* SkDecodingImageGenerator::Create(
|
| }
|
| return SkNEW_ARGS(SkDecodingImageGenerator,
|
| (data, autoStream.detach(), info,
|
| - opts.fSampleSize, opts.fDitherImage, config));
|
| + opts.fSampleSize, opts.fDitherImage, requestedColorType));
|
| }
|
|
|