Home | History | Annotate | Download | only in common
      1 /*
      2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
      3  *
      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
      6  *  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.
      9  */
     10 
     11 
     12 #include "vpx_ports/config.h"
     13 #include "blockd.h"
     14 #include "vpx_mem/vpx_mem.h"
     15 #include "onyxc_int.h"
     16 #include "findnearmv.h"
     17 #include "entropymode.h"
     18 #include "systemdependent.h"
     19 
     20 
     21 extern  void vp8_init_scan_order_mask();
     22 
     23 static void update_mode_info_border(MODE_INFO *mi, int rows, int cols)
     24 {
     25     int i;
     26     vpx_memset(mi - cols - 2, 0, sizeof(MODE_INFO) * (cols + 1));
     27 
     28     for (i = 0; i < rows; i++)
     29     {
     30         vpx_memset(&mi[i*cols-1], 0, sizeof(MODE_INFO));
     31     }
     32 }
     33 
     34 void vp8_de_alloc_frame_buffers(VP8_COMMON *oci)
     35 {
     36     int i;
     37 
     38     for (i = 0; i < NUM_YV12_BUFFERS; i++)
     39         vp8_yv12_de_alloc_frame_buffer(&oci->yv12_fb[i]);
     40 
     41     vp8_yv12_de_alloc_frame_buffer(&oci->temp_scale_frame);
     42     vp8_yv12_de_alloc_frame_buffer(&oci->post_proc_buffer);
     43 
     44     vpx_free(oci->above_context);
     45     vpx_free(oci->mip);
     46 
     47     oci->above_context = 0;
     48     oci->mip = 0;
     49 
     50 }
     51 
     52 int vp8_alloc_frame_buffers(VP8_COMMON *oci, int width, int height)
     53 {
     54     int i;
     55 
     56     vp8_de_alloc_frame_buffers(oci);
     57 
     58     /* our internal buffers are always multiples of 16 */
     59     if ((width & 0xf) != 0)
     60         width += 16 - (width & 0xf);
     61 
     62     if ((height & 0xf) != 0)
     63         height += 16 - (height & 0xf);
     64 
     65 
     66     for (i = 0; i < NUM_YV12_BUFFERS; i++)
     67     {
     68       oci->fb_idx_ref_cnt[0] = 0;
     69 
     70       if (vp8_yv12_alloc_frame_buffer(&oci->yv12_fb[i],  width, height, VP8BORDERINPIXELS) < 0)
     71         {
     72             vp8_de_alloc_frame_buffers(oci);
     73             return 1;
     74         }
     75     }
     76 
     77     oci->new_fb_idx = 0;
     78     oci->lst_fb_idx = 1;
     79     oci->gld_fb_idx = 2;
     80     oci->alt_fb_idx = 3;
     81 
     82     oci->fb_idx_ref_cnt[0] = 1;
     83     oci->fb_idx_ref_cnt[1] = 1;
     84     oci->fb_idx_ref_cnt[2] = 1;
     85     oci->fb_idx_ref_cnt[3] = 1;
     86 
     87     if (vp8_yv12_alloc_frame_buffer(&oci->temp_scale_frame,   width, 16, VP8BORDERINPIXELS) < 0)
     88     {
     89         vp8_de_alloc_frame_buffers(oci);
     90         return 1;
     91     }
     92 
     93     if (vp8_yv12_alloc_frame_buffer(&oci->post_proc_buffer, width, height, VP8BORDERINPIXELS) < 0)
     94     {
     95         vp8_de_alloc_frame_buffers(oci);
     96         return 1;
     97     }
     98 
     99     oci->mb_rows = height >> 4;
    100     oci->mb_cols = width >> 4;
    101     oci->MBs = oci->mb_rows * oci->mb_cols;
    102     oci->mode_info_stride = oci->mb_cols + 1;
    103     oci->mip = vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO));
    104 
    105     if (!oci->mip)
    106     {
    107         vp8_de_alloc_frame_buffers(oci);
    108         return 1;
    109     }
    110 
    111     oci->mi = oci->mip + oci->mode_info_stride + 1;
    112 
    113 
    114     oci->above_context = vpx_calloc(sizeof(ENTROPY_CONTEXT_PLANES) * oci->mb_cols, 1);
    115 
    116     if (!oci->above_context)
    117     {
    118         vp8_de_alloc_frame_buffers(oci);
    119         return 1;
    120     }
    121 
    122     update_mode_info_border(oci->mi, oci->mb_rows, oci->mb_cols);
    123 
    124     return 0;
    125 }
    126 void vp8_setup_version(VP8_COMMON *cm)
    127 {
    128     switch (cm->version)
    129     {
    130     case 0:
    131         cm->no_lpf = 0;
    132         cm->simpler_lpf = 0;
    133         cm->use_bilinear_mc_filter = 0;
    134         cm->full_pixel = 0;
    135         break;
    136     case 1:
    137         cm->no_lpf = 0;
    138         cm->simpler_lpf = 1;
    139         cm->use_bilinear_mc_filter = 1;
    140         cm->full_pixel = 0;
    141         break;
    142     case 2:
    143         cm->no_lpf = 1;
    144         cm->simpler_lpf = 0;
    145         cm->use_bilinear_mc_filter = 1;
    146         cm->full_pixel = 0;
    147         break;
    148     case 3:
    149         cm->no_lpf = 1;
    150         cm->simpler_lpf = 1;
    151         cm->use_bilinear_mc_filter = 1;
    152         cm->full_pixel = 1;
    153         break;
    154     default:
    155         /*4,5,6,7 are reserved for future use*/
    156         cm->no_lpf = 0;
    157         cm->simpler_lpf = 0;
    158         cm->use_bilinear_mc_filter = 0;
    159         cm->full_pixel = 0;
    160         break;
    161     }
    162 }
    163 void vp8_create_common(VP8_COMMON *oci)
    164 {
    165     vp8_machine_specific_config(oci);
    166     vp8_default_coef_probs(oci);
    167     vp8_init_mbmode_probs(oci);
    168     vp8_default_bmode_probs(oci->fc.bmode_prob);
    169 
    170     oci->mb_no_coeff_skip = 1;
    171     oci->no_lpf = 0;
    172     oci->simpler_lpf = 0;
    173     oci->use_bilinear_mc_filter = 0;
    174     oci->full_pixel = 0;
    175     oci->multi_token_partition = ONE_PARTITION;
    176     oci->clr_type = REG_YUV;
    177     oci->clamp_type = RECON_CLAMP_REQUIRED;
    178 
    179     /* Initialise reference frame sign bias structure to defaults */
    180     vpx_memset(oci->ref_frame_sign_bias, 0, sizeof(oci->ref_frame_sign_bias));
    181 
    182     /* Default disable buffer to buffer copying */
    183     oci->copy_buffer_to_gf = 0;
    184     oci->copy_buffer_to_arf = 0;
    185 }
    186 
    187 void vp8_remove_common(VP8_COMMON *oci)
    188 {
    189     vp8_de_alloc_frame_buffers(oci);
    190 }
    191 
    192 void vp8_initialize_common()
    193 {
    194     vp8_coef_tree_initialize();
    195 
    196     vp8_entropy_mode_init();
    197 
    198     vp8_init_scan_order_mask();
    199 
    200 }
    201