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