#include "../tools/tools.h"

#include <EGrabber.h>

using namespace Euresys;

static void sample() {
    EGenTL genTL(Gigelink()); // load GenTL producer
    EGrabber<CallbackOnDemand> grabber(genTL); // create grabber

    grabber.runScript(Tools::getSampleFilePath("101-singleframe.setup.js"));
    grabber.reallocBuffers(1); // prepare 1 buffer
    grabber.start(1, false); // grab 1 buffer
    grabber.execute<RemoteModule>("AcquisitionStart");
    {
        ScopedBuffer buffer(grabber); // wait and get a buffer
        // Note: ScopedBuffer pushes the buffer back to the input queue automatically
        // convert the buffer to BGR8
        ConvertedBuffer bgr = buffer.convert("BGR8");
        // output the converted buffer
        bgr.saveToDisk(Tools::getEnv("sample-output-path") + "/frame.NNN.jpeg", 1);
    }
}

static Tools::Sample addSample(__FILE__, sample, "Single frame grabbing using ScopedBuffer class");
