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