java.lang.Object
com.google.zxing.common.reedsolomon.GenericGF
This class contains utility methods for performing mathematical operations over the Galois Fields. Operations use a given primitive polynomial in calculations.
Throughout this package, elements of the GF are represented as an int for convenience and speed (but at the cost of memory).
Field Summary
Modifier and TypeFieldDescriptionstatic final GenericGFGalois field for Aztec 10-bit data symbols (1024 elements).static final GenericGFGalois field for Aztec 12-bit data symbols (4096 elements).static final GenericGFGalois field for Aztec 6-bit data symbols (64 elements).static final GenericGFAlias for DATA_MATRIX_FIELD_256.static final GenericGFGalois field for Aztec parameter symbols (16 elements).static final GenericGFGalois field for Data Matrix symbols (256 elements).private final int[]Exponent lookup table for the field.private final intBase of the generator used to build polynomials.private final int[]Logarithm lookup table for the field.static final GenericGFAlias for AZTEC_DATA_6.private final GenericGFPolyThe one polynomial of this field.private final intThe primitive polynomial defining the field.static final GenericGFGalois field for QR Code symbols (256 elements).private final intNumber of elements in the field.private final GenericGFPolyThe zero polynomial of this field.Constructor Summary
ConstructorsConstructorDescriptionGenericGF(int primitive, int size, int b) Create a representation of GF(size) using the given primitive polynomial.Method Summary
Modifier and TypeMethodDescription(package private) static intaddOrSubtract(int a, int b) Implements both addition and subtraction -- they are the same in GF(size).(package private) GenericGFPolybuildMonomial(int degree, int coefficient) Build the monomial coefficient * x^degree.(package private) intexp(int a) Get a field element's antilog.intGet the integer the Reed-Solomon generator polynomial is built over.(package private) GenericGFPolygetOne()Get the multiplicative identity of this field.intgetSize()Get the field's cardinality.(package private) GenericGFPolygetZero()Get the additive identity of this field.(package private) intinverse(int a) Get the multiplicative inverse of a field element.(package private) intlog(int a) Get a field element's log.(package private) intmultiply(int a, int b) Multiply two field elements.toString()Human-readable string representation of this Galois field.
Field Details
AZTEC_DATA_12
Galois field for Aztec 12-bit data symbols (4096 elements).AZTEC_DATA_10
Galois field for Aztec 10-bit data symbols (1024 elements).AZTEC_DATA_6
Galois field for Aztec 6-bit data symbols (64 elements).AZTEC_PARAM
Galois field for Aztec parameter symbols (16 elements).QR_CODE_FIELD_256
Galois field for QR Code symbols (256 elements).DATA_MATRIX_FIELD_256
Galois field for Data Matrix symbols (256 elements).AZTEC_DATA_8
Alias for DATA_MATRIX_FIELD_256.MAXICODE_FIELD_64
Alias for AZTEC_DATA_6.expTable
private final int[] expTableExponent lookup table for the field.logTable
private final int[] logTableLogarithm lookup table for the field.zero
The zero polynomial of this field.one
The one polynomial of this field.size
private final int sizeNumber of elements in the field.primitive
private final int primitiveThe primitive polynomial defining the field.generatorBase
private final int generatorBaseBase of the generator used to build polynomials.
Constructor Details
GenericGF
public GenericGF(int primitive, int size, int b) Create a representation of GF(size) using the given primitive polynomial.- Parameters:
primitive- irreducible polynomial whose coefficients are represented by the bits of an int, where the least-significant bit represents the constant coefficientsize- the number of elements in the field, a power of twob- the factor b in the generator polynomial can be 0- or 1-based (g(x) = (x+a^b)(x+a^(b+1))...(x+a^(b+2t-1))). In most cases it should be 1, but for QR code it is 0.
Method Details
getZero
GenericGFPoly getZero()Get the additive identity of this field.- Returns:
- the zero polynomial, the additive identity in GF(size)
getOne
GenericGFPoly getOne()Get the multiplicative identity of this field.- Returns:
- the one polynomial, the multiplicative identity in GF(size)
buildMonomial
Build the monomial coefficient * x^degree.- Parameters:
degree- the exponent of x, not negativecoefficient- the leading coefficient, whose field value is in [0, size)- Returns:
- the monomial, or the zero polynomial if coefficient is 0
- Throws:
IllegalArgumentException- if degree is negative
addOrSubtract
static int addOrSubtract(int a, int b) Implements both addition and subtraction -- they are the same in GF(size).- Parameters:
a- the first operand, whose field value is in [0, size)b- the second operand, whose field value is in [0, size)- Returns:
- sum/difference of a and b
exp
int exp(int a) Get a field element's antilog.- Parameters:
a- the exponent, in [0, size)- Returns:
- 2 to the power of a in GF(size)
log
int log(int a) Get a field element's log.- Parameters:
a- a nonzero field value in [1, size)- Returns:
- base 2 log of a in GF(size)
- Throws:
IllegalArgumentException- if a is 0, whose log is undefined
inverse
int inverse(int a) Get the multiplicative inverse of a field element.- Parameters:
a- a nonzero field value in [1, size)- Returns:
- multiplicative inverse of a, that is a such that a * result is 1
- Throws:
ArithmeticException- if a is 0, which has no inverse
multiply
int multiply(int a, int b) Multiply two field elements.- Parameters:
a- the first factor, whose field value is in [0, size)b- the second factor, whose field value is in [0, size)- Returns:
- product of a and b in GF(size), 0 if either factor is 0
getSize
public int getSize()Get the field's cardinality.- Returns:
- the number of elements in this field
getGeneratorBase
public int getGeneratorBase()Get the integer the Reed-Solomon generator polynomial is built over.- Returns:
- the generator base
toString