FileDocCategorySizeDatePackage
FrameFormat.javaAPI DocAndroid 5.1 API14461Thu Mar 12 22:22:30 GMT 2015android.filterfw.core

FrameFormat

public class FrameFormat extends Object
hide

Fields Summary
public static final int
TYPE_UNSPECIFIED
public static final int
TYPE_BIT
public static final int
TYPE_BYTE
public static final int
TYPE_INT16
public static final int
TYPE_INT32
public static final int
TYPE_FLOAT
public static final int
TYPE_DOUBLE
public static final int
TYPE_POINTER
public static final int
TYPE_OBJECT
public static final int
TARGET_UNSPECIFIED
public static final int
TARGET_SIMPLE
public static final int
TARGET_NATIVE
public static final int
TARGET_GPU
public static final int
TARGET_VERTEXBUFFER
public static final int
TARGET_RS
public static final int
SIZE_UNSPECIFIED
public static final int
BYTES_PER_SAMPLE_UNSPECIFIED
protected static final int
SIZE_UNKNOWN
protected int
mBaseType
protected int
mBytesPerSample
protected int
mSize
protected int
mTarget
protected int[]
mDimensions
protected android.filterfw.core.KeyValueMap
mMetaData
protected Class
mObjectClass
Constructors Summary
protected FrameFormat()


      
    
public FrameFormat(int baseType, int target)

        mBaseType = baseType;
        mTarget = target;
        initDefaults();
    
Methods Summary
public static java.lang.StringbaseTypeToString(int baseType)

        switch (baseType) {
            case TYPE_UNSPECIFIED: return "unspecified";
            case TYPE_BIT:         return "bit";
            case TYPE_BYTE:        return "byte";
            case TYPE_INT16:       return "int";
            case TYPE_INT32:       return "int";
            case TYPE_FLOAT:       return "float";
            case TYPE_DOUBLE:      return "double";
            case TYPE_POINTER:     return "pointer";
            case TYPE_OBJECT:      return "object";
            default:               return "unknown";
        }
    
public static intbytesPerSampleOf(int baseType)

        // Defaults based on base-type
        switch (baseType) {
            case TYPE_BIT:
            case TYPE_BYTE:
                return 1;
            case TYPE_INT16:
                return 2;
            case TYPE_INT32:
            case TYPE_FLOAT:
            case TYPE_POINTER:
                return 4;
            case TYPE_DOUBLE:
                return 8;
            default:
                return 1;
        }
    
intcalcSize(int[] dimensions)

        if (dimensions != null && dimensions.length > 0) {
            int size = getBytesPerSample();
            for (int dim : dimensions) {
                size *= dim;
            }
            return size;
        }
        return 0;
    
public static java.lang.StringdimensionsToString(int[] dimensions)

        StringBuffer buffer = new StringBuffer();
        if (dimensions != null) {
            int n = dimensions.length;
            for (int i = 0; i < n; ++i) {
                if (dimensions[i] == SIZE_UNSPECIFIED) {
                    buffer.append("[]");
                } else {
                    buffer.append("[" + String.valueOf(dimensions[i]) + "]");
                }
            }
        }
        return buffer.toString();
    
public booleanequals(java.lang.Object object)

        if (this == object) {
            return true;
        }

        if (!(object instanceof FrameFormat)) {
            return false;
        }

        FrameFormat format = (FrameFormat)object;
        return format.mBaseType == mBaseType &&
                format.mTarget == mTarget &&
                format.mBytesPerSample == mBytesPerSample &&
                Arrays.equals(format.mDimensions, mDimensions) &&
                format.mMetaData.equals(mMetaData);
    
public intgetBaseType()

        return mBaseType;
    
public intgetBytesPerSample()

        return mBytesPerSample;
    
public intgetDepth()

        return (mDimensions != null && mDimensions.length >= 3) ? mDimensions[2] : -1;
    
public intgetDimension(int i)

        return mDimensions[i];
    
public intgetDimensionCount()

        return mDimensions == null ? 0 : mDimensions.length;
    
public int[]getDimensions()

        return mDimensions;
    
public intgetHeight()

        return (mDimensions != null && mDimensions.length >= 2) ? mDimensions[1] : -1;
    
public intgetLength()

        return (mDimensions != null && mDimensions.length >= 1) ? mDimensions[0] : -1;
    
public java.lang.ObjectgetMetaValue(java.lang.String key)

        return mMetaData != null ? mMetaData.get(key) : null;
    
public intgetNumberOfDimensions()

        return mDimensions != null ? mDimensions.length : 0;
    
public java.lang.ClassgetObjectClass()

        return mObjectClass;
    
public intgetSize()

        if (mSize == SIZE_UNKNOWN) mSize = calcSize(mDimensions);
        return mSize;
    
public intgetTarget()

        return mTarget;
    
public intgetValuesPerSample()

        return mBytesPerSample / bytesPerSampleOf(mBaseType);
    
public intgetWidth()

        return getLength();
    
public booleanhasMetaKey(java.lang.String key)

        return mMetaData != null ? mMetaData.containsKey(key) : false;
    
public booleanhasMetaKey(java.lang.String key, java.lang.Class expectedClass)

        if (mMetaData != null && mMetaData.containsKey(key)) {
            if (!expectedClass.isAssignableFrom(mMetaData.get(key).getClass())) {
                throw new RuntimeException(
                    "FrameFormat meta-key '" + key + "' is of type " +
                    mMetaData.get(key).getClass() + " but expected to be of type " +
                    expectedClass + "!");
            }
            return true;
        }
        return false;
    
public inthashCode()

        return 4211 ^ mBaseType ^ mBytesPerSample ^ getSize();
    
private voidinitDefaults()

        mBytesPerSample = bytesPerSampleOf(mBaseType);
    
public booleanisBinaryDataType()

        return mBaseType >= TYPE_BIT && mBaseType <= TYPE_DOUBLE;
    
public booleanisCompatibleWith(android.filterfw.core.FrameFormat specification)

        // Check base type
        if (specification.getBaseType() != TYPE_UNSPECIFIED
            && getBaseType() != specification.getBaseType()) {
            return false;
        }

        // Check target
        if (specification.getTarget() != TARGET_UNSPECIFIED
            && getTarget() != specification.getTarget()) {
            return false;
        }

        // Check bytes per sample
        if (specification.getBytesPerSample() != BYTES_PER_SAMPLE_UNSPECIFIED
            && getBytesPerSample() != specification.getBytesPerSample()) {
            return false;
        }

        // Check number of dimensions
        if (specification.getDimensionCount() > 0
            && getDimensionCount() != specification.getDimensionCount()) {
            return false;
        }

        // Check dimensions
        for (int i = 0; i < specification.getDimensionCount(); ++i) {
            int specDim = specification.getDimension(i);
            if (specDim != SIZE_UNSPECIFIED && getDimension(i) != specDim) {
                return false;
            }
        }

        // Check class
        if (specification.getObjectClass() != null) {
            if (getObjectClass() == null
                || !specification.getObjectClass().isAssignableFrom(getObjectClass())) {
                return false;
            }
        }

        // Check meta-data
        if (specification.mMetaData != null) {
            for (String specKey : specification.mMetaData.keySet()) {
                if (mMetaData == null
                || !mMetaData.containsKey(specKey)
                || !mMetaData.get(specKey).equals(specification.mMetaData.get(specKey))) {
                    return false;
                }
            }
        }

        // Passed all the tests
        return true;
    
booleanisReplaceableBy(android.filterfw.core.FrameFormat format)

        return mTarget == format.mTarget
            && getSize() == format.getSize()
            && Arrays.equals(format.mDimensions, mDimensions);
    
public booleanmayBeCompatibleWith(android.filterfw.core.FrameFormat specification)

        // Check base type
        if (specification.getBaseType() != TYPE_UNSPECIFIED
            && getBaseType() != TYPE_UNSPECIFIED
            && getBaseType() != specification.getBaseType()) {
            return false;
        }

        // Check target
        if (specification.getTarget() != TARGET_UNSPECIFIED
            && getTarget() != TARGET_UNSPECIFIED
            && getTarget() != specification.getTarget()) {
            return false;
        }

        // Check bytes per sample
        if (specification.getBytesPerSample() != BYTES_PER_SAMPLE_UNSPECIFIED
            && getBytesPerSample() != BYTES_PER_SAMPLE_UNSPECIFIED
            && getBytesPerSample() != specification.getBytesPerSample()) {
            return false;
        }

        // Check number of dimensions
        if (specification.getDimensionCount() > 0
            && getDimensionCount() > 0
            && getDimensionCount() != specification.getDimensionCount()) {
            return false;
        }

        // Check dimensions
        for (int i = 0; i < specification.getDimensionCount(); ++i) {
            int specDim = specification.getDimension(i);
            if (specDim != SIZE_UNSPECIFIED
                && getDimension(i) != SIZE_UNSPECIFIED
                && getDimension(i) != specDim) {
                return false;
            }
        }

        // Check class
        if (specification.getObjectClass() != null && getObjectClass() != null) {
            if (!specification.getObjectClass().isAssignableFrom(getObjectClass())) {
                return false;
            }
        }

        // Check meta-data
        if (specification.mMetaData != null && mMetaData != null) {
            for (String specKey : specification.mMetaData.keySet()) {
                if (mMetaData.containsKey(specKey)
                    && !mMetaData.get(specKey).equals(specification.mMetaData.get(specKey))) {
                    return false;
                }
            }
        }

        // Passed all the tests
        return true;
    
public static java.lang.StringmetaDataToString(android.filterfw.core.KeyValueMap metaData)

        if (metaData == null) {
            return "";
        } else {
            StringBuffer buffer = new StringBuffer();
            buffer.append("{ ");
            for (Entry<String, Object> entry : metaData.entrySet()) {
                buffer.append(entry.getKey() + ": " + entry.getValue() + " ");
            }
            buffer.append("}");
            return buffer.toString();
        }
    
public android.filterfw.core.MutableFrameFormatmutableCopy()

        MutableFrameFormat result = new MutableFrameFormat();
        result.setBaseType(getBaseType());
        result.setTarget(getTarget());
        result.setBytesPerSample(getBytesPerSample());
        result.setDimensions(getDimensions());
        result.setObjectClass(getObjectClass());
        result.mMetaData = mMetaData == null ? null : (KeyValueMap)mMetaData.clone();
        return result;
    
public static intreadTargetString(java.lang.String targetString)

        if (targetString.equalsIgnoreCase("CPU") || targetString.equalsIgnoreCase("NATIVE")) {
            return FrameFormat.TARGET_NATIVE;
        } else if (targetString.equalsIgnoreCase("GPU")) {
            return FrameFormat.TARGET_GPU;
        } else if (targetString.equalsIgnoreCase("SIMPLE")) {
            return FrameFormat.TARGET_SIMPLE;
        } else if (targetString.equalsIgnoreCase("VERTEXBUFFER")) {
            return FrameFormat.TARGET_VERTEXBUFFER;
        } else if (targetString.equalsIgnoreCase("UNSPECIFIED")) {
            return FrameFormat.TARGET_UNSPECIFIED;
        } else {
            throw new RuntimeException("Unknown target type '" + targetString + "'!");
        }
    
public static java.lang.StringtargetToString(int target)

        switch (target) {
            case TARGET_UNSPECIFIED:  return "unspecified";
            case TARGET_SIMPLE:       return "simple";
            case TARGET_NATIVE:       return "native";
            case TARGET_GPU:          return "gpu";
            case TARGET_VERTEXBUFFER: return "vbo";
            case TARGET_RS:           return "renderscript";
            default:                  return "unknown";
        }
    
public java.lang.StringtoString()

        int valuesPerSample = getValuesPerSample();
        String sampleCountString = valuesPerSample == 1 ? "" : String.valueOf(valuesPerSample);
        String targetString = mTarget == TARGET_UNSPECIFIED ? "" : (targetToString(mTarget) + " ");
        String classString = mObjectClass == null
            ? ""
            : (" class(" + mObjectClass.getSimpleName() + ") ");

        return targetString
            + baseTypeToString(mBaseType)
            + sampleCountString
            + dimensionsToString(mDimensions)
            + classString
            + metaDataToString(mMetaData);
    
public static android.filterfw.core.FrameFormatunspecified()

        return new FrameFormat(TYPE_UNSPECIFIED, TARGET_UNSPECIFIED);