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

Print this page


   1 /*
   2  * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


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


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


   1 /*
   2  * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


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


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