00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "contributors.h"
00016 #include "global.h"
00017 #include "image.h"
00018 #include "img_process.h"
00019 #include "io_image.h"
00020 #include "memalloc.h"
00021
00022
00023 static inline void ResetImage(ImageData *imgOut)
00024 {
00025 memset(imgOut->frm_data[0][0], 0, imgOut->format.height * imgOut->format.width * sizeof (imgpel));
00026
00027 if (imgOut->format.yuv_format != YUV400)
00028 {
00029 if (sizeof(imgpel) == sizeof(char))
00030 {
00031 memset(imgOut->frm_data[1][0], 128, imgOut->format.height_cr * imgOut->format.width_cr * sizeof (imgpel));
00032 memset(imgOut->frm_data[2][0], 128, imgOut->format.height_cr * imgOut->format.width_cr * sizeof (imgpel));
00033 }
00034 else
00035 {
00036 int i, j, k;
00037 imgpel med_value;
00038 for (k = 1; k <=2; k++)
00039 {
00040 med_value = (imgpel) (imgOut->format.max_value[k] + 1) >> 1;
00041 for (j = 0; j < imgOut->format.height_cr; j++)
00042 {
00043 for (i = 0; i < imgOut->format.width_cr; i++)
00044 {
00045 imgOut->frm_data[k][j][i] = med_value;
00046 }
00047 }
00048 }
00049 }
00050 }
00051 }
00052
00053
00054 static inline void CPImage(ImageData *imgOut, ImageData *imgIn)
00055 {
00056 memcpy(imgOut->frm_data[0][0], imgIn->frm_data[0][0], imgIn->format.height * imgIn->format.width * sizeof (imgpel));
00057
00058 if (imgIn->format.yuv_format != YUV400)
00059 {
00060 memcpy(imgOut->frm_data[1][0], imgIn->frm_data[1][0], imgIn->format.height_cr * imgIn->format.width_cr * sizeof (imgpel));
00061 memcpy(imgOut->frm_data[2][0], imgIn->frm_data[2][0], imgIn->format.height_cr * imgIn->format.width_cr * sizeof (imgpel));
00062 }
00063 }
00064
00065
00066 static inline void FilterImage(ImageData *imgOut, ImageData *imgIn)
00067 {
00068 memcpy(imgOut->frm_data[0][0], imgIn->frm_data[0][0], imgIn->format.height * imgIn->format.width * sizeof (imgpel));
00069
00070 if (imgIn->format.yuv_format != YUV400)
00071 {
00072 memcpy(imgOut->frm_data[1][0], imgIn->frm_data[1][0], imgIn->format.height_cr * imgIn->format.width_cr * sizeof (imgpel));
00073 memcpy(imgOut->frm_data[2][0], imgIn->frm_data[2][0], imgIn->format.height_cr * imgIn->format.width_cr * sizeof (imgpel));
00074 }
00075 }
00076
00077
00078 static inline void FilterImageSep(ImageData *imgOut, ImageData *imgIn)
00079 {
00080 int i, j;
00081 static const int SepFilter[6] = {1, -5, 20, 20, -5, 1};
00082 int max_width = imgOut->format.width - 1;
00083 int max_height = imgOut->format.height - 1;
00084
00085 int **temp_data;
00086
00087 get_mem2Dint(&temp_data, imgIn->format.height, imgIn->format.width);
00088
00089
00090
00091 for (j = 0; j < imgOut->format.height; j++)
00092 {
00093 for (i = 0; i < imgOut->format.width; i++)
00094 {
00095 temp_data[j][i] =
00096 SepFilter[0] * imgIn->frm_data[0][j][iClip3(0, max_width, i - 2)] +
00097 SepFilter[1] * imgIn->frm_data[0][j][iClip3(0, max_width, i - 1)] +
00098 SepFilter[2] * imgIn->frm_data[0][j][iClip3(0, max_width, i )] +
00099 SepFilter[3] * imgIn->frm_data[0][j][iClip3(0, max_width, i + 1)] +
00100 SepFilter[4] * imgIn->frm_data[0][j][iClip3(0, max_width, i + 2)] +
00101 SepFilter[5] * imgIn->frm_data[0][j][iClip3(0, max_width, i + 3)];
00102 }
00103 }
00104
00105 for (j = 0; j < imgOut->format.height; j++)
00106 {
00107 for (i = 0; i < imgOut->format.width; i++)
00108 {
00109 imgOut->frm_data[0][j][i] = (imgpel) iClip3(0, imgOut->format.max_value[0], rshift_rnd_sign(
00110 SepFilter[0] * temp_data[iClip3(0, max_height, j - 2)][i] +
00111 SepFilter[1] * temp_data[iClip3(0, max_height, j - 1)][i] +
00112 SepFilter[2] * temp_data[iClip3(0, max_height, j )][i] +
00113 SepFilter[3] * temp_data[iClip3(0, max_height, j + 1)][i] +
00114 SepFilter[4] * temp_data[iClip3(0, max_height, j + 2)][i] +
00115 SepFilter[5] * temp_data[iClip3(0, max_height, j + 3)][i], 10));
00116 }
00117 }
00118
00119 if (imgOut->format.yuv_format != YUV400)
00120 {
00121 int k;
00122 max_width = imgOut->format.width_cr - 1;
00123 max_height = imgOut->format.height_cr - 1;
00124
00125 for (k = 1; k <=2; k++)
00126 {
00127
00128 for (j = 0; j < imgOut->format.height_cr; j++)
00129 {
00130 for (i = 0; i < imgOut->format.width_cr; i++)
00131 {
00132 temp_data[j][i] =
00133 SepFilter[0] * imgIn->frm_data[k][j][iClip3(0, max_width, i - 2)] +
00134 SepFilter[1] * imgIn->frm_data[k][j][iClip3(0, max_width, i - 1)] +
00135 SepFilter[2] * imgIn->frm_data[k][j][iClip3(0, max_width, i )] +
00136 SepFilter[3] * imgIn->frm_data[k][j][iClip3(0, max_width, i + 1)] +
00137 SepFilter[4] * imgIn->frm_data[k][j][iClip3(0, max_width, i + 2)] +
00138 SepFilter[5] * imgIn->frm_data[k][j][iClip3(0, max_width, i + 3)];
00139 }
00140 }
00141
00142 for (j = 0; j < imgOut->format.height_cr; j++)
00143 {
00144 for (i = 0; i < imgOut->format.width_cr; i++)
00145 {
00146 imgOut->frm_data[k][j][i] = (imgpel) iClip3(0, imgOut->format.max_value[k], rshift_rnd_sign(
00147 SepFilter[0] * temp_data[iClip3(0, max_height, j - 2)][i] +
00148 SepFilter[1] * temp_data[iClip3(0, max_height, j - 1)][i] +
00149 SepFilter[2] * temp_data[iClip3(0, max_height, j )][i] +
00150 SepFilter[3] * temp_data[iClip3(0, max_height, j + 1)][i] +
00151 SepFilter[4] * temp_data[iClip3(0, max_height, j + 2)][i] +
00152 SepFilter[5] * temp_data[iClip3(0, max_height, j + 3)][i], 10));
00153 }
00154 }
00155 }
00156 }
00157
00158 free_mem2Dint(temp_data);
00159 }
00160
00161
00162
00163 static inline void MuxImages(ImageData *imgOut, ImageData *imgIn0, ImageData *imgIn1, ImageData *Map)
00164 {
00165 int i, j;
00166 for (j = 0; j < imgOut->format.height; j++)
00167 {
00168 for (i = 0; i < imgOut->format.width; i++)
00169 {
00170 imgOut->frm_data[0][j][i] = (imgpel) rshift_rnd_sf(imgIn0->frm_data[0][j][i] * (Map->format.max_value[0] - Map->frm_data[0][j][i]) + imgIn1->frm_data[0][j][i] * Map->frm_data[0][j][i], Map->format.bit_depth[0]);
00171 }
00172 }
00173
00174 if (imgOut->format.yuv_format != YUV400)
00175 {
00176 int k;
00177 for (k = 1; k <=2; k++)
00178 {
00179 for (j = 0; j < imgOut->format.height_cr; j++)
00180 {
00181 for (i = 0; i < imgOut->format.width_cr; i++)
00182 {
00183 imgOut->frm_data[k][j][i] = (imgpel) rshift_rnd_sf(imgIn0->frm_data[k][j][i] * (Map->format.max_value[k] - Map->frm_data[k][j][i]) + imgIn1->frm_data[k][j][i] * Map->frm_data[k][j][i], Map->format.bit_depth[k]);
00184 }
00185 }
00186 }
00187 }
00188 }
00189
00190 static inline void YV12toYUV(ImageData *imgOut, ImageData *imgIn)
00191 {
00192 memcpy(imgOut->frm_data[0][0], imgIn->frm_data[0][0], imgIn->format.height * imgIn->format.width * sizeof (imgpel));
00193
00194 if (imgIn->format.yuv_format != YUV400)
00195 {
00196 memcpy(imgOut->frm_data[1][0], imgIn->frm_data[2][0], imgIn->format.height_cr * imgIn->format.width_cr * sizeof (imgpel));
00197 memcpy(imgOut->frm_data[2][0], imgIn->frm_data[1][0], imgIn->format.height_cr * imgIn->format.width_cr * sizeof (imgpel));
00198 }
00199 }
00200
00201 int InitProcessImage( ImageParameters *p_Img, InputParameters *p_Inp)
00202 {
00203 int memory_size = 0;
00204 switch( p_Inp->ProcessInput )
00205 {
00206 default:
00207 break;
00208 }
00209 return memory_size;
00210 }
00211
00212 void ClearProcessImage( ImageParameters *p_Img, InputParameters *p_Inp)
00213 {
00214 switch( p_Inp->ProcessInput )
00215 {
00216 default:
00217 break;
00218 }
00219 }
00220
00221 void ProcessImage( ImageParameters *p_Img, InputParameters *p_Inp )
00222 {
00223 switch( p_Inp->ProcessInput )
00224 {
00225 default:
00226 case 0:
00227 CPImage(&p_Img->imgData, &p_Img->imgData0);
00228 break;
00229 case 1:
00230 FilterImage(&p_Img->imgData, &p_Img->imgData0);
00231 break;
00232 case 2:
00233 YV12toYUV(&p_Img->imgData, &p_Img->imgData0);
00234 break;
00235 case 3:
00236 MuxImages(&p_Img->imgData, &p_Img->imgData0, &p_Img->imgData1, &p_Img->imgData2);
00237 break;
00238 case 4:
00239 FilterImageSep(&p_Img->imgData, &p_Img->imgData0);
00240 break;
00241 }
00242 }
00243
00244