All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.humble.video.Rational Maven / Gradle / Ivy

Go to download

This is the main Humble Video Java library. It contains no native code, but all Java runtime code. It must be paired up with the correct humble-video-arch-*.jar library for your OS. For most users, depending on humble-video-all will work better.

The newest version!
/* ----------------------------------------------------------------------------
 * This file was automatically generated by SWIG (http://www.swig.org).
 * Version 2.0.6
 *
 * Do not make changes to this file unless you know what you are doing--modify
 * the SWIG interface file instead.
 * ----------------------------------------------------------------------------- */

package io.humble.video;
import io.humble.ferry.*;
/**
 * This class wraps represents a Rational number.
*


* Video formats often use rational numbers, and converting between
* them willy nilly can lead to rounding errors, and eventually, out
* of sync problems. Therefore we use IRational objects to pass
* around Rational Numbers and avoid conversion until the very last moment.
*


* Note: There are some static convenience methods
* in this class that start with s*. They start with s
* (as opposed to overloading methods (e.g. sAdd(...) vs. add(...)).
*

*/ public class Rational extends RefCounted { // JNIHelper.swg: Start generated code // >>>>>>>>>>>>>>>>>>>>>>>>>>> /** * This method is only here to use some references and remove * a Eclipse compiler warning. */ @SuppressWarnings("unused") private void noop() { Buffer.make(null, 1); } private volatile long swigCPtr; /** * Internal Only. */ protected Rational(long cPtr, boolean cMemoryOwn) { super(VideoJNI.Rational_SWIGUpcast(cPtr), cMemoryOwn); swigCPtr = cPtr; } /** * Internal Only. */ protected Rational(long cPtr, boolean cMemoryOwn, java.util.concurrent.atomic.AtomicLong ref) { super(VideoJNI.Rational_SWIGUpcast(cPtr), cMemoryOwn, ref); swigCPtr = cPtr; } /** * Internal Only. Not part of public API. * * Get the raw value of the native object that obj is proxying for. * * @param obj The java proxy object for a native object. * @return The raw pointer obj is proxying for. */ protected static long getCPtr(Rational obj) { if (obj == null) return 0; return obj.getMyCPtr(); } /** * Internal Only. Not part of public API. * * Get the raw value of the native object that we're proxying for. * * @return The raw pointer we're proxying for. */ protected long getMyCPtr() { if (swigCPtr == 0) throw new IllegalStateException("underlying native object already deleted"); return swigCPtr; } /** * Create a new Rational object that is actually referring to the * exact same underlying native object. * * @return the new Java object. */ @Override public Rational copyReference() { if (swigCPtr == 0) return null; else return new Rational(swigCPtr, swigCMemOwn, getJavaRefCount()); } /** * Compares two values, returning true if the underlying objects in native code are the same object. * * That means you can have two different Java objects, but when you do a comparison, you'll find out * they are the EXACT same object. * * @return True if the underlying native object is the same. False otherwise. */ public boolean equals(Object obj) { boolean equal = false; if (obj instanceof Rational) equal = (((Rational)obj).swigCPtr == this.swigCPtr); return equal; } /** * Get a hashable value for this object. * * @return the hashable value. */ public int hashCode() { return (int)swigCPtr; } // <<<<<<<<<<<<<<<<<<<<<<<<<<< // JNIHelper.swg: End generated code /** * Prints the contents of this object as a fraction. * @return "{@link #getNumerator()}/{@link #getDenominator()}" */ @Override public String toString() { return "" + getNumerator() + "/" + getDenominator(); } /** * Is this number positive? * @return true if > 0; false if not. */ public boolean isPositive() { if (getDenominator() == 0) return false; return getDouble() > 0; } /** * Is this number not null and positive. * @param num the number; may be null * @return true if not-null and > 0; else false; */ public static boolean positive(Rational num) { if (num == null) return false; return num.isPositive(); } /** * Is this number negative? * @return true if < 0; false if not. */ public boolean isNegative() { if (getDenominator() == 0) return false; return getDouble() < 0; } /** * Is this number not null and negative. * @param num the number; may be null * @return true if not-null and < 0; else false; */ public static boolean negative(Rational num) { if (num == null) return false; return num.isNegative(); } /** * Get the numerator for this rational.
* @return the numerator. */ public int getNumerator() { return VideoJNI.Rational_getNumerator(swigCPtr, this); } /** * Get the denominator for this rational.
* @return the denominator. */ public int getDenominator() { return VideoJNI.Rational_getDenominator(swigCPtr, this); } /** * Creates a new IRational object by copying (by value) this object.
*
* @return the new object */ public Rational copy() { long cPtr = VideoJNI.Rational_copy(swigCPtr, this); return (cPtr == 0) ? null : new Rational(cPtr, false); } /** * Compare a rational to this rational
* @param other second rational
* @return 0 if this==other, 1 if this>other and -1 if this<other. */ public int compareTo(Rational other) { return VideoJNI.Rational_compareTo(swigCPtr, this, Rational.getCPtr(other), other); } /** * Compare two rationals
* @param a the first rational
* @param b the second rational
* @return 0 if a==b, 1 if a>b and -1 if b<a. */ public static int sCompareTo(Rational a, Rational b) { return VideoJNI.Rational_sCompareTo(Rational.getCPtr(a), a, Rational.getCPtr(b), b); } /** * Rational to double conversion.
*
* @return (double) a */ public double getDouble() { return VideoJNI.Rational_getDouble(swigCPtr, this); } /** * Reduce a fraction to it's lowest common denominators.
* This is useful for framerate calculations.
* @param num the src numerator.
* @param den the src denominator.
* @param max the maximum allowed for nom & den in the reduced fraction.
* @return 1 if exact, 0 otherwise */ public int reduce(long num, long den, long max) { return VideoJNI.Rational_reduce(swigCPtr, this, num, den, max); } /** * Reduce a fraction to it's lowest common denominators.
* This is useful for framerate calculations.
* @param dst The destination rational
* @param num the src numerator.
* @param den the src denominator.
* @param max the maximum allowed for nom & den in the reduced fraction.
* @return 1 if exact, 0 otherwise */ public static int sReduce(Rational dst, long num, long den, long max) { return VideoJNI.Rational_sReduce(Rational.getCPtr(dst), dst, num, den, max); } /** * Multiplies this number by arg
* @param arg number to mulitply by.
* @return this*arg. */ public Rational multiply(Rational arg) { long cPtr = VideoJNI.Rational_multiply(swigCPtr, this, Rational.getCPtr(arg), arg); return (cPtr == 0) ? null : new Rational(cPtr, false); } /** * Multiples a by b.
* @param a the first number
* @param b the second number.
* @return a*b */ public static Rational sMultiply(Rational a, Rational b) { long cPtr = VideoJNI.Rational_sMultiply(Rational.getCPtr(a), a, Rational.getCPtr(b), b); return (cPtr == 0) ? null : new Rational(cPtr, false); } /** * Divides this rational by arg.
* @param arg The divisor to use.
* @return this/arg. */ public Rational divide(Rational arg) { long cPtr = VideoJNI.Rational_divide(swigCPtr, this, Rational.getCPtr(arg), arg); return (cPtr == 0) ? null : new Rational(cPtr, false); } /** * Divides a by b.
* @param a The first number.
* b The second number.
* @return a/b. */ public static Rational sDivide(Rational a, Rational b) { long cPtr = VideoJNI.Rational_sDivide(Rational.getCPtr(a), a, Rational.getCPtr(b), b); return (cPtr == 0) ? null : new Rational(cPtr, false); } /** * Subtracts arg from this rational
* @param arg The amount to subtract from this.
* @return this-arg. */ public Rational subtract(Rational arg) { long cPtr = VideoJNI.Rational_subtract(swigCPtr, this, Rational.getCPtr(arg), arg); return (cPtr == 0) ? null : new Rational(cPtr, false); } /** * Subtracts a from b.
* @param a The first number.
* b The second number.
* @return a-b. */ public static Rational sSubtract(Rational a, Rational b) { long cPtr = VideoJNI.Rational_sSubtract(Rational.getCPtr(a), a, Rational.getCPtr(b), b); return (cPtr == 0) ? null : new Rational(cPtr, false); } /** * Adds arg to this rational
* @param arg The amount to add to this.
* @return this+arg. */ public Rational add(Rational arg) { long cPtr = VideoJNI.Rational_add(swigCPtr, this, Rational.getCPtr(arg), arg); return (cPtr == 0) ? null : new Rational(cPtr, false); } /** * Adds a to b.
* @param a The first number.
* b The second number.
* @return a+b. */ public static Rational sAdd(Rational a, Rational b) { long cPtr = VideoJNI.Rational_sAdd(Rational.getCPtr(a), a, Rational.getCPtr(b), b); return (cPtr == 0) ? null : new Rational(cPtr, false); } /** * Takes a value scaled in increments of origBase and gives the
* equivalent value scaled in terms of this Rational.
*
* @param origValue The original int64_t value you care about.
* @param origBase The original base Rational that origValue is scaled with.
*
* @return The new integer value, scaled in units of this IRational. */ public long rescale(long origValue, Rational origBase) { return VideoJNI.Rational_rescale__SWIG_0(swigCPtr, this, origValue, Rational.getCPtr(origBase), origBase); } /** * Takes a value scaled in increments of origBase and gives the
* equivalent value scaled in terms of this Rational.
*
* @param origValue The original int64_t value you care about.
* @param origBase The original base Rational that origValue is scaled with.
* @param newBase The rational you want to rescale origValue into.
*
* @return The new integer value, scaled in units of this IRational. */ public static long sRescale(long origValue, Rational origBase, Rational newBase) { return VideoJNI.Rational_sRescale__SWIG_0(origValue, Rational.getCPtr(origBase), origBase, Rational.getCPtr(newBase), newBase); } /** * Get a new rational that will be set to 0/1.
* The rational will not have #init() called
* and hence will be modifiable by #setValue(double)
* until #init() is called.
* @return a rational number object */ public static Rational make() { long cPtr = VideoJNI.Rational_make__SWIG_0(); return (cPtr == 0) ? null : new Rational(cPtr, false); } /** * Converts a double precision floating point number to a rational.
* @param d double to convert
* @return A new Rational; caller must release() when done. */ public static Rational make(double d) { long cPtr = VideoJNI.Rational_make__SWIG_1(d); return (cPtr == 0) ? null : new Rational(cPtr, false); } /** * Creates deep copy of a Rational from another Rational.
*
* @param src The source Rational to copy.
* @return A new Rational; Returns null
* if src is null. */ public static Rational make(Rational src) { long cPtr = VideoJNI.Rational_make__SWIG_2(Rational.getCPtr(src), src); return (cPtr == 0) ? null : new Rational(cPtr, false); } /** * Create a rational from a numerator and denominator.
*
* We will always reduce this to the lowest num/den pair
* we can, but never having den exceed what was passed in.
*
* @param num The numerator of the resulting Rational
* @param den The denominator of the resulting Rational
*
* @return A new Rational; */ public static Rational make(int num, int den) { long cPtr = VideoJNI.Rational_make__SWIG_3(num, den); return (cPtr == 0) ? null : new Rational(cPtr, false); } /** * Takes a value scaled in increments of origBase and gives the
* equivalent value scaled in terms of this Rational.
*
* @param origValue The original int64_t value you care about.
* @param origBase The original base Rational that origValue is scaled with.
* @param rounding How you want rounding to occur
* @return The new integer value, scaled in units of this IRational. */ public long rescale(long origValue, Rational origBase, Rational.Rounding rounding) { return VideoJNI.Rational_rescale__SWIG_1(swigCPtr, this, origValue, Rational.getCPtr(origBase), origBase, rounding.swigValue()); } /** * Takes a value scaled in increments of origBase and gives the
* equivalent value scaled in terms of this Rational.
*
* @param origValue The original int64_t value you care about.
* @param origBase The original base Rational that origValue is scaled with.
* @param newBase The rational you want to rescale origValue into.
* @param rounding How you want rounding to occur
*
* @return The new integer value, scaled in units of this IRational. */ public static long sRescale(long origValue, Rational origBase, Rational newBase, Rational.Rounding rounding) { return VideoJNI.Rational_sRescale__SWIG_1(origValue, Rational.getCPtr(origBase), origBase, Rational.getCPtr(newBase), newBase, rounding.swigValue()); } /** * Rescales a long value to another long value.
*


* This method doesn't use IRational values, but
* instead uses numerators and denominators
* passed in by the caller. It will not result
* in any memory allocations.
*


*
* @param srcValue The value to rescale.
* @param dstNumerator The numerator of the units
* you want to scale to. Must be non-zero.
* @param dstDenominator The denominator of the units
* you want to scale to. Must be non-zero.
* @param srcNumerator The numerator of the units
* srcValue is expressed in.
* Must be non-zero.
* @param srcDenominator The denominator of the units
* srcValue is expressed in.
* Must be non-zero.
* @param rounding How you want rounding to occur
*
* @return The new integer value, scaled in units of
* dstNumerator/dstNumerator, or 0 if there
* is a parameter error. */ public static long rescale(long srcValue, int dstNumerator, int dstDenominator, int srcNumerator, int srcDenominator, Rational.Rounding rounding) { return VideoJNI.Rational_rescale__SWIG_2(srcValue, dstNumerator, dstDenominator, srcNumerator, srcDenominator, rounding.swigValue()); } /** * Sets the numerator on this object.
*


* If #isFinalized is true, then this method is ignored.
*

*/ public void setNumerator(int value) { VideoJNI.Rational_setNumerator(swigCPtr, this, value); } /** * Sets the denominator on this object.
*


* If #isFinalized is true, then this method is ignored.
*

*/ public void setDenominator(int value) { VideoJNI.Rational_setDenominator(swigCPtr, this, value); } /** * Sets the numerator and denominator on this object by
* reducing the double to the closest integer numerator
* and denominator.
*


* If #isFinalized is true, then this method is ignored.
*

*/ public void setValue(double value) { VideoJNI.Rational_setValue(swigCPtr, this, value); } /** * An alias for #getDouble() but matching JavaBean
* conventions. */ public double getValue() { return VideoJNI.Rational_getValue(swigCPtr, this); } /** * Returns true if #init() has been called and
* this object is now considered finalized and immutable. */ public boolean isFinalized() { return VideoJNI.Rational_isFinalized(swigCPtr, this); } /** * Marks this object as finalized and immutable. Any
* setters called after the first #init() call
* will be ignored.
*


* Most make methods will call this method
* automatically, with the exception of the blank factory
* method #make().
*

*/ public void init() { VideoJNI.Rational_init(swigCPtr, this); } /** * A type to specify how rounding should be done. */ public enum Rounding { /** * Round toward zero. */ ROUND_ZERO(VideoJNI.Rational_ROUND_ZERO_get()), /** * Round away from zero. */ ROUND_INF(VideoJNI.Rational_ROUND_INF_get()), /** * Round toward -infinity. */ ROUND_DOWN(VideoJNI.Rational_ROUND_DOWN_get()), /** * Round toward +infinity. */ ROUND_UP(VideoJNI.Rational_ROUND_UP_get()), /** * Round to nearest and halfway cases away from zero. */ ROUND_NEAR_INF(VideoJNI.Rational_ROUND_NEAR_INF_get()), /** * Flag to pass INT64_MIN/MAX through instead of rescaling, this avoids special cases for AV_NOPTS_VALUE */ ROUND_PASS_MINMAX(VideoJNI.Rational_ROUND_PASS_MINMAX_get()), ; public final int swigValue() { return swigValue; } public static Rounding swigToEnum(int swigValue) { Rounding[] swigValues = Rounding.class.getEnumConstants(); if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue) return swigValues[swigValue]; for (Rounding swigEnum : swigValues) if (swigEnum.swigValue == swigValue) return swigEnum; throw new IllegalArgumentException("No enum " + Rounding.class + " with value " + swigValue); } @SuppressWarnings("unused") private Rounding() { this.swigValue = SwigNext.next++; } @SuppressWarnings("unused") private Rounding(int swigValue) { this.swigValue = swigValue; SwigNext.next = swigValue+1; } @SuppressWarnings("unused") private Rounding(Rounding swigEnum) { this.swigValue = swigEnum.swigValue; SwigNext.next = this.swigValue+1; } private final int swigValue; private static class SwigNext { private static int next = 0; } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy