SkHeifCodec.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright 2017 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. #ifndef SkHeifCodec_DEFINED
  8. #define SkHeifCodec_DEFINED
  9. #include "include/codec/SkCodec.h"
  10. #include "include/codec/SkEncodedOrigin.h"
  11. #include "include/core/SkImageInfo.h"
  12. #include "include/core/SkStream.h"
  13. #include "src/codec/SkSwizzler.h"
  14. #if __has_include("HeifDecoderAPI.h")
  15. #include "HeifDecoderAPI.h"
  16. #else
  17. #include "src/codec/SkStubHeifDecoderAPI.h"
  18. #endif
  19. class SkHeifCodec : public SkCodec {
  20. public:
  21. static bool IsHeif(const void*, size_t);
  22. /*
  23. * Assumes IsHeif was called and returned true.
  24. */
  25. static std::unique_ptr<SkCodec> MakeFromStream(std::unique_ptr<SkStream>, Result*);
  26. protected:
  27. Result onGetPixels(
  28. const SkImageInfo& dstInfo,
  29. void* dst, size_t dstRowBytes,
  30. const Options& options,
  31. int* rowsDecoded) override;
  32. SkEncodedImageFormat onGetEncodedFormat() const override {
  33. return SkEncodedImageFormat::kHEIF;
  34. }
  35. bool conversionSupported(const SkImageInfo&, bool, bool) override;
  36. bool onRewind() override;
  37. private:
  38. /*
  39. * Creates an instance of the decoder
  40. * Called only by NewFromStream
  41. */
  42. SkHeifCodec(SkEncodedInfo&&, HeifDecoder*, SkEncodedOrigin);
  43. void initializeSwizzler(const SkImageInfo& dstInfo, const Options& options);
  44. void allocateStorage(const SkImageInfo& dstInfo);
  45. int readRows(const SkImageInfo& dstInfo, void* dst,
  46. size_t rowBytes, int count, const Options&);
  47. /*
  48. * Scanline decoding.
  49. */
  50. SkSampler* getSampler(bool createIfNecessary) override;
  51. Result onStartScanlineDecode(const SkImageInfo& dstInfo,
  52. const Options& options) override;
  53. int onGetScanlines(void* dst, int count, size_t rowBytes) override;
  54. bool onSkipScanlines(int count) override;
  55. std::unique_ptr<HeifDecoder> fHeifDecoder;
  56. HeifFrameInfo fFrameInfo;
  57. SkAutoTMalloc<uint8_t> fStorage;
  58. uint8_t* fSwizzleSrcRow;
  59. uint32_t* fColorXformSrcRow;
  60. std::unique_ptr<SkSwizzler> fSwizzler;
  61. typedef SkCodec INHERITED;
  62. };
  63. #endif // SkHeifCodec_DEFINED