public IndexColorModel filterIndexColorModel(IndexColorModel icm) {
        int transferType = icm.getTransferType();
        int bits = icm.getPixelSize();
        int mapSize = icm.getMapSize();
        int colorMap[] = new int[mapSize];
        int filteredColorMap[] = new int[mapSize];
        icm.getRGBs(colorMap);
        int trans = -1;
        boolean hasAlpha = false;
        for(int i = 0; i < mapSize; i++){
            filteredColorMap[i] = filterRGB(-1, -1, colorMap[i]);
            int alpha = filteredColorMap[i] >>> 24;
            if(alpha != 0xff){
                if(!hasAlpha) {
                    hasAlpha = true;
                }
                if(alpha == 0 && trans < 0) {
                    trans = i;
                }
            }
        }

        return new IndexColorModel(bits, mapSize, filteredColorMap, 0,
                hasAlpha, trans, transferType);
    }