/* This file was generated by scramble.py. */
#line 1 "src/rgba.py"
#include "rgba.h"
#line 13
State state;
static State pushed [8];
static int pushed_i;
#line 17
void rgba_push(void) {
    pushed [pushed_i++] = state;
}
void rgba_pop(void) {
    state = pushed [--pushed_i];
}
float rgba_get(float * bumpmap, int x, int y, int w, int h) {
    return bumpmap [imod(x, w) + w * imod(y, h)];
}
void rgba_color(float r, float g, float b, uint8_t * p) {
    p [0] = rgba_C(r);
    p [1] = rgba_C(g);
    p [2] = rgba_C(b);
    p [3] = 255;
}
uint8_t * rgba_p(uint8_t * p, int x, int y, int w) {
    return p + (y * w + x) * 4;
}
void rgba_coloradd(float r, float g, float b, uint8_t * p) {
    r += p [0] / 255.0;
    p [0] = rgba_C(r);
    g += p [1] / 255.0;
    p [1] = rgba_C(g);
    b += p [2] / 255.0;
    p [2] = rgba_C(b);
}
void rgba_colormul(float r, float g, float b, uint8_t * p) {
    r *= p [0] / 255.0;
    p [0] = rgba_C(r);
    g *= p [1] / 255.0;
    p [1] = rgba_C(g);
    b *= p [2] / 255.0;
    p [2] = rgba_C(b);
}
void rgba_alpha(float a, uint8_t * p) {
    float r = a * p [0] / 255.0;
    p [0] = rgba_C(r);
    float g = a * p [1] / 255.0;
    p [1] = rgba_C(g);
    float b = a * p [2] / 255.0;
    p [2] = rgba_C(b);
    p [3] = rgba_C(a);
}
void rgba_start(uint8_t * p, int l, int h) {
    state.p = p;
    state.l = l;
    state.h = h;
    state.scale = 1;
    state.x = 0;
    state.y = 0;
}
void rgba_putpixel(void) {
    if (state.x < 0 || state.y < 0) {
#line 69
        return ;
    }
#line 70
    if (state.x >= state.l || state.y >= state.h) {
#line 70
        return ;
    }
#line 71
    uint8_t * p = rgba_p(state.p, state.x, state.y, state.l);
    p [0] = state.r;
    p [1] = state.g;
    p [2] = state.b;
    p [3] = state.a;
}
void rgba_fill(int wi, int lx, int rx, int hi) {
    if (hi == 0) {
#line 78
        return ;
    }
#line 79
    int ox = state.x;
    int oy = state.y;
    if (hi < 0) {
        hi = - hi;
        state.y -= hi;
    }
#line 84
    int y2 = state.y + hi - 1;
    float wl = lx;
    float wr = rx;
    float h = hi;
    float gl = wl / h;
    float gr = wr / h;
    float xl = ox + 0.5;
    float xr = ox + wi - 1 + 0.5;
    rgba_hline(wi);
    while (state.y != y2) {
        state.y++;
        xl += gl;
        xr += gr;
        rgba_moveto(floor(xl), state.y);
        rgba_hline(floor(xr) - floor(xl) + 1);
    }
#line 99
    state.x = ox;
    state.y = oy;
}
void rgba_moveto(int x, int y) {
    state.x = x;
    state.y = y;
}
void rgba_scale(float s) {
    state.scale = s;
}
void rgba_moverel(int x, int y) {
    state.x += x;
    state.y += y;
}
void rgba_setcolor(float r, float g, float b) {
    state.r = rgba_C(r);
    state.g = rgba_C(g);
    state.b = rgba_C(b);
    state.a = 255;
}
void rgba_lineto(int x, int y) {
    /* 0 1 2 3
     * 0 x x
     * 1     x x
     * 2
     * 3
     */
#line 127
    float w = x - state.x;
    float h = y - state.y;
    if (fabs(w) > fabs(h)) {
        float g = h / fabs(w);
        float yp = state.y + 0.5;
        int d = state.x > x ? - 1 : 1;
        while (state.x != x) {
            state.x += d;
            yp += g;
            state.y = floor(yp);
            rgba_putpixel();
        }
    }
#line 137
    else {
#line 139
        float g = w / fabs(h);
        float xp = state.x + 0.5;
        int d = state.y > y ? - 1 : 1;
        while (state.y != y) {
            state.y += d;
            xp += g;
            state.x = floor(xp);
            rgba_putpixel();
        }
    }
}
#line 148
void rgba_hline(int w) {
    if (state.y >= state.h) {
#line 149
        return ;
    }
    for (int i = 0; i < w; i += 1) {
        rgba_putpixel();
        rgba_moverel(1, 0);
    }
}
#line 155
void rgba_circle(int w, int h) {
    /* w = 4
     * cx = 2
     * ww = 4
     * i = 0 -> x = -1.5
     * i = 1 -> x = -0.5
     * i = 2 -> x = 0.5
     * i = 3 -> x = 1.5
     * i = 4 -> x = 2.5
     * 01234
     * xxxx
     * xxxx
     * xxxx
     */
#line 170
    int ox = state.x;
    int oy = state.y;
    float cx = w * 0.5;
    float cy = h * 0.5;
    float ww = w * w / 4.0;
    float hh = h * h / 4.0;
    for (int j = 0; j < h; j += 1) {
        for (int i = 0; i < w; i += 1) {
            float x = i + 0.5 - cx;
            float y = j + 0.5 - cy;
            if (x * x / ww + y * y / hh < 1.0) {
                rgba_moveto(ox + i, oy + j);
                rgba_putpixel();
            }
        }
    }
#line 183
    state.x = ox;
    state.y = oy;
}
void rgba_arc(int w, int h, float a1, float a2) {
    /* 0° = up
     * 90° = right
     * cos 0° -> 1, cos 90° -> 0
     * sin 0° -> 0, sin 90° -> 1
     * w = 4
     * x = 0
     * left = 0.5
     * right = 3.5
     * cx = 2.0
     * r = 1.5
     * 0 1 2 3 4 5
     * x x x x
     */
#line 204
    int ox = state.x;
    int oy = state.y;
    int n = (w + h) / 2.0 * (a2 - a1) / 4.0;
    if (n < 2) {
        n = 2;
    }
#line 209
    float cx = ox + w * 0.5;
    float cy = oy + h * 0.5;
    float rx = (w - 1) * 0.5;
    float ry = (h - 1) * 0.5;
    for (int i = 0; i < n + 1; i += 1) {
        float a = a1 + (a2 - a1) * i / n;
        float x = sin(a) * rx;
        float y = cos(a) * (- ry);
        if (i == 0) {
            rgba_moveto(floor(cx + x), floor(cy + y));
        }
#line 218
        else {
#line 220
            rgba_lineto(floor(cx + x), floor(cy + y));
        }
    }
#line 221
    state.x = ox;
    state.y = oy;
}
/* This file was generated by scramble.py. */
