<commit_before>#include "pixel_functions.h"
#include <math.h>
#include <string.h>
#include <stdlib.h>

Pixel* create_pixel(unsigned char r, unsigned char g, unsigned char b, unsigned char a) {
	Pixel* temp = ( Pixel* ) malloc( sizeof(Pixel) );
	temp->red = r;
	temp->green = g;
	temp->blue = b;
	temp->alpha = a;
	
	return temp;	
}	

void black_and_white(Pixel *p) {
	double average =( (double) (p->red + p->blue + p->green) )/3;
	unsigned char rounded_average = round( average );
	p->red = p->blue = p->green = average;
}

void overlay(Pixel *a, Pixel *b) {
	Pixel temp;

	temp.red =   calculate_color(a->red, b->red, a->alpha, b->alpha);
	temp.blue =  calculate_color(a->blue, b->blue, a->alpha, b->alpha);
	temp.green = calculate_color(a->green, b->green, a->alpha, b->alpha);
	temp.alpha = (unsigned char) round( (double) b->alpha + a->alpha * (255- b->alpha) / 255 );

	*a = temp;
}

unsigned char calculate_color(unsigned char r1, unsigned char r2, unsigned char a1, unsigned char a2) {
	double double_r2 = (double) r2; /* force double division in calculation */

	return (unsigned char) round( (double_r2 * a2)/255 + a1 * (255 - a2) * r1 / 255 / 255 );
}

void color_shift(Pixel *p, char* pattern) {<commit_msg>(hopefully) optimized calculate_color<commit_after>#include "pixel_functions.h"
#include <math.h>
#include <string.h>
#include <stdlib.h>

Pixel* create_pixel(unsigned char r, unsigned char g, unsigned char b, unsigned char a) {
	Pixel* temp = ( Pixel* ) malloc( sizeof(Pixel) );
	temp->red = r;
	temp->green = g;
	temp->blue = b;
	temp->alpha = a;
	
	return temp;	
}	

void black_and_white(Pixel *p) {
	double average =( (double) (p->red + p->blue + p->green) )/3;
	unsigned char rounded_average = round( average );
	p->red = p->blue = p->green = average;
}

void overlay(Pixel *a, Pixel *b) {
	Pixel temp;

	temp.red =   calculate_color(a->red, b->red, a->alpha, b->alpha);
	temp.blue =  calculate_color(a->blue, b->blue, a->alpha, b->alpha);
	temp.green = calculate_color(a->green, b->green, a->alpha, b->alpha);
	temp.alpha = (unsigned char) round( (double) b->alpha + a->alpha * (255- b->alpha) / 255 );

	*a = temp;
}

unsigned char calculate_color(unsigned char r1, unsigned char r2, unsigned char a1, unsigned char a2) {
	double d_a2 = (double) a2; /* force double division in calculation */
	
	return (unsigned char) round( (d_a2 * r2 /255) + a1(255-d_a2)r1 / (255* 255));
}

void color_shift(Pixel *p, char* pattern) {
{'fraction_non_alphanumeric': 0.17089125102207686, 'fraction_numerical': 0.024529844644317254, 'mean_word_length': 3.9938775510204083, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 59, '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': '870375', 'n_tokens_mistral': 943, 'n_tokens_neox': 892, 'n_words': 258}