Class CharasConverter

java.lang.Object
games.stendhal.tools.charas.CharasConverter

public class CharasConverter extends Object

Utility to convert images saved from Charas to be suitable for Stendhal. Basically this means making the background color transparent and scaling the image using the scale2x algorithm.

Usage:

  1. command line mode: "java tools.CharasConverter source.png destination.png"
  2. graphical mode: start without any parameters to use the file selectors

Author:
johnnnny
  • Constructor Details

    • CharasConverter

      public CharasConverter()
  • Method Details

    • main

      public static void main(String[] args)
    • convertImage

      protected void convertImage(String srcFilename, String dstFilename) throws IOException
      Convert a single image file to destination file.
      Parameters:
      srcFilename - full path to source image file
      dstFilename - full path to destination image file
      Throws:
      IOException - if loading or saving fails
    • getImageWithTransparency

      protected BufferedImage getImageWithTransparency(BufferedImage image, int px, int py)
      Get a copy of the image with a single color transparent. The color made to be transparent is specified by pixel.
      Parameters:
      image - source image
      px - X index of the pixel for transparency color
      py - Y index of the pixel for transparency color
      Returns:
      Copy of the image with one color changed to transparent
    • savePNGImage

      protected void savePNGImage(String filename, BufferedImage image) throws IOException
      Saves an image as PNG.
      Parameters:
      filename - destination filename
      image - imagedata
      Throws:
      IOException - if writing fails
    • loadImage

      protected BufferedImage loadImage(String filename) throws IOException
      Loads an image.
      Parameters:
      filename - the name of the file from which the image file
      Returns:
      loaded image
      Throws:
      IOException - if reading the file fails
    • getScaled2x

      protected BufferedImage getScaled2x(BufferedImage srcImage)
      Scale an image to double size using the scale2x algorithm.
      Parameters:
      srcImage - source image data
      Returns:
      scaled image