1 /* 2 * Copyright (c) 2007, 2017 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 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 }