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 "recon.h" 14 #include "vpx_mem/vpx_mem.h" 15 #include "reconintra.h" 16 17 void vp8_predict_intra4x4(BLOCKD *x, 18 int b_mode, 19 unsigned char *predictor) 20 { 21 int i, r, c; 22 23 unsigned char *Above = *(x->base_dst) + x->dst - x->dst_stride; 24 unsigned char Left[4]; 25 unsigned char top_left = Above[-1]; 26 27 Left[0] = (*(x->base_dst))[x->dst - 1]; 28 Left[1] = (*(x->base_dst))[x->dst - 1 + x->dst_stride]; 29 Left[2] = (*(x->base_dst))[x->dst - 1 + 2 * x->dst_stride]; 30 Left[3] = (*(x->base_dst))[x->dst - 1 + 3 * x->dst_stride]; 31 32 switch (b_mode) 33 { 34 case B_DC_PRED: 35 { 36 int expected_dc = 0; 37 38 for (i = 0; i < 4; i++) 39 { 40 expected_dc += Above[i]; 41 expected_dc += Left[i]; 42 } 43 44 expected_dc = (expected_dc + 4) >> 3; 45 46 for (r = 0; r < 4; r++) 47 { 48 for (c = 0; c < 4; c++) 49 { 50 predictor[c] = expected_dc; 51 } 52 53 predictor += 16; 54 } 55 } 56 break; 57 case B_TM_PRED: 58 { 59 /* prediction similar to true_motion prediction */ 60 for (r = 0; r < 4; r++) 61 { 62 for (c = 0; c < 4; c++) 63 { 64 int pred = Above[c] - top_left + Left[r]; 65 66 if (pred < 0) 67 pred = 0; 68 69 if (pred > 255) 70 pred = 255; 71 72 predictor[c] = pred; 73 } 74 75 predictor += 16; 76 } 77 } 78 break; 79 80 case B_VE_PRED: 81 { 82 83 unsigned int ap[4]; 84 ap[0] = (top_left + 2 * Above[0] + Above[1] + 2) >> 2; 85 ap[1] = (Above[0] + 2 * Above[1] + Above[2] + 2) >> 2; 86 ap[2] = (Above[1] + 2 * Above[2] + Above[3] + 2) >> 2; 87 ap[3] = (Above[2] + 2 * Above[3] + Above[4] + 2) >> 2; 88 89 for (r = 0; r < 4; r++) 90 { 91 for (c = 0; c < 4; c++) 92 { 93 94 predictor[c] = ap[c]; 95 } 96 97 predictor += 16; 98 } 99 100 } 101 break; 102 103 104 case B_HE_PRED: 105 { 106 107 unsigned int lp[4]; 108 lp[0] = (top_left + 2 * Left[0] + Left[1] + 2) >> 2; 109 lp[1] = (Left[0] + 2 * Left[1] + Left[2] + 2) >> 2; 110 lp[2] = (Left[1] + 2 * Left[2] + Left[3] + 2) >> 2; 111 lp[3] = (Left[2] + 2 * Left[3] + Left[3] + 2) >> 2; 112 113 for (r = 0; r < 4; r++) 114 { 115 for (c = 0; c < 4; c++) 116 { 117 predictor[c] = lp[r]; 118 } 119 120 predictor += 16; 121 } 122 } 123 break; 124 case B_LD_PRED: 125 { 126 unsigned char *ptr = Above; 127 predictor[0 * 16 + 0] = (ptr[0] + ptr[1] * 2 + ptr[2] + 2) >> 2; 128 predictor[0 * 16 + 1] = 129 predictor[1 * 16 + 0] = (ptr[1] + ptr[2] * 2 + ptr[3] + 2) >> 2; 130 predictor[0 * 16 + 2] = 131 predictor[1 * 16 + 1] = 132 predictor[2 * 16 + 0] = (ptr[2] + ptr[3] * 2 + ptr[4] + 2) >> 2; 133 predictor[0 * 16 + 3] = 134 predictor[1 * 16 + 2] = 135 predictor[2 * 16 + 1] = 136 predictor[3 * 16 + 0] = (ptr[3] + ptr[4] * 2 + ptr[5] + 2) >> 2; 137 predictor[1 * 16 + 3] = 138 predictor[2 * 16 + 2] = 139 predictor[3 * 16 + 1] = (ptr[4] + ptr[5] * 2 + ptr[6] + 2) >> 2; 140 predictor[2 * 16 + 3] = 141 predictor[3 * 16 + 2] = (ptr[5] + ptr[6] * 2 + ptr[7] + 2) >> 2; 142 predictor[3 * 16 + 3] = (ptr[6] + ptr[7] * 2 + ptr[7] + 2) >> 2; 143 144 } 145 break; 146 case B_RD_PRED: 147 { 148 149 unsigned char pp[9]; 150 151 pp[0] = Left[3]; 152 pp[1] = Left[2]; 153 pp[2] = Left[1]; 154 pp[3] = Left[0]; 155 pp[4] = top_left; 156 pp[5] = Above[0]; 157 pp[6] = Above[1]; 158 pp[7] = Above[2]; 159 pp[8] = Above[3]; 160 161 predictor[3 * 16 + 0] = (pp[0] + pp[1] * 2 + pp[2] + 2) >> 2; 162 predictor[3 * 16 + 1] = 163 predictor[2 * 16 + 0] = (pp[1] + pp[2] * 2 + pp[3] + 2) >> 2; 164 predictor[3 * 16 + 2] = 165 predictor[2 * 16 + 1] = 166 predictor[1 * 16 + 0] = (pp[2] + pp[3] * 2 + pp[4] + 2) >> 2; 167 predictor[3 * 16 + 3] = 168 predictor[2 * 16 + 2] = 169 predictor[1 * 16 + 1] = 170 predictor[0 * 16 + 0] = (pp[3] + pp[4] * 2 + pp[5] + 2) >> 2; 171 predictor[2 * 16 + 3] = 172 predictor[1 * 16 + 2] = 173 predictor[0 * 16 + 1] = (pp[4] + pp[5] * 2 + pp[6] + 2) >> 2; 174 predictor[1 * 16 + 3] = 175 predictor[0 * 16 + 2] = (pp[5] + pp[6] * 2 + pp[7] + 2) >> 2; 176 predictor[0 * 16 + 3] = (pp[6] + pp[7] * 2 + pp[8] + 2) >> 2; 177 178 } 179 break; 180 case B_VR_PRED: 181 { 182 183 unsigned char pp[9]; 184 185 pp[0] = Left[3]; 186 pp[1] = Left[2]; 187 pp[2] = Left[1]; 188 pp[3] = Left[0]; 189 pp[4] = top_left; 190 pp[5] = Above[0]; 191 pp[6] = Above[1]; 192 pp[7] = Above[2]; 193 pp[8] = Above[3]; 194 195 196 predictor[3 * 16 + 0] = (pp[1] + pp[2] * 2 + pp[3] + 2) >> 2; 197 predictor[2 * 16 + 0] = (pp[2] + pp[3] * 2 + pp[4] + 2) >> 2; 198 predictor[3 * 16 + 1] = 199 predictor[1 * 16 + 0] = (pp[3] + pp[4] * 2 + pp[5] + 2) >> 2; 200 predictor[2 * 16 + 1] = 201 predictor[0 * 16 + 0] = (pp[4] + pp[5] + 1) >> 1; 202 predictor[3 * 16 + 2] = 203 predictor[1 * 16 + 1] = (pp[4] + pp[5] * 2 + pp[6] + 2) >> 2; 204 predictor[2 * 16 + 2] = 205 predictor[0 * 16 + 1] = (pp[5] + pp[6] + 1) >> 1; 206 predictor[3 * 16 + 3] = 207 predictor[1 * 16 + 2] = (pp[5] + pp[6] * 2 + pp[7] + 2) >> 2; 208 predictor[2 * 16 + 3] = 209 predictor[0 * 16 + 2] = (pp[6] + pp[7] + 1) >> 1; 210 predictor[1 * 16 + 3] = (pp[6] + pp[7] * 2 + pp[8] + 2) >> 2; 211 predictor[0 * 16 + 3] = (pp[7] + pp[8] + 1) >> 1; 212 213 } 214 break; 215 case B_VL_PRED: 216 { 217 218 unsigned char *pp = Above; 219 220 predictor[0 * 16 + 0] = (pp[0] + pp[1] + 1) >> 1; 221 predictor[1 * 16 + 0] = (pp[0] + pp[1] * 2 + pp[2] + 2) >> 2; 222 predictor[2 * 16 + 0] = 223 predictor[0 * 16 + 1] = (pp[1] + pp[2] + 1) >> 1; 224 predictor[1 * 16 + 1] = 225 predictor[3 * 16 + 0] = (pp[1] + pp[2] * 2 + pp[3] + 2) >> 2; 226 predictor[2 * 16 + 1] = 227 predictor[0 * 16 + 2] = (pp[2] + pp[3] + 1) >> 1; 228 predictor[3 * 16 + 1] = 229 predictor[1 * 16 + 2] = (pp[2] + pp[3] * 2 + pp[4] + 2) >> 2; 230 predictor[0 * 16 + 3] = 231 predictor[2 * 16 + 2] = (pp[3] + pp[4] + 1) >> 1; 232 predictor[1 * 16 + 3] = 233 predictor[3 * 16 + 2] = (pp[3] + pp[4] * 2 + pp[5] + 2) >> 2; 234 predictor[2 * 16 + 3] = (pp[4] + pp[5] * 2 + pp[6] + 2) >> 2; 235 predictor[3 * 16 + 3] = (pp[5] + pp[6] * 2 + pp[7] + 2) >> 2; 236 } 237 break; 238 239 case B_HD_PRED: 240 { 241 unsigned char pp[9]; 242 pp[0] = Left[3]; 243 pp[1] = Left[2]; 244 pp[2] = Left[1]; 245 pp[3] = Left[0]; 246 pp[4] = top_left; 247 pp[5] = Above[0]; 248 pp[6] = Above[1]; 249 pp[7] = Above[2]; 250 pp[8] = Above[3]; 251 252 253 predictor[3 * 16 + 0] = (pp[0] + pp[1] + 1) >> 1; 254 predictor[3 * 16 + 1] = (pp[0] + pp[1] * 2 + pp[2] + 2) >> 2; 255 predictor[2 * 16 + 0] = 256 predictor[3 * 16 + 2] = (pp[1] + pp[2] + 1) >> 1; 257 predictor[2 * 16 + 1] = 258 predictor[3 * 16 + 3] = (pp[1] + pp[2] * 2 + pp[3] + 2) >> 2; 259 predictor[2 * 16 + 2] = 260 predictor[1 * 16 + 0] = (pp[2] + pp[3] + 1) >> 1; 261 predictor[2 * 16 + 3] = 262 predictor[1 * 16 + 1] = (pp[2] + pp[3] * 2 + pp[4] + 2) >> 2; 263 predictor[1 * 16 + 2] = 264 predictor[0 * 16 + 0] = (pp[3] + pp[4] + 1) >> 1; 265 predictor[1 * 16 + 3] = 266 predictor[0 * 16 + 1] = (pp[3] + pp[4] * 2 + pp[5] + 2) >> 2; 267 predictor[0 * 16 + 2] = (pp[4] + pp[5] * 2 + pp[6] + 2) >> 2; 268 predictor[0 * 16 + 3] = (pp[5] + pp[6] * 2 + pp[7] + 2) >> 2; 269 } 270 break; 271 272 273 case B_HU_PRED: 274 { 275 unsigned char *pp = Left; 276 predictor[0 * 16 + 0] = (pp[0] + pp[1] + 1) >> 1; 277 predictor[0 * 16 + 1] = (pp[0] + pp[1] * 2 + pp[2] + 2) >> 2; 278 predictor[0 * 16 + 2] = 279 predictor[1 * 16 + 0] = (pp[1] + pp[2] + 1) >> 1; 280 predictor[0 * 16 + 3] = 281 predictor[1 * 16 + 1] = (pp[1] + pp[2] * 2 + pp[3] + 2) >> 2; 282 predictor[1 * 16 + 2] = 283 predictor[2 * 16 + 0] = (pp[2] + pp[3] + 1) >> 1; 284 predictor[1 * 16 + 3] = 285 predictor[2 * 16 + 1] = (pp[2] + pp[3] * 2 + pp[3] + 2) >> 2; 286 predictor[2 * 16 + 2] = 287 predictor[2 * 16 + 3] = 288 predictor[3 * 16 + 0] = 289 predictor[3 * 16 + 1] = 290 predictor[3 * 16 + 2] = 291 predictor[3 * 16 + 3] = pp[3]; 292 } 293 break; 294 295 296 } 297 } 298 /* copy 4 bytes from the above right down so that the 4x4 prediction modes using pixels above and 299 * to the right prediction have filled in pixels to use. 300 */ 301 void vp8_intra_prediction_down_copy(MACROBLOCKD *x) 302 { 303 unsigned char *above_right = *(x->block[0].base_dst) + x->block[0].dst - x->block[0].dst_stride + 16; 304 305 unsigned int *src_ptr = (unsigned int *)above_right; 306 unsigned int *dst_ptr0 = (unsigned int *)(above_right + 4 * x->block[0].dst_stride); 307 unsigned int *dst_ptr1 = (unsigned int *)(above_right + 8 * x->block[0].dst_stride); 308 unsigned int *dst_ptr2 = (unsigned int *)(above_right + 12 * x->block[0].dst_stride); 309 310 *dst_ptr0 = *src_ptr; 311 *dst_ptr1 = *src_ptr; 312 *dst_ptr2 = *src_ptr; 313 } 314 315 316