/*
* 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
// Usually at least 3 times the module size
if (matchingConsecutiveScans >= moduleWidth * 2) { // MGMG
// 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) {
switch (rowNumber % 3) {
case 0:
break;
case 1:
leftColumnECData = cw;
break;
case 2:
break;
}
}
}
symbol = 0;
//columns = columnNumber;
columnNumber++;
}
if (col
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
由于自身需要以及网上查阅了些资料都不怎么满足,就自己试着下载了zxing源码,然后试着整合出了android版本的zxing扫描器。该项目为zxing android版本扫描器全部源码实现,导入eclipse可直接运行,能快速扫描二维码和条形码。最主要的是可以学习了,嘎嘎,赶紧下下来,不下别后悔!
资源推荐
资源详情
资源评论
收起资源包目录
zxing android 二维码扫描器实现源码 (645个子文件)
resources.ap_ 345KB
CaptureActivity.apk 596KB
proguard.cfg 1KB
BitMatrixParser.class 63KB
PDF417.class 43KB
CaptureActivity.class 26KB
ResultHandler.class 18KB
Encoder.class 16KB
RSSExpandedReader.class 15KB
Version.class 15KB
Detector.class 12KB
RSS14Reader.class 12KB
QRCodeEncoder.class 11KB
HistoryManager.class 11KB
MatrixUtil.class 11KB
VCardResultParser.class 10KB
Code128Reader.class 10KB
Decoder.class 10KB
Detector.class 10KB
PDF417ErrorCorrection.class 10KB
FinderPatternFinder.class 10KB
Detector.class 9KB
GeneralAppIdDecoder.class 9KB
DecodedBitStreamParser.class 9KB
EncodeActivity.class 9KB
SearchBookContentsActivity.class 9KB
Detector.class 8KB
PDF417HighLevelEncoder.class 8KB
UPCEANReader.class 8KB
DecodedBitStreamParser.class 8KB
ResultParser.class 8KB
ShareActivity.class 8KB
BitMatrixParser.class 8KB
FieldParser.class 8KB
DecodedBitStreamParser.class 7KB
HistoryActivity.class 6KB
CameraConfigurationManager.class 6KB
SupplementalInfoRetriever.class 6KB
OneDReader.class 6KB
MultiFinderPatternFinder.class 6KB
CameraManager.class 6KB
Code39Reader.class 6KB
AddressBookResultHandler.class 6KB
ITFReader.class 6KB
BitMatrixParser.class 6KB
Code93Reader.class 6KB
WifiConfigManager.class 6KB
UPCEANExtensionSupport.class 6KB
DecodedBitStreamParser.class 5KB
ViewfinderView.class 5KB
R$string.class 5KB
HttpHelper.class 5KB
CharacterSetECI.class 5KB
QRCodeReader.class 5KB
GenericGFPoly.class 5KB
LocaleManager.class 5KB
BitArray.class 5KB
CodaBarReader.class 5KB
BitMatrix.class 5KB
Version.class 5KB
WhiteRectangleDetector.class 5KB
PDF417Reader.class 5KB
ReedSolomonDecoder.class 5KB
DataMatrixReader.class 5KB
Decoder.class 5KB
CaptureActivityHandler.class 5KB
GenericMultipleBarcodeReader.class 5KB
AlignmentPatternFinder.class 5KB
Code128Writer.class 5KB
EANManufacturerOrgSupport.class 4KB
BookResultInfoRetriever.class 4KB
QRCode.class 4KB
ExpandedProductParsedResult.class 4KB
ExpandedProductResultParser.class 4KB
PDF417Writer.class 4KB
MultiFormatReader.class 4KB
DecodeFormatManager.class 4KB
DecodeHandler.class 4KB
LoadPackagesAsyncTask.class 4KB
CalendarResultHandler.class 4KB
MultiFormatUPCEANReader.class 4KB
MECARDContactEncoder.class 4KB
QRCodeWriter.class 4KB
GlobalHistogramBinarizer.class 4KB
HelpActivity.class 4KB
MaxiCodeReader.class 4KB
MaskUtil.class 4KB
BitMatrixParser.class 4KB
VCardContactEncoder.class 4KB
HybridBinarizer.class 4KB
MultiFormatOneDReader.class 4KB
QRCodeMultiReader.class 4KB
PerspectiveTransform.class 4KB
UPCEReader.class 4KB
PreferencesActivity.class 4KB
BeepManager.class 3KB
Decoder.class 3KB
MultiFormatWriter.class 3KB
MonochromeRectangleDetector.class 3KB
AztecReader.class 3KB
共 645 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
zqwblog
- 粉丝: 2
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于二阶自抗扰ADRC的轨迹跟踪控制,对车辆的不确定性和外界干扰具有一定抗干扰性,基于carsim和simulink仿真 跟踪轨迹为双移线,效果良好,有对应复现资料,是学习自抗扰技术快速入门很好的资料
- 基于python的网页自动化工具项目全套技术资料100%好用.zip
- MATLAB【逆变器二次调频模型】 微电网分布式电源逆变器DROOP控制二次调频模型,加入二次控制实现二次调频控制,及二次调压控制,程序可实现上图功能,工况有所改变 需要matlab2021A版
- 抢购软件:快速复制信息
- 单机无穷大系统发生各类(三相短路,单相接地,两相接地,两相相间短路)等短路故障,各类(单相断线,两相断线,三相断线)等断线故障,暂态稳定仿真分析
- 微信文章爬虫项目全套技术资料100%好用.zip
- 基于动态窗口算法的AGV仿真避障 可设置起点目标点,设置地图,设置移动障碍物起始点目标点,未知静态障碍物 动态窗口方法(DynamicWindowApproach) 是一种可以实现实时避障的局部规划算
- Power Quality Disturbance:基于MATLAB Simulink的各种电能质量扰动仿真模型,包括配电线路故障、感应电机启动、变压器励磁、单相 三相非线性负载等模型,可用于模拟各种
- 数据爬虫项目全套技术资料100%好用.zip
- 聊天系统项目全套技术资料100%好用.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页