2 * Copyright 2007 ZXing authors
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 using ReaderException = com.google.zxing.ReaderException;
\r
18 namespace com.google.zxing.datamatrix.decoder
\r
21 /// <summary> The Version object encapsulates attributes about a particular
\r
22 /// size Data Matrix Code.
\r
25 /// <author> bbrown@google.com (Brian Brown)
\r
27 /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
\r
29 public sealed class Version
\r
31 public int VersionNumber
\r
35 return versionNumber;
\r
39 public int SymbolSizeRows
\r
43 return symbolSizeRows;
\r
47 public int SymbolSizeColumns
\r
51 return symbolSizeColumns;
\r
55 public int DataRegionSizeRows
\r
59 return dataRegionSizeRows;
\r
63 public int DataRegionSizeColumns
\r
67 return dataRegionSizeColumns;
\r
71 public int TotalCodewords
\r
75 return totalCodewords;
\r
80 //UPGRADE_NOTE: Final was removed from the declaration of 'VERSIONS '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
\r
81 private static readonly Version[] VERSIONS = buildVersions();
\r
83 //UPGRADE_NOTE: Final was removed from the declaration of 'versionNumber '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
\r
84 private int versionNumber;
\r
85 //UPGRADE_NOTE: Final was removed from the declaration of 'symbolSizeRows '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
\r
86 private int symbolSizeRows;
\r
87 //UPGRADE_NOTE: Final was removed from the declaration of 'symbolSizeColumns '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
\r
88 private int symbolSizeColumns;
\r
89 //UPGRADE_NOTE: Final was removed from the declaration of 'dataRegionSizeRows '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
\r
90 private int dataRegionSizeRows;
\r
91 //UPGRADE_NOTE: Final was removed from the declaration of 'dataRegionSizeColumns '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
\r
92 private int dataRegionSizeColumns;
\r
93 //UPGRADE_NOTE: Final was removed from the declaration of 'ecBlocks '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
\r
94 private ECBlocks ecBlocks;
\r
95 //UPGRADE_NOTE: Final was removed from the declaration of 'totalCodewords '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
\r
96 private int totalCodewords;
\r
98 private Version(int versionNumber, int symbolSizeRows, int symbolSizeColumns, int dataRegionSizeRows, int dataRegionSizeColumns, ECBlocks ecBlocks)
\r
100 this.versionNumber = versionNumber;
\r
101 this.symbolSizeRows = symbolSizeRows;
\r
102 this.symbolSizeColumns = symbolSizeColumns;
\r
103 this.dataRegionSizeRows = dataRegionSizeRows;
\r
104 this.dataRegionSizeColumns = dataRegionSizeColumns;
\r
105 this.ecBlocks = ecBlocks;
\r
107 // Calculate the total number of codewords
\r
109 int ecCodewords = ecBlocks.ECCodewords;
\r
110 ECB[] ecbArray = ecBlocks.getECBlocks();
\r
111 for (int i = 0; i < ecbArray.Length; i++)
\r
113 ECB ecBlock = ecbArray[i];
\r
114 total += ecBlock.Count * (ecBlock.DataCodewords + ecCodewords);
\r
116 this.totalCodewords = total;
\r
119 internal ECBlocks getECBlocks()
\r
124 /// <summary> <p>Deduces version information from Data Matrix dimensions.</p>
\r
127 /// <param name="numRows">Number of rows in modules
\r
129 /// <param name="numColumns">Number of columns in modules
\r
131 /// <returns> {@link Version} for a Data Matrix Code of those dimensions
\r
133 /// <throws> ReaderException if dimensions do correspond to a valid Data Matrix size </throws>
\r
134 public static Version getVersionForDimensions(int numRows, int numColumns)
\r
136 if ((numRows & 0x01) != 0 || (numColumns & 0x01) != 0)
\r
138 throw ReaderException.Instance;
\r
141 // TODO(bbrown): This is doing a linear search through the array of versions.
\r
142 // If we interleave the rectangular versions with the square versions we could
\r
143 // do a binary search.
\r
144 int numVersions = VERSIONS.Length;
\r
145 for (int i = 0; i < numVersions; ++i)
\r
147 Version version = VERSIONS[i];
\r
148 if (version.symbolSizeRows == numRows && version.symbolSizeColumns == numColumns)
\r
154 throw ReaderException.Instance;
\r
157 /// <summary> <p>Encapsulates a set of error-correction blocks in one symbol version. Most versions will
\r
158 /// use blocks of differing sizes within one version, so, this encapsulates the parameters for
\r
159 /// each set of blocks. It also holds the number of error-correction codewords per block since it
\r
160 /// will be the same across all blocks within one version.</p>
\r
162 internal sealed class ECBlocks
\r
164 internal int ECCodewords
\r
168 return ecCodewords;
\r
172 //UPGRADE_NOTE: Final was removed from the declaration of 'ecCodewords '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
\r
173 private int ecCodewords;
\r
174 //UPGRADE_NOTE: Final was removed from the declaration of 'ecBlocks '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
\r
175 private ECB[] ecBlocks;
\r
177 internal ECBlocks(int ecCodewords, ECB ecBlocks)
\r
179 this.ecCodewords = ecCodewords;
\r
180 this.ecBlocks = new ECB[]{ecBlocks};
\r
183 internal ECBlocks(int ecCodewords, ECB ecBlocks1, ECB ecBlocks2)
\r
185 this.ecCodewords = ecCodewords;
\r
186 this.ecBlocks = new ECB[]{ecBlocks1, ecBlocks2};
\r
189 internal ECB[] getECBlocks()
\r
195 /// <summary> <p>Encapsualtes the parameters for one error-correction block in one symbol version.
\r
196 /// This includes the number of data codewords, and the number of times a block with these
\r
197 /// parameters is used consecutively in the Data Matrix code version's format.</p>
\r
199 internal sealed class ECB
\r
209 internal int DataCodewords
\r
213 return dataCodewords;
\r
217 //UPGRADE_NOTE: Final was removed from the declaration of 'count '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
\r
219 //UPGRADE_NOTE: Final was removed from the declaration of 'dataCodewords '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
\r
220 private int dataCodewords;
\r
222 internal ECB(int count, int dataCodewords)
\r
224 this.count = count;
\r
225 this.dataCodewords = dataCodewords;
\r
229 public override System.String ToString()
\r
231 return System.Convert.ToString(versionNumber);
\r
234 /// <summary> See ISO 16022:2006 5.5.1 Table 7</summary>
\r
235 private static Version[] buildVersions()
\r
237 return new Version[]{new Version(1, 10, 10, 8, 8, new ECBlocks(5, new ECB(1, 3))), new Version(2, 12, 12, 10, 10, new ECBlocks(7, new ECB(1, 5))), new Version(3, 14, 14, 12, 12, new ECBlocks(10, new ECB(1, 8))), new Version(4, 16, 16, 14, 14, new ECBlocks(12, new ECB(1, 12))), new Version(5, 18, 18, 16, 16, new ECBlocks(14, new ECB(1, 18))), new Version(6, 20, 20, 18, 18, new ECBlocks(18, new ECB(1, 22))), new Version(7, 22, 22, 20, 20, new ECBlocks(20, new ECB(1, 30))), new Version(8, 24, 24, 22, 22, new ECBlocks(24, new ECB(1, 36))), new Version(9, 26, 26, 24, 24, new ECBlocks(28, new ECB(1, 44))), new Version(10, 32, 32, 14, 14, new ECBlocks(36, new ECB(1, 62))), new Version(11, 36, 36, 16, 16, new ECBlocks(42, new ECB(1, 86))), new Version(12, 40, 40, 18, 18, new ECBlocks(48, new ECB(1, 114))), new Version(13, 44, 44, 20, 20, new ECBlocks(56, new ECB(1, 144))), new Version(14, 48, 48, 22, 22, new ECBlocks(68, new ECB(1, 174))), new Version(15, 52, 52, 24, 24, new ECBlocks(42, new ECB(2, 102))), new Version(16, 64, 64, 14, 14, new ECBlocks(56, new ECB(2, 140))), new Version(17, 72, 72, 16, 16, new ECBlocks(36, new ECB(4, 92))), new Version(18, 80, 80, 18, 18, new ECBlocks(48, new ECB(4, 114))), new Version(19, 88, 88, 20, 20, new ECBlocks(56, new ECB(4, 144))), new Version(20, 96, 96, 22, 22, new ECBlocks(68, new ECB(4, 174))), new Version(21, 104, 104, 24, 24, new ECBlocks(56, new ECB(6, 136))), new Version(22, 120, 120, 18, 18, new ECBlocks(68, new ECB(6, 175))), new Version(23, 132, 132, 20, 20, new ECBlocks(62, new ECB(8, 163))), new Version(24, 144, 144, 22, 22, new ECBlocks(62, new ECB(8, 156), new ECB(2, 155))), new Version(25, 8, 18, 6, 16, new ECBlocks(7, new ECB(1, 5))), new Version(26, 8, 32, 6, 14, new ECBlocks(11, new ECB(1, 10))), new Version(27, 12, 26, 10, 24, new ECBlocks(14, new ECB(1, 16))), new Version(28, 12, 36, 10, 16, new ECBlocks(18, new ECB(1, 22))), new Version(29, 16, 36, 10, 16, new ECBlocks(24, new ECB(1, 32))), new Version(30, 16, 48, 14, 22, new ECBlocks(28,
\r