<commit_before>/*
* Copyright (C) 2017 by Godlike
* This code is licensed under the MIT license (MIT)
* (http://opensource.org/licenses/MIT)
*/

#include <unicorn/utility/Logger.hpp>
#include <unicorn/video/Texture.hpp>

#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>

namespace unicorn
{
namespace video
{
Texture::Texture(): m_width(0)
                  , m_height(0)
                  , m_channels(0)
                  , m_size(0)
                  , m_data(nullptr)
                  , m_initialized(false)
{
}

void Texture::Delete()
{
    if(m_data)
    {
        stbi_image_free(m_data);
        m_data = nullptr;
    }
    m_initialized = false;
}

int32_t Texture::Size() const
{
    return m_size;
}

unsigned char* Texture::Data() const
{
    return m_data;
}

int32_t Texture::Width() const
{
    return m_width;
}

int32_t Texture::Height() const
{
    return m_height;
}

const char* Texture::Path() const
{
    return m_path;
}

bool Texture::Load(const std::string& path)
{
    m_path = path.c_str();
    m_data = stbi_load(m_path, &m_width, &m_height, &m_channels, STBI_rgb_alpha);
    m_size = m_width * m_height * 4;

    if (!m_data) {
        LOG_ERROR("Failed to load texture image with path - ", m_path);
        return false;
    }
    m_initialized = true;
    return true;
}

bool Texture::IsLoaded() const
{
    return m_initialized;
}
}
}<commit_msg>[#20] Reading from unicorn memory<commit_after>/*
* Copyright (C) 2017 by Godlike
* This code is licensed under the MIT license (MIT)
* (http://opensource.org/licenses/MIT)
*/

#include <unicorn/utility/Logger.hpp>
#include <unicorn/video/Texture.hpp>
#include <unicorn/utility/asset/SimpleStorage.hpp>

#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>

namespace unicorn
{
namespace video
{
Texture::Texture(): m_width(0)
                  , m_height(0)
                  , m_channels(0)
                  , m_size(0)
                  , m_data(nullptr)
                  , m_initialized(false)
{
}

void Texture::Delete()
{
    if(m_data)
    {
        stbi_image_free(m_data);
        m_data = nullptr;
    }
    m_initialized = false;
}

int32_t Texture::Size() const
{
    return m_size;
}

unsigned char* Texture::Data() const
{
    return m_data;
}

int32_t Texture::Width() const
{
    return m_width;
}

int32_t Texture::Height() const
{
    return m_height;
}

const char* Texture::Path() const
{
    return m_path;
}

bool Texture::Load(const std::string& path)
{    
    m_path = path.c_str();
    
    unicorn::utility::asset::SimpleStorage& storage = unicorn::utility::asset::SimpleStorage::Instance();
    unicorn::utility::asset::Handler textureHandler = storage.Get(path.c_str());
    
    m_data = stbi_load_from_memory(textureHandler.GetContent().GetBuffer().data(), 
                                   textureHandler.GetContent().GetBuffer().size(),
                                   &m_width, &m_height, &m_channels, STBI_rgb_alpha);
    m_size = m_width * m_height * 4;

    if (!m_data) {
        LOG_ERROR("Failed to load texture image with path - ", m_path);
        return false;
    }
    m_initialized = true;
    return true;
}

bool Texture::IsLoaded() const
{
    return m_initialized;
}
}
}
{'fraction_non_alphanumeric': 0.1268262356232515, 'fraction_numerical': 0.009947155735156978, 'mean_word_length': 2.7462165308498254, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5380201', 'n_tokens_mistral': 1143, 'n_tokens_neox': 1114, 'n_words': 227}