All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.mathiewz.slick.imageout.ImageWriterFactory Maven / Gradle / Ivy

Go to download

The main purpose of this libraryis to modernize and maintain the slick2D library.

The newest version!
package com.github.mathiewz.slick.imageout;

import java.util.HashMap;

import javax.imageio.ImageIO;

import com.github.mathiewz.slick.SlickException;

/**
 * A factory to produce image writers based on format names
 *
 * @author kevin
 */
public class ImageWriterFactory {
    /** The map from format names to image writer instances */
    private static HashMap writers = new HashMap<>();
    
    // Initialise the list of writers based on the classes we know about
    static {
        String[] formats = ImageIO.getWriterFormatNames();
        ImageIOWriter writer = new ImageIOWriter();
        for (String format : formats) {
            registerWriter(format, writer);
        }
        
        TGAWriter tga = new TGAWriter();
        registerWriter("tga", tga);
    }
    
    /**
     * Register an image writer with the factory. This will allow users
     * to use it to write out the explicit format
     *
     * @param format
     *            The format (usually extension) of the files that will be written out
     * @param writer
     *            The writer to use for the given format
     */
    public static void registerWriter(String format, ImageWriter writer) {
        writers.put(format, writer);
    }
    
    /**
     * Get the list of support format strings for this factory
     *
     * @return The list of support format strings for this factory
     */
    public static String[] getSupportedFormats() {
        return writers.keySet().toArray(new String[0]);
    }
    
    /**
     * Get a Slick image writer for the given format
     *
     * @param format
     *            The format of the image to write
     * @return The image write to use to produce these images
     */
    public static ImageWriter getWriterForFormat(String format) {
        ImageWriter writer = writers.get(format);
        if (writer != null) {
            return writer;
        }
        
        writer = writers.get(format.toLowerCase());
        if (writer != null) {
            return writer;
        }
        
        writer = writers.get(format.toUpperCase());
        if (writer != null) {
            return writer;
        }
        
        throw new SlickException("No image writer available for: " + format);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy