<commit_before>#!/usr/bin/env python
"""
Miscellaneous Routines.
"""
import struct
from sys import maxint as INF


##  PNG Predictor
##
def apply_png_predictor(pred, colors, columns, bitspercomponent, data):
    if bitspercomponent != 8:
        # unsupported
        raise ValueError(bitspercomponent)
    nbytes = colors*columns*bitspercomponent//8
    i = 0
    buf = b''
    line0 = b'\x00' * columns
    for i in xrange(0, len(data), nbytes+1):
        ft = data[i]
        i += 1
        line1 = data[i:i+nbytes]
        line2 = b''
        if ft == b'\x00':
            # PNG none
            line2 += line1
        elif ft == b'\x01':
            # PNG sub (UNTESTED)
            c = 0
            for b in line1:
                c = (c+ord(b)) & 255
                line2 += chr(c)
        elif ft == b'\x02':
            # PNG up
            for (a, b) in zip(line0, line1):
                c = (ord(a)+ord(b)) & 255
                line2 += chr(c)
        elif ft == b'\x03':
            # PNG average (UNTESTED)
            c = 0
            for (a, b) in zip(line0, line1):
                c = ((c+ord(a)+ord(b))//2) & 255
                line2 += chr(c)
        else:
            # unsupported
            raise ValueError(ft)
        buf += line2<commit_msg>make ValueError's descriptive<commit_after>#!/usr/bin/env python
"""
Miscellaneous Routines.
"""
import struct
from sys import maxint as INF


##  PNG Predictor
##
def apply_png_predictor(pred, colors, columns, bitspercomponent, data):
    if bitspercomponent != 8:
        # unsupported
        raise ValueError("Unsupported `bitspercomponent': %d"%bitspercomponent)
    nbytes = colors*columns*bitspercomponent//8
    i = 0
    buf = b''
    line0 = b'\x00' * columns
    for i in xrange(0, len(data), nbytes+1):
        ft = data[i]
        i += 1
        line1 = data[i:i+nbytes]
        line2 = b''
        if ft == b'\x00':
            # PNG none
            line2 += line1
        elif ft == b'\x01':
            # PNG sub (UNTESTED)
            c = 0
            for b in line1:
                c = (c+ord(b)) & 255
                line2 += chr(c)
        elif ft == b'\x02':
            # PNG up
            for (a, b) in zip(line0, line1):
                c = (ord(a)+ord(b)) & 255
                line2 += chr(c)
        elif ft == b'\x03':
            # PNG average (UNTESTED)
            c = 0
            for (a, b) in zip(line0, line1):
                c = ((c+ord(a)+ord(b))//2) & 255
                line2 += chr(c)
        else:
            # unsupported
            raise ValueError("Unsupported predictor value: %d"%ft)
        buf += line2
{'fraction_non_alphanumeric': 0.13102924420812762, 'fraction_numerical': 0.03190277250284846, 'mean_word_length': 1.4849056603773585, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '609579', 'n_tokens_mistral': 912, 'n_tokens_neox': 844, 'n_words': 234}