SkBitmapRegionDecoder.cpp 1.5 KB

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