You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ErrorCorrectionLevel.cs 3.3 kB

10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. using System;
  17. namespace ZXing.QrCode.Internal
  18. {
  19. /// <summary>
  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. /// </summary>
  23. /// <author>Sean Owen</author>
  24. public sealed class ErrorCorrectionLevel
  25. {
  26. /// <summary> L = ~7% correction</summary>
  27. public static readonly ErrorCorrectionLevel L = new ErrorCorrectionLevel(0, 0x01, "L");
  28. /// <summary> M = ~15% correction</summary>
  29. public static readonly ErrorCorrectionLevel M = new ErrorCorrectionLevel(1, 0x00, "M");
  30. /// <summary> Q = ~25% correction</summary>
  31. public static readonly ErrorCorrectionLevel Q = new ErrorCorrectionLevel(2, 0x03, "Q");
  32. /// <summary> H = ~30% correction</summary>
  33. public static readonly ErrorCorrectionLevel H = new ErrorCorrectionLevel(3, 0x02, "H");
  34. private static readonly ErrorCorrectionLevel[] FOR_BITS = new [] { M, L, H, Q };
  35. private readonly int bits;
  36. private ErrorCorrectionLevel(int ordinal, int bits, String name)
  37. {
  38. this.ordinal_Renamed_Field = ordinal;
  39. this.bits = bits;
  40. this.name = name;
  41. }
  42. /// <summary>
  43. /// Gets the bits.
  44. /// </summary>
  45. public int Bits
  46. {
  47. get
  48. {
  49. return bits;
  50. }
  51. }
  52. /// <summary>
  53. /// Gets the name.
  54. /// </summary>
  55. public String Name
  56. {
  57. get
  58. {
  59. return name;
  60. }
  61. }
  62. private readonly int ordinal_Renamed_Field;
  63. private readonly String name;
  64. /// <summary>
  65. /// Ordinals this instance.
  66. /// </summary>
  67. /// <returns></returns>
  68. public int ordinal()
  69. {
  70. return ordinal_Renamed_Field;
  71. }
  72. /// <summary>
  73. /// Returns a <see cref="System.String"/> that represents this instance.
  74. /// </summary>
  75. /// <returns>
  76. /// A <see cref="System.String"/> that represents this instance.
  77. /// </returns>
  78. public override String ToString()
  79. {
  80. return name;
  81. }
  82. /// <summary>
  83. /// Fors the bits.
  84. /// </summary>
  85. /// <param name="bits">int containing the two bits encoding a QR Code's error correction level</param>
  86. /// <returns>
  87. /// <see cref="ErrorCorrectionLevel"/> representing the encoded error correction level
  88. /// </returns>
  89. public static ErrorCorrectionLevel forBits(int bits)
  90. {
  91. if (bits < 0 || bits >= FOR_BITS.Length)
  92. {
  93. throw new ArgumentException();
  94. }
  95. return FOR_BITS[bits];
  96. }
  97. }
  98. }