New C# port from Suraj Supekar
[zxing.git] / csharp / qrcode / decoder / ErrorCorrectionLevel.cs
1 /*\r
2 * Copyright 2007 ZXing authors\r
3 *\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
7 *\r
8 *      http://www.apache.org/licenses/LICENSE-2.0\r
9 *\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
15 */\r
16 using System;\r
17 namespace com.google.zxing.qrcode.decoder\r
18 {\r
19         \r
20         /// <summary> <p>See ISO 18004:2006, 6.5.1. This enum encapsulates the four error correction levels\r
21         /// defined by the QR code standard.</p>\r
22         /// \r
23         /// </summary>\r
24         /// <author>  Sean Owen\r
25         /// </author>\r
26         /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source \r
27         /// </author>\r
28         public sealed class ErrorCorrectionLevel\r
29         {\r
30                 public int Bits\r
31                 {\r
32                         get\r
33                         {\r
34                                 return bits;\r
35                         }\r
36                         \r
37                 }\r
38                 public System.String Name\r
39                 {\r
40                         get\r
41                         {\r
42                                 return name;\r
43                         }\r
44                         \r
45                 }\r
46                 \r
47                 // No, we can't use an enum here. J2ME doesn't support it.\r
48                 \r
49                 /// <summary> L = ~7% correction</summary>\r
50                 //UPGRADE_NOTE: Final was removed from the declaration of 'L '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
51                 public static readonly ErrorCorrectionLevel L = new ErrorCorrectionLevel(0, 0x01, "L");\r
52                 /// <summary> M = ~15% correction</summary>\r
53                 //UPGRADE_NOTE: Final was removed from the declaration of 'M '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
54                 public static readonly ErrorCorrectionLevel M = new ErrorCorrectionLevel(1, 0x00, "M");\r
55                 /// <summary> Q = ~25% correction</summary>\r
56                 //UPGRADE_NOTE: Final was removed from the declaration of 'Q '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
57                 public static readonly ErrorCorrectionLevel Q = new ErrorCorrectionLevel(2, 0x03, "Q");\r
58                 /// <summary> H = ~30% correction</summary>\r
59                 //UPGRADE_NOTE: Final was removed from the declaration of 'H '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
60                 public static readonly ErrorCorrectionLevel H = new ErrorCorrectionLevel(3, 0x02, "H");\r
61                 \r
62                 //UPGRADE_NOTE: Final was removed from the declaration of 'FOR_BITS '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
63                 private static readonly ErrorCorrectionLevel[] FOR_BITS = new ErrorCorrectionLevel[]{M, L, H, Q};\r
64                 \r
65                 //UPGRADE_NOTE: Final was removed from the declaration of 'ordinal '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
66                 private int ordinal_Renamed_Field;\r
67                 //UPGRADE_NOTE: Final was removed from the declaration of 'bits '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
68                 private int bits;\r
69                 //UPGRADE_NOTE: Final was removed from the declaration of 'name '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
70                 private System.String name;\r
71                 \r
72                 private ErrorCorrectionLevel(int ordinal, int bits, System.String name)\r
73                 {\r
74                         this.ordinal_Renamed_Field = ordinal;\r
75                         this.bits = bits;\r
76                         this.name = name;\r
77                 }\r
78                 \r
79                 public int ordinal()\r
80                 {\r
81                         return ordinal_Renamed_Field;\r
82                 }\r
83                 \r
84                 public override System.String ToString()\r
85                 {\r
86                         return name;\r
87                 }\r
88                 \r
89                 /// <param name="bits">int containing the two bits encoding a QR Code's error correction level\r
90                 /// </param>\r
91                 /// <returns> {@link ErrorCorrectionLevel} representing the encoded error correction level\r
92                 /// </returns>\r
93                 public static ErrorCorrectionLevel forBits(int bits)\r
94                 {\r
95                         if (bits < 0 || bits >= FOR_BITS.Length)\r
96                         {\r
97                                 throw new System.ArgumentException();\r
98                         }\r
99                         return FOR_BITS[bits];\r
100                 }\r
101         }\r
102 }