<commit_before>#include "DAIUserInstance.h"
#include <iostream>

namespace dai {

DAIUserInstance::DAIUserInstance(const InstanceInfo& info)
    : DataInstance(info)
{
    m_frameBuffer[0].reset(new UserFrame(640, 480));
    m_frameBuffer[1].reset(new UserFrame(640, 480));
    DataInstance::initFrameBuffer(m_frameBuffer[0], m_frameBuffer[1]);
    m_width = 0;
    m_height = 0;
}

DAIUserInstance::~DAIUserInstance()
{
    m_width = 0;
    m_height = 0;
    closeInstance();
}

bool DAIUserInstance::is_open() const
{
    return m_file.is_open();
}

void DAIUserInstance::openInstance()
{
    QString instancePath = m_info.getDatasetPath() + "/" + m_info.getFileName();

    if (!m_file.is_open())
    {
        m_file.open(instancePath.toStdString().c_str(), ios::in|ios::binary);

        if (!m_file.is_open()) {
            cerr << "Error opening file" << endl;
            return;
        }

        m_file.seekg(0, ios_base::beg);
        m_file.read((char *) &m_nFrames, 4);
        m_file.read((char *) &m_width, 4);
        m_file.read((char *) &m_height, 4);

        if (m_width != 640 || m_height != 480)
            exit(1);
    }
}

void DAIUserInstance::closeInstance()
{
    if (m_file.is_open()) {
        m_file.close();
    }
}

void DAIUserInstance::restartInstance()
{
    if (m_file.is_open()) {
        m_file.seekg(12, ios_base::beg);
    }
}

void DAIUserInstance::nextFrame(DataFrame &frame)
{
    // Read Data from File
    UserFrame& userFrame = (UserFrame&) frame;
    m_file.read( (char *) m_readBuffer, sizeof(m_readBuffer) );

    for (int y=0; y<m_height; ++y)
    {
        for (int x=0; x<m_width; ++x)
        {
            userFrame.setItem(y, x, m_readBuffer[y].userRow[x]);
        }
    }
}

} // End Namespace<commit_msg>Improve reading from DAI dataset *.user files<commit_after>#include "DAIUserInstance.h"
#include <iostream>

namespace dai {

DAIUserInstance::DAIUserInstance(const InstanceInfo& info)
    : DataInstance(info)
{
    m_frameBuffer[0].reset(new UserFrame(640, 480));
    m_frameBuffer[1].reset(new UserFrame(640, 480));
    DataInstance::initFrameBuffer(m_frameBuffer[0], m_frameBuffer[1]);
    m_width = 0;
    m_height = 0;
}

DAIUserInstance::~DAIUserInstance()
{
    m_width = 0;
    m_height = 0;
    closeInstance();
}

bool DAIUserInstance::is_open() const
{
    return m_file.is_open();
}

void DAIUserInstance::openInstance()
{
    QString instancePath = m_info.getDatasetPath() + "/" + m_info.getFileName();

    if (!m_file.is_open())
    {
        m_file.open(instancePath.toStdString().c_str(), ios::in|ios::binary);

        if (!m_file.is_open()) {
            cerr << "Error opening file" << endl;
            return;
        }

        m_file.seekg(0, ios_base::beg);
        m_file.read((char *) &m_nFrames, 4);
        m_file.read((char *) &m_width, 4);
        m_file.read((char *) &m_height, 4);

        if (m_width != 640 || m_height != 480)
            exit(1);
    }
}

void DAIUserInstance::closeInstance()
{
    if (m_file.is_open()) {
        m_file.close();
    }
}

void DAIUserInstance::restartInstance()
{
    if (m_file.is_open()) {
        m_file.seekg(12, ios_base::beg);
    }
}

void DAIUserInstance::nextFrame(DataFrame &frame)
{
    // Read Data from File
    UserFrame& userFrame = (UserFrame&) frame;
    u_int8_t* ptrImg = (u_int8_t*) userFrame.getDataPtr();
    m_file.read( (char *) ptrImg, userFrame.getWidth() * userFrame.getHeight() * sizeof(u_int8_t) );
}

} // End Namespace
{'fraction_non_alphanumeric': 0.15552367288378766, 'fraction_numerical': 0.020373027259684363, 'mean_word_length': 3.101176470588235, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7477703', 'n_tokens_mistral': 1327, 'n_tokens_neox': 1282, 'n_words': 216}