<commit_before>package net.djpowell.nioimage;

import java.awt.image.ColorModel;
import java.awt.image.Raster;

/**
 * Bi-level monochrome color model.
 *
 * @author <NAME>
 * @since 23-Mar-2010
 */
public class DirectMonoColorModel extends ColorModel {

    /**
     * Construct a bi-level monochrome color model.
     */
    public DirectMonoColorModel() {
        super(8);
    }

    @Override
    public int getComponentSize(int componentIdx) {
        return 8;
    }

    @Override
    public int[] getComponentSize() {
        return new int[] {8};
    }

    @Override
    public int getPixelSize() {
        return 8;
    }

    @Override
    public int getRed(int pixel) {
        return (pixel & 0x000000ff) / 32 * 11;
    }

    @Override
    public int getRed(Object inData) {
        byte[] data = (byte[])inData;
        return (data[0] & 0xff) / 32 * 11;
    }

    @Override
    public int getGreen(int pixel) {
        return (pixel & 0x000000ff) / 32 * 16;
    }

    @Override
    public int getGreen(Object inData) {
        byte[] data = (byte[])inData;
        return (data[0] & 0xff) / 32 * 16;
    }

    @Override
    public int getBlue(int pixel) {
        return (pixel & 0x000000ff) / 32 * 5;
    }

    @Override
    public int getBlue(Object inData) {
        byte[] data = (byte[])inData;
        return (data[0] & 0xff) / 32 * 11;
    }

    @Override
    public int getAlpha(int pixel) {
        return 0;
    }

    @Override
    public int getAlpha(Object inData) {
        return 0;
    }

    @Override
    public boolean isCompatibleRaster(Raster raster) {
        return (raster instanceof NioWritableRaster &&
                ((NioWritableRaster)raster).getImageClass().isAssignableFrom(NioMonoImage.class));
    }

    @Override
    public Object getDataElements(int rgb, Object pixel) {
        byte a[] = (byte[])pixel;
        if (a == null) {
            a = new byte[1];
        }
        // ignore alpha, simple threshold conversion
        int grey = ( 11 * (getRed(rgb) & 0xff) +
                16 * (getGreen(rgb) & 0xff) +
                5 * (getBlue(rgb) & 0xff) ) / 32;
        a[0] = (byte)(grey & 0xff);
        return a;
    }

}<commit_msg>Simplified greyscale color model to fix problems with G15. Just use Color.black and Color.white in your code and you should be ok.<commit_after>package net.djpowell.nioimage;

import java.awt.image.ColorModel;
import java.awt.image.Raster;

/**
 * Bi-level monochrome color model.
 *
 * @author <NAME>
 * @since 23-Mar-2010
 */
public class DirectMonoColorModel extends ColorModel {

    /**
     * Construct a bi-level monochrome color model.
     */
    public DirectMonoColorModel() {
        super(8);
    }

    @Override
    public int getComponentSize(int componentIdx) {
        return 8;
    }

    @Override
    public int[] getComponentSize() {
        return new int[] {8};
    }

    @Override
    public int getPixelSize() {
        return 8;
    }

    @Override
    public int getRed(int pixel) {
        return pixel & 0xff;
    }

    @Override
    public int getRed(Object inData) {
        byte[] data = (byte[])inData;
        return data[0] & 0xff;
    }

    @Override
    public int getGreen(int pixel) {
        return pixel & 0xff;
    }

    @Override
    public int getGreen(Object inData) {
        byte[] data = (byte[])inData;
        return data[0] & 0xff;
    }

    @Override
    public int getBlue(int pixel) {
        return pixel & 0xff;
    }

    @Override
    public int getBlue(Object inData) {
        byte[] data = (byte[])inData;
        return data[0] & 0xff;
    }

    @Override
    public int getAlpha(int pixel) {
        return 0;
    }

    @Override
    public int getAlpha(Object inData) {
        return 0;
    }

    @Override
    public boolean isCompatibleRaster(Raster raster) {
        return (raster instanceof NioWritableRaster &&
                ((NioWritableRaster)raster).getImageClass().isAssignableFrom(NioMonoImage.class));
    }

    @Override
    public Object getDataElements(int rgb, Object pixel) {
        byte a[] = (byte[])pixel;
        if (a == null) {
            a = new byte[1];
        }
        // ignore alpha, simple threshold conversion
        int grey = ( 11 * (getRed(rgb) & 0xff) +
                16 * (getGreen(rgb) & 0xff) +
                5 * (getBlue(rgb) & 0xff) ) / 32;
        a[0] = (byte)(grey & 0xff);
        return a;
    }

}
{'fraction_non_alphanumeric': 0.10938175529615218, 'fraction_numerical': 0.023994811932555125, 'mean_word_length': 1.7873493975903614, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6957393', 'n_tokens_mistral': 1576, 'n_tokens_neox': 1384, 'n_words': 369}