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

Side by Side Diff: source/libvpx/vp9/encoder/vp9_encodemb.c

Issue 181493009: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 9 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 | « source/libvpx/vp9/encoder/vp9_encodemb.h ('k') | source/libvpx/vp9/encoder/vp9_encodemv.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 18 matching lines...) Expand all
29 ENTROPY_CONTEXT tl[MAX_MB_PLANE][16]; 29 ENTROPY_CONTEXT tl[MAX_MB_PLANE][16];
30 }; 30 };
31 31
32 struct encode_b_args { 32 struct encode_b_args {
33 MACROBLOCK *x; 33 MACROBLOCK *x;
34 struct optimize_ctx *ctx; 34 struct optimize_ctx *ctx;
35 unsigned char *skip; 35 unsigned char *skip;
36 }; 36 };
37 37
38 void vp9_subtract_block_c(int rows, int cols, 38 void vp9_subtract_block_c(int rows, int cols,
39 int16_t *diff_ptr, ptrdiff_t diff_stride, 39 int16_t *diff, ptrdiff_t diff_stride,
40 const uint8_t *src_ptr, ptrdiff_t src_stride, 40 const uint8_t *src, ptrdiff_t src_stride,
41 const uint8_t *pred_ptr, ptrdiff_t pred_stride) { 41 const uint8_t *pred, ptrdiff_t pred_stride) {
42 int r, c; 42 int r, c;
43 43
44 for (r = 0; r < rows; r++) { 44 for (r = 0; r < rows; r++) {
45 for (c = 0; c < cols; c++) 45 for (c = 0; c < cols; c++)
46 diff_ptr[c] = src_ptr[c] - pred_ptr[c]; 46 diff[c] = src[c] - pred[c];
47 47
48 diff_ptr += diff_stride; 48 diff += diff_stride;
49 pred_ptr += pred_stride; 49 pred += pred_stride;
50 src_ptr += src_stride; 50 src += src_stride;
51 } 51 }
52 } 52 }
53 53
54 static void subtract_plane(MACROBLOCK *x, BLOCK_SIZE bsize, int plane) { 54 void vp9_subtract_plane(MACROBLOCK *x, BLOCK_SIZE bsize, int plane) {
55 struct macroblock_plane *const p = &x->plane[plane]; 55 struct macroblock_plane *const p = &x->plane[plane];
56 const struct macroblockd_plane *const pd = &x->e_mbd.plane[plane]; 56 const struct macroblockd_plane *const pd = &x->e_mbd.plane[plane];
57 const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd); 57 const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd);
58 const int bw = 4 * num_4x4_blocks_wide_lookup[plane_bsize]; 58 const int bw = 4 * num_4x4_blocks_wide_lookup[plane_bsize];
59 const int bh = 4 * num_4x4_blocks_high_lookup[plane_bsize]; 59 const int bh = 4 * num_4x4_blocks_high_lookup[plane_bsize];
60 60
61 vp9_subtract_block(bh, bw, p->src_diff, bw, p->src.buf, p->src.stride, 61 vp9_subtract_block(bh, bw, p->src_diff, bw, p->src.buf, p->src.stride,
62 pd->dst.buf, pd->dst.stride); 62 pd->dst.buf, pd->dst.stride);
63 } 63 }
64 64
65 void vp9_subtract_sby(MACROBLOCK *x, BLOCK_SIZE bsize) {
66 subtract_plane(x, bsize, 0);
67 }
68
69 void vp9_subtract_sbuv(MACROBLOCK *x, BLOCK_SIZE bsize) {
70 int i;
71
72 for (i = 1; i < MAX_MB_PLANE; i++)
73 subtract_plane(x, bsize, i);
74 }
75
76 void vp9_subtract_sb(MACROBLOCK *x, BLOCK_SIZE bsize) {
77 vp9_subtract_sby(x, bsize);
78 vp9_subtract_sbuv(x, bsize);
79 }
80
81 #define RDTRUNC(RM, DM, R, D) ((128 + (R) * (RM)) & 0xFF) 65 #define RDTRUNC(RM, DM, R, D) ((128 + (R) * (RM)) & 0xFF)
82 typedef struct vp9_token_state vp9_token_state; 66 typedef struct vp9_token_state vp9_token_state;
83 67
84 struct vp9_token_state { 68 struct vp9_token_state {
85 int rate; 69 int rate;
86 int error; 70 int error;
87 int next; 71 int next;
88 signed char token; 72 signed char token;
89 short qc; 73 short qc;
90 }; 74 };
(...skipping 23 matching lines...) Expand all
114 const int16_t *nb, 98 const int16_t *nb,
115 int idx, int token, 99 int idx, int token,
116 uint8_t *token_cache) { 100 uint8_t *token_cache) {
117 int bak = token_cache[scan[idx]], pt; 101 int bak = token_cache[scan[idx]], pt;
118 token_cache[scan[idx]] = vp9_pt_energy_class[token]; 102 token_cache[scan[idx]] = vp9_pt_energy_class[token];
119 pt = get_coef_context(nb, token_cache, idx + 1); 103 pt = get_coef_context(nb, token_cache, idx + 1);
120 token_cache[scan[idx]] = bak; 104 token_cache[scan[idx]] = bak;
121 return pt; 105 return pt;
122 } 106 }
123 107
124 static void optimize_b(MACROBLOCK *mb, 108 static void optimize_b(int plane, int block, BLOCK_SIZE plane_bsize,
125 int plane, int block, BLOCK_SIZE plane_bsize, 109 TX_SIZE tx_size, MACROBLOCK *mb,
126 ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l, 110 struct optimize_ctx *ctx) {
127 TX_SIZE tx_size) {
128 MACROBLOCKD *const xd = &mb->e_mbd; 111 MACROBLOCKD *const xd = &mb->e_mbd;
129 struct macroblock_plane *p = &mb->plane[plane]; 112 struct macroblock_plane *p = &mb->plane[plane];
130 struct macroblockd_plane *pd = &xd->plane[plane]; 113 struct macroblockd_plane *pd = &xd->plane[plane];
131 const int ref = is_inter_block(&xd->mi_8x8[0]->mbmi); 114 const int ref = is_inter_block(&xd->mi_8x8[0]->mbmi);
132 vp9_token_state tokens[1025][2]; 115 vp9_token_state tokens[1025][2];
133 unsigned best_index[1025][2]; 116 unsigned best_index[1025][2];
134 const int16_t *coeff_ptr = BLOCK_OFFSET(mb->plane[plane].coeff, block); 117 const int16_t *coeff = BLOCK_OFFSET(mb->plane[plane].coeff, block);
135 int16_t *qcoeff_ptr; 118 int16_t *qcoeff = BLOCK_OFFSET(p->qcoeff, block);
136 int16_t *dqcoeff_ptr; 119 int16_t *dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
137 int eob = p->eobs[block], final_eob, sz = 0; 120 int eob = p->eobs[block], final_eob, sz = 0;
138 const int i0 = 0; 121 const int i0 = 0;
139 int rc, x, next, i; 122 int rc, x, next, i;
140 int64_t rdmult, rddiv, rd_cost0, rd_cost1; 123 int64_t rdmult, rddiv, rd_cost0, rd_cost1;
141 int rate0, rate1, error0, error1, t0, t1; 124 int rate0, rate1, error0, error1, t0, t1;
142 int best, band, pt; 125 int best, band, pt;
143 PLANE_TYPE type = pd->plane_type; 126 PLANE_TYPE type = pd->plane_type;
144 int err_mult = plane_rd_mult[type]; 127 int err_mult = plane_rd_mult[type];
145 const int default_eob = 16 << (tx_size << 1); 128 const int default_eob = 16 << (tx_size << 1);
146
147 const int mul = 1 + (tx_size == TX_32X32); 129 const int mul = 1 + (tx_size == TX_32X32);
148 uint8_t token_cache[1024]; 130 uint8_t token_cache[1024];
149 const int16_t *dequant_ptr = pd->dequant; 131 const int16_t *dequant_ptr = pd->dequant;
150 const uint8_t *const band_translate = get_band_translate(tx_size); 132 const uint8_t *const band_translate = get_band_translate(tx_size);
151 const scan_order *so = get_scan(xd, tx_size, type, block); 133 const scan_order *so = get_scan(xd, tx_size, type, block);
152 const int16_t *scan = so->scan; 134 const int16_t *scan = so->scan;
153 const int16_t *nb = so->neighbors; 135 const int16_t *nb = so->neighbors;
136 ENTROPY_CONTEXT *a, *l;
137 int tx_x, tx_y;
138 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &tx_x, &tx_y);
139 a = &ctx->ta[plane][tx_x];
140 l = &ctx->tl[plane][tx_y];
154 141
155 assert((!type && !plane) || (type && plane)); 142 assert((!type && !plane) || (type && plane));
156 dqcoeff_ptr = BLOCK_OFFSET(pd->dqcoeff, block);
157 qcoeff_ptr = BLOCK_OFFSET(p->qcoeff, block);
158 assert(eob <= default_eob); 143 assert(eob <= default_eob);
159 144
160 /* Now set up a Viterbi trellis to evaluate alternative roundings. */ 145 /* Now set up a Viterbi trellis to evaluate alternative roundings. */
161 rdmult = mb->rdmult * err_mult; 146 rdmult = mb->rdmult * err_mult;
162 if (!is_inter_block(&mb->e_mbd.mi_8x8[0]->mbmi)) 147 if (!is_inter_block(&mb->e_mbd.mi_8x8[0]->mbmi))
163 rdmult = (rdmult * 9) >> 4; 148 rdmult = (rdmult * 9) >> 4;
164 rddiv = mb->rddiv; 149 rddiv = mb->rddiv;
165 /* Initialize the sentinel node of the trellis. */ 150 /* Initialize the sentinel node of the trellis. */
166 tokens[eob][0].rate = 0; 151 tokens[eob][0].rate = 0;
167 tokens[eob][0].error = 0; 152 tokens[eob][0].error = 0;
168 tokens[eob][0].next = default_eob; 153 tokens[eob][0].next = default_eob;
169 tokens[eob][0].token = EOB_TOKEN; 154 tokens[eob][0].token = EOB_TOKEN;
170 tokens[eob][0].qc = 0; 155 tokens[eob][0].qc = 0;
171 *(tokens[eob] + 1) = *(tokens[eob] + 0); 156 *(tokens[eob] + 1) = *(tokens[eob] + 0);
172 next = eob; 157 next = eob;
173 for (i = 0; i < eob; i++) 158 for (i = 0; i < eob; i++)
174 token_cache[scan[i]] = vp9_pt_energy_class[vp9_dct_value_tokens_ptr[ 159 token_cache[scan[i]] = vp9_pt_energy_class[vp9_dct_value_tokens_ptr[
175 qcoeff_ptr[scan[i]]].token]; 160 qcoeff[scan[i]]].token];
176 161
177 for (i = eob; i-- > i0;) { 162 for (i = eob; i-- > i0;) {
178 int base_bits, d2, dx; 163 int base_bits, d2, dx;
179 164
180 rc = scan[i]; 165 rc = scan[i];
181 x = qcoeff_ptr[rc]; 166 x = qcoeff[rc];
182 /* Only add a trellis state for non-zero coefficients. */ 167 /* Only add a trellis state for non-zero coefficients. */
183 if (x) { 168 if (x) {
184 int shortcut = 0; 169 int shortcut = 0;
185 error0 = tokens[next][0].error; 170 error0 = tokens[next][0].error;
186 error1 = tokens[next][1].error; 171 error1 = tokens[next][1].error;
187 /* Evaluate the first possibility for this state. */ 172 /* Evaluate the first possibility for this state. */
188 rate0 = tokens[next][0].rate; 173 rate0 = tokens[next][0].rate;
189 rate1 = tokens[next][1].rate; 174 rate1 = tokens[next][1].rate;
190 t0 = (vp9_dct_value_tokens_ptr + x)->token; 175 t0 = (vp9_dct_value_tokens_ptr + x)->token;
191 /* Consider both possible successor states. */ 176 /* Consider both possible successor states. */
192 if (next < default_eob) { 177 if (next < default_eob) {
193 band = band_translate[i + 1]; 178 band = band_translate[i + 1];
194 pt = trellis_get_coeff_context(scan, nb, i, t0, token_cache); 179 pt = trellis_get_coeff_context(scan, nb, i, t0, token_cache);
195 rate0 += 180 rate0 +=
196 mb->token_costs[tx_size][type][ref][band][0][pt] 181 mb->token_costs[tx_size][type][ref][band][0][pt]
197 [tokens[next][0].token]; 182 [tokens[next][0].token];
198 rate1 += 183 rate1 +=
199 mb->token_costs[tx_size][type][ref][band][0][pt] 184 mb->token_costs[tx_size][type][ref][band][0][pt]
200 [tokens[next][1].token]; 185 [tokens[next][1].token];
201 } 186 }
202 UPDATE_RD_COST(); 187 UPDATE_RD_COST();
203 /* And pick the best. */ 188 /* And pick the best. */
204 best = rd_cost1 < rd_cost0; 189 best = rd_cost1 < rd_cost0;
205 base_bits = *(vp9_dct_value_cost_ptr + x); 190 base_bits = *(vp9_dct_value_cost_ptr + x);
206 dx = mul * (dqcoeff_ptr[rc] - coeff_ptr[rc]); 191 dx = mul * (dqcoeff[rc] - coeff[rc]);
207 d2 = dx * dx; 192 d2 = dx * dx;
208 tokens[i][0].rate = base_bits + (best ? rate1 : rate0); 193 tokens[i][0].rate = base_bits + (best ? rate1 : rate0);
209 tokens[i][0].error = d2 + (best ? error1 : error0); 194 tokens[i][0].error = d2 + (best ? error1 : error0);
210 tokens[i][0].next = next; 195 tokens[i][0].next = next;
211 tokens[i][0].token = t0; 196 tokens[i][0].token = t0;
212 tokens[i][0].qc = x; 197 tokens[i][0].qc = x;
213 best_index[i][0] = best; 198 best_index[i][0] = best;
214 199
215 /* Evaluate the second possibility for this state. */ 200 /* Evaluate the second possibility for this state. */
216 rate0 = tokens[next][0].rate; 201 rate0 = tokens[next][0].rate;
217 rate1 = tokens[next][1].rate; 202 rate1 = tokens[next][1].rate;
218 203
219 if ((abs(x)*dequant_ptr[rc != 0] > abs(coeff_ptr[rc]) * mul) && 204 if ((abs(x)*dequant_ptr[rc != 0] > abs(coeff[rc]) * mul) &&
220 (abs(x)*dequant_ptr[rc != 0] < abs(coeff_ptr[rc]) * mul + 205 (abs(x)*dequant_ptr[rc != 0] < abs(coeff[rc]) * mul +
221 dequant_ptr[rc != 0])) 206 dequant_ptr[rc != 0]))
222 shortcut = 1; 207 shortcut = 1;
223 else 208 else
224 shortcut = 0; 209 shortcut = 0;
225 210
226 if (shortcut) { 211 if (shortcut) {
227 sz = -(x < 0); 212 sz = -(x < 0);
228 x -= 2 * sz + 1; 213 x -= 2 * sz + 1;
229 } 214 }
230 215
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 rate1 = tokens[next][1].rate; 284 rate1 = tokens[next][1].rate;
300 error0 = tokens[next][0].error; 285 error0 = tokens[next][0].error;
301 error1 = tokens[next][1].error; 286 error1 = tokens[next][1].error;
302 t0 = tokens[next][0].token; 287 t0 = tokens[next][0].token;
303 t1 = tokens[next][1].token; 288 t1 = tokens[next][1].token;
304 rate0 += mb->token_costs[tx_size][type][ref][band][0][pt][t0]; 289 rate0 += mb->token_costs[tx_size][type][ref][band][0][pt][t0];
305 rate1 += mb->token_costs[tx_size][type][ref][band][0][pt][t1]; 290 rate1 += mb->token_costs[tx_size][type][ref][band][0][pt][t1];
306 UPDATE_RD_COST(); 291 UPDATE_RD_COST();
307 best = rd_cost1 < rd_cost0; 292 best = rd_cost1 < rd_cost0;
308 final_eob = i0 - 1; 293 final_eob = i0 - 1;
309 vpx_memset(qcoeff_ptr, 0, sizeof(*qcoeff_ptr) * (16 << (tx_size * 2))); 294 vpx_memset(qcoeff, 0, sizeof(*qcoeff) * (16 << (tx_size * 2)));
310 vpx_memset(dqcoeff_ptr, 0, sizeof(*dqcoeff_ptr) * (16 << (tx_size * 2))); 295 vpx_memset(dqcoeff, 0, sizeof(*dqcoeff) * (16 << (tx_size * 2)));
311 for (i = next; i < eob; i = next) { 296 for (i = next; i < eob; i = next) {
312 x = tokens[i][best].qc; 297 x = tokens[i][best].qc;
313 if (x) { 298 if (x) {
314 final_eob = i; 299 final_eob = i;
315 } 300 }
316 rc = scan[i]; 301 rc = scan[i];
317 qcoeff_ptr[rc] = x; 302 qcoeff[rc] = x;
318 dqcoeff_ptr[rc] = (x * dequant_ptr[rc != 0]) / mul; 303 dqcoeff[rc] = (x * dequant_ptr[rc != 0]) / mul;
319 304
320 next = tokens[i][best].next; 305 next = tokens[i][best].next;
321 best = best_index[i][best]; 306 best = best_index[i][best];
322 } 307 }
323 final_eob++; 308 final_eob++;
324 309
325 mb->plane[plane].eobs[block] = final_eob; 310 mb->plane[plane].eobs[block] = final_eob;
326 *a = *l = (final_eob > 0); 311 *a = *l = (final_eob > 0);
327 } 312 }
328 313
329 void vp9_optimize_b(int plane, int block, BLOCK_SIZE plane_bsize, 314 static INLINE void fdct32x32(int rd_transform,
330 TX_SIZE tx_size, MACROBLOCK *mb, struct optimize_ctx *ctx) { 315 const int16_t *src, int16_t *dst, int src_stride) {
331 int x, y; 316 if (rd_transform)
332 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &x, &y); 317 vp9_fdct32x32_rd(src, dst, src_stride);
333 optimize_b(mb, plane, block, plane_bsize, 318 else
334 &ctx->ta[plane][x], &ctx->tl[plane][y], tx_size); 319 vp9_fdct32x32(src, dst, src_stride);
335 } 320 }
336 321
337 static void optimize_init_b(int plane, BLOCK_SIZE bsize,
338 struct encode_b_args *args) {
339 const MACROBLOCKD *xd = &args->x->e_mbd;
340 const struct macroblockd_plane* const pd = &xd->plane[plane];
341 const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd);
342 const int num_4x4_w = num_4x4_blocks_wide_lookup[plane_bsize];
343 const int num_4x4_h = num_4x4_blocks_high_lookup[plane_bsize];
344 const MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi;
345 const TX_SIZE tx_size = plane ? get_uv_tx_size(mbmi) : mbmi->tx_size;
346
347 vp9_get_entropy_contexts(tx_size, args->ctx->ta[plane], args->ctx->tl[plane],
348 pd->above_context, pd->left_context,
349 num_4x4_w, num_4x4_h);
350 }
351 void vp9_xform_quant(MACROBLOCK *x, int plane, int block, 322 void vp9_xform_quant(MACROBLOCK *x, int plane, int block,
352 BLOCK_SIZE plane_bsize, TX_SIZE tx_size) { 323 BLOCK_SIZE plane_bsize, TX_SIZE tx_size) {
353 MACROBLOCKD *const xd = &x->e_mbd; 324 MACROBLOCKD *const xd = &x->e_mbd;
354 struct macroblock_plane *const p = &x->plane[plane]; 325 const struct macroblock_plane *const p = &x->plane[plane];
355 struct macroblockd_plane *const pd = &xd->plane[plane]; 326 const struct macroblockd_plane *const pd = &xd->plane[plane];
356 int16_t *coeff = BLOCK_OFFSET(p->coeff, block); 327 const scan_order *const scan_order = &vp9_default_scan_orders[tx_size];
357 int16_t *qcoeff = BLOCK_OFFSET(p->qcoeff, block); 328 int16_t *const coeff = BLOCK_OFFSET(p->coeff, block);
358 int16_t *dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); 329 int16_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block);
359 const scan_order *scan_order; 330 int16_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
360 uint16_t *eob = &p->eobs[block]; 331 uint16_t *const eob = &p->eobs[block];
361 const int diff_stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize]; 332 const int diff_stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize];
362 int i, j; 333 int i, j;
363 int16_t *src_diff; 334 const int16_t *src_diff;
364 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &i, &j); 335 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &i, &j);
365 src_diff = &p->src_diff[4 * (j * diff_stride + i)]; 336 src_diff = &p->src_diff[4 * (j * diff_stride + i)];
366 337
367 switch (tx_size) { 338 switch (tx_size) {
368 case TX_32X32: 339 case TX_32X32:
369 scan_order = &vp9_default_scan_orders[TX_32X32]; 340 fdct32x32(x->use_lp32x32fdct, src_diff, coeff, diff_stride);
370 if (x->use_lp32x32fdct)
371 vp9_fdct32x32_rd(src_diff, coeff, diff_stride);
372 else
373 vp9_fdct32x32(src_diff, coeff, diff_stride);
374 vp9_quantize_b_32x32(coeff, 1024, x->skip_block, p->zbin, p->round, 341 vp9_quantize_b_32x32(coeff, 1024, x->skip_block, p->zbin, p->round,
375 p->quant, p->quant_shift, qcoeff, dqcoeff, 342 p->quant, p->quant_shift, qcoeff, dqcoeff,
376 pd->dequant, p->zbin_extra, eob, scan_order->scan, 343 pd->dequant, p->zbin_extra, eob, scan_order->scan,
377 scan_order->iscan); 344 scan_order->iscan);
378 break; 345 break;
379 case TX_16X16: 346 case TX_16X16:
380 scan_order = &vp9_default_scan_orders[TX_16X16];
381 vp9_fdct16x16(src_diff, coeff, diff_stride); 347 vp9_fdct16x16(src_diff, coeff, diff_stride);
382 vp9_quantize_b(coeff, 256, x->skip_block, p->zbin, p->round, 348 vp9_quantize_b(coeff, 256, x->skip_block, p->zbin, p->round,
383 p->quant, p->quant_shift, qcoeff, dqcoeff, 349 p->quant, p->quant_shift, qcoeff, dqcoeff,
384 pd->dequant, p->zbin_extra, eob, 350 pd->dequant, p->zbin_extra, eob,
385 scan_order->scan, scan_order->iscan); 351 scan_order->scan, scan_order->iscan);
386 break; 352 break;
387 case TX_8X8: 353 case TX_8X8:
388 scan_order = &vp9_default_scan_orders[TX_8X8];
389 vp9_fdct8x8(src_diff, coeff, diff_stride); 354 vp9_fdct8x8(src_diff, coeff, diff_stride);
390 vp9_quantize_b(coeff, 64, x->skip_block, p->zbin, p->round, 355 vp9_quantize_b(coeff, 64, x->skip_block, p->zbin, p->round,
391 p->quant, p->quant_shift, qcoeff, dqcoeff, 356 p->quant, p->quant_shift, qcoeff, dqcoeff,
392 pd->dequant, p->zbin_extra, eob, 357 pd->dequant, p->zbin_extra, eob,
393 scan_order->scan, scan_order->iscan); 358 scan_order->scan, scan_order->iscan);
394 break; 359 break;
395 case TX_4X4: 360 case TX_4X4:
396 scan_order = &vp9_default_scan_orders[TX_4X4];
397 x->fwd_txm4x4(src_diff, coeff, diff_stride); 361 x->fwd_txm4x4(src_diff, coeff, diff_stride);
398 vp9_quantize_b(coeff, 16, x->skip_block, p->zbin, p->round, 362 vp9_quantize_b(coeff, 16, x->skip_block, p->zbin, p->round,
399 p->quant, p->quant_shift, qcoeff, dqcoeff, 363 p->quant, p->quant_shift, qcoeff, dqcoeff,
400 pd->dequant, p->zbin_extra, eob, 364 pd->dequant, p->zbin_extra, eob,
401 scan_order->scan, scan_order->iscan); 365 scan_order->scan, scan_order->iscan);
402 break; 366 break;
403 default: 367 default:
404 assert(0); 368 assert(0);
405 } 369 }
406 } 370 }
(...skipping 18 matching lines...) Expand all
425 p->eobs[block] = 0; 389 p->eobs[block] = 0;
426 ctx->ta[plane][i] = 0; 390 ctx->ta[plane][i] = 0;
427 ctx->tl[plane][j] = 0; 391 ctx->tl[plane][j] = 0;
428 return; 392 return;
429 } 393 }
430 394
431 if (!x->skip_recode) 395 if (!x->skip_recode)
432 vp9_xform_quant(x, plane, block, plane_bsize, tx_size); 396 vp9_xform_quant(x, plane, block, plane_bsize, tx_size);
433 397
434 if (x->optimize && (!x->skip_recode || !x->skip_optimize)) { 398 if (x->optimize && (!x->skip_recode || !x->skip_optimize)) {
435 vp9_optimize_b(plane, block, plane_bsize, tx_size, x, ctx); 399 optimize_b(plane, block, plane_bsize, tx_size, x, ctx);
436 } else { 400 } else {
437 ctx->ta[plane][i] = p->eobs[block] > 0; 401 ctx->ta[plane][i] = p->eobs[block] > 0;
438 ctx->tl[plane][j] = p->eobs[block] > 0; 402 ctx->tl[plane][j] = p->eobs[block] > 0;
439 } 403 }
440 404
441 if (p->eobs[block]) 405 if (p->eobs[block])
442 *(args->skip) = 0; 406 *(args->skip) = 0;
443 407
444 if (x->skip_encode || p->eobs[block] == 0) 408 if (x->skip_encode || p->eobs[block] == 0)
445 return; 409 return;
(...skipping 13 matching lines...) Expand all
459 // which is significant (not just an optimization) for the lossless 423 // which is significant (not just an optimization) for the lossless
460 // case. 424 // case.
461 xd->itxm_add(dqcoeff, dst, pd->dst.stride, p->eobs[block]); 425 xd->itxm_add(dqcoeff, dst, pd->dst.stride, p->eobs[block]);
462 break; 426 break;
463 default: 427 default:
464 assert(0 && "Invalid transform size"); 428 assert(0 && "Invalid transform size");
465 } 429 }
466 } 430 }
467 static void encode_block_pass1(int plane, int block, BLOCK_SIZE plane_bsize, 431 static void encode_block_pass1(int plane, int block, BLOCK_SIZE plane_bsize,
468 TX_SIZE tx_size, void *arg) { 432 TX_SIZE tx_size, void *arg) {
469 struct encode_b_args *const args = arg; 433 MACROBLOCK *const x = (MACROBLOCK *)arg;
470 MACROBLOCK *const x = args->x;
471 MACROBLOCKD *const xd = &x->e_mbd; 434 MACROBLOCKD *const xd = &x->e_mbd;
472 struct macroblock_plane *const p = &x->plane[plane]; 435 struct macroblock_plane *const p = &x->plane[plane];
473 struct macroblockd_plane *const pd = &xd->plane[plane]; 436 struct macroblockd_plane *const pd = &xd->plane[plane];
474 int16_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); 437 int16_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
475 int i, j; 438 int i, j;
476 uint8_t *dst; 439 uint8_t *dst;
477 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &i, &j); 440 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &i, &j);
478 dst = &pd->dst.buf[4 * j * pd->dst.stride + 4 * i]; 441 dst = &pd->dst.buf[4 * j * pd->dst.stride + 4 * i];
479 442
480 vp9_xform_quant(x, plane, block, plane_bsize, tx_size); 443 vp9_xform_quant(x, plane, block, plane_bsize, tx_size);
481 444
482 if (p->eobs[block] == 0) 445 if (p->eobs[block] > 0)
483 return; 446 xd->itxm_add(dqcoeff, dst, pd->dst.stride, p->eobs[block]);
484
485 xd->itxm_add(dqcoeff, dst, pd->dst.stride, p->eobs[block]);
486 } 447 }
487 448
488 void vp9_encode_sby(MACROBLOCK *x, BLOCK_SIZE bsize) { 449 void vp9_encode_sby_pass1(MACROBLOCK *x, BLOCK_SIZE bsize) {
489 MACROBLOCKD *const xd = &x->e_mbd; 450 vp9_subtract_plane(x, bsize, 0);
490 struct optimize_ctx ctx; 451 vp9_foreach_transformed_block_in_plane(&x->e_mbd, bsize, 0,
491 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; 452 encode_block_pass1, x);
492 struct encode_b_args arg = {x, &ctx, &mbmi->skip};
493
494 vp9_subtract_sby(x, bsize);
495 if (x->optimize)
496 optimize_init_b(0, bsize, &arg);
497
498 vp9_foreach_transformed_block_in_plane(xd, bsize, 0, encode_block_pass1,
499 &arg);
500 } 453 }
501 454
502 void vp9_encode_sb(MACROBLOCK *x, BLOCK_SIZE bsize) { 455 void vp9_encode_sb(MACROBLOCK *x, BLOCK_SIZE bsize) {
503 MACROBLOCKD *const xd = &x->e_mbd; 456 MACROBLOCKD *const xd = &x->e_mbd;
504 struct optimize_ctx ctx; 457 struct optimize_ctx ctx;
505 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; 458 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi;
506 struct encode_b_args arg = {x, &ctx, &mbmi->skip}; 459 struct encode_b_args arg = {x, &ctx, &mbmi->skip};
460 int plane;
507 461
508 if (!x->skip_recode) 462 for (plane = 0; plane < MAX_MB_PLANE; ++plane) {
509 vp9_subtract_sb(x, bsize); 463 if (!x->skip_recode)
464 vp9_subtract_plane(x, bsize, plane);
510 465
511 if (x->optimize && (!x->skip_recode || !x->skip_optimize)) { 466 if (x->optimize && (!x->skip_recode || !x->skip_optimize)) {
512 int i; 467 const struct macroblockd_plane* const pd = &xd->plane[plane];
513 for (i = 0; i < MAX_MB_PLANE; ++i) 468 const TX_SIZE tx_size = plane ? get_uv_tx_size(mbmi) : mbmi->tx_size;
514 optimize_init_b(i, bsize, &arg); 469 vp9_get_entropy_contexts(bsize, tx_size, pd,
470 ctx.ta[plane], ctx.tl[plane]);
471 }
472
473 vp9_foreach_transformed_block_in_plane(xd, bsize, plane, encode_block,
474 &arg);
515 } 475 }
516
517 vp9_foreach_transformed_block(xd, bsize, encode_block, &arg);
518 } 476 }
519 477
520 static void encode_block_intra(int plane, int block, BLOCK_SIZE plane_bsize, 478 static void encode_block_intra(int plane, int block, BLOCK_SIZE plane_bsize,
521 TX_SIZE tx_size, void *arg) { 479 TX_SIZE tx_size, void *arg) {
522 struct encode_b_args* const args = arg; 480 struct encode_b_args* const args = arg;
523 MACROBLOCK *const x = args->x; 481 MACROBLOCK *const x = args->x;
524 MACROBLOCKD *const xd = &x->e_mbd; 482 MACROBLOCKD *const xd = &x->e_mbd;
525 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; 483 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi;
526 struct macroblock_plane *const p = &x->plane[plane]; 484 struct macroblock_plane *const p = &x->plane[plane];
527 struct macroblockd_plane *const pd = &xd->plane[plane]; 485 struct macroblockd_plane *const pd = &xd->plane[plane];
528 int16_t *coeff = BLOCK_OFFSET(p->coeff, block); 486 int16_t *coeff = BLOCK_OFFSET(p->coeff, block);
529 int16_t *qcoeff = BLOCK_OFFSET(p->qcoeff, block); 487 int16_t *qcoeff = BLOCK_OFFSET(p->qcoeff, block);
530 int16_t *dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); 488 int16_t *dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
531 const scan_order *scan_order; 489 const scan_order *scan_order;
532 TX_TYPE tx_type; 490 TX_TYPE tx_type;
533 MB_PREDICTION_MODE mode; 491 MB_PREDICTION_MODE mode;
534 const int bwl = b_width_log2(plane_bsize); 492 const int bwl = b_width_log2(plane_bsize);
535 const int diff_stride = 4 * (1 << bwl); 493 const int diff_stride = 4 * (1 << bwl);
536 uint8_t *src, *dst; 494 uint8_t *src, *dst;
537 int16_t *src_diff; 495 int16_t *src_diff;
538 uint16_t *eob = &p->eobs[block]; 496 uint16_t *eob = &p->eobs[block];
497 const int src_stride = p->src.stride;
498 const int dst_stride = pd->dst.stride;
539 int i, j; 499 int i, j;
540 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &i, &j); 500 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &i, &j);
541 dst = &pd->dst.buf[4 * (j * pd->dst.stride + i)]; 501 dst = &pd->dst.buf[4 * (j * dst_stride + i)];
542 src = &p->src.buf[4 * (j * p->src.stride + i)]; 502 src = &p->src.buf[4 * (j * src_stride + i)];
543 src_diff = &p->src_diff[4 * (j * diff_stride + i)]; 503 src_diff = &p->src_diff[4 * (j * diff_stride + i)];
544 504
545 // if (x->optimize) 505 // if (x->optimize)
546 // vp9_optimize_b(plane, block, plane_bsize, tx_size, x, args->ctx); 506 // optimize_b(plane, block, plane_bsize, tx_size, x, args->ctx);
547 507
548 switch (tx_size) { 508 switch (tx_size) {
549 case TX_32X32: 509 case TX_32X32:
550 scan_order = &vp9_default_scan_orders[TX_32X32]; 510 scan_order = &vp9_default_scan_orders[TX_32X32];
551 mode = plane == 0 ? mbmi->mode : mbmi->uv_mode; 511 mode = plane == 0 ? mbmi->mode : mbmi->uv_mode;
552 vp9_predict_intra_block(xd, block >> 6, bwl, TX_32X32, mode, 512 vp9_predict_intra_block(xd, block >> 6, bwl, TX_32X32, mode,
553 x->skip_encode ? src : dst, 513 x->skip_encode ? src : dst,
554 x->skip_encode ? p->src.stride : pd->dst.stride, 514 x->skip_encode ? src_stride : dst_stride,
555 dst, pd->dst.stride, i, j, plane); 515 dst, dst_stride, i, j, plane);
556 if (!x->skip_recode) { 516 if (!x->skip_recode) {
557 vp9_subtract_block(32, 32, src_diff, diff_stride, 517 vp9_subtract_block(32, 32, src_diff, diff_stride,
558 src, p->src.stride, dst, pd->dst.stride); 518 src, src_stride, dst, dst_stride);
559 if (x->use_lp32x32fdct) 519 fdct32x32(x->use_lp32x32fdct, src_diff, coeff, diff_stride);
560 vp9_fdct32x32_rd(src_diff, coeff, diff_stride);
561 else
562 vp9_fdct32x32(src_diff, coeff, diff_stride);
563 vp9_quantize_b_32x32(coeff, 1024, x->skip_block, p->zbin, p->round, 520 vp9_quantize_b_32x32(coeff, 1024, x->skip_block, p->zbin, p->round,
564 p->quant, p->quant_shift, qcoeff, dqcoeff, 521 p->quant, p->quant_shift, qcoeff, dqcoeff,
565 pd->dequant, p->zbin_extra, eob, scan_order->scan, 522 pd->dequant, p->zbin_extra, eob, scan_order->scan,
566 scan_order->iscan); 523 scan_order->iscan);
567 } 524 }
568 if (!x->skip_encode && *eob) 525 if (!x->skip_encode && *eob)
569 vp9_idct32x32_add(dqcoeff, dst, pd->dst.stride, *eob); 526 vp9_idct32x32_add(dqcoeff, dst, dst_stride, *eob);
570 break; 527 break;
571 case TX_16X16: 528 case TX_16X16:
572 tx_type = get_tx_type_16x16(pd->plane_type, xd); 529 tx_type = get_tx_type_16x16(pd->plane_type, xd);
573 scan_order = &vp9_scan_orders[TX_16X16][tx_type]; 530 scan_order = &vp9_scan_orders[TX_16X16][tx_type];
574 mode = plane == 0 ? mbmi->mode : mbmi->uv_mode; 531 mode = plane == 0 ? mbmi->mode : mbmi->uv_mode;
575 vp9_predict_intra_block(xd, block >> 4, bwl, TX_16X16, mode, 532 vp9_predict_intra_block(xd, block >> 4, bwl, TX_16X16, mode,
576 x->skip_encode ? src : dst, 533 x->skip_encode ? src : dst,
577 x->skip_encode ? p->src.stride : pd->dst.stride, 534 x->skip_encode ? src_stride : dst_stride,
578 dst, pd->dst.stride, i, j, plane); 535 dst, dst_stride, i, j, plane);
579 if (!x->skip_recode) { 536 if (!x->skip_recode) {
580 vp9_subtract_block(16, 16, src_diff, diff_stride, 537 vp9_subtract_block(16, 16, src_diff, diff_stride,
581 src, p->src.stride, dst, pd->dst.stride); 538 src, src_stride, dst, dst_stride);
582 vp9_fht16x16(src_diff, coeff, diff_stride, tx_type); 539 vp9_fht16x16(src_diff, coeff, diff_stride, tx_type);
583 vp9_quantize_b(coeff, 256, x->skip_block, p->zbin, p->round, 540 vp9_quantize_b(coeff, 256, x->skip_block, p->zbin, p->round,
584 p->quant, p->quant_shift, qcoeff, dqcoeff, 541 p->quant, p->quant_shift, qcoeff, dqcoeff,
585 pd->dequant, p->zbin_extra, eob, scan_order->scan, 542 pd->dequant, p->zbin_extra, eob, scan_order->scan,
586 scan_order->iscan); 543 scan_order->iscan);
587 } 544 }
588 if (!x->skip_encode && *eob) 545 if (!x->skip_encode && *eob)
589 vp9_iht16x16_add(tx_type, dqcoeff, dst, pd->dst.stride, *eob); 546 vp9_iht16x16_add(tx_type, dqcoeff, dst, dst_stride, *eob);
590 break; 547 break;
591 case TX_8X8: 548 case TX_8X8:
592 tx_type = get_tx_type_8x8(pd->plane_type, xd); 549 tx_type = get_tx_type_8x8(pd->plane_type, xd);
593 scan_order = &vp9_scan_orders[TX_8X8][tx_type]; 550 scan_order = &vp9_scan_orders[TX_8X8][tx_type];
594 mode = plane == 0 ? mbmi->mode : mbmi->uv_mode; 551 mode = plane == 0 ? mbmi->mode : mbmi->uv_mode;
595 vp9_predict_intra_block(xd, block >> 2, bwl, TX_8X8, mode, 552 vp9_predict_intra_block(xd, block >> 2, bwl, TX_8X8, mode,
596 x->skip_encode ? src : dst, 553 x->skip_encode ? src : dst,
597 x->skip_encode ? p->src.stride : pd->dst.stride, 554 x->skip_encode ? src_stride : dst_stride,
598 dst, pd->dst.stride, i, j, plane); 555 dst, dst_stride, i, j, plane);
599 if (!x->skip_recode) { 556 if (!x->skip_recode) {
600 vp9_subtract_block(8, 8, src_diff, diff_stride, 557 vp9_subtract_block(8, 8, src_diff, diff_stride,
601 src, p->src.stride, dst, pd->dst.stride); 558 src, src_stride, dst, dst_stride);
602 vp9_fht8x8(src_diff, coeff, diff_stride, tx_type); 559 vp9_fht8x8(src_diff, coeff, diff_stride, tx_type);
603 vp9_quantize_b(coeff, 64, x->skip_block, p->zbin, p->round, p->quant, 560 vp9_quantize_b(coeff, 64, x->skip_block, p->zbin, p->round, p->quant,
604 p->quant_shift, qcoeff, dqcoeff, 561 p->quant_shift, qcoeff, dqcoeff,
605 pd->dequant, p->zbin_extra, eob, scan_order->scan, 562 pd->dequant, p->zbin_extra, eob, scan_order->scan,
606 scan_order->iscan); 563 scan_order->iscan);
607 } 564 }
608 if (!x->skip_encode && *eob) 565 if (!x->skip_encode && *eob)
609 vp9_iht8x8_add(tx_type, dqcoeff, dst, pd->dst.stride, *eob); 566 vp9_iht8x8_add(tx_type, dqcoeff, dst, dst_stride, *eob);
610 break; 567 break;
611 case TX_4X4: 568 case TX_4X4:
612 tx_type = get_tx_type_4x4(pd->plane_type, xd, block); 569 tx_type = get_tx_type_4x4(pd->plane_type, xd, block);
613 scan_order = &vp9_scan_orders[TX_4X4][tx_type]; 570 scan_order = &vp9_scan_orders[TX_4X4][tx_type];
614 if (mbmi->sb_type < BLOCK_8X8 && plane == 0) 571 mode = plane == 0 ? get_y_mode(xd->mi_8x8[0], block) : mbmi->uv_mode;
615 mode = xd->mi_8x8[0]->bmi[block].as_mode;
616 else
617 mode = plane == 0 ? mbmi->mode : mbmi->uv_mode;
618
619 vp9_predict_intra_block(xd, block, bwl, TX_4X4, mode, 572 vp9_predict_intra_block(xd, block, bwl, TX_4X4, mode,
620 x->skip_encode ? src : dst, 573 x->skip_encode ? src : dst,
621 x->skip_encode ? p->src.stride : pd->dst.stride, 574 x->skip_encode ? src_stride : dst_stride,
622 dst, pd->dst.stride, i, j, plane); 575 dst, dst_stride, i, j, plane);
623 576
624 if (!x->skip_recode) { 577 if (!x->skip_recode) {
625 vp9_subtract_block(4, 4, src_diff, diff_stride, 578 vp9_subtract_block(4, 4, src_diff, diff_stride,
626 src, p->src.stride, dst, pd->dst.stride); 579 src, src_stride, dst, dst_stride);
627 if (tx_type != DCT_DCT) 580 if (tx_type != DCT_DCT)
628 vp9_fht4x4(src_diff, coeff, diff_stride, tx_type); 581 vp9_fht4x4(src_diff, coeff, diff_stride, tx_type);
629 else 582 else
630 x->fwd_txm4x4(src_diff, coeff, diff_stride); 583 x->fwd_txm4x4(src_diff, coeff, diff_stride);
631 vp9_quantize_b(coeff, 16, x->skip_block, p->zbin, p->round, p->quant, 584 vp9_quantize_b(coeff, 16, x->skip_block, p->zbin, p->round, p->quant,
632 p->quant_shift, qcoeff, dqcoeff, 585 p->quant_shift, qcoeff, dqcoeff,
633 pd->dequant, p->zbin_extra, eob, scan_order->scan, 586 pd->dequant, p->zbin_extra, eob, scan_order->scan,
634 scan_order->iscan); 587 scan_order->iscan);
635 } 588 }
636 589
637 if (!x->skip_encode && *eob) { 590 if (!x->skip_encode && *eob) {
638 if (tx_type == DCT_DCT) 591 if (tx_type == DCT_DCT)
639 // this is like vp9_short_idct4x4 but has a special case around eob<=1 592 // this is like vp9_short_idct4x4 but has a special case around eob<=1
640 // which is significant (not just an optimization) for the lossless 593 // which is significant (not just an optimization) for the lossless
641 // case. 594 // case.
642 xd->itxm_add(dqcoeff, dst, pd->dst.stride, *eob); 595 xd->itxm_add(dqcoeff, dst, dst_stride, *eob);
643 else 596 else
644 vp9_iht4x4_16_add(dqcoeff, dst, pd->dst.stride, tx_type); 597 vp9_iht4x4_16_add(dqcoeff, dst, dst_stride, tx_type);
645 } 598 }
646 break; 599 break;
647 default: 600 default:
648 assert(0); 601 assert(0);
649 } 602 }
650 if (*eob) 603 if (*eob)
651 *(args->skip) = 0; 604 *(args->skip) = 0;
652 } 605 }
653 606
654 void vp9_encode_block_intra(MACROBLOCK *x, int plane, int block, 607 void vp9_encode_block_intra(MACROBLOCK *x, int plane, int block,
(...skipping 16 matching lines...) Expand all
671 MB_MODE_INFO * mbmi = &x->e_mbd.mi_8x8[0]->mbmi; 624 MB_MODE_INFO * mbmi = &x->e_mbd.mi_8x8[0]->mbmi;
672 x->skip_encode = 0; 625 x->skip_encode = 0;
673 mbmi->mode = DC_PRED; 626 mbmi->mode = DC_PRED;
674 mbmi->ref_frame[0] = INTRA_FRAME; 627 mbmi->ref_frame[0] = INTRA_FRAME;
675 mbmi->tx_size = use_16x16_pred ? (mbmi->sb_type >= BLOCK_16X16 ? TX_16X16 628 mbmi->tx_size = use_16x16_pred ? (mbmi->sb_type >= BLOCK_16X16 ? TX_16X16
676 : TX_8X8) 629 : TX_8X8)
677 : TX_4X4; 630 : TX_4X4;
678 vp9_encode_intra_block_plane(x, mbmi->sb_type, 0); 631 vp9_encode_intra_block_plane(x, mbmi->sb_type, 0);
679 return vp9_get_mb_ss(x->plane[0].src_diff); 632 return vp9_get_mb_ss(x->plane[0].src_diff);
680 } 633 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_encodemb.h ('k') | source/libvpx/vp9/encoder/vp9_encodemv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698