Home | History | Annotate | Download | only in android
      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 
     14 SkBitmapRegionDecoder* SkBitmapRegionDecoder::Create(
     15         sk_sp<SkData> data, Strategy strategy) {
     16     return SkBitmapRegionDecoder::Create(new SkMemoryStream(data),
     17             strategy);
     18 }
     19 
     20 SkBitmapRegionDecoder* SkBitmapRegionDecoder::Create(
     21         SkStreamRewindable* stream, Strategy strategy) {
     22     std::unique_ptr<SkStreamRewindable> streamDeleter(stream);
     23     switch (strategy) {
     24         case kAndroidCodec_Strategy: {
     25             std::unique_ptr<SkAndroidCodec> codec(
     26                     SkAndroidCodec::NewFromStream(streamDeleter.release()));
     27             if (nullptr == codec) {
     28                 SkCodecPrintf("Error: Failed to create codec.\n");
     29                 return NULL;
     30             }
     31 
     32             switch ((SkEncodedImageFormat)codec->getEncodedFormat()) {
     33                 case SkEncodedImageFormat::kJPEG:
     34                 case SkEncodedImageFormat::kPNG:
     35                 case SkEncodedImageFormat::kWEBP:
     36                 case SkEncodedImageFormat::kHEIF:
     37                     break;
     38                 default:
     39                     return nullptr;
     40             }
     41 
     42             return new SkBitmapRegionCodec(codec.release());
     43         }
     44         default:
     45             SkASSERT(false);
     46             return nullptr;
     47     }
     48 }
     49