mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Corrected logic to handle case where remainder polynomial has leading 0 coefficients.
git-svn-id: https://zxing.googlecode.com/svn/trunk@730 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
a16d3ba6ef
commit
0a1a550a0f
|
@ -22,7 +22,7 @@ package com.google.zxing;
|
|||
*
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public class WriterException extends Exception {
|
||||
public final class WriterException extends Exception {
|
||||
|
||||
public WriterException(String message) {
|
||||
super(message);
|
||||
|
|
|
@ -51,9 +51,12 @@ public final class ReedSolomonEncoder {
|
|||
}
|
||||
|
||||
public void encode(int[] toEncode, int ecBytes) {
|
||||
if (ecBytes == 0) {
|
||||
throw new IllegalArgumentException("No error correction bytes");
|
||||
}
|
||||
int dataBytes = toEncode.length - ecBytes;
|
||||
if (dataBytes < 0) {
|
||||
throw new IllegalArgumentException("Too few data bytes provided: " + dataBytes);
|
||||
if (dataBytes <= 0) {
|
||||
throw new IllegalArgumentException("No data bytes provided");
|
||||
}
|
||||
GF256Poly generator = buildGenerator(ecBytes);
|
||||
int[] infoCoefficients = new int[dataBytes];
|
||||
|
@ -62,11 +65,11 @@ public final class ReedSolomonEncoder {
|
|||
info = info.multiplyByMonomial(ecBytes, 1);
|
||||
GF256Poly remainder = info.divide(generator)[1];
|
||||
int[] coefficients = remainder.getCoefficients();
|
||||
if (coefficients.length < ecBytes) {
|
||||
throw new RuntimeException("Coefficients array is smaller than EC array (" +
|
||||
coefficients.length + " < " + ecBytes + ")");
|
||||
int numZeroCoefficients = ecBytes - coefficients.length;
|
||||
for (int i = 0; i < numZeroCoefficients; i++) {
|
||||
toEncode[dataBytes + i] = 0;
|
||||
}
|
||||
System.arraycopy(coefficients, 0, toEncode, dataBytes, ecBytes);
|
||||
System.arraycopy(coefficients, 0, toEncode, dataBytes + numZeroCoefficients, coefficients.length);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ public final class ReedSolomonEncoderQRCodeTestCase extends AbstractReedSolomonT
|
|||
for (int i = 0; i < 100; i++) {
|
||||
int size = random.nextInt(1000);
|
||||
int[] toEncode = new int[size];
|
||||
int ecBytes = random.nextInt(2 * (1 + size / 8));
|
||||
int ecBytes = 1 + random.nextInt(2 * (1 + size / 8));
|
||||
int dataBytes = size - ecBytes;
|
||||
for (int j = 0; j < dataBytes; j++) {
|
||||
toEncode[j] = random.nextInt(256);
|
||||
|
|
Loading…
Reference in a new issue