| OLD | NEW |
| 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 "../dec/common.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 #include "../utils/utils.h" |
| 23 #include "../webp/encode.h" |
| 24 |
| 25 #ifdef WEBP_EXPERIMENTAL_FEATURES |
| 26 #include "./vp8li.h" |
| 27 #endif // WEBP_EXPERIMENTAL_FEATURES |
| 22 | 28 |
| 23 #ifdef __cplusplus | 29 #ifdef __cplusplus |
| 24 extern "C" { | 30 extern "C" { |
| 25 #endif | 31 #endif |
| 26 | 32 |
| 27 //------------------------------------------------------------------------------ | 33 //------------------------------------------------------------------------------ |
| 28 // Various defines and enums | 34 // Various defines and enums |
| 29 | 35 |
| 30 // version numbers | 36 // version numbers |
| 31 #define ENC_MAJ_VERSION 0 | 37 #define ENC_MAJ_VERSION 0 |
| 32 #define ENC_MIN_VERSION 4 | 38 #define ENC_MIN_VERSION 5 |
| 33 #define ENC_REV_VERSION 4 | 39 #define ENC_REV_VERSION 0 |
| 34 | 40 |
| 35 // intra prediction modes | 41 enum { MAX_LF_LEVELS = 64, // Maximum loop filter level |
| 36 enum { B_DC_PRED = 0, // 4x4 modes | |
| 37 B_TM_PRED = 1, | |
| 38 B_VE_PRED = 2, | |
| 39 B_HE_PRED = 3, | |
| 40 B_RD_PRED = 4, | |
| 41 B_VR_PRED = 5, | |
| 42 B_LD_PRED = 6, | |
| 43 B_VL_PRED = 7, | |
| 44 B_HD_PRED = 8, | |
| 45 B_HU_PRED = 9, | |
| 46 NUM_BMODES = B_HU_PRED + 1 - B_DC_PRED, // = 10 | |
| 47 | |
| 48 // Luma16 or UV modes | |
| 49 DC_PRED = B_DC_PRED, V_PRED = B_VE_PRED, | |
| 50 H_PRED = B_HE_PRED, TM_PRED = B_TM_PRED, | |
| 51 NUM_PRED_MODES = 4 | |
| 52 }; | |
| 53 | |
| 54 enum { NUM_MB_SEGMENTS = 4, | |
| 55 MAX_NUM_PARTITIONS = 8, | |
| 56 NUM_TYPES = 4, // 0: i16-AC, 1: i16-DC, 2:chroma-AC, 3:i4-AC | |
| 57 NUM_BANDS = 8, | |
| 58 NUM_CTX = 3, | |
| 59 NUM_PROBAS = 11, | |
| 60 MAX_LF_LEVELS = 64, // Maximum loop filter level | |
| 61 MAX_VARIABLE_LEVEL = 67, // last (inclusive) level with variable cost | 42 MAX_VARIABLE_LEVEL = 67, // last (inclusive) level with variable cost |
| 62 MAX_LEVEL = 2047 // max level (note: max codable is 2047 + 67) | 43 MAX_LEVEL = 2047 // max level (note: max codable is 2047 + 67) |
| 63 }; | 44 }; |
| 64 | 45 |
| 65 typedef enum { // Rate-distortion optimization levels | 46 typedef enum { // Rate-distortion optimization levels |
| 66 RD_OPT_NONE = 0, // no rd-opt | 47 RD_OPT_NONE = 0, // no rd-opt |
| 67 RD_OPT_BASIC = 1, // basic scoring (no trellis) | 48 RD_OPT_BASIC = 1, // basic scoring (no trellis) |
| 68 RD_OPT_TRELLIS = 2, // perform trellis-quant on the final decision only | 49 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) | 50 RD_OPT_TRELLIS_ALL = 3 // trellis-quant for every scoring (much slower) |
| 70 } VP8RDLevel; | 51 } VP8RDLevel; |
| 71 | 52 |
| 72 // YUV-cache parameters. Cache is 16-pixels wide. | 53 // YUV-cache parameters. Cache is 32-bytes wide (= one cacheline). |
| 73 // The original or reconstructed samples can be accessed using VP8Scan[] | 54 // The original or reconstructed samples can be accessed using VP8Scan[]. |
| 74 // The predicted blocks can be accessed using offsets to yuv_p_ and | 55 // The predicted blocks can be accessed using offsets to yuv_p_ and |
| 75 // the arrays VP8*ModeOffsets[]; | 56 // the arrays VP8*ModeOffsets[]. |
| 76 // +----+ YUV Samples area. See VP8Scan[] for accessing the blocks. | 57 // * YUV Samples area (yuv_in_/yuv_out_/yuv_out2_) |
| 77 // Y_OFF |YYYY| <- original samples ('yuv_in_') | 58 // (see VP8Scan[] for accessing the blocks, along with |
| 78 // |YYYY| | 59 // Y_OFF_ENC/U_OFF_ENC/V_OFF_ENC): |
| 79 // |YYYY| | 60 // +----+----+ |
| 80 // |YYYY| | 61 // Y_OFF_ENC |YYYY|UUVV| |
| 81 // U_OFF |UUVV| V_OFF (=U_OFF + 8) | 62 // U_OFF_ENC |YYYY|UUVV| |
| 82 // |UUVV| | 63 // V_OFF_ENC |YYYY|....| <- 25% wasted U/V area |
| 83 // +----+ | 64 // |YYYY|....| |
| 84 // Y_OFF |YYYY| <- compressed/decoded samples ('yuv_out_') | 65 // +----+----+ |
| 85 // |YYYY| There are two buffers like this ('yuv_out_'/'yuv_out2_') | 66 // * Prediction area ('yuv_p_', size = PRED_SIZE_ENC) |
| 86 // |YYYY| | 67 // Intra16 predictions (16x16 block each, two per row): |
| 87 // |YYYY| | 68 // |I16DC16|I16TM16| |
| 88 // U_OFF |UUVV| V_OFF | 69 // |I16VE16|I16HE16| |
| 89 // |UUVV| | 70 // Chroma U/V predictions (16x8 block each, two per row): |
| 90 // x2 (for yuv_out2_) | 71 // |C8DC8|C8TM8| |
| 91 // +----+ Prediction area ('yuv_p_', size = PRED_SIZE) | 72 // |C8VE8|C8HE8| |
| 92 // I16DC16 |YYYY| Intra16 predictions (16x16 block each) | 73 // Intra 4x4 predictions (4x4 block each) |
| 93 // |YYYY| | 74 // |I4DC4 I4TM4 I4VE4 I4HE4|I4RD4 I4VR4 I4LD4 I4VL4| |
| 94 // |YYYY| | 75 // |I4HD4 I4HU4 I4TMP .....|.......................| <- ~31% wasted |
| 95 // |YYYY| | 76 #define YUV_SIZE_ENC (BPS * 16) |
| 96 // I16TM16 |YYYY| | 77 #define PRED_SIZE_ENC (32 * BPS + 16 * BPS + 8 * BPS) // I16+Chroma+I4 preds |
| 97 // |YYYY| | 78 #define Y_OFF_ENC (0) |
| 98 // |YYYY| | 79 #define U_OFF_ENC (16) |
| 99 // |YYYY| | 80 #define V_OFF_ENC (16 + 8) |
| 100 // I16VE16 |YYYY| | |
| 101 // |YYYY| | |
| 102 // |YYYY| | |
| 103 // |YYYY| | |
| 104 // I16HE16 |YYYY| | |
| 105 // |YYYY| | |
| 106 // |YYYY| | |
| 107 // |YYYY| | |
| 108 // +----+ Chroma U/V predictions (16x8 block each) | |
| 109 // C8DC8 |UUVV| | |
| 110 // |UUVV| | |
| 111 // C8TM8 |UUVV| | |
| 112 // |UUVV| | |
| 113 // C8VE8 |UUVV| | |
| 114 // |UUVV| | |
| 115 // C8HE8 |UUVV| | |
| 116 // |UUVV| | |
| 117 // +----+ Intra 4x4 predictions (4x4 block each) | |
| 118 // |YYYY| I4DC4 I4TM4 I4VE4 I4HE4 | |
| 119 // |YYYY| I4RD4 I4VR4 I4LD4 I4VL4 | |
| 120 // |YY..| I4HD4 I4HU4 I4TMP | |
| 121 // +----+ | |
| 122 #define BPS 16 // this is the common stride | |
| 123 #define Y_SIZE (BPS * 16) | |
| 124 #define UV_SIZE (BPS * 8) | |
| 125 #define YUV_SIZE (Y_SIZE + UV_SIZE) | |
| 126 #define PRED_SIZE (6 * 16 * BPS + 12 * BPS) | |
| 127 #define Y_OFF (0) | |
| 128 #define U_OFF (Y_SIZE) | |
| 129 #define V_OFF (U_OFF + 8) | |
| 130 #define ALIGN_CST 15 | |
| 131 #define DO_ALIGN(PTR) ((uintptr_t)((PTR) + ALIGN_CST) & ~ALIGN_CST) | |
| 132 | 81 |
| 133 extern const int VP8Scan[16]; // in quant.c | 82 extern const int VP8Scan[16]; // in quant.c |
| 134 extern const int VP8UVModeOffsets[4]; // in analyze.c | 83 extern const int VP8UVModeOffsets[4]; // in analyze.c |
| 135 extern const int VP8I16ModeOffsets[4]; | 84 extern const int VP8I16ModeOffsets[4]; |
| 136 extern const int VP8I4ModeOffsets[NUM_BMODES]; | 85 extern const int VP8I4ModeOffsets[NUM_BMODES]; |
| 137 | 86 |
| 138 // Layout of prediction blocks | 87 // Layout of prediction blocks |
| 139 // intra 16x16 | 88 // intra 16x16 |
| 140 #define I16DC16 (0 * 16 * BPS) | 89 #define I16DC16 (0 * 16 * BPS) |
| 141 #define I16TM16 (1 * 16 * BPS) | 90 #define I16TM16 (I16DC16 + 16) |
| 142 #define I16VE16 (2 * 16 * BPS) | 91 #define I16VE16 (1 * 16 * BPS) |
| 143 #define I16HE16 (3 * 16 * BPS) | 92 #define I16HE16 (I16VE16 + 16) |
| 144 // chroma 8x8, two U/V blocks side by side (hence: 16x8 each) | 93 // chroma 8x8, two U/V blocks side by side (hence: 16x8 each) |
| 145 #define C8DC8 (4 * 16 * BPS) | 94 #define C8DC8 (2 * 16 * BPS) |
| 146 #define C8TM8 (4 * 16 * BPS + 8 * BPS) | 95 #define C8TM8 (C8DC8 + 1 * 16) |
| 147 #define C8VE8 (5 * 16 * BPS) | 96 #define C8VE8 (2 * 16 * BPS + 8 * BPS) |
| 148 #define C8HE8 (5 * 16 * BPS + 8 * BPS) | 97 #define C8HE8 (C8VE8 + 1 * 16) |
| 149 // intra 4x4 | 98 // intra 4x4 |
| 150 #define I4DC4 (6 * 16 * BPS + 0) | 99 #define I4DC4 (3 * 16 * BPS + 0) |
| 151 #define I4TM4 (6 * 16 * BPS + 4) | 100 #define I4TM4 (I4DC4 + 4) |
| 152 #define I4VE4 (6 * 16 * BPS + 8) | 101 #define I4VE4 (I4DC4 + 8) |
| 153 #define I4HE4 (6 * 16 * BPS + 12) | 102 #define I4HE4 (I4DC4 + 12) |
| 154 #define I4RD4 (6 * 16 * BPS + 4 * BPS + 0) | 103 #define I4RD4 (I4DC4 + 16) |
| 155 #define I4VR4 (6 * 16 * BPS + 4 * BPS + 4) | 104 #define I4VR4 (I4DC4 + 20) |
| 156 #define I4LD4 (6 * 16 * BPS + 4 * BPS + 8) | 105 #define I4LD4 (I4DC4 + 24) |
| 157 #define I4VL4 (6 * 16 * BPS + 4 * BPS + 12) | 106 #define I4VL4 (I4DC4 + 28) |
| 158 #define I4HD4 (6 * 16 * BPS + 8 * BPS + 0) | 107 #define I4HD4 (3 * 16 * BPS + 4 * BPS) |
| 159 #define I4HU4 (6 * 16 * BPS + 8 * BPS + 4) | 108 #define I4HU4 (I4HD4 + 4) |
| 160 #define I4TMP (6 * 16 * BPS + 8 * BPS + 8) | 109 #define I4TMP (I4HD4 + 8) |
| 161 | 110 |
| 162 typedef int64_t score_t; // type used for scores, rate, distortion | 111 typedef int64_t score_t; // type used for scores, rate, distortion |
| 163 // Note that MAX_COST is not the maximum allowed by sizeof(score_t), | 112 // Note that MAX_COST is not the maximum allowed by sizeof(score_t), |
| 164 // in order to allow overflowing computations. | 113 // in order to allow overflowing computations. |
| 165 #define MAX_COST ((score_t)0x7fffffffffffffLL) | 114 #define MAX_COST ((score_t)0x7fffffffffffffLL) |
| 166 | 115 |
| 167 #define QFIX 17 | 116 #define QFIX 17 |
| 168 #define BIAS(b) ((b) << (QFIX - 8)) | 117 #define BIAS(b) ((b) << (QFIX - 8)) |
| 169 // Fun fact: this is the _only_ line where we're actually being lossy and | 118 // Fun fact: this is the _only_ line where we're actually being lossy and |
| 170 // discarding bits. | 119 // discarding bits. |
| 171 static WEBP_INLINE int QUANTDIV(uint32_t n, uint32_t iQ, uint32_t B) { | 120 static WEBP_INLINE int QUANTDIV(uint32_t n, uint32_t iQ, uint32_t B) { |
| 172 return (int)((n * iQ + B) >> QFIX); | 121 return (int)((n * iQ + B) >> QFIX); |
| 173 } | 122 } |
| 174 | 123 |
| 175 // size of histogram used by CollectHistogram. | |
| 176 #define MAX_COEFF_THRESH 31 | |
| 177 typedef struct VP8Histogram VP8Histogram; | |
| 178 struct VP8Histogram { | |
| 179 // TODO(skal): we only need to store the max_value and last_non_zero actually. | |
| 180 int distribution[MAX_COEFF_THRESH + 1]; | |
| 181 }; | |
| 182 | |
| 183 // Uncomment the following to remove token-buffer code: | 124 // Uncomment the following to remove token-buffer code: |
| 184 // #define DISABLE_TOKEN_BUFFER | 125 // #define DISABLE_TOKEN_BUFFER |
| 185 | 126 |
| 186 //------------------------------------------------------------------------------ | 127 //------------------------------------------------------------------------------ |
| 187 // Headers | 128 // Headers |
| 188 | 129 |
| 189 typedef uint32_t proba_t; // 16b + 16b | 130 typedef uint32_t proba_t; // 16b + 16b |
| 190 typedef uint8_t ProbaArray[NUM_CTX][NUM_PROBAS]; | 131 typedef uint8_t ProbaArray[NUM_CTX][NUM_PROBAS]; |
| 191 typedef proba_t StatsArray[NUM_CTX][NUM_PROBAS]; | 132 typedef proba_t StatsArray[NUM_CTX][NUM_PROBAS]; |
| 192 typedef uint16_t CostArray[NUM_CTX][MAX_VARIABLE_LEVEL + 1]; | 133 typedef uint16_t CostArray[NUM_CTX][MAX_VARIABLE_LEVEL + 1]; |
| 134 typedef const uint16_t* (*CostArrayPtr)[NUM_CTX]; // for easy casting |
| 135 typedef const uint16_t* CostArrayMap[16][NUM_CTX]; |
| 193 typedef double LFStats[NUM_MB_SEGMENTS][MAX_LF_LEVELS]; // filter stats | 136 typedef double LFStats[NUM_MB_SEGMENTS][MAX_LF_LEVELS]; // filter stats |
| 194 | 137 |
| 195 typedef struct VP8Encoder VP8Encoder; | 138 typedef struct VP8Encoder VP8Encoder; |
| 196 | 139 |
| 197 // segment features | 140 // segment features |
| 198 typedef struct { | 141 typedef struct { |
| 199 int num_segments_; // Actual number of segments. 1 segment only = unused. | 142 int num_segments_; // Actual number of segments. 1 segment only = unused. |
| 200 int update_map_; // whether to update the segment map or not. | 143 int update_map_; // whether to update the segment map or not. |
| 201 // must be 0 if there's only 1 segment. | 144 // must be 0 if there's only 1 segment. |
| 202 int size_; // bit-cost for transmitting the segment map | 145 int size_; // bit-cost for transmitting the segment map |
| 203 } VP8SegmentHeader; | 146 } VP8EncSegmentHeader; |
| 204 | 147 |
| 205 // Struct collecting all frame-persistent probabilities. | 148 // Struct collecting all frame-persistent probabilities. |
| 206 typedef struct { | 149 typedef struct { |
| 207 uint8_t segments_[3]; // probabilities for segment tree | 150 uint8_t segments_[3]; // probabilities for segment tree |
| 208 uint8_t skip_proba_; // final probability of being skipped. | 151 uint8_t skip_proba_; // final probability of being skipped. |
| 209 ProbaArray coeffs_[NUM_TYPES][NUM_BANDS]; // 1056 bytes | 152 ProbaArray coeffs_[NUM_TYPES][NUM_BANDS]; // 1056 bytes |
| 210 StatsArray stats_[NUM_TYPES][NUM_BANDS]; // 4224 bytes | 153 StatsArray stats_[NUM_TYPES][NUM_BANDS]; // 4224 bytes |
| 211 CostArray level_cost_[NUM_TYPES][NUM_BANDS]; // 13056 bytes | 154 CostArray level_cost_[NUM_TYPES][NUM_BANDS]; // 13056 bytes |
| 155 CostArrayMap remapped_costs_[NUM_TYPES]; // 1536 bytes |
| 212 int dirty_; // if true, need to call VP8CalculateLevelCosts() | 156 int dirty_; // if true, need to call VP8CalculateLevelCosts() |
| 213 int use_skip_proba_; // Note: we always use skip_proba for now. | 157 int use_skip_proba_; // Note: we always use skip_proba for now. |
| 214 int nb_skip_; // number of skipped blocks | 158 int nb_skip_; // number of skipped blocks |
| 215 } VP8Proba; | 159 } VP8EncProba; |
| 216 | 160 |
| 217 // Filter parameters. Not actually used in the code (we don't perform | 161 // Filter parameters. Not actually used in the code (we don't perform |
| 218 // the in-loop filtering), but filled from user's config | 162 // the in-loop filtering), but filled from user's config |
| 219 typedef struct { | 163 typedef struct { |
| 220 int simple_; // filtering type: 0=complex, 1=simple | 164 int simple_; // filtering type: 0=complex, 1=simple |
| 221 int level_; // base filter level [0..63] | 165 int level_; // base filter level [0..63] |
| 222 int sharpness_; // [0..7] | 166 int sharpness_; // [0..7] |
| 223 int i4x4_lf_delta_; // delta filter level for i4x4 relative to i16x16 | 167 int i4x4_lf_delta_; // delta filter level for i4x4 relative to i16x16 |
| 224 } VP8FilterHeader; | 168 } VP8EncFilterHeader; |
| 225 | 169 |
| 226 //------------------------------------------------------------------------------ | 170 //------------------------------------------------------------------------------ |
| 227 // Informations about the macroblocks. | 171 // Informations about the macroblocks. |
| 228 | 172 |
| 229 typedef struct { | 173 typedef struct { |
| 230 // block type | 174 // block type |
| 231 unsigned int type_:2; // 0=i4x4, 1=i16x16 | 175 unsigned int type_:2; // 0=i4x4, 1=i16x16 |
| 232 unsigned int uv_mode_:2; | 176 unsigned int uv_mode_:2; |
| 233 unsigned int skip_:1; | 177 unsigned int skip_:1; |
| 234 unsigned int segment_:2; | 178 unsigned int segment_:2; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 int count_down0_; // starting counter value (for progress) | 244 int count_down0_; // starting counter value (for progress) |
| 301 int percent0_; // saved initial progress percent | 245 int percent0_; // saved initial progress percent |
| 302 | 246 |
| 303 uint8_t* y_left_; // left luma samples (addressable from index -1 to 15). | 247 uint8_t* y_left_; // left luma samples (addressable from index -1 to 15). |
| 304 uint8_t* u_left_; // left u samples (addressable from index -1 to 7) | 248 uint8_t* u_left_; // left u samples (addressable from index -1 to 7) |
| 305 uint8_t* v_left_; // left v samples (addressable from index -1 to 7) | 249 uint8_t* v_left_; // left v samples (addressable from index -1 to 7) |
| 306 | 250 |
| 307 uint8_t* y_top_; // top luma samples at position 'x_' | 251 uint8_t* y_top_; // top luma samples at position 'x_' |
| 308 uint8_t* uv_top_; // top u/v samples at position 'x_', packed as 16 bytes | 252 uint8_t* uv_top_; // top u/v samples at position 'x_', packed as 16 bytes |
| 309 | 253 |
| 310 // memory for storing y/u/v_left_ and yuv_in_/out_* | 254 // memory for storing y/u/v_left_ |
| 311 uint8_t yuv_left_mem_[17 + 16 + 16 + 8 + ALIGN_CST]; // memory for *_left_ | 255 uint8_t yuv_left_mem_[17 + 16 + 16 + 8 + WEBP_ALIGN_CST]; |
| 312 uint8_t yuv_mem_[3 * YUV_SIZE + PRED_SIZE + ALIGN_CST]; // memory for yuv_* | 256 // memory for yuv_* |
| 257 uint8_t yuv_mem_[3 * YUV_SIZE_ENC + PRED_SIZE_ENC + WEBP_ALIGN_CST]; |
| 313 } VP8EncIterator; | 258 } VP8EncIterator; |
| 314 | 259 |
| 315 // in iterator.c | 260 // in iterator.c |
| 316 // must be called first | 261 // must be called first |
| 317 void VP8IteratorInit(VP8Encoder* const enc, VP8EncIterator* const it); | 262 void VP8IteratorInit(VP8Encoder* const enc, VP8EncIterator* const it); |
| 318 // restart a scan | 263 // restart a scan |
| 319 void VP8IteratorReset(VP8EncIterator* const it); | 264 void VP8IteratorReset(VP8EncIterator* const it); |
| 320 // reset iterator position to row 'y' | 265 // reset iterator position to row 'y' |
| 321 void VP8IteratorSetRow(VP8EncIterator* const it, int y); | 266 void VP8IteratorSetRow(VP8EncIterator* const it, int y); |
| 322 // set count down (=number of iterations to go) | 267 // set count down (=number of iterations to go) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 void VP8TBufferClear(VP8TBuffer* const b); // de-allocate pages memory | 319 void VP8TBufferClear(VP8TBuffer* const b); // de-allocate pages memory |
| 375 | 320 |
| 376 #if !defined(DISABLE_TOKEN_BUFFER) | 321 #if !defined(DISABLE_TOKEN_BUFFER) |
| 377 | 322 |
| 378 // Finalizes bitstream when probabilities are known. | 323 // Finalizes bitstream when probabilities are known. |
| 379 // Deletes the allocated token memory if final_pass is true. | 324 // Deletes the allocated token memory if final_pass is true. |
| 380 int VP8EmitTokens(VP8TBuffer* const b, VP8BitWriter* const bw, | 325 int VP8EmitTokens(VP8TBuffer* const b, VP8BitWriter* const bw, |
| 381 const uint8_t* const probas, int final_pass); | 326 const uint8_t* const probas, int final_pass); |
| 382 | 327 |
| 383 // record the coding of coefficients without knowing the probabilities yet | 328 // record the coding of coefficients without knowing the probabilities yet |
| 384 int VP8RecordCoeffTokens(int ctx, int coeff_type, int first, int last, | 329 int VP8RecordCoeffTokens(const int ctx, const int coeff_type, |
| 330 int first, int last, |
| 385 const int16_t* const coeffs, | 331 const int16_t* const coeffs, |
| 386 VP8TBuffer* const tokens); | 332 VP8TBuffer* const tokens); |
| 387 | 333 |
| 388 // Estimate the final coded size given a set of 'probas'. | 334 // Estimate the final coded size given a set of 'probas'. |
| 389 size_t VP8EstimateTokenSize(VP8TBuffer* const b, const uint8_t* const probas); | 335 size_t VP8EstimateTokenSize(VP8TBuffer* const b, const uint8_t* const probas); |
| 390 | 336 |
| 391 // unused for now | 337 // unused for now |
| 392 void VP8TokenToStats(const VP8TBuffer* const b, proba_t* const stats); | 338 void VP8TokenToStats(const VP8TBuffer* const b, proba_t* const stats); |
| 393 | 339 |
| 394 #endif // !DISABLE_TOKEN_BUFFER | 340 #endif // !DISABLE_TOKEN_BUFFER |
| 395 | 341 |
| 396 //------------------------------------------------------------------------------ | 342 //------------------------------------------------------------------------------ |
| 397 // VP8Encoder | 343 // VP8Encoder |
| 398 | 344 |
| 399 struct VP8Encoder { | 345 struct VP8Encoder { |
| 400 const WebPConfig* config_; // user configuration and parameters | 346 const WebPConfig* config_; // user configuration and parameters |
| 401 WebPPicture* pic_; // input / output picture | 347 WebPPicture* pic_; // input / output picture |
| 402 | 348 |
| 403 // headers | 349 // headers |
| 404 VP8FilterHeader filter_hdr_; // filtering information | 350 VP8EncFilterHeader filter_hdr_; // filtering information |
| 405 VP8SegmentHeader segment_hdr_; // segment information | 351 VP8EncSegmentHeader segment_hdr_; // segment information |
| 406 | 352 |
| 407 int profile_; // VP8's profile, deduced from Config. | 353 int profile_; // VP8's profile, deduced from Config. |
| 408 | 354 |
| 409 // dimension, in macroblock units. | 355 // dimension, in macroblock units. |
| 410 int mb_w_, mb_h_; | 356 int mb_w_, mb_h_; |
| 411 int preds_w_; // stride of the *preds_ prediction plane (=4*mb_w + 1) | 357 int preds_w_; // stride of the *preds_ prediction plane (=4*mb_w + 1) |
| 412 | 358 |
| 413 // number of partitions (1, 2, 4 or 8 = MAX_NUM_PARTITIONS) | 359 // number of partitions (1, 2, 4 or 8 = MAX_NUM_PARTITIONS) |
| 414 int num_parts_; | 360 int num_parts_; |
| 415 | 361 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 431 int base_quant_; // nominal quantizer value. Only used | 377 int base_quant_; // nominal quantizer value. Only used |
| 432 // for relative coding of segments' quant. | 378 // for relative coding of segments' quant. |
| 433 int alpha_; // global susceptibility (<=> complexity) | 379 int alpha_; // global susceptibility (<=> complexity) |
| 434 int uv_alpha_; // U/V quantization susceptibility | 380 int uv_alpha_; // U/V quantization susceptibility |
| 435 // global offset of quantizers, shared by all segments | 381 // global offset of quantizers, shared by all segments |
| 436 int dq_y1_dc_; | 382 int dq_y1_dc_; |
| 437 int dq_y2_dc_, dq_y2_ac_; | 383 int dq_y2_dc_, dq_y2_ac_; |
| 438 int dq_uv_dc_, dq_uv_ac_; | 384 int dq_uv_dc_, dq_uv_ac_; |
| 439 | 385 |
| 440 // probabilities and statistics | 386 // probabilities and statistics |
| 441 VP8Proba proba_; | 387 VP8EncProba proba_; |
| 442 uint64_t sse_[4]; // sum of Y/U/V/A squared errors for all macroblocks | 388 uint64_t sse_[4]; // sum of Y/U/V/A squared errors for all macroblocks |
| 443 uint64_t sse_count_; // pixel count for the sse_[] stats | 389 uint64_t sse_count_; // pixel count for the sse_[] stats |
| 444 int coded_size_; | 390 int coded_size_; |
| 445 int residual_bytes_[3][4]; | 391 int residual_bytes_[3][4]; |
| 446 int block_count_[3]; | 392 int block_count_[3]; |
| 447 | 393 |
| 448 // quality/speed settings | 394 // quality/speed settings |
| 449 int method_; // 0=fastest, 6=best/slowest. | 395 int method_; // 0=fastest, 6=best/slowest. |
| 450 VP8RDLevel rd_opt_level_; // Deduced from method_. | 396 VP8RDLevel rd_opt_level_; // Deduced from method_. |
| 451 int max_i4_header_bits_; // partition #0 safeness factor | 397 int max_i4_header_bits_; // partition #0 safeness factor |
| 452 int thread_level_; // derived from config->thread_level | 398 int thread_level_; // derived from config->thread_level |
| 453 int do_search_; // derived from config->target_XXX | 399 int do_search_; // derived from config->target_XXX |
| 454 int use_tokens_; // if true, use token buffer | 400 int use_tokens_; // if true, use token buffer |
| 455 | 401 |
| 456 // Memory | 402 // Memory |
| 457 VP8MBInfo* mb_info_; // contextual macroblock infos (mb_w_ + 1) | 403 VP8MBInfo* mb_info_; // contextual macroblock infos (mb_w_ + 1) |
| 458 uint8_t* preds_; // predictions modes: (4*mb_w+1) * (4*mb_h+1) | 404 uint8_t* preds_; // predictions modes: (4*mb_w+1) * (4*mb_h+1) |
| 459 uint32_t* nz_; // non-zero bit context: mb_w+1 | 405 uint32_t* nz_; // non-zero bit context: mb_w+1 |
| 460 uint8_t* y_top_; // top luma samples. | 406 uint8_t* y_top_; // top luma samples. |
| 461 uint8_t* uv_top_; // top u/v samples. | 407 uint8_t* uv_top_; // top u/v samples. |
| 462 // U and V are packed into 16 bytes (8 U + 8 V) | 408 // U and V are packed into 16 bytes (8 U + 8 V) |
| 463 LFStats* lf_stats_; // autofilter stats (if NULL, autofilter is off) | 409 LFStats* lf_stats_; // autofilter stats (if NULL, autofilter is off) |
| 464 }; | 410 }; |
| 465 | 411 |
| 466 //------------------------------------------------------------------------------ | 412 //------------------------------------------------------------------------------ |
| 467 // internal functions. Not public. | 413 // internal functions. Not public. |
| 468 | 414 |
| 469 // in tree.c | 415 // in tree.c |
| 470 extern const uint8_t VP8CoeffsProba0[NUM_TYPES][NUM_BANDS][NUM_CTX][NUM_PROBAS]; | 416 extern const uint8_t VP8CoeffsProba0[NUM_TYPES][NUM_BANDS][NUM_CTX][NUM_PROBAS]; |
| 471 extern const uint8_t | 417 extern const uint8_t |
| 472 VP8CoeffsUpdateProba[NUM_TYPES][NUM_BANDS][NUM_CTX][NUM_PROBAS]; | 418 VP8CoeffsUpdateProba[NUM_TYPES][NUM_BANDS][NUM_CTX][NUM_PROBAS]; |
| 473 // Reset the token probabilities to their initial (default) values | 419 // Reset the token probabilities to their initial (default) values |
| 474 void VP8DefaultProbas(VP8Encoder* const enc); | 420 void VP8DefaultProbas(VP8Encoder* const enc); |
| 475 // Write the token probabilities | 421 // Write the token probabilities |
| 476 void VP8WriteProbas(VP8BitWriter* const bw, const VP8Proba* const probas); | 422 void VP8WriteProbas(VP8BitWriter* const bw, const VP8EncProba* const probas); |
| 477 // Writes the partition #0 modes (that is: all intra modes) | 423 // Writes the partition #0 modes (that is: all intra modes) |
| 478 void VP8CodeIntraModes(VP8Encoder* const enc); | 424 void VP8CodeIntraModes(VP8Encoder* const enc); |
| 479 | 425 |
| 480 // in syntax.c | 426 // in syntax.c |
| 481 // Generates the final bitstream by coding the partition0 and headers, | 427 // Generates the final bitstream by coding the partition0 and headers, |
| 482 // and appending an assembly of all the pre-coded token partitions. | 428 // and appending an assembly of all the pre-coded token partitions. |
| 483 // Return true if everything is ok. | 429 // Return true if everything is ok. |
| 484 int VP8EncWrite(VP8Encoder* const enc); | 430 int VP8EncWrite(VP8Encoder* const enc); |
| 485 // Release memory allocated for bit-writing in VP8EncLoop & seq. | 431 // Release memory allocated for bit-writing in VP8EncLoop & seq. |
| 486 void VP8EncFreeBitWriters(VP8Encoder* const enc); | 432 void VP8EncFreeBitWriters(VP8Encoder* const enc); |
| 487 | 433 |
| 488 // in frame.c | 434 // in frame.c |
| 489 extern const uint8_t VP8EncBands[16 + 1]; | |
| 490 extern const uint8_t VP8Cat3[]; | 435 extern const uint8_t VP8Cat3[]; |
| 491 extern const uint8_t VP8Cat4[]; | 436 extern const uint8_t VP8Cat4[]; |
| 492 extern const uint8_t VP8Cat5[]; | 437 extern const uint8_t VP8Cat5[]; |
| 493 extern const uint8_t VP8Cat6[]; | 438 extern const uint8_t VP8Cat6[]; |
| 494 | 439 |
| 495 // Form all the four Intra16x16 predictions in the yuv_p_ cache | 440 // Form all the four Intra16x16 predictions in the yuv_p_ cache |
| 496 void VP8MakeLuma16Preds(const VP8EncIterator* const it); | 441 void VP8MakeLuma16Preds(const VP8EncIterator* const it); |
| 497 // Form all the four Chroma8x8 predictions in the yuv_p_ cache | 442 // Form all the four Chroma8x8 predictions in the yuv_p_ cache |
| 498 void VP8MakeChroma8Preds(const VP8EncIterator* const it); | 443 void VP8MakeChroma8Preds(const VP8EncIterator* const it); |
| 499 // Form all the ten Intra4x4 predictions in the yuv_p_ cache | 444 // Form all the ten Intra4x4 predictions in the yuv_p_ cache |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 // Preserves the YUV(A) buffer. Returns false in case of error (invalid param, | 507 // Preserves the YUV(A) buffer. Returns false in case of error (invalid param, |
| 563 // out-of-memory). | 508 // out-of-memory). |
| 564 int WebPPictureAllocARGB(WebPPicture* const picture, int width, int height); | 509 int WebPPictureAllocARGB(WebPPicture* const picture, int width, int height); |
| 565 | 510 |
| 566 // Allocates YUVA buffer of given dimension (previous one is always free'd). | 511 // Allocates YUVA buffer of given dimension (previous one is always free'd). |
| 567 // Uses picture->csp to determine whether an alpha buffer is needed. | 512 // Uses picture->csp to determine whether an alpha buffer is needed. |
| 568 // Preserves the ARGB buffer. | 513 // Preserves the ARGB buffer. |
| 569 // Returns false in case of error (invalid param, out-of-memory). | 514 // Returns false in case of error (invalid param, out-of-memory). |
| 570 int WebPPictureAllocYUVA(WebPPicture* const picture, int width, int height); | 515 int WebPPictureAllocYUVA(WebPPicture* const picture, int width, int height); |
| 571 | 516 |
| 517 // Clean-up the RGB samples under fully transparent area, to help lossless |
| 518 // compressibility (no guarantee, though). Assumes that pic->use_argb is true. |
| 519 void WebPCleanupTransparentAreaLossless(WebPPicture* const pic); |
| 520 |
| 521 // in near_lossless.c |
| 522 // Near lossless preprocessing in RGB color-space. |
| 523 int VP8ApplyNearLossless(int xsize, int ysize, uint32_t* argb, int quality); |
| 524 // Near lossless adjustment for predictors. |
| 525 void VP8ApplyNearLosslessPredict(int xsize, int ysize, int pred_bits, |
| 526 const uint32_t* argb_orig, |
| 527 uint32_t* argb, uint32_t* argb_scratch, |
| 528 const uint32_t* const transform_data, |
| 529 int quality, int subtract_green); |
| 572 //------------------------------------------------------------------------------ | 530 //------------------------------------------------------------------------------ |
| 573 | 531 |
| 574 #if WEBP_ENCODER_ABI_VERSION <= 0x0203 | |
| 575 void WebPMemoryWriterClear(WebPMemoryWriter* writer); | |
| 576 #endif | |
| 577 | |
| 578 #ifdef __cplusplus | 532 #ifdef __cplusplus |
| 579 } // extern "C" | 533 } // extern "C" |
| 580 #endif | 534 #endif |
| 581 | 535 |
| 582 #endif /* WEBP_ENC_VP8ENCI_H_ */ | 536 #endif /* WEBP_ENC_VP8ENCI_H_ */ |
| OLD | NEW |