src/share/classes/com/sun/imageio/plugins/jpeg/JPEGMetadata.java

Print this page




 706 
 707     private int findLastUnknownMarkerSegmentPosition() {
 708         ListIterator iter = markerSequence.listIterator(markerSequence.size());
 709         for (int i = markerSequence.size()-1; iter.hasPrevious(); i--) {
 710             MarkerSegment seg = (MarkerSegment)iter.previous();
 711             if (seg.unknown == true) {
 712                 return i;
 713             }
 714         }
 715         return -1;
 716     }
 717 
 718     // Implement Cloneable, but restrict access
 719 
 720     protected Object clone() {
 721         JPEGMetadata newGuy = null;
 722         try {
 723             newGuy = (JPEGMetadata) super.clone();
 724         } catch (CloneNotSupportedException e) {} // won't happen
 725         if (markerSequence != null) {
 726             newGuy.markerSequence = (List) cloneSequence();
 727         }
 728         newGuy.resetSequence = null;
 729         return newGuy;
 730     }
 731 
 732     /**
 733      * Returns a deep copy of the current marker sequence.
 734      */
 735     private List cloneSequence() {
 736         if (markerSequence == null) {
 737             return null;
 738         }
 739         List retval = new ArrayList(markerSequence.size());
 740         Iterator iter = markerSequence.iterator();
 741         while(iter.hasNext()) {
 742             MarkerSegment seg = (MarkerSegment)iter.next();
 743             retval.add(seg.clone());
 744         }
 745 
 746         return retval;


1998 
1999         // Deal with min case
2000         if (value <= epsilon) {
2001             return new Point(1, 255);
2002         }
2003 
2004         // Deal with max case
2005         if (value >= 255) {
2006             return new Point(255, 1);
2007         }
2008 
2009         // Remember if we invert
2010         boolean inverted = false;
2011         if (value < 1.0) {
2012             value = 1.0F/value;
2013             inverted = true;
2014         }
2015 
2016         // First approximation
2017         int y = 1;
2018         int x = (int) Math.round(value);
2019 
2020         float ratio = (float) x;
2021         float delta = Math.abs(value - ratio);
2022         while (delta > epsilon) { // not close enough
2023             // Increment y and compute a new x
2024             y++;
2025             x = (int) Math.round(y*value);
2026             ratio = (float)x/(float)y;
2027             delta = Math.abs(value - ratio);
2028         }
2029         return inverted ? new Point(y, x) : new Point(x, y);
2030     }
2031 
2032     private void mergeStandardDocumentNode(Node node)
2033         throws IIOInvalidTreeException {
2034         // No-op
2035     }
2036 
2037     private void mergeStandardTextNode(Node node)
2038         throws IIOInvalidTreeException {
2039         // Convert to comments.  For the moment ignore the encoding issue.
2040         // Ignore keywords, language, and encoding (for the moment).
2041         // If compression tag is present, use only entries with "none".
2042         NodeList children = node.getChildNodes();
2043         for (int i = 0; i < children.getLength(); i++) {
2044             Node child = children.item(i);
2045             NamedNodeMap attrs = child.getAttributes();




 706 
 707     private int findLastUnknownMarkerSegmentPosition() {
 708         ListIterator iter = markerSequence.listIterator(markerSequence.size());
 709         for (int i = markerSequence.size()-1; iter.hasPrevious(); i--) {
 710             MarkerSegment seg = (MarkerSegment)iter.previous();
 711             if (seg.unknown == true) {
 712                 return i;
 713             }
 714         }
 715         return -1;
 716     }
 717 
 718     // Implement Cloneable, but restrict access
 719 
 720     protected Object clone() {
 721         JPEGMetadata newGuy = null;
 722         try {
 723             newGuy = (JPEGMetadata) super.clone();
 724         } catch (CloneNotSupportedException e) {} // won't happen
 725         if (markerSequence != null) {
 726             newGuy.markerSequence = cloneSequence();
 727         }
 728         newGuy.resetSequence = null;
 729         return newGuy;
 730     }
 731 
 732     /**
 733      * Returns a deep copy of the current marker sequence.
 734      */
 735     private List cloneSequence() {
 736         if (markerSequence == null) {
 737             return null;
 738         }
 739         List retval = new ArrayList(markerSequence.size());
 740         Iterator iter = markerSequence.iterator();
 741         while(iter.hasNext()) {
 742             MarkerSegment seg = (MarkerSegment)iter.next();
 743             retval.add(seg.clone());
 744         }
 745 
 746         return retval;


1998 
1999         // Deal with min case
2000         if (value <= epsilon) {
2001             return new Point(1, 255);
2002         }
2003 
2004         // Deal with max case
2005         if (value >= 255) {
2006             return new Point(255, 1);
2007         }
2008 
2009         // Remember if we invert
2010         boolean inverted = false;
2011         if (value < 1.0) {
2012             value = 1.0F/value;
2013             inverted = true;
2014         }
2015 
2016         // First approximation
2017         int y = 1;
2018         int x = Math.round(value);
2019 
2020         float ratio = (float) x;
2021         float delta = Math.abs(value - ratio);
2022         while (delta > epsilon) { // not close enough
2023             // Increment y and compute a new x
2024             y++;
2025             x = Math.round(y*value);
2026             ratio = (float)x/(float)y;
2027             delta = Math.abs(value - ratio);
2028         }
2029         return inverted ? new Point(y, x) : new Point(x, y);
2030     }
2031 
2032     private void mergeStandardDocumentNode(Node node)
2033         throws IIOInvalidTreeException {
2034         // No-op
2035     }
2036 
2037     private void mergeStandardTextNode(Node node)
2038         throws IIOInvalidTreeException {
2039         // Convert to comments.  For the moment ignore the encoding issue.
2040         // Ignore keywords, language, and encoding (for the moment).
2041         // If compression tag is present, use only entries with "none".
2042         NodeList children = node.getChildNodes();
2043         for (int i = 0; i < children.getLength(); i++) {
2044             Node child = children.item(i);
2045             NamedNodeMap attrs = child.getAttributes();