/* This file was generated by scramble.py. */
#include "detect_eye.h"
#include "scramble.h"
    /* 
     * This is not used. Can be deleted. */
static void split(V *v, int n)
{
    V copy[n];
    for (int i = 0; i < n; i++)
    {
        copy[i] = v[i];
    }
    for (int i = 0; i < n; i += 2)
    {
        v[i / 2] = copy[i];
        v[n / 2 + i / 2] = copy[i + 1];
    }
}
static void unsplit(V *v, int n)
{
    V copy[n];
    for (int i = 0; i < n; i++)
    {
        copy[i] = v[i];
    }
    for (int i = 0; i < n; i += 2)
    {
        v[i] = copy[i / 2];
        v[i + 1] = copy[n / 2 + i / 2];
    }
}
static void haar_highpass(V *v, int n)
{
    for (int i = 0; i < n / 2; i++)
    {
        v[n / 2 + i] -= v[i];
    }
}
static void haar_lowpass(V *v, int n)
{
    for (int i = 0; i < n / 2; i++)
    {
        v[i] += v[n / 2 + i] / 2;
        /* llllhhhh */
        /* lhlhlhlh */
    }
}
void unhaar(V *v, int n)
{
    for (int i = 0; i < n; i += 2)
    {
        V x = v[i];
        V y = v[i + 1];
        v[i] = x - y / 2;
        v[i + 1] = x + y / 2;
    }
}
static void unhaar2(V *v, int n)
{
    for (int i = 0; i < n; i += 2)
    {
        V x = v[i];
        /* V y = v[i + 1] */
        v[i] = x;
        v[i + 1] = x;
    }
}
V * detect_eye(V *image, int w, int h)
{
    for (int l = 0; l < 4; l++)
    {
        int lw = w >> l;
        for (int j = 0; j < h; j++)
        {
            split(image + w * j, lw);
            haar_highpass(image + w * j, lw);
            haar_lowpass(image + w * j, lw);
        }
    }
    for (int l = 3; l >= 0; l--)
    {
        int lw = w >> l;
        for (int j = 0; j < h; j++)
        {
            unsplit(image + w * j, lw);
            unhaar2(image + w * j, lw);
            /* shift_multiply_image_inplace(image, w, h, 128, 1) */
        }
    }
    return image;
}
/* This file was generated by scramble.py. */
