Merge "makefile: fix error message due to missing quotes"
[libvpx.git] / vp8 / common / alloccommon.c
blobac110f761171b80ee3d84184a8f40101462244a3
1 /*
2 * Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license and patent
5 * grant that can be found in the LICENSE file in the root of the source
6 * tree. All contributing project authors may be found in the AUTHORS
7 * file in the root of the source tree.
8 */
11 #include "blockd.h"
12 #include "vpx_mem/vpx_mem.h"
13 #include "onyxc_int.h"
14 #include "findnearmv.h"
15 #include "entropymode.h"
16 #include "systemdependent.h"
17 #include "vpxerrors.h"
19 #ifdef HAVE_CONFIG_H
20 #include "vpx_config.h"
21 #endif
23 extern void vp8_init_scan_order_mask();
25 void vp8_update_mode_info_border(MODE_INFO *mi, int rows, int cols)
27 int i;
28 vpx_memset(mi - cols - 1, 0, sizeof(MODE_INFO) * cols + 1);
30 for (i = 0; i < rows; i++)
32 vpx_memset(&mi[i*cols-1], 0, sizeof(MODE_INFO));
35 void vp8_de_alloc_frame_buffers(VP8_COMMON *oci)
37 vp8_yv12_de_alloc_frame_buffer(&oci->temp_scale_frame);
38 vp8_yv12_de_alloc_frame_buffer(&oci->new_frame);
39 vp8_yv12_de_alloc_frame_buffer(&oci->last_frame);
40 vp8_yv12_de_alloc_frame_buffer(&oci->golden_frame);
41 vp8_yv12_de_alloc_frame_buffer(&oci->alt_ref_frame);
42 vp8_yv12_de_alloc_frame_buffer(&oci->post_proc_buffer);
44 vpx_free(oci->above_context[Y1CONTEXT]);
45 vpx_free(oci->above_context[UCONTEXT]);
46 vpx_free(oci->above_context[VCONTEXT]);
47 vpx_free(oci->above_context[Y2CONTEXT]);
48 vpx_free(oci->mip);
50 oci->above_context[Y1CONTEXT] = 0;
51 oci->above_context[UCONTEXT] = 0;
52 oci->above_context[VCONTEXT] = 0;
53 oci->above_context[Y2CONTEXT] = 0;
54 oci->mip = 0;
56 // Structure used to minitor GF useage
57 if (oci->gf_active_flags != 0)
58 vpx_free(oci->gf_active_flags);
60 oci->gf_active_flags = 0;
63 int vp8_alloc_frame_buffers(VP8_COMMON *oci, int width, int height)
65 vp8_de_alloc_frame_buffers(oci);
67 // our internal buffers are always multiples of 16
68 if ((width & 0xf) != 0)
69 width += 16 - (width & 0xf);
71 if ((height & 0xf) != 0)
72 height += 16 - (height & 0xf);
75 if (vp8_yv12_alloc_frame_buffer(&oci->temp_scale_frame, width, 16, VP8BORDERINPIXELS) < 0)
77 vp8_de_alloc_frame_buffers(oci);
78 return ALLOC_FAILURE;
82 if (vp8_yv12_alloc_frame_buffer(&oci->new_frame, width, height, VP8BORDERINPIXELS) < 0)
84 vp8_de_alloc_frame_buffers(oci);
85 return ALLOC_FAILURE;
88 if (vp8_yv12_alloc_frame_buffer(&oci->last_frame, width, height, VP8BORDERINPIXELS) < 0)
90 vp8_de_alloc_frame_buffers(oci);
91 return ALLOC_FAILURE;
94 if (vp8_yv12_alloc_frame_buffer(&oci->golden_frame, width, height, VP8BORDERINPIXELS) < 0)
96 vp8_de_alloc_frame_buffers(oci);
97 return ALLOC_FAILURE;
100 if (vp8_yv12_alloc_frame_buffer(&oci->alt_ref_frame, width, height, VP8BORDERINPIXELS) < 0)
102 vp8_de_alloc_frame_buffers(oci);
103 return ALLOC_FAILURE;
106 if (vp8_yv12_alloc_frame_buffer(&oci->post_proc_buffer, width, height, VP8BORDERINPIXELS) < 0)
108 vp8_de_alloc_frame_buffers(oci);
109 return ALLOC_FAILURE;
112 oci->mb_rows = height >> 4;
113 oci->mb_cols = width >> 4;
114 oci->MBs = oci->mb_rows * oci->mb_cols;
115 oci->mode_info_stride = oci->mb_cols + 1;
116 oci->mip = vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO));
118 if (!oci->mip)
120 vp8_de_alloc_frame_buffers(oci);
121 return ALLOC_FAILURE;
124 oci->mi = oci->mip + oci->mode_info_stride + 1;
127 oci->above_context[Y1CONTEXT] = vpx_calloc(sizeof(ENTROPY_CONTEXT) * oci->mb_cols * 4 , 1);
129 if (!oci->above_context[Y1CONTEXT])
131 vp8_de_alloc_frame_buffers(oci);
132 return ALLOC_FAILURE;
135 oci->above_context[UCONTEXT] = vpx_calloc(sizeof(ENTROPY_CONTEXT) * oci->mb_cols * 2 , 1);
137 if (!oci->above_context[UCONTEXT])
139 vp8_de_alloc_frame_buffers(oci);
140 return ALLOC_FAILURE;
143 oci->above_context[VCONTEXT] = vpx_calloc(sizeof(ENTROPY_CONTEXT) * oci->mb_cols * 2 , 1);
145 if (!oci->above_context[VCONTEXT])
147 vp8_de_alloc_frame_buffers(oci);
148 return ALLOC_FAILURE;
151 oci->above_context[Y2CONTEXT] = vpx_calloc(sizeof(ENTROPY_CONTEXT) * oci->mb_cols , 1);
153 if (!oci->above_context[Y2CONTEXT])
155 vp8_de_alloc_frame_buffers(oci);
156 return ALLOC_FAILURE;
159 vp8_update_mode_info_border(oci->mi, oci->mb_rows, oci->mb_cols);
161 // Structures used to minitor GF usage
162 if (oci->gf_active_flags != 0)
163 vpx_free(oci->gf_active_flags);
165 oci->gf_active_flags = (unsigned char *)vpx_calloc(oci->mb_rows * oci->mb_cols, 1);
167 if (!oci->gf_active_flags)
169 vp8_de_alloc_frame_buffers(oci);
170 return ALLOC_FAILURE;
173 oci->gf_active_count = oci->mb_rows * oci->mb_cols;
175 return 0;
177 void vp8_setup_version(VP8_COMMON *cm)
179 switch (cm->version)
181 case 0:
182 cm->no_lpf = 0;
183 cm->simpler_lpf = 0;
184 cm->use_bilinear_mc_filter = 0;
185 cm->full_pixel = 0;
186 break;
187 case 1:
188 cm->no_lpf = 0;
189 cm->simpler_lpf = 1;
190 cm->use_bilinear_mc_filter = 1;
191 cm->full_pixel = 0;
192 break;
193 case 2:
194 cm->no_lpf = 1;
195 cm->simpler_lpf = 0;
196 cm->use_bilinear_mc_filter = 1;
197 cm->full_pixel = 0;
198 break;
199 case 3:
200 cm->no_lpf = 1;
201 cm->simpler_lpf = 1;
202 cm->use_bilinear_mc_filter = 1;
203 cm->full_pixel = 1;
204 break;
205 default:
206 //4,5,6,7 are reserved for future use
207 cm->no_lpf = 0;
208 cm->simpler_lpf = 0;
209 cm->use_bilinear_mc_filter = 0;
210 cm->full_pixel = 0;
211 break;
214 void vp8_create_common(VP8_COMMON *oci)
216 vp8_machine_specific_config(oci);
217 vp8_default_coef_probs(oci);
218 vp8_init_mbmode_probs(oci);
219 vp8_default_bmode_probs(oci->fc.bmode_prob);
221 oci->mb_no_coeff_skip = 1;
222 oci->no_lpf = 0;
223 oci->simpler_lpf = 0;
224 oci->use_bilinear_mc_filter = 0;
225 oci->full_pixel = 0;
226 oci->multi_token_partition = ONE_PARTITION;
227 oci->clr_type = REG_YUV;
228 oci->clamp_type = RECON_CLAMP_REQUIRED;
230 // Initialise reference frame sign bias structure to defaults
231 vpx_memset(oci->ref_frame_sign_bias, 0, sizeof(oci->ref_frame_sign_bias));
233 // Default disable buffer to buffer copying
234 oci->copy_buffer_to_gf = 0;
235 oci->copy_buffer_to_arf = 0;
238 void vp8_remove_common(VP8_COMMON *oci)
240 vp8_de_alloc_frame_buffers(oci);
243 void vp8_initialize_common()
245 vp8_coef_tree_initialize();
247 vp8_entropy_mode_init();
249 vp8_init_scan_order_mask();