<commit_before>const Lagrange = require('../computation/lagrange');
const color = require('../util/color');

const lagrangeRgbMap = require('./rgb_map');

const applyInstagramFilter = (filterType, pix) => {
    const rgbMap = lagrangeRgbMap[filterType];
    const lagrangeRed = new Lagrange(0, 0, 1, 1);
    const lagrangeGreen = new Lagrange(0, 0, 1, 1);
    const lagrangeBlue = new Lagrange(0, 0, 1, 1);
    lagrangeRed.addMultiPoints(rgbMap.r);
    lagrangeGreen.addMultiPoints(rgbMap.g);
    lagrangeBlue.addMultiPoints(rgbMap.b);
    for (let i = 0, n = pix.length; i < n; i += 4) {
        pix[i] = lagrangeRed.valueOf(pix[i]);
        pix[i + 1] = lagrangeBlue.valueOf(pix[i + 1]);
        pix[i + 2] = lagrangeGreen.valueOf(pix[i + 2]);
    }
    return pix;
};

module.exports.enhance = (pix) => {
    const n = pix.length;
    for (let i = 0; i < n; i += 4) {
        pix[i] = pix[i] * 1.24;
        pix[i + 1] = pix[i + 1] * 1.33;
        pix[i + 2] = pix[i + 2] * 1.21;
    }
    return pix;
};
module.exports.grayscale = (pix) => {
    const n = pix.length;
    for (let i = 0; i < n; i += 4) {
        const r = pix[i];
        const g = pix[i + 1];
        const b = pix[i + 2];
        const grayscale = color.convertNTSC(r, g, b);
        pix[i] = grayscale;
        pix[i + 1] = grayscale;
        pix[i + 2] = grayscale;
    }
    return pix;
};
module.exports.sepia = (pix) => {
    const n = pix.length;
    for (let i = 0; i < n; i += 4) {
        pix[i] = pix[i] * 1.07;
        pix[i + 1] = pix[i + 1] * 0.74;
        pix[i + 2] = pix[i + 2] * 0.43;
    }
    return pix;
};
module.exports.luminance = (pix) => {
    const n = pix.length;
    for (let i = 0; i < n; i += 4) {
        const r = pix[i];
        const g = pix[i + 1];
        const b = pix[i + 2];
        const luminance = color.convertLuminanceLinearRGB(r, g, b);
        pix[i] = luminance;
        pix[i + 1] = luminance;
        pix[i + 2] = luminance;
    }
    return pix;
};
module.exports.negaposi = (pix) => {
    const n = pix.length;
    for (let i = 0; i < n; i += 4) {
        pix[i] = 255 - pix[i];
        pix[i + 1] = 255 - pix[i + 1];
        pix[i + 2] = 255 - pix[i + 2];
    }
    return pix;
};
module.exports.opacity = (pix, options) => {
    const val = options.value ? options.value : 0.5;
    for (let i = 0, n = pix.length; i < n; i += 4) {
        pix[i + 3] = pix[i + 3] * val;
    }
    return pix;
};
module.exports.brighten = (pix, options) => {
    const val = options.value ? options.value : 50;
    const n = pix.length;
    for (let i = 0; i < n; i += 4) {
        pix[i] += val;
        pix[i + 1] += val;
        pix[i + 2] += val;
    }
    return pix;
};
module.exports.darken = (pix, value = 50) => {
    const n = pix.length;
    for (let i = 0; i < n; i += 4) {
        pix[i] -= value;
        pix[i + 1] -= value;
        pix[i + 2] -= value;
    }
    return pix;
};
module.exports.threshold = (pix) => {
    const len = pix.length;
    for (let i = 0; i < len; i += 4) {
        const r = pix[i];
        const g = pix[i + 1];
        const b = pix[i + 2];
        const threshold = color.convertNTSC(r, g, b);
        const bw = color.blackOrWhite(r, g, b, threshold);
        pix[i] = bw;
        pix[i + 1] = bw;
        pix[i + 2] = bw;
    }
    return pix;
};
module.exports.hueRotate = (pix, deg = 45) => {<commit_msg>- Fix darken effect<commit_after>const Lagrange = require('../computation/lagrange');
const color = require('../util/color');

const lagrangeRgbMap = require('./rgb_map');

const applyInstagramFilter = (filterType, pix) => {
    const rgbMap = lagrangeRgbMap[filterType];
    const lagrangeRed = new Lagrange(0, 0, 1, 1);
    const lagrangeGreen = new Lagrange(0, 0, 1, 1);
    const lagrangeBlue = new Lagrange(0, 0, 1, 1);
    lagrangeRed.addMultiPoints(rgbMap.r);
    lagrangeGreen.addMultiPoints(rgbMap.g);
    lagrangeBlue.addMultiPoints(rgbMap.b);
    for (let i = 0, n = pix.length; i < n; i += 4) {
        pix[i] = lagrangeRed.valueOf(pix[i]);
        pix[i + 1] = lagrangeBlue.valueOf(pix[i + 1]);
        pix[i + 2] = lagrangeGreen.valueOf(pix[i + 2]);
    }
    return pix;
};

module.exports.enhance = (pix) => {
    const n = pix.length;
    for (let i = 0; i < n; i += 4) {
        pix[i] = pix[i] * 1.24;
        pix[i + 1] = pix[i + 1] * 1.33;
        pix[i + 2] = pix[i + 2] * 1.21;
    }
    return pix;
};
module.exports.grayscale = (pix) => {
    const n = pix.length;
    for (let i = 0; i < n; i += 4) {
        const r = pix[i];
        const g = pix[i + 1];
        const b = pix[i + 2];
        const grayscale = color.convertNTSC(r, g, b);
        pix[i] = grayscale;
        pix[i + 1] = grayscale;
        pix[i + 2] = grayscale;
    }
    return pix;
};
module.exports.sepia = (pix) => {
    const n = pix.length;
    for (let i = 0; i < n; i += 4) {
        pix[i] = pix[i] * 1.07;
        pix[i + 1] = pix[i + 1] * 0.74;
        pix[i + 2] = pix[i + 2] * 0.43;
    }
    return pix;
};
module.exports.luminance = (pix) => {
    const n = pix.length;
    for (let i = 0; i < n; i += 4) {
        const r = pix[i];
        const g = pix[i + 1];
        const b = pix[i + 2];
        const luminance = color.convertLuminanceLinearRGB(r, g, b);
        pix[i] = luminance;
        pix[i + 1] = luminance;
        pix[i + 2] = luminance;
    }
    return pix;
};
module.exports.negaposi = (pix) => {
    for (let i = 0, n = pix.length; i < n; i += 4) {
        pix[i] = 255 - pix[i];
        pix[i + 1] = 255 - pix[i + 1];
        pix[i + 2] = 255 - pix[i + 2];
    }
    return pix;
};
module.exports.opacity = (pix, options) => {
    const val = options.value ? options.value : 0.5;
    for (let i = 0, n = pix.length; i < n; i += 4) {
        pix[i + 3] = pix[i + 3] * val;
    }
    return pix;
};
module.exports.brighten = (pix, options) => {
    const val = options.value ? options.value : 50;
    for (let i = 0, n = pix.length; i < n; i += 4) {
        pix[i] += val;
        pix[i + 1] += val;
        pix[i + 2] += val;
    }
    return pix;
};
module.exports.darken = (pix, options) => {
    const val = options.value ? options.value : 50;
    for (let i = 0, n = pix.length; i < n; i += 4) {
        pix[i] -= val;
        pix[i + 1] -= val;
        pix[i + 2] -= val;
    }
    return pix;
};
module.exports.threshold = (pix) => {
    const len = pix.length;
    for (let i = 0; i < len; i += 4) {
        const r = pix[i];
        const g = pix[i + 1];
        const b = pix[i + 2];
        const threshold = color.convertNTSC(r, g, b);
        const bw = color.blackOrWhite(r, g, b, threshold);
        pix[i] = bw;
        pix[i + 1] = bw;
        pix[i + 2] = bw;
    }
    return pix;
};
module.exports.hueRotate = (pix, deg = 45) => {
{'fraction_non_alphanumeric': 0.18038866636997478, 'fraction_numerical': 0.029965880433170153, 'mean_word_length': 1.9466783216783217, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 25, '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': '4855820', 'n_tokens_mistral': 2939, 'n_tokens_neox': 2589, 'n_words': 708}