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