/*
* Copyright 2009 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
package com.google.zxing.pdf417.decoder;
import com.google.zxing.FormatException;
import com.google.zxing.common.BitMatrix;
/**
* <p>
* This class parses the BitMatrix image into codewords.
* </p>
*
* @author SITA Lab (kevin.osullivan@sita.aero)
*/
final class BitMatrixParser {
private static final int[] NO_ERRORS = new int[0];
private static final int MAX_ROW_DIFFERENCE = 6;
private static final int MAX_ROWS = 90;
//private static final int MAX_COLUMNS = 30;
// Maximum Codewords (Data + Error)
private static final int MAX_CW_CAPACITY = 929;
private static final int MODULES_IN_SYMBOL = 17;
private final BitMatrix bitMatrix;
private int rows = 0;
//private int columns = 0;
private int leftColumnECData = 0;
private int rightColumnECData = 0;
private int eraseCount = 0;
private int[] erasures;
private int ecLevel = -1;
BitMatrixParser(BitMatrix bitMatrix) {
this.bitMatrix = bitMatrix;
}
/**
* To ensure separability of rows, codewords of consecutive rows belong to
* different subsets of all possible codewords. This routine scans the
* symbols in the barcode. When it finds a number of consecutive rows which
* are the same, it assumes that this is a row of codewords and processes
* them into a codeword array.
*
* @return an array of codewords.
*/
int[] readCodewords() throws FormatException {
int width = bitMatrix.getWidth();
int height = bitMatrix.getHeight();
erasures = new int[MAX_CW_CAPACITY];
// Get the number of pixels in a module across the X dimension
//float moduleWidth = bitMatrix.getModuleWidth();
float moduleWidth = 1.0f; // Image has been sampled and reduced
int[] rowCounters = new int[width];
int[] codewords = new int[MAX_CW_CAPACITY];
int next = 0;
int matchingConsecutiveScans = 0;
boolean rowInProgress = false;
int rowNumber = 0;
int rowHeight = 0;
for (int i = 1; i < height; i++) {
if (rowNumber >= MAX_ROWS) {
// Something is wrong, since we have exceeded
// the maximum rows in the specification.
throw FormatException.getFormatInstance();
}
int rowDifference = 0;
// Scan a line of modules and check the
// difference between this and the previous line
for (int j = 0; j < width; j++) {
// Accumulate differences between this line and the
// previous line.
if (bitMatrix.get(j, i) != bitMatrix.get(j, i - 1)) {
rowDifference++;
}
}
if (rowDifference <= moduleWidth * MAX_ROW_DIFFERENCE) {
for (int j = 0; j < width; j++) {
// Accumulate the black pixels on this line
if (bitMatrix.get(j, i)) {
rowCounters[j]++;
}
}
// Increment the number of consecutive rows of pixels
// that are more or less the same
matchingConsecutiveScans++;
// Height of a row is a multiple of the module size in pixels
// It's supposed to be >= 3x module width, but, accept anything >= 2x
if ((matchingConsecutiveScans + 1) >= 2.0f * moduleWidth) {
// We have some previous matches as well as a match here
// Set processing a unique row.
rowInProgress = true;
}
} else {
if (rowInProgress) {
// Process Row
next = processRow(rowCounters, rowNumber, rowHeight, codewords, next);
if (next == -1) {
// Something is wrong, since we have exceeded
// the maximum columns in the specification.
throw FormatException.getFormatInstance();
}
// Reinitialize the row counters.
for (int j = 0; j < rowCounters.length; j++) {
rowCounters[j] = 0;
}
rowNumber++;
rowHeight = 0;
}
matchingConsecutiveScans = 0;
rowInProgress = false;
}
rowHeight++;
}
// Check for a row that was in progress before we exited above.
if (rowInProgress) {
// Process Row
if (rowNumber >= MAX_ROWS) {
// Something is wrong, since we have exceeded
// the maximum rows in the specification.
throw FormatException.getFormatInstance();
}
next = processRow(rowCounters, rowNumber, rowHeight, codewords, next);
rowNumber++;
rows = rowNumber;
}
erasures = trimArray(erasures, eraseCount);
return trimArray(codewords, next);
}
/**
* Trim the array to the required size.
*
* @param array the array
* @param size the size to trim it to
* @return the new trimmed array
*/
private static int[] trimArray(int[] array, int size) {
if (size < 0) {
throw new IllegalArgumentException();
}
if (size == 0) {
return NO_ERRORS;
}
int[] a = new int[size];
System.arraycopy(array, 0, a, 0, size);
return a;
}
/**
* Convert the symbols in the row to codewords.
* Each PDF417 symbol character consists of four bar elements and four space
* elements, each of which can be one to six modules wide. The four bar and
* four space elements shall measure 17 modules in total.
*
* @param rowCounters an array containing the counts of black pixels for each column
* in the row.
* @param rowNumber the current row number of codewords.
* @param rowHeight the height of this row in pixels.
* @param codewords the codeword array to save codewords into.
* @param next the next available index into the codewords array.
* @return the next available index into the codeword array after processing
* this row.
*/
int processRow(int[] rowCounters, int rowNumber, int rowHeight, int[] codewords, int next)
throws FormatException {
int width = bitMatrix.getWidth();
int columnNumber = 0;
long symbol = 0;
for (int i = 0; i < width; i += MODULES_IN_SYMBOL) {
// This happens in real life and is almost surely a rare misdecode
if (i + MODULES_IN_SYMBOL > rowCounters.length) {
throw FormatException.getFormatInstance();
}
for (int mask = MODULES_IN_SYMBOL - 1; mask >= 0; mask--) {
if (rowCounters[i + (MODULES_IN_SYMBOL - 1 - mask)] >= rowHeight >>> 1) {
symbol |= 1L << mask;
}
}
if (columnNumber > 0) {
int cw = getCodeword(symbol);
if (cw < 0 && i < width - MODULES_IN_SYMBOL) {
// Skip errors on the Right row indicator column
if (eraseCount >= erasures.length) {
throw FormatException.getFormatInstance();
}
erasures[eraseCount] = next;
next++;
eraseCount++;
} else {
codewords[next++] = cw;
}
} else {
// Left row indicator column
int cw = getCodeword(symbol);
if (ecLevel < 0) {
if (rowNumber % 3 == 1) {
leftColumnECData = cw;
}
}
}
symbol = 0;
//columns = columnNumber;
columnNumber++;
}
if (columnNumber > 1) {
// Right row indicator column is in codeword[next]
//columns--;
/
没有合适的资源?快使用搜索试试~ 我知道了~
android二维码zxing源码
共2678个文件
html:469个
java:419个
h:409个
需积分: 3 19 下载量 125 浏览量
2012-12-26
14:59:01
上传
评论
收藏 16MB ZIP 举报
温馨提示
android有关二维码,其中core/core.jar要引入工程中,并且要放在第一个位置
资源推荐
资源详情
资源评论
收起资源包目录
android二维码zxing源码 (2678个子文件)
manifest.aegis 2KB
beepbeep.aif 58KB
beep-beep.aiff 64KB
beep-beep.aiff 64KB
testClass.as 91KB
BitMatrixParser.as 56KB
PDF417.as 39KB
FinderPatternFinder.as 26KB
DecodedBitStreamParser.as 24KB
Version.as 24KB
MatrixUtil.as 24KB
Encoder.as 24KB
DecodedBitStreamParser.as 21KB
Detector.as 20KB
Detector.as 19KB
RSSExpandedReader.as 19KB
BitMatrixParser.as 19KB
PDF417HighLevelEncoder.as 17KB
Detector.as 17KB
Code128Reader.as 17KB
Detector.as 17KB
RSS14Reader.as 16KB
UPCEANReader.as 15KB
Code39Reader.as 14KB
QRCodeReader.as 14KB
ITFReader.as 14KB
DecodedBitStreamParser.as 14KB
GeneralAppIdDecoder.as 13KB
Decoder.as 13KB
OneDReader.as 12KB
MultiFinderPatternFinder.as 12KB
GF256Poly.as 12KB
AlignmentPatternFinder.as 12KB
GridSampler.as 10KB
ResultParser.as 10KB
WhiteRectangleDetector.as 10KB
FieldParser.as 10KB
BitMatrix.as 10KB
PDF417ErrorCorrection.as 9KB
GenericGFPoly.as 9KB
BitArray.as 9KB
CodaBarReader.as 9KB
BitMatrixParser.as 9KB
Code93Reader.as 9KB
MaskUtil.as 9KB
MonochromeRectangleDetector.as 8KB
Version.as 8KB
MultiFormatReader.as 8KB
DecodedBitStreamParser.as 8KB
ReedSolomonDecoder.as 8KB
EncodeDecodeEAN8Test.as 7KB
UPCEReader.as 7KB
GlobalHistogramBinarizer.as 7KB
HybridBinarizer.as 7KB
Decoder.as 7KB
QRCode.as 7KB
LocalBlockBinarizer.as 7KB
Code128Writer.as 6KB
FormatInformation.as 6KB
Decoder.as 6KB
VCardResultParser.as 6KB
UPCEANExtensionSupport.as 6KB
DataBlock.as 6KB
PDF417Reader.as 6KB
Decoder.as 6KB
PerspectiveTransform.as 6KB
DataMatrixReader.as 6KB
DataBlock.as 6KB
BitMatrixParser.as 6KB
BitVector.as 6KB
EAN13Reader.as 6KB
Mode.as 5KB
Result.as 5KB
GF256.as 5KB
GenericGF.as 5KB
GenericMultipleBarcodeReader.as 5KB
BufferedImageLuminanceSource.as 5KB
BinaryBitmap.as 5KB
LuminanceSource.as 5KB
QRCodeWriter.as 5KB
RSSUtils.as 5KB
ByteMatrix.as 4KB
ResultPoint.as 4KB
EANManufacturerOrgSupport.as 4KB
zxingByteArray.as 4KB
MultiFormatOneDReader.as 4KB
MultiFormatUPCEANReader.as 4KB
MaxiCodeReader.as 4KB
CalendarParsedResult.as 4KB
PDF417Writer.as 4KB
CharacterSetECI.as 4KB
SMSMMSResultParser.as 4KB
ArrayList.as 4KB
DefaultGridSampler.as 4KB
URIParsedResult.as 4KB
BarcodeFormat.as 4KB
AbstractRSSReader.as 4KB
BizcardResultParser.as 4KB
BitSource.as 4KB
Decoder.as 3KB
共 2678 条
- 1
- 2
- 3
- 4
- 5
- 6
- 27
资源评论
mazhao89
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 三菱PLC例程源码Medocsequencegenerator
- 三菱PLC例程源码M1320磨头进出FX1s控制步进电机,有注释
- STRASSEN矩阵乘法算法(改进分治法·C语言)
- 前端.xmind前端.xmind前端.xmind前端.xmind前端.xmind
- 三菱PLC例程源码LOW-E玻璃镀膜线程序(三菱QPLC的)一万步带注释
- 三菱PLC例程源码LCD设备蚀刻机程序
- 三菱PLC例程源码LCD设备蚀刻机
- 全面前端开发指南:从基础到深入
- pvk2pfx 32位 Pvk2Pfx (Pvk2Pfx.exe) 是一种命令行工具,可将 .spc、.cer 和 .pvk 文
- 三菱PLC例程源码JH21-150程序
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功