vp8i_enc.h 21 KB

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