<commit_before>#include "filter.h"

static PyObject*
_round_corner_apply(PyObject *self, PyObject *args)
{
    PyObject *buffer = NULL, *a_radius_py = NULL, *b_radius_py = NULL, *width_py = NULL,
             *height_py = NULL, *r_py = NULL, *b_py = NULL, *g_py = NULL;

    if (!PyArg_UnpackTuple(args, "apply", 8, 8, &a_radius_py, &b_radius_py, 
            &r_py, &g_py, &b_py, &width_py, &height_py, &buffer)) {
        return NULL;
    }

    Py_ssize_t size = PyString_Size(buffer);
    int last_pixel = size - 3;
    unsigned char *ptr = (unsigned char *) PyString_AsString(buffer);
    int a_radius = (int) PyInt_AsLong(a_radius_py),
        b_radius = (int) PyInt_AsLong(b_radius_py),
        width = (int) PyInt_AsLong(width_py),
        height = (int) PyInt_AsLong(height_py);

    unsigned char r = (unsigned char) PyInt_AsLong(r_py),
                  g = (unsigned char) PyInt_AsLong(g_py),
                  b = (unsigned char) PyInt_AsLong(b_py);

    float a_rad = (float)a_radius, b_rad = (float)b_radius;
    float x, y;
    for (y = 0; y <= b_rad; y += 0.2f) {
        x = -(a_rad * sqrt((b_rad * b_rad) - (y * y))) / b_rad;

        int pixel_x = 0,
            pixel_y_top = b_rad - y,
            pixel_y_bottom = (height - b_rad) + y;
        int end_x = x + a_rad;

        for (; pixel_x <= end_x; ++pixel_x) {
            int pixel_top_left = 3 * ((pixel_y_top * width) + pixel_x),
                pixel_bottom_left = 3 * ((pixel_y_bottom * width) + pixel_x),
                pixel_top_right = 3 * ((pixel_y_top * width) + (width - pixel_x)),
                pixel_bottom_right = 3 * ((pixel_y_bottom * width) + (width - pixel_x));

            if (pixel_top_left > last_pixel) {
                pixel_top_left = last_pixel;
            }
            if (pixel_bottom_left > last_pixel) {
                pixel_bottom_left = last_pixel;
            }
            if (pixel_top_right > last_pixel) {
                pixel_top_right = last_pixel;
            }
            if (pixel_bottom_right > last_pixel) {
                pixel_bottom_right = last_pixel;
            }<commit_msg>Using fewer iterations as it still provides a good result.<commit_after>#include "filter.h"

static PyObject*
_round_corner_apply(PyObject *self, PyObject *args)
{
    PyObject *buffer = NULL, *a_radius_py = NULL, *b_radius_py = NULL, *width_py = NULL,
             *height_py = NULL, *r_py = NULL, *b_py = NULL, *g_py = NULL;

    if (!PyArg_UnpackTuple(args, "apply", 8, 8, &a_radius_py, &b_radius_py, 
            &r_py, &g_py, &b_py, &width_py, &height_py, &buffer)) {
        return NULL;
    }

    Py_ssize_t size = PyString_Size(buffer);
    int last_pixel = size - 3;
    unsigned char *ptr = (unsigned char *) PyString_AsString(buffer);
    int a_radius = (int) PyInt_AsLong(a_radius_py),
        b_radius = (int) PyInt_AsLong(b_radius_py),
        width = (int) PyInt_AsLong(width_py),
        height = (int) PyInt_AsLong(height_py);

    unsigned char r = (unsigned char) PyInt_AsLong(r_py),
                  g = (unsigned char) PyInt_AsLong(g_py),
                  b = (unsigned char) PyInt_AsLong(b_py);

    float a_rad = (float)a_radius, b_rad = (float)b_radius;
    float x, y;
    for (y = 0; y <= b_rad; y += 1.0f) {
        x = -(a_rad * sqrt((b_rad * b_rad) - (y * y))) / b_rad;

        int pixel_x = 0,
            pixel_y_top = b_rad - y,
            pixel_y_bottom = (height - b_rad) + y;
        int end_x = x + a_rad;

        for (; pixel_x <= end_x; ++pixel_x) {
            int pixel_top_left = 3 * ((pixel_y_top * width) + pixel_x),
                pixel_bottom_left = 3 * ((pixel_y_bottom * width) + pixel_x),
                pixel_top_right = 3 * ((pixel_y_top * width) + (width - pixel_x)),
                pixel_bottom_right = 3 * ((pixel_y_bottom * width) + (width - pixel_x));

            if (pixel_top_left > last_pixel) {
                pixel_top_left = last_pixel;
            }
            if (pixel_bottom_left > last_pixel) {
                pixel_bottom_left = last_pixel;
            }
            if (pixel_top_right > last_pixel) {
                pixel_top_right = last_pixel;
            }
            if (pixel_bottom_right > last_pixel) {
                pixel_bottom_right = last_pixel;
            }
{'fraction_non_alphanumeric': 0.11928755565971408, 'fraction_numerical': 0.005155847199437544, 'mean_word_length': 2.1405445180279616, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '4721583', 'n_tokens_mistral': 1539, 'n_tokens_neox': 1482, 'n_words': 335}