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 8 #include "SkBitmapRegionCodec.h" 9 #include "SkBitmapRegionDecoder.h" 10 #include "SkAndroidCodec.h" 11 #include "SkCodec.h" 12 #include "SkCodecPriv.h" 13 Create(sk_sp<SkData> data,Strategy strategy)14SkBitmapRegionDecoder* SkBitmapRegionDecoder::Create( 15 sk_sp<SkData> data, Strategy strategy) { 16 return SkBitmapRegionDecoder::Create(new SkMemoryStream(data), 17 strategy); 18 } 19 Create(SkStreamRewindable * stream,Strategy strategy)20SkBitmapRegionDecoder* SkBitmapRegionDecoder::Create( 21 SkStreamRewindable* stream, Strategy strategy) { 22 std::unique_ptr<SkStreamRewindable> streamDeleter(stream); 23 switch (strategy) { 24 case kAndroidCodec_Strategy: { 25 auto codec = SkAndroidCodec::MakeFromStream(std::move(streamDeleter)); 26 if (nullptr == codec) { 27 SkCodecPrintf("Error: Failed to create codec.\n"); 28 return nullptr; 29 } 30 31 switch ((SkEncodedImageFormat)codec->getEncodedFormat()) { 32 case SkEncodedImageFormat::kJPEG: 33 case SkEncodedImageFormat::kPNG: 34 case SkEncodedImageFormat::kWEBP: 35 case SkEncodedImageFormat::kHEIF: 36 break; 37 default: 38 return nullptr; 39 } 40 41 return new SkBitmapRegionCodec(codec.release()); 42 } 43 default: 44 SkASSERT(false); 45 return nullptr; 46 } 47 } 48