<commit_before>package edu.cmu.cs.diamond.opendiamond;

import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;

public class Util {
    private Util() {
    }

    // XXX endian specific
    public static int extractInt(byte[] value) {
        return (value[3] & 0xFF) << 24 | (value[2] & 0xFF) << 16
                | (value[1] & 0xFF) << 8 | (value[0] & 0xFF);
    }

    public static long extractLong(byte[] value) {
        return ((long) (value[7] & 0xFF) << 56)
                | ((long) (value[6] & 0xFF) << 48)
                | ((long) (value[5] & 0xFF) << 40)
                | ((long) (value[4] & 0xFF) << 32)
                | ((long) (value[3] & 0xFF) << 24)
                | ((long) (value[2] & 0xFF) << 16)
                | ((long) (value[1] & 0xFF) << 8) | (value[0] & 0xFF);
    }

    public static double extractDouble(byte[] value) {
        return Double.longBitsToDouble(extractLong(value));
    }

    public static BufferedImage possiblyShrinkImage(BufferedImage img,
            int maxW, int maxH) {
        int h = img.getHeight(null);
        int w = img.getWidth(null);
    
        double scale = 1.0;
        
        // XXX probably not quite right?
        double maxAspect = (double) maxW / maxH;
        double aspect = (double) w / h;
        if (aspect > maxAspect) {
            // more wide
            if (w > maxW) {
                scale = (double) maxW / h;
            }
        } else {
            // more tall
            if (h > maxH) {
                scale = (double) maxH / h;
            }
        }
    
        if (scale == 1.0) {
            return img;
        } else {
            BufferedImage newI = new BufferedImage((int) (w * scale),
                    (int) (h * scale), img.getType());
    
            Graphics2D g = newI.createGraphics();
            g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                    RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            g.scale(scale, scale);
            g.drawImage(img, 0, 0, null);
            g.dispose();
    
            return newI;
        }
    }<commit_msg>fix stupid bug<commit_after>package edu.cmu.cs.diamond.opendiamond;

import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;

public class Util {
    private Util() {
    }

    // XXX endian specific
    public static int extractInt(byte[] value) {
        return (value[3] & 0xFF) << 24 | (value[2] & 0xFF) << 16
                | (value[1] & 0xFF) << 8 | (value[0] & 0xFF);
    }

    public static long extractLong(byte[] value) {
        return ((long) (value[7] & 0xFF) << 56)
                | ((long) (value[6] & 0xFF) << 48)
                | ((long) (value[5] & 0xFF) << 40)
                | ((long) (value[4] & 0xFF) << 32)
                | ((long) (value[3] & 0xFF) << 24)
                | ((long) (value[2] & 0xFF) << 16)
                | ((long) (value[1] & 0xFF) << 8) | (value[0] & 0xFF);
    }

    public static double extractDouble(byte[] value) {
        return Double.longBitsToDouble(extractLong(value));
    }

    public static BufferedImage possiblyShrinkImage(BufferedImage img,
            int maxW, int maxH) {
        int h = img.getHeight(null);
        int w = img.getWidth(null);
    
        double scale = 1.0;
        
        double imgAspect = (double) w / h;
        double targetAspect = (double) maxW / maxH;

        if (imgAspect > targetAspect) {
            // more wide
            if (w > maxW) {
                scale = (double) maxW / w;
            }
        } else {
            // more tall
            if (h > maxH) {
                scale = (double) maxH / h;
            }
        }
    
        if (scale == 1.0) {
            return img;
        } else {
            BufferedImage newI = new BufferedImage((int) (w * scale),
                    (int) (h * scale), img.getType());
    
            Graphics2D g = newI.createGraphics();
            g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                    RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            g.scale(scale, scale);
            g.drawImage(img, 0, 0, null);
            g.dispose();
    
            return newI;
        }
    }
{'fraction_non_alphanumeric': 0.13560517038777908, 'fraction_numerical': 0.023501762632197415, 'mean_word_length': 1.5607701564380265, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 9, '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': '1205695', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1331, 'n_words': 319}