private void generateBannerImage(String materialImageName) throws IOException {
  BufferedImage backgroundImage=null;
  try {
    backgroundImage=ImageIO.read(new File(Options.outputDir + "/tex/banner_base.png"));
  }
 catch (  IOException e) {
synchronized (Banner.class) {
      Log.error("Cant read banner_base - did you export Textures first?",e,firstBaseReadError);
      firstBaseReadError=false;
    }
  }
  if (backgroundImage != null) {
    int imageWidth=backgroundImage.getWidth();
    int imageHeight=backgroundImage.getHeight();
    BufferedImage combined=new BufferedImage(imageWidth,imageHeight,BufferedImage.TYPE_INT_ARGB);
    Graphics combinedGraphics=combined.getGraphics();
    combinedGraphics.drawImage(backgroundImage,0,0,null);
synchronized (PatternList) {
      for (      BannerPattern bp : PatternList) {
        BufferedImage patternImage=new BufferedImage(imageWidth,imageHeight,BufferedImage.TYPE_INT_ARGB);
        BufferedImage patternSource=null;
        try {
          patternSource=ImageIO.read(new File(Options.outputDir + "/tex/banner_pattern_" + bp.getPattern()+ ".png"));
        }
 catch (        IOException e) {
          Log.error("Cant read banner_pattern_" + bp.getPattern() + " - did you export Textures first?",e,true);
        }
        BufferedImage patternAlpha=null;
        try {
          patternAlpha=ImageIO.read(new File(Options.outputDir + "/tex/banner_pattern_" + bp.getPattern()+ "_a.png"));
        }
 catch (        IOException e) {
          Log.error("Cant read banner_pattern_" + bp.getPattern() + "_a - you need to export Textures with seperate alpha!",e,true);
        }
        Color patternColor=getColorById(bp.getColor());
        for (int x=0; x < imageWidth; x++) {
          for (int y=0; y < imageHeight; y++) {
            Color maskColor=new Color(patternSource.getRGB(x,y));
            Color mainMaskColor=new Color(patternAlpha.getRGB(x,y));
            int alpha=maskColor.getRed();
            if (alpha > mainMaskColor.getRed()) {
              alpha=alpha * (mainMaskColor.getRed() / 255);
            }
            Color currentColor=new Color(patternColor.getRed(),patternColor.getGreen(),patternColor.getBlue(),alpha);
            patternImage.setRGB(x,y,currentColor.getRGB());
          }
        }
        combinedGraphics.drawImage(patternImage,0,0,null);
        Log.info(" - Pattern: " + bp.getPattern() + " / "+ bp.getColor()+ "");
      }
    }
    if (!ImageIO.write(combined,"PNG",new File(Options.outputDir + "/tex",materialImageName + ".png"))) {
      throw new RuntimeException("Unexpected error writing image");
    }
  }
}

private void generateBannerImage ( String materialImageName ) throws IOException { BufferedImage backgroundImage = null ; try { backgroundImage = ImageIO . read ( new File ( Options . outputDir + "/tex/banner_base.png" ) ) ; } catch ( IOException e ) { synchronized ( Banner . class ) { Log . error ( "Cant read banner_base - did you export Textures first?" , e , firstBaseReadError ) ; firstBaseReadError = false ; } } if ( backgroundImage != null ) { int imageWidth = backgroundImage . getWidth ( ) ; int imageHeight = backgroundImage . getHeight ( ) ; BufferedImage combined = new BufferedImage ( imageWidth , imageHeight , BufferedImage . TYPE_INT_ARGB ) ; Graphics combinedGraphics = combined . getGraphics ( ) ; combinedGraphics . drawImage ( backgroundImage , 0 , 0 , null ) ; synchronized ( PatternList ) { for ( BannerPattern bp : PatternList ) { BufferedImage patternImage = new BufferedImage ( imageWidth , imageHeight , BufferedImage . TYPE_INT_ARGB ) ; BufferedImage patternSource = null ; try { patternSource = ImageIO . read ( new File ( Options . outputDir + "/tex/banner_pattern_" + bp . getPattern ( ) + ".png" ) ) ; } catch ( IOException e ) { Log . error ( "Cant read banner_pattern_" + bp . getPattern ( ) + " - did you export Textures first?" , e , true ) ; } BufferedImage patternAlpha = null ; try { patternAlpha = ImageIO . read ( new File ( Options . outputDir + "/tex/banner_pattern_" + bp . getPattern ( ) + "_a.png" ) ) ; } catch ( IOException e ) { Log . error ( "Cant read banner_pattern_" + bp . getPattern ( ) + "_a - you need to export Textures with seperate alpha!" , e , true ) ; } Color patternColor = getColorById ( bp . getColor ( ) ) ; for ( int x = 0 ; x < imageWidth ; x ++ ) { for ( int y = 0 ; y < imageHeight ; y ++ ) { Color maskColor = new Color ( patternSource . getRGB ( x , y ) ) ; Color mainMaskColor = new Color ( patternAlpha . getRGB ( x , y ) ) ; int alpha = maskColor . getRed ( ) ; if ( alpha > mainMaskColor . getRed ( ) ) { alpha = alpha * ( mainMaskColor . getRed ( ) / 255 ) ; } Color currentColor = new Color ( patternColor . getRed ( ) , patternColor . getGreen ( ) , patternColor . getBlue ( ) , alpha ) ; patternImage . setRGB ( x , y , currentColor . getRGB ( ) ) ; } } combinedGraphics . drawImage ( patternImage , 0 , 0 , null ) ; Log . info ( " - Pattern: " + bp . getPattern ( ) + " / " + bp . getColor ( ) + "" ) ; } } if ( ! ImageIO . write ( combined , "PNG" , new File ( Options . outputDir + "/tex" , materialImageName + ".png" ) ) ) { throw new RuntimeException ( "Unexpected error writing image" ) ; } } }
creates the banner images
