00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <libdirac_common/upconvert.h>
00039 using namespace dirac;
00040
00041 #include <iostream>
00042
00043
00044 void UpConverter::DoUpConverter(const PicArray& pic_data, PicArray& up_data)
00045 {
00046
00047 xOld = pic_data.LengthX();
00048 yOld = pic_data.LengthY();
00049 xNew = up_data.LengthX();
00050 yNew = up_data.LengthY();
00051
00052
00053
00054 int sum;
00055 int ypos(0);
00056
00057
00058
00059
00060 for(int y = 0 ; y < Stage_I_Size; ++y , ypos += 2)
00061 {
00062
00063
00064
00065
00066
00067 for(int x = 0 , xpos = 0; x < xOld; x++ , xpos+=2 )
00068 {
00069
00070
00071 up_data[ypos][xpos] = pic_data[y][x];
00072
00073
00074
00075 sum = (pic_data[y][x] + pic_data[y+1][x])*StageI_I;
00076 sum += (pic_data[(y>=1)?(y-1):0][x] + pic_data[y+2][x])*StageI_II;
00077 sum += (pic_data[(y>=2)?(y-2):0][x] + pic_data[y+3][x])*StageI_III;
00078 sum += (pic_data[(y>=3)?(y-3):0][x] + pic_data[y+4][x])*StageI_IV;
00079 sum += (pic_data[(y>=4)?(y-4):0][x] + pic_data[y+5][x])*StageI_V;
00080 sum += (pic_data[(y>=5)?(y-5):0][x] + pic_data[y+6][x])*StageI_VI;
00081
00082 up_data[ypos+1][xpos] = sum >> Stage_I_Shift;
00083
00084 }
00085
00086
00087 RowLoop(up_data, ypos);
00088 }
00089
00090
00091
00092 for(int y = Stage_I_Size; y < yOld - Stage_I_Size; ++y , ypos += 2)
00093 {
00094 for(int x = 0 , xpos=0; x < xOld; x++ , xpos+=2 )
00095 {
00096
00097 up_data[ypos][xpos] = pic_data[y][x];
00098
00099 sum = (pic_data[y][x] + pic_data[y+1][x])*StageI_I;
00100 sum += (pic_data[y-1][x] + pic_data[y+2][x])*StageI_II;
00101 sum += (pic_data[y-2][x] + pic_data[y+3][x])*StageI_III;
00102 sum += (pic_data[y-3][x] + pic_data[y+4][x])*StageI_IV;
00103 sum += (pic_data[y-4][x] + pic_data[y+5][x])*StageI_V;
00104 sum += (pic_data[y-5][x] + pic_data[y+6][x])*StageI_VI;
00105
00106 up_data[ypos+1][xpos] = sum >> Stage_I_Shift;
00107
00108 }
00109 RowLoop(up_data, ypos);
00110
00111 }
00112
00113
00114
00115 for(int y = yOld - Stage_I_Size; y < yOld; ++y , ypos+=2)
00116 {
00117 for(int x = 0 , xpos=0 ; x < xOld; x++ , xpos+=2)
00118 {
00119
00120 up_data[ypos][xpos]=pic_data[y][x];
00121
00122 sum = (pic_data[y][x] + pic_data[((y+1)<yOld)?(y+1):(yOld-1)][x])*StageI_I;
00123 sum += (pic_data[y - 1][x] + pic_data[((y+2)<yOld)?(y+2):(yOld-1)][x])*StageI_II;
00124 sum += (pic_data[y - 2][x] + pic_data[((y+3)<yOld)?(y+3):(yOld-1)][x])*StageI_III;
00125 sum += (pic_data[y - 3][x] + pic_data[((y+4)<yOld)?(y+4):(yOld-1)][x])*StageI_IV;
00126 sum += (pic_data[y - 4][x] + pic_data[((y+5)<yOld)?(y+5):(yOld-1)][x])*StageI_V;
00127 sum += (pic_data[y - 5][x] + pic_data[((y+6)<yOld)?(y+6):(yOld-1)][x])*StageI_VI;
00128 up_data[ypos+1][xpos] = sum >> Stage_I_Shift;
00129
00130 }
00131 RowLoop(up_data, ypos);
00132
00133 }
00134 }
00135
00136
00137 void UpConverter::RowLoop(PicArray&up_data, const int row_num)
00138 {
00139
00140 int sum;
00141 int ypos;
00142
00143
00144
00145
00146 for(int i = 0; i < 2; ++i)
00147 {
00148 ypos = row_num + i;
00149
00150 for(int x = 0; x < (2*Stage_I_Size); x+=2)
00151 {
00152
00153 sum = (up_data[ypos][x] + up_data[ypos][x+2])*StageI_I;
00154 sum += (up_data[ypos][(x>=2)?(x-2):0] + up_data[ypos][x+4])*StageI_II;
00155 sum += (up_data[ypos][(x>=4)?(x-4):0] + up_data[ypos][x+6])*StageI_III;
00156 sum += (up_data[ypos][(x>=6)?(x-6):0] + up_data[ypos][x+8])*StageI_IV;
00157 sum += (up_data[ypos][(x>=8)?(x-8):0] + up_data[ypos][x+10])*StageI_V;
00158 sum += (up_data[ypos][(x>=10)?(x-10):0] + up_data[ypos][x+12])*StageI_VI;
00159
00160 up_data[ypos][x+1] = sum >> Stage_I_Shift;
00161 }
00162
00163 for(int x = (2*Stage_I_Size); x < xNew - (2*Stage_I_Size); x+=2)
00164 {
00165 sum = (up_data[ypos][x] + up_data[ypos][x+2])*StageI_I;
00166 sum += (up_data[ypos][x-2] + up_data[ypos][x+4])*StageI_II;
00167 sum += (up_data[ypos][x-4] + up_data[ypos][x+6])*StageI_III;
00168 sum += (up_data[ypos][x-6] + up_data[ypos][x+8])*StageI_IV;
00169 sum += (up_data[ypos][x-8] + up_data[ypos][x+10])*StageI_V;
00170 sum += (up_data[ypos][x-10] + up_data[ypos][x+12])*StageI_VI;
00171
00172 up_data[ypos][x+1] = sum >> Stage_I_Shift;
00173 }
00174
00175 for(int x = xNew - (2*Stage_I_Size); x < xNew; x+=2)
00176 {
00177 sum = (up_data[ypos][x] + up_data[ypos][(((x+2)<xNew)?(x+2):(xNew-2))])*StageI_I;
00178 sum += (up_data[ypos][x-2] + up_data[ypos][(((x+4)<xNew)?(x+4):(xNew-2))])*StageI_II;
00179 sum += (up_data[ypos][x-4] + up_data[ypos][(((x+6)<xNew)?(x+6):(xNew-2))])*StageI_III;
00180 sum += (up_data[ypos][x-6] + up_data[ypos][(((x+8)<xNew)?(x+8):(xNew-2))])*StageI_IV;
00181 sum += (up_data[ypos][x-8] + up_data[ypos][(((x+10)<xNew)?(x+10):(xNew-2))])*StageI_V;
00182 sum += (up_data[ypos][x-10] + up_data[ypos][(((x+12)<xNew)?(x+12):(xNew-2))])*StageI_VI;
00183 up_data[ypos][x+1] = sum >> Stage_I_Shift;
00184 }
00185 }
00186 }