<commit_before>#include "sodna.h"
#include <SDL.h>

static SDL_Window* g_win = NULL;
static SDL_Renderer* g_rend = NULL;
static SDL_Texture* g_texture = NULL;
static Uint32* g_pixels = NULL;
static sodna_Cell* g_cells = NULL;

const int width = 640;
const int height = 400;

/* TODO support different fonts and font sizes. */
const int font_w = 8;
const int font_h = 16;
const uint8_t font[] = {
#include "font16.inc"
};

static inline int font_pixel(uint8_t symbol, int x, int y) {
    /* XXX: Only handles font_w == 8 for now. */
    return font[symbol * font_h + y] & (1 << (7 - x));
}

static inline void cell_to_argb(Uint32* out_fore, Uint32* out_back, sodna_Cell cell) {
    *out_fore = 0xff000000 | cell.fore_r << 20 | cell.fore_g << 12 | cell.fore_b << 4;
    *out_back = 0xff000000 | cell.back_r << 20 | cell.back_g << 12 | cell.back_b << 4;
}

int sodna_init() {
    if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
        return 1;

    g_win = SDL_CreateWindow(
            "", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
            width, height, SDL_WINDOW_SHOWN);
    if (!g_win)
        return 1;

    g_rend = SDL_CreateRenderer(g_win, -1,
            SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
<commit_msg>Maintain aspect when window is resized<commit_after>#include "sodna.h"
#include <SDL.h>

static SDL_Window* g_win = NULL;
static SDL_Renderer* g_rend = NULL;
static SDL_Texture* g_texture = NULL;
static Uint32* g_pixels = NULL;
static sodna_Cell* g_cells = NULL;

const int width = 640;
const int height = 400;

/* TODO support different fonts and font sizes. */
const int font_w = 8;
const int font_h = 16;
const uint8_t font[] = {
#include "font16.inc"
};

static inline int font_pixel(uint8_t symbol, int x, int y) {
    /* XXX: Only handles font_w == 8 for now. */
    return font[symbol * font_h + y] & (1 << (7 - x));
}

static inline void cell_to_argb(Uint32* out_fore, Uint32* out_back, sodna_Cell cell) {
    *out_fore = 0xff000000 | cell.fore_r << 20 | cell.fore_g << 12 | cell.fore_b << 4;
    *out_back = 0xff000000 | cell.back_r << 20 | cell.back_g << 12 | cell.back_b << 4;
}

int sodna_init() {
    if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
        return 1;

    g_win = SDL_CreateWindow(
            "", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
            width, height, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
    if (!g_win)
        return 1;

    g_rend = SDL_CreateRenderer(g_win, -1,
            SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
    SDL_RenderSetLogicalSize(g_rend, width, height);

{'fraction_non_alphanumeric': 0.11668611435239207, 'fraction_numerical': 0.038895371450797356, 'mean_word_length': 3.5043782837127844, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 5, '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': '2810892', 'n_tokens_mistral': 1085, 'n_tokens_neox': 963, 'n_words': 255}