Updating Contact email
[BrunelResearch-dirac.git] / libdirac_decoder / comp_decompress.cpp
blob472f354bfd39c70b872fc50492e765055d7aa77f
1 /* ***** BEGIN LICENSE BLOCK *****
3 * $Id$ $Name$
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License
8 * Version 1.1 (the "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
14 * the specific language governing rights and limitations under the License.
16 * The Original Code is BBC Research and Development code.
18 * The Initial Developer of the Original Code is the British Broadcasting
19 * Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 2004.
21 * All Rights Reserved.
23 * Contributor(s): Thomas Davies (Original Author),
24 * Scott R Ladd,
25 * Anuradha Suraparaju,
26 * Andrew Kennedy,
27 * Tim Borer
29 * Alternatively, the contents of this file may be used under the terms of
30 * the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
31 * Public License Version 2.1 (the "LGPL"), in which case the provisions of
32 * the GPL or the LGPL are applicable instead of those above. If you wish to
33 * allow use of your version of this file only under the terms of the either
34 * the GPL or LGPL and not to allow others to use your version of this file
35 * under the MPL, indicate your decision by deleting the provisions above
36 * and replace them with the notice and other provisions required by the GPL
37 * or LGPL. If you do not delete the provisions above, a recipient may use
38 * your version of this file under the terms of any one of the MPL, the GPL
39 * or the LGPL.
40 * ***** END LICENSE BLOCK ***** */
43 #include <libdirac_decoder/comp_decompress.h>
44 #include <libdirac_common/wavelet_utils.h>
45 #include <libdirac_common/band_codec.h>
46 #include <libdirac_common/band_vlc.h>
47 using namespace dirac;
49 #include <vector>
51 #include <ctime>
53 using std::vector;
55 //Constructor
56 CompDecompressor::CompDecompressor( DecoderParams& decp, const PictureParams& pp)
58 m_decparams(decp),
59 m_pparams(pp),
60 m_psort( pp.PicSort() )
64 void CompDecompressor::Decompress(ComponentByteIO* p_component_byteio,
65 CoeffArray& coeff_data,
66 SubbandList& bands)
69 // Set up the code blocks
70 SetupCodeBlocks( bands );
72 for ( int b=bands.Length() ; b>=1 ; --b ){
73 // Multiple quantiser are used only if
74 // a. The global code_block_mode is QUANT_MULTIPLE
75 // and
76 // b. More than one code block is present in the subband.
77 bands(b).SetUsingMultiQuants(
78 m_decparams.SpatialPartition() &&
79 m_decparams.GetCodeBlockMode() == QUANT_MULTIPLE &&
80 (bands(b).GetCodeBlocks().LengthX() > 1 ||
81 bands(b).GetCodeBlocks().LengthY() > 1)
84 // Read the header data first
85 SubbandByteIO subband_byteio(bands(b), *p_component_byteio);
86 subband_byteio.Input();
88 if ( !bands(b).Skipped() ){
89 if (m_pparams.UsingAC()){
90 // A pointer to the object(s) we'll be using for coding the bands
91 BandCodec* bdecoder;
93 if ( b>=bands.Length()-3){
94 if ( m_psort.IsIntra() && b==bands.Length() )
95 bdecoder=new IntraDCBandCodec(&subband_byteio,
96 TOTAL_COEFF_CTXS ,bands);
97 else
98 bdecoder=new LFBandCodec(&subband_byteio ,
99 TOTAL_COEFF_CTXS, bands ,
100 b, m_psort.IsIntra());
102 else
103 bdecoder=new BandCodec( &subband_byteio , TOTAL_COEFF_CTXS ,
104 bands , b, m_psort.IsIntra());
106 bdecoder->Decompress(coeff_data , subband_byteio.GetBandDataLength());
107 delete bdecoder;
109 else{
110 // A pointer to the object(s) we'll be using for coding the bands
111 BandVLC* bdecoder;
113 if ( m_psort.IsIntra() && b==bands.Length() )
114 bdecoder=new IntraDCBandVLC(&subband_byteio, bands);
115 else
116 bdecoder=new BandVLC( &subband_byteio , bands ,
117 b, m_psort.IsIntra());
119 bdecoder->Decompress(coeff_data , subband_byteio.GetBandDataLength());
120 delete bdecoder;
123 else{
124 SetToVal( coeff_data , bands(b) , 0 );
129 void CompDecompressor::SetupCodeBlocks( SubbandList& bands )
131 int xregions;
132 int yregions;
134 for (int band_num = 1; band_num<=bands.Length() ; ++band_num)
136 if (m_decparams.SpatialPartition())
138 int level = m_decparams.TransformDepth() - (band_num-1)/3;
139 const CodeBlocks &cb = m_decparams.GetCodeBlocks(level);
140 xregions = cb.HorizontalCodeBlocks();
141 yregions = cb.VerticalCodeBlocks();
143 else
145 xregions = 1;
146 yregions = 1;
149 bands( band_num ).SetNumBlocks( yregions ,xregions );
151 }// band_num
154 void CompDecompressor::SetToVal( CoeffArray& coeff_data ,
155 const Subband& node ,
156 CoeffType val )
159 for (int j=node.Yp() ; j<node.Yp()+node.Yl() ; ++j)
160 for (int i=node.Xp() ; i<node.Xp()+node.Xl() ; ++i)
161 coeff_data[j][i]=val;