<commit_before>/*
 * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this 
 * list of conditions and the following disclaimer. 
 * 
 * Redistributions in binary form must reproduce the above copyright notice, 
 * this list of conditions and the following disclaimer in the documentation 
 * and/or other materials provided with the distribution. 
 * 
 * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the 
 * names of its contributors may be used to endorse or promote products derived 
 * from this software without specific prior written permission. 
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */

package com.jme.util;

import java.awt.Graphics2D;
import java.awt.Toolkit;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.awt.image.DirectColorModel;
import java.awt.image.MemoryImageSource;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.ByteBuffer;
import java.util.logging.Level;

import com.jme.image.BitmapHeader;
import com.jme.image.Texture;
import com.jme.renderer.ColorRGBA;

/**
 * 
 * <code>TextureManager</code> provides static methods for building a
 * <code>Texture</code> object. Typically, the information supplied is the
 * filename and the texture properties.
 * @author <NAME>
 * @version $Id: TextureManager.java,v 1.5 2004-02-24 18:00:34 mojomonkey Exp $
 */
public class TextureManager {
   
    // For TGA loading
    private static final int NO_TRANSPARENCY = 255;
    private static final int FULL_TRANSPARENCY = 0;

    private static short idLength;
    private static short colorMapType;
    private static short imageType;
    private static int cMapStart;
    private static int cMapLength;
    private static short cMapDepth;
    private static int xOffset;
    private static int yOffset;
    private static int width;
    private static int height;
    private static short pixelDepth;
    private static short imageDescriptor;
    private static DirectColorModel cm;
    private static int[] pixels;
    
    /**
     * <code>loadTexture</code> loads a new texture defined by the parameter
     * string. Filter parameters are used
     * to define the filtering of the texture. Whether the texture is to be
     * mipmapped or not is denoted by the isMipmapped boolean flag. If there
     * is an error loading the file, null is returned.
     * 
     * @param file the filename of the texture image.
     * @param minFilter the filter for the near values.
     * @param magFilter the filter for the far values.
     * @param isMipmapped determines if we will load the texture mipmapped
     *      or not. True load the texture mipmapped, false do not.
     * @param flipped true flips the bits of the image, false does not. True
     *      by default.
     * 
     * @return the loaded texture. If there is a problem
     *      loading the texture, null is returned.
     */
    public static com.jme.image.Texture loadTexture(
    		String file,
			int minFilter,
			int magFilter,
			boolean isMipMapped) {
    	return loadTexture(file, minFilter, magFilter, isMipMapped, true);
    }
    
    /**
     * <code>loadTexture</code> loads a new texture defined by the parameter
     * string. Filter parameters are used
     * to define the filtering of the texture. Whether the texture is to be
     * mipmapped or not is denoted by the isMipmapped boolean flag. If there
     * is an error loading the file, null is returned.
     * 
     * @param file the filename of the texture image.
     * @param minFilter the filter for the near values.
     * @param magFilter the filter for the far values.
     * @param isMipmapped determines if we will load the texture mipmapped
     *      or not. True load the texture mipmapped, false do not.
     * 
     * @return the loaded texture. If there is a problem
     *      loading the texture, null is returned.
     */
    public static com.jme.image.Texture loadTexture(
    		String file,
			int minFilter,
			int magFilter,
			boolean isMipmapped,
			boolean flipped) {
    	
    	URL url = null;
		try {
			url = new URL("file:"+file);
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
		return loadTexture(url,minFilter,magFilter,isMipmapped,flipped);
    }

    
    /**
     * <code>loadTexture</code> loads a new texture defined by the parameter
     * url. Filter parameters are used
     * to define the filtering of the texture. Whether the texture is to be
     * mipmapped or not is denoted by the isMipmapped boolean flag. If there
     * is an error loading the file, null is returned.
     * 
     * @param file the url of the texture image.
     * @param minFilter the filter for the near values.
     * @param magFilter the filter for the far values.
     * @param isMipmapped determines if we will load the texture mipmapped
     *      or not. True load the texture mipmapped, false do not.
     * @param flipped true flips the bits of the image, false does not. True
     *      by default.
     * 
     * @return the loaded texture. If there is a problem
     *      loading the texture, null is returned.
     */
    public static com.jme.image.Texture loadTexture(
        URL file,
        int minFilter,
        int magFilter,
        boolean isMipMapped) {
        return loadTexture(file, minFilter, magFilter, isMipMapped, true);
    }

    /**
     * <code>loadTexture</code> loads a new texture defined by the parameter
     * url. Filter parameters are used
     * to define the filtering of the texture. Whether the texture is to be
     * mipmapped or not is denoted by the isMipmapped boolean flag. If there
     * is an error loading the file, null is returned.
     * 
     * @param file the url of the texture image.
     * @param minFilter the filter for the near values.
     * @param magFilter the filter for the far values.
     * @param isMipmapped determines if we will load the texture mipmapped
     *      or not. True load the texture mipmapped, false do not.
     * 
     * @return the loaded texture. If there is a problem
     *      loading the texture, null is returned.
     */
    public static com.jme.image.Texture loadTexture(
        URL file,
        int minFilter,
        int magFilter,
        boolean isMipmapped,
        boolean flipped) {

		if(null == file) {
    		return null;
    	}
    	
    	java.awt.Image image = null;
    	String fileName = file.getFile();
        if (".TGA".equalsIgnoreCase(fileName.substring(file.getFile().lastIndexOf('.')))) {
            //Load the TGA file
            image = loadTGAImage(file);
        } else if (
            ".BMP".equalsIgnoreCase(fileName.substring(file.getFile().lastIndexOf('.')))) {
            image = loadBMPImage(file);
        } else {
            //Load the new image.
            image = (new javax.swing.ImageIcon(file)).getImage();
        }<commit_msg>Cleaned up file name testing.<commit_after>/*
 * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this 
 * list of conditions and the following disclaimer. 
 * 
 * Redistributions in binary form must reproduce the above copyright notice, 
 * this list of conditions and the following disclaimer in the documentation 
 * and/or other materials provided with the distribution. 
 * 
 * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the 
 * names of its contributors may be used to endorse or promote products derived 
 * from this software without specific prior written permission. 
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */

package com.jme.util;

import java.awt.Graphics2D;
import java.awt.Toolkit;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.awt.image.DirectColorModel;
import java.awt.image.MemoryImageSource;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.ByteBuffer;
import java.util.logging.Level;

import com.jme.image.BitmapHeader;
import com.jme.image.Texture;
import com.jme.renderer.ColorRGBA;

/**
 * 
 * <code>TextureManager</code> provides static methods for building a
 * <code>Texture</code> object. Typically, the information supplied is the
 * filename and the texture properties.
 * @author <NAME>
 * @version $Id: TextureManager.java,v 1.6 2004-02-24 22:01:13 mojomonkey Exp $
 */
public class TextureManager {
   
    // For TGA loading
    private static final int NO_TRANSPARENCY = 255;
    private static final int FULL_TRANSPARENCY = 0;

    private static short idLength;
    private static short colorMapType;
    private static short imageType;
    private static int cMapStart;
    private static int cMapLength;
    private static short cMapDepth;
    private static int xOffset;
    private static int yOffset;
    private static int width;
    private static int height;
    private static short pixelDepth;
    private static short imageDescriptor;
    private static DirectColorModel cm;
    private static int[] pixels;
    
    /**
     * <code>loadTexture</code> loads a new texture defined by the parameter
     * string. Filter parameters are used
     * to define the filtering of the texture. Whether the texture is to be
     * mipmapped or not is denoted by the isMipmapped boolean flag. If there
     * is an error loading the file, null is returned.
     * 
     * @param file the filename of the texture image.
     * @param minFilter the filter for the near values.
     * @param magFilter the filter for the far values.
     * @param isMipmapped determines if we will load the texture mipmapped
     *      or not. True load the texture mipmapped, false do not.
     * @param flipped true flips the bits of the image, false does not. True
     *      by default.
     * 
     * @return the loaded texture. If there is a problem
     *      loading the texture, null is returned.
     */
    public static com.jme.image.Texture loadTexture(
    		String file,
			int minFilter,
			int magFilter,
			boolean isMipMapped) {
    	return loadTexture(file, minFilter, magFilter, isMipMapped, true);
    }
    
    /**
     * <code>loadTexture</code> loads a new texture defined by the parameter
     * string. Filter parameters are used
     * to define the filtering of the texture. Whether the texture is to be
     * mipmapped or not is denoted by the isMipmapped boolean flag. If there
     * is an error loading the file, null is returned.
     * 
     * @param file the filename of the texture image.
     * @param minFilter the filter for the near values.
     * @param magFilter the filter for the far values.
     * @param isMipmapped determines if we will load the texture mipmapped
     *      or not. True load the texture mipmapped, false do not.
     * 
     * @return the loaded texture. If there is a problem
     *      loading the texture, null is returned.
     */
    public static com.jme.image.Texture loadTexture(
    		String file,
			int minFilter,
			int magFilter,
			boolean isMipmapped,
			boolean flipped) {
    	
    	URL url = null;
		try {
			url = new URL("file:"+file);
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
		return loadTexture(url,minFilter,magFilter,isMipmapped,flipped);
    }

    
    /**
     * <code>loadTexture</code> loads a new texture defined by the parameter
     * url. Filter parameters are used
     * to define the filtering of the texture. Whether the texture is to be
     * mipmapped or not is denoted by the isMipmapped boolean flag. If there
     * is an error loading the file, null is returned.
     * 
     * @param file the url of the texture image.
     * @param minFilter the filter for the near values.
     * @param magFilter the filter for the far values.
     * @param isMipmapped determines if we will load the texture mipmapped
     *      or not. True load the texture mipmapped, false do not.
     * @param flipped true flips the bits of the image, false does not. True
     *      by default.
     * 
     * @return the loaded texture. If there is a problem
     *      loading the texture, null is returned.
     */
    public static com.jme.image.Texture loadTexture(
        URL file,
        int minFilter,
        int magFilter,
        boolean isMipMapped) {
        return loadTexture(file, minFilter, magFilter, isMipMapped, true);
    }

    /**
     * <code>loadTexture</code> loads a new texture defined by the parameter
     * url. Filter parameters are used
     * to define the filtering of the texture. Whether the texture is to be
     * mipmapped or not is denoted by the isMipmapped boolean flag. If there
     * is an error loading the file, null is returned.
     * 
     * @param file the url of the texture image.
     * @param minFilter the filter for the near values.
     * @param magFilter the filter for the far values.
     * @param isMipmapped determines if we will load the texture mipmapped
     *      or not. True load the texture mipmapped, false do not.
     * 
     * @return the loaded texture. If there is a problem
     *      loading the texture, null is returned.
     */
    public static com.jme.image.Texture loadTexture(
        URL file,
        int minFilter,
        int magFilter,
        boolean isMipmapped,
        boolean flipped) {

		if(null == file) {
    		return null;
    	}
    	
    	java.awt.Image image = null;
    	String fileName = file.getFile();
        if (".TGA".equalsIgnoreCase(fileName.substring(fileName.lastIndexOf('.')))) {
            //Load the TGA file
            image = loadTGAImage(file);
        } else if (
            ".BMP".equalsIgnoreCase(fileName.substring(fileName.lastIndexOf('.')))) {
            image = loadBMPImage(file);
        } else {
            //Load the new image.
            image = (new javax.swing.ImageIcon(file)).getImage();
        }
{'fraction_non_alphanumeric': 0.06883519206939281, 'fraction_numerical': 0.0030978934324659233, 'mean_word_length': 2.852267303102625, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1541821', 'n_tokens_mistral': 4602, 'n_tokens_neox': 4342, 'n_words': 1876}