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 com.google.zxing;
\r
18 using com.google.zxing.common;
\r
20 namespace com.google.zxing.qrcode.decoder
\r
22 public sealed class ErrorCorrectionLevel
\r
24 // No, we can't use an enum here. J2ME doesn't support it.
\r
26 * L = ~7% correction
\r
28 public static ErrorCorrectionLevel L = new ErrorCorrectionLevel(0, 0x01, "L");
\r
30 * M = ~15% correction
\r
32 public static ErrorCorrectionLevel M = new ErrorCorrectionLevel(1, 0x00, "M");
\r
34 * Q = ~25% correction
\r
36 public static ErrorCorrectionLevel Q = new ErrorCorrectionLevel(2, 0x03, "Q");
\r
38 * H = ~30% correction
\r
40 public static ErrorCorrectionLevel H = new ErrorCorrectionLevel(3, 0x02, "H");
\r
42 private static ErrorCorrectionLevel[] FOR_BITS = {M, L, H, Q};
\r
44 private int Ordinal;
\r
46 private string name;
\r
48 private ErrorCorrectionLevel(int ordinal, int bits, string name) {
\r
49 this.Ordinal = ordinal;
\r
54 public int ordinal() {
\r
58 public int getBits() {
\r
62 public string getName() {
\r
66 public string toString() {
\r
71 * @param bits int containing the two bits encoding a QR Code's error correction level
\r
72 * @return {@link ErrorCorrectionLevel} representing the encoded error correction level
\r
74 public static ErrorCorrectionLevel forBits(int bits) {
\r
75 if (bits < 0 || bits >= FOR_BITS.Length) {
\r
76 throw new ArgumentException();
\r
78 return FOR_BITS[bits];
\r