<commit_before>package test.com.xceptance.xlt.visual;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import org.apache.commons.lang.ClassUtils;

public abstract class ImageTest
{
    protected File resolveFile(final String name)
    {
        final String path = ClassUtils.getPackageName(this.getClass()).replace(".", "/");
        return new File("src/" + path + "/" + name);
    }

    protected BufferedImage load(File f)
    {
        try
        {
            return ImageIO.read(f);
        }
        catch (IOException e)
        {
            throw new RuntimeException("File " + f.getAbsolutePath() + " not found!", e);
        }
    }

    protected void write(BufferedImage image, String fileName)
    {
        try
        {
            ImageIO.write(image, "PNG", new File("c:/temp/" + fileName));
        }
        catch (IOException e)
        {
            throw new RuntimeException(e);
        }
    }

    protected BufferedImage load(String f)
    {
        return load(resolveFile(f));
    }

    protected boolean imageEqual(BufferedImage img1, BufferedImage img2)
    {
        if (img1 == null && img2 == null)
            return true;

        if (img1 == null || img2 == null)
            return false;

        for (int x = 0; x < img1.getWidth(); x++)
        {
            for (int y = 0; y < img1.getHeight(); y++)
            {
                // if the RGB values of 2 pixels differ
                if (img1.getRGB(x, y) != img2.getRGB(x, y))
                {
                    return false;
                }
            }
        }

        return true;
    }

    protected BufferedImage createTestImageGradient(final Color startColor, final int r, final int g, final int b) throws IOException
    {
        final BufferedImage img = new BufferedImage(300, 13, BufferedImage.TYPE_INT_RGB);

        // white
        final Graphics graphics = img.getGraphics();
        graphics.setColor(Color.WHITE);<commit_msg>Avoid hard coded tmp dir<commit_after>package test.com.xceptance.xlt.visual;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import org.apache.commons.lang.ClassUtils;

public abstract class ImageTest
{
    protected File resolveFile(final String name)
    {
        final String path = ClassUtils.getPackageName(this.getClass()).replace(".", "/");
        return new File("src/" + path + "/" + name);
    }

    protected BufferedImage load(final File f)
    {
        try
        {
            return ImageIO.read(f);
        }
        catch (final IOException e)
        {
            throw new RuntimeException("File " + f.getAbsolutePath() + " not found!", e);
        }
    }

    private void write(final BufferedImage image, final String type, final File file)
    {
        try
        {
            ImageIO.write(image, type, file);
        }
        catch (final IOException e)
        {
            throw new RuntimeException(e);
        }
    }

    protected void write(final BufferedImage image, final String fileName)
    {
        write(image, "PNG", new File(fileName));
    }

    protected void writeToTmp(final BufferedImage image, final String fileName)
    {
        write(image, "PNG", new File(new File(System.getProperty("java.io.tmpdir")), fileName));
    }

    protected BufferedImage load(final String f)
    {
        return load(resolveFile(f));
    }

    protected boolean imageEqual(final BufferedImage img1, final BufferedImage img2)
    {
        if (img1 == null && img2 == null)
            return true;

        if (img1 == null || img2 == null)
            return false;

        for (int x = 0; x < img1.getWidth(); x++)
        {
            for (int y = 0; y < img1.getHeight(); y++)
            {
                // if the RGB values of 2 pixels differ
                if (img1.getRGB(x, y) != img2.getRGB(x, y))
                {
                    return false;
                }
            }
        }

        return true;
    }

    protected BufferedImage createTestImageGradient(final Color startColor, final int r, final int g, final int b) throws IOException
    {
        final BufferedImage img = new BufferedImage(300, 13, BufferedImage.TYPE_INT_RGB);

        // white
        final Graphics graphics = img.getGraphics();
        graphics.setColor(Color.WHITE);
{'fraction_non_alphanumeric': 0.10658098825614891, 'fraction_numerical': 0.007976955461998671, 'mean_word_length': 1.9426336375488917, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '6338600', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1272, 'n_words': 348}