00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "contributors.h"
00015 #include "global.h"
00016 #include "memalloc.h"
00017 #include "img_distortion.h"
00018
00019 #define YUV2RGB_YOFFSET
00020
00021
00022 #ifdef YUV2RGB_YOFFSET
00023 #define OFFSET_Y 16
00024 static const float K0 = 1.164f;
00025 static const float K1 = 1.596f;
00026 static const float K2 = 0.391f;
00027 static const float K3 = 0.813f;
00028 static const float K4 = 2.018f;
00029 #else
00030 static const float K0 = 1.000f;
00031 static const float K1 = 1.402f;
00032 static const float K2 = 0.34414f;
00033 static const float K3 = 0.71414f;
00034 static const float K4 = 1.772f;
00035 #endif
00036
00037 int create_RGB_memory(ImageParameters *p_Img)
00038 {
00039 int memory_size = 0;
00040 int j;
00041 for( j = 0; j < 3; j++ )
00042 {
00043 memory_size += get_mem2Dpel (&p_Img->imgRGB_src.data[j], p_Img->height, p_Img->width);
00044 }
00045 for( j = 0; j < 3; j++ )
00046 {
00047 memory_size += get_mem2Dpel (&p_Img->imgRGB_ref.data[j], p_Img->height, p_Img->width);
00048 }
00049
00050 return memory_size;
00051 }
00052
00053 void delete_RGB_memory(ImageParameters *p_Img)
00054 {
00055 int i;
00056 for( i = 0; i < 3; i++ )
00057 {
00058 free_mem2Dpel(p_Img->imgRGB_src.data[i]);
00059 }
00060 for( i = 0; i < 3; i++ )
00061 {
00062 free_mem2Dpel(p_Img->imgRGB_ref.data[i]);
00063 }
00064 }
00065
00066 void init_YUVtoRGB(ImageParameters *p_Img, InputParameters *p_Inp)
00067 {
00068 float conv_scale = (float) (65536.0f);
00069
00070 p_Img->wka0 = float2int( conv_scale * K0);
00071 p_Img->wka1 = float2int( conv_scale * K1);
00072 p_Img->wka2 = float2int( -conv_scale * K2);
00073 p_Img->wka3 = float2int( -conv_scale * K3);
00074 p_Img->wka4 = float2int( conv_scale * K4);
00075
00076 #ifdef YUV2RGB_YOFFSET
00077 p_Img->offset_y = OFFSET_Y << (p_Inp->output.bit_depth[0] - 8);
00078 p_Img->offset_cr = 1 << (p_Inp->output.bit_depth[0] - 1);
00079 #endif
00080 }
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 void YUVtoRGB(ImageParameters *p_Img, ImageStructure *YUV, ImageStructure *RGB)
00092 {
00093 int i, j, j_cr, i_cr;
00094 int sy, su, sv;
00095 int wbuv, wguv, wruv;
00096 imgpel *Y, *U, *V, *R, *G, *B;
00097 FrameFormat format = YUV->format;
00098 int width = format.width;
00099 int height = format.height;
00100 int max_value = format.max_value[0];
00101
00102
00103 for (j = 0; j < height; j++)
00104 {
00105 j_cr = j >> p_Img->shift_cr_y;
00106 Y = YUV->data[0][j];
00107 U = YUV->data[1][j_cr];
00108 V = YUV->data[2][j_cr];
00109 R = RGB->data[0][j];
00110 G = RGB->data[1][j];
00111 B = RGB->data[2][j];
00112
00113 for (i = 0; i < width; i++)
00114 {
00115 i_cr = i >> p_Img->shift_cr_x;
00116
00117 su = U[i_cr] - p_Img->offset_cr;
00118 sv = V[i_cr] - p_Img->offset_cr;
00119
00120 wruv = p_Img->wka1 * sv;
00121 wguv = p_Img->wka2 * su + p_Img->wka3 * sv;
00122 wbuv = p_Img->wka4 * su;
00123
00124 #ifdef YUV2RGB_YOFFSET // Y offset value of 16 is considered
00125 sy = p_Img->wka0 * (Y[i] - p_Img->offset_y);
00126 #else
00127 sy = p_Img->wka0 * Y[i];
00128 #endif
00129
00130 R[i] = (imgpel) iClip1( max_value, rshift_rnd(sy + wruv, 16));
00131 G[i] = (imgpel) iClip1( max_value, rshift_rnd(sy + wguv, 16));
00132 B[i] = (imgpel) iClip1( max_value, rshift_rnd(sy + wbuv, 16));
00133 }
00134 }
00135
00136 RGB->format = format;
00137 RGB->format.yuv_format = YUV444;
00138 RGB->format.color_model = CM_RGB;
00139 RGB->format.height_cr = format.height;
00140 RGB->format.width_cr = format.width;
00141 for (i = 1; i < 3; i++)
00142 {
00143 RGB->format.size_cmp[i] = format.size_cmp[0];
00144 RGB->format.bit_depth[i] = format.bit_depth[0];
00145 RGB->format.max_value[i] = max_value;
00146 RGB->format.max_value_sq[i] = format.max_value_sq[0];
00147 }
00148 }