Decoder.java revision 7e3fa36d69ffee874dd364b8e3d9aa3cab9a273b
* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * <p>The main class which implements QR Code decoding -- as opposed to locating and extracting * the QR Code from an image.</p> * <p>Convenience method that can decode a QR Code represented as a 2D array of booleans. * "true" is taken to mean a black module.</p> * @param image booleans representing white/black QR Code modules * @return text and bytes encoded within the QR Code * @throws FormatException if the QR Code cannot be decoded * @throws ChecksumException if error correction fails * <p>Decodes a QR Code represented as a {@link BitMatrix}. A 1 or "true" is taken to mean a black module.</p> * @param bits booleans representing white/black QR Code modules * @return text and bytes encoded within the QR Code * @throws FormatException if the QR Code cannot be decoded * @throws ChecksumException if error correction fails // Construct a parser and read version, error-correction level // Will be attempting a mirrored reading of the version and format info. // Preemptively read the version. // Preemptively read the format information. * Since we're here, this means we have successfully detected some kind * of version and format information when mirrored. This is a good sign, * that the QR code may be mirrored, and we should try once more with a // Prepare for a mirrored reading. // Success! Notify the caller that the code was mirrored. // Throw the exception from the original reading // Throw the exception from the original reading // Separate into data blocks // Count total number of data bytes // Error-correct and copy data blocks together into a stream of bytes // Decode the contents of that stream of bytes * <p>Given data and error-correction codewords received, possibly corrupted by errors, attempts to * correct the errors in-place using Reed-Solomon error correction.</p> * @param codewordBytes data and error correction codewords * @param numDataCodewords number of codewords that are data bytes * @throws ChecksumException if error correction fails // First read into an array of ints // Copy back into array of bytes -- only need to worry about the bytes that were data // We don't care about errors in the error-correction codewords