QRCode.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. * Copyright 2008 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 FastReport.Barcode.QRCode
  18. {
  19. /*/// <author> satorux@google.com (Satoru Takabayashi) - creator
  20. /// </author>
  21. /// <author> dswitkin@google.com (Daniel Switkin) - ported from C++
  22. /// </author>
  23. /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
  24. /// </author>*/
  25. internal sealed class QRCode
  26. {
  27. public Mode Mode
  28. {
  29. // Mode of the QR Code.
  30. get
  31. {
  32. return mode;
  33. }
  34. set
  35. {
  36. mode = value;
  37. }
  38. }
  39. public ErrorCorrectionLevel ECLevel
  40. {
  41. // Error correction level of the QR Code.
  42. get
  43. {
  44. return ecLevel;
  45. }
  46. set
  47. {
  48. ecLevel = value;
  49. }
  50. }
  51. public int Version
  52. {
  53. // Version of the QR Code. The bigger size, the bigger version.
  54. get
  55. {
  56. return version;
  57. }
  58. set
  59. {
  60. version = value;
  61. }
  62. }
  63. public int MatrixWidth
  64. {
  65. // ByteMatrix width of the QR Code.
  66. get
  67. {
  68. return matrixWidth;
  69. }
  70. set
  71. {
  72. matrixWidth = value;
  73. }
  74. }
  75. public int MaskPattern
  76. {
  77. // Mask pattern of the QR Code.
  78. get
  79. {
  80. return maskPattern;
  81. }
  82. set
  83. {
  84. maskPattern = value;
  85. }
  86. }
  87. public int NumTotalBytes
  88. {
  89. // Number of total bytes in the QR Code.
  90. get
  91. {
  92. return numTotalBytes;
  93. }
  94. set
  95. {
  96. numTotalBytes = value;
  97. }
  98. }
  99. public int NumDataBytes
  100. {
  101. // Number of data bytes in the QR Code.
  102. get
  103. {
  104. return numDataBytes;
  105. }
  106. set
  107. {
  108. numDataBytes = value;
  109. }
  110. }
  111. public int NumECBytes
  112. {
  113. // Number of error correction bytes in the QR Code.
  114. get
  115. {
  116. return numECBytes;
  117. }
  118. set
  119. {
  120. numECBytes = value;
  121. }
  122. }
  123. public int NumRSBlocks
  124. {
  125. // Number of Reedsolomon blocks in the QR Code.
  126. get
  127. {
  128. return numRSBlocks;
  129. }
  130. set
  131. {
  132. numRSBlocks = value;
  133. }
  134. }
  135. public ByteMatrix Matrix
  136. {
  137. // ByteMatrix data of the QR Code.
  138. get
  139. {
  140. return matrix;
  141. }
  142. // This takes ownership of the 2D array.
  143. set
  144. {
  145. matrix = value;
  146. }
  147. }
  148. public bool Valid
  149. {
  150. // Checks all the member variables are set properly. Returns true on success. Otherwise, returns
  151. // false.
  152. get
  153. {
  154. return mode != null && ecLevel != null && version != - 1 && matrixWidth != - 1 && maskPattern != - 1 && numTotalBytes != - 1 && numDataBytes != - 1 && numECBytes != - 1 && numRSBlocks != - 1 && isValidMaskPattern(maskPattern) && numTotalBytes == numDataBytes + numECBytes && matrix != null && matrixWidth == matrix.Width && matrix.Width == matrix.Height; // Must be square.
  155. }
  156. }
  157. public const int NUM_MASK_PATTERNS = 8;
  158. private Mode mode;
  159. private ErrorCorrectionLevel ecLevel;
  160. private int version;
  161. private int matrixWidth;
  162. private int maskPattern;
  163. private int numTotalBytes;
  164. private int numDataBytes;
  165. private int numECBytes;
  166. private int numRSBlocks;
  167. private ByteMatrix matrix;
  168. public QRCode()
  169. {
  170. mode = null;
  171. ecLevel = null;
  172. version = - 1;
  173. matrixWidth = - 1;
  174. maskPattern = - 1;
  175. numTotalBytes = - 1;
  176. numDataBytes = - 1;
  177. numECBytes = - 1;
  178. numRSBlocks = - 1;
  179. matrix = null;
  180. }
  181. // Check if "mask_pattern" is valid.
  182. public static bool isValidMaskPattern(int maskPattern)
  183. {
  184. return maskPattern >= 0 && maskPattern < NUM_MASK_PATTERNS;
  185. }
  186. }
  187. }