• Home
  • 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 files.
6  */
7 
8 #ifndef SkStubHeifDecoderAPI_DEFINED
9 #define SkStubHeifDecoderAPI_DEFINED
10 
11 // This stub implementation of HeifDecoderAPI.h lets us compile SkHeifCodec.cpp
12 // even when libheif is not available.  It, of course, does nothing and fails to decode.
13 
14 #include <memory>
15 #include <stddef.h>
16 #include <stdint.h>
17 #include <vector>
18 
19 enum SkHeifColorFormat {
20     kHeifColorFormat_RGB565,
21     kHeifColorFormat_RGBA_8888,
22     kHeifColorFormat_BGRA_8888,
23     kHeifColorFormat_RGBA_1010102,
24     kHeifColorFormat_NV12,
25     kHeifColorFormat_NV21,
26     kHeifColorFormat_P010_NV12,
27     kHeifColorFormat_P010_NV21,
28 };
29 
30 struct HeifStream {
~HeifStreamHeifStream31     virtual ~HeifStream() {}
32 
33     virtual size_t read(void*, size_t) = 0;
34     virtual bool   rewind()            = 0;
35     virtual bool   seek(size_t)        = 0;
36     virtual bool   hasLength() const   = 0;
37     virtual size_t getLength() const   = 0;
38     virtual bool   hasPosition() const = 0;
39     virtual size_t getPosition() const = 0;
40 };
41 
42 struct HeifNclxColor {
43     uint16_t colorPrimaries;
44     uint16_t transferCharacteristics;
45     uint16_t matrixCoefficients;
46     uint8_t fullRangeFlag;
47 };
48 
49 struct HeifFrameInfo {
50     uint32_t mWidth;
51     uint32_t mHeight;
52     int32_t  mRotationAngle;           // Rotation angle, clockwise, should be multiple of 90
53     uint32_t mBytesPerPixel;           // Number of bytes for one pixel
54     int64_t mDurationUs;               // Duration of the frame in us
55     std::vector<uint8_t> mIccData;     // ICC data array
56     bool hasNclxColor = false;
57     HeifNclxColor nclxColor;
58 };
59 
60 enum class HeifImageHdrType {
61     UNKNOWN = 0,
62     VIVID_DUAL = 1,
63     ISO_DUAL,
64     VIVID_SINGLE,
65     ISO_SINGLE,
66 };
67 
68 /*
69  * This is a stub implementation of the HeifDecoder API.
70  * For heif yuv decode
71  */
72 struct HeifDecoder {
HeifDecoderHeifDecoder73     HeifDecoder() {}
74 
~HeifDecoderHeifDecoder75     virtual ~HeifDecoder() {}
76 
77     virtual bool init(HeifStream* stream, HeifFrameInfo* frameInfo) = 0;
78 
79     virtual bool getSequenceInfo(HeifFrameInfo* frameInfo, size_t *frameCount) = 0;
80 
81     virtual bool decode(HeifFrameInfo* frameInfo) = 0;
82 
83     virtual bool decodeSequence(int frameIndex, HeifFrameInfo* frameInfo) = 0;
84 
85     virtual bool setOutputColor(SkHeifColorFormat colorFormat) = 0;
86 
87     virtual void setDstBuffer(uint8_t *dstBuffer, size_t rowStride, void *context) = 0;
88 
89     virtual bool getScanline(uint8_t* dst) = 0;
90 
91     virtual size_t skipScanlines(int count) = 0;
92 
93     virtual bool getImageInfo(HeifFrameInfo *frameInfo) = 0;
94 
95     virtual bool decodeGainmap() = 0;
96 
97     virtual void setGainmapDstBuffer(uint8_t* dstBuffer, size_t rowStride) = 0;
98 
99     virtual bool getGainmapInfo(HeifFrameInfo* frameInfo) = 0;
100 
101     virtual bool getTmapInfo(HeifFrameInfo* frameInfo) = 0;
102 
103     virtual HeifImageHdrType getHdrType() = 0;
104 
105     virtual void getVividMetadata(std::vector<uint8_t>& uwaInfo, std::vector<uint8_t>& displayInfo,
106         std::vector<uint8_t>& lightInfo) = 0;
107 
108     virtual void getISOMetadata(std::vector<uint8_t>& isoMetadata) = 0;
109 
110     virtual void getErrMsg(std::string& errMsg) = 0;
111 
112     virtual uint32_t getColorDepth() = 0;
113 };
114 
115 struct StubHeifDecoder : HeifDecoder {
initStubHeifDecoder116     bool init(HeifStream* stream, HeifFrameInfo* frameInfo) override {
117         delete stream;
118         return false;
119     }
120 
getSequenceInfoStubHeifDecoder121     bool getSequenceInfo(HeifFrameInfo* frameInfo, size_t *frameCount) override {
122         return false;
123     }
124 
decodeStubHeifDecoder125     bool decode(HeifFrameInfo* frameInfo) override {
126         return false;
127     }
128 
decodeSequenceStubHeifDecoder129     bool decodeSequence(int frameIndex, HeifFrameInfo* frameInfo) override {
130         return false;
131     }
132 
setOutputColorStubHeifDecoder133     bool setOutputColor(SkHeifColorFormat colorFormat) override {
134         return false;
135     }
136 
setDstBufferStubHeifDecoder137     void setDstBuffer(uint8_t *dstBuffer, size_t rowStride, void *context) override {
138         return;
139     }
140 
getScanlineStubHeifDecoder141     bool getScanline(uint8_t* dst) override {
142         return false;
143     }
144 
skipScanlinesStubHeifDecoder145     size_t skipScanlines(int count) override {
146         return 0;
147     }
148 
getImageInfoStubHeifDecoder149     bool getImageInfo(HeifFrameInfo *frameInfo) override {
150         return false;
151     }
152 
decodeGainmapStubHeifDecoder153     bool decodeGainmap() override {
154         return false;
155     }
156 
setGainmapDstBufferStubHeifDecoder157     void setGainmapDstBuffer(uint8_t* dstBuffer, size_t rowStride) override {
158         return;
159     }
160 
getGainmapInfoStubHeifDecoder161     bool getGainmapInfo(HeifFrameInfo* frameInfo) override {
162         return false;
163     }
164 
getTmapInfoStubHeifDecoder165     bool getTmapInfo(HeifFrameInfo* frameInfo) override {
166         return false;
167     }
168 
getHdrTypeStubHeifDecoder169     HeifImageHdrType getHdrType() override {
170         return HeifImageHdrType::UNKNOWN;
171     }
172 
getVividMetadataStubHeifDecoder173     void getVividMetadata(std::vector<uint8_t>& uwaInfo, std::vector<uint8_t>& displayInfo,
174         std::vector<uint8_t>& lightInfo) override {
175         return;
176     }
177 
getISOMetadataStubHeifDecoder178     void getISOMetadata(std::vector<uint8_t>& isoMetadata) override {
179         return;
180     }
181 
getErrMsgStubHeifDecoder182     void getErrMsg(std::string& errMsg) override {
183         return;
184     }
185 
getColorDepthStubHeifDecoder186     uint32_t getColorDepth() override {
187         return 0;
188     }
189 };
190 
191 #endif//SkStubHeifDecoderAPI_DEFINED
192