ColorSpaceTransformpublic final class ColorSpaceTransform extends Object Immutable class for describing a 3x3 matrix of {@link Rational} values in row-major order.
This matrix maps a transform from one color space to another. For the particular color space
source and target, see the appropriate camera metadata documentation for the key that provides
this value. |
Fields Summary |
---|
private static final int | ROWSThe number of rows in this matrix. | private static final int | COLUMNSThe number of columns in this matrix. | private static final int | COUNTThe number of total Rational elements in this matrix. | private static final int | RATIONAL_SIZENumber of int elements in a rational. | private static final int | OFFSET_NUMERATORNumerator offset inside a rational (pair). | private static final int | OFFSET_DENOMINATORDenominator offset inside a rational (pair). | private static final int | COUNT_INTNumber of int elements in this matrix. | private final int[] | mElements |
Constructors Summary |
---|
public ColorSpaceTransform(android.util.Rational[] elements)Create a new immutable {@link ColorSpaceTransform} instance from a {@link Rational} array.
The elements must be stored in a row-major order.
checkNotNull(elements, "elements must not be null");
if (elements.length != COUNT) {
throw new IllegalArgumentException("elements must be " + COUNT + " length");
}
mElements = new int[COUNT_INT];
for (int i = 0; i < elements.length; ++i) {
checkNotNull(elements, "element[" + i + "] must not be null");
mElements[i * RATIONAL_SIZE + OFFSET_NUMERATOR] = elements[i].getNumerator();
mElements[i * RATIONAL_SIZE + OFFSET_DENOMINATOR] = elements[i].getDenominator();
}
| public ColorSpaceTransform(int[] elements)Create a new immutable {@link ColorSpaceTransform} instance from an {@code int} array.
The elements must be stored in a row-major order. Each rational is stored
contiguously as a {@code (numerator, denominator)} pair.
In particular: {@code
int[] elements = new int[
N11, D11, N12, D12, N13, D13,
N21, D21, N22, D22, N23, D23,
N31, D31, N32, D32, N33, D33
];
new ColorSpaceTransform(elements)}
where {@code Nij} and {@code Dij} is the numerator and denominator for row {@code i} and
column {@code j}.
checkNotNull(elements, "elements must not be null");
if (elements.length != COUNT_INT) {
throw new IllegalArgumentException("elements must be " + COUNT_INT + " length");
}
for (int i = 0; i < elements.length; ++i) {
checkNotNull(elements, "element " + i + " must not be null");
}
mElements = Arrays.copyOf(elements, elements.length);
|
Methods Summary |
---|
public void | copyElements(android.util.Rational[] destination, int offset)Copy the {@link Rational} elements in row-major order from this matrix into the destination.
checkArgumentNonnegative(offset, "offset must not be negative");
checkNotNull(destination, "destination must not be null");
if (destination.length - offset < COUNT) {
throw new ArrayIndexOutOfBoundsException("destination too small to fit elements");
}
for (int i = 0, j = 0; i < COUNT; ++i, j += RATIONAL_SIZE) {
int numerator = mElements[j + OFFSET_NUMERATOR];
int denominator = mElements[j + OFFSET_DENOMINATOR];
destination[i + offset] = new Rational(numerator, denominator);
}
| public void | copyElements(int[] destination, int offset)Copy the {@link Rational} elements in row-major order from this matrix into the destination.
Each element is stored as a contiguous rational packed as a
{@code (numerator, denominator)} pair of ints, identical to the
{@link ColorSpaceTransform#ColorSpaceTransform(int[]) constructor}.
checkArgumentNonnegative(offset, "offset must not be negative");
checkNotNull(destination, "destination must not be null");
if (destination.length - offset < COUNT_INT) {
throw new ArrayIndexOutOfBoundsException("destination too small to fit elements");
}
// Manual copy faster than System#arraycopy for very small loops
for (int i = 0; i < COUNT_INT; ++i) {
destination[i + offset] = mElements[i];
}
| public boolean | equals(java.lang.Object obj)Check if this {@link ColorSpaceTransform} is equal to another {@link ColorSpaceTransform}.
Two color space transforms are equal if and only if all of their elements are
{@link Object#equals equal}.
if (obj == null) {
return false;
}
if (this == obj) {
return true;
}
if (obj instanceof ColorSpaceTransform) {
final ColorSpaceTransform other = (ColorSpaceTransform) obj;
for (int i = 0, j = 0; i < COUNT; ++i, j += RATIONAL_SIZE) {
int numerator = mElements[j + OFFSET_NUMERATOR];
int denominator = mElements[j + OFFSET_DENOMINATOR];
int numeratorOther = other.mElements[j + OFFSET_NUMERATOR];
int denominatorOther = other.mElements[j + OFFSET_DENOMINATOR];
Rational r = new Rational(numerator, denominator);
Rational rOther = new Rational(numeratorOther, denominatorOther);
if (!r.equals(rOther)) {
return false;
}
}
return true;
}
return false;
| public android.util.Rational | getElement(int column, int row)Get an element of this matrix by its row and column.
The rows must be within the range [0, 3),
and the column must be within the range [0, 3).
if (column < 0 || column >= COLUMNS) {
throw new IllegalArgumentException("column out of range");
} else if (row < 0 || row >= ROWS) {
throw new IllegalArgumentException("row out of range");
}
int numerator = mElements[(row * COLUMNS + column) * RATIONAL_SIZE + OFFSET_NUMERATOR];
int denominator = mElements[(row * COLUMNS + column) * RATIONAL_SIZE + OFFSET_DENOMINATOR];
return new Rational(numerator, denominator);
| public int | hashCode(){@inheritDoc}
return HashCodeHelpers.hashCode(mElements);
| private java.lang.String | toShortString()Return the color space transform as a compact string representation.
Example:
{@code "([1/1, 0/1, 0/1], [0/1, 1/1, 0/1], [0/1, 0/1, 1/1])"} is an identity transform.
Elements are printed in row major order.
StringBuilder sb = new StringBuilder("(");
for (int row = 0, i = 0; row < ROWS; row++) {
sb.append("[");
for (int col = 0; col < COLUMNS; col++, i += RATIONAL_SIZE) {
int numerator = mElements[i + OFFSET_NUMERATOR];
int denominator = mElements[i + OFFSET_DENOMINATOR];
sb.append(numerator);
sb.append("/");
sb.append(denominator);
if (col < COLUMNS - 1) {
sb.append(", ");
}
}
sb.append("]");
if (row < ROWS - 1) {
sb.append(", ");
}
}
sb.append(")");
return sb.toString();
| public java.lang.String | toString()Return the color space transform as a string representation.
Example:
{@code "ColorSpaceTransform([1/1, 0/1, 0/1], [0/1, 1/1, 0/1], [0/1, 0/1, 1/1])"} is an
identity transform. Elements are printed in row major order.
return String.format("ColorSpaceTransform%s", toShortString());
|
|