Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Side by Side Diff: third_party/libwebp/enc/vp8enci.h

Issue 116213006: Update libwebp to 0.4.0 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: After Blink Roll Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/libwebp/enc/tree.c ('k') | third_party/libwebp/enc/vp8l.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 Google Inc. All Rights Reserved. 1 // Copyright 2011 Google Inc. All Rights Reserved.
2 // 2 //
3 // Use of this source code is governed by a BSD-style license 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 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 5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS. All contributing project authors may 6 // in the file PATENTS. All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree. 7 // be found in the AUTHORS file in the root of the source tree.
8 // ----------------------------------------------------------------------------- 8 // -----------------------------------------------------------------------------
9 // 9 //
10 // WebP encoder: internal header. 10 // WebP encoder: internal header.
11 // 11 //
12 // Author: Skal (pascal.massimino@gmail.com) 12 // Author: Skal (pascal.massimino@gmail.com)
13 13
14 #ifndef WEBP_ENC_VP8ENCI_H_ 14 #ifndef WEBP_ENC_VP8ENCI_H_
15 #define WEBP_ENC_VP8ENCI_H_ 15 #define WEBP_ENC_VP8ENCI_H_
16 16
17 #include <string.h> // for memcpy() 17 #include <string.h> // for memcpy()
18 #include "../webp/encode.h" 18 #include "../webp/encode.h"
19 #include "../dsp/dsp.h" 19 #include "../dsp/dsp.h"
20 #include "../utils/bit_writer.h" 20 #include "../utils/bit_writer.h"
21 #include "../utils/thread.h" 21 #include "../utils/thread.h"
22 22
23 #if defined(__cplusplus) || defined(c_plusplus) 23 #ifdef __cplusplus
24 extern "C" { 24 extern "C" {
25 #endif 25 #endif
26 26
27 //------------------------------------------------------------------------------ 27 //------------------------------------------------------------------------------
28 // Various defines and enums 28 // Various defines and enums
29 29
30 // version numbers 30 // version numbers
31 #define ENC_MAJ_VERSION 0 31 #define ENC_MAJ_VERSION 0
32 #define ENC_MIN_VERSION 3 32 #define ENC_MIN_VERSION 4
33 #define ENC_REV_VERSION 1 33 #define ENC_REV_VERSION 0
34 34
35 // intra prediction modes 35 // intra prediction modes
36 enum { B_DC_PRED = 0, // 4x4 modes 36 enum { B_DC_PRED = 0, // 4x4 modes
37 B_TM_PRED = 1, 37 B_TM_PRED = 1,
38 B_VE_PRED = 2, 38 B_VE_PRED = 2,
39 B_HE_PRED = 3, 39 B_HE_PRED = 3,
40 B_RD_PRED = 4, 40 B_RD_PRED = 4,
41 B_VR_PRED = 5, 41 B_VR_PRED = 5,
42 B_LD_PRED = 6, 42 B_LD_PRED = 6,
43 B_VL_PRED = 7, 43 B_VL_PRED = 7,
(...skipping 23 matching lines...) Expand all
67 RD_OPT_BASIC = 1, // basic scoring (no trellis) 67 RD_OPT_BASIC = 1, // basic scoring (no trellis)
68 RD_OPT_TRELLIS = 2, // perform trellis-quant on the final decision only 68 RD_OPT_TRELLIS = 2, // perform trellis-quant on the final decision only
69 RD_OPT_TRELLIS_ALL = 3 // trellis-quant for every scoring (much slower) 69 RD_OPT_TRELLIS_ALL = 3 // trellis-quant for every scoring (much slower)
70 } VP8RDLevel; 70 } VP8RDLevel;
71 71
72 // YUV-cache parameters. Cache is 16-pixels wide. 72 // YUV-cache parameters. Cache is 16-pixels wide.
73 // The original or reconstructed samples can be accessed using VP8Scan[] 73 // The original or reconstructed samples can be accessed using VP8Scan[]
74 // The predicted blocks can be accessed using offsets to yuv_p_ and 74 // The predicted blocks can be accessed using offsets to yuv_p_ and
75 // the arrays VP8*ModeOffsets[]; 75 // the arrays VP8*ModeOffsets[];
76 // +----+ YUV Samples area. See VP8Scan[] for accessing the blocks. 76 // +----+ YUV Samples area. See VP8Scan[] for accessing the blocks.
77 // Y_OFF |YYYY| <- original samples (enc->yuv_in_) 77 // Y_OFF |YYYY| <- original samples ('yuv_in_')
78 // |YYYY| 78 // |YYYY|
79 // |YYYY| 79 // |YYYY|
80 // |YYYY| 80 // |YYYY|
81 // U_OFF |UUVV| V_OFF (=U_OFF + 8) 81 // U_OFF |UUVV| V_OFF (=U_OFF + 8)
82 // |UUVV| 82 // |UUVV|
83 // +----+ 83 // +----+
84 // Y_OFF |YYYY| <- compressed/decoded samples ('yuv_out_') 84 // Y_OFF |YYYY| <- compressed/decoded samples ('yuv_out_')
85 // |YYYY| There are two buffers like this ('yuv_out_'/'yuv_out2_') 85 // |YYYY| There are two buffers like this ('yuv_out_'/'yuv_out2_')
86 // |YYYY| 86 // |YYYY|
87 // |YYYY| 87 // |YYYY|
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 uint16_t sharpen_[16]; // frequency boosters for slight sharpening 241 uint16_t sharpen_[16]; // frequency boosters for slight sharpening
242 } VP8Matrix; 242 } VP8Matrix;
243 243
244 typedef struct { 244 typedef struct {
245 VP8Matrix y1_, y2_, uv_; // quantization matrices 245 VP8Matrix y1_, y2_, uv_; // quantization matrices
246 int alpha_; // quant-susceptibility, range [-127,127]. Zero is neutral. 246 int alpha_; // quant-susceptibility, range [-127,127]. Zero is neutral.
247 // Lower values indicate a lower risk of blurriness. 247 // Lower values indicate a lower risk of blurriness.
248 int beta_; // filter-susceptibility, range [0,255]. 248 int beta_; // filter-susceptibility, range [0,255].
249 int quant_; // final segment quantizer. 249 int quant_; // final segment quantizer.
250 int fstrength_; // final in-loop filtering strength 250 int fstrength_; // final in-loop filtering strength
251 int max_edge_; // max edge delta (for filtering strength)
252 int min_disto_; // minimum distortion required to trigger filtering record
251 // reactivities 253 // reactivities
252 int lambda_i16_, lambda_i4_, lambda_uv_; 254 int lambda_i16_, lambda_i4_, lambda_uv_;
253 int lambda_mode_, lambda_trellis_, tlambda_; 255 int lambda_mode_, lambda_trellis_, tlambda_;
254 int lambda_trellis_i16_, lambda_trellis_i4_, lambda_trellis_uv_; 256 int lambda_trellis_i16_, lambda_trellis_i4_, lambda_trellis_uv_;
255 } VP8SegmentInfo; 257 } VP8SegmentInfo;
256 258
257 // Handy transcient struct to accumulate score and info during RD-optimization 259 // Handy transient struct to accumulate score and info during RD-optimization
258 // and mode evaluation. 260 // and mode evaluation.
259 typedef struct { 261 typedef struct {
260 score_t D, SD, R, score; // Distortion, spectral distortion, rate, score. 262 score_t D, SD; // Distortion, spectral distortion
263 score_t H, R, score; // header bits, rate, score.
261 int16_t y_dc_levels[16]; // Quantized levels for luma-DC, luma-AC, chroma. 264 int16_t y_dc_levels[16]; // Quantized levels for luma-DC, luma-AC, chroma.
262 int16_t y_ac_levels[16][16]; 265 int16_t y_ac_levels[16][16];
263 int16_t uv_levels[4 + 4][16]; 266 int16_t uv_levels[4 + 4][16];
264 int mode_i16; // mode number for intra16 prediction 267 int mode_i16; // mode number for intra16 prediction
265 uint8_t modes_i4[16]; // mode numbers for intra4 predictions 268 uint8_t modes_i4[16]; // mode numbers for intra4 predictions
266 int mode_uv; // mode number of chroma prediction 269 int mode_uv; // mode number of chroma prediction
267 uint32_t nz; // non-zero blocks 270 uint32_t nz; // non-zero blocks
268 } VP8ModeScore; 271 } VP8ModeScore;
269 272
270 // Iterator structure to iterate through macroblocks, pointing to the 273 // Iterator structure to iterate through macroblocks, pointing to the
271 // right neighbouring data (samples, predictions, contexts, ...) 274 // right neighbouring data (samples, predictions, contexts, ...)
272 typedef struct { 275 typedef struct {
273 int x_, y_; // current macroblock 276 int x_, y_; // current macroblock
274 int y_offset_, uv_offset_; // offset to the luma / chroma planes
275 int y_stride_, uv_stride_; // respective strides 277 int y_stride_, uv_stride_; // respective strides
276 uint8_t* yuv_in_; // borrowed from enc_ (for now) 278 uint8_t* yuv_in_; // input samples
277 uint8_t* yuv_out_; // '' 279 uint8_t* yuv_out_; // output samples
278 uint8_t* yuv_out2_; // '' 280 uint8_t* yuv_out2_; // secondary buffer swapped with yuv_out_.
279 uint8_t* yuv_p_; // '' 281 uint8_t* yuv_p_; // scratch buffer for prediction
280 VP8Encoder* enc_; // back-pointer 282 VP8Encoder* enc_; // back-pointer
281 VP8MBInfo* mb_; // current macroblock 283 VP8MBInfo* mb_; // current macroblock
282 VP8BitWriter* bw_; // current bit-writer 284 VP8BitWriter* bw_; // current bit-writer
283 uint8_t* preds_; // intra mode predictors (4x4 blocks) 285 uint8_t* preds_; // intra mode predictors (4x4 blocks)
284 uint32_t* nz_; // non-zero pattern 286 uint32_t* nz_; // non-zero pattern
285 uint8_t i4_boundary_[37]; // 32+5 boundary samples needed by intra4x4 287 uint8_t i4_boundary_[37]; // 32+5 boundary samples needed by intra4x4
286 uint8_t* i4_top_; // pointer to the current top boundary sample 288 uint8_t* i4_top_; // pointer to the current top boundary sample
287 int i4_; // current intra4x4 mode being tested 289 int i4_; // current intra4x4 mode being tested
288 int top_nz_[9]; // top-non-zero context. 290 int top_nz_[9]; // top-non-zero context.
289 int left_nz_[9]; // left-non-zero. left_nz[8] is independent. 291 int left_nz_[9]; // left-non-zero. left_nz[8] is independent.
290 uint64_t bit_count_[4][3]; // bit counters for coded levels. 292 uint64_t bit_count_[4][3]; // bit counters for coded levels.
291 uint64_t luma_bits_; // macroblock bit-cost for luma 293 uint64_t luma_bits_; // macroblock bit-cost for luma
292 uint64_t uv_bits_; // macroblock bit-cost for chroma 294 uint64_t uv_bits_; // macroblock bit-cost for chroma
293 LFStats* lf_stats_; // filter stats (borrowed from enc_) 295 LFStats* lf_stats_; // filter stats (borrowed from enc_)
294 int do_trellis_; // if true, perform extra level optimisation 296 int do_trellis_; // if true, perform extra level optimisation
295 int done_; // true when scan is finished 297 int count_down_; // number of mb still to be processed
298 int count_down0_; // starting counter value (for progress)
296 int percent0_; // saved initial progress percent 299 int percent0_; // saved initial progress percent
300
301 uint8_t* y_left_; // left luma samples (addressable from index -1 to 15).
302 uint8_t* u_left_; // left u samples (addressable from index -1 to 7)
303 uint8_t* v_left_; // left v samples (addressable from index -1 to 7)
304
305 uint8_t* y_top_; // top luma samples at position 'x_'
306 uint8_t* uv_top_; // top u/v samples at position 'x_', packed as 16 bytes
307
308 // memory for storing y/u/v_left_ and yuv_in_/out_*
309 uint8_t yuv_left_mem_[17 + 16 + 16 + 8 + ALIGN_CST]; // memory for *_left_
310 uint8_t yuv_mem_[3 * YUV_SIZE + PRED_SIZE + ALIGN_CST]; // memory for yuv_*
297 } VP8EncIterator; 311 } VP8EncIterator;
298 312
299 // in iterator.c 313 // in iterator.c
300 // must be called first. 314 // must be called first
301 void VP8IteratorInit(VP8Encoder* const enc, VP8EncIterator* const it); 315 void VP8IteratorInit(VP8Encoder* const enc, VP8EncIterator* const it);
302 // restart a scan. 316 // restart a scan
303 void VP8IteratorReset(VP8EncIterator* const it); 317 void VP8IteratorReset(VP8EncIterator* const it);
304 // import samples from source 318 // reset iterator position to row 'y'
305 void VP8IteratorImport(const VP8EncIterator* const it); 319 void VP8IteratorSetRow(VP8EncIterator* const it, int y);
320 // set count down (=number of iterations to go)
321 void VP8IteratorSetCountDown(VP8EncIterator* const it, int count_down);
322 // return true if iteration is finished
323 int VP8IteratorIsDone(const VP8EncIterator* const it);
324 // Import uncompressed samples from source.
325 // If tmp_32 is not NULL, import boundary samples too.
326 // tmp_32 is a 32-bytes scratch buffer that must be aligned in memory.
327 void VP8IteratorImport(VP8EncIterator* const it, uint8_t* tmp_32);
306 // export decimated samples 328 // export decimated samples
307 void VP8IteratorExport(const VP8EncIterator* const it); 329 void VP8IteratorExport(const VP8EncIterator* const it);
308 // go to next macroblock. Returns !done_. If *block_to_save is non-null, will 330 // go to next macroblock. Returns false if not finished.
309 // save the boundary values to top_/left_ arrays. block_to_save can be 331 int VP8IteratorNext(VP8EncIterator* const it);
310 // it->yuv_out_ or it->yuv_in_. 332 // save the yuv_out_ boundary values to top_/left_ arrays for next iterations.
311 int VP8IteratorNext(VP8EncIterator* const it, 333 void VP8IteratorSaveBoundary(VP8EncIterator* const it);
312 const uint8_t* const block_to_save);
313 // Report progression based on macroblock rows. Return 0 for user-abort request. 334 // Report progression based on macroblock rows. Return 0 for user-abort request.
314 int VP8IteratorProgress(const VP8EncIterator* const it, 335 int VP8IteratorProgress(const VP8EncIterator* const it,
315 int final_delta_percent); 336 int final_delta_percent);
316 // Intra4x4 iterations 337 // Intra4x4 iterations
317 void VP8IteratorStartI4(VP8EncIterator* const it); 338 void VP8IteratorStartI4(VP8EncIterator* const it);
318 // returns true if not done. 339 // returns true if not done.
319 int VP8IteratorRotateI4(VP8EncIterator* const it, 340 int VP8IteratorRotateI4(VP8EncIterator* const it,
320 const uint8_t* const yuv_out); 341 const uint8_t* const yuv_out);
321 342
322 // Non-zero context setup/teardown 343 // Non-zero context setup/teardown
(...skipping 30 matching lines...) Expand all
353 // Finalizes bitstream when probabilities are known. 374 // Finalizes bitstream when probabilities are known.
354 // Deletes the allocated token memory if final_pass is true. 375 // Deletes the allocated token memory if final_pass is true.
355 int VP8EmitTokens(VP8TBuffer* const b, VP8BitWriter* const bw, 376 int VP8EmitTokens(VP8TBuffer* const b, VP8BitWriter* const bw,
356 const uint8_t* const probas, int final_pass); 377 const uint8_t* const probas, int final_pass);
357 378
358 // record the coding of coefficients without knowing the probabilities yet 379 // record the coding of coefficients without knowing the probabilities yet
359 int VP8RecordCoeffTokens(int ctx, int coeff_type, int first, int last, 380 int VP8RecordCoeffTokens(int ctx, int coeff_type, int first, int last,
360 const int16_t* const coeffs, 381 const int16_t* const coeffs,
361 VP8TBuffer* const tokens); 382 VP8TBuffer* const tokens);
362 383
384 // Estimate the final coded size given a set of 'probas'.
385 size_t VP8EstimateTokenSize(VP8TBuffer* const b, const uint8_t* const probas);
386
363 // unused for now 387 // unused for now
364 void VP8TokenToStats(const VP8TBuffer* const b, proba_t* const stats); 388 void VP8TokenToStats(const VP8TBuffer* const b, proba_t* const stats);
365 389
366 #endif // !DISABLE_TOKEN_BUFFER 390 #endif // !DISABLE_TOKEN_BUFFER
367 391
368 //------------------------------------------------------------------------------ 392 //------------------------------------------------------------------------------
369 // VP8Encoder 393 // VP8Encoder
370 394
371 struct VP8Encoder { 395 struct VP8Encoder {
372 const WebPConfig* config_; // user configuration and parameters 396 const WebPConfig* config_; // user configuration and parameters
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 VP8RDLevel rd_opt_level_; // Deduced from method_. 452 VP8RDLevel rd_opt_level_; // Deduced from method_.
429 int max_i4_header_bits_; // partition #0 safeness factor 453 int max_i4_header_bits_; // partition #0 safeness factor
430 int thread_level_; // derived from config->thread_level 454 int thread_level_; // derived from config->thread_level
431 int do_search_; // derived from config->target_XXX 455 int do_search_; // derived from config->target_XXX
432 int use_tokens_; // if true, use token buffer 456 int use_tokens_; // if true, use token buffer
433 457
434 // Memory 458 // Memory
435 VP8MBInfo* mb_info_; // contextual macroblock infos (mb_w_ + 1) 459 VP8MBInfo* mb_info_; // contextual macroblock infos (mb_w_ + 1)
436 uint8_t* preds_; // predictions modes: (4*mb_w+1) * (4*mb_h+1) 460 uint8_t* preds_; // predictions modes: (4*mb_w+1) * (4*mb_h+1)
437 uint32_t* nz_; // non-zero bit context: mb_w+1 461 uint32_t* nz_; // non-zero bit context: mb_w+1
438 uint8_t* yuv_in_; // input samples
439 uint8_t* yuv_out_; // output samples
440 uint8_t* yuv_out2_; // secondary scratch out-buffer. swapped with yuv_out_.
441 uint8_t* yuv_p_; // scratch buffer for prediction
442 uint8_t *y_top_; // top luma samples. 462 uint8_t *y_top_; // top luma samples.
443 uint8_t *uv_top_; // top u/v samples. 463 uint8_t *uv_top_; // top u/v samples.
444 // U and V are packed into 16 pixels (8 U + 8 V) 464 // U and V are packed into 16 bytes (8 U + 8 V)
445 uint8_t *y_left_; // left luma samples (adressable from index -1 to 15).
446 uint8_t *u_left_; // left u samples (adressable from index -1 to 7)
447 uint8_t *v_left_; // left v samples (adressable from index -1 to 7)
448
449 LFStats *lf_stats_; // autofilter stats (if NULL, autofilter is off) 465 LFStats *lf_stats_; // autofilter stats (if NULL, autofilter is off)
450 }; 466 };
451 467
452 //------------------------------------------------------------------------------ 468 //------------------------------------------------------------------------------
453 // internal functions. Not public. 469 // internal functions. Not public.
454 470
455 // in tree.c 471 // in tree.c
456 extern const uint8_t VP8CoeffsProba0[NUM_TYPES][NUM_BANDS][NUM_CTX][NUM_PROBAS]; 472 extern const uint8_t VP8CoeffsProba0[NUM_TYPES][NUM_BANDS][NUM_CTX][NUM_PROBAS];
457 extern const uint8_t 473 extern const uint8_t
458 VP8CoeffsUpdateProba[NUM_TYPES][NUM_BANDS][NUM_CTX][NUM_PROBAS]; 474 VP8CoeffsUpdateProba[NUM_TYPES][NUM_BANDS][NUM_CTX][NUM_PROBAS];
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 const uint8_t* src2, int stride2, 550 const uint8_t* src2, int stride2,
535 int W, int H, DistoStats* const stats); 551 int W, int H, DistoStats* const stats);
536 double VP8SSIMGet(const DistoStats* const stats); 552 double VP8SSIMGet(const DistoStats* const stats);
537 double VP8SSIMGetSquaredError(const DistoStats* const stats); 553 double VP8SSIMGetSquaredError(const DistoStats* const stats);
538 554
539 // autofilter 555 // autofilter
540 void VP8InitFilter(VP8EncIterator* const it); 556 void VP8InitFilter(VP8EncIterator* const it);
541 void VP8StoreFilterStats(VP8EncIterator* const it); 557 void VP8StoreFilterStats(VP8EncIterator* const it);
542 void VP8AdjustFilterStrength(VP8EncIterator* const it); 558 void VP8AdjustFilterStrength(VP8EncIterator* const it);
543 559
560 // returns the approximate filtering strength needed to smooth a edge
561 // step of 'delta', given a sharpness parameter 'sharpness'.
562 int VP8FilterStrengthFromDelta(int sharpness, int delta);
563
544 //------------------------------------------------------------------------------ 564 //------------------------------------------------------------------------------
545 565
546 #if defined(__cplusplus) || defined(c_plusplus) 566 #ifdef __cplusplus
547 } // extern "C" 567 } // extern "C"
548 #endif 568 #endif
549 569
550 #endif /* WEBP_ENC_VP8ENCI_H_ */ 570 #endif /* WEBP_ENC_VP8ENCI_H_ */
OLDNEW
« no previous file with comments | « third_party/libwebp/enc/tree.c ('k') | third_party/libwebp/enc/vp8l.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698