New comit of SDL2
[supertux.git] / src / SDL2 / external / libwebp-0.3.0 / src / enc / vp8enci.h
1 // Copyright 2011 Google Inc. All Rights Reserved.
2 //
3 // This code is licensed under the same terms as WebM:
4 //  Software License Agreement:  http://www.webmproject.org/license/software/
5 //  Additional IP Rights Grant:  http://www.webmproject.org/license/additional/
6 // -----------------------------------------------------------------------------
7 //
8 //   WebP encoder: internal header.
9 //
10 // Author: Skal (pascal.massimino@gmail.com)
11
12 #ifndef WEBP_ENC_VP8ENCI_H_
13 #define WEBP_ENC_VP8ENCI_H_
14
15 #include <string.h>     // for memcpy()
16 #include "../webp/encode.h"
17 #include "../dsp/dsp.h"
18 #include "../utils/bit_writer.h"
19 #include "../utils/thread.h"
20
21 #if defined(__cplusplus) || defined(c_plusplus)
22 extern "C" {
23 #endif
24
25 //------------------------------------------------------------------------------
26 // Various defines and enums
27
28 // version numbers
29 #define ENC_MAJ_VERSION 0
30 #define ENC_MIN_VERSION 3
31 #define ENC_REV_VERSION 0
32
33 // intra prediction modes
34 enum { B_DC_PRED = 0,   // 4x4 modes
35        B_TM_PRED = 1,
36        B_VE_PRED = 2,
37        B_HE_PRED = 3,
38        B_RD_PRED = 4,
39        B_VR_PRED = 5,
40        B_LD_PRED = 6,
41        B_VL_PRED = 7,
42        B_HD_PRED = 8,
43        B_HU_PRED = 9,
44        NUM_BMODES = B_HU_PRED + 1 - B_DC_PRED,  // = 10
45
46        // Luma16 or UV modes
47        DC_PRED = B_DC_PRED, V_PRED = B_VE_PRED,
48        H_PRED = B_HE_PRED, TM_PRED = B_TM_PRED,
49        NUM_PRED_MODES = 4
50      };
51
52 enum { NUM_MB_SEGMENTS = 4,
53        MAX_NUM_PARTITIONS = 8,
54        NUM_TYPES = 4,   // 0: i16-AC,  1: i16-DC,  2:chroma-AC,  3:i4-AC
55        NUM_BANDS = 8,
56        NUM_CTX = 3,
57        NUM_PROBAS = 11,
58        MAX_LF_LEVELS = 64,       // Maximum loop filter level
59        MAX_VARIABLE_LEVEL = 67,  // last (inclusive) level with variable cost
60        MAX_LEVEL = 2047          // max level (note: max codable is 2047 + 67)
61      };
62
63 typedef enum {   // Rate-distortion optimization levels
64   RD_OPT_NONE        = 0,  // no rd-opt
65   RD_OPT_BASIC       = 1,  // basic scoring (no trellis)
66   RD_OPT_TRELLIS     = 2,  // perform trellis-quant on the final decision only
67   RD_OPT_TRELLIS_ALL = 3   // trellis-quant for every scoring (much slower)
68 } VP8RDLevel;
69
70 // YUV-cache parameters. Cache is 16-pixels wide.
71 // The original or reconstructed samples can be accessed using VP8Scan[]
72 // The predicted blocks can be accessed using offsets to yuv_p_ and
73 // the arrays VP8*ModeOffsets[];
74 //         +----+      YUV Samples area. See VP8Scan[] for accessing the blocks.
75 //  Y_OFF  |YYYY| <- original samples  (enc->yuv_in_)
76 //         |YYYY|
77 //         |YYYY|
78 //         |YYYY|
79 //  U_OFF  |UUVV| V_OFF  (=U_OFF + 8)
80 //         |UUVV|
81 //         +----+
82 //  Y_OFF  |YYYY| <- compressed/decoded samples  ('yuv_out_')
83 //         |YYYY|    There are two buffers like this ('yuv_out_'/'yuv_out2_')
84 //         |YYYY|
85 //         |YYYY|
86 //  U_OFF  |UUVV| V_OFF
87 //         |UUVV|
88 //          x2 (for yuv_out2_)
89 //         +----+     Prediction area ('yuv_p_', size = PRED_SIZE)
90 // I16DC16 |YYYY|  Intra16 predictions (16x16 block each)
91 //         |YYYY|
92 //         |YYYY|
93 //         |YYYY|
94 // I16TM16 |YYYY|
95 //         |YYYY|
96 //         |YYYY|
97 //         |YYYY|
98 // I16VE16 |YYYY|
99 //         |YYYY|
100 //         |YYYY|
101 //         |YYYY|
102 // I16HE16 |YYYY|
103 //         |YYYY|
104 //         |YYYY|
105 //         |YYYY|
106 //         +----+  Chroma U/V predictions (16x8 block each)
107 // C8DC8   |UUVV|
108 //         |UUVV|
109 // C8TM8   |UUVV|
110 //         |UUVV|
111 // C8VE8   |UUVV|
112 //         |UUVV|
113 // C8HE8   |UUVV|
114 //         |UUVV|
115 //         +----+  Intra 4x4 predictions (4x4 block each)
116 //         |YYYY| I4DC4 I4TM4 I4VE4 I4HE4
117 //         |YYYY| I4RD4 I4VR4 I4LD4 I4VL4
118 //         |YY..| I4HD4 I4HU4 I4TMP
119 //         +----+
120 #define BPS       16   // this is the common stride
121 #define Y_SIZE   (BPS * 16)
122 #define UV_SIZE  (BPS * 8)
123 #define YUV_SIZE (Y_SIZE + UV_SIZE)
124 #define PRED_SIZE (6 * 16 * BPS + 12 * BPS)
125 #define Y_OFF    (0)
126 #define U_OFF    (Y_SIZE)
127 #define V_OFF    (U_OFF + 8)
128 #define ALIGN_CST 15
129 #define DO_ALIGN(PTR) ((uintptr_t)((PTR) + ALIGN_CST) & ~ALIGN_CST)
130
131 extern const int VP8Scan[16 + 4 + 4];           // in quant.c
132 extern const int VP8UVModeOffsets[4];           // in analyze.c
133 extern const int VP8I16ModeOffsets[4];
134 extern const int VP8I4ModeOffsets[NUM_BMODES];
135
136 // Layout of prediction blocks
137 // intra 16x16
138 #define I16DC16 (0 * 16 * BPS)
139 #define I16TM16 (1 * 16 * BPS)
140 #define I16VE16 (2 * 16 * BPS)
141 #define I16HE16 (3 * 16 * BPS)
142 // chroma 8x8, two U/V blocks side by side (hence: 16x8 each)
143 #define C8DC8 (4 * 16 * BPS)
144 #define C8TM8 (4 * 16 * BPS + 8 * BPS)
145 #define C8VE8 (5 * 16 * BPS)
146 #define C8HE8 (5 * 16 * BPS + 8 * BPS)
147 // intra 4x4
148 #define I4DC4 (6 * 16 * BPS +  0)
149 #define I4TM4 (6 * 16 * BPS +  4)
150 #define I4VE4 (6 * 16 * BPS +  8)
151 #define I4HE4 (6 * 16 * BPS + 12)
152 #define I4RD4 (6 * 16 * BPS + 4 * BPS +  0)
153 #define I4VR4 (6 * 16 * BPS + 4 * BPS +  4)
154 #define I4LD4 (6 * 16 * BPS + 4 * BPS +  8)
155 #define I4VL4 (6 * 16 * BPS + 4 * BPS + 12)
156 #define I4HD4 (6 * 16 * BPS + 8 * BPS +  0)
157 #define I4HU4 (6 * 16 * BPS + 8 * BPS +  4)
158 #define I4TMP (6 * 16 * BPS + 8 * BPS +  8)
159
160 typedef int64_t score_t;     // type used for scores, rate, distortion
161 #define MAX_COST ((score_t)0x7fffffffffffffLL)
162
163 #define QFIX 17
164 #define BIAS(b)  ((b) << (QFIX - 8))
165 // Fun fact: this is the _only_ line where we're actually being lossy and
166 // discarding bits.
167 static WEBP_INLINE int QUANTDIV(int n, int iQ, int B) {
168   return (n * iQ + B) >> QFIX;
169 }
170
171 // size of histogram used by CollectHistogram.
172 #define MAX_COEFF_THRESH   31
173 typedef struct VP8Histogram VP8Histogram;
174 struct VP8Histogram {
175   // TODO(skal): we only need to store the max_value and last_non_zero actually.
176   int distribution[MAX_COEFF_THRESH + 1];
177 };
178
179 // Uncomment the following to remove token-buffer code:
180 // #define DISABLE_TOKEN_BUFFER
181
182 //------------------------------------------------------------------------------
183 // Headers
184
185 typedef uint32_t proba_t;   // 16b + 16b
186 typedef uint8_t ProbaArray[NUM_CTX][NUM_PROBAS];
187 typedef proba_t StatsArray[NUM_CTX][NUM_PROBAS];
188 typedef uint16_t CostArray[NUM_CTX][MAX_VARIABLE_LEVEL + 1];
189 typedef double LFStats[NUM_MB_SEGMENTS][MAX_LF_LEVELS];  // filter stats
190
191 typedef struct VP8Encoder VP8Encoder;
192
193 // segment features
194 typedef struct {
195   int num_segments_;      // Actual number of segments. 1 segment only = unused.
196   int update_map_;        // whether to update the segment map or not.
197                           // must be 0 if there's only 1 segment.
198   int size_;              // bit-cost for transmitting the segment map
199 } VP8SegmentHeader;
200
201 // Struct collecting all frame-persistent probabilities.
202 typedef struct {
203   uint8_t segments_[3];     // probabilities for segment tree
204   uint8_t skip_proba_;      // final probability of being skipped.
205   ProbaArray coeffs_[NUM_TYPES][NUM_BANDS];      // 924 bytes
206   StatsArray stats_[NUM_TYPES][NUM_BANDS];       // 4224 bytes
207   CostArray level_cost_[NUM_TYPES][NUM_BANDS];   // 11.4k
208   int dirty_;               // if true, need to call VP8CalculateLevelCosts()
209   int use_skip_proba_;      // Note: we always use skip_proba for now.
210   int nb_skip_;             // number of skipped blocks
211 } VP8Proba;
212
213 // Filter parameters. Not actually used in the code (we don't perform
214 // the in-loop filtering), but filled from user's config
215 typedef struct {
216   int simple_;             // filtering type: 0=complex, 1=simple
217   int level_;              // base filter level [0..63]
218   int sharpness_;          // [0..7]
219   int i4x4_lf_delta_;      // delta filter level for i4x4 relative to i16x16
220 } VP8FilterHeader;
221
222 //------------------------------------------------------------------------------
223 // Informations about the macroblocks.
224
225 typedef struct {
226   // block type
227   unsigned int type_:2;     // 0=i4x4, 1=i16x16
228   unsigned int uv_mode_:2;
229   unsigned int skip_:1;
230   unsigned int segment_:2;
231   uint8_t alpha_;      // quantization-susceptibility
232 } VP8MBInfo;
233
234 typedef struct VP8Matrix {
235   uint16_t q_[16];        // quantizer steps
236   uint16_t iq_[16];       // reciprocals, fixed point.
237   uint16_t bias_[16];     // rounding bias
238   uint16_t zthresh_[16];  // value under which a coefficient is zeroed
239   uint16_t sharpen_[16];  // frequency boosters for slight sharpening
240 } VP8Matrix;
241
242 typedef struct {
243   VP8Matrix y1_, y2_, uv_;  // quantization matrices
244   int alpha_;      // quant-susceptibility, range [-127,127]. Zero is neutral.
245                    // Lower values indicate a lower risk of blurriness.
246   int beta_;       // filter-susceptibility, range [0,255].
247   int quant_;      // final segment quantizer.
248   int fstrength_;  // final in-loop filtering strength
249   // reactivities
250   int lambda_i16_, lambda_i4_, lambda_uv_;
251   int lambda_mode_, lambda_trellis_, tlambda_;
252   int lambda_trellis_i16_, lambda_trellis_i4_, lambda_trellis_uv_;
253 } VP8SegmentInfo;
254
255 // Handy transcient struct to accumulate score and info during RD-optimization
256 // and mode evaluation.
257 typedef struct {
258   score_t D, SD, R, score;    // Distortion, spectral distortion, rate, score.
259   int16_t y_dc_levels[16];    // Quantized levels for luma-DC, luma-AC, chroma.
260   int16_t y_ac_levels[16][16];
261   int16_t uv_levels[4 + 4][16];
262   int mode_i16;               // mode number for intra16 prediction
263   uint8_t modes_i4[16];       // mode numbers for intra4 predictions
264   int mode_uv;                // mode number of chroma prediction
265   uint32_t nz;                // non-zero blocks
266 } VP8ModeScore;
267
268 // Iterator structure to iterate through macroblocks, pointing to the
269 // right neighbouring data (samples, predictions, contexts, ...)
270 typedef struct {
271   int x_, y_;                      // current macroblock
272   int y_offset_, uv_offset_;       // offset to the luma / chroma planes
273   int y_stride_, uv_stride_;       // respective strides
274   uint8_t*      yuv_in_;           // borrowed from enc_ (for now)
275   uint8_t*      yuv_out_;          // ''
276   uint8_t*      yuv_out2_;         // ''
277   uint8_t*      yuv_p_;            // ''
278   VP8Encoder*   enc_;              // back-pointer
279   VP8MBInfo*    mb_;               // current macroblock
280   VP8BitWriter* bw_;               // current bit-writer
281   uint8_t*      preds_;            // intra mode predictors (4x4 blocks)
282   uint32_t*     nz_;               // non-zero pattern
283   uint8_t       i4_boundary_[37];  // 32+5 boundary samples needed by intra4x4
284   uint8_t*      i4_top_;           // pointer to the current top boundary sample
285   int           i4_;               // current intra4x4 mode being tested
286   int           top_nz_[9];        // top-non-zero context.
287   int           left_nz_[9];       // left-non-zero. left_nz[8] is independent.
288   uint64_t      bit_count_[4][3];  // bit counters for coded levels.
289   uint64_t      luma_bits_;        // macroblock bit-cost for luma
290   uint64_t      uv_bits_;          // macroblock bit-cost for chroma
291   LFStats*      lf_stats_;         // filter stats (borrowed from enc_)
292   int           do_trellis_;       // if true, perform extra level optimisation
293   int           done_;             // true when scan is finished
294   int           percent0_;         // saved initial progress percent
295 } VP8EncIterator;
296
297   // in iterator.c
298 // must be called first.
299 void VP8IteratorInit(VP8Encoder* const enc, VP8EncIterator* const it);
300 // restart a scan.
301 void VP8IteratorReset(VP8EncIterator* const it);
302 // import samples from source
303 void VP8IteratorImport(const VP8EncIterator* const it);
304 // export decimated samples
305 void VP8IteratorExport(const VP8EncIterator* const it);
306 // go to next macroblock. Returns !done_. If *block_to_save is non-null, will
307 // save the boundary values to top_/left_ arrays. block_to_save can be
308 // it->yuv_out_ or it->yuv_in_.
309 int VP8IteratorNext(VP8EncIterator* const it,
310                     const uint8_t* const block_to_save);
311 // Report progression based on macroblock rows. Return 0 for user-abort request.
312 int VP8IteratorProgress(const VP8EncIterator* const it,
313                         int final_delta_percent);
314 // Intra4x4 iterations
315 void VP8IteratorStartI4(VP8EncIterator* const it);
316 // returns true if not done.
317 int VP8IteratorRotateI4(VP8EncIterator* const it,
318                         const uint8_t* const yuv_out);
319
320 // Non-zero context setup/teardown
321 void VP8IteratorNzToBytes(VP8EncIterator* const it);
322 void VP8IteratorBytesToNz(VP8EncIterator* const it);
323
324 // Helper functions to set mode properties
325 void VP8SetIntra16Mode(const VP8EncIterator* const it, int mode);
326 void VP8SetIntra4Mode(const VP8EncIterator* const it, const uint8_t* modes);
327 void VP8SetIntraUVMode(const VP8EncIterator* const it, int mode);
328 void VP8SetSkip(const VP8EncIterator* const it, int skip);
329 void VP8SetSegment(const VP8EncIterator* const it, int segment);
330
331 //------------------------------------------------------------------------------
332 // Paginated token buffer
333
334 typedef struct VP8Tokens VP8Tokens;  // struct details in token.c
335
336 typedef struct {
337 #if !defined(DISABLE_TOKEN_BUFFER)
338   VP8Tokens* pages_;        // first page
339   VP8Tokens** last_page_;   // last page
340   uint16_t* tokens_;        // set to (*last_page_)->tokens_
341   int left_;          // how many free tokens left before the page is full.
342 #endif
343   int error_;         // true in case of malloc error
344 } VP8TBuffer;
345
346 void VP8TBufferInit(VP8TBuffer* const b);    // initialize an empty buffer
347 void VP8TBufferClear(VP8TBuffer* const b);   // de-allocate pages memory
348
349 #if !defined(DISABLE_TOKEN_BUFFER)
350
351 // Finalizes bitstream when probabilities are known.
352 // Deletes the allocated token memory if final_pass is true.
353 int VP8EmitTokens(VP8TBuffer* const b, VP8BitWriter* const bw,
354                   const uint8_t* const probas, int final_pass);
355
356 // record the coding of coefficients without knowing the probabilities yet
357 int VP8RecordCoeffTokens(int ctx, int coeff_type, int first, int last,
358                          const int16_t* const coeffs,
359                          VP8TBuffer* const tokens);
360
361 // unused for now
362 void VP8TokenToStats(const VP8TBuffer* const b, proba_t* const stats);
363
364 #endif  // !DISABLE_TOKEN_BUFFER
365
366 //------------------------------------------------------------------------------
367 // VP8Encoder
368
369 struct VP8Encoder {
370   const WebPConfig* config_;    // user configuration and parameters
371   WebPPicture* pic_;            // input / output picture
372
373   // headers
374   VP8FilterHeader   filter_hdr_;     // filtering information
375   VP8SegmentHeader  segment_hdr_;    // segment information
376
377   int profile_;                      // VP8's profile, deduced from Config.
378
379   // dimension, in macroblock units.
380   int mb_w_, mb_h_;
381   int preds_w_;   // stride of the *preds_ prediction plane (=4*mb_w + 1)
382
383   // number of partitions (1, 2, 4 or 8 = MAX_NUM_PARTITIONS)
384   int num_parts_;
385
386   // per-partition boolean decoders.
387   VP8BitWriter bw_;                         // part0
388   VP8BitWriter parts_[MAX_NUM_PARTITIONS];  // token partitions
389   VP8TBuffer tokens_;                       // token buffer
390
391   int percent_;                             // for progress
392
393   // transparency blob
394   int has_alpha_;
395   uint8_t* alpha_data_;       // non-NULL if transparency is present
396   uint32_t alpha_data_size_;
397   WebPWorker alpha_worker_;
398
399   // enhancement layer
400   int use_layer_;
401   VP8BitWriter layer_bw_;
402   uint8_t* layer_data_;
403   size_t layer_data_size_;
404
405   // quantization info (one set of DC/AC dequant factor per segment)
406   VP8SegmentInfo dqm_[NUM_MB_SEGMENTS];
407   int base_quant_;                 // nominal quantizer value. Only used
408                                    // for relative coding of segments' quant.
409   int alpha_;                      // global susceptibility (<=> complexity)
410   int uv_alpha_;                   // U/V quantization susceptibility
411   // global offset of quantizers, shared by all segments
412   int dq_y1_dc_;
413   int dq_y2_dc_, dq_y2_ac_;
414   int dq_uv_dc_, dq_uv_ac_;
415
416   // probabilities and statistics
417   VP8Proba proba_;
418   uint64_t sse_[4];        // sum of Y/U/V/A squared errors for all macroblocks
419   uint64_t sse_count_;     // pixel count for the sse_[] stats
420   int      coded_size_;
421   int      residual_bytes_[3][4];
422   int      block_count_[3];
423
424   // quality/speed settings
425   int method_;               // 0=fastest, 6=best/slowest.
426   VP8RDLevel rd_opt_level_;  // Deduced from method_.
427   int max_i4_header_bits_;   // partition #0 safeness factor
428   int thread_level_;         // derived from config->thread_level
429   int do_search_;            // derived from config->target_XXX
430   int use_tokens_;           // if true, use token buffer
431
432   // Memory
433   VP8MBInfo* mb_info_;   // contextual macroblock infos (mb_w_ + 1)
434   uint8_t*   preds_;     // predictions modes: (4*mb_w+1) * (4*mb_h+1)
435   uint32_t*  nz_;        // non-zero bit context: mb_w+1
436   uint8_t*   yuv_in_;    // input samples
437   uint8_t*   yuv_out_;   // output samples
438   uint8_t*   yuv_out2_;  // secondary scratch out-buffer. swapped with yuv_out_.
439   uint8_t*   yuv_p_;     // scratch buffer for prediction
440   uint8_t   *y_top_;     // top luma samples.
441   uint8_t   *uv_top_;    // top u/v samples.
442                          // U and V are packed into 16 pixels (8 U + 8 V)
443   uint8_t   *y_left_;    // left luma samples (adressable from index -1 to 15).
444   uint8_t   *u_left_;    // left u samples (adressable from index -1 to 7)
445   uint8_t   *v_left_;    // left v samples (adressable from index -1 to 7)
446
447   LFStats   *lf_stats_;  // autofilter stats (if NULL, autofilter is off)
448 };
449
450 //------------------------------------------------------------------------------
451 // internal functions. Not public.
452
453   // in tree.c
454 extern const uint8_t VP8CoeffsProba0[NUM_TYPES][NUM_BANDS][NUM_CTX][NUM_PROBAS];
455 extern const uint8_t
456     VP8CoeffsUpdateProba[NUM_TYPES][NUM_BANDS][NUM_CTX][NUM_PROBAS];
457 // Reset the token probabilities to their initial (default) values
458 void VP8DefaultProbas(VP8Encoder* const enc);
459 // Write the token probabilities
460 void VP8WriteProbas(VP8BitWriter* const bw, const VP8Proba* const probas);
461 // Writes the partition #0 modes (that is: all intra modes)
462 void VP8CodeIntraModes(VP8Encoder* const enc);
463
464   // in syntax.c
465 // Generates the final bitstream by coding the partition0 and headers,
466 // and appending an assembly of all the pre-coded token partitions.
467 // Return true if everything is ok.
468 int VP8EncWrite(VP8Encoder* const enc);
469 // Release memory allocated for bit-writing in VP8EncLoop & seq.
470 void VP8EncFreeBitWriters(VP8Encoder* const enc);
471
472   // in frame.c
473 extern const uint8_t VP8EncBands[16 + 1];
474 extern const uint8_t VP8Cat3[];
475 extern const uint8_t VP8Cat4[];
476 extern const uint8_t VP8Cat5[];
477 extern const uint8_t VP8Cat6[];
478
479 // Form all the four Intra16x16 predictions in the yuv_p_ cache
480 void VP8MakeLuma16Preds(const VP8EncIterator* const it);
481 // Form all the four Chroma8x8 predictions in the yuv_p_ cache
482 void VP8MakeChroma8Preds(const VP8EncIterator* const it);
483 // Form all the ten Intra4x4 predictions in the yuv_p_ cache
484 // for the 4x4 block it->i4_
485 void VP8MakeIntra4Preds(const VP8EncIterator* const it);
486 // Rate calculation
487 int VP8GetCostLuma16(VP8EncIterator* const it, const VP8ModeScore* const rd);
488 int VP8GetCostLuma4(VP8EncIterator* const it, const int16_t levels[16]);
489 int VP8GetCostUV(VP8EncIterator* const it, const VP8ModeScore* const rd);
490 // Main coding calls
491 int VP8EncLoop(VP8Encoder* const enc);
492 int VP8EncTokenLoop(VP8Encoder* const enc);
493
494   // in webpenc.c
495 // Assign an error code to a picture. Return false for convenience.
496 int WebPEncodingSetError(const WebPPicture* const pic, WebPEncodingError error);
497 int WebPReportProgress(const WebPPicture* const pic,
498                        int percent, int* const percent_store);
499
500   // in analysis.c
501 // Main analysis loop. Decides the segmentations and complexity.
502 // Assigns a first guess for Intra16 and uvmode_ prediction modes.
503 int VP8EncAnalyze(VP8Encoder* const enc);
504
505   // in quant.c
506 // Sets up segment's quantization values, base_quant_ and filter strengths.
507 void VP8SetSegmentParams(VP8Encoder* const enc, float quality);
508 // Pick best modes and fills the levels. Returns true if skipped.
509 int VP8Decimate(VP8EncIterator* const it, VP8ModeScore* const rd,
510                 VP8RDLevel rd_opt);
511
512   // in alpha.c
513 void VP8EncInitAlpha(VP8Encoder* const enc);    // initialize alpha compression
514 int VP8EncStartAlpha(VP8Encoder* const enc);    // start alpha coding process
515 int VP8EncFinishAlpha(VP8Encoder* const enc);   // finalize compressed data
516 int VP8EncDeleteAlpha(VP8Encoder* const enc);   // delete compressed data
517
518   // in layer.c
519 void VP8EncInitLayer(VP8Encoder* const enc);     // init everything
520 void VP8EncCodeLayerBlock(VP8EncIterator* it);   // code one more macroblock
521 int VP8EncFinishLayer(VP8Encoder* const enc);    // finalize coding
522 void VP8EncDeleteLayer(VP8Encoder* enc);         // reclaim memory
523
524   // in filter.c
525
526 // SSIM utils
527 typedef struct {
528   double w, xm, ym, xxm, xym, yym;
529 } DistoStats;
530 void VP8SSIMAddStats(const DistoStats* const src, DistoStats* const dst);
531 void VP8SSIMAccumulatePlane(const uint8_t* src1, int stride1,
532                             const uint8_t* src2, int stride2,
533                             int W, int H, DistoStats* const stats);
534 double VP8SSIMGet(const DistoStats* const stats);
535 double VP8SSIMGetSquaredError(const DistoStats* const stats);
536
537 // autofilter
538 void VP8InitFilter(VP8EncIterator* const it);
539 void VP8StoreFilterStats(VP8EncIterator* const it);
540 void VP8AdjustFilterStrength(VP8EncIterator* const it);
541
542 //------------------------------------------------------------------------------
543
544 #if defined(__cplusplus) || defined(c_plusplus)
545 }    // extern "C"
546 #endif
547
548 #endif  /* WEBP_ENC_VP8ENCI_H_ */