* @param fill      fill value to apply to mask.
     * @return masked image encoded with the fill colour and transparency.
     */
    private static BufferedImage applyExplicitMask(BufferedImage baseImage, Color fill) {
        // create an
        int baseWidth = baseImage.getWidth();
        int baseHeight = baseImage.getHeight();

        BufferedImage imageMask = new BufferedImage(baseWidth, baseHeight,
                BufferedImage.TYPE_INT_ARGB);

        // 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 = baseImage.getRGB(x, y);
                if (!(maskPixel == -1 || maskPixel == 0xffffff)) {
                    imageMask.setRGB(x, y, fill.getRGB());
                }
            }
        }
        // clean up the old image.
        baseImage.flush();
        // return the mask.
        return imageMask;
    }