<commit_before>/*
 * Copyright (c) 2011 <NAME> (http://www.incaseofstairs.com/)
 * See LICENSE for license information
 */
var ImageDataUtils;

(function() {
const DEFAULT_SNAP_SCAN_RANGE = 10;

function sign(a, b) {
    return (a > b) ? 1 : (a < b) ? -1 : 0;
}

function getPixelDelta(coord, endOffset, imageData) {
    var testOffset = ImageDataUtils.getOffset(coord, imageData),
        data = imageData.data;

    return Math.abs(data[endOffset]-data[testOffset])
            + Math.abs(data[endOffset+1]-data[testOffset+1])
            + Math.abs(data[endOffset+2]-data[testOffset+2])
            + Math.abs(data[endOffset+3]-data[testOffset+3]);
}

ImageDataUtils = {
    getCoords: function(offset, imageData) {
        var binWidth = imageData.width * 4;
        return {
            x: offset % binWidth,
            y: offset / binWidth | 0
        };
    },
    getOffset: function(coords, imageData) {
        return (coords.x + coords.y*imageData.width)*4;
    },
    getPixel: function(context, coord) {
        return context.getImageData(coord.x, coord.y, 1, 1).data;
    },
    getWindow: function getSnapToWindow(context, coord, windowSize) {
        var firstPixel = {x: Math.max(coord.x-windowSize, 0), y: Math.max(coord.y-windowSize, 0)};
        return {
            firstPixel: firstPixel,
            focusPixel: {x: coord.x-firstPixel.x, y: coord.y-firstPixel.y},
            imageData: context.getImageData(
                firstPixel.x,
                firstPixel.y,
                Math.min(2*windowSize, context.canvas.width-firstPixel.x),
                Math.min(2*windowSize, context.canvas.height-firstPixel.y))
        };
    },
    getLinePixels: function(context, coordStart, coordEnd) {
        // Extract the rectangle that contains our data
        var containingRect = LineUtils.containingRect(coordStart, coordEnd),
            image = context.getImageData(containingRect.x, containingRect.y, containingRect.width+1, containingRect.height+1),
            imageData = image.data;

        // Determine the properties of our line
        var len = LineUtils.distance(coordStart, coordEnd)|0;
        if (!len) {
            return;
        }

        // Create our destination image
        var line = context.createImageData(len, 1),
            lineData = line.data;

        LineUtils.walkLine(coordStart, coordEnd, function(t, coords) {
            var firstCoord = {x: Math.floor(coords.x), y: Math.floor(coords.y)},
                nextCoord = {x: Math.floor(coords.x), y: Math.ceil(coords.y)};<commit_msg>Handle differing behavior for getImageData for current mozilla browsers.<commit_after>/*
 * Copyright (c) 2011 <NAME> (http://www.incaseofstairs.com/)
 * See LICENSE for license information
 */
var ImageDataUtils;

(function() {
const DEFAULT_SNAP_SCAN_RANGE = 10;

function sign(a, b) {
    return (a > b) ? 1 : (a < b) ? -1 : 0;
}

function getPixelDelta(coord, endOffset, imageData) {
    var testOffset = ImageDataUtils.getOffset(coord, imageData),
        data = imageData.data;

    return Math.abs(data[endOffset]-data[testOffset])
            + Math.abs(data[endOffset+1]-data[testOffset+1])
            + Math.abs(data[endOffset+2]-data[testOffset+2])
            + Math.abs(data[endOffset+3]-data[testOffset+3]);
}

ImageDataUtils = {
    getCoords: function(offset, imageData) {
        var binWidth = imageData.width * 4;
        return {
            x: offset % binWidth,
            y: offset / binWidth | 0
        };
    },
    getOffset: function(coords, imageData) {
        return (coords.x + coords.y*imageData.width)*4;
    },
    getPixel: function(context, coord) {
        return context.getImageData(coord.x, coord.y, 1, 1).data;
    },
    getWindow: function getSnapToWindow(context, coord, windowSize) {
        var firstPixel = {x: Math.max(coord.x-windowSize, 0), y: Math.max(coord.y-windowSize, 0)};
        return {
            firstPixel: firstPixel,
            focusPixel: {x: coord.x-firstPixel.x, y: coord.y-firstPixel.y},
            imageData: context.getImageData(
                firstPixel.x,
                firstPixel.y,
                Math.min(2*windowSize, context.canvas.width-firstPixel.x),
                Math.min(2*windowSize, context.canvas.height-firstPixel.y))
        };
    },
    getLinePixels: function(context, coordStart, coordEnd) {
        // Extract the rectangle that contains our data
        var containingRect = LineUtils.containingRect(coordStart, coordEnd),
            image = context.getImageData(
                containingRect.x,
                containingRect.y,
                Math.min(containingRect.width+1, context.canvas.width-containingRect.x),     // Need to limit to image coords for Mozilla
                Math.min(containingRect.height+1, context.canvas.height-containingRect.y)),
            imageData = image.data;

        // Determine the properties of our line
        var len = LineUtils.distance(coordStart, coordEnd)|0;
        if (!len) {
            return;
        }

        // Create our destination image
        var line = context.createImageData(len, 1),
            lineData = line.data;

        LineUtils.walkLine(coordStart, coordEnd, function(t, coords) {
            var firstCoord = {x: Math.floor(coords.x), y: Math.floor(coords.y)},
                nextCoord = {x: Math.floor(coords.x), y: Math.ceil(coords.y)};
{'fraction_non_alphanumeric': 0.12411611462597692, 'fraction_numerical': 0.01042054335690361, 'mean_word_length': 2.4279336734693877, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4397371', 'n_tokens_mistral': 1690, 'n_tokens_neox': 1617, 'n_words': 342}