Coverage Report

Created: 2025-12-31 07:53

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libwebp/src/enc/vp8i_enc.h
Line
Count
Source
1
// Copyright 2011 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
//   WebP encoder: internal header.
11
//
12
// Author: Skal (pascal.massimino@gmail.com)
13
14
#ifndef WEBP_ENC_VP8I_ENC_H_
15
#define WEBP_ENC_VP8I_ENC_H_
16
17
#include <string.h>  // for memcpy()
18
19
#include "src/dec/common_dec.h"
20
#include "src/dsp/cpu.h"
21
#include "src/dsp/dsp.h"
22
#include "src/utils/bit_writer_utils.h"
23
#include "src/utils/thread_utils.h"
24
#include "src/utils/utils.h"
25
#include "src/webp/encode.h"
26
#include "src/webp/types.h"
27
28
#ifdef __cplusplus
29
extern "C" {
30
#endif
31
32
//------------------------------------------------------------------------------
33
// Various defines and enums
34
35
// version numbers
36
5
#define ENC_MAJ_VERSION 1
37
5
#define ENC_MIN_VERSION 6
38
5
#define ENC_REV_VERSION 0
39
40
enum {
41
  MAX_LF_LEVELS = 64,       // Maximum loop filter level
42
  MAX_VARIABLE_LEVEL = 67,  // last (inclusive) level with variable cost
43
  MAX_LEVEL = 2047          // max level (note: max codable is 2047 + 67)
44
};
45
46
typedef enum {            // Rate-distortion optimization levels
47
  RD_OPT_NONE = 0,        // no rd-opt
48
  RD_OPT_BASIC = 1,       // basic scoring (no trellis)
49
  RD_OPT_TRELLIS = 2,     // perform trellis-quant on the final decision only
50
  RD_OPT_TRELLIS_ALL = 3  // trellis-quant for every scoring (much slower)
51
} VP8RDLevel;
52
53
// YUV-cache parameters. Cache is 32-bytes wide (= one cacheline).
54
// The original or reconstructed samples can be accessed using VP8Scan[].
55
// The predicted blocks can be accessed using offsets to 'yuv_p' and
56
// the arrays VP8*ModeOffsets[].
57
// * YUV Samples area ('yuv_in'/'yuv_out'/'yuv_out2')
58
//   (see VP8Scan[] for accessing the blocks, along with
59
//   Y_OFF_ENC/U_OFF_ENC/V_OFF_ENC):
60
//             +----+----+
61
//  Y_OFF_ENC  |YYYY|UUVV|
62
//  U_OFF_ENC  |YYYY|UUVV|
63
//  V_OFF_ENC  |YYYY|....| <- 25% wasted U/V area
64
//             |YYYY|....|
65
//             +----+----+
66
// * Prediction area ('yuv_p', size = PRED_SIZE_ENC)
67
//   Intra16 predictions (16x16 block each, two per row):
68
//         |I16DC16|I16TM16|
69
//         |I16VE16|I16HE16|
70
//   Chroma U/V predictions (16x8 block each, two per row):
71
//         |C8DC8|C8TM8|
72
//         |C8VE8|C8HE8|
73
//   Intra 4x4 predictions (4x4 block each)
74
//         |I4DC4 I4TM4 I4VE4 I4HE4|I4RD4 I4VR4 I4LD4 I4VL4|
75
//         |I4HD4 I4HU4 I4TMP .....|.......................| <- ~31% wasted
76
28.4k
#define YUV_SIZE_ENC (BPS * 16)
77
#define PRED_SIZE_ENC (32 * BPS + 16 * BPS + 8 * BPS)  // I16+Chroma+I4 preds
78
90.1M
#define Y_OFF_ENC (0)
79
66.4M
#define U_OFF_ENC (16)
80
18.9M
#define V_OFF_ENC (16 + 8)
81
82
extern const uint16_t VP8Scan[16];
83
extern const uint16_t VP8UVModeOffsets[4];
84
extern const uint16_t VP8I16ModeOffsets[4];
85
86
// Layout of prediction blocks
87
// intra 16x16
88
18.9M
#define I16DC16 (0 * 16 * BPS)
89
9.49M
#define I16TM16 (I16DC16 + 16)
90
18.9M
#define I16VE16 (1 * 16 * BPS)
91
9.49M
#define I16HE16 (I16VE16 + 16)
92
// chroma 8x8, two U/V blocks side by side (hence: 16x8 each)
93
37.9M
#define C8DC8 (2 * 16 * BPS)
94
18.9M
#define C8TM8 (C8DC8 + 1 * 16)
95
37.9M
#define C8VE8 (2 * 16 * BPS + 8 * BPS)
96
18.9M
#define C8HE8 (C8VE8 + 1 * 16)
97
// intra 4x4
98
395M
#define I4DC4 (3 * 16 * BPS + 0)
99
49.4M
#define I4TM4 (I4DC4 + 4)
100
49.4M
#define I4VE4 (I4DC4 + 8)
101
49.4M
#define I4HE4 (I4DC4 + 12)
102
49.4M
#define I4RD4 (I4DC4 + 16)
103
49.4M
#define I4VR4 (I4DC4 + 20)
104
49.4M
#define I4LD4 (I4DC4 + 24)
105
49.4M
#define I4VL4 (I4DC4 + 28)
106
148M
#define I4HD4 (3 * 16 * BPS + 4 * BPS)
107
49.4M
#define I4HU4 (I4HD4 + 4)
108
49.4M
#define I4TMP (I4HD4 + 8)
109
110
typedef int64_t score_t;  // type used for scores, rate, distortion
111
// Note that MAX_COST is not the maximum allowed by sizeof(score_t),
112
// in order to allow overflowing computations.
113
63.6M
#define MAX_COST ((score_t)0x7fffffffffffffLL)
114
115
3.93G
#define QFIX 17
116
68.6k
#define BIAS(b) ((b) << (QFIX - 8))
117
// Fun fact: this is the _only_ line where we're actually being lossy and
118
// discarding bits.
119
57.3M
static WEBP_INLINE int QUANTDIV(uint32_t n, uint32_t iQ, uint32_t B) {
120
57.3M
  return (int)((n * iQ + B) >> QFIX);
121
57.3M
}
Unexecuted instantiation: picture_csp_enc.c:QUANTDIV
Unexecuted instantiation: picture_enc.c:QUANTDIV
Unexecuted instantiation: webp_enc.c:QUANTDIV
Unexecuted instantiation: cost.c:QUANTDIV
Unexecuted instantiation: enc.c:QUANTDIV
Unexecuted instantiation: cost_sse2.c:QUANTDIV
Unexecuted instantiation: enc_sse2.c:QUANTDIV
Unexecuted instantiation: enc_sse41.c:QUANTDIV
Unexecuted instantiation: alpha_enc.c:QUANTDIV
Unexecuted instantiation: analysis_enc.c:QUANTDIV
Unexecuted instantiation: frame_enc.c:QUANTDIV
Unexecuted instantiation: iterator_enc.c:QUANTDIV
Unexecuted instantiation: picture_tools_enc.c:QUANTDIV
quant_enc.c:QUANTDIV
Line
Count
Source
119
57.3M
static WEBP_INLINE int QUANTDIV(uint32_t n, uint32_t iQ, uint32_t B) {
120
57.3M
  return (int)((n * iQ + B) >> QFIX);
121
57.3M
}
Unexecuted instantiation: syntax_enc.c:QUANTDIV
Unexecuted instantiation: token_enc.c:QUANTDIV
Unexecuted instantiation: tree_enc.c:QUANTDIV
Unexecuted instantiation: vp8l_enc.c:QUANTDIV
Unexecuted instantiation: backward_references_enc.c:QUANTDIV
Unexecuted instantiation: cost_enc.c:QUANTDIV
Unexecuted instantiation: filter_enc.c:QUANTDIV
Unexecuted instantiation: histogram_enc.c:QUANTDIV
Unexecuted instantiation: picture_rescale_enc.c:QUANTDIV
Unexecuted instantiation: predictor_enc.c:QUANTDIV
122
123
// Uncomment the following to remove token-buffer code:
124
// #define DISABLE_TOKEN_BUFFER
125
126
// quality below which error-diffusion is enabled
127
6.32k
#define ERROR_DIFFUSION_QUALITY 98
128
129
//------------------------------------------------------------------------------
130
// Headers
131
132
typedef uint32_t proba_t;  // 16b + 16b
133
typedef uint8_t ProbaArray[NUM_CTX][NUM_PROBAS];
134
typedef proba_t StatsArray[NUM_CTX][NUM_PROBAS];
135
typedef uint16_t CostArray[NUM_CTX][MAX_VARIABLE_LEVEL + 1];
136
typedef const uint16_t* (*CostArrayPtr)[NUM_CTX];  // for easy casting
137
typedef const uint16_t* CostArrayMap[16][NUM_CTX];
138
typedef double LFStats[NUM_MB_SEGMENTS][MAX_LF_LEVELS];  // filter stats
139
140
typedef struct VP8Encoder VP8Encoder;
141
142
// segment features
143
typedef struct {
144
  int num_segments;  // Actual number of segments. 1 segment only = unused.
145
  int update_map;    // whether to update the segment map or not.
146
                     // must be 0 if there's only 1 segment.
147
  int size;          // bit-cost for transmitting the segment map
148
} VP8EncSegmentHeader;
149
150
// Struct collecting all frame-persistent probabilities.
151
typedef struct {
152
  uint8_t segments[3];  // probabilities for segment tree
153
  uint8_t skip_proba;   // final probability of being skipped.
154
  ProbaArray coeffs[NUM_TYPES][NUM_BANDS];     // 1056 bytes
155
  StatsArray stats[NUM_TYPES][NUM_BANDS];      // 4224 bytes
156
  CostArray level_cost[NUM_TYPES][NUM_BANDS];  // 13056 bytes
157
  CostArrayMap remapped_costs[NUM_TYPES];      // 1536 bytes
158
  int dirty;           // if true, need to call VP8CalculateLevelCosts()
159
  int use_skip_proba;  // Note: we always use skip_proba for now.
160
  int nb_skip;         // number of skipped blocks
161
} VP8EncProba;
162
163
// Filter parameters. Not actually used in the code (we don't perform
164
// the in-loop filtering), but filled from user's config
165
typedef struct {
166
  int simple;         // filtering type: 0=complex, 1=simple
167
  int level;          // base filter level [0..63]
168
  int sharpness;      // [0..7]
169
  int i4x4_lf_delta;  // delta filter level for i4x4 relative to i16x16
170
} VP8EncFilterHeader;
171
172
//------------------------------------------------------------------------------
173
// Informations about the macroblocks.
174
175
typedef struct {
176
  // block type
177
  unsigned int type : 2;  // 0=i4x4, 1=i16x16
178
  unsigned int uv_mode : 2;
179
  unsigned int skip : 1;
180
  unsigned int segment : 2;
181
  uint8_t alpha;  // quantization-susceptibility
182
} VP8MBInfo;
183
184
typedef struct VP8Matrix {
185
  uint16_t q[16];        // quantizer steps
186
  uint16_t iq[16];       // reciprocals, fixed point.
187
  uint32_t bias[16];     // rounding bias
188
  uint32_t zthresh[16];  // value below which a coefficient is zeroed
189
  uint16_t sharpen[16];  // frequency boosters for slight sharpening
190
} VP8Matrix;
191
192
typedef struct {
193
  VP8Matrix y1, y2, uv;  // quantization matrices
194
  int alpha;      // quant-susceptibility, range [-127,127]. Zero is neutral.
195
                  // Lower values indicate a lower risk of blurriness.
196
  int beta;       // filter-susceptibility, range [0,255].
197
  int quant;      // final segment quantizer.
198
  int fstrength;  // final in-loop filtering strength
199
  int max_edge;   // max edge delta (for filtering strength)
200
  int min_disto;  // minimum distortion required to trigger filtering record
201
  // reactivities
202
  int lambda_i16, lambda_i4, lambda_uv;
203
  int lambda_mode, lambda_trellis, tlambda;
204
  int lambda_trellis_i16, lambda_trellis_i4, lambda_trellis_uv;
205
206
  // lambda values for distortion-based evaluation
207
  score_t i4_penalty;  // penalty for using Intra4
208
} VP8SegmentInfo;
209
210
typedef int8_t DError[2 /* u/v */][2 /* top or left */];
211
212
// Handy transient struct to accumulate score and info during RD-optimization
213
// and mode evaluation.
214
typedef struct {
215
  score_t D, SD;            // Distortion, spectral distortion
216
  score_t H, R, score;      // header bits, rate, score.
217
  int16_t y_dc_levels[16];  // Quantized levels for luma-DC, luma-AC, chroma.
218
  int16_t y_ac_levels[16][16];
219
  int16_t uv_levels[4 + 4][16];
220
  int mode_i16;          // mode number for intra16 prediction
221
  uint8_t modes_i4[16];  // mode numbers for intra4 predictions
222
  int mode_uv;           // mode number of chroma prediction
223
  uint32_t nz;           // non-zero blocks
224
  int8_t derr[2][3];     // DC diffusion errors for U/V for blocks #1/2/3
225
} VP8ModeScore;
226
227
// Iterator structure to iterate through macroblocks, pointing to the
228
// right neighbouring data (samples, predictions, contexts, ...)
229
typedef struct {
230
  int x, y;           // current macroblock
231
  uint8_t* yuv_in;    // input samples
232
  uint8_t* yuv_out;   // output samples
233
  uint8_t* yuv_out2;  // secondary buffer swapped with yuv_out.
234
  uint8_t* yuv_p;     // scratch buffer for prediction
235
  VP8Encoder* enc;    // back-pointer
236
  VP8MBInfo* mb;      // current macroblock
237
  VP8BitWriter* bw;   // current bit-writer
238
  uint8_t* preds;     // intra mode predictors (4x4 blocks)
239
  uint32_t* nz;       // non-zero pattern
240
#if WEBP_AARCH64 && BPS == 32
241
  uint8_t i4_boundary[40];  // 32+8 boundary samples needed by intra4x4
242
#else
243
  uint8_t i4_boundary[37];  // 32+5 boundary samples needed by intra4x4
244
#endif
245
  uint8_t* i4_top;           // pointer to the current top boundary sample
246
  int i4;                    // current intra4x4 mode being tested
247
  int top_nz[9];             // top-non-zero context.
248
  int left_nz[9];            // left-non-zero. left_nz[8] is independent.
249
  uint64_t bit_count[4][3];  // bit counters for coded levels.
250
  uint64_t luma_bits;        // macroblock bit-cost for luma
251
  uint64_t uv_bits;          // macroblock bit-cost for chroma
252
  LFStats* lf_stats;         // filter stats (borrowed from enc)
253
  int do_trellis;            // if true, perform extra level optimisation
254
  int count_down;            // number of mb still to be processed
255
  int count_down0;           // starting counter value (for progress)
256
  int percent0;              // saved initial progress percent
257
258
  DError left_derr;  // left error diffusion (u/v)
259
  DError* top_derr;  // top diffusion error - NULL if disabled
260
261
  uint8_t* y_left;  // left luma samples (addressable from index -1 to 15).
262
  uint8_t* u_left;  // left u samples (addressable from index -1 to 7)
263
  uint8_t* v_left;  // left v samples (addressable from index -1 to 7)
264
265
  uint8_t* y_top;   // top luma samples at position 'x'
266
  uint8_t* uv_top;  // top u/v samples at position 'x', packed as 16 bytes
267
268
  // memory for storing y/u/v_left
269
  uint8_t yuv_left_mem[17 + 16 + 16 + 8 + WEBP_ALIGN_CST];
270
  // memory for yuv*
271
  uint8_t yuv_mem[3 * YUV_SIZE_ENC + PRED_SIZE_ENC + WEBP_ALIGN_CST];
272
} VP8EncIterator;
273
274
// in iterator.c
275
// must be called first
276
void VP8IteratorInit(VP8Encoder* const enc, VP8EncIterator* const it);
277
// reset iterator position to row 'y'
278
void VP8IteratorSetRow(VP8EncIterator* const it, int y);
279
// set count down (=number of iterations to go)
280
void VP8IteratorSetCountDown(VP8EncIterator* const it, int count_down);
281
// return true if iteration is finished
282
int VP8IteratorIsDone(const VP8EncIterator* const it);
283
// Import uncompressed samples from source.
284
// If tmp_32 is not NULL, import boundary samples too.
285
// tmp_32 is a 32-bytes scratch buffer that must be aligned in memory.
286
void VP8IteratorImport(VP8EncIterator* const it, uint8_t* const tmp_32);
287
// export decimated samples
288
void VP8IteratorExport(const VP8EncIterator* const it);
289
// go to next macroblock. Returns false if not finished.
290
int VP8IteratorNext(VP8EncIterator* const it);
291
// save the 'yuv_out' boundary values to 'top'/'left' arrays for next
292
// iterations.
293
void VP8IteratorSaveBoundary(VP8EncIterator* const it);
294
// Report progression based on macroblock rows. Return 0 for user-abort request.
295
int VP8IteratorProgress(const VP8EncIterator* const it, int delta);
296
// Intra4x4 iterations
297
void VP8IteratorStartI4(VP8EncIterator* const it);
298
// returns true if not done.
299
int VP8IteratorRotateI4(VP8EncIterator* const it, const uint8_t* const yuv_out);
300
301
// Non-zero context setup/teardown
302
void VP8IteratorNzToBytes(VP8EncIterator* const it);
303
void VP8IteratorBytesToNz(VP8EncIterator* const it);
304
305
// Helper functions to set mode properties
306
void VP8SetIntra16Mode(const VP8EncIterator* const it, int mode);
307
void VP8SetIntra4Mode(const VP8EncIterator* const it, const uint8_t* modes);
308
void VP8SetIntraUVMode(const VP8EncIterator* const it, int mode);
309
void VP8SetSkip(const VP8EncIterator* const it, int skip);
310
void VP8SetSegment(const VP8EncIterator* const it, int segment);
311
312
//------------------------------------------------------------------------------
313
// Paginated token buffer
314
315
typedef struct VP8Tokens VP8Tokens;  // struct details in token.c
316
317
typedef struct {
318
#if !defined(DISABLE_TOKEN_BUFFER)
319
  VP8Tokens* pages;       // first page
320
  VP8Tokens** last_page;  // last page
321
  uint16_t* tokens;       // set to (*last_page)->tokens
322
  int left;               // how many free tokens left before the page is full
323
  int page_size;          // number of tokens per page
324
#endif
325
  int error;  // true in case of malloc error
326
} VP8TBuffer;
327
328
// initialize an empty buffer
329
void VP8TBufferInit(VP8TBuffer* const b, int page_size);
330
void VP8TBufferClear(VP8TBuffer* const b);  // de-allocate pages memory
331
332
#if !defined(DISABLE_TOKEN_BUFFER)
333
334
// Finalizes bitstream when probabilities are known.
335
// Deletes the allocated token memory if final_pass is true.
336
int VP8EmitTokens(VP8TBuffer* const b, VP8BitWriter* const bw,
337
                  const uint8_t* const probas, int final_pass);
338
339
// record the coding of coefficients without knowing the probabilities yet
340
int VP8RecordCoeffTokens(int ctx, const struct VP8Residual* const res,
341
                         VP8TBuffer* const tokens);
342
343
// Estimate the final coded size given a set of 'probas'.
344
size_t VP8EstimateTokenSize(VP8TBuffer* const b, const uint8_t* const probas);
345
346
#endif  // !DISABLE_TOKEN_BUFFER
347
348
//------------------------------------------------------------------------------
349
// VP8Encoder
350
351
struct VP8Encoder {
352
  const WebPConfig* config;  // user configuration and parameters
353
  WebPPicture* pic;          // input / output picture
354
355
  // headers
356
  VP8EncFilterHeader filter_hdr;    // filtering information
357
  VP8EncSegmentHeader segment_hdr;  // segment information
358
359
  int profile;  // VP8's profile, deduced from Config.
360
361
  // dimension, in macroblock units.
362
  int mb_w, mb_h;
363
  int preds_w;  // stride of the *preds prediction plane (=4*mb_w + 1)
364
365
  // number of partitions (1, 2, 4 or 8 = MAX_NUM_PARTITIONS)
366
  int num_parts;
367
368
  // per-partition boolean decoders.
369
  VP8BitWriter bw;                         // part0
370
  VP8BitWriter parts[MAX_NUM_PARTITIONS];  // token partitions
371
  VP8TBuffer tokens;                       // token buffer
372
373
  int percent;  // for progress
374
375
  // transparency blob
376
  int has_alpha;
377
  uint8_t* alpha_data;  // non-NULL if transparency is present
378
  uint32_t alpha_data_size;
379
  WebPWorker alpha_worker;
380
381
  // quantization info (one set of DC/AC dequant factor per segment)
382
  VP8SegmentInfo dqm[NUM_MB_SEGMENTS];
383
  int base_quant;  // nominal quantizer value. Only used
384
                   // for relative coding of segments' quant.
385
  int alpha;       // global susceptibility (<=> complexity)
386
  int uv_alpha;    // U/V quantization susceptibility
387
  // global offset of quantizers, shared by all segments
388
  int dq_y1_dc;
389
  int dq_y2_dc, dq_y2_ac;
390
  int dq_uv_dc, dq_uv_ac;
391
392
  // probabilities and statistics
393
  VP8EncProba proba;
394
  uint64_t sse[4];     // sum of Y/U/V/A squared errors for all macroblocks
395
  uint64_t sse_count;  // pixel count for the sse[] stats
396
  int coded_size;
397
  int residual_bytes[3][4];
398
  int block_count[3];
399
400
  // quality/speed settings
401
  int method;               // 0=fastest, 6=best/slowest.
402
  VP8RDLevel rd_opt_level;  // Deduced from method.
403
  int max_i4_header_bits;   // partition #0 safeness factor
404
  int mb_header_limit;      // rough limit for header bits per MB
405
  int thread_level;         // derived from config->thread_level
406
  int do_search;            // derived from config->target_XXX
407
  int use_tokens;           // if true, use token buffer
408
409
  // Memory
410
  VP8MBInfo* mb_info;  // contextual macroblock infos (mb_w + 1)
411
  uint8_t* preds;      // predictions modes: (4*mb_w+1) * (4*mb_h+1)
412
  uint32_t* nz;        // non-zero bit context: mb_w+1
413
  uint8_t* y_top;      // top luma samples.
414
  uint8_t* uv_top;     // top u/v samples.
415
                       // U and V are packed into 16 bytes (8 U + 8 V)
416
  LFStats* lf_stats;   // autofilter stats (if NULL, autofilter is off)
417
  DError* top_derr;    // diffusion error (NULL if disabled)
418
};
419
420
//------------------------------------------------------------------------------
421
// internal functions. Not public.
422
423
// in tree.c
424
extern const uint8_t VP8CoeffsProba0[NUM_TYPES][NUM_BANDS][NUM_CTX][NUM_PROBAS];
425
extern const uint8_t VP8CoeffsUpdateProba[NUM_TYPES][NUM_BANDS][NUM_CTX]
426
                                         [NUM_PROBAS];
427
// Reset the token probabilities to their initial (default) values
428
void VP8DefaultProbas(VP8Encoder* const enc);
429
// Write the token probabilities
430
void VP8WriteProbas(VP8BitWriter* const bw, const VP8EncProba* const probas);
431
// Writes the partition #0 modes (that is: all intra modes)
432
void VP8CodeIntraModes(VP8Encoder* const enc);
433
434
// in syntax.c
435
// Generates the final bitstream by coding the partition0 and headers,
436
// and appending an assembly of all the pre-coded token partitions.
437
// Return true if everything is ok.
438
int VP8EncWrite(VP8Encoder* const enc);
439
// Release memory allocated for bit-writing in VP8EncLoop & seq.
440
void VP8EncFreeBitWriters(VP8Encoder* const enc);
441
442
// in frame.c
443
extern const uint8_t VP8Cat3[];
444
extern const uint8_t VP8Cat4[];
445
extern const uint8_t VP8Cat5[];
446
extern const uint8_t VP8Cat6[];
447
448
// Form all the four Intra16x16 predictions in the 'yuv_p' cache
449
void VP8MakeLuma16Preds(const VP8EncIterator* const it);
450
// Form all the four Chroma8x8 predictions in the 'yuv_p' cache
451
void VP8MakeChroma8Preds(const VP8EncIterator* const it);
452
// Rate calculation
453
int VP8GetCostLuma16(VP8EncIterator* const it, const VP8ModeScore* const rd);
454
int VP8GetCostLuma4(VP8EncIterator* const it, const int16_t levels[16]);
455
int VP8GetCostUV(VP8EncIterator* const it, const VP8ModeScore* const rd);
456
// Main coding calls
457
int VP8EncLoop(VP8Encoder* const enc);
458
int VP8EncTokenLoop(VP8Encoder* const enc);
459
460
// in webpenc.c
461
// Assign an error code to a picture. Return false for convenience.
462
int WebPEncodingSetError(const WebPPicture* const pic, WebPEncodingError error);
463
int WebPReportProgress(const WebPPicture* const pic, int percent,
464
                       int* const percent_store);
465
466
// in analysis.c
467
// Main analysis loop. Decides the segmentations and complexity.
468
// Assigns a first guess for Intra16 and 'uvmode' prediction modes.
469
int VP8EncAnalyze(VP8Encoder* const enc);
470
471
// in quant.c
472
// Sets up segment's quantization values, 'base_quant' and filter strengths.
473
void VP8SetSegmentParams(VP8Encoder* const enc, float quality);
474
// Pick best modes and fills the levels. Returns true if skipped.
475
int VP8Decimate(VP8EncIterator* WEBP_RESTRICT const it,
476
                VP8ModeScore* WEBP_RESTRICT const rd, VP8RDLevel rd_opt);
477
478
// in alpha.c
479
void VP8EncInitAlpha(VP8Encoder* const enc);   // initialize alpha compression
480
int VP8EncStartAlpha(VP8Encoder* const enc);   // start alpha coding process
481
int VP8EncFinishAlpha(VP8Encoder* const enc);  // finalize compressed data
482
int VP8EncDeleteAlpha(VP8Encoder* const enc);  // delete compressed data
483
484
// autofilter
485
void VP8InitFilter(VP8EncIterator* const it);
486
void VP8StoreFilterStats(VP8EncIterator* const it);
487
void VP8AdjustFilterStrength(VP8EncIterator* const it);
488
489
// returns the approximate filtering strength needed to smooth a edge
490
// step of 'delta', given a sharpness parameter 'sharpness'.
491
int VP8FilterStrengthFromDelta(int sharpness, int delta);
492
493
// misc utils for picture_*.c:
494
495
// Returns true if 'picture' is non-NULL and dimensions/colorspace are within
496
// their valid ranges. If returning false, the 'error_code' in 'picture' is
497
// updated.
498
int WebPValidatePicture(const WebPPicture* const picture);
499
500
// Remove reference to the ARGB/YUVA buffer (doesn't free anything).
501
void WebPPictureResetBuffers(WebPPicture* const picture);
502
503
// Allocates ARGB buffer according to set width/height (previous one is
504
// always free'd). Preserves the YUV(A) buffer. Returns false in case of error
505
// (invalid param, out-of-memory).
506
int WebPPictureAllocARGB(WebPPicture* const picture);
507
508
// Allocates YUVA buffer according to set width/height (previous one is always
509
// free'd). Uses picture->csp to determine whether an alpha buffer is needed.
510
// Preserves the ARGB buffer.
511
// Returns false in case of error (invalid param, out-of-memory).
512
int WebPPictureAllocYUVA(WebPPicture* const picture);
513
514
// Replace samples that are fully transparent by 'color' to help compressibility
515
// (no guarantee, though). Assumes pic->use_argb is true.
516
void WebPReplaceTransparentPixels(WebPPicture* const pic, uint32_t color);
517
518
//------------------------------------------------------------------------------
519
520
#ifdef __cplusplus
521
}  // extern "C"
522
#endif
523
524
#endif  // WEBP_ENC_VP8I_ENC_H_