00001
00017 #include "global.h"
00018 #include "intra16x16_pred.h"
00019 #include "mb_access.h"
00020 #include "image.h"
00021
00032 static inline int intra16x16_dc_pred(Macroblock *currMB,
00033 ColorPlane pl)
00034 {
00035 Slice *currSlice = currMB->p_Slice;
00036 ImageParameters *p_Img = currMB->p_Img;
00037
00038 int s0 = 0, s1 = 0, s2 = 0;
00039
00040 int i,j;
00041
00042 imgpel **imgY = (pl) ? p_Img->dec_picture->imgUV[pl - 1] : p_Img->dec_picture->imgY;
00043 imgpel **mb_pred = &(currSlice->mb_pred[pl][0]);
00044
00045 PixelPos up;
00046 PixelPos left[17];
00047
00048 int up_avail, left_avail, left_up_avail;
00049
00050 s1=s2=0;
00051
00052 for (i=0;i<17;++i)
00053 {
00054 p_Img->getNeighbour(currMB, -1, i-1, p_Img->mb_size[IS_LUMA], &left[i]);
00055 }
00056 p_Img->getNeighbour(currMB, 0, -1, p_Img->mb_size[IS_LUMA], &up);
00057
00058 if (!p_Img->active_pps->constrained_intra_pred_flag)
00059 {
00060 up_avail = up.available;
00061 left_avail = left[1].available;
00062 left_up_avail = left[0].available;
00063 }
00064 else
00065 {
00066 up_avail = up.available ? p_Img->intra_block[up.mb_addr] : 0;
00067 for (i = 1, left_avail = 1; i < 17; ++i)
00068 left_avail &= left[i].available ? p_Img->intra_block[left[i].mb_addr]: 0;
00069 left_up_avail = left[0].available ? p_Img->intra_block[left[0].mb_addr]: 0;
00070 }
00071
00072 for (i = 0; i < MB_BLOCK_SIZE; ++i)
00073 {
00074 if (up_avail)
00075 s1 += imgY[up.pos_y][up.pos_x+i];
00076 if (left_avail)
00077 s2 += imgY[left[i + 1].pos_y][left[i + 1].pos_x];
00078 }
00079 if (up_avail && left_avail)
00080 s0 = (s1 + s2 + 16)>>5;
00081 else if (!up_avail && left_avail)
00082 s0 = (s2 + 8)>>4;
00083 else if (up_avail && !left_avail)
00084 s0 = (s1 + 8)>>4;
00085 else
00086 s0 = p_Img->dc_pred_value_comp[pl];
00087
00088 for(j = 0; j < MB_BLOCK_SIZE; ++j)
00089 {
00090 for(i = 0; i < MB_BLOCK_SIZE; ++i)
00091 {
00092 mb_pred[j][i]=(imgpel) s0;
00093 }
00094 }
00095
00096 return DECODING_OK;
00097 }
00098
00099
00110 static inline int intra16x16_vert_pred(Macroblock *currMB,
00111 ColorPlane pl)
00112 {
00113 Slice *currSlice = currMB->p_Slice;
00114 ImageParameters *p_Img = currMB->p_Img;
00115
00116 int j;
00117
00118 imgpel **imgY = (pl) ? p_Img->dec_picture->imgUV[pl - 1] : p_Img->dec_picture->imgY;
00119
00120 PixelPos up;
00121
00122 int up_avail;
00123
00124 p_Img->getNeighbour(currMB, 0, -1, p_Img->mb_size[IS_LUMA], &up);
00125
00126 if (!p_Img->active_pps->constrained_intra_pred_flag)
00127 {
00128 up_avail = up.available;
00129 }
00130 else
00131 {
00132 up_avail = up.available ? p_Img->intra_block[up.mb_addr] : 0;
00133 }
00134
00135 if (!up_avail)
00136 error ("invalid 16x16 intra pred Mode VERT_PRED_16",500);
00137
00138 for(j=0;j<MB_BLOCK_SIZE;++j)
00139 memcpy(&currSlice->mb_pred[pl][j][0], &(imgY[up.pos_y][up.pos_x]), MB_BLOCK_SIZE * sizeof(imgpel));
00140
00141 return DECODING_OK;
00142 }
00143
00144
00155 static inline int intra16x16_hor_pred(Macroblock *currMB,
00156 ColorPlane pl)
00157 {
00158 Slice *currSlice = currMB->p_Slice;
00159 ImageParameters *p_Img = currMB->p_Img;
00160 int i,j;
00161
00162 imgpel **imgY = (pl) ? p_Img->dec_picture->imgUV[pl - 1] : p_Img->dec_picture->imgY;
00163 imgpel **mb_pred = &(currSlice->mb_pred[pl][0]);
00164 imgpel prediction;
00165
00166 PixelPos left[17];
00167
00168 int left_avail, left_up_avail;
00169
00170 for (i=0;i<17;++i)
00171 {
00172 p_Img->getNeighbour(currMB, -1, i-1, p_Img->mb_size[IS_LUMA], &left[i]);
00173 }
00174
00175 if (!p_Img->active_pps->constrained_intra_pred_flag)
00176 {
00177 left_avail = left[1].available;
00178 left_up_avail = left[0].available;
00179 }
00180 else
00181 {
00182 for (i = 1, left_avail = 1; i < 17; ++i)
00183 left_avail &= left[i].available ? p_Img->intra_block[left[i].mb_addr]: 0;
00184 left_up_avail = left[0].available ? p_Img->intra_block[left[0].mb_addr]: 0;
00185 }
00186
00187 if (!left_avail)
00188 error ("invalid 16x16 intra pred Mode HOR_PRED_16",500);
00189
00190 for(j = 0; j < MB_BLOCK_SIZE; ++j)
00191 {
00192 prediction = imgY[left[j+1].pos_y][left[j+1].pos_x];
00193 for(i = 0; i < MB_BLOCK_SIZE; ++i)
00194 mb_pred[j][i]= prediction;
00195 }
00196
00197 return DECODING_OK;
00198 }
00199
00210 static inline int intra16x16_plane_pred(Macroblock *currMB,
00211 ColorPlane pl)
00212 {
00213 Slice *currSlice = currMB->p_Slice;
00214 ImageParameters *p_Img = currMB->p_Img;
00215
00216 int i,j;
00217
00218 int ih = 0, iv = 0;
00219 int ib,ic,iaa;
00220
00221 imgpel **imgY = (pl) ? p_Img->dec_picture->imgUV[pl - 1] : p_Img->dec_picture->imgY;
00222 imgpel **mb_pred = &(currSlice->mb_pred[pl][0]);
00223 imgpel *mpr_line;
00224 int max_imgpel_value = p_Img->max_imgpel_value_comp[pl];
00225
00226 PixelPos up;
00227 PixelPos left[17];
00228
00229 int up_avail, left_avail, left_up_avail;
00230
00231 for (i=0;i<17; ++i)
00232 {
00233 p_Img->getNeighbour(currMB, -1, i-1, p_Img->mb_size[IS_LUMA], &left[i]);
00234 }
00235 p_Img->getNeighbour(currMB, 0, -1, p_Img->mb_size[IS_LUMA], &up);
00236
00237 if (!p_Img->active_pps->constrained_intra_pred_flag)
00238 {
00239 up_avail = up.available;
00240 left_avail = left[1].available;
00241 left_up_avail = left[0].available;
00242 }
00243 else
00244 {
00245 up_avail = up.available ? p_Img->intra_block[up.mb_addr] : 0;
00246 for (i = 1, left_avail = 1; i < 17; ++i)
00247 left_avail &= left[i].available ? p_Img->intra_block[left[i].mb_addr]: 0;
00248 left_up_avail = left[0].available ? p_Img->intra_block[left[0].mb_addr]: 0;
00249 }
00250
00251 if (!up_avail || !left_up_avail || !left_avail)
00252 error ("invalid 16x16 intra pred Mode PLANE_16",500);
00253
00254 mpr_line = &imgY[up.pos_y][up.pos_x+7];
00255 for (i = 1; i < 8; ++i)
00256 {
00257 ih += i*(mpr_line[i] - mpr_line[-i]);
00258 iv += i*(imgY[left[8+i].pos_y][left[8+i].pos_x] - imgY[left[8-i].pos_y][left[8-i].pos_x]);
00259 }
00260
00261 ih += 8*(mpr_line[8] - imgY[left[0].pos_y][left[0].pos_x]);
00262 iv += 8*(imgY[left[16].pos_y][left[16].pos_x] - imgY[left[0].pos_y][left[0].pos_x]);
00263
00264 ib=(5 * ih + 32)>>6;
00265 ic=(5 * iv + 32)>>6;
00266
00267 iaa=16 * (mpr_line[8] + imgY[left[16].pos_y][left[16].pos_x]);
00268 for (j = 0;j < MB_BLOCK_SIZE; ++j)
00269 {
00270 for (i = 0;i < MB_BLOCK_SIZE; ++i)
00271 {
00272 mb_pred[j][i] = (imgpel) iClip1(max_imgpel_value, ((iaa + (i - 7) * ib + (j - 7) * ic + 16) >> 5));
00273 }
00274 }
00275
00276 return DECODING_OK;
00277 }
00278
00289 int intrapred16x16(Macroblock *currMB,
00290 ColorPlane pl,
00291 int predmode)
00292 {
00293 switch (predmode)
00294 {
00295 case VERT_PRED_16:
00296 return (intra16x16_vert_pred(currMB, pl));
00297 break;
00298 case HOR_PRED_16:
00299 return (intra16x16_hor_pred(currMB, pl));
00300 break;
00301 case DC_PRED_16:
00302 return (intra16x16_dc_pred(currMB, pl));
00303 break;
00304 case PLANE_16:
00305 return (intra16x16_plane_pred(currMB, pl));
00306 break;
00307 default:
00308 {
00309 printf("illegal 16x16 intra prediction mode input: %d\n",predmode);
00310 return SEARCH_SYNC;
00311 }
00312 }
00313
00314 return DECODING_OK;
00315 }
00316