msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 8 | #include "SkBitmapRegionCodec.h" |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 9 | #include "SkBitmapRegionDecoder.h" |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 10 | #include "SkAndroidCodec.h" |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 11 | #include "SkCodec.h" |
msarett | 04965c6 | 2015-10-12 10:24:38 -0700 | [diff] [blame] | 12 | #include "SkCodecPriv.h" |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 13 | |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 14 | SkBitmapRegionDecoder* SkBitmapRegionDecoder::Create( |
reed | 42943c8 | 2016-09-12 12:01:44 -0700 | [diff] [blame] | 15 | sk_sp<SkData> data, Strategy strategy) { |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 16 | return SkBitmapRegionDecoder::Create(new SkMemoryStream(data), |
msarett | 3f65e93 | 2015-10-27 13:12:59 -0700 | [diff] [blame] | 17 | strategy); |
| 18 | } |
| 19 | |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 20 | SkBitmapRegionDecoder* SkBitmapRegionDecoder::Create( |
msarett | 3f65e93 | 2015-10-27 13:12:59 -0700 | [diff] [blame] | 21 | SkStreamRewindable* stream, Strategy strategy) { |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 22 | std::unique_ptr<SkStreamRewindable> streamDeleter(stream); |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 23 | switch (strategy) { |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 24 | case kAndroidCodec_Strategy: { |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 25 | auto codec = SkAndroidCodec::MakeFromStream(std::move(streamDeleter)); |
msarett | 73d882e | 2015-11-16 13:30:20 -0800 | [diff] [blame] | 26 | if (nullptr == codec) { |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 27 | SkCodecPrintf("Error: Failed to create codec.\n"); |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 28 | return nullptr; |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 29 | } |
msarett | 73d882e | 2015-11-16 13:30:20 -0800 | [diff] [blame] | 30 | |
Hal Canary | db68301 | 2016-11-23 08:55:18 -0700 | [diff] [blame] | 31 | switch ((SkEncodedImageFormat)codec->getEncodedFormat()) { |
| 32 | case SkEncodedImageFormat::kJPEG: |
| 33 | case SkEncodedImageFormat::kPNG: |
| 34 | case SkEncodedImageFormat::kWEBP: |
Leon Scroggins III | 04be2b5 | 2017-08-17 15:13:20 -0400 | [diff] [blame] | 35 | case SkEncodedImageFormat::kHEIF: |
msarett | 73d882e | 2015-11-16 13:30:20 -0800 | [diff] [blame] | 36 | break; |
| 37 | default: |
| 38 | return nullptr; |
| 39 | } |
| 40 | |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame] | 41 | return new SkBitmapRegionCodec(codec.release()); |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 42 | } |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 43 | default: |
| 44 | SkASSERT(false); |
| 45 | return nullptr; |
| 46 | } |
| 47 | } |