corrade-vassal – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 1 /*
2 * CVS identifier:
3 *
4 * $Id: LayersInfo.java,v 1.7 2001/04/15 14:31:22 grosbois Exp $
5 *
6 * Class: LayersInfo
7 *
8 * Description: Specification of a layer
9 *
10 *
11 *
12 * COPYRIGHT:
13 *
14 * This software module was originally developed by Raphaël Grosbois and
15 * Diego Santa Cruz (Swiss Federal Institute of Technology-EPFL); Joel
16 * Askelöf (Ericsson Radio Systems AB); and Bertrand Berthelot, David
17 * Bouchard, Félix Henry, Gerard Mozelle and Patrice Onno (Canon Research
18 * Centre France S.A) in the course of development of the JPEG2000
19 * standard as specified by ISO/IEC 15444 (JPEG 2000 Standard). This
20 * software module is an implementation of a part of the JPEG 2000
21 * Standard. Swiss Federal Institute of Technology-EPFL, Ericsson Radio
22 * Systems AB and Canon Research Centre France S.A (collectively JJ2000
23 * Partners) agree not to assert against ISO/IEC and users of the JPEG
24 * 2000 Standard (Users) any of their rights under the copyright, not
25 * including other intellectual property rights, for this software module
26 * with respect to the usage by ISO/IEC and Users of this software module
27 * or modifications thereof for use in hardware or software products
28 * claiming conformance to the JPEG 2000 Standard. Those intending to use
29 * this software module in hardware or software products are advised that
30 * their use may infringe existing patents. The original developers of
31 * this software module, JJ2000 Partners and ISO/IEC assume no liability
32 * for use of this software module or modifications thereof. No license
33 * or right to this software module is granted for non JPEG 2000 Standard
34 * conforming products. JJ2000 Partners have full right to use this
35 * software module for his/her own purpose, assign or donate this
36 * software module to any third party and to inhibit third parties from
37 * using this software module for non JPEG 2000 Standard conforming
38 * products. This copyright notice must be included in all copies or
39 * derivative works of this software module.
40 *
41 * Copyright (c) 1999/2000 JJ2000 Partners.
42 * */
43 using System;
44 namespace CSJ2K.j2k.entropy.encoder
45 {
46  
47 /// <summary> This class stores the specification of a layer distribution in the bit
48 /// stream. The specification is made of optimization points and a number of
49 /// extra layers to add between the optimization points. Each optimization
50 /// point creates a layer which is optimized by the rate allocator to the
51 /// specified target bitrate. The extra layers are added by the rate allocator
52 /// between the optimized layers, with the difference that they are not
53 /// optimized (i.e. they have no precise target bitrate).
54 ///
55 /// <p>The overall target bitrate for the bit stream is always added as the
56 /// last optimization point without any extra layers after it. If there are
57 /// some optimization points whose target bitrate is larger than the overall
58 /// target bitrate, the overall target bitrate will still appear as the last
59 /// optimization point, even though it does not follow the increasing target
60 /// bitrate order of the other optimization points. The rate allocator is
61 /// responsible for eliminating layers that have target bitrates larger than
62 /// the overall target bitrate.</p>
63 ///
64 /// <p>Optimization points can be added with the addOptPoint() method. It takes
65 /// the target bitrate for the optimized layer and the number of extra layers
66 /// to add after it.</p>
67 ///
68 /// <p>Information about the total number of layers, total number of
69 /// optimization points, target bitrates, etc. can be obtained with the other
70 /// methods.</p>
71 ///
72 /// </summary>
73 public class LayersInfo
74 {
75 /// <summary> Returns the overall target bitrate for the entire bit stream.
76 ///
77 /// </summary>
78 /// <returns> The overall target bitrate
79 ///
80 /// </returns>
81 virtual public float TotBitrate
82 {
83 get
84 {
85 return totbrate;
86 }
87  
88 }
89 /// <summary> Returns the total number of layers, according to the layer
90 /// specification of this object and the overall target bitrate.
91 ///
92 /// </summary>
93 /// <returns> The total number of layers, according to the layer spec.
94 ///
95 /// </returns>
96 virtual public int TotNumLayers
97 {
98 get
99 {
100 return totlyrs;
101 }
102  
103 }
104 /// <summary> Returns the number of layers to optimize, or optimization points, as
105 /// specified by this object.
106 ///
107 /// </summary>
108 /// <returns> The number of optimization points
109 ///
110 /// </returns>
111 virtual public int NOptPoints
112 {
113 get
114 {
115 // overall target bitrate is counted as extra
116 return nopt + 1;
117 }
118  
119 }
120  
121 /// <summary>The initial size for the arrays: 10 </summary>
122 private const int SZ_INIT = 10;
123  
124 /// <summary>The size increment for the arrays </summary>
125 private const int SZ_INCR = 5;
126  
127 /// <summary>The total number of layers </summary>
128 // Starts at 1: overall target bitrate is always an extra optimized layer
129 internal int totlyrs = 1;
130  
131 /// <summary>The overall target bitrate, for the whole bit stream </summary>
132 internal float totbrate;
133  
134 /// <summary>The number of optimized layers, or optimization points, without
135 /// counting the extra one coming from the overall target bitrate
136 /// </summary>
137 internal int nopt;
138  
139 /// <summary>The target bitrate to which specified layers should be optimized. </summary>
140 internal float[] optbrate = new float[SZ_INIT];
141  
142 /// <summary>The number of extra layers to be added after an optimized layer. After
143 /// the layer that is optimized to optbrate[i], extralyrs[i] extra layers
144 /// should be added. These layers are allocated between the bitrate
145 /// optbrate[i] and the next optimized bitrate optbrate[i+1] or, if it does
146 /// not exist, the overall target bitrate.
147 /// </summary>
148 internal int[] extralyrs = new int[SZ_INIT];
149  
150 /// <summary> Creates a new LayersInfo object. The overall target bitrate 'brate' is
151 /// always an extra optimization point, with no extra layers are after
152 /// it. Note that any optimization points that are added with addOptPoint()
153 /// are always added before the overall target bitrate.
154 ///
155 /// </summary>
156 /// <param name="brate">The overall target bitrate for the bit stream
157 ///
158 /// </param>
159 public LayersInfo(float brate)
160 {
161 if (brate <= 0)
162 {
163 throw new System.ArgumentException("Overall target bitrate must " + "be a positive number");
164 }
165 totbrate = brate;
166 }
167  
168 /// <summary> Returns the target bitrate of the optmimization point 'n'.
169 ///
170 /// </summary>
171 /// <param name="n">The optimization point index (starts at 0).
172 ///
173 /// </param>
174 /// <returns> The target bitrate (in bpp) for the optimization point 'n'.
175 ///
176 /// </returns>
177 public virtual float getTargetBitrate(int n)
178 {
179 // overall target bitrate is counted as extra
180 return (n < nopt)?optbrate[n]:totbrate;
181 }
182  
183 /// <summary> Returns the number of extra layers to add after the optimization point
184 /// 'n', but before optimization point 'n+1'. If there is no optimization
185 /// point 'n+1' then they should be added before the overall target
186 /// bitrate.
187 ///
188 /// </summary>
189 /// <param name="n">The optimization point index (starts at 0).
190 ///
191 /// </param>
192 /// <returns> The number of extra (unoptimized) layers to add after the
193 /// optimization point 'n'
194 ///
195 /// </returns>
196 public virtual int getExtraLayers(int n)
197 {
198 // overall target bitrate is counted as extra
199 return (n < nopt)?extralyrs[n]:0;
200 }
201  
202 /// <summary> Adds a new optimization point, with target bitrate 'brate' and with
203 /// 'elyrs' (unoptimized) extra layers after it. The target bitrate 'brate'
204 /// must be larger than the previous optimization point. The arguments are
205 /// checked and IllegalArgumentException is thrown if they are not correct.
206 ///
207 /// </summary>
208 /// <param name="brate">The target bitrate for the optimized layer.
209 ///
210 /// </param>
211 /// <param name="elyrs">The number of extra (unoptimized) layers to add after the
212 /// optimized layer.
213 ///
214 /// </param>
215 public virtual void addOptPoint(float brate, int elyrs)
216 {
217 // Check validity of arguments
218 if (brate <= 0)
219 {
220 throw new System.ArgumentException("Target bitrate must be positive");
221 }
222 if (elyrs < 0)
223 {
224 throw new System.ArgumentException("The number of extra layers " + "must be 0 or more");
225 }
226 if (nopt > 0 && optbrate[nopt - 1] >= brate)
227 {
228 throw new System.ArgumentException("New optimization point must have " + "a target bitrate higher than the " + "preceding one");
229 }
230 // Check room for new optimization point
231 if (optbrate.Length == nopt)
232 {
233 // Need more room
234 float[] tbr = optbrate;
235 int[] tel = extralyrs;
236 // both arrays always have same size
237 optbrate = new float[optbrate.Length + SZ_INCR];
238 extralyrs = new int[extralyrs.Length + SZ_INCR];
239 Array.Copy(tbr, 0, optbrate, 0, nopt);
240 Array.Copy(tel, 0, extralyrs, 0, nopt);
241 }
242 // Add new optimization point
243 optbrate[nopt] = brate;
244 extralyrs[nopt] = elyrs;
245 nopt++;
246 // Update total number of layers
247 totlyrs += 1 + elyrs;
248 }
249 }
250 }