< prev index next >

core/JemmyCore/src/org/jemmy/image/pixel/ColorMappingComparator.java

Print this page




  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
  23  * questions.
  24  */
  25 package org.jemmy.image.pixel;
  26 
  27 import java.util.List;
  28 import org.jemmy.Dimension;
  29 import org.jemmy.image.pixel.Raster.Component;
  30 
  31 /**
  32  *
  33  * @author shura
  34  */
  35 public abstract class ColorMappingComparator implements RasterComparator {
  36 
  37     final private ColorMap left;
  38     final private ColorMap right;
  39     private RasterComparator subComparator;
  40 
  41     /**
  42      *
  43      * @param left
  44      * @param right
  45      * @param subComparator
  46      */
  47     public ColorMappingComparator(ColorMap left, ColorMap right,
  48             RasterComparator subComparator) {
  49         this.subComparator = subComparator;
  50         this.left = left;
  51         this.right = right;
  52     }
  53 
  54     /**
  55      *
  56      * @return
  57      */
  58     public RasterComparator getSubComparator() {
  59         return subComparator;
  60     }
  61 
  62     /**
  63      *
  64      * @param subComparator
  65      */
  66     public void setSubComparator(RasterComparator subComparator) {
  67         this.subComparator = subComparator;
  68     }
  69 
  70     /**
  71      *
  72      * @param both
  73      * @param subComparator
  74      */
  75     public ColorMappingComparator(ColorMap both, RasterComparator subComparator) {
  76         this(both, both, subComparator);
  77     }
  78 
  79     /**
  80      *
  81      * @param image1
  82      * @param image2
  83      * @return
  84      */
  85     public boolean compare(Raster image1, Raster image2) {
  86         return subComparator.compare(map(image1, left), map(image2, right));
  87     }
  88 
  89     /**
  90      *
  91      * @param image
  92      * @param map
  93      * @return
  94      */
  95     public WriteableRaster map(Raster image, ColorMap map) {
  96         WriteableRaster res = createView(image.getSize());
  97         double[] colors = new double[image.getSupported().length];
  98         double[] newColors = new double[image.getSupported().length];
  99         for (int x = 0; x < image.getSize().width; x++) {
 100             for (int y = 0; y < image.getSize().height; y++) {
 101                 image.getColors(x, y, colors);
 102                 map.map(image.getSupported(), colors, newColors);
 103                 res.setColors(x, y, newColors);
 104             }
 105         }
 106         return res;
 107     }
 108 
 109     /**
 110      *
 111      * @param size
 112      * @return
 113      */
 114     protected abstract WriteableRaster createView(Dimension size);
 115 
 116     /**
 117      *
 118      * @return
 119      */
 120     public String getID() {
 121         return ColorMappingComparator.class.getName() + ":" +
 122                 left.getID() + "," + right.getID() + "(" +
 123                 subComparator.getID() + ")";
 124     }
 125 
 126     /**
 127      *
 128      */
 129     public interface ColorMap {
 130 
 131         /**
 132          *
 133          * @param components
 134          * @param values
 135          * @param newValues
 136          */
 137         public void map(Component[] components, double[] values, double[] newValues);
 138         /**
 139          *
 140          * @return
 141          */
 142         public String getID();
 143     }
 144 }


  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
  23  * questions.
  24  */
  25 package org.jemmy.image.pixel;
  26 
  27 import java.util.List;
  28 import org.jemmy.Dimension;
  29 import org.jemmy.image.pixel.Raster.Component;
  30 
  31 /**

  32  * @author shura
  33  */
  34 public abstract class ColorMappingComparator implements RasterComparator {
  35 
  36     final private ColorMap left;
  37     final private ColorMap right;
  38     private RasterComparator subComparator;
  39 






  40     public ColorMappingComparator(ColorMap left, ColorMap right,
  41             RasterComparator subComparator) {
  42         this.subComparator = subComparator;
  43         this.left = left;
  44         this.right = right;
  45     }
  46 




  47     public RasterComparator getSubComparator() {
  48         return subComparator;
  49     }
  50 




  51     public void setSubComparator(RasterComparator subComparator) {
  52         this.subComparator = subComparator;
  53     }
  54 





  55     public ColorMappingComparator(ColorMap both, RasterComparator subComparator) {
  56         this(both, both, subComparator);
  57     }
  58 






  59     public boolean compare(Raster image1, Raster image2) {
  60         return subComparator.compare(map(image1, left), map(image2, right));
  61     }
  62 






  63     public WriteableRaster map(Raster image, ColorMap map) {
  64         WriteableRaster res = createView(image.getSize());
  65         double[] colors = new double[image.getSupported().length];
  66         double[] newColors = new double[image.getSupported().length];
  67         for (int x = 0; x < image.getSize().width; x++) {
  68             for (int y = 0; y < image.getSize().height; y++) {
  69                 image.getColors(x, y, colors);
  70                 map.map(image.getSupported(), colors, newColors);
  71                 res.setColors(x, y, newColors);
  72             }
  73         }
  74         return res;
  75     }
  76 





  77     protected abstract WriteableRaster createView(Dimension size);
  78 




  79     public String getID() {
  80         return ColorMappingComparator.class.getName() + ":" +
  81                 left.getID() + "," + right.getID() + "(" +
  82                 subComparator.getID() + ")";
  83     }
  84 



  85     public interface ColorMap {
  86 






  87         public void map(Component[] components, double[] values, double[] newValues);
  88 



  89         public String getID();
  90     }
  91 }
< prev index next >