<commit_before>
/* appchoo - Application Chooser with Timeout
 * (c) 2012 <NAME> <<EMAIL>>
 * written from scratch, public domain
 */

#include <math.h>
#include <SDL.h>
#include <SDL_image.h>

int fit_image(SDL_Surface *image, int w, int h)
{
	if (!image)
		return 0;
	if (image->format->BytesPerPixel != 3)
		return 0;
	if (w >= image->w && h >= image->h)
		return 1;
	int f = 0;
	do f++; while (image->w / f > w || image->h / f > h);
	w = image->w;
	h = image->h;
	image->clip_rect.w = image->w /= f;
	image->clip_rect.h = image->h /= f;
	image->pitch = image->w * 3;
	uint8_t *pixels = image->pixels;
	for (int y = 0; y < image->h; y++) {
		for (int x = 0; x < image->w; x++) {
			uint32_t s[3] = {0, 0, 0};
			for (int j = 0; j < f; j++)
				for (int i = 0; i < f; i++)
					for (int c = 0; c < 3; c++)
						 s[c] += pixels[((y*f + j) * w + x*f + i) * 3 + c];
			for (int c = 0; c < 3; c++)
				pixels[(y * image->w + x) * 3 + c] = s[c] / (f*f);
		}
	}
	return 1;
}

void handle_events()
{
	SDL_Event event;
	while (SDL_PollEvent(&event)) {
		switch (event.type) {
			case SDL_KEYDOWN:
				switch (event.key.keysym.sym) {
					case SDLK_q:
						exit(0);
						break;
					case SDLK_ESCAPE:
						exit(0);
						break;
					default:
						break;
				}
				break;<commit_msg>use image->pitch to align lines to 4 bytes<commit_after>
/* appchoo - Application Chooser with Timeout
 * (c) 2012 <NAME> <<EMAIL>>
 * written from scratch, public domain
 */

#include <math.h>
#include <SDL.h>
#include <SDL_image.h>

int fit_image(SDL_Surface *image, int w, int h)
{
	if (!image)
		return 0;
	if (image->format->BytesPerPixel != 3)
		return 0;
	if (w >= image->w && h >= image->h)
		return 1;
	int f = 0;
	do f++; while (image->w / f > w || image->h / f > h);
	w = image->w;
	h = image->h;
	int pitch = image->pitch;
	image->clip_rect.w = image->w /= f;
	image->clip_rect.h = image->h /= f;
	image->pitch = (image->w * 3 + 3) & (~3);
	uint8_t *pixels = image->pixels;
	for (int y = 0; y < image->h; y++) {
		for (int x = 0; x < image->w; x++) {
			uint32_t s[3] = {0, 0, 0};
			for (int j = 0; j < f; j++)
				for (int i = 0; i < f; i++)
					for (int c = 0; c < 3; c++)
						 s[c] += pixels[(y*f+j) * pitch + (x*f+i) * 3 + c];
			for (int c = 0; c < 3; c++)
				pixels[y * image->pitch + x * 3 + c] = s[c] / (f*f);
		}
	}
	return 1;
}

void handle_events()
{
	SDL_Event event;
	while (SDL_PollEvent(&event)) {
		switch (event.type) {
			case SDL_KEYDOWN:
				switch (event.key.keysym.sym) {
					case SDLK_q:
						exit(0);
						break;
					case SDLK_ESCAPE:
						exit(0);
						break;
					default:
						break;
				}
				break;
{'fraction_non_alphanumeric': 0.19954389965792474, 'fraction_numerical': 0.02394526795895097, 'mean_word_length': 2.422626788036411, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 61, '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': '5639339', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1118, 'n_words': 327}