<commit_before>#!/usr/bin/env python

import os, sys, argparse
from pygments.formatters import terminal256
from PIL import Image, PngImagePlugin

def termify_pixels(img):
	sx, sy = img.size
	out = ''
	formatter = terminal256.Terminal256Formatter()
	def bgescape(color):
		r,g,b,a = color
		if color == (0,0,0,0):
			return terminal256.EscapeSequence(bg=formatter._closest_color(0,0,0)).reset_string()
		return terminal256.EscapeSequence(bg=formatter._closest_color(r,g,b)).color_string()
	def fgescape(color):
		r,g,b,_ = color
		return terminal256.EscapeSequence(fg=formatter._closest_color(r,g,b)).color_string()
	#NOTE: This ignores the last line if there is an odd number of lines.
	for y in range(0, sy-1, 2):
		for x in range(sx):
			coltop = img.getpixel((x, y))
			colbot = img.getpixel((x, y+1))
			if coltop[3] != 255:
				coltop = (0,0,0,0)
			if colbot[3] != 255:
				colbot = (0,0,0,0)
			c  = '▀'
			te = fgescape
			be = bgescape
			#Da magicks: ▀█▄<commit_msg>First optimization: Do not double-output color codes.<commit_after>#!/usr/bin/env python

import os, sys, argparse
from pygments.formatters import terminal256
from PIL import Image, PngImagePlugin

def termify_pixels(img):
	sx, sy = img.size
	out = ''
	formatter = terminal256.Terminal256Formatter()
	fg,bg = None,None
	def bgescape(color):
		nonlocal bg
		if bg == color:
			return ''
		bg=color
		r,g,b,a = color
		if color == (0,0,0,0):
			return terminal256.EscapeSequence(bg=formatter._closest_color(0,0,0)).reset_string()
		return terminal256.EscapeSequence(bg=formatter._closest_color(r,g,b)).color_string()
	def fgescape(color):
		nonlocal fg
		if fg == color:
			return ''
		fg=color
		r,g,b,_ = color
		return terminal256.EscapeSequence(fg=formatter._closest_color(r,g,b)).color_string()
	#NOTE: This ignores the last line if there is an odd number of lines.
	for y in range(0, sy-1, 2):
		for x in range(sx):
			coltop = img.getpixel((x, y))
			colbot = img.getpixel((x, y+1))
			if coltop[3] != 255:
				coltop = (0,0,0,0)
			if colbot[3] != 255:
				colbot = (0,0,0,0)
			c  = '▀'
			te = fgescape
			be = bgescape
			#Da magicks: ▀█▄
{'fraction_non_alphanumeric': 0.14319359397079603, 'fraction_numerical': 0.04239284032030146, 'mean_word_length': 4.193154034229829, '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': '7606684', 'n_tokens_mistral': 957, 'n_tokens_neox': 832, 'n_words': 199}