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