#include <iostream>
#include "src/opencv/image_blur_detection.h"
#include "src/utils/count_down_latch.h"

static void *detection_thread(void *arg) {
    const char *filename = "/Users/devyk/Downloads/IMG_3067.PNG";
//    const char *filename = "/Users/devyk/Downloads/black.png";
    FILE *fp = fopen(filename, "rb");
    if (!fp) return reinterpret_cast<void *>(-1);
    fseek(fp, 0L, SEEK_END);
    int size = ftell(fp);
//    fseek(fp, 0L, SEEK_SET);
    rewind(fp);
    uint8_t *data = (uint8_t *) malloc(sizeof(uint8_t) * size);
    size_t size2 = fread(data, size, 1, fp);
    printf("图片模糊度检测 %d \n", image_blur_detection(filename));
    printf("图片模糊度检测 %d \n", bytes_blur_detection(data, size));
    free(data);
//    printf("图片模糊度检测 %d \n", image_blur_detection("/Users/devyk/Downloads/black.png"));
    auto *countdown = (CountDownLatch *) arg;
    countdown->countDown();
    return reinterpret_cast<void *>(1);
}

int main() {

    int count = 1;
    for (int i = 0; i < 1; ++i) {
        auto *countdown = new CountDownLatch(count);
        for (int i = 0; i < count; ++i) {
            pthread_t id;
            pthread_create(&id, 0, detection_thread, countdown);
        }
        countdown->await();
    }
    return 0;
}



