#include <stdexcept>
#include <EGrabber.h>
#include "../common/window.h"

using namespace Euresys;

int main() {
    EGenTL genTL;
    EGrabberDiscovery egrabberDiscovery(genTL);
    egrabberDiscovery.discover();
    if (egrabberDiscovery.cameraCount() == 0) {
        throw std::runtime_error("No camera");
    }
    EGrabber<CallbackOnDemand> grabber(egrabberDiscovery.cameras(0));
    Window window(grabber.getWidth(), grabber.getHeight());
    grabber.reallocBuffers(3);
    grabber.start();
    while (window.isAlive()) {
        ScopedBuffer buffer(grabber);
        ConvertedBuffer rgb = buffer.convert("RGB8");
        window.updateImage(rgb.getPixels(), rgb.getBufferSize());
    }
    return 0;
}
