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

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

Issue 1546003002: libwebp: update to 0.5.0 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 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
« no previous file with comments | « third_party/libwebp/enc/frame.c ('k') | third_party/libwebp/enc/histogram.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 2012 Google Inc. All Rights Reserved. 1 // Copyright 2012 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 // Author: Jyrki Alakuijala (jyrki@google.com) 10 // Author: Jyrki Alakuijala (jyrki@google.com)
11 // 11 //
12 // Models the histograms of literal and distance codes. 12 // Models the histograms of literal and distance codes.
13 13
14 #ifndef WEBP_ENC_HISTOGRAM_H_ 14 #ifndef WEBP_ENC_HISTOGRAM_H_
15 #define WEBP_ENC_HISTOGRAM_H_ 15 #define WEBP_ENC_HISTOGRAM_H_
16 16
17 #include <assert.h>
18 #include <stddef.h>
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include <string.h> 17 #include <string.h>
22 18
23 #include "./backward_references.h" 19 #include "./backward_references.h"
24 #include "../webp/format_constants.h" 20 #include "../webp/format_constants.h"
25 #include "../webp/types.h" 21 #include "../webp/types.h"
26 22
27 #ifdef __cplusplus 23 #ifdef __cplusplus
28 extern "C" { 24 extern "C" {
29 #endif 25 #endif
30 26
27 // Not a trivial literal symbol.
28 #define VP8L_NON_TRIVIAL_SYM (0xffffffff)
29
31 // A simple container for histograms of data. 30 // A simple container for histograms of data.
32 typedef struct { 31 typedef struct {
33 // literal_ contains green literal, palette-code and 32 // literal_ contains green literal, palette-code and
34 // copy-length-prefix histogram 33 // copy-length-prefix histogram
35 uint32_t* literal_; // Pointer to the allocated buffer for literal. 34 uint32_t* literal_; // Pointer to the allocated buffer for literal.
36 uint32_t red_[NUM_LITERAL_CODES]; 35 uint32_t red_[NUM_LITERAL_CODES];
37 uint32_t blue_[NUM_LITERAL_CODES]; 36 uint32_t blue_[NUM_LITERAL_CODES];
38 uint32_t alpha_[NUM_LITERAL_CODES]; 37 uint32_t alpha_[NUM_LITERAL_CODES];
39 // Backward reference prefix-code histogram. 38 // Backward reference prefix-code histogram.
40 uint32_t distance_[NUM_DISTANCE_CODES]; 39 uint32_t distance_[NUM_DISTANCE_CODES];
41 int palette_code_bits_; 40 int palette_code_bits_;
42 double bit_cost_; // cached value of VP8LHistogramEstimateBits(this) 41 uint32_t trivial_symbol_; // True, if histograms for Red, Blue & Alpha
43 double literal_cost_; // Cached values of dominant entropy costs: 42 // literal symbols are single valued.
44 double red_cost_; // literal, red & blue. 43 double bit_cost_; // cached value of bit cost.
44 double literal_cost_; // Cached values of dominant entropy costs:
45 double red_cost_; // literal, red & blue.
45 double blue_cost_; 46 double blue_cost_;
46 } VP8LHistogram; 47 } VP8LHistogram;
47 48
48 // Collection of histograms with fixed capacity, allocated as one 49 // Collection of histograms with fixed capacity, allocated as one
49 // big memory chunk. Can be destroyed by calling WebPSafeFree(). 50 // big memory chunk. Can be destroyed by calling WebPSafeFree().
50 typedef struct { 51 typedef struct {
51 int size; // number of slots currently in use 52 int size; // number of slots currently in use
52 int max_size; // maximum capacity 53 int max_size; // maximum capacity
53 VP8LHistogram** histograms; 54 VP8LHistogram** histograms;
54 } VP8LHistogramSet; 55 } VP8LHistogramSet;
(...skipping 29 matching lines...) Expand all
84 85
85 // Allocate and initialize histogram object with specified 'cache_bits'. 86 // Allocate and initialize histogram object with specified 'cache_bits'.
86 // Returns NULL in case of memory error. 87 // Returns NULL in case of memory error.
87 // Special case of VP8LAllocateHistogramSet, with size equals 1. 88 // Special case of VP8LAllocateHistogramSet, with size equals 1.
88 VP8LHistogram* VP8LAllocateHistogram(int cache_bits); 89 VP8LHistogram* VP8LAllocateHistogram(int cache_bits);
89 90
90 // Accumulate a token 'v' into a histogram. 91 // Accumulate a token 'v' into a histogram.
91 void VP8LHistogramAddSinglePixOrCopy(VP8LHistogram* const histo, 92 void VP8LHistogramAddSinglePixOrCopy(VP8LHistogram* const histo,
92 const PixOrCopy* const v); 93 const PixOrCopy* const v);
93 94
94 // Estimate how many bits the combined entropy of literals and distance
95 // approximately maps to.
96 double VP8LHistogramEstimateBits(const VP8LHistogram* const p);
97
98 // This function estimates the cost in bits excluding the bits needed to
99 // represent the entropy code itself.
100 double VP8LHistogramEstimateBitsBulk(const VP8LHistogram* const p);
101
102 static WEBP_INLINE int VP8LHistogramNumCodes(int palette_code_bits) { 95 static WEBP_INLINE int VP8LHistogramNumCodes(int palette_code_bits) {
103 return NUM_LITERAL_CODES + NUM_LENGTH_CODES + 96 return NUM_LITERAL_CODES + NUM_LENGTH_CODES +
104 ((palette_code_bits > 0) ? (1 << palette_code_bits) : 0); 97 ((palette_code_bits > 0) ? (1 << palette_code_bits) : 0);
105 } 98 }
106 99
107 // Builds the histogram image. 100 // Builds the histogram image.
108 int VP8LGetHistoImageSymbols(int xsize, int ysize, 101 int VP8LGetHistoImageSymbols(int xsize, int ysize,
109 const VP8LBackwardRefs* const refs, 102 const VP8LBackwardRefs* const refs,
110 int quality, int histogram_bits, int cache_bits, 103 int quality, int low_effort,
104 int histogram_bits, int cache_bits,
111 VP8LHistogramSet* const image_in, 105 VP8LHistogramSet* const image_in,
106 VP8LHistogramSet* const tmp_histos,
112 uint16_t* const histogram_symbols); 107 uint16_t* const histogram_symbols);
113 108
109 // Returns the entropy for the symbols in the input array.
110 // Also sets trivial_symbol to the code value, if the array has only one code
111 // value. Otherwise, set it to VP8L_NON_TRIVIAL_SYM.
112 double VP8LBitsEntropy(const uint32_t* const array, int n,
113 uint32_t* const trivial_symbol);
114
115 // Estimate how many bits the combined entropy of literals and distance
116 // approximately maps to.
117 double VP8LHistogramEstimateBits(const VP8LHistogram* const p);
118
114 #ifdef __cplusplus 119 #ifdef __cplusplus
115 } 120 }
116 #endif 121 #endif
117 122
118 #endif // WEBP_ENC_HISTOGRAM_H_ 123 #endif // WEBP_ENC_HISTOGRAM_H_
OLDNEW
« no previous file with comments | « third_party/libwebp/enc/frame.c ('k') | third_party/libwebp/enc/histogram.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698