*/
    private static BufferedImage applyExplicitSMask(BufferedImage baseImage, BufferedImage sMaskImage) {
        // 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();

        final int maskWidth = sMaskImage.getWidth();
        final int maskHeight = sMaskImage.getHeight();

        // we're going for quality over memory foot print here, for most
        // masks its better to scale the base image up to the mask size.
        if (baseWidth != maskWidth || baseHeight != maskHeight) {
            // calculate scale factors.
            double scaleX = maskWidth / (double) baseWidth;
            double scaleY = maskHeight / (double) baseHeight;
            // 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(baseImage, null);
            baseImage.flush();
            baseImage = sbim;
        }
        // apply the mask by simply painting white to the base image where
        // the mask specified no colour.
        // todo: need to apply alpha instead of white, but requires a new CM.
        int maskPixel;
        for (int y = 0; y < maskHeight; y++) {
            for (int x = 0; x < maskWidth; x++) {
                maskPixel = sMaskImage.getRGB(x, y);
                if (maskPixel != -1 || maskPixel != 0xffffff || maskPixel != 0) {
                    baseImage.setRGB(x, y, Color.WHITE.getRGB());
                }
            }
        }
        return baseImage;
    }