<commit_before>/*
 * This file is part of Caustic API.
 *
 * Copyright (c) 2013 Spout LLC <http://www.spout.org/>
 * Caustic API is licensed under the Spout License Version 1.
 *
 * Caustic API is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 *
 * In addition, 180 days after any changes are published, you can use the
 * software, incorporating those changes, under the terms of the MIT license,
 * as described in the Spout License Version 1.
 *
 * Caustic API is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
 * more details.
 *
 * You should have received a copy of the GNU Lesser General Public License,
 * the MIT license and the Spout License Version 1 along with this program.
 * If not, see <http://www.gnu.org/licenses/> for the GNU Lesser General Public
 * License and see <http://spout.in/licensev1> for the full license, including
 * the MIT license.
 */
package org.spout.renderer.api.util;

import javax.imageio.ImageIO;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.DoubleBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;
import java.util.logging.Logger;

import com.flowpowered.math.GenericMath;
import com.flowpowered.math.vector.Vector4f;

import gnu.trove.list.TFloatList;
import gnu.trove.list.TIntList;
import gnu.trove.list.array.TFloatArrayList;

import org.spout.renderer.api.GLVersioned;
import org.spout.renderer.api.GLVersioned.GLVersion;
import org.spout.renderer.api.data.VertexAttribute.DataType;
import org.spout.renderer.api.gl.Texture.Format;

/**
 * Utility methods for Caustic and rendering.
 */
public final class CausticUtil {
    private static boolean debug = true;
    private static final Logger logger = Logger.getLogger("Caustic");
    public static final Vector4f WHITE = new Vector4f(1, 1, 1, 1);
    public static final Vector4f LIGHT_GRAY = new Vector4f(192 / 255f, 192 / 255f, 192 / 255f, 1);
    public static final Vector4f GRAY = new Vector4f(128 / 255f, 128 / 255f, 128 / 255f, 1);
    public static final Vector4f DARK_GRAY = new Vector4f(64 / 255f, 64 / 255f, 64 / 255f, 1);
    public static final Vector4f BLACK = new Vector4f(0, 0, 0, 1);
    public static final Vector4f RED = new Vector4f(1, 0, 0, 1);
    public static final Vector4f PINK = new Vector4f(1, 175 / 255f, 175 / 255f, 1);
    public static final Vector4f ORANGE = new Vector4f(1, 200 / 255f, 0, 1);
    public static final Vector4f YELLOW = new Vector4f(1, 1, 0, 1);
    public static final Vector4f GREEN = new Vector4f(0, 1, 0, 1);
    public static final Vector4f MAGENTA = new Vector4f(1, 0, 1, 1);
    public static final Vector4f CYAN = new Vector4f(0, 1, 1, 1);
    public static final Vector4f BLUE = new Vector4f(0, 0, 1, 1);

    private CausticUtil() {
    }

    /**
     * Sets the caustic renderer in debug mode.
     *
     * @param enabled If debug should be enabled
     */
    public static void setDebugEnabled(boolean enabled) {
        debug = enabled;
    }

    /**
     * Returns true if debug mode is enabled, false if otherwise.
     *
     * @return Whether or not debug mode is enabled.
     */
    public static boolean isDebugEnabled() {
        return debug;
    }

    /**
     * Returns the logger used by the Caustic classes.
     *
     * @return The Caustic logger
     */
    public static Logger getCausticLogger() {
        return logger;
    }

    /**
     * Checks if two OpenGL versioned object have compatible version. Throws an exception if that's not the case.
     *
     * @param required The required version
     * @param object The object to check the version of
     * @throws IllegalStateException If the object versions are not compatible
     */
    public static void checkVersion(GLVersioned required, GLVersioned object) {
        final GLVersion requiredVersion = required.getGLVersion();
        final GLVersion objectVersion = object.getGLVersion();
        if (objectVersion.getMajor() != requiredVersion.getMajor() && objectVersion.getMinor() > requiredVersion.getMinor()) {
            throw new IllegalStateException("Versions not compatible: expected " + requiredVersion + " or lower in minor versions, got " + objectVersion);
        }
    }

    /**
     * Gets the {@link java.io.InputStream}'s data as a {@link java.nio.ByteBuffer}. The image data reading is done according to the {@link org.spout.renderer.api.gl.Texture.Format}. The image size is
     * stored in the passed {@link Rectangle} instance. The returned buffer is flipped an ready for reading.
     *
     * @param source The image input stream to extract the data from
     * @param format The format of the image data
     * @param size The rectangle to store the size in<commit_msg>Allow lower major version in checkVersion<commit_after>/*
 * This file is part of Caustic API.
 *
 * Copyright (c) 2013 Spout LLC <http://www.spout.org/>
 * Caustic API is licensed under the Spout License Version 1.
 *
 * Caustic API is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 *
 * In addition, 180 days after any changes are published, you can use the
 * software, incorporating those changes, under the terms of the MIT license,
 * as described in the Spout License Version 1.
 *
 * Caustic API is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
 * more details.
 *
 * You should have received a copy of the GNU Lesser General Public License,
 * the MIT license and the Spout License Version 1 along with this program.
 * If not, see <http://www.gnu.org/licenses/> for the GNU Lesser General Public
 * License and see <http://spout.in/licensev1> for the full license, including
 * the MIT license.
 */
package org.spout.renderer.api.util;

import javax.imageio.ImageIO;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.DoubleBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;
import java.util.logging.Logger;

import com.flowpowered.math.GenericMath;
import com.flowpowered.math.vector.Vector4f;

import gnu.trove.list.TFloatList;
import gnu.trove.list.TIntList;
import gnu.trove.list.array.TFloatArrayList;

import org.spout.renderer.api.GLVersioned;
import org.spout.renderer.api.GLVersioned.GLVersion;
import org.spout.renderer.api.data.VertexAttribute.DataType;
import org.spout.renderer.api.gl.Texture.Format;

/**
 * Utility methods for Caustic and rendering.
 */
public final class CausticUtil {
    private static boolean debug = true;
    private static final Logger logger = Logger.getLogger("Caustic");
    public static final Vector4f WHITE = new Vector4f(1, 1, 1, 1);
    public static final Vector4f LIGHT_GRAY = new Vector4f(192 / 255f, 192 / 255f, 192 / 255f, 1);
    public static final Vector4f GRAY = new Vector4f(128 / 255f, 128 / 255f, 128 / 255f, 1);
    public static final Vector4f DARK_GRAY = new Vector4f(64 / 255f, 64 / 255f, 64 / 255f, 1);
    public static final Vector4f BLACK = new Vector4f(0, 0, 0, 1);
    public static final Vector4f RED = new Vector4f(1, 0, 0, 1);
    public static final Vector4f PINK = new Vector4f(1, 175 / 255f, 175 / 255f, 1);
    public static final Vector4f ORANGE = new Vector4f(1, 200 / 255f, 0, 1);
    public static final Vector4f YELLOW = new Vector4f(1, 1, 0, 1);
    public static final Vector4f GREEN = new Vector4f(0, 1, 0, 1);
    public static final Vector4f MAGENTA = new Vector4f(1, 0, 1, 1);
    public static final Vector4f CYAN = new Vector4f(0, 1, 1, 1);
    public static final Vector4f BLUE = new Vector4f(0, 0, 1, 1);

    private CausticUtil() {
    }

    /**
     * Sets the caustic renderer in debug mode.
     *
     * @param enabled If debug should be enabled
     */
    public static void setDebugEnabled(boolean enabled) {
        debug = enabled;
    }

    /**
     * Returns true if debug mode is enabled, false if otherwise.
     *
     * @return Whether or not debug mode is enabled.
     */
    public static boolean isDebugEnabled() {
        return debug;
    }

    /**
     * Returns the logger used by the Caustic classes.
     *
     * @return The Caustic logger
     */
    public static Logger getCausticLogger() {
        return logger;
    }

    /**
     * Checks if two OpenGL versioned object have compatible version. Throws an exception if that's not the case. A version is determined to be compatible with another is it's lower than the said
     * version. This isn't always true when deprecation is involved, but it's an acceptable way of doing this in most implementations.
     *
     * @param required The required version
     * @param object The object to check the version of
     * @throws IllegalStateException If the object versions are not compatible
     */
    public static void checkVersion(GLVersioned required, GLVersioned object) {
        final GLVersion requiredVersion = required.getGLVersion();
        final GLVersion objectVersion = object.getGLVersion();
        if (objectVersion.getMajor() > requiredVersion.getMajor() && objectVersion.getMinor() > requiredVersion.getMinor()) {
            throw new IllegalStateException("Versions not compatible: expected " + requiredVersion + " or lower, got " + objectVersion);
        }
    }

    /**
     * Gets the {@link java.io.InputStream}'s data as a {@link java.nio.ByteBuffer}. The image data reading is done according to the {@link org.spout.renderer.api.gl.Texture.Format}. The image size is
     * stored in the passed {@link Rectangle} instance. The returned buffer is flipped an ready for reading.
     *
     * @param source The image input stream to extract the data from
     * @param format The format of the image data
     * @param size The rectangle to store the size in
{'fraction_non_alphanumeric': 0.08478382930937675, 'fraction_numerical': 0.027699794123151787, 'mean_word_length': 3.354930725346373, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '6887943', 'n_tokens_mistral': 3292, 'n_tokens_neox': 3042, 'n_words': 1238}