mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-27 21:02:35 +00:00
moved java files for pre-convert
This commit is contained in:
85
src/oned/rss/expanded/BitArrayBuilder.java
Normal file
85
src/oned/rss/expanded/BitArrayBuilder.java
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded;
|
||||
|
||||
import com.google.zxing.common.BitArray;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
|
||||
*/
|
||||
final class BitArrayBuilder {
|
||||
|
||||
private BitArrayBuilder() {
|
||||
}
|
||||
|
||||
static BitArray buildBitArray(List<ExpandedPair> pairs) {
|
||||
int charNumber = (pairs.size() * 2) - 1;
|
||||
if (pairs.get(pairs.size() - 1).getRightChar() == null) {
|
||||
charNumber -= 1;
|
||||
}
|
||||
|
||||
int size = 12 * charNumber;
|
||||
|
||||
BitArray binary = new BitArray(size);
|
||||
int accPos = 0;
|
||||
|
||||
ExpandedPair firstPair = pairs.get(0);
|
||||
int firstValue = firstPair.getRightChar().getValue();
|
||||
for (int i = 11; i >= 0; --i) {
|
||||
if ((firstValue & (1 << i)) != 0) {
|
||||
binary.set(accPos);
|
||||
}
|
||||
accPos++;
|
||||
}
|
||||
|
||||
for (int i = 1; i < pairs.size(); ++i) {
|
||||
ExpandedPair currentPair = pairs.get(i);
|
||||
|
||||
int leftValue = currentPair.getLeftChar().getValue();
|
||||
for (int j = 11; j >= 0; --j) {
|
||||
if ((leftValue & (1 << j)) != 0) {
|
||||
binary.set(accPos);
|
||||
}
|
||||
accPos++;
|
||||
}
|
||||
|
||||
if (currentPair.getRightChar() != null) {
|
||||
int rightValue = currentPair.getRightChar().getValue();
|
||||
for (int j = 11; j >= 0; --j) {
|
||||
if ((rightValue & (1 << j)) != 0) {
|
||||
binary.set(accPos);
|
||||
}
|
||||
accPos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return binary;
|
||||
}
|
||||
}
|
||||
90
src/oned/rss/expanded/ExpandedPair.java
Normal file
90
src/oned/rss/expanded/ExpandedPair.java
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded;
|
||||
|
||||
import com.google.zxing.oned.rss.DataCharacter;
|
||||
import com.google.zxing.oned.rss.FinderPattern;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
*/
|
||||
final class ExpandedPair {
|
||||
|
||||
private final DataCharacter leftChar;
|
||||
private final DataCharacter rightChar;
|
||||
private final FinderPattern finderPattern;
|
||||
|
||||
ExpandedPair(DataCharacter leftChar,
|
||||
DataCharacter rightChar,
|
||||
FinderPattern finderPattern) {
|
||||
this.leftChar = leftChar;
|
||||
this.rightChar = rightChar;
|
||||
this.finderPattern = finderPattern;
|
||||
}
|
||||
|
||||
DataCharacter getLeftChar() {
|
||||
return this.leftChar;
|
||||
}
|
||||
|
||||
DataCharacter getRightChar() {
|
||||
return this.rightChar;
|
||||
}
|
||||
|
||||
FinderPattern getFinderPattern() {
|
||||
return this.finderPattern;
|
||||
}
|
||||
|
||||
boolean mustBeLast() {
|
||||
return this.rightChar == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return
|
||||
"[ " + leftChar + " , " + rightChar + " : " +
|
||||
(finderPattern == null ? "null" : finderPattern.getValue()) + " ]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof ExpandedPair)) {
|
||||
return false;
|
||||
}
|
||||
ExpandedPair that = (ExpandedPair) o;
|
||||
return Objects.equals(leftChar, that.leftChar) &&
|
||||
Objects.equals(rightChar, that.rightChar) &&
|
||||
Objects.equals(finderPattern, that.finderPattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(leftChar) ^ Objects.hashCode(rightChar) ^ Objects.hashCode(finderPattern);
|
||||
}
|
||||
|
||||
}
|
||||
69
src/oned/rss/expanded/ExpandedRow.java
Normal file
69
src/oned/rss/expanded/ExpandedRow.java
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.oned.rss.expanded;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* One row of an RSS Expanded Stacked symbol, consisting of 1+ expanded pairs.
|
||||
*/
|
||||
final class ExpandedRow {
|
||||
|
||||
private final List<ExpandedPair> pairs;
|
||||
private final int rowNumber;
|
||||
|
||||
ExpandedRow(List<ExpandedPair> pairs, int rowNumber) {
|
||||
this.pairs = new ArrayList<>(pairs);
|
||||
this.rowNumber = rowNumber;
|
||||
}
|
||||
|
||||
List<ExpandedPair> getPairs() {
|
||||
return this.pairs;
|
||||
}
|
||||
|
||||
int getRowNumber() {
|
||||
return this.rowNumber;
|
||||
}
|
||||
|
||||
boolean isEquivalent(List<ExpandedPair> otherPairs) {
|
||||
return this.pairs.equals(otherPairs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{ " + pairs + " }";
|
||||
}
|
||||
|
||||
/**
|
||||
* Two rows are equal if they contain the same pairs in the same order.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof ExpandedRow)) {
|
||||
return false;
|
||||
}
|
||||
ExpandedRow that = (ExpandedRow) o;
|
||||
return this.pairs.equals(that.pairs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return pairs.hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
768
src/oned/rss/expanded/RSSExpandedReader.java
Normal file
768
src/oned/rss/expanded/RSSExpandedReader.java
Normal file
@@ -0,0 +1,768 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.DecodeHintType;
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.ResultMetadataType;
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.common.BitArray;
|
||||
import com.google.zxing.common.detector.MathUtils;
|
||||
import com.google.zxing.oned.rss.AbstractRSSReader;
|
||||
import com.google.zxing.oned.rss.DataCharacter;
|
||||
import com.google.zxing.oned.rss.FinderPattern;
|
||||
import com.google.zxing.oned.rss.RSSUtils;
|
||||
import com.google.zxing.oned.rss.expanded.decoders.AbstractExpandedDecoder;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
|
||||
*/
|
||||
public final class RSSExpandedReader extends AbstractRSSReader {
|
||||
|
||||
private static final int[] SYMBOL_WIDEST = {7, 5, 4, 3, 1};
|
||||
private static final int[] EVEN_TOTAL_SUBSET = {4, 20, 52, 104, 204};
|
||||
private static final int[] GSUM = {0, 348, 1388, 2948, 3988};
|
||||
|
||||
private static final int[][] FINDER_PATTERNS = {
|
||||
{1,8,4,1}, // A
|
||||
{3,6,4,1}, // B
|
||||
{3,4,6,1}, // C
|
||||
{3,2,8,1}, // D
|
||||
{2,6,5,1}, // E
|
||||
{2,2,9,1} // F
|
||||
};
|
||||
|
||||
private static final int[][] WEIGHTS = {
|
||||
{ 1, 3, 9, 27, 81, 32, 96, 77},
|
||||
{ 20, 60, 180, 118, 143, 7, 21, 63},
|
||||
{189, 145, 13, 39, 117, 140, 209, 205},
|
||||
{193, 157, 49, 147, 19, 57, 171, 91},
|
||||
{ 62, 186, 136, 197, 169, 85, 44, 132},
|
||||
{185, 133, 188, 142, 4, 12, 36, 108},
|
||||
{113, 128, 173, 97, 80, 29, 87, 50},
|
||||
{150, 28, 84, 41, 123, 158, 52, 156},
|
||||
{ 46, 138, 203, 187, 139, 206, 196, 166},
|
||||
{ 76, 17, 51, 153, 37, 111, 122, 155},
|
||||
{ 43, 129, 176, 106, 107, 110, 119, 146},
|
||||
{ 16, 48, 144, 10, 30, 90, 59, 177},
|
||||
{109, 116, 137, 200, 178, 112, 125, 164},
|
||||
{ 70, 210, 208, 202, 184, 130, 179, 115},
|
||||
{134, 191, 151, 31, 93, 68, 204, 190},
|
||||
{148, 22, 66, 198, 172, 94, 71, 2},
|
||||
{ 6, 18, 54, 162, 64, 192,154, 40},
|
||||
{120, 149, 25, 75, 14, 42,126, 167},
|
||||
{ 79, 26, 78, 23, 69, 207,199, 175},
|
||||
{103, 98, 83, 38, 114, 131, 182, 124},
|
||||
{161, 61, 183, 127, 170, 88, 53, 159},
|
||||
{ 55, 165, 73, 8, 24, 72, 5, 15},
|
||||
{ 45, 135, 194, 160, 58, 174, 100, 89}
|
||||
};
|
||||
|
||||
private static final int FINDER_PAT_A = 0;
|
||||
private static final int FINDER_PAT_B = 1;
|
||||
private static final int FINDER_PAT_C = 2;
|
||||
private static final int FINDER_PAT_D = 3;
|
||||
private static final int FINDER_PAT_E = 4;
|
||||
private static final int FINDER_PAT_F = 5;
|
||||
|
||||
@SuppressWarnings("checkstyle:lineLength")
|
||||
private static final int[][] FINDER_PATTERN_SEQUENCES = {
|
||||
{ FINDER_PAT_A, FINDER_PAT_A },
|
||||
{ FINDER_PAT_A, FINDER_PAT_B, FINDER_PAT_B },
|
||||
{ FINDER_PAT_A, FINDER_PAT_C, FINDER_PAT_B, FINDER_PAT_D },
|
||||
{ FINDER_PAT_A, FINDER_PAT_E, FINDER_PAT_B, FINDER_PAT_D, FINDER_PAT_C },
|
||||
{ FINDER_PAT_A, FINDER_PAT_E, FINDER_PAT_B, FINDER_PAT_D, FINDER_PAT_D, FINDER_PAT_F },
|
||||
{ FINDER_PAT_A, FINDER_PAT_E, FINDER_PAT_B, FINDER_PAT_D, FINDER_PAT_E, FINDER_PAT_F, FINDER_PAT_F },
|
||||
{ FINDER_PAT_A, FINDER_PAT_A, FINDER_PAT_B, FINDER_PAT_B, FINDER_PAT_C, FINDER_PAT_C, FINDER_PAT_D, FINDER_PAT_D },
|
||||
{ FINDER_PAT_A, FINDER_PAT_A, FINDER_PAT_B, FINDER_PAT_B, FINDER_PAT_C, FINDER_PAT_C, FINDER_PAT_D, FINDER_PAT_E, FINDER_PAT_E },
|
||||
{ FINDER_PAT_A, FINDER_PAT_A, FINDER_PAT_B, FINDER_PAT_B, FINDER_PAT_C, FINDER_PAT_C, FINDER_PAT_D, FINDER_PAT_E, FINDER_PAT_F, FINDER_PAT_F },
|
||||
{ FINDER_PAT_A, FINDER_PAT_A, FINDER_PAT_B, FINDER_PAT_B, FINDER_PAT_C, FINDER_PAT_D, FINDER_PAT_D, FINDER_PAT_E, FINDER_PAT_E, FINDER_PAT_F, FINDER_PAT_F },
|
||||
};
|
||||
|
||||
private static final int MAX_PAIRS = 11;
|
||||
|
||||
private final List<ExpandedPair> pairs = new ArrayList<>(MAX_PAIRS);
|
||||
private final List<ExpandedRow> rows = new ArrayList<>();
|
||||
private final int [] startEnd = new int[2];
|
||||
private boolean startFromEven;
|
||||
|
||||
@Override
|
||||
public Result decodeRow(int rowNumber,
|
||||
BitArray row,
|
||||
Map<DecodeHintType,?> hints) throws NotFoundException, FormatException {
|
||||
// Rows can start with even pattern in case in prev rows there where odd number of patters.
|
||||
// So lets try twice
|
||||
this.pairs.clear();
|
||||
this.startFromEven = false;
|
||||
try {
|
||||
return constructResult(decodeRow2pairs(rowNumber, row));
|
||||
} catch (NotFoundException e) {
|
||||
// OK
|
||||
}
|
||||
|
||||
this.pairs.clear();
|
||||
this.startFromEven = true;
|
||||
return constructResult(decodeRow2pairs(rowNumber, row));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
this.pairs.clear();
|
||||
this.rows.clear();
|
||||
}
|
||||
|
||||
// Not private for testing
|
||||
List<ExpandedPair> decodeRow2pairs(int rowNumber, BitArray row) throws NotFoundException {
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
try {
|
||||
this.pairs.add(retrieveNextPair(row, this.pairs, rowNumber));
|
||||
} catch (NotFoundException nfe) {
|
||||
if (this.pairs.isEmpty()) {
|
||||
throw nfe;
|
||||
}
|
||||
// exit this loop when retrieveNextPair() fails and throws
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: verify sequence of finder patterns as in checkPairSequence()
|
||||
if (checkChecksum()) {
|
||||
return this.pairs;
|
||||
}
|
||||
|
||||
boolean tryStackedDecode = !this.rows.isEmpty();
|
||||
storeRow(rowNumber); // TODO: deal with reversed rows
|
||||
if (tryStackedDecode) {
|
||||
// When the image is 180-rotated, then rows are sorted in wrong direction.
|
||||
// Try twice with both the directions.
|
||||
List<ExpandedPair> ps = checkRows(false);
|
||||
if (ps != null) {
|
||||
return ps;
|
||||
}
|
||||
ps = checkRows(true);
|
||||
if (ps != null) {
|
||||
return ps;
|
||||
}
|
||||
}
|
||||
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
|
||||
private List<ExpandedPair> checkRows(boolean reverse) {
|
||||
// Limit number of rows we are checking
|
||||
// We use recursive algorithm with pure complexity and don't want it to take forever
|
||||
// Stacked barcode can have up to 11 rows, so 25 seems reasonable enough
|
||||
if (this.rows.size() > 25) {
|
||||
this.rows.clear(); // We will never have a chance to get result, so clear it
|
||||
return null;
|
||||
}
|
||||
|
||||
this.pairs.clear();
|
||||
if (reverse) {
|
||||
Collections.reverse(this.rows);
|
||||
}
|
||||
|
||||
List<ExpandedPair> ps = null;
|
||||
try {
|
||||
ps = checkRows(new ArrayList<>(), 0);
|
||||
} catch (NotFoundException e) {
|
||||
// OK
|
||||
}
|
||||
|
||||
if (reverse) {
|
||||
Collections.reverse(this.rows);
|
||||
}
|
||||
|
||||
return ps;
|
||||
}
|
||||
|
||||
// Try to construct a valid rows sequence
|
||||
// Recursion is used to implement backtracking
|
||||
private List<ExpandedPair> checkRows(List<ExpandedRow> collectedRows, int currentRow) throws NotFoundException {
|
||||
for (int i = currentRow; i < rows.size(); i++) {
|
||||
ExpandedRow row = rows.get(i);
|
||||
this.pairs.clear();
|
||||
for (ExpandedRow collectedRow : collectedRows) {
|
||||
this.pairs.addAll(collectedRow.getPairs());
|
||||
}
|
||||
this.pairs.addAll(row.getPairs());
|
||||
|
||||
if (isValidSequence(this.pairs)) {
|
||||
if (checkChecksum()) {
|
||||
return this.pairs;
|
||||
}
|
||||
|
||||
List<ExpandedRow> rs = new ArrayList<>(collectedRows);
|
||||
rs.add(row);
|
||||
try {
|
||||
// Recursion: try to add more rows
|
||||
return checkRows(rs, i + 1);
|
||||
} catch (NotFoundException e) {
|
||||
// We failed, try the next candidate
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
|
||||
// Whether the pairs form a valid find pattern sequence,
|
||||
// either complete or a prefix
|
||||
private static boolean isValidSequence(List<ExpandedPair> pairs) {
|
||||
for (int[] sequence : FINDER_PATTERN_SEQUENCES) {
|
||||
if (pairs.size() <= sequence.length) {
|
||||
boolean stop = true;
|
||||
for (int j = 0; j < pairs.size(); j++) {
|
||||
if (pairs.get(j).getFinderPattern().getValue() != sequence[j]) {
|
||||
stop = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (stop) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void storeRow(int rowNumber) {
|
||||
// Discard if duplicate above or below; otherwise insert in order by row number.
|
||||
int insertPos = 0;
|
||||
boolean prevIsSame = false;
|
||||
boolean nextIsSame = false;
|
||||
while (insertPos < this.rows.size()) {
|
||||
ExpandedRow erow = this.rows.get(insertPos);
|
||||
if (erow.getRowNumber() > rowNumber) {
|
||||
nextIsSame = erow.isEquivalent(this.pairs);
|
||||
break;
|
||||
}
|
||||
prevIsSame = erow.isEquivalent(this.pairs);
|
||||
insertPos++;
|
||||
}
|
||||
if (nextIsSame || prevIsSame) {
|
||||
return;
|
||||
}
|
||||
|
||||
// When the row was partially decoded (e.g. 2 pairs found instead of 3),
|
||||
// it will prevent us from detecting the barcode.
|
||||
// Try to merge partial rows
|
||||
|
||||
// Check whether the row is part of an already detected row
|
||||
if (isPartialRow(this.pairs, this.rows)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.rows.add(insertPos, new ExpandedRow(this.pairs, rowNumber));
|
||||
|
||||
removePartialRows(this.pairs, this.rows);
|
||||
}
|
||||
|
||||
// Remove all the rows that contains only specified pairs
|
||||
private static void removePartialRows(Collection<ExpandedPair> pairs, Collection<ExpandedRow> rows) {
|
||||
for (Iterator<ExpandedRow> iterator = rows.iterator(); iterator.hasNext();) {
|
||||
ExpandedRow r = iterator.next();
|
||||
if (r.getPairs().size() != pairs.size()) {
|
||||
boolean allFound = true;
|
||||
for (ExpandedPair p : r.getPairs()) {
|
||||
if (!pairs.contains(p)) {
|
||||
allFound = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (allFound) {
|
||||
// 'pairs' contains all the pairs from the row 'r'
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Returns true when one of the rows already contains all the pairs
|
||||
private static boolean isPartialRow(Iterable<ExpandedPair> pairs, Iterable<ExpandedRow> rows) {
|
||||
for (ExpandedRow r : rows) {
|
||||
boolean allFound = true;
|
||||
for (ExpandedPair p : pairs) {
|
||||
boolean found = false;
|
||||
for (ExpandedPair pp : r.getPairs()) {
|
||||
if (p.equals(pp)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
allFound = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (allFound) {
|
||||
// the row 'r' contain all the pairs from 'pairs'
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only used for unit testing
|
||||
List<ExpandedRow> getRows() {
|
||||
return this.rows;
|
||||
}
|
||||
|
||||
// Not private for unit testing
|
||||
static Result constructResult(List<ExpandedPair> pairs) throws NotFoundException, FormatException {
|
||||
BitArray binary = BitArrayBuilder.buildBitArray(pairs);
|
||||
|
||||
AbstractExpandedDecoder decoder = AbstractExpandedDecoder.createDecoder(binary);
|
||||
String resultingString = decoder.parseInformation();
|
||||
|
||||
ResultPoint[] firstPoints = pairs.get(0).getFinderPattern().getResultPoints();
|
||||
ResultPoint[] lastPoints = pairs.get(pairs.size() - 1).getFinderPattern().getResultPoints();
|
||||
|
||||
Result result = new Result(
|
||||
resultingString,
|
||||
null,
|
||||
new ResultPoint[]{firstPoints[0], firstPoints[1], lastPoints[0], lastPoints[1]},
|
||||
BarcodeFormat.RSS_EXPANDED
|
||||
);
|
||||
result.putMetadata(ResultMetadataType.SYMBOLOGY_IDENTIFIER, "]e0");
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean checkChecksum() {
|
||||
ExpandedPair firstPair = this.pairs.get(0);
|
||||
DataCharacter checkCharacter = firstPair.getLeftChar();
|
||||
DataCharacter firstCharacter = firstPair.getRightChar();
|
||||
|
||||
if (firstCharacter == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int checksum = firstCharacter.getChecksumPortion();
|
||||
int s = 2;
|
||||
|
||||
for (int i = 1; i < this.pairs.size(); ++i) {
|
||||
ExpandedPair currentPair = this.pairs.get(i);
|
||||
checksum += currentPair.getLeftChar().getChecksumPortion();
|
||||
s++;
|
||||
DataCharacter currentRightChar = currentPair.getRightChar();
|
||||
if (currentRightChar != null) {
|
||||
checksum += currentRightChar.getChecksumPortion();
|
||||
s++;
|
||||
}
|
||||
}
|
||||
|
||||
checksum %= 211;
|
||||
|
||||
int checkCharacterValue = 211 * (s - 4) + checksum;
|
||||
|
||||
return checkCharacterValue == checkCharacter.getValue();
|
||||
}
|
||||
|
||||
private static int getNextSecondBar(BitArray row, int initialPos) {
|
||||
int currentPos;
|
||||
if (row.get(initialPos)) {
|
||||
currentPos = row.getNextUnset(initialPos);
|
||||
currentPos = row.getNextSet(currentPos);
|
||||
} else {
|
||||
currentPos = row.getNextSet(initialPos);
|
||||
currentPos = row.getNextUnset(currentPos);
|
||||
}
|
||||
return currentPos;
|
||||
}
|
||||
|
||||
// not private for testing
|
||||
ExpandedPair retrieveNextPair(BitArray row, List<ExpandedPair> previousPairs, int rowNumber)
|
||||
throws NotFoundException {
|
||||
boolean isOddPattern = previousPairs.size() % 2 == 0;
|
||||
if (startFromEven) {
|
||||
isOddPattern = !isOddPattern;
|
||||
}
|
||||
|
||||
FinderPattern pattern;
|
||||
|
||||
boolean keepFinding = true;
|
||||
int forcedOffset = -1;
|
||||
do {
|
||||
this.findNextPair(row, previousPairs, forcedOffset);
|
||||
pattern = parseFoundFinderPattern(row, rowNumber, isOddPattern);
|
||||
if (pattern == null) {
|
||||
forcedOffset = getNextSecondBar(row, this.startEnd[0]);
|
||||
} else {
|
||||
keepFinding = false;
|
||||
}
|
||||
} while (keepFinding);
|
||||
|
||||
// When stacked symbol is split over multiple rows, there's no way to guess if this pair can be last or not.
|
||||
// boolean mayBeLast = checkPairSequence(previousPairs, pattern);
|
||||
|
||||
DataCharacter leftChar = this.decodeDataCharacter(row, pattern, isOddPattern, true);
|
||||
|
||||
if (!previousPairs.isEmpty() && previousPairs.get(previousPairs.size() - 1).mustBeLast()) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
|
||||
DataCharacter rightChar;
|
||||
try {
|
||||
rightChar = this.decodeDataCharacter(row, pattern, isOddPattern, false);
|
||||
} catch (NotFoundException ignored) {
|
||||
rightChar = null;
|
||||
}
|
||||
return new ExpandedPair(leftChar, rightChar, pattern);
|
||||
}
|
||||
|
||||
private void findNextPair(BitArray row, List<ExpandedPair> previousPairs, int forcedOffset)
|
||||
throws NotFoundException {
|
||||
int[] counters = this.getDecodeFinderCounters();
|
||||
counters[0] = 0;
|
||||
counters[1] = 0;
|
||||
counters[2] = 0;
|
||||
counters[3] = 0;
|
||||
|
||||
int width = row.getSize();
|
||||
|
||||
int rowOffset;
|
||||
if (forcedOffset >= 0) {
|
||||
rowOffset = forcedOffset;
|
||||
} else if (previousPairs.isEmpty()) {
|
||||
rowOffset = 0;
|
||||
} else {
|
||||
ExpandedPair lastPair = previousPairs.get(previousPairs.size() - 1);
|
||||
rowOffset = lastPair.getFinderPattern().getStartEnd()[1];
|
||||
}
|
||||
boolean searchingEvenPair = previousPairs.size() % 2 != 0;
|
||||
if (startFromEven) {
|
||||
searchingEvenPair = !searchingEvenPair;
|
||||
}
|
||||
|
||||
boolean isWhite = false;
|
||||
while (rowOffset < width) {
|
||||
isWhite = !row.get(rowOffset);
|
||||
if (!isWhite) {
|
||||
break;
|
||||
}
|
||||
rowOffset++;
|
||||
}
|
||||
|
||||
int counterPosition = 0;
|
||||
int patternStart = rowOffset;
|
||||
for (int x = rowOffset; x < width; x++) {
|
||||
if (row.get(x) != isWhite) {
|
||||
counters[counterPosition]++;
|
||||
} else {
|
||||
if (counterPosition == 3) {
|
||||
if (searchingEvenPair) {
|
||||
reverseCounters(counters);
|
||||
}
|
||||
|
||||
if (isFinderPattern(counters)) {
|
||||
this.startEnd[0] = patternStart;
|
||||
this.startEnd[1] = x;
|
||||
return;
|
||||
}
|
||||
|
||||
if (searchingEvenPair) {
|
||||
reverseCounters(counters);
|
||||
}
|
||||
|
||||
patternStart += counters[0] + counters[1];
|
||||
counters[0] = counters[2];
|
||||
counters[1] = counters[3];
|
||||
counters[2] = 0;
|
||||
counters[3] = 0;
|
||||
counterPosition--;
|
||||
} else {
|
||||
counterPosition++;
|
||||
}
|
||||
counters[counterPosition] = 1;
|
||||
isWhite = !isWhite;
|
||||
}
|
||||
}
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
|
||||
private static void reverseCounters(int [] counters) {
|
||||
int length = counters.length;
|
||||
for (int i = 0; i < length / 2; ++i) {
|
||||
int tmp = counters[i];
|
||||
counters[i] = counters[length - i - 1];
|
||||
counters[length - i - 1] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
private FinderPattern parseFoundFinderPattern(BitArray row, int rowNumber, boolean oddPattern) {
|
||||
// Actually we found elements 2-5.
|
||||
int firstCounter;
|
||||
int start;
|
||||
int end;
|
||||
|
||||
if (oddPattern) {
|
||||
// If pattern number is odd, we need to locate element 1 *before* the current block.
|
||||
|
||||
int firstElementStart = this.startEnd[0] - 1;
|
||||
// Locate element 1
|
||||
while (firstElementStart >= 0 && !row.get(firstElementStart)) {
|
||||
firstElementStart--;
|
||||
}
|
||||
|
||||
firstElementStart++;
|
||||
firstCounter = this.startEnd[0] - firstElementStart;
|
||||
start = firstElementStart;
|
||||
end = this.startEnd[1];
|
||||
|
||||
} else {
|
||||
// If pattern number is even, the pattern is reversed, so we need to locate element 1 *after* the current block.
|
||||
|
||||
start = this.startEnd[0];
|
||||
|
||||
end = row.getNextUnset(this.startEnd[1] + 1);
|
||||
firstCounter = end - this.startEnd[1];
|
||||
}
|
||||
|
||||
// Make 'counters' hold 1-4
|
||||
int [] counters = this.getDecodeFinderCounters();
|
||||
System.arraycopy(counters, 0, counters, 1, counters.length - 1);
|
||||
|
||||
counters[0] = firstCounter;
|
||||
int value;
|
||||
try {
|
||||
value = parseFinderValue(counters, FINDER_PATTERNS);
|
||||
} catch (NotFoundException ignored) {
|
||||
return null;
|
||||
}
|
||||
return new FinderPattern(value, new int[] {start, end}, start, end, rowNumber);
|
||||
}
|
||||
|
||||
DataCharacter decodeDataCharacter(BitArray row,
|
||||
FinderPattern pattern,
|
||||
boolean isOddPattern,
|
||||
boolean leftChar) throws NotFoundException {
|
||||
int[] counters = this.getDataCharacterCounters();
|
||||
Arrays.fill(counters, 0);
|
||||
|
||||
if (leftChar) {
|
||||
recordPatternInReverse(row, pattern.getStartEnd()[0], counters);
|
||||
} else {
|
||||
recordPattern(row, pattern.getStartEnd()[1], counters);
|
||||
// reverse it
|
||||
for (int i = 0, j = counters.length - 1; i < j; i++, j--) {
|
||||
int temp = counters[i];
|
||||
counters[i] = counters[j];
|
||||
counters[j] = temp;
|
||||
}
|
||||
} //counters[] has the pixels of the module
|
||||
|
||||
int numModules = 17; //left and right data characters have all the same length
|
||||
float elementWidth = MathUtils.sum(counters) / (float) numModules;
|
||||
|
||||
// Sanity check: element width for pattern and the character should match
|
||||
float expectedElementWidth = (pattern.getStartEnd()[1] - pattern.getStartEnd()[0]) / 15.0f;
|
||||
if (Math.abs(elementWidth - expectedElementWidth) / expectedElementWidth > 0.3f) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
|
||||
int[] oddCounts = this.getOddCounts();
|
||||
int[] evenCounts = this.getEvenCounts();
|
||||
float[] oddRoundingErrors = this.getOddRoundingErrors();
|
||||
float[] evenRoundingErrors = this.getEvenRoundingErrors();
|
||||
|
||||
for (int i = 0; i < counters.length; i++) {
|
||||
float value = 1.0f * counters[i] / elementWidth;
|
||||
int count = (int) (value + 0.5f); // Round
|
||||
if (count < 1) {
|
||||
if (value < 0.3f) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
count = 1;
|
||||
} else if (count > 8) {
|
||||
if (value > 8.7f) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
count = 8;
|
||||
}
|
||||
int offset = i / 2;
|
||||
if ((i & 0x01) == 0) {
|
||||
oddCounts[offset] = count;
|
||||
oddRoundingErrors[offset] = value - count;
|
||||
} else {
|
||||
evenCounts[offset] = count;
|
||||
evenRoundingErrors[offset] = value - count;
|
||||
}
|
||||
}
|
||||
|
||||
adjustOddEvenCounts(numModules);
|
||||
|
||||
int weightRowNumber = 4 * pattern.getValue() + (isOddPattern ? 0 : 2) + (leftChar ? 0 : 1) - 1;
|
||||
|
||||
int oddSum = 0;
|
||||
int oddChecksumPortion = 0;
|
||||
for (int i = oddCounts.length - 1; i >= 0; i--) {
|
||||
if (isNotA1left(pattern, isOddPattern, leftChar)) {
|
||||
int weight = WEIGHTS[weightRowNumber][2 * i];
|
||||
oddChecksumPortion += oddCounts[i] * weight;
|
||||
}
|
||||
oddSum += oddCounts[i];
|
||||
}
|
||||
int evenChecksumPortion = 0;
|
||||
for (int i = evenCounts.length - 1; i >= 0; i--) {
|
||||
if (isNotA1left(pattern, isOddPattern, leftChar)) {
|
||||
int weight = WEIGHTS[weightRowNumber][2 * i + 1];
|
||||
evenChecksumPortion += evenCounts[i] * weight;
|
||||
}
|
||||
}
|
||||
int checksumPortion = oddChecksumPortion + evenChecksumPortion;
|
||||
|
||||
if ((oddSum & 0x01) != 0 || oddSum > 13 || oddSum < 4) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
|
||||
int group = (13 - oddSum) / 2;
|
||||
int oddWidest = SYMBOL_WIDEST[group];
|
||||
int evenWidest = 9 - oddWidest;
|
||||
int vOdd = RSSUtils.getRSSvalue(oddCounts, oddWidest, true);
|
||||
int vEven = RSSUtils.getRSSvalue(evenCounts, evenWidest, false);
|
||||
int tEven = EVEN_TOTAL_SUBSET[group];
|
||||
int gSum = GSUM[group];
|
||||
int value = vOdd * tEven + vEven + gSum;
|
||||
|
||||
return new DataCharacter(value, checksumPortion);
|
||||
}
|
||||
|
||||
private static boolean isNotA1left(FinderPattern pattern, boolean isOddPattern, boolean leftChar) {
|
||||
// A1: pattern.getValue is 0 (A), and it's an oddPattern, and it is a left char
|
||||
return !(pattern.getValue() == 0 && isOddPattern && leftChar);
|
||||
}
|
||||
|
||||
private void adjustOddEvenCounts(int numModules) throws NotFoundException {
|
||||
|
||||
int oddSum = MathUtils.sum(this.getOddCounts());
|
||||
int evenSum = MathUtils.sum(this.getEvenCounts());
|
||||
|
||||
boolean incrementOdd = false;
|
||||
boolean decrementOdd = false;
|
||||
|
||||
if (oddSum > 13) {
|
||||
decrementOdd = true;
|
||||
} else if (oddSum < 4) {
|
||||
incrementOdd = true;
|
||||
}
|
||||
boolean incrementEven = false;
|
||||
boolean decrementEven = false;
|
||||
if (evenSum > 13) {
|
||||
decrementEven = true;
|
||||
} else if (evenSum < 4) {
|
||||
incrementEven = true;
|
||||
}
|
||||
|
||||
int mismatch = oddSum + evenSum - numModules;
|
||||
boolean oddParityBad = (oddSum & 0x01) == 1;
|
||||
boolean evenParityBad = (evenSum & 0x01) == 0;
|
||||
switch (mismatch) {
|
||||
case 1:
|
||||
if (oddParityBad) {
|
||||
if (evenParityBad) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
decrementOdd = true;
|
||||
} else {
|
||||
if (!evenParityBad) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
decrementEven = true;
|
||||
}
|
||||
break;
|
||||
case -1:
|
||||
if (oddParityBad) {
|
||||
if (evenParityBad) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
incrementOdd = true;
|
||||
} else {
|
||||
if (!evenParityBad) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
incrementEven = true;
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
if (oddParityBad) {
|
||||
if (!evenParityBad) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
// Both bad
|
||||
if (oddSum < evenSum) {
|
||||
incrementOdd = true;
|
||||
decrementEven = true;
|
||||
} else {
|
||||
decrementOdd = true;
|
||||
incrementEven = true;
|
||||
}
|
||||
} else {
|
||||
if (evenParityBad) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
// Nothing to do!
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
|
||||
if (incrementOdd) {
|
||||
if (decrementOdd) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
increment(this.getOddCounts(), this.getOddRoundingErrors());
|
||||
}
|
||||
if (decrementOdd) {
|
||||
decrement(this.getOddCounts(), this.getOddRoundingErrors());
|
||||
}
|
||||
if (incrementEven) {
|
||||
if (decrementEven) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
increment(this.getEvenCounts(), this.getOddRoundingErrors());
|
||||
}
|
||||
if (decrementEven) {
|
||||
decrement(this.getEvenCounts(), this.getEvenRoundingErrors());
|
||||
}
|
||||
}
|
||||
}
|
||||
49
src/oned/rss/expanded/decoders/AI013103decoder.java
Normal file
49
src/oned/rss/expanded/decoders/AI013103decoder.java
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded.decoders;
|
||||
|
||||
import com.google.zxing.common.BitArray;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
*/
|
||||
final class AI013103decoder extends AI013x0xDecoder {
|
||||
|
||||
AI013103decoder(BitArray information) {
|
||||
super(information);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addWeightCode(StringBuilder buf, int weight) {
|
||||
buf.append("(3103)");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int checkWeight(int weight) {
|
||||
return weight;
|
||||
}
|
||||
}
|
||||
57
src/oned/rss/expanded/decoders/AI01320xDecoder.java
Normal file
57
src/oned/rss/expanded/decoders/AI01320xDecoder.java
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded.decoders;
|
||||
|
||||
import com.google.zxing.common.BitArray;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
*/
|
||||
final class AI01320xDecoder extends AI013x0xDecoder {
|
||||
|
||||
AI01320xDecoder(BitArray information) {
|
||||
super(information);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addWeightCode(StringBuilder buf, int weight) {
|
||||
if (weight < 10000) {
|
||||
buf.append("(3202)");
|
||||
} else {
|
||||
buf.append("(3203)");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int checkWeight(int weight) {
|
||||
if (weight < 10000) {
|
||||
return weight;
|
||||
}
|
||||
return weight - 10000;
|
||||
}
|
||||
|
||||
}
|
||||
68
src/oned/rss/expanded/decoders/AI01392xDecoder.java
Normal file
68
src/oned/rss/expanded/decoders/AI01392xDecoder.java
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded.decoders;
|
||||
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.common.BitArray;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
*/
|
||||
final class AI01392xDecoder extends AI01decoder {
|
||||
|
||||
private static final int HEADER_SIZE = 5 + 1 + 2;
|
||||
private static final int LAST_DIGIT_SIZE = 2;
|
||||
|
||||
AI01392xDecoder(BitArray information) {
|
||||
super(information);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parseInformation() throws NotFoundException, FormatException {
|
||||
if (this.getInformation().getSize() < HEADER_SIZE + GTIN_SIZE) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
|
||||
StringBuilder buf = new StringBuilder();
|
||||
|
||||
encodeCompressedGtin(buf, HEADER_SIZE);
|
||||
|
||||
int lastAIdigit =
|
||||
this.getGeneralDecoder().extractNumericValueFromBitArray(HEADER_SIZE + GTIN_SIZE, LAST_DIGIT_SIZE);
|
||||
buf.append("(392");
|
||||
buf.append(lastAIdigit);
|
||||
buf.append(')');
|
||||
|
||||
DecodedInformation decodedInformation =
|
||||
this.getGeneralDecoder().decodeGeneralPurposeField(HEADER_SIZE + GTIN_SIZE + LAST_DIGIT_SIZE, null);
|
||||
buf.append(decodedInformation.getNewString());
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
}
|
||||
78
src/oned/rss/expanded/decoders/AI01393xDecoder.java
Normal file
78
src/oned/rss/expanded/decoders/AI01393xDecoder.java
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
package com.google.zxing.oned.rss.expanded.decoders;
|
||||
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.common.BitArray;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
*/
|
||||
final class AI01393xDecoder extends AI01decoder {
|
||||
|
||||
private static final int HEADER_SIZE = 5 + 1 + 2;
|
||||
private static final int LAST_DIGIT_SIZE = 2;
|
||||
private static final int FIRST_THREE_DIGITS_SIZE = 10;
|
||||
|
||||
AI01393xDecoder(BitArray information) {
|
||||
super(information);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parseInformation() throws NotFoundException, FormatException {
|
||||
if (this.getInformation().getSize() < HEADER_SIZE + GTIN_SIZE) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
|
||||
StringBuilder buf = new StringBuilder();
|
||||
|
||||
encodeCompressedGtin(buf, HEADER_SIZE);
|
||||
|
||||
int lastAIdigit =
|
||||
this.getGeneralDecoder().extractNumericValueFromBitArray(HEADER_SIZE + GTIN_SIZE, LAST_DIGIT_SIZE);
|
||||
|
||||
buf.append("(393");
|
||||
buf.append(lastAIdigit);
|
||||
buf.append(')');
|
||||
|
||||
int firstThreeDigits = this.getGeneralDecoder().extractNumericValueFromBitArray(
|
||||
HEADER_SIZE + GTIN_SIZE + LAST_DIGIT_SIZE, FIRST_THREE_DIGITS_SIZE);
|
||||
if (firstThreeDigits / 100 == 0) {
|
||||
buf.append('0');
|
||||
}
|
||||
if (firstThreeDigits / 10 == 0) {
|
||||
buf.append('0');
|
||||
}
|
||||
buf.append(firstThreeDigits);
|
||||
|
||||
DecodedInformation generalInformation = this.getGeneralDecoder().decodeGeneralPurposeField(
|
||||
HEADER_SIZE + GTIN_SIZE + LAST_DIGIT_SIZE + FIRST_THREE_DIGITS_SIZE, null);
|
||||
buf.append(generalInformation.getNewString());
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
108
src/oned/rss/expanded/decoders/AI013x0x1xDecoder.java
Normal file
108
src/oned/rss/expanded/decoders/AI013x0x1xDecoder.java
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded.decoders;
|
||||
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.common.BitArray;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
|
||||
*/
|
||||
final class AI013x0x1xDecoder extends AI01weightDecoder {
|
||||
|
||||
private static final int HEADER_SIZE = 7 + 1;
|
||||
private static final int WEIGHT_SIZE = 20;
|
||||
private static final int DATE_SIZE = 16;
|
||||
|
||||
private final String dateCode;
|
||||
private final String firstAIdigits;
|
||||
|
||||
AI013x0x1xDecoder(BitArray information, String firstAIdigits, String dateCode) {
|
||||
super(information);
|
||||
this.dateCode = dateCode;
|
||||
this.firstAIdigits = firstAIdigits;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parseInformation() throws NotFoundException {
|
||||
if (this.getInformation().getSize() != HEADER_SIZE + GTIN_SIZE + WEIGHT_SIZE + DATE_SIZE) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
|
||||
StringBuilder buf = new StringBuilder();
|
||||
|
||||
encodeCompressedGtin(buf, HEADER_SIZE);
|
||||
encodeCompressedWeight(buf, HEADER_SIZE + GTIN_SIZE, WEIGHT_SIZE);
|
||||
encodeCompressedDate(buf, HEADER_SIZE + GTIN_SIZE + WEIGHT_SIZE);
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private void encodeCompressedDate(StringBuilder buf, int currentPos) {
|
||||
int numericDate = this.getGeneralDecoder().extractNumericValueFromBitArray(currentPos, DATE_SIZE);
|
||||
if (numericDate == 38400) {
|
||||
return;
|
||||
}
|
||||
|
||||
buf.append('(');
|
||||
buf.append(this.dateCode);
|
||||
buf.append(')');
|
||||
|
||||
int day = numericDate % 32;
|
||||
numericDate /= 32;
|
||||
int month = numericDate % 12 + 1;
|
||||
numericDate /= 12;
|
||||
int year = numericDate;
|
||||
|
||||
if (year / 10 == 0) {
|
||||
buf.append('0');
|
||||
}
|
||||
buf.append(year);
|
||||
if (month / 10 == 0) {
|
||||
buf.append('0');
|
||||
}
|
||||
buf.append(month);
|
||||
if (day / 10 == 0) {
|
||||
buf.append('0');
|
||||
}
|
||||
buf.append(day);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addWeightCode(StringBuilder buf, int weight) {
|
||||
buf.append('(');
|
||||
buf.append(this.firstAIdigits);
|
||||
buf.append(weight / 100000);
|
||||
buf.append(')');
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int checkWeight(int weight) {
|
||||
return weight % 100000;
|
||||
}
|
||||
}
|
||||
57
src/oned/rss/expanded/decoders/AI013x0xDecoder.java
Normal file
57
src/oned/rss/expanded/decoders/AI013x0xDecoder.java
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded.decoders;
|
||||
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.common.BitArray;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
*/
|
||||
abstract class AI013x0xDecoder extends AI01weightDecoder {
|
||||
|
||||
private static final int HEADER_SIZE = 4 + 1;
|
||||
private static final int WEIGHT_SIZE = 15;
|
||||
|
||||
AI013x0xDecoder(BitArray information) {
|
||||
super(information);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parseInformation() throws NotFoundException {
|
||||
if (this.getInformation().getSize() != HEADER_SIZE + GTIN_SIZE + WEIGHT_SIZE) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
|
||||
StringBuilder buf = new StringBuilder();
|
||||
|
||||
encodeCompressedGtin(buf, HEADER_SIZE);
|
||||
encodeCompressedWeight(buf, HEADER_SIZE + GTIN_SIZE, WEIGHT_SIZE);
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
58
src/oned/rss/expanded/decoders/AI01AndOtherAIs.java
Normal file
58
src/oned/rss/expanded/decoders/AI01AndOtherAIs.java
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded.decoders;
|
||||
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.common.BitArray;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
|
||||
*/
|
||||
final class AI01AndOtherAIs extends AI01decoder {
|
||||
|
||||
private static final int HEADER_SIZE = 1 + 1 + 2; //first bit encodes the linkage flag,
|
||||
//the second one is the encodation method, and the other two are for the variable length
|
||||
AI01AndOtherAIs(BitArray information) {
|
||||
super(information);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parseInformation() throws NotFoundException, FormatException {
|
||||
StringBuilder buff = new StringBuilder();
|
||||
|
||||
buff.append("(01)");
|
||||
int initialGtinPosition = buff.length();
|
||||
int firstGtinDigit = this.getGeneralDecoder().extractNumericValueFromBitArray(HEADER_SIZE, 4);
|
||||
buff.append(firstGtinDigit);
|
||||
|
||||
this.encodeCompressedGtinWithoutAI(buff, HEADER_SIZE + 4, initialGtinPosition);
|
||||
|
||||
return this.getGeneralDecoder().decodeAllCodes(buff, HEADER_SIZE + 44);
|
||||
}
|
||||
}
|
||||
81
src/oned/rss/expanded/decoders/AI01decoder.java
Normal file
81
src/oned/rss/expanded/decoders/AI01decoder.java
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded.decoders;
|
||||
|
||||
import com.google.zxing.common.BitArray;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
|
||||
*/
|
||||
abstract class AI01decoder extends AbstractExpandedDecoder {
|
||||
|
||||
static final int GTIN_SIZE = 40;
|
||||
|
||||
AI01decoder(BitArray information) {
|
||||
super(information);
|
||||
}
|
||||
|
||||
final void encodeCompressedGtin(StringBuilder buf, int currentPos) {
|
||||
buf.append("(01)");
|
||||
int initialPosition = buf.length();
|
||||
buf.append('9');
|
||||
|
||||
encodeCompressedGtinWithoutAI(buf, currentPos, initialPosition);
|
||||
}
|
||||
|
||||
final void encodeCompressedGtinWithoutAI(StringBuilder buf, int currentPos, int initialBufferPosition) {
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
int currentBlock = this.getGeneralDecoder().extractNumericValueFromBitArray(currentPos + 10 * i, 10);
|
||||
if (currentBlock / 100 == 0) {
|
||||
buf.append('0');
|
||||
}
|
||||
if (currentBlock / 10 == 0) {
|
||||
buf.append('0');
|
||||
}
|
||||
buf.append(currentBlock);
|
||||
}
|
||||
|
||||
appendCheckDigit(buf, initialBufferPosition);
|
||||
}
|
||||
|
||||
private static void appendCheckDigit(StringBuilder buf, int currentPos) {
|
||||
int checkDigit = 0;
|
||||
for (int i = 0; i < 13; i++) {
|
||||
int digit = buf.charAt(i + currentPos) - '0';
|
||||
checkDigit += (i & 0x01) == 0 ? 3 * digit : digit;
|
||||
}
|
||||
|
||||
checkDigit = 10 - (checkDigit % 10);
|
||||
if (checkDigit == 10) {
|
||||
checkDigit = 0;
|
||||
}
|
||||
|
||||
buf.append(checkDigit);
|
||||
}
|
||||
|
||||
}
|
||||
60
src/oned/rss/expanded/decoders/AI01weightDecoder.java
Normal file
60
src/oned/rss/expanded/decoders/AI01weightDecoder.java
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded.decoders;
|
||||
|
||||
import com.google.zxing.common.BitArray;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
*/
|
||||
abstract class AI01weightDecoder extends AI01decoder {
|
||||
|
||||
AI01weightDecoder(BitArray information) {
|
||||
super(information);
|
||||
}
|
||||
|
||||
final void encodeCompressedWeight(StringBuilder buf, int currentPos, int weightSize) {
|
||||
int originalWeightNumeric = this.getGeneralDecoder().extractNumericValueFromBitArray(currentPos, weightSize);
|
||||
addWeightCode(buf, originalWeightNumeric);
|
||||
|
||||
int weightNumeric = checkWeight(originalWeightNumeric);
|
||||
|
||||
int currentDivisor = 100000;
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
if (weightNumeric / currentDivisor == 0) {
|
||||
buf.append('0');
|
||||
}
|
||||
currentDivisor /= 10;
|
||||
}
|
||||
buf.append(weightNumeric);
|
||||
}
|
||||
|
||||
protected abstract void addWeightCode(StringBuilder buf, int weight);
|
||||
|
||||
protected abstract int checkWeight(int weight);
|
||||
|
||||
}
|
||||
93
src/oned/rss/expanded/decoders/AbstractExpandedDecoder.java
Normal file
93
src/oned/rss/expanded/decoders/AbstractExpandedDecoder.java
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded.decoders;
|
||||
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.common.BitArray;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
|
||||
*/
|
||||
public abstract class AbstractExpandedDecoder {
|
||||
|
||||
private final BitArray information;
|
||||
private final GeneralAppIdDecoder generalDecoder;
|
||||
|
||||
AbstractExpandedDecoder(BitArray information) {
|
||||
this.information = information;
|
||||
this.generalDecoder = new GeneralAppIdDecoder(information);
|
||||
}
|
||||
|
||||
protected final BitArray getInformation() {
|
||||
return information;
|
||||
}
|
||||
|
||||
protected final GeneralAppIdDecoder getGeneralDecoder() {
|
||||
return generalDecoder;
|
||||
}
|
||||
|
||||
public abstract String parseInformation() throws NotFoundException, FormatException;
|
||||
|
||||
public static AbstractExpandedDecoder createDecoder(BitArray information) {
|
||||
if (information.get(1)) {
|
||||
return new AI01AndOtherAIs(information);
|
||||
}
|
||||
if (!information.get(2)) {
|
||||
return new AnyAIDecoder(information);
|
||||
}
|
||||
|
||||
int fourBitEncodationMethod = GeneralAppIdDecoder.extractNumericValueFromBitArray(information, 1, 4);
|
||||
|
||||
switch (fourBitEncodationMethod) {
|
||||
case 4: return new AI013103decoder(information);
|
||||
case 5: return new AI01320xDecoder(information);
|
||||
}
|
||||
|
||||
int fiveBitEncodationMethod = GeneralAppIdDecoder.extractNumericValueFromBitArray(information, 1, 5);
|
||||
switch (fiveBitEncodationMethod) {
|
||||
case 12: return new AI01392xDecoder(information);
|
||||
case 13: return new AI01393xDecoder(information);
|
||||
}
|
||||
|
||||
int sevenBitEncodationMethod = GeneralAppIdDecoder.extractNumericValueFromBitArray(information, 1, 7);
|
||||
switch (sevenBitEncodationMethod) {
|
||||
case 56: return new AI013x0x1xDecoder(information, "310", "11");
|
||||
case 57: return new AI013x0x1xDecoder(information, "320", "11");
|
||||
case 58: return new AI013x0x1xDecoder(information, "310", "13");
|
||||
case 59: return new AI013x0x1xDecoder(information, "320", "13");
|
||||
case 60: return new AI013x0x1xDecoder(information, "310", "15");
|
||||
case 61: return new AI013x0x1xDecoder(information, "320", "15");
|
||||
case 62: return new AI013x0x1xDecoder(information, "310", "17");
|
||||
case 63: return new AI013x0x1xDecoder(information, "320", "17");
|
||||
}
|
||||
|
||||
throw new IllegalStateException("unknown decoder: " + information);
|
||||
}
|
||||
|
||||
}
|
||||
50
src/oned/rss/expanded/decoders/AnyAIDecoder.java
Normal file
50
src/oned/rss/expanded/decoders/AnyAIDecoder.java
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded.decoders;
|
||||
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.common.BitArray;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
|
||||
*/
|
||||
final class AnyAIDecoder extends AbstractExpandedDecoder {
|
||||
|
||||
private static final int HEADER_SIZE = 2 + 1 + 2;
|
||||
|
||||
AnyAIDecoder(BitArray information) {
|
||||
super(information);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parseInformation() throws NotFoundException, FormatException {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
return this.getGeneralDecoder().decodeAllCodes(buf, HEADER_SIZE);
|
||||
}
|
||||
}
|
||||
54
src/oned/rss/expanded/decoders/BlockParsedResult.java
Normal file
54
src/oned/rss/expanded/decoders/BlockParsedResult.java
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded.decoders;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
|
||||
*/
|
||||
final class BlockParsedResult {
|
||||
|
||||
private final DecodedInformation decodedInformation;
|
||||
private final boolean finished;
|
||||
|
||||
BlockParsedResult() {
|
||||
this(null, false);
|
||||
}
|
||||
|
||||
BlockParsedResult(DecodedInformation information, boolean finished) {
|
||||
this.finished = finished;
|
||||
this.decodedInformation = information;
|
||||
}
|
||||
|
||||
DecodedInformation getDecodedInformation() {
|
||||
return this.decodedInformation;
|
||||
}
|
||||
|
||||
boolean isFinished() {
|
||||
return this.finished;
|
||||
}
|
||||
}
|
||||
83
src/oned/rss/expanded/decoders/CurrentParsingState.java
Normal file
83
src/oned/rss/expanded/decoders/CurrentParsingState.java
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded.decoders;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
*/
|
||||
final class CurrentParsingState {
|
||||
|
||||
private int position;
|
||||
private State encoding;
|
||||
|
||||
private enum State {
|
||||
NUMERIC,
|
||||
ALPHA,
|
||||
ISO_IEC_646
|
||||
}
|
||||
|
||||
CurrentParsingState() {
|
||||
this.position = 0;
|
||||
this.encoding = State.NUMERIC;
|
||||
}
|
||||
|
||||
int getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
void setPosition(int position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
void incrementPosition(int delta) {
|
||||
position += delta;
|
||||
}
|
||||
|
||||
boolean isAlpha() {
|
||||
return this.encoding == State.ALPHA;
|
||||
}
|
||||
|
||||
boolean isNumeric() {
|
||||
return this.encoding == State.NUMERIC;
|
||||
}
|
||||
|
||||
boolean isIsoIec646() {
|
||||
return this.encoding == State.ISO_IEC_646;
|
||||
}
|
||||
|
||||
void setNumeric() {
|
||||
this.encoding = State.NUMERIC;
|
||||
}
|
||||
|
||||
void setAlpha() {
|
||||
this.encoding = State.ALPHA;
|
||||
}
|
||||
|
||||
void setIsoIec646() {
|
||||
this.encoding = State.ISO_IEC_646;
|
||||
}
|
||||
}
|
||||
52
src/oned/rss/expanded/decoders/DecodedChar.java
Normal file
52
src/oned/rss/expanded/decoders/DecodedChar.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded.decoders;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
|
||||
*/
|
||||
final class DecodedChar extends DecodedObject {
|
||||
|
||||
private final char value;
|
||||
|
||||
static final char FNC1 = '$'; // It's not in Alphanumeric neither in ISO/IEC 646 charset
|
||||
|
||||
DecodedChar(int newPosition, char value) {
|
||||
super(newPosition);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
char getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
boolean isFNC1() {
|
||||
return this.value == FNC1;
|
||||
}
|
||||
|
||||
}
|
||||
64
src/oned/rss/expanded/decoders/DecodedInformation.java
Normal file
64
src/oned/rss/expanded/decoders/DecodedInformation.java
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded.decoders;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
|
||||
*/
|
||||
final class DecodedInformation extends DecodedObject {
|
||||
|
||||
private final String newString;
|
||||
private final int remainingValue;
|
||||
private final boolean remaining;
|
||||
|
||||
DecodedInformation(int newPosition, String newString) {
|
||||
super(newPosition);
|
||||
this.newString = newString;
|
||||
this.remaining = false;
|
||||
this.remainingValue = 0;
|
||||
}
|
||||
|
||||
DecodedInformation(int newPosition, String newString, int remainingValue) {
|
||||
super(newPosition);
|
||||
this.remaining = true;
|
||||
this.remainingValue = remainingValue;
|
||||
this.newString = newString;
|
||||
}
|
||||
|
||||
String getNewString() {
|
||||
return this.newString;
|
||||
}
|
||||
|
||||
boolean isRemaining() {
|
||||
return this.remaining;
|
||||
}
|
||||
|
||||
int getRemainingValue() {
|
||||
return this.remainingValue;
|
||||
}
|
||||
}
|
||||
73
src/oned/rss/expanded/decoders/DecodedNumeric.java
Normal file
73
src/oned/rss/expanded/decoders/DecodedNumeric.java
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded.decoders;
|
||||
|
||||
import com.google.zxing.FormatException;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
|
||||
*/
|
||||
final class DecodedNumeric extends DecodedObject {
|
||||
|
||||
private final int firstDigit;
|
||||
private final int secondDigit;
|
||||
|
||||
static final int FNC1 = 10;
|
||||
|
||||
DecodedNumeric(int newPosition, int firstDigit, int secondDigit) throws FormatException {
|
||||
super(newPosition);
|
||||
|
||||
if (firstDigit < 0 || firstDigit > 10 || secondDigit < 0 || secondDigit > 10) {
|
||||
throw FormatException.getFormatInstance();
|
||||
}
|
||||
|
||||
this.firstDigit = firstDigit;
|
||||
this.secondDigit = secondDigit;
|
||||
}
|
||||
|
||||
int getFirstDigit() {
|
||||
return this.firstDigit;
|
||||
}
|
||||
|
||||
int getSecondDigit() {
|
||||
return this.secondDigit;
|
||||
}
|
||||
|
||||
int getValue() {
|
||||
return this.firstDigit * 10 + this.secondDigit;
|
||||
}
|
||||
|
||||
boolean isFirstDigitFNC1() {
|
||||
return this.firstDigit == FNC1;
|
||||
}
|
||||
|
||||
boolean isSecondDigitFNC1() {
|
||||
return this.secondDigit == FNC1;
|
||||
}
|
||||
|
||||
}
|
||||
44
src/oned/rss/expanded/decoders/DecodedObject.java
Normal file
44
src/oned/rss/expanded/decoders/DecodedObject.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded.decoders;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
*/
|
||||
abstract class DecodedObject {
|
||||
|
||||
private final int newPosition;
|
||||
|
||||
DecodedObject(int newPosition) {
|
||||
this.newPosition = newPosition;
|
||||
}
|
||||
|
||||
final int getNewPosition() {
|
||||
return this.newPosition;
|
||||
}
|
||||
|
||||
}
|
||||
239
src/oned/rss/expanded/decoders/FieldParser.java
Normal file
239
src/oned/rss/expanded/decoders/FieldParser.java
Normal file
@@ -0,0 +1,239 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded.decoders;
|
||||
|
||||
import com.google.zxing.NotFoundException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
|
||||
*/
|
||||
final class FieldParser {
|
||||
|
||||
private static final Map<String,DataLength> TWO_DIGIT_DATA_LENGTH = new HashMap<>();
|
||||
static {
|
||||
TWO_DIGIT_DATA_LENGTH.put("00", DataLength.fixed(18));
|
||||
TWO_DIGIT_DATA_LENGTH.put("01", DataLength.fixed(14));
|
||||
TWO_DIGIT_DATA_LENGTH.put("02", DataLength.fixed(14));
|
||||
TWO_DIGIT_DATA_LENGTH.put("10", DataLength.variable(20));
|
||||
TWO_DIGIT_DATA_LENGTH.put("11", DataLength.fixed(6));
|
||||
TWO_DIGIT_DATA_LENGTH.put("12", DataLength.fixed(6));
|
||||
TWO_DIGIT_DATA_LENGTH.put("13", DataLength.fixed(6));
|
||||
TWO_DIGIT_DATA_LENGTH.put("15", DataLength.fixed(6));
|
||||
TWO_DIGIT_DATA_LENGTH.put("17", DataLength.fixed(6));
|
||||
TWO_DIGIT_DATA_LENGTH.put("20", DataLength.fixed(2));
|
||||
TWO_DIGIT_DATA_LENGTH.put("21", DataLength.variable(20));
|
||||
TWO_DIGIT_DATA_LENGTH.put("22", DataLength.variable(29));
|
||||
TWO_DIGIT_DATA_LENGTH.put("30", DataLength.variable(8));
|
||||
TWO_DIGIT_DATA_LENGTH.put("37", DataLength.variable(8));
|
||||
//internal company codes
|
||||
for (int i = 90; i <= 99; i++) {
|
||||
TWO_DIGIT_DATA_LENGTH.put(String.valueOf(i), DataLength.variable(30));
|
||||
}
|
||||
}
|
||||
|
||||
private static final Map<String,DataLength> THREE_DIGIT_DATA_LENGTH = new HashMap<>();
|
||||
static {
|
||||
THREE_DIGIT_DATA_LENGTH.put("240", DataLength.variable(30));
|
||||
THREE_DIGIT_DATA_LENGTH.put("241", DataLength.variable(30));
|
||||
THREE_DIGIT_DATA_LENGTH.put("242", DataLength.variable(6));
|
||||
THREE_DIGIT_DATA_LENGTH.put("250", DataLength.variable(30));
|
||||
THREE_DIGIT_DATA_LENGTH.put("251", DataLength.variable(30));
|
||||
THREE_DIGIT_DATA_LENGTH.put("253", DataLength.variable(17));
|
||||
THREE_DIGIT_DATA_LENGTH.put("254", DataLength.variable(20));
|
||||
THREE_DIGIT_DATA_LENGTH.put("400", DataLength.variable(30));
|
||||
THREE_DIGIT_DATA_LENGTH.put("401", DataLength.variable(30));
|
||||
THREE_DIGIT_DATA_LENGTH.put("402", DataLength.fixed(17));
|
||||
THREE_DIGIT_DATA_LENGTH.put("403", DataLength.variable(30));
|
||||
THREE_DIGIT_DATA_LENGTH.put("410", DataLength.fixed(13));
|
||||
THREE_DIGIT_DATA_LENGTH.put("411", DataLength.fixed(13));
|
||||
THREE_DIGIT_DATA_LENGTH.put("412", DataLength.fixed(13));
|
||||
THREE_DIGIT_DATA_LENGTH.put("413", DataLength.fixed(13));
|
||||
THREE_DIGIT_DATA_LENGTH.put("414", DataLength.fixed(13));
|
||||
THREE_DIGIT_DATA_LENGTH.put("420", DataLength.variable(20));
|
||||
THREE_DIGIT_DATA_LENGTH.put("421", DataLength.variable(15));
|
||||
THREE_DIGIT_DATA_LENGTH.put("422", DataLength.fixed(3));
|
||||
THREE_DIGIT_DATA_LENGTH.put("423", DataLength.variable(15));
|
||||
THREE_DIGIT_DATA_LENGTH.put("424", DataLength.fixed(3));
|
||||
THREE_DIGIT_DATA_LENGTH.put("425", DataLength.fixed(3));
|
||||
THREE_DIGIT_DATA_LENGTH.put("426", DataLength.fixed(3));
|
||||
}
|
||||
|
||||
private static final Map<String,DataLength> THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH = new HashMap<>();
|
||||
static {
|
||||
for (int i = 310; i <= 316; i++) {
|
||||
THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH.put(String.valueOf(i), DataLength.fixed(6));
|
||||
}
|
||||
for (int i = 320; i <= 336; i++) {
|
||||
THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH.put(String.valueOf(i), DataLength.fixed(6));
|
||||
}
|
||||
for (int i = 340; i <= 357; i++) {
|
||||
THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH.put(String.valueOf(i), DataLength.fixed(6));
|
||||
}
|
||||
for (int i = 360; i <= 369; i++) {
|
||||
THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH.put(String.valueOf(i), DataLength.fixed(6));
|
||||
}
|
||||
THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH.put("390", DataLength.variable(15));
|
||||
THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH.put("391", DataLength.variable(18));
|
||||
THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH.put("392", DataLength.variable(15));
|
||||
THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH.put("393", DataLength.variable(18));
|
||||
THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH.put("703", DataLength.variable(30));
|
||||
}
|
||||
|
||||
private static final Map<String,DataLength> FOUR_DIGIT_DATA_LENGTH = new HashMap<>();
|
||||
static {
|
||||
FOUR_DIGIT_DATA_LENGTH.put("7001", DataLength.fixed(13));
|
||||
FOUR_DIGIT_DATA_LENGTH.put("7002", DataLength.variable(30));
|
||||
FOUR_DIGIT_DATA_LENGTH.put("7003", DataLength.fixed(10));
|
||||
FOUR_DIGIT_DATA_LENGTH.put("8001", DataLength.fixed(14));
|
||||
FOUR_DIGIT_DATA_LENGTH.put("8002", DataLength.variable(20));
|
||||
FOUR_DIGIT_DATA_LENGTH.put("8003", DataLength.variable(30));
|
||||
FOUR_DIGIT_DATA_LENGTH.put("8004", DataLength.variable(30));
|
||||
FOUR_DIGIT_DATA_LENGTH.put("8005", DataLength.fixed(6));
|
||||
FOUR_DIGIT_DATA_LENGTH.put("8006", DataLength.fixed(18));
|
||||
FOUR_DIGIT_DATA_LENGTH.put("8007", DataLength.variable(30));
|
||||
FOUR_DIGIT_DATA_LENGTH.put("8008", DataLength.variable(12));
|
||||
FOUR_DIGIT_DATA_LENGTH.put("8018", DataLength.fixed(18));
|
||||
FOUR_DIGIT_DATA_LENGTH.put("8020", DataLength.variable(25));
|
||||
FOUR_DIGIT_DATA_LENGTH.put("8100", DataLength.fixed(6));
|
||||
FOUR_DIGIT_DATA_LENGTH.put("8101", DataLength.fixed(10));
|
||||
FOUR_DIGIT_DATA_LENGTH.put("8102", DataLength.fixed(2));
|
||||
FOUR_DIGIT_DATA_LENGTH.put("8110", DataLength.variable(70));
|
||||
FOUR_DIGIT_DATA_LENGTH.put("8200", DataLength.variable(70));
|
||||
}
|
||||
|
||||
private FieldParser() {
|
||||
}
|
||||
|
||||
static String parseFieldsInGeneralPurpose(String rawInformation) throws NotFoundException {
|
||||
if (rawInformation.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Processing 2-digit AIs
|
||||
|
||||
if (rawInformation.length() < 2) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
|
||||
DataLength twoDigitDataLength = TWO_DIGIT_DATA_LENGTH.get(rawInformation.substring(0, 2));
|
||||
if (twoDigitDataLength != null) {
|
||||
if (twoDigitDataLength.variable) {
|
||||
return processVariableAI(2, twoDigitDataLength.length, rawInformation);
|
||||
}
|
||||
return processFixedAI(2, twoDigitDataLength.length, rawInformation);
|
||||
}
|
||||
|
||||
if (rawInformation.length() < 3) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
|
||||
String firstThreeDigits = rawInformation.substring(0, 3);
|
||||
DataLength threeDigitDataLength = THREE_DIGIT_DATA_LENGTH.get(firstThreeDigits);
|
||||
if (threeDigitDataLength != null) {
|
||||
if (threeDigitDataLength.variable) {
|
||||
return processVariableAI(3, threeDigitDataLength.length, rawInformation);
|
||||
}
|
||||
return processFixedAI(3, threeDigitDataLength.length, rawInformation);
|
||||
}
|
||||
|
||||
if (rawInformation.length() < 4) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
|
||||
DataLength threeDigitPlusDigitDataLength = THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH.get(firstThreeDigits);
|
||||
if (threeDigitPlusDigitDataLength != null) {
|
||||
if (threeDigitPlusDigitDataLength.variable) {
|
||||
return processVariableAI(4, threeDigitPlusDigitDataLength.length, rawInformation);
|
||||
}
|
||||
return processFixedAI(4, threeDigitPlusDigitDataLength.length, rawInformation);
|
||||
}
|
||||
|
||||
DataLength firstFourDigitLength = FOUR_DIGIT_DATA_LENGTH.get(rawInformation.substring(0, 4));
|
||||
if (firstFourDigitLength != null) {
|
||||
if (firstFourDigitLength.variable) {
|
||||
return processVariableAI(4, firstFourDigitLength.length, rawInformation);
|
||||
}
|
||||
return processFixedAI(4, firstFourDigitLength.length, rawInformation);
|
||||
}
|
||||
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
|
||||
private static String processFixedAI(int aiSize, int fieldSize, String rawInformation) throws NotFoundException {
|
||||
if (rawInformation.length() < aiSize) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
|
||||
String ai = rawInformation.substring(0, aiSize);
|
||||
|
||||
if (rawInformation.length() < aiSize + fieldSize) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
|
||||
String field = rawInformation.substring(aiSize, aiSize + fieldSize);
|
||||
String remaining = rawInformation.substring(aiSize + fieldSize);
|
||||
String result = '(' + ai + ')' + field;
|
||||
String parsedAI = parseFieldsInGeneralPurpose(remaining);
|
||||
return parsedAI == null ? result : result + parsedAI;
|
||||
}
|
||||
|
||||
private static String processVariableAI(int aiSize, int variableFieldSize, String rawInformation)
|
||||
throws NotFoundException {
|
||||
String ai = rawInformation.substring(0, aiSize);
|
||||
int maxSize = Math.min(rawInformation.length(), aiSize + variableFieldSize);
|
||||
String field = rawInformation.substring(aiSize, maxSize);
|
||||
String remaining = rawInformation.substring(maxSize);
|
||||
String result = '(' + ai + ')' + field;
|
||||
String parsedAI = parseFieldsInGeneralPurpose(remaining);
|
||||
return parsedAI == null ? result : result + parsedAI;
|
||||
}
|
||||
|
||||
private static final class DataLength {
|
||||
|
||||
final boolean variable;
|
||||
final int length;
|
||||
|
||||
private DataLength(boolean variable, int length) {
|
||||
this.variable = variable;
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
static DataLength fixed(int length) {
|
||||
return new DataLength(false, length);
|
||||
}
|
||||
|
||||
static DataLength variable(int length) {
|
||||
return new DataLength(true, length);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
470
src/oned/rss/expanded/decoders/GeneralAppIdDecoder.java
Normal file
470
src/oned/rss/expanded/decoders/GeneralAppIdDecoder.java
Normal file
@@ -0,0 +1,470 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded.decoders;
|
||||
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.common.BitArray;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
|
||||
*/
|
||||
final class GeneralAppIdDecoder {
|
||||
|
||||
private final BitArray information;
|
||||
private final CurrentParsingState current = new CurrentParsingState();
|
||||
private final StringBuilder buffer = new StringBuilder();
|
||||
|
||||
GeneralAppIdDecoder(BitArray information) {
|
||||
this.information = information;
|
||||
}
|
||||
|
||||
String decodeAllCodes(StringBuilder buff, int initialPosition) throws NotFoundException, FormatException {
|
||||
int currentPosition = initialPosition;
|
||||
String remaining = null;
|
||||
do {
|
||||
DecodedInformation info = this.decodeGeneralPurposeField(currentPosition, remaining);
|
||||
String parsedFields = FieldParser.parseFieldsInGeneralPurpose(info.getNewString());
|
||||
if (parsedFields != null) {
|
||||
buff.append(parsedFields);
|
||||
}
|
||||
if (info.isRemaining()) {
|
||||
remaining = String.valueOf(info.getRemainingValue());
|
||||
} else {
|
||||
remaining = null;
|
||||
}
|
||||
|
||||
if (currentPosition == info.getNewPosition()) { // No step forward!
|
||||
break;
|
||||
}
|
||||
currentPosition = info.getNewPosition();
|
||||
} while (true);
|
||||
|
||||
return buff.toString();
|
||||
}
|
||||
|
||||
private boolean isStillNumeric(int pos) {
|
||||
// It's numeric if it still has 7 positions
|
||||
// and one of the first 4 bits is "1".
|
||||
if (pos + 7 > this.information.getSize()) {
|
||||
return pos + 4 <= this.information.getSize();
|
||||
}
|
||||
|
||||
for (int i = pos; i < pos + 3; ++i) {
|
||||
if (this.information.get(i)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return this.information.get(pos + 3);
|
||||
}
|
||||
|
||||
private DecodedNumeric decodeNumeric(int pos) throws FormatException {
|
||||
if (pos + 7 > this.information.getSize()) {
|
||||
int numeric = extractNumericValueFromBitArray(pos, 4);
|
||||
if (numeric == 0) {
|
||||
return new DecodedNumeric(this.information.getSize(), DecodedNumeric.FNC1, DecodedNumeric.FNC1);
|
||||
}
|
||||
return new DecodedNumeric(this.information.getSize(), numeric - 1, DecodedNumeric.FNC1);
|
||||
}
|
||||
int numeric = extractNumericValueFromBitArray(pos, 7);
|
||||
|
||||
int digit1 = (numeric - 8) / 11;
|
||||
int digit2 = (numeric - 8) % 11;
|
||||
|
||||
return new DecodedNumeric(pos + 7, digit1, digit2);
|
||||
}
|
||||
|
||||
int extractNumericValueFromBitArray(int pos, int bits) {
|
||||
return extractNumericValueFromBitArray(this.information, pos, bits);
|
||||
}
|
||||
|
||||
static int extractNumericValueFromBitArray(BitArray information, int pos, int bits) {
|
||||
int value = 0;
|
||||
for (int i = 0; i < bits; ++i) {
|
||||
if (information.get(pos + i)) {
|
||||
value |= 1 << (bits - i - 1);
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
DecodedInformation decodeGeneralPurposeField(int pos, String remaining) throws FormatException {
|
||||
this.buffer.setLength(0);
|
||||
|
||||
if (remaining != null) {
|
||||
this.buffer.append(remaining);
|
||||
}
|
||||
|
||||
this.current.setPosition(pos);
|
||||
|
||||
DecodedInformation lastDecoded = parseBlocks();
|
||||
if (lastDecoded != null && lastDecoded.isRemaining()) {
|
||||
return new DecodedInformation(this.current.getPosition(),
|
||||
this.buffer.toString(), lastDecoded.getRemainingValue());
|
||||
}
|
||||
return new DecodedInformation(this.current.getPosition(), this.buffer.toString());
|
||||
}
|
||||
|
||||
private DecodedInformation parseBlocks() throws FormatException {
|
||||
boolean isFinished;
|
||||
BlockParsedResult result;
|
||||
do {
|
||||
int initialPosition = current.getPosition();
|
||||
|
||||
if (current.isAlpha()) {
|
||||
result = parseAlphaBlock();
|
||||
isFinished = result.isFinished();
|
||||
} else if (current.isIsoIec646()) {
|
||||
result = parseIsoIec646Block();
|
||||
isFinished = result.isFinished();
|
||||
} else { // it must be numeric
|
||||
result = parseNumericBlock();
|
||||
isFinished = result.isFinished();
|
||||
}
|
||||
|
||||
boolean positionChanged = initialPosition != current.getPosition();
|
||||
if (!positionChanged && !isFinished) {
|
||||
break;
|
||||
}
|
||||
} while (!isFinished);
|
||||
|
||||
return result.getDecodedInformation();
|
||||
}
|
||||
|
||||
private BlockParsedResult parseNumericBlock() throws FormatException {
|
||||
while (isStillNumeric(current.getPosition())) {
|
||||
DecodedNumeric numeric = decodeNumeric(current.getPosition());
|
||||
current.setPosition(numeric.getNewPosition());
|
||||
|
||||
if (numeric.isFirstDigitFNC1()) {
|
||||
DecodedInformation information;
|
||||
if (numeric.isSecondDigitFNC1()) {
|
||||
information = new DecodedInformation(current.getPosition(), buffer.toString());
|
||||
} else {
|
||||
information = new DecodedInformation(current.getPosition(), buffer.toString(), numeric.getSecondDigit());
|
||||
}
|
||||
return new BlockParsedResult(information, true);
|
||||
}
|
||||
buffer.append(numeric.getFirstDigit());
|
||||
|
||||
if (numeric.isSecondDigitFNC1()) {
|
||||
DecodedInformation information = new DecodedInformation(current.getPosition(), buffer.toString());
|
||||
return new BlockParsedResult(information, true);
|
||||
}
|
||||
buffer.append(numeric.getSecondDigit());
|
||||
}
|
||||
|
||||
if (isNumericToAlphaNumericLatch(current.getPosition())) {
|
||||
current.setAlpha();
|
||||
current.incrementPosition(4);
|
||||
}
|
||||
return new BlockParsedResult();
|
||||
}
|
||||
|
||||
private BlockParsedResult parseIsoIec646Block() throws FormatException {
|
||||
while (isStillIsoIec646(current.getPosition())) {
|
||||
DecodedChar iso = decodeIsoIec646(current.getPosition());
|
||||
current.setPosition(iso.getNewPosition());
|
||||
|
||||
if (iso.isFNC1()) {
|
||||
DecodedInformation information = new DecodedInformation(current.getPosition(), buffer.toString());
|
||||
return new BlockParsedResult(information, true);
|
||||
}
|
||||
buffer.append(iso.getValue());
|
||||
}
|
||||
|
||||
if (isAlphaOr646ToNumericLatch(current.getPosition())) {
|
||||
current.incrementPosition(3);
|
||||
current.setNumeric();
|
||||
} else if (isAlphaTo646ToAlphaLatch(current.getPosition())) {
|
||||
if (current.getPosition() + 5 < this.information.getSize()) {
|
||||
current.incrementPosition(5);
|
||||
} else {
|
||||
current.setPosition(this.information.getSize());
|
||||
}
|
||||
|
||||
current.setAlpha();
|
||||
}
|
||||
return new BlockParsedResult();
|
||||
}
|
||||
|
||||
private BlockParsedResult parseAlphaBlock() {
|
||||
while (isStillAlpha(current.getPosition())) {
|
||||
DecodedChar alpha = decodeAlphanumeric(current.getPosition());
|
||||
current.setPosition(alpha.getNewPosition());
|
||||
|
||||
if (alpha.isFNC1()) {
|
||||
DecodedInformation information = new DecodedInformation(current.getPosition(), buffer.toString());
|
||||
return new BlockParsedResult(information, true); //end of the char block
|
||||
}
|
||||
|
||||
buffer.append(alpha.getValue());
|
||||
}
|
||||
|
||||
if (isAlphaOr646ToNumericLatch(current.getPosition())) {
|
||||
current.incrementPosition(3);
|
||||
current.setNumeric();
|
||||
} else if (isAlphaTo646ToAlphaLatch(current.getPosition())) {
|
||||
if (current.getPosition() + 5 < this.information.getSize()) {
|
||||
current.incrementPosition(5);
|
||||
} else {
|
||||
current.setPosition(this.information.getSize());
|
||||
}
|
||||
|
||||
current.setIsoIec646();
|
||||
}
|
||||
return new BlockParsedResult();
|
||||
}
|
||||
|
||||
private boolean isStillIsoIec646(int pos) {
|
||||
if (pos + 5 > this.information.getSize()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int fiveBitValue = extractNumericValueFromBitArray(pos, 5);
|
||||
if (fiveBitValue >= 5 && fiveBitValue < 16) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (pos + 7 > this.information.getSize()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int sevenBitValue = extractNumericValueFromBitArray(pos, 7);
|
||||
if (sevenBitValue >= 64 && sevenBitValue < 116) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (pos + 8 > this.information.getSize()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int eightBitValue = extractNumericValueFromBitArray(pos, 8);
|
||||
return eightBitValue >= 232 && eightBitValue < 253;
|
||||
|
||||
}
|
||||
|
||||
private DecodedChar decodeIsoIec646(int pos) throws FormatException {
|
||||
int fiveBitValue = extractNumericValueFromBitArray(pos, 5);
|
||||
if (fiveBitValue == 15) {
|
||||
return new DecodedChar(pos + 5, DecodedChar.FNC1);
|
||||
}
|
||||
|
||||
if (fiveBitValue >= 5 && fiveBitValue < 15) {
|
||||
return new DecodedChar(pos + 5, (char) ('0' + fiveBitValue - 5));
|
||||
}
|
||||
|
||||
int sevenBitValue = extractNumericValueFromBitArray(pos, 7);
|
||||
|
||||
if (sevenBitValue >= 64 && sevenBitValue < 90) {
|
||||
return new DecodedChar(pos + 7, (char) (sevenBitValue + 1));
|
||||
}
|
||||
|
||||
if (sevenBitValue >= 90 && sevenBitValue < 116) {
|
||||
return new DecodedChar(pos + 7, (char) (sevenBitValue + 7));
|
||||
}
|
||||
|
||||
int eightBitValue = extractNumericValueFromBitArray(pos, 8);
|
||||
char c;
|
||||
switch (eightBitValue) {
|
||||
case 232:
|
||||
c = '!';
|
||||
break;
|
||||
case 233:
|
||||
c = '"';
|
||||
break;
|
||||
case 234:
|
||||
c = '%';
|
||||
break;
|
||||
case 235:
|
||||
c = '&';
|
||||
break;
|
||||
case 236:
|
||||
c = '\'';
|
||||
break;
|
||||
case 237:
|
||||
c = '(';
|
||||
break;
|
||||
case 238:
|
||||
c = ')';
|
||||
break;
|
||||
case 239:
|
||||
c = '*';
|
||||
break;
|
||||
case 240:
|
||||
c = '+';
|
||||
break;
|
||||
case 241:
|
||||
c = ',';
|
||||
break;
|
||||
case 242:
|
||||
c = '-';
|
||||
break;
|
||||
case 243:
|
||||
c = '.';
|
||||
break;
|
||||
case 244:
|
||||
c = '/';
|
||||
break;
|
||||
case 245:
|
||||
c = ':';
|
||||
break;
|
||||
case 246:
|
||||
c = ';';
|
||||
break;
|
||||
case 247:
|
||||
c = '<';
|
||||
break;
|
||||
case 248:
|
||||
c = '=';
|
||||
break;
|
||||
case 249:
|
||||
c = '>';
|
||||
break;
|
||||
case 250:
|
||||
c = '?';
|
||||
break;
|
||||
case 251:
|
||||
c = '_';
|
||||
break;
|
||||
case 252:
|
||||
c = ' ';
|
||||
break;
|
||||
default:
|
||||
throw FormatException.getFormatInstance();
|
||||
}
|
||||
return new DecodedChar(pos + 8, c);
|
||||
}
|
||||
|
||||
private boolean isStillAlpha(int pos) {
|
||||
if (pos + 5 > this.information.getSize()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// We now check if it's a valid 5-bit value (0..9 and FNC1)
|
||||
int fiveBitValue = extractNumericValueFromBitArray(pos, 5);
|
||||
if (fiveBitValue >= 5 && fiveBitValue < 16) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (pos + 6 > this.information.getSize()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int sixBitValue = extractNumericValueFromBitArray(pos, 6);
|
||||
return sixBitValue >= 16 && sixBitValue < 63; // 63 not included
|
||||
}
|
||||
|
||||
private DecodedChar decodeAlphanumeric(int pos) {
|
||||
int fiveBitValue = extractNumericValueFromBitArray(pos, 5);
|
||||
if (fiveBitValue == 15) {
|
||||
return new DecodedChar(pos + 5, DecodedChar.FNC1);
|
||||
}
|
||||
|
||||
if (fiveBitValue >= 5 && fiveBitValue < 15) {
|
||||
return new DecodedChar(pos + 5, (char) ('0' + fiveBitValue - 5));
|
||||
}
|
||||
|
||||
int sixBitValue = extractNumericValueFromBitArray(pos, 6);
|
||||
|
||||
if (sixBitValue >= 32 && sixBitValue < 58) {
|
||||
return new DecodedChar(pos + 6, (char) (sixBitValue + 33));
|
||||
}
|
||||
|
||||
char c;
|
||||
switch (sixBitValue) {
|
||||
case 58:
|
||||
c = '*';
|
||||
break;
|
||||
case 59:
|
||||
c = ',';
|
||||
break;
|
||||
case 60:
|
||||
c = '-';
|
||||
break;
|
||||
case 61:
|
||||
c = '.';
|
||||
break;
|
||||
case 62:
|
||||
c = '/';
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Decoding invalid alphanumeric value: " + sixBitValue);
|
||||
}
|
||||
return new DecodedChar(pos + 6, c);
|
||||
}
|
||||
|
||||
private boolean isAlphaTo646ToAlphaLatch(int pos) {
|
||||
if (pos + 1 > this.information.getSize()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 5 && i + pos < this.information.getSize(); ++i) {
|
||||
if (i == 2) {
|
||||
if (!this.information.get(pos + 2)) {
|
||||
return false;
|
||||
}
|
||||
} else if (this.information.get(pos + i)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isAlphaOr646ToNumericLatch(int pos) {
|
||||
// Next is alphanumeric if there are 3 positions and they are all zeros
|
||||
if (pos + 3 > this.information.getSize()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = pos; i < pos + 3; ++i) {
|
||||
if (this.information.get(i)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isNumericToAlphaNumericLatch(int pos) {
|
||||
// Next is alphanumeric if there are 4 positions and they are all zeros, or
|
||||
// if there is a subset of this just before the end of the symbol
|
||||
if (pos + 1 > this.information.getSize()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4 && i + pos < this.information.getSize(); ++i) {
|
||||
if (this.information.get(pos + i)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user