* @param maskImage image mask to be applied to base image.
     */
    private static void applyExplicitMask(BufferedImage baseImage, BufferedImage maskImage) {
        // check to see if we need to scale the mask to match the size of the
        // base image.
        int baseWidth = baseImage.getWidth();
        int baseHeight = baseImage.getHeight();
        int maskWidth = maskImage.getWidth();
        int maskHeight = maskImage.getHeight();

        if (baseWidth != maskWidth || baseHeight != maskHeight) {
            // calculate scale factors.
            double scaleX = baseWidth / (double) maskWidth;
            double scaleY = baseHeight / (double) maskHeight;
            // scale the mask to match the base image.
            AffineTransform tx = new AffineTransform();
            tx.scale(scaleX, scaleY);
            AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
            BufferedImage sbim = op.filter(maskImage, null);
            maskImage.flush();
            maskImage = sbim;
        }
        // apply the mask by simply painting white to the base image where
        // the mask specified no colour.
        for (int y = 0; y < baseHeight; y++) {
            for (int x = 0; x < baseWidth; x++) {
                int maskPixel = maskImage.getRGB(x, y);
                if (maskPixel == -1 || maskPixel == 0xffffff) {
                    baseImage.setRGB(x, y, Color.WHITE.getRGB());
                }
            }
        }

//        int width = maskImage.getWidth();
//        int height = maskImage.getHeight();
//        final BufferedImage bi = new BufferedImage(width,height, BufferedImage.TYPE_INT_RGB);
//        for (int y = 0; y < height; y++) {
//            for (int x = 0; x < width; x++) {
//                if (maskImage.getRGB(x,y) != -1){
//                    bi.setRGB(x, y, Color.red.getRGB());
//                }
//                else{
//                    bi.setRGB(x, y, Color.green.getRGB());
//                }
//            }
//        }
//        final JFrame f = new JFrame("Test");
//        f.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
//
//        JComponent image = new JComponent() {
//            @Override
//            public void paint(Graphics g_) {
//                super.paint(g_);
//                g_.drawImage(bi, 0, 0, f);
//            }
//        };
//        image.setPreferredSize(new Dimension(bi.getWidth(), bi.getHeight()));
//        image.setSize(new Dimension(bi.getWidth(), bi.getHeight()));
//
//        JPanel test  =new JPanel();
//        test.setPreferredSize(new Dimension(1200,1200));
//        JScrollPane tmp = new JScrollPane(image);
//        tmp.revalidate();
//        f.setSize(new Dimension(800, 800));
//        f.getContentPane().add(tmp);
//        f.validate();
//        f.setVisible(true);

    }