Coverage Report

Created: 2025-12-31 07:53

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