<commit_before>#include <stdint.h>
#include <stddef.h>

#include "effects.h"

static inline
uint8_t scale_color(uint8_t color, uint8_t scale) {
	return ((int)color * (int)(scale)) >> 9;
}

static
void antialias_treads(struct render_args* args) {
	int i;
	int j;
	int cycle;
	int num_pixels = args->framelen/3;

	for (i = 0; i < num_pixels; i++) {
		char* pixel = &args->framebuf[i*3];
		union color color = args->effect->color_arg.color;
		get_cycle(args, i, &j, &cycle);

		if (cycle == 9) {         // leading edge
			pixel[0] = 0x80 | scale_color(color.rgb.green, args->shift_remainder);
			pixel[1] = 0x80 | scale_color(color.rgb.red,   args->shift_remainder);
			pixel[2] = 0x80 | scale_color(color.rgb.blue,  args->shift_remainder);
		} else if (cycle == 14) { // trailing edge
			pixel[0] = 0x80 | scale_color(color.rgb.green, 0xff - args->shift_remainder);
			pixel[1] = 0x80 | scale_color(color.rgb.red,   0xff - args->shift_remainder);
			pixel[2] = 0x80 | scale_color(color.rgb.blue,  0xff - args->shift_remainder);
		} else if (cycle >= 10) { // middle
			pixel[0] = 0x80 | color.rgb.green;
			pixel[1] = 0x80 | color.rgb.red;
			pixel[2] = 0x80 | color.rgb.blue;
		} else {
			pixel[0] = 0x80;
			pixel[1] = 0x80;
			pixel[2] = 0x80;
		}
	}
}

static
void rolling_rainbow_treads(struct render_args* args) {
	int i;
	int j;
	int cycle;
	int num_pixels = args->framelen/3;

	for (i = 0; i < num_pixels; i++) {
		int k;
		char* pixel = &args->framebuf[i*3];

		get_cycle(args, i, &j, &cycle);

		k = j * args->framelen / RAINBOW_LENGTH;

		if (cycle == 9) {         // left edge
			pixel[0] = 0x80 | scale_color(RAINBOW_G(k), args->shift_remainder);
			pixel[1] = 0x80 | scale_color(RAINBOW_R(k), args->shift_remainder);
			pixel[2] = 0x80 | scale_color(RAINBOW_B(k), args->shift_remainder);
		} else if (cycle == 14) { // right edge
			pixel[0] = 0x80 | scale_color(RAINBOW_G(k), 0xff - args->shift_remainder);
			pixel[1] = 0x80 | scale_color(RAINBOW_R(k), 0xff - args->shift_remainder);
			pixel[2] = 0x80 | scale_color(RAINBOW_B(k), 0xff - args->shift_remainder);
		} else if (cycle >= 10) { // middle
			pixel[0] = 0x80 | RAINBOW_G(k) >> 1;
			pixel[1] = 0x80 | RAINBOW_R(k) >> 1;
			pixel[2] = 0x80 | RAINBOW_B(k) >> 1;
		} else {
			pixel[0] = 0x80;<commit_msg>Fix rainbow scaling<commit_after>#include <stdint.h>
#include <stddef.h>

#include "effects.h"

static inline
uint8_t scale_color(uint8_t color, uint8_t scale) {
	return ((int)color * (int)(scale)) >> 9;
}

static
void antialias_treads(struct render_args* args) {
	int i;
	int j;
	int cycle;
	int num_pixels = args->framelen/3;

	for (i = 0; i < num_pixels; i++) {
		char* pixel = &args->framebuf[i*3];
		union color color = args->effect->color_arg.color;
		get_cycle(args, i, &j, &cycle);

		if (cycle == 9) {         // leading edge
			pixel[0] = 0x80 | scale_color(color.rgb.green, args->shift_remainder);
			pixel[1] = 0x80 | scale_color(color.rgb.red,   args->shift_remainder);
			pixel[2] = 0x80 | scale_color(color.rgb.blue,  args->shift_remainder);
		} else if (cycle == 14) { // trailing edge
			pixel[0] = 0x80 | scale_color(color.rgb.green, 0xff - args->shift_remainder);
			pixel[1] = 0x80 | scale_color(color.rgb.red,   0xff - args->shift_remainder);
			pixel[2] = 0x80 | scale_color(color.rgb.blue,  0xff - args->shift_remainder);
		} else if (cycle >= 10) { // middle
			pixel[0] = 0x80 | color.rgb.green;
			pixel[1] = 0x80 | color.rgb.red;
			pixel[2] = 0x80 | color.rgb.blue;
		} else {
			pixel[0] = 0x80;
			pixel[1] = 0x80;
			pixel[2] = 0x80;
		}
	}
}

static
void rolling_rainbow_treads(struct render_args* args) {
	int i;
	int j;
	int cycle;
	int num_pixels = args->framelen/3;

	for (i = 0, j = 0; i < num_pixels; i++, j += 3) {
		int k;
		char* pixel = &args->framebuf[j];
		get_cycle(args, i, &k, &cycle);
		int c = k * RAINBOW_LENGTH / num_pixels;

		if (cycle == 9) {         // left edge
			pixel[0] = 0x80 | scale_color(RAINBOW_G(c), args->shift_remainder);
			pixel[1] = 0x80 | scale_color(RAINBOW_R(c), args->shift_remainder);
			pixel[2] = 0x80 | scale_color(RAINBOW_B(c), args->shift_remainder);
		} else if (cycle == 14) { // right edge
			pixel[0] = 0x80 | scale_color(RAINBOW_G(c), 0xff - args->shift_remainder);
			pixel[1] = 0x80 | scale_color(RAINBOW_R(c), 0xff - args->shift_remainder);
			pixel[2] = 0x80 | scale_color(RAINBOW_B(c), 0xff - args->shift_remainder);
		} else if (cycle >= 10) { // middle
			pixel[0] = 0x80 | RAINBOW_G(c) >> 1;
			pixel[1] = 0x80 | RAINBOW_R(c) >> 1;
			pixel[2] = 0x80 | RAINBOW_B(c) >> 1;
		} else {
			pixel[0] = 0x80;
{'fraction_non_alphanumeric': 0.17056636781106493, 'fraction_numerical': 0.05138858517384649, 'mean_word_length': 3.551243781094527, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 64, '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': '7284982', 'n_tokens_mistral': 2221, 'n_tokens_neox': 1949, 'n_words': 402}