public void setImageLevel(TransparentImageLevel lev, int index) {
        if (index < 0 || index > MAX_IMG_LEVELS) {
            throw new IllegalArgumentException("Bad index for setImageLevel:" + index);
        }
        if (imgLevels[index] == null && lev != null) {
            // new one added
            numImgLevels++;
            imgLevels[index] = lev;
        } else if (imgLevels[index] != null && lev == null) {
            // old one replaced with null
            numImgLevels--;
            imgLevels[index] = lev;
        } else {
            // overwrite existing
            imgLevels[index] = lev;
        }
    }