/src/libwebp/src/dec/vp8_dec.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2010 Google Inc. All Rights Reserved. |
2 | | // |
3 | | // Use of this source code is governed by a BSD-style license |
4 | | // that can be found in the COPYING file in the root of the source |
5 | | // tree. An additional intellectual property rights grant can be found |
6 | | // in the file PATENTS. All contributing project authors may |
7 | | // be found in the AUTHORS file in the root of the source tree. |
8 | | // ----------------------------------------------------------------------------- |
9 | | // |
10 | | // Low-level API for VP8 decoder |
11 | | // |
12 | | // Author: Skal (pascal.massimino@gmail.com) |
13 | | |
14 | | #ifndef WEBP_DEC_VP8_DEC_H_ |
15 | | #define WEBP_DEC_VP8_DEC_H_ |
16 | | |
17 | | #include <stddef.h> |
18 | | |
19 | | #include "src/webp/decode.h" |
20 | | #include "src/webp/types.h" |
21 | | |
22 | | #ifdef __cplusplus |
23 | | extern "C" { |
24 | | #endif |
25 | | |
26 | | //------------------------------------------------------------------------------ |
27 | | // Lower-level API |
28 | | // |
29 | | // These functions provide fine-grained control of the decoding process. |
30 | | // The call flow should resemble: |
31 | | // |
32 | | // VP8Io io; |
33 | | // VP8InitIo(&io); |
34 | | // io.data = data; |
35 | | // io.data_size = size; |
36 | | // /* customize io's functions (setup()/put()/teardown()) if needed. */ |
37 | | // |
38 | | // VP8Decoder* dec = VP8New(); |
39 | | // int ok = VP8Decode(dec, &io); |
40 | | // if (!ok) printf("Error: %s\n", VP8StatusMessage(dec)); |
41 | | // VP8Delete(dec); |
42 | | // return ok; |
43 | | |
44 | | // Input / Output |
45 | | typedef struct VP8Io VP8Io; |
46 | | typedef int (*VP8IoPutHook)(const VP8Io* io); |
47 | | typedef int (*VP8IoSetupHook)(VP8Io* io); |
48 | | typedef void (*VP8IoTeardownHook)(const VP8Io* io); |
49 | | |
50 | | struct VP8Io { |
51 | | // set by VP8GetHeaders() |
52 | | int width, height; // picture dimensions, in pixels (invariable). |
53 | | // These are the original, uncropped dimensions. |
54 | | // The actual area passed to put() is stored |
55 | | // in mb_w / mb_h fields. |
56 | | |
57 | | // set before calling put() |
58 | | int mb_y; // position of the current rows (in pixels) |
59 | | int mb_w; // number of columns in the sample |
60 | | int mb_h; // number of rows in the sample |
61 | | const uint8_t* y, *u, *v; // rows to copy (in yuv420 format) |
62 | | int y_stride; // row stride for luma |
63 | | int uv_stride; // row stride for chroma |
64 | | |
65 | | void* opaque; // user data |
66 | | |
67 | | // called when fresh samples are available. Currently, samples are in |
68 | | // YUV420 format, and can be up to width x 24 in size (depending on the |
69 | | // in-loop filtering level, e.g.). Should return false in case of error |
70 | | // or abort request. The actual size of the area to update is mb_w x mb_h |
71 | | // in size, taking cropping into account. |
72 | | VP8IoPutHook put; |
73 | | |
74 | | // called just before starting to decode the blocks. |
75 | | // Must return false in case of setup error, true otherwise. If false is |
76 | | // returned, teardown() will NOT be called. But if the setup succeeded |
77 | | // and true is returned, then teardown() will always be called afterward. |
78 | | VP8IoSetupHook setup; |
79 | | |
80 | | // Called just after block decoding is finished (or when an error occurred |
81 | | // during put()). Is NOT called if setup() failed. |
82 | | VP8IoTeardownHook teardown; |
83 | | |
84 | | // this is a recommendation for the user-side yuv->rgb converter. This flag |
85 | | // is set when calling setup() hook and can be overwritten by it. It then |
86 | | // can be taken into consideration during the put() method. |
87 | | int fancy_upsampling; |
88 | | |
89 | | // Input buffer. |
90 | | size_t data_size; |
91 | | const uint8_t* data; |
92 | | |
93 | | // If true, in-loop filtering will not be performed even if present in the |
94 | | // bitstream. Switching off filtering may speed up decoding at the expense |
95 | | // of more visible blocking. Note that output will also be non-compliant |
96 | | // with the VP8 specifications. |
97 | | int bypass_filtering; |
98 | | |
99 | | // Cropping parameters. |
100 | | int use_cropping; |
101 | | int crop_left, crop_right, crop_top, crop_bottom; |
102 | | |
103 | | // Scaling parameters. |
104 | | int use_scaling; |
105 | | int scaled_width, scaled_height; |
106 | | |
107 | | // If non NULL, pointer to the alpha data (if present) corresponding to the |
108 | | // start of the current row (That is: it is pre-offset by mb_y and takes |
109 | | // cropping into account). |
110 | | const uint8_t* a; |
111 | | }; |
112 | | |
113 | | // Internal, version-checked, entry point |
114 | | WEBP_NODISCARD int VP8InitIoInternal(VP8Io* const, int); |
115 | | |
116 | | // Set the custom IO function pointers and user-data. The setter for IO hooks |
117 | | // should be called before initiating incremental decoding. Returns true if |
118 | | // WebPIDecoder object is successfully modified, false otherwise. |
119 | | WEBP_NODISCARD int WebPISetIOHooks(WebPIDecoder* const idec, VP8IoPutHook put, |
120 | | VP8IoSetupHook setup, |
121 | | VP8IoTeardownHook teardown, void* user_data); |
122 | | |
123 | | // Main decoding object. This is an opaque structure. |
124 | | typedef struct VP8Decoder VP8Decoder; |
125 | | |
126 | | // Create a new decoder object. |
127 | | VP8Decoder* VP8New(void); |
128 | | |
129 | | // Must be called to make sure 'io' is initialized properly. |
130 | | // Returns false in case of version mismatch. Upon such failure, no other |
131 | | // decoding function should be called (VP8Decode, VP8GetHeaders, ...) |
132 | 0 | WEBP_NODISCARD static WEBP_INLINE int VP8InitIo(VP8Io* const io) { |
133 | 0 | return VP8InitIoInternal(io, WEBP_DECODER_ABI_VERSION); |
134 | 0 | } Unexecuted instantiation: webp_dec.c:VP8InitIo Unexecuted instantiation: buffer_dec.c:VP8InitIo Unexecuted instantiation: frame_dec.c:VP8InitIo Unexecuted instantiation: io_dec.c:VP8InitIo Unexecuted instantiation: vp8_dec.c:VP8InitIo Unexecuted instantiation: vp8l_dec.c:VP8InitIo Unexecuted instantiation: dec.c:VP8InitIo Unexecuted instantiation: lossless.c:VP8InitIo Unexecuted instantiation: upsampling.c:VP8InitIo Unexecuted instantiation: yuv.c:VP8InitIo Unexecuted instantiation: dec_sse2.c:VP8InitIo Unexecuted instantiation: upsampling_sse2.c:VP8InitIo Unexecuted instantiation: yuv_sse2.c:VP8InitIo Unexecuted instantiation: dec_sse41.c:VP8InitIo Unexecuted instantiation: upsampling_sse41.c:VP8InitIo Unexecuted instantiation: yuv_sse41.c:VP8InitIo Unexecuted instantiation: picture_csp_enc.c:VP8InitIo Unexecuted instantiation: picture_tools_enc.c:VP8InitIo Unexecuted instantiation: alpha_dec.c:VP8InitIo Unexecuted instantiation: quant_dec.c:VP8InitIo Unexecuted instantiation: tree_dec.c:VP8InitIo |
135 | | |
136 | | // Decode the VP8 frame header. Returns true if ok. |
137 | | // Note: 'io->data' must be pointing to the start of the VP8 frame header. |
138 | | WEBP_NODISCARD int VP8GetHeaders(VP8Decoder* const dec, VP8Io* const io); |
139 | | |
140 | | // Decode a picture. Will call VP8GetHeaders() if it wasn't done already. |
141 | | // Returns false in case of error. |
142 | | WEBP_NODISCARD int VP8Decode(VP8Decoder* const dec, VP8Io* const io); |
143 | | |
144 | | // Return current status of the decoder: |
145 | | VP8StatusCode VP8Status(VP8Decoder* const dec); |
146 | | |
147 | | // return readable string corresponding to the last status. |
148 | | const char* VP8StatusMessage(VP8Decoder* const dec); |
149 | | |
150 | | // Resets the decoder in its initial state, reclaiming memory. |
151 | | // Not a mandatory call between calls to VP8Decode(). |
152 | | void VP8Clear(VP8Decoder* const dec); |
153 | | |
154 | | // Destroy the decoder object. |
155 | | void VP8Delete(VP8Decoder* const dec); |
156 | | |
157 | | //------------------------------------------------------------------------------ |
158 | | // Miscellaneous VP8/VP8L bitstream probing functions. |
159 | | |
160 | | // Returns true if the next 3 bytes in data contain the VP8 signature. |
161 | | WEBP_EXTERN int VP8CheckSignature(const uint8_t* const data, size_t data_size); |
162 | | |
163 | | // Validates the VP8 data-header and retrieves basic header information viz |
164 | | // width and height. Returns 0 in case of formatting error. *width/*height |
165 | | // can be passed NULL. |
166 | | WEBP_EXTERN int VP8GetInfo( |
167 | | const uint8_t* data, |
168 | | size_t data_size, // data available so far |
169 | | size_t chunk_size, // total data size expected in the chunk |
170 | | int* const width, int* const height); |
171 | | |
172 | | // Returns true if the next byte(s) in data is a VP8L signature. |
173 | | WEBP_EXTERN int VP8LCheckSignature(const uint8_t* const data, size_t size); |
174 | | |
175 | | // Validates the VP8L data-header and retrieves basic header information viz |
176 | | // width, height and alpha. Returns 0 in case of formatting error. |
177 | | // width/height/has_alpha can be passed NULL. |
178 | | WEBP_EXTERN int VP8LGetInfo( |
179 | | const uint8_t* data, size_t data_size, // data available so far |
180 | | int* const width, int* const height, int* const has_alpha); |
181 | | |
182 | | #ifdef __cplusplus |
183 | | } // extern "C" |
184 | | #endif |
185 | | |
186 | | #endif // WEBP_DEC_VP8_DEC_H_ |