- Main Page
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

# frame.cpp

    00001 /* ***** BEGIN LICENSE BLOCK *****
    00002 *
    00003 * $Id: frame.cpp,v 1.2 2005/01/30 05:11:40 gabest Exp $ $Name:  $
    00004 *
    00005 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
    00006 *
    00007 * The contents of this file are subject to the Mozilla Public License
    00008 * Version 1.1 (the "License"); you may not use this file except in compliance
    00009 * with the License. You may obtain a copy of the License at
    00010 * http://www.mozilla.org/MPL/
    00011 *
    00012 * Software distributed under the License is distributed on an "AS IS" basis,
    00013 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
    00014 * the specific language governing rights and limitations under the License.
    00015 *
    00016 * The Original Code is BBC Research and Development code.
    00017 *
    00018 * The Initial Developer of the Original Code is the British Broadcasting
    00019 * Corporation.
    00020 * Portions created by the Initial Developer are Copyright (C) 2004.
    00021 * All Rights Reserved.
    00022 *
    00023 * Contributor(s): Thomas Davies (Original Author)
    00024 *
    00025 * Alternatively, the contents of this file may be used under the terms of
    00026 * the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
    00027 * Public License Version 2.1 (the "LGPL"), in which case the provisions of
    00028 * the GPL or the LGPL are applicable instead of those above. If you wish to
    00029 * allow use of your version of this file only under the terms of the either
    00030 * the GPL or LGPL and not to allow others to use your version of this file
    00031 * under the MPL, indicate your decision by deleting the provisions above
    00032 * and replace them with the notice and other provisions required by the GPL
    00033 * or LGPL. If you do not delete the provisions above, a recipient may use
    00034 * your version of this file under the terms of any one of the MPL, the GPL
    00035 * or the LGPL.
    00036 * ***** END LICENSE BLOCK ***** */
    00037
    00038 //Implementation of frame classes in frame.h
    00039
    00040 #include <libdirac_common/frame.h>
    00041 #include <libdirac_common/upconvert.h>
    00042 using namespace dirac;
    00043
    00044 #include <iostream>
    00045
    00047 //---Frame---//
    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     //delete data to be overwritten
    00074     ClearData();
    00075
    00076     //now copy the data accross
    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         // Delete current data
    00114         ClearData();
    00115
    00116         // Copy the data across
    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 //Other functions
    00139
    00140 void Frame::Init()
    00141 {
    00142     const ChromaFormat cformat=m_fparams.CFormat();
    00143
    00144     //first delete data if we need to
    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     //(other formats all assumed to be Yonly
    00182 }
    00183
    00184 PicArray& Frame::Data(CompSort cs)
    00185 {//another way to access the data
    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 {//another way to access the data
    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     {//we have to do the upconversion
    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     {//we have to do the upconversion
    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     {//we have to do the upconversion
    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         //We have to do the upconversion
    00265         //Although we're changing a value - the pointer to the array - it doesn't affect the state of
    00266         //the object as viewable from outside. So the pointers to the upconveted data have been
    00267         //declared mutable.
    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         //We have to do the upconversion
    00286         //Although we're changing a value - the pointer to the array - it doesn't affect the state of
    00287         //the object as viewable from outside. So the pointers to the upconveted data have been
    00288         //declared mutable.
    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         //We have to do the upconversion
    00307         //Although we're changing a value - the pointer to the array - it doesn't affect the state of
    00308         //the object as viewable from outside. So the pointers to the upconveted data have been
    00309         //declared mutable.
    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         }// i
    00340     }// j
    00341 }
    00342
    00343 void Frame::Clip()
    00344 {
    00345     //just clips the straight picture data, not the upconverted data
    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 }