<commit_before>Png = require('pngjs').PNG
fs = require 'fs'

module.exports = class WalkabilityImageCompiler
    brunchPlugin: yes
    type: 'javascript'

    processImage: (path, callback) ->
        # reading in again since framework always reads w/ utf-8
        fs.createReadStream(path)
            .pipe(new Png {filterType: 4})
            .on 'parsed', () ->
                output = 'return [\n'
                mapCell =
                    walkable: 0
                    unwalkable: 1
                    door: 2
                pixelToWalkabilityMap =
                    '255255255': mapCell.walkable
                    '000': mapCell.unwalkable
                    '25500': mapCell.door

                getPixelString = (x, y) =>
                    idx = (this.width * y + x) << 2
                    pixelString = '' + this.data[idx] + this.data[idx + 1] +
                        this.data[idx + 2]
                    if pixelString not of pixelToWalkabilityMap
                        callback 'failed to extract pixel: ' + pixelString
                        return
                    return pixelToWalkabilityMap[pixelString]

                for y in [0 ... this.height]
                    output += '    '
                    for x in [0 ... this.width]
                        pixelString = getPixelString x, y
                        output += pixelString
                        if not (y == this.height - 1 and x == this.width - 1)
                            output += ', '
                    output += '\n'
                output += ']'

                callback null, {data: output}

    constructor: (@config) ->
        @pattern = @config.plugins?.walkabilityImages?.pattern ?<commit_msg>Export image dimensions along with contents<commit_after>Png = require('pngjs').PNG
fs = require 'fs'

module.exports = class WalkabilityImageCompiler
    brunchPlugin: yes
    type: 'javascript'

    processImage: (path, callback) ->
        # reading in again since framework always reads w/ utf-8
        fs.createReadStream(path)
            .pipe(new Png {filterType: 4})
            .on 'parsed', () ->
                output = 'exports.width = ' + this.width + ';\n'
                output += 'exports.height = ' + this.height + ';\n'

                output += 'exports.contents = [\n'
                mapCell =
                    walkable: 0
                    unwalkable: 1
                    door: 2
                pixelToWalkabilityMap =
                    '255255255': mapCell.walkable
                    '000': mapCell.unwalkable
                    '25500': mapCell.door

                getPixelString = (x, y) =>
                    idx = (this.width * y + x) << 2
                    pixelString = '' + this.data[idx] + this.data[idx + 1] +
                        this.data[idx + 2]
                    if pixelString not of pixelToWalkabilityMap
                        callback 'failed to extract pixel: ' + pixelString
                        return
                    return pixelToWalkabilityMap[pixelString]

                for y in [0 ... this.height]
                    output += '    '
                    for x in [0 ... this.width]
                        pixelString = getPixelString x, y
                        output += pixelString
                        if not (y == this.height - 1 and x == this.width - 1)
                            output += ', '
                    output += '\n'

                output += ']'

                callback null, {data: output}

    constructor: (@config) ->
        @pattern = @config.plugins?.walkabilityImages?.pattern ?
{'fraction_non_alphanumeric': 0.09972451790633609, 'fraction_numerical': 0.015977961432506887, 'mean_word_length': 1.1561757719714965, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '4071597', 'n_tokens_mistral': 965, 'n_tokens_neox': 858, 'n_words': 241}