00001
00015 #include "global.h"
00016 #include "block.h"
00017 #include "mb_access.h"
00018 #include "image.h"
00019
00020 static void intra_chroma_DC_single(imgpel **curr_img, int up_avail, int left_avail, PixelPos up, PixelPos left[17], int blk_x, int blk_y, int *pred, int direction )
00021 {
00022 int i;
00023 int s0 = 0;
00024
00025 if ((direction && up_avail) || (!left_avail && up_avail))
00026 {
00027 for (i = blk_x; i < (blk_x + 4);++i)
00028 s0 += curr_img[up.pos_y][up.pos_x + i];
00029 *pred = (s0 + 2) >> 2;
00030 }
00031 else if (left_avail)
00032 {
00033 for (i = blk_y; i < (blk_y + 4);++i)
00034 s0 += curr_img[left[i].pos_y][left[i].pos_x];
00035 *pred = (s0 + 2) >> 2;
00036 }
00037 }
00038
00039
00040 static void intra_chroma_DC_all(imgpel **curr_img, int up_avail, int left_avail, PixelPos up, PixelPos left[17], int blk_x, int blk_y, int *pred )
00041 {
00042 int i;
00043 int s0 = 0, s1 = 0;
00044
00045 if (up_avail)
00046 for (i = blk_x; i < (blk_x + 4);++i)
00047 s0 += curr_img[up.pos_y][up.pos_x + i];
00048
00049 if (left_avail)
00050 for (i = blk_y; i < (blk_y + 4);++i)
00051 s1 += curr_img[left[i].pos_y][left[i].pos_x];
00052
00053 if (up_avail && left_avail)
00054 *pred = (s0 + s1 + 4) >> 3;
00055 else if (up_avail)
00056 *pred = (s0 + 2) >> 2;
00057 else if (left_avail)
00058 *pred = (s1 + 2) >> 2;
00059 }
00060
00068 void intrapred_chroma(Macroblock *currMB, int uv)
00069 {
00070 Slice *currSlice = currMB->p_Slice;
00071 ImageParameters *p_Img = currMB->p_Img;
00072 int i,j, ii, jj;
00073 StorablePicture *dec_picture = p_Img->dec_picture;
00074 imgpel **imgUV = dec_picture->imgUV[uv];
00075 imgpel **mb_pred = currSlice->mb_pred[uv + 1];
00076 int max_imgpel_value = p_Img->max_imgpel_value_comp[uv + 1];
00077
00078 int ih, iv, ib, ic, iaa;
00079
00080 int b8, b4;
00081 int yuv = dec_picture->chroma_format_idc - 1;
00082 int blk_x, blk_y;
00083 int pred;
00084 static const int block_pos[3][4][4]=
00085 {
00086 { {0, 1, 2, 3},{0, 0, 0, 0},{0, 0, 0, 0},{0, 0, 0, 0}},
00087 { {0, 1, 2, 3},{2, 3, 2, 3},{0, 0, 0, 0},{0, 0, 0, 0}},
00088 { {0, 1, 2, 3},{1, 1, 3, 3},{2, 3, 2, 3},{3, 3, 3, 3}}
00089 };
00090
00091 PixelPos up;
00092 PixelPos left[17];
00093
00094 int up_avail, left_avail[2], left_up_avail;
00095
00096 int cr_MB_x = p_Img->mb_cr_size_x;
00097 int cr_MB_y = p_Img->mb_cr_size_y;
00098 int cr_MB_y2 = (cr_MB_y >> 1);
00099 int cr_MB_x2 = (cr_MB_x >> 1);
00100
00101 for (i=0; i < cr_MB_y + 1 ; ++i)
00102 {
00103 p_Img->getNeighbour(currMB, -1, i-1, p_Img->mb_size[IS_CHROMA], &left[i]);
00104 }
00105
00106 p_Img->getNeighbour(currMB, 0, -1, p_Img->mb_size[IS_CHROMA], &up);
00107
00108 if (!p_Img->active_pps->constrained_intra_pred_flag)
00109 {
00110 up_avail = up.available;
00111 left_avail[0] = left_avail[1] = left[1].available;
00112 left_up_avail = left[0].available;
00113 }
00114 else
00115 {
00116 up_avail = up.available ? p_Img->intra_block[up.mb_addr] : 0;
00117 for (i=0, left_avail[0] = 1; i < cr_MB_y2;++i)
00118 left_avail[0] &= left[i + 1].available ? p_Img->intra_block[left[i + 1].mb_addr]: 0;
00119
00120 for (i = cr_MB_y2, left_avail[1] = 1; i<cr_MB_y;++i)
00121 left_avail[1] &= left[i + 1].available ? p_Img->intra_block[left[i + 1].mb_addr]: 0;
00122
00123 left_up_avail = left[0].available ? p_Img->intra_block[left[0].mb_addr]: 0;
00124 }
00125
00126 switch (currMB->c_ipred_mode)
00127 {
00128 case DC_PRED_8:
00129
00130
00131
00132 for(b8 = 0; b8 < (p_Img->num_uv_blocks) ;++b8)
00133 {
00134 for (b4 = 0; b4 < 4; ++b4)
00135 {
00136 blk_y = subblk_offset_y[yuv][b8][b4];
00137 blk_x = subblk_offset_x[yuv][b8][b4];
00138
00139 pred = p_Img->dc_pred_value_comp[1];
00140
00141
00142 switch (block_pos[yuv][b8][b4])
00143 {
00144 case 0:
00145 intra_chroma_DC_all (imgUV, up_avail, left_avail[0], up, left, blk_x, blk_y + 1, &pred);
00146 break;
00147 case 1:
00148 intra_chroma_DC_single(imgUV, up_avail, left_avail[0], up, left, blk_x, blk_y + 1, &pred, 1);
00149 break;
00150 case 2:
00151 intra_chroma_DC_single(imgUV, up_avail, left_avail[1], up, left, blk_x, blk_y + 1, &pred, 0);
00152 break;
00153 case 3:
00154 intra_chroma_DC_all (imgUV, up_avail, left_avail[1], up, left, blk_x, blk_y + 1, &pred);
00155 break;
00156 }
00157
00158 for (jj = blk_y; jj < blk_y + BLOCK_SIZE; ++jj)
00159 {
00160 for (ii = blk_x; ii < blk_x + BLOCK_SIZE; ++ii)
00161 {
00162 mb_pred[jj][ii]=(imgpel) pred;
00163 }
00164 }
00165 }
00166 }
00167 break;
00168 case HOR_PRED_8:
00169
00170 if (!left_avail[0] || !left_avail[1])
00171 error("unexpected HOR_PRED_8 chroma intra prediction mode",-1);
00172
00173 for (j = 0; j < cr_MB_y; ++j)
00174 {
00175 pred = imgUV[left[1 + j].pos_y][left[1 + j].pos_x];
00176 for (i = 0; i < cr_MB_x; ++i)
00177 mb_pred[j][i]=(imgpel) pred;
00178 }
00179
00180 break;
00181 case VERT_PRED_8:
00182
00183 if (!up_avail)
00184 error("unexpected VERT_PRED_8 chroma intra prediction mode",-1);
00185
00186 for (j = 0; j < cr_MB_y; ++j)
00187 {
00188 memcpy(&(mb_pred[j][0]), &(imgUV[up.pos_y][up.pos_x]), cr_MB_x * sizeof(imgpel));
00189 }
00190 break;
00191 case PLANE_8:
00192
00193 if (!left_up_avail || !left_avail[0] || !left_avail[1] || !up_avail)
00194 error("unexpected PLANE_8 chroma intra prediction mode",-1);
00195 else
00196 {
00197 imgpel *upPred = &imgUV[up.pos_y][up.pos_x];
00198
00199 ih = cr_MB_x2 * (upPred[cr_MB_x - 1] - imgUV[left[0].pos_y][left[0].pos_x]);
00200 for (i = 0; i < cr_MB_x2 - 1; ++i)
00201 ih += (i + 1) * (upPred[cr_MB_x2 + i] - upPred[cr_MB_x2 - 2 - i]);
00202
00203 iv = cr_MB_y2 * (imgUV[left[cr_MB_y].pos_y][left[cr_MB_y].pos_x] - imgUV[left[0].pos_y][left[0].pos_x]);
00204 for (i = 0; i < cr_MB_y2 - 1; ++i)
00205 iv += (i + 1)*(imgUV[left[cr_MB_y2 + 1 + i].pos_y][left[cr_MB_y2 + 1 + i].pos_x] -
00206 imgUV[left[cr_MB_y2 - 1 - i].pos_y][left[cr_MB_y2 - 1 - i].pos_x]);
00207
00208 ib= ((cr_MB_x == 8 ? 17 : 5) * ih + 2 * cr_MB_x)>>(cr_MB_x == 8 ? 5 : 6);
00209 ic= ((cr_MB_y == 8 ? 17 : 5) * iv + 2 * cr_MB_y)>>(cr_MB_y == 8 ? 5 : 6);
00210
00211 iaa=16*(imgUV[left[cr_MB_y].pos_y][left[cr_MB_y].pos_x] + upPred[cr_MB_x-1]);
00212
00213 for (j = 0; j < cr_MB_y; ++j)
00214 for (i = 0; i < cr_MB_x; ++i)
00215 mb_pred[j][i]=(imgpel) iClip1(max_imgpel_value, ((iaa + (i - cr_MB_x2 + 1) * ib + (j - cr_MB_y2 + 1) * ic + 16) >> 5));
00216 }
00217 break;
00218 default:
00219 error("illegal chroma intra prediction mode", 600);
00220 break;
00221 }
00222 }
00223
00224
00225
00226