blob: 15a530e21a0dd947c099a0016b7895ca19718916 [file] [log] [blame]
msaretta5783ae2015-09-08 15:35:32 -07001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
msarett26ad17b2015-10-22 07:29:19 -07008#include "SkBitmapRegionCodec.h"
msarett5cb48852015-11-06 08:56:32 -08009#include "SkBitmapRegionDecoder.h"
msarett26ad17b2015-10-22 07:29:19 -070010#include "SkAndroidCodec.h"
scroggo46c57472015-09-30 08:57:13 -070011#include "SkCodec.h"
msarett04965c62015-10-12 10:24:38 -070012#include "SkCodecPriv.h"
msaretta5783ae2015-09-08 15:35:32 -070013
msarett5cb48852015-11-06 08:56:32 -080014SkBitmapRegionDecoder* SkBitmapRegionDecoder::Create(
reed42943c82016-09-12 12:01:44 -070015 sk_sp<SkData> data, Strategy strategy) {
msarett5cb48852015-11-06 08:56:32 -080016 return SkBitmapRegionDecoder::Create(new SkMemoryStream(data),
msarett3f65e932015-10-27 13:12:59 -070017 strategy);
18}
19
msarett5cb48852015-11-06 08:56:32 -080020SkBitmapRegionDecoder* SkBitmapRegionDecoder::Create(
msarett3f65e932015-10-27 13:12:59 -070021 SkStreamRewindable* stream, Strategy strategy) {
Ben Wagner145dbcd2016-11-03 14:40:50 -040022 std::unique_ptr<SkStreamRewindable> streamDeleter(stream);
msaretta5783ae2015-09-08 15:35:32 -070023 switch (strategy) {
msarett26ad17b2015-10-22 07:29:19 -070024 case kAndroidCodec_Strategy: {
Ben Wagner145dbcd2016-11-03 14:40:50 -040025 std::unique_ptr<SkAndroidCodec> codec(
26 SkAndroidCodec::NewFromStream(streamDeleter.release()));
msarett73d882e2015-11-16 13:30:20 -080027 if (nullptr == codec) {
msarett26ad17b2015-10-22 07:29:19 -070028 SkCodecPrintf("Error: Failed to create codec.\n");
mtklein5c05d102015-12-02 12:32:02 -080029 return NULL;
msarett26ad17b2015-10-22 07:29:19 -070030 }
msarett73d882e2015-11-16 13:30:20 -080031
Hal Canarya2b4bdc2016-11-22 14:21:38 -070032 SkEncodedFormat format = codec->getEncodedFormat();
33 switch (format) {
34 case SkEncodedFormat::kJPEG_SkEncodedFormat:
35 case SkEncodedFormat::kPNG_SkEncodedFormat:
36 case SkEncodedFormat::kWEBP_SkEncodedFormat:
msarett73d882e2015-11-16 13:30:20 -080037 break;
38 default:
39 return nullptr;
40 }
41
mtklein18300a32016-03-16 13:53:35 -070042 return new SkBitmapRegionCodec(codec.release());
msarett26ad17b2015-10-22 07:29:19 -070043 }
msaretta5783ae2015-09-08 15:35:32 -070044 default:
45 SkASSERT(false);
46 return nullptr;
47 }
48}