corrade-vassal – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 1 | /* |
2 | * CVS identifier: |
||
3 | * |
||
4 | * $Id: EntropyCoder.java,v 1.58 2001/09/20 12:40:30 grosbois Exp $ |
||
5 | * |
||
6 | * Class: EntropyCoder |
||
7 | * |
||
8 | * Description: The abstract class for entropy encoders |
||
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 | using CSJ2K.j2k.quantization.quantizer; |
||
45 | using CSJ2K.j2k.codestream.writer; |
||
46 | using CSJ2K.j2k.wavelet.analysis; |
||
47 | using CSJ2K.j2k.wavelet; |
||
48 | using CSJ2K.j2k.encoder; |
||
49 | using CSJ2K.j2k.entropy; |
||
50 | using CSJ2K.j2k.image; |
||
51 | using CSJ2K.j2k.util; |
||
52 | using CSJ2K.j2k.roi; |
||
53 | using CSJ2K.j2k; |
||
54 | namespace CSJ2K.j2k.entropy.encoder |
||
55 | { |
||
56 | |||
57 | /// <summary> This abstract class provides the general interface for block-based entropy |
||
58 | /// encoders. The input to the entropy coder is the quantized wavelet |
||
59 | /// coefficients, or codewords, represented in sign magnitude. The output is a |
||
60 | /// compressed code-block with rate-distortion information. |
||
61 | /// |
||
62 | /// <p>The source of data for objects of this class are 'CBlkQuantDataSrcEnc' |
||
63 | /// objects.</p> |
||
64 | /// |
||
65 | /// <p>For more details on the sign magnitude representation used see the |
||
66 | /// Quantizer class.</p> |
||
67 | /// |
||
68 | /// <p>This class provides default implemenations for most of the methods |
||
69 | /// (wherever it makes sense), under the assumption that the image and |
||
70 | /// component dimensions, and the tiles, are not modifed by the entropy |
||
71 | /// coder. If that is not the case for a particular implementation then the |
||
72 | /// methods should be overriden.</p> |
||
73 | /// |
||
74 | /// </summary> |
||
75 | /// <seealso cref="Quantizer"> |
||
76 | /// </seealso> |
||
77 | /// <seealso cref="CBlkQuantDataSrcEnc"> |
||
78 | /// |
||
79 | /// </seealso> |
||
80 | public abstract class EntropyCoder:ImgDataAdapter, CodedCBlkDataSrcEnc |
||
81 | { |
||
82 | /// <summary> Returns the horizontal offset of the code-block partition. Allowable |
||
83 | /// values are 0 and 1, nothing else. |
||
84 | /// |
||
85 | /// </summary> |
||
86 | virtual public int CbULX |
||
87 | { |
||
88 | get |
||
89 | { |
||
90 | return src.CbULX; |
||
91 | } |
||
92 | |||
93 | } |
||
94 | /// <summary> Returns the vertical offset of the code-block partition. Allowable |
||
95 | /// values are 0 and 1, nothing else. |
||
96 | /// |
||
97 | /// </summary> |
||
98 | virtual public int CbULY |
||
99 | { |
||
100 | get |
||
101 | { |
||
102 | return src.CbULY; |
||
103 | } |
||
104 | |||
105 | } |
||
106 | /// <summary> Returns the parameters that are used in this class and implementing |
||
107 | /// classes. It returns a 2D String array. Each of the 1D arrays is for a |
||
108 | /// different option, and they have 3 elements. The first element is the |
||
109 | /// option name, the second one is the synopsis, the third one is a long |
||
110 | /// description of what the parameter is and the fourth is its default |
||
111 | /// value. The synopsis or description may be 'null', in which case it is |
||
112 | /// assumed that there is no synopsis or description of the option, |
||
113 | /// respectively. Null may be returned if no options are supported. |
||
114 | /// |
||
115 | /// </summary> |
||
116 | /// <returns> the options name, their synopsis and their explanation, or null |
||
117 | /// if no options are supported. |
||
118 | /// |
||
119 | /// </returns> |
||
120 | public static System.String[][] ParameterInfo |
||
121 | { |
||
122 | get |
||
123 | { |
||
124 | return pinfo; |
||
125 | } |
||
126 | |||
127 | } |
||
128 | |||
129 | /// <summary>The prefix for entropy coder options: 'C' </summary> |
||
130 | public const char OPT_PREFIX = 'C'; |
||
131 | |||
132 | /// <summary>The list of parameters that is accepted for entropy coding. Options |
||
133 | /// for entropy coding start with 'C'. |
||
134 | /// </summary> |
||
135 | //UPGRADE_NOTE: Final was removed from the declaration of 'pinfo'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" |
||
136 | private static readonly System.String[][] pinfo = new System.String[][]{new System.String[]{"Cblksiz", "[<tile-component idx>] <width> <height> " + "[[<tile-component idx>] <width> <height>]", "Specifies the maximum code-block size to use for tile-component. " + "The maximum width and height is 1024, however the surface area " + "(i.e. width x height) must not exceed 4096. The minimum width and " + "height is 4.", "64 64"}, new System.String[]{"Cbypass", "[<tile-component idx>] on|off" + "[ [<tile-component idx>] on|off ...]", "Uses the lazy coding mode with the entropy coder. This will bypass " + "the MQ coder for some of the coding passes, where the distribution " + "is often close to uniform. Since the MQ codeword will be " + "terminated " + "at least once per lazy pass, it is important to use an efficient " + "termination algorithm, see the 'Cterm_type' option." + "'on' enables, 'off' disables it.", "off"}, new System.String[]{"CresetMQ", "[<tile-component idx>] on|off" + "[ [<tile-component idx>] on|off ...]", "If this is enabled the probability estimates of the MQ coder are " + "reset after each arithmetically coded (i.e. non-lazy) coding pass. " + "'on' enables, 'off' disables it.", "off"}, new System.String[]{"Cterminate", "[<tile-component idx>] on|off" + "[ [<tile-component idx>] on|off ...]", "If this is enabled the codeword (raw or MQ) is terminated on a " + "byte boundary after each coding pass. In this case it is important " + "to use an efficient termination algorithm, see the 'Cterm' option. " + "'on' enables, 'off' disables it.", "off"}, new System.String[]{"Ccausal", "[<tile-component idx>] on|off" + "[ [<tile-component idx>] on|off ...]", "Uses vertically stripe causal context formation. If this is " + "enabled " + "the context formation process in one stripe is independant of the " + "next stripe (i.e. the one below it). 'on' " + "enables, 'off' disables it.", "off"}, new System.String[]{"Cseg_symbol", "[<tile-component idx>] on|off" + "[ [<tile-component idx>] on|off ...]", |
||
137 | "Inserts an error resilience segmentation symbol in the MQ " + "codeword at the end of " + "each bit-plane (cleanup pass). Decoders can use this " + "information to detect and " + "conceal errors.'on' enables, 'off' disables " + "it.", "off"}, new System.String[]{"Cterm_type", "[<tile-component idx>] near_opt|easy|predict|full" + "[ [<tile-component idx>] near_opt|easy|predict|full ...]", "Specifies the algorithm used to terminate the MQ codeword. " + "The most efficient one is 'near_opt', which delivers a codeword " + "which in almost all cases is the shortest possible. The 'easy' is " + "a simpler algorithm that delivers a codeword length that is close " + "to the previous one (in average 1 bit longer). The 'predict' is" + " almost " + "the same as the 'easy' but it leaves error resilient information " + "on " + "the spare least significant bits (in average 3.5 bits), which can " + "be used by a decoder to detect errors. The 'full' algorithm " + "performs a full flush of the MQ coder and is highly inefficient.\n" + "It is important to use a good termination policy since the MQ " + "codeword can be terminated quite often, specially if the 'Cbypass'" + " or " + "'Cterminate' options are enabled (in the normal case it would be " + "terminated once per code-block, while if 'Cterminate' is specified " + "it will be done almost 3 times per bit-plane in each code-block).", "near_opt"}, new System.String[]{"Clen_calc", "[<tile-component idx>] near_opt|lazy_good|lazy" + "[ [<tile-component idx>] ...]", "Specifies the algorithm to use in calculating the necessary MQ " + "length for each decoding pass. The best one is 'near_opt', which " + "performs a rather sophisticated calculation and provides the best " + "results. The 'lazy_good' and 'lazy' are very simple algorithms " + "that " + "provide rather conservative results, 'lazy_good' one being " + "slightly " + "better. Do not change this option unless you want to experiment " + "the effect of different length calculation algorithms.", "near_opt"}, new |
||
138 | System.String[]{"Cpp", "[<tile-component idx>] <dim> <dim> [<dim> <dim>] " + "[ [<tile-component idx>] ...]", "Specifies precinct partition dimensions for tile-component. The " + "first " + "two values apply to the highest resolution and the following ones " + "(if " + "any) apply to the remaining resolutions in decreasing order. If " + "less " + "values than the number of decomposition levels are specified, " + "then the " + "last two values are used for the remaining resolutions.", null}}; |
||
139 | |||
140 | /// <summary>The source of quantized wavelet coefficients </summary> |
||
141 | protected internal CBlkQuantDataSrcEnc src; |
||
142 | |||
143 | /// <summary> Initializes the source of quantized wavelet coefficients. |
||
144 | /// |
||
145 | /// </summary> |
||
146 | /// <param name="src">The source of quantized wavelet coefficients. |
||
147 | /// |
||
148 | /// </param> |
||
149 | public EntropyCoder(CBlkQuantDataSrcEnc src):base(src) |
||
150 | { |
||
151 | this.src = src; |
||
152 | } |
||
153 | |||
154 | /// <summary> Returns the code-block width for the specified tile and component. |
||
155 | /// |
||
156 | /// </summary> |
||
157 | /// <param name="t">The tile index |
||
158 | /// |
||
159 | /// </param> |
||
160 | /// <param name="c">the component index |
||
161 | /// |
||
162 | /// </param> |
||
163 | /// <returns> The code-block width for the specified tile and component |
||
164 | /// |
||
165 | /// </returns> |
||
166 | public abstract int getCBlkWidth(int t, int c); |
||
167 | |||
168 | /// <summary> Returns the code-block height for the specified tile and component. |
||
169 | /// |
||
170 | /// </summary> |
||
171 | /// <param name="t">The tile index |
||
172 | /// |
||
173 | /// </param> |
||
174 | /// <param name="c">the component index |
||
175 | /// |
||
176 | /// </param> |
||
177 | /// <returns> The code-block height for the specified tile and component |
||
178 | /// |
||
179 | /// </returns> |
||
180 | public abstract int getCBlkHeight(int t, int c); |
||
181 | |||
182 | /// <summary> Returns the reversibility of the tile-component data that is provided |
||
183 | /// by the object. Data is reversible when it is suitable for lossless and |
||
184 | /// lossy-to-lossless compression. |
||
185 | /// |
||
186 | /// <P>Since entropy coders themselves are always reversible, it returns |
||
187 | /// the reversibility of the data that comes from the 'CBlkQuantDataSrcEnc' |
||
188 | /// source object (i.e. ROIScaler). |
||
189 | /// |
||
190 | /// </summary> |
||
191 | /// <param name="t">Tile index |
||
192 | /// |
||
193 | /// </param> |
||
194 | /// <param name="c">Component index |
||
195 | /// |
||
196 | /// </param> |
||
197 | /// <returns> true is the data is reversible, false if not. |
||
198 | /// |
||
199 | /// </returns> |
||
200 | /// <seealso cref="jj2000.j2k.roi.encoder.ROIScaler"> |
||
201 | /// |
||
202 | /// </seealso> |
||
203 | public virtual bool isReversible(int t, int c) |
||
204 | { |
||
205 | return src.isReversible(t, c); |
||
206 | } |
||
207 | |||
208 | /// <summary> Returns a reference to the root of subband tree structure representing |
||
209 | /// the subband decomposition for the specified tile-component. |
||
210 | /// |
||
211 | /// </summary> |
||
212 | /// <param name="t">The index of the tile. |
||
213 | /// |
||
214 | /// </param> |
||
215 | /// <param name="c">The index of the component. |
||
216 | /// |
||
217 | /// </param> |
||
218 | /// <returns> The root of the subband tree structure, see Subband. |
||
219 | /// |
||
220 | /// </returns> |
||
221 | /// <seealso cref="SubbandAn"> |
||
222 | /// |
||
223 | /// </seealso> |
||
224 | /// <seealso cref="Subband"> |
||
225 | /// |
||
226 | /// </seealso> |
||
227 | public virtual SubbandAn getAnSubbandTree(int t, int c) |
||
228 | { |
||
229 | return src.getAnSubbandTree(t, c); |
||
230 | } |
||
231 | |||
232 | /// <summary> Creates a EntropyCoder object for the appropriate entropy coding |
||
233 | /// parameters in the parameter list 'pl', and having 'src' as the source |
||
234 | /// of quantized data. |
||
235 | /// |
||
236 | /// </summary> |
||
237 | /// <param name="src">The source of data to be entropy coded |
||
238 | /// |
||
239 | /// </param> |
||
240 | /// <param name="pl">The parameter list (or options). |
||
241 | /// |
||
242 | /// </param> |
||
243 | /// <param name="cbks">Code-block size specifications |
||
244 | /// |
||
245 | /// </param> |
||
246 | /// <param name="pss">Precinct partition specifications |
||
247 | /// |
||
248 | /// </param> |
||
249 | /// <param name="bms">By-pass mode specifications |
||
250 | /// |
||
251 | /// </param> |
||
252 | /// <param name="mqrs">MQ-reset specifications |
||
253 | /// |
||
254 | /// </param> |
||
255 | /// <param name="rts">Regular termination specifications |
||
256 | /// |
||
257 | /// </param> |
||
258 | /// <param name="css">Causal stripes specifications |
||
259 | /// |
||
260 | /// </param> |
||
261 | /// <param name="sss">Error resolution segment symbol use specifications |
||
262 | /// |
||
263 | /// </param> |
||
264 | /// <param name="lcs">Length computation specifications |
||
265 | /// |
||
266 | /// </param> |
||
267 | /// <param name="tts">Termination type specifications |
||
268 | /// |
||
269 | /// </param> |
||
270 | /// <exception cref="IllegalArgumentException">If an error occurs while parsing |
||
271 | /// the options in 'pl' |
||
272 | /// |
||
273 | /// </exception> |
||
274 | public static EntropyCoder createInstance(CBlkQuantDataSrcEnc src, ParameterList pl, CBlkSizeSpec cblks, PrecinctSizeSpec pss, StringSpec bms, StringSpec mqrs, StringSpec rts, StringSpec css, StringSpec sss, StringSpec lcs, StringSpec tts) |
||
275 | { |
||
276 | // Check parameters |
||
277 | pl.checkList(OPT_PREFIX, CSJ2K.j2k.util.ParameterList.toNameArray(pinfo)); |
||
278 | return new StdEntropyCoder(src, cblks, pss, bms, mqrs, rts, css, sss, lcs, tts); |
||
279 | } |
||
280 | public abstract CSJ2K.j2k.entropy.encoder.CBlkRateDistStats getNextCodeBlock(int param1, CSJ2K.j2k.entropy.encoder.CBlkRateDistStats param2); |
||
281 | public abstract bool precinctPartitionUsed(int param1, int param2); |
||
282 | public abstract int getPPX(int param1, int param2, int param3); |
||
283 | public abstract int getPPY(int param1, int param2, int param3); |
||
284 | } |
||
285 | } |