public BufferedImage convert(BufferedImage src, int[] cols) {
    	if (cols.length != xcolors.length) {System.out.println("# of colors doesn't match"); return src;}
        int w = src.getWidth();
        int h = src.getHeight();
        int type = Transparency.BITMASK;
        BufferedImage dst = getCompatibleImage(w,h,type);
        int buf[] = new int[w];
        for(int y = 0; y < h; y++) {
            src.getRGB(0, y, w, 1, buf, 0, w);
            for(int x = 0; x < w; x++) {
                for (int c = 0; c < xcolors.length; c++) {
                	if(buf[x] == xcolors[c]) {buf[x] = cols[c]; break;}
                }
            }
            dst.setRGB(0, y, w, 1, buf, 0, w);
        }
        return dst;
    }