Example #1
0
/*! 
*************************************************************************************
* \brief
*    YUV to RGB conversion
*    ITU 601 with and without offset consideration
*    Upsampling by repetition of chroma samples in case of 4:2:0 and 4:2:2
*    Method not support for 4:0:0 content
*************************************************************************************
*/
void YUVtoRGB(ImageParameters *p_Img, ImageStructure *YUV, ImageStructure *RGB)
{
  int i, j, j_cr, i_cr;
  int sy, su, sv;
  int wbuv, wguv, wruv;
  imgpel *Y, *U, *V, *R, *G, *B;
  FrameFormat format = YUV->format;
  int width = format.width;
  int height = format.height;
  int max_value = format.max_value[0];

  // Color conversion
  for (j = 0; j < height; j++)
  {
    j_cr = j >> p_Img->shift_cr_y;
    Y = YUV->data[0][j];
    U = YUV->data[1][j_cr];
    V = YUV->data[2][j_cr];
    R = RGB->data[0][j];
    G = RGB->data[1][j];
    B = RGB->data[2][j];

    for (i = 0; i < width; i++)
    {
      i_cr = i >> p_Img->shift_cr_x;

      su = U[i_cr] - p_Img->offset_cr;
      sv = V[i_cr] - p_Img->offset_cr;

      wruv = p_Img->wka1 * sv;
      wguv = p_Img->wka2 * su + p_Img->wka3 * sv;
      wbuv = p_Img->wka4 * su;

#ifdef YUV2RGB_YOFFSET // Y offset value of 16 is considered
      sy = p_Img->wka0 * (Y[i] - p_Img->offset_y);
#else
      sy = p_Img->wka0 * Y[i];
#endif

      R[i] = (imgpel) iClip1( max_value, rshift_rnd(sy + wruv, 16));
      G[i] = (imgpel) iClip1( max_value, rshift_rnd(sy + wguv, 16));
      B[i] = (imgpel) iClip1( max_value, rshift_rnd(sy + wbuv, 16));
    }
  }
  // Setting RGB FrameFormat
  RGB->format = format;  // copy format information from YUV to RGB
  RGB->format.yuv_format  = YUV444;
  RGB->format.color_model = CM_RGB;
  RGB->format.height_cr   = format.height;
  RGB->format.width_cr    = format.width;
  for (i = 1; i < 3; i++)
  {
    RGB->format.size_cmp[i]     = format.size_cmp[0];
    RGB->format.bit_depth[i]    = format.bit_depth[0];
    RGB->format.max_value[i]    = max_value;
    RGB->format.max_value_sq[i] = format.max_value_sq[0];
  }
}
Example #2
0
/*!
 ************************************************************************
 * \brief
 *    Weighted Prediction
 ************************************************************************
 */
static void weighted_mc_prediction(imgpel** mb_pred, 
                                   imgpel* lpred, 
                                   int block_size_y, 
                                   int block_size_x,
                                   int ioff, 
                                   int max_imgpel_value,
                                   short wp_scale, 
                                   short wp_offset,
                                   short wp_round, 
                                   short weight_denom)
{
  int i, j;
  int result;
  int block_x4 = ioff + block_size_x;

  for   (j = 0; j < block_size_y; j++)
  {
    for (i = ioff; i < block_x4; i++)
    {
      result = rshift_rnd((wp_scale * *lpred++), weight_denom) + wp_offset;      
      mb_pred[j][i] = (imgpel) iClip1( max_imgpel_value, result);
     }
  }
}