public static BufferedImage loadImage(String filename, ImageViewer imViewer, ImageMapper imMapper)
    					throws WrongSizeException, WrongProportionException, WrongImageTypeException
    	{
        BufferedImage img = null;
        try
        {
          img = ImageIO.read(new File(filename));
        }
        catch (Exception e)
        {
        		throw new WrongImageTypeException();
        }
        if (img.getWidth() > 256 || img.getHeight() > 256) {
	        	img = null;
	        	throw new WrongSizeException();
        }
        if (img.getWidth() % 8 != 0 || img.getHeight() % 8 != 0) {
	        	img = null;
	        	throw new WrongProportionException();
        }
        int cmap[] = ImageViewer.COLOR_MAP;
        IndexColorModel colorModel = new IndexColorModel(8, cmap.length, cmap, 0, true, -1, DataBuffer.TYPE_BYTE);
        BufferedImage image2 = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_BYTE_INDEXED, colorModel);
        Graphics g = image2.getGraphics();  
        g.drawImage(img, 0, 0, null);  
        g.dispose();
        return image2;
    }