- Main Page
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

# comp_decompress.cpp

    00001 /* ***** BEGIN LICENSE BLOCK *****
    00002 *
    00003 * $Id: comp_decompress.cpp,v 1.2 2005/01/30 05:11:41 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), Scott R Ladd
    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
    00039 #include <libdirac_decoder/comp_decompress.h>
    00040 #include <libdirac_common/wavelet_utils.h>
    00041 #include <libdirac_common/band_codec.h>
    00042 #include <libdirac_common/golomb.h>
    00043 using namespace dirac;
    00044
    00045 #include <vector>
    00046
    00047 #include <ctime>
    00048
    00049 using std::vector;
    00050
    00051 //Constructor
    00052 CompDecompressor::CompDecompressor( DecoderParams& decp, const FrameParams& fp)
    00053 :
    00054 m_qflist(60),
    00055 m_decparams(decp),
    00056 m_fparams(fp)
    00057 {}
    00058
    00059
    00060 void CompDecompressor::Decompress(PicArray& pic_data)
    00061 {
    00062         const FrameSort& fsort=m_fparams.FSort();
    00063         const int depth=4;
    00064         BandCodec* bdecoder;
    00065     const size_t CONTEXTS_REQUIRED = 24;
    00066         Subband node;
    00067         unsigned int max_bits;
    00068         int qf_idx;
    00069
    00070         WaveletTransform wtransform(depth);
    00071         SubbandList& bands=wtransform.BandList();
    00072         bands.Init(depth , pic_data.LengthX() , pic_data.LengthY());
    00073
    00074         GenQuantList();
    00075
    00076         for (int I=bands.Length();I>=1;--I)
    00077         {
    00078
    00079                 //read the header data first
    00080                 qf_idx=GolombDecode( m_decparams.BitsIn() );
    00081                 if (qf_idx!=-1){
    00082                         bands(I).SetQf(0,m_qflist[qf_idx]);
    00083                         max_bits=UnsignedGolombDecode( m_decparams.BitsIn() );
    00084                         m_decparams.BitsIn().FlushInput();
    00085
    00086                         if (I>=bands.Length()){
    00087                                 if (fsort==I_frame && I==bands.Length())
    00088                                         bdecoder=new IntraDCBandCodec( &m_decparams.BitsIn() , CONTEXTS_REQUIRED ,bands);
    00089                                 else
    00090                                         bdecoder=new LFBandCodec( &m_decparams.BitsIn() , CONTEXTS_REQUIRED ,bands , I);
    00091                         }
    00092                         else
    00093                                 bdecoder=new BandCodec( &m_decparams.BitsIn() , CONTEXTS_REQUIRED , bands , I);
    00094
    00095                         bdecoder->InitContexts();
    00096                         bdecoder->Decompress(pic_data,max_bits);
    00097                         delete bdecoder;
    00098                 }
    00099                 else{
    00100                         m_decparams.BitsIn().FlushInput();
    00101                         if (I==bands.Length() && fsort==I_frame)
    00102                                 SetToVal(pic_data,bands(I),2692);
    00103                         else
    00104                                 SetToVal(pic_data,bands(I),0);
    00105                 }
    00106         }
    00107         wtransform.Transform(BACKWARD,pic_data);
    00108 }
    00109
    00110 void CompDecompressor::SetToVal(PicArray& pic_data,const Subband& node,ValueType val){
    00111         for (int J=node.Yp();J<node.Yp()+node.Yl();++J)
    00112         {
    00113                 for (int I=node.Xp();I<node.Xp()+node.Xl();++I)
    00114                 {
    00115                         pic_data[J][I]=val;
    00116                 }
    00117         }
    00118 }
    00119
    00120 void CompDecompressor::GenQuantList(){//generates the list of quantisers and inverse quantisers
    00121         //there is some repetition in this list but at the moment this is easiest from the perspective of SelectQuant
    00122         //Need to remove this repetition later TJD 29 March 04.
    00123
    00124         m_qflist[0]=1;
    00125         m_qflist[1]=1;
    00126         m_qflist[2]=1;
    00127         m_qflist[3]=1;
    00128         m_qflist[4]=2;
    00129         m_qflist[5]=2;
    00130         m_qflist[6]=2;
    00131         m_qflist[7]=3;
    00132         m_qflist[8]=4;
    00133         m_qflist[9]=4;
    00134         m_qflist[10]=5;
    00135         m_qflist[11]=6;
    00136         m_qflist[12]=8;
    00137         m_qflist[13]=9;
    00138         m_qflist[14]=11;
    00139         m_qflist[15]=13;
    00140         m_qflist[16]=16;
    00141         m_qflist[17]=19;
    00142         m_qflist[18]=22;
    00143         m_qflist[19]=26;
    00144         m_qflist[20]=32;
    00145         m_qflist[21]=38;
    00146         m_qflist[22]=45;
    00147         m_qflist[23]=53;
    00148         m_qflist[24]=64;
    00149         m_qflist[25]=76;
    00150         m_qflist[26]=90;
    00151         m_qflist[27]=107;
    00152         m_qflist[28]=128;
    00153         m_qflist[29]=152;
    00154         m_qflist[30]=181;
    00155         m_qflist[31]=215;
    00156         m_qflist[32]=256;
    00157         m_qflist[33]=304;
    00158         m_qflist[34]=362;
    00159         m_qflist[35]=430;
    00160         m_qflist[36]=512;
    00161         m_qflist[37]=608;
    00162         m_qflist[38]=724;
    00163         m_qflist[39]=861;
    00164         m_qflist[40]=1024;
    00165         m_qflist[41]=1217;
    00166         m_qflist[42]=1448;
    00167         m_qflist[43]=1722;
    00168         m_qflist[44]=2048;
    00169         m_qflist[45]=2435;
    00170         m_qflist[46]=2896;
    00171         m_qflist[47]=3444;
    00172         m_qflist[48]=4096;
    00173         m_qflist[49]=4870;
    00174         m_qflist[50]=5792;
    00175         m_qflist[51]=6888;
    00176         m_qflist[52]=8192;
    00177         m_qflist[53]=9741;
    00178         m_qflist[54]=11585;
    00179         m_qflist[55]=13777;
    00180         m_qflist[56]=16384;
    00181         m_qflist[57]=19483;
    00182         m_qflist[58]=23170;
    00183         m_qflist[59]=27554;
    00184 }