pickinter.c 53.8 KB
Newer Older
John Koleszar's avatar
John Koleszar committed
1
/*
2
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
John Koleszar's avatar
John Koleszar committed
3
 *
4
 *  Use of this source code is governed by a BSD-style license
5 6
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
7
 *  in the file PATENTS.  All contributing project authors may
8
 *  be found in the AUTHORS file in the root of the source tree.
John Koleszar's avatar
John Koleszar committed
9 10 11 12
 */


#include <limits.h>
13
#include "vpx_config.h"
John Koleszar's avatar
John Koleszar committed
14 15 16
#include "onyx_int.h"
#include "modecosts.h"
#include "encodeintra.h"
John Koleszar's avatar
John Koleszar committed
17
#include "vp8/common/entropymode.h"
John Koleszar's avatar
John Koleszar committed
18
#include "pickinter.h"
John Koleszar's avatar
John Koleszar committed
19
#include "vp8/common/findnearmv.h"
John Koleszar's avatar
John Koleszar committed
20
#include "encodemb.h"
John Koleszar's avatar
John Koleszar committed
21 22 23 24
#include "vp8/common/reconinter.h"
#include "vp8/common/reconintra.h"
#include "vp8/common/reconintra4x4.h"
#include "vp8/common/g_common.h"
John Koleszar's avatar
John Koleszar committed
25 26
#include "variance.h"
#include "mcomp.h"
27
#include "rdopt.h"
John Koleszar's avatar
John Koleszar committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41
#include "vpx_mem/vpx_mem.h"

#if CONFIG_RUNTIME_CPU_DETECT
#define IF_RTCD(x) (x)
#else
#define IF_RTCD(x)  NULL
#endif

extern int VP8_UVSSE(MACROBLOCK *x, const vp8_variance_rtcd_vtable_t *rtcd);

#ifdef SPEEDSTATS
extern unsigned int cnt_pm;
#endif

42
extern const int vp8_ref_frame_order[MAX_MODES];
John Koleszar's avatar
John Koleszar committed
43 44 45 46 47 48
extern const MB_PREDICTION_MODE vp8_mode_order[MAX_MODES];

extern unsigned int (*vp8_get4x4sse_cs)(unsigned char *src_ptr, int  source_stride, unsigned char *ref_ptr, int  recon_stride);
extern int vp8_cost_mv_ref(MB_PREDICTION_MODE m, const int near_mv_ref_ct[4]);


Scott LaVarnway's avatar
Scott LaVarnway committed
49 50 51 52 53 54
int vp8_skip_fractional_mv_step(MACROBLOCK *mb, BLOCK *b, BLOCKD *d,
                                int_mv *bestmv, int_mv *ref_mv,
                                int error_per_bit,
                                const vp8_variance_fn_ptr_t *vfp,
                                int *mvcost[2], int *distortion,
                                unsigned int *sse)
John Koleszar's avatar
John Koleszar committed
55 56 57 58 59
{
    (void) b;
    (void) d;
    (void) ref_mv;
    (void) error_per_bit;
60
    (void) vfp;
John Koleszar's avatar
John Koleszar committed
61
    (void) mvcost;
62
    (void) distortion;
63
    (void) sse;
Scott LaVarnway's avatar
Scott LaVarnway committed
64 65
    bestmv->as_mv.row <<= 3;
    bestmv->as_mv.col <<= 3;
John Koleszar's avatar
John Koleszar committed
66 67 68 69
    return 0;
}


70 71 72 73
static int get_inter_mbpred_error(MACROBLOCK *mb,
                                  const vp8_variance_fn_ptr_t *vfp,
                                  unsigned int *sse,
                                  int_mv this_mv)
John Koleszar's avatar
John Koleszar committed
74 75 76 77 78 79 80 81
{

    BLOCK *b = &mb->block[0];
    BLOCKD *d = &mb->e_mbd.block[0];
    unsigned char *what = (*(b->base_src) + b->src);
    int what_stride = b->src_stride;
    unsigned char *in_what = *(d->base_pre) + d->pre ;
    int in_what_stride = d->pre_stride;
82 83
    int xoffset = this_mv.as_mv.col & 7;
    int yoffset = this_mv.as_mv.row & 7;
John Koleszar's avatar
John Koleszar committed
84

85
    in_what += (this_mv.as_mv.row >> 3) * d->pre_stride + (this_mv.as_mv.col >> 3);
John Koleszar's avatar
John Koleszar committed
86 87 88

    if (xoffset | yoffset)
    {
89
        return vfp->svf(in_what, in_what_stride, xoffset, yoffset, what, what_stride, sse);
John Koleszar's avatar
John Koleszar committed
90 91 92
    }
    else
    {
93
        return vfp->vf(what, what_stride, in_what, in_what_stride, sse);
John Koleszar's avatar
John Koleszar committed
94 95 96 97 98 99 100
    }

}


unsigned int vp8_get4x4sse_cs_c
(
101
    const unsigned char *src_ptr,
John Koleszar's avatar
John Koleszar committed
102
    int  source_stride,
103
    const unsigned char *ref_ptr,
104
    int  recon_stride
John Koleszar's avatar
John Koleszar committed
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
)
{
    int distortion = 0;
    int r, c;

    for (r = 0; r < 4; r++)
    {
        for (c = 0; c < 4; c++)
        {
            int diff = src_ptr[c] - ref_ptr[c];
            distortion += diff * diff;
        }

        src_ptr += source_stride;
        ref_ptr += recon_stride;
    }

    return distortion;
}

static int get_prediction_error(BLOCK *be, BLOCKD *b, const vp8_variance_rtcd_vtable_t *rtcd)
{
    unsigned char *sptr;
    unsigned char *dptr;
    sptr = (*(be->base_src) + be->src);
    dptr = b->predictor;

132
    return VARIANCE_INVOKE(rtcd, get4x4sse_cs)(sptr, be->src_stride, dptr, 16);
John Koleszar's avatar
John Koleszar committed
133 134 135 136 137 138

}

static int pick_intra4x4block(
    const VP8_ENCODER_RTCD *rtcd,
    MACROBLOCK *x,
139
    int ib,
John Koleszar's avatar
John Koleszar committed
140
    B_PREDICTION_MODE *best_mode,
Scott LaVarnway's avatar
Scott LaVarnway committed
141
    unsigned int *mode_costs,
John Koleszar's avatar
John Koleszar committed
142 143 144 145

    int *bestrate,
    int *bestdistortion)
{
146 147 148

    BLOCKD *b = &x->e_mbd.block[ib];
    BLOCK *be = &x->block[ib];
John Koleszar's avatar
John Koleszar committed
149 150 151 152 153 154 155 156 157 158
    B_PREDICTION_MODE mode;
    int best_rd = INT_MAX;       // 1<<30
    int rate;
    int distortion;

    for (mode = B_DC_PRED; mode <= B_HE_PRED /*B_HU_PRED*/; mode++)
    {
        int this_rd;

        rate = mode_costs[mode];
159
        RECON_INVOKE(&rtcd->common->recon, intra4x4_predict)
160 161
                     (*(b->base_dst) + b->dst, b->dst_stride,
                      mode, b->predictor, 16);
John Koleszar's avatar
John Koleszar committed
162
        distortion = get_prediction_error(be, b, &rtcd->variance);
Yunqing Wang's avatar
Yunqing Wang committed
163
        this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion);
John Koleszar's avatar
John Koleszar committed
164 165 166 167 168 169 170 171 172

        if (this_rd < best_rd)
        {
            *bestrate = rate;
            *bestdistortion = distortion;
            best_rd = this_rd;
            *best_mode = mode;
        }
    }
Scott LaVarnway's avatar
Scott LaVarnway committed
173 174

    b->bmi.as_mode = (B_PREDICTION_MODE)(*best_mode);
175
    vp8_encode_intra4x4block(rtcd, x, ib);
John Koleszar's avatar
John Koleszar committed
176 177 178 179
    return best_rd;
}


180
static int pick_intra4x4mby_modes
181 182 183 184 185 186
(
    const VP8_ENCODER_RTCD *rtcd,
    MACROBLOCK *mb,
    int *Rate,
    int *best_dist
)
John Koleszar's avatar
John Koleszar committed
187 188 189 190
{
    MACROBLOCKD *const xd = &mb->e_mbd;
    int i;
    int cost = mb->mbmode_cost [xd->frame_type] [B_PRED];
191
    int error;
John Koleszar's avatar
John Koleszar committed
192
    int distortion = 0;
Scott LaVarnway's avatar
Scott LaVarnway committed
193
    unsigned int *bmode_costs;
John Koleszar's avatar
John Koleszar committed
194 195 196

    vp8_intra_prediction_down_copy(xd);

Scott LaVarnway's avatar
Scott LaVarnway committed
197 198
    bmode_costs = mb->inter_bmode_costs;

John Koleszar's avatar
John Koleszar committed
199 200 201 202
    for (i = 0; i < 16; i++)
    {
        MODE_INFO *const mic = xd->mode_info_context;
        const int mis = xd->mode_info_stride;
Scott LaVarnway's avatar
Scott LaVarnway committed
203

John Koleszar's avatar
John Koleszar committed
204 205 206
        B_PREDICTION_MODE UNINITIALIZED_IS_SAFE(best_mode);
        int UNINITIALIZED_IS_SAFE(r), UNINITIALIZED_IS_SAFE(d);

Scott LaVarnway's avatar
Scott LaVarnway committed
207 208 209 210 211 212 213 214 215 216
        if (mb->e_mbd.frame_type == KEY_FRAME)
        {
            const B_PREDICTION_MODE A = above_block_mode(mic, i, mis);
            const B_PREDICTION_MODE L = left_block_mode(mic, i);

            bmode_costs  = mb->bmode_costs[A][L];
        }


        pick_intra4x4block(rtcd, mb, i, &best_mode, bmode_costs, &r, &d);
John Koleszar's avatar
John Koleszar committed
217 218 219

        cost += r;
        distortion += d;
Scott LaVarnway's avatar
Scott LaVarnway committed
220
        mic->bmi[i].as_mode = best_mode;
John Koleszar's avatar
John Koleszar committed
221

222 223
        // Break out case where we have already exceeded best so far value
        // that was passed in
John Koleszar's avatar
John Koleszar committed
224 225 226 227 228 229 230
        if (distortion > *best_dist)
            break;
    }

    *Rate = cost;

    if (i == 16)
231
    {
John Koleszar's avatar
John Koleszar committed
232
        *best_dist = distortion;
Yunqing Wang's avatar
Yunqing Wang committed
233
        error = RDCOST(mb->rdmult, mb->rddiv, cost, distortion);
234
    }
John Koleszar's avatar
John Koleszar committed
235
    else
236
    {
John Koleszar's avatar
John Koleszar committed
237
        *best_dist = INT_MAX;
238 239
        error = INT_MAX;
    }
John Koleszar's avatar
John Koleszar committed
240 241 242 243

    return error;
}

244
static void pick_intra_mbuv_mode(MACROBLOCK *mb)
John Koleszar's avatar
John Koleszar committed
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
{

    MACROBLOCKD *x = &mb->e_mbd;
    unsigned char *uabove_row = x->dst.u_buffer - x->dst.uv_stride;
    unsigned char *vabove_row = x->dst.v_buffer - x->dst.uv_stride;
    unsigned char *usrc_ptr = (mb->block[16].src + *mb->block[16].base_src);
    unsigned char *vsrc_ptr = (mb->block[20].src + *mb->block[20].base_src);
    int uvsrc_stride = mb->block[16].src_stride;
    unsigned char uleft_col[8];
    unsigned char vleft_col[8];
    unsigned char utop_left = uabove_row[-1];
    unsigned char vtop_left = vabove_row[-1];
    int i, j;
    int expected_udc;
    int expected_vdc;
    int shift;
    int Uaverage = 0;
    int Vaverage = 0;
    int diff;
    int pred_error[4] = {0, 0, 0, 0}, best_error = INT_MAX;
    MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(best_mode);


    for (i = 0; i < 8; i++)
    {
        uleft_col[i] = x->dst.u_buffer [i* x->dst.uv_stride -1];
        vleft_col[i] = x->dst.v_buffer [i* x->dst.uv_stride -1];
    }

    if (!x->up_available && !x->left_available)
    {
        expected_udc = 128;
        expected_vdc = 128;
    }
    else
    {
        shift = 2;

        if (x->up_available)
        {

            for (i = 0; i < 8; i++)
            {
                Uaverage += uabove_row[i];
                Vaverage += vabove_row[i];
            }

            shift ++;

        }

        if (x->left_available)
        {
            for (i = 0; i < 8; i++)
            {
                Uaverage += uleft_col[i];
                Vaverage += vleft_col[i];
            }

            shift ++;

        }

        expected_udc = (Uaverage + (1 << (shift - 1))) >> shift;
        expected_vdc = (Vaverage + (1 << (shift - 1))) >> shift;
    }


    for (i = 0; i < 8; i++)
    {
        for (j = 0; j < 8; j++)
        {

            int predu = uleft_col[i] + uabove_row[j] - utop_left;
            int predv = vleft_col[i] + vabove_row[j] - vtop_left;
            int u_p, v_p;

            u_p = usrc_ptr[j];
            v_p = vsrc_ptr[j];

            if (predu < 0)
                predu = 0;

            if (predu > 255)
                predu = 255;

            if (predv < 0)
                predv = 0;

            if (predv > 255)
                predv = 255;


            diff = u_p - expected_udc;
            pred_error[DC_PRED] += diff * diff;
            diff = v_p - expected_vdc;
            pred_error[DC_PRED] += diff * diff;


            diff = u_p - uabove_row[j];
            pred_error[V_PRED] += diff * diff;
            diff = v_p - vabove_row[j];
            pred_error[V_PRED] += diff * diff;


            diff = u_p - uleft_col[i];
            pred_error[H_PRED] += diff * diff;
            diff = v_p - vleft_col[i];
            pred_error[H_PRED] += diff * diff;


            diff = u_p - predu;
            pred_error[TM_PRED] += diff * diff;
            diff = v_p - predv;
            pred_error[TM_PRED] += diff * diff;


        }

        usrc_ptr += uvsrc_stride;
        vsrc_ptr += uvsrc_stride;

        if (i == 3)
        {
            usrc_ptr = (mb->block[18].src + *mb->block[18].base_src);
            vsrc_ptr = (mb->block[22].src + *mb->block[22].base_src);
        }



    }


    for (i = DC_PRED; i <= TM_PRED; i++)
    {
        if (best_error > pred_error[i])
        {
            best_error = pred_error[i];
            best_mode = (MB_PREDICTION_MODE)i;
        }
    }


388
    mb->e_mbd.mode_info_context->mbmi.uv_mode = best_mode;
John Koleszar's avatar
John Koleszar committed
389 390 391

}

392
static void update_mvcount(VP8_COMP *cpi, MACROBLOCKD *xd, int_mv *best_ref_mv)
393
{
394 395
    /* Split MV modes currently not supported when RD is nopt enabled,
     * therefore, only need to modify MVcount in NEWMV mode. */
396 397
    if (xd->mode_info_context->mbmi.mode == NEWMV)
    {
Scott LaVarnway's avatar
Scott LaVarnway committed
398
        cpi->MVcount[0][mv_max+((xd->mode_info_context->mbmi.mv.as_mv.row -
399
                                      best_ref_mv->as_mv.row) >> 1)]++;
Scott LaVarnway's avatar
Scott LaVarnway committed
400
        cpi->MVcount[1][mv_max+((xd->mode_info_context->mbmi.mv.as_mv.col -
401
                                      best_ref_mv->as_mv.col) >> 1)]++;
402 403 404
    }
}

405 406 407
void vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset,
                         int recon_uvoffset, int *returnrate,
                         int *returndistortion, int *returnintra)
John Koleszar's avatar
John Koleszar committed
408 409 410 411 412
{
    BLOCK *b = &x->block[0];
    BLOCKD *d = &x->e_mbd.block[0];
    MACROBLOCKD *xd = &x->e_mbd;
    MB_MODE_INFO best_mbmode;
413

Scott LaVarnway's avatar
Scott LaVarnway committed
414 415
    int_mv best_ref_mv;
    int_mv mode_mv[MB_MODE_COUNT];
John Koleszar's avatar
John Koleszar committed
416 417 418 419 420 421 422 423 424 425 426 427
    MB_PREDICTION_MODE this_mode;
    int num00;
    int mdcounts[4];
    int best_rd = INT_MAX; // 1 << 30;
    int best_intra_rd = INT_MAX;
    int mode_index;
    int rate;
    int rate2;
    int distortion2;
    int bestsme;
    //int all_rds[MAX_MODES];         // Experimental debug code.
    int best_mode_index = 0;
428
    unsigned int sse = INT_MAX, best_sse = INT_MAX;
John Koleszar's avatar
John Koleszar committed
429

Scott LaVarnway's avatar
Scott LaVarnway committed
430
    int_mv mvp;
431 432 433 434
    int near_sadidx[8] = {0, 1, 2, 3, 4, 5, 6, 7};
    int saddone=0;
    int sr=0;    //search range got from mv_pred(). It uses step_param levels. (0-7)

Scott LaVarnway's avatar
Scott LaVarnway committed
435 436 437
    int_mv nearest_mv[4];
    int_mv near_mv[4];
    int_mv frame_best_ref_mv[4];
John Koleszar's avatar
John Koleszar committed
438 439 440 441
    int MDCounts[4][4];
    unsigned char *y_buffer[4];
    unsigned char *u_buffer[4];
    unsigned char *v_buffer[4];
442 443
    int i;
    int ref_frame_map[4];
John Koleszar's avatar
John Koleszar committed
444

Alpha Lam's avatar
Alpha Lam committed
445
    int found_near_mvs[4] = {0, 0, 0, 0};
John Koleszar's avatar
John Koleszar committed
446

447 448
    int have_subp_search = cpi->sf.half_pixel_search;  /* In real-time mode, when Speed >= 15, no sub-pixel search. */

John Koleszar's avatar
John Koleszar committed
449 450 451
    vpx_memset(mode_mv, 0, sizeof(mode_mv));
    vpx_memset(nearest_mv, 0, sizeof(nearest_mv));
    vpx_memset(near_mv, 0, sizeof(near_mv));
452
    vpx_memset(&best_mbmode, 0, sizeof(best_mbmode));
John Koleszar's avatar
John Koleszar committed
453

454 455 456 457 458 459 460 461 462 463 464
    /* Setup search priorities */
    i=0;
    ref_frame_map[i++] = INTRA_FRAME;
    if (cpi->ref_frame_flags & VP8_LAST_FLAG)
        ref_frame_map[i++] = LAST_FRAME;
    if (cpi->ref_frame_flags & VP8_GOLD_FLAG)
        ref_frame_map[i++] = GOLDEN_FRAME;
    if (cpi->ref_frame_flags & VP8_ALT_FLAG) // &&(cpi->source_alt_ref_active || cpi->oxcf.number_of_layers > 1)
        ref_frame_map[i++] = ALTREF_FRAME;
    for(; i<4; i++)
        ref_frame_map[i] = -1;
John Koleszar's avatar
John Koleszar committed
465 466 467 468

    // set up all the refframe dependent pointers.
    if (cpi->ref_frame_flags & VP8_LAST_FLAG)
    {
469 470 471 472
        YV12_BUFFER_CONFIG *lst_yv12 = &cpi->common.yv12_fb[cpi->common.lst_fb_idx];
        y_buffer[LAST_FRAME] = lst_yv12->y_buffer + recon_yoffset;
        u_buffer[LAST_FRAME] = lst_yv12->u_buffer + recon_uvoffset;
        v_buffer[LAST_FRAME] = lst_yv12->v_buffer + recon_uvoffset;
John Koleszar's avatar
John Koleszar committed
473 474 475 476
    }

    if (cpi->ref_frame_flags & VP8_GOLD_FLAG)
    {
477 478 479 480
        YV12_BUFFER_CONFIG *gld_yv12 = &cpi->common.yv12_fb[cpi->common.gld_fb_idx];
        y_buffer[GOLDEN_FRAME] = gld_yv12->y_buffer + recon_yoffset;
        u_buffer[GOLDEN_FRAME] = gld_yv12->u_buffer + recon_uvoffset;
        v_buffer[GOLDEN_FRAME] = gld_yv12->v_buffer + recon_uvoffset;
John Koleszar's avatar
John Koleszar committed
481 482
    }

483
    if (cpi->ref_frame_flags & VP8_ALT_FLAG)
John Koleszar's avatar
John Koleszar committed
484
    {
485 486 487 488
        YV12_BUFFER_CONFIG *alt_yv12 = &cpi->common.yv12_fb[cpi->common.alt_fb_idx];
        y_buffer[ALTREF_FRAME] = alt_yv12->y_buffer + recon_yoffset;
        u_buffer[ALTREF_FRAME] = alt_yv12->u_buffer + recon_uvoffset;
        v_buffer[ALTREF_FRAME] = alt_yv12->v_buffer + recon_uvoffset;
John Koleszar's avatar
John Koleszar committed
489 490 491 492
    }

    cpi->mbs_tested_so_far++;          // Count of the number of MBs tested so far this frame

Paul Wilkins's avatar
Paul Wilkins committed
493
    *returnintra = INT_MAX;
John Koleszar's avatar
John Koleszar committed
494 495
    x->skip = 0;

496
    x->e_mbd.mode_info_context->mbmi.ref_frame = INTRA_FRAME;
John Koleszar's avatar
John Koleszar committed
497 498 499 500 501 502 503

    // if we encode a new mv this is important
    // find the best new motion vector
    for (mode_index = 0; mode_index < MAX_MODES; mode_index++)
    {
        int frame_cost;
        int this_rd = INT_MAX;
504
        int this_ref_frame = ref_frame_map[vp8_ref_frame_order[mode_index]];
John Koleszar's avatar
John Koleszar committed
505 506 507 508

        if (best_rd <= cpi->rd_threshes[mode_index])
            continue;

509
        if (this_ref_frame < 0)
John Koleszar's avatar
John Koleszar committed
510 511
            continue;

512 513 514
        x->e_mbd.mode_info_context->mbmi.ref_frame = this_ref_frame;


John Koleszar's avatar
John Koleszar committed
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
        // Check to see if the testing frequency for this mode is at its max
        // If so then prevent it from being tested and increase the threshold for its testing
        if (cpi->mode_test_hit_counts[mode_index] && (cpi->mode_check_freq[mode_index] > 1))
        {
            //if ( (cpi->mbs_tested_so_far / cpi->mode_test_hit_counts[mode_index]) <= cpi->mode_check_freq[mode_index] )
            if (cpi->mbs_tested_so_far <= (cpi->mode_check_freq[mode_index] * cpi->mode_test_hit_counts[mode_index]))
            {
                // Increase the threshold for coding this mode to make it less likely to be chosen
                cpi->rd_thresh_mult[mode_index] += 4;

                if (cpi->rd_thresh_mult[mode_index] > MAX_THRESHMULT)
                    cpi->rd_thresh_mult[mode_index] = MAX_THRESHMULT;

                cpi->rd_threshes[mode_index] = (cpi->rd_baseline_thresh[mode_index] >> 7) * cpi->rd_thresh_mult[mode_index];

                continue;
            }
        }

Alpha Lam's avatar
Alpha Lam committed
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548
        // If nearby MVs haven't been found for this reference frame then do it now.
        if (x->e_mbd.mode_info_context->mbmi.ref_frame != INTRA_FRAME &&
            !found_near_mvs[x->e_mbd.mode_info_context->mbmi.ref_frame])
        {
            int ref_frame = x->e_mbd.mode_info_context->mbmi.ref_frame;
            vp8_find_near_mvs(&x->e_mbd,
                              x->e_mbd.mode_info_context,
                              &nearest_mv[ref_frame], &near_mv[ref_frame],
                              &frame_best_ref_mv[ref_frame],
                              MDCounts[ref_frame],
                              ref_frame,
                              cpi->common.ref_frame_sign_bias);
            found_near_mvs[ref_frame] = 1;
        }

John Koleszar's avatar
John Koleszar committed
549 550 551 552 553 554 555
        // We have now reached the point where we are going to test the current mode so increment the counter for the number of times it has been tested
        cpi->mode_test_hit_counts[mode_index] ++;

        rate2 = 0;
        distortion2 = 0;

        this_mode = vp8_mode_order[mode_index];
556

John Koleszar's avatar
John Koleszar committed
557 558 559
        // Experimental debug code.
        //all_rds[mode_index] = -1;

560 561
        x->e_mbd.mode_info_context->mbmi.mode = this_mode;
        x->e_mbd.mode_info_context->mbmi.uv_mode = DC_PRED;
John Koleszar's avatar
John Koleszar committed
562 563

        // Work out the cost assosciated with selecting the reference frame
564 565
        frame_cost =
            x->e_mbd.ref_frame_cost[x->e_mbd.mode_info_context->mbmi.ref_frame];
John Koleszar's avatar
John Koleszar committed
566 567 568
        rate2 += frame_cost;

        // everything but intra
569
        if (x->e_mbd.mode_info_context->mbmi.ref_frame)
John Koleszar's avatar
John Koleszar committed
570
        {
571 572 573 574 575
            x->e_mbd.pre.y_buffer = y_buffer[x->e_mbd.mode_info_context->mbmi.ref_frame];
            x->e_mbd.pre.u_buffer = u_buffer[x->e_mbd.mode_info_context->mbmi.ref_frame];
            x->e_mbd.pre.v_buffer = v_buffer[x->e_mbd.mode_info_context->mbmi.ref_frame];
            mode_mv[NEARESTMV] = nearest_mv[x->e_mbd.mode_info_context->mbmi.ref_frame];
            mode_mv[NEARMV] = near_mv[x->e_mbd.mode_info_context->mbmi.ref_frame];
576
            best_ref_mv = frame_best_ref_mv[x->e_mbd.mode_info_context->mbmi.ref_frame];
577
            memcpy(mdcounts, MDCounts[x->e_mbd.mode_info_context->mbmi.ref_frame], sizeof(mdcounts));
John Koleszar's avatar
John Koleszar committed
578 579
        }

580 581 582 583
        // Only consider ZEROMV/ALTREF_FRAME for alt ref frame,
        // unless ARNR filtering is enabled in which case we want
        // an unfiltered alternative
        if (cpi->is_src_frame_alt_ref && (cpi->oxcf.arnr_max_frames == 0))
John Koleszar's avatar
John Koleszar committed
584
        {
585
            if (this_mode != ZEROMV || x->e_mbd.mode_info_context->mbmi.ref_frame != ALTREF_FRAME)
John Koleszar's avatar
John Koleszar committed
586 587 588 589 590 591
                continue;
        }

        switch (this_mode)
        {
        case B_PRED:
592
            // Pass best so far to pick_intra4x4mby_modes to use as breakout
593
            distortion2 = best_sse;
594
            pick_intra4x4mby_modes(IF_RTCD(&cpi->rtcd), x, &rate, &distortion2);
John Koleszar's avatar
John Koleszar committed
595 596 597 598 599 600 601

            if (distortion2 == INT_MAX)
            {
                this_rd = INT_MAX;
            }
            else
            {
602 603
                rate2 += rate;
                distortion2 = VARIANCE_INVOKE
604
                                (&cpi->rtcd.variance, var16x16)(
605
                                    *(b->base_src), b->src_stride,
606
                                    x->e_mbd.predictor, 16, &sse);
Yunqing Wang's avatar
Yunqing Wang committed
607
                this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2);
John Koleszar's avatar
John Koleszar committed
608 609 610 611

                if (this_rd < best_intra_rd)
                {
                    best_intra_rd = this_rd;
Paul Wilkins's avatar
Paul Wilkins committed
612
                    *returnintra = distortion2;
John Koleszar's avatar
John Koleszar committed
613 614 615 616 617 618 619 620 621 622 623 624 625 626
                }
            }

            break;

        case SPLITMV:

            // Split MV modes currently not supported when RD is nopt enabled.
            break;

        case DC_PRED:
        case V_PRED:
        case H_PRED:
        case TM_PRED:
627 628
            RECON_INVOKE(&cpi->common.rtcd.recon, build_intra_predictors_mby)
                (&x->e_mbd);
629
            distortion2 = VARIANCE_INVOKE(&cpi->rtcd.variance, var16x16)
630
                                          (*(b->base_src), b->src_stride,
631
                                          x->e_mbd.predictor, 16, &sse);
632
            rate2 += x->mbmode_cost[x->e_mbd.frame_type][x->e_mbd.mode_info_context->mbmi.mode];
Yunqing Wang's avatar
Yunqing Wang committed
633
            this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2);
John Koleszar's avatar
John Koleszar committed
634 635 636 637

            if (this_rd < best_intra_rd)
            {
                best_intra_rd = this_rd;
Paul Wilkins's avatar
Paul Wilkins committed
638
                *returnintra = distortion2;
John Koleszar's avatar
John Koleszar committed
639 640 641 642 643 644 645 646 647
            }
            break;

        case NEWMV:
        {
            int thissme;
            int step_param;
            int further_steps;
            int n = 0;
648
            int sadpb = x->sadperbit16;
649
            int_mv mvp_full;
John Koleszar's avatar
John Koleszar committed
650

651 652 653 654
            int col_min = (best_ref_mv.as_mv.col>>3) - MAX_FULL_PEL_VAL + ((best_ref_mv.as_mv.col & 7)?1:0);
            int row_min = (best_ref_mv.as_mv.row>>3) - MAX_FULL_PEL_VAL + ((best_ref_mv.as_mv.row & 7)?1:0);
            int col_max = (best_ref_mv.as_mv.col>>3) + MAX_FULL_PEL_VAL;
            int row_max = (best_ref_mv.as_mv.row>>3) + MAX_FULL_PEL_VAL;
655 656 657 658 659 660

            int tmp_col_min = x->mv_col_min;
            int tmp_col_max = x->mv_col_max;
            int tmp_row_min = x->mv_row_min;
            int tmp_row_max = x->mv_row_max;

661
            int speed_adjust = (cpi->Speed > 5) ? ((cpi->Speed >= 8)? 3 : 2) : 1;
John Koleszar's avatar
John Koleszar committed
662

663
            // Further step/diamond searches as necessary
664 665 666
            step_param = cpi->sf.first_step + speed_adjust;

            if(cpi->sf.improved_mv_pred)
John Koleszar's avatar
John Koleszar committed
667
            {
668 669 670 671 672 673 674 675 676
                if(!saddone)
                {
                    vp8_cal_sad(cpi,xd,x, recon_yoffset ,&near_sadidx[0] );
                    saddone = 1;
                }

                vp8_mv_pred(cpi, &x->e_mbd, x->e_mbd.mode_info_context, &mvp,
                            x->e_mbd.mode_info_context->mbmi.ref_frame, cpi->common.ref_frame_sign_bias, &sr, &near_sadidx[0]);

677 678 679 680
                sr += speed_adjust;
                //adjust search range according to sr from mv prediction
                if(sr > step_param)
                    step_param = sr;
681 682 683 684

                mvp_full.as_mv.col = mvp.as_mv.col>>3;
                mvp_full.as_mv.row = mvp.as_mv.row>>3;

685 686
            }else
            {
Scott LaVarnway's avatar
Scott LaVarnway committed
687
                mvp.as_int = best_ref_mv.as_int;
688 689
                mvp_full.as_mv.col = best_ref_mv.as_mv.col>>3;
                mvp_full.as_mv.row = best_ref_mv.as_mv.row>>3;
John Koleszar's avatar
John Koleszar committed
690 691
            }

692 693 694 695 696 697 698 699 700 701
            // Get intersection of UMV window and valid MV window to reduce # of checks in diamond search.
            if (x->mv_col_min < col_min )
                x->mv_col_min = col_min;
            if (x->mv_col_max > col_max )
                x->mv_col_max = col_max;
            if (x->mv_row_min < row_min )
                x->mv_row_min = row_min;
            if (x->mv_row_max > row_max )
                x->mv_row_max = row_max;

702 703
            further_steps = (cpi->Speed >= 8)? 0: (cpi->sf.max_step_search_steps - 1 - step_param);

John Koleszar's avatar
John Koleszar committed
704 705
            if (cpi->sf.search_method == HEX)
            {
Yunqing Wang's avatar
Yunqing Wang committed
706 707 708 709 710 711 712 713
#if CONFIG_MULTI_RES_ENCODING
                /* TODO: In higher-res pick_inter_mode, step_param is used to
                 * modify hex search range. Here, set step_param to 0 not to
                 * change the behavior in lowest-resolution encoder.
                 * Will improve it later.
                 */
                step_param = 0;
#endif
714
                bestsme = vp8_hex_search(x, b, d, &mvp_full, &d->bmi.mv, step_param,
715
                                      sadpb, &cpi->fn_ptr[BLOCK_16X16],
716
                                      x->mvsadcost, x->mvcost, &best_ref_mv);
Scott LaVarnway's avatar
Scott LaVarnway committed
717
                mode_mv[NEWMV].as_int = d->bmi.mv.as_int;
John Koleszar's avatar
John Koleszar committed
718 719 720
            }
            else
            {
721
                bestsme = cpi->diamond_search_sad(x, b, d, &mvp_full, &d->bmi.mv,
722 723 724
                                      step_param, sadpb, &num00,
                                      &cpi->fn_ptr[BLOCK_16X16],
                                      x->mvcost, &best_ref_mv);
Scott LaVarnway's avatar
Scott LaVarnway committed
725
                mode_mv[NEWMV].as_int = d->bmi.mv.as_int;
John Koleszar's avatar
John Koleszar committed
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741

                // Further step/diamond searches as necessary
                n = 0;
                //further_steps = (cpi->sf.max_step_search_steps - 1) - step_param;

                n = num00;
                num00 = 0;

                while (n < further_steps)
                {
                    n++;

                    if (num00)
                        num00--;
                    else
                    {
Scott LaVarnway's avatar
Scott LaVarnway committed
742
                        thissme =
743
                        cpi->diamond_search_sad(x, b, d, &mvp_full,
Scott LaVarnway's avatar
Scott LaVarnway committed
744 745
                                                &d->bmi.mv,
                                                step_param + n,
746
                                                sadpb, &num00,
Scott LaVarnway's avatar
Scott LaVarnway committed
747 748
                                                &cpi->fn_ptr[BLOCK_16X16],
                                                x->mvcost, &best_ref_mv);
John Koleszar's avatar
John Koleszar committed
749 750 751
                        if (thissme < bestsme)
                        {
                            bestsme = thissme;
Scott LaVarnway's avatar
Scott LaVarnway committed
752
                            mode_mv[NEWMV].as_int = d->bmi.mv.as_int;
John Koleszar's avatar
John Koleszar committed
753 754 755
                        }
                        else
                        {
Scott LaVarnway's avatar
Scott LaVarnway committed
756
                            d->bmi.mv.as_int = mode_mv[NEWMV].as_int;
John Koleszar's avatar
John Koleszar committed
757 758 759 760 761
                        }
                    }
                }
            }

762 763 764 765
            x->mv_col_min = tmp_col_min;
            x->mv_col_max = tmp_col_max;
            x->mv_row_min = tmp_row_min;
            x->mv_row_max = tmp_row_max;
John Koleszar's avatar
John Koleszar committed
766

767
            if (bestsme < INT_MAX)
768 769 770 771 772
                cpi->find_fractional_mv_step(x, b, d, &d->bmi.mv, &best_ref_mv,
                                             x->errorperbit,
                                             &cpi->fn_ptr[BLOCK_16X16],
                                             cpi->mb.mvcost,
                                             &distortion2,&sse);
John Koleszar's avatar
John Koleszar committed
773

Scott LaVarnway's avatar
Scott LaVarnway committed
774
            mode_mv[NEWMV].as_int = d->bmi.mv.as_int;
John Koleszar's avatar
John Koleszar committed
775

776 777 778
            // mv cost;
            rate2 += vp8_mv_bit_cost(&mode_mv[NEWMV], &best_ref_mv, cpi->mb.mvcost, 128);
        }
John Koleszar's avatar
John Koleszar committed
779 780 781 782

        case NEARESTMV:
        case NEARMV:

Scott LaVarnway's avatar
Scott LaVarnway committed
783
            if (mode_mv[this_mode].as_int == 0)
John Koleszar's avatar
John Koleszar committed
784 785 786 787 788 789 790
                continue;

        case ZEROMV:

            // Trap vectors that reach beyond the UMV borders
            // Note that ALL New MV, Nearest MV Near MV and Zero MV code drops through to this point
            // because of the lack of break statements in the previous two cases.
Scott LaVarnway's avatar
Scott LaVarnway committed
791 792
            if (((mode_mv[this_mode].as_mv.row >> 3) < x->mv_row_min) || ((mode_mv[this_mode].as_mv.row >> 3) > x->mv_row_max) ||
                ((mode_mv[this_mode].as_mv.col >> 3) < x->mv_col_min) || ((mode_mv[this_mode].as_mv.col >> 3) > x->mv_col_max))
John Koleszar's avatar
John Koleszar committed
793 794 795
                continue;

            rate2 += vp8_cost_mv_ref(this_mode, mdcounts);
796 797
            x->e_mbd.mode_info_context->mbmi.mv.as_int =
                                                    mode_mv[this_mode].as_int;
John Koleszar's avatar
John Koleszar committed
798

799 800 801 802 803 804 805 806 807
            /* Exit early and don't compute the distortion if this macroblock is marked inactive. */
            if (cpi->active_map_enabled && x->active_ptr[0] == 0)
            {
                sse = 0;
                distortion2 = 0;
                x->skip = 1;
                break;
            }

808 809 810 811 812
            if((this_mode != NEWMV) ||
                !(have_subp_search) || cpi->common.full_pixel==1)
                distortion2 = get_inter_mbpred_error(x,
                                                     &cpi->fn_ptr[BLOCK_16X16],
                                                     &sse, mode_mv[this_mode]);
John Koleszar's avatar
John Koleszar committed
813

Yunqing Wang's avatar
Yunqing Wang committed
814
            this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2);
John Koleszar's avatar
John Koleszar committed
815

816
            if (sse < x->encode_breakout)
John Koleszar's avatar
John Koleszar committed
817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843
            {
                // Check u and v to make sure skip is ok
                int sse2 = 0;

                sse2 = VP8_UVSSE(x, IF_RTCD(&cpi->rtcd.variance));

                if (sse2 * 2 < x->encode_breakout)
                    x->skip = 1;
                else
                    x->skip = 0;
            }

            break;
        default:
            break;
        }

        // Experimental debug code.
        //all_rds[mode_index] = this_rd;

        if (this_rd < best_rd || x->skip)
        {
            // Note index of best mode
            best_mode_index = mode_index;

            *returnrate = rate2;
            *returndistortion = distortion2;
844
            best_sse = sse;
John Koleszar's avatar
John Koleszar committed
845
            best_rd = this_rd;
846
            vpx_memcpy(&best_mbmode, &x->e_mbd.mode_info_context->mbmi, sizeof(MB_MODE_INFO));
John Koleszar's avatar
John Koleszar committed
847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888

            // Testing this mode gave rise to an improvement in best error score. Lower threshold a bit for next time
            cpi->rd_thresh_mult[mode_index] = (cpi->rd_thresh_mult[mode_index] >= (MIN_THRESHMULT + 2)) ? cpi->rd_thresh_mult[mode_index] - 2 : MIN_THRESHMULT;
            cpi->rd_threshes[mode_index] = (cpi->rd_baseline_thresh[mode_index] >> 7) * cpi->rd_thresh_mult[mode_index];
        }

        // If the mode did not help improve the best error case then raise the threshold for testing that mode next time around.
        else
        {
            cpi->rd_thresh_mult[mode_index] += 4;

            if (cpi->rd_thresh_mult[mode_index] > MAX_THRESHMULT)
                cpi->rd_thresh_mult[mode_index] = MAX_THRESHMULT;

            cpi->rd_threshes[mode_index] = (cpi->rd_baseline_thresh[mode_index] >> 7) * cpi->rd_thresh_mult[mode_index];
        }

        if (x->skip)
            break;
    }

    // Reduce the activation RD thresholds for the best choice mode
    if ((cpi->rd_baseline_thresh[best_mode_index] > 0) && (cpi->rd_baseline_thresh[best_mode_index] < (INT_MAX >> 2)))
    {
        int best_adjustment = (cpi->rd_thresh_mult[best_mode_index] >> 3);

        cpi->rd_thresh_mult[best_mode_index] = (cpi->rd_thresh_mult[best_mode_index] >= (MIN_THRESHMULT + best_adjustment)) ? cpi->rd_thresh_mult[best_mode_index] - best_adjustment : MIN_THRESHMULT;
        cpi->rd_threshes[best_mode_index] = (cpi->rd_baseline_thresh[best_mode_index] >> 7) * cpi->rd_thresh_mult[best_mode_index];
    }


    {
        int this_rdbin = (*returndistortion >> 7);

        if (this_rdbin >= 1024)
        {
            this_rdbin = 1023;
        }

        cpi->error_bins[this_rdbin] ++;
    }

889 890
    if (cpi->is_src_frame_alt_ref &&
        (best_mbmode.mode != ZEROMV || best_mbmode.ref_frame != ALTREF_FRAME))
John Koleszar's avatar
John Koleszar committed
891
    {
892 893
        x->e_mbd.mode_info_context->mbmi.mode = ZEROMV;
        x->e_mbd.mode_info_context->mbmi.ref_frame = ALTREF_FRAME;
894
        x->e_mbd.mode_info_context->mbmi.mv.as_int = 0;
895 896 897 898 899
        x->e_mbd.mode_info_context->mbmi.uv_mode = DC_PRED;
        x->e_mbd.mode_info_context->mbmi.mb_skip_coeff =
                                        (cpi->common.mb_no_coeff_skip) ? 1 : 0;
        x->e_mbd.mode_info_context->mbmi.partitioning = 0;

900
        return;
John Koleszar's avatar
John Koleszar committed
901 902
    }

Alpha Lam's avatar
Alpha Lam committed
903 904 905
    /* set to the best mb mode, this copy can be skip if x->skip since it already has the right content */
    if (!x->skip)
        vpx_memcpy(&x->e_mbd.mode_info_context->mbmi, &best_mbmode, sizeof(MB_MODE_INFO));
John Koleszar's avatar
John Koleszar committed
906

907 908 909
    if (best_mbmode.mode <= B_PRED)
    {
        /* set mode_info_context->mbmi.uv_mode */
910
        pick_intra_mbuv_mode(x);
911
    }
Scott LaVarnway's avatar
Scott LaVarnway committed
912

913
    update_mvcount(cpi, &x->e_mbd, &frame_best_ref_mv[xd->mode_info_context->mbmi.ref_frame]);
John Koleszar's avatar
John Koleszar committed
914
}
915 916 917 918 919


void vp8_pick_intra_mode(VP8_COMP *cpi, MACROBLOCK *x, int *rate_)
{
    int error4x4, error16x16 = INT_MAX;
920
    int rate, best_rate = 0, distortion, best_sse;
921 922
    MB_PREDICTION_MODE mode, best_mode = DC_PRED;
    int this_rd;
923
    unsigned int sse;
924
    BLOCK *b = &x->block[0];
925

926 927
    x->e_mbd.mode_info_context->mbmi.ref_frame = INTRA_FRAME;

928 929 930 931 932 933 934
    pick_intra_mbuv_mode(x);

    for (mode = DC_PRED; mode <= TM_PRED; mode ++)
    {
        x->e_mbd.mode_info_context->mbmi.mode = mode;
        RECON_INVOKE(&cpi->common.rtcd.recon, build_intra_predictors_mby)
            (&x->e_mbd);
935
        distortion = VARIANCE_INVOKE(&cpi->rtcd.variance, var16x16)
936
            (*(b->base_src), b->src_stride, x->e_mbd.predictor, 16, &sse);
937 938 939 940 941 942 943
        rate = x->mbmode_cost[x->e_mbd.frame_type][mode];
        this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion);

        if (error16x16 > this_rd)
        {
            error16x16 = this_rd;
            best_mode = mode;
944
            best_sse = sse;
945
            best_rate = rate;
946 947 948 949 950
        }
    }
    x->e_mbd.mode_info_context->mbmi.mode = best_mode;

    error4x4 = pick_intra4x4mby_modes(IF_RTCD(&cpi->rtcd), x, &rate,
951
                                      &best_sse);
952
    if (error4x4 < error16x16)
953
    {
954
        x->e_mbd.mode_info_context->mbmi.mode = B_PRED;
955 956
        best_rate = rate;
    }
957

958
    *rate_ = best_rate;
959
}
Yunqing Wang's avatar
Yunqing Wang committed
960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1