FileDocCategorySizeDatePackage
ColorSpaceTransform.javaAPI DocAndroid 5.1 API11159Thu Mar 12 22:22:10 GMT 2015android.hardware.camera2.params

ColorSpaceTransform

public 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.

see
CameraMetadata

Fields Summary
private static final int
ROWS
The number of rows in this matrix.
private static final int
COLUMNS
The number of columns in this matrix.
private static final int
COUNT
The number of total Rational elements in this matrix.
private static final int
RATIONAL_SIZE
Number of int elements in a rational.
private static final int
OFFSET_NUMERATOR
Numerator offset inside a rational (pair).
private static final int
OFFSET_DENOMINATOR
Denominator offset inside a rational (pair).
private static final int
COUNT_INT
Number 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.

param
elements An array of {@code 9} elements
throws
IllegalArgumentException if the count of {@code elements} is not {@code 9}
throws
NullPointerException if {@code elements} or any sub-element is {@code null}


                                                                                   
       

        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}.

param
elements An array of {@code 18} elements
throws
IllegalArgumentException if the count of {@code elements} is not {@code 18}
throws
NullPointerException if {@code elements} is {@code null}

        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 voidcopyElements(android.util.Rational[] destination, int offset)
Copy the {@link Rational} elements in row-major order from this matrix into the destination.

param
destination an array big enough to hold at least {@code 9} elements after the {@code offset}
param
offset a non-negative offset into the array
throws
NullPointerException If {@code destination} was {@code null}
throws
ArrayIndexOutOfBoundsException If there's not enough room to write the elements at the specified destination and offset.

        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 voidcopyElements(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}.

param
destination an array big enough to hold at least {@code 18} elements after the {@code offset}
param
offset a non-negative offset into the array
throws
NullPointerException If {@code destination} was {@code null}
throws
ArrayIndexOutOfBoundsException If there's not enough room to write the elements at the specified destination and offset.
see
ColorSpaceTransform#ColorSpaceTransform(int[])

        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 booleanequals(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}.

return
{@code true} if the objects were equal, {@code false} otherwise

        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.RationalgetElement(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).

return
element (non-{@code null})
throws
IllegalArgumentException if column or row was out of range

        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 inthashCode()
{@inheritDoc}

        return HashCodeHelpers.hashCode(mElements);
    
private java.lang.StringtoShortString()
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.

return
compact string representation of color space transform

        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.StringtoString()
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 representation of color space transform

        return String.format("ColorSpaceTransform%s", toShortString());