1 /*
2  * Copyright 2007 ZXing authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package com.google.zxing.qrcode.decoder;
18
19 /**
20  * <p>See ISO 18004:2006, 6.5.1. This enum encapsulates the four error correction levels
21  * defined by the QR code standard.</p>
22  *
23  * @author Sean Owen
24  */

25 public enum ErrorCorrectionLevel {
26
27   /** L = ~7% correction */
28   L(0x01),
29   /** M = ~15% correction */
30   M(0x00),
31   /** Q = ~25% correction */
32   Q(0x03),
33   /** H = ~30% correction */
34   H(0x02);
35
36   private static final ErrorCorrectionLevel[] FOR_BITS = {M, L, H, Q};
37
38   private final int bits;
39
40   ErrorCorrectionLevel(int bits) {
41     this.bits = bits;
42   }
43
44   public int getBits() {
45     return bits;
46   }
47
48   /**
49    * @param bits int containing the two bits encoding a QR Code's error correction level
50    * @return ErrorCorrectionLevel representing the encoded error correction level
51    */

52   public static ErrorCorrectionLevel forBits(int bits) {
53     if (bits < 0 || bits >= FOR_BITS.length) {
54       throw new IllegalArgumentException();
55     }
56     return FOR_BITS[bits];
57   }
58
59
60 }
61