1 /* ***** BEGIN LICENSE BLOCK *****
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
20 * Portions created by the Initial Developer are Copyright (C) 2004.
21 * All Rights Reserved.
23 * Contributor(s): Thomas Davies (Original Author),
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
40 * ***** END LICENSE BLOCK ***** */
43 //Compression of an individual component,
44 //after motion compensation if appropriate
45 //////////////////////////////////////////
47 #include <libdirac_encoder/comp_compress.h>
48 #include <libdirac_common/band_codec.h>
49 #include <libdirac_common/band_vlc.h>
50 #include <libdirac_common/motion.h>
52 using namespace dirac
;
58 CompCompressor::CompCompressor( EncoderParams
& encp
,const PictureParams
& pp
)
61 m_psort( m_pparams
.PicSort() ),
62 m_cformat( m_pparams
.CFormat() )
65 ComponentByteIO
* CompCompressor::Compress( CoeffArray
& coeff_data
,
68 const OneDArray
<unsigned int>& estimated_bits
)
70 // Need to transform, select quantisers for each band,
71 // and then compress each component in turn
73 unsigned int num_band_bytes( 0 );
76 ComponentByteIO
*p_component_byteio
= new ComponentByteIO(csort
);
78 // Loop over all the bands (from DC to HF) quantising and coding them
79 for (int b
=bands
.Length() ; b
>=1 ; --b
)
82 // create subband byte io
83 SubbandByteIO
subband_byteio(bands(b
));
85 if ( !bands(b
).Skipped() )
86 { // If not skipped ...
87 if (m_pparams
.UsingAC())
89 // A pointer to an object for coding the subband data
93 // Pick the right codec according to the picture type and subband
94 if (b
>= bands
.Length()-3)
96 if ( m_psort
.IsIntra() && b
== bands
.Length() )
97 bcoder
=new IntraDCBandCodec(&subband_byteio
,
98 TOTAL_COEFF_CTXS
, bands
);
100 bcoder
=new LFBandCodec(&subband_byteio
,TOTAL_COEFF_CTXS
,
101 bands
, b
, m_psort
.IsIntra());
104 bcoder
=new BandCodec(&subband_byteio
, TOTAL_COEFF_CTXS
,
105 bands
, b
, m_psort
.IsIntra() );
107 num_band_bytes
= bcoder
->Compress(coeff_data
);
114 // A pointer to an object for coding the subband data
117 if ( m_psort
.IsIntra() && b
== bands
.Length() )
118 bcoder
=new IntraDCBandVLC(&subband_byteio
, bands
);
120 bcoder
=new BandVLC(&subband_byteio
, bands
, b
,
123 num_band_bytes
= bcoder
->Compress(coeff_data
);
127 // Update the entropy correction factors
128 m_encparams
.EntropyFactors().Update(b
, m_pparams
, csort
,
129 estimated_bits
[b
] , 8*num_band_bytes
);
133 SetToVal( coeff_data
, bands(b
) , 0 );
136 // output sub-band data
137 p_component_byteio
->AddSubband(&subband_byteio
);
142 return p_component_byteio
;
145 void CompCompressor::SetToVal(CoeffArray
& coeff_data
,const Subband
& node
,ValueType val
)
148 for (int j
=node
.Yp() ; j
<node
.Yp() + node
.Yl() ; ++j
)
150 for (int i
=node
.Xp(); i
<node
.Xp() + node
.Xl() ; ++i
)
152 coeff_data
[j
][i
] = val
;