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
00039 #include <libdirac_motionest/downconvert.h>
00040 using namespace dirac;
00041
00042 DownConverter::DownConverter()
00043 {}
00044
00045
00046
00047 void DownConverter::DoDownConvert(const PicArray& old_data, PicArray& new_data)
00048 {
00049
00050 m_row_buffer= new ValueType[old_data.LengthX()];
00051
00052 int sum;
00053 int colpos;
00054
00055
00056 const int xlen = 2*new_data.LengthX();
00057 const int ylen = 2*new_data.LengthY();
00058
00059
00060
00061
00062 colpos=0;
00063 for( int y=0; y<Stage_I_Size*2 ; y+=2 , colpos++ )
00064 {
00065
00066
00067
00068
00069
00070 for( int x=0 ; x<xlen ; x++ )
00071 {
00072
00073
00074
00075 sum = (old_data[y][x] + old_data[y+1][x])*StageI_I;
00076 sum += (old_data[((y-1)>=0)?(y-1):0][x] + old_data[y+2][x])*StageI_II;
00077 sum += (old_data[((y-2)>=0)?(y-2):0][x] + old_data[y+3][x])*StageI_III;
00078 sum += (old_data[((y-3)>=0)?(y-3):0][x] + old_data[y+4][x])*StageI_IV;
00079 sum += (old_data[((y-4)>=0)?(y-4):0][x] + old_data[y+5][x])*StageI_V;
00080 sum += (old_data[((y-5)>=0)?(y-5):0][x] + old_data[y+6][x])*StageI_VI;
00081 sum += 1<<(StageI_Shift-1);
00082 m_row_buffer[x] = sum >> StageI_Shift;
00083 }
00084
00085
00086 RowLoop(colpos,old_data,new_data);
00087 }
00088
00089
00090
00091
00092 for( int y=Stage_I_Size*2 ; y<ylen-Stage_I_Size*2 ; y+=2 , colpos++ )
00093 {
00094 for( int x=0 ; x<xlen ; x++ )
00095 {
00096
00097 sum = (old_data[y][x] + old_data[y+1][x])*StageI_I;
00098 sum += (old_data[y-1][x] + old_data[y+2][x])*StageI_II;
00099 sum += (old_data[y-2][x] + old_data[y+3][x])*StageI_III;
00100 sum += (old_data[y-3][x] + old_data[y+4][x])*StageI_IV;
00101 sum += (old_data[y-4][x] + old_data[y+5][x])*StageI_V;
00102 sum += (old_data[y-5][x] + old_data[y+6][x])*StageI_VI;
00103 sum += 1<<(StageI_Shift-1);
00104 m_row_buffer[x] = sum >> StageI_Shift;
00105 }
00106
00107 RowLoop( colpos , old_data , new_data );
00108 }
00109
00110
00111
00112
00113
00114 for( int y=ylen-(Stage_I_Size*2) ; y<ylen-1 ; y+=2 , colpos++ )
00115 {
00116 for( int x=0; x<xlen ; x++ )
00117 {
00118
00119 sum = (old_data[y][x] + old_data[((y+1)<ylen)?(y+1):(ylen-1)][x])*StageI_I;
00120 sum += (old_data[y-1][x] + old_data[((y+2)<ylen)?(y+2):(ylen-1)][x])*StageI_II;
00121 sum += (old_data[y-2][x] + old_data[((y+3)<ylen)?(y+3):(ylen-1)][x])*StageI_III;
00122 sum += (old_data[y-3][x] + old_data[((y+4)<ylen)?(y+4):(ylen-1)][x])*StageI_IV;
00123 sum += (old_data[y-4][x] + old_data[((y+5)<ylen)?(y+5):(ylen-1)][x])*StageI_V;
00124 sum += (old_data[y-5][x] + old_data[((y+6)<ylen)?(y+6):(ylen-1)][x])*StageI_VI;
00125
00126
00127 sum += 1<<(StageI_Shift-1);
00128 m_row_buffer[x] = sum >> StageI_Shift;
00129
00130 }
00131
00132 RowLoop( colpos , old_data , new_data );
00133
00134 }
00135
00136
00137 delete[] m_row_buffer;
00138
00139 }
00140
00141
00142
00143
00144 void DownConverter::RowLoop( const int colpos , const PicArray& old_data , PicArray& new_data)
00145 {
00146
00147
00148 int sum;
00149 const int xlen = 2*new_data.LengthX();
00150 int linepos=0;
00151
00152
00153
00154
00155
00156
00157 for( int x=0; x<(2*Stage_I_Size) ; x+=2 , linepos++ )
00158 {
00159 sum = (m_row_buffer[((x)>=0)?(x):0] + m_row_buffer[x+1])*StageI_I;
00160 sum += (m_row_buffer[((x-1)>=0)?(x-1):0] + m_row_buffer[x+2])*StageI_II;
00161 sum += (m_row_buffer[((x-2)>=0)?(x-2):0] + m_row_buffer[x+3])*StageI_III;
00162 sum += (m_row_buffer[((x-3)>=0)?(x-3):0] + m_row_buffer[x+4])*StageI_IV;
00163 sum += (m_row_buffer[((x-4)>=0)?(x-4):0] + m_row_buffer[x+5])*StageI_V;
00164 sum += (m_row_buffer[((x-5)>=0)?(x-5):0] + m_row_buffer[x+6])*StageI_VI;
00165 sum += 1<<(StageI_Shift-1);
00166
00167 new_data[colpos][linepos] = sum >> StageI_Shift;
00168
00169 }
00170
00171 for( int x=(2*Stage_I_Size) ; x<xlen-(2*Stage_I_Size) ; x+=2 , linepos++)
00172 {
00173 sum = (m_row_buffer[x] + m_row_buffer[x+1])*StageI_I;
00174 sum += (m_row_buffer[x-1] + m_row_buffer[x+2])*StageI_II;
00175 sum += (m_row_buffer[x-2] + m_row_buffer[x+3])*StageI_III;
00176 sum += (m_row_buffer[x-3] + m_row_buffer[x+4])*StageI_IV;
00177 sum += (m_row_buffer[x-4] + m_row_buffer[x+5])*StageI_V;
00178 sum += (m_row_buffer[x-5] + m_row_buffer[x+6])*StageI_VI;
00179 sum += 1<<(StageI_Shift-1);
00180
00181 new_data[colpos][linepos] = sum >> StageI_Shift;
00182
00183 }
00184
00185 for( int x=xlen-(2*Stage_I_Size) ; x< xlen-1 ; x+=2 , linepos++ )
00186 {
00187 sum = (m_row_buffer[x] + m_row_buffer[((x+1)<xlen)?(x+1):(xlen-1)])*StageI_I;
00188 sum += (m_row_buffer[x-1] + m_row_buffer[((x+2)<xlen)?(x+2):(xlen-1)])*StageI_II;
00189 sum += (m_row_buffer[x-2] + m_row_buffer[((x+3)<xlen)?(x+3):(xlen-1)])*StageI_III;
00190 sum += (m_row_buffer[x-3] + m_row_buffer[((x+4)<xlen)?(x+4):(xlen-1)])*StageI_IV;
00191 sum += (m_row_buffer[x-4] + m_row_buffer[((x+5)<xlen)?(x+5):(xlen-1)])*StageI_V;
00192 sum += (m_row_buffer[x-5] + m_row_buffer[((x+6)<xlen)?(x+6):(xlen-1)])*StageI_VI;
00193 sum += 1<<(StageI_Shift-1);
00194
00195 new_data[colpos][linepos] = sum >> StageI_Shift;
00196
00197 }
00198
00199 }