/** Create a Rational identity matrix of the specified size. */ private Rational [] identityMatrix (int dim) { Rational[] val = new Rational [dim * dim]; // Set them all to zero, then overwrite the diagonal values // to one. int i; for (i = 0; i < dim * dim; i++) { val[i] = new Rational (0, 1); } for (i = 0; i < dim; i++) { val[dim * i + i] = new Rational (1, 1); } return val; }
protected static Rational average(Rational r1, Rational r2) { long d1 = r1.getDenominator(); long d2 = r2.getDenominator(); Rational f1 = new Rational(r1.getNumerator()*d2, r1.getDenominator()*d2); Rational f2 = new Rational(r2.getNumerator()*d1, r2.getDenominator()*d1); return new Rational((f1.getNumerator() + f2.getNumerator())/2, f1.getDenominator()); }
/** Appends a Rational value to a StringBuffer */ public void rationalToString (StringBuffer buf, String tag, String margin, Rational r) { String margn2 = margin + " "; long numer = r.getNumerator (); long denom = r.getDenominator (); buf.append (margin + elementStart (tag) + EOL); buf.append (margn2 + element ("mix:numerator", Long.toString (numer)) + EOL); if (denom != 1L) { buf.append (margn2 + element ("mix:denominator", Long.toString (denom)) + EOL); } buf.append (margin + elementEnd (tag) + EOL); } }
/** * Checks if the value of the XResolution tag matches * any of the values in the array passed to it. * * @param ifd The IFD being checked * @param values An array of values, any of which will * satisfy the test. */ protected boolean satisfiesXResolution (TiffIFD ifd, int [] values) { long xf = ifd.getNisoImageMetadata ().getXSamplingFrequency ().toLong (); for (int i = 0; i < values.length; i++) { if (xf == values[i]) { return true; } } return false; }
if (type == RATIONAL) { Rational r = readRational (count, value); _batteryLevel = Double.toString (r.toDouble ()); if (count == 1) { _niso.setBrightness (readSignedRational (count, value).toDouble ()); _niso.setBrightness (average (r[0], r[1]).toDouble ()); if (count == 1) { _niso.setExposureBias (readSignedRational (count, value).toDouble ()); _niso.setExposureBias (average (r[0], r[1]).toDouble ()); if (count == 1) { _niso.setExposureTime (readRational (count, value).toDouble ()); _niso.setExposureTime (average (r[0], r[1]).toDouble ()); if (count == 1) { _niso.setFlashEnergy (readRational (count, value).toDouble ()); _niso.setFlashEnergy (average (r[0], r[1]).toDouble ()); checkType (tag, type, RATIONAL);
/** * Return String representation of an array of Rational, each evaluated * as a double, with space separator. */ protected static String rationalArray (Rational [] rarray) { StringBuffer buffer = new StringBuffer (); for (int i=0; i<rarray.length; i++) { if (i > 0) { buffer.append (" "); } buffer.append (rarray[i].toDouble ()); } return buffer.toString (); }
if (r != null) { smBuf.append (margn5 + element ("mix:XSamplingFrequency", Long.toString (r.toLong())) + EOL); useSMBuf = true; if (r != null) { smBuf.append (margn5 + element ("mix:YSamplingFrequency", Long.toString (r.toLong())) + EOL); useSMBuf = true; if (r != null) { eBuf.append (margn5 + element ("mix:WhitePoint_Xvalue", r.toString ()) + EOL); r1.toString ()) + EOL); eBuf.append (margn4 + elementStart("mix:PrimaryChromaticities") + EOL); eBuf.append (margn5 + element ("mix:PrimaryChromaticities_RedX", r.toString ()) + EOL); r = niso.getPrimaryChromaticitiesRedY (); if (r != null) { eBuf.append (margn5 + element ("mix:PrimaryChromaticities_RedY", r.toString ()) + EOL); r.toString ()) + EOL); r.toString ()) + EOL); r.toString ()) + EOL);
nod.add (new DefaultMutableTreeNode (rarray[i].toString (), false)); nod.add (new DefaultMutableTreeNode (rarray[i].toString (), false)); val.add (new DefaultMutableTreeNode ("XSamplingFrequency: " + rat.toString (), false)); val.add (new DefaultMutableTreeNode ("WhitePointXValue: " + r.toString (), false));
/** * Return String representation of an array of Rational, each as * two integers, with space separator. */ protected static String rationalArray10 (Rational [] rarray) { StringBuffer buffer = new StringBuffer (); for (int i=0; i<rarray.length; i++) { if (i > 0) { buffer.append (" "); } buffer.append (rarray[i].getNumerator ()); buffer.append (" "); buffer.append (rarray[i].getNumerator ()); } return buffer.toString (); }
/** * Checks if the value of the XResolution tag matches * any of the values in the array passed to it. * * @param ifd The IFD being checked * @param values An array of values, any of which will * satisfy the test. */ protected boolean satisfiesYResolution (TiffIFD ifd, int [] values) { long yf = ifd.getNisoImageMetadata ().getYSamplingFrequency ().toLong (); for (int i = 0; i < values.length; i++) { if (yf == values[i]) { return true; } } return false; }
protected Property addRationalArrayProperty(String name, Rational [] r, boolean rawOutput) { Property prop = null; if (!rawOutput) { String [] s = new String[r.length]; for (int i=0; i<r.length; i++) { s[i] = _format.format(r[i].toDouble()); } prop = new Property(name, PropertyType.STRING, PropertyArity.ARRAY, s); } if (prop == null) { prop = new Property(name, PropertyType.RATIONAL, PropertyArity.ARRAY, r); } return prop; }
if (r != null) { colorEncBuf.append (margn5 + element ("mix:whitePointXValue", r.toString ()) + EOL); r2.toString ()) + EOL); if (r != null) { chromaBuf.append (margn5 + element ("mix:primaryChromaticitiesRedX", r.toString ()) + EOL); useChromaBuf = true; if (r != null) { chromaBuf.append (margn5 + element ("mix:primaryChromaticitiesRedY", r.toString ()) + EOL); useChromaBuf = true; if (r != null) { chromaBuf.append (margn5 + element ("mix:primaryChromaticitiesGreenX", r.toString ()) + EOL); useChromaBuf = true; if (r != null) { chromaBuf.append (margn5 + element ("mix:primaryChromaticitiesGreenY", r.toString ()) + EOL); useChromaBuf = true; if (r != null) { chromaBuf.append (margn5 + element ("mix:primaryChromaticitiesBlueX", r.toString ()) + EOL);
/** Reads an SRATIONAL value and returns it as a Rational. */ protected Rational readSignedRational(long count, long value) throws IOException { _raf.seek(value); long numer = ModuleBase.readSignedInt(_raf, _bigEndian); long denom = ModuleBase.readSignedInt(_raf, _bigEndian); return new Rational(numer, denom); }
elem = rationalArray[i].toString ();
/** Reads a RATIONAL value and returns it as a Rational. */ protected Rational readRational(long count, long value) throws IOException { _raf.seek(value); long numer = ModuleBase.readUnsignedInt(_raf, _bigEndian); long denom = ModuleBase.readUnsignedInt(_raf, _bigEndian); return new Rational(numer, denom); }
/** * Returns a property for a tag with a RATIONAL value. * If rawOutput is true, returns a property with type * RATIONAL. Otherwise, returns a property with type * STRING, and the text representation of the Rational * value as a floating-point ratio. */ protected Property addRationalProperty(String name, Rational r, boolean rawOutput) { Property prop = null; if (!rawOutput) { prop = new Property(name, PropertyType.STRING, _format.format(r.toDouble())); } if (prop == null) { prop = new Property(name, PropertyType.RATIONAL, r); } return prop; }