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
00040 #include <libdirac_common/frame.h>
00041 #include <libdirac_common/upconvert.h>
00042 using namespace dirac;
00043
00044 #include <iostream>
00045
00047
00049
00050 Frame::Frame(const FrameParams& fp):
00051 m_fparams(fp),
00052 m_Y_data(0),
00053 m_U_data(0),
00054 m_V_data(0),
00055 m_upY_data(0),
00056 m_upU_data(0),
00057 m_upV_data(0)
00058 {
00059 Init();
00060 }
00061
00062 Frame::Frame( const Frame& cpy ):
00063 m_fparams(cpy.m_fparams),
00064 m_Y_data(0),
00065 m_U_data(0),
00066 m_V_data(0),
00067 m_upY_data(0),
00068 m_upU_data(0),
00069 m_upV_data(0)
00070 {
00071 const ChromaFormat& cformat = m_fparams.CFormat();
00072
00073
00074 ClearData();
00075
00076
00077 m_Y_data = new PicArray( *(cpy.m_Y_data) );
00078 if (cpy.m_upY_data != 0){
00079 m_upY_data = new PicArray( *(cpy.m_upY_data) );
00080 }
00081
00082 if (cformat != Yonly)
00083 {
00084 m_U_data = new PicArray( *(cpy.m_U_data) );
00085 m_V_data = new PicArray( *(cpy.m_V_data) );
00086
00087 if ( cpy.m_upU_data != 0 )
00088 {
00089 m_upU_data = new PicArray( *(cpy.m_upU_data) );
00090 }
00091 if ( cpy.m_upV_data != 0 )
00092 {
00093 m_upV_data = new PicArray( *(cpy.m_upV_data) );
00094 }
00095
00096 }
00097
00098 }
00099
00100
00101 Frame::~Frame()
00102 {
00103 ClearData();
00104 }
00105
00106 Frame& Frame::operator=(const Frame& rhs)
00107 {
00108 if ( &rhs != this)
00109 {
00110 m_fparams=rhs.m_fparams;
00111 const ChromaFormat& cformat=m_fparams.CFormat();
00112
00113
00114 ClearData();
00115
00116
00117 m_Y_data= new PicArray( *(rhs.m_Y_data) );
00118
00119 if ( rhs.m_upY_data != 0)
00120 m_upY_data = new PicArray( *(rhs.m_upY_data) );
00121
00122 if (cformat != Yonly)
00123 {
00124 m_U_data= new PicArray( *(rhs.m_U_data) );
00125 if (rhs.m_upU_data!=0)
00126 m_upU_data = new PicArray(*(rhs.m_upU_data) );
00127
00128 m_V_data= new PicArray( *(rhs.m_V_data) );
00129 if (rhs.m_upV_data!=0)
00130 m_upV_data= new PicArray( *(rhs.m_upV_data) );
00131 }
00132 }
00133
00134 return *this;
00135
00136 }
00137
00138
00139
00140 void Frame::Init()
00141 {
00142 const ChromaFormat cformat=m_fparams.CFormat();
00143
00144
00145 ClearData();
00146
00147 m_Y_data=new PicArray( m_fparams.Yl() , m_fparams.Xl());
00148 m_Y_data->SetCSort( Y_COMP );
00149
00150 if(cformat == format422)
00151 {
00152 m_U_data = new PicArray( m_fparams.Yl() , m_fparams.Xl()/2 );
00153 m_U_data->SetCSort( U_COMP );
00154
00155 m_V_data = new PicArray( m_fparams.Yl() , m_fparams.Xl()/2 );
00156 m_V_data->SetCSort( V_COMP );
00157 }
00158 else if (cformat == format420)
00159 {
00160 m_U_data = new PicArray( m_fparams.Yl()/2 , m_fparams.Xl()/2 );
00161 m_U_data->SetCSort( U_COMP );
00162
00163 m_V_data = new PicArray( m_fparams.Yl()/2 , m_fparams.Xl()/2 );
00164 m_V_data->SetCSort(V_COMP);
00165 }
00166 else if (cformat == format411)
00167 {
00168 m_U_data = new PicArray( m_fparams.Yl() , m_fparams.Xl()/4 );
00169 m_U_data->SetCSort( U_COMP );
00170
00171 m_V_data = new PicArray( m_fparams.Yl() , m_fparams.Xl()/4 );
00172 m_V_data->SetCSort( V_COMP );
00173 }
00174 else if (cformat==format444){
00175 m_U_data = new PicArray( m_fparams.Yl() , m_fparams.Xl() );
00176 m_U_data->SetCSort( U_COMP );
00177
00178 m_V_data = new PicArray( m_fparams.Yl() , m_fparams.Xl() );
00179 m_V_data->SetCSort( V_COMP );
00180 }
00181
00182 }
00183
00184 PicArray& Frame::Data(CompSort cs)
00185 {
00186
00187 if (cs == U_COMP) return *m_U_data;
00188 else if (cs == V_COMP) return *m_V_data;
00189 else return *m_Y_data;
00190 }
00191
00192 const PicArray& Frame::Data(CompSort cs) const
00193 {
00194
00195 if (cs == U_COMP) return *m_U_data;
00196 else if (cs == V_COMP) return *m_V_data;
00197 else return *m_Y_data;
00198 }
00199
00200 PicArray& Frame::UpYdata()
00201 {
00202 if (m_upY_data != 0)
00203 return *m_upY_data;
00204 else
00205 {
00206
00207 m_upY_data = new PicArray( 2*m_Y_data->LengthY() , 2*m_Y_data->LengthX() );
00208 UpConverter myupconv;
00209 myupconv.DoUpConverter( *m_Y_data , *m_upY_data );
00210
00211 return *m_upY_data;
00212
00213 }
00214 }
00215
00216 PicArray& Frame::UpUdata()
00217 {
00218 if (m_upU_data != 0)
00219 return *m_upU_data;
00220 else
00221 {
00222
00223 m_upU_data = new PicArray(2*m_U_data->LengthY() , 2*m_U_data->LengthX());
00224 UpConverter myupconv;
00225 myupconv.DoUpConverter( *m_U_data , *m_upU_data );
00226
00227 return *m_upU_data;
00228
00229 }
00230 }
00231
00232 PicArray& Frame::UpVdata()
00233 {
00234 if (m_upV_data != 0)
00235 return *m_upV_data;
00236 else
00237 {
00238
00239 m_upV_data = new PicArray( 2*m_V_data->LengthY() , 2*m_V_data->LengthX() );
00240 UpConverter myupconv;
00241 myupconv.DoUpConverter( *m_V_data , *m_upV_data );
00242
00243 return *m_upV_data;
00244
00245 }
00246 }
00247
00248 PicArray& Frame::UpData(CompSort cs)
00249 {
00250 if (cs == U_COMP)
00251 return UpUdata();
00252 else if (cs == V_COMP)
00253 return UpVdata();
00254 else
00255 return UpYdata();
00256 }
00257
00258 const PicArray& Frame::UpYdata() const
00259 {
00260 if (m_upY_data != 0)
00261 return *m_upY_data;
00262 else
00263 {
00264
00265
00266
00267
00268
00269 m_upY_data = new PicArray( 2*m_Y_data->LengthY() , 2*m_Y_data->LengthX() );
00270
00271 UpConverter myupconv;
00272 myupconv.DoUpConverter( *m_Y_data , *m_upY_data );
00273
00274 return *m_upY_data;
00275
00276 }
00277 }
00278
00279 const PicArray& Frame::UpUdata() const
00280 {
00281 if (m_upU_data != 0)
00282 return *m_upU_data;
00283 else
00284 {
00285
00286
00287
00288
00289
00290 m_upU_data = new PicArray( 2*m_U_data->LengthY() , 2*m_U_data->LengthX() );
00291
00292 UpConverter myupconv;
00293 myupconv.DoUpConverter( *m_U_data , *m_upU_data );
00294
00295 return *m_upU_data;
00296
00297 }
00298 }
00299
00300 const PicArray& Frame::UpVdata() const
00301 {
00302 if (m_upV_data != 0)
00303 return *m_upV_data;
00304 else
00305 {
00306
00307
00308
00309
00310
00311 m_upV_data = new PicArray( 2*m_V_data->LengthY() , 2*m_V_data->LengthX() );
00312
00313 UpConverter myupconv;
00314 myupconv.DoUpConverter( *m_V_data , *m_upV_data );
00315
00316 return *m_upV_data;
00317
00318 }
00319 }
00320
00321 const PicArray& Frame::UpData(CompSort cs) const
00322 {
00323 if (cs == U_COMP)
00324 return UpUdata();
00325 else if (cs == V_COMP)
00326 return UpVdata();
00327 else
00328 return UpYdata();
00329 }
00330
00331 void Frame::ClipComponent(PicArray& pic_data)
00332 {
00333 for (int j=pic_data.FirstY() ; j<=pic_data.LastY() ; ++j)
00334 {
00335 for (int i=pic_data.FirstX() ; i<=pic_data.LastX() ; ++i)
00336 {
00337 pic_data[j][i] = std::min( pic_data[j][i] , ValueType( 1020 ) );
00338 pic_data[j][i] = std::max( pic_data[j][i] , ValueType( 0 ) );
00339 }
00340 }
00341 }
00342
00343 void Frame::Clip()
00344 {
00345
00346
00347 ClipComponent( *m_Y_data );
00348
00349 if (m_fparams.CFormat() != Yonly)
00350 {
00351 ClipComponent( *m_U_data );
00352 ClipComponent( *m_V_data );
00353 }
00354 }
00355
00356 void Frame::ClearData()
00357 {
00358 if (m_Y_data != 0)
00359 {
00360 delete m_Y_data;
00361 m_Y_data = 0;
00362 }
00363
00364 if (m_U_data!=0)
00365 {
00366 delete m_U_data;
00367 m_U_data = 0;
00368 }
00369
00370 if (m_V_data!=0)
00371 {
00372 delete m_V_data;
00373 m_V_data = 0;
00374 }
00375
00376 if (m_upY_data != 0)
00377 {
00378 delete m_upY_data;
00379 m_upY_data = 0;
00380 }
00381
00382 if (m_upU_data!=0)
00383 {
00384 delete m_upU_data;
00385 m_upU_data = 0;
00386 }
00387
00388 if (m_upV_data != 0)
00389 {
00390 delete m_upV_data;
00391 m_upV_data = 0;
00392 }
00393 }