<commit_before>import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class BMPInterface {
    public static int HEIGHT=0;
    public static int WIDTH=0;

    public static void printvec(byte[] vec) {
        for (int i=0; i<vec.length; i++) {
            System.out.print(vec[i] + " ");
        }
        System.out.println();
    }

    public static void printvec(double[] vec) {
        for (int i=0; i<vec.length; i++) {
            System.out.print(vec[i] + " ");
        }
        System.out.println();
    }

    public static double[] toDouble(byte[] vec) {
        double[] ret = new double[vec.length];
        for (int i=0; i<vec.length; i++) {
            ret[i] = (double)(vec[i] & 0xFF) / 255;
        }
        return ret;
    }

    public static byte[] toByte(double[] vec) {
        byte[] ret = new byte[vec.length];
        for (int i=0; i<vec.length; i++) {
            ret[i] = (byte)(vec[i] * 255);
        }
        return ret;
    }

    public static double[] readBMP(String path){
        // read image
        BufferedImage img;
        try { 
            img = ImageIO.read(new File(path)); 
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        if (HEIGHT == 0 && WIDTH == 0) { // avoid multiple setting
            HEIGHT = img.getHeight();
            WIDTH  = img.getWidth();
        }
        // make sure it's grayscale (one byte per pixel)
        if(img.getType()!=BufferedImage.TYPE_BYTE_GRAY) {
            System.out.println("Converting to grayscale...");
            img = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_BYTE_GRAY);
        }

        // return array of pixels
        byte[] pixels = new byte[WIDTH*HEIGHT];
        img.getRaster().getDataElements(0,0,WIDTH,HEIGHT,pixels);
        return toDouble(pixels);
    }

    public static void writeBMP(double[] pixels, String path) {<commit_msg>readBMP now takes either File or String-path<commit_after>import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class BMPInterface {
    public static int HEIGHT=0;
    public static int WIDTH=0;

    public static void printvec(byte[] vec) {
        for (int i=0; i<vec.length; i++) {
            System.out.print(vec[i] + " ");
        }
        System.out.println();
    }

    public static void printvec(double[] vec) {
        for (int i=0; i<vec.length; i++) {
            System.out.print(vec[i] + " ");
        }
        System.out.println();
    }

    public static double[] toDouble(byte[] vec) {
        double[] ret = new double[vec.length];
        for (int i=0; i<vec.length; i++) {
            ret[i] = (double)(vec[i] & 0xFF) / 255;
        }
        return ret;
    }

    public static byte[] toByte(double[] vec) {
        byte[] ret = new byte[vec.length];
        for (int i=0; i<vec.length; i++) {
            ret[i] = (byte)(vec[i] * 255);
        }
        return ret;
    }

    public static double[] readBMP(String path){
        return readBMP(new File(path));
    }

    public static double[] readBMP(File file){
        // read image
        BufferedImage img;
        try { 
            img = ImageIO.read(file); 
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        if (HEIGHT == 0 && WIDTH == 0) { // avoid multiple setting
            HEIGHT = img.getHeight();
            WIDTH  = img.getWidth();
        }
        // make sure it's grayscale (one byte per pixel)
        if(img.getType()!=BufferedImage.TYPE_BYTE_GRAY) {
            System.out.println("Converting to grayscale...");
            img = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_BYTE_GRAY);
        }

        // return array of pixels
        byte[] pixels = new byte[WIDTH*HEIGHT];
        img.getRaster().getDataElements(0,0,WIDTH,HEIGHT,pixels);
        return toDouble(pixels);
    }

    public static void writeBMP(double[] pixels, String path) {
{'fraction_non_alphanumeric': 0.13553558416322564, 'fraction_numerical': 0.008258440612096187, 'mean_word_length': 2.0617100371747212, 'pattern_counts': {'":': 0, '<': 11, '<?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': '183511', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1269, 'n_words': 313}