"""
This is not used. Can be deleted.
"""
import config, image

static def 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 def 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 def haar_highpass(V *v, int n):
    for int i = 0; i < n / 2; i++:
        v[n / 2 + i] -= v[i]

static def haar_lowpass(V *v, int n):
    for int i = 0; i < n / 2; i++:
        v[i] += v[n / 2 + i] / 2

# llllhhhh
# lhlhlhlh
def 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 def 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 *def detect_eye(V *image, int w, 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
