5cb4885b4c
We no longer need to worry about namespace conflicts SkBitmapRegionDecoder in Android (which we are replacing). Additionally, the static Create() function does not need to repeat the name BitmapRegionDecoder. BUG=skia: Review URL: https://codereview.chromium.org/1415243007
78 lines
2.7 KiB
C++
78 lines
2.7 KiB
C++
/*
|
|
* Copyright 2015 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "SkBitmapRegionCanvas.h"
|
|
#include "SkBitmapRegionCodec.h"
|
|
#include "SkBitmapRegionDecoder.h"
|
|
#include "SkBitmapRegionSampler.h"
|
|
#include "SkAndroidCodec.h"
|
|
#include "SkCodec.h"
|
|
#include "SkCodecPriv.h"
|
|
#include "SkImageDecoder.h"
|
|
|
|
SkBitmapRegionDecoder* SkBitmapRegionDecoder::Create(
|
|
SkData* data, Strategy strategy) {
|
|
return SkBitmapRegionDecoder::Create(new SkMemoryStream(data),
|
|
strategy);
|
|
}
|
|
|
|
SkBitmapRegionDecoder* SkBitmapRegionDecoder::Create(
|
|
SkStreamRewindable* stream, Strategy strategy) {
|
|
SkAutoTDelete<SkStreamRewindable> streamDeleter(stream);
|
|
switch (strategy) {
|
|
case kOriginal_Strategy: {
|
|
SkImageDecoder* decoder = SkImageDecoder::Factory(streamDeleter);
|
|
int width, height;
|
|
if (nullptr == decoder) {
|
|
SkCodecPrintf("Error: Could not create image decoder.\n");
|
|
return nullptr;
|
|
}
|
|
if (!decoder->buildTileIndex(streamDeleter.detach(), &width, &height)) {
|
|
SkCodecPrintf("Error: Could not build tile index.\n");
|
|
delete decoder;
|
|
return nullptr;
|
|
}
|
|
return new SkBitmapRegionSampler(decoder, width, height);
|
|
}
|
|
case kCanvas_Strategy: {
|
|
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(streamDeleter.detach()));
|
|
if (nullptr == codec) {
|
|
SkCodecPrintf("Error: Failed to create decoder.\n");
|
|
return nullptr;
|
|
}
|
|
|
|
if (SkEncodedFormat::kWEBP_SkEncodedFormat == codec->getEncodedFormat()) {
|
|
// FIXME: Support webp using a special case. Webp does not support
|
|
// scanline decoding.
|
|
return nullptr;
|
|
}
|
|
|
|
switch (codec->getScanlineOrder()) {
|
|
case SkCodec::kTopDown_SkScanlineOrder:
|
|
case SkCodec::kNone_SkScanlineOrder:
|
|
break;
|
|
default:
|
|
SkCodecPrintf("Error: Scanline ordering not supported.\n");
|
|
return nullptr;
|
|
}
|
|
return new SkBitmapRegionCanvas(codec.detach());
|
|
}
|
|
case kAndroidCodec_Strategy: {
|
|
SkAutoTDelete<SkAndroidCodec> codec =
|
|
SkAndroidCodec::NewFromStream(streamDeleter.detach());
|
|
if (NULL == codec) {
|
|
SkCodecPrintf("Error: Failed to create codec.\n");
|
|
return NULL;
|
|
}
|
|
return new SkBitmapRegionCodec(codec.detach());
|
|
}
|
|
default:
|
|
SkASSERT(false);
|
|
return nullptr;
|
|
}
|
|
}
|